11#import <Cocoa/Cocoa.h>
12#import <QuartzCore/CAConstraintLayoutManager.h>
24 ~MetalWindowContext_mac()
override;
38 , fMainView(
info.fMainView) {
42 this->initializeContext();
45MetalWindowContext_mac::~MetalWindowContext_mac() {
46 this->destroyContext();
49bool MetalWindowContext_mac::onInitializeContext() {
52 fMetalLayer = [CAMetalLayer layer];
53 fMetalLayer.device = fDevice.get();
54 fMetalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
59 BOOL useVsync = fDisplayParams.fDisableVsync ? NO : YES;
60 fMetalLayer.displaySyncEnabled = useVsync;
61 fMetalLayer.layoutManager = [CAConstraintLayoutManager layoutManager];
62 fMetalLayer.autoresizingMask = kCALayerHeightSizable | kCALayerWidthSizable;
63 fMetalLayer.contentsGravity = kCAGravityTopLeft;
64 fMetalLayer.magnificationFilter = kCAFilterNearest;
65 NSColorSpace* cs = fMainView.window.colorSpace;
66 fMetalLayer.colorspace = cs.CGColorSpace;
68 fMainView.layer = fMetalLayer;
69 fMainView.wantsLayer = YES;
74void MetalWindowContext_mac::onDestroyContext() {}
76void MetalWindowContext_mac::resize(
int w,
int h) {
78 CGSize backingSize = fMainView.bounds.size;
79 backingSize.width *= backingScaleFactor;
80 backingSize.height *= backingScaleFactor;
82 fMetalLayer.drawableSize = backingSize;
83 fMetalLayer.contentsScale = backingScaleFactor;
85 fWidth = backingSize.width;
86 fHeight = backingSize.height;
95 std::unique_ptr<WindowContext> ctx(
new MetalWindowContext_mac(
info,
params));
96 if (!ctx->isValid()) {
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
virtual void resize(int w, int h)=0
virtual bool onInitializeContext()=0
virtual void onDestroyContext()=0
const EmbeddedViewParams * params
std::unique_ptr< WindowContext > MakeMetalForMac(const MacWindowInfo &info, const DisplayParams ¶ms)
static CGFloat GetBackingScaleFactor(NSView *view)