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 12 matching lines...) Expand all Loading... |
23 // The cache listens for these messages to purge junk resources proactively. | 23 // The cache listens for these messages to purge junk resources proactively. |
24 struct GrResourceInvalidatedMessage { | 24 struct GrResourceInvalidatedMessage { |
25 GrResourceKey key; | 25 GrResourceKey key; |
26 }; | 26 }; |
27 | 27 |
28 /////////////////////////////////////////////////////////////////////////////// | 28 /////////////////////////////////////////////////////////////////////////////// |
29 | 29 |
30 class GrResourceCacheEntry { | 30 class GrResourceCacheEntry { |
31 public: | 31 public: |
32 GrGpuResource* resource() const { return fResource; } | 32 GrGpuResource* resource() const { return fResource; } |
33 const GrResourceKey& key() const { return fKey; } | |
34 | 33 |
35 static const GrResourceKey& GetKey(const GrResourceCacheEntry& e) { return e
.key(); } | 34 static uint32_t Hash(const GrGpuResource* resource) { |
36 static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); } | 35 return static_cast<uint32_t>(reinterpret_cast<intptr_t>(resource)); |
| 36 } |
37 #ifdef SK_DEBUG | 37 #ifdef SK_DEBUG |
38 void validate() const; | 38 void validate() const; |
39 #else | 39 #else |
40 void validate() const {} | 40 void validate() const {} |
41 #endif | 41 #endif |
42 | 42 |
43 /** | 43 /** |
44 * Update the cached size for this entry and inform the resource cache that | 44 * Update the cached size for this entry and inform the resource cache that |
45 * it has changed. Usually invoked from GrGpuResource::didChangeGpuMemorySi
ze, | 45 * it has changed. Usually invoked from GrGpuResource::didChangeGpuMemorySi
ze, |
46 * not directly from here. | 46 * not directly from here. |
47 */ | 47 */ |
48 void didChangeResourceSize(); | 48 void didChangeResourceSize(); |
49 | 49 |
50 private: | 50 private: |
51 GrResourceCacheEntry(GrResourceCache* resourceCache, | 51 GrResourceCacheEntry(GrResourceCache*, GrGpuResource*); |
52 const GrResourceKey& key, | |
53 GrGpuResource* resource); | |
54 ~GrResourceCacheEntry(); | 52 ~GrResourceCacheEntry(); |
55 | 53 |
56 GrResourceCache* fResourceCache; | 54 GrResourceCache* fResourceCache; |
57 GrResourceKey fKey; | |
58 GrGpuResource* fResource; | 55 GrGpuResource* fResource; |
59 size_t fCachedSize; | 56 size_t fCachedSize; |
60 bool fIsExclusive; | |
61 | 57 |
62 // Linked list for the LRU ordering. | 58 // Linked list for the LRU ordering. |
63 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResourceCacheEntry); | 59 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResourceCacheEntry); |
64 | 60 |
65 friend class GrResourceCache; | 61 friend class GrResourceCache; |
66 friend class GrContext; | 62 friend class GrContext; |
67 }; | 63 }; |
68 | 64 |
69 /////////////////////////////////////////////////////////////////////////////// | 65 /////////////////////////////////////////////////////////////////////////////// |
70 | 66 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 194 |
199 private: | 195 private: |
200 void internalDetach(GrResourceCacheEntry*); | 196 void internalDetach(GrResourceCacheEntry*); |
201 void attachToHead(GrResourceCacheEntry*); | 197 void attachToHead(GrResourceCacheEntry*); |
202 void purgeInvalidated(); | 198 void purgeInvalidated(); |
203 void internalPurge(int extraCount, size_t extraBytes); | 199 void internalPurge(int extraCount, size_t extraBytes); |
204 #ifdef SK_DEBUG | 200 #ifdef SK_DEBUG |
205 static size_t countBytes(const SkTInternalLList<GrResourceCacheEntry>& list)
; | 201 static size_t countBytes(const SkTInternalLList<GrResourceCacheEntry>& list)
; |
206 #endif | 202 #endif |
207 | 203 |
208 typedef SkTMultiMap<GrResourceCacheEntry, GrResourceKey> CacheMap; | |
209 CacheMap fCache; | |
210 | |
211 // We're an internal doubly linked list | 204 // We're an internal doubly linked list |
212 typedef SkTInternalLList<GrResourceCacheEntry> EntryList; | 205 typedef SkTInternalLList<GrResourceCacheEntry> EntryList; |
213 EntryList fList; | 206 EntryList fList; |
214 | 207 |
215 // our budget, used in purgeAsNeeded() | 208 // our budget, used in purgeAsNeeded() |
216 int fMaxCount; | 209 int fMaxCount; |
217 size_t fMaxBytes; | 210 size_t fMaxBytes; |
218 | 211 |
219 // our current stats, related to our budget | 212 // our current stats, related to our budget |
220 #if GR_CACHE_STATS | 213 #if GR_CACHE_STATS |
221 int fHighWaterEntryCount; | 214 int fHighWaterEntryCount; |
222 size_t fHighWaterEntryBytes; | 215 size_t fHighWaterEntryBytes; |
223 #endif | 216 #endif |
224 | 217 |
225 int fEntryCount; | 218 int fEntryCount; |
226 size_t fEntryBytes; | 219 size_t fEntryBytes; |
227 | 220 |
228 // prevents recursive purging | 221 // prevents recursive purging |
229 bool fPurging; | 222 bool fPurging; |
230 | 223 |
231 PFOverbudgetCB fOverbudgetCB; | 224 PFOverbudgetCB fOverbudgetCB; |
232 void* fOverbudgetData; | 225 void* fOverbudgetData; |
233 | 226 |
234 SkAutoTUnref<const GrDrawTargetCaps> fCaps; | 227 SkAutoTUnref<const GrDrawTargetCaps> fCaps; |
235 | |
236 // Listen for messages that a resource has been invalidated and purge cached
junk proactively. | |
237 typedef SkMessageBus<GrResourceInvalidatedMessage>::Inbox Inbox; | |
238 Inbox fInvalidationInbox; | |
239 }; | 228 }; |
240 | 229 |
241 /////////////////////////////////////////////////////////////////////////////// | 230 /////////////////////////////////////////////////////////////////////////////// |
242 | 231 |
243 #ifdef SK_DEBUG | 232 #ifdef SK_DEBUG |
244 class GrAutoResourceCacheValidate { | 233 class GrAutoResourceCacheValidate { |
245 public: | 234 public: |
246 GrAutoResourceCacheValidate(GrResourceCache* cache) : fCache(cache) { | 235 GrAutoResourceCacheValidate(GrResourceCache* cache) : fCache(cache) { |
247 cache->validate(); | 236 cache->validate(); |
248 } | 237 } |
249 ~GrAutoResourceCacheValidate() { | 238 ~GrAutoResourceCacheValidate() { |
250 fCache->validate(); | 239 fCache->validate(); |
251 } | 240 } |
252 private: | 241 private: |
253 GrResourceCache* fCache; | 242 GrResourceCache* fCache; |
254 }; | 243 }; |
255 #else | 244 #else |
256 class GrAutoResourceCacheValidate { | 245 class GrAutoResourceCacheValidate { |
257 public: | 246 public: |
258 GrAutoResourceCacheValidate(GrResourceCache*) {} | 247 GrAutoResourceCacheValidate(GrResourceCache*) {} |
259 }; | 248 }; |
260 #endif | 249 #endif |
261 | 250 |
262 #endif | 251 #endif |
OLD | NEW |