| Flutter Impeller |

Public Types | Public Member Functions | Static Public Member Functions | List of all members
impeller::ColorSource Class Reference

`#include <color_source.h>`

## Public Types
enum | Type { Type::kColor, Type::kImage, Type::kLinearGradient, Type::kRadialGradient, Type::kConicalGradient, Type::kSweepGradient, Type::kRuntimeEffect, Type::kScene }
using | ColorSourceProc = std::function< std::shared_ptr< ColorSourceContents >(const Paint &paint)>

## Public Member Functions
| ColorSource () noexcept
| ~ColorSource ()
Type | GetType () const
std::shared_ptr< ColorSourceContents > | GetContents (const Paint &paint) const

## Static Public Member Functions
static ColorSource | MakeColor ()
static ColorSource | MakeLinearGradient (Point start_point, Point end_point, std::vector< Color > colors, std::vector< Scalar > stops, Entity::TileMode tile_mode, Matrix effect_transform)
static ColorSource | MakeConicalGradient (Point center, Scalar radius, std::vector< Color > colors, std::vector< Scalar > stops, Point focus_center, Scalar focus_radius, Entity::TileMode tile_mode, Matrix effect_transform)
static ColorSource | MakeRadialGradient (Point center, Scalar radius, std::vector< Color > colors, std::vector< Scalar > stops, Entity::TileMode tile_mode, Matrix effect_transform)
static ColorSource | MakeSweepGradient (Point center, Degrees start_angle, Degrees end_angle, std::vector< Color > colors, std::vector< Scalar > stops, Entity::TileMode tile_mode, Matrix effect_transform)
static ColorSource | MakeImage (std::shared_ptr< Texture > texture, Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode, SamplerDescriptor sampler_descriptor, Matrix effect_transform)
static ColorSource | MakeRuntimeEffect (std::shared_ptr< RuntimeStage > runtime_stage, std::shared_ptr< std::vector< uint8_t >> uniform_data, std::vector< RuntimeEffectContents::TextureInput > texture_inputs)

## Detailed Description

Definition at line 28 of file color_source.h.

## Member Typedef Documentation

## ◆ ColorSourceProc

using impeller::ColorSource::ColorSourceProc = std::function<std::shared_ptr<ColorSourceContents>(const Paint& paint)>

Definition at line 42 of file color_source.h.

## Member Enumeration Documentation

## ◆ Type

enum impeller::ColorSource::Type
| strong

Enumerator
kColor |
kImage |
kLinearGradient |
kRadialGradient |
kConicalGradient |
kSweepGradient |
kRuntimeEffect |
kScene |

Definition at line 30 of file color_source.h.

30 {
31 kColor,
32 kImage,
33 kLinearGradient,
34 kRadialGradient,
35 kConicalGradient,
36 kSweepGradient,
37 kRuntimeEffect,
38 kScene,
39 };

## Constructor & Destructor Documentation

## ◆ ColorSource()

impeller::ColorSource::ColorSource | ( |  | ) |
| noexcept

Definition at line 32 of file color_source.cc.

33 : proc_([](const Paint& paint) -> std::shared_ptr<ColorSourceContents> {
34 auto contents = std::make_shared<SolidColorContents>();
35 contents->SetColor(paint.color);
36 return contents;
37 }){};

## ◆ ~ColorSource()

impeller::ColorSource::~ColorSource | ( |  | ) |
| default

## Member Function Documentation

## ◆ GetContents()

std::shared_ptr< ColorSourceContents > impeller::ColorSource::GetContents | ( | const Paint & | paint | ) | const

Definition at line 234 of file color_source.cc.

235 {
236 return proc_(paint);
237 }

Referenced by impeller::Paint::CreateContentsForGeometry().

## ◆ GetType()

ColorSource::Type impeller::ColorSource::GetType | ( |  | ) | const

Definition at line 230 of file color_source.cc.

230 {
231 return type_;
232 }

Referenced by impeller::Canvas::DrawVertices(), and impeller::UseColorSourceContents().

## ◆ MakeColor()

ColorSource impeller::ColorSource::MakeColor | ( |  | ) |
| static

Definition at line 41 of file color_source.cc.

41 {
42 return {};
43 }

Referenced by impeller::DlDispatcher::setColorSource().

## ◆ MakeConicalGradient()

ColorSource impeller::ColorSource::MakeConicalGradient | ( | Point | center,
|  | Scalar | radius,
|  | std::vector< Color > | colors,
|  | std::vector< Scalar > | stops,
|  | Point | focus_center,
|  | Scalar | focus_radius,
|  | Entity::TileMode | tile_mode,
|  | Matrix | effect_transform
| ) |  |
| static

Definition at line 74 of file color_source.cc.

81 {
82 ColorSource result;
83 result.type_ = Type::kConicalGradient;
84 result.proc_ = [center, radius, colors = std::move(colors),
85 stops = std::move(stops), focus_center, focus_radius,
86 tile_mode, effect_transform](const Paint& paint) {
87 std::shared_ptr<ConicalGradientContents> contents =
88 std::make_shared<ConicalGradientContents>();
89 contents->SetOpacityFactor(paint.color.alpha);
90 contents->SetColors(colors);
91 contents->SetStops(stops);
92 contents->SetCenterAndRadius(center, radius);
93 contents->SetTileMode(tile_mode);
94 contents->SetEffectTransform(effect_transform);
95 contents->SetFocus(focus_center, focus_radius);
96
97 auto radius_pt = Point(radius, radius);
98 std::vector<Point> bounds{center + radius_pt, center - radius_pt};
99 auto intrinsic_size = Rect::MakePointBounds(bounds.begin(), bounds.end());
100 if (intrinsic_size.has_value()) {
101 contents->SetColorSourceSize(intrinsic_size->GetSize());
102 }
103 return contents;
104 };
105 return result;
106 }

References kConicalGradient, and impeller::TRect< Scalar >::MakePointBounds().

Referenced by impeller::testing::CanRenderConicalGradientWithDithering(), impeller::DlDispatcher::setColorSource(), impeller::testing::TEST_F(), and impeller::testing::TEST_P().

## ◆ MakeImage()

ColorSource impeller::ColorSource::MakeImage | ( | std::shared_ptr< Texture > | texture,
|  | Entity::TileMode | x_tile_mode,
|  | Entity::TileMode | y_tile_mode,
|  | SamplerDescriptor | sampler_descriptor,
|  | Matrix | effect_transform
| ) |  |
| static

Definition at line 163 of file color_source.cc.

167 {
168 ColorSource result;
169 result.type_ = Type::kImage;
170 result.proc_ = [texture = std::move(texture), x_tile_mode, y_tile_mode,
171 sampler_descriptor = std::move(sampler_descriptor),
172 effect_transform](const Paint& paint) {
173 auto contents = std::make_shared<TiledTextureContents>();
174 contents->SetOpacityFactor(paint.color.alpha);
175 contents->SetTexture(texture);
176 contents->SetTileModes(x_tile_mode, y_tile_mode);
177 contents->SetSamplerDescriptor(sampler_descriptor);
178 contents->SetEffectTransform(effect_transform);
179 if (paint.color_filter) {
180 TiledTextureContents::ColorFilterProc filter_proc =
181 [color_filter = paint.color_filter](FilterInput::Ref input) {
182 return color_filter->WrapWithGPUColorFilter(
183 std::move(input), ColorFilterContents::AbsorbOpacity::kNo);
184 };
185 contents->SetColorFilter(filter_proc);
186 }
187 contents->SetColorSourceSize(Size::Ceil(texture->GetSize()));
188 return contents;
189 };
190 return result;
191 }

References impeller::TSize< Scalar >::Ceil(), kImage, and impeller::ColorFilterContents::kNo.

Referenced by impeller::DlDispatcher::setColorSource(), and impeller::testing::TEST_P().

## ◆ MakeLinearGradient()

ColorSource impeller::ColorSource::MakeLinearGradient | ( | Point | start_point,
|  | Point | end_point,
|  | std::vector< Color > | colors,
|  | std::vector< Scalar > | stops,
|  | Entity::TileMode | tile_mode,
|  | Matrix | effect_transform
| ) |  |
| static

Definition at line 45 of file color_source.cc.

50 {
51 ColorSource result;
52 result.type_ = Type::kLinearGradient;
53 result.proc_ = [start_point, end_point, colors = std::move(colors),
54 stops = std::move(stops), tile_mode,
55 effect_transform](const Paint& paint) {
56 auto contents = std::make_shared<LinearGradientContents>();
57 contents->SetOpacityFactor(paint.color.alpha);
58 contents->SetColors(colors);
59 contents->SetStops(stops);
60 contents->SetEndPoints(start_point, end_point);
61 contents->SetTileMode(tile_mode);
62 contents->SetEffectTransform(effect_transform);
63
64 std::vector<Point> bounds{start_point, end_point};
65 auto intrinsic_size = Rect::MakePointBounds(bounds.begin(), bounds.end());
66 if (intrinsic_size.has_value()) {
67 contents->SetColorSourceSize(intrinsic_size->GetSize());
68 }
69 return contents;
70 };
71 return result;
72 }

References kLinearGradient, and impeller::TRect< Scalar >::MakePointBounds().

Referenced by impeller::testing::CanRenderLinearGradientWithDithering(), impeller::DlDispatcher::setColorSource(), and impeller::testing::TEST_P().

## ◆ MakeRadialGradient()

ColorSource impeller::ColorSource::MakeRadialGradient | ( | Point | center,
|  | Scalar | radius,
|  | std::vector< Color > | colors,
|  | std::vector< Scalar > | stops,
|  | Entity::TileMode | tile_mode,
|  | Matrix | effect_transform
| ) |  |
| static

Definition at line 108 of file color_source.cc.

113 {
114 ColorSource result;
115 result.type_ = Type::kRadialGradient;
116 result.proc_ = [center, radius, colors = std::move(colors),
117 stops = std::move(stops), tile_mode,
118 effect_transform](const Paint& paint) {
119 auto contents = std::make_shared<RadialGradientContents>();
120 contents->SetOpacityFactor(paint.color.alpha);
121 contents->SetColors(colors);
122 contents->SetStops(stops);
123 contents->SetCenterAndRadius(center, radius);
124 contents->SetTileMode(tile_mode);
125 contents->SetEffectTransform(effect_transform);
126
127 auto radius_pt = Point(radius, radius);
128 std::vector<Point> bounds{center + radius_pt, center - radius_pt};
129 auto intrinsic_size = Rect::MakePointBounds(bounds.begin(), bounds.end());
130 if (intrinsic_size.has_value()) {
131 contents->SetColorSourceSize(intrinsic_size->GetSize());
132 }
133 return contents;
134 };
135 return result;
136 }

References kRadialGradient, and impeller::TRect< Scalar >::MakePointBounds().

Referenced by impeller::testing::CanRenderRadialGradientWithDithering(), impeller::DlDispatcher::setColorSource(), and impeller::testing::TEST_P().

## ◆ MakeRuntimeEffect()

ColorSource impeller::ColorSource::MakeRuntimeEffect | ( | std::shared_ptr< RuntimeStage > | runtime_stage,
|  | std::shared_ptr< std::vector< uint8_t >> | uniform_data,
|  | std::vector< RuntimeEffectContents::TextureInput > | texture_inputs
| ) |  |
| static

Definition at line 193 of file color_source.cc.

196 {
197 ColorSource result;
198 result.type_ = Type::kRuntimeEffect;
199 result.proc_ = [runtime_stage = std::move(runtime_stage),
200 uniform_data = std::move(uniform_data),
201 texture_inputs =
202 std::move(texture_inputs)](const Paint& paint) {
203 auto contents = std::make_shared<RuntimeEffectContents>();
204 contents->SetOpacityFactor(paint.color.alpha);
205 contents->SetRuntimeStage(runtime_stage);
206 contents->SetUniformData(uniform_data);
207 contents->SetTextureInputs(texture_inputs);
208 return contents;
209 };
210 return result;
211 }

References kRuntimeEffect.

Referenced by impeller::DlDispatcher::setColorSource(), and impeller::testing::TEST_P().

## ◆ MakeSweepGradient()

ColorSource impeller::ColorSource::MakeSweepGradient | ( | Point | center,
|  | Degrees | start_angle,
|  | Degrees | end_angle,
|  | std::vector< Color > | colors,
|  | std::vector< Scalar > | stops,
|  | Entity::TileMode | tile_mode,
|  | Matrix | effect_transform
| ) |  |
| static

Definition at line 138 of file color_source.cc.

144 {
145 ColorSource result;
146 result.type_ = Type::kSweepGradient;
147 result.proc_ = [center, start_angle, end_angle, colors = std::move(colors),
148 stops = std::move(stops), tile_mode,
149 effect_transform](const Paint& paint) {
150 auto contents = std::make_shared<SweepGradientContents>();
151 contents->SetOpacityFactor(paint.color.alpha);
152 contents->SetCenterAndAngles(center, start_angle, end_angle);
153 contents->SetColors(colors);
154 contents->SetStops(stops);
155 contents->SetTileMode(tile_mode);
156 contents->SetEffectTransform(effect_transform);
157
158 return contents;
159 };
160 return result;
161 }

References kSweepGradient.

Referenced by impeller::testing::CanRenderSweepGradientWithDithering(), impeller::DlDispatcher::setColorSource(), and impeller::testing::TEST_P().

The documentation for this class was generated from the following files:

- impeller/aiks/color_source.h
- impeller/aiks/color_source.cc

impeller::ColorSource::Type::kLinearGradient
@ kLinearGradient
impeller::ColorSource::Type::kRadialGradient
@ kRadialGradient
impeller::FilterInput::Ref
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:32
impeller::ShaderType::kImage
@ kImage
impeller::TSize< Scalar >::Ceil
constexpr TSize Ceil() const
Definition: size.h:96
impeller::ColorFilterContents::AbsorbOpacity::kNo
@ kNo
impeller::TiledTextureContents::ColorFilterProc
std::function< std::shared_ptr< ColorFilterContents >(FilterInput::Ref)> ColorFilterProc
Definition: tiled_texture_contents.h:29
impeller::TRect< Scalar >::MakePointBounds
constexpr static std::optional< TRect > MakePointBounds(const U &value)
Definition: rect.h:49
impeller::kColor
@ kColor
Definition: geometry.h:36
impeller::Point
TPoint< Scalar > Point
Definition: point.h:308
impeller::ColorSource::Type::kRuntimeEffect
@ kRuntimeEffect
impeller::ColorSource::ColorSource
ColorSource() noexcept
Definition: color_source.cc:32
impeller::ColorSource::Type::kImage
@ kImage
impeller::ColorSource::Type::kConicalGradient
@ kConicalGradient
impeller::ColorSource::Type::kSweepGradient
@ kSweepGradient