1 /* 2 * Copyright 2019 Google LLC 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 SkSLSlide_DEFINED 9 #define SkSLSlide_DEFINED 10 11 #include "include/core/SkM44.h" 12 #include "include/effects/SkRuntimeEffect.h" 13 #include "tools/viewer/Slide.h" 14 15 class SkSLSlide : public Slide { 16 public: 17 SkSLSlide(); 18 19 // TODO: We need a way for primarily interactive slides to always be as large as the window getDimensions()20 SkISize getDimensions() const override { return SkISize::MakeEmpty(); } 21 22 void draw(SkCanvas* canvas) override; 23 bool animate(double nanos) override; 24 resize(SkScalar winWidth,SkScalar winHeight)25 void resize(SkScalar winWidth, SkScalar winHeight) override { 26 fResolution = { winWidth, winHeight, 1.0f }; 27 } 28 void load(SkScalar winWidth, SkScalar winHeight) override; 29 void unload() override; 30 onMouse(SkScalar x,SkScalar y,skui::InputState state,skui::ModifierKey modifiers)31 bool onMouse(SkScalar x, SkScalar y, skui::InputState state, 32 skui::ModifierKey modifiers) override { return true; } 33 34 private: 35 bool rebuild(); 36 37 SkString fSkSL; 38 bool fCodeIsDirty; 39 sk_sp<SkRuntimeEffect> fEffect; 40 SkAutoTMalloc<char> fInputs; 41 SkTArray<sk_sp<SkShader>> fChildren; 42 float fSeconds = 0.0f; 43 44 enum Geometry { 45 kFill, 46 kCircle, 47 kRoundRect, 48 kCapsule, 49 kText, 50 }; 51 int fGeometry = kFill; 52 SkV3 fResolution = { 1, 1, 1 }; 53 SkV4 fMousePos; 54 55 // Named shaders that can be selected as inputs 56 SkTArray<std::pair<const char*, sk_sp<SkShader>>> fShaders; 57 }; 58 59 #endif 60