Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/gpu/GrResourceCache.h

Issue 257093002: Add size change notifications to GrResourceCache (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "GrTMultiMap.h" 16 #include "GrTMultiMap.h"
17 #include "GrBinHashKey.h" 17 #include "GrBinHashKey.h"
18 #include "SkMessageBus.h" 18 #include "SkMessageBus.h"
19 #include "SkTInternalLList.h" 19 #include "SkTInternalLList.h"
20 20
21 class GrCacheable; 21 class GrCacheable;
22 class GrResourceCache;
22 class GrResourceCacheEntry; 23 class GrResourceCacheEntry;
23 24
24 class GrResourceKey { 25 class GrResourceKey {
25 public: 26 public:
26 static GrCacheID::Domain ScratchDomain() { 27 static GrCacheID::Domain ScratchDomain() {
27 static const GrCacheID::Domain gDomain = GrCacheID::GenerateDomain(); 28 static const GrCacheID::Domain gDomain = GrCacheID::GenerateDomain();
28 return gDomain; 29 return gDomain;
29 } 30 }
30 31
31 /** Uniquely identifies the GrCacheable subclass in the key to avoid collisi ons 32 /** Uniquely identifies the GrCacheable subclass in the key to avoid collisi ons
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 const GrResourceKey& key() const { return fKey; } 122 const GrResourceKey& key() const { return fKey; }
122 123
123 static const GrResourceKey& GetKey(const GrResourceCacheEntry& e) { return e .key(); } 124 static const GrResourceKey& GetKey(const GrResourceCacheEntry& e) { return e .key(); }
124 static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); } 125 static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); }
125 #ifdef SK_DEBUG 126 #ifdef SK_DEBUG
126 void validate() const; 127 void validate() const;
127 #else 128 #else
128 void validate() const {} 129 void validate() const {}
129 #endif 130 #endif
130 131
132 void onResourceSizeChanged();
133
131 private: 134 private:
132 GrResourceCacheEntry(const GrResourceKey& key, GrCacheable* resource); 135 GrResourceCacheEntry(GrResourceCache* resourceCache,
136 const GrResourceKey& key,
137 GrCacheable* resource);
133 ~GrResourceCacheEntry(); 138 ~GrResourceCacheEntry();
134 139
140 GrResourceCache* fResourceCache;
135 GrResourceKey fKey; 141 GrResourceKey fKey;
136 GrCacheable* fResource; 142 GrCacheable* fResource;
143 size_t fCachedSize;
144 bool fIsExclusive;
137 145
138 // Linked list for the LRU ordering. 146 // Linked list for the LRU ordering.
139 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResourceCacheEntry); 147 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResourceCacheEntry);
140 148
141 friend class GrResourceCache; 149 friend class GrResourceCache;
142 }; 150 };
143 151
144 /////////////////////////////////////////////////////////////////////////////// 152 ///////////////////////////////////////////////////////////////////////////////
145 153
146 /** 154 /**
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 */ 273 */
266 void makeExclusive(GrResourceCacheEntry* entry); 274 void makeExclusive(GrResourceCacheEntry* entry);
267 275
268 /** 276 /**
269 * Restore 'entry' so that it can be found by future searches. 'entry' 277 * Restore 'entry' so that it can be found by future searches. 'entry'
270 * will also be purgeable (provided its lock count is now 0.) 278 * will also be purgeable (provided its lock count is now 0.)
271 */ 279 */
272 void makeNonExclusive(GrResourceCacheEntry* entry); 280 void makeNonExclusive(GrResourceCacheEntry* entry);
273 281
274 /** 282 /**
283 * Notify the cache that the size of a resource has changed.
284 */
285 void onResourceSizeIncreased(const GrResourceCacheEntry*, size_t amount);
286 void onResourceSizeDecreased(const GrResourceCacheEntry*, size_t amount);
287
288 /**
275 * Remove a resource from the cache and delete it! 289 * Remove a resource from the cache and delete it!
276 */ 290 */
277 void deleteResource(GrResourceCacheEntry* entry); 291 void deleteResource(GrResourceCacheEntry* entry);
278 292
279 /** 293 /**
280 * Removes every resource in the cache that isn't locked. 294 * Removes every resource in the cache that isn't locked.
281 */ 295 */
282 void purgeAllUnlocked(); 296 void purgeAllUnlocked();
283 297
284 /** 298 /**
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 GrResourceCache* fCache; 389 GrResourceCache* fCache;
376 }; 390 };
377 #else 391 #else
378 class GrAutoResourceCacheValidate { 392 class GrAutoResourceCacheValidate {
379 public: 393 public:
380 GrAutoResourceCacheValidate(GrResourceCache*) {} 394 GrAutoResourceCacheValidate(GrResourceCache*) {}
381 }; 395 };
382 #endif 396 #endif
383 397
384 #endif 398 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698