diff options
author | jvanverth <jvanverth@google.com> | 2016-06-13 09:31:26 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-13 09:31:27 -0700 |
commit | 76963e73704a42a18c29d6fbdcccb566e5c67658 (patch) | |
tree | e007527879859f5c1857bd9bf3c2c3df32a1fd4c /tools | |
parent | fe19987e5499650e8637a8d109f19b8156601660 (diff) |
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
Diffstat (limited to 'tools')
-rw-r--r-- | tools/viewer/SKPSlide.cpp | 2 | ||||
-rw-r--r-- | tools/viewer/SKPSlide.h | 2 | ||||
-rwxr-xr-x | tools/viewer/SampleSlide.cpp | 37 | ||||
-rwxr-xr-x | tools/viewer/SampleSlide.h | 34 | ||||
-rw-r--r-- | tools/viewer/Slide.h | 6 | ||||
-rw-r--r-- | tools/viewer/Viewer.cpp | 12 |
6 files changed, 87 insertions, 6 deletions
diff --git a/tools/viewer/SKPSlide.cpp b/tools/viewer/SKPSlide.cpp index 6a9899b92f..9419253f0c 100644 --- a/tools/viewer/SKPSlide.cpp +++ b/tools/viewer/SKPSlide.cpp @@ -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(); } diff --git a/tools/viewer/SKPSlide.h b/tools/viewer/SKPSlide.h index 42845fa30d..ff92ed1a39 100644 --- a/tools/viewer/SKPSlide.h +++ b/tools/viewer/SKPSlide.h @@ -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 index 0000000000..2ae1280dc3 --- /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 0000000000..3d772d093d --- /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 cdc225b0a8..bc0ffd4016 100644 --- a/tools/viewer/Slide.h +++ b/tools/viewer/Slide.h @@ -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; } diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp index 499673572b..ca7eddd12d 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 @@ 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(); } |