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

Unified Diff: src/gpu/GrResourceCache.cpp

Issue 19591003: Add purgeAsNeeded calls before addResource calls (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: added extraCount & extraSize to account for future memory requirements Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrResourceCache.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrResourceCache.cpp
===================================================================
--- src/gpu/GrResourceCache.cpp (revision 10123)
+++ src/gpu/GrResourceCache.cpp (working copy)
@@ -276,28 +276,33 @@
* resource's destructor inserting new resources into the cache. If these
* new resources were unlocked before purgeAsNeeded completed it could
* potentially make purgeAsNeeded loop infinitely.
+ *
+ * extraCount and extraBytes are added to the current resource totals to account
+ * for incoming resources (e.g., GrContext is about to add 10MB split between
+ * 10 textures).
*/
-void GrResourceCache::purgeAsNeeded() {
+void GrResourceCache::purgeAsNeeded(int extraCount, size_t extraBytes) {
if (fPurging) {
return;
}
fPurging = true;
- this->internalPurge();
- if ((fEntryCount > fMaxCount || fEntryBytes > fMaxBytes) &&
+ this->internalPurge(extraCount, extraBytes);
+ if (((fEntryCount+extraCount) > fMaxCount ||
+ (fEntryBytes+extraBytes) > fMaxBytes) &&
NULL != fOverbudgetCB) {
// Despite the purge we're still over budget. See if Ganesh can
// release some resources and purge again.
if ((*fOverbudgetCB)(fOverbudgetData)) {
- this->internalPurge();
+ this->internalPurge(extraCount, extraBytes);
}
}
fPurging = false;
}
-void GrResourceCache::internalPurge() {
+void GrResourceCache::internalPurge(int extraCount, size_t extraBytes) {
SkASSERT(fPurging);
bool withinBudget = false;
@@ -319,7 +324,8 @@
while (NULL != entry) {
GrAutoResourceCacheValidate atcv(this);
- if (fEntryCount <= fMaxCount && fEntryBytes <= fMaxBytes) {
+ if ((fEntryCount+extraCount) <= fMaxCount &&
+ (fEntryBytes+extraBytes) <= fMaxBytes) {
withinBudget = true;
break;
}
« no previous file with comments | « src/gpu/GrResourceCache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698