| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 void validate() const { | 64 void validate() const { |
| 65 #ifdef SK_DEBUG | 65 #ifdef SK_DEBUG |
| 66 SkASSERT(fRefCnt >= 0); | 66 SkASSERT(fRefCnt >= 0); |
| 67 SkASSERT(fPendingReads >= 0); | 67 SkASSERT(fPendingReads >= 0); |
| 68 SkASSERT(fPendingWrites >= 0); | 68 SkASSERT(fPendingWrites >= 0); |
| 69 SkASSERT(fRefCnt + fPendingReads + fPendingWrites > 0); | 69 SkASSERT(fRefCnt + fPendingReads + fPendingWrites > 0); |
| 70 #endif | 70 #endif |
| 71 } | 71 } |
| 72 | 72 |
| 73 protected: | 73 protected: |
| 74 GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0) { } | 74 GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0), fIsScratch(kNo_
IsScratch) { } |
| 75 | 75 |
| 76 bool internalHasPendingRead() const { return SkToBool(fPendingReads); } | 76 bool internalHasPendingRead() const { return SkToBool(fPendingReads); } |
| 77 bool internalHasPendingWrite() const { return SkToBool(fPendingWrites); } | 77 bool internalHasPendingWrite() const { return SkToBool(fPendingWrites); } |
| 78 bool internalHasPendingIO() const { return SkToBool(fPendingWrites | fPendin
gReads); } | 78 bool internalHasPendingIO() const { return SkToBool(fPendingWrites | fPendin
gReads); } |
| 79 | 79 |
| 80 private: | 80 private: |
| 81 void addPendingRead() const { | 81 void addPendingRead() const { |
| 82 this->validate(); | 82 this->validate(); |
| 83 ++fPendingReads; | 83 ++fPendingReads; |
| 84 } | 84 } |
| (...skipping 26 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 friend class GrResourceCache2; // to check IO ref counts. | 121 |
| 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. |
| 122 | 131 |
| 123 template <typename, GrIOType> friend class GrPendingIOResource; | 132 template <typename, GrIOType> friend class GrPendingIOResource; |
| 124 }; | 133 }; |
| 125 | 134 |
| 126 /** | 135 /** |
| 127 * Base class for objects that can be kept in the GrResourceCache. | 136 * Base class for objects that can be kept in the GrResourceCache. |
| 128 */ | 137 */ |
| 129 class GrGpuResource : public GrIORef<GrGpuResource> { | 138 class GrGpuResource : public GrIORef<GrGpuResource> { |
| 130 public: | 139 public: |
| 131 SK_DECLARE_INST_COUNT(GrGpuResource) | 140 SK_DECLARE_INST_COUNT(GrGpuResource) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 183 |
| 175 void setCacheEntry(GrResourceCacheEntry* cacheEntry) { fCacheEntry = cacheEn
try; } | 184 void setCacheEntry(GrResourceCacheEntry* cacheEntry) { fCacheEntry = cacheEn
try; } |
| 176 GrResourceCacheEntry* getCacheEntry() const { return fCacheEntry; } | 185 GrResourceCacheEntry* getCacheEntry() const { return fCacheEntry; } |
| 177 | 186 |
| 178 /** | 187 /** |
| 179 * If this resource can be used as a scratch resource this returns a valid | 188 * If this resource can be used as a scratch resource this returns a valid |
| 180 * scratch key. Otherwise it returns a key for which isNullScratch is true. | 189 * scratch key. Otherwise it returns a key for which isNullScratch is true. |
| 181 */ | 190 */ |
| 182 const GrResourceKey& getScratchKey() const { return fScratchKey; } | 191 const GrResourceKey& getScratchKey() const { return fScratchKey; } |
| 183 | 192 |
| 184 /** | |
| 185 * If this resource is currently cached by its contents then this will retur
n | |
| 186 * the content key. Otherwise, NULL is returned. | |
| 187 */ | |
| 188 const GrResourceKey* getContentKey() const; | |
| 189 | |
| 190 /** | 193 /** |
| 191 * Gets an id that is unique for this GrGpuResource object. It is static in
that it does | 194 * Gets an id that is unique for this GrGpuResource object. It is static in
that it does |
| 192 * not change when the content of the GrGpuResource object changes. This wil
l never return | 195 * not change when the content of the GrGpuResource object changes. This wil
l never return |
| 193 * 0. | 196 * 0. |
| 194 */ | 197 */ |
| 195 uint32_t getUniqueID() const { return fUniqueID; } | 198 uint32_t getUniqueID() const { return fUniqueID; } |
| 196 | 199 |
| 197 protected: | 200 protected: |
| 198 // This must be called by every GrGpuObject. It should be called once the ob
ject is fully | 201 // This must be called by every GrGpuObject. It should be called once the ob
ject is fully |
| 199 // initialized (i.e. not in a base class constructor). | 202 // initialized (i.e. not in a base class constructor). |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache | 260 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache |
| 258 const uint32_t fUniqueID; | 261 const uint32_t fUniqueID; |
| 259 | 262 |
| 260 GrResourceKey fScratchKey; | 263 GrResourceKey fScratchKey; |
| 261 | 264 |
| 262 typedef GrIORef<GrGpuResource> INHERITED; | 265 typedef GrIORef<GrGpuResource> INHERITED; |
| 263 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable. | 266 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable. |
| 264 }; | 267 }; |
| 265 | 268 |
| 266 #endif | 269 #endif |
| OLD | NEW |