Lines Matching full:resource
40 SK_ABORT("Too many Resource Types"); in GenerateResourceType()
75 inline GrResourceCache::ResourceAwaitingUnref::ResourceAwaitingUnref(GrGpuResource* resource) in ResourceAwaitingUnref() argument
76 : fResource(resource), fNumUnrefs(1) {} in ResourceAwaitingUnref()
146 void GrResourceCache::insertResource(GrGpuResource* resource) { in insertResource() argument
148 SkASSERT(resource); in insertResource()
149 SkASSERT(!this->isInCache(resource)); in insertResource()
150 SkASSERT(!resource->wasDestroyed()); in insertResource()
151 SkASSERT(!resource->resourcePriv().isPurgeable()); in insertResource()
155 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in insertResource()
157 this->addToNonpurgeableArray(resource); in insertResource()
159 size_t size = resource->gpuMemorySize(); in insertResource()
166 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in insertResource()
176 if (resource->resourcePriv().getScratchKey().isValid() && in insertResource()
177 !resource->getUniqueKey().isValid()) { in insertResource()
178 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); in insertResource()
179 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in insertResource()
185 void GrResourceCache::removeResource(GrGpuResource* resource) { in removeResource() argument
188 SkASSERT(this->isInCache(resource)); in removeResource()
190 size_t size = resource->gpuMemorySize(); in removeResource()
191 if (resource->resourcePriv().isPurgeable()) { in removeResource()
192 fPurgeableQueue.remove(resource); in removeResource()
195 this->removeFromNonpurgeableArray(resource); in removeResource()
200 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in removeResource()
207 if (resource->resourcePriv().getScratchKey().isValid() && in removeResource()
208 !resource->getUniqueKey().isValid()) { in removeResource()
209 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in removeResource()
211 if (resource->getUniqueKey().isValid()) { in removeResource()
212 fUniqueHash.remove(resource->getUniqueKey()); in removeResource()
288 bool operator()(const GrGpuResource* resource) const { in operator ()()
289 SkASSERT(!resource->getUniqueKey().isValid() && in operator ()()
290 resource->resourcePriv().getScratchKey().isValid()); in operator ()()
291 if (resource->internalHasRef() || !resource->cacheAccess().isScratch()) { in operator ()()
294 return !fRejectPendingIO || !resource->internalHasPendingIO(); in operator ()()
306 GrGpuResource* resource; in findAndRefScratchResource() local
308 resource = fScratchMap.find(scratchKey, AvailableForScratchUse(true)); in findAndRefScratchResource()
309 if (resource) { in findAndRefScratchResource()
310 this->refAndMakeResourceMRU(resource); in findAndRefScratchResource()
312 return resource; in findAndRefScratchResource()
319 // kPrefer is specified, we didn't find a resource without pending io, in findAndRefScratchResource()
320 // but there is still space in our budget for the resource so force in findAndRefScratchResource()
321 // the caller to allocate a new resource. in findAndRefScratchResource()
325 resource = fScratchMap.find(scratchKey, AvailableForScratchUse(false)); in findAndRefScratchResource()
326 if (resource) { in findAndRefScratchResource()
327 this->refAndMakeResourceMRU(resource); in findAndRefScratchResource()
330 return resource; in findAndRefScratchResource()
333 void GrResourceCache::willRemoveScratchKey(const GrGpuResource* resource) { in willRemoveScratchKey() argument
335 SkASSERT(resource->resourcePriv().getScratchKey().isValid()); in willRemoveScratchKey()
336 if (!resource->getUniqueKey().isValid()) { in willRemoveScratchKey()
337 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in willRemoveScratchKey()
341 void GrResourceCache::removeUniqueKey(GrGpuResource* resource) { in removeUniqueKey() argument
343 // Someone has a ref to this resource in order to have removed the key. When the ref count in removeUniqueKey()
345 if (resource->getUniqueKey().isValid()) { in removeUniqueKey()
346 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey())); in removeUniqueKey()
347 fUniqueHash.remove(resource->getUniqueKey()); in removeUniqueKey()
349 resource->cacheAccess().removeUniqueKey(); in removeUniqueKey()
350 if (resource->resourcePriv().getScratchKey().isValid()) { in removeUniqueKey()
351 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in removeUniqueKey()
354 // Removing a unique key from a kUnbudgetedCacheable resource would make the resource in removeUniqueKey()
355 // require purging. However, the resource must be ref'ed to get here and therefore can't in removeUniqueKey()
357 SkASSERT(!resource->resourcePriv().isPurgeable()); in removeUniqueKey()
361 void GrResourceCache::changeUniqueKey(GrGpuResource* resource, const GrUniqueKey& newKey) { in changeUniqueKey() argument
363 SkASSERT(resource); in changeUniqueKey()
364 SkASSERT(this->isInCache(resource)); in changeUniqueKey()
366 // If another resource has the new key, remove its key then install the key on this resource. in changeUniqueKey()
369 // If the old resource using the key is purgeable and is unreachable, then remove it. in changeUniqueKey()
374 // removeUniqueKey expects an external owner of the resource. in changeUniqueKey()
380 // Remove the entry for this resource if it already has a unique key. in changeUniqueKey()
381 if (resource->getUniqueKey().isValid()) { in changeUniqueKey()
382 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey())); in changeUniqueKey()
383 fUniqueHash.remove(resource->getUniqueKey()); in changeUniqueKey()
384 SkASSERT(nullptr == fUniqueHash.find(resource->getUniqueKey())); in changeUniqueKey()
386 // 'resource' didn't have a valid unique key before so it is switching sides. Remove it in changeUniqueKey()
388 if (resource->resourcePriv().getScratchKey().isValid()) { in changeUniqueKey()
389 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in changeUniqueKey()
393 resource->cacheAccess().setUniqueKey(newKey); in changeUniqueKey()
394 fUniqueHash.add(resource); in changeUniqueKey()
396 this->removeUniqueKey(resource); in changeUniqueKey()
402 void GrResourceCache::refAndMakeResourceMRU(GrGpuResource* resource) { in refAndMakeResourceMRU() argument
404 SkASSERT(resource); in refAndMakeResourceMRU()
405 SkASSERT(this->isInCache(resource)); in refAndMakeResourceMRU()
407 if (resource->resourcePriv().isPurgeable()) { in refAndMakeResourceMRU()
409 fPurgeableBytes -= resource->gpuMemorySize(); in refAndMakeResourceMRU()
410 fPurgeableQueue.remove(resource); in refAndMakeResourceMRU()
411 this->addToNonpurgeableArray(resource); in refAndMakeResourceMRU()
413 resource->ref(); in refAndMakeResourceMRU()
415 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in refAndMakeResourceMRU()
419 void GrResourceCache::notifyCntReachedZero(GrGpuResource* resource, uint32_t flags) { in notifyCntReachedZero() argument
421 SkASSERT(resource); in notifyCntReachedZero()
422 SkASSERT(!resource->wasDestroyed()); in notifyCntReachedZero()
424 SkASSERT(this->isInCache(resource)); in notifyCntReachedZero()
425 // This resource should always be in the nonpurgeable array when this function is called. It in notifyCntReachedZero()
427 SkASSERT(fNonpurgeableResources[*resource->cacheAccess().accessCacheIndex()] == resource); in notifyCntReachedZero()
434 if (resource->resourcePriv().isPurgeable()) { in notifyCntReachedZero()
435 fNewlyPurgeableResourceForValidation = resource; in notifyCntReachedZero()
438 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in notifyCntReachedZero()
443 SkASSERT(!resource->resourcePriv().isPurgeable()); in notifyCntReachedZero()
447 if (!resource->resourcePriv().isPurgeable()) { in notifyCntReachedZero()
452 this->removeFromNonpurgeableArray(resource); in notifyCntReachedZero()
453 fPurgeableQueue.insert(resource); in notifyCntReachedZero()
454 resource->cacheAccess().setTimeWhenResourceBecomePurgeable(); in notifyCntReachedZero()
455 fPurgeableBytes += resource->gpuMemorySize(); in notifyCntReachedZero()
457 bool hasUniqueKey = resource->getUniqueKey().isValid(); in notifyCntReachedZero()
459 GrBudgetedType budgetedType = resource->resourcePriv().budgetedType(); in notifyCntReachedZero()
462 // Purge the resource immediately if we're over budget in notifyCntReachedZero()
463 // Also purge if the resource has neither a valid scratch key nor a unique key. in notifyCntReachedZero()
464 bool hasKey = resource->resourcePriv().getScratchKey().isValid() || hasUniqueKey; in notifyCntReachedZero()
474 // Check whether this resource could still be used as a scratch resource. in notifyCntReachedZero()
475 if (!resource->resourcePriv().refsWrappedObjects() && in notifyCntReachedZero()
476 resource->resourcePriv().getScratchKey().isValid()) { in notifyCntReachedZero()
477 // We won't purge an existing resource to make room for this one. in notifyCntReachedZero()
479 fBudgetedBytes + resource->gpuMemorySize() <= fMaxBytes) { in notifyCntReachedZero()
480 resource->resourcePriv().makeBudgeted(); in notifyCntReachedZero()
487 resource->cacheAccess().release(); in notifyCntReachedZero()
488 // We should at least free this resource, perhaps dependent resources as well. in notifyCntReachedZero()
493 void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) { in didChangeBudgetStatus() argument
495 SkASSERT(resource); in didChangeBudgetStatus()
496 SkASSERT(this->isInCache(resource)); in didChangeBudgetStatus()
498 size_t size = resource->gpuMemorySize(); in didChangeBudgetStatus()
500 // resource become purgeable. However, we should never allow that transition. Wrapped in didChangeBudgetStatus()
503 SkDEBUGCODE(bool wasPurgeable = resource->resourcePriv().isPurgeable()); in didChangeBudgetStatus()
504 if (resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { in didChangeBudgetStatus()
513 SkASSERT(resource->resourcePriv().budgetedType() != GrBudgetedType::kUnbudgetedCacheable); in didChangeBudgetStatus()
517 SkASSERT(wasPurgeable == resource->resourcePriv().isPurgeable()); in didChangeBudgetStatus()
541 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeAsNeeded() local
542 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeAsNeeded()
543 resource->cacheAccess().release(); in purgeAsNeeded()
555 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeUnlockedResources() local
556 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
557 resource->cacheAccess().release(); in purgeUnlockedResources()
566 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeUnlockedResources() local
567 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
568 if (!resource->getUniqueKey().isValid()) { in purgeUnlockedResources()
569 *scratchResources.append() = resource; in purgeUnlockedResources()
590 // resource is made non-purgeable again. So, at this point all the remaining in purgeResourcesNotUsedSince()
595 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeResourcesNotUsedSince() local
596 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeResourcesNotUsedSince()
597 resource->cacheAccess().release(); in purgeResourcesNotUsedSince()
614 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeUnlockedResources() local
615 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
616 if (!resource->getUniqueKey().isValid()) { in purgeUnlockedResources()
617 *scratchResources.append() = resource; in purgeUnlockedResources()
618 scratchByteCount += resource->gpuMemorySize(); in purgeUnlockedResources()
642 void GrResourceCache::insertDelayedResourceUnref(GrGpuResource* resource) { in insertDelayedResourceUnref() argument
643 resource->ref(); in insertDelayedResourceUnref()
644 uint32_t id = resource->uniqueID().asUInt(); in insertDelayedResourceUnref()
648 fResourcesAwaitingUnref.set(id, {resource}); in insertDelayedResourceUnref()
662 // trying to unref the resource twice. in processFreedGpuResources()
672 void GrResourceCache::addToNonpurgeableArray(GrGpuResource* resource) { in addToNonpurgeableArray() argument
674 *fNonpurgeableResources.append() = resource; in addToNonpurgeableArray()
675 *resource->cacheAccess().accessCacheIndex() = index; in addToNonpurgeableArray()
678 void GrResourceCache::removeFromNonpurgeableArray(GrGpuResource* resource) { in removeFromNonpurgeableArray() argument
679 int* index = resource->cacheAccess().accessCacheIndex(); in removeFromNonpurgeableArray()
683 SkASSERT(fNonpurgeableResources[*index] == resource); in removeFromNonpurgeableArray()
722 // Correct the index in the nonpurgeable array stored on the resource post-sort. in getNextTimestamp()
813 // Reduce the frequency of validations for large resource counts. in validate()
837 void update(GrGpuResource* resource) { in validate()
838 fBytes += resource->gpuMemorySize(); in validate()
840 if (!resource->resourcePriv().isPurgeable()) { in validate()
844 const GrScratchKey& scratchKey = resource->resourcePriv().getScratchKey(); in validate()
845 const GrUniqueKey& uniqueKey = resource->getUniqueKey(); in validate()
847 if (resource->cacheAccess().isScratch()) { in validate()
851 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); in validate()
853 SkASSERT(GrBudgetedType::kBudgeted != resource->resourcePriv().budgetedType() || in validate()
859 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); in validate()
863 SkASSERT(fUniqueHash->find(uniqueKey) == resource); in validate()
864 SkASSERT(GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType() || in validate()
865 resource->resourcePriv().refsWrappedObjects()); in validate()
868 SkASSERT(!fScratchMap->has(resource, scratchKey)); in validate()
872 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in validate()
874 fBudgetedBytes += resource->gpuMemorySize(); in validate()
884 const GrGpuResource* resource = *iter; in validate() local
885 SkASSERT(resource->resourcePriv().getScratchKey().isValid()); in validate()
886 SkASSERT(!resource->getUniqueKey().isValid()); in validate()
934 bool GrResourceCache::isInCache(const GrGpuResource* resource) const { in isInCache()
935 int index = *resource->cacheAccess().accessCacheIndex(); in isInCache()
939 if (index < fPurgeableQueue.count() && fPurgeableQueue.at(index) == resource) { in isInCache()
942 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index] == resource) { in isInCache()
945 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the cache."); in isInCache()