macos: double buffer IOSurface

It looks like, particularly on the M1, we might need to double buffer the
contents of the IOSurface<->OpenGL texture bindings. This doesn't appear
to show up on the Intel macbooks I've tried, but I've seen it in the wild
on an M1.
This commit is contained in:
Christian Hergert 2022-02-21 23:53:55 -08:00
parent b2de83efcb
commit 6016e17a38
2 changed files with 14 additions and 1 deletions

View File

@ -47,6 +47,7 @@ struct _GdkMacosSurface
GdkMacosWindow *window;
GdkMacosBuffer *buffer;
GdkMacosBuffer *front;
GPtrArray *monitors;
cairo_region_t *opaque_region;
char *title;

View File

@ -152,6 +152,7 @@ gdk_macos_surface_hide (GdkSurface *surface)
_gdk_surface_clear_update_area (surface);
g_clear_object (&self->buffer);
g_clear_object (&self->front);
if (was_key)
{
@ -427,6 +428,9 @@ gdk_macos_surface_destroy (GdkSurface *surface,
g_clear_pointer (&self->monitors, g_ptr_array_unref);
g_clear_object (&self->buffer);
g_clear_object (&self->front);
g_assert (self->sorted.prev == NULL);
g_assert (self->sorted.next == NULL);
g_assert (self->frame.prev == NULL);
@ -781,6 +785,7 @@ _gdk_macos_surface_configure (GdkMacosSurface *self)
surface->height = content_rect.size.height;
g_clear_object (&self->buffer);
g_clear_object (&self->front);
_gdk_surface_update_size (surface);
gdk_surface_request_layout (surface);
@ -1032,6 +1037,7 @@ _gdk_macos_surface_monitor_changed (GdkMacosSurface *self)
/* We need to create a new IOSurface for this monitor */
g_clear_object (&self->buffer);
g_clear_object (&self->front);
_gdk_macos_surface_configure (self);
@ -1156,14 +1162,20 @@ void
_gdk_macos_surface_swap_buffers (GdkMacosSurface *self,
const cairo_region_t *damage)
{
GdkMacosBuffer *swap;
g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
g_return_if_fail (damage != NULL);
swap = self->buffer;
self->buffer = self->front;
self->front = swap;
/* This code looks like it swaps buffers, but since the IOSurfaceRef
* appears to be retained on the other side, we really just ask all
* of the GdkMacosTile CALayer's to update their contents.
*/
[self->window swapBuffer:self->buffer withDamage:damage];
[self->window swapBuffer:swap withDamage:damage];
/* We might have delayed actually showing the window until the buffer
* contents are ready to be displayed. Doing so ensures that we don't