Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GraphiteMetalWindowContext.mm
Go to the documentation of this file.
1/*
2 * Copyright 2021 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
19#include "src/base/SkMathPriv.h"
20#include "tools/GpuToolUtils.h"
22
25
26namespace skwindow::internal {
27
34
37 SkASSERT(!fGraphiteContext);
38
39 fDevice.reset(MTLCreateSystemDefaultDevice());
40 fQueue.reset([*fDevice newCommandQueue]);
41
43 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
44 if (![*fDevice supportsTextureSampleCount:fDisplayParams.fMSAASampleCount]) {
45 return;
46 }
47 } else {
48 return;
49 }
50 }
52 fStencilBits = 8;
53
55
56 skgpu::graphite::MtlBackendContext backendContext = {};
57 backendContext.fDevice.retain((CFTypeRef)fDevice.get());
58 backendContext.fQueue.retain((CFTypeRef)fQueue.get());
59
60 fDisplayParams.fGraphiteContextOptions.fOptions.fDisableCachedGlyphUploads = true;
61 // Needed to make synchronous readPixels work:
62 fDisplayParams.fGraphiteContextOptions.fPriv.fStoreContextRefInRecorder = true;
64 backendContext, fDisplayParams.fGraphiteContextOptions.fOptions);
65 fGraphiteRecorder = fGraphiteContext->makeRecorder(ToolUtils::CreateTestingRecorderOptions());
66 // TODO
67// if (!fGraphiteContext && fDisplayParams.fMSAASampleCount > 1) {
68// fDisplayParams.fMSAASampleCount /= 2;
69// this->initializeContext();
70// return;
71// }
72}
73
75 if (fGraphiteContext) {
76 fGraphiteRecorder.reset();
77 fGraphiteContext.reset();
78 }
79
80 this->onDestroyContext();
81
82 fMetalLayer = nil;
83 fValid = false;
84
85 fQueue.reset();
86 fDevice.reset();
87}
88
91 id<CAMetalDrawable> currentDrawable = [fMetalLayer nextDrawable];
92 if (currentDrawable == nil) {
93 return nullptr;
94 }
95
97 (CFTypeRef)currentDrawable.texture);
98
99 surface = SkSurfaces::WrapBackendTexture(this->graphiteRecorder(),
100 backendTex,
104 fDrawableHandle = CFRetain((CFTypeRef) currentDrawable);
105
106 return surface;
107}
108
110 if (fGraphiteContext) {
111 SkASSERT(fGraphiteRecorder);
112 std::unique_ptr<skgpu::graphite::Recording> recording = fGraphiteRecorder->snap();
113 if (recording) {
115 info.fRecording = recording.get();
116 fGraphiteContext->insertRecording(info);
117 fGraphiteContext->submit(skgpu::graphite::SyncToCpu::kNo);
118 }
119 }
120
121 id<CAMetalDrawable> currentDrawable = (id<CAMetalDrawable>)fDrawableHandle;
122
123 id<MTLCommandBuffer> commandBuffer([*fQueue commandBuffer]);
124 commandBuffer.label = @"Present";
125
126 [commandBuffer presentDrawable:currentDrawable];
127 [commandBuffer commit];
128 // ARC is off in sk_app, so we need to release the CF ref manually
129 CFRelease(fDrawableHandle);
130 fDrawableHandle = nil;
131}
132
138
140
141} //namespace skwindow::internal
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#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
sk_sp< GrDirectContext > fContext
DisplayParams fDisplayParams
SkISize dimensions() const
void setDisplayParams(const DisplayParams &params) override
const EmbeddedViewParams * params
VkSurfaceKHR surface
Definition main.cc:49
SK_API sk_sp< SkSurface > WrapBackendTexture(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
SK_API std::unique_ptr< Context > MakeMetal(const MtlBackendContext &, const ContextOptions &)
SkSurfaceProps fSurfaceProps
sk_sp< SkColorSpace > fColorSpace