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

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

Issue 2307053002: Restructure flushing relationship between GrContext, GrDrawingManager, and GrResourceCache. (Closed)
Patch Set: cleanup Created 4 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "GrResourceCache.h" 9 #include "GrResourceCache.h"
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 , fMaxUnusedFlushes(kDefaultMaxUnusedFlushes) 66 , fMaxUnusedFlushes(kDefaultMaxUnusedFlushes)
67 #if GR_CACHE_STATS 67 #if GR_CACHE_STATS
68 , fHighWaterCount(0) 68 , fHighWaterCount(0)
69 , fHighWaterBytes(0) 69 , fHighWaterBytes(0)
70 , fBudgetedHighWaterCount(0) 70 , fBudgetedHighWaterCount(0)
71 , fBudgetedHighWaterBytes(0) 71 , fBudgetedHighWaterBytes(0)
72 #endif 72 #endif
73 , fBytes(0) 73 , fBytes(0)
74 , fBudgetedCount(0) 74 , fBudgetedCount(0)
75 , fBudgetedBytes(0) 75 , fBudgetedBytes(0)
76 , fOverBudgetCB(nullptr)
77 , fOverBudgetData(nullptr)
78 , fFlushTimestamps(nullptr) 76 , fFlushTimestamps(nullptr)
79 , fLastFlushTimestampIndex(0) 77 , fLastFlushTimestampIndex(0)
80 , fPreferVRAMUseOverFlushes(caps->preferVRAMUseOverFlushes()) { 78 , fPreferVRAMUseOverFlushes(caps->preferVRAMUseOverFlushes()) {
81 SkDEBUGCODE(fCount = 0;) 79 SkDEBUGCODE(fCount = 0;)
82 SkDEBUGCODE(fNewlyPurgeableResourceForValidation = nullptr;) 80 SkDEBUGCODE(fNewlyPurgeableResourceForValidation = nullptr;)
83 this->resetFlushTimestamps(); 81 this->resetFlushTimestamps();
84 } 82 }
85 83
86 GrResourceCache::~GrResourceCache() { 84 GrResourceCache::~GrResourceCache() {
87 this->releaseAll(); 85 this->releaseAll();
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 bool stillOverbudget = this->overBudget(); 493 bool stillOverbudget = this->overBudget();
496 while (stillOverbudget && fPurgeableQueue.count()) { 494 while (stillOverbudget && fPurgeableQueue.count()) {
497 GrGpuResource* resource = fPurgeableQueue.peek(); 495 GrGpuResource* resource = fPurgeableQueue.peek();
498 SkASSERT(resource->isPurgeable()); 496 SkASSERT(resource->isPurgeable());
499 resource->cacheAccess().release(); 497 resource->cacheAccess().release();
500 stillOverbudget = this->overBudget(); 498 stillOverbudget = this->overBudget();
501 } 499 }
502 500
503 this->validate(); 501 this->validate();
504 502
505 if (stillOverbudget) { 503 if (stillOverbudget) {
robertphillips 2016/09/02 16:23:06 GrDrawingManager ?
506 // Despite the purge we're still over budget. Call our over budget callb ack. If this frees 504 // Set this so that GrDrawContext will issue a flush to free up resource s with pending IO.
507 // any resources then we'll get notified and take appropriate action. 505 fRequestFlush = true;
508 (*fOverBudgetCB)(fOverBudgetData);
509 this->validate();
510 } 506 }
511 } 507 }
512 508
513 void GrResourceCache::purgeAllUnlocked() { 509 void GrResourceCache::purgeAllUnlocked() {
514 // We could disable maintaining the heap property here, but it would add a l ot of complexity. 510 // We could disable maintaining the heap property here, but it would add a l ot of complexity.
515 // Moreover, this is rarely called. 511 // Moreover, this is rarely called.
516 while (fPurgeableQueue.count()) { 512 while (fPurgeableQueue.count()) {
517 GrGpuResource* resource = fPurgeableQueue.peek(); 513 GrGpuResource* resource = fPurgeableQueue.peek();
518 SkASSERT(resource->isPurgeable()); 514 SkASSERT(resource->isPurgeable());
519 resource->cacheAccess().release(); 515 resource->cacheAccess().release();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 // count should be the next timestamp we return. 610 // count should be the next timestamp we return.
615 SkASSERT(fTimestamp == SkToU32(count)); 611 SkASSERT(fTimestamp == SkToU32(count));
616 612
617 // The historical timestamps of flushes are now invalid. 613 // The historical timestamps of flushes are now invalid.
618 this->resetFlushTimestamps(); 614 this->resetFlushTimestamps();
619 } 615 }
620 } 616 }
621 return fTimestamp++; 617 return fTimestamp++;
622 } 618 }
623 619
624 void GrResourceCache::notifyFlushOccurred() { 620 void GrResourceCache::notifyFlushOccurred(FlushType type) {
625 if (fFlushTimestamps) { 621 switch (type) {
626 SkASSERT(SkIsPow2(fMaxUnusedFlushes)); 622 case FlushType::kCacheRequested:
627 fLastFlushTimestampIndex = (fLastFlushTimestampIndex + 1) & (fMaxUnusedF lushes - 1); 623 SkASSERT(fRequestFlush);
628 // get the timestamp before accessing fFlushTimestamps because getNextTi mestamp will 624 fRequestFlush = false;
robertphillips 2016/09/02 16:23:06 pull out purgeAsNeeds calls and just have one at t
629 // reallocate fFlushTimestamps on timestamp overflow. 625 this->purgeAsNeeded();
630 uint32_t timestamp = this->getNextTimestamp(); 626 break;
631 fFlushTimestamps[fLastFlushTimestampIndex] = timestamp; 627 case FlushType::kExternal:
632 this->purgeAsNeeded(); 628 if (fFlushTimestamps) {
629 SkASSERT(SkIsPow2(fMaxUnusedFlushes));
630 fLastFlushTimestampIndex = (fLastFlushTimestampIndex + 1) & (fMa xUnusedFlushes - 1);
631 // get the timestamp before accessing fFlushTimestamps because g etNextTimestamp will
632 // reallocate fFlushTimestamps on timestamp overflow.
633 uint32_t timestamp = this->getNextTimestamp();
634 fFlushTimestamps[fLastFlushTimestampIndex] = timestamp;
635 this->purgeAsNeeded();
636 }
637 break;
633 } 638 }
634 } 639 }
635 640
636 void GrResourceCache::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) c onst { 641 void GrResourceCache::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) c onst {
637 for (int i = 0; i < fNonpurgeableResources.count(); ++i) { 642 for (int i = 0; i < fNonpurgeableResources.count(); ++i) {
638 fNonpurgeableResources[i]->dumpMemoryStatistics(traceMemoryDump); 643 fNonpurgeableResources[i]->dumpMemoryStatistics(traceMemoryDump);
639 } 644 }
640 for (int i = 0; i < fPurgeableQueue.count(); ++i) { 645 for (int i = 0; i < fPurgeableQueue.count(); ++i) {
641 fPurgeableQueue.at(i)->dumpMemoryStatistics(traceMemoryDump); 646 fPurgeableQueue.at(i)->dumpMemoryStatistics(traceMemoryDump);
642 } 647 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 return true; 776 return true;
772 } 777 }
773 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index] == resource) { 778 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index] == resource) {
774 return true; 779 return true;
775 } 780 }
776 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca che."); 781 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca che.");
777 return false; 782 return false;
778 } 783 }
779 784
780 #endif 785 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698