Expose the owning surface to a canvas?

Handy if you want to flush, or otherwise understand the underlying buffer(s).

Change-Id: I3d6610695c8603232192b26c687c6c74512165dd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/254803
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/bench/ImageCycleBench.cpp b/bench/ImageCycleBench.cpp
index 032e43b..1bb38d0 100644
--- a/bench/ImageCycleBench.cpp
+++ b/bench/ImageCycleBench.cpp
@@ -73,7 +73,9 @@
                 }
             }
             // Prevent any batching between "frames".
-            canvas->flush();
+            if (auto surf = canvas->getSurface()) {
+                surf->flush();
+            }
         }
     }
 
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 2237337..373b779 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -286,6 +286,11 @@
     */
     virtual GrContext* getGrContext();
 
+    /** Sometimes a canvas is owned by a surface. If it is, getSurface() will return a bare
+     *  pointer to that surface, else this will return nullptr.
+     */
+    SkSurface* getSurface() const;
+
     /** Returns the pixel base address, SkImageInfo, rowBytes, and origin if the pixels
         can be read directly. The returned address is only valid
         while SkCanvas is in scope and unchanged. Any SkCanvas call or SkSurface call
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 72fe22d..9dd0f16 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -619,6 +619,10 @@
     }
 }
 
+SkSurface* SkCanvas::getSurface() const {
+    return fSurfaceBase;
+}
+
 SkISize SkCanvas::getBaseLayerSize() const {
     SkBaseDevice* d = this->getDevice();
     return d ? SkISize::Make(d->width(), d->height()) : SkISize::Make(0, 0);