OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 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 |
| 10 |
9 #include "GrResourceCache.h" | 11 #include "GrResourceCache.h" |
10 #include "GrGpuResource.h" | 12 #include "GrGpuResource.h" |
11 #include "GrTexturePriv.h" | 13 #include "GrTexturePriv.h" |
12 | 14 |
| 15 |
13 DECLARE_SKMESSAGEBUS_MESSAGE(GrResourceInvalidatedMessage); | 16 DECLARE_SKMESSAGEBUS_MESSAGE(GrResourceInvalidatedMessage); |
14 | 17 |
15 /////////////////////////////////////////////////////////////////////////////// | 18 /////////////////////////////////////////////////////////////////////////////// |
16 | 19 |
17 void GrGpuResource::didChangeGpuMemorySize() const { | 20 void GrGpuResource::didChangeGpuMemorySize() const { |
18 if (this->isInCache()) { | 21 if (this->isInCache()) { |
19 fCacheEntry->didChangeResourceSize(); | 22 fCacheEntry->didChangeResourceSize(); |
20 } | 23 } |
21 } | 24 } |
22 | 25 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 this->internalDetach(entry); | 174 this->internalDetach(entry); |
172 this->attachToHead(entry); | 175 this->attachToHead(entry); |
173 } | 176 } |
174 } | 177 } |
175 | 178 |
176 void GrResourceCache::notifyPurgable(const GrGpuResource* resource) { | 179 void GrResourceCache::notifyPurgable(const GrGpuResource* resource) { |
177 // Remove scratch textures from the cache the moment they become purgeable i
f | 180 // Remove scratch textures from the cache the moment they become purgeable i
f |
178 // scratch texture reuse is turned off. | 181 // scratch texture reuse is turned off. |
179 SkASSERT(resource->getCacheEntry()); | 182 SkASSERT(resource->getCacheEntry()); |
180 if (resource->getCacheEntry()->key().getResourceType() == GrTexturePriv::Res
ourceType() && | 183 if (resource->getCacheEntry()->key().getResourceType() == GrTexturePriv::Res
ourceType() && |
181 resource->getCacheEntry()->key().isScratch() && | 184 resource->fIsScratch && |
182 !fCaps->reuseScratchTextures() && | 185 !fCaps->reuseScratchTextures() && |
183 !(static_cast<const GrTexture*>(resource)->desc().fFlags & | 186 !(static_cast<const GrTexture*>(resource)->desc().fFlags & |
184 kRenderTarget_GrTextureFlagBit)) { | 187 kRenderTarget_GrTextureFlagBit)) { |
185 this->deleteResource(resource->getCacheEntry()); | 188 this->deleteResource(resource->getCacheEntry()); |
186 } | 189 } |
187 } | 190 } |
188 | 191 |
189 GrGpuResource* GrResourceCache::find(const GrResourceKey& key) { | 192 GrGpuResource* GrResourceCache::find(const GrResourceKey& key) { |
190 // GrResourceCache2 is responsible for scratch resources. | |
191 SkASSERT(!key.isScratch()); | |
192 | |
193 GrAutoResourceCacheValidate atcv(this); | 193 GrAutoResourceCacheValidate atcv(this); |
194 | 194 |
195 GrResourceCacheEntry* entry = fCache.find(key); | 195 GrResourceCacheEntry* entry = NULL; |
| 196 |
| 197 entry = fCache.find(key); |
| 198 |
196 if (NULL == entry) { | 199 if (NULL == entry) { |
197 return NULL; | 200 return NULL; |
198 } | 201 } |
199 | 202 |
200 // Make this resource MRU | 203 // Make this resource MRU |
201 this->internalDetach(entry); | 204 this->internalDetach(entry); |
202 this->attachToHead(entry); | 205 this->attachToHead(entry); |
203 | 206 |
| 207 // GrResourceCache2 is responsible for scratch resources. |
| 208 SkASSERT(GrGpuResource::kNo_IsScratch == entry->resource()->fIsScratch); |
204 return entry->fResource; | 209 return entry->fResource; |
205 } | 210 } |
206 | 211 |
207 void GrResourceCache::addResource(const GrResourceKey& key, GrGpuResource* resou
rce) { | 212 void GrResourceCache::addResource(const GrResourceKey& key, GrGpuResource* resou
rce) { |
208 SkASSERT(NULL == resource->getCacheEntry()); | 213 SkASSERT(NULL == resource->getCacheEntry()); |
209 // we don't expect to create new resources during a purge. In theory | 214 // we don't expect to create new resources during a purge. In theory |
210 // this could cause purgeAsNeeded() into an infinite loop (e.g. | 215 // this could cause purgeAsNeeded() into an infinite loop (e.g. |
211 // each resource destroyed creates and locks 2 resources and | 216 // each resource destroyed creates and locks 2 resources and |
212 // unlocks 1 thereby causing a new purge). | 217 // unlocks 1 thereby causing a new purge). |
213 SkASSERT(!fPurging); | 218 SkASSERT(!fPurging); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes); | 423 SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes); |
419 SkDebugf("\t\tEntry Count: current %d (%d locked) high %d\n", | 424 SkDebugf("\t\tEntry Count: current %d (%d locked) high %d\n", |
420 fEntryCount, locked, fHighWaterEntryCount); | 425 fEntryCount, locked, fHighWaterEntryCount); |
421 SkDebugf("\t\tEntry Bytes: current %d high %d\n", | 426 SkDebugf("\t\tEntry Bytes: current %d high %d\n", |
422 fEntryBytes, fHighWaterEntryBytes); | 427 fEntryBytes, fHighWaterEntryBytes); |
423 } | 428 } |
424 | 429 |
425 #endif | 430 #endif |
426 | 431 |
427 /////////////////////////////////////////////////////////////////////////////// | 432 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |