github.com/Seikaijyu/gio@v0.0.1/app/metal_macos.go (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 //go:build darwin && !ios && !nometal 4 // +build darwin,!ios,!nometal 5 6 package app 7 8 /* 9 #cgo CFLAGS: -Werror -xobjective-c -fobjc-arc 10 11 #import <AppKit/AppKit.h> 12 #import <QuartzCore/CAMetalLayer.h> 13 #include <CoreFoundation/CoreFoundation.h> 14 15 CALayer *gio_layerFactory(void) { 16 @autoreleasepool { 17 return [CAMetalLayer layer]; 18 } 19 } 20 21 static CFTypeRef getMetalLayer(CFTypeRef viewRef) { 22 @autoreleasepool { 23 NSView *view = (__bridge NSView *)viewRef; 24 return CFBridgingRetain(view.layer); 25 } 26 } 27 28 static void resizeDrawable(CFTypeRef viewRef, CFTypeRef layerRef) { 29 @autoreleasepool { 30 NSView *view = (__bridge NSView *)viewRef; 31 CAMetalLayer *layer = (__bridge CAMetalLayer *)layerRef; 32 CGSize size = layer.bounds.size; 33 size.width *= layer.contentsScale; 34 size.height *= layer.contentsScale; 35 layer.drawableSize = size; 36 } 37 } 38 */ 39 import "C" 40 41 func getMetalLayer(view C.CFTypeRef) C.CFTypeRef { 42 return C.getMetalLayer(view) 43 } 44 45 func resizeDrawable(view, layer C.CFTypeRef) { 46 C.resizeDrawable(view, layer) 47 }