Add samples to Viewer.

This adds support with animation, assuming the sample has
implemented onAnimate. Event handling has not been
implemented.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2056343004

Review-Url: https://codereview.chromium.org/2056343004
diff --git a/tools/viewer/SKPSlide.cpp b/tools/viewer/SKPSlide.cpp
index 6a9899b..9419253 100644
--- a/tools/viewer/SKPSlide.cpp
+++ b/tools/viewer/SKPSlide.cpp
@@ -48,7 +48,7 @@
     return pic;
 }
 
-void SKPSlide::load() {
+void SKPSlide::load(SkScalar, SkScalar) {
     fPic = read_picture(fPath.c_str());
     fCullRect = fPic->cullRect().roundOut();
 }
diff --git a/tools/viewer/SKPSlide.h b/tools/viewer/SKPSlide.h
index 42845fa..ff92ed1 100644
--- a/tools/viewer/SKPSlide.h
+++ b/tools/viewer/SKPSlide.h
@@ -19,7 +19,7 @@
     SkISize getDimensions() const override { return fCullRect.size(); }
 
     void draw(SkCanvas* canvas) override;
-    void load() override;
+    void load(SkScalar winWidth, SkScalar winHeight) override;
     void unload() override;
 
 private:
diff --git a/tools/viewer/SampleSlide.cpp b/tools/viewer/SampleSlide.cpp
new file mode 100755
index 0000000..2ae1280
--- /dev/null
+++ b/tools/viewer/SampleSlide.cpp
@@ -0,0 +1,37 @@
+/*
+* Copyright 2016 Google Inc.
+*
+* Use of this source code is governed by a BSD-style license that can be
+* found in the LICENSE file.
+*/
+
+#include "SampleSlide.h"
+
+#include "SkCanvas.h"
+#include "SkCommonFlags.h"
+#include "SkOSFile.h"
+#include "SkStream.h"
+
+SampleSlide::SampleSlide(const SkViewFactory* factory) : fViewFactory(factory) {
+    SkView* view = (*factory)();
+    SampleCode::RequestTitle(view, &fName);
+    view->unref();
+}
+
+SampleSlide::~SampleSlide() {}
+
+void SampleSlide::draw(SkCanvas* canvas) {
+    fView->draw(canvas);
+}
+
+void SampleSlide::load(SkScalar winWidth, SkScalar winHeight) {
+    fView = (*fViewFactory)();
+    fView->setVisibleP(true);
+    fView->setClipToBounds(false);
+    fView->setSize(winWidth, winHeight);
+}
+
+void SampleSlide::unload() {
+    fView->unref();
+    fView = nullptr;
+}
diff --git a/tools/viewer/SampleSlide.h b/tools/viewer/SampleSlide.h
new file mode 100755
index 0000000..3d772d0
--- /dev/null
+++ b/tools/viewer/SampleSlide.h
@@ -0,0 +1,34 @@
+/*
+* Copyright 2016 Google Inc.
+*
+* Use of this source code is governed by a BSD-style license that can be
+* found in the LICENSE file.
+*/
+
+#ifndef SampleSlide_DEFINED
+#define SampleSlide_DEFINED
+
+#include "Slide.h"
+#include "SampleCode.h"
+
+class SampleSlide : public Slide {
+public:
+    SampleSlide(const SkViewFactory* factory);
+    ~SampleSlide() override;
+
+    void draw(SkCanvas* canvas) override;
+    void load(SkScalar winWidth, SkScalar winHeight) override;
+    void unload() override;
+    bool animate(const SkAnimTimer& timer) override {
+        if (SampleView::IsSampleView(fView)) {
+            return ((SampleView*)fView)->animate(timer);
+        }
+        return false;
+    }
+
+private:
+    const SkViewFactory*   fViewFactory;
+    SkView*                fView;
+};
+
+#endif
diff --git a/tools/viewer/Slide.h b/tools/viewer/Slide.h
index cdc225b..bc0ffd4 100644
--- a/tools/viewer/Slide.h
+++ b/tools/viewer/Slide.h
@@ -19,11 +19,13 @@
 public:
     virtual ~Slide() {}
 
-    virtual SkISize getDimensions() const = 0;
+    virtual SkISize getDimensions() const {
+        return SkISize::Make(0, 0);
+    }
 
     virtual void draw(SkCanvas* canvas) = 0;
     virtual bool animate(const SkAnimTimer&) { return false;  }
-    virtual void load() {}
+    virtual void load(SkScalar winWidth, SkScalar winHeight) {}
     virtual void unload() {}
 
     SkString getName() { return fName; }
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 4996735..ca7eddd 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -8,6 +8,7 @@
 #include "Viewer.h"
 
 #include "GMSlide.h"
+#include "SampleSlide.h"
 #include "SKPSlide.h"
 
 #include "SkCanvas.h"
@@ -42,7 +43,6 @@
 }
 
 DEFINE_bool2(fullscreen, f, true, "Run fullscreen.");
-DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON identifying this builder.");
 DEFINE_string2(match, m, nullptr,
                "[~][^]substring[$] [...] of bench name to run.\n"
                "Multiple matches may be separated by spaces.\n"
@@ -196,6 +196,14 @@
         fSlides[fSlides.count() - i - 1] = temp;
     }
 
+    // samples
+    const SkViewRegister* reg = SkViewRegister::Head();
+    while (reg) {
+        sk_sp<Slide> slide(new SampleSlide(reg->factory()));
+        fSlides.push_back(slide);
+        reg = reg->next();
+    }
+
     // SKPs
     for (int i = 0; i < FLAGS_skps.count(); i++) {
         if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
@@ -272,7 +280,7 @@
 
     this->updateTitle();
     this->updateUIState();
-    fSlides[fCurrentSlide]->load();
+    fSlides[fCurrentSlide]->load(SkIntToScalar(fWindow->width()), SkIntToScalar(fWindow->height()));
     if (previousSlide >= 0) {
         fSlides[previousSlide]->unload();
     }