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

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

Issue 721353002: Allow GPU resources to not be counted against the cache budget. (Closed) Base URL: https://skia.googlesource.com/skia.git@wrap
Patch Set: fix constructor order Created 6 years, 1 month 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
« no previous file with comments | « src/gpu/GrResourceCache2.h ('k') | tests/ResourceCacheTest.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 2014 Google Inc. 3 * Copyright 2014 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 #include "GrResourceCache2.h" 10 #include "GrResourceCache2.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 AutoValidate av(this); 93 AutoValidate av(this);
94 94
95 SkASSERT(resource); 95 SkASSERT(resource);
96 SkASSERT(!resource->wasDestroyed()); 96 SkASSERT(!resource->wasDestroyed());
97 SkASSERT(!this->isInCache(resource)); 97 SkASSERT(!this->isInCache(resource));
98 SkASSERT(!fPurging); 98 SkASSERT(!fPurging);
99 fResources.addToHead(resource); 99 fResources.addToHead(resource);
100 100
101 size_t size = resource->gpuMemorySize(); 101 size_t size = resource->gpuMemorySize();
102 ++fCount; 102 ++fCount;
103 fBytes += resource->gpuMemorySize(); 103 fBytes += size;
104 #if GR_CACHE_STATS 104 #if GR_CACHE_STATS
105 fHighWaterCount = SkTMax(fCount, fHighWaterCount); 105 fHighWaterCount = SkTMax(fCount, fHighWaterCount);
106 fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes); 106 fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes);
107 #endif 107 #endif
108 if (!resource->cacheAccess().isWrapped()) { 108 if (resource->cacheAccess().isBudgeted()) {
109 ++fBudgetedCount; 109 ++fBudgetedCount;
110 fBudgetedBytes += size; 110 fBudgetedBytes += size;
111 #if GR_CACHE_STATS 111 #if GR_CACHE_STATS
112 fBudgetedHighWaterCount = SkTMax(fBudgetedCount, fBudgetedHighWaterCount ); 112 fBudgetedHighWaterCount = SkTMax(fBudgetedCount, fBudgetedHighWaterCount );
113 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes ); 113 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes );
114 #endif 114 #endif
115 } 115 }
116 if (!resource->cacheAccess().getScratchKey().isNullScratch()) { 116 if (!resource->cacheAccess().getScratchKey().isNullScratch()) {
117 // TODO(bsalomon): Make this assertion possible. 117 SkASSERT(!resource->cacheAccess().isWrapped());
118 // SkASSERT(!resource->isWrapped());
119 fScratchMap.insert(resource->cacheAccess().getScratchKey(), resource); 118 fScratchMap.insert(resource->cacheAccess().getScratchKey(), resource);
120 } 119 }
121 120
122 this->purgeAsNeeded(); 121 this->purgeAsNeeded();
123 } 122 }
124 123
125 void GrResourceCache2::removeResource(GrGpuResource* resource) { 124 void GrResourceCache2::removeResource(GrGpuResource* resource) {
126 AutoValidate av(this); 125 AutoValidate av(this);
127 126
128 SkASSERT(this->isInCache(resource)); 127 SkASSERT(this->isInCache(resource));
129 128
130 size_t size = resource->gpuMemorySize(); 129 size_t size = resource->gpuMemorySize();
131 --fCount; 130 --fCount;
132 fBytes -= size; 131 fBytes -= size;
133 if (!resource->cacheAccess().isWrapped()) { 132 if (resource->cacheAccess().isBudgeted()) {
134 --fBudgetedCount; 133 --fBudgetedCount;
135 fBudgetedBytes -= size; 134 fBudgetedBytes -= size;
136 } 135 }
137 136
138 fResources.remove(resource); 137 fResources.remove(resource);
139 if (!resource->cacheAccess().getScratchKey().isNullScratch()) { 138 if (!resource->cacheAccess().getScratchKey().isNullScratch()) {
140 fScratchMap.remove(resource->cacheAccess().getScratchKey(), resource); 139 fScratchMap.remove(resource->cacheAccess().getScratchKey(), resource);
141 } 140 }
142 if (const GrResourceKey* contentKey = resource->cacheAccess().getContentKey( )) { 141 if (const GrResourceKey* contentKey = resource->cacheAccess().getContentKey( )) {
143 fContentHash.remove(*contentKey); 142 fContentHash.remove(*contentKey);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 179 }
181 180
182 class GrResourceCache2::AvailableForScratchUse { 181 class GrResourceCache2::AvailableForScratchUse {
183 public: 182 public:
184 AvailableForScratchUse(bool rejectPendingIO) : fRejectPendingIO(rejectPendin gIO) { } 183 AvailableForScratchUse(bool rejectPendingIO) : fRejectPendingIO(rejectPendin gIO) { }
185 184
186 bool operator()(const GrGpuResource* resource) const { 185 bool operator()(const GrGpuResource* resource) const {
187 if (resource->internalHasRef() || !resource->cacheAccess().isScratch()) { 186 if (resource->internalHasRef() || !resource->cacheAccess().isScratch()) {
188 return false; 187 return false;
189 } 188 }
190
191 return !fRejectPendingIO || !resource->internalHasPendingIO(); 189 return !fRejectPendingIO || !resource->internalHasPendingIO();
192 } 190 }
193 191
194 private: 192 private:
195 bool fRejectPendingIO; 193 bool fRejectPendingIO;
196 }; 194 };
197 195
198 GrGpuResource* GrResourceCache2::findAndRefScratchResource(const GrResourceKey& scratchKey, 196 GrGpuResource* GrResourceCache2::findAndRefScratchResource(const GrResourceKey& scratchKey,
199 uint32_t flags) { 197 uint32_t flags) {
200 AutoValidate av(this); 198 AutoValidate av(this);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 // SkASSERT(!fPurging); GrPathRange increases size during flush. :( 284 // SkASSERT(!fPurging); GrPathRange increases size during flush. :(
287 SkASSERT(resource); 285 SkASSERT(resource);
288 SkASSERT(this->isInCache(resource)); 286 SkASSERT(this->isInCache(resource));
289 287
290 ptrdiff_t delta = resource->gpuMemorySize() - oldSize; 288 ptrdiff_t delta = resource->gpuMemorySize() - oldSize;
291 289
292 fBytes += delta; 290 fBytes += delta;
293 #if GR_CACHE_STATS 291 #if GR_CACHE_STATS
294 fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes); 292 fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes);
295 #endif 293 #endif
296 if (!resource->cacheAccess().isWrapped()) { 294 if (resource->cacheAccess().isBudgeted()) {
297 fBudgetedBytes += delta; 295 fBudgetedBytes += delta;
298 #if GR_CACHE_STATS 296 #if GR_CACHE_STATS
299 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes ); 297 fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes );
300 #endif 298 #endif
301 } 299 }
302 300
303 this->purgeAsNeeded(); 301 this->purgeAsNeeded();
304 this->validate(); 302 this->validate();
305 } 303 }
306 304
305 void GrResourceCache2::didChangeBudgetStatus(GrGpuResource* resource) {
306 SkASSERT(!fPurging);
307 SkASSERT(resource);
308 SkASSERT(this->isInCache(resource));
309
310 size_t size = resource->gpuMemorySize();
311
312 if (resource->cacheAccess().isBudgeted()) {
313 ++fBudgetedCount;
314 fBudgetedBytes += size;
315 this->purgeAsNeeded();
316 } else {
317 --fBudgetedCount;
318 fBudgetedBytes -= size;
319 }
320
321 this->validate();
322 }
323
324
307 void GrResourceCache2::internalPurgeAsNeeded() { 325 void GrResourceCache2::internalPurgeAsNeeded() {
308 SkASSERT(!fPurging); 326 SkASSERT(!fPurging);
309 SkASSERT(!fNewlyPurgableResourceWhilePurging); 327 SkASSERT(!fNewlyPurgableResourceWhilePurging);
310 SkASSERT(fBudgetedCount > fMaxCount || fBudgetedBytes > fMaxBytes); 328 SkASSERT(fBudgetedCount > fMaxCount || fBudgetedBytes > fMaxBytes);
311 329
312 fPurging = true; 330 fPurging = true;
313 331
314 AutoValidate av(this); // Put this after setting fPurging so we're allowed t o be over budget. 332 AutoValidate av(this); // Put this after setting fPurging so we're allowed t o be over budget.
315 333
316 bool overBudget = true; 334 bool overBudget = true;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 SkASSERT(fScratchMap.countForKey(resource->cacheAccess().getScratchK ey())); 421 SkASSERT(fScratchMap.countForKey(resource->cacheAccess().getScratchK ey()));
404 SkASSERT(!resource->cacheAccess().isWrapped()); 422 SkASSERT(!resource->cacheAccess().isWrapped());
405 } 423 }
406 424
407 if (const GrResourceKey* contentKey = resource->cacheAccess().getContent Key()) { 425 if (const GrResourceKey* contentKey = resource->cacheAccess().getContent Key()) {
408 ++content; 426 ++content;
409 SkASSERT(fContentHash.find(*contentKey) == resource); 427 SkASSERT(fContentHash.find(*contentKey) == resource);
410 SkASSERT(!resource->cacheAccess().isWrapped()); 428 SkASSERT(!resource->cacheAccess().isWrapped());
411 } 429 }
412 430
413 if (!resource->cacheAccess().isWrapped()) { 431 if (resource->cacheAccess().isBudgeted()) {
414 ++budgetedCount; 432 ++budgetedCount;
415 budgetedBytes += resource->gpuMemorySize(); 433 budgetedBytes += resource->gpuMemorySize();
416 } 434 }
417 } 435 }
418 436
419 SkASSERT(fBudgetedCount <= fCount); 437 SkASSERT(fBudgetedCount <= fCount);
420 SkASSERT(fBudgetedBytes <= fBudgetedBytes); 438 SkASSERT(fBudgetedBytes <= fBudgetedBytes);
421 SkASSERT(bytes == fBytes); 439 SkASSERT(bytes == fBytes);
422 SkASSERT(count == fCount); 440 SkASSERT(count == fCount);
423 SkASSERT(budgetedBytes == fBudgetedBytes); 441 SkASSERT(budgetedBytes == fBudgetedBytes);
(...skipping 15 matching lines...) Expand all
439 // SkASSERT(!overBudget || locked == count || fPurging); 457 // SkASSERT(!overBudget || locked == count || fPurging);
440 } 458 }
441 #endif 459 #endif
442 460
443 #if GR_CACHE_STATS 461 #if GR_CACHE_STATS
444 void GrResourceCache2::printStats() const { 462 void GrResourceCache2::printStats() const {
445 this->validate(); 463 this->validate();
446 464
447 int locked = 0; 465 int locked = 0;
448 int scratch = 0; 466 int scratch = 0;
467 int wrapped = 0;
468 size_t unbudgetedSize = 0;
449 469
450 ResourceList::Iter iter; 470 ResourceList::Iter iter;
451 GrGpuResource* resource = iter.init(fResources, ResourceList::Iter::kHead_It erStart); 471 GrGpuResource* resource = iter.init(fResources, ResourceList::Iter::kHead_It erStart);
452 472
453 for ( ; resource; resource = iter.next()) { 473 for ( ; resource; resource = iter.next()) {
454 if (!resource->isPurgable()) { 474 if (!resource->isPurgable()) {
455 ++locked; 475 ++locked;
456 } 476 }
457 if (resource->cacheAccess().isScratch()) { 477 if (resource->cacheAccess().isScratch()) {
458 ++scratch; 478 ++scratch;
459 } 479 }
480 if (resource->cacheAccess().isWrapped()) {
481 ++wrapped;
482 }
483 if (!resource->cacheAccess().isBudgeted()) {
484 unbudgetedSize += resource->gpuMemorySize();
485 }
460 } 486 }
461 487
462 float countUtilization = (100.f * fBudgetedCount) / fMaxCount; 488 float countUtilization = (100.f * fBudgetedCount) / fMaxCount;
463 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes; 489 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes;
464 490
465 SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes); 491 SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes);
466 SkDebugf( 492 SkDebugf("\t\tEntry Count: current %d"
467 "\t\tEntry Count: current %d (%d budgeted, %d locked, %d scratch %.2g%% full), high %d\n", 493 " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), hig h %d\n",
468 fCount, fBudgetedCount, locked, scratch, countUtilization, fHighWaterCou nt); 494 fCount, fBudgetedCount, wrapped, locked, scratch, countUtilization, fHig hWaterCount);
469 SkDebugf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full) high %d\n", 495 SkDebugf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudget ed) high %d\n",
470 fBytes, fBudgetedBytes, byteUtilization, fHighWaterBytes); 496 fBytes, fBudgetedBytes, byteUtilization, unbudgetedSize, fHighWa terBytes);
471 } 497 }
472 498
473 #endif 499 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrResourceCache2.h ('k') | tests/ResourceCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698