| 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 #ifndef GrResourceCache2_DEFINED | 9 #ifndef GrResourceCache2_DEFINED |
| 10 #define GrResourceCache2_DEFINED | 10 #define GrResourceCache2_DEFINED |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 #ifdef SK_DEBUG | 103 #ifdef SK_DEBUG |
| 104 // This is not particularly fast and only used for validation, so debug only
. | 104 // This is not particularly fast and only used for validation, so debug only
. |
| 105 int countScratchEntriesForKey(const GrScratchKey& scratchKey) const { | 105 int countScratchEntriesForKey(const GrScratchKey& scratchKey) const { |
| 106 return fScratchMap.countForKey(scratchKey); | 106 return fScratchMap.countForKey(scratchKey); |
| 107 } | 107 } |
| 108 #endif | 108 #endif |
| 109 | 109 |
| 110 /** | 110 /** |
| 111 * Find a resource that matches a content key. | 111 * Find a resource that matches a content key. |
| 112 */ | 112 */ |
| 113 GrGpuResource* findAndRefContentResource(const GrResourceKey& contentKey) { | 113 GrGpuResource* findAndRefContentResource(const GrContentKey& contentKey) { |
| 114 GrGpuResource* resource = fContentHash.find(contentKey); | 114 GrGpuResource* resource = fContentHash.find(contentKey); |
| 115 if (resource) { | 115 if (resource) { |
| 116 resource->ref(); | 116 resource->ref(); |
| 117 this->makeResourceMRU(resource); | 117 this->makeResourceMRU(resource); |
| 118 } | 118 } |
| 119 return resource; | 119 return resource; |
| 120 } | 120 } |
| 121 | 121 |
| 122 /** | 122 /** |
| 123 * Query whether a content key exists in the cache. | 123 * Query whether a content key exists in the cache. |
| 124 */ | 124 */ |
| 125 bool hasContentKey(const GrResourceKey& contentKey) const { | 125 bool hasContentKey(const GrContentKey& contentKey) const { |
| 126 return SkToBool(fContentHash.find(contentKey)); | 126 return SkToBool(fContentHash.find(contentKey)); |
| 127 } | 127 } |
| 128 | 128 |
| 129 /** Purges all resources that don't have external owners. */ | 129 /** Purges all resources that don't have external owners. */ |
| 130 void purgeAllUnlocked(); | 130 void purgeAllUnlocked(); |
| 131 | 131 |
| 132 /** | 132 /** |
| 133 * The callback function used by the cache when it is still over budget afte
r a purge. The | 133 * The callback function used by the cache when it is still over budget afte
r a purge. The |
| 134 * passed in 'data' is the same 'data' handed to setOverbudgetCallback. | 134 * passed in 'data' is the same 'data' handed to setOverbudgetCallback. |
| 135 */ | 135 */ |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 struct ScratchMapTraits { | 186 struct ScratchMapTraits { |
| 187 static const GrScratchKey& GetKey(const GrGpuResource& r) { | 187 static const GrScratchKey& GetKey(const GrGpuResource& r) { |
| 188 return r.cacheAccess().getScratchKey(); | 188 return r.cacheAccess().getScratchKey(); |
| 189 } | 189 } |
| 190 | 190 |
| 191 static uint32_t Hash(const GrScratchKey& key) { return key.hash(); } | 191 static uint32_t Hash(const GrScratchKey& key) { return key.hash(); } |
| 192 }; | 192 }; |
| 193 typedef SkTMultiMap<GrGpuResource, GrScratchKey, ScratchMapTraits> ScratchMa
p; | 193 typedef SkTMultiMap<GrGpuResource, GrScratchKey, ScratchMapTraits> ScratchMa
p; |
| 194 | 194 |
| 195 struct ContentHashTraits { | 195 struct ContentHashTraits { |
| 196 static const GrResourceKey& GetKey(const GrGpuResource& r) { | 196 static const GrContentKey& GetKey(const GrGpuResource& r) { |
| 197 return *r.cacheAccess().getContentKey(); | 197 return r.cacheAccess().getContentKey(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); } | 200 static uint32_t Hash(const GrContentKey& key) { return key.hash(); } |
| 201 }; | 201 }; |
| 202 typedef SkTDynamicHash<GrGpuResource, GrResourceKey, ContentHashTraits> Cont
entHash; | 202 typedef SkTDynamicHash<GrGpuResource, GrContentKey, ContentHashTraits> Conte
ntHash; |
| 203 | 203 |
| 204 typedef SkTInternalLList<GrGpuResource> ResourceList; | 204 typedef SkTInternalLList<GrGpuResource> ResourceList; |
| 205 | 205 |
| 206 ResourceList fResources; | 206 ResourceList fResources; |
| 207 // This map holds all resources that can be used as scratch resources. | 207 // This map holds all resources that can be used as scratch resources. |
| 208 ScratchMap fScratchMap; | 208 ScratchMap fScratchMap; |
| 209 // This holds all resources that have content keys. | 209 // This holds all resources that have content keys. |
| 210 ContentHash fContentHash; | 210 ContentHash fContentHash; |
| 211 | 211 |
| 212 // our budget, used in purgeAsNeeded() | 212 // our budget, used in purgeAsNeeded() |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 295 |
| 296 friend class GrGpuResource; // To access all the proxy inline methods. | 296 friend class GrGpuResource; // To access all the proxy inline methods. |
| 297 friend class GrResourceCache2; // To create this type. | 297 friend class GrResourceCache2; // To create this type. |
| 298 }; | 298 }; |
| 299 | 299 |
| 300 inline GrResourceCache2::ResourceAccess GrResourceCache2::resourceAccess() { | 300 inline GrResourceCache2::ResourceAccess GrResourceCache2::resourceAccess() { |
| 301 return ResourceAccess(this); | 301 return ResourceAccess(this); |
| 302 } | 302 } |
| 303 | 303 |
| 304 #endif | 304 #endif |
| OLD | NEW |