blob: ce74d74ad15fa0631343cfeb54c59b5a46a71fb9 [file] [log] [blame]
commit-bot@chromium.org089a7802014-05-02 21:38:22 +00001/*
bsalomonc44be0e2014-07-25 07:32:33 -07002 * Copyright 2014 Google Inc.
commit-bot@chromium.org089a7802014-05-02 21:38:22 +00003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
bsalomon6d3fe022014-07-25 08:35:45 -07008#ifndef GrGpuResource_DEFINED
9#define GrGpuResource_DEFINED
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/private/GrResourceKey.h"
12#include "include/private/GrTypesPriv.h"
13#include "include/private/SkNoncopyable.h"
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000014
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000015class GrContext;
bsalomon37dd3312014-11-03 08:47:23 -080016class GrGpu;
bsalomon0ea80f42015-02-11 10:49:59 -080017class GrResourceCache;
ericrk0a5fa482015-09-15 14:16:10 -070018class SkTraceMemoryDump;
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000019
20/**
bsalomon00b76bd2014-09-03 14:05:49 -070021 * Base class for GrGpuResource. Handles the various types of refs we need. Separated out as a base
22 * class to isolate the ref-cnting behavior and provide friendship without exposing all of
23 * GrGpuResource.
mtklein6f076652015-01-13 08:22:43 -080024 *
bsalomon00b76bd2014-09-03 14:05:49 -070025 * Gpu resources can have three types of refs:
26 * 1) Normal ref (+ by ref(), - by unref()): These are used by code that is issuing draw calls
Robert Phillipsf2361d22016-10-25 14:20:06 -040027 * that read and write the resource via GrOpList and by any object that must own a
bsalomon00b76bd2014-09-03 14:05:49 -070028 * GrGpuResource and is itself owned (directly or indirectly) by Skia-client code.
bsalomonbcf0a522014-10-08 08:40:09 -070029 * 2) Pending read (+ by addPendingRead(), - by completedRead()): GrContext has scheduled a read
bsalomon00b76bd2014-09-03 14:05:49 -070030 * of the resource by the GPU as a result of a skia API call but hasn't executed it yet.
bsalomonbcf0a522014-10-08 08:40:09 -070031 * 3) Pending write (+ by addPendingWrite(), - by completedWrite()): GrContext has scheduled a
bsalomon00b76bd2014-09-03 14:05:49 -070032 * write to the resource by the GPU as a result of a skia API call but hasn't executed it yet.
33 *
34 * The latter two ref types are private and intended only for Gr core code.
bsalomonbcf0a522014-10-08 08:40:09 -070035 *
Brian Salomon8cabb322019-02-22 10:44:19 -050036 * PRIOR to the last ref/IO count being removed DERIVED::notifyAllCntsWillBeZero() will be called
37 * (static poly morphism using CRTP). It is legal for additional ref's or pending IOs to be added
38 * during this time. AFTER all the ref/io counts reach zero DERIVED::notifyAllCntsAreZero() will be
39 * called. Similarly when the ref (but not necessarily pending read/write) count reaches 0
40 * DERIVED::notifyRefCountIsZero() will be called. In the case when an unref() causes both
bsalomon3f324322015-04-08 11:01:54 -070041 * the ref cnt to reach zero and the other counts are zero, notifyRefCountIsZero() will be called
Brian Salomon9bc76d92019-01-24 12:18:33 -050042 * before notifyAllCntsAreZero(). Moreover, if notifyRefCountIsZero() returns false then
Brian Salomon8cabb322019-02-22 10:44:19 -050043 * notifyAllCntsAreZero() won't be called at all. notifyRefCountIsZero() must return false if the
bsalomon3f324322015-04-08 11:01:54 -070044 * object may be deleted after notifyRefCntIsZero() returns.
45 *
46 * GrIORef and GrGpuResource are separate classes for organizational reasons and to be
bsalomonbcf0a522014-10-08 08:40:09 -070047 * able to give access via friendship to only the functions related to pending IO operations.
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000048 */
bsalomonbcf0a522014-10-08 08:40:09 -070049template <typename DERIVED> class GrIORef : public SkNoncopyable {
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000050public:
bsalomon00b76bd2014-09-03 14:05:49 -070051 // Some of the signatures are written to mirror SkRefCnt so that GrGpuResource can work with
bungeman6bd52842016-10-27 09:30:08 -070052 // templated helper classes (e.g. sk_sp). However, we have different categories of
bsalomon00b76bd2014-09-03 14:05:49 -070053 // refs (e.g. pending reads). We also don't require thread safety as GrCacheable objects are
54 // not intended to cross thread boundaries.
bsalomon00b76bd2014-09-03 14:05:49 -070055 void ref() const {
Brian Salomon01ceae92019-04-02 11:49:54 -040056 // Only the cache should be able to add the first ref to a resource.
57 SkASSERT(fRefCnt > 0);
Brian Salomon9323b8b2014-10-07 15:07:38 -040058 this->validate();
bsalomonbcf0a522014-10-08 08:40:09 -070059 ++fRefCnt;
bsalomonc44be0e2014-07-25 07:32:33 -070060 }
bsalomon00b76bd2014-09-03 14:05:49 -070061
62 void unref() const {
63 this->validate();
mtklein2766c002015-06-26 11:45:03 -070064
Brian Salomon8cabb322019-02-22 10:44:19 -050065 if (fRefCnt == 1) {
66 if (!this->internalHasPendingIO()) {
67 static_cast<const DERIVED*>(this)->notifyAllCntsWillBeZero();
68 }
69 SkASSERT(fRefCnt > 0);
70 }
71 if (--fRefCnt == 0) {
bsalomon3f324322015-04-08 11:01:54 -070072 if (!static_cast<const DERIVED*>(this)->notifyRefCountIsZero()) {
73 return;
74 }
75 }
76
77 this->didRemoveRefOrPendingIO(kRef_CntType);
bsalomon00b76bd2014-09-03 14:05:49 -070078 }
79
bsalomon00b76bd2014-09-03 14:05:49 -070080 void validate() const {
81#ifdef SK_DEBUG
82 SkASSERT(fRefCnt >= 0);
83 SkASSERT(fPendingReads >= 0);
84 SkASSERT(fPendingWrites >= 0);
bsalomon12299ab2014-11-14 13:33:09 -080085 SkASSERT(fRefCnt + fPendingReads + fPendingWrites >= 0);
bsalomonc44be0e2014-07-25 07:32:33 -070086#endif
bsalomon00b76bd2014-09-03 14:05:49 -070087 }
88
Robert Phillipsb5204762019-06-19 14:12:13 -040089#if GR_TEST_UTILS
90 int32_t testingOnly_getRefCnt() const { return fRefCnt; }
91 int32_t testingOnly_getPendingReads() const { return fPendingReads; }
92 int32_t testingOnly_getPendingWrites() const { return fPendingWrites; }
93#endif
94
bsalomon00b76bd2014-09-03 14:05:49 -070095protected:
Brian Salomon9f7d9a22018-12-11 19:01:32 +000096 GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0) { }
bsalomon00b76bd2014-09-03 14:05:49 -070097
bsalomon3f324322015-04-08 11:01:54 -070098 enum CntType {
99 kRef_CntType,
100 kPendingRead_CntType,
101 kPendingWrite_CntType,
102 };
103
bsalomon8d034a12014-09-22 12:21:08 -0700104 bool internalHasPendingRead() const { return SkToBool(fPendingReads); }
105 bool internalHasPendingWrite() const { return SkToBool(fPendingWrites); }
106 bool internalHasPendingIO() const { return SkToBool(fPendingWrites | fPendingReads); }
107
bsalomon6d4488c2014-11-11 07:27:16 -0800108 bool internalHasRef() const { return SkToBool(fRefCnt); }
Eric Karl914a36b2017-10-12 12:44:50 -0700109 bool internalHasUniqueRef() const { return fRefCnt == 1; }
bsalomon6d4488c2014-11-11 07:27:16 -0800110
Brian Salomon01ceae92019-04-02 11:49:54 -0400111 // Privileged method that allows going from ref count = 0 to ref count = 1.
112 void addInitialRef() const {
113 this->validate();
114 ++fRefCnt;
115 }
116
bsalomon00b76bd2014-09-03 14:05:49 -0700117private:
118 void addPendingRead() const {
119 this->validate();
120 ++fPendingReads;
121 }
122
123 void completedRead() const {
124 this->validate();
Brian Salomon8cabb322019-02-22 10:44:19 -0500125 if (fPendingReads == 1 && !fPendingWrites && !fRefCnt) {
126 static_cast<const DERIVED*>(this)->notifyAllCntsWillBeZero();
127 }
bsalomon00b76bd2014-09-03 14:05:49 -0700128 --fPendingReads;
bsalomon3f324322015-04-08 11:01:54 -0700129 this->didRemoveRefOrPendingIO(kPendingRead_CntType);
bsalomon00b76bd2014-09-03 14:05:49 -0700130 }
131
132 void addPendingWrite() const {
133 this->validate();
134 ++fPendingWrites;
135 }
136
137 void completedWrite() const {
138 this->validate();
Brian Salomon8cabb322019-02-22 10:44:19 -0500139 if (fPendingWrites == 1 && !fPendingReads && !fRefCnt) {
140 static_cast<const DERIVED*>(this)->notifyAllCntsWillBeZero();
141 }
bsalomon00b76bd2014-09-03 14:05:49 -0700142 --fPendingWrites;
bsalomon3f324322015-04-08 11:01:54 -0700143 this->didRemoveRefOrPendingIO(kPendingWrite_CntType);
bsalomon00b76bd2014-09-03 14:05:49 -0700144 }
145
bsalomon3f324322015-04-08 11:01:54 -0700146 void didRemoveRefOrPendingIO(CntType cntTypeRemoved) const {
bsalomon12299ab2014-11-14 13:33:09 -0800147 if (0 == fPendingReads && 0 == fPendingWrites && 0 == fRefCnt) {
bsalomon3f324322015-04-08 11:01:54 -0700148 static_cast<const DERIVED*>(this)->notifyAllCntsAreZero(cntTypeRemoved);
bsalomonbcf0a522014-10-08 08:40:09 -0700149 }
150 }
151
bsalomon00b76bd2014-09-03 14:05:49 -0700152 mutable int32_t fRefCnt;
153 mutable int32_t fPendingReads;
154 mutable int32_t fPendingWrites;
155
Brian Salomon9f7d9a22018-12-11 19:01:32 +0000156 friend class GrResourceCache; // to check IO ref counts.
bsalomonbcf0a522014-10-08 08:40:09 -0700157
158 template <typename, GrIOType> friend class GrPendingIOResource;
bsalomon00b76bd2014-09-03 14:05:49 -0700159};
160
161/**
bsalomon0ea80f42015-02-11 10:49:59 -0800162 * Base class for objects that can be kept in the GrResourceCache.
bsalomon00b76bd2014-09-03 14:05:49 -0700163 */
bsalomon544fe232014-10-08 10:24:07 -0700164class SK_API GrGpuResource : public GrIORef<GrGpuResource> {
bsalomon00b76bd2014-09-03 14:05:49 -0700165public:
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000166 /**
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000167 * Tests whether a object has been abandoned or released. All objects will
168 * be in this state after their creating GrContext is destroyed or has
169 * contextLost called. It's up to the client to test wasDestroyed() before
170 * attempting to use an object if it holds refs on objects across
171 * ~GrContext, freeResources with the force flag, or contextLost.
172 *
173 * @return true if the object has been released or abandoned,
174 * false otherwise.
175 */
Ben Wagnera93a14a2017-08-28 10:34:05 -0400176 bool wasDestroyed() const { return nullptr == fGpu; }
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000177
178 /**
179 * Retrieves the context that owns the object. Note that it is possible for
180 * this to return NULL. When objects have been release()ed or abandon()ed
181 * they no longer have an owning context. Destroying a GrContext
182 * automatically releases all its resources.
183 */
184 const GrContext* getContext() const;
185 GrContext* getContext();
186
bsalomonc44be0e2014-07-25 07:32:33 -0700187 /**
188 * Retrieves the amount of GPU memory used by this resource in bytes. It is
189 * approximate since we aren't aware of additional padding or copies made
190 * by the driver.
191 *
192 * @return the amount of GPU memory used in bytes
193 */
bsalomon69ed47f2014-11-12 11:13:39 -0800194 size_t gpuMemorySize() const {
195 if (kInvalidGpuMemorySize == fGpuMemorySize) {
196 fGpuMemorySize = this->onGpuMemorySize();
197 SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize);
198 }
199 return fGpuMemorySize;
200 }
bsalomonc44be0e2014-07-25 07:32:33 -0700201
Robert Phillips294870f2016-11-11 12:38:40 -0500202 class UniqueID {
203 public:
Brian Salomon8c8806f2019-02-07 13:55:57 -0500204 UniqueID() = default;
Robert Phillips294870f2016-11-11 12:38:40 -0500205
206 explicit UniqueID(uint32_t id) : fID(id) {}
207
208 uint32_t asUInt() const { return fID; }
209
Brian Salomon8c8806f2019-02-07 13:55:57 -0500210 bool operator==(const UniqueID& other) const { return fID == other.fID; }
211 bool operator!=(const UniqueID& other) const { return !(*this == other); }
Robert Phillips294870f2016-11-11 12:38:40 -0500212
213 void makeInvalid() { fID = SK_InvalidUniqueID; }
Brian Salomon8c8806f2019-02-07 13:55:57 -0500214 bool isInvalid() const { return fID == SK_InvalidUniqueID; }
Robert Phillips294870f2016-11-11 12:38:40 -0500215
216 protected:
Brian Salomon8c8806f2019-02-07 13:55:57 -0500217 uint32_t fID = SK_InvalidUniqueID;
Robert Phillips294870f2016-11-11 12:38:40 -0500218 };
219
bsalomonc44be0e2014-07-25 07:32:33 -0700220 /**
bsalomon52e9d632014-09-05 12:23:12 -0700221 * Gets an id that is unique for this GrGpuResource object. It is static in that it does
222 * not change when the content of the GrGpuResource object changes. This will never return
bsalomonc44be0e2014-07-25 07:32:33 -0700223 * 0.
224 */
Robert Phillips294870f2016-11-11 12:38:40 -0500225 UniqueID uniqueID() const { return fUniqueID; }
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000226
bsalomon8718aaf2015-02-19 07:24:21 -0800227 /** Returns the current unique key for the resource. It will be invalid if the resource has no
228 associated unique key. */
229 const GrUniqueKey& getUniqueKey() const { return fUniqueKey; }
bsalomon563ff602015-02-02 17:25:26 -0800230
bsalomon453cf402014-11-11 14:15:57 -0800231 /**
bsalomon3582d3e2015-02-13 14:20:05 -0800232 * Internal-only helper class used for manipulations of the resource by the cache.
bsalomon453cf402014-11-11 14:15:57 -0800233 */
234 class CacheAccess;
235 inline CacheAccess cacheAccess();
236 inline const CacheAccess cacheAccess() const;
237
junov436293a2014-12-11 10:32:32 -0800238 /**
Brian Salomon01ceae92019-04-02 11:49:54 -0400239 * Internal-only helper class used for manipulations of the resource by GrSurfaceProxy.
240 */
241 class ProxyAccess;
242 inline ProxyAccess proxyAccess();
243
244 /**
bsalomon3582d3e2015-02-13 14:20:05 -0800245 * Internal-only helper class used for manipulations of the resource by internal code.
246 */
247 class ResourcePriv;
248 inline ResourcePriv resourcePriv();
249 inline const ResourcePriv resourcePriv() const;
250
251 /**
ericrk0a5fa482015-09-15 14:16:10 -0700252 * Dumps memory usage information for this GrGpuResource to traceMemoryDump.
253 * Typically, subclasses should not need to override this, and should only
254 * need to override setMemoryBacking.
255 **/
256 virtual void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
257
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -0400258 /**
259 * Describes the type of gpu resource that is represented by the implementing
260 * class (e.g. texture, buffer object, stencil). This data is used for diagnostic
261 * purposes by dumpMemoryStatistics().
262 *
263 * The value returned is expected to be long lived and will not be copied by the caller.
264 */
265 virtual const char* getResourceType() const = 0;
266
robertphillips8abb3702016-08-31 14:04:06 -0700267 static uint32_t CreateUniqueID();
268
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000269protected:
kkinnunen2e6055b2016-04-22 01:48:29 -0700270 // This must be called by every non-wrapped GrGpuObject. It should be called once the object is
271 // fully initialized (i.e. only from the constructors of the final class).
272 void registerWithCache(SkBudgeted);
bsalomon16961262014-08-26 14:01:07 -0700273
kkinnunen2e6055b2016-04-22 01:48:29 -0700274 // This must be called by every GrGpuObject that references any wrapped backend objects. It
275 // should be called once the object is fully initialized (i.e. only from the constructors of the
276 // final class).
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500277 void registerWithCacheWrapped(GrWrapCacheable);
kkinnunen2e6055b2016-04-22 01:48:29 -0700278
279 GrGpuResource(GrGpu*);
bsalomon6d3fe022014-07-25 08:35:45 -0700280 virtual ~GrGpuResource();
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000281
282 GrGpu* getGpu() const { return fGpu; }
283
bsalomon12299ab2014-11-14 13:33:09 -0800284 /** Overridden to free GPU resources in the backend API. */
Brian Salomon9f7d9a22018-12-11 19:01:32 +0000285 virtual void onRelease() { }
bsalomon12299ab2014-11-14 13:33:09 -0800286 /** Overridden to abandon any internal handles, ptrs, etc to backend API resources.
287 This may be called when the underlying 3D context is no longer valid and so no
288 backend API calls should be made. */
Brian Salomon9f7d9a22018-12-11 19:01:32 +0000289 virtual void onAbandon() { }
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000290
bsalomonc44be0e2014-07-25 07:32:33 -0700291 /**
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -0400292 * Allows subclasses to add additional backing information to the SkTraceMemoryDump.
ericrk0a5fa482015-09-15 14:16:10 -0700293 **/
294 virtual void setMemoryBacking(SkTraceMemoryDump*, const SkString&) const {}
295
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -0400296 /**
297 * Returns a string that uniquely identifies this resource.
298 */
299 SkString getResourceName() const;
300
301 /**
302 * A helper for subclasses that override dumpMemoryStatistics(). This method using a format
303 * consistent with the default implementation of dumpMemoryStatistics() but allows the caller
304 * to customize various inputs.
305 */
306 void dumpMemoryStatisticsPriv(SkTraceMemoryDump* traceMemoryDump, const SkString& resourceName,
307 const char* type, size_t size) const;
308
Brian Salomon9f7d9a22018-12-11 19:01:32 +0000309
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000310private:
Brian Salomon9bc76d92019-01-24 12:18:33 -0500311 bool isPurgeable() const;
Brian Salomon2c791fc2019-04-02 11:52:03 -0400312 bool hasRef() const;
Brian Salomon9bc76d92019-01-24 12:18:33 -0500313 bool hasRefOrPendingIO() const;
Brian Salomon614c1a82018-12-19 15:42:06 -0500314
bsalomon12299ab2014-11-14 13:33:09 -0800315 /**
kkinnunen2e6055b2016-04-22 01:48:29 -0700316 * Called by the registerWithCache if the resource is available to be used as scratch.
317 * Resource subclasses should override this if the instances should be recycled as scratch
318 * resources and populate the scratchKey with the key.
319 * By default resources are not recycled as scratch.
320 **/
Brian Salomon9bc76d92019-01-24 12:18:33 -0500321 virtual void computeScratchKey(GrScratchKey*) const {}
kkinnunen2e6055b2016-04-22 01:48:29 -0700322
323 /**
Brian Salomon35ba6142019-01-24 13:08:59 -0500324 * Removes references to objects in the underlying 3D API without freeing them.
325 * Called by CacheAccess.
326 */
327 void abandon();
328
329 /**
bsalomon12299ab2014-11-14 13:33:09 -0800330 * Frees the object in the underlying 3D API. Called by CacheAccess.
331 */
332 void release();
333
bsalomon69ed47f2014-11-12 11:13:39 -0800334 virtual size_t onGpuMemorySize() const = 0;
335
Brian Salomon614c1a82018-12-19 15:42:06 -0500336 /**
Brian Salomon9bc76d92019-01-24 12:18:33 -0500337 * Called by GrResourceCache when a resource loses its last ref or pending IO.
Brian Salomon614c1a82018-12-19 15:42:06 -0500338 */
Brian Salomon8cabb322019-02-22 10:44:19 -0500339 virtual void willRemoveLastRefOrPendingIO() {}
Brian Salomon614c1a82018-12-19 15:42:06 -0500340
bsalomon9f2d1572015-02-17 11:47:40 -0800341 // See comments in CacheAccess and ResourcePriv.
bsalomonf99e9612015-02-19 08:24:16 -0800342 void setUniqueKey(const GrUniqueKey&);
bsalomon8718aaf2015-02-19 07:24:21 -0800343 void removeUniqueKey();
Brian Salomon8cabb322019-02-22 10:44:19 -0500344 void notifyAllCntsWillBeZero() const;
bsalomon3f324322015-04-08 11:01:54 -0700345 void notifyAllCntsAreZero(CntType) const;
346 bool notifyRefCountIsZero() const;
bsalomon10e23ca2014-11-25 05:52:06 -0800347 void removeScratchKey();
bsalomonafe30052015-01-16 07:32:33 -0800348 void makeBudgeted();
bsalomonc2f35b72015-01-23 07:19:22 -0800349 void makeUnbudgeted();
bsalomonbcf0a522014-10-08 08:40:09 -0700350
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000351#ifdef SK_DEBUG
Brian Salomon5e150852017-03-22 14:53:13 -0400352 friend class GrGpu; // for assert in GrGpu to access getGpu
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000353#endif
Brian Salomon5e150852017-03-22 14:53:13 -0400354
bsalomonf320e042015-02-17 15:09:34 -0800355 // An index into a heap when this resource is purgeable or an array when not. This is maintained
356 // by the cache.
Brian Salomon5e150852017-03-22 14:53:13 -0400357 int fCacheArrayIndex;
bsalomon9f2d1572015-02-17 11:47:40 -0800358 // This value reflects how recently this resource was accessed in the cache. This is maintained
359 // by the cache.
Brian Salomon5e150852017-03-22 14:53:13 -0400360 uint32_t fTimestamp;
Brian Salomon5e150852017-03-22 14:53:13 -0400361 GrStdSteadyClock::time_point fTimeWhenBecamePurgeable;
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000362
bsalomon69ed47f2014-11-12 11:13:39 -0800363 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
Brian Salomon5e150852017-03-22 14:53:13 -0400364 GrScratchKey fScratchKey;
365 GrUniqueKey fUniqueKey;
bsalomon84c8e622014-11-17 09:33:27 -0800366
367 // This is not ref'ed but abandon() or release() will be called before the GrGpu object
368 // is destroyed. Those calls set will this to NULL.
Brian Salomon5e150852017-03-22 14:53:13 -0400369 GrGpu* fGpu;
Brian Salomonfa2ebea2019-01-24 15:58:58 -0500370 mutable size_t fGpuMemorySize = kInvalidGpuMemorySize;
bsalomon84c8e622014-11-17 09:33:27 -0800371
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500372 GrBudgetedType fBudgetedType = GrBudgetedType::kUnbudgetedUncacheable;
Brian Salomonfa2ebea2019-01-24 15:58:58 -0500373 bool fRefsWrappedObjects = false;
Brian Salomon5e150852017-03-22 14:53:13 -0400374 const UniqueID fUniqueID;
bsalomon744998e2014-08-28 09:54:34 -0700375
bsalomonbcf0a522014-10-08 08:40:09 -0700376 typedef GrIORef<GrGpuResource> INHERITED;
Brian Salomon9f7d9a22018-12-11 19:01:32 +0000377 friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and notifyRefCntIsZero.
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000378};
379
Brian Salomon01ceae92019-04-02 11:49:54 -0400380class GrGpuResource::ProxyAccess {
381private:
382 ProxyAccess(GrGpuResource* resource) : fResource(resource) {}
383
384 /** Proxies are allowed to take a resource from no refs to one ref. */
Brian Salomon2c791fc2019-04-02 11:52:03 -0400385 void ref(GrResourceCache* cache);
Brian Salomon01ceae92019-04-02 11:49:54 -0400386
387 // No taking addresses of this type.
388 const CacheAccess* operator&() const = delete;
389 CacheAccess* operator&() = delete;
390
391 GrGpuResource* fResource;
392
393 friend class GrGpuResource;
394 friend class GrSurfaceProxy;
395 friend class GrIORefProxy;
396};
397
398inline GrGpuResource::ProxyAccess GrGpuResource::proxyAccess() { return ProxyAccess(this); }
399
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000400#endif