Rename flushForExternalRead->flushForExternalIO and always call in SkSurface::getTextureHandle

Review URL: https://codereview.chromium.org/1216243003
diff --git a/include/core/SkImage.h b/include/core/SkImage.h
index e0ea721..28b1803 100644
--- a/include/core/SkImage.h
+++ b/include/core/SkImage.h
@@ -171,11 +171,11 @@
     bool isTextureBacked() const;
 
     /**
-     *  Retrieves the backend API handle of the texture. If flushPendingGrContextReads then the
-     *  GrContext will issue to the backend API any deferred read operations on the texture before
+     *  Retrieves the backend API handle of the texture. If flushPendingGrContextIO then the
+     *  GrContext will issue to the backend API any deferred IO operations on the texture before
      *  returning.
      */
-    GrBackendObject getTextureHandle(bool flushPendingGrContextReads) const;
+    GrBackendObject getTextureHandle(bool flushPendingGrContextIO) const;
 
     /**
      *  Copy the pixels from the image into the specified buffer (pixels + rowBytes),
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 63f577f..1f1ebc2 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -304,15 +304,14 @@
     void flushSurfaceWrites(GrSurface* surface);
 
     /**
-     * Equivalent to flushSurfaceWrites but also performs MSAA resolve if necessary. This call is
-     * used to make the surface contents available to be read in the backend 3D API, usually for a
-     * compositing step external to Skia.
+     * 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.
      */
-    void prepareSurfaceForExternalRead(GrSurface*);
+    void prepareSurfaceForExternalIO(GrSurface*);
 
     /**
      * An ID associated with this context, guaranteed to be unique.
diff --git a/include/gpu/GrSurface.h b/include/gpu/GrSurface.h
index 543ccd1..bdf48be 100644
--- a/include/gpu/GrSurface.h
+++ b/include/gpu/GrSurface.h
@@ -116,10 +116,10 @@
 
 
     /**
-     * After this returns any pending writes to the surface will be issued to the backend 3D API and
+     * After this returns any pending surface IO will be issued to the backend 3D API and
      * if the surface has MSAA it will be resolved.
      */
-    void prepareForExternalRead();
+    void prepareForExternalIO();
 
     /** Access methods that are only to be used within Skia code. */
     inline GrSurfacePriv surfacePriv();
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index ed588b6..5cb8934 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -593,7 +593,7 @@
     return true;
 }
 
-void GrContext::prepareSurfaceForExternalRead(GrSurface* surface) {
+void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) {
     RETURN_IF_ABANDONED
     SkASSERT(surface);
     ASSERT_OWNED_RESOURCE(surface);
diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp
index b304ccb..9685c56 100644
--- a/src/gpu/GrSurface.cpp
+++ b/src/gpu/GrSurface.cpp
@@ -84,9 +84,9 @@
     }
 }
 
-void GrSurface::prepareForExternalRead() {
+void GrSurface::prepareForExternalIO() {
     if (!this->wasDestroyed()) {
-        this->getContext()->prepareSurfaceForExternalRead(this);
+        this->getContext()->prepareSurfaceForExternalIO(this);
     }
 }
 
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 17d837b..028ab56 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1737,7 +1737,7 @@
 
 void SkGpuDevice::flush() {
     DO_DEFERRED_CLEAR();
-    fRenderTarget->prepareForExternalRead();
+    fRenderTarget->prepareForExternalIO();
 }
 
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index 5e7d1b9..1d61438 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -122,13 +122,13 @@
 
 bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->getTexture()); }
 
-GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextReads) const {
+GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextIO) const {
     GrTexture* texture = as_IB(this)->getTexture();
     if (texture) {
         GrContext* context = texture->getContext();
         if (context) {            
-            if (flushPendingGrContextReads) {
-                context->prepareSurfaceForExternalRead(texture);
+            if (flushPendingGrContextIO) {
+                context->prepareSurfaceForExternalIO(texture);
             }
         }
         return texture->getTextureHandle();
@@ -142,7 +142,7 @@
 
 bool SkImage::isTextureBacked() const { return false; }
 
-GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextReads) const { return 0; }
+GrBackendObject SkImage::getTextureHandle(bool) const { return 0; }
 
 #endif
 
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 71bed3a..d243b65 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -30,15 +30,14 @@
     GrRenderTarget* rt = fDevice->accessRenderTarget();
     switch (access) {
         case kFlushRead_TextureHandleAccess:
-            rt->prepareForExternalRead();   // todo: rename to prepareForExternalAccess()
             break;
         case kFlushWrite_TextureHandleAccess:
         case kDiscardWrite_TextureHandleAccess:
             // for now we don't special-case on Discard, but we may in the future.
             this->notifyContentWillChange(kRetain_ContentChangeMode);
-            rt->flushWrites();
             break;
     }
+    rt->prepareForExternalIO();
     return rt->asTexture()->getTextureHandle();
 }