• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) 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 protected:
39     SkComposeShader(SkReadBuffer&);
40     void flatten(SkWriteBuffer&) const override;
41     sk_sp<SkShader> onMakeColorSpace(SkColorSpaceXformer* xformer) const override;
42     bool onAppendStages(const StageRec&) const override;
43 
44 private:
45     SK_FLATTENABLE_HOOKS(SkComposeShader)
46 
47     sk_sp<SkShader>     fDst;
48     sk_sp<SkShader>     fSrc;
49     const float         fLerpT;
50     const SkBlendMode   fMode;
51 
isJustMode()52     bool isJustMode() const { return fLerpT == 1; }
isJustLerp()53     bool isJustLerp() const { return fMode == SkBlendMode::kSrc; }
54 
55     typedef SkShaderBase INHERITED;
56 };
57 
58 #endif
59