Lines Matching refs:resource

102 void GrResourceCache::insertResource(GrGpuResource* resource) {
103 SkASSERT(resource);
104 SkASSERT(!this->isInCache(resource));
105 SkASSERT(!resource->wasDestroyed());
106 SkASSERT(!resource->isPurgeable());
110 resource->cacheAccess().setTimestamp(this->getNextTimestamp());
112 this->addToNonpurgeableArray(resource);
114 size_t size = resource->gpuMemorySize();
121 if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) {
131 if (resource->resourcePriv().getScratchKey().isValid() &&
132 !resource->getUniqueKey().isValid()) {
133 SkASSERT(!resource->resourcePriv().refsWrappedObjects());
134 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource);
140 void GrResourceCache::removeResource(GrGpuResource* resource) {
142 SkASSERT(this->isInCache(resource));
144 size_t size = resource->gpuMemorySize();
145 if (resource->isPurgeable()) {
146 fPurgeableQueue.remove(resource);
149 this->removeFromNonpurgeableArray(resource);
154 if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) {
161 if (resource->resourcePriv().getScratchKey().isValid() &&
162 !resource->getUniqueKey().isValid()) {
163 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource);
165 if (resource->getUniqueKey().isValid()) {
166 fUniqueHash.remove(resource->getUniqueKey());
232 bool operator()(const GrGpuResource* resource) const {
233 SkASSERT(!resource->getUniqueKey().isValid() &&
234 resource->resourcePriv().getScratchKey().isValid());
235 if (resource->internalHasRef() || !resource->cacheAccess().isScratch()) {
238 return !fRejectPendingIO || !resource->internalHasPendingIO();
250 GrGpuResource* resource;
252 resource = fScratchMap.find(scratchKey, AvailableForScratchUse(true));
253 if (resource) {
254 this->refAndMakeResourceMRU(resource);
256 return resource;
263 // kPrefer is specified, we didn't find a resource without pending io,
264 // but there is still space in our budget for the resource so force
265 // the caller to allocate a new resource.
269 resource = fScratchMap.find(scratchKey, AvailableForScratchUse(false));
270 if (resource) {
271 this->refAndMakeResourceMRU(resource);
274 return resource;
277 void GrResourceCache::willRemoveScratchKey(const GrGpuResource* resource) {
278 SkASSERT(resource->resourcePriv().getScratchKey().isValid());
279 if (!resource->getUniqueKey().isValid()) {
280 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource);
284 void GrResourceCache::removeUniqueKey(GrGpuResource* resource) {
285 // Someone has a ref to this resource in order to have removed the key. When the ref count
287 if (resource->getUniqueKey().isValid()) {
288 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey()));
289 fUniqueHash.remove(resource->getUniqueKey());
291 resource->cacheAccess().removeUniqueKey();
293 if (resource->resourcePriv().getScratchKey().isValid()) {
294 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource);
300 void GrResourceCache::changeUniqueKey(GrGpuResource* resource, const GrUniqueKey& newKey) {
301 SkASSERT(resource);
302 SkASSERT(this->isInCache(resource));
304 // If another resource has the new key, remove its key then install the key on this resource.
307 // If the old resource using the key is purgeable and is unreachable, then remove it.
316 // Remove the entry for this resource if it already has a unique key.
317 if (resource->getUniqueKey().isValid()) {
318 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey()));
319 fUniqueHash.remove(resource->getUniqueKey());
320 SkASSERT(nullptr == fUniqueHash.find(resource->getUniqueKey()));
322 // 'resource' didn't have a valid unique key before so it is switching sides. Remove it
324 if (resource->resourcePriv().getScratchKey().isValid()) {
325 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource);
329 resource->cacheAccess().setUniqueKey(newKey);
330 fUniqueHash.add(resource);
332 this->removeUniqueKey(resource);
338 void GrResourceCache::refAndMakeResourceMRU(GrGpuResource* resource) {
339 SkASSERT(resource);
340 SkASSERT(this->isInCache(resource));
342 if (resource->isPurgeable()) {
344 fPurgeableBytes -= resource->gpuMemorySize();
345 fPurgeableQueue.remove(resource);
346 this->addToNonpurgeableArray(resource);
348 resource->ref();
350 resource->cacheAccess().setTimestamp(this->getNextTimestamp());
354 void GrResourceCache::notifyCntReachedZero(GrGpuResource* resource, uint32_t flags) {
355 SkASSERT(resource);
356 SkASSERT(!resource->wasDestroyed());
358 SkASSERT(this->isInCache(resource));
359 // This resource should always be in the nonpurgeable array when this function is called. It
361 SkASSERT(fNonpurgeableResources[*resource->cacheAccess().accessCacheIndex()] == resource);
368 if (resource->isPurgeable()) {
369 fNewlyPurgeableResourceForValidation = resource;
372 resource->cacheAccess().setTimestamp(this->getNextTimestamp());
377 SkASSERT(!resource->isPurgeable());
381 SkASSERT(resource->isPurgeable());
382 this->removeFromNonpurgeableArray(resource);
383 fPurgeableQueue.insert(resource);
384 resource->cacheAccess().setFlushCntWhenResourceBecamePurgeable(fExternalFlushCnt);
385 resource->cacheAccess().setTimeWhenResourceBecomePurgeable();
386 fPurgeableBytes += resource->gpuMemorySize();
388 if (SkBudgeted::kNo == resource->resourcePriv().isBudgeted()) {
389 // Check whether this resource could still be used as a scratch resource.
390 if (!resource->resourcePriv().refsWrappedObjects() &&
391 resource->resourcePriv().getScratchKey().isValid()) {
392 // We won't purge an existing resource to make room for this one.
394 fBudgetedBytes + resource->gpuMemorySize() <= fMaxBytes) {
395 resource->resourcePriv().makeBudgeted();
400 // Purge the resource immediately if we're over budget
401 // Also purge if the resource has neither a valid scratch key nor a unique key.
402 bool noKey = !resource->resourcePriv().getScratchKey().isValid() &&
403 !resource->getUniqueKey().isValid();
410 resource->cacheAccess().release();
411 // We should at least free this resource, perhaps dependent resources as well.
416 void GrResourceCache::didChangeGpuMemorySize(const GrGpuResource* resource, size_t oldSize) {
418 SkASSERT(resource);
419 SkASSERT(this->isInCache(resource));
421 ptrdiff_t delta = resource->gpuMemorySize() - oldSize;
427 if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) {
440 void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) {
441 SkASSERT(resource);
442 SkASSERT(this->isInCache(resource));
444 size_t size = resource->gpuMemorySize();
446 if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) {
474 // We want to know how many complete flushes have occurred without the resource being used.
475 // If the resource was tagged when fExternalFlushCnt was N then this means it became
487 // resource is made non-purgeable again. So, at this point all the remaining
492 GrGpuResource* resource = fPurgeableQueue.peek();
493 SkASSERT(resource->isPurgeable());
494 resource->cacheAccess().release();
501 GrGpuResource* resource = fPurgeableQueue.peek();
502 SkASSERT(resource->isPurgeable());
503 resource->cacheAccess().release();
521 GrGpuResource* resource = fPurgeableQueue.peek();
522 SkASSERT(resource->isPurgeable());
523 resource->cacheAccess().release();
532 GrGpuResource* resource = fPurgeableQueue.at(i);
533 SkASSERT(resource->isPurgeable());
534 if (!resource->getUniqueKey().isValid()) {
535 *scratchResources.append() = resource;
556 // resource is made non-purgeable again. So, at this point all the remaining
561 GrGpuResource* resource = fPurgeableQueue.peek();
562 SkASSERT(resource->isPurgeable());
563 resource->cacheAccess().release();
580 GrGpuResource* resource = fPurgeableQueue.at(i);
581 SkASSERT(resource->isPurgeable());
582 if (!resource->getUniqueKey().isValid()) {
583 *scratchResources.append() = resource;
584 scratchByteCount += resource->gpuMemorySize();
615 GrGpuResource* resource = this->findAndRefUniqueResource(msgs[i].key());
616 if (resource) {
617 resource->resourcePriv().removeUniqueKey();
618 resource->unref(); // If this resource is now purgeable, the cache will be notified.
623 void GrResourceCache::insertCrossContextGpuResource(GrGpuResource* resource) {
624 resource->ref();
637 void GrResourceCache::addToNonpurgeableArray(GrGpuResource* resource) {
639 *fNonpurgeableResources.append() = resource;
640 *resource->cacheAccess().accessCacheIndex() = index;
643 void GrResourceCache::removeFromNonpurgeableArray(GrGpuResource* resource) {
644 int* index = resource->cacheAccess().accessCacheIndex();
648 SkASSERT(fNonpurgeableResources[*index] == resource);
687 // Correct the index in the nonpurgeable array stored on the resource post-sort.
747 // Reduce the frequency of validations for large resource counts.
771 void update(GrGpuResource* resource) {
772 fBytes += resource->gpuMemorySize();
774 if (!resource->isPurgeable()) {
778 const GrScratchKey& scratchKey = resource->resourcePriv().getScratchKey();
779 const GrUniqueKey& uniqueKey = resource->getUniqueKey();
781 if (resource->cacheAccess().isScratch()) {
785 SkASSERT(!resource->resourcePriv().refsWrappedObjects());
787 SkASSERT(SkBudgeted::kNo == resource->resourcePriv().isBudgeted() ||
793 SkASSERT(!resource->resourcePriv().refsWrappedObjects());
797 SkASSERT(fUniqueHash->find(uniqueKey) == resource);
798 SkASSERT(SkBudgeted::kYes == resource->resourcePriv().isBudgeted() ||
799 resource->resourcePriv().refsWrappedObjects());
802 SkASSERT(!fScratchMap->has(resource, scratchKey));
806 if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) {
808 fBudgetedBytes += resource->gpuMemorySize();
818 const GrGpuResource* resource = *iter;
819 SkASSERT(resource->resourcePriv().getScratchKey().isValid());
820 SkASSERT(!resource->getUniqueKey().isValid());
868 bool GrResourceCache::isInCache(const GrGpuResource* resource) const {
869 int index = *resource->cacheAccess().accessCacheIndex();
873 if (index < fPurgeableQueue.count() && fPurgeableQueue.at(index) == resource) {
876 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index] == resource) {
879 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the cache.");