blob: d90c408ba626ec352ae07f9a4cd6ff5c0b0b2e59 [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() {
Greg Daniel4684f822018-03-08 15:27:36 -050061 // The proxy itself may still have multiple refs. It can be owned by an SkImage and multiple
62 // SkDeferredDisplayLists at the same time if we are using DDLs.
Robert Phillips4bc70112018-03-01 10:24:02 -050063 SkASSERT(0 == fPendingReads);
64 SkASSERT(0 == fPendingWrites);
65
66 SkASSERT(fTarget->internalHasUniqueRef());
67 SkASSERT(!fTarget->internalHasPendingIO());
68 fTarget->unref();
69 fTarget = nullptr;
70 }
71
Robert Phillipsc7635fa2016-10-28 13:25:24 -040072 void validate() const {
Robert Phillipsb6deea82017-05-11 14:14:30 -040073#ifdef SK_DEBUG
74 SkASSERT(fRefCnt >= 0);
robertphillips1125a032016-11-16 11:17:17 -080075 SkASSERT(fPendingReads >= 0);
76 SkASSERT(fPendingWrites >= 0);
77 SkASSERT(fRefCnt + fPendingReads + fPendingWrites >= 1);
78
79 if (fTarget) {
robertphillips1125a032016-11-16 11:17:17 -080080 // The backing GrSurface can have more refs than the proxy if the proxy
81 // started off wrapping an external resource (that came in with refs).
82 // The GrSurface should never have fewer refs than the proxy however.
83 SkASSERT(fTarget->fRefCnt >= fRefCnt);
Robert Phillipsb6deea82017-05-11 14:14:30 -040084 SkASSERT(fTarget->fPendingReads >= fPendingReads);
85 SkASSERT(fTarget->fPendingWrites >= fPendingWrites);
robertphillips1125a032016-11-16 11:17:17 -080086 }
Robert Phillipsc7635fa2016-10-28 13:25:24 -040087#endif
88 }
89
robertphillips1125a032016-11-16 11:17:17 -080090 int32_t getProxyRefCnt_TestOnly() const;
91 int32_t getBackingRefCnt_TestOnly() const;
92 int32_t getPendingReadCnt_TestOnly() const;
93 int32_t getPendingWriteCnt_TestOnly() const;
94
Brian Salomoncf75b002017-08-16 10:42:09 -040095 void addPendingRead() const {
96 this->validate();
97
98 ++fPendingReads;
99 if (fTarget) {
100 fTarget->addPendingRead();
101 }
102 }
103
104 void completedRead() const {
105 this->validate();
106
107 if (fTarget) {
108 fTarget->completedRead();
109 }
110
111 --fPendingReads;
112 this->didRemoveRefOrPendingIO();
113 }
114
115 void addPendingWrite() const {
116 this->validate();
117
118 ++fPendingWrites;
119 if (fTarget) {
120 fTarget->addPendingWrite();
121 }
122 }
123
124 void completedWrite() const {
125 this->validate();
126
127 if (fTarget) {
128 fTarget->completedWrite();
129 }
130
131 --fPendingWrites;
132 this->didRemoveRefOrPendingIO();
133 }
134
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400135protected:
robertphillips1125a032016-11-16 11:17:17 -0800136 GrIORefProxy() : fTarget(nullptr), fRefCnt(1), fPendingReads(0), fPendingWrites(0) {}
137 GrIORefProxy(sk_sp<GrSurface> surface) : fRefCnt(1), fPendingReads(0), fPendingWrites(0) {
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400138 // Since we're manually forwarding on refs & unrefs we don't want sk_sp doing
139 // anything extra.
140 fTarget = surface.release();
141 }
142 virtual ~GrIORefProxy() {
143 // We don't unref 'fTarget' here since the 'unref' method will already
Robert Phillips4bc70112018-03-01 10:24:02 -0500144 // have forwarded on the unref call that got us here.
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400145 }
146
robertphillips1125a032016-11-16 11:17:17 -0800147 // This GrIORefProxy was deferred before but has just been instantiated. To
148 // make all the reffing & unreffing work out we now need to transfer any deferred
149 // refs & unrefs to the new GrSurface
150 void transferRefs() {
151 SkASSERT(fTarget);
152
Robert Phillipsf8e25022017-11-08 15:24:31 -0500153 SkASSERT(fTarget->fRefCnt > 0);
Robert Phillips2d9cb572017-11-13 13:38:05 +0000154 fTarget->fRefCnt += (fRefCnt-1); // don't xfer the proxy's creation ref
robertphillips1125a032016-11-16 11:17:17 -0800155 fTarget->fPendingReads += fPendingReads;
156 fTarget->fPendingWrites += fPendingWrites;
robertphillips1125a032016-11-16 11:17:17 -0800157 }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400158
Robert Phillips757914d2017-01-25 15:48:30 -0500159 bool internalHasPendingIO() const {
160 if (fTarget) {
161 return fTarget->internalHasPendingIO();
162 }
163
164 return SkToBool(fPendingWrites | fPendingReads);
165 }
166
Robert Phillips7ee385e2017-03-30 08:02:11 -0400167 bool internalHasPendingWrite() const {
168 if (fTarget) {
169 return fTarget->internalHasPendingWrite();
170 }
171
172 return SkToBool(fPendingWrites);
173 }
174
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400175 // For deferred proxies this will be null. For wrapped proxies it will point to the
176 // wrapped resource.
177 GrSurface* fTarget;
robertphillips1125a032016-11-16 11:17:17 -0800178
179private:
180 // This class is used to manage conversion of refs to pending reads/writes.
Robert Phillipsb6deea82017-05-11 14:14:30 -0400181 friend class GrSurfaceProxyRef;
robertphillips1125a032016-11-16 11:17:17 -0800182 template <typename, GrIOType> friend class GrPendingIOResource;
183
Robert Phillipsb6deea82017-05-11 14:14:30 -0400184 void didRemoveRefOrPendingIO() const {
185 if (0 == fPendingReads && 0 == fPendingWrites && 0 == fRefCnt) {
186 delete this;
187 }
robertphillips1125a032016-11-16 11:17:17 -0800188 }
189
190 mutable int32_t fRefCnt;
191 mutable int32_t fPendingReads;
192 mutable int32_t fPendingWrites;
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400193};
194
195class GrSurfaceProxy : public GrIORefProxy {
robertphillips76948d42016-05-04 12:47:41 -0700196public:
Greg Daniel457469c2018-02-08 15:05:44 -0500197 enum class LazyInstantiationType {
Greg Daniel4684f822018-03-08 15:27:36 -0500198 kSingleUse, // Instantiation callback is allowed to be called only once
199 kMultipleUse, // Instantiation callback can be called multiple times.
200 kUninstantiate, // Instantiation callback can be called multiple times,
201 // but we will uninstantiate the proxy after every flush
Greg Daniel457469c2018-02-08 15:05:44 -0500202 };
203
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500204 enum class LazyState {
Greg Daniel0a375db2018-02-01 12:21:39 -0500205 kNot, // The proxy is instantiated or does not have a lazy callback
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500206 kPartially, // The proxy has a lazy callback but knows basic information about itself.
207 kFully, // The proxy has a lazy callback and also doesn't know its width, height, etc.
208 };
209
210 LazyState lazyInstantiationState() const {
Greg Daniel0a375db2018-02-01 12:21:39 -0500211 if (fTarget || !SkToBool(fLazyInstantiateCallback)) {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500212 return LazyState::kNot;
213 } else {
214 if (fWidth <= 0) {
215 SkASSERT(fHeight <= 0);
216 return LazyState::kFully;
217 } else {
218 SkASSERT(fHeight > 0);
219 return LazyState::kPartially;
220 }
221 }
222 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700223
224 GrPixelConfig config() const { return fConfig; }
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500225 int width() const {
226 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
227 return fWidth;
228 }
229 int height() const {
230 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
231 return fHeight;
232 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700233 int worstCaseWidth() const;
234 int worstCaseHeight() const;
robertphillips76948d42016-05-04 12:47:41 -0700235 GrSurfaceOrigin origin() const {
Brian Salomonbb5711a2017-05-17 13:49:59 -0400236 SkASSERT(kTopLeft_GrSurfaceOrigin == fOrigin || kBottomLeft_GrSurfaceOrigin == fOrigin);
237 return fOrigin;
robertphillips76948d42016-05-04 12:47:41 -0700238 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700239
Robert Phillips294870f2016-11-11 12:38:40 -0500240 class UniqueID {
241 public:
Robert Phillips7ee385e2017-03-30 08:02:11 -0400242 static UniqueID InvalidID() {
243 return UniqueID(uint32_t(SK_InvalidUniqueID));
244 }
245
Robert Phillips294870f2016-11-11 12:38:40 -0500246 // wrapped
247 explicit UniqueID(const GrGpuResource::UniqueID& id) : fID(id.asUInt()) { }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700248 // deferred and lazy-callback
Robert Phillips294870f2016-11-11 12:38:40 -0500249 UniqueID() : fID(GrGpuResource::CreateUniqueID()) { }
250
251 uint32_t asUInt() const { return fID; }
252
253 bool operator==(const UniqueID& other) const {
254 return fID == other.fID;
255 }
256 bool operator!=(const UniqueID& other) const {
257 return !(*this == other);
258 }
259
Robert Phillips7ee385e2017-03-30 08:02:11 -0400260 void makeInvalid() { fID = SK_InvalidUniqueID; }
Robert Phillips294870f2016-11-11 12:38:40 -0500261 bool isInvalid() const { return SK_InvalidUniqueID == fID; }
262
263 private:
Robert Phillips7ee385e2017-03-30 08:02:11 -0400264 explicit UniqueID(uint32_t id) : fID(id) {}
265
266 uint32_t fID;
Robert Phillips294870f2016-11-11 12:38:40 -0500267 };
268
269 /*
270 * The contract for the uniqueID is:
271 * for wrapped resources:
272 * the uniqueID will match that of the wrapped resource
273 *
274 * for deferred resources:
275 * the uniqueID will be different from the real resource, when it is allocated
276 * the proxy's uniqueID will not change across the instantiate call
277 *
278 * the uniqueIDs of the proxies and the resources draw from the same pool
279 *
280 * What this boils down to is that the uniqueID of a proxy can be used to consistently
281 * track/identify a proxy but should never be used to distinguish between
282 * resources and proxies - beware!
283 */
284 UniqueID uniqueID() const { return fUniqueID; }
robertphillips76948d42016-05-04 12:47:41 -0700285
Robert Phillips159e3c62017-06-19 12:02:00 -0400286 UniqueID underlyingUniqueID() const {
287 if (fTarget) {
288 return UniqueID(fTarget->uniqueID());
289 }
290
291 return fUniqueID;
292 }
293
Robert Phillipseee4d6e2017-06-05 09:26:07 -0400294 virtual bool instantiate(GrResourceProvider* resourceProvider) = 0;
Robert Phillips37430132016-11-09 06:50:43 -0500295
Robert Phillips4bc70112018-03-01 10:24:02 -0500296 void deInstantiate();
297
robertphillips76948d42016-05-04 12:47:41 -0700298 /**
robertphillips13a7eee2016-08-31 15:06:24 -0700299 * Helper that gets the width and height of the surface as a bounding rectangle.
300 */
Chris Dalton706a6ff2017-11-29 22:01:06 -0700301 SkRect getBoundsRect() const {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500302 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
Chris Dalton706a6ff2017-11-29 22:01:06 -0700303 return SkRect::MakeIWH(this->width(), this->height());
304 }
Robert Phillips784b7bf2016-12-09 13:35:02 -0500305
robertphillips13a7eee2016-08-31 15:06:24 -0700306 /**
robertphillips76948d42016-05-04 12:47:41 -0700307 * @return the texture proxy associated with the surface proxy, may be NULL.
308 */
309 virtual GrTextureProxy* asTextureProxy() { return nullptr; }
310 virtual const GrTextureProxy* asTextureProxy() const { return nullptr; }
311
312 /**
313 * @return the render target proxy associated with the surface proxy, may be NULL.
314 */
315 virtual GrRenderTargetProxy* asRenderTargetProxy() { return nullptr; }
316 virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; }
317
robertphillips13a7eee2016-08-31 15:06:24 -0700318 /**
319 * Does the resource count against the resource budget?
320 */
321 SkBudgeted isBudgeted() const { return fBudgeted; }
322
Robert Phillipsf2361d22016-10-25 14:20:06 -0400323 void setLastOpList(GrOpList* opList);
324 GrOpList* getLastOpList() { return fLastOpList; }
325
Brian Osman45580d32016-11-23 09:37:01 -0500326 GrRenderTargetOpList* getLastRenderTargetOpList();
327 GrTextureOpList* getLastTextureOpList();
328
Robert Phillips8bc06d02016-11-01 17:28:40 -0400329 /**
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400330 * Retrieves the amount of GPU memory that will be or currently is used by this resource
Robert Phillips8bc06d02016-11-01 17:28:40 -0400331 * in bytes. It is approximate since we aren't aware of additional padding or copies made
332 * by the driver.
333 *
334 * @return the amount of GPU memory used in bytes
335 */
336 size_t gpuMemorySize() const {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500337 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
Brian Salomonbb5711a2017-05-17 13:49:59 -0400338 if (fTarget) {
339 return fTarget->gpuMemorySize();
340 }
Robert Phillips8bc06d02016-11-01 17:28:40 -0400341 if (kInvalidGpuMemorySize == fGpuMemorySize) {
Brian Salomonbb5711a2017-05-17 13:49:59 -0400342 fGpuMemorySize = this->onUninstantiatedGpuMemorySize();
Robert Phillips8bc06d02016-11-01 17:28:40 -0400343 SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize);
344 }
345 return fGpuMemorySize;
346 }
347
Robert Phillipse2f7d182016-12-15 09:23:05 -0500348 // Helper function that creates a temporary SurfaceContext to perform the copy
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400349 // It always returns a kExact-backed proxy bc it is used when converting an SkSpecialImage
Brian Salomon63e79732017-05-15 21:23:13 -0400350 // to an SkImage. The copy is is not a render target and not multisampled.
Greg Daniel65c7f662017-10-30 13:39:09 -0400351 static sk_sp<GrTextureProxy> Copy(GrContext*, GrSurfaceProxy* src, GrMipMapped,
Robert Phillipse2f7d182016-12-15 09:23:05 -0500352 SkIRect srcRect, SkBudgeted);
353
354 // Copy the entire 'src'
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400355 // It always returns a kExact-backed proxy bc it is used in SkGpuDevice::snapSpecial
Greg Daniel65c7f662017-10-30 13:39:09 -0400356 static sk_sp<GrTextureProxy> Copy(GrContext* context, GrSurfaceProxy* src, GrMipMapped,
Robert Phillips63c67462017-02-15 14:19:01 -0500357 SkBudgeted budgeted);
Robert Phillipse2f7d182016-12-15 09:23:05 -0500358
359 // Test-only entry point - should decrease in use as proxies propagate
Robert Phillipsd46697a2017-01-25 12:10:37 -0500360 static sk_sp<GrSurfaceContext> TestCopy(GrContext* context, const GrSurfaceDesc& dstDesc,
Brian Salomon2a4f9832018-03-03 22:43:43 -0500361 GrSurfaceOrigin, GrSurfaceProxy* srcProxy);
Robert Phillipse2f7d182016-12-15 09:23:05 -0500362
Robert Phillipseaa86252016-11-08 13:49:39 +0000363 bool isWrapped_ForTesting() const;
364
Brian Osman45580d32016-11-23 09:37:01 -0500365 SkDEBUGCODE(void validate(GrContext*) const;)
366
Robert Phillips757914d2017-01-25 15:48:30 -0500367 // Provides access to functions that aren't part of the public API.
Robert Phillips420c4cf2017-09-28 09:00:45 -0400368 inline GrSurfaceProxyPriv priv();
369 inline const GrSurfaceProxyPriv priv() const;
Robert Phillips757914d2017-01-25 15:48:30 -0500370
robertphillips76948d42016-05-04 12:47:41 -0700371protected:
robertphillips8abb3702016-08-31 14:04:06 -0700372 // Deferred version
Brian Salomon2a4f9832018-03-03 22:43:43 -0500373 GrSurfaceProxy(const GrSurfaceDesc& desc, GrSurfaceOrigin origin, SkBackingFit fit,
374 SkBudgeted budgeted, uint32_t flags)
375 : GrSurfaceProxy(nullptr, LazyInstantiationType::kSingleUse, desc, origin, fit,
376 budgeted, flags) {
Robert Phillips294870f2016-11-11 12:38:40 -0500377 // Note: this ctor pulls a new uniqueID from the same pool at the GrGpuResources
robertphillips8abb3702016-08-31 14:04:06 -0700378 }
379
Robert Phillipsce5209a2018-02-13 11:13:51 -0500380 using LazyInstantiateCallback = std::function<sk_sp<GrSurface>(GrResourceProvider*)>;
Robert Phillips777707b2018-01-17 11:40:14 -0500381
Chris Dalton706a6ff2017-11-29 22:01:06 -0700382 // Lazy-callback version
Greg Daniel457469c2018-02-08 15:05:44 -0500383 GrSurfaceProxy(LazyInstantiateCallback&& callback, LazyInstantiationType lazyType,
Brian Salomon2a4f9832018-03-03 22:43:43 -0500384 const GrSurfaceDesc& desc, GrSurfaceOrigin origin, SkBackingFit fit,
385 SkBudgeted budgeted, uint32_t flags);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700386
robertphillips8abb3702016-08-31 14:04:06 -0700387 // Wrapped version
Robert Phillips066f0202017-07-25 10:16:35 -0400388 GrSurfaceProxy(sk_sp<GrSurface> surface, GrSurfaceOrigin origin, SkBackingFit fit);
robertphillips76948d42016-05-04 12:47:41 -0700389
Robert Phillipsf2361d22016-10-25 14:20:06 -0400390 virtual ~GrSurfaceProxy();
391
Robert Phillips757914d2017-01-25 15:48:30 -0500392 friend class GrSurfaceProxyPriv;
393
394 // Methods made available via GrSurfaceProxyPriv
395 bool hasPendingIO() const {
396 return this->internalHasPendingIO();
397 }
398
Robert Phillips7ee385e2017-03-30 08:02:11 -0400399 bool hasPendingWrite() const {
400 return this->internalHasPendingWrite();
401 }
402
Robert Phillips57aa3672017-07-21 11:38:13 -0400403 void computeScratchKey(GrScratchKey*) const;
404
Robert Phillips5af44de2017-07-18 14:49:38 -0400405 virtual sk_sp<GrSurface> createSurface(GrResourceProvider*) const = 0;
406 void assign(sk_sp<GrSurface> surface);
407
Robert Phillips65048132017-08-10 08:44:49 -0400408 sk_sp<GrSurface> createSurfaceImpl(GrResourceProvider*, int sampleCnt, bool needsStencil,
Greg Danield2d8e922018-02-12 12:07:39 -0500409 GrSurfaceFlags flags, GrMipMapped mipMapped) const;
Robert Phillips5af44de2017-07-18 14:49:38 -0400410
Robert Phillips65048132017-08-10 08:44:49 -0400411 bool instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt, bool needsStencil,
Greg Danield2d8e922018-02-12 12:07:39 -0500412 GrSurfaceFlags flags, GrMipMapped mipMapped, const GrUniqueKey*);
Brian Salomonbb5711a2017-05-17 13:49:59 -0400413
Chris Dalton706a6ff2017-11-29 22:01:06 -0700414private:
Brian Salomonbb5711a2017-05-17 13:49:59 -0400415 // For wrapped resources, 'fConfig', 'fWidth', 'fHeight', and 'fOrigin; will always be filled in
416 // from the wrapped resource.
417 GrPixelConfig fConfig;
418 int fWidth;
419 int fHeight;
420 GrSurfaceOrigin fOrigin;
Chris Dalton706a6ff2017-11-29 22:01:06 -0700421 SkBackingFit fFit; // always kApprox for lazy-callback resources
422 // always kExact for wrapped resources
423 mutable SkBudgeted fBudgeted; // always kYes for lazy-callback resources
424 // set from the backing resource for wrapped resources
Robert Phillipsb726d582017-03-09 16:36:32 -0500425 // mutable bc of SkSurface/SkImage wishy-washiness
Robert Phillipsc787e492017-02-28 11:26:32 -0500426 const uint32_t fFlags;
Robert Phillipsa4c41b32017-03-15 13:02:45 -0400427
Robert Phillips294870f2016-11-11 12:38:40 -0500428 const UniqueID fUniqueID; // set from the backing resource for wrapped resources
robertphillips76948d42016-05-04 12:47:41 -0700429
Chris Dalton706a6ff2017-11-29 22:01:06 -0700430 LazyInstantiateCallback fLazyInstantiateCallback;
Greg Daniel457469c2018-02-08 15:05:44 -0500431 // If this is set to kSingleuse, then after one call to fLazyInstantiateCallback we will cleanup
432 // the lazy callback and then delete it. This will allow for any refs and resources being held
433 // by the standard function to be released. This is specifically useful in non-dll cases where
434 // we make lazy proxies and instantiate them immediately.
435 // Note: This is ignored if fLazyInstantiateCallback is null.
436 LazyInstantiationType fLazyInstantiationType;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500437 SkDEBUGCODE(virtual void validateLazySurface(const GrSurface*) = 0;)
Chris Dalton706a6ff2017-11-29 22:01:06 -0700438
Robert Phillips8bc06d02016-11-01 17:28:40 -0400439 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
Robert Phillips29e52f12016-11-03 10:19:14 -0400440 SkDEBUGCODE(size_t getRawGpuMemorySize_debugOnly() const { return fGpuMemorySize; })
441
Brian Salomonbb5711a2017-05-17 13:49:59 -0400442 virtual size_t onUninstantiatedGpuMemorySize() const = 0;
Robert Phillips29e52f12016-11-03 10:19:14 -0400443
Brian Salomond17b4a62017-05-23 16:53:47 -0400444 bool fNeedsClear;
445
Robert Phillips8bc06d02016-11-01 17:28:40 -0400446 // This entry is lazily evaluated so, when the proxy wraps a resource, the resource
447 // will be called but, when the proxy is deferred, it will compute the answer itself.
448 // If the proxy computes its own answer that answer is checked (in debug mode) in
449 // the instantiation method.
450 mutable size_t fGpuMemorySize;
451
Robert Phillipsf2361d22016-10-25 14:20:06 -0400452 // The last opList that wrote to or is currently going to write to this surface
Robert Phillipsb6deea82017-05-11 14:14:30 -0400453 // The opList can be closed (e.g., no surface context is currently bound
454 // to this proxy).
Robert Phillipsf2361d22016-10-25 14:20:06 -0400455 // This back-pointer is required so that we can add a dependancy between
456 // the opList used to create the current contents of this surface
457 // and the opList of a destination surface to which this one is being drawn or copied.
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400458 // This pointer is unreffed. OpLists own a ref on their surface proxies.
Robert Phillipsf2361d22016-10-25 14:20:06 -0400459 GrOpList* fLastOpList;
460
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400461 typedef GrIORefProxy INHERITED;
robertphillips76948d42016-05-04 12:47:41 -0700462};
463
464#endif