Lines Matching refs:resource
108 void GrResourceCache::insertResource(GrGpuResource* resource) { in insertResource() argument
110 SkASSERT(resource); in insertResource()
111 SkASSERT(!this->isInCache(resource)); in insertResource()
112 SkASSERT(!resource->wasDestroyed()); in insertResource()
113 SkASSERT(!resource->resourcePriv().isPurgeable()); in insertResource()
117 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in insertResource()
119 this->addToNonpurgeableArray(resource); in insertResource()
121 size_t size = resource->gpuMemorySize(); in insertResource()
128 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in insertResource()
138 if (resource->resourcePriv().getScratchKey().isValid() && in insertResource()
139 !resource->getUniqueKey().isValid()) { in insertResource()
140 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); in insertResource()
141 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in insertResource()
147 void GrResourceCache::removeResource(GrGpuResource* resource) { in removeResource() argument
150 SkASSERT(this->isInCache(resource)); in removeResource()
152 size_t size = resource->gpuMemorySize(); in removeResource()
153 if (resource->resourcePriv().isPurgeable()) { in removeResource()
154 fPurgeableQueue.remove(resource); in removeResource()
157 this->removeFromNonpurgeableArray(resource); in removeResource()
162 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in removeResource()
169 if (resource->resourcePriv().getScratchKey().isValid() && in removeResource()
170 !resource->getUniqueKey().isValid()) { in removeResource()
171 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in removeResource()
173 if (resource->getUniqueKey().isValid()) { in removeResource()
174 fUniqueHash.remove(resource->getUniqueKey()); in removeResource()
254 bool operator()(const GrGpuResource* resource) const { in operator ()()
255 SkASSERT(!resource->getUniqueKey().isValid() && in operator ()()
256 resource->resourcePriv().getScratchKey().isValid()); in operator ()()
257 if (resource->internalHasRef() || !resource->cacheAccess().isScratch()) { in operator ()()
260 return !fRejectPendingIO || !resource->internalHasPendingIO(); in operator ()()
272 GrGpuResource* resource; in findAndRefScratchResource() local
274 resource = fScratchMap.find(scratchKey, AvailableForScratchUse(true)); in findAndRefScratchResource()
275 if (resource) { in findAndRefScratchResource()
276 this->refAndMakeResourceMRU(resource); in findAndRefScratchResource()
278 return resource; in findAndRefScratchResource()
291 resource = fScratchMap.find(scratchKey, AvailableForScratchUse(false)); in findAndRefScratchResource()
292 if (resource) { in findAndRefScratchResource()
293 this->refAndMakeResourceMRU(resource); in findAndRefScratchResource()
296 return resource; in findAndRefScratchResource()
299 void GrResourceCache::willRemoveScratchKey(const GrGpuResource* resource) { in willRemoveScratchKey() argument
301 SkASSERT(resource->resourcePriv().getScratchKey().isValid()); in willRemoveScratchKey()
302 if (!resource->getUniqueKey().isValid()) { in willRemoveScratchKey()
303 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in willRemoveScratchKey()
307 void GrResourceCache::removeUniqueKey(GrGpuResource* resource) { in removeUniqueKey() argument
311 if (resource->getUniqueKey().isValid()) { in removeUniqueKey()
312 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey())); in removeUniqueKey()
313 fUniqueHash.remove(resource->getUniqueKey()); in removeUniqueKey()
315 resource->cacheAccess().removeUniqueKey(); in removeUniqueKey()
316 if (resource->resourcePriv().getScratchKey().isValid()) { in removeUniqueKey()
317 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in removeUniqueKey()
323 SkASSERT(!resource->resourcePriv().isPurgeable()); in removeUniqueKey()
327 void GrResourceCache::changeUniqueKey(GrGpuResource* resource, const GrUniqueKey& newKey) { in changeUniqueKey() argument
329 SkASSERT(resource); in changeUniqueKey()
330 SkASSERT(this->isInCache(resource)); in changeUniqueKey()
347 if (resource->getUniqueKey().isValid()) { in changeUniqueKey()
348 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey())); in changeUniqueKey()
349 fUniqueHash.remove(resource->getUniqueKey()); in changeUniqueKey()
350 SkASSERT(nullptr == fUniqueHash.find(resource->getUniqueKey())); in changeUniqueKey()
354 if (resource->resourcePriv().getScratchKey().isValid()) { in changeUniqueKey()
355 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in changeUniqueKey()
359 resource->cacheAccess().setUniqueKey(newKey); in changeUniqueKey()
360 fUniqueHash.add(resource); in changeUniqueKey()
362 this->removeUniqueKey(resource); in changeUniqueKey()
368 void GrResourceCache::refAndMakeResourceMRU(GrGpuResource* resource) { in refAndMakeResourceMRU() argument
370 SkASSERT(resource); in refAndMakeResourceMRU()
371 SkASSERT(this->isInCache(resource)); in refAndMakeResourceMRU()
373 if (resource->resourcePriv().isPurgeable()) { in refAndMakeResourceMRU()
375 fPurgeableBytes -= resource->gpuMemorySize(); in refAndMakeResourceMRU()
376 fPurgeableQueue.remove(resource); in refAndMakeResourceMRU()
377 this->addToNonpurgeableArray(resource); in refAndMakeResourceMRU()
379 resource->ref(); in refAndMakeResourceMRU()
381 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in refAndMakeResourceMRU()
385 void GrResourceCache::notifyCntReachedZero(GrGpuResource* resource, uint32_t flags) { in notifyCntReachedZero() argument
387 SkASSERT(resource); in notifyCntReachedZero()
388 SkASSERT(!resource->wasDestroyed()); in notifyCntReachedZero()
390 SkASSERT(this->isInCache(resource)); in notifyCntReachedZero()
393 SkASSERT(fNonpurgeableResources[*resource->cacheAccess().accessCacheIndex()] == resource); in notifyCntReachedZero()
400 if (resource->resourcePriv().isPurgeable()) { in notifyCntReachedZero()
401 fNewlyPurgeableResourceForValidation = resource; in notifyCntReachedZero()
404 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in notifyCntReachedZero()
409 SkASSERT(!resource->resourcePriv().isPurgeable()); in notifyCntReachedZero()
413 if (!resource->resourcePriv().isPurgeable()) { in notifyCntReachedZero()
418 this->removeFromNonpurgeableArray(resource); in notifyCntReachedZero()
419 fPurgeableQueue.insert(resource); in notifyCntReachedZero()
420 resource->cacheAccess().setTimeWhenResourceBecomePurgeable(); in notifyCntReachedZero()
421 fPurgeableBytes += resource->gpuMemorySize(); in notifyCntReachedZero()
423 bool hasUniqueKey = resource->getUniqueKey().isValid(); in notifyCntReachedZero()
425 GrBudgetedType budgetedType = resource->resourcePriv().budgetedType(); in notifyCntReachedZero()
430 bool hasKey = resource->resourcePriv().getScratchKey().isValid() || hasUniqueKey; in notifyCntReachedZero()
441 if (!resource->resourcePriv().refsWrappedObjects() && in notifyCntReachedZero()
442 resource->resourcePriv().getScratchKey().isValid()) { in notifyCntReachedZero()
445 fBudgetedBytes + resource->gpuMemorySize() <= fMaxBytes) { in notifyCntReachedZero()
446 resource->resourcePriv().makeBudgeted(); in notifyCntReachedZero()
453 resource->cacheAccess().release(); in notifyCntReachedZero()
459 void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) { in didChangeBudgetStatus() argument
461 SkASSERT(resource); in didChangeBudgetStatus()
462 SkASSERT(this->isInCache(resource)); in didChangeBudgetStatus()
464 size_t size = resource->gpuMemorySize(); in didChangeBudgetStatus()
469 SkDEBUGCODE(bool wasPurgeable = resource->resourcePriv().isPurgeable()); in didChangeBudgetStatus()
470 if (resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { in didChangeBudgetStatus()
479 SkASSERT(resource->resourcePriv().budgetedType() != GrBudgetedType::kUnbudgetedCacheable); in didChangeBudgetStatus()
483 SkASSERT(wasPurgeable == resource->resourcePriv().isPurgeable()); in didChangeBudgetStatus()
507 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeAsNeeded() local
508 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeAsNeeded()
509 resource->cacheAccess().release(); in purgeAsNeeded()
521 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeUnlockedResources() local
522 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
523 resource->cacheAccess().release(); in purgeUnlockedResources()
532 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeUnlockedResources() local
533 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
534 if (!resource->getUniqueKey().isValid()) { in purgeUnlockedResources()
535 *scratchResources.append() = resource; in purgeUnlockedResources()
561 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeResourcesNotUsedSince() local
562 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeResourcesNotUsedSince()
563 resource->cacheAccess().release(); in purgeResourcesNotUsedSince()
580 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeUnlockedResources() local
581 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
582 if (!resource->getUniqueKey().isValid()) { in purgeUnlockedResources()
583 *scratchResources.append() = resource; in purgeUnlockedResources()
584 scratchByteCount += resource->gpuMemorySize(); in purgeUnlockedResources()
608 void GrResourceCache::insertCrossContextGpuResource(GrGpuResource* resource) { in insertCrossContextGpuResource() argument
609 resource->ref(); in insertCrossContextGpuResource()
610 SkASSERT(!fResourcesWaitingForFreeMsg.contains(resource)); in insertCrossContextGpuResource()
611 fResourcesWaitingForFreeMsg.push_back(resource); in insertCrossContextGpuResource()
631 void GrResourceCache::addToNonpurgeableArray(GrGpuResource* resource) { in addToNonpurgeableArray() argument
633 *fNonpurgeableResources.append() = resource; in addToNonpurgeableArray()
634 *resource->cacheAccess().accessCacheIndex() = index; in addToNonpurgeableArray()
637 void GrResourceCache::removeFromNonpurgeableArray(GrGpuResource* resource) { in removeFromNonpurgeableArray() argument
638 int* index = resource->cacheAccess().accessCacheIndex(); in removeFromNonpurgeableArray()
642 SkASSERT(fNonpurgeableResources[*index] == resource); in removeFromNonpurgeableArray()
746 void update(GrGpuResource* resource) { in validate()
747 fBytes += resource->gpuMemorySize(); in validate()
749 if (!resource->resourcePriv().isPurgeable()) { in validate()
753 const GrScratchKey& scratchKey = resource->resourcePriv().getScratchKey(); in validate()
754 const GrUniqueKey& uniqueKey = resource->getUniqueKey(); in validate()
756 if (resource->cacheAccess().isScratch()) { in validate()
760 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); in validate()
762 SkASSERT(GrBudgetedType::kBudgeted != resource->resourcePriv().budgetedType() || in validate()
768 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); in validate()
772 SkASSERT(fUniqueHash->find(uniqueKey) == resource); in validate()
773 SkASSERT(GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType() || in validate()
774 resource->resourcePriv().refsWrappedObjects()); in validate()
777 SkASSERT(!fScratchMap->has(resource, scratchKey)); in validate()
781 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in validate()
783 fBudgetedBytes += resource->gpuMemorySize(); in validate()
793 const GrGpuResource* resource = *iter; in validate() local
794 SkASSERT(resource->resourcePriv().getScratchKey().isValid()); in validate()
795 SkASSERT(!resource->getUniqueKey().isValid()); in validate()
843 bool GrResourceCache::isInCache(const GrGpuResource* resource) const { in isInCache()
844 int index = *resource->cacheAccess().accessCacheIndex(); in isInCache()
848 if (index < fPurgeableQueue.count() && fPurgeableQueue.at(index) == resource) { in isInCache()
851 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index] == resource) { in isInCache()