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