• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #include "sk_app/Application.h"
12 #include "sk_app/CommandSet.h"
13 #include "sk_app/Window.h"
14 #include "gm.h"
15 #include "SkAnimTimer.h"
16 #include "SkTouchGesture.h"
17 #include "Slide.h"
18 
19 class SkCanvas;
20 
21 class Viewer : public sk_app::Application {
22 public:
23     Viewer(int argc, char** argv, void* platformData);
24     ~Viewer() override;
25 
26     void onBackendCreated();
27     void onPaint(SkCanvas* canvas);
28     void onIdle() override;
29     bool onTouch(intptr_t owner, sk_app::Window::InputState state, float x, float y);
30     bool onMouse(float x, float y, sk_app::Window::InputState state, uint32_t modifiers);
31     void onUIStateChanged(const SkString& stateName, const SkString& stateValue);
32     bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers);
33     bool onChar(SkUnichar c, uint32_t modifiers);
34 
35 private:
36     enum class ColorMode {
37         kLegacy,                                 // N32, no color management
38         kColorManagedSRGB8888_NonLinearBlending, // N32, sRGB transfer function, nonlinear blending
39         kColorManagedSRGB8888,                   // N32, sRGB transfer function, linear blending
40         kColorManagedLinearF16,                  // F16, linear transfer function, linear blending
41     };
42 
43     void initSlides();
44     void updateTitle();
45     void setBackend(sk_app::Window::BackendType);
46     void setColorMode(ColorMode);
47     void setStartupSlide();
48     void setupCurrentSlide(int previousSlide);
49     void listNames();
50 
51     void updateUIState();
52 
53     void drawSlide(SkCanvas* canvs);
54     void drawStats(SkCanvas* canvas);
55     void drawImGui(SkCanvas* canvas);
56 
57     void changeZoomLevel(float delta);
58     SkMatrix computeMatrix();
59 
60     sk_app::Window*        fWindow;
61 
62     static const int kMeasurementCount = 64;  // should be power of 2 for fast mod
63     double fPaintTimes[kMeasurementCount];
64     double fFlushTimes[kMeasurementCount];
65     double fAnimateTimes[kMeasurementCount];
66     int fCurrentMeasurement;
67 
68     SkAnimTimer            fAnimTimer;
69     SkTArray<sk_sp<Slide>> fSlides;
70     int                    fCurrentSlide;
71 
72     bool                   fDisplayStats;
73     bool                   fRefresh; // whether to continuously refresh for measuring render time
74 
75     SkPaint                fImGuiFontPaint;
76     SkPaint                fImGuiGamutPaint;
77     bool                   fShowImGuiDebugWindow;
78     bool                   fShowImGuiTestWindow;
79 
80     bool                   fShowZoomWindow;
81     sk_sp<SkImage>         fLastImage;
82 
83     sk_app::Window::BackendType fBackendType;
84 
85     // Color properties for slide rendering
86     ColorMode              fColorMode;
87     SkColorSpacePrimaries  fColorSpacePrimaries;
88 
89     // transform data
90     SkScalar               fZoomLevel;
91 
92     sk_app::CommandSet     fCommands;
93 
94     enum class GestureDevice {
95         kNone,
96         kTouch,
97         kMouse,
98     };
99 
100     SkTouchGesture         fGesture;
101     GestureDevice          fGestureDevice;
102 
103     // identity unless the window initially scales the content to fit the screen.
104     SkMatrix               fDefaultMatrix;
105 
106     SkTArray<std::function<void(void)>> fDeferredActions;
107 
108     Json::Value            fAllSlideNames; // cache all slide names for fast updateUIState
109 };
110 
111 
112 #endif
113