macOS: Big Sur performance patch

One of 4 that were applied on Gimp 2.99. Original authorship
@DesMcGuiness and adapted to Gtk3 by @lukaso
This commit is contained in:
Lukas Oberhuber 2021-12-18 22:59:58 +00:00
parent c3b3f4711d
commit 10b5f8a0d6
2 changed files with 36 additions and 4 deletions

View File

@ -289,6 +289,22 @@
gdk_screen_get_rgba_visual (_gdk_screen); 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 -(void)drawRect: (NSRect)rect
{ {
GdkRectangle gdk_rect; GdkRectangle gdk_rect;
@ -416,7 +432,7 @@
{ {
if (GDK_WINDOW_DESTROYED (gdk_window)) if (GDK_WINDOW_DESTROYED (gdk_window))
return; return;
[super setFrame: frame]; [super setFrame: frame];
if ([self window]) if ([self window])

View File

@ -162,8 +162,16 @@ gdk_window_impl_quartz_get_context (GdkWindowImplQuartz *window_impl,
*/ */
if (window_impl->in_paint_rect_count == 0) if (window_impl->in_paint_rect_count == 0)
{ {
if (![window_impl->view lockFocusIfCanDraw]) /* The NSView focus-locking API set was deprecated in MacOS 10.14 and
return NULL; * 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 #if MAC_OS_X_VERSION_MAX_ALLOWED < 101000
cg_context = [[NSGraphicsContext currentContext] graphicsPort]; 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) if (window_impl->in_paint_rect_count == 0)
{ {
_gdk_quartz_window_flush (window_impl); _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];
} }
} }