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 void onUIStateChanged(const SkString& stateName, const SkString& stateValue); 31 bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers); 32 bool onChar(SkUnichar c, uint32_t modifiers); 33 34 private: 35 enum class ColorMode { 36 kLegacy, // N32, no color management 37 kColorManagedSRGB8888_NonLinearBlending, // N32, sRGB transfer function, nonlinear blending 38 kColorManagedSRGB8888, // N32, sRGB transfer function, linear blending 39 kColorManagedLinearF16, // F16, linear transfer function, linear blending 40 }; 41 42 void initSlides(); 43 void updateTitle(); 44 void setBackend(sk_app::Window::BackendType); 45 void setColorMode(ColorMode); 46 void setStartupSlide(); 47 void setupCurrentSlide(int previousSlide); 48 void listNames(); 49 50 void updateUIState(); 51 52 void drawSlide(SkCanvas* canvs); 53 void drawStats(SkCanvas* canvas); 54 void drawImGui(SkCanvas* canvas); 55 56 void changeZoomLevel(float delta); 57 SkMatrix computeMatrix(); 58 59 sk_app::Window* fWindow; 60 61 static const int kMeasurementCount = 64; // should be power of 2 for fast mod 62 double fPaintTimes[kMeasurementCount]; 63 double fFlushTimes[kMeasurementCount]; 64 double fAnimateTimes[kMeasurementCount]; 65 int fCurrentMeasurement; 66 67 SkAnimTimer fAnimTimer; 68 SkTArray<sk_sp<Slide>> fSlides; 69 int fCurrentSlide; 70 71 bool fDisplayStats; 72 bool fRefresh; // whether to continuously refresh for measuring render time 73 74 SkPaint fImGuiFontPaint; 75 SkPaint fImGuiGamutPaint; 76 bool fShowImGuiDebugWindow; 77 bool fShowImGuiTestWindow; 78 79 bool fShowZoomWindow; 80 sk_sp<SkImage> fLastImage; 81 82 sk_app::Window::BackendType fBackendType; 83 84 // Color properties for slide rendering 85 ColorMode fColorMode; 86 SkColorSpacePrimaries fColorSpacePrimaries; 87 88 // transform data 89 SkScalar fZoomCenterX; 90 SkScalar fZoomCenterY; 91 SkScalar fZoomLevel; 92 SkScalar fZoomScale; 93 94 sk_app::CommandSet fCommands; 95 96 SkTouchGesture fGesture; 97 98 // identity unless the window initially scales the content to fit the screen. 99 SkMatrix fDefaultMatrix; 100 SkMatrix fDefaultMatrixInv; 101 102 SkTArray<std::function<void(void)>> fDeferredActions; 103 104 Json::Value fAllSlideNames; // cache all slide names for fast updateUIState 105 }; 106 107 108 #endif 109