Flutter Engine
The Flutter Engine
GrVkSecondaryCBDrawContext.cpp
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
26
28 const SkImageInfo& imageInfo,
29 const GrVkDrawableInfo& vkInfo,
30 const SkSurfaceProps* props) {
31 if (!rContext) {
32 return nullptr;
33 }
34
35 if (rContext->backend() != GrBackendApi::kVulkan) {
36 return nullptr;
37 }
38
39
40 GrProxyProvider* gpp = rContext->priv().proxyProvider();
41 if (gpp->isAbandoned()) {
42 return nullptr;
43 }
44
45 GrResourceProvider* resourceProvider = gpp->resourceProvider();
46 if (!resourceProvider) {
47 return nullptr;
48 }
49
50 sk_sp<GrRenderTarget> rt = resourceProvider->wrapVulkanSecondaryCBAsRenderTarget(imageInfo,
51 vkInfo);
52 if (!rt) {
53 return nullptr;
54 }
55
56 SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable
57 SkASSERT(!rt->getUniqueKey().isValid());
58 // This proxy should be unbudgeted because we're just wrapping an external resource
59 SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType());
60
62
64 colorType, GrBackendFormats::MakeVk(vkInfo.fFormat), /*sampleCount=*/1)) {
65 return nullptr;
66 }
67
69 new GrRenderTargetProxy(std::move(rt),
72
73 if (!proxy) {
74 return nullptr;
75 }
76
77 SkASSERT(proxy->isInstantiated());
78
79 auto device = rContext->priv().createDevice(SkColorTypeToGrColorType(imageInfo.colorType()),
80 std::move(proxy),
81 imageInfo.refColorSpace(),
85 if (!device) {
86 return nullptr;
87 }
88
90 props));
91}
92
93GrVkSecondaryCBDrawContext::GrVkSecondaryCBDrawContext(sk_sp<skgpu::ganesh::Device> device,
94 const SkSurfaceProps* props)
95 : fDevice(std::move(device)), fProps(SkSurfacePropsCopyOrDefault(props)) {}
96
98 SkASSERT(!fDevice);
99 SkASSERT(!fCachedCanvas.get());
100}
101
103 if (!fCachedCanvas) {
104 fCachedCanvas = std::make_unique<SkCanvas>(fDevice);
105 }
106 return fCachedCanvas.get();
107}
108
110 auto dContext = GrAsDirectContext(fDevice->recordingContext());
111
112 if (dContext) {
113 dContext->priv().flushSurface(fDevice->targetProxy());
114 dContext->submit();
115 }
116}
117
118bool GrVkSecondaryCBDrawContext::wait(int numSemaphores,
119 const GrBackendSemaphore waitSemaphores[],
120 bool deleteSemaphoresAfterWait) {
121 return fDevice->wait(numSemaphores, waitSemaphores, deleteSemaphoresAfterWait);
122}
123
125 fCachedCanvas.reset();
126 fDevice.reset();
127}
128
130 auto direct = fDevice->recordingContext()->asDirectContext();
131 if (!direct) {
132 return false;
133 }
134
135 SkImageInfo ii = fDevice->imageInfo();
136 if (ii.colorType() == kUnknown_SkColorType) {
137 return false;
138 }
139
140 GrSurfaceProxyView readSurfaceView = fDevice->readSurfaceView();
141 size_t maxResourceBytes = direct->getResourceCacheLimit();
142
143 // We current don't support textured GrVkSecondaryCBDrawContexts.
144 SkASSERT(!readSurfaceView.asTextureProxy());
145
147 int numSamples = readSurfaceView.asRenderTargetProxy()->numSamples();
148 GrProtected isProtected = readSurfaceView.asRenderTargetProxy()->isProtected();
149
150 characterization->set(direct->threadSafeProxy(),
151 maxResourceBytes,
152 ii,
153 format,
154 readSurfaceView.origin(),
155 numSamples,
161 isProtected,
162 this->props());
163
164 return true;
165}
166
168 const GrSurfaceCharacterization& characterization) const {
169
170 auto dContext = fDevice->recordingContext()->asDirectContext();
171 if (!dContext) {
172 return false;
173 }
174
175 if (!characterization.isValid()) {
176 return false;
177 }
178
179 if (!characterization.vulkanSecondaryCBCompatible()) {
180 return false;
181 }
182
183 if (characterization.isTextureable()) {
184 // We don't support textureable DDL when rendering to a GrVkSecondaryCBDrawContext.
185 return false;
186 }
187
188 if (characterization.usesGLFBO0()) {
189 return false;
190 }
191
192 SkImageInfo ii = fDevice->imageInfo();
193 if (ii.colorType() == kUnknown_SkColorType) {
194 return false;
195 }
196
197 GrSurfaceProxyView readSurfaceView = fDevice->readSurfaceView();
198 // As long as the current state in the context allows for greater or equal resources,
199 // we allow the DDL to be replayed.
200 // DDL TODO: should we just remove the resource check and ignore the cache limits on playback?
201 size_t maxResourceBytes = dContext->getResourceCacheLimit();
202
204 int numSamples = readSurfaceView.asRenderTargetProxy()->numSamples();
205 GrProtected isProtected = readSurfaceView.asRenderTargetProxy()->isProtected();
206
207 return characterization.contextInfo() &&
208 characterization.contextInfo()->priv().matches(dContext) &&
209 characterization.cacheMaxResourceBytes() <= maxResourceBytes &&
210 characterization.origin() == readSurfaceView.origin() &&
211 characterization.backendFormat() == format &&
212 characterization.width() == ii.width() &&
213 characterization.height() == ii.height() &&
214 characterization.colorType() == ii.colorType() &&
215 characterization.sampleCount() == numSamples &&
216 SkColorSpace::Equals(characterization.colorSpace(), ii.colorInfo().colorSpace()) &&
217 characterization.isProtected() == isProtected &&
218 characterization.surfaceProps() == fDevice->surfaceProps();
219}
220
221#ifndef SK_DDL_IS_UNIQUE_POINTER
223#else
225#endif
226 if (!ddl || !this->isCompatible(ddl->characterization())) {
227 return false;
228 }
229
230 auto direct = fDevice->recordingContext()->asDirectContext();
231 if (!direct) {
232 return false;
233 }
234
235 GrSurfaceProxyView readSurfaceView = fDevice->readSurfaceView();
236
237 direct->priv().createDDLTask(std::move(ddl), readSurfaceView.asRenderTargetProxyRef());
238 return true;
239}
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
GrColorType
Definition: GrTypesPriv.h:540
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
Definition: GrTypesPriv.h:629
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kUnknown_SkColorType
uninitialized
Definition: SkColorType.h:20
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static SkSurfaceProps SkSurfacePropsCopyOrDefault(const SkSurfaceProps *props)
Definition: SkSurfacePriv.h:15
virtual bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat &format, int sampleCount=1) const =0
bool matches(GrContext_Base *candidate) const
GrContextThreadSafeProxyPriv priv()
virtual GrDirectContext * asDirectContext()
SK_API GrBackendApi backend() const
SK_API const GrSurfaceCharacterization & characterization() const
GrResourceProvider * resourceProvider() const
bool isAbandoned() const
const GrCaps * caps() const
GrProxyProvider * proxyProvider()
sk_sp< skgpu::ganesh::Device > createDevice(GrColorType, sk_sp< GrSurfaceProxy >, sk_sp< SkColorSpace >, GrSurfaceOrigin, const SkSurfaceProps &, skgpu::ganesh::Device::InitContents)
GrRecordingContextPriv priv()
sk_sp< GrRenderTarget > wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo &, const GrVkDrawableInfo &)
GrContextThreadSafeProxy * contextInfo() const
GrTextureProxy * asTextureProxy() const
GrSurfaceOrigin origin() const
GrRenderTargetProxy * asRenderTargetProxy() const
sk_sp< GrRenderTargetProxy > asRenderTargetProxyRef() const
GrProtected isProtected() const
const GrBackendFormat & backendFormat() const
bool isInstantiated() const
bool draw(sk_sp< const GrDeferredDisplayList > deferredDisplayList)
bool isCompatible(const GrSurfaceCharacterization &characterization) const
static sk_sp< GrVkSecondaryCBDrawContext > Make(GrRecordingContext *, const SkImageInfo &, const GrVkDrawableInfo &, const SkSurfaceProps *props)
const SkSurfaceProps & props() const
bool wait(int numSemaphores, const GrBackendSemaphore waitSemaphores[], bool deleteSemaphoresAfterWait=true)
bool characterize(GrSurfaceCharacterization *characterization) const
SkColorSpace * colorSpace() const
Definition: SkImageInfo.cpp:66
static bool Equals(const SkColorSpace *, const SkColorSpace *)
const SkImageInfo & imageInfo() const
Definition: SkDevice.h:117
const SkSurfaceProps & surfaceProps() const
Definition: SkDevice.h:131
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
GrSurfaceProxyView readSurfaceView()
Definition: Device.cpp:1283
GrRenderTargetProxy * targetProxy()
Definition: Device.cpp:1287
bool wait(int numSemaphores, const GrBackendSemaphore *waitSemaphores, bool deleteSemaphoresAfterWait)
Definition: Device.cpp:1291
GrRecordingContext * recordingContext() const override
Definition: Device.h:101
VkDevice device
Definition: main.cc:53
uint32_t uint32_t * format
SK_API GrBackendFormat MakeVk(VkFormat format, bool willUseDRMFormatModifiers=false)
Protected
Definition: GpuTypes.h:61
Definition: ref_ptr.h:256
VkFormat fFormat
Definition: GrVkTypes.h:88
const SkColorInfo & colorInfo() const
Definition: SkImageInfo.h:404
sk_sp< SkColorSpace > refColorSpace() const
int width() const
Definition: SkImageInfo.h:365
SkColorType colorType() const
Definition: SkImageInfo.h:373
int height() const
Definition: SkImageInfo.h:371