@@ -80,6 +80,47 @@ static std::shared_ptr<Contents> CreateContentsForGeometryWithFilters(
80
80
return contents_copy;
81
81
}
82
82
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
+
83
124
static std::shared_ptr<Contents> CreatePathContentsWithFilters (
84
125
const Paint& paint,
85
126
const Path& path) {
@@ -891,27 +932,22 @@ void Canvas::DrawVertices(const std::shared_ptr<VerticesGeometry>& vertices,
891
932
892
933
// If there is are per-vertex colors, an image, and the blend mode
893
934
// 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
+ }
915
951
}
916
952
917
953
auto src_paint = paint;
0 commit comments