Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: src/gpu/GrResourceCache.h

Issue 932863004: Use an array of nonpurgeable resources in GrResourceCache (Closed) Base URL: https://skia.googlesource.com/skia.git@queue
Patch Set: add assert back Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 ResourceAccess resourceAccess(); 48 ResourceAccess resourceAccess();
49 49
50 /** 50 /**
51 * Sets the cache limits in terms of number of resources and max gpu memory byte size. 51 * Sets the cache limits in terms of number of resources and max gpu memory byte size.
52 */ 52 */
53 void setLimits(int count, size_t bytes); 53 void setLimits(int count, size_t bytes);
54 54
55 /** 55 /**
56 * Returns the number of resources. 56 * Returns the number of resources.
57 */ 57 */
58 int getResourceCount() const { return fCount; } 58 int getResourceCount() const {
59 return fPurgeableQueue.count() + fNonpurgeableResources.count();
60 }
59 61
60 /** 62 /**
61 * Returns the number of resources that count against the budget. 63 * Returns the number of resources that count against the budget.
62 */ 64 */
63 int getBudgetedResourceCount() const { return fBudgetedCount; } 65 int getBudgetedResourceCount() const { return fBudgetedCount; }
64 66
65 /** 67 /**
66 * Returns the number of bytes consumed by resources. 68 * Returns the number of bytes consumed by resources.
67 */ 69 */
68 size_t getResourceBytes() const { return fBytes; } 70 size_t getResourceBytes() const { return fBytes; }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize); 180 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize);
179 bool didSetContentKey(GrGpuResource*); 181 bool didSetContentKey(GrGpuResource*);
180 void willRemoveScratchKey(const GrGpuResource*); 182 void willRemoveScratchKey(const GrGpuResource*);
181 void willRemoveContentKey(const GrGpuResource*); 183 void willRemoveContentKey(const GrGpuResource*);
182 void didChangeBudgetStatus(GrGpuResource*); 184 void didChangeBudgetStatus(GrGpuResource*);
183 void refAndMakeResourceMRU(GrGpuResource*); 185 void refAndMakeResourceMRU(GrGpuResource*);
184 /// @} 186 /// @}
185 187
186 void internalPurgeAsNeeded(); 188 void internalPurgeAsNeeded();
187 void processInvalidContentKeys(const SkTArray<GrContentKeyInvalidatedMessage >&); 189 void processInvalidContentKeys(const SkTArray<GrContentKeyInvalidatedMessage >&);
190 void addToNonpurgeableArray(GrGpuResource*);
191 void removeFromNonpurgeableArray(GrGpuResource*);
robertphillips 2015/02/17 18:32:23 <= for underBudget ?
bsalomon 2015/02/17 19:32:51 I made it < since this is used to check if there i
192 bool underBudget() const { return fBudgetedBytes < fMaxBytes && fBudgetedCou nt < fMaxCount; }
193 bool overBudget() const { return fBudgetedBytes > fMaxBytes || fBudgetedCoun t > fMaxCount; }
188 194
189 #ifdef SK_DEBUG 195 #ifdef SK_DEBUG
190 bool isInCache(const GrGpuResource* r) const { return fResources.isInList(r) ; } 196 bool isInCache(const GrGpuResource* r) const;
191 void validate() const; 197 void validate() const;
192 #else 198 #else
193 void validate() const {} 199 void validate() const {}
194 #endif 200 #endif
195 201
196 class AutoValidate; 202 class AutoValidate;
197 203
198 class AvailableForScratchUse; 204 class AvailableForScratchUse;
199 205
200 struct ScratchMapTraits { 206 struct ScratchMapTraits {
201 static const GrScratchKey& GetKey(const GrGpuResource& r) { 207 static const GrScratchKey& GetKey(const GrGpuResource& r) {
202 return r.resourcePriv().getScratchKey(); 208 return r.resourcePriv().getScratchKey();
203 } 209 }
204 210
205 static uint32_t Hash(const GrScratchKey& key) { return key.hash(); } 211 static uint32_t Hash(const GrScratchKey& key) { return key.hash(); }
206 }; 212 };
207 typedef SkTMultiMap<GrGpuResource, GrScratchKey, ScratchMapTraits> ScratchMa p; 213 typedef SkTMultiMap<GrGpuResource, GrScratchKey, ScratchMapTraits> ScratchMa p;
208 214
209 struct ContentHashTraits { 215 struct ContentHashTraits {
210 static const GrContentKey& GetKey(const GrGpuResource& r) { 216 static const GrContentKey& GetKey(const GrGpuResource& r) {
211 return r.getContentKey(); 217 return r.getContentKey();
212 } 218 }
213 219
214 static uint32_t Hash(const GrContentKey& key) { return key.hash(); } 220 static uint32_t Hash(const GrContentKey& key) { return key.hash(); }
215 }; 221 };
216 typedef SkTDynamicHash<GrGpuResource, GrContentKey, ContentHashTraits> Conte ntHash; 222 typedef SkTDynamicHash<GrGpuResource, GrContentKey, ContentHashTraits> Conte ntHash;
217 223
218 typedef SkTInternalLList<GrGpuResource> ResourceList;
219
220 static bool CompareTimestamp(GrGpuResource* const& a, GrGpuResource* const& b) { 224 static bool CompareTimestamp(GrGpuResource* const& a, GrGpuResource* const& b) {
221 return a->cacheAccess().timestamp() < b->cacheAccess().timestamp(); 225 return a->cacheAccess().timestamp() < b->cacheAccess().timestamp();
222 } 226 }
223 227
224 static int* AccessResourceIndex(GrGpuResource* const& res) { 228 static int* AccessResourceIndex(GrGpuResource* const& res) {
225 return res->cacheAccess().accessCacheIndex(); 229 return res->cacheAccess().accessCacheIndex();
226 } 230 }
227 231
228 typedef SkMessageBus<GrContentKeyInvalidatedMessage>::Inbox InvalidContentKe yInbox; 232 typedef SkMessageBus<GrContentKeyInvalidatedMessage>::Inbox InvalidContentKe yInbox;
229 typedef SkTDPQueue<GrGpuResource*, CompareTimestamp, AccessResourceIndex> Pu rgeableQueue; 233 typedef SkTDPQueue<GrGpuResource*, CompareTimestamp, AccessResourceIndex> Pu rgeableQueue;
234 typedef SkTDArray<GrGpuResource*> ResourceArray;
230 235
231 uint32_t fTimestamp; 236 uint32_t fTimestamp;
232 PurgeableQueue fPurgeableQueue; 237 PurgeableQueue fPurgeableQueue;
233 238 ResourceArray fNonpurgeableResources;
234 // TODO: Replace this with an array of nonpurgeable resources
235 ResourceList fResources;
236 239
237 // This map holds all resources that can be used as scratch resources. 240 // This map holds all resources that can be used as scratch resources.
238 ScratchMap fScratchMap; 241 ScratchMap fScratchMap;
239 // This holds all resources that have content keys. 242 // This holds all resources that have content keys.
240 ContentHash fContentHash; 243 ContentHash fContentHash;
241 244
242 // our budget, used in purgeAsNeeded() 245 // our budget, used in purgeAsNeeded()
243 int fMaxCount; 246 int fMaxCount;
244 size_t fMaxBytes; 247 size_t fMaxBytes;
245 248
246 #if GR_CACHE_STATS 249 #if GR_CACHE_STATS
247 int fHighWaterCount; 250 int fHighWaterCount;
248 size_t fHighWaterBytes; 251 size_t fHighWaterBytes;
249 int fBudgetedHighWaterCount; 252 int fBudgetedHighWaterCount;
250 size_t fBudgetedHighWaterBytes; 253 size_t fBudgetedHighWaterBytes;
251 #endif 254 #endif
252 255
253 // our current stats for all resources 256 // our current stats for all resources
254 int fCount; 257 SkDEBUGCODE(int fCount;)
255 size_t fBytes; 258 size_t fBytes;
256 259
257 // our current stats for resources that count against the budget 260 // our current stats for resources that count against the budget
258 int fBudgetedCount; 261 int fBudgetedCount;
259 size_t fBudgetedBytes; 262 size_t fBudgetedBytes;
260 263
261 PFOverBudgetCB fOverBudgetCB; 264 PFOverBudgetCB fOverBudgetCB;
262 void* fOverBudgetData; 265 void* fOverBudgetData;
263 266
264 InvalidContentKeyInbox fInvalidContentKeyInbox; 267 InvalidContentKeyInbox fInvalidContentKeyInbox;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 332
330 friend class GrGpuResource; // To access all the proxy inline methods. 333 friend class GrGpuResource; // To access all the proxy inline methods.
331 friend class GrResourceCache; // To create this type. 334 friend class GrResourceCache; // To create this type.
332 }; 335 };
333 336
334 inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() { 337 inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() {
335 return ResourceAccess(this); 338 return ResourceAccess(this);
336 } 339 }
337 340
338 #endif 341 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698