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); |
liyuqian | 2edb0f4 | 2016-07-06 14:11:32 -0700 | [diff] [blame] | 27 | void onIdle() 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); |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 30 | bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers); |
| 31 | bool onChar(SkUnichar c, uint32_t modifiers); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 32 | |
| 33 | private: |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 34 | void initSlides(); |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 35 | void updateTitle(); |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 36 | void setColorMode(SkColorType, sk_sp<SkColorSpace>); |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame^] | 37 | void setStartupSlide(); |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 38 | void setupCurrentSlide(int previousSlide); |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame^] | 39 | void listNames(); |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 40 | |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 41 | void updateUIState(); |
| 42 | |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 43 | void drawSlide(SkCanvas* canvs); |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 44 | void drawStats(SkCanvas* canvas); |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 45 | void drawImGui(SkCanvas* canvas); |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 46 | |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 47 | void changeZoomLevel(float delta); |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 48 | SkMatrix computeMatrix(); |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 49 | |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 50 | sk_app::Window* fWindow; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 51 | |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 52 | static const int kMeasurementCount = 64; // should be power of 2 for fast mod |
Brian Osman | 1df161a | 2017-02-09 12:10:20 -0500 | [diff] [blame] | 53 | double fPaintTimes[kMeasurementCount]; |
| 54 | double fFlushTimes[kMeasurementCount]; |
| 55 | double fAnimateTimes[kMeasurementCount]; |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 56 | int fCurrentMeasurement; |
| 57 | |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 58 | SkAnimTimer fAnimTimer; |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 59 | SkTArray<sk_sp<Slide>> fSlides; |
| 60 | int fCurrentSlide; |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame^] | 61 | bool fSetupFirstFrame; |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 62 | |
| 63 | bool fDisplayStats; |
liyuqian | 2edb0f4 | 2016-07-06 14:11:32 -0700 | [diff] [blame] | 64 | bool fRefresh; // whether to continuously refresh for measuring render time |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 65 | |
Brian Osman | f687709 | 2017-02-13 09:39:57 -0500 | [diff] [blame] | 66 | SkPaint fImGuiFontPaint; |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 67 | bool fShowImGuiDebugWindow; |
| 68 | bool fShowImGuiTestWindow; |
| 69 | |
Brian Osman | f687709 | 2017-02-13 09:39:57 -0500 | [diff] [blame] | 70 | bool fShowZoomWindow; |
| 71 | sk_sp<SkImage> fLastImage; |
| 72 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 73 | sk_app::Window::BackendType fBackendType; |
| 74 | |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 75 | // Color properties for slide rendering |
| 76 | SkColorType fColorType; |
| 77 | sk_sp<SkColorSpace> fColorSpace; |
| 78 | |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 79 | // transform data |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 80 | SkScalar fZoomCenterX; |
| 81 | SkScalar fZoomCenterY; |
| 82 | SkScalar fZoomLevel; |
| 83 | SkScalar fZoomScale; |
| 84 | |
brianosman | 622c8d5 | 2016-05-10 06:50:49 -0700 | [diff] [blame] | 85 | sk_app::CommandSet fCommands; |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 86 | |
| 87 | SkTouchGesture fGesture; |
liyuqian | e46e4f0 | 2016-05-20 07:32:19 -0700 | [diff] [blame] | 88 | |
| 89 | // identity unless the window initially scales the content to fit the screen. |
| 90 | SkMatrix fDefaultMatrix; |
| 91 | SkMatrix fDefaultMatrixInv; |
liyuqian | 1f508fd | 2016-06-07 06:57:40 -0700 | [diff] [blame] | 92 | |
| 93 | Json::Value fAllSlideNames; // cache all slide names for fast updateUIState |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | |
| 97 | #endif |