Flutter Engine
The Flutter Engine
MetalWindowContext.mm
Go to the documentation of this file.
1/*
2 * Copyright 2019 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
20#include "src/base/SkMathPriv.h"
24
27
28namespace skwindow::internal {
29
32 , fValid(false)
33 , fDrawableHandle(nil) {
35}
36
39
40 fDevice.reset(MTLCreateSystemDefaultDevice());
41 fQueue.reset([*fDevice newCommandQueue]);
42
44 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
45 if (![*fDevice supportsTextureSampleCount:fDisplayParams.fMSAASampleCount]) {
46 return;
47 }
48 } else {
49 return;
50 }
51 }
53 fStencilBits = 8;
54
56
57 GrMtlBackendContext backendContext = {};
58 backendContext.fDevice.retain((GrMTLHandle)fDevice.get());
59 backendContext.fQueue.retain((GrMTLHandle)fQueue.get());
63 this->initializeContext();
64 return;
65 }
66}
67
69 if (fContext) {
70 // in case we have outstanding refs to this (lua?)
73 }
74
75 this->onDestroyContext();
76
77 fMetalLayer = nil;
78 fValid = false;
79
80 fQueue.reset();
81 fDevice.reset();
82}
83
86 if (fContext) {
89 (__bridge GrMTLHandle)fMetalLayer,
96 } else {
97 id<CAMetalDrawable> currentDrawable = [fMetalLayer nextDrawable];
98 if (currentDrawable == nil) {
99 return nullptr;
100 }
101
102 GrMtlTextureInfo fbInfo;
103 fbInfo.fTexture.retain(currentDrawable.texture);
104
105 GrBackendRenderTarget backendRT =
107
109 backendRT,
114
115 fDrawableHandle = CFRetain((GrMTLHandle) currentDrawable);
116 }
117 }
118
119 return surface;
120}
121
123 id<CAMetalDrawable> currentDrawable = (id<CAMetalDrawable>)fDrawableHandle;
124
125 id<MTLCommandBuffer> commandBuffer([*fQueue commandBuffer]);
126 commandBuffer.label = @"Present";
127
128 [commandBuffer presentDrawable:currentDrawable];
129 [commandBuffer commit];
130 // ARC is off in sk_app, so we need to release the CF ref manually
131 CFRelease(fDrawableHandle);
132 fDrawableHandle = nil;
133}
134
136 this->destroyContext();
138 this->initializeContext();
139}
140
141} //namespace skwindow::internal
const void * GrMTLHandle
Definition: GrMtlTypes.h:20
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
static uint32_t GrNextPow2(uint32_t n)
Definition: SkMathPriv.h:302
void abandonContext() override
T * get() const
Definition: SkRefCnt.h:303
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
sk_sp< GrDirectContext > fContext
Definition: WindowContext.h:63
DisplayParams fDisplayParams
Definition: WindowContext.h:71
void setDisplayParams(const DisplayParams &params) override
sk_cfp< id< MTLCommandQueue > > fQueue
sk_sp< SkSurface > getBackbufferSurface() override
const EmbeddedViewParams * params
VkSurfaceKHR surface
Definition: main.cc:49
SK_API GrBackendRenderTarget MakeMtl(int width, int height, const GrMtlTextureInfo &mtlInfo)
SK_API sk_sp< GrDirectContext > MakeMetal(const GrMtlBackendContext &, const GrContextOptions &)
SK_API sk_sp< SkSurface > WrapCAMetalLayer(GrRecordingContext *context, GrMTLHandle layer, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, GrMTLHandle *drawable) SK_API_AVAILABLE_CA_METAL_LAYER
SK_API sk_sp< SkSurface > WrapBackendRenderTarget(GrRecordingContext *context, const GrBackendRenderTarget &backendRenderTarget, GrSurfaceOrigin origin, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, RenderTargetReleaseProc releaseProc=nullptr, ReleaseContext releaseContext=nullptr)
sk_cfp< GrMTLHandle > fDevice
sk_cfp< GrMTLHandle > fQueue
SkSurfaceProps fSurfaceProps
Definition: DisplayParams.h:68
GrContextOptions fGrContextOptions
Definition: DisplayParams.h:61
sk_sp< SkColorSpace > fColorSpace
Definition: DisplayParams.h:59