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 | |
Christopher Dalton | 443ec1b | 2017-02-24 13:22:53 -0700 | [diff] [blame] | 26 | void onBackendCreated(); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 27 | void onPaint(SkCanvas* canvas); |
liyuqian | 2edb0f4 | 2016-07-06 14:11:32 -0700 | [diff] [blame] | 28 | void onIdle() override; |
jvanverth | 814e38d | 2016-06-06 08:48:47 -0700 | [diff] [blame] | 29 | bool onTouch(intptr_t owner, sk_app::Window::InputState state, float x, float y); |
Jim Van Verth | e770578 | 2017-05-04 14:00:59 -0400 | [diff] [blame] | 30 | bool onMouse(float x, float y, sk_app::Window::InputState state, uint32_t modifiers); |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 31 | void onUIStateChanged(const SkString& stateName, const SkString& stateValue); |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 32 | bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers); |
| 33 | bool onChar(SkUnichar c, uint32_t modifiers); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 34 | |
| 35 | private: |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 36 | enum class ColorMode { |
| 37 | kLegacy, // N32, no color management |
| 38 | kColorManagedSRGB8888_NonLinearBlending, // N32, sRGB transfer function, nonlinear blending |
| 39 | kColorManagedSRGB8888, // N32, sRGB transfer function, linear blending |
| 40 | kColorManagedLinearF16, // F16, linear transfer function, linear blending |
| 41 | }; |
| 42 | |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 43 | void initSlides(); |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 44 | void updateTitle(); |
Brian Osman | 621491e | 2017-02-28 15:45:01 -0500 | [diff] [blame] | 45 | void setBackend(sk_app::Window::BackendType); |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 46 | void setColorMode(ColorMode); |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 47 | void setStartupSlide(); |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 48 | void setupCurrentSlide(int previousSlide); |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 49 | void listNames(); |
Jim Van Verth | 90dcce5 | 2017-11-03 13:36:07 -0400 | [diff] [blame] | 50 | void resetMeasurements(); |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 51 | |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 52 | void updateUIState(); |
| 53 | |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 54 | void drawSlide(SkCanvas* canvs); |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 55 | void drawStats(SkCanvas* canvas); |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 56 | void drawImGui(SkCanvas* canvas); |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 57 | |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 58 | void changeZoomLevel(float delta); |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 59 | SkMatrix computeMatrix(); |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 60 | |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 61 | sk_app::Window* fWindow; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 62 | |
Jim Van Verth | 90dcce5 | 2017-11-03 13:36:07 -0400 | [diff] [blame] | 63 | static const int kMeasurementCount = 1 << 6; // should be power of 2 for fast mod |
Brian Osman | 1df161a | 2017-02-09 12:10:20 -0500 | [diff] [blame] | 64 | double fPaintTimes[kMeasurementCount]; |
| 65 | double fFlushTimes[kMeasurementCount]; |
| 66 | double fAnimateTimes[kMeasurementCount]; |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 67 | int fCurrentMeasurement; |
Jim Van Verth | 90dcce5 | 2017-11-03 13:36:07 -0400 | [diff] [blame] | 68 | double fCumulativeMeasurementTime; |
| 69 | int fCumulativeMeasurementCount; |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 70 | |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 71 | SkAnimTimer fAnimTimer; |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 72 | SkTArray<sk_sp<Slide>> fSlides; |
| 73 | int fCurrentSlide; |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 74 | |
| 75 | bool fDisplayStats; |
liyuqian | 2edb0f4 | 2016-07-06 14:11:32 -0700 | [diff] [blame] | 76 | bool fRefresh; // whether to continuously refresh for measuring render time |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 77 | |
Brian Osman | f687709 | 2017-02-13 09:39:57 -0500 | [diff] [blame] | 78 | SkPaint fImGuiFontPaint; |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 79 | SkPaint fImGuiGamutPaint; |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 80 | bool fShowImGuiDebugWindow; |
Brian Osman | fce09c5 | 2017-11-14 15:32:20 -0500 | [diff] [blame] | 81 | bool fShowSlidePicker; |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 82 | bool fShowImGuiTestWindow; |
| 83 | |
Brian Osman | f687709 | 2017-02-13 09:39:57 -0500 | [diff] [blame] | 84 | bool fShowZoomWindow; |
| 85 | sk_sp<SkImage> fLastImage; |
| 86 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 87 | sk_app::Window::BackendType fBackendType; |
| 88 | |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 89 | // Color properties for slide rendering |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 90 | ColorMode fColorMode; |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 91 | SkColorSpacePrimaries fColorSpacePrimaries; |
Brian Osman | fdab576 | 2017-11-09 10:27:55 -0500 | [diff] [blame] | 92 | SkColorSpaceTransferFn fColorSpaceTransferFn; |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 93 | |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 94 | // transform data |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 95 | SkScalar fZoomLevel; |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 96 | |
brianosman | 622c8d5 | 2016-05-10 06:50:49 -0700 | [diff] [blame] | 97 | sk_app::CommandSet fCommands; |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 98 | |
Brian Osman | b53f48c | 2017-06-07 10:00:30 -0400 | [diff] [blame] | 99 | enum class GestureDevice { |
| 100 | kNone, |
| 101 | kTouch, |
| 102 | kMouse, |
| 103 | }; |
| 104 | |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 105 | SkTouchGesture fGesture; |
Brian Osman | b53f48c | 2017-06-07 10:00:30 -0400 | [diff] [blame] | 106 | GestureDevice fGestureDevice; |
liyuqian | e46e4f0 | 2016-05-20 07:32:19 -0700 | [diff] [blame] | 107 | |
| 108 | // identity unless the window initially scales the content to fit the screen. |
| 109 | SkMatrix fDefaultMatrix; |
liyuqian | 1f508fd | 2016-06-07 06:57:40 -0700 | [diff] [blame] | 110 | |
Brian Osman | fd8f4d5 | 2017-02-24 11:57:23 -0500 | [diff] [blame] | 111 | SkTArray<std::function<void(void)>> fDeferredActions; |
| 112 | |
liyuqian | 1f508fd | 2016-06-07 06:57:40 -0700 | [diff] [blame] | 113 | Json::Value fAllSlideNames; // cache all slide names for fast updateUIState |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | |
| 117 | #endif |