OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #ifndef GrResourceCache_DEFINED | 9 #ifndef GrResourceCache_DEFINED |
10 #define GrResourceCache_DEFINED | 10 #define GrResourceCache_DEFINED |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 /** | 133 /** |
134 * Returns the number of bytes consumed by cached resources. | 134 * Returns the number of bytes consumed by cached resources. |
135 */ | 135 */ |
136 size_t getCachedResourceBytes() const { return fEntryBytes; } | 136 size_t getCachedResourceBytes() const { return fEntryBytes; } |
137 | 137 |
138 /** | 138 /** |
139 * Returns the number of cached resources. | 139 * Returns the number of cached resources. |
140 */ | 140 */ |
141 int getCachedResourceCount() const { return fEntryCount; } | 141 int getCachedResourceCount() const { return fEntryCount; } |
142 | 142 |
143 /** | |
144 * Search for an entry with the same Key. If found, return it. | |
145 * If not found, return null. | |
146 */ | |
147 GrGpuResource* find(const GrResourceKey& key); | |
148 | |
149 void makeResourceMRU(GrGpuResource*); | 143 void makeResourceMRU(GrGpuResource*); |
150 | 144 |
151 /** Called by GrGpuResources when they detects that they are newly purgable.
*/ | 145 /** Called by GrGpuResources when they detects that they are newly purgable.
*/ |
152 void notifyPurgable(const GrGpuResource*); | 146 void notifyPurgable(const GrGpuResource*); |
153 | 147 |
154 /** | 148 /** |
155 * Add the new resource to the cache (by creating a new cache entry based | 149 * Add the new resource to the cache (by creating a new cache entry based |
156 * on the provided key and resource). | 150 * on the provided key and resource). |
157 * | 151 * |
158 * Ownership of the resource is transferred to the resource cache, | 152 * Ownership of the resource is transferred to the resource cache, |
159 * which will unref() it when it is purged or deleted. | 153 * which will unref() it when it is purged or deleted. |
| 154 * |
| 155 * This can fail if the key is already taken, or the resource is already in |
| 156 * the cache. |
160 */ | 157 */ |
161 void addResource(const GrResourceKey& key, GrGpuResource* resource); | 158 bool addResource(const GrResourceKey& key, GrGpuResource* resource); |
162 | |
163 /** | |
164 * Determines if the cache contains an entry matching a key. If a matching | |
165 * entry exists but was detached then it will not be found. | |
166 */ | |
167 bool hasKey(const GrResourceKey& key) const { return SkToBool(fCache.find(ke
y)); } | |
168 | 159 |
169 /** | 160 /** |
170 * Notify the cache that the size of a resource has changed. | 161 * Notify the cache that the size of a resource has changed. |
171 */ | 162 */ |
172 void didIncreaseResourceSize(const GrResourceCacheEntry*, size_t amountInc); | 163 void didIncreaseResourceSize(const GrResourceCacheEntry*, size_t amountInc); |
173 void didDecreaseResourceSize(const GrResourceCacheEntry*, size_t amountDec); | 164 void didDecreaseResourceSize(const GrResourceCacheEntry*, size_t amountDec); |
174 | 165 |
175 /** | 166 /** |
176 * Remove a resource from the cache and delete it! | 167 * Remove a resource from the cache and delete it! |
177 */ | 168 */ |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 GrResourceCache* fCache; | 253 GrResourceCache* fCache; |
263 }; | 254 }; |
264 #else | 255 #else |
265 class GrAutoResourceCacheValidate { | 256 class GrAutoResourceCacheValidate { |
266 public: | 257 public: |
267 GrAutoResourceCacheValidate(GrResourceCache*) {} | 258 GrAutoResourceCacheValidate(GrResourceCache*) {} |
268 }; | 259 }; |
269 #endif | 260 #endif |
270 | 261 |
271 #endif | 262 #endif |
OLD | NEW |