github.com/utopiagio/gio@v0.0.8/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  		CAMetalLayer *l = (CAMetalLayer *)view.layer;
    25  		l.needsDisplayOnBoundsChange = YES;
    26  		l.presentsWithTransaction = YES;
    27  		return CFBridgingRetain(l);
    28  	}
    29  }
    30  
    31  static void resizeDrawable(CFTypeRef viewRef, CFTypeRef layerRef) {
    32  	@autoreleasepool {
    33  		UIView *view = (__bridge UIView *)viewRef;
    34  		CAMetalLayer *layer = (__bridge CAMetalLayer *)layerRef;
    35  		layer.contentsScale = view.contentScaleFactor;
    36  		CGSize size = layer.bounds.size;
    37  		size.width *= layer.contentsScale;
    38  		size.height *= layer.contentsScale;
    39  		layer.drawableSize = size;
    40  	}
    41  }
    42  */
    43  import "C"
    44  
    45  func getMetalLayer(view C.CFTypeRef) C.CFTypeRef {
    46  	return C.getMetalLayer(view)
    47  }
    48  
    49  func resizeDrawable(view, layer C.CFTypeRef) {
    50  	C.resizeDrawable(view, layer)
    51  }