blob: e4679e4f4b42b1f7c24c4c0317d89c7cb78c856f [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"
djsollen9207cae2016-06-10 07:50:00 -070019#include "SkTouchGesture.h"
jvanverth2bb3b6d2016-04-08 07:24:09 -070020#include "Slide.h"
Brian Osman56a24812017-12-19 11:15:16 -050021#include "StatsLayer.h"
jvanverth9f372462016-04-06 06:08:59 -070022
23class SkCanvas;
24
Brian Osman80fc07e2017-12-08 16:45:43 -050025class Viewer : public sk_app::Application, sk_app::Window::Layer {
jvanverth9f372462016-04-06 06:08:59 -070026public:
jvanverth34524262016-05-04 13:49:13 -070027 Viewer(int argc, char** argv, void* platformData);
28 ~Viewer() override;
jvanverth9f372462016-04-06 06:08:59 -070029
liyuqian2edb0f42016-07-06 14:11:32 -070030 void onIdle() override;
Brian Osman80fc07e2017-12-08 16:45:43 -050031
32 void onBackendCreated() override;
33 void onPaint(SkCanvas* canvas) override;
34 bool onTouch(intptr_t owner, sk_app::Window::InputState state, float x, float y) override;
35 bool onMouse(int x, int y, sk_app::Window::InputState state, uint32_t modifiers) override;
Brian Osman80fc07e2017-12-08 16:45:43 -050036 void onUIStateChanged(const SkString& stateName, const SkString& stateValue) override;
37 bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers) override;
38 bool onChar(SkUnichar c, uint32_t modifiers) override;
jvanverth9f372462016-04-06 06:08:59 -070039
Ben Wagnerabdcc5f2018-02-12 16:37:28 -050040 struct SkPaintFields {
41 bool fTypeface = false;
42 bool fPathEffect = false;
43 bool fShader = false;
44 bool fMaskFilter = false;
45 bool fColorFilter = false;
46 bool fDrawLooper = false;
47 bool fImageFilter = false;
48
49 bool fTextSize = false;
50 bool fTextScaleX = false;
51 bool fTextSkewX = false;
52 bool fColor = false;
53 bool fWidth = false;
54 bool fMiterLimit = false;
55 bool fBlendMode = false;
56
57 uint32_t fFlags = 0;
58 enum class AntiAliasState {
59 Alias,
60 Normal,
61 AnalyticAAEnabled,
62 AnalyticAAForced,
63 DeltaAAEnabled,
64 DeltaAAForced,
65 } fAntiAlias = AntiAliasState::Alias;
66 bool fOriginalSkUseAnalyticAA = false;
67 bool fOriginalSkForceAnalyticAA = false;
68 bool fOriginalSkUseDeltaAA = false;
69 bool fOriginalSkForceDeltaAA = false;
70
71 bool fTextAlign = false;
72 bool fCapType = false;
73 bool fJoinType = false;
74 bool fStyle = false;
75 bool fTextEncoding = false;
76 bool fHinting = false;
77 bool fFilterQuality = false;
78 };
jvanverth9f372462016-04-06 06:08:59 -070079private:
Brian Osman92004802017-03-06 11:47:26 -050080 enum class ColorMode {
81 kLegacy, // N32, no color management
82 kColorManagedSRGB8888_NonLinearBlending, // N32, sRGB transfer function, nonlinear blending
83 kColorManagedSRGB8888, // N32, sRGB transfer function, linear blending
84 kColorManagedLinearF16, // F16, linear transfer function, linear blending
85 };
86
jvanverth2bb3b6d2016-04-08 07:24:09 -070087 void initSlides();
brianosman05de2162016-05-06 13:28:57 -070088 void updateTitle();
Brian Osman621491e2017-02-28 15:45:01 -050089 void setBackend(sk_app::Window::BackendType);
Brian Osman92004802017-03-06 11:47:26 -050090 void setColorMode(ColorMode);
Florin Malitaab99c342018-01-16 16:23:03 -050091 int startupSlide() const;
92 void setCurrentSlide(int);
93 void setupCurrentSlide();
94 void listNames() const;
jvanverth2bb3b6d2016-04-08 07:24:09 -070095
liyuqiane5a6cd92016-05-27 08:52:52 -070096 void updateUIState();
97
Brian Osmanf750fbc2017-02-08 10:47:28 -050098 void drawSlide(SkCanvas* canvs);
Brian Osmand67e5182017-12-08 16:46:09 -050099 void drawImGui();
jvanverth3d6ed3a2016-04-07 11:09:51 -0700100
jvanverthc265a922016-04-08 12:51:45 -0700101 void changeZoomLevel(float delta);
liyuqiand3cdbca2016-05-17 12:44:20 -0700102 SkMatrix computeMatrix();
jvanverthc265a922016-04-08 12:51:45 -0700103
Yuqian Lib2ba6642017-11-22 12:07:41 -0500104 void resetExecutor() {
105 fExecutor = SkExecutor::MakeFIFOThreadPool(fThreadCnt == 0 ? fTileCnt : fThreadCnt);
106 }
107
jvanverth34524262016-05-04 13:49:13 -0700108 sk_app::Window* fWindow;
jvanverth9f372462016-04-06 06:08:59 -0700109
Brian Osman56a24812017-12-19 11:15:16 -0500110 StatsLayer fStatsLayer;
111 StatsLayer::Timer fPaintTimer;
112 StatsLayer::Timer fFlushTimer;
113 StatsLayer::Timer fAnimateTimer;
jvanverth3d6ed3a2016-04-07 11:09:51 -0700114
jvanverthc265a922016-04-08 12:51:45 -0700115 SkAnimTimer fAnimTimer;
jvanverth2bb3b6d2016-04-08 07:24:09 -0700116 SkTArray<sk_sp<Slide>> fSlides;
117 int fCurrentSlide;
jvanverthc265a922016-04-08 12:51:45 -0700118
liyuqian2edb0f42016-07-06 14:11:32 -0700119 bool fRefresh; // whether to continuously refresh for measuring render time
jvanverthc265a922016-04-08 12:51:45 -0700120
Brian Osman3ac99cf2017-12-01 11:23:53 -0500121 bool fSaveToSKP;
122
Brian Osmand67e5182017-12-08 16:46:09 -0500123 ImGuiLayer fImGuiLayer;
Brian Osmana109e392017-02-24 09:49:14 -0500124 SkPaint fImGuiGamutPaint;
Brian Osman79086b92017-02-10 13:36:16 -0500125 bool fShowImGuiDebugWindow;
Brian Osmanfce09c52017-11-14 15:32:20 -0500126 bool fShowSlidePicker;
Brian Osman79086b92017-02-10 13:36:16 -0500127 bool fShowImGuiTestWindow;
128
Brian Osmanf6877092017-02-13 09:39:57 -0500129 bool fShowZoomWindow;
130 sk_sp<SkImage> fLastImage;
131
jvanverthaf236b52016-05-20 06:01:06 -0700132 sk_app::Window::BackendType fBackendType;
133
Brian Osmanf750fbc2017-02-08 10:47:28 -0500134 // Color properties for slide rendering
Brian Osman92004802017-03-06 11:47:26 -0500135 ColorMode fColorMode;
Brian Osmana109e392017-02-24 09:49:14 -0500136 SkColorSpacePrimaries fColorSpacePrimaries;
Brian Osmanfdab5762017-11-09 10:27:55 -0500137 SkColorSpaceTransferFn fColorSpaceTransferFn;
Brian Osmanf750fbc2017-02-08 10:47:28 -0500138
jvanverthc265a922016-04-08 12:51:45 -0700139 // transform data
jvanverthc265a922016-04-08 12:51:45 -0700140 SkScalar fZoomLevel;
jvanverthc265a922016-04-08 12:51:45 -0700141
brianosman622c8d52016-05-10 06:50:49 -0700142 sk_app::CommandSet fCommands;
liyuqiand3cdbca2016-05-17 12:44:20 -0700143
Brian Osmanb53f48c2017-06-07 10:00:30 -0400144 enum class GestureDevice {
145 kNone,
146 kTouch,
147 kMouse,
148 };
149
liyuqiand3cdbca2016-05-17 12:44:20 -0700150 SkTouchGesture fGesture;
Brian Osmanb53f48c2017-06-07 10:00:30 -0400151 GestureDevice fGestureDevice;
liyuqiane46e4f02016-05-20 07:32:19 -0700152
153 // identity unless the window initially scales the content to fit the screen.
154 SkMatrix fDefaultMatrix;
liyuqian1f508fd2016-06-07 06:57:40 -0700155
Brian Osmanfd8f4d52017-02-24 11:57:23 -0500156 SkTArray<std::function<void(void)>> fDeferredActions;
157
liyuqian1f508fd2016-06-07 06:57:40 -0700158 Json::Value fAllSlideNames; // cache all slide names for fast updateUIState
Yuqian Lib2ba6642017-11-22 12:07:41 -0500159
160 int fTileCnt;
161 int fThreadCnt;
162 std::unique_ptr<SkExecutor> fExecutor;
Ben Wagnerabdcc5f2018-02-12 16:37:28 -0500163
164 SkPaint fPaint;
165 SkPaintFields fPaintOverrides;
jvanverth9f372462016-04-06 06:08:59 -0700166};
167
168
169#endif