| 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 GrResourceCache_DEFINED | 9 #ifndef GrResourceCache_DEFINED |
| 10 #define GrResourceCache_DEFINED | 10 #define GrResourceCache_DEFINED |
| 11 | 11 |
| 12 #include "GrGpuResource.h" | 12 #include "GrGpuResource.h" |
| 13 #include "GrGpuResourceCacheAccess.h" | 13 #include "GrGpuResourceCacheAccess.h" |
| 14 #include "GrGpuResourcePriv.h" | 14 #include "GrGpuResourcePriv.h" |
| 15 #include "GrResourceKey.h" | 15 #include "GrResourceKey.h" |
| 16 #include "SkMessageBus.h" | 16 #include "SkMessageBus.h" |
| 17 #include "SkRefCnt.h" | 17 #include "SkRefCnt.h" |
| 18 #include "SkTArray.h" | 18 #include "SkTArray.h" |
| 19 #include "SkTDPQueue.h" | 19 #include "SkTDPQueue.h" |
| 20 #include "SkTInternalLList.h" | 20 #include "SkTInternalLList.h" |
| 21 #include "SkTMultiMap.h" | 21 #include "SkTMultiMap.h" |
| 22 | 22 |
| 23 class SkString; | 23 class SkString; |
| 24 class SkTraceMemoryDump; |
| 24 | 25 |
| 25 /** | 26 /** |
| 26 * Manages the lifetime of all GrGpuResource instances. | 27 * Manages the lifetime of all GrGpuResource instances. |
| 27 * | 28 * |
| 28 * Resources may have optionally have two types of keys: | 29 * Resources may have optionally have two types of keys: |
| 29 * 1) A scratch key. This is for resources whose allocations are cached but
not their contents. | 30 * 1) A scratch key. This is for resources whose allocations are cached but
not their contents. |
| 30 * Multiple resources can share the same scratch key. This is so a calle
r can have two | 31 * Multiple resources can share the same scratch key. This is so a calle
r can have two |
| 31 * resource instances with the same properties (e.g. multipass rendering
that ping-pongs | 32 * resource instances with the same properties (e.g. multipass rendering
that ping-pongs |
| 32 * between two temporary surfaces). The scratch key is set at resource c
reation time and | 33 * between two temporary surfaces). The scratch key is set at resource c
reation time and |
| 33 * should never change. Resources need not have a scratch key. | 34 * should never change. Resources need not have a scratch key. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 /** Will not return any resources that match but have pending IO. */ | 123 /** Will not return any resources that match but have pending IO. */ |
| 123 kRequireNoPendingIO_ScratchFlag = 0x2, | 124 kRequireNoPendingIO_ScratchFlag = 0x2, |
| 124 }; | 125 }; |
| 125 | 126 |
| 126 /** | 127 /** |
| 127 * Find a resource that matches a scratch key. | 128 * Find a resource that matches a scratch key. |
| 128 */ | 129 */ |
| 129 GrGpuResource* findAndRefScratchResource(const GrScratchKey& scratchKey, | 130 GrGpuResource* findAndRefScratchResource(const GrScratchKey& scratchKey, |
| 130 size_t resourceSize, | 131 size_t resourceSize, |
| 131 uint32_t flags); | 132 uint32_t flags); |
| 132 | 133 |
| 133 #ifdef SK_DEBUG | 134 #ifdef SK_DEBUG |
| 134 // This is not particularly fast and only used for validation, so debug only
. | 135 // This is not particularly fast and only used for validation, so debug only
. |
| 135 int countScratchEntriesForKey(const GrScratchKey& scratchKey) const { | 136 int countScratchEntriesForKey(const GrScratchKey& scratchKey) const { |
| 136 return fScratchMap.countForKey(scratchKey); | 137 return fScratchMap.countForKey(scratchKey); |
| 137 } | 138 } |
| 138 #endif | 139 #endif |
| 139 | 140 |
| 140 /** | 141 /** |
| 141 * Find a resource that matches a unique key. | 142 * Find a resource that matches a unique key. |
| 142 */ | 143 */ |
| (...skipping 27 matching lines...) Expand all Loading... |
| 170 | 171 |
| 171 /** | 172 /** |
| 172 * Set the callback the cache should use when it is still over budget after
a purge. The 'data' | 173 * Set the callback the cache should use when it is still over budget after
a purge. The 'data' |
| 173 * provided here will be passed back to the callback. Note that the cache wi
ll attempt to purge | 174 * provided here will be passed back to the callback. Note that the cache wi
ll attempt to purge |
| 174 * any resources newly freed by the callback. | 175 * any resources newly freed by the callback. |
| 175 */ | 176 */ |
| 176 void setOverBudgetCallback(PFOverBudgetCB overBudgetCB, void* data) { | 177 void setOverBudgetCallback(PFOverBudgetCB overBudgetCB, void* data) { |
| 177 fOverBudgetCB = overBudgetCB; | 178 fOverBudgetCB = overBudgetCB; |
| 178 fOverBudgetData = data; | 179 fOverBudgetData = data; |
| 179 } | 180 } |
| 180 | 181 |
| 181 void notifyFlushOccurred(); | 182 void notifyFlushOccurred(); |
| 182 | 183 |
| 183 #if GR_GPU_STATS | 184 #if GR_GPU_STATS |
| 184 void dumpStats(SkString*) const; | 185 void dumpStats(SkString*) const; |
| 185 #endif | 186 #endif |
| 186 | 187 |
| 187 // This function is for unit testing and is only defined in test tools. | 188 // This function is for unit testing and is only defined in test tools. |
| 188 void changeTimestamp(uint32_t newTimestamp); | 189 void changeTimestamp(uint32_t newTimestamp); |
| 189 | 190 |
| 191 /** Enumerates all cached resources and dumps their details to traceMemoryDu
mp. */ |
| 192 void onMemoryDump(SkTraceMemoryDump* traceMemoryDump) const; |
| 193 |
| 190 private: | 194 private: |
| 191 /////////////////////////////////////////////////////////////////////////// | 195 /////////////////////////////////////////////////////////////////////////// |
| 192 /// @name Methods accessible via ResourceAccess | 196 /// @name Methods accessible via ResourceAccess |
| 193 //// | 197 //// |
| 194 void insertResource(GrGpuResource*); | 198 void insertResource(GrGpuResource*); |
| 195 void removeResource(GrGpuResource*); | 199 void removeResource(GrGpuResource*); |
| 196 void notifyCntReachedZero(GrGpuResource*, uint32_t flags); | 200 void notifyCntReachedZero(GrGpuResource*, uint32_t flags); |
| 197 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize); | 201 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize); |
| 198 void changeUniqueKey(GrGpuResource*, const GrUniqueKey&); | 202 void changeUniqueKey(GrGpuResource*, const GrUniqueKey&); |
| 199 void removeUniqueKey(GrGpuResource*); | 203 void removeUniqueKey(GrGpuResource*); |
| 200 void willRemoveScratchKey(const GrGpuResource*); | 204 void willRemoveScratchKey(const GrGpuResource*); |
| 201 void didChangeBudgetStatus(GrGpuResource*); | 205 void didChangeBudgetStatus(GrGpuResource*); |
| 202 void refAndMakeResourceMRU(GrGpuResource*); | 206 void refAndMakeResourceMRU(GrGpuResource*); |
| 203 /// @} | 207 /// @} |
| 204 | 208 |
| 205 void resetFlushTimestamps(); | 209 void resetFlushTimestamps(); |
| 206 void processInvalidUniqueKeys(const SkTArray<GrUniqueKeyInvalidatedMessage>&
); | 210 void processInvalidUniqueKeys(const SkTArray<GrUniqueKeyInvalidatedMessage>&
); |
| 207 void addToNonpurgeableArray(GrGpuResource*); | 211 void addToNonpurgeableArray(GrGpuResource*); |
| 208 void removeFromNonpurgeableArray(GrGpuResource*); | 212 void removeFromNonpurgeableArray(GrGpuResource*); |
| 209 bool overBudget() const { return fBudgetedBytes > fMaxBytes || fBudgetedCoun
t > fMaxCount; } | 213 bool overBudget() const { return fBudgetedBytes > fMaxBytes || fBudgetedCoun
t > fMaxCount; } |
| 210 | 214 |
| 211 bool wouldFit(size_t bytes) { | 215 bool wouldFit(size_t bytes) { |
| 212 return fBudgetedBytes+bytes <= fMaxBytes && fBudgetedCount+1 <= fMaxCoun
t; | 216 return fBudgetedBytes+bytes <= fMaxBytes && fBudgetedCount+1 <= fMaxCoun
t; |
| 213 } | 217 } |
| 214 | 218 |
| 215 uint32_t getNextTimestamp(); | 219 uint32_t getNextTimestamp(); |
| 216 | 220 |
| 217 #ifdef SK_DEBUG | 221 #ifdef SK_DEBUG |
| 218 bool isInCache(const GrGpuResource* r) const; | 222 bool isInCache(const GrGpuResource* r) const; |
| 219 void validate() const; | 223 void validate() const; |
| 220 #else | 224 #else |
| 221 void validate() const {} | 225 void validate() const {} |
| 222 #endif | 226 #endif |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 | 381 |
| 378 friend class GrGpuResource; // To access all the proxy inline methods. | 382 friend class GrGpuResource; // To access all the proxy inline methods. |
| 379 friend class GrResourceCache; // To create this type. | 383 friend class GrResourceCache; // To create this type. |
| 380 }; | 384 }; |
| 381 | 385 |
| 382 inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() { | 386 inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() { |
| 383 return ResourceAccess(this); | 387 return ResourceAccess(this); |
| 384 } | 388 } |
| 385 | 389 |
| 386 #endif | 390 #endif |
| OLD | NEW |