blob: be35a885251ad6a7ac1b31892989c8ab7818970d [file] [log] [blame]
jvanverth9f372462016-04-06 06:08:59 -07001/*
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
jvanverth34524262016-05-04 13:49:13 -07008#ifndef Viewer_DEFINED
9#define Viewer_DEFINED
jvanverth9f372462016-04-06 06:08:59 -070010
jvanvertha8d0d6c2016-05-05 12:32:03 -070011#include "sk_app/Application.h"
brianosman622c8d52016-05-10 06:50:49 -070012#include "sk_app/CommandSet.h"
jvanvertha8d0d6c2016-05-05 12:32:03 -070013#include "sk_app/Window.h"
jvanverth9f372462016-04-06 06:08:59 -070014#include "gm.h"
Brian Osmand67e5182017-12-08 16:46:09 -050015#include "ImGuiLayer.h"
jvanverthc265a922016-04-08 12:51:45 -070016#include "SkAnimTimer.h"
Yuqian Lib2ba6642017-11-22 12:07:41 -050017#include "SkExecutor.h"
Brian Osmaneff04b52017-11-21 13:18:02 -050018#include "SkJSONCPP.h"
Ben Wagnera580fb32018-04-17 11:16:32 -040019#include "SkScan.h"
djsollen9207cae2016-06-10 07:50:00 -070020#include "SkTouchGesture.h"
jvanverth2bb3b6d2016-04-08 07:24:09 -070021#include "Slide.h"
Brian Osman56a24812017-12-19 11:15:16 -050022#include "StatsLayer.h"
jvanverth9f372462016-04-06 06:08:59 -070023
24class SkCanvas;
25
Brian Osman80fc07e2017-12-08 16:45:43 -050026class Viewer : public sk_app::Application, sk_app::Window::Layer {
jvanverth9f372462016-04-06 06:08:59 -070027public:
jvanverth34524262016-05-04 13:49:13 -070028 Viewer(int argc, char** argv, void* platformData);
29 ~Viewer() override;
jvanverth9f372462016-04-06 06:08:59 -070030
liyuqian2edb0f42016-07-06 14:11:32 -070031 void onIdle() override;
Brian Osman80fc07e2017-12-08 16:45:43 -050032
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 Osman80fc07e2017-12-08 16:45:43 -050037 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;
jvanverth9f372462016-04-06 06:08:59 -070040
Ben Wagnerabdcc5f2018-02-12 16:37:28 -050041 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 Wagnera580fb32018-04-17 11:16:32 -040067 const bool fOriginalSkUseAnalyticAA = gSkUseAnalyticAA;
68 const bool fOriginalSkForceAnalyticAA = gSkForceAnalyticAA;
69 const bool fOriginalSkUseDeltaAA = gSkUseDeltaAA;
70 const bool fOriginalSkForceDeltaAA = gSkForceDeltaAA;
Ben Wagnerabdcc5f2018-02-12 16:37:28 -050071
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 };
jvanverth9f372462016-04-06 06:08:59 -070080private:
Brian Osman92004802017-03-06 11:47:26 -050081 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
jvanverth2bb3b6d2016-04-08 07:24:09 -070088 void initSlides();
brianosman05de2162016-05-06 13:28:57 -070089 void updateTitle();
Brian Osman621491e2017-02-28 15:45:01 -050090 void setBackend(sk_app::Window::BackendType);
Brian Osman92004802017-03-06 11:47:26 -050091 void setColorMode(ColorMode);
Florin Malitaab99c342018-01-16 16:23:03 -050092 int startupSlide() const;
93 void setCurrentSlide(int);
94 void setupCurrentSlide();
95 void listNames() const;
jvanverth2bb3b6d2016-04-08 07:24:09 -070096
liyuqiane5a6cd92016-05-27 08:52:52 -070097 void updateUIState();
98
Brian Osmanf750fbc2017-02-08 10:47:28 -050099 void drawSlide(SkCanvas* canvs);
Brian Osmand67e5182017-12-08 16:46:09 -0500100 void drawImGui();
jvanverth3d6ed3a2016-04-07 11:09:51 -0700101
jvanverthc265a922016-04-08 12:51:45 -0700102 void changeZoomLevel(float delta);
Ben Wagnerd02a74d2018-04-23 12:55:06 -0400103 void preTouchMatrixChanged();
Yuqian Li755778c2018-03-28 16:23:31 -0400104 SkMatrix computePreTouchMatrix();
liyuqiand3cdbca2016-05-17 12:44:20 -0700105 SkMatrix computeMatrix();
Florin Malitacefc1b92018-02-19 21:43:47 -0500106 SkPoint mapEvent(float x, float y);
jvanverthc265a922016-04-08 12:51:45 -0700107
Yuqian Lib2ba6642017-11-22 12:07:41 -0500108 void resetExecutor() {
109 fExecutor = SkExecutor::MakeFIFOThreadPool(fThreadCnt == 0 ? fTileCnt : fThreadCnt);
110 }
111
jvanverth34524262016-05-04 13:49:13 -0700112 sk_app::Window* fWindow;
jvanverth9f372462016-04-06 06:08:59 -0700113
Brian Osman56a24812017-12-19 11:15:16 -0500114 StatsLayer fStatsLayer;
115 StatsLayer::Timer fPaintTimer;
116 StatsLayer::Timer fFlushTimer;
117 StatsLayer::Timer fAnimateTimer;
jvanverth3d6ed3a2016-04-07 11:09:51 -0700118
jvanverthc265a922016-04-08 12:51:45 -0700119 SkAnimTimer fAnimTimer;
jvanverth2bb3b6d2016-04-08 07:24:09 -0700120 SkTArray<sk_sp<Slide>> fSlides;
121 int fCurrentSlide;
jvanverthc265a922016-04-08 12:51:45 -0700122
liyuqian2edb0f42016-07-06 14:11:32 -0700123 bool fRefresh; // whether to continuously refresh for measuring render time
jvanverthc265a922016-04-08 12:51:45 -0700124
Brian Osman3ac99cf2017-12-01 11:23:53 -0500125 bool fSaveToSKP;
126
Brian Osmand67e5182017-12-08 16:46:09 -0500127 ImGuiLayer fImGuiLayer;
Brian Osmana109e392017-02-24 09:49:14 -0500128 SkPaint fImGuiGamutPaint;
Brian Osman79086b92017-02-10 13:36:16 -0500129 bool fShowImGuiDebugWindow;
Brian Osmanfce09c52017-11-14 15:32:20 -0500130 bool fShowSlidePicker;
Brian Osman79086b92017-02-10 13:36:16 -0500131 bool fShowImGuiTestWindow;
132
Brian Osmanf6877092017-02-13 09:39:57 -0500133 bool fShowZoomWindow;
134 sk_sp<SkImage> fLastImage;
135
jvanverthaf236b52016-05-20 06:01:06 -0700136 sk_app::Window::BackendType fBackendType;
137
Brian Osmanf750fbc2017-02-08 10:47:28 -0500138 // Color properties for slide rendering
Brian Osman92004802017-03-06 11:47:26 -0500139 ColorMode fColorMode;
Brian Osmana109e392017-02-24 09:49:14 -0500140 SkColorSpacePrimaries fColorSpacePrimaries;
Brian Osmanfdab5762017-11-09 10:27:55 -0500141 SkColorSpaceTransferFn fColorSpaceTransferFn;
Brian Osmanf750fbc2017-02-08 10:47:28 -0500142
jvanverthc265a922016-04-08 12:51:45 -0700143 // transform data
jvanverthc265a922016-04-08 12:51:45 -0700144 SkScalar fZoomLevel;
Ben Wagnerd02a74d2018-04-23 12:55:06 -0400145 SkScalar fRotation;
jvanverthc265a922016-04-08 12:51:45 -0700146
brianosman622c8d52016-05-10 06:50:49 -0700147 sk_app::CommandSet fCommands;
liyuqiand3cdbca2016-05-17 12:44:20 -0700148
Brian Osmanb53f48c2017-06-07 10:00:30 -0400149 enum class GestureDevice {
150 kNone,
151 kTouch,
152 kMouse,
153 };
154
liyuqiand3cdbca2016-05-17 12:44:20 -0700155 SkTouchGesture fGesture;
Brian Osmanb53f48c2017-06-07 10:00:30 -0400156 GestureDevice fGestureDevice;
liyuqiane46e4f02016-05-20 07:32:19 -0700157
158 // identity unless the window initially scales the content to fit the screen.
159 SkMatrix fDefaultMatrix;
liyuqian1f508fd2016-06-07 06:57:40 -0700160
Brian Osman9bb47cf2018-04-26 15:55:00 -0400161 bool fPerspective;
162 SkPoint fPerspectivePoints[4];
163
Brian Osmanfd8f4d52017-02-24 11:57:23 -0500164 SkTArray<std::function<void(void)>> fDeferredActions;
165
liyuqian1f508fd2016-06-07 06:57:40 -0700166 Json::Value fAllSlideNames; // cache all slide names for fast updateUIState
Yuqian Lib2ba6642017-11-22 12:07:41 -0500167
168 int fTileCnt;
169 int fThreadCnt;
170 std::unique_ptr<SkExecutor> fExecutor;
Ben Wagnerabdcc5f2018-02-12 16:37:28 -0500171
172 SkPaint fPaint;
173 SkPaintFields fPaintOverrides;
Ben Wagner37c54032018-04-13 14:30:23 -0400174 bool fPixelGeometryOverrides = false;
jvanverth9f372462016-04-06 06:08:59 -0700175};
176
177
178#endif