[gtk/wip/chergert/macos-perf-fixes: 7/7] macos: improve use of swap rectangles with OpenGL




commit 13e162c404d649a485999e85da457df18b008b56
Author: Christian Hergert <chergert redhat com>
Date:   Mon Feb 8 09:59:59 2021 -0800

    macos: improve use of swap rectangles with OpenGL

 gdk/macos/gdkmacosglcontext-private.h |  1 -
 gdk/macos/gdkmacosglcontext.c         | 46 +++++++++++++++++------------------
 2 files changed, 23 insertions(+), 24 deletions(-)
---
diff --git a/gdk/macos/gdkmacosglcontext-private.h b/gdk/macos/gdkmacosglcontext-private.h
index f3499ab1ca..97d209b6f7 100644
--- a/gdk/macos/gdkmacosglcontext-private.h
+++ b/gdk/macos/gdkmacosglcontext-private.h
@@ -45,7 +45,6 @@ struct _GdkMacosGLContext
   NSView *dummy_view;
 
   cairo_region_t *damage;
-  cairo_rectangle_int_t flush_rect;
 
   guint is_attached : 1;
   guint needs_resize : 1;
diff --git a/gdk/macos/gdkmacosglcontext.c b/gdk/macos/gdkmacosglcontext.c
index 28b3ed7ac7..f50e837465 100644
--- a/gdk/macos/gdkmacosglcontext.c
+++ b/gdk/macos/gdkmacosglcontext.c
@@ -278,6 +278,9 @@ gdk_macos_gl_context_begin_frame (GdkDrawContext *context,
 
   surface = gdk_draw_context_get_surface (context);
 
+  g_clear_pointer (&self->damage, cairo_region_destroy);
+  self->damage = cairo_region_copy (painted);
+
   /* If begin frame is called, that means we are trying to draw to
    * the NSWindow using our view. That might be a GdkMacosCairoView
    * but we need it to be a GL view. Also, only in this case do we
@@ -286,28 +289,7 @@ gdk_macos_gl_context_begin_frame (GdkDrawContext *context,
    */
   if (!self->is_attached &&
       gdk_gl_context_get_shared_context (GDK_GL_CONTEXT (context)))
-    {
-      CGLContextObj glctx = [self->gl_context CGLContextObj];
-      GLint swapRect[4];
-
-      ensure_gl_view (self);
-
-      g_clear_pointer (&self->damage, cairo_region_destroy);
-      self->damage = cairo_region_copy (painted);
-
-      cairo_region_get_extents (painted, &self->flush_rect);
-
-      /* Coordinates are in display coordinates, where as flush_rect is
-       * in GDK coordinates. Must flip Y to match display coordinates where
-       * 0,0 is the bottom-left corner.
-       */
-      swapRect[0] = self->flush_rect.x;                   /* left */
-      swapRect[1] = surface->height - self->flush_rect.y; /* bottom */
-      swapRect[2] = self->flush_rect.width;               /* width */
-      swapRect[3] = self->flush_rect.height;              /* height */
-
-      CGLSetParameter (glctx, kCGLCPSwapRectangle, swapRect);
-    }
+    ensure_gl_view (self);
 
   if (self->needs_resize)
     {
@@ -363,7 +345,25 @@ gdk_macos_gl_context_end_frame (GdkDrawContext *context,
   GDK_DRAW_CONTEXT_CLASS (gdk_macos_gl_context_parent_class)->end_frame (context, painted);
 
   if (!self->is_attached)
-    [self->gl_context flushBuffer];
+    {
+      GdkSurface *surface = gdk_draw_context_get_surface (context);
+      CGLContextObj glctx = [self->gl_context CGLContextObj];
+      cairo_rectangle_int_t flush_rect;
+      GLint swapRect[4];
+
+      /* Coordinates are in display coordinates, where as flush_rect is
+       * in GDK coordinates. Must flip Y to match display coordinates where
+       * 0,0 is the bottom-left corner.
+       */
+      cairo_region_get_extents (painted, &flush_rect);
+      swapRect[0] = flush_rect.x;                   /* left */
+      swapRect[1] = surface->height - flush_rect.y; /* bottom */
+      swapRect[2] = flush_rect.width;               /* width */
+      swapRect[3] = flush_rect.height;              /* height */
+      CGLSetParameter (glctx, kCGLCPSwapRectangle, swapRect);
+
+      [self->gl_context flushBuffer];
+    }
 }
 
 static void


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