| 1 |
// Copyright 2019 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
// +build darwin |
| 6 |
|
| 7 |
#import <QuartzCore/QuartzCore.h> |
| 8 |
#include "coreanim.h" |
| 9 |
|
| 10 |
void * MakeMetalLayer() { |
| 11 |
return [[CAMetalLayer alloc] init]; |
| 12 |
} |
| 13 |
|
| 14 |
uint16_t MetalLayer_PixelFormat(void * metalLayer) { |
| 15 |
return ((CAMetalLayer *)metalLayer).pixelFormat; |
| 16 |
} |
| 17 |
|
| 18 |
void MetalLayer_SetDevice(void * metalLayer, void * device) { |
| 19 |
((CAMetalLayer *)metalLayer).device = (id<MTLDevice>)device; |
| 20 |
} |
| 21 |
|
| 22 |
const char * MetalLayer_SetPixelFormat(void * metalLayer, uint16_t pixelFormat) { |
| 23 |
@try { |
| 24 |
((CAMetalLayer *)metalLayer).pixelFormat = (MTLPixelFormat)pixelFormat; |
| 25 |
} |
| 26 |
@catch (NSException * exception) { |
| 27 |
return exception.reason.UTF8String; |
| 28 |
} |
| 29 |
return NULL; |
| 30 |
} |
| 31 |
|
| 32 |
const char * MetalLayer_SetMaximumDrawableCount(void * metalLayer, uint_t maximumDrawableCount) { |
| 33 |
if (@available(macOS 10.13.2, *)) { |
| 34 |
@try { |
| 35 |
((CAMetalLayer *)metalLayer).maximumDrawableCount = (NSUInteger)maximumDrawableCount; |
| 36 |
} |
| 37 |
@catch (NSException * exception) { |
| 38 |
return exception.reason.UTF8String; |
| 39 |
} |
| 40 |
} |
| 41 |
return NULL; |
| 42 |
} |
| 43 |
|
| 44 |
void MetalLayer_SetDisplaySyncEnabled(void * metalLayer, bool displaySyncEnabled) { |
| 45 |
((CAMetalLayer *)metalLayer).displaySyncEnabled = displaySyncEnabled; |
| 46 |
} |
| 47 |
|
| 48 |
void MetalLayer_SetDrawableSize(void * metalLayer, double width, double height) { |
| 49 |
((CAMetalLayer *)metalLayer).drawableSize = (CGSize){width, height}; |
| 50 |
} |
| 51 |
|
| 52 |
void * MetalLayer_NextDrawable(void * metalLayer) { |
| 53 |
return [(CAMetalLayer *)metalLayer nextDrawable]; |
| 54 |
} |
| 55 |
|
| 56 |
void * MetalDrawable_Texture(void * metalDrawable) { |
| 57 |
return ((id<CAMetalDrawable>)metalDrawable).texture; |
| 58 |
} |