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 "SkShaderBase.h" 12 #include "SkBlendMode.h" 13 14 class SkComposeShader final : public SkShaderBase { 15 public: SkComposeShader(sk_sp<SkShader> dst,sk_sp<SkShader> src,SkBlendMode mode,float lerpT)16 SkComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader> src, SkBlendMode mode, float lerpT) 17 : fDst(std::move(dst)) 18 , fSrc(std::move(src)) 19 , fLerpT(lerpT) 20 , fMode(mode) 21 { 22 SkASSERT(lerpT >= 0 && lerpT <= 1); 23 } 24 25 #if SK_SUPPORT_GPU 26 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const override; 27 #endif 28 29 #ifdef SK_DEBUGx getShaderA()30 SkShader* getShaderA() { return fShaderA.get(); } getShaderB()31 SkShader* getShaderB() { return fShaderB.get(); } 32 #endif 33 34 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 35 bool asACompose(ComposeRec* rec) const override; 36 #endif 37 38 SK_TO_STRING_OVERRIDE() 39 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeShader) 40 41 protected: 42 SkComposeShader(SkReadBuffer&); 43 void flatten(SkWriteBuffer&) const override; 44 sk_sp<SkShader> onMakeColorSpace(SkColorSpaceXformer* xformer) const override; 45 bool onAppendStages(SkRasterPipeline*, SkColorSpace* dstCS, SkArenaAlloc*, 46 const SkMatrix&, const SkPaint&, const SkMatrix* localM) const override; 47 onIsRasterPipelineOnly()48 bool onIsRasterPipelineOnly() const override { return true; } 49 50 private: 51 sk_sp<SkShader> fDst; 52 sk_sp<SkShader> fSrc; 53 const float fLerpT; 54 const SkBlendMode fMode; 55 isJustMode()56 bool isJustMode() const { return fLerpT == 1; } isJustLerp()57 bool isJustLerp() const { return fMode == SkBlendMode::kSrc; } 58 59 typedef SkShaderBase INHERITED; 60 }; 61 62 #endif 63