Flutter Engine
The Flutter Engine
SkColorShader.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
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
16
17class SkReadBuffer;
18class SkWriteBuffer;
19struct SkStageRec;
20
21/** \class SkColorShader
22 A Shader that represents a single color. In general, this effect can be
23 accomplished by just using the color field on the paint, but if an
24 actual shader object is needed, this provides that feature.
25*/
27public:
28 /** Create a ColorShader that ignores the color in the paint, and uses the
29 specified color. Note: like all shaders, at draw time the paint's alpha
30 will be respected, and is applied to the specified color.
31 */
32 explicit SkColorShader(SkColor c);
33
34 bool isOpaque() const override;
35 bool isConstant() const override { return true; }
36
37 ShaderType type() const override { return ShaderType::kColor; }
38
39 SkColor color() const { return fColor; }
40
41private:
44
45 void flatten(SkWriteBuffer&) const override;
46
47 bool onAsLuminanceColor(SkColor4f* lum) const override {
48 *lum = SkColor4f::FromColor(fColor);
49 return true;
50 }
51
52 bool appendStages(const SkStageRec&, const SkShaders::MatrixRec&) const override;
53
54 SkColor fColor;
55};
56
58public:
60
61 bool isOpaque() const override { return fColor.isOpaque(); }
62 bool isConstant() const override { return true; }
63
64 ShaderType type() const override { return ShaderType::kColor4; }
65
66 sk_sp<SkColorSpace> colorSpace() const { return fColorSpace; }
67 SkColor4f color() const { return fColor; }
68
69private:
72
73 void flatten(SkWriteBuffer&) const override;
74 bool onAsLuminanceColor(SkColor4f* lum) const override;
75 bool appendStages(const SkStageRec&, const SkShaders::MatrixRec&) const override;
76
77 sk_sp<SkColorSpace> fColorSpace;
78 const SkColor4f fColor;
79};
80
81#endif
static constexpr SkColor kColor
Definition: CanvasTest.cpp:265
void SkRegisterColor4ShaderFlattenable()
void SkRegisterColorShaderFlattenable()
uint32_t SkColor
Definition: SkColor.h:37
#define SK_FLATTENABLE_HOOKS(type)
bool isOpaque() const override
Definition: SkColorShader.h:61
bool isConstant() const override
Definition: SkColorShader.h:62
SkColor4Shader(const SkColor4f &, sk_sp< SkColorSpace >)
SkColor4f color() const
Definition: SkColorShader.h:67
sk_sp< SkColorSpace > colorSpace() const
Definition: SkColorShader.h:66
ShaderType type() const override
Definition: SkColorShader.h:64
bool isConstant() const override
Definition: SkColorShader.h:35
SkColor color() const
Definition: SkColorShader.h:39
ShaderType type() const override
Definition: SkColorShader.h:37
SkColorShader(SkColor c)
bool isOpaque() const override
static float lum(float r, float g, float b)
Definition: hsl.cpp:52