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

Commit 61ed98a

Browse files
author
jonahwilliams
committed
simplify.
1 parent 7623919 commit 61ed98a

File tree

1 file changed

+28
-45
lines changed

1 file changed

+28
-45
lines changed

impeller/entity/contents/linear_gradient_contents.cc

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -84,52 +84,35 @@ bool LinearGradientContents::FastLinearGradient(const ContentContext& renderer,
8484
bool horizontal_axis = start_point_.y == end_point_.y;
8585

8686
// Step 1. Compute the locations of each breakpoint along the primary axis.
87-
if (stops_.size() == 2) {
88-
// If there are exactly two stops then we have a nearly trivial gradient.
89-
// Augment each vertex and submit. This is wrong if the gradient goes end ->
90-
// start, we could fix that via some normalization.
91-
vtx_builder.AddVertices(
92-
{{rect.GetLeftTop(), colors_[0]},
93-
{rect.GetRightTop(), horizontal_axis ? colors_[1] : colors_[0]},
94-
{rect.GetLeftBottom(), horizontal_axis ? colors_[0] : colors_[1]},
95-
{rect.GetRightTop(), horizontal_axis ? colors_[1] : colors_[0]},
96-
{rect.GetLeftBottom(), horizontal_axis ? colors_[0] : colors_[1]},
97-
{rect.GetRightBottom(), colors_[1]}});
98-
} else {
99-
// Otherwise, we need to compute a point along the primary axis.
100-
std::vector<Point> points(stops_.size());
101-
for (auto i = 0u; i < stops_.size(); i++) {
102-
Scalar t = stops_[i];
103-
points[i] = (1.0 - t) * start_point_ + t * end_point_;
104-
}
105-
// Now create a rectangle that joins each segment. That will be two
106-
// triangles between each pair of points.
107-
vtx_builder.Reserve(6 * (stops_.size() - 1));
108-
for (auto i = 1u; i < points.size(); i++) {
109-
Rect section =
110-
horizontal_axis
111-
? Rect::MakeXYWH(points[i - 1].x, rect.GetY(),
112-
abs(points[i].x - points[i - 1].x),
113-
rect.GetHeight())
114-
115-
: Rect::MakeXYWH(rect.GetX(), points[i - 1].y, rect.GetWidth(),
116-
abs(points[i].y - points[i - 1].y));
117-
vtx_builder.AddVertices({
118-
{section.GetLeftTop(), colors_[i - 1]},
119-
{section.GetRightTop(),
120-
horizontal_axis ? colors_[i] : colors_[i - 1]},
121-
{section.GetLeftBottom(),
122-
horizontal_axis ? colors_[i - 1] : colors_[i]},
123-
{section.GetRightTop(),
124-
horizontal_axis ? colors_[i] : colors_[i - 1]},
125-
{section.GetLeftBottom(),
126-
horizontal_axis ? colors_[i - 1] : colors_[i]},
127-
{section.GetRightBottom(),
128-
horizontal_axis ? colors_[i] : colors_[i - 1]},
129-
});
130-
}
87+
std::vector<Point> points(stops_.size());
88+
for (auto i = 0u; i < stops_.size(); i++) {
89+
Scalar t = stops_[i];
90+
points[i] = (1.0 - t) * start_point_ + t * end_point_;
91+
}
92+
// Now create a rectangle that joins each segment. That will be two
93+
// triangles between each pair of points.
94+
vtx_builder.Reserve(6 * (stops_.size() - 1));
95+
for (auto i = 1u; i < points.size(); i++) {
96+
Rect section =
97+
horizontal_axis
98+
? Rect::MakeXYWH(points[i - 1].x, rect.GetY(),
99+
abs(points[i].x - points[i - 1].x),
100+
rect.GetHeight())
101+
102+
: Rect::MakeXYWH(rect.GetX(), points[i - 1].y, rect.GetWidth(),
103+
abs(points[i].y - points[i - 1].y));
104+
vtx_builder.AddVertices({
105+
{section.GetLeftTop(), colors_[i - 1]},
106+
{section.GetRightTop(), horizontal_axis ? colors_[i] : colors_[i - 1]},
107+
{section.GetLeftBottom(),
108+
horizontal_axis ? colors_[i - 1] : colors_[i]},
109+
{section.GetRightTop(), horizontal_axis ? colors_[i] : colors_[i - 1]},
110+
{section.GetLeftBottom(),
111+
horizontal_axis ? colors_[i - 1] : colors_[i]},
112+
{section.GetRightBottom(),
113+
horizontal_axis ? colors_[i] : colors_[i - 1]},
114+
});
131115
}
132-
133116
auto& host_buffer = renderer.GetTransientsBuffer();
134117

135118
pass.SetLabel("LinearGradient");

0 commit comments

Comments
 (0)