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/core/SkRefCnt.h" 13 #include "include/core/SkScalar.h" 14 #include "include/core/SkShader.h" 15 #include "include/core/SkString.h" 16 #include "include/effects/SkRuntimeEffect.h" 17 #include "include/private/base/SkTArray.h" 18 #include "include/private/base/SkTemplates.h" 19 #include "tools/viewer/Slide.h" 20 21 #include <utility> 22 23 class SkCanvas; 24 25 namespace skui { 26 enum class InputState; 27 enum class ModifierKey; 28 } // namespace sk 29 30 class SkSLSlide : public Slide { 31 public: 32 SkSLSlide(); 33 34 void draw(SkCanvas* canvas) override; 35 bool animate(double nanos) override; 36 resize(SkScalar winWidth,SkScalar winHeight)37 void resize(SkScalar winWidth, SkScalar winHeight) override { 38 fResolution = { winWidth, winHeight, 1.0f }; 39 } 40 void load(SkScalar winWidth, SkScalar winHeight) override; 41 void unload() override; 42 onMouse(SkScalar x,SkScalar y,skui::InputState state,skui::ModifierKey modifiers)43 bool onMouse(SkScalar x, SkScalar y, skui::InputState state, 44 skui::ModifierKey modifiers) override { return true; } 45 46 private: 47 bool rebuild(); 48 49 SkString fSkSL; 50 bool fCodeIsDirty; 51 sk_sp<SkRuntimeEffect> fEffect; 52 skia_private::AutoTMalloc<char> fInputs; 53 skia_private::TArray<sk_sp<SkShader>> fChildren; 54 float fSeconds = 0.0f; 55 56 enum Geometry { 57 kFill, 58 kCircle, 59 kRoundRect, 60 kCapsule, 61 kText, 62 }; 63 int fGeometry = kFill; 64 SkV3 fResolution = { 1, 1, 1 }; 65 SkV4 fMousePos; 66 int fTraceCoord[2] = {64, 64}; 67 bool fShadertoyUniforms = true; 68 69 // Named shaders that can be selected as inputs 70 skia_private::TArray<std::pair<const char*, sk_sp<SkShader>>> fShaders; 71 }; 72 73 #endif 74