Reland "Split apart flushing and submitting in the GrGpu classes and GrDrawingManager."

This reverts commit 2faa33772be498c21e014155608036a903647891.

Reason for revert: <INSERT REASONING HERE>

Original change's description:
> Revert "Split apart flushing and submitting in the GrGpu classes and GrDrawingManager."
> 
> This reverts commit 6341d92280f09f8d892b6c51c1eca53dcd1c205f.
> 
> Reason for revert: metal tests failing
> 
> Original change's description:
> > Split apart flushing and submitting in the GrGpu classes and GrDrawingManager.
> > 
> > Bug: skia:10118
> > Change-Id: I53e3b9f1bd28a00276a3d35b5160aa0cfec30cfd
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/282417
> > Reviewed-by: Jim Van Verth <jvanverth@google.com>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> 
> TBR=egdaniel@google.com,jvanverth@google.com,bsalomon@google.com,senorblanco@chromium.org
> 
> Change-Id: I2cb98b470e3a066c09012b686e9942edb5a3979b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:10118
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/282852
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Commit-Queue: Greg Daniel <egdaniel@google.com>

Bug: skia:10118
Change-Id: I9a77abe995a991275a87ee1d38bcab4deb361a9d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/282976
Reviewed-by: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index ff5deb2..b45562d 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -221,7 +221,7 @@
 }
 
 // MDB TODO: make use of the 'proxy' parameter.
-GrSemaphoresSubmitted GrDrawingManager::flush(GrSurfaceProxy* proxies[], int numProxies,
+bool GrDrawingManager::flush(GrSurfaceProxy* proxies[], int numProxies,
         SkSurface::BackendSurfaceAccess access, const GrFlushInfo& info,
         const GrPrepareForExternalIORequests& externalRequests) {
     SkASSERT(numProxies >= 0);
@@ -232,7 +232,7 @@
         if (info.fFinishedProc) {
             info.fFinishedProc(info.fFinishedContext);
         }
-        return GrSemaphoresSubmitted::kNo;
+        return false;
     }
 
     SkDEBUGCODE(this->validate());
@@ -244,7 +244,7 @@
             canSkip = !fDAG.isUsed(proxies[i]) && !this->isDDLTarget(proxies[i]);
         }
         if (canSkip) {
-            return GrSemaphoresSubmitted::kNo;
+            return false;
         }
     }
 
@@ -253,7 +253,7 @@
         if (info.fFinishedProc) {
             info.fFinishedProc(info.fFinishedContext);
         }
-        return GrSemaphoresSubmitted::kNo; // Can't flush while DDL recording
+        return false; // Can't flush while DDL recording
     }
     direct->priv().clientMappedBufferManager()->process();
 
@@ -262,7 +262,7 @@
         if (info.fFinishedProc) {
             info.fFinishedProc(info.fFinishedContext);
         }
-        return GrSemaphoresSubmitted::kNo; // Can't flush while DDL recording
+        return false; // Can't flush while DDL recording
     }
 
     fFlushing = true;
@@ -394,8 +394,7 @@
     opMemoryPool->isEmpty();
 #endif
 
-    GrSemaphoresSubmitted result = gpu->finishFlush(proxies, numProxies, access, info,
-                                                    externalRequests);
+    gpu->executeFlushInfo(proxies, numProxies, access, info, externalRequests);
 
     // Give the cache a chance to purge resources that become purgeable due to flushing.
     if (flushed) {
@@ -413,7 +412,20 @@
     fFlushingRenderTaskIDs.reset();
     fFlushing = false;
 
-    return result;
+    return true;
+}
+
+bool GrDrawingManager::submitToGpu(bool syncToCpu) {
+    if (fFlushing || this->wasAbandoned()) {
+        return false;
+    }
+
+    auto direct = fContext->priv().asDirectContext();
+    if (!direct) {
+        return false; // Can't submit while DDL recording
+    }
+    GrGpu* gpu = direct->priv().getGpu();
+    return gpu->submitToGpu(syncToCpu);
 }
 
 bool GrDrawingManager::executeRenderTasks(int startIndex, int stopIndex, GrOpFlushState* flushState,
@@ -462,8 +474,7 @@
         onFlushRenderTask = nullptr;
         (*numRenderTasksExecuted)++;
         if (*numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) {
-            flushState->gpu()->finishFlush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess,
-                                           GrFlushInfo(), GrPrepareForExternalIORequests());
+            flushState->gpu()->submitToGpu(false);
             *numRenderTasksExecuted = 0;
         }
     }
@@ -481,8 +492,7 @@
         }
         (*numRenderTasksExecuted)++;
         if (*numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) {
-            flushState->gpu()->finishFlush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess,
-                                           GrFlushInfo(), GrPrepareForExternalIORequests());
+            flushState->gpu()->submitToGpu(false);
             *numRenderTasksExecuted = 0;
         }
     }
@@ -523,12 +533,12 @@
     // TODO: It is important to upgrade the drawingmanager to just flushing the
     // portion of the DAG required by 'proxies' in order to restore some of the
     // semantics of this method.
-    GrSemaphoresSubmitted result = this->flush(proxies, numProxies, access, info,
-                                               GrPrepareForExternalIORequests());
+    bool didFlush = this->flush(proxies, numProxies, access, info,
+                                GrPrepareForExternalIORequests());
     for (int i = 0; i < numProxies; ++i) {
         GrSurfaceProxy* proxy = proxies[i];
         if (!proxy->isInstantiated()) {
-            return result;
+            continue;
         }
         // In the flushSurfaces case, we need to resolve MSAA immediately after flush. This is
         // because the client will call through to this method when drawing into a target created by
@@ -558,7 +568,16 @@
     }
 
     SkDEBUGCODE(this->validate());
-    return result;
+
+    bool submitted = false;
+    if (didFlush) {
+        submitted = this->submitToGpu(SkToBool(info.fFlags & kSyncCpu_GrFlushFlag));
+    }
+
+    if (!submitted || (!direct->priv().caps()->semaphoreSupport() && info.fNumSemaphores)) {
+        return GrSemaphoresSubmitted::kNo;
+    }
+    return GrSemaphoresSubmitted::kYes;
 }
 
 void GrDrawingManager::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) {
@@ -910,8 +929,10 @@
 
     auto resourceCache = direct->priv().getResourceCache();
     if (resourceCache && resourceCache->requestsFlush()) {
-        this->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(),
-                    GrPrepareForExternalIORequests());
+        if (this->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(),
+                        GrPrepareForExternalIORequests())) {
+            this->submitToGpu(false);
+        }
         resourceCache->purgeAsNeeded();
     }
 }