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