12to11/12to11.c
oldosfan b4ee06589e Add support for EGL, for YUV image formats
EGL support is still incomplete; stuff like scaling is missing.

* 12to11.c (PickVisual, XLMain): Remove function.  Initialize
renderers, and rely on that to initialize the visuals.
* 12to11.man: Document new environment variables.
* Imakefile (SRCS, OBJS): Add picture_renderer.c and renderer.c
and their associated objects.
(GENHEADERS): New variable for generated headers.
(EGL_SRCS, EGL_OBJS): New variables.
(LOCAL_LIBRARIES, SRCS, OBJS, DEFINES): [HaveEglSupport]: Add
EGL defines, libraries, and objects.:(shaders.h): New rule.
(depend, cleandir): Depend on generated headers and SRCs.
$($(OBJS)): Depend on $(GENHEADERS).
* README: Write how to build with EGL support and update content
descriptions.
* buffer.c (XLPictureFromBuffer): Delete function.
(XLRenderBufferFromBuffer): New function.
(XLPixmapFromBuffer): Delete function.
* compositor.h (enum _Operation, struct _SharedMemoryAttributes)
(struct _DmaBufAttributes, union _RenderTarget)
(union _RenderBuffer, struct _RenderFuncs, struct _DrmFormat)
(struct _ShmFormat, struct _BufferFuncs, struct
_ExtBufferFuncs): New structures.
(Fallthrough): New define.  Define to __attribute__
((fallthrough)) wherever supported.  Replace uses of Picture
with RenderBuffer.
* dmabuf.c (struct _DrmFormatInfo): Remove structures.
(struct _BufferParams): Remove link.
(struct _Buffer): Replace pixmap and picture with render buffer
object.
(dri3_opcode, all_formats, pending_success, next_roundtrip_id)
(round_trip_window): Delete.
(ReleaseBufferParams, HandleParamsResourceDestroy, ForceRoundTrip)
(DepthForFormat, XLHandleErrorForDmabuf, PictFormatForFormat)
(DestroyBacking, GetPictureFunc, GetPixmapFunc, GetBufferFunc)
(CreateBufferFor, ModifierHigh, FinishBufferCreation)
(XLHandleOneXEventForDmabuf, CreateHeader, Create, CreateImmed)
(FindFormatMatching, FindSupportedModifiers, FindSupportedFormats)
(SendSupportedFormats, HandleBind, InitDrmDevice, WriteFormatTable)
(ReallyInitDmabuf, ReadSupportedFormats, XLInitDmabuf): Remove
various functions and reimplement as a wrapper around the
renderer abstraction, instead of DRI3.
* fns.c (struct _Busfault): New structure.
(busfault_tree, bus_handler_installed): New variables.
(GetHeight, FixHeights, RotateLeft, RotateRight, RebalanceBusfault)
(RecordBusfault, DetectBusfault, DeleteMin, RemoveBusfault)
(HandleBusfault, MaybeInstallBusHandler, BlockSigbus)
(UnblockSigbus, XLRecordBusfault, XLRemoveBusfaults): New
functions to store non-overlapping regions of mapped memory in
an AVL tree, and to ignore SIGBUS events that trap within.
* icon_surface.c (struct _IconSurface): Replace picture with
rendering target.
(ReleaseBacking, XLGetIconSurface): Use rendering targets
instead of pictures.
* libraries.def: Add defines for EGL.
* run.c (HandleOneXEvent): Replace old dmabuf code with renderer
code.
* seat.c (CursorFromRole, PictureForCursor, ApplyCursor)
(UpdateCursorFromSubcompositor, Subframe, EndSubframe): Rewrite
cursor code to use rendering targets and not pictures.
* shm.c (Buffer, DereferencePool): Remove SIGBUS protection.
(DereferenceBuffer): Reimplement in terms of renderer functions.
(GetPictureFunc): Delete function.
(GetBufferFunc): New function.
(GetPixmapFunc): Delete function.
(PrintBuffer): Remove now-broken implementation.
(DepthForFormat, PictFormatForFormat): Delete functions, as they
are now part of the rendering backend.
(IsFormatSupported): New function.
(CreateBuffer): Reimplement in terms of renderer functions.
(ResizePool): Change SIGBUS protection for resize.
(CreatePool): Protect buffer data from SIGBUS should a client
truncate the file.
(PostFormats): Reimplement in terms of RenderGetShmFormats.
(XLInitShm): Stop initializing MIT-SHM.
* subcompositor.c (IsTargetAttached): New flag and associated
macros.
(struct _View): Remove useless field.
(struct _Subcompositor): Change target to RenderTarget.  Add
fields for prior damage.
(MakeSubcompositor): Initialize new fields.
(SubcompositorSetTarget): Accept RenderTarget, not picture, and
set target attached flag.
(ViewGetTransform): Delete function.
(ViewApplyTransform): New function.
(FillBoxesWithTransparency): Reimplement in terms of renderer
functions.
(StorePreviousDamage): New function.
(SubcompositorUpdate): Reimplement in terms of renderer
functions.  Also, learn to deal with situations where the buffer
reflects the state 1 to 2 swaps ago.
(SubcompositorExpose): Reimplement in terms of renderer
functions.
(SubcompositorFree): Free new fields.
(SubcompositorInit): Remove no longer required initialization of
identity matrix.
* xdata.c (ReceiveBody): Fix coding style.
* xdg_surface.c (struct _XdgRole, ReleaseBacking,
XLGetXdgSurface): Switch from pictures to RenderTargets.
* xerror.c (ErrorHandler): Handle errors for picture renderer
instead of dmabuf.c.
2022-09-23 08:44:37 +00:00

146 lines
3.7 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 Colormap
MakeColormap (void)
{
return XCreateColormap (compositor.display,
DefaultRootWindow (compositor.display),
compositor.visual, AllocNone);
}
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 ();
/* Set up the colormap. Initializing renderers should also cause
the visual to be set. */
compositor.colormap = MakeColormap ();
XLInitRROutputs ();
XLInitCompositor ();
XLInitSurfaces ();
XLInitShm ();
XLInitXdgWM ();
XLInitXdgSurfaces ();
XLInitXdgToplevels ();
XLInitFrameClock ();
XLInitSubsurfaces ();
XLInitSeats ();
XLInitDataDevice ();
XLInitPopups ();
XLInitDmabuf ();
XLInitXData ();
XLInitXSettings ();
XLInitIconSurfaces ();
XLInitPrimarySelection ();
/* This has to come after the rest of the initialization. */
DetermineServerTime ();
XLRunCompositor ();
}
int
main (int argc, char **argv)
{
XLMain (argc, argv);
return 0;
}