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