Flutter Engine
The Flutter Engine
Viewer.h
Go to the documentation of this file.
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
8#ifndef Viewer_DEFINED
9#define Viewer_DEFINED
10
12#include "include/core/SkData.h"
13#include "include/core/SkFont.h"
17#include "modules/skcms/skcms.h"
22#include "tools/sk_app/Window.h"
28
29#include <cstdint>
30#include <atomic>
31#include <functional>
32#include <string>
33
34class SkImage;
35class SkSurface;
36class Slide;
37namespace skui {
38enum class InputState;
39enum class Key;
40enum class ModifierKey;
41} // namespace skui
42
44public:
45 Viewer(int argc, char** argv, void* platformData);
46 ~Viewer() override;
47
48 void onIdle() override;
49
50 void onBackendCreated() override;
51 void onPaint(SkSurface*) override;
52 void onResize(int width, int height) override;
53 bool onTouch(intptr_t owner, skui::InputState state, float x, float y) override;
54 bool onMouse(int x, int y, skui::InputState state, skui::ModifierKey modifiers) override;
55 bool onMouseWheel(float delta, int x, int y, skui::ModifierKey) override;
56 void onUIStateChanged(const SkString& stateName, const SkString& stateValue) override;
57 bool onKey(skui::Key key, skui::InputState state, skui::ModifierKey modifiers) override;
58 bool onChar(SkUnichar c, skui::ModifierKey modifiers) override;
59 bool onPinch(skui::InputState state, float scale, float x, float y) override;
60 bool onFling(skui::InputState state) override;
61
63
64 struct SkFontFields {
65 bool overridesSomething() const {
66 return fTypeface ||
67 fSize ||
68 fScaleX ||
69 fSkewX ||
70 fHinting ||
71 fEdging ||
72 fSubpixel ||
76 fEmbolden ||
78 }
79
80 bool fTypeface = false;
81 bool fSize = false;
82 SkScalar fSizeRange[2] = { 0, 20 };
83 bool fScaleX = false;
84 bool fSkewX = false;
85 bool fHinting = false;
86 bool fEdging = false;
87 bool fSubpixel = false;
88 bool fForceAutoHinting = false;
89 bool fEmbeddedBitmaps = false;
90 bool fLinearMetrics = false;
91 bool fEmbolden = false;
92 bool fBaselineSnap = false;
93 };
95 bool overridesSomething() const {
96 return fPathEffect ||
97 fShader ||
100 fImageFilter ||
101 fColor ||
102 fStrokeWidth ||
103 fMiterLimit ||
104 fBlendMode ||
105 fAntiAlias ||
106 fDither ||
108 fCapType ||
109 fJoinType ||
110 fStyle;
111 }
112
113 bool fPathEffect = false;
114 bool fShader = false;
115 bool fMaskFilter = false;
116 bool fColorFilter = false;
117 bool fImageFilter = false;
118
119 bool fColor = false;
120 bool fStrokeWidth = false;
121 bool fMiterLimit = false;
122 bool fBlendMode = false;
123
124 bool fAntiAlias = false;
125 bool fDither = false;
126 bool fForceRuntimeBlend = false;
127
128 bool fCapType = false;
129 bool fJoinType = false;
130 bool fStyle = false;
131 };
133 bool fFlags = false;
134 bool fPixelGeometry = false;
135 };
137 bool fColorType = false;
138 bool fColorSpace = false;
139 bool fMSAASampleCount = false;
140 bool fGrContextOptions = false;
142 bool fDisableVsync = false;
143 };
144private:
145 enum class ColorMode {
146 kLegacy, // 8888, no color management
147 kColorManaged8888, // 8888 with color management
148 kColorManagedF16, // F16 with color management
149 kColorManagedF16Norm, // Normalized F16 with color management
150 };
151
152 void initSlides();
153 void updateTitle();
154 void setBackend(sk_app::Window::BackendType);
155 void setColorMode(ColorMode);
156 int startupSlide() const;
157 void setCurrentSlide(int);
158 void setupCurrentSlide();
159 SkISize currentSlideSize() const;
160 void listNames() const;
161 void dumpShadersToResources();
162
163 void updateUIState();
164
165 void drawSlide(SkSurface* surface);
166 void drawImGui();
167
168 void changeZoomLevel(float delta);
169 void updateGestureTransLimit();
170 SkMatrix computePreTouchMatrix();
171 SkMatrix computePerspectiveMatrix();
172 SkMatrix computeMatrix();
173 SkPoint mapEvent(float x, float y);
174
175 sk_app::Window* fWindow;
176
177 StatsLayer fStatsLayer;
178 StatsLayer::Timer fPaintTimer;
179 StatsLayer::Timer fFlushTimer;
180 StatsLayer::Timer fAnimateTimer;
181
182 AnimTimer fAnimTimer;
184 int fCurrentSlide;
185
186 bool fRefresh; // whether to continuously refresh for measuring render time
187
188 bool fSaveToSKP;
189 bool fShowSlideDimensions;
190
191 ImGuiLayer fImGuiLayer;
192 SkPaint fImGuiGamutPaint;
193 bool fShowImGuiDebugWindow;
194 bool fShowSlidePicker;
195 bool fShowImGuiTestWindow;
196 bool fShowHistogramWindow;
197
198 bool fShowZoomWindow;
199 bool fZoomWindowFixed;
200 SkPoint fZoomWindowLocation;
201 sk_sp<SkImage> fLastImage;
202 bool fZoomUI;
203
204 sk_app::Window::BackendType fBackendType;
205
206 // Color properties for slide rendering
207 ColorMode fColorMode;
208 SkColorSpacePrimaries fColorSpacePrimaries;
209 skcms_TransferFunction fColorSpaceTransferFn;
210
211 // transform data
212 bool fApplyBackingScale;
213 SkScalar fZoomLevel;
214 SkScalar fRotation;
215 SkVector fOffset;
216
217 sk_app::CommandSet fCommands;
218
219 enum class GestureDevice {
220 kNone,
221 kTouch,
222 kMouse,
223 };
224
225 TouchGesture fGesture;
226 GestureDevice fGestureDevice;
227
228 // identity unless the window initially scales the content to fit the screen.
229 SkMatrix fDefaultMatrix;
230
231 bool fTiled;
232 bool fDrawTileBoundaries;
233 SkSize fTileScale;
234 bool fDrawViaSerialize = false;
235
236 enum PerspectiveMode {
237 kPerspective_Off,
238 kPerspective_Real,
239 kPerspective_Fake,
240 };
241 PerspectiveMode fPerspectiveMode;
242 SkPoint fPerspectivePoints[4];
243
244 skia_private::TArray<std::function<void()>> fDeferredActions;
245
246 // fPaint contains override values, fPaintOverrides controls if overrides are applied.
247 SkPaint fPaint;
248 SkPaintFields fPaintOverrides;
249
250 // fFont contains override values, fFontOverrides controls if overrides are applied.
251 SkFont fFont;
252 SkFontFields fFontOverrides;
253
254 // fDisplay contains default values (fWindow.fRequestedDisplayParams contains the overrides),
255 // fDisplayOverrides controls if overrides are applied.
257 DisplayFields fDisplayOverrides;
258
259 struct CachedShader {
260 bool fHovered = false;
261
263 SkString fKeyString;
264 SkString fKeyDescription;
265
266 SkFourByteTag fShaderType;
267 std::string fShader[kGrShaderTypeCount];
269 };
270
271 sk_gpu_test::MemoryCache fPersistentCache;
273
274 enum ShaderOptLevel : int {
275 kShaderOptLevel_Source,
276 kShaderOptLevel_Compile,
277 kShaderOptLevel_Optimize,
278 kShaderOptLevel_Inline,
279 };
280 ShaderOptLevel fOptLevel = kShaderOptLevel_Source;
281};
282
283#endif
static const int kGrShaderTypeCount
Definition: GrTypesPriv.h:282
int32_t SkUnichar
Definition: SkTypes.h:175
uint32_t SkFourByteTag
Definition: SkTypes.h:166
Definition: SkFont.h:35
Definition: Slide.h:29
Definition: Viewer.h:43
bool onChar(SkUnichar c, skui::ModifierKey modifiers) override
Definition: Viewer.cpp:3359
static GrContextOptions::ShaderErrorHandler * ShaderErrorHandler()
Definition: Viewer.cpp:167
bool onKey(skui::Key key, skui::InputState state, skui::ModifierKey modifiers) override
Definition: Viewer.cpp:3355
bool onTouch(intptr_t owner, skui::InputState state, float x, float y) override
Definition: Viewer.cpp:1914
void onBackendCreated() override
Definition: Viewer.cpp:1871
bool onMouseWheel(float delta, int x, int y, skui::ModifierKey) override
Definition: Viewer.cpp:2004
void onIdle() override
Definition: Viewer.cpp:3153
bool onPinch(skui::InputState state, float scale, float x, float y) override
Definition: Viewer.cpp:2027
void onResize(int width, int height) override
Definition: Viewer.cpp:1891
Viewer(int argc, char **argv, void *platformData)
Definition: Viewer.cpp:498
void onUIStateChanged(const SkString &stateName, const SkString &stateValue) override
Definition: Viewer.cpp:3288
void onPaint(SkSurface *) override
Definition: Viewer.cpp:1876
bool onFling(skui::InputState state) override
Definition: Viewer.cpp:2016
~Viewer() override
Definition: Viewer.cpp:1119
bool onMouse(int x, int y, skui::InputState state, skui::ModifierKey modifiers) override
Definition: Viewer.cpp:1967
VkSurfaceKHR surface
Definition: main.cc:49
float SkScalar
Definition: extension.cpp:12
AtkStateType state
Dart_NativeFunction function
Definition: fuchsia.cc:51
char ** argv
Definition: library.h:9
double y
double x
InputState
Definition: InputState.h:6
ModifierKey
Definition: ModifierKey.h:9
Key
Definition: Key.h:6
int32_t height
int32_t width
const Scalar scale
Definition: SkSize.h:16
Definition: SkSize.h:52
SkSurfacePropsFields fSurfaceProps
Definition: Viewer.h:141
bool fForceAutoHinting
Definition: Viewer.h:88
bool fEmbeddedBitmaps
Definition: Viewer.h:89
bool overridesSomething() const
Definition: Viewer.h:65
SkScalar fSizeRange[2]
Definition: Viewer.h:82
bool overridesSomething() const
Definition: Viewer.h:95