| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrGpuResource_DEFINED | 8 #ifndef GrGpuResource_DEFINED |
| 9 #define GrGpuResource_DEFINED | 9 #define GrGpuResource_DEFINED |
| 10 | 10 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 void validate() const { | 63 void validate() const { |
| 64 #ifdef SK_DEBUG | 64 #ifdef SK_DEBUG |
| 65 SkASSERT(fRefCnt >= 0); | 65 SkASSERT(fRefCnt >= 0); |
| 66 SkASSERT(fPendingReads >= 0); | 66 SkASSERT(fPendingReads >= 0); |
| 67 SkASSERT(fPendingWrites >= 0); | 67 SkASSERT(fPendingWrites >= 0); |
| 68 SkASSERT(fRefCnt + fPendingReads + fPendingWrites > 0); | 68 SkASSERT(fRefCnt + fPendingReads + fPendingWrites > 0); |
| 69 #endif | 69 #endif |
| 70 } | 70 } |
| 71 | 71 |
| 72 protected: | 72 protected: |
| 73 GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0), fIsScratch(kNo_
IsScratch) { } | 73 GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0) { } |
| 74 | 74 |
| 75 bool internalHasPendingRead() const { return SkToBool(fPendingReads); } | 75 bool internalHasPendingRead() const { return SkToBool(fPendingReads); } |
| 76 bool internalHasPendingWrite() const { return SkToBool(fPendingWrites); } | 76 bool internalHasPendingWrite() const { return SkToBool(fPendingWrites); } |
| 77 bool internalHasPendingIO() const { return SkToBool(fPendingWrites | fPendin
gReads); } | 77 bool internalHasPendingIO() const { return SkToBool(fPendingWrites | fPendin
gReads); } |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 void addPendingRead() const { | 80 void addPendingRead() const { |
| 81 this->validate(); | 81 this->validate(); |
| 82 ++fPendingReads; | 82 ++fPendingReads; |
| 83 } | 83 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 mutable int32_t fRefCnt; | 115 mutable int32_t fRefCnt; |
| 116 mutable int32_t fPendingReads; | 116 mutable int32_t fPendingReads; |
| 117 mutable int32_t fPendingWrites; | 117 mutable int32_t fPendingWrites; |
| 118 | 118 |
| 119 // This class is used to manage conversion of refs to pending reads/writes. | 119 // This class is used to manage conversion of refs to pending reads/writes. |
| 120 friend class GrGpuResourceRef; | 120 friend class GrGpuResourceRef; |
| 121 | 121 friend class GrResourceCache2; // to check IO ref counts. |
| 122 // This is temporary until GrResourceCache is fully replaced by GrResourceCa
che2. | |
| 123 enum IsScratch { | |
| 124 kNo_IsScratch, | |
| 125 kYes_IsScratch | |
| 126 } fIsScratch; | |
| 127 | |
| 128 friend class GrContext; // to set the above field. | |
| 129 friend class GrResourceCache; // to check the above field. | |
| 130 friend class GrResourceCache2; // to check the above field. | |
| 131 | 122 |
| 132 template <typename, GrIOType> friend class GrPendingIOResource; | 123 template <typename, GrIOType> friend class GrPendingIOResource; |
| 133 }; | 124 }; |
| 134 | 125 |
| 135 /** | 126 /** |
| 136 * Base class for objects that can be kept in the GrResourceCache. | 127 * Base class for objects that can be kept in the GrResourceCache. |
| 137 */ | 128 */ |
| 138 class SK_API GrGpuResource : public GrIORef<GrGpuResource> { | 129 class SK_API GrGpuResource : public GrIORef<GrGpuResource> { |
| 139 public: | 130 public: |
| 140 SK_DECLARE_INST_COUNT(GrGpuResource) | 131 SK_DECLARE_INST_COUNT(GrGpuResource) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 * Retrieves the amount of GPU memory used by this resource in bytes. It is | 167 * Retrieves the amount of GPU memory used by this resource in bytes. It is |
| 177 * approximate since we aren't aware of additional padding or copies made | 168 * approximate since we aren't aware of additional padding or copies made |
| 178 * by the driver. | 169 * by the driver. |
| 179 * | 170 * |
| 180 * @return the amount of GPU memory used in bytes | 171 * @return the amount of GPU memory used in bytes |
| 181 */ | 172 */ |
| 182 virtual size_t gpuMemorySize() const = 0; | 173 virtual size_t gpuMemorySize() const = 0; |
| 183 | 174 |
| 184 void setCacheEntry(GrResourceCacheEntry* cacheEntry) { fCacheEntry = cacheEn
try; } | 175 void setCacheEntry(GrResourceCacheEntry* cacheEntry) { fCacheEntry = cacheEn
try; } |
| 185 GrResourceCacheEntry* getCacheEntry() const { return fCacheEntry; } | 176 GrResourceCacheEntry* getCacheEntry() const { return fCacheEntry; } |
| 177 bool isScratch() const; |
| 186 | 178 |
| 187 /** | 179 /** |
| 188 * If this resource can be used as a scratch resource this returns a valid | 180 * If this resource can be used as a scratch resource this returns a valid |
| 189 * scratch key. Otherwise it returns a key for which isNullScratch is true. | 181 * scratch key. Otherwise it returns a key for which isNullScratch is true. |
| 190 */ | 182 */ |
| 191 const GrResourceKey& getScratchKey() const { return fScratchKey; } | 183 const GrResourceKey& getScratchKey() const { return fScratchKey; } |
| 192 | 184 |
| 185 /** |
| 186 * If this resource is currently cached by its contents then this will retur
n |
| 187 * the content key. Otherwise, NULL is returned. |
| 188 */ |
| 189 const GrResourceKey* getContentKey() const; |
| 190 |
| 193 /** | 191 /** |
| 194 * Gets an id that is unique for this GrGpuResource object. It is static in
that it does | 192 * Gets an id that is unique for this GrGpuResource object. It is static in
that it does |
| 195 * not change when the content of the GrGpuResource object changes. This wil
l never return | 193 * not change when the content of the GrGpuResource object changes. This wil
l never return |
| 196 * 0. | 194 * 0. |
| 197 */ | 195 */ |
| 198 uint32_t getUniqueID() const { return fUniqueID; } | 196 uint32_t getUniqueID() const { return fUniqueID; } |
| 199 | 197 |
| 200 protected: | 198 protected: |
| 201 // This must be called by every GrGpuObject. It should be called once the ob
ject is fully | 199 // This must be called by every GrGpuObject. It should be called once the ob
ject is fully |
| 202 // initialized (i.e. not in a base class constructor). | 200 // initialized (i.e. not in a base class constructor). |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache | 258 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache |
| 261 const uint32_t fUniqueID; | 259 const uint32_t fUniqueID; |
| 262 | 260 |
| 263 GrResourceKey fScratchKey; | 261 GrResourceKey fScratchKey; |
| 264 | 262 |
| 265 typedef GrIORef<GrGpuResource> INHERITED; | 263 typedef GrIORef<GrGpuResource> INHERITED; |
| 266 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable. | 264 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable. |
| 267 }; | 265 }; |
| 268 | 266 |
| 269 #endif | 267 #endif |
| OLD | NEW |