commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 1 | /* |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 2 | * Copyright 2014 Google Inc. |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 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 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 8 | #ifndef GrGpuResource_DEFINED |
| 9 | #define GrGpuResource_DEFINED |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 10 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 11 | #include "GrResourceKey.h" |
| 12 | #include "GrTypesPriv.h" |
junov | 5756aff | 2014-12-11 14:59:31 -0800 | [diff] [blame] | 13 | #include "SkData.h" |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 14 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 15 | class GrContext; |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 16 | class GrGpu; |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 17 | class GrResourceCache; |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 18 | class SkTraceMemoryDump; |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 19 | |
| 20 | /** |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 21 | * 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. |
mtklein | 6f07665 | 2015-01-13 08:22:43 -0800 | [diff] [blame] | 24 | * |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 25 | * 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 |
| 27 | * that read and write the resource via GrDrawTarget and by any object that must own a |
| 28 | * GrGpuResource and is itself owned (directly or indirectly) by Skia-client code. |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 29 | * 2) Pending read (+ by addPendingRead(), - by completedRead()): GrContext has scheduled a read |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 30 | * of the resource by the GPU as a result of a skia API call but hasn't executed it yet. |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 31 | * 3) Pending write (+ by addPendingWrite(), - by completedWrite()): GrContext has scheduled a |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 32 | * 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. |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 35 | * |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 36 | * When all the ref/io counts reach zero DERIVED::notifyAllCntsAreZero() will be called (static poly |
| 37 | * morphism using CRTP). Similarly when the ref (but not necessarily pending read/write) count |
| 38 | * reaches 0 DERIVED::notifyRefCountIsZero() will be called. In the case when an unref() causes both |
| 39 | * the ref cnt to reach zero and the other counts are zero, notifyRefCountIsZero() will be called |
| 40 | * before notifyIsPurgeable(). Moreover, if notifyRefCountIsZero() returns false then |
| 41 | * notifyAllRefCntsAreZero() won't be called at all. notifyRefCountIsZero() must return false if the |
| 42 | * object may be deleted after notifyRefCntIsZero() returns. |
| 43 | * |
| 44 | * GrIORef and GrGpuResource are separate classes for organizational reasons and to be |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 45 | * able to give access via friendship to only the functions related to pending IO operations. |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 46 | */ |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 47 | template <typename DERIVED> class GrIORef : public SkNoncopyable { |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 48 | public: |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 49 | // Some of the signatures are written to mirror SkRefCnt so that GrGpuResource can work with |
| 50 | // templated helper classes (e.g. SkAutoTUnref). However, we have different categories of |
| 51 | // refs (e.g. pending reads). We also don't require thread safety as GrCacheable objects are |
| 52 | // not intended to cross thread boundaries. |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 53 | void ref() const { |
Brian Salomon | 9323b8b | 2014-10-07 15:07:38 -0400 | [diff] [blame] | 54 | this->validate(); |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 55 | ++fRefCnt; |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 56 | } |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 57 | |
| 58 | void unref() const { |
| 59 | this->validate(); |
mtklein | 2766c00 | 2015-06-26 11:45:03 -0700 | [diff] [blame] | 60 | |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 61 | if (!(--fRefCnt)) { |
| 62 | if (!static_cast<const DERIVED*>(this)->notifyRefCountIsZero()) { |
| 63 | return; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | this->didRemoveRefOrPendingIO(kRef_CntType); |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 68 | } |
| 69 | |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 70 | void validate() const { |
| 71 | #ifdef SK_DEBUG |
| 72 | SkASSERT(fRefCnt >= 0); |
| 73 | SkASSERT(fPendingReads >= 0); |
| 74 | SkASSERT(fPendingWrites >= 0); |
bsalomon | 12299ab | 2014-11-14 13:33:09 -0800 | [diff] [blame] | 75 | SkASSERT(fRefCnt + fPendingReads + fPendingWrites >= 0); |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 76 | #endif |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | protected: |
bsalomon | 1e2530b | 2014-10-09 09:57:18 -0700 | [diff] [blame] | 80 | GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0) { } |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 81 | |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 82 | enum CntType { |
| 83 | kRef_CntType, |
| 84 | kPendingRead_CntType, |
| 85 | kPendingWrite_CntType, |
| 86 | }; |
| 87 | |
bsalomon | 63c992f | 2015-01-23 12:47:59 -0800 | [diff] [blame] | 88 | bool isPurgeable() const { return !this->internalHasRef() && !this->internalHasPendingIO(); } |
bsalomon | 12299ab | 2014-11-14 13:33:09 -0800 | [diff] [blame] | 89 | |
bsalomon | 8d034a1 | 2014-09-22 12:21:08 -0700 | [diff] [blame] | 90 | bool internalHasPendingRead() const { return SkToBool(fPendingReads); } |
| 91 | bool internalHasPendingWrite() const { return SkToBool(fPendingWrites); } |
| 92 | bool internalHasPendingIO() const { return SkToBool(fPendingWrites | fPendingReads); } |
| 93 | |
bsalomon | 6d4488c | 2014-11-11 07:27:16 -0800 | [diff] [blame] | 94 | bool internalHasRef() const { return SkToBool(fRefCnt); } |
| 95 | |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 96 | private: |
| 97 | void addPendingRead() const { |
| 98 | this->validate(); |
| 99 | ++fPendingReads; |
| 100 | } |
| 101 | |
| 102 | void completedRead() const { |
| 103 | this->validate(); |
| 104 | --fPendingReads; |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 105 | this->didRemoveRefOrPendingIO(kPendingRead_CntType); |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void addPendingWrite() const { |
| 109 | this->validate(); |
| 110 | ++fPendingWrites; |
| 111 | } |
| 112 | |
| 113 | void completedWrite() const { |
| 114 | this->validate(); |
| 115 | --fPendingWrites; |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 116 | this->didRemoveRefOrPendingIO(kPendingWrite_CntType); |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | private: |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 120 | void didRemoveRefOrPendingIO(CntType cntTypeRemoved) const { |
bsalomon | 12299ab | 2014-11-14 13:33:09 -0800 | [diff] [blame] | 121 | if (0 == fPendingReads && 0 == fPendingWrites && 0 == fRefCnt) { |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 122 | static_cast<const DERIVED*>(this)->notifyAllCntsAreZero(cntTypeRemoved); |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 126 | mutable int32_t fRefCnt; |
| 127 | mutable int32_t fPendingReads; |
| 128 | mutable int32_t fPendingWrites; |
| 129 | |
bsalomon | ac8d619 | 2014-09-04 14:13:44 -0700 | [diff] [blame] | 130 | // This class is used to manage conversion of refs to pending reads/writes. |
bsalomon | f96ba02 | 2014-09-17 08:05:40 -0700 | [diff] [blame] | 131 | friend class GrGpuResourceRef; |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 132 | friend class GrResourceCache; // to check IO ref counts. |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 133 | |
| 134 | template <typename, GrIOType> friend class GrPendingIOResource; |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | /** |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 138 | * Base class for objects that can be kept in the GrResourceCache. |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 139 | */ |
bsalomon | 544fe23 | 2014-10-08 10:24:07 -0700 | [diff] [blame] | 140 | class SK_API GrGpuResource : public GrIORef<GrGpuResource> { |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 141 | public: |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 142 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 143 | /** |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 144 | * Tests whether a object has been abandoned or released. All objects will |
| 145 | * be in this state after their creating GrContext is destroyed or has |
| 146 | * contextLost called. It's up to the client to test wasDestroyed() before |
| 147 | * attempting to use an object if it holds refs on objects across |
| 148 | * ~GrContext, freeResources with the force flag, or contextLost. |
| 149 | * |
| 150 | * @return true if the object has been released or abandoned, |
| 151 | * false otherwise. |
| 152 | */ |
| 153 | bool wasDestroyed() const { return NULL == fGpu; } |
| 154 | |
| 155 | /** |
| 156 | * Retrieves the context that owns the object. Note that it is possible for |
| 157 | * this to return NULL. When objects have been release()ed or abandon()ed |
| 158 | * they no longer have an owning context. Destroying a GrContext |
| 159 | * automatically releases all its resources. |
| 160 | */ |
| 161 | const GrContext* getContext() const; |
| 162 | GrContext* getContext(); |
| 163 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 164 | /** |
| 165 | * Retrieves the amount of GPU memory used by this resource in bytes. It is |
| 166 | * approximate since we aren't aware of additional padding or copies made |
| 167 | * by the driver. |
| 168 | * |
| 169 | * @return the amount of GPU memory used in bytes |
| 170 | */ |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 171 | size_t gpuMemorySize() const { |
| 172 | if (kInvalidGpuMemorySize == fGpuMemorySize) { |
| 173 | fGpuMemorySize = this->onGpuMemorySize(); |
| 174 | SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize); |
| 175 | } |
| 176 | return fGpuMemorySize; |
| 177 | } |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 178 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 179 | /** |
bsalomon | 52e9d63 | 2014-09-05 12:23:12 -0700 | [diff] [blame] | 180 | * Gets an id that is unique for this GrGpuResource object. It is static in that it does |
| 181 | * not change when the content of the GrGpuResource object changes. This will never return |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 182 | * 0. |
| 183 | */ |
| 184 | uint32_t getUniqueID() const { return fUniqueID; } |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 185 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 186 | /** Returns the current unique key for the resource. It will be invalid if the resource has no |
| 187 | associated unique key. */ |
| 188 | const GrUniqueKey& getUniqueKey() const { return fUniqueKey; } |
bsalomon | 563ff60 | 2015-02-02 17:25:26 -0800 | [diff] [blame] | 189 | |
bsalomon | 453cf40 | 2014-11-11 14:15:57 -0800 | [diff] [blame] | 190 | /** |
junov | 5756aff | 2014-12-11 14:59:31 -0800 | [diff] [blame] | 191 | * Attach a custom data object to this resource. The data will remain attached |
| 192 | * for the lifetime of this resource (until it is abandoned or released). |
| 193 | * Takes a ref on data. Previously attached data, if any, is unrefed. |
| 194 | * Returns the data argument, for convenience. |
| 195 | */ |
| 196 | const SkData* setCustomData(const SkData* data); |
| 197 | |
| 198 | /** |
| 199 | * Returns the custom data object that was attached to this resource by |
| 200 | * calling setCustomData. |
| 201 | */ |
| 202 | const SkData* getCustomData() const { return fData.get(); } |
| 203 | |
| 204 | /** |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 205 | * Internal-only helper class used for manipulations of the resource by the cache. |
bsalomon | 453cf40 | 2014-11-11 14:15:57 -0800 | [diff] [blame] | 206 | */ |
| 207 | class CacheAccess; |
| 208 | inline CacheAccess cacheAccess(); |
| 209 | inline const CacheAccess cacheAccess() const; |
| 210 | |
junov | 436293a | 2014-12-11 10:32:32 -0800 | [diff] [blame] | 211 | /** |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 212 | * Internal-only helper class used for manipulations of the resource by internal code. |
| 213 | */ |
| 214 | class ResourcePriv; |
| 215 | inline ResourcePriv resourcePriv(); |
| 216 | inline const ResourcePriv resourcePriv() const; |
| 217 | |
| 218 | /** |
junov | 436293a | 2014-12-11 10:32:32 -0800 | [diff] [blame] | 219 | * Removes references to objects in the underlying 3D API without freeing them. |
| 220 | * Called by CacheAccess. |
| 221 | * In general this method should not be called outside of skia. It was |
| 222 | * made by public for a special case where it needs to be called in Blink |
| 223 | * when a texture becomes unsafe to use after having been shared through |
| 224 | * a texture mailbox. |
| 225 | */ |
| 226 | void abandon(); |
| 227 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 228 | /** |
| 229 | * Dumps memory usage information for this GrGpuResource to traceMemoryDump. |
| 230 | * Typically, subclasses should not need to override this, and should only |
| 231 | * need to override setMemoryBacking. |
| 232 | **/ |
| 233 | virtual void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const; |
| 234 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 235 | protected: |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 236 | // This must be called by every non-wrapped GrGpuObject. It should be called once the object is |
| 237 | // fully initialized (i.e. only from the constructors of the final class). |
| 238 | void registerWithCache(SkBudgeted); |
bsalomon | 1696126 | 2014-08-26 14:01:07 -0700 | [diff] [blame] | 239 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 240 | // This must be called by every GrGpuObject that references any wrapped backend objects. It |
| 241 | // should be called once the object is fully initialized (i.e. only from the constructors of the |
| 242 | // final class). |
| 243 | void registerWithCacheWrapped(); |
| 244 | |
| 245 | GrGpuResource(GrGpu*); |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 246 | virtual ~GrGpuResource(); |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 247 | |
| 248 | GrGpu* getGpu() const { return fGpu; } |
| 249 | |
bsalomon | 12299ab | 2014-11-14 13:33:09 -0800 | [diff] [blame] | 250 | /** Overridden to free GPU resources in the backend API. */ |
| 251 | virtual void onRelease() { } |
| 252 | /** Overridden to abandon any internal handles, ptrs, etc to backend API resources. |
| 253 | This may be called when the underlying 3D context is no longer valid and so no |
| 254 | backend API calls should be made. */ |
| 255 | virtual void onAbandon() { } |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 256 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 257 | /** |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 258 | * This entry point should be called whenever gpuMemorySize() should report a different size. |
| 259 | * The cache will call gpuMemorySize() to update the current size of the resource. |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 260 | */ |
| 261 | void didChangeGpuMemorySize() const; |
| 262 | |
bsalomon | 744998e | 2014-08-28 09:54:34 -0700 | [diff] [blame] | 263 | /** |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 264 | * Allows subclasses to add additional backing information to the SkTraceMemoryDump. Called by |
| 265 | * onMemoryDump. The default implementation adds no backing information. |
| 266 | **/ |
| 267 | virtual void setMemoryBacking(SkTraceMemoryDump*, const SkString&) const {} |
| 268 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 269 | private: |
bsalomon | 12299ab | 2014-11-14 13:33:09 -0800 | [diff] [blame] | 270 | /** |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 271 | * Called by the registerWithCache if the resource is available to be used as scratch. |
| 272 | * Resource subclasses should override this if the instances should be recycled as scratch |
| 273 | * resources and populate the scratchKey with the key. |
| 274 | * By default resources are not recycled as scratch. |
| 275 | **/ |
| 276 | virtual void computeScratchKey(GrScratchKey*) const { }; |
| 277 | |
| 278 | /** |
bsalomon | 12299ab | 2014-11-14 13:33:09 -0800 | [diff] [blame] | 279 | * Frees the object in the underlying 3D API. Called by CacheAccess. |
| 280 | */ |
| 281 | void release(); |
| 282 | |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 283 | virtual size_t onGpuMemorySize() const = 0; |
| 284 | |
bsalomon | 9f2d157 | 2015-02-17 11:47:40 -0800 | [diff] [blame] | 285 | // See comments in CacheAccess and ResourcePriv. |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 286 | void setUniqueKey(const GrUniqueKey&); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 287 | void removeUniqueKey(); |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 288 | void notifyAllCntsAreZero(CntType) const; |
| 289 | bool notifyRefCountIsZero() const; |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 290 | void removeScratchKey(); |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 291 | void makeBudgeted(); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 292 | void makeUnbudgeted(); |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 293 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 294 | #ifdef SK_DEBUG |
| 295 | friend class GrGpu; // for assert in GrGpu to access getGpu |
| 296 | #endif |
| 297 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 298 | static uint32_t CreateUniqueID(); |
| 299 | |
bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 300 | // An index into a heap when this resource is purgeable or an array when not. This is maintained |
| 301 | // by the cache. |
bsalomon | 9f2d157 | 2015-02-17 11:47:40 -0800 | [diff] [blame] | 302 | int fCacheArrayIndex; |
| 303 | // This value reflects how recently this resource was accessed in the cache. This is maintained |
| 304 | // by the cache. |
| 305 | uint32_t fTimestamp; |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 306 | |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 307 | static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0); |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 308 | GrScratchKey fScratchKey; |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 309 | GrUniqueKey fUniqueKey; |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 310 | |
| 311 | // This is not ref'ed but abandon() or release() will be called before the GrGpu object |
| 312 | // is destroyed. Those calls set will this to NULL. |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 313 | GrGpu* fGpu; |
| 314 | mutable size_t fGpuMemorySize; |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 315 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 316 | SkBudgeted fBudgeted; |
| 317 | bool fRefsWrappedObjects; |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 318 | const uint32_t fUniqueID; |
bsalomon | 744998e | 2014-08-28 09:54:34 -0700 | [diff] [blame] | 319 | |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 320 | SkAutoTUnref<const SkData> fData; |
junov | 5756aff | 2014-12-11 14:59:31 -0800 | [diff] [blame] | 321 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 322 | typedef GrIORef<GrGpuResource> INHERITED; |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 323 | friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and notifyRefCntIsZero. |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 324 | }; |
| 325 | |
| 326 | #endif |