| OLD | NEW |
| 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 Loading... |
| 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) |
| 76 , fFlushTimestamps(nullptr) | 78 , fFlushTimestamps(nullptr) |
| 77 , fLastFlushTimestampIndex(0) | 79 , fLastFlushTimestampIndex(0) |
| 78 , fPreferVRAMUseOverFlushes(caps->preferVRAMUseOverFlushes()) { | 80 , fPreferVRAMUseOverFlushes(caps->preferVRAMUseOverFlushes()) { |
| 79 SkDEBUGCODE(fCount = 0;) | 81 SkDEBUGCODE(fCount = 0;) |
| 80 SkDEBUGCODE(fNewlyPurgeableResourceForValidation = nullptr;) | 82 SkDEBUGCODE(fNewlyPurgeableResourceForValidation = nullptr;) |
| 81 this->resetFlushTimestamps(); | 83 this->resetFlushTimestamps(); |
| 82 } | 84 } |
| 83 | 85 |
| 84 GrResourceCache::~GrResourceCache() { | 86 GrResourceCache::~GrResourceCache() { |
| 85 this->releaseAll(); | 87 this->releaseAll(); |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 while (stillOverbudget && fPurgeableQueue.count()) { | 496 while (stillOverbudget && fPurgeableQueue.count()) { |
| 495 GrGpuResource* resource = fPurgeableQueue.peek(); | 497 GrGpuResource* resource = fPurgeableQueue.peek(); |
| 496 SkASSERT(resource->isPurgeable()); | 498 SkASSERT(resource->isPurgeable()); |
| 497 resource->cacheAccess().release(); | 499 resource->cacheAccess().release(); |
| 498 stillOverbudget = this->overBudget(); | 500 stillOverbudget = this->overBudget(); |
| 499 } | 501 } |
| 500 | 502 |
| 501 this->validate(); | 503 this->validate(); |
| 502 | 504 |
| 503 if (stillOverbudget) { | 505 if (stillOverbudget) { |
| 504 // Set this so that GrDrawingManager will issue a flush to free up resou
rces with pending | 506 // Despite the purge we're still over budget. Call our over budget callb
ack. If this frees |
| 505 // IO that we were unable to purge in this pass. | 507 // any resources then we'll get notified and take appropriate action. |
| 506 fRequestFlush = true; | 508 (*fOverBudgetCB)(fOverBudgetData); |
| 509 this->validate(); |
| 507 } | 510 } |
| 508 } | 511 } |
| 509 | 512 |
| 510 void GrResourceCache::purgeAllUnlocked() { | 513 void GrResourceCache::purgeAllUnlocked() { |
| 511 // We could disable maintaining the heap property here, but it would add a l
ot of complexity. | 514 // We could disable maintaining the heap property here, but it would add a l
ot of complexity. |
| 512 // Moreover, this is rarely called. | 515 // Moreover, this is rarely called. |
| 513 while (fPurgeableQueue.count()) { | 516 while (fPurgeableQueue.count()) { |
| 514 GrGpuResource* resource = fPurgeableQueue.peek(); | 517 GrGpuResource* resource = fPurgeableQueue.peek(); |
| 515 SkASSERT(resource->isPurgeable()); | 518 SkASSERT(resource->isPurgeable()); |
| 516 resource->cacheAccess().release(); | 519 resource->cacheAccess().release(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 // count should be the next timestamp we return. | 614 // count should be the next timestamp we return. |
| 612 SkASSERT(fTimestamp == SkToU32(count)); | 615 SkASSERT(fTimestamp == SkToU32(count)); |
| 613 | 616 |
| 614 // The historical timestamps of flushes are now invalid. | 617 // The historical timestamps of flushes are now invalid. |
| 615 this->resetFlushTimestamps(); | 618 this->resetFlushTimestamps(); |
| 616 } | 619 } |
| 617 } | 620 } |
| 618 return fTimestamp++; | 621 return fTimestamp++; |
| 619 } | 622 } |
| 620 | 623 |
| 621 void GrResourceCache::notifyFlushOccurred(FlushType type) { | 624 void GrResourceCache::notifyFlushOccurred() { |
| 622 switch (type) { | 625 if (fFlushTimestamps) { |
| 623 case FlushType::kImmediateMode: | 626 SkASSERT(SkIsPow2(fMaxUnusedFlushes)); |
| 624 break; | 627 fLastFlushTimestampIndex = (fLastFlushTimestampIndex + 1) & (fMaxUnusedF
lushes - 1); |
| 625 case FlushType::kCacheRequested: | 628 // get the timestamp before accessing fFlushTimestamps because getNextTi
mestamp will |
| 626 SkASSERT(fRequestFlush); | 629 // reallocate fFlushTimestamps on timestamp overflow. |
| 627 fRequestFlush = false; | 630 uint32_t timestamp = this->getNextTimestamp(); |
| 628 break; | 631 fFlushTimestamps[fLastFlushTimestampIndex] = timestamp; |
| 629 case FlushType::kExternal: | 632 this->purgeAsNeeded(); |
| 630 if (fFlushTimestamps) { | |
| 631 SkASSERT(SkIsPow2(fMaxUnusedFlushes)); | |
| 632 fLastFlushTimestampIndex = (fLastFlushTimestampIndex + 1) & (fMa
xUnusedFlushes - 1); | |
| 633 // get the timestamp before accessing fFlushTimestamps because g
etNextTimestamp will | |
| 634 // reallocate fFlushTimestamps on timestamp overflow. | |
| 635 uint32_t timestamp = this->getNextTimestamp(); | |
| 636 fFlushTimestamps[fLastFlushTimestampIndex] = timestamp; | |
| 637 } | |
| 638 break; | |
| 639 } | 633 } |
| 640 this->purgeAsNeeded(); | |
| 641 } | 634 } |
| 642 | 635 |
| 643 void GrResourceCache::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) c
onst { | 636 void GrResourceCache::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) c
onst { |
| 644 for (int i = 0; i < fNonpurgeableResources.count(); ++i) { | 637 for (int i = 0; i < fNonpurgeableResources.count(); ++i) { |
| 645 fNonpurgeableResources[i]->dumpMemoryStatistics(traceMemoryDump); | 638 fNonpurgeableResources[i]->dumpMemoryStatistics(traceMemoryDump); |
| 646 } | 639 } |
| 647 for (int i = 0; i < fPurgeableQueue.count(); ++i) { | 640 for (int i = 0; i < fPurgeableQueue.count(); ++i) { |
| 648 fPurgeableQueue.at(i)->dumpMemoryStatistics(traceMemoryDump); | 641 fPurgeableQueue.at(i)->dumpMemoryStatistics(traceMemoryDump); |
| 649 } | 642 } |
| 650 } | 643 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 return true; | 771 return true; |
| 779 } | 772 } |
| 780 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { | 773 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { |
| 781 return true; | 774 return true; |
| 782 } | 775 } |
| 783 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca
che."); | 776 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca
che."); |
| 784 return false; | 777 return false; |
| 785 } | 778 } |
| 786 | 779 |
| 787 #endif | 780 #endif |
| OLD | NEW |