Reland of 8525 with fix for case when GrRT outlives GrTexture.
Review URL: https://codereview.chromium.org/13814015

git-svn-id: http://skia.googlecode.com/svn/trunk@8573 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrSurface.h b/include/gpu/GrSurface.h
index 02fc0d5..52a5665 100644
--- a/include/gpu/GrSurface.h
+++ b/include/gpu/GrSurface.h
@@ -64,6 +64,22 @@
     virtual const GrRenderTarget* asRenderTarget() const = 0;
 
     /**
+     * Checks whether this GrSurface refers to the same GPU object as other. This
+     * catches the case where a GrTexture and GrRenderTarget refer to the same
+     * GPU memory.
+     */
+    bool isSameAs(const GrSurface* other) const {
+        const GrRenderTarget* thisRT = this->asRenderTarget();
+        if (NULL != thisRT) {
+            return thisRT == other->asRenderTarget();
+        } else {
+            const GrTexture* thisTex = this->asTexture();
+            GrAssert(NULL != thisTex); // We must be one or the other
+            return thisTex == other->asTexture();
+        }
+    }
+
+    /**
      * Reads a rectangle of pixels from the surface.
      * @param left          left edge of the rectangle to read (inclusive)
      * @param top           top edge of the rectangle to read (inclusive)