| Flutter Impeller |

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 #pragma once
6
7 #include "impeller/entity/contents/filters/color_filter_contents.h"
8 #include "impeller/geometry/color.h"
9
10 namespace impeller {
11
12 struct Paint;
13
14 /*******************************************************************************
15 ******* ColorFilter
16 ******************************************************************************/
17
18 class ColorFilter {
19 public:
20 /// A procedure that filters a given unpremultiplied color to produce a new
21 /// unpremultiplied color.
22 using ColorFilterProc = std::function<Color(Color)>;
23
24 ColorFilter();
25
26 virtual ~ColorFilter();
27
28 static std::shared_ptr<ColorFilter> MakeBlend(BlendMode blend_mode,
29 Color color);
30
31 static std::shared_ptr<ColorFilter> MakeMatrix(ColorMatrix color_matrix);
32
33 static std::shared_ptr<ColorFilter> MakeSrgbToLinear();
34
35 static std::shared_ptr<ColorFilter> MakeLinearToSrgb();
36
37 /// @brief Wraps the given filter input with a GPU-based filter that will
38 /// perform the color operation. The given input will first be
39 /// rendered to a texture and then filtered.
40 ///
41 /// Note that this operation has no consideration for the original
42 /// geometry mask of the filter input. And the entire input texture is
43 /// treated as color information.
44 virtual std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
45 std::shared_ptr<FilterInput> input,
46 ColorFilterContents::AbsorbOpacity absorb_opacity) const = 0;
47
48 /// @brief Returns a function that can be used to filter unpremultiplied
49 /// Impeller Colors on the CPU.
50 virtual ColorFilterProc GetCPUColorFilterProc() const = 0;
51
52 virtual std::shared_ptr<ColorFilter> Clone() const = 0;
53 };
54
55 /*******************************************************************************
56 ******* BlendColorFilter
57 ******************************************************************************/
58
59 class BlendColorFilter final : public ColorFilter {
60 public:
61 BlendColorFilter(BlendMode blend_mode, Color color);
62
63 ~BlendColorFilter() override;
64
65 // |ColorFilter|
66 std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
67 std::shared_ptr<FilterInput> input,
68 ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
69
70 // |ColorFilter|
71 ColorFilterProc GetCPUColorFilterProc() const override;
72
73 // |ColorFilter|
74 std::shared_ptr<ColorFilter> Clone() const override;
75
76 private:
77 BlendMode blend_mode_;
78 Color color_;
79 };
80
81 /*******************************************************************************
82 ******* MatrixColorFilter
83 ******************************************************************************/
84
85 class MatrixColorFilter final : public ColorFilter {
86 public:
87 explicit MatrixColorFilter(ColorMatrix color_matrix);
88
89 ~MatrixColorFilter() override;
90
91 // |ColorFilter|
92 std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
93 std::shared_ptr<FilterInput> input,
94 ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
95
96 // |ColorFilter|
97 ColorFilterProc GetCPUColorFilterProc() const override;
98
99 // |ColorFilter|
100 std::shared_ptr<ColorFilter> Clone() const override;
101
102 private:
103 ColorMatrix color_matrix_;
104 };
105
106 /*******************************************************************************
107 ******* SrgbToLinearColorFilter
108 ******************************************************************************/
109
110 class SrgbToLinearColorFilter final : public ColorFilter {
111 public:
112 explicit SrgbToLinearColorFilter();
113
114 ~SrgbToLinearColorFilter() override;
115
116 // |ColorFilter|
117 std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
118 std::shared_ptr<FilterInput> input,
119 ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
120
121 // |ColorFilter|
122 ColorFilterProc GetCPUColorFilterProc() const override;
123
124 // |ColorFilter|
125 std::shared_ptr<ColorFilter> Clone() const override;
126 };
127
128 /*******************************************************************************
129 ******* LinearToSrgbColorFilter
130 ******************************************************************************/
131
132 class LinearToSrgbColorFilter final : public ColorFilter {
133 public:
134 explicit LinearToSrgbColorFilter();
135
136 ~LinearToSrgbColorFilter() override;
137
138 // |ColorFilter|
139 std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
140 std::shared_ptr<FilterInput> input,
141 ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
142
143 // |ColorFilter|
144 ColorFilterProc GetCPUColorFilterProc() const override;
145
146 // |ColorFilter|
147 std::shared_ptr<ColorFilter> Clone() const override;
148 };
149
150 } // namespace impeller
impeller::BlendMode
BlendMode
Definition: color.h:57
impeller::MatrixColorFilter::~MatrixColorFilter
~MatrixColorFilter() override
impeller::ColorFilter
Definition: color_filter.h:18
impeller::MatrixColorFilter::GetCPUColorFilterProc
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
Definition: color_filter.cc:83
impeller::BlendColorFilter::WrapWithGPUColorFilter
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....
Definition: color_filter.cc:46
impeller::BlendColorFilter::BlendColorFilter
BlendColorFilter(BlendMode blend_mode, Color color)
Definition: color_filter.cc:41
impeller::Color
Definition: color.h:122
impeller::ColorFilter::ColorFilterProc
std::function< Color(Color)> ColorFilterProc
Definition: color_filter.h:24
impeller::ColorFilter::GetCPUColorFilterProc
virtual ColorFilterProc GetCPUColorFilterProc() const =0
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
impeller::MatrixColorFilter::MatrixColorFilter
MatrixColorFilter(ColorMatrix color_matrix)
Definition: color_filter.cc:69
impeller::ColorFilter::Clone
virtual std::shared_ptr< ColorFilter > Clone() const =0
impeller::ColorFilter::ColorFilter
ColorFilter()
impeller::MatrixColorFilter::WrapWithGPUColorFilter
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....
Definition: color_filter.cc:74
impeller::BlendColorFilter::Clone
std::shared_ptr< ColorFilter > Clone() const override
Definition: color_filter.cc:61
impeller::SrgbToLinearColorFilter
Definition: color_filter.h:110
impeller::SrgbToLinearColorFilter::Clone
std::shared_ptr< ColorFilter > Clone() const override
Definition: color_filter.cc:115
impeller::LinearToSrgbColorFilter::LinearToSrgbColorFilter
LinearToSrgbColorFilter()
impeller::ColorFilter::MakeBlend
static std::shared_ptr< ColorFilter > MakeBlend(BlendMode blend_mode, Color color)
Definition: color_filter.cc:20
impeller::LinearToSrgbColorFilter::Clone
std::shared_ptr< ColorFilter > Clone() const override
Definition: color_filter.cc:141
impeller::BlendColorFilter::~BlendColorFilter
~BlendColorFilter() override
impeller::SrgbToLinearColorFilter::WrapWithGPUColorFilter
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....
Definition: color_filter.cc:102
impeller::SrgbToLinearColorFilter::~SrgbToLinearColorFilter
~SrgbToLinearColorFilter() override
impeller::LinearToSrgbColorFilter::WrapWithGPUColorFilter
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....
Definition: color_filter.cc:128
impeller::SrgbToLinearColorFilter::SrgbToLinearColorFilter
SrgbToLinearColorFilter()
impeller::LinearToSrgbColorFilter
Definition: color_filter.h:132
impeller::BlendColorFilter
Definition: color_filter.h:59
color_filter_contents.h
impeller::MatrixColorFilter::Clone
std::shared_ptr< ColorFilter > Clone() const override
Definition: color_filter.cc:89
impeller::ColorFilter::MakeMatrix
static std::shared_ptr< ColorFilter > MakeMatrix(ColorMatrix color_matrix)
Definition: color_filter.cc:25
impeller::BlendColorFilter::GetCPUColorFilterProc
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
Definition: color_filter.cc:55
impeller::ColorFilter::~ColorFilter
virtual ~ColorFilter()
impeller::ColorFilter::MakeLinearToSrgb
static std::shared_ptr< ColorFilter > MakeLinearToSrgb()
Definition: color_filter.cc:33
impeller::LinearToSrgbColorFilter::~LinearToSrgbColorFilter
~LinearToSrgbColorFilter() override
color.h
impeller::ColorFilter::WrapWithGPUColorFilter
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....
impeller::MatrixColorFilter
Definition: color_filter.h:85
impeller::ColorFilter::MakeSrgbToLinear
static std::shared_ptr< ColorFilter > MakeSrgbToLinear()
Definition: color_filter.cc:29
impeller::LinearToSrgbColorFilter::GetCPUColorFilterProc
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
Definition: color_filter.cc:136
impeller::SrgbToLinearColorFilter::GetCPUColorFilterProc
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
Definition: color_filter.cc:110
impeller::ColorMatrix
Definition: color.h:115
impeller::ColorFilterContents::AbsorbOpacity
AbsorbOpacity
Definition: color_filter_contents.h:13
impeller
Definition: aiks_context.cc:10