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 | 9 |
10 | 10 |
11 #include "GrResourceCache.h" | 11 #include "GrResourceCache.h" |
12 #include "GrResource.h" | 12 #include "GrResource.h" |
13 | 13 |
| 14 DECLARE_SKMESSAGEBUS_MESSAGE(GrResourceInvalidatedMessage); |
14 | 15 |
15 GrResourceKey::ResourceType GrResourceKey::GenerateResourceType() { | 16 GrResourceKey::ResourceType GrResourceKey::GenerateResourceType() { |
16 static int32_t gNextType = 0; | 17 static int32_t gNextType = 0; |
17 | 18 |
18 int32_t type = sk_atomic_inc(&gNextType); | 19 int32_t type = sk_atomic_inc(&gNextType); |
19 if (type >= (1 << 8 * sizeof(ResourceType))) { | 20 if (type >= (1 << 8 * sizeof(ResourceType))) { |
20 GrCrash("Too many Resource Types"); | 21 GrCrash("Too many Resource Types"); |
21 } | 22 } |
22 | 23 |
23 return static_cast<ResourceType>(type); | 24 return static_cast<ResourceType>(type); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 fInvalidationInbox.poll(&invalidated); | 306 fInvalidationInbox.poll(&invalidated); |
306 | 307 |
307 for (int i = 0; i < invalidated.count(); i++) { | 308 for (int i = 0; i < invalidated.count(); i++) { |
308 // We're somewhat missing an opportunity here. We could use the | 309 // We're somewhat missing an opportunity here. We could use the |
309 // default find functor that gives us back resources whether we own | 310 // default find functor that gives us back resources whether we own |
310 // them exclusively or not, and when they're not exclusively owned mark | 311 // them exclusively or not, and when they're not exclusively owned mark |
311 // them for purging later when they do become exclusively owned. | 312 // them for purging later when they do become exclusively owned. |
312 // | 313 // |
313 // This is complicated and confusing. May try this in the future. For | 314 // This is complicated and confusing. May try this in the future. For |
314 // now, these resources are just LRU'd as if we never got the message. | 315 // now, these resources are just LRU'd as if we never got the message. |
315 GrResourceEntry* entry = fCache.find(invalidated[i].key, GrTFindUnreffed
Functor()); | 316 while (GrResourceEntry* entry = fCache.find(invalidated[i].key, GrTFindU
nreffedFunctor())) { |
316 if (entry) { | |
317 this->deleteResource(entry); | 317 this->deleteResource(entry); |
318 } | 318 } |
319 } | 319 } |
320 } | 320 } |
321 | 321 |
322 void GrResourceCache::deleteResource(GrResourceEntry* entry) { | 322 void GrResourceCache::deleteResource(GrResourceEntry* entry) { |
323 SkASSERT(1 == entry->fResource->getRefCnt()); | 323 SkASSERT(1 == entry->fResource->getRefCnt()); |
324 | 324 |
325 // remove from our cache | 325 // remove from our cache |
326 fCache.remove(entry->key(), entry); | 326 fCache.remove(entry->key(), entry); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 fEntryBytes, fHighWaterEntryBytes); | 486 fEntryBytes, fHighWaterEntryBytes); |
487 SkDebugf("\t\tDetached Entry Count: current %d high %d\n", | 487 SkDebugf("\t\tDetached Entry Count: current %d high %d\n", |
488 fClientDetachedCount, fHighWaterClientDetachedCount); | 488 fClientDetachedCount, fHighWaterClientDetachedCount); |
489 SkDebugf("\t\tDetached Bytes: current %d high %d\n", | 489 SkDebugf("\t\tDetached Bytes: current %d high %d\n", |
490 fClientDetachedBytes, fHighWaterClientDetachedBytes); | 490 fClientDetachedBytes, fHighWaterClientDetachedBytes); |
491 } | 491 } |
492 | 492 |
493 #endif | 493 #endif |
494 | 494 |
495 /////////////////////////////////////////////////////////////////////////////// | 495 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |