Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrTextureProxy.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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
10
11#include "include/core/SkSize.h"
15#include "include/gpu/GrTypes.h"
24
25#include <utility>
26
27class GrOpFlushState;
28
29// Deferred version - no data
31 SkISize dimensions,
32 skgpu::Mipmapped mipmapped,
33 GrMipmapStatus mipmapStatus,
34 SkBackingFit fit,
35 skgpu::Budgeted budgeted,
36 GrProtected isProtected,
37 GrInternalSurfaceFlags surfaceFlags,
38 UseAllocator useAllocator,
39 GrDDLProvider creatingProvider,
40 std::string_view label)
41 : INHERITED(
42 format, dimensions, fit, budgeted, isProtected, surfaceFlags, useAllocator, label)
43 , fMipmapped(mipmapped)
44 , fMipmapStatus(mipmapStatus) SkDEBUGCODE(, fInitialMipmapStatus(fMipmapStatus))
45 , fCreatingProvider(creatingProvider)
46 , fProxyProvider(nullptr)
47 , fDeferredUploader(nullptr) {
51 }
52}
53
54// Lazy-callback version
57 SkISize dimensions,
58 skgpu::Mipmapped mipmapped,
59 GrMipmapStatus mipmapStatus,
60 SkBackingFit fit,
61 skgpu::Budgeted budgeted,
62 GrProtected isProtected,
63 GrInternalSurfaceFlags surfaceFlags,
64 UseAllocator useAllocator,
65 GrDDLProvider creatingProvider,
66 std::string_view label)
67 : INHERITED(std::move(callback),
68 format,
69 dimensions,
70 fit,
71 budgeted,
72 isProtected,
73 surfaceFlags,
74 useAllocator,
75 label)
76 , fMipmapped(mipmapped)
77 , fMipmapStatus(mipmapStatus) SkDEBUGCODE(, fInitialMipmapStatus(fMipmapStatus))
78 , fCreatingProvider(creatingProvider)
79 , fProxyProvider(nullptr)
80 , fDeferredUploader(nullptr) {
84 }
85}
86
87// Wrapped version
89 UseAllocator useAllocator,
90 GrDDLProvider creatingProvider)
91 : INHERITED(std::move(surf), SkBackingFit::kExact, useAllocator)
92 , fMipmapped(fTarget->asTexture()->mipmapped())
93 , fMipmapStatus(fTarget->asTexture()->mipmapStatus())
94 SkDEBUGCODE(, fInitialMipmapStatus(fMipmapStatus))
95 , fCreatingProvider(creatingProvider)
96 , fProxyProvider(nullptr)
97 , fDeferredUploader(nullptr) {
98 if (fTarget->getUniqueKey().isValid()) {
99 fProxyProvider = fTarget->asTexture()->getContext()->priv().proxyProvider();
100 fProxyProvider->adoptUniqueKeyFromSurface(this, fTarget.get());
101 }
102 if (this->textureType() == GrTextureType::kExternal) {
104 }
105}
106
108 // Due to the order of cleanup the GrSurface this proxy may have wrapped may have gone away
109 // at this point. Zero out the pointer so the cache invalidation code doesn't try to use it.
110 fTarget = nullptr;
111
112 // In DDL-mode, uniquely keyed proxies keep their key even after their originating
113 // proxy provider has gone away. In that case there is noone to send the invalid key
114 // message to (Note: in this case we don't want to remove its cached resource).
115 if (fUniqueKey.isValid() && fProxyProvider) {
116 fProxyProvider->processInvalidUniqueKey(fUniqueKey, this,
118 } else {
119 SkASSERT(!fProxyProvider);
120 }
121}
122
124 if (this->isLazy()) {
125 return false;
126 }
127 if (!this->instantiateImpl(resourceProvider, 1, GrRenderable::kNo, fMipmapped,
128 fUniqueKey.isValid() ? &fUniqueKey : nullptr)) {
129 return false;
130 }
131
132 SkASSERT(!this->peekRenderTarget());
133 SkASSERT(this->peekTexture());
134 return true;
135}
136
138 sk_sp<GrSurface> surface = this->createSurfaceImpl(resourceProvider, 1, GrRenderable::kNo,
139 fMipmapped);
140 if (!surface) {
141 return nullptr;
142 }
143
144 SkASSERT(!surface->asRenderTarget());
145 SkASSERT(surface->asTexture());
146 return surface;
147}
148
149void GrTextureProxyPriv::setDeferredUploader(std::unique_ptr<GrDeferredProxyUploader> uploader) {
150 SkASSERT(!fTextureProxy->fDeferredUploader);
151 fTextureProxy->fDeferredUploader = std::move(uploader);
152}
153
155 // The texture proxy's contents may already have been uploaded or instantiation may have failed
156 if (fTextureProxy->fDeferredUploader && fTextureProxy->isInstantiated()) {
157 fTextureProxy->fDeferredUploader->scheduleUpload(flushState, fTextureProxy);
158 }
159}
160
162 SkASSERT(fTextureProxy->fDeferredUploader);
163 fTextureProxy->fDeferredUploader.reset();
164}
165
167 if (this->isInstantiated()) {
168 return this->peekTexture()->mipmapped();
169 }
170 return fMipmapped;
171}
172
174
176 return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(),
177 /*colorSamplesPerPixel=*/1, this->proxyMipmapped(),
178 !this->priv().isExact());
179}
180
182 const GrSurfaceProxy* second) {
183 // In order to be compatible, the proxies should also have the same texture type. This is
184 // checked explicitly since the GrBackendFormat == operator does not compare texture type
185 return first->backendFormat().textureType() == second->backendFormat().textureType() &&
186 first->backendFormat() == second->backendFormat();
187}
188
189void GrTextureProxy::setUniqueKey(GrProxyProvider* proxyProvider, const skgpu::UniqueKey& key) {
190 SkASSERT(key.isValid());
191 SkASSERT(!fUniqueKey.isValid()); // proxies can only ever get one uniqueKey
192
193 if (fTarget && fSyncTargetKey) {
194 if (!fTarget->getUniqueKey().isValid()) {
196 }
198 }
199
200 fUniqueKey = key;
201 fProxyProvider = proxyProvider;
202}
203
204void GrTextureProxy::clearUniqueKey() {
205 fUniqueKey.reset();
206 fProxyProvider = nullptr;
207}
208
210 SkISize dims;
211 SkBackingFit fit;
212 if (this->isFullyLazy()) {
214 dims = {-1, -1};
215 } else {
217 dims = this->dimensions();
218 }
219 return {
220 dims,
221 fit,
222 GrRenderable::kNo,
223 fMipmapped,
224 1,
225 this->backendFormat(),
226 this->textureType(),
227 this->isProtected(),
228 this->isBudgeted(),
229 this->getLabel(),
230 };
231}
232
233#ifdef SK_DEBUG
234void GrTextureProxy::onValidateSurface(const GrSurface* surface) {
235 SkASSERT(!surface->asRenderTarget());
236
237 // Anything that is checked here should be duplicated in GrTextureRenderTargetProxy's version
238 SkASSERT(surface->asTexture());
239 // It is possible to fulfill a non-mipmapped proxy with a mipmapped texture.
240 SkASSERT(skgpu::Mipmapped::kNo == this->proxyMipmapped() ||
241 skgpu::Mipmapped::kYes == surface->asTexture()->mipmapped());
242
243 SkASSERT(surface->asTexture()->textureType() == this->textureType());
244
246 GrInternalSurfaceFlags surfaceFlags = surface->flags();
247 SkASSERT(((int)proxyFlags & kGrInternalTextureFlagsMask) ==
248 ((int)surfaceFlags & kGrInternalTextureFlagsMask));
249}
250
251#endif
252
static constexpr int kGrInternalTextureFlagsMask
GrDDLProvider
Definition GrTypesPriv.h:70
GrMipmapStatus
GrTextureType
GrInternalSurfaceFlags
#define SkASSERT(cond)
Definition SkAssert.h:116
SkBackingFit
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
#define INHERITED(method,...)
GrTextureType textureType() const
GrDirectContextPriv priv()
void setUniqueKey(const skgpu::UniqueKey &key)
const GrDirectContext * getContext() const
const skgpu::UniqueKey & getUniqueKey() const
ResourcePriv resourcePriv()
GrResourceProvider * resourceProvider() const final
void processInvalidUniqueKey(const skgpu::UniqueKey &, GrTextureProxy *, InvalidateGPUResource)
void adoptUniqueKeyFromSurface(GrTextureProxy *proxy, const GrSurface *)
GrProxyProvider * proxyProvider()
GrProtected isProtected() const
const GrBackendFormat & backendFormat() const
bool instantiateImpl(GrResourceProvider *resourceProvider, int sampleCnt, GrRenderable, skgpu::Mipmapped, const skgpu::UniqueKey *)
GrSurfaceProxyPriv priv()
bool isLazy() const
std::string_view getLabel() const
GrTexture * peekTexture() const
bool isFullyLazy() const
skgpu::Budgeted isBudgeted() const
SkISize dimensions() const
std::function< LazyCallbackResult(GrResourceProvider *, const LazySurfaceDesc &)> LazyInstantiateCallback
bool isInstantiated() const
bool isFunctionallyExact() const
sk_sp< GrSurface > createSurfaceImpl(GrResourceProvider *, int sampleCnt, GrRenderable, skgpu::Mipmapped) const
sk_sp< GrSurface > fTarget
GrInternalSurfaceFlags fSurfaceFlags
GrRenderTarget * peekRenderTarget() const
static size_t ComputeSize(const GrBackendFormat &, SkISize dimensions, int colorSamplesPerPixel, skgpu::Mipmapped, bool binSize=false)
Definition GrSurface.cpp:21
virtual GrTexture * asTexture()
Definition GrSurface.h:59
void setDeferredUploader(std::unique_ptr< GrDeferredProxyUploader >)
void scheduleUpload(GrOpFlushState *)
GrTextureType textureType() const
static bool ProxiesAreCompatibleAsDynamicState(const GrSurfaceProxy *first, const GrSurfaceProxy *second)
skgpu::Mipmapped proxyMipmapped() const
GrTextureProxy(const GrBackendFormat &, SkISize, skgpu::Mipmapped, GrMipmapStatus, SkBackingFit, skgpu::Budgeted, skgpu::Protected, GrInternalSurfaceFlags, UseAllocator, GrDDLProvider creatingProvider, std::string_view label)
LazySurfaceDesc callbackDesc() const override
size_t onUninstantiatedGpuMemorySize() const override
sk_sp< GrSurface > createSurface(GrResourceProvider *) const override
~GrTextureProxy() override
skgpu::Mipmapped mipmapped() const
bool instantiate(GrResourceProvider *) override
skgpu::Mipmapped mipmapped() const
Definition GrTexture.h:62
T * get() const
Definition SkRefCnt.h:303
bool isValid() const
Definition ResourceKey.h:55
VkSurfaceKHR surface
Definition main.cc:49
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
uint32_t uint32_t * format
Budgeted
Definition GpuTypes.h:35
Mipmapped
Definition GpuTypes.h:53
Protected
Definition GpuTypes.h:61
Definition ref_ptr.h:256