blob: 470ab7de6518b9e980d86004d53e00564e6ee131 [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 Phillips4bc70112018-03-01 10:24:02 -050060 void release() {
61 SkASSERT(1 == fRefCnt);
62 SkASSERT(0 == fPendingReads);
63 SkASSERT(0 == fPendingWrites);
64
65 SkASSERT(fTarget->internalHasUniqueRef());
66 SkASSERT(!fTarget->internalHasPendingIO());
67 fTarget->unref();
68 fTarget = nullptr;
69 }
70
Robert Phillipsc7635fa2016-10-28 13:25:24 -040071 void validate() const {
Robert Phillipsb6deea82017-05-11 14:14:30 -040072#ifdef SK_DEBUG
73 SkASSERT(fRefCnt >= 0);
robertphillips1125a032016-11-16 11:17:17 -080074 SkASSERT(fPendingReads >= 0);
75 SkASSERT(fPendingWrites >= 0);
76 SkASSERT(fRefCnt + fPendingReads + fPendingWrites >= 1);
77
78 if (fTarget) {
robertphillips1125a032016-11-16 11:17:17 -080079 // The backing GrSurface can have more refs than the proxy if the proxy
80 // started off wrapping an external resource (that came in with refs).
81 // The GrSurface should never have fewer refs than the proxy however.
82 SkASSERT(fTarget->fRefCnt >= fRefCnt);
Robert Phillipsb6deea82017-05-11 14:14:30 -040083 SkASSERT(fTarget->fPendingReads >= fPendingReads);
84 SkASSERT(fTarget->fPendingWrites >= fPendingWrites);
robertphillips1125a032016-11-16 11:17:17 -080085 }
Robert Phillipsc7635fa2016-10-28 13:25:24 -040086#endif
87 }
88
robertphillips1125a032016-11-16 11:17:17 -080089 int32_t getProxyRefCnt_TestOnly() const;
90 int32_t getBackingRefCnt_TestOnly() const;
91 int32_t getPendingReadCnt_TestOnly() const;
92 int32_t getPendingWriteCnt_TestOnly() const;
93
Brian Salomoncf75b002017-08-16 10:42:09 -040094 void addPendingRead() const {
95 this->validate();
96
97 ++fPendingReads;
98 if (fTarget) {
99 fTarget->addPendingRead();
100 }
101 }
102
103 void completedRead() const {
104 this->validate();
105
106 if (fTarget) {
107 fTarget->completedRead();
108 }
109
110 --fPendingReads;
111 this->didRemoveRefOrPendingIO();
112 }
113
114 void addPendingWrite() const {
115 this->validate();
116
117 ++fPendingWrites;
118 if (fTarget) {
119 fTarget->addPendingWrite();
120 }
121 }
122
123 void completedWrite() const {
124 this->validate();
125
126 if (fTarget) {
127 fTarget->completedWrite();
128 }
129
130 --fPendingWrites;
131 this->didRemoveRefOrPendingIO();
132 }
133
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400134protected:
robertphillips1125a032016-11-16 11:17:17 -0800135 GrIORefProxy() : fTarget(nullptr), fRefCnt(1), fPendingReads(0), fPendingWrites(0) {}
136 GrIORefProxy(sk_sp<GrSurface> surface) : fRefCnt(1), fPendingReads(0), fPendingWrites(0) {
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400137 // Since we're manually forwarding on refs & unrefs we don't want sk_sp doing
138 // anything extra.
139 fTarget = surface.release();
140 }
141 virtual ~GrIORefProxy() {
142 // We don't unref 'fTarget' here since the 'unref' method will already
Robert Phillips4bc70112018-03-01 10:24:02 -0500143 // have forwarded on the unref call that got us here.
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400144 }
145
robertphillips1125a032016-11-16 11:17:17 -0800146 // This GrIORefProxy was deferred before but has just been instantiated. To
147 // make all the reffing & unreffing work out we now need to transfer any deferred
148 // refs & unrefs to the new GrSurface
149 void transferRefs() {
150 SkASSERT(fTarget);
151
Robert Phillipsf8e25022017-11-08 15:24:31 -0500152 SkASSERT(fTarget->fRefCnt > 0);
Robert Phillips2d9cb572017-11-13 13:38:05 +0000153 fTarget->fRefCnt += (fRefCnt-1); // don't xfer the proxy's creation ref
robertphillips1125a032016-11-16 11:17:17 -0800154 fTarget->fPendingReads += fPendingReads;
155 fTarget->fPendingWrites += fPendingWrites;
robertphillips1125a032016-11-16 11:17:17 -0800156 }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400157
Robert Phillips757914d2017-01-25 15:48:30 -0500158 bool internalHasPendingIO() const {
159 if (fTarget) {
160 return fTarget->internalHasPendingIO();
161 }
162
163 return SkToBool(fPendingWrites | fPendingReads);
164 }
165
Robert Phillips7ee385e2017-03-30 08:02:11 -0400166 bool internalHasPendingWrite() const {
167 if (fTarget) {
168 return fTarget->internalHasPendingWrite();
169 }
170
171 return SkToBool(fPendingWrites);
172 }
173
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400174 // For deferred proxies this will be null. For wrapped proxies it will point to the
175 // wrapped resource.
176 GrSurface* fTarget;
robertphillips1125a032016-11-16 11:17:17 -0800177
178private:
179 // This class is used to manage conversion of refs to pending reads/writes.
Robert Phillipsb6deea82017-05-11 14:14:30 -0400180 friend class GrSurfaceProxyRef;
robertphillips1125a032016-11-16 11:17:17 -0800181 template <typename, GrIOType> friend class GrPendingIOResource;
182
Robert Phillipsb6deea82017-05-11 14:14:30 -0400183 void didRemoveRefOrPendingIO() const {
184 if (0 == fPendingReads && 0 == fPendingWrites && 0 == fRefCnt) {
185 delete this;
186 }
robertphillips1125a032016-11-16 11:17:17 -0800187 }
188
189 mutable int32_t fRefCnt;
190 mutable int32_t fPendingReads;
191 mutable int32_t fPendingWrites;
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400192};
193
194class GrSurfaceProxy : public GrIORefProxy {
robertphillips76948d42016-05-04 12:47:41 -0700195public:
Greg Daniel457469c2018-02-08 15:05:44 -0500196 enum class LazyInstantiationType {
197 kSingleUse, // Instantiation callback is allowed to be called only once
198 kMultipleUse, // Instantiation callback can be called multiple times.
199 };
200
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500201 enum class LazyState {
Greg Daniel0a375db2018-02-01 12:21:39 -0500202 kNot, // The proxy is instantiated or does not have a lazy callback
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500203 kPartially, // The proxy has a lazy callback but knows basic information about itself.
204 kFully, // The proxy has a lazy callback and also doesn't know its width, height, etc.
205 };
206
207 LazyState lazyInstantiationState() const {
Greg Daniel0a375db2018-02-01 12:21:39 -0500208 if (fTarget || !SkToBool(fLazyInstantiateCallback)) {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500209 return LazyState::kNot;
210 } else {
211 if (fWidth <= 0) {
212 SkASSERT(fHeight <= 0);
213 return LazyState::kFully;
214 } else {
215 SkASSERT(fHeight > 0);
216 return LazyState::kPartially;
217 }
218 }
219 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700220
221 GrPixelConfig config() const { return fConfig; }
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500222 int width() const {
223 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
224 return fWidth;
225 }
226 int height() const {
227 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
228 return fHeight;
229 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700230 int worstCaseWidth() const;
231 int worstCaseHeight() const;
robertphillips76948d42016-05-04 12:47:41 -0700232 GrSurfaceOrigin origin() const {
Brian Salomonbb5711a2017-05-17 13:49:59 -0400233 SkASSERT(kTopLeft_GrSurfaceOrigin == fOrigin || kBottomLeft_GrSurfaceOrigin == fOrigin);
234 return fOrigin;
robertphillips76948d42016-05-04 12:47:41 -0700235 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700236
Robert Phillips294870f2016-11-11 12:38:40 -0500237 class UniqueID {
238 public:
Robert Phillips7ee385e2017-03-30 08:02:11 -0400239 static UniqueID InvalidID() {
240 return UniqueID(uint32_t(SK_InvalidUniqueID));
241 }
242
Robert Phillips294870f2016-11-11 12:38:40 -0500243 // wrapped
244 explicit UniqueID(const GrGpuResource::UniqueID& id) : fID(id.asUInt()) { }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700245 // deferred and lazy-callback
Robert Phillips294870f2016-11-11 12:38:40 -0500246 UniqueID() : fID(GrGpuResource::CreateUniqueID()) { }
247
248 uint32_t asUInt() const { return fID; }
249
250 bool operator==(const UniqueID& other) const {
251 return fID == other.fID;
252 }
253 bool operator!=(const UniqueID& other) const {
254 return !(*this == other);
255 }
256
Robert Phillips7ee385e2017-03-30 08:02:11 -0400257 void makeInvalid() { fID = SK_InvalidUniqueID; }
Robert Phillips294870f2016-11-11 12:38:40 -0500258 bool isInvalid() const { return SK_InvalidUniqueID == fID; }
259
260 private:
Robert Phillips7ee385e2017-03-30 08:02:11 -0400261 explicit UniqueID(uint32_t id) : fID(id) {}
262
263 uint32_t fID;
Robert Phillips294870f2016-11-11 12:38:40 -0500264 };
265
266 /*
267 * The contract for the uniqueID is:
268 * for wrapped resources:
269 * the uniqueID will match that of the wrapped resource
270 *
271 * for deferred resources:
272 * the uniqueID will be different from the real resource, when it is allocated
273 * the proxy's uniqueID will not change across the instantiate call
274 *
275 * the uniqueIDs of the proxies and the resources draw from the same pool
276 *
277 * What this boils down to is that the uniqueID of a proxy can be used to consistently
278 * track/identify a proxy but should never be used to distinguish between
279 * resources and proxies - beware!
280 */
281 UniqueID uniqueID() const { return fUniqueID; }
robertphillips76948d42016-05-04 12:47:41 -0700282
Robert Phillips159e3c62017-06-19 12:02:00 -0400283 UniqueID underlyingUniqueID() const {
284 if (fTarget) {
285 return UniqueID(fTarget->uniqueID());
286 }
287
288 return fUniqueID;
289 }
290
Robert Phillipseee4d6e2017-06-05 09:26:07 -0400291 virtual bool instantiate(GrResourceProvider* resourceProvider) = 0;
Robert Phillips37430132016-11-09 06:50:43 -0500292
Robert Phillips4bc70112018-03-01 10:24:02 -0500293 void deInstantiate();
294
robertphillips76948d42016-05-04 12:47:41 -0700295 /**
robertphillips13a7eee2016-08-31 15:06:24 -0700296 * Helper that gets the width and height of the surface as a bounding rectangle.
297 */
Chris Dalton706a6ff2017-11-29 22:01:06 -0700298 SkRect getBoundsRect() const {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500299 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
Chris Dalton706a6ff2017-11-29 22:01:06 -0700300 return SkRect::MakeIWH(this->width(), this->height());
301 }
Robert Phillips784b7bf2016-12-09 13:35:02 -0500302
robertphillips13a7eee2016-08-31 15:06:24 -0700303 /**
robertphillips76948d42016-05-04 12:47:41 -0700304 * @return the texture proxy associated with the surface proxy, may be NULL.
305 */
306 virtual GrTextureProxy* asTextureProxy() { return nullptr; }
307 virtual const GrTextureProxy* asTextureProxy() const { return nullptr; }
308
309 /**
310 * @return the render target proxy associated with the surface proxy, may be NULL.
311 */
312 virtual GrRenderTargetProxy* asRenderTargetProxy() { return nullptr; }
313 virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; }
314
robertphillips13a7eee2016-08-31 15:06:24 -0700315 /**
316 * Does the resource count against the resource budget?
317 */
318 SkBudgeted isBudgeted() const { return fBudgeted; }
319
Robert Phillipsf2361d22016-10-25 14:20:06 -0400320 void setLastOpList(GrOpList* opList);
321 GrOpList* getLastOpList() { return fLastOpList; }
322
Brian Osman45580d32016-11-23 09:37:01 -0500323 GrRenderTargetOpList* getLastRenderTargetOpList();
324 GrTextureOpList* getLastTextureOpList();
325
Robert Phillips8bc06d02016-11-01 17:28:40 -0400326 /**
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400327 * Retrieves the amount of GPU memory that will be or currently is used by this resource
Robert Phillips8bc06d02016-11-01 17:28:40 -0400328 * in bytes. It is approximate since we aren't aware of additional padding or copies made
329 * by the driver.
330 *
331 * @return the amount of GPU memory used in bytes
332 */
333 size_t gpuMemorySize() const {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500334 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
Brian Salomonbb5711a2017-05-17 13:49:59 -0400335 if (fTarget) {
336 return fTarget->gpuMemorySize();
337 }
Robert Phillips8bc06d02016-11-01 17:28:40 -0400338 if (kInvalidGpuMemorySize == fGpuMemorySize) {
Brian Salomonbb5711a2017-05-17 13:49:59 -0400339 fGpuMemorySize = this->onUninstantiatedGpuMemorySize();
Robert Phillips8bc06d02016-11-01 17:28:40 -0400340 SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize);
341 }
342 return fGpuMemorySize;
343 }
344
Robert Phillipse2f7d182016-12-15 09:23:05 -0500345 // Helper function that creates a temporary SurfaceContext to perform the copy
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400346 // It always returns a kExact-backed proxy bc it is used when converting an SkSpecialImage
Brian Salomon63e79732017-05-15 21:23:13 -0400347 // to an SkImage. The copy is is not a render target and not multisampled.
Greg Daniel65c7f662017-10-30 13:39:09 -0400348 static sk_sp<GrTextureProxy> Copy(GrContext*, GrSurfaceProxy* src, GrMipMapped,
Robert Phillipse2f7d182016-12-15 09:23:05 -0500349 SkIRect srcRect, SkBudgeted);
350
351 // Copy the entire 'src'
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400352 // It always returns a kExact-backed proxy bc it is used in SkGpuDevice::snapSpecial
Greg Daniel65c7f662017-10-30 13:39:09 -0400353 static sk_sp<GrTextureProxy> Copy(GrContext* context, GrSurfaceProxy* src, GrMipMapped,
Robert Phillips63c67462017-02-15 14:19:01 -0500354 SkBudgeted budgeted);
Robert Phillipse2f7d182016-12-15 09:23:05 -0500355
356 // Test-only entry point - should decrease in use as proxies propagate
Robert Phillipsd46697a2017-01-25 12:10:37 -0500357 static sk_sp<GrSurfaceContext> TestCopy(GrContext* context, const GrSurfaceDesc& dstDesc,
Brian Salomon2a4f9832018-03-03 22:43:43 -0500358 GrSurfaceOrigin, GrSurfaceProxy* srcProxy);
Robert Phillipse2f7d182016-12-15 09:23:05 -0500359
Robert Phillipseaa86252016-11-08 13:49:39 +0000360 bool isWrapped_ForTesting() const;
361
Brian Osman45580d32016-11-23 09:37:01 -0500362 SkDEBUGCODE(void validate(GrContext*) const;)
363
Robert Phillips757914d2017-01-25 15:48:30 -0500364 // Provides access to functions that aren't part of the public API.
Robert Phillips420c4cf2017-09-28 09:00:45 -0400365 inline GrSurfaceProxyPriv priv();
366 inline const GrSurfaceProxyPriv priv() const;
Robert Phillips757914d2017-01-25 15:48:30 -0500367
robertphillips76948d42016-05-04 12:47:41 -0700368protected:
robertphillips8abb3702016-08-31 14:04:06 -0700369 // Deferred version
Brian Salomon2a4f9832018-03-03 22:43:43 -0500370 GrSurfaceProxy(const GrSurfaceDesc& desc, GrSurfaceOrigin origin, SkBackingFit fit,
371 SkBudgeted budgeted, uint32_t flags)
372 : GrSurfaceProxy(nullptr, LazyInstantiationType::kSingleUse, desc, origin, fit,
373 budgeted, flags) {
Robert Phillips294870f2016-11-11 12:38:40 -0500374 // Note: this ctor pulls a new uniqueID from the same pool at the GrGpuResources
robertphillips8abb3702016-08-31 14:04:06 -0700375 }
376
Robert Phillipsce5209a2018-02-13 11:13:51 -0500377 using LazyInstantiateCallback = std::function<sk_sp<GrSurface>(GrResourceProvider*)>;
Robert Phillips777707b2018-01-17 11:40:14 -0500378
Chris Dalton706a6ff2017-11-29 22:01:06 -0700379 // Lazy-callback version
Greg Daniel457469c2018-02-08 15:05:44 -0500380 GrSurfaceProxy(LazyInstantiateCallback&& callback, LazyInstantiationType lazyType,
Brian Salomon2a4f9832018-03-03 22:43:43 -0500381 const GrSurfaceDesc& desc, GrSurfaceOrigin origin, SkBackingFit fit,
382 SkBudgeted budgeted, uint32_t flags);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700383
robertphillips8abb3702016-08-31 14:04:06 -0700384 // Wrapped version
Robert Phillips066f0202017-07-25 10:16:35 -0400385 GrSurfaceProxy(sk_sp<GrSurface> surface, GrSurfaceOrigin origin, SkBackingFit fit);
robertphillips76948d42016-05-04 12:47:41 -0700386
Robert Phillipsf2361d22016-10-25 14:20:06 -0400387 virtual ~GrSurfaceProxy();
388
Robert Phillips757914d2017-01-25 15:48:30 -0500389 friend class GrSurfaceProxyPriv;
390
391 // Methods made available via GrSurfaceProxyPriv
392 bool hasPendingIO() const {
393 return this->internalHasPendingIO();
394 }
395
Robert Phillips7ee385e2017-03-30 08:02:11 -0400396 bool hasPendingWrite() const {
397 return this->internalHasPendingWrite();
398 }
399
Robert Phillips57aa3672017-07-21 11:38:13 -0400400 void computeScratchKey(GrScratchKey*) const;
401
Robert Phillips5af44de2017-07-18 14:49:38 -0400402 virtual sk_sp<GrSurface> createSurface(GrResourceProvider*) const = 0;
403 void assign(sk_sp<GrSurface> surface);
404
Robert Phillips65048132017-08-10 08:44:49 -0400405 sk_sp<GrSurface> createSurfaceImpl(GrResourceProvider*, int sampleCnt, bool needsStencil,
Greg Danield2d8e922018-02-12 12:07:39 -0500406 GrSurfaceFlags flags, GrMipMapped mipMapped) const;
Robert Phillips5af44de2017-07-18 14:49:38 -0400407
Robert Phillips65048132017-08-10 08:44:49 -0400408 bool instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt, bool needsStencil,
Greg Danield2d8e922018-02-12 12:07:39 -0500409 GrSurfaceFlags flags, GrMipMapped mipMapped, const GrUniqueKey*);
Brian Salomonbb5711a2017-05-17 13:49:59 -0400410
Chris Dalton706a6ff2017-11-29 22:01:06 -0700411private:
Brian Salomonbb5711a2017-05-17 13:49:59 -0400412 // For wrapped resources, 'fConfig', 'fWidth', 'fHeight', and 'fOrigin; will always be filled in
413 // from the wrapped resource.
414 GrPixelConfig fConfig;
415 int fWidth;
416 int fHeight;
417 GrSurfaceOrigin fOrigin;
Chris Dalton706a6ff2017-11-29 22:01:06 -0700418 SkBackingFit fFit; // always kApprox for lazy-callback resources
419 // always kExact for wrapped resources
420 mutable SkBudgeted fBudgeted; // always kYes for lazy-callback resources
421 // set from the backing resource for wrapped resources
Robert Phillipsb726d582017-03-09 16:36:32 -0500422 // mutable bc of SkSurface/SkImage wishy-washiness
Robert Phillipsc787e492017-02-28 11:26:32 -0500423 const uint32_t fFlags;
Robert Phillipsa4c41b32017-03-15 13:02:45 -0400424
Robert Phillips294870f2016-11-11 12:38:40 -0500425 const UniqueID fUniqueID; // set from the backing resource for wrapped resources
robertphillips76948d42016-05-04 12:47:41 -0700426
Chris Dalton706a6ff2017-11-29 22:01:06 -0700427 LazyInstantiateCallback fLazyInstantiateCallback;
Greg Daniel457469c2018-02-08 15:05:44 -0500428 // If this is set to kSingleuse, then after one call to fLazyInstantiateCallback we will cleanup
429 // the lazy callback and then delete it. This will allow for any refs and resources being held
430 // by the standard function to be released. This is specifically useful in non-dll cases where
431 // we make lazy proxies and instantiate them immediately.
432 // Note: This is ignored if fLazyInstantiateCallback is null.
433 LazyInstantiationType fLazyInstantiationType;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500434 SkDEBUGCODE(virtual void validateLazySurface(const GrSurface*) = 0;)
Chris Dalton706a6ff2017-11-29 22:01:06 -0700435
Robert Phillips8bc06d02016-11-01 17:28:40 -0400436 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
Robert Phillips29e52f12016-11-03 10:19:14 -0400437 SkDEBUGCODE(size_t getRawGpuMemorySize_debugOnly() const { return fGpuMemorySize; })
438
Brian Salomonbb5711a2017-05-17 13:49:59 -0400439 virtual size_t onUninstantiatedGpuMemorySize() const = 0;
Robert Phillips29e52f12016-11-03 10:19:14 -0400440
Brian Salomond17b4a62017-05-23 16:53:47 -0400441 bool fNeedsClear;
442
Robert Phillips8bc06d02016-11-01 17:28:40 -0400443 // This entry is lazily evaluated so, when the proxy wraps a resource, the resource
444 // will be called but, when the proxy is deferred, it will compute the answer itself.
445 // If the proxy computes its own answer that answer is checked (in debug mode) in
446 // the instantiation method.
447 mutable size_t fGpuMemorySize;
448
Robert Phillipsf2361d22016-10-25 14:20:06 -0400449 // The last opList that wrote to or is currently going to write to this surface
Robert Phillipsb6deea82017-05-11 14:14:30 -0400450 // The opList can be closed (e.g., no surface context is currently bound
451 // to this proxy).
Robert Phillipsf2361d22016-10-25 14:20:06 -0400452 // This back-pointer is required so that we can add a dependancy between
453 // the opList used to create the current contents of this surface
454 // and the opList of a destination surface to which this one is being drawn or copied.
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400455 // This pointer is unreffed. OpLists own a ref on their surface proxies.
Robert Phillipsf2361d22016-10-25 14:20:06 -0400456 GrOpList* fLastOpList;
457
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400458 typedef GrIORefProxy INHERITED;
robertphillips76948d42016-05-04 12:47:41 -0700459};
460
461#endif