11#import <Cocoa/Cocoa.h>
12#import <QuartzCore/CAConstraintLayoutManager.h>
24 ~GraphiteMetalWindowContext_mac()
override;
35GraphiteMetalWindowContext_mac::GraphiteMetalWindowContext_mac(
const MacWindowInfo&
info,
38 , fMainView(
info.fMainView) {
42 this->initializeContext();
45GraphiteMetalWindowContext_mac::~GraphiteMetalWindowContext_mac() {
46 this->destroyContext();
49bool GraphiteMetalWindowContext_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 fMetalLayer.framebufferOnly =
false;
66 NSColorSpace* cs = fMainView.window.colorSpace;
67 fMetalLayer.colorspace = cs.CGColorSpace;
69 fMainView.layer = fMetalLayer;
70 fMainView.wantsLayer = YES;
75void GraphiteMetalWindowContext_mac::onDestroyContext() {}
77void GraphiteMetalWindowContext_mac::resize(
int w,
int h) {
79 CGSize backingSize = fMainView.bounds.size;
80 backingSize.width *= backingScaleFactor;
81 backingSize.height *= backingScaleFactor;
83 fMetalLayer.drawableSize = backingSize;
84 fMetalLayer.contentsScale = backingScaleFactor;
86 fWidth = backingSize.width;
87 fHeight = backingSize.height;
96 std::unique_ptr<WindowContext> ctx(
new GraphiteMetalWindowContext_mac(
info,
params));
97 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
static CGFloat GetBackingScaleFactor(NSView *view)
std::unique_ptr< WindowContext > MakeGraphiteMetalForMac(const MacWindowInfo &info, const DisplayParams ¶ms)