35struct CreateContentsVisitor {
36 explicit CreateContentsVisitor(
const Paint& p_paint) :
paint(p_paint) {}
40 std::shared_ptr<ColorSourceContents> operator()(
41 const LinearGradientData&
data) {
42 auto contents = std::make_shared<LinearGradientContents>();
43 contents->SetOpacityFactor(
paint.color.alpha);
44 contents->SetColors(
data.colors);
45 contents->SetStops(
data.stops);
46 contents->SetEndPoints(
data.start_point,
data.end_point);
47 contents->SetTileMode(
data.tile_mode);
48 contents->SetEffectTransform(
data.effect_transform);
52 if (intrinsic_size.has_value()) {
53 contents->SetColorSourceSize(intrinsic_size->GetSize());
58 std::shared_ptr<ColorSourceContents> operator()(
59 const RadialGradientData&
data) {
60 auto contents = std::make_shared<RadialGradientContents>();
61 contents->SetOpacityFactor(
paint.color.alpha);
62 contents->SetColors(
data.colors);
63 contents->SetStops(
data.stops);
64 contents->SetCenterAndRadius(
data.center,
data.radius);
65 contents->SetTileMode(
data.tile_mode);
66 contents->SetEffectTransform(
data.effect_transform);
69 std::vector<Point>
bounds{
data.center + radius_pt,
data.center - radius_pt};
71 if (intrinsic_size.has_value()) {
72 contents->SetColorSourceSize(intrinsic_size->GetSize());
77 std::shared_ptr<ColorSourceContents> operator()(
78 const ConicalGradientData&
data) {
79 std::shared_ptr<ConicalGradientContents> contents =
80 std::make_shared<ConicalGradientContents>();
81 contents->SetOpacityFactor(
paint.color.alpha);
82 contents->SetColors(
data.colors);
83 contents->SetStops(
data.stops);
84 contents->SetCenterAndRadius(
data.center,
data.radius);
85 contents->SetTileMode(
data.tile_mode);
86 contents->SetEffectTransform(
data.effect_transform);
87 contents->SetFocus(
data.focus_center,
data.focus_radius);
90 std::vector<Point>
bounds{
data.center + radius_pt,
data.center - radius_pt};
92 if (intrinsic_size.has_value()) {
93 contents->SetColorSourceSize(intrinsic_size->GetSize());
98 std::shared_ptr<ColorSourceContents> operator()(
99 const SweepGradientData&
data) {
100 auto contents = std::make_shared<SweepGradientContents>();
101 contents->SetOpacityFactor(
paint.color.alpha);
102 contents->SetCenterAndAngles(
data.center,
data.start_angle,
data.end_angle);
103 contents->SetColors(
data.colors);
104 contents->SetStops(
data.stops);
105 contents->SetTileMode(
data.tile_mode);
106 contents->SetEffectTransform(
data.effect_transform);
111 std::shared_ptr<ColorSourceContents> operator()(
const ImageData&
data) {
112 auto contents = std::make_shared<TiledTextureContents>();
113 contents->SetOpacityFactor(
paint.color.alpha);
114 contents->SetTexture(
data.texture);
115 contents->SetTileModes(
data.x_tile_mode,
data.y_tile_mode);
116 contents->SetSamplerDescriptor(
data.sampler_descriptor);
117 contents->SetEffectTransform(
data.effect_transform);
118 if (
paint.color_filter) {
124 contents->SetColorFilter(filter_proc);
126 contents->SetColorSourceSize(
Size::Ceil(
data.texture->GetSize()));
130 std::shared_ptr<ColorSourceContents> operator()(
131 const RuntimeEffectData&
data) {
132 auto contents = std::make_shared<RuntimeEffectContents>();
133 contents->SetOpacityFactor(
paint.color.alpha);
134 contents->SetRuntimeStage(
data.runtime_stage);
135 contents->SetUniformData(
data.uniform_data);
136 contents->SetTextureInputs(
data.texture_inputs);
140 std::shared_ptr<ColorSourceContents> operator()(
const std::monostate&
data) {
141 auto contents = std::make_shared<SolidColorContents>();
142 contents->SetColor(
paint.color);
146#if IMPELLER_ENABLE_3D
147 std::shared_ptr<ColorSourceContents> operator()(
const SceneData&
data) {
148 auto contents = std::make_shared<SceneContents>();
149 contents->SetOpacityFactor(
paint.color.alpha);
150 contents->SetNode(
data.scene_node);
151 contents->SetCameraTransform(
data.camera_transform);
168 std::vector<Color>
colors,
169 std::vector<Scalar> stops,
171 Matrix effect_transform) {
174 result.color_source_data_ =
176 std::move(stops), tile_mode, effect_transform};
182 std::vector<Color>
colors,
183 std::vector<Scalar> stops,
187 Matrix effect_transform) {
191 center, radius, std::move(
colors), std::move(stops),
192 focus_center, focus_radius, tile_mode, effect_transform};
198 std::vector<Color>
colors,
199 std::vector<Scalar> stops,
201 Matrix effect_transform) {
204 result.color_source_data_ =
206 std::move(stops), tile_mode, effect_transform};
213 std::vector<Color>
colors,
214 std::vector<Scalar> stops,
216 Matrix effect_transform) {
220 center, start_angle, end_angle, std::move(
colors),
221 std::move(stops), tile_mode, effect_transform};
229 Matrix effect_transform) {
232 result.color_source_data_ =
234 std::move(sampler_descriptor), effect_transform};
239 std::shared_ptr<RuntimeStage> runtime_stage,
240 std::shared_ptr<std::vector<uint8_t>> uniform_data,
241 std::vector<RuntimeEffectContents::TextureInput> texture_inputs) {
244 result.color_source_data_ =
246 std::move(texture_inputs)};
250#if IMPELLER_ENABLE_3D
251ColorSource ColorSource::MakeScene(std::shared_ptr<scene::Node> scene_node,
252 Matrix camera_transform) {
255 result.color_source_data_ = SceneData{scene_node, camera_transform};
266 return std::visit(CreateContentsVisitor{
paint}, color_source_data_);
270 return color_source_data_;
static sk_sp< SkImage > color_filter(const SkImage *image, SkColorFilter *colorFilter)
const ColorSourceData & GetData() const
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 MakeColor()
static ColorSource MakeRadialGradient(Point center, Scalar radius, 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 MakeSweepGradient(Point center, Degrees start_angle, Degrees end_angle, std::vector< Color > colors, std::vector< Scalar > stops, Entity::TileMode tile_mode, Matrix effect_transform)
std::shared_ptr< ColorSourceContents > GetContents(const Paint &paint) const
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 MakeRuntimeEffect(std::shared_ptr< RuntimeStage > runtime_stage, std::shared_ptr< std::vector< uint8_t > > uniform_data, std::vector< RuntimeEffectContents::TextureInput > texture_inputs)
std::function< std::shared_ptr< ColorFilterContents >(FilterInput::Ref)> ColorFilterProc
Optional< SkRect > bounds
PODArray< SkColor > colors
std::variant< LinearGradientData, RadialGradientData, ConicalGradientData, SweepGradientData, ImageData, RuntimeEffectData, std::monostate > ColorSourceData
A 4x4 matrix using column-major storage.
static constexpr std::optional< TRect > MakePointBounds(const U &value)
constexpr TSize Ceil() const
std::shared_ptr< const fml::Mapping > data