Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrTextureProxy.h
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
8#ifndef GrTextureProxy_DEFINED
9#define GrTextureProxy_DEFINED
10
16#include "src/gpu/ResourceKey.h"
20
21#include <cstddef>
22#include <memory>
23#include <string_view>
24
25class GrBackendFormat;
27class GrProxyProvider;
30enum class SkBackingFit;
31struct SkISize;
32
33// This class delays the acquisition of textures until they are actually required
34class GrTextureProxy : virtual public GrSurfaceProxy {
35public:
36 GrTextureProxy* asTextureProxy() override { return this; }
37 const GrTextureProxy* asTextureProxy() const override { return this; }
38
39 // Actually instantiate the backing texture, if necessary
40 bool instantiate(GrResourceProvider*) override;
41
42 // If we are instantiated and have a target, return the mip state of that target. Otherwise
43 // returns the proxy's mip state from creation time. This is useful for lazy proxies which may
44 // claim to not need mips at creation time, but the instantiation happens to give us a mipped
45 // target. In that case we should use that for our benefit to avoid possible copies/mip
46 // generation later.
48
49 bool mipmapsAreDirty() const {
50 SkASSERT((skgpu::Mipmapped::kNo == fMipmapped) ==
51 (GrMipmapStatus::kNotAllocated == fMipmapStatus));
52 return skgpu::Mipmapped::kYes == fMipmapped && GrMipmapStatus::kValid != fMipmapStatus;
53 }
55 SkASSERT(skgpu::Mipmapped::kYes == fMipmapped);
56 fMipmapStatus = GrMipmapStatus::kDirty;
57 }
59 SkASSERT(skgpu::Mipmapped::kYes == fMipmapped);
60 fMipmapStatus = GrMipmapStatus::kValid;
61 }
62
63 // Returns the skgpu::Mipmapped value of the proxy from creation time regardless of whether it has
64 // been instantiated or not.
65 skgpu::Mipmapped proxyMipmapped() const { return fMipmapped; }
66
68
69 /** If true then the texture does not support MIP maps and only supports clamp wrap mode. */
73
74 // Returns true if the passed in proxies can be used as dynamic state together when flushing
75 // draws to the gpu. This accepts GrSurfaceProxy since the information needed is defined on
76 // that type, but this function exists in GrTextureProxy because it's only relevant when the
77 // proxies are being used as textures.
79 const GrSurfaceProxy* second);
80
81 /**
82 * Return the texture proxy's unique key. It will be invalid if the proxy doesn't have one.
83 */
84 const skgpu::UniqueKey& getUniqueKey() const override {
85#ifdef SK_DEBUG
86 if (this->isInstantiated() && fUniqueKey.isValid() && fSyncTargetKey &&
87 fCreatingProvider == GrDDLProvider::kNo) {
88 GrSurface* surface = this->peekSurface();
89 SkASSERT(surface);
90
91 SkASSERT(surface->getUniqueKey().isValid());
92 // It is possible for a non-keyed proxy to have a uniquely keyed resource assigned to
93 // it. This just means that a future user of the resource will be filling it with unique
94 // data. However, if the proxy has a unique key its attached resource should also
95 // have that key.
96 SkASSERT(fUniqueKey == surface->getUniqueKey());
97 }
98#endif
99
100 return fUniqueKey;
101 }
102
103 /**
104 * Internal-only helper class used for manipulations of the resource by the cache.
105 */
106 class CacheAccess;
107 inline CacheAccess cacheAccess();
108 inline const CacheAccess cacheAccess() const; // NOLINT(readability-const-return-type)
109
110 // Provides access to special purpose functions.
112 const GrTextureProxyPriv texPriv() const; // NOLINT(readability-const-return-type)
113
114 SkDEBUGCODE(GrDDLProvider creatingProvider() const { return fCreatingProvider; })
115
116protected:
117 // DDL TODO: rm the GrSurfaceProxy friending
118 friend class GrSurfaceProxy; // for ctors
119 friend class GrProxyProvider; // for ctors
120 friend class GrTextureProxyPriv;
121 friend class GrSurfaceProxyPriv; // ability to change key sync state after lazy instantiation.
122
123 // Deferred version - no data.
125 SkISize,
133 GrDDLProvider creatingProvider,
134 std::string_view label);
135
136 // Lazy-callback version
137 // There are two main use cases for lazily-instantiated proxies:
138 // basic knowledge - width, height, config, origin are known
139 // minimal knowledge - only config is known.
140 //
141 // The basic knowledge version is used for DDL where we know the type of proxy we are going to
142 // use, but we don't have access to the GPU yet to instantiate it.
143 //
144 // The minimal knowledge version is used for when we are generating an atlas but we do not know
145 // the final size until we have finished adding to it.
147 const GrBackendFormat&,
148 SkISize,
156 GrDDLProvider creatingProvider,
157 std::string_view label);
158
159 // Wrapped version
162 GrDDLProvider creatingProvider);
163
164 ~GrTextureProxy() override;
165
167
168 // By default uniqueKeys are propagated from a textureProxy to its backing GrTexture.
169 // Setting syncTargetKey to false disables this behavior and only keeps the unique key
170 // on the proxy.
171 void setTargetKeySync(bool sync) { fSyncTargetKey = sync; }
172
173private:
174 // WARNING: Be careful when adding or removing fields here. ASAN is likely to trigger warnings
175 // when instantiating GrTextureRenderTargetProxy. The std::function in GrSurfaceProxy makes
176 // each class in the diamond require 16 byte alignment. Clang appears to layout the fields for
177 // each class to achieve the necessary alignment. However, ASAN checks the alignment of 'this'
178 // in the constructors, and always looks for the full 16 byte alignment, even if the fields in
179 // that particular class don't require it. Changing the size of this object can move the start
180 // address of other types, leading to this problem.
181
182 skgpu::Mipmapped fMipmapped;
183
184 // This tracks the mipmap status at the proxy level and is thus somewhat distinct from the
185 // backing GrTexture's mipmap status. In particular, this status is used to determine when
186 // mipmap levels need to be explicitly regenerated during the execution of a DAG of opsTasks.
187 GrMipmapStatus fMipmapStatus;
188 // TEMPORARY: We are in the process of moving GrMipmapStatus from the texture to the proxy.
189 // We track the fInitialMipmapStatus here so we can assert that the proxy did indeed expect
190 // the correct mipmap status immediately after instantiation.
191 //
192 // NOTE: fMipmapStatus may no longer be equal to fInitialMipmapStatus by the time the texture
193 // is instantiated, since it tracks mipmaps in the time frame in which the DAG is being built.
194 SkDEBUGCODE(const GrMipmapStatus fInitialMipmapStatus;)
195
196 bool fSyncTargetKey = true; // Should target's unique key be sync'ed with ours.
197
198 // For GrTextureProxies created in a DDL recording thread it is possible for the uniqueKey
199 // to be cleared on the backing GrTexture while the uniqueKey remains on the proxy.
200 // A fCreatingProvider of DDLProvider::kYes loosens up asserts that the key of an instantiated
201 // uniquely-keyed textureProxy is also always set on the backing GrTexture.
202 GrDDLProvider fCreatingProvider = GrDDLProvider::kNo;
203
204 skgpu::UniqueKey fUniqueKey;
205 GrProxyProvider* fProxyProvider; // only set when fUniqueKey is valid
206
207 LazySurfaceDesc callbackDesc() const override;
208
209 // Only used for proxies whose contents are being prepared on a worker thread. This object
210 // stores the texture data, allowing the proxy to remain uninstantiated until flush. At that
211 // point, the proxy is instantiated, and this data is used to perform an ASAP upload.
212 std::unique_ptr<GrDeferredProxyUploader> fDeferredUploader;
213
214 size_t onUninstantiatedGpuMemorySize() const override;
215
216 // Methods made available via GrTextureProxy::CacheAccess
217 void setUniqueKey(GrProxyProvider*, const skgpu::UniqueKey&);
218 void clearUniqueKey();
219
220 SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
221
223};
224
225#endif
GrDDLProvider
Definition GrTypesPriv.h:70
GrMipmapStatus
GrTextureType
GrInternalSurfaceFlags
static bool GrTextureTypeHasRestrictedSampling(GrTextureType type)
#define SkASSERT(cond)
Definition SkAssert.h:116
SkBackingFit
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
#define INHERITED(method,...)
std::function< LazyCallbackResult(GrResourceProvider *, const LazySurfaceDesc &)> LazyInstantiateCallback
GrSurface * peekSurface() const
bool isInstantiated() const
GrTextureType textureType() const
void setTargetKeySync(bool sync)
static bool ProxiesAreCompatibleAsDynamicState(const GrSurfaceProxy *first, const GrSurfaceProxy *second)
skgpu::Mipmapped proxyMipmapped() const
bool hasRestrictedSampling() const
void markMipmapsClean()
LazySurfaceDesc callbackDesc() const override
const GrTextureProxy * asTextureProxy() const override
size_t onUninstantiatedGpuMemorySize() const override
sk_sp< GrSurface > createSurface(GrResourceProvider *) const override
const skgpu::UniqueKey & getUniqueKey() const override
GrTextureProxyPriv texPriv()
~GrTextureProxy() override
void markMipmapsDirty()
skgpu::Mipmapped mipmapped() const
bool mipmapsAreDirty() const
bool instantiate(GrResourceProvider *) override
GrTextureProxy * asTextureProxy() override
bool isValid() const
Definition ResourceKey.h:55
VkSurfaceKHR surface
Definition main.cc:49
Budgeted
Definition GpuTypes.h:35
Mipmapped
Definition GpuTypes.h:53
Protected
Definition GpuTypes.h:61