blob: fc094fcbe8c1059a10c2e9a4859d6ff56ad85994 [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"
jvanverthc265a922016-04-08 12:51:45 -070015#include "SkAnimTimer.h"
djsollen9207cae2016-06-10 07:50:00 -070016#include "SkTouchGesture.h"
jvanverth2bb3b6d2016-04-08 07:24:09 -070017#include "Slide.h"
jvanverth9f372462016-04-06 06:08:59 -070018
19class SkCanvas;
20
jvanverth34524262016-05-04 13:49:13 -070021class Viewer : public sk_app::Application {
jvanverth9f372462016-04-06 06:08:59 -070022public:
jvanverth34524262016-05-04 13:49:13 -070023 Viewer(int argc, char** argv, void* platformData);
24 ~Viewer() override;
jvanverth9f372462016-04-06 06:08:59 -070025
Christopher Dalton443ec1b2017-02-24 13:22:53 -070026 void onBackendCreated();
jvanverth9f372462016-04-06 06:08:59 -070027 void onPaint(SkCanvas* canvas);
liyuqian2edb0f42016-07-06 14:11:32 -070028 void onIdle() override;
jvanverth814e38d2016-06-06 08:48:47 -070029 bool onTouch(intptr_t owner, sk_app::Window::InputState state, float x, float y);
liyuqiane5a6cd92016-05-27 08:52:52 -070030 void onUIStateChanged(const SkString& stateName, const SkString& stateValue);
Brian Osman79086b92017-02-10 13:36:16 -050031 bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers);
32 bool onChar(SkUnichar c, uint32_t modifiers);
jvanverth9f372462016-04-06 06:08:59 -070033
34private:
jvanverth2bb3b6d2016-04-08 07:24:09 -070035 void initSlides();
brianosman05de2162016-05-06 13:28:57 -070036 void updateTitle();
Brian Osman621491e2017-02-28 15:45:01 -050037 void setBackend(sk_app::Window::BackendType);
Brian Osmana109e392017-02-24 09:49:14 -050038 void setColorMode(SkColorType, bool colorManaged);
Jim Van Verth6f449692017-02-14 15:16:46 -050039 void setStartupSlide();
jvanverthc265a922016-04-08 12:51:45 -070040 void setupCurrentSlide(int previousSlide);
Jim Van Verth6f449692017-02-14 15:16:46 -050041 void listNames();
jvanverth2bb3b6d2016-04-08 07:24:09 -070042
liyuqiane5a6cd92016-05-27 08:52:52 -070043 void updateUIState();
44
Brian Osmanf750fbc2017-02-08 10:47:28 -050045 void drawSlide(SkCanvas* canvs);
jvanverth3d6ed3a2016-04-07 11:09:51 -070046 void drawStats(SkCanvas* canvas);
Brian Osman79086b92017-02-10 13:36:16 -050047 void drawImGui(SkCanvas* canvas);
jvanverth3d6ed3a2016-04-07 11:09:51 -070048
jvanverthc265a922016-04-08 12:51:45 -070049 void changeZoomLevel(float delta);
liyuqiand3cdbca2016-05-17 12:44:20 -070050 SkMatrix computeMatrix();
jvanverthc265a922016-04-08 12:51:45 -070051
jvanverth34524262016-05-04 13:49:13 -070052 sk_app::Window* fWindow;
jvanverth9f372462016-04-06 06:08:59 -070053
jvanverth3d6ed3a2016-04-07 11:09:51 -070054 static const int kMeasurementCount = 64; // should be power of 2 for fast mod
Brian Osman1df161a2017-02-09 12:10:20 -050055 double fPaintTimes[kMeasurementCount];
56 double fFlushTimes[kMeasurementCount];
57 double fAnimateTimes[kMeasurementCount];
jvanverth3d6ed3a2016-04-07 11:09:51 -070058 int fCurrentMeasurement;
59
jvanverthc265a922016-04-08 12:51:45 -070060 SkAnimTimer fAnimTimer;
jvanverth2bb3b6d2016-04-08 07:24:09 -070061 SkTArray<sk_sp<Slide>> fSlides;
62 int fCurrentSlide;
jvanverthc265a922016-04-08 12:51:45 -070063
64 bool fDisplayStats;
liyuqian2edb0f42016-07-06 14:11:32 -070065 bool fRefresh; // whether to continuously refresh for measuring render time
jvanverthc265a922016-04-08 12:51:45 -070066
Brian Osmanf6877092017-02-13 09:39:57 -050067 SkPaint fImGuiFontPaint;
Brian Osmana109e392017-02-24 09:49:14 -050068 SkPaint fImGuiGamutPaint;
Brian Osman79086b92017-02-10 13:36:16 -050069 bool fShowImGuiDebugWindow;
70 bool fShowImGuiTestWindow;
71
Brian Osmanf6877092017-02-13 09:39:57 -050072 bool fShowZoomWindow;
73 sk_sp<SkImage> fLastImage;
74
jvanverthaf236b52016-05-20 06:01:06 -070075 sk_app::Window::BackendType fBackendType;
76
Brian Osmanf750fbc2017-02-08 10:47:28 -050077 // Color properties for slide rendering
78 SkColorType fColorType;
Brian Osmana109e392017-02-24 09:49:14 -050079 bool fColorManaged;
80 SkColorSpacePrimaries fColorSpacePrimaries;
Brian Osmanf750fbc2017-02-08 10:47:28 -050081
jvanverthc265a922016-04-08 12:51:45 -070082 // transform data
jvanverthc265a922016-04-08 12:51:45 -070083 SkScalar fZoomCenterX;
84 SkScalar fZoomCenterY;
85 SkScalar fZoomLevel;
86 SkScalar fZoomScale;
87
brianosman622c8d52016-05-10 06:50:49 -070088 sk_app::CommandSet fCommands;
liyuqiand3cdbca2016-05-17 12:44:20 -070089
90 SkTouchGesture fGesture;
liyuqiane46e4f02016-05-20 07:32:19 -070091
92 // identity unless the window initially scales the content to fit the screen.
93 SkMatrix fDefaultMatrix;
94 SkMatrix fDefaultMatrixInv;
liyuqian1f508fd2016-06-07 06:57:40 -070095
Brian Osmanfd8f4d52017-02-24 11:57:23 -050096 SkTArray<std::function<void(void)>> fDeferredActions;
97
liyuqian1f508fd2016-06-07 06:57:40 -070098 Json::Value fAllSlideNames; // cache all slide names for fast updateUIState
jvanverth9f372462016-04-06 06:08:59 -070099};
100
101
102#endif