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" |
Ben Wagner | a580fb3 | 2018-04-17 11:16:32 -0400 | [diff] [blame] | 19 | #include "SkScan.h" |
djsollen | 9207cae | 2016-06-10 07:50:00 -0700 | [diff] [blame] | 20 | #include "SkTouchGesture.h" |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 21 | #include "Slide.h" |
Brian Osman | 56a2481 | 2017-12-19 11:15:16 -0500 | [diff] [blame] | 22 | #include "StatsLayer.h" |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 23 | |
| 24 | class SkCanvas; |
| 25 | |
Brian Osman | 80fc07e | 2017-12-08 16:45:43 -0500 | [diff] [blame] | 26 | class Viewer : public sk_app::Application, sk_app::Window::Layer { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 27 | public: |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 28 | Viewer(int argc, char** argv, void* platformData); |
| 29 | ~Viewer() override; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 30 | |
liyuqian | 2edb0f4 | 2016-07-06 14:11:32 -0700 | [diff] [blame] | 31 | void onIdle() override; |
Brian Osman | 80fc07e | 2017-12-08 16:45:43 -0500 | [diff] [blame] | 32 | |
| 33 | void onBackendCreated() override; |
| 34 | void onPaint(SkCanvas* canvas) override; |
| 35 | bool onTouch(intptr_t owner, sk_app::Window::InputState state, float x, float y) override; |
| 36 | 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] | 37 | void onUIStateChanged(const SkString& stateName, const SkString& stateValue) override; |
| 38 | bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers) override; |
| 39 | bool onChar(SkUnichar c, uint32_t modifiers) override; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 40 | |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 41 | struct SkPaintFields { |
| 42 | bool fTypeface = false; |
| 43 | bool fPathEffect = false; |
| 44 | bool fShader = false; |
| 45 | bool fMaskFilter = false; |
| 46 | bool fColorFilter = false; |
| 47 | bool fDrawLooper = false; |
| 48 | bool fImageFilter = false; |
| 49 | |
| 50 | bool fTextSize = false; |
| 51 | bool fTextScaleX = false; |
| 52 | bool fTextSkewX = false; |
| 53 | bool fColor = false; |
| 54 | bool fWidth = false; |
| 55 | bool fMiterLimit = false; |
| 56 | bool fBlendMode = false; |
| 57 | |
| 58 | uint32_t fFlags = 0; |
| 59 | enum class AntiAliasState { |
| 60 | Alias, |
| 61 | Normal, |
| 62 | AnalyticAAEnabled, |
| 63 | AnalyticAAForced, |
| 64 | DeltaAAEnabled, |
| 65 | DeltaAAForced, |
| 66 | } fAntiAlias = AntiAliasState::Alias; |
Ben Wagner | a580fb3 | 2018-04-17 11:16:32 -0400 | [diff] [blame] | 67 | const bool fOriginalSkUseAnalyticAA = gSkUseAnalyticAA; |
| 68 | const bool fOriginalSkForceAnalyticAA = gSkForceAnalyticAA; |
| 69 | const bool fOriginalSkUseDeltaAA = gSkUseDeltaAA; |
| 70 | const bool fOriginalSkForceDeltaAA = gSkForceDeltaAA; |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 71 | |
| 72 | bool fTextAlign = false; |
| 73 | bool fCapType = false; |
| 74 | bool fJoinType = false; |
| 75 | bool fStyle = false; |
| 76 | bool fTextEncoding = false; |
| 77 | bool fHinting = false; |
| 78 | bool fFilterQuality = false; |
| 79 | }; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 80 | private: |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 81 | enum class ColorMode { |
| 82 | kLegacy, // N32, no color management |
| 83 | kColorManagedSRGB8888_NonLinearBlending, // N32, sRGB transfer function, nonlinear blending |
| 84 | kColorManagedSRGB8888, // N32, sRGB transfer function, linear blending |
| 85 | kColorManagedLinearF16, // F16, linear transfer function, linear blending |
| 86 | }; |
| 87 | |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 88 | void initSlides(); |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 89 | void updateTitle(); |
Brian Osman | 621491e | 2017-02-28 15:45:01 -0500 | [diff] [blame] | 90 | void setBackend(sk_app::Window::BackendType); |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 91 | void setColorMode(ColorMode); |
Florin Malita | ab99c34 | 2018-01-16 16:23:03 -0500 | [diff] [blame] | 92 | int startupSlide() const; |
| 93 | void setCurrentSlide(int); |
| 94 | void setupCurrentSlide(); |
| 95 | void listNames() const; |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 96 | |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 97 | void updateUIState(); |
| 98 | |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 99 | void drawSlide(SkCanvas* canvs); |
Brian Osman | d67e518 | 2017-12-08 16:46:09 -0500 | [diff] [blame] | 100 | void drawImGui(); |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 101 | |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 102 | void changeZoomLevel(float delta); |
Ben Wagner | d02a74d | 2018-04-23 12:55:06 -0400 | [diff] [blame] | 103 | void preTouchMatrixChanged(); |
Yuqian Li | 755778c | 2018-03-28 16:23:31 -0400 | [diff] [blame] | 104 | SkMatrix computePreTouchMatrix(); |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 105 | SkMatrix computeMatrix(); |
Florin Malita | cefc1b9 | 2018-02-19 21:43:47 -0500 | [diff] [blame] | 106 | SkPoint mapEvent(float x, float y); |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 107 | |
Yuqian Li | b2ba664 | 2017-11-22 12:07:41 -0500 | [diff] [blame] | 108 | void resetExecutor() { |
| 109 | fExecutor = SkExecutor::MakeFIFOThreadPool(fThreadCnt == 0 ? fTileCnt : fThreadCnt); |
| 110 | } |
| 111 | |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 112 | sk_app::Window* fWindow; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 113 | |
Brian Osman | 56a2481 | 2017-12-19 11:15:16 -0500 | [diff] [blame] | 114 | StatsLayer fStatsLayer; |
| 115 | StatsLayer::Timer fPaintTimer; |
| 116 | StatsLayer::Timer fFlushTimer; |
| 117 | StatsLayer::Timer fAnimateTimer; |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 118 | |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 119 | SkAnimTimer fAnimTimer; |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 120 | SkTArray<sk_sp<Slide>> fSlides; |
| 121 | int fCurrentSlide; |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 122 | |
liyuqian | 2edb0f4 | 2016-07-06 14:11:32 -0700 | [diff] [blame] | 123 | bool fRefresh; // whether to continuously refresh for measuring render time |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 124 | |
Brian Osman | 3ac99cf | 2017-12-01 11:23:53 -0500 | [diff] [blame] | 125 | bool fSaveToSKP; |
| 126 | |
Brian Osman | d67e518 | 2017-12-08 16:46:09 -0500 | [diff] [blame] | 127 | ImGuiLayer fImGuiLayer; |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 128 | SkPaint fImGuiGamutPaint; |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 129 | bool fShowImGuiDebugWindow; |
Brian Osman | fce09c5 | 2017-11-14 15:32:20 -0500 | [diff] [blame] | 130 | bool fShowSlidePicker; |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 131 | bool fShowImGuiTestWindow; |
| 132 | |
Brian Osman | f687709 | 2017-02-13 09:39:57 -0500 | [diff] [blame] | 133 | bool fShowZoomWindow; |
| 134 | sk_sp<SkImage> fLastImage; |
| 135 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 136 | sk_app::Window::BackendType fBackendType; |
| 137 | |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 138 | // Color properties for slide rendering |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 139 | ColorMode fColorMode; |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 140 | SkColorSpacePrimaries fColorSpacePrimaries; |
Brian Osman | fdab576 | 2017-11-09 10:27:55 -0500 | [diff] [blame] | 141 | SkColorSpaceTransferFn fColorSpaceTransferFn; |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 142 | |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 143 | // transform data |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 144 | SkScalar fZoomLevel; |
Ben Wagner | d02a74d | 2018-04-23 12:55:06 -0400 | [diff] [blame] | 145 | SkScalar fRotation; |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 146 | |
brianosman | 622c8d5 | 2016-05-10 06:50:49 -0700 | [diff] [blame] | 147 | sk_app::CommandSet fCommands; |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 148 | |
Brian Osman | b53f48c | 2017-06-07 10:00:30 -0400 | [diff] [blame] | 149 | enum class GestureDevice { |
| 150 | kNone, |
| 151 | kTouch, |
| 152 | kMouse, |
| 153 | }; |
| 154 | |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 155 | SkTouchGesture fGesture; |
Brian Osman | b53f48c | 2017-06-07 10:00:30 -0400 | [diff] [blame] | 156 | GestureDevice fGestureDevice; |
liyuqian | e46e4f0 | 2016-05-20 07:32:19 -0700 | [diff] [blame] | 157 | |
| 158 | // identity unless the window initially scales the content to fit the screen. |
| 159 | SkMatrix fDefaultMatrix; |
liyuqian | 1f508fd | 2016-06-07 06:57:40 -0700 | [diff] [blame] | 160 | |
Brian Osman | 9bb47cf | 2018-04-26 15:55:00 -0400 | [diff] [blame] | 161 | bool fPerspective; |
| 162 | SkPoint fPerspectivePoints[4]; |
| 163 | |
Brian Osman | fd8f4d5 | 2017-02-24 11:57:23 -0500 | [diff] [blame] | 164 | SkTArray<std::function<void(void)>> fDeferredActions; |
| 165 | |
liyuqian | 1f508fd | 2016-06-07 06:57:40 -0700 | [diff] [blame] | 166 | Json::Value fAllSlideNames; // cache all slide names for fast updateUIState |
Yuqian Li | b2ba664 | 2017-11-22 12:07:41 -0500 | [diff] [blame] | 167 | |
| 168 | int fTileCnt; |
| 169 | int fThreadCnt; |
| 170 | std::unique_ptr<SkExecutor> fExecutor; |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 171 | |
| 172 | SkPaint fPaint; |
| 173 | SkPaintFields fPaintOverrides; |
Ben Wagner | 37c5403 | 2018-04-13 14:30:23 -0400 | [diff] [blame] | 174 | bool fPixelGeometryOverrides = false; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 175 | }; |
| 176 | |
| 177 | |
| 178 | #endif |