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