Revert "Stop using pendingIO in read/writeSurfacePixels"

This reverts commit 76cf552e2854e78a430fb51de040e5eb70387bfe.

Reason for revert: Maybe breaking some bots

Original change's description:
> Stop using pendingIO in read/writeSurfacePixels
> 
> This changes the implementation to always flush for these operations.
> Once partial DAG flushes are implemented this behavior will be better than the old method.
> 
> Change-Id: I1f9edd33dcf5aa15cc5dcdf8f0e06a3b3cd88f48
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/205584
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>

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

Change-Id: If3e8cc9a6e92b98f85bc3faf2b99fba7395ec946
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/206067
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrContextPriv.cpp b/src/gpu/GrContextPriv.cpp
index 98820c3..2b9d1e7 100644
--- a/src/gpu/GrContextPriv.cpp
+++ b/src/gpu/GrContextPriv.cpp
@@ -304,13 +304,12 @@
     ASSERT_OWNED_PROXY_PRIV(src->asSurfaceProxy());
     GR_CREATE_TRACE_MARKER_CONTEXT("GrContextPriv", "readSurfacePixels", fContext);
 
-    GrSurfaceProxy* srcProxy = src->asSurfaceProxy();
-
     // MDB TODO: delay this instantiation until later in the method
-    if (!srcProxy->instantiate(this->resourceProvider())) {
+    if (!src->asSurfaceProxy()->instantiate(this->resourceProvider(), true)) {
         return false;
     }
 
+    GrSurfaceProxy* srcProxy = src->asSurfaceProxy();
     GrSurface* srcSurface = srcProxy->peekSurface();
 
     if (!GrSurfacePriv::AdjustReadPixelParams(srcSurface->width(), srcSurface->height(),
@@ -451,7 +450,9 @@
         sk_bzero(buffer, tempPixmap.computeByteSize());
     }
 
-    this->flush(srcProxy);
+    if (srcSurface->surfacePriv().hasPendingWrite()) {
+        this->flush(nullptr);  // MDB TODO: tighten this
+    }
 
     if (!fContext->fGpu->readPixels(srcSurface, left, top, width, height, allowedColorType, buffer,
                                     rowBytes)) {
@@ -492,11 +493,11 @@
         return false;
     }
 
-    GrSurfaceProxy* dstProxy = dst->asSurfaceProxy();
-    if (!dstProxy->instantiate(this->resourceProvider())) {
+    if (!dst->asSurfaceProxy()->instantiate(this->resourceProvider(), true)) {
         return false;
     }
 
+    GrSurfaceProxy* dstProxy = dst->asSurfaceProxy();
     GrSurface* dstSurface = dstProxy->peekSurface();
 
     if (!GrSurfacePriv::AdjustWritePixelParams(dstSurface->width(), dstSurface->height(),
@@ -579,13 +580,10 @@
             dst->asRenderTargetContext()->fillRectToRect(
                     GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(),
                     SkRect::MakeXYWH(left, top, width, height), SkRect::MakeWH(width, height));
+            return true;
         } else {
-            if (!dst->copy(tempProxy.get(), SkIRect::MakeWH(width, height), {left, top})) {
-                return false;
-            }
+            return dst->copy(tempProxy.get(), SkIRect::MakeWH(width, height), {left, top});
         }
-
-        return true;
     }
 
     bool convert = premul || needColorConversion;
@@ -647,7 +645,9 @@
         top = dstSurface->height() - top - height;
     }
 
-    this->flush(dstProxy);
+    if (dstSurface->surfacePriv().hasPendingIO()) {
+        this->flush(nullptr);  // MDB TODO: tighten this
+    }
 
     return this->getGpu()->writePixels(dstSurface, left, top, width, height, srcColorType, buffer,
                                        rowBytes);