gioui.org@v0.6.1-0.20240506124620-7a9ce51988ce/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  		CAMetalLayer *l = [CAMetalLayer layer];
    18  		l.autoresizingMask = kCALayerHeightSizable|kCALayerWidthSizable;
    19  		l.needsDisplayOnBoundsChange = YES;
    20  		l.presentsWithTransaction = YES;
    21  		return l;
    22  	}
    23  }
    24  
    25  static CFTypeRef getMetalLayer(CFTypeRef viewRef) {
    26  	@autoreleasepool {
    27  		NSView *view = (__bridge NSView *)viewRef;
    28  		return CFBridgingRetain(view.layer);
    29  	}
    30  }
    31  
    32  static void resizeDrawable(CFTypeRef viewRef, CFTypeRef layerRef) {
    33  	@autoreleasepool {
    34  		NSView *view = (__bridge NSView *)viewRef;
    35  		CAMetalLayer *layer = (__bridge CAMetalLayer *)layerRef;
    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  }