12to11/12to11.c
oldosfan 4d2e85d002 Implement wp_viewporter support and fix scaling for fractional values
* 12to11.c (XLMain): Initialize wp_viewporter.
* Imakefile (ETAGS): Remove unused variable.
(SRCS, OBJS): Add wp_viewporter.c and wp_viewporter.o.
(GENHEADERS): Remove unnecessary headers.
(viewporter): New scanner target.
* README: Document support for wp_viewporter.
* compositor.h (struct _ViewportExt): New forward declaration.
(struct _DrawParams): New fields for cropping and stretching.
(struct _RenderFuncs): Describe how composite works.
(struct _BufferFuncs): Make update_buffer_for_damage take
DrawParams as an argument.
(struct _State): New fields for viewporting.
(struct _Surface): New field `viewport' and associated input
delta.
(struct _XdgRoleImplementationFuncs): New field
`is_window_mapped'.  Do not commit while unmapped.
* dmabuf.c (XLInitDmabuf): Remove outdated comment.
* dnd.c (HandleMotion): Use TruncateWindowToSurface.
* egl.c (struct _EglBuffer): Add 3x3 reverse transformation
matrix.
(struct _CompositeProgram): Rename `scale' to `source'.
(Index): New macro.
(PickBetterVisual, FindVisual): Compensate for EGL picking a
non-RGBA visual.
(EglCompileCompositeProgram): Look for source, not scale.
(ComputeTransformMatrix): New function.
(Composite): Compute transformation matrix and draw using that.
(BufferFromDmaBuf, BufferFromShm): Copy identity transform and
stop setting scale.
(ReverseTransformToBox): New function.
(UpdateShmBufferIncrementally): Accept DrawParams and invert
damage according to that.
(UpdateBuffer, UpdateBufferForDamage): Pass draw params to the
incremental buffer update function.
* fns.c (XLExtendRegion): New function.
* frame_clock.c (CurrentHighPrecisionTimestamp): Delete
function.
(HighPrecisionTimestamp, HighPrecisionTimestamp32): New
functions.
(PostEndFrame): Handle X server time truncation to 32 bits.
(XLFrameClockFreeze): Remove trailing whitespace.
* picture_renderer.c (GetSourceX, GetSourceY, CompareStretch):
New functions.
(MaybeApplyTransform): Check more values before applying
transformations.  Then, handle stretch and offset.
* positioner.c (GetAdjustmentOffset, ApplyConstraintAdjustment)
(XLPositionerCalculateGeometry): Scale coordinates using new
functions.
* renderer.c (RenderUpdateBufferForDamage): Accept DrawParams
instead of scale.
* shaders.txt (Composite Rectangle Fragment Shader RGBA)
(Composite Rectangle Fragment Shader RGBX)
(Composite Rectangle Fragment Shader External): Stop
transforming texcoords.
(Composite Rectangle Vertex Shader): Transform texcoords in the
vertex shader instead.
* subcompositor.c (IsViewported, SetViewported,
ClearViewported): New functions.
(struct _View): New fields for tracking viewports and fractional
offsets.
(ViewAttachBuffer): Do not garbage upon buffer size change if a
viewport is set.
(ViewMoveFractional): New function.
(ViewDamage): Describe what the damage is and is not transformed
by.
(GetContentScale): New function.
(ViewWidth, ViewHeight): Apply viewport.
(ViewSetScale): Use ViewAfterSizeUpdate instead of duplicating
code.
(ViewSetViewport, ViewClearViewport): New functions.
(ViewComputeTransform): Compute transform for viewports.  New
arg draw; use it to determine whether or not to include a
fractional offset.
(IntersectBoxes): Fix intersection calculation.
(SubcompositorUpdate): Don't keep calling ViewWidth and
ViewHeight in a loop.
(SubcompositorExpose): Adjust for changes to buffer damage
uploading.
* subsurface.c (MoveFractional): New function.  Handle
fractional offsets after scaling.
(MaybeUpdateOutputs, AfterParentCommit, Setup, Rescale): Use
that function to move the subsurface instead.
* surface.c (ApplyScale): Update comment.
(ApplyViewport, CheckViewportValues): New functions.
(HandleScaleChanged): Apply the viewport as well upon scale
change.
(ApplyDamage): Improve damage calculation for viewported
surfaces.
(SavePendingState, InternalCommit): Save and commit viewport
state; check old values upon buffer commit.
(InitState): Initialize viewport to initial values.
(XLSurfaceRunFrameCallbacks): Handle overflows of 32-bit time at
the 49-day mark.
(SurfaceToWindow, ScaleToWindow, WindowToSurface, ScaleToSurface)
(TruncateScaleToWindow, TruncateScaleToWindow)
(TruncateWindowToSurface, TruncateScaleToSurface): New functions
for handling scale.
* xdg_popup.c (MoveWindow, IsWindowMapped, XLGetXdgPopup):
* xdg_surface.c (IsRoleMapped, Commit, Subframe)
(GetResizeDimensions, XLXdgRoleCalcNewWindowSize):
* xdg_toplevel.c (IsWindowMapped, NoteConfigureTime, SendStates)
(RecordStateSize, HandleWindowGeometryChange, NoteWindowPreResize)
(XLGetXdgToplevel): Use them instead of manually multiplying
with the factor.
2022-09-30 01:17:47 +00:00

136 lines
3.5 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* Wayland compositor running on top of an X serer.
Copyright (C) 2022 to various contributors.
This file is part of 12to11.
12to11 is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
12to11 is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with 12to11. If not, see <https://www.gnu.org/licenses/>. */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "compositor.h"
/* Globals. */
Compositor compositor;
static void
DetermineServerTime (void)
{
Time server_time;
struct timespec clock_spec, server_spec, diff;
/* Try to determine if the X server time is the same as the
monotonic time. If it is not, certain features such as "active"
frame synchronization will not be available. */
clock_gettime (CLOCK_MONOTONIC, &clock_spec);
server_time = XLGetServerTimeRoundtrip ();
server_spec.tv_sec = server_time / 1000;
server_spec.tv_nsec = ((server_time - server_time / 1000 * 1000)
* 1000000);
diff = TimespecSub (server_spec, clock_spec);
if (TimespecCmp (diff, MakeTimespec (0, 50000000)) <= 0
|| TimespecCmp (diff, MakeTimespec (0, -50000000)) <= 0)
/* Since the difference between the server time and the monotonic
time is less than 50 ms, the server time is the monotonic
time. */
compositor.server_time_monotonic = True;
else
{
compositor.server_time_monotonic = False;
fprintf (stderr, "Warning: the X server time does not seem to"
" be synchronized with the monotonic time. Multiple"
" subsurfaces may be displayed at a reduced maximum"
" frame rate.\n");
}
}
static void
XLMain (int argc, char **argv)
{
Display *dpy;
struct wl_display *wl_display;
const char *socket;
dpy = XOpenDisplay (NULL);
wl_display = wl_display_create ();
if (!dpy || !wl_display)
{
fprintf (stderr, "Display initialization failed\n");
exit (1);
}
socket = wl_display_add_socket_auto (wl_display);
if (!socket)
{
fprintf (stderr, "Unable to add socket to Wayland display\n");
exit (1);
}
compositor.display = dpy;
compositor.conn = XGetXCBConnection (dpy);
compositor.wl_display = wl_display;
compositor.wl_socket = socket;
compositor.wl_event_loop
= wl_display_get_event_loop (wl_display);
InitXErrors ();
SubcompositorInit ();
InitSelections ();
XLInitTimers ();
XLInitAtoms ();
/* Initialize renderers immediately after timers and atoms are set
up. */
InitRenderers ();
XLInitRROutputs ();
XLInitCompositor ();
XLInitSurfaces ();
XLInitShm ();
XLInitXdgWM ();
XLInitXdgSurfaces ();
XLInitXdgToplevels ();
XLInitFrameClock ();
XLInitSubsurfaces ();
XLInitSeats ();
XLInitDataDevice ();
XLInitPopups ();
XLInitDmabuf ();
XLInitXData ();
XLInitXSettings ();
XLInitIconSurfaces ();
XLInitPrimarySelection ();
XLInitExplicitSynchronization ();
XLInitWpViewporter ();
/* This has to come after the rest of the initialization. */
DetermineServerTime ();
XLRunCompositor ();
}
int
main (int argc, char **argv)
{
XLMain (argc, argv);
return 0;
}