Skip to content

Commit 190edba

Browse files
committed
Optimize single-segment Path::fastBoundingRect()
https://bugs.webkit.org/show_bug.cgi?id=290234 rdar://147623819 Reviewed by Cameron McCormack. `PathStream::computeFastBoundingRect()` has some overhead we can remove if we just have a single segment; the loop, and the call to `calculateEndPoint()`. So implement in `Path::fastBoundingRect()` in a way that works for single segment paths. * Source/WebCore/platform/graphics/Path.cpp: (WebCore::Path::fastBoundingRect const): Canonical link: https://commits.webkit.org/292543@main
1 parent 8d714c8 commit 190edba

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

Source/WebCore/platform/graphics/Path.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ bool Path::hasSubpaths() const
629629
FloatRect Path::fastBoundingRect() const
630630
{
631631
if (auto* segment = asSingle())
632-
return PathStream::computeFastBoundingRect(singleElementSpan(*segment));
632+
return segment->fastBoundingRect();
633633

634634
if (auto* impl = asImpl())
635635
return impl->fastBoundingRect();

Source/WebCore/platform/graphics/PathSegment.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ std::optional<FloatPoint> PathSegment::tryGetEndPointWithoutContext() const
5151
});
5252
}
5353

54+
FloatRect PathSegment::fastBoundingRect() const
55+
{
56+
FloatPoint currentPoint;
57+
FloatPoint lastMoveToPoint;
58+
59+
auto boundingRect = FloatRect::smallestRect();
60+
extendFastBoundingRect(currentPoint, lastMoveToPoint, boundingRect);
61+
62+
if (boundingRect.isSmallest()) {
63+
currentPoint = calculateEndPoint(currentPoint, lastMoveToPoint);
64+
boundingRect.extend(currentPoint);
65+
}
66+
67+
return boundingRect;
68+
}
69+
5470
void PathSegment::extendFastBoundingRect(const FloatPoint& currentPoint, const FloatPoint& lastMoveToPoint, FloatRect& boundingRect) const
5571
{
5672
WTF::switchOn(m_data, [&](auto& data) {

Source/WebCore/platform/graphics/PathSegment.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class PathSegment {
6666

6767
FloatPoint calculateEndPoint(const FloatPoint& currentPoint, FloatPoint& lastMoveToPoint) const;
6868
std::optional<FloatPoint> tryGetEndPointWithoutContext() const;
69+
70+
FloatRect fastBoundingRect() const;
6971
void extendFastBoundingRect(const FloatPoint& currentPoint, const FloatPoint& lastMoveToPoint, FloatRect& boundingRect) const;
7072
void extendBoundingRect(const FloatPoint& currentPoint, const FloatPoint& lastMoveToPoint, FloatRect& boundingRect) const;
7173

0 commit comments

Comments
 (0)