aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-18 17:12:57 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-18 17:12:57 +0000
commit41d2532931a2e85b56ae112047d57927cb09ef6f (patch)
tree3247c8b04f9f19cbabdeb9f1e24e6b1ce581fbc4
parent1622a6d950a4a1deb13048210bdb78d952375f05 (diff)
The rest of: Add purgeAsNeeded calls before addResource calls
-rw-r--r--src/gpu/GrResourceCache.cpp18
-rw-r--r--src/gpu/GrResourceCache.h8
2 files changed, 18 insertions, 8 deletions
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index baae6bd31c..9dab021c60 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -276,28 +276,33 @@ void GrResourceCache::makeNonExclusive(GrResourceEntry* entry) {
* 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 @@ void GrResourceCache::internalPurge() {
while (NULL != entry) {
GrAutoResourceCacheValidate atcv(this);
- if (fEntryCount <= fMaxCount && fEntryBytes <= fMaxBytes) {
+ if ((fEntryCount+extraCount) <= fMaxCount &&
+ (fEntryBytes+extraBytes) <= fMaxBytes) {
withinBudget = true;
break;
}
diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h
index debd064443..b27219eafc 100644
--- a/src/gpu/GrResourceCache.h
+++ b/src/gpu/GrResourceCache.h
@@ -326,8 +326,12 @@ public:
* Allow cache to purge unused resources to obey resource limitations
* Note: this entry point will be hidden (again) once totally ref-driven
* cache maintenance is implemented
+ *
+ * extraCount and extraBytes are added to the current resource allocation
+ * to make sure enough room is available for future additions (e.g,
+ * 10MB across 10 textures is about to be added).
*/
- void purgeAsNeeded();
+ void purgeAsNeeded(int extraCount = 0, size_t extraBytes = 0);
#if GR_DEBUG
void validate() const;
@@ -384,7 +388,7 @@ private:
PFOverbudgetCB fOverbudgetCB;
void* fOverbudgetData;
- void internalPurge();
+ void internalPurge(int extraCount, size_t extraBytes);
#if GR_DEBUG
static size_t countBytes(const SkTInternalLList<GrResourceEntry>& list);