From: Christian Hergert Date: Mon, 28 Feb 2022 09:29:22 +0000 (-0800) Subject: macos: add readonly IOSurfaceLock helper X-Git-Tag: archive/raspbian/4.8.3+ds-2+rpi1~3^2~20^2~4^2~353^2~8 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=dbede0b11599b284bf57154a334254789fc16ab1;p=gtk4.git macos: add readonly IOSurfaceLock helper This can be used to lock a surface for reading to avoid causing the surface contents to be invalidated. This is needed when reading back from a front-buffer to the back-buffer as is needed when using Cairo surfaces to implement something similar to BufferAge. --- diff --git a/gdk/macos/gdkmacosbuffer-private.h b/gdk/macos/gdkmacosbuffer-private.h index 6be201147c..4b446a7212 100644 --- a/gdk/macos/gdkmacosbuffer-private.h +++ b/gdk/macos/gdkmacosbuffer-private.h @@ -41,6 +41,8 @@ GdkMacosBuffer *_gdk_macos_buffer_new (int width IOSurfaceRef _gdk_macos_buffer_get_native (GdkMacosBuffer *self); void _gdk_macos_buffer_lock (GdkMacosBuffer *self); void _gdk_macos_buffer_unlock (GdkMacosBuffer *self); +void _gdk_macos_buffer_read_lock (GdkMacosBuffer *self); +void _gdk_macos_buffer_read_unlock (GdkMacosBuffer *self); guint _gdk_macos_buffer_get_width (GdkMacosBuffer *self); guint _gdk_macos_buffer_get_height (GdkMacosBuffer *self); guint _gdk_macos_buffer_get_stride (GdkMacosBuffer *self); diff --git a/gdk/macos/gdkmacosbuffer.c b/gdk/macos/gdkmacosbuffer.c index ac99302ee4..46a0504461 100644 --- a/gdk/macos/gdkmacosbuffer.c +++ b/gdk/macos/gdkmacosbuffer.c @@ -192,6 +192,45 @@ _gdk_macos_buffer_unlock (GdkMacosBuffer *self) IOSurfaceUnlock (self->surface, 0, NULL); } +/** + * _gdk_macos_buffer_lock_readonly: + * + * Like _gdk_macos_buffer_lock() but uses the read-only flag to + * indicate we are not interested in retrieving the updates from + * the GPU before modifying the CPU-side cache. + * + * Must be used with _gdk_macos_buffer_unlock_readonly(). + */ +void +_gdk_macos_buffer_read_lock (GdkMacosBuffer *self) +{ + kern_return_t ret; + + g_return_if_fail (GDK_IS_MACOS_BUFFER (self)); + g_return_if_fail (self->lock_count == 0); + + self->lock_count++; + + ret = IOSurfaceLock (self->surface, kIOSurfaceLockReadOnly, NULL); + + g_return_if_fail (ret == KERN_SUCCESS); +} + +void +_gdk_macos_buffer_read_unlock (GdkMacosBuffer *self) +{ + kern_return_t ret; + + g_return_if_fail (GDK_IS_MACOS_BUFFER (self)); + g_return_if_fail (self->lock_count == 1); + + self->lock_count--; + + ret = IOSurfaceUnlock (self->surface, kIOSurfaceLockReadOnly, NULL); + + g_return_if_fail (ret == KERN_SUCCESS); +} + guint _gdk_macos_buffer_get_width (GdkMacosBuffer *self) {