~eliasnaur/gio

2a18a0c1355392bb8b4974a38a61f3e565069012 — Elias Naur 5 months ago 93ac0b0
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 <mail@eliasnaur.com>
3 files changed, 11 insertions(+), 3 deletions(-)

M app/metal_darwin.go
M app/metal_ios.go
M app/metal_macos.go
M app/metal_darwin.go => app/metal_darwin.go +2 -1
@@ 60,8 60,9 @@ static void presentDrawable(CFTypeRef queueRef, CFTypeRef drawableRef) {
		id<MTLDrawable> drawable = (__bridge id<MTLDrawable>)drawableRef;
		id<MTLCommandQueue> queue = (__bridge id<MTLCommandQueue>)queueRef;
		id<MTLCommandBuffer> cmdBuffer = [queue commandBuffer];
		[cmdBuffer presentDrawable:drawable];
		[cmdBuffer commit];
		[cmdBuffer waitUntilScheduled];
		[drawable present];
	}
}


M app/metal_ios.go => app/metal_ios.go +4 -1
@@ 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);
	}
}


M app/metal_macos.go => app/metal_macos.go +5 -1
@@ 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;
	}
}