Skip to content

Commit

Permalink
Cherry-pick a21f72a. rdar://problem/113604836
Browse files Browse the repository at this point in the history
    Cherry-pick fe314ea. rdar://problem/112741404

        Use a new type PathCloseSubpath instead of std::monostate to represent a close command in PathSegment
        https://bugs.webkit.org/show_bug.cgi?id=259430
        rdar://problem/112741404

        Reviewed by Simon Fraser.

        Adding an empty struct lets us treat this command like all the others,
        and not special case it in the WTF::switchOn calls in PathSegment.cpp.

        * Source/WebCore/platform/graphics/PathSegment.cpp:
        (WebCore::PathSegment::calculateEndPoint const):
        (WebCore::PathSegment::extendFastBoundingRect const):
        (WebCore::PathSegment::extendBoundingRect const):
        (WebCore::PathSegment::addToImpl const):
        (WebCore::PathSegment::applyElements const):
        (WebCore::operator<<):
        * Source/WebCore/platform/graphics/PathSegment.h:
        (WebCore::PathSegment::isCloseSubPath const):
        * Source/WebCore/platform/graphics/PathSegmentData.cpp:
        (WebCore::PathCloseSubpath::calculateEndPoint const):
        (WebCore::PathCloseSubpath::extendFastBoundingRect const):
        (WebCore::PathCloseSubpath::extendBoundingRect const):
        (WebCore::PathCloseSubpath::addToImpl const):
        (WebCore::PathCloseSubpath::applyElements const):
        (WebCore::operator<<):
        * Source/WebCore/platform/graphics/PathSegmentData.h:
        * Source/WebCore/platform/graphics/PathStream.cpp:
        (WebCore::PathStream::closeSubpath):
        * Source/WebCore/platform/graphics/cg/PathCG.cpp:
        (WebCore::pathSegmentApplierCallback):
        * Source/WebKit/GPUProcess/graphics/PathSegment.serialization.in:

        Canonical link: https://commits.webkit.org/266264@main

Identifier: 265870.265@safari-7616-branch
  • Loading branch information
heycam authored and MyahCobbs committed Aug 9, 2023
1 parent 29eb782 commit 5d7fe04
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 54 deletions.
67 changes: 18 additions & 49 deletions Source/WebCore/platform/graphics/PathSegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,75 +39,44 @@ PathSegment::PathSegment(Data&& data)

FloatPoint PathSegment::calculateEndPoint(const FloatPoint& currentPoint, FloatPoint& lastMoveToPoint) const
{
return WTF::switchOn(m_data,
[&](auto& data) {
return data.calculateEndPoint(currentPoint, lastMoveToPoint);
},
[&](std::monostate) {
return lastMoveToPoint;
}
);
return WTF::switchOn(m_data, [&](auto& data) {
return data.calculateEndPoint(currentPoint, lastMoveToPoint);
});
}

void PathSegment::extendFastBoundingRect(const FloatPoint& currentPoint, const FloatPoint& lastMoveToPoint, FloatRect& boundingRect) const
{
WTF::switchOn(m_data,
[&](auto& data) {
data.extendFastBoundingRect(currentPoint, lastMoveToPoint, boundingRect);
},
[&](std::monostate) {
boundingRect.extend(lastMoveToPoint);
}
);
WTF::switchOn(m_data, [&](auto& data) {
data.extendFastBoundingRect(currentPoint, lastMoveToPoint, boundingRect);
});
}

void PathSegment::extendBoundingRect(const FloatPoint& currentPoint, const FloatPoint& lastMoveToPoint, FloatRect& boundingRect) const
{
WTF::switchOn(m_data,
[&](auto& data) {
data.extendBoundingRect(currentPoint, lastMoveToPoint, boundingRect);
},
[&](std::monostate) {
boundingRect.extend(lastMoveToPoint);
}
);
WTF::switchOn(m_data, [&](auto& data) {
data.extendBoundingRect(currentPoint, lastMoveToPoint, boundingRect);
});
}

void PathSegment::addToImpl(PathImpl& impl) const
{
WTF::switchOn(m_data,
[&](auto& data) {
data.addToImpl(impl);
},
[&](std::monostate) {
impl.closeSubpath();
}
);
WTF::switchOn(m_data, [&](auto& data) {
data.addToImpl(impl);
});
}

void PathSegment::applyElements(const PathElementApplier& applier) const
{
WTF::switchOn(m_data,
[&](auto& data) {
data.applyElements(applier);
},
[&](std::monostate) {
applier({ PathElement::Type::CloseSubpath, { } });
}
);
WTF::switchOn(m_data, [&](auto& data) {
data.applyElements(applier);
});
}

TextStream& operator<<(TextStream& ts, const PathSegment& segment)
{
return WTF::switchOn(segment.data(),
[&](auto& data) -> TextStream& {
return ts << data;
},
[&](std::monostate) -> TextStream& {
ts << "close subpath";
return ts;
}
);
return WTF::switchOn(segment.data(), [&](auto& data) -> TextStream& {
return ts << data;
});
}

} // namespace WebCore
4 changes: 2 additions & 2 deletions Source/WebCore/platform/graphics/PathSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class PathSegment {
PathDataBezierCurve,
PathDataArc,

std::monostate
PathCloseSubpath
>;

WEBCORE_EXPORT PathSegment(Data&&);

bool operator==(const PathSegment&) const = default;

const Data& data() const { return m_data; }
bool isCloseSubPath() const { return std::holds_alternative<std::monostate>(m_data); }
bool isCloseSubPath() const { return std::holds_alternative<PathCloseSubpath>(m_data); }

FloatPoint calculateEndPoint(const FloatPoint& currentPoint, FloatPoint& lastMoveToPoint) const;
void extendFastBoundingRect(const FloatPoint& currentPoint, const FloatPoint& lastMoveToPoint, FloatRect& boundingRect) const;
Expand Down
31 changes: 31 additions & 0 deletions Source/WebCore/platform/graphics/PathSegmentData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,4 +687,35 @@ WTF::TextStream& operator<<(WTF::TextStream& ts, const PathDataArc& data)
return ts;
}

FloatPoint PathCloseSubpath::calculateEndPoint(const FloatPoint&, FloatPoint& lastMoveToPoint) const
{
return lastMoveToPoint;
}

void PathCloseSubpath::extendFastBoundingRect(const FloatPoint&, const FloatPoint& lastMoveToPoint, FloatRect& boundingRect) const
{
boundingRect.extend(lastMoveToPoint);
}

void PathCloseSubpath::extendBoundingRect(const FloatPoint&, const FloatPoint& lastMoveToPoint, FloatRect& boundingRect) const
{
boundingRect.extend(lastMoveToPoint);
}

void PathCloseSubpath::addToImpl(PathImpl& impl) const
{
impl.closeSubpath();
}

void PathCloseSubpath::applyElements(const PathElementApplier& applier) const
{
applier({ PathElement::Type::CloseSubpath, { } });
}

WTF::TextStream& operator<<(WTF::TextStream& ts, const PathCloseSubpath&)
{
ts << "close subpath";
return ts;
}

} // namespace WebCore
14 changes: 14 additions & 0 deletions Source/WebCore/platform/graphics/PathSegmentData.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,18 @@ struct PathDataArc {

WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const PathDataArc&);

struct PathCloseSubpath {
bool operator==(const PathCloseSubpath&) const = default;

FloatPoint calculateEndPoint(const FloatPoint& currentPoint, FloatPoint& lastMoveToPoint) const;

void extendFastBoundingRect(const FloatPoint& currentPoint, const FloatPoint& lastMoveToPoint, FloatRect& boundingRect) const;
void extendBoundingRect(const FloatPoint& currentPoint, const FloatPoint& lastMoveToPoint, FloatRect& boundingRect) const;

void addToImpl(PathImpl&) const;
void applyElements(const PathElementApplier&) const;
};

WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const PathCloseSubpath&);

} // namespace WebCore
2 changes: 1 addition & 1 deletion Source/WebCore/platform/graphics/PathStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void PathStream::addRoundedRect(const FloatRoundedRect& roundedRect, PathRounded

void PathStream::closeSubpath()
{
segments().append(std::monostate());
segments().append(PathCloseSubpath { });
}

const Vector<PathSegment>& PathStream::segments() const
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/graphics/cairo/PathCairo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void PathCairo::applySegments(const PathSegmentApplier& applier) const
break;

case PathElement::Type::CloseSubpath:
applier({ std::monostate() });
applier({ PathCloseSubpath { } });
break;
}
});
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/graphics/cg/PathCG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static void pathSegmentApplierCallback(void* info, const CGPathElement* element)
break;

case kCGPathElementCloseSubpath:
applier({ std::monostate() });
applier({ PathCloseSubpath { } });
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ header: <WebCore/PathSegmentData.h>
float radius;
};

header: <WebCore/PathSegment.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::PathCloseSubpath {
};

header: <WebCore/PathSegment.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] class WebCore::PathSegment {
WebCore::PathSegment::Data data();
Expand Down

0 comments on commit 5d7fe04

Please sign in to comment.