jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 8 | #ifndef Viewer_DEFINED |
| 9 | #define Viewer_DEFINED |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 10 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 11 | #include "sk_app/Application.h" |
brianosman | 622c8d5 | 2016-05-10 06:50:49 -0700 | [diff] [blame] | 12 | #include "sk_app/CommandSet.h" |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 13 | #include "sk_app/Window.h" |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 14 | #include "gm.h" |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 15 | #include "SkAnimTimer.h" |
djsollen | 9207cae | 2016-06-10 07:50:00 -0700 | [diff] [blame] | 16 | #include "SkTouchGesture.h" |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 17 | #include "Slide.h" |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 18 | |
| 19 | class SkCanvas; |
| 20 | |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 21 | class Viewer : public sk_app::Application { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 22 | public: |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 23 | Viewer(int argc, char** argv, void* platformData); |
| 24 | ~Viewer() override; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 25 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 26 | void onPaint(SkCanvas* canvas); |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 27 | void onIdle(double ms) override; |
jvanverth | 814e38d | 2016-06-06 08:48:47 -0700 | [diff] [blame] | 28 | bool onTouch(intptr_t owner, sk_app::Window::InputState state, float x, float y); |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 29 | void onUIStateChanged(const SkString& stateName, const SkString& stateValue); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 30 | |
| 31 | private: |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 32 | void initSlides(); |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 33 | void updateTitle(); |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 34 | void setupCurrentSlide(int previousSlide); |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 35 | |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 36 | void updateUIState(); |
| 37 | |
liyuqian | 6f163d2 | 2016-06-13 12:26:45 -0700 | [diff] [blame] | 38 | void drawSlide(SkCanvas* canvs, bool inSplitScreen); |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 39 | void drawStats(SkCanvas* canvas); |
| 40 | |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 41 | void changeZoomLevel(float delta); |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 42 | SkMatrix computeMatrix(); |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 43 | |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 44 | sk_app::Window* fWindow; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 45 | |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 46 | static const int kMeasurementCount = 64; // should be power of 2 for fast mod |
| 47 | double fMeasurements[kMeasurementCount]; |
| 48 | int fCurrentMeasurement; |
| 49 | |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 50 | SkAnimTimer fAnimTimer; |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 51 | SkTArray<sk_sp<Slide>> fSlides; |
| 52 | int fCurrentSlide; |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 53 | |
| 54 | bool fDisplayStats; |
| 55 | |
liyuqian | 6f163d2 | 2016-06-13 12:26:45 -0700 | [diff] [blame] | 56 | // whether to split the screen and draw two copies of the slide, one with sRGB and one without |
| 57 | bool fSplitScreen; |
| 58 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 59 | sk_app::Window::BackendType fBackendType; |
| 60 | |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 61 | // transform data |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 62 | SkScalar fZoomCenterX; |
| 63 | SkScalar fZoomCenterY; |
| 64 | SkScalar fZoomLevel; |
| 65 | SkScalar fZoomScale; |
| 66 | |
brianosman | 622c8d5 | 2016-05-10 06:50:49 -0700 | [diff] [blame] | 67 | sk_app::CommandSet fCommands; |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 68 | |
| 69 | SkTouchGesture fGesture; |
liyuqian | e46e4f0 | 2016-05-20 07:32:19 -0700 | [diff] [blame] | 70 | |
| 71 | // identity unless the window initially scales the content to fit the screen. |
| 72 | SkMatrix fDefaultMatrix; |
| 73 | SkMatrix fDefaultMatrixInv; |
liyuqian | 1f508fd | 2016-06-07 06:57:40 -0700 | [diff] [blame] | 74 | |
| 75 | Json::Value fAllSlideNames; // cache all slide names for fast updateUIState |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | |
| 79 | #endif |