aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/viewer/Viewer.h
blob: 9499c6c9795098d207c39837b89782f226f83c7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/

#ifndef Viewer_DEFINED
#define Viewer_DEFINED

#include "sk_app/Application.h"
#include "sk_app/CommandSet.h"
#include "sk_app/Window.h"
#include "gm.h"
#include "SkAnimTimer.h"
#include "SkTouchGesture.h"
#include "Slide.h"

class SkCanvas;

class Viewer : public sk_app::Application {
public:
    Viewer(int argc, char** argv, void* platformData);
    ~Viewer() override;

    void onPaint(SkCanvas* canvas);
    void onIdle() override;
    bool onTouch(intptr_t owner, sk_app::Window::InputState state, float x, float y);
    void onUIStateChanged(const SkString& stateName, const SkString& stateValue);
    bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers);
    bool onChar(SkUnichar c, uint32_t modifiers);

private:
    void initSlides();
    void updateTitle();
    void setColorMode(SkColorType, sk_sp<SkColorSpace>);
    void setupCurrentSlide(int previousSlide);

    void updateUIState();

    void drawSlide(SkCanvas* canvs);
    void drawStats(SkCanvas* canvas);
    void drawImGui(SkCanvas* canvas);

    void changeZoomLevel(float delta);
    SkMatrix computeMatrix();

    sk_app::Window*        fWindow;

    static const int kMeasurementCount = 64;  // should be power of 2 for fast mod
    double fPaintTimes[kMeasurementCount];
    double fFlushTimes[kMeasurementCount];
    double fAnimateTimes[kMeasurementCount];
    int fCurrentMeasurement;

    SkAnimTimer            fAnimTimer;
    SkTArray<sk_sp<Slide>> fSlides;
    int                    fCurrentSlide;

    bool                   fDisplayStats;
    bool                   fRefresh; // whether to continuously refresh for measuring render time

    sk_sp<SkImage>         fImGuiFontImage;
    bool                   fShowImGuiDebugWindow;
    bool                   fShowImGuiTestWindow;

    sk_app::Window::BackendType fBackendType;

    // Color properties for slide rendering
    SkColorType            fColorType;
    sk_sp<SkColorSpace>    fColorSpace;

    // transform data
    SkScalar               fZoomCenterX;
    SkScalar               fZoomCenterY;
    SkScalar               fZoomLevel;
    SkScalar               fZoomScale;

    sk_app::CommandSet     fCommands;

    SkTouchGesture         fGesture;

    // identity unless the window initially scales the content to fit the screen.
    SkMatrix               fDefaultMatrix;
    SkMatrix               fDefaultMatrixInv;

    Json::Value            fAllSlideNames; // cache all slide names for fast updateUIState
};


#endif