Lines Matching refs:resource
133 void GrResourceCache::insertResource(GrGpuResource* resource) { in insertResource() argument
135 SkASSERT(resource); in insertResource()
136 SkASSERT(!this->isInCache(resource)); in insertResource()
137 SkASSERT(!resource->wasDestroyed()); in insertResource()
138 SkASSERT(!resource->resourcePriv().isPurgeable()); in insertResource()
142 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in insertResource()
144 this->addToNonpurgeableArray(resource); in insertResource()
146 size_t size = resource->gpuMemorySize(); in insertResource()
153 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in insertResource()
163 SkASSERT(!resource->cacheAccess().isUsableAsScratch()); in insertResource()
167 void GrResourceCache::removeResource(GrGpuResource* resource) { in removeResource() argument
170 SkASSERT(this->isInCache(resource)); in removeResource()
172 size_t size = resource->gpuMemorySize(); in removeResource()
173 if (resource->resourcePriv().isPurgeable()) { in removeResource()
174 fPurgeableQueue.remove(resource); in removeResource()
177 this->removeFromNonpurgeableArray(resource); in removeResource()
182 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in removeResource()
189 if (resource->cacheAccess().isUsableAsScratch()) { in removeResource()
190 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in removeResource()
192 if (resource->getUniqueKey().isValid()) { in removeResource()
193 fUniqueHash.remove(resource->getUniqueKey()); in removeResource()
271 void GrResourceCache::refResource(GrGpuResource* resource) { in refResource() argument
272 SkASSERT(resource); in refResource()
273 SkASSERT(resource->getContext()->priv().getResourceCache() == this); in refResource()
274 if (resource->cacheAccess().hasRef()) { in refResource()
275 resource->ref(); in refResource()
277 this->refAndMakeResourceMRU(resource); in refResource()
286 bool operator()(const GrGpuResource* resource) const { in operator ()()
296 GrGpuResource* resource = fScratchMap.find(scratchKey, AvailableForScratchUse()); in findAndRefScratchResource() local
297 if (resource) { in findAndRefScratchResource()
298 fScratchMap.remove(scratchKey, resource); in findAndRefScratchResource()
299 this->refAndMakeResourceMRU(resource); in findAndRefScratchResource()
302 return resource; in findAndRefScratchResource()
305 void GrResourceCache::willRemoveScratchKey(const GrGpuResource* resource) { in willRemoveScratchKey() argument
307 SkASSERT(resource->resourcePriv().getScratchKey().isValid()); in willRemoveScratchKey()
308 if (resource->cacheAccess().isUsableAsScratch()) { in willRemoveScratchKey()
309 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in willRemoveScratchKey()
313 void GrResourceCache::removeUniqueKey(GrGpuResource* resource) { in removeUniqueKey() argument
317 if (resource->getUniqueKey().isValid()) { in removeUniqueKey()
318 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey())); in removeUniqueKey()
319 fUniqueHash.remove(resource->getUniqueKey()); in removeUniqueKey()
321 resource->cacheAccess().removeUniqueKey(); in removeUniqueKey()
322 if (resource->cacheAccess().isUsableAsScratch()) { in removeUniqueKey()
323 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in removeUniqueKey()
329 SkASSERT(!resource->resourcePriv().isPurgeable()); in removeUniqueKey()
333 void GrResourceCache::changeUniqueKey(GrGpuResource* resource, const GrUniqueKey& newKey) { in changeUniqueKey() argument
335 SkASSERT(resource); in changeUniqueKey()
336 SkASSERT(this->isInCache(resource)); in changeUniqueKey()
353 if (resource->getUniqueKey().isValid()) { in changeUniqueKey()
354 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey())); in changeUniqueKey()
355 fUniqueHash.remove(resource->getUniqueKey()); in changeUniqueKey()
356 SkASSERT(nullptr == fUniqueHash.find(resource->getUniqueKey())); in changeUniqueKey()
361 if (resource->cacheAccess().isUsableAsScratch()) { in changeUniqueKey()
362 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in changeUniqueKey()
366 resource->cacheAccess().setUniqueKey(newKey); in changeUniqueKey()
367 fUniqueHash.add(resource); in changeUniqueKey()
369 this->removeUniqueKey(resource); in changeUniqueKey()
375 void GrResourceCache::refAndMakeResourceMRU(GrGpuResource* resource) { in refAndMakeResourceMRU() argument
377 SkASSERT(resource); in refAndMakeResourceMRU()
378 SkASSERT(this->isInCache(resource)); in refAndMakeResourceMRU()
380 if (resource->resourcePriv().isPurgeable()) { in refAndMakeResourceMRU()
382 fPurgeableBytes -= resource->gpuMemorySize(); in refAndMakeResourceMRU()
383 fPurgeableQueue.remove(resource); in refAndMakeResourceMRU()
384 this->addToNonpurgeableArray(resource); in refAndMakeResourceMRU()
385 } else if (!resource->cacheAccess().hasRefOrCommandBufferUsage() && in refAndMakeResourceMRU()
386 resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { in refAndMakeResourceMRU()
390 resource->cacheAccess().ref(); in refAndMakeResourceMRU()
392 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in refAndMakeResourceMRU()
396 void GrResourceCache::notifyARefCntReachedZero(GrGpuResource* resource, in notifyARefCntReachedZero() argument
399 SkASSERT(resource); in notifyARefCntReachedZero()
400 SkASSERT(!resource->wasDestroyed()); in notifyARefCntReachedZero()
401 SkASSERT(this->isInCache(resource)); in notifyARefCntReachedZero()
404 SkASSERT(fNonpurgeableResources[*resource->cacheAccess().accessCacheIndex()] == resource); in notifyARefCntReachedZero()
407 if (resource->cacheAccess().isUsableAsScratch()) { in notifyARefCntReachedZero()
408 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in notifyARefCntReachedZero()
412 if (resource->cacheAccess().hasRefOrCommandBufferUsage()) { in notifyARefCntReachedZero()
421 if (resource->resourcePriv().isPurgeable()) { in notifyARefCntReachedZero()
422 fNewlyPurgeableResourceForValidation = resource; in notifyARefCntReachedZero()
425 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in notifyARefCntReachedZero()
428 if (!resource->resourcePriv().isPurgeable() && in notifyARefCntReachedZero()
429 resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { in notifyARefCntReachedZero()
433 if (!resource->resourcePriv().isPurgeable()) { in notifyARefCntReachedZero()
438 this->removeFromNonpurgeableArray(resource); in notifyARefCntReachedZero()
439 fPurgeableQueue.insert(resource); in notifyARefCntReachedZero()
440 resource->cacheAccess().setTimeWhenResourceBecomePurgeable(); in notifyARefCntReachedZero()
441 fPurgeableBytes += resource->gpuMemorySize(); in notifyARefCntReachedZero()
443 bool hasUniqueKey = resource->getUniqueKey().isValid(); in notifyARefCntReachedZero()
445 GrBudgetedType budgetedType = resource->resourcePriv().budgetedType(); in notifyARefCntReachedZero()
450 bool hasKey = resource->resourcePriv().getScratchKey().isValid() || hasUniqueKey; in notifyARefCntReachedZero()
461 if (!resource->resourcePriv().refsWrappedObjects() && in notifyARefCntReachedZero()
462 resource->resourcePriv().getScratchKey().isValid()) { in notifyARefCntReachedZero()
464 if (this->wouldFit(resource->gpuMemorySize())) { in notifyARefCntReachedZero()
465 resource->resourcePriv().makeBudgeted(); in notifyARefCntReachedZero()
472 resource->cacheAccess().release(); in notifyARefCntReachedZero()
478 void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) { in didChangeBudgetStatus() argument
480 SkASSERT(resource); in didChangeBudgetStatus()
481 SkASSERT(this->isInCache(resource)); in didChangeBudgetStatus()
483 size_t size = resource->gpuMemorySize(); in didChangeBudgetStatus()
488 SkDEBUGCODE(bool wasPurgeable = resource->resourcePriv().isPurgeable()); in didChangeBudgetStatus()
489 if (resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { in didChangeBudgetStatus()
496 if (!resource->resourcePriv().isPurgeable() && in didChangeBudgetStatus()
497 !resource->cacheAccess().hasRefOrCommandBufferUsage()) { in didChangeBudgetStatus()
500 if (resource->cacheAccess().isUsableAsScratch()) { in didChangeBudgetStatus()
501 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in didChangeBudgetStatus()
505 SkASSERT(resource->resourcePriv().budgetedType() != GrBudgetedType::kUnbudgetedCacheable); in didChangeBudgetStatus()
508 if (!resource->resourcePriv().isPurgeable() && in didChangeBudgetStatus()
509 !resource->cacheAccess().hasRefOrCommandBufferUsage()) { in didChangeBudgetStatus()
512 if (!resource->cacheAccess().hasRef() && !resource->getUniqueKey().isValid() && in didChangeBudgetStatus()
513 resource->resourcePriv().getScratchKey().isValid()) { in didChangeBudgetStatus()
514 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in didChangeBudgetStatus()
517 SkASSERT(wasPurgeable == resource->resourcePriv().isPurgeable()); in didChangeBudgetStatus()
547 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeAsNeeded() local
548 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeAsNeeded()
549 resource->cacheAccess().release(); in purgeAsNeeded()
557 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeAsNeeded() local
558 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeAsNeeded()
559 resource->cacheAccess().release(); in purgeAsNeeded()
580 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeUnlockedResources() local
583 resource->cacheAccess().timeWhenResourceBecamePurgeable(); in purgeUnlockedResources()
593 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
594 resource->cacheAccess().release(); in purgeUnlockedResources()
610 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeUnlockedResources() local
613 resource->cacheAccess().timeWhenResourceBecamePurgeable(); in purgeUnlockedResources()
618 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
619 if (!resource->getUniqueKey().isValid()) { in purgeUnlockedResources()
620 *scratchResources.append() = resource; in purgeUnlockedResources()
647 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeToMakeHeadroom() local
648 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in purgeToMakeHeadroom()
649 projectedBudget -= resource->gpuMemorySize(); in purgeToMakeHeadroom()
667 for (GrGpuResource* resource : resources) { in purgeToMakeHeadroom()
668 resource->cacheAccess().release(); in purgeToMakeHeadroom()
686 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeUnlockedResources() local
687 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
688 if (!resource->getUniqueKey().isValid()) { in purgeUnlockedResources()
689 *scratchResources.append() = resource; in purgeUnlockedResources()
690 scratchByteCount += resource->gpuMemorySize(); in purgeUnlockedResources()
751 void GrResourceCache::addToNonpurgeableArray(GrGpuResource* resource) { in addToNonpurgeableArray() argument
753 *fNonpurgeableResources.append() = resource; in addToNonpurgeableArray()
754 *resource->cacheAccess().accessCacheIndex() = index; in addToNonpurgeableArray()
757 void GrResourceCache::removeFromNonpurgeableArray(GrGpuResource* resource) { in removeFromNonpurgeableArray() argument
758 int* index = resource->cacheAccess().accessCacheIndex(); in removeFromNonpurgeableArray()
762 SkASSERT(fNonpurgeableResources[*index] == resource); in removeFromNonpurgeableArray()
915 void update(GrGpuResource* resource) { in validate()
916 fBytes += resource->gpuMemorySize(); in validate()
918 if (!resource->resourcePriv().isPurgeable()) { in validate()
922 const GrScratchKey& scratchKey = resource->resourcePriv().getScratchKey(); in validate()
923 const GrUniqueKey& uniqueKey = resource->getUniqueKey(); in validate()
925 if (resource->cacheAccess().isUsableAsScratch()) { in validate()
927 SkASSERT(GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()); in validate()
928 SkASSERT(!resource->cacheAccess().hasRef()); in validate()
931 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); in validate()
933 SkASSERT(GrBudgetedType::kBudgeted != resource->resourcePriv().budgetedType() || in validate()
934 uniqueKey.isValid() || resource->cacheAccess().hasRef()); in validate()
935 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); in validate()
936 SkASSERT(!fScratchMap->has(resource, scratchKey)); in validate()
940 SkASSERT(fUniqueHash->find(uniqueKey) == resource); in validate()
941 SkASSERT(GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType() || in validate()
942 resource->resourcePriv().refsWrappedObjects()); in validate()
945 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in validate()
947 fBudgetedBytes += resource->gpuMemorySize(); in validate()
954 fScratchMap.foreach([&](const GrGpuResource& resource) { in validate() argument
955 SkASSERT(resource.cacheAccess().isUsableAsScratch()); in validate()
1011 bool GrResourceCache::isInCache(const GrGpuResource* resource) const { in isInCache()
1012 int index = *resource->cacheAccess().accessCacheIndex(); in isInCache()
1016 if (index < fPurgeableQueue.count() && fPurgeableQueue.at(index) == resource) { in isInCache()
1019 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index] == resource) { in isInCache()