Lines Matching refs:resource
269 auto resource = fPurgeableQueue.at(i);
270 auto resourceTag = resource->getResourceTag();
272 updatePurgeableWidMap(resource, purgNameInfoWid, purgSizeInfoWid, purgPidInfoWid, purgCountInfoWid);
274 updatePurgeablePidMap(resource, purgNameInfoPid, purgSizeInfoPid, purgCountInfoPid);
276 updatePurgeableFidMap(resource, purgNameInfoFid, purgSizeInfoFid, purgCountInfoFid);
279 purgSizeUnknown += resource->gpuMemorySize();
319 auto resource = fNonpurgeableResources[i];
320 if (resource == nullptr) {
323 auto resourceTag = resource->getResourceTag();
325 updatePurgeableWidMap(resource, noPurgNameInfoWid, noPurgSizeInfoWid, noPurgPidInfoWid, noPurgCountInfoWid);
327 updatePurgeablePidMap(resource, noPurgNameInfoPid, noPurgSizeInfoPid, noPurgCountInfoPid);
329 updatePurgeableFidMap(resource, noPurgNameInfoFid, noPurgSizeInfoFid, noPurgCountInfoFid);
332 noPurgSizeUnknown += resource->gpuMemorySize();
357 auto resource = fPurgeableQueue.at(i);
358 if (resource == nullptr || !resource->isRealAlloc()) {
361 realAllocImageSize += resource->getRealAllocSize();
364 auto resource = fNonpurgeableResources[i];
365 if (resource == nullptr || !resource->isRealAlloc()) {
368 realAllocImageSize += resource->getRealAllocSize();
392 auto resource = fNonpurgeableResources[i];
393 if (resource == nullptr || !resource->isRealAlloc()) {
396 auto resourceTag = resource->getResourceTag();
398 updateRealAllocWidMap(resource, realAllocNameInfoWid, realAllocSizeInfoWid, realAllocPidInfoWid, realAllocCountInfoWid);
400 updateRealAllocPidMap(resource, realAllocNameInfoPid, realAllocSizeInfoPid, realAllocCountInfoPid);
402 updateRealAllocFidMap(resource, realAllocNameInfoFid, realAllocSizeInfoFid, realAllocCountInfoFid);
405 realAllocSizeUnknown += resource->getRealAllocSize();
410 auto resource = fPurgeableQueue.at(i);
411 if (resource == nullptr || !resource->isRealAlloc()) {
414 auto resourceTag = resource->getResourceTag();
416 updateRealAllocWidMap(resource, realAllocNameInfoWid, realAllocSizeInfoWid, realAllocPidInfoWid, realAllocCountInfoWid);
418 updateRealAllocPidMap(resource, realAllocNameInfoPid, realAllocSizeInfoPid, realAllocCountInfoPid);
420 updateRealAllocFidMap(resource, realAllocNameInfoFid, realAllocSizeInfoFid, realAllocCountInfoFid);
423 realAllocSizeUnknown += resource->getRealAllocSize();
457 void GrResourceCache::updatePurgeableWidMap(GrGpuResource* resource,
463 auto resourceTag = resource->getResourceTag();
466 sizeInfoWid[resourceTag.fWid] = it->second + resource->gpuMemorySize();
469 sizeInfoWid[resourceTag.fWid] = resource->gpuMemorySize();
476 void GrResourceCache::updatePurgeablePidMap(GrGpuResource* resource,
481 auto resourceTag = resource->getResourceTag();
484 sizeInfoPid[resourceTag.fPid] = it->second + resource->gpuMemorySize();
487 sizeInfoPid[resourceTag.fPid] = resource->gpuMemorySize();
493 void GrResourceCache::updatePurgeableFidMap(GrGpuResource* resource,
498 auto resourceTag = resource->getResourceTag();
501 sizeInfoFid[resourceTag.fFid] = it->second + resource->gpuMemorySize();
504 sizeInfoFid[resourceTag.fFid] = resource->gpuMemorySize();
510 void GrResourceCache::updateRealAllocWidMap(GrGpuResource* resource,
516 size_t size = resource->getRealAllocSize();
517 auto resourceTag = resource->getResourceTag();
530 void GrResourceCache::updateRealAllocPidMap(GrGpuResource* resource,
535 size_t size = resource->getRealAllocSize();
536 auto resourceTag = resource->getResourceTag();
548 void GrResourceCache::updateRealAllocFidMap(GrGpuResource* resource,
553 size_t size = resource->getRealAllocSize();
554 auto resourceTag = resource->getResourceTag();
625 void GrResourceCache::insertResource(GrGpuResource* resource)
628 SkASSERT(resource);
629 SkASSERT(!this->isInCache(resource));
630 SkASSERT(!resource->wasDestroyed());
631 SkASSERT(!resource->resourcePriv().isPurgeable());
632 if (!resource || this->isInCache(resource) || resource->wasDestroyed() || resource->resourcePriv().isPurgeable()) {
633 SkDebugf("OHOS GrResourceCache::insertResource resource is invalid!!!");
638 resource->cacheAccess().setTimestamp(this->getNextTimestamp());
640 this->addToNonpurgeableArray(resource);
642 size_t size = resource->gpuMemorySize();
647 auto pid = resource->getResourceTag().fPid;
648 if (pid && resource->isRealAlloc()) {
650 pidSize += resource->getRealAllocSize();
655 SkDebugf("OHOS resource overflow! pid[%{public}d], size[%{public}zu]", pid, pidSize);
657 HITRACE_OHOS_NAME_FMT_ALWAYS("OHOS gpu resource overflow: pid(%u), size:(%u)", pid, pidSize);
666 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) {
676 SkASSERT(!resource->cacheAccess().isUsableAsScratch());
696 void GrResourceCache::removeResource(GrGpuResource* resource) {
699 SkASSERT(this->isInCache(resource));
701 size_t size = resource->gpuMemorySize();
702 if (resource->resourcePriv().isPurgeable() && this->isInPurgeableCache(resource)) {
703 fPurgeableQueue.remove(resource);
705 } else if (this->isInNonpurgeableCache(resource)) {
706 this->removeFromNonpurgeableArray(resource);
713 auto pid = resource->getResourceTag().fPid;
714 if (pid && resource->isRealAlloc()) {
716 pidSize -= resource->getRealAllocSize();
723 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) {
730 if (resource->cacheAccess().isUsableAsScratch()) {
731 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource);
733 if (resource->getUniqueKey().isValid()) {
734 fUniqueHash.remove(resource->getUniqueKey());
818 GrGpuResource* resource = fNonpurgeableResources[i];
819 if (tag.filter(resource->getResourceTag())) {
820 recycleVector.emplace_back(resource);
821 if (resource->getUniqueKey().isValid()) {
822 fProxyProvider->processInvalidUniqueKey(resource->getUniqueKey(), nullptr,
829 GrGpuResource* resource = fPurgeableQueue.at(i);
830 if (tag.filter(resource->getResourceTag())) {
831 recycleVector.emplace_back(resource);
832 if (resource->getUniqueKey().isValid()) {
833 fProxyProvider->processInvalidUniqueKey(resource->getUniqueKey(), nullptr,
839 for (auto resource : recycleVector) {
840 SkASSERT(!resource->wasDestroyed());
841 resource->cacheAccess().release();
899 // OH ISSUE: change the fbyte when the resource tag changes.
917 void GrResourceCache::refResource(GrGpuResource* resource) {
918 SkASSERT(resource);
919 SkASSERT(resource->getContext()->priv().getResourceCache() == this);
920 if (resource->cacheAccess().hasRef()) {
921 resource->ref();
923 this->refAndMakeResourceMRU(resource);
932 bool operator()(const GrGpuResource* resource) const {
934 // scratch resource.
942 GrGpuResource* resource = fScratchMap.find(scratchKey, AvailableForScratchUse());
943 if (resource) {
944 fScratchMap.remove(scratchKey, resource);
945 if (!this->isInCache(resource)) {
949 this->refAndMakeResourceMRU(resource);
952 return resource;
955 void GrResourceCache::willRemoveScratchKey(const GrGpuResource* resource) {
957 SkASSERT(resource->resourcePriv().getScratchKey().isValid());
958 if (resource->cacheAccess().isUsableAsScratch()) {
959 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource);
963 void GrResourceCache::removeUniqueKey(GrGpuResource* resource) {
965 // Someone has a ref to this resource in order to have removed the key. When the ref count
967 if (resource->getUniqueKey().isValid()) {
968 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey()));
969 fUniqueHash.remove(resource->getUniqueKey());
971 resource->cacheAccess().removeUniqueKey();
972 if (resource->cacheAccess().isUsableAsScratch()) {
973 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource);
976 // Removing a unique key from a kUnbudgetedCacheable resource would make the resource
977 // require purging. However, the resource must be ref'ed to get here and therefore can't
979 SkASSERT(!resource->resourcePriv().isPurgeable());
983 void GrResourceCache::changeUniqueKey(GrGpuResource* resource, const GrUniqueKey& newKey) {
985 SkASSERT(resource);
986 SkASSERT(this->isInCache(resource));
988 // If another resource has the new key, remove its key then install the key on this resource.
991 // If the old resource using the key is purgeable and is unreachable, then remove it.
996 // removeUniqueKey expects an external owner of the resource.
1002 // Remove the entry for this resource if it already has a unique key.
1003 if (resource->getUniqueKey().isValid()) {
1004 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey()));
1005 fUniqueHash.remove(resource->getUniqueKey());
1006 SkASSERT(nullptr == fUniqueHash.find(resource->getUniqueKey()));
1008 // 'resource' didn't have a valid unique key before so it is switching sides. Remove it
1011 if (resource->cacheAccess().isUsableAsScratch()) {
1012 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource);
1016 resource->cacheAccess().setUniqueKey(newKey);
1017 fUniqueHash.add(resource);
1019 this->removeUniqueKey(resource);
1025 void GrResourceCache::refAndMakeResourceMRU(GrGpuResource* resource) {
1027 SkASSERT(resource);
1028 SkASSERT(this->isInCache(resource));
1030 if (resource->resourcePriv().isPurgeable()) {
1032 if (this->isInPurgeableCache(resource)) {
1033 fPurgeableBytes -= resource->gpuMemorySize();
1034 fPurgeableQueue.remove(resource);
1036 if (!this->isInNonpurgeableCache(resource)) {
1037 this->addToNonpurgeableArray(resource);
1039 SkDebugf("OHOS resource in isInNonpurgeableCache, do not add again!");
1041 } else if (!resource->cacheAccess().hasRefOrCommandBufferUsage() &&
1042 resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) {
1046 resource->cacheAccess().ref();
1048 resource->cacheAccess().setTimestamp(this->getNextTimestamp());
1052 void GrResourceCache::notifyARefCntReachedZero(GrGpuResource* resource,
1055 SkASSERT(resource);
1056 SkASSERT(!resource->wasDestroyed());
1057 SkASSERT(this->isInCache(resource));
1058 // This resource should always be in the nonpurgeable array when this function is called. It
1060 SkASSERT(fNonpurgeableResources[*resource->cacheAccess().accessCacheIndex()] == resource);
1061 if (!resource || resource->wasDestroyed() || this->isInPurgeableCache(resource) ||
1062 !this->isInNonpurgeableCache(resource)) {
1067 if (resource->cacheAccess().isUsableAsScratch()) {
1068 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource);
1072 if (resource->cacheAccess().hasRefOrCommandBufferUsage()) {
1081 if (resource->resourcePriv().isPurgeable()) {
1082 fNewlyPurgeableResourceForValidation = resource;
1085 resource->cacheAccess().setTimestamp(this->getNextTimestamp());
1088 if (!resource->resourcePriv().isPurgeable() &&
1089 resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) {
1093 if (!resource->resourcePriv().isPurgeable()) {
1098 this->removeFromNonpurgeableArray(resource);
1099 fPurgeableQueue.insert(resource);
1100 resource->cacheAccess().setTimeWhenResourceBecomePurgeable();
1101 fPurgeableBytes += resource->gpuMemorySize();
1103 bool hasUniqueKey = resource->getUniqueKey().isValid();
1105 GrBudgetedType budgetedType = resource->resourcePriv().budgetedType();
1108 // Purge the resource immediately if we're over budget
1109 // Also purge if the resource has neither a valid scratch key nor a unique key.
1110 bool hasKey = resource->resourcePriv().getScratchKey().isValid() || hasUniqueKey;
1120 // Check whether this resource could still be used as a scratch resource.
1121 if (!resource->resourcePriv().refsWrappedObjects() &&
1122 resource->resourcePriv().getScratchKey().isValid()) {
1123 // We won't purge an existing resource to make room for this one.
1124 if (this->wouldFit(resource->gpuMemorySize())) {
1125 resource->resourcePriv().makeBudgeted();
1132 resource->cacheAccess().release();
1133 // We should at least free this resource, perhaps dependent resources as well.
1138 void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) {
1140 SkASSERT(resource);
1141 SkASSERT(this->isInCache(resource));
1143 size_t size = resource->gpuMemorySize();
1145 // resource become purgeable. However, we should never allow that transition. Wrapped
1148 SkDEBUGCODE(bool wasPurgeable = resource->resourcePriv().isPurgeable());
1149 if (resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) {
1156 if (!resource->resourcePriv().isPurgeable() &&
1157 !resource->cacheAccess().hasRefOrCommandBufferUsage()) {
1160 if (resource->cacheAccess().isUsableAsScratch()) {
1161 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource);
1165 SkASSERT(resource->resourcePriv().budgetedType() != GrBudgetedType::kUnbudgetedCacheable);
1168 if (!resource->resourcePriv().isPurgeable() &&
1169 !resource->cacheAccess().hasRefOrCommandBufferUsage()) {
1172 if (!resource->cacheAccess().hasRef() && !resource->getUniqueKey().isValid() &&
1173 resource->resourcePriv().getScratchKey().isValid()) {
1174 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource);
1177 SkASSERT(wasPurgeable == resource->resourcePriv().isPurgeable());
1240 GrGpuResource* resource = fPurgeableQueue.peek();
1241 if (!resource->resourcePriv().isPurgeable()) {
1242 SkDebugf("OHOS GrResourceCache::purgeAsNeeded() resource is nonPurgeable");
1245 SkASSERT(resource->resourcePriv().isPurgeable());
1246 resource->cacheAccess().release();
1255 GrGpuResource* resource = fPurgeableQueue.peek();
1256 if (!resource->resourcePriv().isPurgeable()) {
1257 SkDebugf("OHOS GrResourceCache::purgeAsNeeded() resource is nonPurgeable after dropUniqueRefs");
1260 SkASSERT(resource->resourcePriv().isPurgeable());
1261 resource->cacheAccess().release();
1285 GrGpuResource* resource = fPurgeableQueue.peek();
1288 resource->cacheAccess().timeWhenResourceBecamePurgeable();
1292 // resource is made non-purgeable again. So, at this point all the remaining
1298 SkASSERT(resource->resourcePriv().isPurgeable());
1299 resource->cacheAccess().release();
1318 GrGpuResource* resource = fPurgeableQueue.at(i);
1321 resource->cacheAccess().timeWhenResourceBecamePurgeable();
1326 SkASSERT(resource->resourcePriv().isPurgeable());
1327 if (!resource->getUniqueKey().isValid()) {
1328 *scratchResources.append() = resource;
1357 GrGpuResource* resource = fPurgeableQueue.at(i);
1358 if (!resource) {
1361 SkASSERT(resource->resourcePriv().isPurgeable());
1362 if (!resource->getUniqueKey().isValid()) {
1363 *scratchResources.append() = resource;
1367 //Delete the scatch resource. This must be done as a separate pass
1392 GrGpuResource* resource = fPurgeableQueue.at(i);
1393 SkASSERT(resource->resourcePriv().isPurgeable());
1394 if (exitedPidSet.find(resource->getResourceTag().fPid) != exitedPidSet.end()) {
1395 resource->cacheAccess().release();
1412 GrGpuResource* resource = fPurgeableQueue.at(i);
1413 SkASSERT(resource->resourcePriv().isPurgeable());
1414 if (protectedPidSet.find(resource->getResourceTag().fPid) == protectedPidSet.end()
1415 && (!scratchResourcesOnly || !resource->getUniqueKey().isValid())) {
1416 resource->cacheAccess().release();
1437 GrGpuResource* resource = fPurgeableQueue.at(i);
1438 if (!resource) {
1441 SkASSERT(resource->resourcePriv().isPurgeable());
1442 if (exitedPidSet.count(resource->getResourceTag().fPid)) {
1443 *exitPidResources.append() = resource;
1444 } else if (!resource->getUniqueKey().isValid()) {
1445 *scratchResources.append() = resource;
1449 //Delete the exited pid and scatch resource. This must be done as a separate pass
1475 GrGpuResource* resource = fPurgeableQueue.at(i);
1476 SkASSERT(resource->resourcePriv().isPurgeable());
1477 if (tag.filter(resource->getResourceTag()) && (!scratchResourcesOnly || !resource->getUniqueKey().isValid())) {
1478 *scratchResources.append() = resource;
1482 //Delete the scatch resource. This must be done as a separate pass
1504 GrGpuResource* resource = fPurgeableQueue.at(i);
1505 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) {
1506 projectedBudget -= resource->gpuMemorySize();
1524 for (GrGpuResource* resource : resources) {
1525 resource->cacheAccess().release();
1543 GrGpuResource* resource = fPurgeableQueue.at(i);
1544 SkASSERT(resource->resourcePriv().isPurgeable());
1545 if (!resource->getUniqueKey().isValid()) {
1546 *scratchResources.append() = resource;
1547 scratchByteCount += resource->gpuMemorySize();
1608 void GrResourceCache::addToNonpurgeableArray(GrGpuResource* resource) {
1610 *fNonpurgeableResources.append() = resource;
1611 *resource->cacheAccess().accessCacheIndex() = index;
1614 void GrResourceCache::removeFromNonpurgeableArray(GrGpuResource* resource) {
1615 int* index = resource->cacheAccess().accessCacheIndex();
1619 SkASSERT(fNonpurgeableResources[*index] == resource);
1658 // Correct the index in the nonpurgeable array stored on the resource post-sort.
1697 auto resource = resources.getAt(i);
1698 if (!resource || resource->wasDestroyed()) {
1701 resource->dumpMemoryStatistics(traceMemoryDump);
1768 // Reduce the frequency of validations for large resource counts.
1792 void update(GrGpuResource* resource) {
1793 fBytes += resource->gpuMemorySize();
1795 if (!resource->resourcePriv().isPurgeable()) {
1799 const GrScratchKey& scratchKey = resource->resourcePriv().getScratchKey();
1800 const GrUniqueKey& uniqueKey = resource->getUniqueKey();
1802 if (resource->cacheAccess().isUsableAsScratch()) {
1804 SkASSERT(GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType());
1805 SkASSERT(!resource->cacheAccess().hasRef());
1808 SkASSERT(!resource->resourcePriv().refsWrappedObjects());
1810 SkASSERT(GrBudgetedType::kBudgeted != resource->resourcePriv().budgetedType() ||
1811 uniqueKey.isValid() || resource->cacheAccess().hasRef());
1812 SkASSERT(!resource->resourcePriv().refsWrappedObjects());
1813 SkASSERT(!fScratchMap->has(resource, scratchKey));
1817 SkASSERT(fUniqueHash->find(uniqueKey) == resource);
1818 SkASSERT(GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType() ||
1819 resource->resourcePriv().refsWrappedObjects());
1822 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) {
1824 fBudgetedBytes += resource->gpuMemorySize();
1831 fScratchMap.foreach([&](const GrGpuResource& resource) {
1832 SkASSERT(resource.cacheAccess().isUsableAsScratch());
1889 bool GrResourceCache::isInCache(const GrGpuResource* resource) const {
1890 int index = *resource->cacheAccess().accessCacheIndex();
1894 if (index < fPurgeableQueue.count() && fPurgeableQueue.at(index) == resource) {
1897 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index] == resource) {
1900 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the cache.");
1904 bool GrResourceCache::isInPurgeableCache(const GrGpuResource* resource) const {
1905 int index = *resource->cacheAccess().accessCacheIndex();
1909 if (index < fPurgeableQueue.count() && fPurgeableQueue.at(index) == resource) {
1912 SkDEBUGFAIL("OHOS Resource index should be -1 or the resource should be in the cache.");
1916 bool GrResourceCache::isInNonpurgeableCache(const GrGpuResource* resource) const {
1917 int index = *resource->cacheAccess().accessCacheIndex();
1921 if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index] == resource) {
1924 SkDEBUGFAIL("OHOS Resource index should be -1 or the resource should be in the cache.");
1932 fUniqueHash.foreach([&](const GrGpuResource& resource){
1933 if (0 == strcmp(tag, resource.getUniqueKey().tag())) {