Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkMetalViewBridge.mm
Go to the documentation of this file.
1// Copyright 2019 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3
5
16
17#import <Metal/Metal.h>
18#import <MetalKit/MetalKit.h>
19
21 if (!rContext ||
22 MTLPixelFormatDepth32Float_Stencil8 != [mtkView depthStencilPixelFormat] ||
23 MTLPixelFormatBGRA8Unorm != [mtkView colorPixelFormat]) {
24 return nullptr;
25 }
26
27 const SkColorType colorType = kBGRA_8888_SkColorType; // MTLPixelFormatBGRA8Unorm
28 sk_sp<SkColorSpace> colorSpace = nullptr; // MTLPixelFormatBGRA8Unorm
30 const SkSurfaceProps surfaceProps;
31 int sampleCount = (int)[mtkView sampleCount];
32
33 return SkSurfaces::WrapMTKView(rContext,
34 (__bridge GrMTLHandle)mtkView,
35 origin,
36 sampleCount,
38 colorSpace,
39 &surfaceProps);
40}
41
42GrContextHolder SkMetalDeviceToGrContext(id<MTLDevice> device, id<MTLCommandQueue> queue) {
43 GrMtlBackendContext backendContext = {};
44 backendContext.fDevice.reset((__bridge void*)device);
45 backendContext.fQueue.reset((__bridge void*)queue);
46 GrContextOptions grContextOptions; // set different options here.
47 return GrContextHolder(GrDirectContexts::MakeMetal(backendContext, grContextOptions).release());
48}
49
50void SkMtkViewConfigForSkia(MTKView* mtkView) {
51 [mtkView setDepthStencilPixelFormat:MTLPixelFormatDepth32Float_Stencil8];
52 [mtkView setColorPixelFormat:MTLPixelFormatBGRA8Unorm];
53 [mtkView setSampleCount:1];
54}
std::unique_ptr< GrDirectContext, GrContextRelease > GrContextHolder
const void * GrMTLHandle
Definition GrMtlTypes.h:20
GrSurfaceOrigin
Definition GrTypes.h:147
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
SkColorType
Definition SkColorType.h:19
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
void SkMtkViewConfigForSkia(MTKView *mtkView)
sk_sp< SkSurface > SkMtkViewToSurface(MTKView *mtkView, GrRecordingContext *rContext)
GrContextHolder SkMetalDeviceToGrContext(id< MTLDevice > device, id< MTLCommandQueue > queue)
Type::kYUV Type::kRGBA() int(0.7 *637)
VkDevice device
Definition main.cc:53
VkQueue queue
Definition main.cc:55
SK_API sk_sp< GrDirectContext > MakeMetal(const GrMtlBackendContext &, const GrContextOptions &)
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)
sk_cfp< GrMTLHandle > fDevice
sk_cfp< GrMTLHandle > fQueue