| 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 27 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 41 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 29 of file color_source.h.

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

## 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 238 of file color_source.cc.

239 {
240 return proc_(paint);
241 }

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

## ◆ GetType()

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

Definition at line 234 of file color_source.cc.

234 {
235 return type_;
236 }

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 75 of file color_source.cc.

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

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 167 of file color_source.cc.

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

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

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

## ◆ 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->SetDither(paint.dither);
63 contents->SetEffectTransform(effect_transform);
64
65 std::vector<Point> bounds{start_point, end_point};
66 auto intrinsic_size = Rect::MakePointBounds(bounds.begin(), bounds.end());
67 if (intrinsic_size.has_value()) {
68 contents->SetColorSourceSize(intrinsic_size->size);
69 }
70 return contents;
71 };
72 return result;
73 }

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 110 of file color_source.cc.

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

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 197 of file color_source.cc.

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

References kRuntimeEffect.

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

## ◆ 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 141 of file color_source.cc.

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

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:31
impeller::ShaderType::kImage
@ kImage
impeller::TSize::Ceil
constexpr TSize Ceil() const
Definition: size.h:91
impeller::ColorFilterContents::AbsorbOpacity::kNo
@ kNo
impeller::TiledTextureContents::ColorFilterProc
std::function< std::shared_ptr< ColorFilterContents >(FilterInput::Ref)> ColorFilterProc
Definition: tiled_texture_contents.h:28
impeller::kColor
@ kColor
Definition: geometry.h:27
impeller::Point
TPoint< Scalar > Point
Definition: point.h:306
impeller::ColorSource::Type::kRuntimeEffect
@ kRuntimeEffect
impeller::TRect< Scalar >::MakePointBounds
constexpr static std::optional< TRect > MakePointBounds(const PointIter first, const PointIter last)
Definition: rect.h:57
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