Handle the empty case in GrDrawingManager::insertTaskBeforeLast

Change-Id: I3c0f042b28cc39cc6df2f63b52a0f431cee6bda4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/421826
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Adlai Holler <adlai@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index 109aac0..46da592 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -452,10 +452,12 @@
 }
 
 GrRenderTask* GrDrawingManager::insertTaskBeforeLast(sk_sp<GrRenderTask> task) {
-    SkASSERT(!fDAG.empty());
     if (!task) {
         return nullptr;
     }
+    if (fDAG.empty()) {
+        return fDAG.push_back(std::move(task)).get();
+    }
     // Release 'fDAG.back()' and grab the raw pointer, in case the SkTArray grows
     // and reallocates during emplace_back.
     // TODO: Either use std::vector that can do this for us, or use SkSTArray to get the
@@ -662,8 +664,18 @@
         }
     }
 
-    if (!fDAG.empty() && !fDAG.back()->isClosed()) {
-        SkASSERT(fActiveOpsTask == fDAG.back().get());
+    // The active opsTask, if any, should always be at the back of the DAG.
+    if (!fDAG.empty()) {
+        if (fDAG.back()->isSetFlag(GrRenderTask::kAtlas_Flag)) {
+            SkASSERT(fActiveOpsTask == nullptr);
+            SkASSERT(!fDAG.back()->isClosed());
+        } else if (fDAG.back()->isClosed()) {
+            SkASSERT(fActiveOpsTask == nullptr);
+        } else {
+            SkASSERT(fActiveOpsTask == fDAG.back().get());
+        }
+    } else {
+        SkASSERT(fActiveOpsTask == nullptr);
     }
 }
 #endif