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

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

Issue 2307053002: Restructure flushing relationship between GrContext, GrDrawingManager, and GrResourceCache. (Closed)
Patch Set: cleanup Created 4 years, 3 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 * 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 #ifndef GrResourceCache_DEFINED 8 #ifndef GrResourceCache_DEFINED
9 #define GrResourceCache_DEFINED 9 #define GrResourceCache_DEFINED
10 10
11 #include "GrGpuResource.h" 11 #include "GrGpuResource.h"
12 #include "GrGpuResourceCacheAccess.h" 12 #include "GrGpuResourceCacheAccess.h"
13 #include "GrGpuResourcePriv.h" 13 #include "GrGpuResourcePriv.h"
14 #include "GrResourceCache.h"
14 #include "GrResourceKey.h" 15 #include "GrResourceKey.h"
15 #include "SkMessageBus.h" 16 #include "SkMessageBus.h"
16 #include "SkRefCnt.h" 17 #include "SkRefCnt.h"
17 #include "SkTArray.h" 18 #include "SkTArray.h"
18 #include "SkTDPQueue.h" 19 #include "SkTDPQueue.h"
19 #include "SkTInternalLList.h" 20 #include "SkTInternalLList.h"
20 #include "SkTMultiMap.h" 21 #include "SkTMultiMap.h"
21 22
22 class GrCaps; 23 class GrCaps;
23 class SkString; 24 class SkString;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 return SkToBool(fUniqueHash.find(key)); 157 return SkToBool(fUniqueHash.find(key));
157 } 158 }
158 159
159 /** Purges resources to become under budget and processes resources with inv alidated unique 160 /** Purges resources to become under budget and processes resources with inv alidated unique
160 keys. */ 161 keys. */
161 void purgeAsNeeded(); 162 void purgeAsNeeded();
162 163
163 /** Purges all resources that don't have external owners. */ 164 /** Purges all resources that don't have external owners. */
164 void purgeAllUnlocked(); 165 void purgeAllUnlocked();
165 166
166 /** 167 /** Returns true if the cache would like a flush to occur in order to make m ore resources
167 * The callback function used by the cache when it is still over budget afte r a purge. The 168 purgeable. */
168 * passed in 'data' is the same 'data' handed to setOverbudgetCallback. 169 bool requestsFlush() const { return fRequestFlush; }
169 */
170 typedef void (*PFOverBudgetCB)(void* data);
171 170
172 /** 171 enum FlushType {
173 * Set the callback the cache should use when it is still over budget after a purge. The 'data' 172 kExternal,
174 * provided here will be passed back to the callback. Note that the cache wi ll attempt to purge 173 kCacheRequested,
175 * any resources newly freed by the callback. 174 };
176 */ 175 void notifyFlushOccurred(FlushType);
177 void setOverBudgetCallback(PFOverBudgetCB overBudgetCB, void* data) {
178 fOverBudgetCB = overBudgetCB;
179 fOverBudgetData = data;
180 }
181
182 void notifyFlushOccurred();
183 176
184 #if GR_CACHE_STATS 177 #if GR_CACHE_STATS
185 struct Stats { 178 struct Stats {
186 int fTotal; 179 int fTotal;
187 int fNumPurgeable; 180 int fNumPurgeable;
188 int fNumNonPurgeable; 181 int fNumNonPurgeable;
189 182
190 int fScratch; 183 int fScratch;
191 int fWrapped; 184 int fWrapped;
192 size_t fUnbudgetedSize; 185 size_t fUnbudgetedSize;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 #endif 312 #endif
320 313
321 // our current stats for all resources 314 // our current stats for all resources
322 SkDEBUGCODE(int fCount;) 315 SkDEBUGCODE(int fCount;)
323 size_t fBytes; 316 size_t fBytes;
324 317
325 // our current stats for resources that count against the budget 318 // our current stats for resources that count against the budget
326 int fBudgetedCount; 319 int fBudgetedCount;
327 size_t fBudgetedBytes; 320 size_t fBudgetedBytes;
328 321
329 PFOverBudgetCB fOverBudgetCB; 322 bool fRequestFlush;
330 void* fOverBudgetData;
331 323
332 // We keep track of the "timestamps" of the last n flushes. If a resource ha sn't been used in 324 // We keep track of the "timestamps" of the last n flushes. If a resource ha sn't been used in
333 // that time then we well preemptively purge it to reduce memory usage. 325 // that time then we well preemptively purge it to reduce memory usage.
334 uint32_t* fFlushTimestamps; 326 uint32_t* fFlushTimestamps;
335 int fLastFlushTimestampIndex; 327 int fLastFlushTimestampIndex;
336 328
337 InvalidUniqueKeyInbox fInvalidUniqueKeyInbox; 329 InvalidUniqueKeyInbox fInvalidUniqueKeyInbox;
338 330
339 // This resource is allowed to be in the nonpurgeable array for the sake of validate() because 331 // This resource is allowed to be in the nonpurgeable array for the sake of validate() because
340 // we're in the midst of converting it to purgeable status. 332 // we're in the midst of converting it to purgeable status.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 412
421 friend class GrGpuResource; // To access all the proxy inline methods. 413 friend class GrGpuResource; // To access all the proxy inline methods.
422 friend class GrResourceCache; // To create this type. 414 friend class GrResourceCache; // To create this type.
423 }; 415 };
424 416
425 inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() { 417 inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() {
426 return ResourceAccess(this); 418 return ResourceAccess(this);
427 } 419 }
428 420
429 #endif 421 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698