diff --git a/engine/src/flutter/impeller/geometry/path.cc b/engine/src/flutter/impeller/geometry/path.cc index 818bb6d0ef..1d444b5fb6 100644 --- a/engine/src/flutter/impeller/geometry/path.cc +++ b/engine/src/flutter/impeller/geometry/path.cc @@ -144,32 +144,30 @@ bool Path::UpdateCubicComponentAtIndex(size_t index, return true; } -void Path::EnumerateSmoothPoints( - SmoothPointsEnumerator enumerator, - const SmoothingApproximation& approximation) const { - if (enumerator == nullptr) { - return; - } +static void AddPoints(std::vector& dest, const std::vector& src) { + dest.reserve(dest.size() + src.size()); + dest.insert(dest.end(), src.begin(), src.end()); +} +std::vector Path::SubdivideAdaptively( + const SmoothingApproximation& approximation) const { + std::vector points; for (const auto& component : components_) { switch (component.type) { - case ComponentType::kLinear: { - if (!enumerator(linears_[component.index].SmoothPoints())) { - return; - } - } break; - case ComponentType::kQuadratic: { - if (!enumerator(quads_[component.index].SmoothPoints(approximation))) { - return; - } - } break; - case ComponentType::kCubic: { - if (!enumerator(cubics_[component.index].SmoothPoints(approximation))) { - return; - } - } break; + case ComponentType::kLinear: + AddPoints(points, linears_[component.index].SubdivideAdaptively()); + break; + case ComponentType::kQuadratic: + AddPoints(points, + quads_[component.index].SubdivideAdaptively(approximation)); + break; + case ComponentType::kCubic: + AddPoints(points, + cubics_[component.index].SubdivideAdaptively(approximation)); + break; } } + return points; } Rect Path::GetBoundingBox() const { diff --git a/engine/src/flutter/impeller/geometry/path.h b/engine/src/flutter/impeller/geometry/path.h index 5560011ebe..18c7b4a602 100644 --- a/engine/src/flutter/impeller/geometry/path.h +++ b/engine/src/flutter/impeller/geometry/path.h @@ -53,9 +53,8 @@ class Path { bool UpdateCubicComponentAtIndex(size_t index, CubicPathComponent& cubic); - using SmoothPointsEnumerator = std::function points)>; - void EnumerateSmoothPoints(SmoothPointsEnumerator enumerator, - const SmoothingApproximation& approximation) const; + std::vector SubdivideAdaptively( + const SmoothingApproximation& approximation) const; Rect GetBoundingBox() const; diff --git a/engine/src/flutter/impeller/geometry/path_component.cc b/engine/src/flutter/impeller/geometry/path_component.cc index 554d7672dc..02c7242803 100644 --- a/engine/src/flutter/impeller/geometry/path_component.cc +++ b/engine/src/flutter/impeller/geometry/path_component.cc @@ -63,7 +63,7 @@ Point LinearPathComponent::Solve(Scalar time) const { }; } -std::vector LinearPathComponent::SmoothPoints() const { +std::vector LinearPathComponent::SubdivideAdaptively() const { return {p1, p2}; } @@ -85,10 +85,10 @@ Point QuadraticPathComponent::SolveDerivative(Scalar time) const { }; } -std::vector QuadraticPathComponent::SmoothPoints( +std::vector QuadraticPathComponent::SubdivideAdaptively( const SmoothingApproximation& approximation) const { CubicPathComponent elevated(*this); - return elevated.SmoothPoints(approximation); + return elevated.SubdivideAdaptively(approximation); } std::vector QuadraticPathComponent::Extrema() const { @@ -336,7 +336,7 @@ static void CubicPathSmoothenRecursive(const SmoothingApproximation& approx, CubicPathSmoothenRecursive(approx, points, p1234, p234, p34, p4, level + 1); } -std::vector CubicPathComponent::SmoothPoints( +std::vector CubicPathComponent::SubdivideAdaptively( const SmoothingApproximation& approximation) const { std::vector points; points.emplace_back(p1); diff --git a/engine/src/flutter/impeller/geometry/path_component.h b/engine/src/flutter/impeller/geometry/path_component.h index 636e9b1fa0..effc7d9822 100644 --- a/engine/src/flutter/impeller/geometry/path_component.h +++ b/engine/src/flutter/impeller/geometry/path_component.h @@ -41,7 +41,7 @@ struct LinearPathComponent { Point Solve(Scalar time) const; - std::vector SmoothPoints() const; + std::vector SubdivideAdaptively() const; std::vector Extrema() const; @@ -64,7 +64,7 @@ struct QuadraticPathComponent { Point SolveDerivative(Scalar time) const; - std::vector SmoothPoints( + std::vector SubdivideAdaptively( const SmoothingApproximation& approximation) const; std::vector Extrema() const; @@ -95,7 +95,7 @@ struct CubicPathComponent { Point SolveDerivative(Scalar time) const; - std::vector SmoothPoints( + std::vector SubdivideAdaptively( const SmoothingApproximation& approximation) const; std::vector Extrema() const;