Skip to content

Commit

Permalink
[SVG] Add ShapeType to LegacyRenderSVGShape
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=262724
rdar://116538506

Reviewed by Simon Fraser.

This patch adds ShapeType to LegacyRenderSVGShape, which tells shape type of LegacyRenderSVGShape.
This enum will be used for efficient dispatch / behavior change for approximate repainting bounding box computation.

* Source/WebCore/platform/graphics/Path.cpp:
(WebCore::Path::isSingleDataLine const):
* Source/WebCore/platform/graphics/Path.h:
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGEllipse.cpp:
(WebCore::LegacyRenderSVGEllipse::updateShapeFromElement):
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGPath.cpp:
(WebCore::LegacyRenderSVGPath::updateShapeFromElement):
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGRect.cpp:
(WebCore::LegacyRenderSVGRect::updateShapeFromElement):
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGShape.cpp:
(WebCore::LegacyRenderSVGShape::layout):
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGShape.h:
(WebCore::LegacyRenderSVGShape::shapeType const):

Canonical link: https://commits.webkit.org/268961@main
  • Loading branch information
Constellation committed Oct 6, 2023
1 parent 6dc5092 commit d671418
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Source/WebCore/platform/graphics/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ bool Path::isEmpty() const
return false;
}

bool Path::definitelySingleLine() const
{
return !!singleDataLine();
}

PlatformPathPtr Path::platformPath() const
{
return const_cast<Path&>(*this).ensurePlatformPathImpl().platformPath();
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/platform/graphics/Path.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Path {
std::optional<PathDataBezierCurve> singleBezierCurve() const;

WEBCORE_EXPORT bool isEmpty() const;
bool definitelySingleLine() const;
WEBCORE_EXPORT PlatformPathPtr platformPath() const;

const PathSegment* singleSegmentIfExists() const { return asSingle(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ void LegacyRenderSVGEllipse::updateShapeFromElement()
if (m_radii.isEmpty())
return;

if (m_radii.width() == m_radii.height())
m_shapeType = ShapeType::Circle;
else
m_shapeType = ShapeType::Ellipse;

if (hasNonScalingStroke()) {
// Fallback to LegacyRenderSVGShape if shape has a non-scaling stroke.
LegacyRenderSVGShape::updateShapeFromElement();
Expand Down
8 changes: 8 additions & 0 deletions Source/WebCore/rendering/svg/legacy/LegacyRenderSVGPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ void LegacyRenderSVGPath::updateShapeFromElement()
updateZeroLengthSubpaths();

m_strokeBoundingBox = calculateUpdatedStrokeBoundingBox();

ASSERT(hasPath());
if (path().isEmpty())
m_shapeType = ShapeType::Empty;
else if (path().definitelySingleLine())
m_shapeType = ShapeType::Line;
else
m_shapeType = ShapeType::Path;
}

FloatRect LegacyRenderSVGPath::calculateUpdatedStrokeBoundingBox() const
Expand Down
6 changes: 5 additions & 1 deletion Source/WebCore/rendering/svg/legacy/LegacyRenderSVGRect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ void LegacyRenderSVGRect::updateShapeFromElement()
if (boundingBoxSize.isEmpty())
return;

if (rectElement().rx().value(lengthContext) > 0 || rectElement().ry().value(lengthContext) > 0 || hasNonScalingStroke()) {
m_shapeType = ShapeType::Rectangle;
if (rectElement().rx().value(lengthContext) > 0 || rectElement().ry().value(lengthContext) > 0)
m_shapeType = ShapeType::RoundedRectangle;

if (m_shapeType != ShapeType::Rectangle || hasNonScalingStroke()) {
// Fall back to LegacyRenderSVGShape
LegacyRenderSVGShape::updateShapeFromElement();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void LegacyRenderSVGShape::layout()
bool updateCachedBoundariesInParents = false;

if (m_needsShapeUpdate || m_needsBoundariesUpdate) {
m_shapeType = ShapeType::Empty;
updateShapeFromElement();
m_needsShapeUpdate = false;
updateRepaintBoundingBox();
Expand Down
16 changes: 15 additions & 1 deletion Source/WebCore/rendering/svg/legacy/LegacyRenderSVGShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ class SVGGraphicsElement;
class LegacyRenderSVGShape : public LegacyRenderSVGModelObject {
WTF_MAKE_ISO_ALLOCATED(LegacyRenderSVGShape);
public:
enum class ShapeType : uint8_t {
Empty,
Path,
Line,
Rectangle,
RoundedRectangle,
Ellipse,
Circle,
};

enum PointCoordinateSpace {
GlobalCoordinateSpace,
LocalCoordinateSpace
Expand Down Expand Up @@ -73,6 +83,8 @@ class LegacyRenderSVGShape : public LegacyRenderSVGModelObject {
}
void clearPath() { m_path = nullptr; }

ShapeType shapeType() const { return m_shapeType; }

protected:
void element() const = delete;

Expand Down Expand Up @@ -136,7 +148,9 @@ class LegacyRenderSVGShape : public LegacyRenderSVGModelObject {
bool m_needsBoundariesUpdate : 1;
bool m_needsShapeUpdate : 1;
bool m_needsTransformUpdate : 1;

protected:
ShapeType m_shapeType : 3 { ShapeType::Empty };
private:
AffineTransform m_localTransform;
std::unique_ptr<Path> m_path;
Vector<MarkerPosition> m_markerPositions;
Expand Down

0 comments on commit d671418

Please sign in to comment.