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

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: rebase 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
« no previous file with comments | « include/gpu/GrTexture.h ('k') | src/gpu/GrResourceCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /**
133 * Update the cached size for this entry and inform the resource cache that
134 * it has changed. Usually invoked from GrCacheable::didChangeGpuMemorySize ,
135 * not directly from here.
136 */
137 void didChangeResourceSize();
138
131 private: 139 private:
132 GrResourceCacheEntry(const GrResourceKey& key, GrCacheable* resource); 140 GrResourceCacheEntry(GrResourceCache* resourceCache,
141 const GrResourceKey& key,
142 GrCacheable* resource);
133 ~GrResourceCacheEntry(); 143 ~GrResourceCacheEntry();
134 144
145 GrResourceCache* fResourceCache;
135 GrResourceKey fKey; 146 GrResourceKey fKey;
136 GrCacheable* fResource; 147 GrCacheable* fResource;
148 size_t fCachedSize;
149 bool fIsExclusive;
137 150
138 // Linked list for the LRU ordering. 151 // Linked list for the LRU ordering.
139 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResourceCacheEntry); 152 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResourceCacheEntry);
140 153
141 friend class GrResourceCache; 154 friend class GrResourceCache;
142 }; 155 };
143 156
144 /////////////////////////////////////////////////////////////////////////////// 157 ///////////////////////////////////////////////////////////////////////////////
145 158
146 /** 159 /**
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 */ 278 */
266 void makeExclusive(GrResourceCacheEntry* entry); 279 void makeExclusive(GrResourceCacheEntry* entry);
267 280
268 /** 281 /**
269 * Restore 'entry' so that it can be found by future searches. 'entry' 282 * Restore 'entry' so that it can be found by future searches. 'entry'
270 * will also be purgeable (provided its lock count is now 0.) 283 * will also be purgeable (provided its lock count is now 0.)
271 */ 284 */
272 void makeNonExclusive(GrResourceCacheEntry* entry); 285 void makeNonExclusive(GrResourceCacheEntry* entry);
273 286
274 /** 287 /**
288 * Notify the cache that the size of a resource has changed.
289 */
290 void didIncreaseResourceSize(const GrResourceCacheEntry*, size_t amountInc);
291 void didDecreaseResourceSize(const GrResourceCacheEntry*, size_t amountDec);
292
293 /**
275 * Remove a resource from the cache and delete it! 294 * Remove a resource from the cache and delete it!
276 */ 295 */
277 void deleteResource(GrResourceCacheEntry* entry); 296 void deleteResource(GrResourceCacheEntry* entry);
278 297
279 /** 298 /**
280 * Removes every resource in the cache that isn't locked. 299 * Removes every resource in the cache that isn't locked.
281 */ 300 */
282 void purgeAllUnlocked(); 301 void purgeAllUnlocked();
283 302
284 /** 303 /**
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 GrResourceCache* fCache; 394 GrResourceCache* fCache;
376 }; 395 };
377 #else 396 #else
378 class GrAutoResourceCacheValidate { 397 class GrAutoResourceCacheValidate {
379 public: 398 public:
380 GrAutoResourceCacheValidate(GrResourceCache*) {} 399 GrAutoResourceCacheValidate(GrResourceCache*) {}
381 }; 400 };
382 #endif 401 #endif
383 402
384 #endif 403 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrTexture.h ('k') | src/gpu/GrResourceCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698