OLD | NEW |
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 "GrResourceCache.h" | 10 #include "GrResourceCache.h" |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 } | 557 } |
558 }; | 558 }; |
559 Less less; | 559 Less less; |
560 SkTQSort(fNonpurgeableResources.begin(), fNonpurgeableResources.end(
) - 1, less); | 560 SkTQSort(fNonpurgeableResources.begin(), fNonpurgeableResources.end(
) - 1, less); |
561 | 561 |
562 // Pick resources out of the purgeable and non-purgeable arrays base
d on lowest | 562 // Pick resources out of the purgeable and non-purgeable arrays base
d on lowest |
563 // timestamp and assign new timestamps. | 563 // timestamp and assign new timestamps. |
564 int currP = 0; | 564 int currP = 0; |
565 int currNP = 0; | 565 int currNP = 0; |
566 while (currP < sortedPurgeableResources.count() && | 566 while (currP < sortedPurgeableResources.count() && |
567 currNP < fNonpurgeableResources.count()) { | 567 currNP < fNonpurgeableResources.count()) { |
568 uint32_t tsP = sortedPurgeableResources[currP]->cacheAccess().ti
mestamp(); | 568 uint32_t tsP = sortedPurgeableResources[currP]->cacheAccess().ti
mestamp(); |
569 uint32_t tsNP = fNonpurgeableResources[currNP]->cacheAccess().ti
mestamp(); | 569 uint32_t tsNP = fNonpurgeableResources[currNP]->cacheAccess().ti
mestamp(); |
570 SkASSERT(tsP != tsNP); | 570 SkASSERT(tsP != tsNP); |
571 if (tsP < tsNP) { | 571 if (tsP < tsNP) { |
572 sortedPurgeableResources[currP++]->cacheAccess().setTimestam
p(fTimestamp++); | 572 sortedPurgeableResources[currP++]->cacheAccess().setTimestam
p(fTimestamp++); |
573 } else { | 573 } else { |
574 // Correct the index in the nonpurgeable array stored on the
resource post-sort. | 574 // Correct the index in the nonpurgeable array stored on the
resource post-sort. |
575 *fNonpurgeableResources[currNP]->cacheAccess().accessCacheIn
dex() = currNP; | 575 *fNonpurgeableResources[currNP]->cacheAccess().accessCacheIn
dex() = currNP; |
576 fNonpurgeableResources[currNP++]->cacheAccess().setTimestamp
(fTimestamp++); | 576 fNonpurgeableResources[currNP++]->cacheAccess().setTimestamp
(fTimestamp++); |
577 } | 577 } |
(...skipping 11 matching lines...) Expand all Loading... |
589 // Rebuild the queue. | 589 // Rebuild the queue. |
590 for (int i = 0; i < sortedPurgeableResources.count(); ++i) { | 590 for (int i = 0; i < sortedPurgeableResources.count(); ++i) { |
591 fPurgeableQueue.insert(sortedPurgeableResources[i]); | 591 fPurgeableQueue.insert(sortedPurgeableResources[i]); |
592 } | 592 } |
593 | 593 |
594 this->validate(); | 594 this->validate(); |
595 SkASSERT(count == this->getResourceCount()); | 595 SkASSERT(count == this->getResourceCount()); |
596 | 596 |
597 // count should be the next timestamp we return. | 597 // count should be the next timestamp we return. |
598 SkASSERT(fTimestamp == SkToU32(count)); | 598 SkASSERT(fTimestamp == SkToU32(count)); |
599 | 599 |
600 // The historical timestamps of flushes are now invalid. | 600 // The historical timestamps of flushes are now invalid. |
601 this->resetFlushTimestamps(); | 601 this->resetFlushTimestamps(); |
602 } | 602 } |
603 } | 603 } |
604 return fTimestamp++; | 604 return fTimestamp++; |
605 } | 605 } |
606 | 606 |
607 void GrResourceCache::notifyFlushOccurred() { | 607 void GrResourceCache::notifyFlushOccurred() { |
608 if (fFlushTimestamps) { | 608 if (fFlushTimestamps) { |
609 SkASSERT(SkIsPow2(fMaxUnusedFlushes)); | 609 SkASSERT(SkIsPow2(fMaxUnusedFlushes)); |
610 fLastFlushTimestampIndex = (fLastFlushTimestampIndex + 1) & (fMaxUnusedF
lushes - 1); | 610 fLastFlushTimestampIndex = (fLastFlushTimestampIndex + 1) & (fMaxUnusedF
lushes - 1); |
611 // get the timestamp before accessing fFlushTimestamps because getNextTi
mestamp will | 611 // get the timestamp before accessing fFlushTimestamps because getNextTi
mestamp will |
612 // reallocate fFlushTimestamps on timestamp overflow. | 612 // reallocate fFlushTimestamps on timestamp overflow. |
613 uint32_t timestamp = this->getNextTimestamp(); | 613 uint32_t timestamp = this->getNextTimestamp(); |
614 fFlushTimestamps[fLastFlushTimestampIndex] = timestamp; | 614 fFlushTimestamps[fLastFlushTimestampIndex] = timestamp; |
615 this->purgeAsNeeded(); | 615 this->purgeAsNeeded(); |
616 } | 616 } |
617 } | 617 } |
618 | 618 |
| 619 void GrResourceCache::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) c
onst { |
| 620 for (int i = 0; i < fNonpurgeableResources.count(); ++i) { |
| 621 fNonpurgeableResources[i]->dumpMemoryStatistics(traceMemoryDump); |
| 622 } |
| 623 for (int i = 0; i < fPurgeableQueue.count(); ++i) { |
| 624 fPurgeableQueue.at(i)->dumpMemoryStatistics(traceMemoryDump); |
| 625 } |
| 626 } |
| 627 |
619 #ifdef SK_DEBUG | 628 #ifdef SK_DEBUG |
620 void GrResourceCache::validate() const { | 629 void GrResourceCache::validate() const { |
621 // Reduce the frequency of validations for large resource counts. | 630 // Reduce the frequency of validations for large resource counts. |
622 static SkRandom gRandom; | 631 static SkRandom gRandom; |
623 int mask = (SkNextPow2(fCount + 1) >> 5) - 1; | 632 int mask = (SkNextPow2(fCount + 1) >> 5) - 1; |
624 if (~mask && (gRandom.nextU() & mask)) { | 633 if (~mask && (gRandom.nextU() & mask)) { |
625 return; | 634 return; |
626 } | 635 } |
627 | 636 |
628 struct Stats { | 637 struct Stats { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 return true; | 733 return true; |
725 } | 734 } |
726 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { | 735 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { |
727 return true; | 736 return true; |
728 } | 737 } |
729 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca
che."); | 738 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca
che."); |
730 return false; | 739 return false; |
731 } | 740 } |
732 | 741 |
733 #endif | 742 #endif |
OLD | NEW |