Change flushing policy in GrContextPriv::writeSurfacePixels

Together with the following Chrome-side CL, this patch fixes Skia's flushing behavior for platforms that prefer flushes over VRAM use (i.e., ANGLE) and for platforms that don't (e.g., Android).

https://chromium-review.googlesource.com/c/chromium/src/+/1582181 (Remove additional FlushSkia in CanvasResourceProvider::WritePixels)

Here are the perf numbers on Android and Windows for the putImageData performance test:

                              Android (Nexus 5x)   Windows (i.e., ANGLE)
Current Chrome                        112.9             512.1
Chrome w/ 1582181                     131.9             334.8
Chrome w/ 1582181 and this CL         133.6             589.4

So, after both CLs have landed, Android will be faster while Windows will, roughly, remain the same.

Note, on ChromiumPerf the swing for the Nexus 5x is from 126.8 to 153.6 (so, a larger delta than I'm seeing here).

Bug: 942538, 953720
Change-Id: Iead6388e7a378240f87363e9a342d36a63f4c7f8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/210062
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrContextPriv.cpp b/src/gpu/GrContextPriv.cpp
index c6c6507..dfb2c0b 100644
--- a/src/gpu/GrContextPriv.cpp
+++ b/src/gpu/GrContextPriv.cpp
@@ -627,7 +627,12 @@
         top = dstSurface->height() - top - height;
     }
 
-    this->flush(dstProxy);
+    // On platforms that prefer flushes over VRAM use (i.e., ANGLE) we're better off forcing a
+    // complete flush here. On platforms that prefer VRAM use over flushes we're better off
+    // 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->flush(caps->preferVRAMUseOverFlushes() ? dstProxy : nullptr);
 
     return this->getGpu()->writePixels(dstSurface, left, top, width, height, srcColorType, buffer,
                                        rowBytes);
@@ -758,4 +763,3 @@
     fContext->drawingManager()->testingOnly_removeOnFlushCallbackObject(cb);
 }
 #endif
-