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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 return false; | 239 return false; |
240 } | 240 } |
241 return !fRejectPendingIO || !resource->internalHasPendingIO(); | 241 return !fRejectPendingIO || !resource->internalHasPendingIO(); |
242 } | 242 } |
243 | 243 |
244 private: | 244 private: |
245 bool fRejectPendingIO; | 245 bool fRejectPendingIO; |
246 }; | 246 }; |
247 | 247 |
248 GrGpuResource* GrResourceCache::findAndRefScratchResource(const GrScratchKey& sc
ratchKey, | 248 GrGpuResource* GrResourceCache::findAndRefScratchResource(const GrScratchKey& sc
ratchKey, |
| 249 size_t resourceSize, |
249 uint32_t flags) { | 250 uint32_t flags) { |
250 SkASSERT(scratchKey.isValid()); | 251 SkASSERT(scratchKey.isValid()); |
251 | 252 |
252 GrGpuResource* resource; | 253 GrGpuResource* resource; |
253 if (flags & (kPreferNoPendingIO_ScratchFlag | kRequireNoPendingIO_ScratchFla
g)) { | 254 if (flags & (kPreferNoPendingIO_ScratchFlag | kRequireNoPendingIO_ScratchFla
g)) { |
254 resource = fScratchMap.find(scratchKey, AvailableForScratchUse(true)); | 255 resource = fScratchMap.find(scratchKey, AvailableForScratchUse(true)); |
255 if (resource) { | 256 if (resource) { |
256 this->refAndMakeResourceMRU(resource); | 257 this->refAndMakeResourceMRU(resource); |
257 this->validate(); | 258 this->validate(); |
258 return resource; | 259 return resource; |
259 } else if (flags & kRequireNoPendingIO_ScratchFlag) { | 260 } else if (flags & kRequireNoPendingIO_ScratchFlag) { |
260 return NULL; | 261 return NULL; |
261 } | 262 } |
262 // TODO: fail here when kPrefer is specified, we didn't find a resource
without pending io, | 263 if (this->wouldFit(resourceSize)) { |
263 // but there is still space in our budget for the resource. | 264 // 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. |
| 266 return NULL; |
| 267 } |
264 } | 268 } |
265 resource = fScratchMap.find(scratchKey, AvailableForScratchUse(false)); | 269 resource = fScratchMap.find(scratchKey, AvailableForScratchUse(false)); |
266 if (resource) { | 270 if (resource) { |
267 this->refAndMakeResourceMRU(resource); | 271 this->refAndMakeResourceMRU(resource); |
268 this->validate(); | 272 this->validate(); |
269 } | 273 } |
270 return resource; | 274 return resource; |
271 } | 275 } |
272 | 276 |
273 void GrResourceCache::willRemoveScratchKey(const GrGpuResource* resource) { | 277 void GrResourceCache::willRemoveScratchKey(const GrGpuResource* resource) { |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 return true; | 720 return true; |
717 } | 721 } |
718 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { | 722 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index]
== resource) { |
719 return true; | 723 return true; |
720 } | 724 } |
721 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca
che."); | 725 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the ca
che."); |
722 return false; | 726 return false; |
723 } | 727 } |
724 | 728 |
725 #endif | 729 #endif |
OLD | NEW |