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

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

Issue 19482004: Alter resource cache and GrContext to (optionally) never reuse a scratch texture (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Disabled Created 7 years, 5 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 | « src/gpu/GrResourceCache.h ('k') | src/gpu/gl/GrGLCaps.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 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
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 fCache.remove(entry->fKey, entry); 81 fCache.remove(entry->fKey, entry);
82 82
83 // remove from our llist 83 // remove from our llist
84 this->internalDetach(entry); 84 this->internalDetach(entry);
85 85
86 delete entry; 86 delete entry;
87 } 87 }
88 } 88 }
89 89
90 void GrResourceCache::getLimits(int* maxResources, size_t* maxResourceBytes) con st{ 90 void GrResourceCache::getLimits(int* maxResources, size_t* maxResourceBytes) con st{
91 if (maxResources) { 91 if (NULL != maxResources) {
92 *maxResources = fMaxCount; 92 *maxResources = fMaxCount;
93 } 93 }
94 if (maxResourceBytes) { 94 if (NULL != maxResourceBytes) {
95 *maxResourceBytes = fMaxBytes; 95 *maxResourceBytes = fMaxBytes;
96 } 96 }
97 } 97 }
98 98
99 void GrResourceCache::setLimits(int maxResources, size_t maxResourceBytes) { 99 void GrResourceCache::setLimits(int maxResources, size_t maxResourceBytes) {
100 bool smaller = (maxResources < fMaxCount) || (maxResourceBytes < fMaxBytes); 100 bool smaller = (maxResources < fMaxCount) || (maxResourceBytes < fMaxBytes);
101 101
102 fMaxCount = maxResources; 102 fMaxCount = maxResources;
103 fMaxBytes = maxResourceBytes; 103 fMaxBytes = maxResourceBytes;
104 104
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 this->makeExclusive(entry); 189 this->makeExclusive(entry);
190 } else { 190 } else {
191 // Make this resource MRU 191 // Make this resource MRU
192 this->internalDetach(entry); 192 this->internalDetach(entry);
193 this->attachToHead(entry); 193 this->attachToHead(entry);
194 } 194 }
195 195
196 return entry->fResource; 196 return entry->fResource;
197 } 197 }
198 198
199 bool GrResourceCache::hasKey(const GrResourceKey& key) const {
200 return NULL != fCache.find(key);
201 }
202
203 void GrResourceCache::addResource(const GrResourceKey& key, 199 void GrResourceCache::addResource(const GrResourceKey& key,
204 GrResource* resource, 200 GrResource* resource,
205 uint32_t ownershipFlags) { 201 uint32_t ownershipFlags) {
206 GrAssert(NULL == resource->getCacheEntry()); 202 GrAssert(NULL == resource->getCacheEntry());
207 // we don't expect to create new resources during a purge. In theory 203 // we don't expect to create new resources during a purge. In theory
208 // this could cause purgeAsNeeded() into an infinite loop (e.g. 204 // this could cause purgeAsNeeded() into an infinite loop (e.g.
209 // each resource destroyed creates and locks 2 resources and 205 // each resource destroyed creates and locks 2 resources and
210 // unlocks 1 thereby causing a new purge). 206 // unlocks 1 thereby causing a new purge).
211 GrAssert(!fPurging); 207 GrAssert(!fPurging);
212 GrAutoResourceCacheValidate atcv(this); 208 GrAutoResourceCacheValidate atcv(this);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // Despite the purge we're still over budget. See if Ganesh can 291 // Despite the purge we're still over budget. See if Ganesh can
296 // release some resources and purge again. 292 // release some resources and purge again.
297 if ((*fOverbudgetCB)(fOverbudgetData)) { 293 if ((*fOverbudgetCB)(fOverbudgetData)) {
298 this->internalPurge(extraCount, extraBytes); 294 this->internalPurge(extraCount, extraBytes);
299 } 295 }
300 } 296 }
301 297
302 fPurging = false; 298 fPurging = false;
303 } 299 }
304 300
301 void GrResourceCache::deleteResource(GrResourceEntry* entry) {
302 GrAssert(1 == entry->fResource->getRefCnt());
303
304 // remove from our cache
305 fCache.remove(entry->key(), entry);
306
307 // remove from our llist
308 this->internalDetach(entry);
309 delete entry;
310 }
311
305 void GrResourceCache::internalPurge(int extraCount, size_t extraBytes) { 312 void GrResourceCache::internalPurge(int extraCount, size_t extraBytes) {
306 SkASSERT(fPurging); 313 SkASSERT(fPurging);
307 314
308 bool withinBudget = false; 315 bool withinBudget = false;
309 bool changed = false; 316 bool changed = false;
310 317
311 // The purging process is repeated several times since one pass 318 // The purging process is repeated several times since one pass
312 // may free up other resources 319 // may free up other resources
313 do { 320 do {
314 EntryList::Iter iter; 321 EntryList::Iter iter;
(...skipping 11 matching lines...) Expand all
326 333
327 if ((fEntryCount+extraCount) <= fMaxCount && 334 if ((fEntryCount+extraCount) <= fMaxCount &&
328 (fEntryBytes+extraBytes) <= fMaxBytes) { 335 (fEntryBytes+extraBytes) <= fMaxBytes) {
329 withinBudget = true; 336 withinBudget = true;
330 break; 337 break;
331 } 338 }
332 339
333 GrResourceEntry* prev = iter.prev(); 340 GrResourceEntry* prev = iter.prev();
334 if (1 == entry->fResource->getRefCnt()) { 341 if (1 == entry->fResource->getRefCnt()) {
335 changed = true; 342 changed = true;
336 343 this->deleteResource(entry);
337 // remove from our cache
338 fCache.remove(entry->key(), entry);
339
340 // remove from our llist
341 this->internalDetach(entry);
342 delete entry;
343 } 344 }
344 entry = prev; 345 entry = prev;
345 } 346 }
346 } while (!withinBudget && changed); 347 } while (!withinBudget && changed);
347 } 348 }
348 349
349 void GrResourceCache::purgeAllUnlocked() { 350 void GrResourceCache::purgeAllUnlocked() {
350 GrAutoResourceCacheValidate atcv(this); 351 GrAutoResourceCacheValidate atcv(this);
351 352
352 // we can have one GrResource holding a lock on another 353 // we can have one GrResource holding a lock on another
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 fEntryBytes, fHighWaterEntryBytes); 465 fEntryBytes, fHighWaterEntryBytes);
465 SkDebugf("\t\tDetached Entry Count: current %d high %d\n", 466 SkDebugf("\t\tDetached Entry Count: current %d high %d\n",
466 fClientDetachedCount, fHighWaterClientDetachedCount); 467 fClientDetachedCount, fHighWaterClientDetachedCount);
467 SkDebugf("\t\tDetached Bytes: current %d high %d\n", 468 SkDebugf("\t\tDetached Bytes: current %d high %d\n",
468 fClientDetachedBytes, fHighWaterClientDetachedBytes); 469 fClientDetachedBytes, fHighWaterClientDetachedBytes);
469 } 470 }
470 471
471 #endif 472 #endif
472 473
473 /////////////////////////////////////////////////////////////////////////////// 474 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « src/gpu/GrResourceCache.h ('k') | src/gpu/gl/GrGLCaps.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698