Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 51b88e0

Browse files
author
jonahwilliams
committed
use visitor type, fix offsets.
1 parent fb976a8 commit 51b88e0

File tree

4 files changed

+66
-25
lines changed

4 files changed

+66
-25
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2754,10 +2754,9 @@ TEST_P(AiksTest, VerticesGeometryColorUVPositionData) {
27542754
std::vector<uint16_t> indices = {};
27552755
std::vector<Point> texture_coordinates = {};
27562756
std::vector<Color> vertex_colors = {
2757-
Color::Red().WithAlpha(0.5),
2758-
Color::Blue().WithAlpha(0.5),
2759-
Color::Green().WithAlpha(0.5),
2760-
Color::Red().WithAlpha(0.5),
2757+
Color::Red().WithAlpha(0.5), Color::Blue().WithAlpha(0.5),
2758+
Color::Green().WithAlpha(0.5), Color::Red().WithAlpha(0.5),
2759+
Color::Blue().WithAlpha(0.5), Color::Green().WithAlpha(0.5),
27612760
};
27622761
auto geometry = std::make_shared<VerticesGeometry>(
27632762
vertices, indices, texture_coordinates, vertex_colors,

impeller/aiks/canvas.cc

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,47 @@ static std::shared_ptr<Contents> CreateContentsForGeometryWithFilters(
8080
return contents_copy;
8181
}
8282

83+
struct GetTextureColorSourceDataVisitor {
84+
GetTextureColorSourceDataVisitor() {}
85+
86+
std::optional<ImageData> operator()(const LinearGradientData& data) {
87+
return std::nullopt;
88+
}
89+
90+
std::optional<ImageData> operator()(const RadialGradientData& data) {
91+
return std::nullopt;
92+
}
93+
94+
std::optional<ImageData> operator()(const ConicalGradientData& data) {
95+
return std::nullopt;
96+
}
97+
98+
std::optional<ImageData> operator()(const SweepGradientData& data) {
99+
return std::nullopt;
100+
}
101+
102+
std::optional<ImageData> operator()(const ImageData& data) { return data; }
103+
104+
std::optional<ImageData> operator()(const RuntimeEffectData& data) {
105+
return std::nullopt;
106+
}
107+
108+
std::optional<ImageData> operator()(const std::monostate& data) {
109+
return std::nullopt;
110+
}
111+
112+
#if IMPELLER_ENABLE_3D
113+
std::shared_ptr<ColorSourceContents> operator()(const SceneData& data) {
114+
return std::nullopt;
115+
}
116+
#endif // IMPELLER_ENABLE_3D
117+
};
118+
119+
static std::optional<ImageData> GetImageColorSourceData(
120+
const ColorSource& color_source) {
121+
return std::visit(GetTextureColorSourceDataVisitor{}, color_source.GetData());
122+
}
123+
83124
static std::shared_ptr<Contents> CreatePathContentsWithFilters(
84125
const Paint& paint,
85126
const Path& path) {
@@ -891,27 +932,22 @@ void Canvas::DrawVertices(const std::shared_ptr<VerticesGeometry>& vertices,
891932

892933
// If there is are per-vertex colors, an image, and the blend mode
893934
// is simple we can draw without a sub-renderpass.
894-
if (blend_mode <= BlendMode::kModulate && vertices->HasVertexColors() &&
895-
paint.color_source.GetType() == ColorSource::Type::kImage) {
896-
auto contents = std::make_shared<VerticesSimpleBlendContents>();
897-
contents->SetBlendMode(blend_mode);
898-
contents->SetAlpha(paint.color.alpha);
899-
contents->SetGeometry(vertices);
900-
901-
std::shared_ptr<ColorSourceContents> raw_color_source_contents =
902-
paint.color_source.GetContents(paint);
903-
TiledTextureContents* color_contents =
904-
static_cast<TiledTextureContents*>(raw_color_source_contents.get());
905-
FML_DCHECK(color_contents);
906-
907-
contents->SetEffectTransform(color_contents->GetInverseEffectTransform());
908-
contents->SetTexture(color_contents->GetTexture());
909-
auto [tmx, tmy] = color_contents->GetTileModes();
910-
contents->SetTileMode(tmx, tmy);
911-
912-
entity.SetContents(paint.WithFilters(std::move(contents)));
913-
AddEntityToCurrentPass(std::move(entity));
914-
return;
935+
if (blend_mode <= BlendMode::kModulate && vertices->HasVertexColors()) {
936+
if (auto maybe_image_data = GetImageColorSourceData(paint.color_source)) {
937+
auto image_data = maybe_image_data.value();
938+
auto contents = std::make_shared<VerticesSimpleBlendContents>();
939+
contents->SetBlendMode(blend_mode);
940+
contents->SetAlpha(paint.color.alpha);
941+
contents->SetGeometry(vertices);
942+
943+
contents->SetEffectTransform(image_data.effect_transform.Invert());
944+
contents->SetTexture(image_data.texture);
945+
contents->SetTileMode(image_data.x_tile_mode, image_data.y_tile_mode);
946+
947+
entity.SetContents(paint.WithFilters(std::move(contents)));
948+
AddEntityToCurrentPass(std::move(entity));
949+
return;
950+
}
915951
}
916952

917953
auto src_paint = paint;

impeller/aiks/color_source.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,8 @@ std::shared_ptr<ColorSourceContents> ColorSource::GetContents(
266266
return std::visit(CreateContentsVisitor{paint}, color_source_data_);
267267
}
268268

269+
const ColorSourceData& ColorSource::GetData() const {
270+
return color_source_data_;
271+
}
272+
269273
} // namespace impeller

impeller/aiks/color_source.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ class ColorSource {
166166

167167
std::shared_ptr<ColorSourceContents> GetContents(const Paint& paint) const;
168168

169+
const ColorSourceData& GetData() const;
170+
169171
private:
170172
Type type_ = Type::kColor;
171173
ColorSourceData color_source_data_;

0 commit comments

Comments
 (0)