Revert "Add flush() to SkImage."

This reverts commit d0503a72ac4293562a8e88be33633ec0cf55c3d4.

Reason for revert: <INSERT REASONING HERE>

Original change's description:
> Add flush() to SkImage.
> 
> This allows a client to ensure all uses of a texture-backed image have
> been flushed.
> 
> Does nothing if the image isn't texture-backed.
> 
> The implementation adds support for triggering a flush if any of a set
> of proxies are used rather than just a single proxy.
> 
> Change-Id: I358882d9737e63c6e69b924c0767f49b8f8f36ec
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/212405
> Commit-Queue: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Robert Phillips <robertphillips@google.com>

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

Change-Id: Ie376bf4225307f45b8fb3eb4a63bf84702365797
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/212884
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/include/core/SkImage.h b/include/core/SkImage.h
index 96809fd..a1a26a7 100644
--- a/include/core/SkImage.h
+++ b/include/core/SkImage.h
@@ -726,23 +726,6 @@
     */
     bool isValid(GrContext* context) const;
 
-    /** Flushes any pending uses of texture-backed images in the GPU backend. If the image is not
-        texture-backed (including promise texture images) or if the the GrContext does not
-        have the same context ID as the context backing the image then this is a no-op.
-
-        If the image was not used in any non-culled draws recorded on the passed GrContext then
-        this is a no-op unless the GrFlushInfo contains semaphores, a finish proc, or uses
-        kSyncCpu_GrFlushFlag. Those are respected even when the image has not been used.
-
-        @param context  the context on which to flush pending usages of the image.
-        @param info     flush options
-        @return         one of: GrSemaphoresSubmitted::kYes, GrSemaphoresSubmitted::kNo
-     */
-    GrSemaphoresSubmitted flush(GrContext* context, const GrFlushInfo& flushInfo);
-
-    /** Version of flush() that uses a default GrFlushInfo. */
-    void flush(GrContext*);
-
     /** Retrieves the back-end texture. If SkImage has no back-end texture, an invalid
         object is returned. Call GrBackendTexture::isValid to determine if the result
         is valid.
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 19d1f6e..a90dce9 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -264,7 +264,7 @@
         return GrSemaphoresSubmitted::kNo;
     }
 
-    return this->drawingManager()->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess,
+    return this->drawingManager()->flush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess,
                                          info);
 }
 
diff --git a/src/gpu/GrContextPriv.cpp b/src/gpu/GrContextPriv.cpp
index 10772ef..dfb2c0b 100644
--- a/src/gpu/GrContextPriv.cpp
+++ b/src/gpu/GrContextPriv.cpp
@@ -24,12 +24,12 @@
 #include "src/image/SkImage_Base.h"
 #include "src/image/SkImage_Gpu.h"
 
-#define ASSERT_OWNED_PROXY(P) \
+#define ASSERT_OWNED_PROXY_PRIV(P) \
     SkASSERT(!(P) || !((P)->peekTexture()) || (P)->peekTexture()->getContext() == fContext)
-#define ASSERT_SINGLE_OWNER \
+#define ASSERT_SINGLE_OWNER_PRIV \
     SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fContext->singleOwner());)
-#define RETURN_VALUE_IF_ABANDONED(value) if (fContext->abandoned()) { return (value); }
-#define RETURN_IF_ABANDONED RETURN_VALUE_IF_ABANDONED(void)
+#define RETURN_IF_ABANDONED_PRIV if (fContext->abandoned()) { return; }
+#define RETURN_FALSE_IF_ABANDONED_PRIV if (fContext->abandoned()) { return false; }
 
 sk_sp<const GrCaps> GrContextPriv::refCaps() const {
     return fContext->refCaps();
@@ -103,7 +103,7 @@
 sk_sp<GrTextureContext> GrContextPriv::makeBackendTextureContext(const GrBackendTexture& tex,
                                                                  GrSurfaceOrigin origin,
                                                                  sk_sp<SkColorSpace> colorSpace) {
-    ASSERT_SINGLE_OWNER
+    ASSERT_SINGLE_OWNER_PRIV
 
     sk_sp<GrSurfaceProxy> proxy = this->proxyProvider()->wrapBackendTexture(
             tex, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
@@ -122,7 +122,7 @@
                                                                    const SkSurfaceProps* props,
                                                                    ReleaseProc releaseProc,
                                                                    ReleaseContext releaseCtx) {
-    ASSERT_SINGLE_OWNER
+    ASSERT_SINGLE_OWNER_PRIV
     SkASSERT(sampleCnt > 0);
 
     sk_sp<GrTextureProxy> proxy(this->proxyProvider()->wrapRenderableBackendTexture(
@@ -143,7 +143,7 @@
                                                 const SkSurfaceProps* surfaceProps,
                                                 ReleaseProc releaseProc,
                                                 ReleaseContext releaseCtx) {
-    ASSERT_SINGLE_OWNER
+    ASSERT_SINGLE_OWNER_PRIV
 
     sk_sp<GrSurfaceProxy> proxy = this->proxyProvider()->wrapBackendRenderTarget(
             backendRT, origin, releaseProc, releaseCtx);
@@ -162,7 +162,7 @@
                                                      int sampleCnt,
                                                      sk_sp<SkColorSpace> colorSpace,
                                                      const SkSurfaceProps* props) {
-    ASSERT_SINGLE_OWNER
+    ASSERT_SINGLE_OWNER_PRIV
     SkASSERT(sampleCnt > 0);
     sk_sp<GrSurfaceProxy> proxy(
             this->proxyProvider()->wrapBackendTextureAsRenderTarget(tex, origin, sampleCnt));
@@ -177,7 +177,7 @@
 
 sk_sp<GrRenderTargetContext> GrContextPriv::makeVulkanSecondaryCBRenderTargetContext(
         const SkImageInfo& imageInfo, const GrVkDrawableInfo& vkInfo, const SkSurfaceProps* props) {
-    ASSERT_SINGLE_OWNER
+    ASSERT_SINGLE_OWNER_PRIV
     sk_sp<GrSurfaceProxy> proxy(
             this->proxyProvider()->wrapVulkanSecondaryCBAsRenderTarget(imageInfo, vkInfo));
     if (!proxy) {
@@ -189,22 +189,23 @@
                                                            props);
 }
 
-GrSemaphoresSubmitted GrContextPriv::flushSurfaces(GrSurfaceProxy* proxies[], int numProxies,
-                                                   const GrFlushInfo& info) {
-    ASSERT_SINGLE_OWNER
-    RETURN_VALUE_IF_ABANDONED(GrSemaphoresSubmitted::kNo)
-    GR_CREATE_TRACE_MARKER_CONTEXT("GrContextPriv", "flushSurfaces", fContext);
-    SkASSERT(numProxies >= 0);
-    SkASSERT(!numProxies || proxies);
-    for (int i = 0; i < numProxies; ++i) {
-        SkASSERT(proxies[i]);
-        ASSERT_OWNED_PROXY(proxies[i]);
-    }
-    return fContext->drawingManager()->flushSurfaces(
-            proxies, numProxies, SkSurface::BackendSurfaceAccess::kNoAccess, info);
+void GrContextPriv::flush(GrSurfaceProxy* proxy) {
+    ASSERT_SINGLE_OWNER_PRIV
+    RETURN_IF_ABANDONED_PRIV
+    ASSERT_OWNED_PROXY_PRIV(proxy);
+
+    fContext->drawingManager()->flush(proxy, SkSurface::BackendSurfaceAccess::kNoAccess,
+                                      GrFlushInfo());
 }
 
-void GrContextPriv::flushSurface(GrSurfaceProxy* proxy) { this->flushSurfaces(&proxy, 1, {}); }
+void GrContextPriv::flushSurface(GrSurfaceProxy* proxy) {
+    ASSERT_SINGLE_OWNER_PRIV
+    RETURN_IF_ABANDONED_PRIV
+    SkASSERT(proxy);
+    ASSERT_OWNED_PROXY_PRIV(proxy);
+    fContext->drawingManager()->flushSurface(proxy,
+            SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo());
+}
 
 static bool valid_premul_color_type(GrColorType ct) {
     switch (ct) {
@@ -276,11 +277,11 @@
                                       int height, GrColorType dstColorType,
                                       SkColorSpace* dstColorSpace, void* buffer, size_t rowBytes,
                                       uint32_t pixelOpsFlags) {
-    ASSERT_SINGLE_OWNER
-    RETURN_VALUE_IF_ABANDONED(false)
+    ASSERT_SINGLE_OWNER_PRIV
+    RETURN_FALSE_IF_ABANDONED_PRIV
     SkASSERT(src);
     SkASSERT(buffer);
-    ASSERT_OWNED_PROXY(src->asSurfaceProxy());
+    ASSERT_OWNED_PROXY_PRIV(src->asSurfaceProxy());
     GR_CREATE_TRACE_MARKER_CONTEXT("GrContextPriv", "readSurfacePixels", fContext);
 
     GrSurfaceProxy* srcProxy = src->asSurfaceProxy();
@@ -430,7 +431,7 @@
         sk_bzero(buffer, tempPixmap.computeByteSize());
     }
 
-    this->flushSurface(srcProxy);
+    this->flush(srcProxy);
 
     if (!fContext->fGpu->readPixels(srcSurface, left, top, width, height, allowedColorType, buffer,
                                     rowBytes)) {
@@ -460,11 +461,11 @@
                                        int height, GrColorType srcColorType,
                                        SkColorSpace* srcColorSpace, const void* buffer,
                                        size_t rowBytes, uint32_t pixelOpsFlags) {
-    ASSERT_SINGLE_OWNER
-    RETURN_VALUE_IF_ABANDONED(false)
+    ASSERT_SINGLE_OWNER_PRIV
+    RETURN_FALSE_IF_ABANDONED_PRIV
     SkASSERT(dst);
     SkASSERT(buffer);
-    ASSERT_OWNED_PROXY(dst->asSurfaceProxy());
+    ASSERT_OWNED_PROXY_PRIV(dst->asSurfaceProxy());
     GR_CREATE_TRACE_MARKER_CONTEXT("GrContextPriv", "writeSurfacePixels", fContext);
 
     if (GrColorType::kUnknown == srcColorType) {
@@ -631,7 +632,7 @@
     // giving the drawing manager the chance of skipping the flush (i.e., by passing in the
     // destination proxy)
     // TODO: should this policy decision just be moved into the drawing manager?
-    this->flushSurface(caps->preferVRAMUseOverFlushes() ? dstProxy : nullptr);
+    this->flush(caps->preferVRAMUseOverFlushes() ? dstProxy : nullptr);
 
     return this->getGpu()->writePixels(dstSurface, left, top, width, height, srcColorType, buffer,
                                        rowBytes);
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index 9e8e729..ebf3f6a 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -164,18 +164,22 @@
             const SkImageInfo&, const GrVkDrawableInfo&, const SkSurfaceProps* = nullptr);
 
     /**
-     * Finalizes all pending reads and writes to the surfaces and also performs an MSAA resolves
-     * if necessary. The GrSurfaceProxy array is treated as a hint. If it is supplied the context
-     * will guarantee that the draws required for those proxies are flushed but it could do more.
-     * If no array is provided then all current work will be flushed.
+     * Call to ensure all drawing to the context has been issued to the
+     * underlying 3D API.
+     * The 'proxy' parameter is a hint. If it is supplied the context will guarantee that
+     * the draws required for that proxy are flushed but it could do more. If no 'proxy' is
+     * provided then all current work will be flushed.
+     */
+    void flush(GrSurfaceProxy*);
+
+    /**
+     * Finalizes all pending reads and writes to the surface and also performs an MSAA resolve
+     * if necessary.
      *
      * It is not necessary to call this before reading the render target via Skia/GrContext.
      * GrContext will detect when it must perform a resolve before reading pixels back from the
      * surface or using it as a texture.
      */
-    GrSemaphoresSubmitted flushSurfaces(GrSurfaceProxy*[], int numProxies, const GrFlushInfo&);
-
-    /** Version of above that flushes for a single proxy and uses a default GrFlushInfo. */
     void flushSurface(GrSurfaceProxy*);
 
    /**
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index c56101e..4d00261 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -194,12 +194,9 @@
 }
 
 // MDB TODO: make use of the 'proxy' parameter.
-GrSemaphoresSubmitted GrDrawingManager::flush(GrSurfaceProxy* proxies[],
-                                              int numProxies,
+GrSemaphoresSubmitted GrDrawingManager::flush(GrSurfaceProxy* proxy,
                                               SkSurface::BackendSurfaceAccess access,
                                               const GrFlushInfo& info) {
-    SkASSERT(numProxies >= 0);
-    SkASSERT(!numProxies || proxies);
     GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "flush", fContext);
 
     if (fFlushing || this->wasAbandoned()) {
@@ -211,14 +208,9 @@
 
     SkDEBUGCODE(this->validate());
 
-    if (kNone_GrFlushFlags == info.fFlags && !info.fNumSemaphores && !info.fFinishedProc) {
-        bool canSkip = numProxies > 0;
-        for (int i = 0; i < numProxies && canSkip; ++i) {
-            canSkip = !fDAG.isUsed(proxies[i]) && !this->isDDLTarget(proxies[i]);
-        }
-        if (canSkip) {
-            return GrSemaphoresSubmitted::kNo;
-        }
+    if (kNone_GrFlushFlags == info.fFlags && !info.fNumSemaphores && !info.fFinishedProc &&
+            proxy && !this->isDDLTarget(proxy) && !fDAG.isUsed(proxy)) {
+        return GrSemaphoresSubmitted::kNo;
     }
 
     auto direct = fContext->priv().asDirectContext();
@@ -357,7 +349,7 @@
     opMemoryPool->isEmpty();
 #endif
 
-    GrSemaphoresSubmitted result = gpu->finishFlush(proxies, numProxies, access, info);
+    GrSemaphoresSubmitted result = gpu->finishFlush(proxy, access, info);
 
     flushState.deinstantiateProxyTracker()->deinstantiateAllProxies();
 
@@ -440,7 +432,7 @@
         onFlushOpList = nullptr;
         (*numOpListsExecuted)++;
         if (*numOpListsExecuted >= kMaxOpListsBeforeFlush) {
-            flushState->gpu()->finishFlush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess,
+            flushState->gpu()->finishFlush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess,
                                            GrFlushInfo());
             *numOpListsExecuted = 0;
         }
@@ -458,7 +450,7 @@
         }
         (*numOpListsExecuted)++;
         if (*numOpListsExecuted >= kMaxOpListsBeforeFlush) {
-            flushState->gpu()->finishFlush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess,
+            flushState->gpu()->finishFlush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess,
                                            GrFlushInfo());
             *numOpListsExecuted = 0;
         }
@@ -477,15 +469,13 @@
     return anyOpListsExecuted;
 }
 
-GrSemaphoresSubmitted GrDrawingManager::flushSurfaces(GrSurfaceProxy* proxies[], int n,
-                                                      SkSurface::BackendSurfaceAccess access,
-                                                      const GrFlushInfo& info) {
+GrSemaphoresSubmitted GrDrawingManager::flushSurface(
+        GrSurfaceProxy* proxy, SkSurface::BackendSurfaceAccess access, const GrFlushInfo& info) {
     if (this->wasAbandoned()) {
         return GrSemaphoresSubmitted::kNo;
     }
     SkDEBUGCODE(this->validate());
-    SkASSERT(proxies);
-    SkASSERT(n > 0);
+    SkASSERT(proxy);
 
     auto direct = fContext->priv().asDirectContext();
     if (!direct) {
@@ -498,25 +488,21 @@
     }
 
     // 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
+    // portion of the DAG required by 'proxy' in order to restore some of the
     // semantics of this method.
-    GrSemaphoresSubmitted result = this->flush(proxies, n, access, info);
-    for (int i = 0; i < n; ++i) {
-        if (!proxies[i]->isInstantiated()) {
-            return result;
-        }
+    GrSemaphoresSubmitted result = this->flush(proxy, access, info);
+    if (!proxy->isInstantiated()) {
+        return result;
     }
 
-    for (int i = 0; i < n; ++i) {
-        GrSurface* surface = proxies[i]->peekSurface();
-        if (auto* rt = surface->asRenderTarget()) {
-            gpu->resolveRenderTarget(rt);
-        }
-        if (auto* tex = surface->asTexture()) {
-            if (tex->texturePriv().mipMapped() == GrMipMapped::kYes &&
-                tex->texturePriv().mipMapsAreDirty()) {
-                gpu->regenerateMipMapLevels(tex);
-            }
+    GrSurface* surface = proxy->peekSurface();
+    if (auto* rt = surface->asRenderTarget()) {
+        gpu->resolveRenderTarget(rt);
+    }
+    if (auto* tex = surface->asTexture()) {
+        if (tex->texturePriv().mipMapped() == GrMipMapped::kYes &&
+            tex->texturePriv().mipMapsAreDirty()) {
+            gpu->regenerateMipMapLevels(tex);
         }
     }
 
@@ -745,7 +731,7 @@
 
     auto resourceCache = direct->priv().getResourceCache();
     if (resourceCache && resourceCache->requestsFlush()) {
-        this->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo());
+        this->flush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo());
         resourceCache->purgeAsNeeded();
     }
 }
diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h
index 521ed66..2b04b9a 100644
--- a/src/gpu/GrDrawingManager.h
+++ b/src/gpu/GrDrawingManager.h
@@ -71,15 +71,9 @@
 
     static bool ProgramUnitTest(GrContext* context, int maxStages, int maxLevels);
 
-    GrSemaphoresSubmitted flushSurfaces(GrSurfaceProxy* proxies[],
-                                        int cnt,
-                                        SkSurface::BackendSurfaceAccess access,
-                                        const GrFlushInfo& info);
-    GrSemaphoresSubmitted flushSurface(GrSurfaceProxy* proxy,
+    GrSemaphoresSubmitted flushSurface(GrSurfaceProxy*,
                                        SkSurface::BackendSurfaceAccess access,
-                                       const GrFlushInfo& info) {
-        return this->flushSurfaces(&proxy, 1, access, info);
-    }
+                                       const GrFlushInfo& info);
 
     void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
 
@@ -153,8 +147,7 @@
     // return true if any opLists were actually executed; false otherwise
     bool executeOpLists(int startIndex, int stopIndex, GrOpFlushState*, int* numOpListsExecuted);
 
-    GrSemaphoresSubmitted flush(GrSurfaceProxy* proxies[],
-                                int numProxies,
+    GrSemaphoresSubmitted flush(GrSurfaceProxy* proxy,
                                 SkSurface::BackendSurfaceAccess access,
                                 const GrFlushInfo&);
 
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 479d733..c57b169 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -412,8 +412,7 @@
     return fSamplePatternDictionary.findOrAssignSamplePatternKey(sampleLocations);
 }
 
-GrSemaphoresSubmitted GrGpu::finishFlush(GrSurfaceProxy* proxies[],
-                                         int n,
+GrSemaphoresSubmitted GrGpu::finishFlush(GrSurfaceProxy* proxy,
                                          SkSurface::BackendSurfaceAccess access,
                                          const GrFlushInfo& info) {
     this->stats()->incNumFinishFlushes();
@@ -437,7 +436,7 @@
             }
         }
     }
-    this->onFinishFlush(proxies, n, access, info);
+    this->onFinishFlush(proxy, access, info);
     return this->caps()->semaphoreSupport() ? GrSemaphoresSubmitted::kYes
                                             : GrSemaphoresSubmitted::kNo;
 }
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index be4a9bf..5b90f05 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -303,8 +303,8 @@
     // Provides a hook for post-flush actions (e.g. Vulkan command buffer submits). This will also
     // insert any numSemaphore semaphores on the gpu and set the backendSemaphores to match the
     // inserted semaphores.
-    GrSemaphoresSubmitted finishFlush(GrSurfaceProxy*[], int n,
-                                      SkSurface::BackendSurfaceAccess access, const GrFlushInfo&);
+    GrSemaphoresSubmitted finishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
+                                      const GrFlushInfo&);
 
     virtual void submit(GrGpuCommandBuffer*) = 0;
 
@@ -547,7 +547,7 @@
                                const SkIRect& srcRect, const SkIPoint& dstPoint,
                                bool canDiscardOutsideDstRect) = 0;
 
-    virtual void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access,
+    virtual void onFinishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
                                const GrFlushInfo&) = 0;
 
 #ifdef SK_ENABLE_DUMP_GPU
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index f41733c..197a1a6 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -4274,7 +4274,7 @@
     return attribState;
 }
 
-void GrGLGpu::onFinishFlush(GrSurfaceProxy*[], int, SkSurface::BackendSurfaceAccess access,
+void GrGLGpu::onFinishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
                             const GrFlushInfo& info) {
     // If we inserted semaphores during the flush, we need to call GLFlush.
     bool insertedSemaphore = info.fNumSemaphores > 0 && this->caps()->semaphoreSupport();
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index fde6d22..b2821e4 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -295,7 +295,7 @@
 
     void flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSwizzle&);
 
-    void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access,
+    void onFinishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
                        const GrFlushInfo&) override;
 
     bool waitSync(GrGLsync, uint64_t timeout, bool flush);
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
index 5df9c02..57d8f7a 100644
--- a/src/gpu/mock/GrMockGpu.h
+++ b/src/gpu/mock/GrMockGpu.h
@@ -111,7 +111,7 @@
 
     void onResolveRenderTarget(GrRenderTarget* target) override { return; }
 
-    void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access,
+    void onFinishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
                        const GrFlushInfo& info) override {
         if (info.fFinishedProc) {
             info.fFinishedProc(info.fFinishedContext);
diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h
index 0eed4ed..d16ae2d 100644
--- a/src/gpu/mtl/GrMtlGpu.h
+++ b/src/gpu/mtl/GrMtlGpu.h
@@ -184,7 +184,7 @@
 
     void onResolveRenderTarget(GrRenderTarget* target) override { return; }
 
-    void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access,
+    void onFinishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
                        const GrFlushInfo& info) override {
         if (info.fFlags & kSyncCpu_GrFlushFlag) {
             this->submitCommandBuffer(kForce_SyncQueue);
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index b1c9979..a82775a 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -1889,25 +1889,21 @@
                                        barrier);
 }
 
-void GrVkGpu::onFinishFlush(GrSurfaceProxy* proxies[], int n,
-                            SkSurface::BackendSurfaceAccess access, const GrFlushInfo& info) {
-    SkASSERT(n >= 0);
-    SkASSERT(!n || proxies);
+void GrVkGpu::onFinishFlush(GrSurfaceProxy* proxy, SkSurface::BackendSurfaceAccess access,
+                            const GrFlushInfo& info) {
     // Submit the current command buffer to the Queue. Whether we inserted semaphores or not does
     // not effect what we do here.
-    if (n && access == SkSurface::BackendSurfaceAccess::kPresent) {
+    if (proxy && access == SkSurface::BackendSurfaceAccess::kPresent) {
         GrVkImage* image;
-        for (int i = 0; i < n; ++i) {
-            SkASSERT(proxies[i]->isInstantiated());
-            if (GrTexture* tex = proxies[i]->peekTexture()) {
-                image = static_cast<GrVkTexture*>(tex);
-            } else {
-                GrRenderTarget* rt = proxies[i]->peekRenderTarget();
-                SkASSERT(rt);
-                image = static_cast<GrVkRenderTarget*>(rt);
-            }
-            image->prepareForPresent(this);
+        SkASSERT(proxy->isInstantiated());
+        if (GrTexture* tex = proxy->peekTexture()) {
+            image = static_cast<GrVkTexture*>(tex);
+        } else {
+            GrRenderTarget* rt = proxy->peekRenderTarget();
+            SkASSERT(rt);
+            image = static_cast<GrVkRenderTarget*>(rt);
         }
+        image->prepareForPresent(this);
     }
     if (info.fFlags & kSyncCpu_GrFlushFlag) {
         this->submitCommandBuffer(kForce_SyncQueue, info.fFinishedProc, info.fFinishedContext);
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index 9446467..2321f9a 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -225,7 +225,7 @@
                        GrSurfaceOrigin srcOrigin, const SkIRect& srcRect,
                        const SkIPoint& dstPoint, bool canDiscardOutsideDstRect) override;
 
-    void onFinishFlush(GrSurfaceProxy*[], int, SkSurface::BackendSurfaceAccess access,
+    void onFinishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
                        const GrFlushInfo&) override;
 
     // Ends and submits the current command buffer to the queue and then creates a new command
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index 8c27a1d..cbc8a01 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -160,12 +160,6 @@
     return as_IB(this)->onIsValid(context);
 }
 
-GrSemaphoresSubmitted SkImage::flush(GrContext* context, const GrFlushInfo& flushInfo) {
-    return as_IB(this)->onFlush(context, flushInfo);
-}
-
-void SkImage::flush(GrContext* context) { as_IB(this)->onFlush(context, {}); }
-
 #else
 
 GrTexture* SkImage::getTexture() const { return nullptr; }
@@ -184,12 +178,6 @@
     return as_IB(this)->onIsValid(context);
 }
 
-GrSemaphoresSubmitted SkImage::flush(GrContext*, const GrFlushInfo&) {
-    return GrSemaphoresSubmitted::kNo;
-}
-
-void SkImage::flush(GrContext*) {}
-
 #endif
 
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h
index b06d7fc..3b28dd6 100644
--- a/src/image/SkImage_Base.h
+++ b/src/image/SkImage_Base.h
@@ -48,10 +48,6 @@
     virtual GrContext* context() const { return nullptr; }
 
 #if SK_SUPPORT_GPU
-    virtual GrSemaphoresSubmitted onFlush(GrContext* context, const GrFlushInfo&) {
-        return GrSemaphoresSubmitted::kNo;
-    }
-
     // Return the proxy if this image is backed by a single proxy. For YUVA images, this
     // will return nullptr unless the YUVA planes have been converted to RGBA in which case
     // that single backing proxy will be returned.
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 02bb8b5..5f77ceb 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -64,15 +64,6 @@
 
 SkImage_Gpu::~SkImage_Gpu() {}
 
-GrSemaphoresSubmitted SkImage_Gpu::onFlush(GrContext* context, const GrFlushInfo& info) {
-    if (!context || !fContext->priv().matches(context) || fContext->abandoned()) {
-        return GrSemaphoresSubmitted::kNo;
-    }
-
-    GrSurfaceProxy* p[1] = {fProxy.get()};
-    return context->priv().flushSurfaces(p, 1, info);
-}
-
 sk_sp<SkImage> SkImage_Gpu::onMakeColorTypeAndColorSpace(GrRecordingContext* context,
                                                          SkColorType targetCT,
                                                          sk_sp<SkColorSpace> targetCS) const {
@@ -665,8 +656,7 @@
 
     GrFlushInfo info;
     info.fFlags = kSyncCpu_GrFlushFlag;
-    GrSurfaceProxy* p[1] = {proxy.get()};
-    drawingManager->flush(p, 1, SkSurface::BackendSurfaceAccess::kNoAccess, info);
+    drawingManager->flush(proxy.get(), SkSurface::BackendSurfaceAccess::kNoAccess, info);
 
     return image;
 }
diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h
index 08cd131..8ee0e0f 100644
--- a/src/image/SkImage_Gpu.h
+++ b/src/image/SkImage_Gpu.h
@@ -26,8 +26,6 @@
                 sk_sp<SkColorSpace>);
     ~SkImage_Gpu() override;
 
-    GrSemaphoresSubmitted onFlush(GrContext*, const GrFlushInfo&) override;
-
     GrTextureProxy* peekProxy() const override {
         return fProxy.get();
     }
diff --git a/src/image/SkImage_GpuYUVA.cpp b/src/image/SkImage_GpuYUVA.cpp
index 915d0de..7f5a7ec 100644
--- a/src/image/SkImage_GpuYUVA.cpp
+++ b/src/image/SkImage_GpuYUVA.cpp
@@ -103,21 +103,6 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
-GrSemaphoresSubmitted SkImage_GpuYUVA::onFlush(GrContext* context, const GrFlushInfo& info) {
-    if (!context || !fContext->priv().matches(context) || fContext->abandoned()) {
-        return GrSemaphoresSubmitted::kNo;
-    }
-
-    GrSurfaceProxy* proxies[5] = {fProxies[0].get(), fProxies[1].get(),
-                                  fProxies[2].get(), fProxies[3].get(), nullptr};
-    int numProxies = fNumProxies;
-    if (fRGBProxy) {
-        proxies[fNumProxies] = fRGBProxy.get();
-        ++numProxies;
-    }
-    return context->priv().flushSurfaces(proxies, numProxies, info);
-}
-
 GrTextureProxy* SkImage_GpuYUVA::peekProxy() const {
     return fRGBProxy.get();
 }
diff --git a/src/image/SkImage_GpuYUVA.h b/src/image/SkImage_GpuYUVA.h
index daa9ee1..eee5759 100644
--- a/src/image/SkImage_GpuYUVA.h
+++ b/src/image/SkImage_GpuYUVA.h
@@ -29,8 +29,6 @@
                     GrSurfaceOrigin, sk_sp<SkColorSpace>);
     ~SkImage_GpuYUVA() override;
 
-    GrSemaphoresSubmitted onFlush(GrContext*, const GrFlushInfo&) override;
-
     // This returns the single backing proxy if the YUV channels have already been flattened but
     // nullptr if they have not.
     GrTextureProxy* peekProxy() const override;
@@ -58,8 +56,6 @@
     // Returns a ref-ed texture proxy with miplevels
     sk_sp<GrTextureProxy> asMippedTextureProxyRef(GrRecordingContext*) const;
 
-    bool testingOnly_IsFlattened() const { return SkToBool(fRGBProxy); }
-
     /**
      * This is the implementation of SkDeferredDisplayListRecorder::makeYUVAPromiseTexture.
      */
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index df2fc1d..7af9593 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -313,7 +313,7 @@
         GrDrawRandomOp(&random, renderTargetContext.get(), std::move(paint));
     }
     // Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes)
-    drawingManager->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo());
+    drawingManager->flush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo());
 
     const GrBackendFormat format =
             context->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
@@ -342,7 +342,7 @@
             auto blockFP = BlockInputFragmentProcessor::Make(std::move(fp));
             paint.addColorFragmentProcessor(std::move(blockFP));
             GrDrawRandomOp(&random, renderTargetContext.get(), std::move(paint));
-            drawingManager->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess,
+            drawingManager->flush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess,
                                   GrFlushInfo());
         }
     }
diff --git a/tests/GrFinishedFlushTest.cpp b/tests/GrFinishedFlushTest.cpp
index 04a5fa7..6243a8a 100644
--- a/tests/GrFinishedFlushTest.cpp
+++ b/tests/GrFinishedFlushTest.cpp
@@ -43,9 +43,9 @@
     sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info);
     SkCanvas* canvas = surface->getCanvas();
 
-    canvas->clear(SK_ColorGREEN);
-    auto image = surface->makeImageSnapshot();
-
+    // We flush the surface first just to get rid of any discards/clears that got recorded from
+    // making the surface.
+    surface->flush();
     GrFlushInfo flushInfoSyncCpu;
     flushInfoSyncCpu.fFlags = kSyncCpu_GrFlushFlag;
     ctx->flush(flushInfoSyncCpu);
@@ -78,9 +78,9 @@
     ctx->flush(flushInfoSyncCpu);
     REPORTER_ASSERT(reporter, count == 2);
 
-    // Test flushing via the SkImage
-    canvas->drawImage(image, 0, 0);
-    image->flush(ctx, flushInfoFinishedProc);
+    // Test flushing via the GrContext
+    canvas->clear(SK_ColorBLUE);
+    ctx->flush(flushInfoFinishedProc);
     if (expectAsyncCallback) {
         // On Vulkan the command buffer we just submitted may or may not have finished immediately
         // so the finish proc may not have been called.
@@ -91,23 +91,10 @@
     ctx->flush(flushInfoSyncCpu);
     REPORTER_ASSERT(reporter, count == 3);
 
-    // Test flushing via the GrContext
-    canvas->clear(SK_ColorBLUE);
-    ctx->flush(flushInfoFinishedProc);
-    if (expectAsyncCallback) {
-        // On Vulkan the command buffer we just submitted may or may not have finished immediately
-        // so the finish proc may not have been called.
-        REPORTER_ASSERT(reporter, count == 3 || count == 4);
-    } else {
-        REPORTER_ASSERT(reporter, count == 4);
-    }
-    ctx->flush(flushInfoSyncCpu);
-    REPORTER_ASSERT(reporter, count == 4);
-
     // There is no work on the surface so flushing may immediately call the finished proc.
     ctx->flush(flushInfoFinishedProc);
-    REPORTER_ASSERT(reporter, count == 4 || count == 5);
-    busy_wait_for_callback(&count, 5, ctx, reporter);
+    REPORTER_ASSERT(reporter, count == 3 || count == 4);
+    busy_wait_for_callback(&count, 4, ctx, reporter);
 
     count = 0;
     int count2 = 0;
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index bd4bad0..ce50074 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -20,23 +20,24 @@
 #include "include/core/SkSerialProcs.h"
 #include "include/core/SkStream.h"
 #include "include/core/SkSurface.h"
-#include "include/gpu/GrContextThreadSafeProxy.h"
-#include "include/gpu/GrTexture.h"
 #include "src/core/SkAutoPixmapStorage.h"
 #include "src/core/SkColorSpacePriv.h"
 #include "src/core/SkImagePriv.h"
 #include "src/core/SkMakeUnique.h"
 #include "src/core/SkUtils.h"
+#include "src/image/SkImage_Base.h"
+#include "tests/Test.h"
+#include "tests/TestUtils.h"
+
+#include "tools/Resources.h"
+#include "tools/ToolUtils.h"
+
+#include "include/gpu/GrContextThreadSafeProxy.h"
+#include "include/gpu/GrTexture.h"
 #include "src/gpu/GrContextPriv.h"
 #include "src/gpu/GrGpu.h"
 #include "src/gpu/GrResourceCache.h"
 #include "src/gpu/SkGr.h"
-#include "src/image/SkImage_Base.h"
-#include "src/image/SkImage_GpuYUVA.h"
-#include "tests/Test.h"
-#include "tests/TestUtils.h"
-#include "tools/Resources.h"
-#include "tools/ToolUtils.h"
 
 using namespace sk_gpu_test;
 
@@ -1376,76 +1377,3 @@
     }
 }
 
-DEF_GPUTEST_FOR_ALL_CONTEXTS(ImageFlush, reporter, ctxInfo) {
-    auto c = ctxInfo.grContext();
-    auto ii = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
-    auto s = SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kYes, ii, 1, nullptr);
-
-    s->getCanvas()->clear(SK_ColorRED);
-    auto i0 = s->makeImageSnapshot();
-    s->getCanvas()->clear(SK_ColorBLUE);
-    auto i1 = s->makeImageSnapshot();
-    s->getCanvas()->clear(SK_ColorGREEN);
-
-    // Make a YUVA image.
-    SkAutoPixmapStorage pm;
-    pm.alloc(SkImageInfo::Make(1, 1, kAlpha_8_SkColorType, kPremul_SkAlphaType));
-    const SkPixmap pmaps[] = {pm, pm, pm, pm};
-    SkYUVAIndex indices[] = {{0, SkColorChannel::kA}, {1, SkColorChannel::kA},
-                             {2, SkColorChannel::kA}, {3, SkColorChannel::kA}};
-    auto i2 = SkImage::MakeFromYUVAPixmaps(c, kJPEG_SkYUVColorSpace, pmaps, indices,
-                                           SkISize::Make(1, 1), kTopLeft_GrSurfaceOrigin, false);
-
-    // Flush all the setup work we did above and then make little lambda that reports the flush
-    // count delta since the last time it was called.
-    c->flush();
-    auto numFlushes = [c, flushCnt = c->priv().getGpu()->stats()->numFinishFlushes()]() mutable {
-        int curr = c->priv().getGpu()->stats()->numFinishFlushes();
-        int n = curr - flushCnt;
-        flushCnt = curr;
-        return n;
-    };
-
-    // Images aren't used therefore flush is ignored.
-    i0->flush(c);
-    i1->flush(c);
-    i2->flush(c);
-    REPORTER_ASSERT(reporter, numFlushes() == 0);
-
-    // Syncing forces the flush to happen even if the images aren't used.
-    GrFlushInfo syncInfo;
-    syncInfo.fFlags = kSyncCpu_GrFlushFlag;
-    i0->flush(c, syncInfo);
-    REPORTER_ASSERT(reporter, numFlushes() == 1);
-    i1->flush(c, syncInfo);
-    REPORTER_ASSERT(reporter, numFlushes() == 1);
-    i2->flush(c, syncInfo);
-    REPORTER_ASSERT(reporter, numFlushes() == 1);
-
-    // Use image 1
-    s->getCanvas()->drawImage(i1, 0, 0);
-    // Flushing image 0 should do nothing.
-    i0->flush(c);
-    REPORTER_ASSERT(reporter, numFlushes() == 0);
-    // Flushing image 1 should flush.
-    i1->flush(c);
-    REPORTER_ASSERT(reporter, numFlushes() == 1);
-    // Flushing image 2 should do nothing.
-    i2->flush(c);
-    REPORTER_ASSERT(reporter, numFlushes() == 0);
-
-    // Use image 2
-    s->getCanvas()->drawImage(i2, 0, 0);
-    // Flushing image 0 should do nothing.
-    i0->flush(c);
-    REPORTER_ASSERT(reporter, numFlushes() == 0);
-    // Flushing image 1 do nothing.
-    i1->flush(c);
-    REPORTER_ASSERT(reporter, numFlushes() == 0);
-    // Flushing image 2 should flush.
-    i2->flush(c);
-    REPORTER_ASSERT(reporter, numFlushes() == 1);
-    // Since we just did a simple image draw it should not have been flattened.
-    REPORTER_ASSERT(reporter,
-                    !static_cast<SkImage_GpuYUVA*>(as_IB(i2.get()))->testingOnly_IsFlattened());
-}
diff --git a/tests/SurfaceSemaphoreTest.cpp b/tests/SurfaceSemaphoreTest.cpp
index 4f6f72b..d992171 100644
--- a/tests/SurfaceSemaphoreTest.cpp
+++ b/tests/SurfaceSemaphoreTest.cpp
@@ -104,13 +104,11 @@
     check_pixels(reporter, bitmap);
 }
 
-enum class FlushType { kSurface, kImage, kContext };
-
 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,
-                            FlushType flushType) {
+                            bool flushContext) {
     GrContext* mainCtx = mainInfo.grContext();
     if (!mainCtx->priv().caps()->semaphoreSupport()) {
         return;
@@ -123,11 +121,7 @@
                                                              ii, 0, kTopLeft_GrSurfaceOrigin,
                                                              nullptr));
     SkCanvas* mainCanvas = mainSurface->getCanvas();
-    auto blueSurface = mainSurface->makeSurface(ii);
-    blueSurface->getCanvas()->clear(SK_ColorBLUE);
-    auto blueImage = blueSurface->makeImageSnapshot();
-    blueSurface.reset();
-    mainCanvas->drawImage(blueImage, 0, 0);
+    mainCanvas->clear(SK_ColorBLUE);
 
     SkAutoTArray<GrBackendSemaphore> semaphores(2);
 #ifdef SK_VULKAN
@@ -152,16 +146,10 @@
     GrFlushInfo info;
     info.fNumSemaphores = 2;
     info.fSignalSemaphores = semaphores.get();
-    switch (flushType) {
-        case FlushType::kSurface:
-            mainSurface->flush(SkSurface::BackendSurfaceAccess::kNoAccess, info);
-            break;
-        case FlushType::kImage:
-            blueImage->flush(mainCtx, info);
-            break;
-        case FlushType::kContext:
-            mainCtx->flush(info);
-            break;
+    if (flushContext) {
+        mainCtx->flush(info);
+    } else {
+        mainSurface->flush(SkSurface::BackendSurfaceAccess::kNoAccess, info);
     }
 
     sk_sp<SkImage> mainImage = mainSurface->makeImageSnapshot();
@@ -191,7 +179,7 @@
 #endif
 
     for (int typeInt = 0; typeInt < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++typeInt) {
-        for (auto flushType : {FlushType::kSurface, FlushType::kImage, FlushType::kContext}) {
+        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
@@ -219,7 +207,7 @@
                     continue;
                 }
 
-                surface_semaphore_test(reporter, ctxInfo, child1, child2, flushType);
+                surface_semaphore_test(reporter, ctxInfo, child1, child2, flushContext);
             }
         }
     }
diff --git a/tests/TransferPixelsTest.cpp b/tests/TransferPixelsTest.cpp
index 952d2b8..631a870 100644
--- a/tests/TransferPixelsTest.cpp
+++ b/tests/TransferPixelsTest.cpp
@@ -275,7 +275,7 @@
         GrFlushInfo flushInfo;
         flushInfo.fFlags = kSyncCpu_GrFlushFlag;
         if (context->priv().caps()->mapBufferFlags() & GrCaps::kAsyncRead_MapFlag) {
-            gpu->finishFlush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
+            gpu->finishFlush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
         }
 
         const auto* map = reinterpret_cast<const GrColor*>(buffer->map());
@@ -304,7 +304,7 @@
         ++expectedTransferCnt;
 
         if (context->priv().caps()->mapBufferFlags() & GrCaps::kAsyncRead_MapFlag) {
-            gpu->finishFlush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
+            gpu->finishFlush(nullptr, SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
         }
 
         map = reinterpret_cast<const GrColor*>(buffer->map());