From 2a18a0c1355392bb8b4974a38a61f3e565069012 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Tue, 19 Dec 2023 17:24:56 -0600 Subject: [PATCH] app: [macOS] synchronize rendering with Core Animation for smooth resizes Magic incantations lifted from https://thume.ca/2019/06/19/glitchless-metal-window-resizing/ Signed-off-by: Elias Naur --- app/metal_darwin.go | 3 ++- app/metal_ios.go | 5 ++++- app/metal_macos.go | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/metal_darwin.go b/app/metal_darwin.go index e93b0251..0043ffb3 100644 --- a/app/metal_darwin.go +++ b/app/metal_darwin.go @@ -60,8 +60,9 @@ static void presentDrawable(CFTypeRef queueRef, CFTypeRef drawableRef) { id drawable = (__bridge id)drawableRef; id queue = (__bridge id)queueRef; id cmdBuffer = [queue commandBuffer]; - [cmdBuffer presentDrawable:drawable]; [cmdBuffer commit]; + [cmdBuffer waitUntilScheduled]; + [drawable present]; } } diff --git a/app/metal_ios.go b/app/metal_ios.go index 860ba1aa..d5b5dc41 100644 --- a/app/metal_ios.go +++ b/app/metal_ios.go @@ -21,7 +21,10 @@ Class gio_layerClass(void) { static CFTypeRef getMetalLayer(CFTypeRef viewRef) { @autoreleasepool { UIView *view = (__bridge UIView *)viewRef; - return CFBridgingRetain(view.layer); + CAMetalLayer *l = (CAMetalLayer *)view.layer; + l.needsDisplayOnBoundsChange = YES; + l.presentsWithTransaction = YES; + return CFBridgingRetain(l); } } diff --git a/app/metal_macos.go b/app/metal_macos.go index 8b602ee3..4fe7586c 100644 --- a/app/metal_macos.go +++ b/app/metal_macos.go @@ -14,7 +14,11 @@ package app CALayer *gio_layerFactory(void) { @autoreleasepool { - return [CAMetalLayer layer]; + CAMetalLayer *l = [CAMetalLayer layer]; + l.autoresizingMask = kCALayerHeightSizable|kCALayerWidthSizable; + l.needsDisplayOnBoundsChange = YES; + l.presentsWithTransaction = YES; + return l; } }