12to11/12to11.c
oldosfan 713eb811ea Add support for DRM leasing and significantly rework composition code
* 12to11.c (HandleCmdline): Improve messages printed during
-help.
(XLMain): Initialize DRM leasing.
* 12to11.man: Document changes.
* Imakefile (LOCAL_LIBRARIES): Add xcb-randr, xf86drm and
XPresent.
(SRCS): Add drm_lease.c.
(OBJS): Add drm_lease.o.
* atoms.c (names): Add CONNECTOR_ID.
(CONNECTOR_ID): New atom.
(XLInitAtoms): Intern CONNECTOR_ID.
* compositor.h (struct _RenderFuncs): Require event mask to be
passed to target_from_window.  New functions
`set_standard_event_mask', `present_to_window',
`cancel_presentation_callback', and `cancel_presentation'.
(struct _BufferFuncs): Move buffer release machinery here.
(enum _FrameMode): New enum.
* egl.c (TargetFromWindow, SetStandardEventMask,
egl_render_funcs): Adjust functions accordingly.
* frame_clock.c (struct _FrameClock): New fields
`end_frame_called' and `pending_sync_value'.
(HandleEndFrame, PostEndFrame, StartFrame, EndFrame): Clean up
frame synchronization code.  Do not end upon predicted
presentation time if EndFrame was not called in time.
(FreezeForValue): New function.
(XLFrameClockHandleFrameEvent): Defer actually freezing until
StartFrame happens.
(XLFrameClockGetFrameTime): New function.
* icon_surface.c (ReleaseBuffer): Use RenderWaitForIdle.
(RunFrameCallbacks, AfterFrame): Pass frame clock to callbacks.
Use frame time if available.
(XLGetIconSurface): Require wait_for_idle to work.
* output.c (change_hook): New hook.
(XLHandleOneXEventForOutputs): Run hook if set.
(XLOutputSetChangeFunction): New function.
(XLInitRROutputs): Select for RRResourceChangeNotify if
providers are supported.
* picture_renderer.c (struct _PresentRecord)
(struct _BufferActivityRecord, struct _IdleCallback)
(struct _PictureBuffer, struct _PictureTarget)
(struct _DrmFormatInfo, struct _DmaBufRecord)
(struct _PresentCompletionCallback): New record structures.
(all_formats, SendRoundtripMessage, FindBufferActivityRecord)
(RecordBufferActivity, RunIdleCallbacks, MaybeRunIdleCallbacks)
(UnlinkActivityRecord, HandleActivityEvent, InitRenderFuncs)
(TargetFromDrawable, TargetFromPixmap, TargetFromWindow)
(SetStandardEventMask, NoteTargetSize, PictureFromTarget)
(DestroyRenderTarget, FillBoxesWithTransparency)
(ServerRegionFromRegion, ClearRectangle, Composite)
(FindPresentRecord, AllocateRecord, PresentToWindow)
(CancelPresentationCallback, CancelPresentation)
(picture_render_funcs, FindSupportedModifiers, InitDrmFormats)
(PictFormatIsPresentable, BufferFromDmaBuf, FinishDmaBufRecord)
(BufferFromDmaBufAsync, BufferFromShm, BufferFromSinglePixel)
(FreeShmBuffer, FreeDmabufBuffer, FreeSinglePixelBuffer)
(AddIdleCallback, CancelIdleCallback, IsBufferIdle)
(IdleEventPredicate, WaitForIdle, SetNeedWaitForIdle)
(picture_buffer_funcs, HandlePresentCompleteNotify)
(HandlePresentIdleNotify, HandlePresentationEvent)
(HandleOneXEventForPictureRenderer, InitPictureRenderer): Allow
presenting pixmaps directly, and move buffer release tracking
machinery here.
* renderer.c (RenderTargetFromWindow): Update signature.
(RenderPresentToWindow, RenderCancelPresentationCallback)
(RenderCancelPresentation, RenderAddIdleCallback)
(RegisterStaticRenderer): New wrapper functions.
* run.c (HandleOneXEvent): Handle picture renderer events
earlier.
* seat.c (MaybeCreateCursor): Require wait_for_idle.
(ReleaseBuffer): Wait for buffer to become idle on each target
in the cursor ring.
* subcompositor.c (struct _Subcompositor): New callback
`note_frame'.
(SubcompositorSetNoteFrameCallback, NoViewsAfter)
(PresentCompletedCallback): New functions.
(SubcompositorUpdate): Try to present the buffer if possible,
and run completion callbacks.
(SubcompositorFree): Free presentation key.
* surface.c (XLSurfaceRunFrameCallbacksMs): New function.
* text_input.c: Improve commentary.
* xdg-shell.xml: Update from wayland-protocols.
* xdg_surface.c (struct _XdgRole): New fields `pending_frame',
`last_specified_serial'.
(struct _ReleaseLaterRecord): Replace free function with idle
callback key and xdg role pointers.
(RemoveRecord): Delete function.
(FreeRecords): Stop cancelling buffer destroy listener.
(ReleaseLaterExtBufferFunc): Delete function.
(RunFrameCallbacks): Use frame clock time if it is set.
(HandleReleaseLaterMessage): Delete function.
(BufferIdleCallback): New function.
(ReleaseLater): Delete function.
(XLHandleXEventForXdgSurfaces): Stop handling buffer release
events here.
(AckConfigure): Improve debug code and reject duplicate serials.
(Commit): Unfreeze earlier; also, in general...
(NoteFrame): Move frame handling implementation here.
(ReleaseBuffer, Subframe, EndSubframe, AfterFrame, ResizeForMap)
(SelectExtraEvents): Set standard event mask.
(XLGetXdgSurface, XLXdgRoleSendConfigure): ...Replace frame
clock logic with that in NoteFrame.
2022-10-12 12:53:09 +00:00

239 lines
5.8 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 <string.h>
#include <time.h>
#include <locale.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
HandleCmdline (Display *dpy, int argc, char **argv)
{
int i;
XrmDatabase rdb, initial_rdb;
/* Set the default resource and class names. */
compositor.resource_name = "12to11";
compositor.app_name = "12to11";
if (argc < 2)
/* There are no arguments to handle. */
return;
/* Obtain the resource database. */
initial_rdb = rdb = XrmGetDatabase (dpy);
/* Determine the instance name based on the executable. First,
remove any leading directory separator from argv[0]. */
compositor.app_name = strrchr (argv[0], '/');
/* If no directory separator was present, just use it. */
if (!compositor.app_name)
compositor.app_name = argv[0];
else
/* Otherwise, strip the trailing '/'. */
compositor.app_name = compositor.app_name + 1;
for (i = 1; i < argc; ++i)
{
if (!strcmp (argv[i], "-help"))
{
print_usage:
fprintf (stderr,
"usage: %s [-name name] [-class class] [-xrm resourcestring...]\n",
argv[0]);
exit (!strcmp (argv[i], "-help") ? 0 : 1);
}
else if (!strcmp (argv[i], "-class"))
{
if (i + 1 >= argc)
{
fprintf (stderr, "%s: option -class requires a value\n",
argv[0]);
exit (1);
}
compositor.resource_name = argv[++i];
}
else if (!strcmp (argv[i], "-name"))
{
if (i + 1 >= argc)
{
fprintf (stderr, "%s: option -name requires a value\n",
argv[0]);
exit (1);
}
compositor.app_name = argv[++i];
}
else if (!strcmp (argv[i], "-xrm"))
{
if (i + 1 >= argc)
{
fprintf (stderr, "%s: option -xrm requires a value\n",
argv[0]);
exit (1);
}
XrmPutLineResource (&rdb, argv[++i]);
}
else
{
fprintf (stderr, "%s: bad command line option \"%s\"\n",
argv[0], argv[1]);
goto print_usage;
}
}
/* In case XrmPutLineResource created a new database, set it as the
display's resource database. */
if (rdb != initial_rdb)
XrmSetDatabase (dpy, rdb);
}
static void
XLMain (int argc, char **argv)
{
Display *dpy;
struct wl_display *wl_display;
const char *socket;
/* Set the locale. */
setlocale (LC_ALL, "");
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);
}
/* Call XGetDefault with some dummy values to have the resource
database set up. */
XrmInitialize ();
XGetDefault (dpy, "dummmy", "value");
/* Parse command-line arguments. */
HandleCmdline (dpy, argc, argv);
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 ();
XLInitDecoration ();
XLInitTextInput ();
XLInitSinglePixelBuffer ();
XLInitDrmLease ();
/* This has to come after the rest of the initialization. */
DetermineServerTime ();
XLRunCompositor ();
}
int
main (int argc, char **argv)
{
XLMain (argc, argv);
return 0;
}