Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSurface_GaneshMtl.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
24
25#import <Metal/Metal.h>
26#import <MetalKit/MetalKit.h>
27#import <QuartzCore/CAMetalLayer.h>
28
29namespace SkSurfaces {
30
32 GrMTLHandle layer,
33 GrSurfaceOrigin origin,
34 int sampleCnt,
36 sk_sp<SkColorSpace> colorSpace,
37 const SkSurfaceProps* surfaceProps,
38 GrMTLHandle* drawable) {
39 GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
40
41 CAMetalLayer* metalLayer = (__bridge CAMetalLayer*)layer;
42 GrBackendFormat backendFormat = GrBackendFormats::MakeMtl(metalLayer.pixelFormat);
43
45
46 SkISize dims = {(int)metalLayer.drawableSize.width, (int)metalLayer.drawableSize.height};
47
49 texInfo.fMipmapped = skgpu::Mipmapped::kNo;
51
53 [layer, drawable](GrResourceProvider* resourceProvider,
55 CAMetalLayer* metalLayer = (__bridge CAMetalLayer*)layer;
56 id<CAMetalDrawable> currentDrawable = [metalLayer nextDrawable];
57
58 GrMtlGpu* mtlGpu = (GrMtlGpu*)resourceProvider->priv().gpu();
60 if (metalLayer.framebufferOnly) {
62 mtlGpu, desc.fDimensions, desc.fSampleCnt, currentDrawable.texture);
63 } else {
65 mtlGpu,
66 desc.fDimensions,
67 desc.fSampleCnt,
68 currentDrawable.texture,
70 }
71 if (surface && desc.fSampleCnt > 1) {
72 surface->setRequiresManualMSAAResolve();
73 }
74
75 *drawable = (__bridge_retained GrMTLHandle)currentDrawable;
77 },
78 backendFormat,
79 dims,
80 sampleCnt,
83 metalLayer.framebufferOnly ? nullptr : &texInfo,
87 GrProtected::kNo,
88 false,
90
91 auto device = rContext->priv().createDevice(grColorType,
92 std::move(proxy),
93 std::move(colorSpace),
94 origin,
95 SkSurfacePropsCopyOrDefault(surfaceProps),
97 if (!device) {
98 return nullptr;
99 }
100
101 return sk_make_sp<SkSurface_Ganesh>(std::move(device));
102}
103
105 GrMTLHandle view,
106 GrSurfaceOrigin origin,
107 int sampleCnt,
109 sk_sp<SkColorSpace> colorSpace,
110 const SkSurfaceProps* surfaceProps) {
111 GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
112
113 MTKView* mtkView = (__bridge MTKView*)view;
114 GrBackendFormat backendFormat = GrBackendFormats::MakeMtl(mtkView.colorPixelFormat);
115
117
118 SkISize dims = {(int)mtkView.drawableSize.width, (int)mtkView.drawableSize.height};
119
121 texInfo.fMipmapped = skgpu::Mipmapped::kNo;
123
125 [view](GrResourceProvider* resourceProvider,
127 MTKView* mtkView = (__bridge MTKView*)view;
128 id<CAMetalDrawable> currentDrawable = [mtkView currentDrawable];
129
130 GrMtlGpu* mtlGpu = (GrMtlGpu*)resourceProvider->priv().gpu();
132 if (mtkView.framebufferOnly) {
134 mtlGpu, desc.fDimensions, desc.fSampleCnt, currentDrawable.texture);
135 } else {
137 mtlGpu,
138 desc.fDimensions,
139 desc.fSampleCnt,
140 currentDrawable.texture,
142 }
143 if (surface && desc.fSampleCnt > 1) {
144 surface->setRequiresManualMSAAResolve();
145 }
146
148 },
149 backendFormat,
150 dims,
151 sampleCnt,
154 mtkView.framebufferOnly ? nullptr : &texInfo,
158 GrProtected::kNo,
159 false,
161
162 auto device = rContext->priv().createDevice(grColorType,
163 std::move(proxy),
164 std::move(colorSpace),
165 origin,
166 SkSurfacePropsCopyOrDefault(surfaceProps),
168 if (!device) {
169 return nullptr;
170 }
171
172 return sk_make_sp<SkSurface_Ganesh>(std::move(device));
173}
174
175} // namespace SkSurfaces
const void * GrMTLHandle
Definition GrMtlTypes.h:20
GrColorType
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
GrSurfaceOrigin
Definition GrTypes.h:147
SkColorType
Definition SkColorType.h:19
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static SkSurfaceProps SkSurfacePropsCopyOrDefault(const SkSurfaceProps *props)
Type::kYUV Type::kRGBA() int(0.7 *637)
static sk_sp< GrMtlRenderTarget > MakeWrappedRenderTarget(GrMtlGpu *, SkISize, int sampleCnt, id< MTLTexture >)
static sk_sp< GrMtlTextureRenderTarget > MakeWrappedTextureRenderTarget(GrMtlGpu *, SkISize, int sampleCnt, id< MTLTexture >, GrWrapCacheable)
sk_sp< GrRenderTargetProxy > createLazyRenderTargetProxy(LazyInstantiateCallback &&, const GrBackendFormat &, SkISize dimensions, int renderTargetSampleCnt, GrInternalSurfaceFlags, const TextureInfo *, GrMipmapStatus, SkBackingFit, skgpu::Budgeted, GrProtected, bool wrapsVkSecondaryCB, UseAllocator useAllocator)
GrProxyProvider * proxyProvider()
sk_sp< skgpu::ganesh::Device > createDevice(GrColorType, sk_sp< GrSurfaceProxy >, sk_sp< SkColorSpace >, GrSurfaceOrigin, const SkSurfaceProps &, skgpu::ganesh::Device::InitContents)
GrRecordingContextPriv priv()
GrResourceProviderPriv priv()
VkDevice device
Definition main.cc:53
VkSurfaceKHR surface
Definition main.cc:49
SK_API GrBackendFormat MakeMtl(GrMTLPixelFormat format)
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 > WrapMTKView(GrRecordingContext *context, GrMTLHandle mtkView, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps) SK_API_AVAILABLE(macos(10.11)
constexpr int32_t width() const
Definition SkSize.h:36