xref: /aosp_15_r20/external/skia/src/core/SkRuntimeBlender.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2023 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 #ifndef SkRuntimeBlender_DEFINED
8 #define SkRuntimeBlender_DEFINED
9 
10 #include "include/core/SkData.h"
11 #include "include/core/SkFlattenable.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/effects/SkRuntimeEffect.h"
14 #include "include/private/base/SkSpan_impl.h"
15 #include "src/core/SkBlenderBase.h"
16 
17 #include <utility>
18 #include <vector>
19 
20 class SkReadBuffer;
21 class SkWriteBuffer;
22 struct SkStageRec;
23 
24 class SkRuntimeBlender : public SkBlenderBase {
25 public:
SkRuntimeBlender(sk_sp<SkRuntimeEffect> effect,sk_sp<const SkData> uniforms,SkSpan<const SkRuntimeEffect::ChildPtr> children)26     SkRuntimeBlender(sk_sp<SkRuntimeEffect> effect,
27                      sk_sp<const SkData> uniforms,
28                      SkSpan<const SkRuntimeEffect::ChildPtr> children)
29             : fEffect(std::move(effect))
30             , fUniforms(std::move(uniforms))
31             , fChildren(children.begin(), children.end()) {}
32 
asRuntimeEffect()33     SkRuntimeEffect* asRuntimeEffect() const override { return fEffect.get(); }
34 
type()35     BlenderType type() const override { return BlenderType::kRuntime; }
36 
37     bool onAppendStages(const SkStageRec& rec) const override;
38 
39     void flatten(SkWriteBuffer& buffer) const override;
40 
SK_FLATTENABLE_HOOKS(SkRuntimeBlender)41     SK_FLATTENABLE_HOOKS(SkRuntimeBlender)
42 
43     sk_sp<SkRuntimeEffect> effect() const { return fEffect; }
uniforms()44     sk_sp<const SkData> uniforms() const { return fUniforms; }
children()45     SkSpan<const SkRuntimeEffect::ChildPtr> children() const { return fChildren; }
46 
47 private:
48     sk_sp<SkRuntimeEffect> fEffect;
49     sk_sp<const SkData> fUniforms;
50     std::vector<SkRuntimeEffect::ChildPtr> fChildren;
51 };
52 
53 #endif
54