forked from 12to11/12to11

Note that the EGL renderer has been broken by these changes. * compositor.h (struct _RenderFuncs): Change arguments to `finish_render'. Add `cancel_completion_callback'. Remove `cancel_presentation'. (struct _BufferFuncs): Add `is_buffer_opaque'. * egl.c: Note that the EGL renderer is currently broken. * fence_ring.c (FenceFree, struct _Fence, GetFence, FenceAwait) (FenceToXFence): Repurpose fence code as a generic allocator of fences. * frame_clock.c (EndFrame): Adjust calculation of even value. * picture_renderer.c (struct _BufferActivityRecord): Remove `fence'. (struct _PictureBuffer): Remove unused field. (struct _PresentCompletionCallback): Remove unused fields linking it to the target. (struct _BackBuffer): New structure. (IsBufferBusy, SetBufferBusy, ClearBufferBusy): New macros. (struct _PictureTarget): Add back buffer and GC fields. (use_sync_fences): Remove variable. (RecordBufferActivity): Don't take fence. (UnlinkActivityRecord): Don't wait on fence. (FreeBackBuffer, FreeBackBuffers, CreateBackBuffer) (MakePresentationCallback, SwapBackBuffers) (SwapBackBuffersWithCopy, MaybeAwaitBuffer, GetNextBackBuffer) (EnsurePicture): New functions. (TargetFromDrawable): Don't create picture for window targets, and create GC for those. (NoteTargetSize): Free back buffers instead of creating presentation windows. (DestroyRenderTarget): Free back buffers. (ViewContainsExtents): Delete function. (FinishRender): Swap back buffers and handle callbacks. (CancelCompletionCallback): New function. (TargetAge): Implement accordingly. (PresentToWindow, CancelPresentationCallback): Present to the regular window instead of a separate ``presentation window''. (CancelPresentation): Remove function. (picture_render_funcs): Add CancelCompletionCallback; remove NeverAges and CancelPresentation. (BufferFromDmaBuf, FinishDmaBufRecord, BufferFromShm): Set opaque flag accordingly. (IsBufferOpaque): New function. (picture_buffer_funcs): Add IsBufferOpaque. (HandlePresentCompleteNotify, HandlePresentIdleNotify): Handle back buffer release. * renderer.c (RenderFinishRender, RenderCancelCompletionCallback) (RenderCancelPresentation, RenderIsBufferOpaque): Adjust accordingly. * seat.c (InterpolateAxes): Fix NULL-pointer dereference. * subcompositor.c (SetFrozen, IsFrozen): Get rid of unused state. (struct _View): Cache the width and height. Add cull_region field. (struct _Subcompositor): Add `render_key' field. (ViewAfterSizeUpdate): Set cached width and height. (ViewAttachBuffer): Correctly handle size changes. (ViewDamage): Apply buffer damage. (ViewDamageBuffer): use ViewDamage. (ApplyBufferDamage): New function.:(FillBoxesWithTransparency, ViewContainsExtents, IntersectBoxes): Delete unused functions. (RenderCompletedCallback): New function. (NoViewsAfter): Delete function. (SkipSlug): New slug. (SubcompositorUpdateAncillary, TryPresent, AnyParentUnmapped) (DoCull, DrawBackground, CompositeSingleView, InitBackground) (SubcompositorComposite1, SubcompositorComposite): New functions. Implement new redisplay logic here. (SubcompositorUpdate, CopyRegion): New function. (SubcompositorExpose, SubcompositorFree): Clear render callback if set. (SubcompositorLookupView): Use cached width and height. (SubcompositorFreeze, SubcompositorUnfreeze): Remove unused functions. * time.c (InitTime): Fix use of uninitialized value initializing the Sync extension. * transform.c (TransformBox): Pacify compiler warning.
125 lines
2.5 KiB
C
125 lines
2.5 KiB
C
/* Wayland compositor running on top of an X server.
|
|
|
|
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 <sys/fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "compositor.h"
|
|
|
|
#include <X11/xshmfence.h>
|
|
#include <X11/extensions/sync.h>
|
|
|
|
#include <xcb/dri3.h>
|
|
|
|
struct _Fence
|
|
{
|
|
/* The xshmfence. */
|
|
struct xshmfence *fence;
|
|
|
|
/* The sync fence. */
|
|
XSyncFence fence_id;
|
|
|
|
/* The number of references to this fence. Incremented by
|
|
FenceRetain, decremented by FenceRelease. */
|
|
int refcount;
|
|
};
|
|
|
|
Fence *
|
|
GetFence (void)
|
|
{
|
|
Fence *fence;
|
|
int fd;
|
|
Window drawable;
|
|
|
|
drawable = DefaultRootWindow (compositor.display);
|
|
|
|
/* Allocate a new fence. */
|
|
fence = XLCalloc (1, sizeof *fence);
|
|
fd = xshmfence_alloc_shm ();
|
|
|
|
if (fd < 0)
|
|
{
|
|
perror ("xshmfence_alloc_shm");
|
|
abort ();
|
|
}
|
|
|
|
/* Map it. */
|
|
fence->fence = xshmfence_map_shm (fd);
|
|
|
|
if (!fence->fence)
|
|
{
|
|
perror ("xshmfence_map_shm");
|
|
abort ();
|
|
}
|
|
|
|
/* Upload the fence to the X server. XCB will close the file
|
|
descriptor. */
|
|
fence->fence_id = xcb_generate_id (compositor.conn);
|
|
|
|
/* Make the file descriptor CLOEXEC, since it isn't closed
|
|
immediately. */
|
|
XLAddFdFlag (fd, FD_CLOEXEC, False);
|
|
xcb_dri3_fence_from_fd (compositor.conn, drawable,
|
|
fence->fence_id, 0, fd);
|
|
|
|
/* Retain the fence. */
|
|
FenceRetain (fence);
|
|
|
|
/* Return the fence. */
|
|
return fence;
|
|
}
|
|
|
|
void
|
|
FenceAwait (Fence *fence)
|
|
{
|
|
/* Wait for the fence to be triggered. */
|
|
xshmfence_await (fence->fence);
|
|
|
|
/* Reset the fence. */
|
|
xshmfence_reset (fence->fence);
|
|
}
|
|
|
|
void
|
|
FenceRelease (Fence *fence)
|
|
{
|
|
if (--fence->refcount)
|
|
return;
|
|
|
|
/* Unmap the fence. */
|
|
xshmfence_unmap_shm (fence->fence);
|
|
|
|
/* Destroy the fence. */
|
|
XSyncDestroyFence (compositor.display, fence->fence_id);
|
|
|
|
/* Free the fence. */
|
|
XLFree (fence);
|
|
}
|
|
|
|
void
|
|
FenceRetain (Fence *fence)
|
|
{
|
|
fence->refcount++;
|
|
}
|
|
|
|
XSyncFence
|
|
FenceToXFence (Fence *fence)
|
|
{
|
|
return fence->fence_id;
|
|
}
|