| 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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 int32_t domain = sk_atomic_inc(&gDomain); | 36 int32_t domain = sk_atomic_inc(&gDomain); |
| 37 if (domain > SK_MaxU16) { | 37 if (domain > SK_MaxU16) { |
| 38 SkFAIL("Too many GrUniqueKey Domains"); | 38 SkFAIL("Too many GrUniqueKey Domains"); |
| 39 } | 39 } |
| 40 | 40 |
| 41 return static_cast<Domain>(domain); | 41 return static_cast<Domain>(domain); |
| 42 } | 42 } |
| 43 | 43 |
| 44 uint32_t GrResourceKeyHash(const uint32_t* data, size_t size) { | 44 uint32_t GrResourceKeyHash(const uint32_t* data, size_t size) { |
| 45 return SkChecksum::Murmur3(data, size); | 45 return SkChecksum::Compute(data, size); |
| 46 } | 46 } |
| 47 | 47 |
| 48 ////////////////////////////////////////////////////////////////////////////// | 48 ////////////////////////////////////////////////////////////////////////////// |
| 49 | 49 |
| 50 class GrResourceCache::AutoValidate : ::SkNoncopyable { | 50 class GrResourceCache::AutoValidate : ::SkNoncopyable { |
| 51 public: | 51 public: |
| 52 AutoValidate(GrResourceCache* cache) : fCache(cache) { cache->validate(); } | 52 AutoValidate(GrResourceCache* cache) : fCache(cache) { cache->validate(); } |
| 53 ~AutoValidate() { fCache->validate(); } | 53 ~AutoValidate() { fCache->validate(); } |
| 54 private: | 54 private: |
| 55 GrResourceCache* fCache; | 55 GrResourceCache* fCache; |
| (...skipping 501 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. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 return true; | 733 return true; |
| 734 } | 734 } |
| 735 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { | 735 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { |
| 736 return true; | 736 return true; |
| 737 } | 737 } |
| 738 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."); |
| 739 return false; | 739 return false; |
| 740 } | 740 } |
| 741 | 741 |
| 742 #endif | 742 #endif |
| OLD | NEW |