Revert "Revert "Revert "Revert "Add support for semaphores to be inserted on GrContext flush""""

This reverts commit cc8eb60c486eaf397685c60b28998682025fee1a.

Reason for revert: Chrome change landed that should fix chrome roll

Original change's description:
> Revert "Revert "Revert "Add support for semaphores to be inserted on GrContext flush"""
> 
> This reverts commit 876aed8758b7109574999ffac43b1ea47f359bd7.
> 
> Reason for revert: the bots seem to be unhappily red with this CL
> 
> Original change's description:
> > Revert "Revert "Add support for semaphores to be inserted on GrContext flush""
> > 
> > This reverts commit 8724b4609996eb6369b454611e31b065f3d8d2cf.
> > 
> > Reason for revert: Creating a test CL to see what happens on the bots
> > 
> > Original change's description:
> > > Revert "Add support for semaphores to be inserted on GrContext flush"
> > > 
> > > This reverts commit cd1416efbc7af6f115dbaa09dce48e075d1d96ca.
> > > 
> > > Reason for revert: speculative, to try to fix roll see gpu_tests.pixel_integration_test.PixelIntegrationTest.Pixel_GpuRasterization_ConcavePaths
> > > 
> > > Original change's description:
> > > > Add support for semaphores to be inserted on GrContext flush
> > > > 
> > > > This also moves the logic of inserting semaphores down into GrDrawingManager
> > > > and finishFlush on GrGpu. With it being on finishFlush, there should be no
> > > > issues when the DrawingManager starts respecting the proxy passed in assuming
> > > > it always calls finishFlush at the end (which it should).
> > > > 
> > > > Bug: skia:
> > > > Change-Id: I925c2a289dcbbb9159b9120878af1d34f21a2dc7
> > > > Reviewed-on: https://skia-review.googlesource.com/25641
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > > 
> > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
> > > 
> > > Change-Id: I9c5b9cf8c060193e1861dbb8f0c10fb11dfb5249
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Bug: skia:
> > > Reviewed-on: https://skia-review.googlesource.com/25980
> > > Reviewed-by: Mike Reed <reed@google.com>
> > > Commit-Queue: Mike Reed <reed@google.com>
> > 
> > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reed@google.com
> > 
> > # Not skipping CQ checks because original CL landed > 1 day ago.
> > 
> > Bug: skia:
> > Change-Id: I5edbeaa0769670ee58f362f0ccaa78319410aa6c
> > Reviewed-on: https://skia-review.googlesource.com/26160
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> 
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reed@google.com
> 
> Change-Id: I22fd6febafe70489a5fdb695c6f4263368eb423d
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/29422
> Reviewed-by: Yuqian Li <liyuqian@google.com>
> Commit-Queue: Yuqian Li <liyuqian@google.com>

TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,liyuqian@google.com,reed@google.com

Change-Id: Ie3eae818b02599a70f714ef6b6635ce7d171bde6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/30000
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/tests/SurfaceSemaphoreTest.cpp b/tests/SurfaceSemaphoreTest.cpp
index cd3b8e5..bb726c2 100644
--- a/tests/SurfaceSemaphoreTest.cpp
+++ b/tests/SurfaceSemaphoreTest.cpp
@@ -108,7 +108,8 @@
 void surface_semaphore_test(skiatest::Reporter* reporter,
                             const sk_gpu_test::ContextInfo& mainInfo,
                             const sk_gpu_test::ContextInfo& childInfo1,
-                            const sk_gpu_test::ContextInfo& childInfo2) {
+                            const sk_gpu_test::ContextInfo& childInfo2,
+                            bool flushContext) {
     GrContext* mainCtx = mainInfo.grContext();
     if (!mainCtx->caps()->fenceSyncSupport()) {
         return;
@@ -143,7 +144,11 @@
     }
 #endif
 
-    mainSurface->flushAndSignalSemaphores(2, semaphores.get());
+    if (flushContext) {
+        mainCtx->flushAndSignalSemaphores(2, semaphores.get());
+    } else {
+        mainSurface->flushAndSignalSemaphores(2, semaphores.get());
+    }
 
     sk_sp<SkImage> mainImage = mainSurface->makeImageSnapshot();
     GrBackendObject backendImage = mainImage->getTextureHandle(false);
@@ -171,31 +176,35 @@
 #endif
 
     for (int typeInt = 0; typeInt < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++typeInt) {
-        sk_gpu_test::GrContextFactory::ContextType contextType =
-                (sk_gpu_test::GrContextFactory::ContextType) typeInt;
-        // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on
-        // desktop since tests do not account for not fixing http://skbug.com/2809
-        if (contextType == sk_gpu_test::GrContextFactory::kGL_ContextType ||
-            contextType == sk_gpu_test::GrContextFactory::kGLES_ContextType) {
-            if (contextType != kNativeGLType) {
+        for (auto flushContext : { false, true }) {
+            sk_gpu_test::GrContextFactory::ContextType contextType =
+                    (sk_gpu_test::GrContextFactory::ContextType) typeInt;
+            // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on
+            // desktop since tests do not account for not fixing http://skbug.com/2809
+            if (contextType == sk_gpu_test::GrContextFactory::kGL_ContextType ||
+                contextType == sk_gpu_test::GrContextFactory::kGLES_ContextType) {
+                if (contextType != kNativeGLType) {
+                    continue;
+                }
+            }
+            sk_gpu_test::ContextInfo ctxInfo = factory->getContextInfo(
+                    contextType, sk_gpu_test::GrContextFactory::ContextOverrides::kDisableNVPR);
+            if (!sk_gpu_test::GrContextFactory::IsRenderingContext(contextType)) {
                 continue;
             }
-        }
-        sk_gpu_test::ContextInfo ctxInfo = factory->getContextInfo(
-                contextType, sk_gpu_test::GrContextFactory::ContextOverrides::kDisableNVPR);
-        if (!sk_gpu_test::GrContextFactory::IsRenderingContext(contextType)) {
-            continue;
-        }
-        skiatest::ReporterContext ctx(
-                reporter, SkString(sk_gpu_test::GrContextFactory::ContextTypeName(contextType)));
-        if (ctxInfo.grContext()) {
-            sk_gpu_test::ContextInfo child1 = factory->getSharedContextInfo(ctxInfo.grContext(), 0);
-            sk_gpu_test::ContextInfo child2 = factory->getSharedContextInfo(ctxInfo.grContext(), 1);
-            if (!child1.grContext() || !child2.grContext()) {
-                continue;
-            }
+            skiatest::ReporterContext ctx(
+                   reporter, SkString(sk_gpu_test::GrContextFactory::ContextTypeName(contextType)));
+            if (ctxInfo.grContext()) {
+                sk_gpu_test::ContextInfo child1 = factory->getSharedContextInfo(ctxInfo.grContext(),
+                                                                                0);
+                sk_gpu_test::ContextInfo child2 = factory->getSharedContextInfo(ctxInfo.grContext(),
+                                                                                1);
+                if (!child1.grContext() || !child2.grContext()) {
+                    continue;
+                }
 
-            surface_semaphore_test(reporter, ctxInfo, child1, child2);
+                surface_semaphore_test(reporter, ctxInfo, child1, child2, flushContext);
+            }
         }
     }
 }
@@ -217,7 +226,8 @@
     mainSurface->flush();
 
     GrBackendSemaphore semaphore;
-    REPORTER_ASSERT(reporter, mainSurface->flushAndSignalSemaphores(1, &semaphore));
+    GrSemaphoresSubmitted submitted = mainSurface->flushAndSignalSemaphores(1, &semaphore);
+    REPORTER_ASSERT(reporter, GrSemaphoresSubmitted::kYes == submitted);
 
     if (kOpenGL_GrBackend == ctxInfo.backend()) {
         GrGLGpu* gpu = static_cast<GrGLGpu*>(ctx->getGpu());