Add GrResourceAllocator::reset

This is used in the fallback code when reordering produces
a DAG that goes over our memory budget.

Bug: skia:10877
Change-Id: I13772b30e270eb546957b88586ded1cf42d2dbeb
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/397136
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 1dff77d..68b36d2 100644
--- a/src/gpu/GrResourceAllocator.cpp
+++ b/src/gpu/GrResourceAllocator.cpp
@@ -387,7 +387,25 @@
     return fDContext->priv().getResourceCache()->purgeToMakeHeadroom(additionalBytesNeeded);
 }
 
+void GrResourceAllocator::reset() {
+    // NOTE: We do not reset the failedInstantiation flag because we currently do not attempt
+    // to recover from failed instantiations. The user is responsible for checking this flag and
+    // bailing early.
+    SkDEBUGCODE(fPlanned = false;)
+    SkDEBUGCODE(fAssigned = false;)
+    SkASSERT(fActiveIntvls.empty());
+    fFinishedIntvls = IntervalList();
+    fIntvlList = IntervalList();
+    fIntvlHash.reset();
+    fUniqueKeyRegisters.reset();
+    fFreePool.reset();
+    fInternalAllocator.reset();
+}
+
 bool GrResourceAllocator::assign() {
+    if (fFailedInstantiation) {
+        return false;
+    }
     SkASSERT(fPlanned && !fAssigned);
     SkDEBUGCODE(fAssigned = true;)
     auto resourceProvider = fDContext->priv().resourceProvider();