From: jvanverth Date: Mon, 13 Jun 2016 16:31:26 +0000 (-0700) Subject: Add samples to Viewer. X-Git-Tag: submit/tizen/20180928.044319~129^2~210 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=76963e73704a42a18c29d6fbdcccb566e5c67658;p=platform%2Fupstream%2FlibSkiaSharp.git 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/gyp/viewer.gyp b/gyp/viewer.gyp index 1013e070ae..c15e1d9f8e 100644 --- a/gyp/viewer.gyp +++ b/gyp/viewer.gyp @@ -17,27 +17,141 @@ ], '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', ' Dot2DPathEffect::CreateProc(SkReadBuffer& buffer) { SkMatrix matrix; buffer.readMatrix(&matrix); diff --git a/samplecode/SampleAtlas.cpp b/samplecode/SampleAtlas.cpp index 7cf1bb3761..3daf312f6a 100644 --- a/samplecode/SampleAtlas.cpp +++ b/samplecode/SampleAtlas.cpp @@ -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 { diff --git a/samplecode/SampleClock.cpp b/samplecode/SampleClock.cpp index ae7462d1dc..ff3a5b1927 100644 --- a/samplecode/SampleClock.cpp +++ b/samplecode/SampleClock.cpp @@ -215,8 +215,10 @@ protected: #endif canvas->restore(); + } - this->inval(nullptr); + bool onAnimate(const SkAnimTimer&) override { + return true; } private: 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 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(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(); }