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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/private/GrResourceKey.h" |
| 12 | #include "include/private/GrTypesPriv.h" |
| 13 | #include "include/private/SkNoncopyable.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 | /** |
Robert Phillips | bf8bf83 | 2019-08-30 13:13:44 -0400 | [diff] [blame] | 21 | * Base class for GrGpuResource. Provides the hooks for resources to interact with the cache. |
| 22 | * Separated out as a base class to isolate the ref-cnting behavior and provide friendship without |
| 23 | * exposing all of GrGpuResource. |
mtklein | 6f07665 | 2015-01-13 08:22:43 -0800 | [diff] [blame] | 24 | * |
Robert Phillips | bf8bf83 | 2019-08-30 13:13:44 -0400 | [diff] [blame] | 25 | * PRIOR to the last ref being removed DERIVED::notifyRefCntWillBeZero() will be called |
| 26 | * (static poly morphism using CRTP). It is legal for additional ref's to be added |
| 27 | * during this time. AFTER the ref count reaches zero DERIVED::notifyRefCntIsZero() will be |
| 28 | * called. |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 29 | */ |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 30 | template <typename DERIVED> class GrIORef : public SkNoncopyable { |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 31 | public: |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 32 | bool unique() const { return fRefCnt == 1; } |
| 33 | |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 34 | void ref() const { |
Brian Salomon | 01ceae9 | 2019-04-02 11:49:54 -0400 | [diff] [blame] | 35 | // Only the cache should be able to add the first ref to a resource. |
Brian Salomon | b810c25 | 2019-09-23 12:48:06 -0400 | [diff] [blame] | 36 | SkASSERT(this->getRefCnt() > 0); |
| 37 | // No barrier required. |
| 38 | (void)fRefCnt.fetch_add(+1, std::memory_order_relaxed); |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 39 | } |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 40 | |
| 41 | void unref() const { |
Brian Salomon | b810c25 | 2019-09-23 12:48:06 -0400 | [diff] [blame] | 42 | SkASSERT(this->getRefCnt() > 0); |
| 43 | if (1 == fRefCnt.fetch_add(-1, std::memory_order_acq_rel)) { |
| 44 | // At this point we better be the only thread accessing this resource. |
| 45 | // Trick out the notifyRefCntWillBeZero() call by adding back one more ref. |
| 46 | fRefCnt.fetch_add(+1, std::memory_order_relaxed); |
Robert Phillips | bf8bf83 | 2019-08-30 13:13:44 -0400 | [diff] [blame] | 47 | static_cast<const DERIVED*>(this)->notifyRefCntWillBeZero(); |
Brian Salomon | b810c25 | 2019-09-23 12:48:06 -0400 | [diff] [blame] | 48 | // notifyRefCntWillBeZero() could have done anything, including re-refing this and |
| 49 | // passing on to another thread. Take away the ref-count we re-added above and see |
| 50 | // if we're back to zero. |
| 51 | // TODO: Consider making it so that refs can't be added and merge |
| 52 | // notifyRefCntWillBeZero()/willRemoveLastRef() with notifyRefCntIsZero(). |
| 53 | if (1 == fRefCnt.fetch_add(-1, std::memory_order_acq_rel)) { |
| 54 | static_cast<const DERIVED*>(this)->notifyRefCntIsZero(); |
| 55 | } |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 56 | } |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 59 | #if GR_TEST_UTILS |
Brian Salomon | b810c25 | 2019-09-23 12:48:06 -0400 | [diff] [blame] | 60 | int32_t testingOnly_getRefCnt() const { return this->getRefCnt(); } |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 61 | #endif |
| 62 | |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 63 | protected: |
Robert Phillips | bf8bf83 | 2019-08-30 13:13:44 -0400 | [diff] [blame] | 64 | friend class GrResourceCache; // for internalHasRef |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 65 | |
Robert Phillips | bf8bf83 | 2019-08-30 13:13:44 -0400 | [diff] [blame] | 66 | GrIORef() : fRefCnt(1) {} |
bsalomon | 8d034a1 | 2014-09-22 12:21:08 -0700 | [diff] [blame] | 67 | |
Brian Salomon | b810c25 | 2019-09-23 12:48:06 -0400 | [diff] [blame] | 68 | bool internalHasRef() const { return SkToBool(this->getRefCnt()); } |
Robert Phillips | bf8bf83 | 2019-08-30 13:13:44 -0400 | [diff] [blame] | 69 | |
Brian Salomon | 01ceae9 | 2019-04-02 11:49:54 -0400 | [diff] [blame] | 70 | // Privileged method that allows going from ref count = 0 to ref count = 1. |
| 71 | void addInitialRef() const { |
Robert Phillips | bf8bf83 | 2019-08-30 13:13:44 -0400 | [diff] [blame] | 72 | SkASSERT(fRefCnt >= 0); |
Brian Salomon | b810c25 | 2019-09-23 12:48:06 -0400 | [diff] [blame] | 73 | // No barrier required. |
| 74 | (void)fRefCnt.fetch_add(+1, std::memory_order_relaxed); |
Brian Salomon | 01ceae9 | 2019-04-02 11:49:54 -0400 | [diff] [blame] | 75 | } |
| 76 | |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 77 | private: |
Brian Salomon | b810c25 | 2019-09-23 12:48:06 -0400 | [diff] [blame] | 78 | int32_t getRefCnt() const { return fRefCnt.load(std::memory_order_relaxed); } |
| 79 | |
| 80 | mutable std::atomic<int32_t> fRefCnt; |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 81 | |
| 82 | typedef SkNoncopyable INHERITED; |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | /** |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 86 | * Base class for objects that can be kept in the GrResourceCache. |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 87 | */ |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 88 | class GrGpuResource : public GrIORef<GrGpuResource> { |
bsalomon | 00b76bd | 2014-09-03 14:05:49 -0700 | [diff] [blame] | 89 | public: |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 90 | /** |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 91 | * Tests whether a object has been abandoned or released. All objects will |
| 92 | * be in this state after their creating GrContext is destroyed or has |
| 93 | * contextLost called. It's up to the client to test wasDestroyed() before |
| 94 | * attempting to use an object if it holds refs on objects across |
| 95 | * ~GrContext, freeResources with the force flag, or contextLost. |
| 96 | * |
| 97 | * @return true if the object has been released or abandoned, |
| 98 | * false otherwise. |
| 99 | */ |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 100 | bool wasDestroyed() const { return nullptr == fGpu; } |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Retrieves the context that owns the object. Note that it is possible for |
| 104 | * this to return NULL. When objects have been release()ed or abandon()ed |
| 105 | * they no longer have an owning context. Destroying a GrContext |
| 106 | * automatically releases all its resources. |
| 107 | */ |
| 108 | const GrContext* getContext() const; |
| 109 | GrContext* getContext(); |
| 110 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 111 | /** |
| 112 | * Retrieves the amount of GPU memory used by this resource in bytes. It is |
| 113 | * approximate since we aren't aware of additional padding or copies made |
| 114 | * by the driver. |
| 115 | * |
| 116 | * @return the amount of GPU memory used in bytes |
| 117 | */ |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 118 | size_t gpuMemorySize() const { |
| 119 | if (kInvalidGpuMemorySize == fGpuMemorySize) { |
| 120 | fGpuMemorySize = this->onGpuMemorySize(); |
| 121 | SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize); |
| 122 | } |
| 123 | return fGpuMemorySize; |
| 124 | } |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 125 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 126 | class UniqueID { |
| 127 | public: |
Brian Salomon | 8c8806f | 2019-02-07 13:55:57 -0500 | [diff] [blame] | 128 | UniqueID() = default; |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 129 | |
| 130 | explicit UniqueID(uint32_t id) : fID(id) {} |
| 131 | |
| 132 | uint32_t asUInt() const { return fID; } |
| 133 | |
Brian Salomon | 8c8806f | 2019-02-07 13:55:57 -0500 | [diff] [blame] | 134 | bool operator==(const UniqueID& other) const { return fID == other.fID; } |
| 135 | bool operator!=(const UniqueID& other) const { return !(*this == other); } |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 136 | |
| 137 | void makeInvalid() { fID = SK_InvalidUniqueID; } |
Brian Salomon | 8c8806f | 2019-02-07 13:55:57 -0500 | [diff] [blame] | 138 | bool isInvalid() const { return fID == SK_InvalidUniqueID; } |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 139 | |
| 140 | protected: |
Brian Salomon | 8c8806f | 2019-02-07 13:55:57 -0500 | [diff] [blame] | 141 | uint32_t fID = SK_InvalidUniqueID; |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 142 | }; |
| 143 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 144 | /** |
bsalomon | 52e9d63 | 2014-09-05 12:23:12 -0700 | [diff] [blame] | 145 | * Gets an id that is unique for this GrGpuResource object. It is static in that it does |
| 146 | * 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] | 147 | * 0. |
| 148 | */ |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 149 | UniqueID uniqueID() const { return fUniqueID; } |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 150 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 151 | /** Returns the current unique key for the resource. It will be invalid if the resource has no |
| 152 | associated unique key. */ |
| 153 | const GrUniqueKey& getUniqueKey() const { return fUniqueKey; } |
bsalomon | 563ff60 | 2015-02-02 17:25:26 -0800 | [diff] [blame] | 154 | |
bsalomon | 453cf40 | 2014-11-11 14:15:57 -0800 | [diff] [blame] | 155 | /** |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 156 | * Internal-only helper class used for manipulations of the resource by the cache. |
bsalomon | 453cf40 | 2014-11-11 14:15:57 -0800 | [diff] [blame] | 157 | */ |
| 158 | class CacheAccess; |
| 159 | inline CacheAccess cacheAccess(); |
| 160 | inline const CacheAccess cacheAccess() const; |
| 161 | |
junov | 436293a | 2014-12-11 10:32:32 -0800 | [diff] [blame] | 162 | /** |
Brian Salomon | 01ceae9 | 2019-04-02 11:49:54 -0400 | [diff] [blame] | 163 | * Internal-only helper class used for manipulations of the resource by GrSurfaceProxy. |
| 164 | */ |
| 165 | class ProxyAccess; |
| 166 | inline ProxyAccess proxyAccess(); |
| 167 | |
| 168 | /** |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 169 | * Internal-only helper class used for manipulations of the resource by internal code. |
| 170 | */ |
| 171 | class ResourcePriv; |
| 172 | inline ResourcePriv resourcePriv(); |
| 173 | inline const ResourcePriv resourcePriv() const; |
| 174 | |
| 175 | /** |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 176 | * Dumps memory usage information for this GrGpuResource to traceMemoryDump. |
| 177 | * Typically, subclasses should not need to override this, and should only |
| 178 | * need to override setMemoryBacking. |
| 179 | **/ |
| 180 | virtual void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const; |
| 181 | |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 182 | /** |
| 183 | * Describes the type of gpu resource that is represented by the implementing |
| 184 | * class (e.g. texture, buffer object, stencil). This data is used for diagnostic |
| 185 | * purposes by dumpMemoryStatistics(). |
| 186 | * |
| 187 | * The value returned is expected to be long lived and will not be copied by the caller. |
| 188 | */ |
| 189 | virtual const char* getResourceType() const = 0; |
| 190 | |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 191 | static uint32_t CreateUniqueID(); |
| 192 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 193 | protected: |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 194 | // This must be called by every non-wrapped GrGpuObject. It should be called once the object is |
| 195 | // fully initialized (i.e. only from the constructors of the final class). |
| 196 | void registerWithCache(SkBudgeted); |
bsalomon | 1696126 | 2014-08-26 14:01:07 -0700 | [diff] [blame] | 197 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 198 | // This must be called by every GrGpuObject that references any wrapped backend objects. It |
| 199 | // should be called once the object is fully initialized (i.e. only from the constructors of the |
| 200 | // final class). |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 201 | void registerWithCacheWrapped(GrWrapCacheable); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 202 | |
| 203 | GrGpuResource(GrGpu*); |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 204 | virtual ~GrGpuResource(); |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 205 | |
| 206 | GrGpu* getGpu() const { return fGpu; } |
| 207 | |
bsalomon | 12299ab | 2014-11-14 13:33:09 -0800 | [diff] [blame] | 208 | /** Overridden to free GPU resources in the backend API. */ |
Brian Salomon | 9f7d9a2 | 2018-12-11 19:01:32 +0000 | [diff] [blame] | 209 | virtual void onRelease() { } |
bsalomon | 12299ab | 2014-11-14 13:33:09 -0800 | [diff] [blame] | 210 | /** Overridden to abandon any internal handles, ptrs, etc to backend API resources. |
| 211 | This may be called when the underlying 3D context is no longer valid and so no |
| 212 | backend API calls should be made. */ |
Brian Salomon | 9f7d9a2 | 2018-12-11 19:01:32 +0000 | [diff] [blame] | 213 | virtual void onAbandon() { } |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 214 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 215 | /** |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 216 | * Allows subclasses to add additional backing information to the SkTraceMemoryDump. |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 217 | **/ |
| 218 | virtual void setMemoryBacking(SkTraceMemoryDump*, const SkString&) const {} |
| 219 | |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 220 | /** |
| 221 | * Returns a string that uniquely identifies this resource. |
| 222 | */ |
| 223 | SkString getResourceName() const; |
| 224 | |
| 225 | /** |
| 226 | * A helper for subclasses that override dumpMemoryStatistics(). This method using a format |
| 227 | * consistent with the default implementation of dumpMemoryStatistics() but allows the caller |
| 228 | * to customize various inputs. |
| 229 | */ |
| 230 | void dumpMemoryStatisticsPriv(SkTraceMemoryDump* traceMemoryDump, const SkString& resourceName, |
| 231 | const char* type, size_t size) const; |
| 232 | |
Brian Salomon | 9f7d9a2 | 2018-12-11 19:01:32 +0000 | [diff] [blame] | 233 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 234 | private: |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 235 | bool isPurgeable() const; |
Brian Salomon | 2c791fc | 2019-04-02 11:52:03 -0400 | [diff] [blame] | 236 | bool hasRef() const; |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 237 | |
bsalomon | 12299ab | 2014-11-14 13:33:09 -0800 | [diff] [blame] | 238 | /** |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 239 | * Called by the registerWithCache if the resource is available to be used as scratch. |
| 240 | * Resource subclasses should override this if the instances should be recycled as scratch |
| 241 | * resources and populate the scratchKey with the key. |
| 242 | * By default resources are not recycled as scratch. |
| 243 | **/ |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 244 | virtual void computeScratchKey(GrScratchKey*) const {} |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 245 | |
| 246 | /** |
Brian Salomon | 35ba614 | 2019-01-24 13:08:59 -0500 | [diff] [blame] | 247 | * Removes references to objects in the underlying 3D API without freeing them. |
| 248 | * Called by CacheAccess. |
| 249 | */ |
| 250 | void abandon(); |
| 251 | |
| 252 | /** |
bsalomon | 12299ab | 2014-11-14 13:33:09 -0800 | [diff] [blame] | 253 | * Frees the object in the underlying 3D API. Called by CacheAccess. |
| 254 | */ |
| 255 | void release(); |
| 256 | |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 257 | virtual size_t onGpuMemorySize() const = 0; |
| 258 | |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 259 | /** |
Robert Phillips | bf8bf83 | 2019-08-30 13:13:44 -0400 | [diff] [blame] | 260 | * Called by GrIORef when a resource is about to lose its last ref |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 261 | */ |
Robert Phillips | bf8bf83 | 2019-08-30 13:13:44 -0400 | [diff] [blame] | 262 | virtual void willRemoveLastRef() {} |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 263 | |
bsalomon | 9f2d157 | 2015-02-17 11:47:40 -0800 | [diff] [blame] | 264 | // See comments in CacheAccess and ResourcePriv. |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 265 | void setUniqueKey(const GrUniqueKey&); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 266 | void removeUniqueKey(); |
Robert Phillips | bf8bf83 | 2019-08-30 13:13:44 -0400 | [diff] [blame] | 267 | void notifyRefCntWillBeZero() const; |
| 268 | void notifyRefCntIsZero() const; |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 269 | void removeScratchKey(); |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 270 | void makeBudgeted(); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 271 | void makeUnbudgeted(); |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 272 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 273 | #ifdef SK_DEBUG |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 274 | friend class GrGpu; // for assert in GrGpu to access getGpu |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 275 | #endif |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 276 | |
bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 277 | // An index into a heap when this resource is purgeable or an array when not. This is maintained |
| 278 | // by the cache. |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 279 | int fCacheArrayIndex; |
bsalomon | 9f2d157 | 2015-02-17 11:47:40 -0800 | [diff] [blame] | 280 | // This value reflects how recently this resource was accessed in the cache. This is maintained |
| 281 | // by the cache. |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 282 | uint32_t fTimestamp; |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 283 | GrStdSteadyClock::time_point fTimeWhenBecamePurgeable; |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 284 | |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 285 | static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 286 | GrScratchKey fScratchKey; |
| 287 | GrUniqueKey fUniqueKey; |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 288 | |
| 289 | // This is not ref'ed but abandon() or release() will be called before the GrGpu object |
| 290 | // is destroyed. Those calls set will this to NULL. |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 291 | GrGpu* fGpu; |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 292 | mutable size_t fGpuMemorySize = kInvalidGpuMemorySize; |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 293 | |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 294 | GrBudgetedType fBudgetedType = GrBudgetedType::kUnbudgetedUncacheable; |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 295 | bool fRefsWrappedObjects = false; |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 296 | const UniqueID fUniqueID; |
bsalomon | 744998e | 2014-08-28 09:54:34 -0700 | [diff] [blame] | 297 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 298 | typedef GrIORef<GrGpuResource> INHERITED; |
Robert Phillips | bf8bf83 | 2019-08-30 13:13:44 -0400 | [diff] [blame] | 299 | friend class GrIORef<GrGpuResource>; // to access notifyRefCntWillBeZero and notifyRefCntIsZero. |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 300 | }; |
| 301 | |
Brian Salomon | 01ceae9 | 2019-04-02 11:49:54 -0400 | [diff] [blame] | 302 | class GrGpuResource::ProxyAccess { |
| 303 | private: |
| 304 | ProxyAccess(GrGpuResource* resource) : fResource(resource) {} |
| 305 | |
| 306 | /** Proxies are allowed to take a resource from no refs to one ref. */ |
Brian Salomon | 2c791fc | 2019-04-02 11:52:03 -0400 | [diff] [blame] | 307 | void ref(GrResourceCache* cache); |
Brian Salomon | 01ceae9 | 2019-04-02 11:49:54 -0400 | [diff] [blame] | 308 | |
| 309 | // No taking addresses of this type. |
| 310 | const CacheAccess* operator&() const = delete; |
| 311 | CacheAccess* operator&() = delete; |
| 312 | |
| 313 | GrGpuResource* fResource; |
| 314 | |
| 315 | friend class GrGpuResource; |
| 316 | friend class GrSurfaceProxy; |
Brian Salomon | 01ceae9 | 2019-04-02 11:49:54 -0400 | [diff] [blame] | 317 | }; |
| 318 | |
| 319 | inline GrGpuResource::ProxyAccess GrGpuResource::proxyAccess() { return ProxyAccess(this); } |
| 320 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 321 | #endif |