blob: ad29e0adf7c5b80a04edcb7196d2e286d6789264 [file] [log] [blame]
robertphillips76948d42016-05-04 12:47:41 -07001/*
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 GrSurfaceProxy_DEFINED
9#define GrSurfaceProxy_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkRect.h"
12#include "include/gpu/GrBackendSurface.h"
13#include "include/gpu/GrGpuResource.h"
14#include "include/gpu/GrSurface.h"
15#include "include/gpu/GrTexture.h"
16#include "include/private/SkNoncopyable.h"
Brian Salomona036f0d2019-08-29 11:16:04 -040017#include "src/gpu/GrNonAtomicRef.h"
Greg Daniel2c19e7f2019-06-18 13:29:21 -040018#include "src/gpu/GrSwizzle.h"
robertphillips76948d42016-05-04 12:47:41 -070019
Robert Phillips37430132016-11-09 06:50:43 -050020class GrCaps;
Robert Phillips292a6b22019-02-14 14:49:02 -050021class GrContext_Base;
Greg Danielf41b2bd2019-08-22 16:19:24 -040022class GrOpsTask;
Robert Phillipsd44146b2019-02-15 14:44:28 -050023class GrRecordingContext;
Brian Osman45580d32016-11-23 09:37:01 -050024class GrRenderTargetProxy;
Chris Dalton6b498102019-08-01 14:14:52 -060025class GrRenderTask;
Brian Osman32342f02017-03-04 08:12:46 -050026class GrResourceProvider;
Robert Phillipsd46697a2017-01-25 12:10:37 -050027class GrSurfaceContext;
Robert Phillips757914d2017-01-25 15:48:30 -050028class GrSurfaceProxyPriv;
robertphillips76948d42016-05-04 12:47:41 -070029class GrTextureProxy;
robertphillips76948d42016-05-04 12:47:41 -070030
Brian Salomona036f0d2019-08-29 11:16:04 -040031class GrSurfaceProxy : public GrNonAtomicRef<GrSurfaceProxy> {
Robert Phillipsc7635fa2016-10-28 13:25:24 -040032public:
Brian Salomona036f0d2019-08-29 11:16:04 -040033 virtual ~GrSurfaceProxy();
Robert Phillipsb5204762019-06-19 14:12:13 -040034
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040035 /**
Chris Dalton4ece96d2019-08-30 11:26:39 -060036 * Indicates "resolutions" that need to be done on a surface before its pixels can be accessed.
37 * If both types of resolve are requested, the MSAA resolve will happen first.
38 */
39 enum class ResolveFlags {
40 kNone = 0,
41 kMSAA = 1 << 0, // Blit and resolve an internal MSAA render buffer into the texture.
42 kMipMaps = 1 << 1, // Regenerate all mipmap levels.
43 };
44
45 /**
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040046 * Some lazy proxy callbacks want to set their own (or no key) on the GrSurfaces they return.
47 * Others want the GrSurface's key to be kept in sync with the proxy's key. This enum controls
48 * the key relationship between proxies and their targets.
49 */
50 enum class LazyInstantiationKeyMode {
51 /**
52 * Don't key the GrSurface with the proxy's key. The lazy instantiation callback is free to
53 * return a GrSurface that already has a unique key unrelated to the proxy's key.
54 */
55 kUnsynced,
56 /**
57 * Keep the GrSurface's unique key in sync with the proxy's unique key. The GrSurface
58 * returned from the lazy instantiation callback must not have a unique key or have the same
59 * same unique key as the proxy. If the proxy is later assigned a key it is in turn assigned
60 * to the GrSurface.
61 */
62 kSynced
63 };
64
Brian Salomonbeb7f522019-08-30 16:19:42 -040065 struct LazyCallbackResult {
66 LazyCallbackResult() = default;
67 LazyCallbackResult(const LazyCallbackResult&) = default;
68 LazyCallbackResult(LazyCallbackResult&& that) = default;
69 LazyCallbackResult(sk_sp<GrSurface> surf,
70 bool releaseCallback = true,
71 LazyInstantiationKeyMode mode = LazyInstantiationKeyMode::kSynced)
72 : fSurface(std::move(surf)), fKeyMode(mode), fReleaseCallback(releaseCallback) {}
73 LazyCallbackResult(sk_sp<GrTexture> tex)
74 : LazyCallbackResult(sk_sp<GrSurface>(std::move(tex))) {}
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040075
Brian Salomonbeb7f522019-08-30 16:19:42 -040076 LazyCallbackResult& operator=(const LazyCallbackResult&) = default;
77 LazyCallbackResult& operator=(LazyCallbackResult&&) = default;
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040078
79 sk_sp<GrSurface> fSurface;
80 LazyInstantiationKeyMode fKeyMode = LazyInstantiationKeyMode::kSynced;
Brian Salomonbeb7f522019-08-30 16:19:42 -040081 /**
82 * Should the callback be disposed of after it has returned or preserved until the proxy
83 * is freed. Only honored if fSurface is not-null. If it is null the callback is preserved.
84 */
85 bool fReleaseCallback = true;
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040086 };
87
Brian Salomonbeb7f522019-08-30 16:19:42 -040088 using LazyInstantiateCallback = std::function<LazyCallbackResult(GrResourceProvider*)>;
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040089
Brian Salomonbeb7f522019-08-30 16:19:42 -040090 enum class UseAllocator {
91 /**
92 * This proxy will be instantiated outside the allocator (e.g. for proxies that are
93 * instantiated in on-flush callbacks).
94 */
95 kNo = false,
96 /**
97 * GrResourceAllocator should instantiate this proxy.
98 */
99 kYes = true,
Greg Daniel457469c2018-02-08 15:05:44 -0500100 };
101
Brian Salomonbeb7f522019-08-30 16:19:42 -0400102 bool isLazy() const { return !this->isInstantiated() && SkToBool(fLazyInstantiateCallback); }
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500103
Brian Salomonbeb7f522019-08-30 16:19:42 -0400104 bool isFullyLazy() const {
Brian Salomon1d19da02019-09-11 17:39:30 -0400105 bool result = fHeight < 0;
106 SkASSERT(result == (fWidth < 0));
Brian Salomonbeb7f522019-08-30 16:19:42 -0400107 SkASSERT(!result || this->isLazy());
108 return result;
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500109 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700110
111 GrPixelConfig config() const { return fConfig; }
Brian Salomonbeb7f522019-08-30 16:19:42 -0400112
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500113 int width() const {
Brian Salomonbeb7f522019-08-30 16:19:42 -0400114 SkASSERT(!this->isFullyLazy());
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500115 return fWidth;
116 }
Brian Salomonbeb7f522019-08-30 16:19:42 -0400117
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500118 int height() const {
Brian Salomonbeb7f522019-08-30 16:19:42 -0400119 SkASSERT(!this->isFullyLazy());
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500120 return fHeight;
121 }
Brian Salomon7eae3e02018-08-07 14:02:38 +0000122
123 SkISize isize() const { return {fWidth, fHeight}; }
124
Chris Dalton706a6ff2017-11-29 22:01:06 -0700125 int worstCaseWidth() const;
126 int worstCaseHeight() const;
Brian Salomond8eb7b62018-05-25 10:08:05 -0400127 /**
128 * Helper that gets the width and height of the surface as a bounding rectangle.
129 */
130 SkRect getBoundsRect() const {
Brian Salomonbeb7f522019-08-30 16:19:42 -0400131 SkASSERT(!this->isFullyLazy());
Brian Salomond8eb7b62018-05-25 10:08:05 -0400132 return SkRect::MakeIWH(this->width(), this->height());
133 }
134 /**
135 * Helper that gets the worst case width and height of the surface as a bounding rectangle.
136 */
137 SkRect getWorstCaseBoundsRect() const {
Brian Salomonbeb7f522019-08-30 16:19:42 -0400138 SkASSERT(!this->isFullyLazy());
Brian Salomond8eb7b62018-05-25 10:08:05 -0400139 return SkRect::MakeIWH(this->worstCaseWidth(), this->worstCaseHeight());
140 }
141
robertphillips76948d42016-05-04 12:47:41 -0700142 GrSurfaceOrigin origin() const {
Brian Salomonbb5711a2017-05-17 13:49:59 -0400143 SkASSERT(kTopLeft_GrSurfaceOrigin == fOrigin || kBottomLeft_GrSurfaceOrigin == fOrigin);
144 return fOrigin;
robertphillips76948d42016-05-04 12:47:41 -0700145 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700146
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400147 const GrSwizzle& textureSwizzle() const { return fTextureSwizzle; }
148
Greg Daniel4065d452018-11-16 15:43:41 -0500149 const GrBackendFormat& backendFormat() const { return fFormat; }
150
Robert Phillips294870f2016-11-11 12:38:40 -0500151 class UniqueID {
152 public:
Robert Phillips7ee385e2017-03-30 08:02:11 -0400153 static UniqueID InvalidID() {
154 return UniqueID(uint32_t(SK_InvalidUniqueID));
155 }
156
Robert Phillips294870f2016-11-11 12:38:40 -0500157 // wrapped
158 explicit UniqueID(const GrGpuResource::UniqueID& id) : fID(id.asUInt()) { }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700159 // deferred and lazy-callback
Robert Phillips294870f2016-11-11 12:38:40 -0500160 UniqueID() : fID(GrGpuResource::CreateUniqueID()) { }
161
162 uint32_t asUInt() const { return fID; }
163
164 bool operator==(const UniqueID& other) const {
165 return fID == other.fID;
166 }
167 bool operator!=(const UniqueID& other) const {
168 return !(*this == other);
169 }
170
Robert Phillips7ee385e2017-03-30 08:02:11 -0400171 void makeInvalid() { fID = SK_InvalidUniqueID; }
Robert Phillips294870f2016-11-11 12:38:40 -0500172 bool isInvalid() const { return SK_InvalidUniqueID == fID; }
173
174 private:
Robert Phillips7ee385e2017-03-30 08:02:11 -0400175 explicit UniqueID(uint32_t id) : fID(id) {}
176
177 uint32_t fID;
Robert Phillips294870f2016-11-11 12:38:40 -0500178 };
179
180 /*
181 * The contract for the uniqueID is:
182 * for wrapped resources:
183 * the uniqueID will match that of the wrapped resource
184 *
185 * for deferred resources:
186 * the uniqueID will be different from the real resource, when it is allocated
187 * the proxy's uniqueID will not change across the instantiate call
188 *
189 * the uniqueIDs of the proxies and the resources draw from the same pool
190 *
191 * What this boils down to is that the uniqueID of a proxy can be used to consistently
192 * track/identify a proxy but should never be used to distinguish between
193 * resources and proxies - beware!
194 */
195 UniqueID uniqueID() const { return fUniqueID; }
robertphillips76948d42016-05-04 12:47:41 -0700196
Robert Phillips159e3c62017-06-19 12:02:00 -0400197 UniqueID underlyingUniqueID() const {
198 if (fTarget) {
199 return UniqueID(fTarget->uniqueID());
200 }
201
202 return fUniqueID;
203 }
204
Robert Phillips10d17212019-04-24 14:09:10 -0400205 virtual bool instantiate(GrResourceProvider*) = 0;
Robert Phillips37430132016-11-09 06:50:43 -0500206
Brian Salomon967df202018-12-07 11:15:53 -0500207 void deinstantiate();
Robert Phillips4bc70112018-03-01 10:24:02 -0500208
robertphillips76948d42016-05-04 12:47:41 -0700209 /**
Brian Salomon7d94bb52018-10-12 14:37:19 -0400210 * Proxies that are already instantiated and whose backing surface cannot be recycled to
211 * instantiate other proxies do not need to be considered by GrResourceAllocator.
212 */
213 bool canSkipResourceAllocator() const;
214
215 /**
robertphillips76948d42016-05-04 12:47:41 -0700216 * @return the texture proxy associated with the surface proxy, may be NULL.
217 */
218 virtual GrTextureProxy* asTextureProxy() { return nullptr; }
219 virtual const GrTextureProxy* asTextureProxy() const { return nullptr; }
220
221 /**
222 * @return the render target proxy associated with the surface proxy, may be NULL.
223 */
224 virtual GrRenderTargetProxy* asRenderTargetProxy() { return nullptr; }
225 virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; }
226
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400227 bool isInstantiated() const { return SkToBool(fTarget); }
228
229 // If the proxy is already instantiated, return its backing GrTexture; if not, return null.
Robert Phillipse5f73282019-06-18 17:15:04 -0400230 GrSurface* peekSurface() const { return fTarget.get(); }
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400231
232 // If this is a texture proxy and the proxy is already instantiated, return its backing
233 // GrTexture; if not, return null.
234 GrTexture* peekTexture() const { return fTarget ? fTarget->asTexture() : nullptr; }
235
236 // If this is a render target proxy and the proxy is already instantiated, return its backing
237 // GrRenderTarget; if not, return null.
238 GrRenderTarget* peekRenderTarget() const {
239 return fTarget ? fTarget->asRenderTarget() : nullptr;
240 }
241
robertphillips13a7eee2016-08-31 15:06:24 -0700242 /**
243 * Does the resource count against the resource budget?
244 */
245 SkBudgeted isBudgeted() const { return fBudgeted; }
246
Brian Salomonc67c31c2018-12-06 10:00:03 -0500247 /**
248 * The pixel values of this proxy's surface cannot be modified (e.g. doesn't support write
Brian Salomon9cadc312018-12-05 15:09:19 -0500249 * pixels or MIP map level regen). Read-only proxies also bypass interval tracking and
250 * assignment in GrResourceAllocator.
Brian Salomonc67c31c2018-12-06 10:00:03 -0500251 */
252 bool readOnly() const { return fSurfaceFlags & GrInternalSurfaceFlags::kReadOnly; }
253
Chris Dalton3f7932e2019-08-19 00:39:13 -0600254 /**
255 * This means surface is a multisampled render target, and internally holds a non-msaa texture
256 * for resolving into. The render target resolves itself by blitting into this internal texture.
257 * (asTexture() might or might not return the internal texture, but if it does, we always
258 * resolve the render target before accessing this texture's data.)
259 */
260 bool requiresManualMSAAResolve() const {
261 return fSurfaceFlags & GrInternalSurfaceFlags::kRequiresManualMSAAResolve;
262 }
263
Chris Dalton6b498102019-08-01 14:14:52 -0600264 void setLastRenderTask(GrRenderTask*);
265 GrRenderTask* getLastRenderTask() { return fLastRenderTask; }
Robert Phillipsf2361d22016-10-25 14:20:06 -0400266
Greg Danielf41b2bd2019-08-22 16:19:24 -0400267 GrOpsTask* getLastOpsTask();
Brian Osman45580d32016-11-23 09:37:01 -0500268
Robert Phillips8bc06d02016-11-01 17:28:40 -0400269 /**
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400270 * Retrieves the amount of GPU memory that will be or currently is used by this resource
Robert Phillips8bc06d02016-11-01 17:28:40 -0400271 * in bytes. It is approximate since we aren't aware of additional padding or copies made
272 * by the driver.
273 *
274 * @return the amount of GPU memory used in bytes
275 */
276 size_t gpuMemorySize() const {
Brian Salomonbeb7f522019-08-30 16:19:42 -0400277 SkASSERT(!this->isFullyLazy());
Brian Salomonbb5711a2017-05-17 13:49:59 -0400278 if (fTarget) {
279 return fTarget->gpuMemorySize();
280 }
Robert Phillips8bc06d02016-11-01 17:28:40 -0400281 if (kInvalidGpuMemorySize == fGpuMemorySize) {
Brian Salomonbb5711a2017-05-17 13:49:59 -0400282 fGpuMemorySize = this->onUninstantiatedGpuMemorySize();
Robert Phillips8bc06d02016-11-01 17:28:40 -0400283 SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize);
284 }
285 return fGpuMemorySize;
286 }
287
Greg Daniel46cfbc62019-06-07 11:43:30 -0400288 enum class RectsMustMatch : bool {
289 kNo = false,
290 kYes = true
291 };
292
Robert Phillipse2f7d182016-12-15 09:23:05 -0500293 // Helper function that creates a temporary SurfaceContext to perform the copy
Brian Salomonfee3f9b2018-12-19 12:34:12 -0500294 // The copy is is not a render target and not multisampled.
Robert Phillipsd44146b2019-02-15 14:44:28 -0500295 static sk_sp<GrTextureProxy> Copy(GrRecordingContext*, GrSurfaceProxy* src, GrMipMapped,
Greg Daniel46cfbc62019-06-07 11:43:30 -0400296 SkIRect srcRect, SkBackingFit, SkBudgeted,
297 RectsMustMatch = RectsMustMatch::kNo);
Robert Phillipse2f7d182016-12-15 09:23:05 -0500298
299 // Copy the entire 'src'
Robert Phillipsd44146b2019-02-15 14:44:28 -0500300 static sk_sp<GrTextureProxy> Copy(GrRecordingContext*, GrSurfaceProxy* src, GrMipMapped,
301 SkBackingFit, SkBudgeted);
Robert Phillipse2f7d182016-12-15 09:23:05 -0500302
Robert Phillipsb5204762019-06-19 14:12:13 -0400303#if GR_TEST_UTILS
304 int32_t testingOnly_getBackingRefCnt() const;
305 GrInternalSurfaceFlags testingOnly_getFlags() const;
306#endif
Robert Phillipseaa86252016-11-08 13:49:39 +0000307
Robert Phillips292a6b22019-02-14 14:49:02 -0500308 SkDEBUGCODE(void validate(GrContext_Base*) const;)
Brian Osman45580d32016-11-23 09:37:01 -0500309
Robert Phillips757914d2017-01-25 15:48:30 -0500310 // Provides access to functions that aren't part of the public API.
Robert Phillips420c4cf2017-09-28 09:00:45 -0400311 inline GrSurfaceProxyPriv priv();
312 inline const GrSurfaceProxyPriv priv() const;
Robert Phillips757914d2017-01-25 15:48:30 -0500313
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400314 // Returns true if we are working with protected content.
315 bool isProtected() const { return fIsProtected == GrProtected::kYes; }
316
robertphillips76948d42016-05-04 12:47:41 -0700317protected:
Brian Salomonbeb7f522019-08-30 16:19:42 -0400318 // Deferred version - takes a new UniqueID from the shared resource/proxy pool.
319 GrSurfaceProxy(const GrBackendFormat&,
320 const GrSurfaceDesc&,
321 GrRenderable,
322 GrSurfaceOrigin,
323 const GrSwizzle& textureSwizzle,
324 SkBackingFit,
325 SkBudgeted,
326 GrProtected,
327 GrInternalSurfaceFlags,
328 UseAllocator);
329 // Lazy-callback version - takes a new UniqueID from the shared resource/proxy pool.
330 GrSurfaceProxy(LazyInstantiateCallback&&,
331 const GrBackendFormat&,
332 const GrSurfaceDesc&,
333 GrRenderable,
334 GrSurfaceOrigin,
335 const GrSwizzle& textureSwizzle,
336 SkBackingFit,
337 SkBudgeted,
338 GrProtected,
339 GrInternalSurfaceFlags,
340 UseAllocator);
robertphillips8abb3702016-08-31 14:04:06 -0700341
Brian Salomonbeb7f522019-08-30 16:19:42 -0400342 // Wrapped version - shares the UniqueID of the passed surface.
343 // Takes UseAllocator because even though this is already instantiated it still can participate
344 // in allocation by having its backing resource recycled to other uninstantiated proxies or
345 // not depending on UseAllocator.
346 GrSurfaceProxy(sk_sp<GrSurface>,
347 GrSurfaceOrigin,
348 const GrSwizzle& textureSwizzle,
349 SkBackingFit,
350 UseAllocator);
robertphillips76948d42016-05-04 12:47:41 -0700351
Robert Phillips757914d2017-01-25 15:48:30 -0500352 friend class GrSurfaceProxyPriv;
353
354 // Methods made available via GrSurfaceProxyPriv
Robert Phillips5f78adf2019-04-22 12:41:39 -0400355 bool ignoredByResourceAllocator() const { return fIgnoredByResourceAllocator; }
356 void setIgnoredByResourceAllocator() { fIgnoredByResourceAllocator = true; }
357
Robert Phillips57aa3672017-07-21 11:38:13 -0400358 void computeScratchKey(GrScratchKey*) const;
359
Robert Phillips5af44de2017-07-18 14:49:38 -0400360 virtual sk_sp<GrSurface> createSurface(GrResourceProvider*) const = 0;
361 void assign(sk_sp<GrSurface> surface);
362
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400363 sk_sp<GrSurface> createSurfaceImpl(GrResourceProvider*, int sampleCnt,
364 int minStencilSampleCount, GrRenderable, GrMipMapped) const;
Robert Phillips5af44de2017-07-18 14:49:38 -0400365
Chris Daltonf91b7552019-04-29 16:21:18 -0600366 // Once the size of a fully-lazy proxy is decided, and before it gets instantiated, the client
367 // can use this optional method to specify the proxy's size. (A proxy's size can be less than
368 // the GPU surface that backs it. e.g., SkBackingFit::kApprox.) Otherwise, the proxy's size will
369 // be set to match the underlying GPU surface upon instantiation.
370 void setLazySize(int width, int height) {
Brian Salomonbeb7f522019-08-30 16:19:42 -0400371 SkASSERT(this->isFullyLazy());
Chris Daltonf91b7552019-04-29 16:21:18 -0600372 SkASSERT(width > 0 && height > 0);
373 fWidth = width;
374 fHeight = height;
375 }
376
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400377 bool instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt,
378 int minStencilSampleCount, GrRenderable, GrMipMapped, const GrUniqueKey*);
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400379
Robert Phillipsb5204762019-06-19 14:12:13 -0400380 // For deferred proxies this will be null until the proxy is instantiated.
381 // For wrapped proxies it will point to the wrapped resource.
382 sk_sp<GrSurface> fTarget;
383
Greg Daniele3204862018-04-16 11:24:10 -0400384 // In many cases these flags aren't actually known until the proxy has been instantiated.
385 // However, Ganesh frequently needs to change its behavior based on these settings. For
386 // internally create proxies we will know these properties ahead of time. For wrapped
387 // proxies we will copy the properties off of the GrSurface. For lazy proxies we force the
388 // call sites to provide the required information ahead of time. At instantiation time
389 // we verify that the assumed properties match the actual properties.
390 GrInternalSurfaceFlags fSurfaceFlags;
391
Chris Dalton706a6ff2017-11-29 22:01:06 -0700392private:
Greg Daniel4065d452018-11-16 15:43:41 -0500393 // For wrapped resources, 'fFormat', 'fConfig', 'fWidth', 'fHeight', and 'fOrigin; will always
394 // be filled in from the wrapped resource.
395 GrBackendFormat fFormat;
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400396 GrPixelConfig fConfig;
397 int fWidth;
398 int fHeight;
399 GrSurfaceOrigin fOrigin;
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400400 GrSwizzle fTextureSwizzle;
401
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400402 SkBackingFit fFit; // always kApprox for lazy-callback resources
403 // always kExact for wrapped resources
404 mutable SkBudgeted fBudgeted; // always kYes for lazy-callback resources
405 // set from the backing resource for wrapped resources
406 // mutable bc of SkSurface/SkImage wishy-washiness
Brian Salomonbeb7f522019-08-30 16:19:42 -0400407 // Only meaningful if fLazyInstantiateCallback is non-null.
408 UseAllocator fUseAllocator;
Robert Phillipsa4c41b32017-03-15 13:02:45 -0400409
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400410 const UniqueID fUniqueID; // set from the backing resource for wrapped resources
robertphillips76948d42016-05-04 12:47:41 -0700411
Chris Dalton706a6ff2017-11-29 22:01:06 -0700412 LazyInstantiateCallback fLazyInstantiateCallback;
Greg Daniel849dce12018-04-24 14:32:53 -0400413
414 SkDEBUGCODE(void validateSurface(const GrSurface*);)
415 SkDEBUGCODE(virtual void onValidateSurface(const GrSurface*) = 0;)
Chris Dalton706a6ff2017-11-29 22:01:06 -0700416
Robert Phillips8bc06d02016-11-01 17:28:40 -0400417 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
Robert Phillips29e52f12016-11-03 10:19:14 -0400418 SkDEBUGCODE(size_t getRawGpuMemorySize_debugOnly() const { return fGpuMemorySize; })
419
Brian Salomonbb5711a2017-05-17 13:49:59 -0400420 virtual size_t onUninstantiatedGpuMemorySize() const = 0;
Robert Phillips29e52f12016-11-03 10:19:14 -0400421
Robert Phillips5f78adf2019-04-22 12:41:39 -0400422 bool fIgnoredByResourceAllocator = false;
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400423 GrProtected fIsProtected;
Brian Salomond17b4a62017-05-23 16:53:47 -0400424
Robert Phillips8bc06d02016-11-01 17:28:40 -0400425 // This entry is lazily evaluated so, when the proxy wraps a resource, the resource
426 // will be called but, when the proxy is deferred, it will compute the answer itself.
427 // If the proxy computes its own answer that answer is checked (in debug mode) in
428 // the instantiation method.
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400429 mutable size_t fGpuMemorySize;
Robert Phillips8bc06d02016-11-01 17:28:40 -0400430
Greg Danielf41b2bd2019-08-22 16:19:24 -0400431 // The last GrRenderTask that wrote to or is currently going to write to this surface
432 // The GrRenderTask can be closed (e.g., no surface context is currently bound
Robert Phillipsb6deea82017-05-11 14:14:30 -0400433 // to this proxy).
Robert Phillipsf2361d22016-10-25 14:20:06 -0400434 // This back-pointer is required so that we can add a dependancy between
Greg Danielf41b2bd2019-08-22 16:19:24 -0400435 // the GrRenderTask used to create the current contents of this surface
436 // and the GrRenderTask of a destination surface to which this one is being drawn or copied.
Chris Dalton6b498102019-08-01 14:14:52 -0600437 // This pointer is unreffed. GrRenderTasks own a ref on their surface proxies.
Brian Salomonbeb7f522019-08-30 16:19:42 -0400438 GrRenderTask* fLastRenderTask = nullptr;
robertphillips76948d42016-05-04 12:47:41 -0700439};
440
Chris Dalton4ece96d2019-08-30 11:26:39 -0600441GR_MAKE_BITFIELD_CLASS_OPS(GrSurfaceProxy::ResolveFlags)
442
robertphillips76948d42016-05-04 12:47:41 -0700443#endif