Remove submit from async read pixels. User must submit.

Bug: chromium:1087118

Change-Id: Iab152ac483787fbdcca448aee0c4b9d2b354a92b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292840
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index e170cad..8da29c7 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -8,6 +8,11 @@
 ------------
 
   * <insert new release notes here>
+  
+  * SkSurface::asyncRescaleAndReadPixels and SkSurfaceasyncRescaleAndReadPixelsYUV420
+    now require explicit GrContext submit to guarantee finite time before callback
+    is invoked.
+    https://review.skia.org/292840
 
   * Add VkSharingMode field to GrVkImageInfo.
     https://review.skia.org/293559
diff --git a/gm/asyncrescaleandread.cpp b/gm/asyncrescaleandread.cpp
index 8b56f39..f119144 100644
--- a/gm/asyncrescaleandread.cpp
+++ b/gm/asyncrescaleandread.cpp
@@ -43,6 +43,9 @@
                                         SkFilterQuality quality) {
     auto* context = new AsyncContext();
     surface->asyncRescaleAndReadPixels(ii, srcRect, rescaleGamma, quality, async_callback, context);
+    if (auto ctx = surface->getContext()) {
+        ctx->submit();
+    }
     while (!context->fCalled) {
         // Only GPU should actually be asynchronous.
         SkASSERT(surface->getCanvas()->getGrContext());
@@ -69,6 +72,9 @@
     AsyncContext context;
     surface->asyncRescaleAndReadPixelsYUV420(yuvCS, SkColorSpace::MakeSRGB(), srcRect, size,
                                              rescaleGamma, quality, async_callback, &context);
+    if (auto ctx = surface->getContext()) {
+        ctx->submit();
+    }
     while (!context.fCalled) {
         // Only GPU should actually be asynchronous.
         SkASSERT(surface->getCanvas()->getGrContext());
diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h
index 1e1db19..652d218 100644
--- a/include/core/SkSurface.h
+++ b/include/core/SkSurface.h
@@ -797,7 +797,8 @@
         When the pixel data is ready the caller's ReadPixelsCallback is called with a
         AsyncReadResult containing pixel data in the requested color type, alpha type, and color
         space. The AsyncReadResult will have count() == 1. Upon failure the callback is called
-        with nullptr for AsyncReadResult.
+        with nullptr for AsyncReadResult. For a GPU surface this flushes work but a submit must
+        occur to guarantee a finite time before the callback is called.
 
         The data is valid for the lifetime of AsyncReadResult with the exception that if the
         SkSurface is GPU-backed the data is immediately invalidated if the GrContext is abandoned
@@ -825,7 +826,9 @@
 
         When the pixel data is ready the caller's ReadPixelsCallback is called with a
         AsyncReadResult containing the planar data. The AsyncReadResult will have count() == 3.
-        Upon failure the callback is called with nullptr for AsyncReadResult.
+        Upon failure the callback is called with nullptr for AsyncReadResult. For a GPU surface this
+        flushes work but a submit must occur to guarantee a finite time before the callback is
+        called.
 
         The data is valid for the lifetime of AsyncReadResult with the exception that if the
         SkSurface is GPU-backed the data is immediately invalidated if the GrContext is abandoned
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index 5e7a321..cdbc65d 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -1895,7 +1895,6 @@
     flushInfo.fFinishedContext = finishContext;
     flushInfo.fFinishedProc = finishCallback;
     this->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
-    directContext->submit();
 }
 
 void GrRenderTargetContext::asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
@@ -2148,7 +2147,6 @@
     flushInfo.fFinishedContext = finishContext;
     flushInfo.fFinishedProc = finishCallback;
     this->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
-    direct->submit();
 }
 
 GrSemaphoresSubmitted GrRenderTargetContext::flush(SkSurface::BackendSurfaceAccess access,
diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp
index d164f28..28d1359 100644
--- a/tests/ReadPixelsTest.cpp
+++ b/tests/ReadPixelsTest.cpp
@@ -948,6 +948,7 @@
         // Rescale quality and linearity don't matter since we're doing a non-scaling readback.
         surface->asyncRescaleAndReadPixels(pixels.info(), rect, SkSurface::RescaleGamma::kSrc,
                                            kNone_SkFilterQuality, async_callback, &context);
+        surface->getContext()->submit();
         while (!context.fCalled) {
             surface->getCanvas()->getGrContext()->checkAsyncWorkCompletion();
         }
@@ -1065,6 +1066,7 @@
                                                     kNone_SkFilterQuality, &async_callback,
                                                     &cbContext);
                 }
+                surf->getContext()->submit();
                 while (!cbContext.fCalled) {
                     context->checkAsyncWorkCompletion();
                 }
diff --git a/tests/VkProtectedContextTest.cpp b/tests/VkProtectedContextTest.cpp
index 30c8907..c238d6d 100644
--- a/tests/VkProtectedContextTest.cpp
+++ b/tests/VkProtectedContextTest.cpp
@@ -281,6 +281,7 @@
                                              image_info.bounds(), image_info.dimensions(),
                                              SkSurface::RescaleGamma::kSrc, kNone_SkFilterQuality,
                                              &async_callback, &cbContext);
+    surface->getContext()->submit();
     while (!cbContext.fCalled) {
         surface->getCanvas()->getGrContext()->checkAsyncWorkCompletion();
     }
diff --git a/tools/skottie2movie.cpp b/tools/skottie2movie.cpp
index ca887b5..e9da0d1 100644
--- a/tools/skottie2movie.cpp
+++ b/tools/skottie2movie.cpp
@@ -146,6 +146,7 @@
                                                 SkSurface::RescaleGamma::kSrc,
                                                 kNone_SkFilterQuality,
                                                 read_pixels_cb, &asyncRec);
+                surf->getContext()->submit();
             } else {
                 SkPixmap pm;
                 SkAssertResult(surf->peekPixels(&pm));