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: SkShader_Blend(SkBlendMode mode,sk_sp<SkShader> dst,sk_sp<SkShader> src,const SkMatrix * lm)16 SkShader_Blend(SkBlendMode mode, sk_sp<SkShader> dst, sk_sp<SkShader> src, const SkMatrix* lm) 17 : INHERITED(lm) 18 , fDst(std::move(dst)) 19 , fSrc(std::move(src)) 20 , fMode(mode) 21 {} 22 23 #if SK_SUPPORT_GPU 24 std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override; 25 #endif 26 27 protected: 28 SkShader_Blend(SkReadBuffer&); 29 void flatten(SkWriteBuffer&) const override; 30 bool onAppendStages(const SkStageRec&) const override; 31 32 private: 33 SK_FLATTENABLE_HOOKS(SkShader_Blend) 34 35 sk_sp<SkShader> fDst; 36 sk_sp<SkShader> fSrc; 37 const SkBlendMode fMode; 38 39 typedef SkShaderBase INHERITED; 40 }; 41 42 class SkShader_Lerp final : public SkShaderBase { 43 public: SkShader_Lerp(float weight,sk_sp<SkShader> dst,sk_sp<SkShader> src,const SkMatrix * lm)44 SkShader_Lerp(float weight, sk_sp<SkShader> dst, sk_sp<SkShader> src, const SkMatrix* lm) 45 : INHERITED(lm) 46 , fDst(std::move(dst)) 47 , fSrc(std::move(src)) 48 , fWeight(weight) 49 { 50 SkASSERT(weight >= 0 && weight <= 1); 51 } 52 53 #if SK_SUPPORT_GPU 54 std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override; 55 #endif 56 57 protected: 58 SkShader_Lerp(SkReadBuffer&); 59 void flatten(SkWriteBuffer&) const override; 60 bool onAppendStages(const SkStageRec&) const override; 61 62 private: 63 SK_FLATTENABLE_HOOKS(SkShader_Lerp) 64 65 sk_sp<SkShader> fDst; 66 sk_sp<SkShader> fSrc; 67 const float fWeight; 68 69 typedef SkShaderBase INHERITED; 70 }; 71 72 class SkShader_LerpRed final : public SkShaderBase { 73 public: SkShader_LerpRed(sk_sp<SkShader> red,sk_sp<SkShader> dst,sk_sp<SkShader> src,const SkMatrix * lm)74 SkShader_LerpRed(sk_sp<SkShader> red, sk_sp<SkShader> dst, sk_sp<SkShader> src, 75 const SkMatrix* lm) 76 : INHERITED(lm) 77 , fDst(std::move(dst)) 78 , fSrc(std::move(src)) 79 , fRed(std::move(red)) 80 {} 81 82 #if SK_SUPPORT_GPU 83 std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override; 84 #endif 85 86 protected: 87 SkShader_LerpRed(SkReadBuffer&); 88 void flatten(SkWriteBuffer&) const override; 89 bool onAppendStages(const SkStageRec&) const override; 90 91 private: 92 SK_FLATTENABLE_HOOKS(SkShader_LerpRed) 93 94 sk_sp<SkShader> fDst; 95 sk_sp<SkShader> fSrc; 96 sk_sp<SkShader> fRed; 97 98 typedef SkShaderBase INHERITED; 99 }; 100 101 #endif 102