| 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 |
| 11 #include "GrCaps.h" | 11 #include "GrCaps.h" |
| 12 #include "GrGpuResourceCacheAccess.h" | 12 #include "GrGpuResourceCacheAccess.h" |
| 13 #include "GrTracing.h" | 13 #include "GrTracing.h" |
| 14 #include "SkChecksum.h" | |
| 15 #include "SkGr.h" | 14 #include "SkGr.h" |
| 16 #include "SkMessageBus.h" | 15 #include "SkMessageBus.h" |
| 16 #include "SkOpts.h" |
| 17 #include "SkTSort.h" | 17 #include "SkTSort.h" |
| 18 | 18 |
| 19 DECLARE_SKMESSAGEBUS_MESSAGE(GrUniqueKeyInvalidatedMessage); | 19 DECLARE_SKMESSAGEBUS_MESSAGE(GrUniqueKeyInvalidatedMessage); |
| 20 | 20 |
| 21 ////////////////////////////////////////////////////////////////////////////// | 21 ////////////////////////////////////////////////////////////////////////////// |
| 22 | 22 |
| 23 GrScratchKey::ResourceType GrScratchKey::GenerateResourceType() { | 23 GrScratchKey::ResourceType GrScratchKey::GenerateResourceType() { |
| 24 static int32_t gType = INHERITED::kInvalidDomain + 1; | 24 static int32_t gType = INHERITED::kInvalidDomain + 1; |
| 25 | 25 |
| 26 int32_t type = sk_atomic_inc(&gType); | 26 int32_t type = sk_atomic_inc(&gType); |
| 27 if (type > SK_MaxU16) { | 27 if (type > SK_MaxU16) { |
| 28 SkFAIL("Too many Resource Types"); | 28 SkFAIL("Too many Resource Types"); |
| 29 } | 29 } |
| 30 | 30 |
| 31 return static_cast<ResourceType>(type); | 31 return static_cast<ResourceType>(type); |
| 32 } | 32 } |
| 33 | 33 |
| 34 GrUniqueKey::Domain GrUniqueKey::GenerateDomain() { | 34 GrUniqueKey::Domain GrUniqueKey::GenerateDomain() { |
| 35 static int32_t gDomain = INHERITED::kInvalidDomain + 1; | 35 static int32_t gDomain = INHERITED::kInvalidDomain + 1; |
| 36 | 36 |
| 37 int32_t domain = sk_atomic_inc(&gDomain); | 37 int32_t domain = sk_atomic_inc(&gDomain); |
| 38 if (domain > SK_MaxU16) { | 38 if (domain > SK_MaxU16) { |
| 39 SkFAIL("Too many GrUniqueKey Domains"); | 39 SkFAIL("Too many GrUniqueKey Domains"); |
| 40 } | 40 } |
| 41 | 41 |
| 42 return static_cast<Domain>(domain); | 42 return static_cast<Domain>(domain); |
| 43 } | 43 } |
| 44 | 44 |
| 45 uint32_t GrResourceKeyHash(const uint32_t* data, size_t size) { | 45 uint32_t GrResourceKeyHash(const uint32_t* data, size_t size) { |
| 46 return SkChecksum::Murmur3(data, size); | 46 return SkOpts::hash(data, size); |
| 47 } | 47 } |
| 48 | 48 |
| 49 ////////////////////////////////////////////////////////////////////////////// | 49 ////////////////////////////////////////////////////////////////////////////// |
| 50 | 50 |
| 51 class GrResourceCache::AutoValidate : ::SkNoncopyable { | 51 class GrResourceCache::AutoValidate : ::SkNoncopyable { |
| 52 public: | 52 public: |
| 53 AutoValidate(GrResourceCache* cache) : fCache(cache) { cache->validate(); } | 53 AutoValidate(GrResourceCache* cache) : fCache(cache) { cache->validate(); } |
| 54 ~AutoValidate() { fCache->validate(); } | 54 ~AutoValidate() { fCache->validate(); } |
| 55 private: | 55 private: |
| 56 GrResourceCache* fCache; | 56 GrResourceCache* fCache; |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 | 680 |
| 681 if (resource->cacheAccess().isScratch()) { | 681 if (resource->cacheAccess().isScratch()) { |
| 682 SkASSERT(!uniqueKey.isValid()); | 682 SkASSERT(!uniqueKey.isValid()); |
| 683 ++fScratch; | 683 ++fScratch; |
| 684 SkASSERT(fScratchMap->countForKey(scratchKey)); | 684 SkASSERT(fScratchMap->countForKey(scratchKey)); |
| 685 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); | 685 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); |
| 686 } else if (scratchKey.isValid()) { | 686 } else if (scratchKey.isValid()) { |
| 687 SkASSERT(SkBudgeted::kNo == resource->resourcePriv().isBudgeted(
) || | 687 SkASSERT(SkBudgeted::kNo == resource->resourcePriv().isBudgeted(
) || |
| 688 uniqueKey.isValid()); | 688 uniqueKey.isValid()); |
| 689 if (!uniqueKey.isValid()) { | 689 if (!uniqueKey.isValid()) { |
| 690 ++fCouldBeScratch; | 690 ++fCouldBeScratch; |
| 691 SkASSERT(fScratchMap->countForKey(scratchKey)); | 691 SkASSERT(fScratchMap->countForKey(scratchKey)); |
| 692 } | 692 } |
| 693 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); | 693 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); |
| 694 } | 694 } |
| 695 if (uniqueKey.isValid()) { | 695 if (uniqueKey.isValid()) { |
| 696 ++fContent; | 696 ++fContent; |
| 697 SkASSERT(fUniqueHash->find(uniqueKey) == resource); | 697 SkASSERT(fUniqueHash->find(uniqueKey) == resource); |
| 698 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); | 698 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); |
| 699 SkASSERT(SkBudgeted::kYes == resource->resourcePriv().isBudgeted
()); | 699 SkASSERT(SkBudgeted::kYes == resource->resourcePriv().isBudgeted
()); |
| 700 | 700 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 return true; | 771 return true; |
| 772 } | 772 } |
| 773 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { | 773 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { |
| 774 return true; | 774 return true; |
| 775 } | 775 } |
| 776 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."); |
| 777 return false; | 777 return false; |
| 778 } | 778 } |
| 779 | 779 |
| 780 #endif | 780 #endif |
| OLD | NEW |