1 | /* |
2 | * Copyright 2006 The Android Open Source Project |
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 SkComposeShader_DEFINED |
9 | #define SkComposeShader_DEFINED |
10 | |
11 | #include "include/core/SkBlendMode.h" |
12 | #include "src/shaders/SkShaderBase.h" |
13 | |
14 | class SkShader_Blend final : public SkShaderBase { |
15 | public: |
16 | SkShader_Blend(SkBlendMode mode, sk_sp<SkShader> dst, sk_sp<SkShader> src) |
17 | : fDst(std::move(dst)) |
18 | , fSrc(std::move(src)) |
19 | , fMode(mode) |
20 | {} |
21 | |
22 | #if SK_SUPPORT_GPU |
23 | std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override; |
24 | #endif |
25 | |
26 | protected: |
27 | SkShader_Blend(SkReadBuffer&); |
28 | void flatten(SkWriteBuffer&) const override; |
29 | bool onAppendStages(const SkStageRec&) const override; |
30 | skvm::Color onProgram(skvm::Builder*, skvm::F32 x, skvm::F32 y, skvm::Color paint, |
31 | const SkMatrix& ctm, const SkMatrix* localM, |
32 | SkFilterQuality, const SkColorInfo& dst, |
33 | skvm::Uniforms*, SkArenaAlloc*) const override; |
34 | |
35 | private: |
36 | SK_FLATTENABLE_HOOKS(SkShader_Blend) |
37 | |
38 | sk_sp<SkShader> fDst; |
39 | sk_sp<SkShader> fSrc; |
40 | const SkBlendMode fMode; |
41 | |
42 | typedef SkShaderBase INHERITED; |
43 | }; |
44 | |
45 | class SkShader_Lerp final : public SkShaderBase { |
46 | public: |
47 | SkShader_Lerp(float weight, sk_sp<SkShader> dst, sk_sp<SkShader> src) |
48 | : fDst(std::move(dst)) |
49 | , fSrc(std::move(src)) |
50 | , fWeight(weight) |
51 | { |
52 | SkASSERT(weight >= 0 && weight <= 1); |
53 | } |
54 | |
55 | #if SK_SUPPORT_GPU |
56 | std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override; |
57 | #endif |
58 | |
59 | protected: |
60 | SkShader_Lerp(SkReadBuffer&); |
61 | void flatten(SkWriteBuffer&) const override; |
62 | bool onAppendStages(const SkStageRec&) const override; |
63 | skvm::Color onProgram(skvm::Builder*, skvm::F32 x, skvm::F32 y, skvm::Color paint, |
64 | const SkMatrix& ctm, const SkMatrix* localM, |
65 | SkFilterQuality, const SkColorInfo& dst, |
66 | skvm::Uniforms*, SkArenaAlloc*) const override; |
67 | |
68 | private: |
69 | SK_FLATTENABLE_HOOKS(SkShader_Lerp) |
70 | |
71 | sk_sp<SkShader> fDst; |
72 | sk_sp<SkShader> fSrc; |
73 | const float fWeight; |
74 | |
75 | typedef SkShaderBase INHERITED; |
76 | }; |
77 | |
78 | #endif |
79 | |