/* * Copyright 2023 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef SkRuntimeShader_DEFINED #define SkRuntimeShader_DEFINED #include "include/core/SkData.h" #include "include/core/SkFlattenable.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSpan.h" #include "include/effects/SkRuntimeEffect.h" #include "include/private/base/SkDebug.h" #include "src/core/SkRuntimeEffectPriv.h" #include "src/shaders/SkShaderBase.h" #include "src/sksl/tracing/SkSLDebugTracePriv.h" #include class SkColorSpace; class SkReadBuffer; class SkWriteBuffer; struct SkIPoint; struct SkStageRec; using UniformsCallback = SkRuntimeEffectPriv::UniformsCallback; class SkRuntimeShader : public SkShaderBase { public: SkRuntimeShader(sk_sp effect, sk_sp debugTrace, sk_sp uniforms, SkSpan children); SkRuntimeShader(sk_sp effect, sk_sp debugTrace, UniformsCallback uniformsCallback, SkSpan children); SkRuntimeEffect::TracedShader makeTracedClone(const SkIPoint& coord); bool isOpaque() const override { return fEffect->alwaysOpaque(); } ShaderType type() const override { return ShaderType::kRuntime; } bool appendStages(const SkStageRec& rec, const SkShaders::MatrixRec& mRec) const override; void flatten(SkWriteBuffer& buffer) const override; SkRuntimeEffect* asRuntimeEffect() const override { return fEffect.get(); } sk_sp effect() const { return fEffect; } SkSpan children() const { return fChildren; } sk_sp uniformData(const SkColorSpace* dstCS) const; SK_FLATTENABLE_HOOKS(SkRuntimeShader) private: enum Flags { kHasLegacyLocalMatrix_Flag = 1 << 1, }; sk_sp fEffect; sk_sp fDebugTrace; sk_sp fUniformData; UniformsCallback fUniformsCallback; std::vector fChildren; }; #endif