| 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 | 9 |
| 10 | 10 |
| 11 #ifndef GrResourceCache_DEFINED | 11 #ifndef GrResourceCache_DEFINED |
| 12 #define GrResourceCache_DEFINED | 12 #define GrResourceCache_DEFINED |
| 13 | 13 |
| 14 #include "GrConfig.h" | 14 #include "GrConfig.h" |
| 15 #include "GrTypes.h" | 15 #include "GrTypes.h" |
| 16 #include "GrTHashTable.h" | 16 #include "GrTHashTable.h" |
| 17 #include "GrBinHashKey.h" | 17 #include "GrBinHashKey.h" |
| 18 #include "SkMessageBus.h" |
| 18 #include "SkTInternalLList.h" | 19 #include "SkTInternalLList.h" |
| 19 | 20 |
| 20 class GrResource; | 21 class GrResource; |
| 21 class GrResourceEntry; | 22 class GrResourceEntry; |
| 22 | 23 |
| 23 class GrResourceKey { | 24 class GrResourceKey { |
| 24 public: | 25 public: |
| 25 enum { | 26 enum { |
| 26 kHashBits = 7, | 27 kHashBits = 7, |
| 27 kHashCount = 1 << kHashBits, | 28 kHashCount = 1 << kHashBits, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 int compare(const HashedKey& hashedKey) const { | 135 int compare(const HashedKey& hashedKey) const { |
| 135 return fHashedKey.compare(hashedKey); | 136 return fHashedKey.compare(hashedKey); |
| 136 } | 137 } |
| 137 | 138 |
| 138 HashedKey fHashedKey; | 139 HashedKey fHashedKey; |
| 139 }; | 140 }; |
| 140 | 141 |
| 141 Key fKey; | 142 Key fKey; |
| 142 }; | 143 }; |
| 143 | 144 |
| 145 // The cache listens for these messages to purge junk resources proactively. |
| 146 struct GrResourceInvalidatedMessage { |
| 147 GrResourceKey key; |
| 148 }; |
| 149 |
| 144 /////////////////////////////////////////////////////////////////////////////// | 150 /////////////////////////////////////////////////////////////////////////////// |
| 145 | 151 |
| 146 class GrResourceEntry { | 152 class GrResourceEntry { |
| 147 public: | 153 public: |
| 148 GrResource* resource() const { return fResource; } | 154 GrResource* resource() const { return fResource; } |
| 149 const GrResourceKey& key() const { return fKey; } | 155 const GrResourceKey& key() const { return fKey; } |
| 150 | 156 |
| 151 #ifdef SK_DEBUG | 157 #ifdef SK_DEBUG |
| 152 void validate() const; | 158 void validate() const; |
| 153 #else | 159 #else |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 size_t fClientDetachedBytes; | 394 size_t fClientDetachedBytes; |
| 389 | 395 |
| 390 // prevents recursive purging | 396 // prevents recursive purging |
| 391 bool fPurging; | 397 bool fPurging; |
| 392 | 398 |
| 393 PFOverbudgetCB fOverbudgetCB; | 399 PFOverbudgetCB fOverbudgetCB; |
| 394 void* fOverbudgetData; | 400 void* fOverbudgetData; |
| 395 | 401 |
| 396 void internalPurge(int extraCount, size_t extraBytes); | 402 void internalPurge(int extraCount, size_t extraBytes); |
| 397 | 403 |
| 404 // Listen for messages that a resource has been invalidated and purge cached
junk proactively. |
| 405 SkMessageBus<GrResourceInvalidatedMessage>::Inbox fInvalidationInbox; |
| 406 void purgeInvalidated(); |
| 407 |
| 398 #ifdef SK_DEBUG | 408 #ifdef SK_DEBUG |
| 399 static size_t countBytes(const SkTInternalLList<GrResourceEntry>& list); | 409 static size_t countBytes(const SkTInternalLList<GrResourceEntry>& list); |
| 400 #endif | 410 #endif |
| 401 }; | 411 }; |
| 402 | 412 |
| 403 /////////////////////////////////////////////////////////////////////////////// | 413 /////////////////////////////////////////////////////////////////////////////// |
| 404 | 414 |
| 405 #ifdef SK_DEBUG | 415 #ifdef SK_DEBUG |
| 406 class GrAutoResourceCacheValidate { | 416 class GrAutoResourceCacheValidate { |
| 407 public: | 417 public: |
| 408 GrAutoResourceCacheValidate(GrResourceCache* cache) : fCache(cache) { | 418 GrAutoResourceCacheValidate(GrResourceCache* cache) : fCache(cache) { |
| 409 cache->validate(); | 419 cache->validate(); |
| 410 } | 420 } |
| 411 ~GrAutoResourceCacheValidate() { | 421 ~GrAutoResourceCacheValidate() { |
| 412 fCache->validate(); | 422 fCache->validate(); |
| 413 } | 423 } |
| 414 private: | 424 private: |
| 415 GrResourceCache* fCache; | 425 GrResourceCache* fCache; |
| 416 }; | 426 }; |
| 417 #else | 427 #else |
| 418 class GrAutoResourceCacheValidate { | 428 class GrAutoResourceCacheValidate { |
| 419 public: | 429 public: |
| 420 GrAutoResourceCacheValidate(GrResourceCache*) {} | 430 GrAutoResourceCacheValidate(GrResourceCache*) {} |
| 421 }; | 431 }; |
| 422 #endif | 432 #endif |
| 423 | 433 |
| 424 #endif | 434 #endif |
| OLD | NEW |