11#import <Cocoa/Cocoa.h>
12#import <QuartzCore/CAConstraintLayoutManager.h>
13#import <QuartzCore/CAMetalLayer.h>
25 ~GraphiteDawnMetalWindowContext_mac()
override;
32 bool resizeInternal();
35 CAMetalLayer* fMetalLayer;
38GraphiteDawnMetalWindowContext_mac::GraphiteDawnMetalWindowContext_mac(
const MacWindowInfo&
info,
41 , fMainView(
info.fMainView) {
44 CGSize backingSize = fMainView.bounds.size;
45 this->initializeContext(backingSize.width * backingScaleFactor,
46 backingSize.height * backingScaleFactor);
49GraphiteDawnMetalWindowContext_mac::~GraphiteDawnMetalWindowContext_mac() {
50 this->destroyContext();
53bool GraphiteDawnMetalWindowContext_mac::onInitializeContext() {
56 auto device = createDevice(wgpu::BackendType::Metal);
64 fMetalLayer = [CAMetalLayer layer];
65 BOOL useVsync = fDisplayParams.fDisableVsync ? NO : YES;
66 fMetalLayer.displaySyncEnabled = useVsync;
67 fMainView.wantsLayer = YES;
68 fMainView.layer = fMetalLayer;
71 this->resizeInternal();
73 wgpu::SurfaceDescriptorFromMetalLayer surfaceChainedDesc;
74 surfaceChainedDesc.layer = fMetalLayer;
75 wgpu::SurfaceDescriptor surfaceDesc;
76 surfaceDesc.nextInChain = &surfaceChainedDesc;
78 auto surface = wgpu::Instance(fInstance->Get()).CreateSurface(&surfaceDesc);
85 fDevice = std::move(
device);
87 fSwapChain = this->createSwapChain();
92void GraphiteDawnMetalWindowContext_mac::onDestroyContext() {}
94void GraphiteDawnMetalWindowContext_mac::resize(
int w,
int h) {
95 if (!this->resizeInternal()) {
98 fSwapChain = this->createSwapChain();
101bool GraphiteDawnMetalWindowContext_mac::resizeInternal() {
103 CGSize backingSize = fMainView.bounds.size;
104 backingSize.width *= backingScaleFactor;
105 backingSize.height *= backingScaleFactor;
107 fMetalLayer.drawableSize = backingSize;
108 fMetalLayer.contentsScale = backingScaleFactor;
110 if (fWidth == backingSize.width && fHeight == backingSize.height) {
114 fWidth = backingSize.width;
115 fHeight = backingSize.height;
125 std::unique_ptr<WindowContext> ctx(
new GraphiteDawnMetalWindowContext_mac(
info,
params));
126 if (!ctx->isValid()) {
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
virtual void resize(int w, int h)=0
virtual void onDestroyContext()=0
virtual bool onInitializeContext()=0
const EmbeddedViewParams * params
std::unique_ptr< WindowContext > MakeGraphiteDawnMetalForMac(const MacWindowInfo &info, const DisplayParams ¶ms)
static CGFloat GetBackingScaleFactor(NSView *view)