Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 66096b5

Browse files
chinmaygardednfield
authored andcommitted
Add support for path composition in path builder.
1 parent f83a021 commit 66096b5

File tree

4 files changed

+40
-26
lines changed

4 files changed

+40
-26
lines changed

impeller/display_list/display_list_impeller.cc

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,22 @@ static PathBuilder::RoundingRadii ToRoundingRadii(const SkRRect& rrect) {
231231
return radii;
232232
}
233233

234+
static Path ToPath(const SkPath& path) {
235+
UNIMPLEMENTED;
236+
return Path{};
237+
}
238+
239+
static Path ToPath(const SkRRect& rrect) {
240+
return PathBuilder{}
241+
.AddRoundedRect(ToRect(rrect.getBounds()), ToRoundingRadii(rrect))
242+
.TakePath();
243+
}
244+
234245
// |flutter::Dispatcher|
235246
void DisplayListImpeller::clipRRect(const SkRRect& rrect,
236247
SkClipOp clip_op,
237248
bool is_aa) {
238-
auto path =
239-
PathBuilder{}
240-
.AddRoundedRect(ToRect(rrect.getBounds()), ToRoundingRadii(rrect))
241-
.TakePath();
242-
canvas_.ClipPath(std::move(path));
243-
}
244-
245-
static Path ToPath(const SkPath& path) {
246-
UNIMPLEMENTED;
247-
return Path{};
249+
canvas_.ClipPath(ToPath(rrect));
248250
}
249251

250252
// |flutter::Dispatcher|
@@ -290,17 +292,16 @@ void DisplayListImpeller::drawCircle(const SkPoint& center, SkScalar radius) {
290292

291293
// |flutter::Dispatcher|
292294
void DisplayListImpeller::drawRRect(const SkRRect& rrect) {
293-
auto path =
294-
PathBuilder{}
295-
.AddRoundedRect(ToRect(rrect.getBounds()), ToRoundingRadii(rrect))
296-
.TakePath();
297-
canvas_.DrawPath(std::move(path), paint_);
295+
canvas_.DrawPath(ToPath(rrect), paint_);
298296
}
299297

300298
// |flutter::Dispatcher|
301299
void DisplayListImpeller::drawDRRect(const SkRRect& outer,
302300
const SkRRect& inner) {
303-
UNIMPLEMENTED;
301+
PathBuilder builder;
302+
builder.AddPath(ToPath(outer));
303+
builder.AddPath(ToPath(inner));
304+
canvas_.DrawPath(builder.TakePath(FillType::kOdd), paint_);
304305
}
305306

306307
// |flutter::Dispatcher|

impeller/geometry/path.cc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,26 +155,23 @@ bool Path::UpdateCubicComponentAtIndex(size_t index,
155155
return true;
156156
}
157157

158-
static void AddPoints(std::vector<Point>& dest, const std::vector<Point>& src) {
159-
dest.reserve(dest.size() + src.size());
160-
dest.insert(dest.end(), src.begin(), src.end());
161-
}
162-
163158
std::vector<Point> Path::CreatePolyline(
164159
const SmoothingApproximation& approximation) const {
165160
std::vector<Point> points;
161+
auto collect_points = [&points](const std::vector<Point>& collection) {
162+
points.reserve(points.size() + collection.size());
163+
points.insert(points.end(), collection.begin(), collection.end());
164+
};
166165
for (const auto& component : components_) {
167166
switch (component.type) {
168167
case ComponentType::kLinear:
169-
AddPoints(points, linears_[component.index].CreatePolyline());
168+
collect_points(linears_[component.index].CreatePolyline());
170169
break;
171170
case ComponentType::kQuadratic:
172-
AddPoints(points,
173-
quads_[component.index].CreatePolyline(approximation));
171+
collect_points(quads_[component.index].CreatePolyline(approximation));
174172
break;
175173
case ComponentType::kCubic:
176-
AddPoints(points,
177-
cubics_[component.index].CreatePolyline(approximation));
174+
collect_points(cubics_[component.index].CreatePolyline(approximation));
178175
break;
179176
}
180177
}

impeller/geometry/path_builder.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,18 @@ const Path& PathBuilder::GetCurrentPath() const {
320320
return prototype_;
321321
}
322322

323+
PathBuilder& PathBuilder::AddPath(const Path& path) {
324+
auto linear = [&](size_t index, const LinearPathComponent& l) {
325+
prototype_.AddLinearComponent(l.p1, l.p2);
326+
};
327+
auto quadratic = [&](size_t index, const QuadraticPathComponent& q) {
328+
prototype_.AddQuadraticComponent(q.p1, q.cp, q.p2);
329+
};
330+
auto cubic = [&](size_t index, const CubicPathComponent& c) {
331+
prototype_.AddCubicComponent(c.p1, c.cp1, c.cp2, c.p2);
332+
};
333+
path.EnumerateComponents(linear, quadratic, cubic);
334+
return *this;
335+
}
336+
323337
} // namespace impeller

impeller/geometry/path_builder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class PathBuilder {
8585

8686
PathBuilder& AddRoundedRect(Rect rect, Scalar radius);
8787

88+
PathBuilder& AddPath(const Path& path);
89+
8890
private:
8991
Point subpath_start_;
9092
Point current_;

0 commit comments

Comments
 (0)