[gtk/wip/chergert/macos-iosurface: 2/2] macos: delay IOSurface creation until necessary




commit a4f14a3b5ffecd39269112521b7b1e8481a60262
Author: Christian Hergert <christian hergert me>
Date:   Sat Feb 12 02:46:58 2022 -0800

    macos: delay IOSurface creation until necessary
    
    We don't need to create buffers especially if we're just going to throw
    them away in the same frame processing changes. Instead just move towards
    releasing them and creating it on the next frame rendering.

 gdk/macos/gdkmacossurface.c | 56 ++++++++++++++++++++++-----------------------
 1 file changed, 27 insertions(+), 29 deletions(-)
---
diff --git a/gdk/macos/gdkmacossurface.c b/gdk/macos/gdkmacossurface.c
index 49e11e43c0..859a5c935d 100644
--- a/gdk/macos/gdkmacossurface.c
+++ b/gdk/macos/gdkmacossurface.c
@@ -63,6 +63,14 @@ window_is_fullscreen (GdkMacosSurface *self)
   return ([self->window styleMask] & NSWindowStyleMaskFullScreen) != 0;
 }
 
+static void
+gdk_macos_surface_update_buffers (GdkMacosSurface *self)
+{
+  g_assert (GDK_IS_MACOS_SURFACE (self));
+
+  g_clear_object (&self->buffer);
+}
+
 void
 _gdk_macos_surface_reposition_children (GdkMacosSurface *self)
 {
@@ -137,6 +145,8 @@ gdk_macos_surface_hide (GdkSurface *surface)
 
   _gdk_surface_clear_update_area (surface);
 
+  gdk_macos_surface_update_buffers (self);
+
   if (was_mapped)
     gdk_surface_freeze_updates (GDK_SURFACE (self));
 }
@@ -861,35 +871,6 @@ _gdk_macos_surface_synthesize_null_key (GdkMacosSurface *self)
   _gdk_event_queue_append (display, event);
 }
 
-static void
-gdk_macos_surface_update_buffers (GdkMacosSurface *self)
-{
-  GdkMacosBuffer *buffer;
-  double scale;
-  guint width;
-  guint height;
-
-  g_assert (GDK_IS_MACOS_SURFACE (self));
-
-  scale = gdk_surface_get_scale_factor (GDK_SURFACE (self));
-  width = GDK_SURFACE (self)->width * scale;
-  height = GDK_SURFACE (self)->height * scale;
-
-  /* Create replacement buffer. We always use 4-byte and 32-bit BGRA for
-   * our surface as that can work with both Cairo and GL. The GdkMacosTile
-   * handles opaque regions for the compositor, so using 3-byte/24-bit is
-   * not a necessary optimization.
-   */
-  buffer = _gdk_macos_buffer_new (width, height, scale, 4, 32);
-
-  /* If we failed, just keep the old buffer around. */
-  if (buffer != NULL)
-    {
-      g_clear_object (&self->buffer);
-      self->buffer = buffer;
-    }
-}
-
 void
 _gdk_macos_surface_move (GdkMacosSurface *self,
                          int              x,
@@ -1124,6 +1105,23 @@ _gdk_macos_surface_get_buffer (GdkMacosSurface *self)
 {
   g_return_val_if_fail (GDK_IS_MACOS_SURFACE (self), NULL);
 
+  if (GDK_SURFACE_DESTROYED (self))
+    return NULL;
+
+  if (self->buffer == NULL)
+    {
+      /* Create replacement buffer. We always use 4-byte and 32-bit BGRA for
+       * our surface as that can work with both Cairo and GL. The GdkMacosTile
+       * handles opaque regions for the compositor, so using 3-byte/24-bit is
+       * not a necessary optimization.
+       */
+      double scale = gdk_surface_get_scale_factor (GDK_SURFACE (self));
+      guint width = GDK_SURFACE (self)->width * scale;
+      guint height = GDK_SURFACE (self)->height * scale;
+
+      self->buffer = _gdk_macos_buffer_new (width, height, scale, 4, 32);
+    }
+
   return self->buffer;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]