blob: 5a2a4b536ecde9f8c44476bbc4fccbf440a5a3ba [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
11#include "GrGpuResource.h"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040012#include "GrSurface.h"
Robert Phillips93f16332016-11-23 19:37:13 -050013
csmartdaltonbf4a8f92016-09-06 10:01:06 -070014#include "SkRect.h"
robertphillips76948d42016-05-04 12:47:41 -070015
Greg Daniel7ef28f32017-04-20 16:41:55 +000016class GrBackendTexture;
Robert Phillips37430132016-11-09 06:50:43 -050017class GrCaps;
Robert Phillipsc589b0b2017-04-17 07:53:07 -040018class GrOpList;
Robert Phillips1afd4cd2018-01-08 13:40:32 -050019class GrProxyProvider;
Brian Osman45580d32016-11-23 09:37:01 -050020class GrRenderTargetOpList;
21class GrRenderTargetProxy;
Brian Osman32342f02017-03-04 08:12:46 -050022class GrResourceProvider;
Robert Phillipsd46697a2017-01-25 12:10:37 -050023class GrSurfaceContext;
Robert Phillips757914d2017-01-25 15:48:30 -050024class GrSurfaceProxyPriv;
Brian Osman45580d32016-11-23 09:37:01 -050025class GrTextureOpList;
robertphillips76948d42016-05-04 12:47:41 -070026class GrTextureProxy;
robertphillips76948d42016-05-04 12:47:41 -070027
Robert Phillipsc7635fa2016-10-28 13:25:24 -040028// This class replicates the functionality GrIORef<GrSurface> but tracks the
29// utilitization for later resource allocation (for the deferred case) and
30// forwards on the utilization in the wrapped case
31class GrIORefProxy : public SkNoncopyable {
32public:
33 void ref() const {
34 this->validate();
35
36 ++fRefCnt;
37 if (fTarget) {
38 fTarget->ref();
39 }
40 }
41
42 void unref() const {
43 this->validate();
44
45 if (fTarget) {
46 fTarget->unref();
47 }
48
Robert Phillipsb6deea82017-05-11 14:14:30 -040049 --fRefCnt;
50 this->didRemoveRefOrPendingIO();
Robert Phillipsc7635fa2016-10-28 13:25:24 -040051 }
52
Chris Daltona32a3c32017-12-05 10:05:21 -070053#ifdef SK_DEBUG
54 bool isUnique_debugOnly() const { // For asserts.
55 SkASSERT(fRefCnt >= 0 && fPendingWrites >= 0 && fPendingReads >= 0);
56 return 1 == fRefCnt + fPendingWrites + fPendingReads;
57 }
58#endif
59
Robert Phillipsc7635fa2016-10-28 13:25:24 -040060 void validate() const {
Robert Phillipsb6deea82017-05-11 14:14:30 -040061#ifdef SK_DEBUG
62 SkASSERT(fRefCnt >= 0);
robertphillips1125a032016-11-16 11:17:17 -080063 SkASSERT(fPendingReads >= 0);
64 SkASSERT(fPendingWrites >= 0);
65 SkASSERT(fRefCnt + fPendingReads + fPendingWrites >= 1);
66
67 if (fTarget) {
robertphillips1125a032016-11-16 11:17:17 -080068 // The backing GrSurface can have more refs than the proxy if the proxy
69 // started off wrapping an external resource (that came in with refs).
70 // The GrSurface should never have fewer refs than the proxy however.
71 SkASSERT(fTarget->fRefCnt >= fRefCnt);
Robert Phillipsb6deea82017-05-11 14:14:30 -040072 SkASSERT(fTarget->fPendingReads >= fPendingReads);
73 SkASSERT(fTarget->fPendingWrites >= fPendingWrites);
robertphillips1125a032016-11-16 11:17:17 -080074 }
Robert Phillipsc7635fa2016-10-28 13:25:24 -040075#endif
76 }
77
robertphillips1125a032016-11-16 11:17:17 -080078 int32_t getProxyRefCnt_TestOnly() const;
79 int32_t getBackingRefCnt_TestOnly() const;
80 int32_t getPendingReadCnt_TestOnly() const;
81 int32_t getPendingWriteCnt_TestOnly() const;
82
Brian Salomoncf75b002017-08-16 10:42:09 -040083 void addPendingRead() const {
84 this->validate();
85
86 ++fPendingReads;
87 if (fTarget) {
88 fTarget->addPendingRead();
89 }
90 }
91
92 void completedRead() const {
93 this->validate();
94
95 if (fTarget) {
96 fTarget->completedRead();
97 }
98
99 --fPendingReads;
100 this->didRemoveRefOrPendingIO();
101 }
102
103 void addPendingWrite() const {
104 this->validate();
105
106 ++fPendingWrites;
107 if (fTarget) {
108 fTarget->addPendingWrite();
109 }
110 }
111
112 void completedWrite() const {
113 this->validate();
114
115 if (fTarget) {
116 fTarget->completedWrite();
117 }
118
119 --fPendingWrites;
120 this->didRemoveRefOrPendingIO();
121 }
122
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400123protected:
robertphillips1125a032016-11-16 11:17:17 -0800124 GrIORefProxy() : fTarget(nullptr), fRefCnt(1), fPendingReads(0), fPendingWrites(0) {}
125 GrIORefProxy(sk_sp<GrSurface> surface) : fRefCnt(1), fPendingReads(0), fPendingWrites(0) {
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400126 // Since we're manually forwarding on refs & unrefs we don't want sk_sp doing
127 // anything extra.
128 fTarget = surface.release();
129 }
130 virtual ~GrIORefProxy() {
131 // We don't unref 'fTarget' here since the 'unref' method will already
132 // have forwarded on the unref call that got use here.
133 }
134
robertphillips1125a032016-11-16 11:17:17 -0800135 // This GrIORefProxy was deferred before but has just been instantiated. To
136 // make all the reffing & unreffing work out we now need to transfer any deferred
137 // refs & unrefs to the new GrSurface
138 void transferRefs() {
139 SkASSERT(fTarget);
140
Robert Phillipsf8e25022017-11-08 15:24:31 -0500141 SkASSERT(fTarget->fRefCnt > 0);
Robert Phillips2d9cb572017-11-13 13:38:05 +0000142 fTarget->fRefCnt += (fRefCnt-1); // don't xfer the proxy's creation ref
robertphillips1125a032016-11-16 11:17:17 -0800143 fTarget->fPendingReads += fPendingReads;
144 fTarget->fPendingWrites += fPendingWrites;
robertphillips1125a032016-11-16 11:17:17 -0800145 }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400146
Robert Phillips757914d2017-01-25 15:48:30 -0500147 bool internalHasPendingIO() const {
148 if (fTarget) {
149 return fTarget->internalHasPendingIO();
150 }
151
152 return SkToBool(fPendingWrites | fPendingReads);
153 }
154
Robert Phillips7ee385e2017-03-30 08:02:11 -0400155 bool internalHasPendingWrite() const {
156 if (fTarget) {
157 return fTarget->internalHasPendingWrite();
158 }
159
160 return SkToBool(fPendingWrites);
161 }
162
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400163 // For deferred proxies this will be null. For wrapped proxies it will point to the
164 // wrapped resource.
165 GrSurface* fTarget;
robertphillips1125a032016-11-16 11:17:17 -0800166
167private:
168 // This class is used to manage conversion of refs to pending reads/writes.
Robert Phillipsb6deea82017-05-11 14:14:30 -0400169 friend class GrSurfaceProxyRef;
robertphillips1125a032016-11-16 11:17:17 -0800170 template <typename, GrIOType> friend class GrPendingIOResource;
171
Robert Phillipsb6deea82017-05-11 14:14:30 -0400172 void didRemoveRefOrPendingIO() const {
173 if (0 == fPendingReads && 0 == fPendingWrites && 0 == fRefCnt) {
174 delete this;
175 }
robertphillips1125a032016-11-16 11:17:17 -0800176 }
177
178 mutable int32_t fRefCnt;
179 mutable int32_t fPendingReads;
180 mutable int32_t fPendingWrites;
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400181};
182
183class GrSurfaceProxy : public GrIORefProxy {
robertphillips76948d42016-05-04 12:47:41 -0700184public:
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500185 // DDL TODO: remove this entry point
Robert Phillips066f0202017-07-25 10:16:35 -0400186 static sk_sp<GrTextureProxy> MakeWrapped(sk_sp<GrTexture>, GrSurfaceOrigin);
Robert Phillips37430132016-11-09 06:50:43 -0500187
Chris Dalton706a6ff2017-11-29 22:01:06 -0700188 using LazyInstantiateCallback = std::function<sk_sp<GrTexture>(GrResourceProvider*,
189 GrSurfaceOrigin* outOrigin)>;
190
191 enum class Renderable : bool {
192 kNo = false,
193 kYes = true
194 };
195
196 /**
197 * Creates a texture proxy that will be instantiated by a user-supplied callback during flush.
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500198 * (Stencil is not supported by this method.) The width and height must either both be greater
199 * than 0 or both less than or equal to zero. A non-positive value is a signal that the width
200 * and height are currently unknown.
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500201 * DDL TODO: remove this entry point
Chris Dalton706a6ff2017-11-29 22:01:06 -0700202 */
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500203 static sk_sp<GrTextureProxy> MakeLazy(LazyInstantiateCallback&&, const GrSurfaceDesc& desc,
204 GrMipMapped, SkBackingFit fit, SkBudgeted budgeted);
205
206 static sk_sp<GrTextureProxy> MakeFullyLazy(LazyInstantiateCallback&&, Renderable,
207 GrPixelConfig);
208
209 enum class LazyState {
210 kNot, // The proxy has no lazy callback that must be made.
211 kPartially, // The proxy has a lazy callback but knows basic information about itself.
212 kFully, // The proxy has a lazy callback and also doesn't know its width, height, etc.
213 };
214
215 LazyState lazyInstantiationState() const {
216 if (!SkToBool(fLazyInstantiateCallback)) {
217 return LazyState::kNot;
218 } else {
219 if (fWidth <= 0) {
220 SkASSERT(fHeight <= 0);
221 return LazyState::kFully;
222 } else {
223 SkASSERT(fHeight > 0);
224 return LazyState::kPartially;
225 }
226 }
227 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700228
229 GrPixelConfig config() const { return fConfig; }
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500230 int width() const {
231 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
232 return fWidth;
233 }
234 int height() const {
235 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
236 return fHeight;
237 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700238 int worstCaseWidth() const;
239 int worstCaseHeight() const;
robertphillips76948d42016-05-04 12:47:41 -0700240 GrSurfaceOrigin origin() const {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500241 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
Brian Salomonbb5711a2017-05-17 13:49:59 -0400242 SkASSERT(kTopLeft_GrSurfaceOrigin == fOrigin || kBottomLeft_GrSurfaceOrigin == fOrigin);
243 return fOrigin;
robertphillips76948d42016-05-04 12:47:41 -0700244 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700245
Robert Phillips294870f2016-11-11 12:38:40 -0500246 class UniqueID {
247 public:
Robert Phillips7ee385e2017-03-30 08:02:11 -0400248 static UniqueID InvalidID() {
249 return UniqueID(uint32_t(SK_InvalidUniqueID));
250 }
251
Robert Phillips294870f2016-11-11 12:38:40 -0500252 // wrapped
253 explicit UniqueID(const GrGpuResource::UniqueID& id) : fID(id.asUInt()) { }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700254 // deferred and lazy-callback
Robert Phillips294870f2016-11-11 12:38:40 -0500255 UniqueID() : fID(GrGpuResource::CreateUniqueID()) { }
256
257 uint32_t asUInt() const { return fID; }
258
259 bool operator==(const UniqueID& other) const {
260 return fID == other.fID;
261 }
262 bool operator!=(const UniqueID& other) const {
263 return !(*this == other);
264 }
265
Robert Phillips7ee385e2017-03-30 08:02:11 -0400266 void makeInvalid() { fID = SK_InvalidUniqueID; }
Robert Phillips294870f2016-11-11 12:38:40 -0500267 bool isInvalid() const { return SK_InvalidUniqueID == fID; }
268
269 private:
Robert Phillips7ee385e2017-03-30 08:02:11 -0400270 explicit UniqueID(uint32_t id) : fID(id) {}
271
272 uint32_t fID;
Robert Phillips294870f2016-11-11 12:38:40 -0500273 };
274
275 /*
276 * The contract for the uniqueID is:
277 * for wrapped resources:
278 * the uniqueID will match that of the wrapped resource
279 *
280 * for deferred resources:
281 * the uniqueID will be different from the real resource, when it is allocated
282 * the proxy's uniqueID will not change across the instantiate call
283 *
284 * the uniqueIDs of the proxies and the resources draw from the same pool
285 *
286 * What this boils down to is that the uniqueID of a proxy can be used to consistently
287 * track/identify a proxy but should never be used to distinguish between
288 * resources and proxies - beware!
289 */
290 UniqueID uniqueID() const { return fUniqueID; }
robertphillips76948d42016-05-04 12:47:41 -0700291
Robert Phillips159e3c62017-06-19 12:02:00 -0400292 UniqueID underlyingUniqueID() const {
293 if (fTarget) {
294 return UniqueID(fTarget->uniqueID());
295 }
296
297 return fUniqueID;
298 }
299
Robert Phillipseee4d6e2017-06-05 09:26:07 -0400300 virtual bool instantiate(GrResourceProvider* resourceProvider) = 0;
Robert Phillips37430132016-11-09 06:50:43 -0500301
robertphillips76948d42016-05-04 12:47:41 -0700302 /**
robertphillips13a7eee2016-08-31 15:06:24 -0700303 * Helper that gets the width and height of the surface as a bounding rectangle.
304 */
Chris Dalton706a6ff2017-11-29 22:01:06 -0700305 SkRect getBoundsRect() const {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500306 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
Chris Dalton706a6ff2017-11-29 22:01:06 -0700307 return SkRect::MakeIWH(this->width(), this->height());
308 }
Robert Phillips784b7bf2016-12-09 13:35:02 -0500309
robertphillips13a7eee2016-08-31 15:06:24 -0700310 /**
robertphillips76948d42016-05-04 12:47:41 -0700311 * @return the texture proxy associated with the surface proxy, may be NULL.
312 */
313 virtual GrTextureProxy* asTextureProxy() { return nullptr; }
314 virtual const GrTextureProxy* asTextureProxy() const { return nullptr; }
315
316 /**
317 * @return the render target proxy associated with the surface proxy, may be NULL.
318 */
319 virtual GrRenderTargetProxy* asRenderTargetProxy() { return nullptr; }
320 virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; }
321
robertphillips13a7eee2016-08-31 15:06:24 -0700322 /**
323 * Does the resource count against the resource budget?
324 */
325 SkBudgeted isBudgeted() const { return fBudgeted; }
326
Robert Phillipsf2361d22016-10-25 14:20:06 -0400327 void setLastOpList(GrOpList* opList);
328 GrOpList* getLastOpList() { return fLastOpList; }
329
Brian Osman45580d32016-11-23 09:37:01 -0500330 GrRenderTargetOpList* getLastRenderTargetOpList();
331 GrTextureOpList* getLastTextureOpList();
332
Robert Phillips8bc06d02016-11-01 17:28:40 -0400333 /**
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400334 * Retrieves the amount of GPU memory that will be or currently is used by this resource
Robert Phillips8bc06d02016-11-01 17:28:40 -0400335 * in bytes. It is approximate since we aren't aware of additional padding or copies made
336 * by the driver.
337 *
338 * @return the amount of GPU memory used in bytes
339 */
340 size_t gpuMemorySize() const {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500341 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
Brian Salomonbb5711a2017-05-17 13:49:59 -0400342 if (fTarget) {
343 return fTarget->gpuMemorySize();
344 }
Robert Phillips8bc06d02016-11-01 17:28:40 -0400345 if (kInvalidGpuMemorySize == fGpuMemorySize) {
Brian Salomonbb5711a2017-05-17 13:49:59 -0400346 fGpuMemorySize = this->onUninstantiatedGpuMemorySize();
Robert Phillips8bc06d02016-11-01 17:28:40 -0400347 SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize);
348 }
349 return fGpuMemorySize;
350 }
351
Robert Phillipse2f7d182016-12-15 09:23:05 -0500352 // Helper function that creates a temporary SurfaceContext to perform the copy
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400353 // It always returns a kExact-backed proxy bc it is used when converting an SkSpecialImage
Brian Salomon63e79732017-05-15 21:23:13 -0400354 // to an SkImage. The copy is is not a render target and not multisampled.
Greg Daniel65c7f662017-10-30 13:39:09 -0400355 static sk_sp<GrTextureProxy> Copy(GrContext*, GrSurfaceProxy* src, GrMipMapped,
Robert Phillipse2f7d182016-12-15 09:23:05 -0500356 SkIRect srcRect, SkBudgeted);
357
358 // Copy the entire 'src'
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400359 // It always returns a kExact-backed proxy bc it is used in SkGpuDevice::snapSpecial
Greg Daniel65c7f662017-10-30 13:39:09 -0400360 static sk_sp<GrTextureProxy> Copy(GrContext* context, GrSurfaceProxy* src, GrMipMapped,
Robert Phillips63c67462017-02-15 14:19:01 -0500361 SkBudgeted budgeted);
Robert Phillipse2f7d182016-12-15 09:23:05 -0500362
363 // Test-only entry point - should decrease in use as proxies propagate
Robert Phillipsd46697a2017-01-25 12:10:37 -0500364 static sk_sp<GrSurfaceContext> TestCopy(GrContext* context, const GrSurfaceDesc& dstDesc,
365 GrSurfaceProxy* srcProxy);
Robert Phillipse2f7d182016-12-15 09:23:05 -0500366
Robert Phillipseaa86252016-11-08 13:49:39 +0000367 bool isWrapped_ForTesting() const;
368
Brian Osman45580d32016-11-23 09:37:01 -0500369 SkDEBUGCODE(void validate(GrContext*) const;)
370
Robert Phillips757914d2017-01-25 15:48:30 -0500371 // Provides access to functions that aren't part of the public API.
Robert Phillips420c4cf2017-09-28 09:00:45 -0400372 inline GrSurfaceProxyPriv priv();
373 inline const GrSurfaceProxyPriv priv() const;
Robert Phillips757914d2017-01-25 15:48:30 -0500374
robertphillips76948d42016-05-04 12:47:41 -0700375protected:
robertphillips8abb3702016-08-31 14:04:06 -0700376 // Deferred version
Robert Phillipsc787e492017-02-28 11:26:32 -0500377 GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted, uint32_t flags)
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500378 : GrSurfaceProxy(nullptr, desc, fit, budgeted, flags) {
Robert Phillips294870f2016-11-11 12:38:40 -0500379 // Note: this ctor pulls a new uniqueID from the same pool at the GrGpuResources
robertphillips8abb3702016-08-31 14:04:06 -0700380 }
381
Chris Dalton706a6ff2017-11-29 22:01:06 -0700382 // Lazy-callback version
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500383 GrSurfaceProxy(LazyInstantiateCallback&& callback, const GrSurfaceDesc& desc,
384 SkBackingFit fit, SkBudgeted budgeted, uint32_t flags);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700385
robertphillips8abb3702016-08-31 14:04:06 -0700386 // Wrapped version
Robert Phillips066f0202017-07-25 10:16:35 -0400387 GrSurfaceProxy(sk_sp<GrSurface> surface, GrSurfaceOrigin origin, SkBackingFit fit);
robertphillips76948d42016-05-04 12:47:41 -0700388
Robert Phillipsf2361d22016-10-25 14:20:06 -0400389 virtual ~GrSurfaceProxy();
390
Robert Phillips757914d2017-01-25 15:48:30 -0500391 friend class GrSurfaceProxyPriv;
392
393 // Methods made available via GrSurfaceProxyPriv
394 bool hasPendingIO() const {
395 return this->internalHasPendingIO();
396 }
397
Robert Phillips7ee385e2017-03-30 08:02:11 -0400398 bool hasPendingWrite() const {
399 return this->internalHasPendingWrite();
400 }
401
Robert Phillips57aa3672017-07-21 11:38:13 -0400402 void computeScratchKey(GrScratchKey*) const;
403
Robert Phillips5af44de2017-07-18 14:49:38 -0400404 virtual sk_sp<GrSurface> createSurface(GrResourceProvider*) const = 0;
405 void assign(sk_sp<GrSurface> surface);
406
Robert Phillips65048132017-08-10 08:44:49 -0400407 sk_sp<GrSurface> createSurfaceImpl(GrResourceProvider*, int sampleCnt, bool needsStencil,
Greg Daniele252f082017-10-23 16:05:23 -0400408 GrSurfaceFlags flags, GrMipMapped mipMapped,
Robert Phillips5af44de2017-07-18 14:49:38 -0400409 SkDestinationSurfaceColorMode mipColorMode) const;
410
Robert Phillips65048132017-08-10 08:44:49 -0400411 bool instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt, bool needsStencil,
Greg Daniele252f082017-10-23 16:05:23 -0400412 GrSurfaceFlags flags, GrMipMapped mipMapped,
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400413 SkDestinationSurfaceColorMode mipColorMode, const GrUniqueKey*);
Brian Salomonbb5711a2017-05-17 13:49:59 -0400414
Chris Dalton706a6ff2017-11-29 22:01:06 -0700415private:
Brian Salomonbb5711a2017-05-17 13:49:59 -0400416 // For wrapped resources, 'fConfig', 'fWidth', 'fHeight', and 'fOrigin; will always be filled in
417 // from the wrapped resource.
418 GrPixelConfig fConfig;
419 int fWidth;
420 int fHeight;
421 GrSurfaceOrigin fOrigin;
Chris Dalton706a6ff2017-11-29 22:01:06 -0700422 SkBackingFit fFit; // always kApprox for lazy-callback resources
423 // always kExact for wrapped resources
424 mutable SkBudgeted fBudgeted; // always kYes for lazy-callback resources
425 // set from the backing resource for wrapped resources
Robert Phillipsb726d582017-03-09 16:36:32 -0500426 // mutable bc of SkSurface/SkImage wishy-washiness
Robert Phillipsc787e492017-02-28 11:26:32 -0500427 const uint32_t fFlags;
Robert Phillipsa4c41b32017-03-15 13:02:45 -0400428
Robert Phillips294870f2016-11-11 12:38:40 -0500429 const UniqueID fUniqueID; // set from the backing resource for wrapped resources
robertphillips76948d42016-05-04 12:47:41 -0700430
Chris Dalton706a6ff2017-11-29 22:01:06 -0700431 LazyInstantiateCallback fLazyInstantiateCallback;
432 SkDEBUGCODE(virtual void validateLazyTexture(const GrTexture*) = 0;)
433
Robert Phillips8bc06d02016-11-01 17:28:40 -0400434 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
Robert Phillips29e52f12016-11-03 10:19:14 -0400435 SkDEBUGCODE(size_t getRawGpuMemorySize_debugOnly() const { return fGpuMemorySize; })
436
Brian Salomonbb5711a2017-05-17 13:49:59 -0400437 virtual size_t onUninstantiatedGpuMemorySize() const = 0;
Robert Phillips29e52f12016-11-03 10:19:14 -0400438
Brian Salomond17b4a62017-05-23 16:53:47 -0400439 bool fNeedsClear;
440
Robert Phillips8bc06d02016-11-01 17:28:40 -0400441 // This entry is lazily evaluated so, when the proxy wraps a resource, the resource
442 // will be called but, when the proxy is deferred, it will compute the answer itself.
443 // If the proxy computes its own answer that answer is checked (in debug mode) in
444 // the instantiation method.
445 mutable size_t fGpuMemorySize;
446
Robert Phillipsf2361d22016-10-25 14:20:06 -0400447 // The last opList that wrote to or is currently going to write to this surface
Robert Phillipsb6deea82017-05-11 14:14:30 -0400448 // The opList can be closed (e.g., no surface context is currently bound
449 // to this proxy).
Robert Phillipsf2361d22016-10-25 14:20:06 -0400450 // This back-pointer is required so that we can add a dependancy between
451 // the opList used to create the current contents of this surface
452 // and the opList of a destination surface to which this one is being drawn or copied.
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400453 // This pointer is unreffed. OpLists own a ref on their surface proxies.
Robert Phillipsf2361d22016-10-25 14:20:06 -0400454 GrOpList* fLastOpList;
455
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400456 typedef GrIORefProxy INHERITED;
robertphillips76948d42016-05-04 12:47:41 -0700457};
458
459#endif