[gtk/wip/chergert/gdk-macos-gl-renderer: 16/26] macos: do less work to update backing surface




commit ba1c8fee854e8df394c32b1cd9f251b57a975cb2
Author: Christian Hergert <chergert redhat com>
Date:   Tue Oct 27 16:48:25 2020 -0700

    macos: do less work to update backing surface
    
    We don't need to call update so much on the NSOpenGLContext. Instead,
    just do it when our window size changes. But only do that right when we
    start the next frame. While we still are not sync'd with the window resizing,
    we do seem to be less latent.

 gdk/macos/GdkMacosGLView.c            | 49 +----------------------------------
 gdk/macos/GdkMacosGLView.h            |  1 -
 gdk/macos/gdkmacosglcontext-private.h |  1 +
 gdk/macos/gdkmacosglcontext.c         | 37 ++++++++++++++------------
 4 files changed, 22 insertions(+), 66 deletions(-)
---
diff --git a/gdk/macos/GdkMacosGLView.c b/gdk/macos/GdkMacosGLView.c
index 7b3dbebbfb..ca7b600783 100644
--- a/gdk/macos/GdkMacosGLView.c
+++ b/gdk/macos/GdkMacosGLView.c
@@ -50,22 +50,7 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
   self = [super initWithFrame:frameRect];
 
   if (self != nil)
-    {
-      NSNotificationCenter *center;
-
-      _pixelFormat = [format retain];
-      center = [NSNotificationCenter defaultCenter];
-
-      [center addObserver:self
-                 selector:@selector(_surfaceNeedsUpdate:)
-                     name:NSViewGlobalFrameDidChangeNotification
-                   object:self];
-
-      [center addObserver:self
-                 selector:@selector(_surfaceNeedsUpdate:)
-                     name:NSViewFrameDidChangeNotification
-                   object:self];
-    }
+    _pixelFormat = [format retain];
 
   return self;
 }
@@ -80,18 +65,6 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
   return _pixelFormat;
 }
 
--(void)_surfaceNeedsUpdate:(NSNotification *)notification
-{
-  [[self openGLContext] makeCurrentContext];
-  [self update];
-  [self reshape];
-}
-
--(void)reshape
-{
-  [self update];
-}
-
 -(void)lockFocus
 {
   NSOpenGLContext *context;
@@ -104,11 +77,6 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
     [context setView: self];
 }
 
--(void)update
-{
-  [[self openGLContext] update];
-}
-
 -(void)drawRect:(NSRect)rect
 {
 }
@@ -144,21 +112,6 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
   return _openGLContext;
 }
 
--(void)dealloc
-{
-  NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
-
-  [center removeObserver:self
-                    name:NSViewGlobalFrameDidChangeNotification
-                  object:self];
-
-  [center removeObserver:self
-                    name:NSViewFrameDidChangeNotification
-                  object:self];
-
-  [super dealloc];
-}
-
 -(BOOL)isOpaque
 {
   return NO;
diff --git a/gdk/macos/GdkMacosGLView.h b/gdk/macos/GdkMacosGLView.h
index 855b345bbc..c30928910e 100644
--- a/gdk/macos/GdkMacosGLView.h
+++ b/gdk/macos/GdkMacosGLView.h
@@ -37,7 +37,6 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 -(id)initWithFrame:(NSRect)frameRect pixelFormat:(NSOpenGLPixelFormat*)format;
 -(void)setOpenGLContext:(NSOpenGLContext*)context;
 -(NSOpenGLContext *)openGLContext;
--(void)update;
 -(void)setPixelFormat:(NSOpenGLPixelFormat*)pixelFormat;
 -(NSOpenGLPixelFormat*)pixelFormat;
 -(void)invalidateRegion:(const cairo_region_t *)region;
diff --git a/gdk/macos/gdkmacosglcontext-private.h b/gdk/macos/gdkmacosglcontext-private.h
index 722e74cde1..e47a3e2eec 100644
--- a/gdk/macos/gdkmacosglcontext-private.h
+++ b/gdk/macos/gdkmacosglcontext-private.h
@@ -45,6 +45,7 @@ struct _GdkMacosGLContext
   NSView *dummy_view;
 
   guint is_attached : 1;
+  guint needs_resize : 1;
 };
 
 struct _GdkMacosGLContextClass
diff --git a/gdk/macos/gdkmacosglcontext.c b/gdk/macos/gdkmacosglcontext.c
index 73dca20fe1..b5ba191751 100644
--- a/gdk/macos/gdkmacosglcontext.c
+++ b/gdk/macos/gdkmacosglcontext.c
@@ -119,10 +119,10 @@ gdk_macos_gl_context_real_realize (GdkGLContext  *context,
       if (!(shared_gl_context = get_ns_open_gl_context (GDK_MACOS_GL_CONTEXT (shared), error)))
         return FALSE;
     }
-  else
+  else if (shared_data != NULL)
     {
-      if (shared_data != NULL)
-        shared_gl_context = get_ns_open_gl_context (GDK_MACOS_GL_CONTEXT (shared_data), NULL);
+      if (!(shared_gl_context = get_ns_open_gl_context (GDK_MACOS_GL_CONTEXT (shared_data), error)))
+        return FALSE;
     }
 
   gl_context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat
@@ -155,7 +155,6 @@ gdk_macos_gl_context_real_realize (GdkGLContext  *context,
       [gl_context setView:self->dummy_view];
     }
 
-  [gl_context update];
   [gl_context makeCurrentContext];
 
   GDK_NOTE (OPENGL,
@@ -174,6 +173,22 @@ gdk_macos_gl_context_begin_frame (GdkDrawContext *context,
 
   g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
 
+
+  if (self->needs_resize)
+    {
+      self->needs_resize = FALSE;
+
+      if (self->dummy_view != NULL)
+        {
+          GdkSurface *surface = gdk_draw_context_get_surface (context);
+          GLint vals[2] = { surface->width, surface->height };
+
+          [self->gl_context setValues:vals forParameter:NSOpenGLContextParameterSurfaceBackingSize];
+        }
+
+      [self->gl_context update];
+    }
+
   GDK_DRAW_CONTEXT_CLASS (gdk_macos_gl_context_parent_class)->begin_frame (context, painted);
 
   if (!self->is_attached)
@@ -222,22 +237,10 @@ static void
 gdk_macos_gl_context_surface_resized (GdkDrawContext *draw_context)
 {
   GdkMacosGLContext *self = (GdkMacosGLContext *)draw_context;
-  GdkSurface *surface;
 
   g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
 
-  if (self->gl_context == nil)
-    return;
-
-  surface = gdk_draw_context_get_surface (draw_context);
-
-  if (self->dummy_view != NULL)
-    {
-      GLint vals[2] = { surface->width, surface->height };
-      [self->gl_context setValues:vals forParameter:NSOpenGLContextParameterSurfaceBackingSize];
-    }
-
-  [self->gl_context update];
+  self->needs_resize = TRUE;
 }
 
 static void


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