1 /* 2 * Copyright 2019 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 SkRTShader_DEFINED 9 #define SkRTShader_DEFINED 10 11 #include "include/core/SkString.h" 12 #include "include/private/SkMutex.h" 13 #include "src/shaders/SkShaderBase.h" 14 #include "src/sksl/SkSLByteCode.h" 15 16 #if SK_SUPPORT_GPU 17 #include "src/gpu/GrFragmentProcessor.h" 18 #endif 19 20 class SkData; 21 class SkMatrix; 22 23 class SkRTShader : public SkShaderBase { 24 public: 25 SkRTShader(SkString sksl, sk_sp<SkData> inputs, const SkMatrix* localMatrix, bool isOpaque); 26 isOpaque()27 bool isOpaque() const override { return fIsOpaque; } 28 29 #if SK_SUPPORT_GPU 30 std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override; 31 #endif 32 33 protected: 34 void flatten(SkWriteBuffer&) const override; 35 bool onAppendStages(const SkStageRec& rec) const override; 36 37 private: 38 SK_FLATTENABLE_HOOKS(SkRTShader) 39 40 SkString fSkSL; 41 sk_sp<SkData> fInputs; 42 const uint32_t fUniqueID; 43 const bool fIsOpaque; 44 45 mutable SkMutex fByteCodeMutex; 46 mutable std::unique_ptr<SkSL::ByteCode> fByteCode; 47 48 typedef SkShaderBase INHERITED; 49 }; 50 51 #endif 52