| Flutter Impeller |

color_source.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_SOURCE_H_
6 #define FLUTTER_IMPELLER_AIKS_COLOR_SOURCE_H_
7
8 #include <functional>
9 #include <memory>
10 #include <variant>
11 #include <vector>
12
13 #include "impeller/entity/contents/runtime_effect_contents.h"
14 #include "impeller/entity/entity.h"
15 #include "impeller/geometry/color.h"
16 #include "impeller/geometry/matrix.h"
17 #include "impeller/geometry/point.h"
18 #include "impeller/runtime_stage/runtime_stage.h"
19
20 #if IMPELLER_ENABLE_3D
21 #include "impeller/scene/node.h" // nogncheck
22 #endif // IMPELLER_ENABLE_3D
23
24 namespace impeller {
25
26 struct Paint;
27
28 struct LinearGradientData {
29 Point start_point;
30 Point end_point;
31 std::vector<Color> colors;
32 std::vector<Scalar> stops;
33 Entity::TileMode tile_mode;
34 Matrix effect_transform;
35 };
36
37 struct RadialGradientData {
38 Point center;
39 Scalar radius;
40 std::vector<Color> colors;
41 std::vector<Scalar> stops;
42 Entity::TileMode tile_mode;
43 Matrix effect_transform;
44 };
45
46 struct ConicalGradientData {
47 Point center;
48 Scalar radius;
49 std::vector<Color> colors;
50 std::vector<Scalar> stops;
51 Point focus_center;
52 Scalar focus_radius;
53 Entity::TileMode tile_mode;
54 Matrix effect_transform;
55 };
56
57 struct SweepGradientData {
58 Point center;
59 Degrees start_angle;
60 Degrees end_angle;
61 std::vector<Color> colors;
62 std::vector<Scalar> stops;
63 Entity::TileMode tile_mode;
64 Matrix effect_transform;
65 };
66
67 struct ImageData {
68 std::shared_ptr<Texture> texture;
69 Entity::TileMode x_tile_mode;
70 Entity::TileMode y_tile_mode;
71 SamplerDescriptor sampler_descriptor;
72 Matrix effect_transform;
73 };
74
75 struct RuntimeEffectData {
76 std::shared_ptr<RuntimeStage> runtime_stage;
77 std::shared_ptr<std::vector<uint8_t>> uniform_data;
78 std::vector<RuntimeEffectContents::TextureInput> texture_inputs;
79 };
80
81 #if IMPELLER_ENABLE_3D
82 struct SceneData {
83 std::shared_ptr<scene::Node> scene_node;
84 Matrix camera_transform;
85 };
86 #endif // IMPELLER_ENABLE_3D
87
88 using ColorSourceData = std::variant<LinearGradientData,
89 RadialGradientData,
90 ConicalGradientData,
91 SweepGradientData,
92 ImageData,
93 RuntimeEffectData,
94 #if IMPELLER_ENABLE_3D
95 SceneData,
96 #endif // IMPELLER_ENABLE_3D
97 std::monostate>;
98
99 class ColorSource {
100 public:
101 enum class Type {
102 kColor,
103 kImage,
104 kLinearGradient,
105 kRadialGradient,
106 kConicalGradient,
107 kSweepGradient,
108 kRuntimeEffect,
109 kScene,
110 };
111
112 ColorSource() noexcept;
113
114 ~ColorSource();
115
116 static ColorSource MakeColor();
117
118 static ColorSource MakeLinearGradient(Point start_point,
119 Point end_point,
120 std::vector<Color> colors,
121 std::vector<Scalar> stops,
122 Entity::TileMode tile_mode,
123 Matrix effect_transform);
124
125 static ColorSource MakeConicalGradient(Point center,
126 Scalar radius,
127 std::vector<Color> colors,
128 std::vector<Scalar> stops,
129 Point focus_center,
130 Scalar focus_radius,
131 Entity::TileMode tile_mode,
132 Matrix effect_transform);
133
134 static ColorSource MakeRadialGradient(Point center,
135 Scalar radius,
136 std::vector<Color> colors,
137 std::vector<Scalar> stops,
138 Entity::TileMode tile_mode,
139 Matrix effect_transform);
140
141 static ColorSource MakeSweepGradient(Point center,
142 Degrees start_angle,
143 Degrees end_angle,
144 std::vector<Color> colors,
145 std::vector<Scalar> stops,
146 Entity::TileMode tile_mode,
147 Matrix effect_transform);
148
149 static ColorSource MakeImage(std::shared_ptr<Texture> texture,
150 Entity::TileMode x_tile_mode,
151 Entity::TileMode y_tile_mode,
152 SamplerDescriptor sampler_descriptor,
153 Matrix effect_transform);
154
155 static ColorSource MakeRuntimeEffect(
156 std::shared_ptr<RuntimeStage> runtime_stage,
157 std::shared_ptr<std::vector<uint8_t>> uniform_data,
158 std::vector<RuntimeEffectContents::TextureInput> texture_inputs);
159
160 #if IMPELLER_ENABLE_3D
161 static ColorSource MakeScene(std::shared_ptr<scene::Node> scene_node,
162 Matrix camera_transform);
163 #endif // IMPELLER_ENABLE_3D
164
165 Type GetType() const;
166
167 std::shared_ptr<ColorSourceContents> GetContents(const Paint& paint) const;
168
169 const ColorSourceData& GetData() const;
170
171 private:
172 Type type_ = Type::kColor;
173 ColorSourceData color_source_data_;
174 };
175
176 } // namespace impeller
177
178 #endif // FLUTTER_IMPELLER_AIKS_COLOR_SOURCE_H_
impeller::ColorSource::Type::kScene
@ kScene
impeller::SweepGradientData::tile_mode
Entity::TileMode tile_mode
Definition: color_source.h:63
impeller::ColorSource::Type::kLinearGradient
@ kLinearGradient
impeller::SweepGradientData::center
Point center
Definition: color_source.h:58
impeller::ColorSource::GetContents
std::shared_ptr< ColorSourceContents > GetContents(const Paint &paint) const
Definition: color_source.cc:264
point.h
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::ColorSource::Type::kRadialGradient
@ kRadialGradient
entity.h
impeller::RuntimeEffectData
Definition: color_source.h:75
impeller::ColorSource::MakeLinearGradient
static ColorSource MakeLinearGradient(Point start_point, Point end_point, std::vector< Color > colors, std::vector< Scalar > stops, Entity::TileMode tile_mode, Matrix effect_transform)
Definition: color_source.cc:166
impeller::Paint
Definition: paint.h:23
impeller::Color
Definition: color.h:124
impeller::LinearGradientData::colors
std::vector< Color > colors
Definition: color_source.h:31
impeller::RuntimeEffectData::uniform_data
std::shared_ptr< std::vector< uint8_t > > uniform_data
Definition: color_source.h:77
impeller::LinearGradientData
Definition: color_source.h:28
impeller::SweepGradientData::stops
std::vector< Scalar > stops
Definition: color_source.h:62
impeller::LinearGradientData::start_point
Point start_point
Definition: color_source.h:29
impeller::ConicalGradientData::colors
std::vector< Color > colors
Definition: color_source.h:49
impeller::RadialGradientData::stops
std::vector< Scalar > stops
Definition: color_source.h:41
impeller::ColorSource::MakeSweepGradient
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)
Definition: color_source.cc:210
impeller::ColorSource::MakeColor
static ColorSource MakeColor()
Definition: color_source.cc:162
impeller::SweepGradientData::colors
std::vector< Color > colors
Definition: color_source.h:61
impeller::ColorSource::MakeImage
static ColorSource MakeImage(std::shared_ptr< Texture > texture, Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode, SamplerDescriptor sampler_descriptor, Matrix effect_transform)
Definition: color_source.cc:225
impeller::RadialGradientData::effect_transform
Matrix effect_transform
Definition: color_source.h:43
impeller::RuntimeEffectData::texture_inputs
std::vector< RuntimeEffectContents::TextureInput > texture_inputs
Definition: color_source.h:78
impeller::LinearGradientData::effect_transform
Matrix effect_transform
Definition: color_source.h:34
impeller::RuntimeStage
Definition: runtime_stage.h:20
impeller::ColorSourceData
std::variant< LinearGradientData, RadialGradientData, ConicalGradientData, SweepGradientData, ImageData, RuntimeEffectData, std::monostate > ColorSourceData
Definition: color_source.h:97
runtime_effect_contents.h
impeller::SweepGradientData::effect_transform
Matrix effect_transform
Definition: color_source.h:64
impeller::RuntimeEffectContents
Definition: runtime_effect_contents.h:17
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:15
matrix.h
impeller::Entity
Definition: entity.h:20
impeller::Texture
Definition: texture.h:17
impeller::ColorSource
Definition: color_source.h:99
runtime_stage.h
node.h
impeller::ColorSource::MakeConicalGradient
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)
Definition: color_source.cc:180
impeller::ColorSource::Type::kRuntimeEffect
@ kRuntimeEffect
impeller::LinearGradientData::end_point
Point end_point
Definition: color_source.h:30
impeller::ImageData
Definition: color_source.h:67
impeller::ImageData::y_tile_mode
Entity::TileMode y_tile_mode
Definition: color_source.h:70
impeller::LinearGradientData::stops
std::vector< Scalar > stops
Definition: color_source.h:32
impeller::ConicalGradientData
Definition: color_source.h:46
impeller::ConicalGradientData::stops
std::vector< Scalar > stops
Definition: color_source.h:50
impeller::SweepGradientData
Definition: color_source.h:57
impeller::SweepGradientData::start_angle
Degrees start_angle
Definition: color_source.h:59
impeller::ColorSource::ColorSource
ColorSource() noexcept
Definition: color_source.cc:158
impeller::RadialGradientData::radius
Scalar radius
Definition: color_source.h:39
impeller::Entity::TileMode
TileMode
Definition: entity.h:42
impeller::ColorSource::MakeRadialGradient
static ColorSource MakeRadialGradient(Point center, Scalar radius, std::vector< Color > colors, std::vector< Scalar > stops, Entity::TileMode tile_mode, Matrix effect_transform)
Definition: color_source.cc:196
impeller::ConicalGradientData::focus_center
Point focus_center
Definition: color_source.h:51
impeller::ImageData::x_tile_mode
Entity::TileMode x_tile_mode
Definition: color_source.h:69
impeller::ConicalGradientData::tile_mode
Entity::TileMode tile_mode
Definition: color_source.h:53
impeller::ColorSource::Type::kImage
@ kImage
impeller::ColorSource::MakeRuntimeEffect
static ColorSource MakeRuntimeEffect(std::shared_ptr< RuntimeStage > runtime_stage, std::shared_ptr< std::vector< uint8_t >> uniform_data, std::vector< RuntimeEffectContents::TextureInput > texture_inputs)
Definition: color_source.cc:238
impeller::RuntimeEffectData::runtime_stage
std::shared_ptr< RuntimeStage > runtime_stage
Definition: color_source.h:76
impeller::ImageData::texture
std::shared_ptr< Texture > texture
Definition: color_source.h:68
impeller::ColorSource::Type::kConicalGradient
@ kConicalGradient
std
Definition: comparable.h:95
impeller::ColorSource::Type
Type
Definition: color_source.h:101
impeller::RadialGradientData
Definition: color_source.h:37
impeller::TPoint< Scalar >
impeller::RadialGradientData::colors
std::vector< Color > colors
Definition: color_source.h:40
impeller::ConicalGradientData::center
Point center
Definition: color_source.h:47
impeller::ImageData::sampler_descriptor
SamplerDescriptor sampler_descriptor
Definition: color_source.h:71
impeller::ColorSource::GetData
const ColorSourceData & GetData() const
Definition: color_source.cc:269
impeller::LinearGradientData::tile_mode
Entity::TileMode tile_mode
Definition: color_source.h:33
paint
const Paint & paint
Definition: color_source.cc:38
impeller::ConicalGradientData::focus_radius
Scalar focus_radius
Definition: color_source.h:52
impeller::Degrees
Definition: scalar.h:46
color.h
impeller::SweepGradientData::end_angle
Degrees end_angle
Definition: color_source.h:60
impeller::RadialGradientData::tile_mode
Entity::TileMode tile_mode
Definition: color_source.h:42
impeller::ConicalGradientData::radius
Scalar radius
Definition: color_source.h:48
impeller::ColorSource::Type::kSweepGradient
@ kSweepGradient
impeller
Definition: aiks_blend_unittests.cc:18
impeller::ConicalGradientData::effect_transform
Matrix effect_transform
Definition: color_source.h:54
impeller::ColorSource::Type::kColor
@ kColor
impeller::ColorSource::GetType
Type GetType() const
Definition: color_source.cc:260
impeller::ImageData::effect_transform
Matrix effect_transform
Definition: color_source.h:72
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::RadialGradientData::center
Point center
Definition: color_source.h:38