• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2007 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 SkColorShader_DEFINED
9 #define SkColorShader_DEFINED
10 
11 #include "src/shaders/SkShaderBase.h"
12 
13 /** \class SkColorShader
14     A Shader that represents a single color. In general, this effect can be
15     accomplished by just using the color field on the paint, but if an
16     actual shader object is needed, this provides that feature.
17 */
18 class SkColorShader : public SkShaderBase {
19 public:
20     /** Create a ColorShader that ignores the color in the paint, and uses the
21         specified color. Note: like all shaders, at draw time the paint's alpha
22         will be respected, and is applied to the specified color.
23     */
24     explicit SkColorShader(SkColor c);
25 
26     bool isOpaque() const override;
isConstant()27     bool isConstant() const override { return true; }
28 
29     GradientType asAGradient(GradientInfo* info) const override;
30 
31 #if SK_SUPPORT_GPU
32     std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
33 #endif
34 
35 private:
36     SK_FLATTENABLE_HOOKS(SkColorShader)
37 
38     void flatten(SkWriteBuffer&) const override;
39 
onAsLuminanceColor(SkColor * lum)40     bool onAsLuminanceColor(SkColor* lum) const override {
41         *lum = fColor;
42         return true;
43     }
44 
45     bool onAppendStages(const SkStageRec&) const override;
46 
47     skvm::Color onProgram(skvm::Builder*, skvm::Coord device, skvm::Coord local, skvm::Color paint,
48                           const SkMatrixProvider&, const SkMatrix* localM, const SkColorInfo& dst,
49                           skvm::Uniforms* uniforms, SkArenaAlloc*) const override;
50 
51     SkColor fColor;
52 };
53 
54 class SkColor4Shader : public SkShaderBase {
55 public:
56     SkColor4Shader(const SkColor4f&, sk_sp<SkColorSpace>);
57 
isOpaque()58     bool isOpaque()   const override { return fColor.isOpaque(); }
isConstant()59     bool isConstant() const override { return true; }
60 
61 #if SK_SUPPORT_GPU
62     std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
63 #endif
64 
65 private:
66     SK_FLATTENABLE_HOOKS(SkColor4Shader)
67 
68     void flatten(SkWriteBuffer&) const override;
69     bool onAppendStages(const SkStageRec&) const override;
70 
71     skvm::Color onProgram(skvm::Builder*, skvm::Coord device, skvm::Coord local, skvm::Color paint,
72                           const SkMatrixProvider&, const SkMatrix* localM, const SkColorInfo& dst,
73                           skvm::Uniforms* uniforms, SkArenaAlloc*) const override;
74 
75     sk_sp<SkColorSpace> fColorSpace;
76     const SkColor4f     fColor;
77 };
78 
79 #endif
80