blob: f121c1799439cac6dd90b0b26c20462d6954654e [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);
Jim Van Verthe7705782017-05-04 14:00:59 -040030 bool onMouse(float x, float y, sk_app::Window::InputState state, uint32_t modifiers);
liyuqiane5a6cd92016-05-27 08:52:52 -070031 void onUIStateChanged(const SkString& stateName, const SkString& stateValue);
Brian Osman79086b92017-02-10 13:36:16 -050032 bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers);
33 bool onChar(SkUnichar c, uint32_t modifiers);
jvanverth9f372462016-04-06 06:08:59 -070034
35private:
Brian Osman92004802017-03-06 11:47:26 -050036 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
jvanverth2bb3b6d2016-04-08 07:24:09 -070043 void initSlides();
brianosman05de2162016-05-06 13:28:57 -070044 void updateTitle();
Brian Osman621491e2017-02-28 15:45:01 -050045 void setBackend(sk_app::Window::BackendType);
Brian Osman92004802017-03-06 11:47:26 -050046 void setColorMode(ColorMode);
Jim Van Verth6f449692017-02-14 15:16:46 -050047 void setStartupSlide();
jvanverthc265a922016-04-08 12:51:45 -070048 void setupCurrentSlide(int previousSlide);
Jim Van Verth6f449692017-02-14 15:16:46 -050049 void listNames();
Jim Van Verth90dcce52017-11-03 13:36:07 -040050 void resetMeasurements();
jvanverth2bb3b6d2016-04-08 07:24:09 -070051
liyuqiane5a6cd92016-05-27 08:52:52 -070052 void updateUIState();
53
Brian Osmanf750fbc2017-02-08 10:47:28 -050054 void drawSlide(SkCanvas* canvs);
jvanverth3d6ed3a2016-04-07 11:09:51 -070055 void drawStats(SkCanvas* canvas);
Brian Osman79086b92017-02-10 13:36:16 -050056 void drawImGui(SkCanvas* canvas);
jvanverth3d6ed3a2016-04-07 11:09:51 -070057
jvanverthc265a922016-04-08 12:51:45 -070058 void changeZoomLevel(float delta);
liyuqiand3cdbca2016-05-17 12:44:20 -070059 SkMatrix computeMatrix();
jvanverthc265a922016-04-08 12:51:45 -070060
jvanverth34524262016-05-04 13:49:13 -070061 sk_app::Window* fWindow;
jvanverth9f372462016-04-06 06:08:59 -070062
Jim Van Verth90dcce52017-11-03 13:36:07 -040063 static const int kMeasurementCount = 1 << 6; // should be power of 2 for fast mod
Brian Osman1df161a2017-02-09 12:10:20 -050064 double fPaintTimes[kMeasurementCount];
65 double fFlushTimes[kMeasurementCount];
66 double fAnimateTimes[kMeasurementCount];
jvanverth3d6ed3a2016-04-07 11:09:51 -070067 int fCurrentMeasurement;
Jim Van Verth90dcce52017-11-03 13:36:07 -040068 double fCumulativeMeasurementTime;
69 int fCumulativeMeasurementCount;
jvanverth3d6ed3a2016-04-07 11:09:51 -070070
jvanverthc265a922016-04-08 12:51:45 -070071 SkAnimTimer fAnimTimer;
jvanverth2bb3b6d2016-04-08 07:24:09 -070072 SkTArray<sk_sp<Slide>> fSlides;
73 int fCurrentSlide;
jvanverthc265a922016-04-08 12:51:45 -070074
75 bool fDisplayStats;
liyuqian2edb0f42016-07-06 14:11:32 -070076 bool fRefresh; // whether to continuously refresh for measuring render time
jvanverthc265a922016-04-08 12:51:45 -070077
Brian Osmanf6877092017-02-13 09:39:57 -050078 SkPaint fImGuiFontPaint;
Brian Osmana109e392017-02-24 09:49:14 -050079 SkPaint fImGuiGamutPaint;
Brian Osman79086b92017-02-10 13:36:16 -050080 bool fShowImGuiDebugWindow;
Brian Osmanfce09c52017-11-14 15:32:20 -050081 bool fShowSlidePicker;
Brian Osman79086b92017-02-10 13:36:16 -050082 bool fShowImGuiTestWindow;
83
Brian Osmanf6877092017-02-13 09:39:57 -050084 bool fShowZoomWindow;
85 sk_sp<SkImage> fLastImage;
86
jvanverthaf236b52016-05-20 06:01:06 -070087 sk_app::Window::BackendType fBackendType;
88
Brian Osmanf750fbc2017-02-08 10:47:28 -050089 // Color properties for slide rendering
Brian Osman92004802017-03-06 11:47:26 -050090 ColorMode fColorMode;
Brian Osmana109e392017-02-24 09:49:14 -050091 SkColorSpacePrimaries fColorSpacePrimaries;
Brian Osmanfdab5762017-11-09 10:27:55 -050092 SkColorSpaceTransferFn fColorSpaceTransferFn;
Brian Osmanf750fbc2017-02-08 10:47:28 -050093
jvanverthc265a922016-04-08 12:51:45 -070094 // transform data
jvanverthc265a922016-04-08 12:51:45 -070095 SkScalar fZoomLevel;
jvanverthc265a922016-04-08 12:51:45 -070096
brianosman622c8d52016-05-10 06:50:49 -070097 sk_app::CommandSet fCommands;
liyuqiand3cdbca2016-05-17 12:44:20 -070098
Brian Osmanb53f48c2017-06-07 10:00:30 -040099 enum class GestureDevice {
100 kNone,
101 kTouch,
102 kMouse,
103 };
104
liyuqiand3cdbca2016-05-17 12:44:20 -0700105 SkTouchGesture fGesture;
Brian Osmanb53f48c2017-06-07 10:00:30 -0400106 GestureDevice fGestureDevice;
liyuqiane46e4f02016-05-20 07:32:19 -0700107
108 // identity unless the window initially scales the content to fit the screen.
109 SkMatrix fDefaultMatrix;
liyuqian1f508fd2016-06-07 06:57:40 -0700110
Brian Osmanfd8f4d52017-02-24 11:57:23 -0500111 SkTArray<std::function<void(void)>> fDeferredActions;
112
liyuqian1f508fd2016-06-07 06:57:40 -0700113 Json::Value fAllSlideNames; // cache all slide names for fast updateUIState
jvanverth9f372462016-04-06 06:08:59 -0700114};
115
116
117#endif