[gtk/gtk-3-24: 1/2] macOS: Big Sur performance patch




commit 10b5f8a0d6ab76b1d3c7130b22e34362fc28aafc
Author: Lukas Oberhuber <lukaso gmail com>
Date:   Sat Dec 18 22:59:58 2021 +0000

    macOS: Big Sur performance patch
    
    One of 4 that were applied on Gimp 2.99. Original authorship
    @DesMcGuiness and adapted to Gtk3 by @lukaso

 gdk/quartz/GdkQuartzView.c    | 18 +++++++++++++++++-
 gdk/quartz/gdkwindow-quartz.c | 22 +++++++++++++++++++---
 2 files changed, 36 insertions(+), 4 deletions(-)
---
diff --git a/gdk/quartz/GdkQuartzView.c b/gdk/quartz/GdkQuartzView.c
index 3dc7339b06..d3eca93207 100644
--- a/gdk/quartz/GdkQuartzView.c
+++ b/gdk/quartz/GdkQuartzView.c
@@ -289,6 +289,22 @@
     gdk_screen_get_rgba_visual (_gdk_screen);
 }
 
+- (void) viewWillDraw
+{
+  /* MacOS 11 (Big Sur) has added a new, dynamic "accent" as default.
+   * This uses a 10-bit colorspace so every GIMP drawing operation
+   * has the additional cost of an 8-bit (ARGB) to 10-bit conversion.
+   * Let's disable this mode to regain the lost performance.
+   */
+  if(gdk_quartz_osx_version() >= GDK_OSX_BIGSUR)
+  {
+    CALayer* layer = self.layer;
+    layer.contentsFormat = kCAContentsFormatRGBA8Uint;
+  }
+
+  [super viewWillDraw];
+}
+
 -(void)drawRect: (NSRect)rect
 {
   GdkRectangle gdk_rect;
@@ -416,7 +432,7 @@
 {
   if (GDK_WINDOW_DESTROYED (gdk_window))
     return;
-  
+
   [super setFrame: frame];
 
   if ([self window])
diff --git a/gdk/quartz/gdkwindow-quartz.c b/gdk/quartz/gdkwindow-quartz.c
index 30e62a7574..aa85318e0b 100644
--- a/gdk/quartz/gdkwindow-quartz.c
+++ b/gdk/quartz/gdkwindow-quartz.c
@@ -162,8 +162,16 @@ gdk_window_impl_quartz_get_context (GdkWindowImplQuartz *window_impl,
    */
   if (window_impl->in_paint_rect_count == 0)
     {
-      if (![window_impl->view lockFocusIfCanDraw])
-        return NULL;
+      /* The NSView focus-locking API set was deprecated in MacOS 10.14 and
+       * has a significant cost in MacOS 11 - every lock/unlock seems to 
+       * trigger a drawRect: call for the entire window.  To return the
+       * lost performance, do not use the locking API in MacOS 11+
+       */
+      if(gdk_quartz_osx_version() < GDK_OSX_BIGSUR)
+        {
+          if (![window_impl->view lockFocusIfCanDraw])
+            return NULL;
+        }
     }
 #if MAC_OS_X_VERSION_MAX_ALLOWED < 101000
     cg_context = [[NSGraphicsContext currentContext] graphicsPort];
@@ -201,7 +209,15 @@ gdk_window_impl_quartz_release_context (GdkWindowImplQuartz *window_impl,
   if (window_impl->in_paint_rect_count == 0)
     {
       _gdk_quartz_window_flush (window_impl);
-      [window_impl->view unlockFocus];
+
+      /* As per gdk_window_impl_quartz_get_context(), the NSView
+        * focus-locking API set was deprecated in MacOS 10.14 and has
+        * a significant cost in MacOS 11 - every lock/unlock seems to 
+        * trigger a drawRect: call for the entire window.  To return the
+        * lost performance, do not use the locking API in MacOS 11+
+        */
+      if(gdk_quartz_osx_version() < GDK_OSX_BIGSUR)
+        [window_impl->view unlockFocus];
     }
 }
 


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