diff --git a/engine/src/flutter/impeller/display_list/display_list_impeller.cc b/engine/src/flutter/impeller/display_list/display_list_impeller.cc index 1258b7f6f2..b83d7e3469 100644 --- a/engine/src/flutter/impeller/display_list/display_list_impeller.cc +++ b/engine/src/flutter/impeller/display_list/display_list_impeller.cc @@ -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| diff --git a/engine/src/flutter/impeller/geometry/path.cc b/engine/src/flutter/impeller/geometry/path.cc index 5bbf70b184..a9e09e5b83 100644 --- a/engine/src/flutter/impeller/geometry/path.cc +++ b/engine/src/flutter/impeller/geometry/path.cc @@ -155,26 +155,23 @@ bool Path::UpdateCubicComponentAtIndex(size_t index, return true; } -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::CreatePolyline( const SmoothingApproximation& approximation) const { std::vector points; + auto collect_points = [&points](const std::vector& 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; } } diff --git a/engine/src/flutter/impeller/geometry/path_builder.cc b/engine/src/flutter/impeller/geometry/path_builder.cc index 8cd4b29048..4c7d8a341a 100644 --- a/engine/src/flutter/impeller/geometry/path_builder.cc +++ b/engine/src/flutter/impeller/geometry/path_builder.cc @@ -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 diff --git a/engine/src/flutter/impeller/geometry/path_builder.h b/engine/src/flutter/impeller/geometry/path_builder.h index 7687d889e8..7c55299f1e 100644 --- a/engine/src/flutter/impeller/geometry/path_builder.h +++ b/engine/src/flutter/impeller/geometry/path_builder.h @@ -85,6 +85,8 @@ class PathBuilder { PathBuilder& AddRoundedRect(Rect rect, Scalar radius); + PathBuilder& AddPath(const Path& path); + private: Point subpath_start_; Point current_;