ok: refactor Src/Dst interactions

This makes everything a lot more like DM, for the same reason:
it's the best way to make Vias work.

Instead of exposing a canvas, Dsts take a Src to draw.  Vias still are
Dsts that wrap Dsts.  They do their internal work in draw() then pass a
proxy Src encapsulating that work to the next Dst's draw().

A little refactoring in ok.cpp allows arbitrary chains of Vias.

I removed the guarantee that Src methods are called in strict order.
It's easy enough to make each Src initialize itself as needed.

I moved the .png encoding back to ok.cpp.  It seemed weird for Dsts to
have to think about files and paths.  One day Dst will want a data()
method for non-image output (.pdf, .skp), and then we'll want ok.cpp to
be the one to coordinate what to write where.

Change-Id: Id4a3674b2d05aef2b5f10e0077df0a8407c07b61
Reviewed-on: https://skia-review.googlesource.com/10175
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
diff --git a/tools/ok_srcs.cpp b/tools/ok_srcs.cpp
index ce3e653..a7d262c 100644
--- a/tools/ok_srcs.cpp
+++ b/tools/ok_srcs.cpp
@@ -23,19 +23,27 @@
         skiagm::GM* (*factory)(void*);
         std::unique_ptr<skiagm::GM> gm;
 
-        std::string name() override {
+        void init() {
+            if (gm) { return; }
             gm.reset(factory(nullptr));
+        }
+
+        std::string name() override {
+            this->init();
             return gm->getName();
         }
 
         SkISize size() override {
+            this->init();
             return gm->getISize();
         }
 
-        void draw(SkCanvas* canvas) override {
+        bool draw(SkCanvas* canvas) override {
+            this->init();
             canvas->clear(0xffffffff);
             canvas->concat(gm->getInitialTransform());
             gm->draw(canvas);
+            return true;
         }
     };
 
@@ -69,19 +77,26 @@
         std::string dir, path;
         sk_sp<SkPicture> pic;
 
+        void init() {
+            if (pic) { return; }
+            auto skp = SkData::MakeFromFileName((dir+"/"+path).c_str());
+            pic = SkPicture::MakeFromData(skp.get());
+        }
+
         std::string name() override {
             return path;
         }
 
         SkISize size() override {
-            auto skp = SkData::MakeFromFileName((dir+"/"+path).c_str());
-            pic = SkPicture::MakeFromData(skp.get());
+            this->init();
             return pic->cullRect().roundOut().size();
         }
 
-        void draw(SkCanvas* canvas) override {
+        bool draw(SkCanvas* canvas) override {
+            this->init();
             canvas->clear(0xffffffff);
             pic->playback(canvas);
+            return true;
         }
     };