Add support for path composition in path builder.
This commit is contained in:
@@ -231,20 +231,22 @@ static PathBuilder::RoundingRadii ToRoundingRadii(const SkRRect& rrect) {
|
||||
return radii;
|
||||
}
|
||||
|
||||
static Path ToPath(const SkPath& path) {
|
||||
UNIMPLEMENTED;
|
||||
return Path{};
|
||||
}
|
||||
|
||||
static Path ToPath(const SkRRect& rrect) {
|
||||
return PathBuilder{}
|
||||
.AddRoundedRect(ToRect(rrect.getBounds()), ToRoundingRadii(rrect))
|
||||
.TakePath();
|
||||
}
|
||||
|
||||
// |flutter::Dispatcher|
|
||||
void DisplayListImpeller::clipRRect(const SkRRect& rrect,
|
||||
SkClipOp clip_op,
|
||||
bool is_aa) {
|
||||
auto path =
|
||||
PathBuilder{}
|
||||
.AddRoundedRect(ToRect(rrect.getBounds()), ToRoundingRadii(rrect))
|
||||
.TakePath();
|
||||
canvas_.ClipPath(std::move(path));
|
||||
}
|
||||
|
||||
static Path ToPath(const SkPath& path) {
|
||||
UNIMPLEMENTED;
|
||||
return Path{};
|
||||
canvas_.ClipPath(ToPath(rrect));
|
||||
}
|
||||
|
||||
// |flutter::Dispatcher|
|
||||
@@ -290,17 +292,16 @@ void DisplayListImpeller::drawCircle(const SkPoint& center, SkScalar radius) {
|
||||
|
||||
// |flutter::Dispatcher|
|
||||
void DisplayListImpeller::drawRRect(const SkRRect& rrect) {
|
||||
auto path =
|
||||
PathBuilder{}
|
||||
.AddRoundedRect(ToRect(rrect.getBounds()), ToRoundingRadii(rrect))
|
||||
.TakePath();
|
||||
canvas_.DrawPath(std::move(path), paint_);
|
||||
canvas_.DrawPath(ToPath(rrect), paint_);
|
||||
}
|
||||
|
||||
// |flutter::Dispatcher|
|
||||
void DisplayListImpeller::drawDRRect(const SkRRect& outer,
|
||||
const SkRRect& inner) {
|
||||
UNIMPLEMENTED;
|
||||
PathBuilder builder;
|
||||
builder.AddPath(ToPath(outer));
|
||||
builder.AddPath(ToPath(inner));
|
||||
canvas_.DrawPath(builder.TakePath(FillType::kOdd), paint_);
|
||||
}
|
||||
|
||||
// |flutter::Dispatcher|
|
||||
|
||||
@@ -155,26 +155,23 @@ bool Path::UpdateCubicComponentAtIndex(size_t index,
|
||||
return true;
|
||||
}
|
||||
|
||||
static void AddPoints(std::vector<Point>& dest, const std::vector<Point>& src) {
|
||||
dest.reserve(dest.size() + src.size());
|
||||
dest.insert(dest.end(), src.begin(), src.end());
|
||||
}
|
||||
|
||||
std::vector<Point> Path::CreatePolyline(
|
||||
const SmoothingApproximation& approximation) const {
|
||||
std::vector<Point> points;
|
||||
auto collect_points = [&points](const std::vector<Point>& collection) {
|
||||
points.reserve(points.size() + collection.size());
|
||||
points.insert(points.end(), collection.begin(), collection.end());
|
||||
};
|
||||
for (const auto& component : components_) {
|
||||
switch (component.type) {
|
||||
case ComponentType::kLinear:
|
||||
AddPoints(points, linears_[component.index].CreatePolyline());
|
||||
collect_points(linears_[component.index].CreatePolyline());
|
||||
break;
|
||||
case ComponentType::kQuadratic:
|
||||
AddPoints(points,
|
||||
quads_[component.index].CreatePolyline(approximation));
|
||||
collect_points(quads_[component.index].CreatePolyline(approximation));
|
||||
break;
|
||||
case ComponentType::kCubic:
|
||||
AddPoints(points,
|
||||
cubics_[component.index].CreatePolyline(approximation));
|
||||
collect_points(cubics_[component.index].CreatePolyline(approximation));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,4 +320,18 @@ const Path& PathBuilder::GetCurrentPath() const {
|
||||
return prototype_;
|
||||
}
|
||||
|
||||
PathBuilder& PathBuilder::AddPath(const Path& path) {
|
||||
auto linear = [&](size_t index, const LinearPathComponent& l) {
|
||||
prototype_.AddLinearComponent(l.p1, l.p2);
|
||||
};
|
||||
auto quadratic = [&](size_t index, const QuadraticPathComponent& q) {
|
||||
prototype_.AddQuadraticComponent(q.p1, q.cp, q.p2);
|
||||
};
|
||||
auto cubic = [&](size_t index, const CubicPathComponent& c) {
|
||||
prototype_.AddCubicComponent(c.p1, c.cp1, c.cp2, c.p2);
|
||||
};
|
||||
path.EnumerateComponents(linear, quadratic, cubic);
|
||||
return *this;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -85,6 +85,8 @@ class PathBuilder {
|
||||
|
||||
PathBuilder& AddRoundedRect(Rect rect, Scalar radius);
|
||||
|
||||
PathBuilder& AddPath(const Path& path);
|
||||
|
||||
private:
|
||||
Point subpath_start_;
|
||||
Point current_;
|
||||
|
||||
Reference in New Issue
Block a user