Reduce usage of SkCanvas::flush

SkCanvas::flush is problematic and we wish to deprecate it. As a first step, this CL begins to remove Skia's internal usage of it.

Ideally clients would use SkSurface::flush and/or GrContext::flush.

Change-Id: I39bb0702f8230134a97961a4ee70833fd5bd0dcc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/196641
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/tools/viewer/StatsLayer.cpp b/tools/viewer/StatsLayer.cpp
index 8d25e8b..b7960f7 100644
--- a/tools/viewer/StatsLayer.cpp
+++ b/tools/viewer/StatsLayer.cpp
@@ -10,6 +10,7 @@
 #include "SkCanvas.h"
 #include "SkFont.h"
 #include "SkString.h"
+#include "SkSurface.h"
 #include "SkTime.h"
 
 StatsLayer::StatsLayer()
@@ -50,7 +51,7 @@
     return fTimers[timer].fTimes[idx];
 }
 
-void StatsLayer::onPaint(SkCanvas* canvas) {
+void StatsLayer::onPaint(SkSurface* surface) {
     // Advance our timing bookkeeping
     for (int i = 0; i < fTimers.count(); ++i) {
         fCumulativeMeasurementTime += fTimers[i].fTimes[fCurrentMeasurement];
@@ -79,6 +80,7 @@
     static const int kGraphPadding = 3;
     static const SkScalar kBaseMS = 1000.f / 60.f;  // ms/frame to hit 60 fps
 
+    auto canvas = surface->getCanvas();
     SkISize canvasSize = canvas->getBaseLayerSize();
     SkRect rect = SkRect::MakeXYWH(SkIntToScalar(canvasSize.fWidth-kDisplayWidth-kDisplayPadding),
                                    SkIntToScalar(kDisplayPadding),