| 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 | 9 |
| 10 #include "GrResourceCache.h" | 10 #include "GrResourceCache.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 public: | 51 public: |
| 52 AutoValidate(GrResourceCache* cache) : fCache(cache) { cache->validate(); } | 52 AutoValidate(GrResourceCache* cache) : fCache(cache) { cache->validate(); } |
| 53 ~AutoValidate() { fCache->validate(); } | 53 ~AutoValidate() { fCache->validate(); } |
| 54 private: | 54 private: |
| 55 GrResourceCache* fCache; | 55 GrResourceCache* fCache; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 ////////////////////////////////////////////////////////////////////////////// | 58 ////////////////////////////////////////////////////////////////////////////// |
| 59 | 59 |
| 60 | 60 |
| 61 GrResourceCache::GrResourceCache() | 61 GrResourceCache::GrResourceCache(const GrCaps* caps) |
| 62 : fTimestamp(0) | 62 : fTimestamp(0) |
| 63 , fMaxCount(kDefaultMaxCount) | 63 , fMaxCount(kDefaultMaxCount) |
| 64 , fMaxBytes(kDefaultMaxSize) | 64 , fMaxBytes(kDefaultMaxSize) |
| 65 , fMaxUnusedFlushes(kDefaultMaxUnusedFlushes) | 65 , fMaxUnusedFlushes(kDefaultMaxUnusedFlushes) |
| 66 #if GR_CACHE_STATS | 66 #if GR_CACHE_STATS |
| 67 , fHighWaterCount(0) | 67 , fHighWaterCount(0) |
| 68 , fHighWaterBytes(0) | 68 , fHighWaterBytes(0) |
| 69 , fBudgetedHighWaterCount(0) | 69 , fBudgetedHighWaterCount(0) |
| 70 , fBudgetedHighWaterBytes(0) | 70 , fBudgetedHighWaterBytes(0) |
| 71 #endif | 71 #endif |
| 72 , fBytes(0) | 72 , fBytes(0) |
| 73 , fBudgetedCount(0) | 73 , fBudgetedCount(0) |
| 74 , fBudgetedBytes(0) | 74 , fBudgetedBytes(0) |
| 75 , fOverBudgetCB(NULL) | 75 , fOverBudgetCB(NULL) |
| 76 , fOverBudgetData(NULL) | 76 , fOverBudgetData(NULL) |
| 77 , fFlushTimestamps(NULL) | 77 , fFlushTimestamps(NULL) |
| 78 , fLastFlushTimestampIndex(0){ | 78 , fLastFlushTimestampIndex(0) |
| 79 , fPreferVRAMUseOverFlushes(caps->preferVRAMUseOverFlushes()) { |
| 79 SkDEBUGCODE(fCount = 0;) | 80 SkDEBUGCODE(fCount = 0;) |
| 80 SkDEBUGCODE(fNewlyPurgeableResourceForValidation = NULL;) | 81 SkDEBUGCODE(fNewlyPurgeableResourceForValidation = NULL;) |
| 81 this->resetFlushTimestamps(); | 82 this->resetFlushTimestamps(); |
| 82 } | 83 } |
| 83 | 84 |
| 84 GrResourceCache::~GrResourceCache() { | 85 GrResourceCache::~GrResourceCache() { |
| 85 this->releaseAll(); | 86 this->releaseAll(); |
| 86 SkDELETE_ARRAY(fFlushTimestamps); | 87 SkDELETE_ARRAY(fFlushTimestamps); |
| 87 } | 88 } |
| 88 | 89 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 GrGpuResource* resource; | 254 GrGpuResource* resource; |
| 254 if (flags & (kPreferNoPendingIO_ScratchFlag | kRequireNoPendingIO_ScratchFla
g)) { | 255 if (flags & (kPreferNoPendingIO_ScratchFlag | kRequireNoPendingIO_ScratchFla
g)) { |
| 255 resource = fScratchMap.find(scratchKey, AvailableForScratchUse(true)); | 256 resource = fScratchMap.find(scratchKey, AvailableForScratchUse(true)); |
| 256 if (resource) { | 257 if (resource) { |
| 257 this->refAndMakeResourceMRU(resource); | 258 this->refAndMakeResourceMRU(resource); |
| 258 this->validate(); | 259 this->validate(); |
| 259 return resource; | 260 return resource; |
| 260 } else if (flags & kRequireNoPendingIO_ScratchFlag) { | 261 } else if (flags & kRequireNoPendingIO_ScratchFlag) { |
| 261 return NULL; | 262 return NULL; |
| 262 } | 263 } |
| 263 if (this->wouldFit(resourceSize)) { | 264 // We would prefer to consume more available VRAM rather than flushing |
| 265 // immediately, but on ANGLE this can lead to starving of the GPU. |
| 266 if (fPreferVRAMUseOverFlushes && this->wouldFit(resourceSize)) { |
| 264 // kPrefer is specified, we didn't find a resource without pending i
o, | 267 // kPrefer is specified, we didn't find a resource without pending i
o, |
| 265 // but there is still space in our budget for the resource. | 268 // but there is still space in our budget for the resource so force |
| 269 // the caller to allocate a new resource. |
| 266 return NULL; | 270 return NULL; |
| 267 } | 271 } |
| 268 } | 272 } |
| 269 resource = fScratchMap.find(scratchKey, AvailableForScratchUse(false)); | 273 resource = fScratchMap.find(scratchKey, AvailableForScratchUse(false)); |
| 270 if (resource) { | 274 if (resource) { |
| 271 this->refAndMakeResourceMRU(resource); | 275 this->refAndMakeResourceMRU(resource); |
| 272 this->validate(); | 276 this->validate(); |
| 273 } | 277 } |
| 274 return resource; | 278 return resource; |
| 275 } | 279 } |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 return true; | 724 return true; |
| 721 } | 725 } |
| 722 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { | 726 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { |
| 723 return true; | 727 return true; |
| 724 } | 728 } |
| 725 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca
che."); | 729 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca
che."); |
| 726 return false; | 730 return false; |
| 727 } | 731 } |
| 728 | 732 |
| 729 #endif | 733 #endif |
| OLD | NEW |