Add GrResourceAllocator::makeBudgetHeadroom
This allows the caller to decide whether a plan is feasible before
committing to it. In this CL the drawing manager doesn't actually
call it, but we test it. We'll call it in a follow-up CL
Bug: skia:10877
Change-Id: Ie3a6c14a0196f595c522a0c961aba7b10c980711
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/394157
Commit-Queue: Adlai Holler <adlai@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrResourceAllocator.cpp b/src/gpu/GrResourceAllocator.cpp
index 9fc6afe..1dff77d 100644
--- a/src/gpu/GrResourceAllocator.cpp
+++ b/src/gpu/GrResourceAllocator.cpp
@@ -362,6 +362,31 @@
return !fFailedInstantiation;
}
+bool GrResourceAllocator::makeBudgetHeadroom() {
+ SkASSERT(fPlanned);
+ SkASSERT(!fFailedInstantiation);
+ size_t additionalBytesNeeded = 0;
+ for (Interval* cur = fFinishedIntvls.peekHead(); cur; cur = cur->next()) {
+ GrSurfaceProxy* proxy = cur->proxy();
+ if (SkBudgeted::kNo == proxy->isBudgeted() || proxy->isInstantiated()) {
+ continue;
+ }
+
+ // N.B Fully-lazy proxies were already instantiated in planAssignment
+ if (proxy->isLazy()) {
+ additionalBytesNeeded += proxy->gpuMemorySize();
+ } else {
+ Register* r = cur->getRegister();
+ SkASSERT(r);
+ if (!r->accountedForInBudget() && !r->existingSurface()) {
+ additionalBytesNeeded += proxy->gpuMemorySize();
+ }
+ r->setAccountedForInBudget();
+ }
+ }
+ return fDContext->priv().getResourceCache()->purgeToMakeHeadroom(additionalBytesNeeded);
+}
+
bool GrResourceAllocator::assign() {
SkASSERT(fPlanned && !fAssigned);
SkDEBUGCODE(fAssigned = true;)