Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrProxyProvider.h
Go to the documentation of this file.
1/*
2 * Copyright 2018 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 GrProxyProvider_DEFINED
9#define GrProxyProvider_DEFINED
10
11#include "include/gpu/GrTypes.h"
13#include "src/gpu/ResourceKey.h"
15
18class GrImageContext;
20class SkBitmap;
21class SkImage;
23struct GrVkDrawableInfo;
24
25/*
26 * A factory for creating GrSurfaceProxy-derived objects.
27 */
29public:
31
33
35
36 /*
37 * Assigns a unique key to a proxy. The proxy will be findable via this key using
38 * findProxyByUniqueKey(). It is an error if an existing proxy already has a key.
39 */
41
42 /*
43 * Sets the unique key of the provided proxy to the unique key of the surface. The surface must
44 * have a valid unique key.
45 */
47
48 /*
49 * Removes a unique key from a proxy. If the proxy has already been instantiated, it will
50 * also remove the unique key from the target GrSurface.
51 */
53
54 /*
55 * Finds a proxy by unique key.
56 */
58
59 /*
60 * Finds a proxy by unique key or creates a new one that wraps a resource matching the unique
61 * key.
62 */
64 UseAllocator = UseAllocator::kYes);
65
66 /**
67 * A helper that uses findOrCreateProxyByUniqueKey() to find a proxy and, if found, creates
68 * a view for the found proxy using the passed in origin and color type. It is assumed that if
69 * the proxy is renderable then it was created via a fallback code path so the fallback
70 * color type will be used to create the view.
71 */
75 int sampleCnt);
76
77 /*
78 * Creates a new texture proxy for the bitmap, optionally with mip levels generated by the cpu.
79 * The bitmap is uploaded to the texture proxy assuming a kTopLeft_GrSurfaceOrigin.
80 */
85
86 /*
87 * Create a GrSurfaceProxy without any data.
88 */
90 SkISize dimensions,
92 int renderTargetSampleCnt,
97 std::string_view label,
99 UseAllocator useAllocator = UseAllocator::kYes);
100
101 /*
102 * Create a texture proxy from compressed texture data.
103 */
109 sk_sp<SkData> data);
110
111 // These match the definitions in SkImage & GrTexture.h, for whence they came
112 typedef void* ReleaseContext;
113 typedef void (*ReleaseProc)(ReleaseContext);
114
115 /*
116 * Create a texture proxy that wraps a (non-renderable) backend texture. GrIOType must be
117 * kRead or kRW.
118 */
122 GrIOType,
124
129
130 /*
131 * Create a texture proxy that wraps a backend texture and is both texture-able and renderable
132 */
134 int sampleCnt,
137 sk_sp<skgpu::RefCntedCallback> releaseHelper);
138
139 /*
140 * Create a render target proxy that wraps a backend render target
141 */
143 sk_sp<skgpu::RefCntedCallback> releaseHelper);
144
149
154
155 /**
156 * Similar to createLazyProxy below, except narrowed to the use case of shared promise images
157 * i.e. static so it doesn't have access to mutable state. Used by MakePromiseImageLazyProxy().
158 */
161 const GrBackendFormat&,
162 SkISize dimensions,
164
165 /**
166 * Creates a texture proxy that will be instantiated by a user-supplied callback during flush.
167 * The width and height must either both be greater than 0 or both less than or equal to zero. A
168 * non-positive value is a signal that the width height are currently unknown. The texture will
169 * not be renderable.
170 *
171 * When called, the callback must be able to cleanup any resources that it captured at creation.
172 * It also must support being passed in a null GrResourceProvider. When this happens, the
173 * callback should cleanup any resources it captured and return an empty sk_sp<GrTextureProxy>.
174 */
176 const GrBackendFormat&,
177 SkISize dimensions,
185 std::string_view label);
186
187 /** A null TextureInfo indicates a non-textureable render target. */
189 const GrBackendFormat&,
190 SkISize dimensions,
191 int renderTargetSampleCnt,
193 const TextureInfo*,
198 bool wrapsVkSecondaryCB,
199 UseAllocator useAllocator);
200
201 /**
202 * Fully lazy proxies have unspecified width and height. Methods that rely on those values
203 * (e.g., width, height, getBoundsRect) should be avoided.
204 */
206 const GrBackendFormat&,
208 int renderTargetSampleCnt,
210 const GrCaps&,
212
213 enum class InvalidateGPUResource : bool { kNo = false, kYes = true };
214
215 /*
216 * This method ensures that, if a proxy w/ the supplied unique key exists, it is removed from
217 * the proxy provider's map and its unique key is removed. If 'invalidateSurface' is true, it
218 * will independently ensure that the unique key is removed from any GrGpuResources that may
219 * have it.
220 *
221 * If 'proxy' is provided (as an optimization to stop re-looking it up), its unique key must be
222 * valid and match the provided unique key.
223 *
224 * This method is called if either the proxy attached to the unique key is being deleted
225 * (in which case we don't want it cluttering up the hash table) or the client has indicated
226 * that it will never refer to the unique key again.
227 */
229
231
232 // TODO: remove these entry points - it is a bit sloppy to be getting context info from here
233 uint32_t contextID() const;
234 const GrCaps* caps() const;
236
238
240
241 // This is called on a DDL's proxyprovider when the DDL is finished. The uniquely keyed
242 // proxies need to keep their unique key but cannot hold on to the proxy provider unique
243 // pointer.
244 void orphanAllUniqueKeys();
245 // This is only used by GrContext::releaseResourcesAndAbandonContext()
246 void removeAllUniqueKeys();
247
248 /**
249 * Does the proxy provider have access to a GrDirectContext? If so, proxies will be
250 * instantiated immediately.
251 */
252 bool renderingDirectly() const;
253 bool isAbandoned() const;
254
255#if defined(GR_TEST_UTILS)
256 /**
257 * Create a texture proxy that is backed by an instantiated GrSurface.
258 */
259 sk_sp<GrTextureProxy> testingOnly_createInstantiatedProxy(SkISize dimensions,
260 const GrBackendFormat& format,
261 GrRenderable renderable,
262 int renderTargetSampleCnt,
263 SkBackingFit fit,
264 skgpu::Budgeted budgeted,
265 GrProtected isProtected);
266
267 /** Version of above that picks the default format for the color type. */
268 sk_sp<GrTextureProxy> testingOnly_createInstantiatedProxy(SkISize dimensions,
270 GrRenderable renderable,
271 int renderTargetSampleCnt,
272 SkBackingFit fit,
273 skgpu::Budgeted budgeted,
274 GrProtected isProtected);
275
276 sk_sp<GrTextureProxy> testingOnly_createWrapped(sk_sp<GrTexture>);
277#endif
278
279private:
280 friend class GrAHardwareBufferImageGenerator; // for createWrapped
281 friend class GrResourceProvider; // for createWrapped
282
283 // processInvalidUniqueKey() with control over removing hash table entries,
284 // which is not safe while iterating with foreach().
285 enum class RemoveTableEntry { kNo, kYes };
286 void processInvalidUniqueKeyImpl(const skgpu::UniqueKey&, GrTextureProxy*,
287 InvalidateGPUResource, RemoveTableEntry);
288
289 /*
290 * Create an un-mipmapped texture proxy for the bitmap.
291 */
292 sk_sp<GrTextureProxy> createNonMippedProxyFromBitmap(const SkBitmap&,
295 /*
296 * Create an mipmapped texture proxy for the bitmap.
297 */
298 sk_sp<GrTextureProxy> createMippedProxyFromBitmap(const SkBitmap&, skgpu::Budgeted);
299
300 sk_sp<GrTextureProxy> createWrapped(sk_sp<GrTexture> tex, UseAllocator useAllocator);
301
302 struct UniquelyKeyedProxyHashTraits {
303 static const skgpu::UniqueKey& GetKey(const GrTextureProxy& p) { return p.getUniqueKey(); }
304
305 static uint32_t Hash(const skgpu::UniqueKey& key) { return key.hash(); }
306 };
308
309 // This holds the texture proxies that have unique keys. The resourceCache does not get a ref
310 // on these proxies but they must send a message to the resourceCache when they are deleted.
311 UniquelyKeyedProxyHash fUniquelyKeyedProxies;
312
313 GrImageContext* fImageContext;
314};
315
316#endif
GrWrapCacheable
Definition GrTypesPriv.h:84
GrDDLProvider
Definition GrTypesPriv.h:70
GrIOType
GrMipmapStatus
GrWrapOwnership
Definition GrTypesPriv.h:76
GrTextureType
GrColorType
GrInternalSurfaceFlags
GrSurfaceOrigin
Definition GrTypes.h:147
SkBackingFit
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
uint32_t contextID() const
void removeUniqueKeyFromProxy(GrTextureProxy *)
sk_sp< GrRenderTargetProxy > createLazyRenderTargetProxy(LazyInstantiateCallback &&, const GrBackendFormat &, SkISize dimensions, int renderTargetSampleCnt, GrInternalSurfaceFlags, const TextureInfo *, GrMipmapStatus, SkBackingFit, skgpu::Budgeted, GrProtected, bool wrapsVkSecondaryCB, UseAllocator useAllocator)
GrSurfaceProxyView findCachedProxyWithColorTypeFallback(const skgpu::UniqueKey &, GrSurfaceOrigin, GrColorType, int sampleCnt)
GrResourceProvider * resourceProvider() const
sk_sp< const GrCaps > refCaps() const
bool isAbandoned() const
sk_sp< GrTextureProxy > findProxyByUniqueKey(const skgpu::UniqueKey &)
sk_sp< GrTextureProxy > createLazyProxy(LazyInstantiateCallback &&, const GrBackendFormat &, SkISize dimensions, skgpu::Mipmapped, GrMipmapStatus, GrInternalSurfaceFlags, SkBackingFit, skgpu::Budgeted, GrProtected, UseAllocator, std::string_view label)
sk_sp< GrTextureProxy > wrapBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType, sk_sp< skgpu::RefCntedCallback >=nullptr)
GrSurfaceProxy::UseAllocator UseAllocator
int numUniqueKeyProxies_TestOnly() const
sk_sp< GrTextureProxy > createProxy(const GrBackendFormat &, SkISize dimensions, GrRenderable, int renderTargetSampleCnt, skgpu::Mipmapped, SkBackingFit, skgpu::Budgeted, GrProtected, std::string_view label, GrInternalSurfaceFlags=GrInternalSurfaceFlags::kNone, UseAllocator useAllocator=UseAllocator::kYes)
GrDDLProvider isDDLProvider() const
sk_sp< GrTextureProxy > wrapCompressedBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, sk_sp< skgpu::RefCntedCallback >)
static sk_sp< GrTextureProxy > CreatePromiseProxy(GrContextThreadSafeProxy *, LazyInstantiateCallback &&, const GrBackendFormat &, SkISize dimensions, skgpu::Mipmapped)
bool assignUniqueKeyToProxy(const skgpu::UniqueKey &, GrTextureProxy *)
sk_sp< GrTextureProxy > findOrCreateProxyByUniqueKey(const skgpu::UniqueKey &, UseAllocator=UseAllocator::kYes)
void(* ReleaseProc)(ReleaseContext)
void processInvalidUniqueKey(const skgpu::UniqueKey &, GrTextureProxy *, InvalidateGPUResource)
sk_sp< GrTextureProxy > wrapRenderableBackendTexture(const GrBackendTexture &, int sampleCnt, GrWrapOwnership, GrWrapCacheable, sk_sp< skgpu::RefCntedCallback > releaseHelper)
void adoptUniqueKeyFromSurface(GrTextureProxy *proxy, const GrSurface *)
sk_sp< GrSurfaceProxy > wrapBackendRenderTarget(const GrBackendRenderTarget &, sk_sp< skgpu::RefCntedCallback > releaseHelper)
static sk_sp< GrTextureProxy > MakeFullyLazyProxy(LazyInstantiateCallback &&, const GrBackendFormat &, GrRenderable, int renderTargetSampleCnt, GrProtected, const GrCaps &, UseAllocator)
bool renderingDirectly() const
sk_sp< GrTextureProxy > createProxyFromBitmap(const SkBitmap &, skgpu::Mipmapped, SkBackingFit, skgpu::Budgeted)
GrSurfaceProxy::LazyInstantiateCallback LazyInstantiateCallback
sk_sp< GrTextureProxy > createCompressedTextureProxy(SkISize dimensions, skgpu::Budgeted, skgpu::Mipmapped, GrProtected, SkTextureCompressionType, sk_sp< SkData > data)
const GrCaps * caps() const
std::function< LazyCallbackResult(GrResourceProvider *, const LazySurfaceDesc &)> LazyInstantiateCallback
uint32_t uint32_t * format
Budgeted
Definition GpuTypes.h:35
Renderable
Definition GpuTypes.h:69
Mipmapped
Definition GpuTypes.h:53
Protected
Definition GpuTypes.h:61