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 void draw(SkCanvas* canvas) override; 20 bool animate(double nanos) override; 21 resize(SkScalar winWidth,SkScalar winHeight)22 void resize(SkScalar winWidth, SkScalar winHeight) override { 23 fResolution = { winWidth, winHeight, 1.0f }; 24 } 25 void load(SkScalar winWidth, SkScalar winHeight) override; 26 void unload() override; 27 onMouse(SkScalar x,SkScalar y,skui::InputState state,skui::ModifierKey modifiers)28 bool onMouse(SkScalar x, SkScalar y, skui::InputState state, 29 skui::ModifierKey modifiers) override { return true; } 30 31 private: 32 bool rebuild(); 33 34 SkString fSkSL; 35 bool fCodeIsDirty; 36 sk_sp<SkRuntimeEffect> fEffect; 37 skia_private::AutoTMalloc<char> fInputs; 38 SkTArray<sk_sp<SkShader>> fChildren; 39 float fSeconds = 0.0f; 40 41 enum Geometry { 42 kFill, 43 kCircle, 44 kRoundRect, 45 kCapsule, 46 kText, 47 }; 48 int fGeometry = kFill; 49 SkV3 fResolution = { 1, 1, 1 }; 50 SkV4 fMousePos; 51 int fTraceCoord[2] = {64, 64}; 52 bool fShadertoyUniforms = true; 53 54 // Named shaders that can be selected as inputs 55 SkTArray<std::pair<const char*, sk_sp<SkShader>>> fShaders; 56 }; 57 58 #endif 59