blob: 2ab3de5281c42e51b6f86b542c1df21fd767ba75 [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"
Brian Osmand67e5182017-12-08 16:46:09 -050015#include "ImGuiLayer.h"
jvanverthc265a922016-04-08 12:51:45 -070016#include "SkAnimTimer.h"
Yuqian Lib2ba6642017-11-22 12:07:41 -050017#include "SkExecutor.h"
Brian Osmaneff04b52017-11-21 13:18:02 -050018#include "SkJSONCPP.h"
djsollen9207cae2016-06-10 07:50:00 -070019#include "SkTouchGesture.h"
jvanverth2bb3b6d2016-04-08 07:24:09 -070020#include "Slide.h"
jvanverth9f372462016-04-06 06:08:59 -070021
22class SkCanvas;
23
Brian Osman80fc07e2017-12-08 16:45:43 -050024class Viewer : public sk_app::Application, sk_app::Window::Layer {
jvanverth9f372462016-04-06 06:08:59 -070025public:
jvanverth34524262016-05-04 13:49:13 -070026 Viewer(int argc, char** argv, void* platformData);
27 ~Viewer() override;
jvanverth9f372462016-04-06 06:08:59 -070028
liyuqian2edb0f42016-07-06 14:11:32 -070029 void onIdle() override;
Brian Osman80fc07e2017-12-08 16:45:43 -050030
31 void onBackendCreated() override;
32 void onPaint(SkCanvas* canvas) override;
33 bool onTouch(intptr_t owner, sk_app::Window::InputState state, float x, float y) override;
34 bool onMouse(int x, int y, sk_app::Window::InputState state, uint32_t modifiers) override;
Brian Osman80fc07e2017-12-08 16:45:43 -050035 void onUIStateChanged(const SkString& stateName, const SkString& stateValue) override;
36 bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers) override;
37 bool onChar(SkUnichar c, uint32_t modifiers) override;
jvanverth9f372462016-04-06 06:08:59 -070038
39private:
Brian Osman92004802017-03-06 11:47:26 -050040 enum class ColorMode {
41 kLegacy, // N32, no color management
42 kColorManagedSRGB8888_NonLinearBlending, // N32, sRGB transfer function, nonlinear blending
43 kColorManagedSRGB8888, // N32, sRGB transfer function, linear blending
44 kColorManagedLinearF16, // F16, linear transfer function, linear blending
45 };
46
jvanverth2bb3b6d2016-04-08 07:24:09 -070047 void initSlides();
brianosman05de2162016-05-06 13:28:57 -070048 void updateTitle();
Brian Osman621491e2017-02-28 15:45:01 -050049 void setBackend(sk_app::Window::BackendType);
Brian Osman92004802017-03-06 11:47:26 -050050 void setColorMode(ColorMode);
Jim Van Verth6f449692017-02-14 15:16:46 -050051 void setStartupSlide();
jvanverthc265a922016-04-08 12:51:45 -070052 void setupCurrentSlide(int previousSlide);
Jim Van Verth6f449692017-02-14 15:16:46 -050053 void listNames();
Jim Van Verth90dcce52017-11-03 13:36:07 -040054 void resetMeasurements();
jvanverth2bb3b6d2016-04-08 07:24:09 -070055
liyuqiane5a6cd92016-05-27 08:52:52 -070056 void updateUIState();
57
Brian Osmanf750fbc2017-02-08 10:47:28 -050058 void drawSlide(SkCanvas* canvs);
jvanverth3d6ed3a2016-04-07 11:09:51 -070059 void drawStats(SkCanvas* canvas);
Brian Osmand67e5182017-12-08 16:46:09 -050060 void drawImGui();
jvanverth3d6ed3a2016-04-07 11:09:51 -070061
jvanverthc265a922016-04-08 12:51:45 -070062 void changeZoomLevel(float delta);
liyuqiand3cdbca2016-05-17 12:44:20 -070063 SkMatrix computeMatrix();
jvanverthc265a922016-04-08 12:51:45 -070064
Yuqian Lib2ba6642017-11-22 12:07:41 -050065 void resetExecutor() {
66 fExecutor = SkExecutor::MakeFIFOThreadPool(fThreadCnt == 0 ? fTileCnt : fThreadCnt);
67 }
68
jvanverth34524262016-05-04 13:49:13 -070069 sk_app::Window* fWindow;
jvanverth9f372462016-04-06 06:08:59 -070070
Jim Van Verth90dcce52017-11-03 13:36:07 -040071 static const int kMeasurementCount = 1 << 6; // should be power of 2 for fast mod
Brian Osman1df161a2017-02-09 12:10:20 -050072 double fPaintTimes[kMeasurementCount];
73 double fFlushTimes[kMeasurementCount];
74 double fAnimateTimes[kMeasurementCount];
jvanverth3d6ed3a2016-04-07 11:09:51 -070075 int fCurrentMeasurement;
Jim Van Verth90dcce52017-11-03 13:36:07 -040076 double fCumulativeMeasurementTime;
77 int fCumulativeMeasurementCount;
jvanverth3d6ed3a2016-04-07 11:09:51 -070078
jvanverthc265a922016-04-08 12:51:45 -070079 SkAnimTimer fAnimTimer;
jvanverth2bb3b6d2016-04-08 07:24:09 -070080 SkTArray<sk_sp<Slide>> fSlides;
81 int fCurrentSlide;
jvanverthc265a922016-04-08 12:51:45 -070082
83 bool fDisplayStats;
liyuqian2edb0f42016-07-06 14:11:32 -070084 bool fRefresh; // whether to continuously refresh for measuring render time
jvanverthc265a922016-04-08 12:51:45 -070085
Brian Osman3ac99cf2017-12-01 11:23:53 -050086 bool fSaveToSKP;
87
Brian Osmand67e5182017-12-08 16:46:09 -050088 ImGuiLayer fImGuiLayer;
Brian Osmana109e392017-02-24 09:49:14 -050089 SkPaint fImGuiGamutPaint;
Brian Osman79086b92017-02-10 13:36:16 -050090 bool fShowImGuiDebugWindow;
Brian Osmanfce09c52017-11-14 15:32:20 -050091 bool fShowSlidePicker;
Brian Osman79086b92017-02-10 13:36:16 -050092 bool fShowImGuiTestWindow;
93
Brian Osmanf6877092017-02-13 09:39:57 -050094 bool fShowZoomWindow;
95 sk_sp<SkImage> fLastImage;
96
jvanverthaf236b52016-05-20 06:01:06 -070097 sk_app::Window::BackendType fBackendType;
98
Brian Osmanf750fbc2017-02-08 10:47:28 -050099 // Color properties for slide rendering
Brian Osman92004802017-03-06 11:47:26 -0500100 ColorMode fColorMode;
Brian Osmana109e392017-02-24 09:49:14 -0500101 SkColorSpacePrimaries fColorSpacePrimaries;
Brian Osmanfdab5762017-11-09 10:27:55 -0500102 SkColorSpaceTransferFn fColorSpaceTransferFn;
Brian Osmanf750fbc2017-02-08 10:47:28 -0500103
jvanverthc265a922016-04-08 12:51:45 -0700104 // transform data
jvanverthc265a922016-04-08 12:51:45 -0700105 SkScalar fZoomLevel;
jvanverthc265a922016-04-08 12:51:45 -0700106
brianosman622c8d52016-05-10 06:50:49 -0700107 sk_app::CommandSet fCommands;
liyuqiand3cdbca2016-05-17 12:44:20 -0700108
Brian Osmanb53f48c2017-06-07 10:00:30 -0400109 enum class GestureDevice {
110 kNone,
111 kTouch,
112 kMouse,
113 };
114
liyuqiand3cdbca2016-05-17 12:44:20 -0700115 SkTouchGesture fGesture;
Brian Osmanb53f48c2017-06-07 10:00:30 -0400116 GestureDevice fGestureDevice;
liyuqiane46e4f02016-05-20 07:32:19 -0700117
118 // identity unless the window initially scales the content to fit the screen.
119 SkMatrix fDefaultMatrix;
liyuqian1f508fd2016-06-07 06:57:40 -0700120
Brian Osmanfd8f4d52017-02-24 11:57:23 -0500121 SkTArray<std::function<void(void)>> fDeferredActions;
122
liyuqian1f508fd2016-06-07 06:57:40 -0700123 Json::Value fAllSlideNames; // cache all slide names for fast updateUIState
Yuqian Lib2ba6642017-11-22 12:07:41 -0500124
125 int fTileCnt;
126 int fThreadCnt;
127 std::unique_ptr<SkExecutor> fExecutor;
jvanverth9f372462016-04-06 06:08:59 -0700128};
129
130
131#endif