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