Add samples to Viewer.
authorjvanverth <jvanverth@google.com>
Mon, 13 Jun 2016 16:31:26 +0000 (09:31 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 13 Jun 2016 16:31:27 +0000 (09:31 -0700)
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

gyp/viewer.gyp
samplecode/ClockFaceView.cpp
samplecode/SampleAtlas.cpp
samplecode/SampleClock.cpp
tools/viewer/SKPSlide.cpp
tools/viewer/SKPSlide.h
tools/viewer/SampleSlide.cpp [new file with mode: 0755]
tools/viewer/SampleSlide.h [new file with mode: 0755]
tools/viewer/Slide.h
tools/viewer/Viewer.cpp

index 1013e070ae0c9bd043c3100232e8a08bd8edd317..c15e1d9f8eb517034455c8eb46341c28e4291081 100644 (file)
       ],
       'include_dirs': [
         '../bench',
+       '../experimental',
         '../gm',
         '../include/views',
         '../include/private',
+       '../samplecode',
         '../src/core',
         '../src/effects',
         '../src/gpu',
-        '../src/images',
         '../src/image',
+        '../src/images',
+        '../src/pathops',
         '../src/views/unix',
         '../tools/timer',
+       '../tools',
       ],
       'sources': [
         '../gm/gm.cpp',
-        '../src/views/SkTouchGesture.cpp',
+
         '../src/views/unix/keysym2ucs.c',
         '<!@(python find.py ../tools/viewer "*.cpp")',
+
+        # Samples
+        '../samplecode/GMSampleView.h',
+        '../samplecode/GMSampleView.cpp',
+        '../samplecode/ClockFaceView.cpp',
+        '../samplecode/OverView.cpp',
+        '../samplecode/OverView.h',
+        '../samplecode/PerlinPatch.cpp',
+        '../samplecode/Sample2PtRadial.cpp',
+        '../samplecode/SampleAAClip.cpp',
+        '../samplecode/SampleAAGeometry.cpp',
+        '../samplecode/SampleAARects.cpp',
+        '../samplecode/SampleAARectModes.cpp',
+        '../samplecode/SampleAll.cpp',
+        '../samplecode/SampleAnimatedText.cpp',
+        '../samplecode/SampleAnimBlur.cpp',
+        '../samplecode/SampleApp.cpp',
+        '../samplecode/SampleArc.cpp',
+        '../samplecode/SampleAtlas.cpp',
+        '../samplecode/SampleBigBlur.cpp',
+        '../samplecode/SampleBigGradient.cpp',
+        '../samplecode/SampleBitmapRect.cpp',
+        '../samplecode/SampleBlur.cpp',
+        '../samplecode/SampleCamera.cpp',
+        '../samplecode/SampleChart.cpp',
+        '../samplecode/SampleCircle.cpp',
+        '../samplecode/SampleClip.cpp',
+        '../samplecode/SampleClipDrawMatch.cpp',
+        '../samplecode/SampleClock.cpp',
+        '../samplecode/SampleCode.h',
+        '../samplecode/SampleColorFilter.cpp',
+        '../samplecode/SampleComplexClip.cpp',
+        '../samplecode/SampleConcavePaths.cpp',
+        '../samplecode/SampleDegenerateTwoPtRadials.cpp',
+        '../samplecode/SampleDither.cpp',
+        '../samplecode/SampleDitherBitmap.cpp',
+        '../samplecode/SampleEffects.cpp',
+        '../samplecode/SampleEmboss.cpp',
+        '../samplecode/SampleFatBits.cpp',
+        '../samplecode/SampleFillType.cpp',
+        '../samplecode/SampleFilter.cpp',
+        '../samplecode/SampleFilter2.cpp',
+        '../samplecode/SampleFilterQuality.cpp',
+        '../samplecode/SampleFilterFuzz.cpp',
+        '../samplecode/SampleFontCache.cpp',
+        '../samplecode/SampleFontScalerTest.cpp',
+        '../samplecode/SampleFuzz.cpp',
+        '../samplecode/SampleGradients.cpp',
+        '../samplecode/SampleHairCurves.cpp',
+        '../samplecode/SampleHairline.cpp',
+        '../samplecode/SampleHairModes.cpp',
+        '../samplecode/SampleHT.cpp',
+        '../samplecode/SampleIdentityScale.cpp',
+        '../samplecode/SampleLayerMask.cpp',
+        '../samplecode/SampleLayers.cpp',
+        '../samplecode/SampleLCD.cpp',
+        '../samplecode/SampleLighting.cpp',
+        '../samplecode/SampleLines.cpp',
+        '../samplecode/SampleLitAtlas.cpp',
+        '../samplecode/SampleLua.cpp',
+        '../samplecode/SampleManyRects.cpp',
+        '../samplecode/SampleMeasure.cpp',
+        '../samplecode/SampleMegaStroke.cpp',
+        '../samplecode/SamplePatch.cpp',
+        '../samplecode/SamplePath.cpp',
+        '../samplecode/SamplePathClip.cpp',
+        '../samplecode/SamplePathFuzz.cpp',
+        '../samplecode/SamplePathEffects.cpp',
+        '../samplecode/SamplePictFile.cpp',
+        '../samplecode/SamplePoints.cpp',
+        '../samplecode/SamplePolyToPoly.cpp',
+        '../samplecode/SampleQuadStroker.cpp',
+        '../samplecode/SampleRectanizer.cpp',
+        '../samplecode/SampleRegion.cpp',
+        '../samplecode/SampleRepeatTile.cpp',
+        '../samplecode/SampleShaders.cpp',
+        '../samplecode/SampleShaderText.cpp',
+        '../samplecode/SampleShip.cpp',
+        '../samplecode/SampleSkLayer.cpp',
+        '../samplecode/SampleSlides.cpp',
+        '../samplecode/SampleStringArt.cpp',
+        '../samplecode/SampleStrokePath.cpp',
+        '../samplecode/SampleSubpixelTranslate.cpp',
+        '../samplecode/SampleText.cpp',
+        '../samplecode/SampleTextAlpha.cpp',
+        '../samplecode/SampleTextBox.cpp',
+        '../samplecode/SampleTextOnPath.cpp',
+        '../samplecode/SampleTextureDomain.cpp',
+        '../samplecode/SampleTiling.cpp',
+        '../samplecode/SampleTinyBitmap.cpp',
+        '../samplecode/SampleUnpremul.cpp',
+        '../samplecode/SampleVertices.cpp',
+        '../samplecode/SampleXfermodesBlur.cpp',
+        '../samplecode/SampleXfer.cpp',
+        '../src/views/SkTouchGesture.cpp',
+       
+        # PerlinNoise2
+        '../experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp',
+        '../experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.h',
+
+       # Lua
+        '../src/utils/SkLuaCanvas.cpp',
+        '../src/utils/SkLua.cpp',
       ],
+      'sources!': [
+        '../samplecode/SampleSkLayer.cpp', #relies on SkMatrix44 which doesn't compile
+        '../samplecode/SampleFontCache.cpp', #relies on pthread.h
+      ],      
       'dependencies': [
+        'experimental.gyp:experimental',
         'flags.gyp:flags',
         'gputest.gyp:skgputest',
         'jsoncpp.gyp:jsoncpp',
+       'lua.gyp:lua',
+        'pdf.gyp:pdf',
         'skia_lib.gyp:skia_lib',
         'tools.gyp:crash_handler',
         'tools.gyp:proc_stats',
         'tools.gyp:sk_tool_utils',
         'tools.gyp:timer',
         'tools.gyp:url_data_manager',
+       'views.gyp:views',
+       'xml.gyp:xml',
       ],
       'conditions' : [
         [ 'skia_os == "android"', {
index ef0fec75774034849bdfe84f243f406a316f9125..9cee95b84c36fd19829afa98faa1df90959f18f6 100644 (file)
@@ -72,7 +72,14 @@ public:
     : Sk2DPathEffect(matrix), fRadius(radius), fPts(pts) {}
 
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Dot2DPathEffect)
-
+    class Registrar {
+    public:
+        Registrar() {
+            SkFlattenable::Register("Dot2DPathEffect",
+                                    Dot2DPathEffect::CreateProc,
+                                    Dot2DPathEffect::GetFlattenableType());
+        }
+    };
 protected:
     void begin(const SkIRect& uvBounds, SkPath* dst) const override {
         if (fPts) {
@@ -101,6 +108,8 @@ private:
     typedef Sk2DPathEffect INHERITED;
 };
 
+static Dot2DPathEffect::Registrar gReg0;
+
 sk_sp<SkFlattenable> Dot2DPathEffect::CreateProc(SkReadBuffer& buffer) {
     SkMatrix matrix;
     buffer.readMatrix(&matrix);
index 7cf1bb376193022114a31278bcbd8fd212ccfda5..3daf312f6a1a623d0a933e1e8087369ef3fe82d0 100644 (file)
@@ -232,9 +232,11 @@ protected:
 
     void onDrawContent(SkCanvas* canvas) override {
         canvas->drawDrawable(fDrawable);
-        this->inval(nullptr);
     }
 
+    bool onAnimate(const SkAnimTimer&) override {
+        return true;
+    }
 #if 0
     // TODO: switch over to use this for our animation
     bool onAnimate(const SkAnimTimer& timer) override {
index ae7462d1dce3466b45348be65e04fe9aea1db14c..ff3a5b19274ae7f73b98f4e1eaf3ceb2352916d4 100644 (file)
@@ -215,8 +215,10 @@ protected:
 #endif
 
         canvas->restore();
+    }
 
-        this->inval(nullptr);
+    bool onAnimate(const SkAnimTimer&) override {
+        return true;
     }
 
 private:
index 6a9899b92fbe29ff01dfaca22ee6130e32847e05..9419253f0c25a2aa4f0a238018e0790bb84c09c3 100644 (file)
@@ -48,7 +48,7 @@ static sk_sp<SkPicture> read_picture(const char path[]) {
     return pic;
 }
 
-void SKPSlide::load() {
+void SKPSlide::load(SkScalar, SkScalar) {
     fPic = read_picture(fPath.c_str());
     fCullRect = fPic->cullRect().roundOut();
 }
index 42845fa30d9ef3f38d82f8f0f495a94d138ee18c..ff92ed1a39b5c01222b3f1349d98759681b00838 100644 (file)
@@ -19,7 +19,7 @@ public:
     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 (executable)
index 0000000..2ae1280
--- /dev/null
@@ -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 (executable)
index 0000000..3d772d0
--- /dev/null
@@ -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
index cdc225b0a8c24b74762d075d6a4f6b21a1353909..bc0ffd40168f900fee49fa847cc6b699878f246e 100644 (file)
@@ -19,11 +19,13 @@ class Slide : public SkRefCnt {
 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; }
index 499673572b4d296541768aafcd1c08e84a3815e8..ca7eddd12dbb4a8c4732df1cfeff49aaa00f413d 100644 (file)
@@ -8,6 +8,7 @@
 #include "Viewer.h"
 
 #include "GMSlide.h"
+#include "SampleSlide.h"
 #include "SKPSlide.h"
 
 #include "SkCanvas.h"
@@ -42,7 +43,6 @@ static void on_ui_state_changed_handler(const SkString& stateName, const SkStrin
 }
 
 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 @@ void Viewer::initSlides() {
         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 @@ void Viewer::setupCurrentSlide(int previousSlide) {
 
     this->updateTitle();
     this->updateUIState();
-    fSlides[fCurrentSlide]->load();
+    fSlides[fCurrentSlide]->load(SkIntToScalar(fWindow->width()), SkIntToScalar(fWindow->height()));
     if (previousSlide >= 0) {
         fSlides[previousSlide]->unload();
     }