Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
color_filter.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_IMPELLER_AIKS_COLOR_FILTER_H_
6#define FLUTTER_IMPELLER_AIKS_COLOR_FILTER_H_
7
10
11namespace impeller {
12
13struct Paint;
14
15/*******************************************************************************
16 ******* ColorFilter
17 ******************************************************************************/
18
20 public:
21 /// A procedure that filters a given unpremultiplied color to produce a new
22 /// unpremultiplied color.
23 using ColorFilterProc = std::function<Color(Color)>;
24
26
27 virtual ~ColorFilter();
28
29 static std::shared_ptr<ColorFilter> MakeBlend(BlendMode blend_mode,
30 Color color);
31
32 static std::shared_ptr<ColorFilter> MakeMatrix(ColorMatrix color_matrix);
33
34 static std::shared_ptr<ColorFilter> MakeSrgbToLinear();
35
36 static std::shared_ptr<ColorFilter> MakeLinearToSrgb();
37
38 static std::shared_ptr<ColorFilter> MakeComposed(
39 const std::shared_ptr<ColorFilter>& outer,
40 const std::shared_ptr<ColorFilter>& inner);
41
42 /// @brief Wraps the given filter input with a GPU-based filter that will
43 /// perform the color operation. The given input will first be
44 /// rendered to a texture and then filtered.
45 ///
46 /// Note that this operation has no consideration for the original
47 /// geometry mask of the filter input. And the entire input texture is
48 /// treated as color information.
49 virtual std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
50 std::shared_ptr<FilterInput> input,
51 ColorFilterContents::AbsorbOpacity absorb_opacity) const = 0;
52
53 /// @brief Returns a function that can be used to filter unpremultiplied
54 /// Impeller Colors on the CPU.
56
57 virtual std::shared_ptr<ColorFilter> Clone() const = 0;
58};
59
60/*******************************************************************************
61 ******* BlendColorFilter
62 ******************************************************************************/
63
64class BlendColorFilter final : public ColorFilter {
65 public:
67
69
70 // |ColorFilter|
71 std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
72 std::shared_ptr<FilterInput> input,
73 ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
74
75 // |ColorFilter|
77
78 // |ColorFilter|
79 std::shared_ptr<ColorFilter> Clone() const override;
80
81 private:
82 BlendMode blend_mode_;
83 Color color_;
84};
85
86/*******************************************************************************
87 ******* MatrixColorFilter
88 ******************************************************************************/
89
90class MatrixColorFilter final : public ColorFilter {
91 public:
92 explicit MatrixColorFilter(ColorMatrix color_matrix);
93
95
96 // |ColorFilter|
97 std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
98 std::shared_ptr<FilterInput> input,
99 ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
100
101 // |ColorFilter|
102 ColorFilterProc GetCPUColorFilterProc() const override;
103
104 // |ColorFilter|
105 std::shared_ptr<ColorFilter> Clone() const override;
106
107 private:
108 ColorMatrix color_matrix_;
109};
110
111/*******************************************************************************
112 ******* SrgbToLinearColorFilter
113 ******************************************************************************/
114
116 public:
118
120
121 // |ColorFilter|
122 std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
123 std::shared_ptr<FilterInput> input,
124 ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
125
126 // |ColorFilter|
127 ColorFilterProc GetCPUColorFilterProc() const override;
128
129 // |ColorFilter|
130 std::shared_ptr<ColorFilter> Clone() const override;
131};
132
133/*******************************************************************************
134 ******* LinearToSrgbColorFilter
135 ******************************************************************************/
136
138 public:
140
142
143 // |ColorFilter|
144 std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
145 std::shared_ptr<FilterInput> input,
146 ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
147
148 // |ColorFilter|
149 ColorFilterProc GetCPUColorFilterProc() const override;
150
151 // |ColorFilter|
152 std::shared_ptr<ColorFilter> Clone() const override;
153};
154
155/// @brief Applies color filters as f(g(x)), where x is the input color.
156class ComposedColorFilter final : public ColorFilter {
157 public:
158 ComposedColorFilter(const std::shared_ptr<ColorFilter>& outer,
159 const std::shared_ptr<ColorFilter>& inner);
160
162
163 // |ColorFilter|
164 std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
165 std::shared_ptr<FilterInput> input,
166 ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
167
168 // |ColorFilter|
169 ColorFilterProc GetCPUColorFilterProc() const override;
170
171 // |ColorFilter|
172 std::shared_ptr<ColorFilter> Clone() const override;
173
174 private:
175 std::shared_ptr<ColorFilter> outer_;
176 std::shared_ptr<ColorFilter> inner_;
177};
178
179} // namespace impeller
180
181#endif // FLUTTER_IMPELLER_AIKS_COLOR_FILTER_H_
SkColor4f color
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const override
Wraps the given filter input with a GPU-based filter that will perform the color operation....
std::shared_ptr< ColorFilter > Clone() const override
static std::shared_ptr< ColorFilter > MakeComposed(const std::shared_ptr< ColorFilter > &outer, const std::shared_ptr< ColorFilter > &inner)
std::function< Color(Color)> ColorFilterProc
static std::shared_ptr< ColorFilter > MakeMatrix(ColorMatrix color_matrix)
virtual std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const =0
Wraps the given filter input with a GPU-based filter that will perform the color operation....
virtual ColorFilterProc GetCPUColorFilterProc() const =0
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
static std::shared_ptr< ColorFilter > MakeBlend(BlendMode blend_mode, Color color)
virtual std::shared_ptr< ColorFilter > Clone() const =0
static std::shared_ptr< ColorFilter > MakeLinearToSrgb()
static std::shared_ptr< ColorFilter > MakeSrgbToLinear()
Applies color filters as f(g(x)), where x is the input color.
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const override
Wraps the given filter input with a GPU-based filter that will perform the color operation....
std::shared_ptr< ColorFilter > Clone() const override
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
std::shared_ptr< ColorFilter > Clone() const override
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const override
Wraps the given filter input with a GPU-based filter that will perform the color operation....
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
std::shared_ptr< ColorFilter > Clone() const override
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const override
Wraps the given filter input with a GPU-based filter that will perform the color operation....
std::shared_ptr< ColorFilter > Clone() const override
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const override
Wraps the given filter input with a GPU-based filter that will perform the color operation....
BlendMode
Definition color.h:59