Diff
Modified: trunk/Source/WebCore/ChangeLog (287833 => 287834)
--- trunk/Source/WebCore/ChangeLog 2022-01-10 12:48:26 UTC (rev 287833)
+++ trunk/Source/WebCore/ChangeLog 2022-01-10 13:10:42 UTC (rev 287834)
@@ -1,5 +1,41 @@
2022-01-10 Nikolas Zimmermann <[email protected]>
+ [LBSE] Begin layer-aware RenderSVGRect implementation
+ https://bugs.webkit.org/show_bug.cgi?id=234992
+
+ Reviewed by Rob Buis.
+
+ Create RenderSVGRect as copy of LegacyRenderSVGRect, inheriting from
+ RenderSVGShape (and thus RenderLayerModelObject) instead of
+ LegacyRenderSVGShape, as LegacyRenderSVGRect does.
+
+ This patch does not yet enable the creation of RenderSVGRect
+ renderers if LBSE is enabled, this is postponed until more
+ functionality is fully available in LBSE (such as layout!).
+
+ Covered by existing tests, no change in behaviour.
+
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * rendering/svg/LegacyRenderSVGModelObject.cpp:
+ (WebCore::LegacyRenderSVGModelObject::clippedOverflowRect const):
+ (WebCore::LegacyRenderSVGModelObject::nodeAtPoint):
+ * rendering/svg/RenderSVGRect.cpp: Added.
+ (WebCore::RenderSVGRect::RenderSVGRect):
+ (WebCore::RenderSVGRect::rectElement const):
+ (WebCore::RenderSVGRect::updateShapeFromElement):
+ (WebCore::RenderSVGRect::fillShape const):
+ (WebCore::RenderSVGRect::strokeShape const):
+ (WebCore::RenderSVGRect::shapeDependentStrokeContains):
+ (WebCore::RenderSVGRect::shapeDependentFillContains const):
+ (WebCore::RenderSVGRect::isRenderingDisabled const):
+ * rendering/svg/RenderSVGRect.h: Added.
+ * rendering/svg/SVGResources.cpp:
+ * svg/SVGRectElement.cpp:
+ (WebCore::SVGRectElement::createElementRenderer):
+
+2022-01-10 Nikolas Zimmermann <[email protected]>
+
[LBSE] Begin layer-aware RenderSVGShape implementation
https://bugs.webkit.org/show_bug.cgi?id=234954
Modified: trunk/Source/WebCore/Sources.txt (287833 => 287834)
--- trunk/Source/WebCore/Sources.txt 2022-01-10 12:48:26 UTC (rev 287833)
+++ trunk/Source/WebCore/Sources.txt 2022-01-10 13:10:42 UTC (rev 287834)
@@ -2493,6 +2493,7 @@
rendering/svg/RenderSVGResourcePattern.cpp
rendering/svg/RenderSVGResourceRadialGradient.cpp
rendering/svg/RenderSVGResourceSolidColor.cpp
+rendering/svg/RenderSVGRect.cpp
rendering/svg/RenderSVGRoot.cpp
rendering/svg/RenderSVGShape.cpp
rendering/svg/RenderSVGTSpan.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (287833 => 287834)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2022-01-10 12:48:26 UTC (rev 287833)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2022-01-10 13:10:42 UTC (rev 287834)
@@ -3272,6 +3272,7 @@
A104EC5E220A3E4E00CBF67A /* JSMockPaymentContactFields.h in Headers */ = {isa = PBXBuildFile; fileRef = A104EC5C220A3E4400CBF67A /* JSMockPaymentContactFields.h */; };
A104F24414C71F7A009E2C23 /* CachedSVGDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = A104F24214C71F7A009E2C23 /* CachedSVGDocument.h */; settings = {ATTRIBUTES = (Private, ); }; };
A10BB5851484E3A700B2E87A /* LegacyRenderSVGRect.h in Headers */ = {isa = PBXBuildFile; fileRef = A10BB5831484E3A700B2E87A /* LegacyRenderSVGRect.h */; };
+ A10BB5851484E3A700B3AB6D /* RenderSVGRect.h in Headers */ = {isa = PBXBuildFile; fileRef = A10BB5831484E3A700B3AB6D /* RenderSVGRect.h */; };
A10BB58B1484E3B300B2E87A /* LegacyRenderSVGShape.h in Headers */ = {isa = PBXBuildFile; fileRef = A10BB5891484E3B300B2E87A /* LegacyRenderSVGShape.h */; };
A10BB58B1484E3B300C3F77B /* RenderSVGShape.h in Headers */ = {isa = PBXBuildFile; fileRef = A10BB5891484E3B300C3F77B /* RenderSVGShape.h */; };
A10DBF4718F92317000D70C6 /* LegacyPreviewLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = A10DBF4618F92317000D70C6 /* LegacyPreviewLoaderClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -13379,7 +13380,9 @@
A104F24114C71F7A009E2C23 /* CachedSVGDocument.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CachedSVGDocument.cpp; sourceTree = "<group>"; };
A104F24214C71F7A009E2C23 /* CachedSVGDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedSVGDocument.h; sourceTree = "<group>"; };
A10BB5821484E3A700B2E87A /* LegacyRenderSVGRect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LegacyRenderSVGRect.cpp; sourceTree = "<group>"; };
+ A10BB5821484E3A700B3AB6D /* RenderSVGRect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGRect.cpp; sourceTree = "<group>"; };
A10BB5831484E3A700B2E87A /* LegacyRenderSVGRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LegacyRenderSVGRect.h; sourceTree = "<group>"; };
+ A10BB5831484E3A700B3AB6D /* RenderSVGRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGRect.h; sourceTree = "<group>"; };
A10BB5881484E3B300B2E87A /* LegacyRenderSVGShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LegacyRenderSVGShape.cpp; sourceTree = "<group>"; };
A10CC5881473E3B300B2A8BF /* RenderSVGShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGShape.cpp; sourceTree = "<group>"; };
A10BB5891484E3B300B2E87A /* LegacyRenderSVGShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LegacyRenderSVGShape.h; sourceTree = "<group>"; };
@@ -18945,6 +18948,8 @@
436708FD12D9CA4A00032114 /* RenderSVGModelObject.h */,
ADDF1AD41257CD9A0003A759 /* RenderSVGPath.cpp */,
ADDF1AD51257CD9A0003A759 /* RenderSVGPath.h */,
+ A10BB5821484E3A700B3AB6D /* RenderSVGRect.cpp */,
+ A10BB5831484E3A700B3AB6D /* RenderSVGRect.h */,
4367088D12D9CA4A00044234 /* RenderSVGResource.cpp */,
4367088E12D9CA4A00044234 /* RenderSVGResource.h */,
4367088F12D9CA4A00044234 /* RenderSVGResourceClipper.cpp */,
@@ -36739,6 +36744,7 @@
0854B0171255E4E600B9CDD0 /* RenderSVGInlineText.h in Headers */,
43670C9342D9BC4B00044234 /* RenderSVGModelObject.h in Headers */,
ADDF1AD71257CD9A0003A759 /* RenderSVGPath.h in Headers */,
+ A10BB5851484E3A700B3AB6D /* RenderSVGRect.h in Headers */,
436708CD12D9CA4B00044234 /* RenderSVGResource.h in Headers */,
436708CF12D9CA4B00044234 /* RenderSVGResourceClipper.h in Headers */,
CDF747EF270F6F8D008FEEEC /* RenderSVGResourceClipperInlines.h in Headers */,
Modified: trunk/Source/WebCore/rendering/svg/LegacyRenderSVGModelObject.cpp (287833 => 287834)
--- trunk/Source/WebCore/rendering/svg/LegacyRenderSVGModelObject.cpp 2022-01-10 12:48:26 UTC (rev 287833)
+++ trunk/Source/WebCore/rendering/svg/LegacyRenderSVGModelObject.cpp 2022-01-10 13:10:42 UTC (rev 287834)
@@ -51,20 +51,8 @@
{
}
-LayoutRect LegacyRenderSVGModelObject::clippedOverflowRect(const RenderLayerModelObject* repaintContainer, VisibleRectContext context) const
+LayoutRect LegacyRenderSVGModelObject::clippedOverflowRect(const RenderLayerModelObject* repaintContainer, VisibleRectContext) const
{
-#if ENABLE(LAYER_BASED_SVG_ENGINE)
- if (document().settings().layerBasedSVGEngineEnabled()) {
- if (style().visibility() != Visibility::Visible && !enclosingLayer()->hasVisibleContent())
- return LayoutRect();
-
- ASSERT(!view().frameView().layoutContext().isPaintOffsetCacheEnabled());
- return computeRect(visualOverflowRectEquivalent(), repaintContainer, context);
- }
-#else
- UNUSED_PARAM(context);
-#endif
-
return SVGRenderSupport::clippedOverflowRectForRepaint(*this, repaintContainer);
}
@@ -126,14 +114,6 @@
bool LegacyRenderSVGModelObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&, HitTestAction)
{
-#if ENABLE(LAYER_BASED_SVG_ENGINE)
- if (document().settings().layerBasedSVGEngineEnabled()) {
- // FIXME: [LBSE] Upstream LegacyRenderSVGModelObject inheritance changes (should inherit from RenderLayerModelObject).
- notImplemented();
- return false;
- }
-#endif
-
ASSERT_NOT_REACHED();
return false;
}
Added: trunk/Source/WebCore/rendering/svg/RenderSVGRect.cpp (0 => 287834)
--- trunk/Source/WebCore/rendering/svg/RenderSVGRect.cpp (rev 0)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGRect.cpp 2022-01-10 13:10:42 UTC (rev 287834)
@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 2011 University of Szeged
+ * Copyright (C) 2011 Renata Hodovan <[email protected]>
+ * Copyright (C) 2020, 2021, 2022 Igalia S.L.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RenderSVGRect.h"
+
+#if ENABLE(LAYER_BASED_SVG_ENGINE)
+#include "RenderSVGShapeInlines.h"
+#include "SVGElementTypeHelpers.h"
+#include "SVGRectElement.h"
+#include <wtf/IsoMallocInlines.h>
+
+namespace WebCore {
+
+WTF_MAKE_ISO_ALLOCATED_IMPL(RenderSVGRect);
+
+RenderSVGRect::RenderSVGRect(SVGRectElement& element, RenderStyle&& style)
+ : RenderSVGShape(element, WTFMove(style))
+ , m_usePathFallback(false)
+{
+}
+
+RenderSVGRect::~RenderSVGRect() = default;
+
+SVGRectElement& RenderSVGRect::rectElement() const
+{
+ return downcast<SVGRectElement>(RenderSVGShape::graphicsElement());
+}
+
+void RenderSVGRect::updateShapeFromElement()
+{
+ // Before creating a new object we need to clear the cached bounding box
+ // to avoid using garbage.
+ m_fillBoundingBox = FloatRect();
+ m_innerStrokeRect = FloatRect();
+ m_outerStrokeRect = FloatRect();
+ clearPath();
+ m_usePathFallback = false;
+
+ SVGLengthContext lengthContext(&rectElement());
+ FloatSize boundingBoxSize(lengthContext.valueForLength(style().width(), SVGLengthMode::Width), lengthContext.valueForLength(style().height(), SVGLengthMode::Height));
+
+ // Spec: "A negative value is illegal. A value of zero disables rendering of the element."
+ if (boundingBoxSize.isEmpty())
+ return;
+
+ if (rectElement().rx().value(lengthContext) > 0 || rectElement().ry().value(lengthContext) > 0 || hasNonScalingStroke()) {
+ // Fall back to RenderSVGShape
+ RenderSVGShape::updateShapeFromElement();
+ m_usePathFallback = true;
+ return;
+ }
+
+ m_fillBoundingBox = FloatRect(FloatPoint(lengthContext.valueForLength(style().svgStyle().x(), SVGLengthMode::Width),
+ lengthContext.valueForLength(style().svgStyle().y(), SVGLengthMode::Height)),
+ boundingBoxSize);
+
+ // To decide if the stroke contains a point we create two rects which represent the inner and
+ // the outer stroke borders. A stroke contains the point, if the point is between them.
+ m_innerStrokeRect = m_fillBoundingBox;
+ m_outerStrokeRect = m_fillBoundingBox;
+
+ if (style().svgStyle().hasStroke()) {
+ float strokeWidth = this->strokeWidth();
+ m_innerStrokeRect.inflate(-strokeWidth / 2);
+ m_outerStrokeRect.inflate(strokeWidth / 2);
+ }
+
+ m_strokeBoundingBox = m_outerStrokeRect;
+
+#if USE(CG)
+ // CoreGraphics can inflate the stroke by 1px when drawing a rectangle with antialiasing disabled at non-integer coordinates, we need to compensate.
+ if (style().svgStyle().shapeRendering() == ShapeRendering::CrispEdges)
+ m_strokeBoundingBox.inflate(1);
+#endif
+}
+
+void RenderSVGRect::fillShape(GraphicsContext& context) const
+{
+ if (m_usePathFallback) {
+ RenderSVGShape::fillShape(context);
+ return;
+ }
+
+#if USE(CG)
+ // FIXME: CG implementation of GraphicsContextCG::fillRect has an own
+ // shadow drawing method, which draws an extra shadow.
+ // This is a workaround for switching off the extra shadow.
+ // https://bugs.webkit.org/show_bug.cgi?id=68899
+ if (context.hasShadow()) {
+ GraphicsContextStateSaver stateSaver(context);
+ context.clearShadow();
+ context.fillRect(m_fillBoundingBox);
+ return;
+ }
+#endif
+
+ context.fillRect(m_fillBoundingBox);
+}
+
+void RenderSVGRect::strokeShape(GraphicsContext& context) const
+{
+ if (!style().hasVisibleStroke())
+ return;
+
+ if (m_usePathFallback) {
+ RenderSVGShape::strokeShape(context);
+ return;
+ }
+
+ context.strokeRect(m_fillBoundingBox, strokeWidth());
+}
+
+bool RenderSVGRect::shapeDependentStrokeContains(const FloatPoint& point, PointCoordinateSpace pointCoordinateSpace)
+{
+ // The optimized contains code below does not support non-smooth strokes so we need
+ // to fall back to RenderSVGShape::shapeDependentStrokeContains in these cases.
+ if (m_usePathFallback || !hasSmoothStroke()) {
+ if (!hasPath())
+ RenderSVGShape::updateShapeFromElement();
+ return RenderSVGShape::shapeDependentStrokeContains(point, pointCoordinateSpace);
+ }
+
+ return m_outerStrokeRect.contains(point, FloatRect::InsideOrOnStroke) && !m_innerStrokeRect.contains(point, FloatRect::InsideButNotOnStroke);
+}
+
+bool RenderSVGRect::shapeDependentFillContains(const FloatPoint& point, const WindRule fillRule) const
+{
+ if (m_usePathFallback)
+ return RenderSVGShape::shapeDependentFillContains(point, fillRule);
+ return m_fillBoundingBox.contains(point.x(), point.y());
+}
+
+bool RenderSVGRect::isRenderingDisabled() const
+{
+ // A width or height of zero disables rendering for the element, and results in an empty bounding box.
+ return m_fillBoundingBox.isEmpty();
+}
+
+}
+
+#endif // ENABLE(LAYER_BASED_SVG_ENGINE)
Added: trunk/Source/WebCore/rendering/svg/RenderSVGRect.h (0 => 287834)
--- trunk/Source/WebCore/rendering/svg/RenderSVGRect.h (rev 0)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGRect.h 2022-01-10 13:10:42 UTC (rev 287834)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2011 University of Szeged
+ * Copyright (C) 2011 Renata Hodovan <[email protected]>
+ * Copyright (C) 2020, 2021, 2022 Igalia S.L.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(LAYER_BASED_SVG_ENGINE)
+#include "RenderSVGShape.h"
+
+namespace WebCore {
+
+class SVGRectElement;
+
+class RenderSVGRect final : public RenderSVGShape {
+ WTF_MAKE_ISO_ALLOCATED(RenderSVGRect);
+public:
+ RenderSVGRect(SVGRectElement&, RenderStyle&&);
+ virtual ~RenderSVGRect();
+
+ SVGRectElement& rectElement() const;
+
+private:
+ void graphicsElement() const = delete;
+
+ const char* renderName() const override { return "RenderSVGRect"; }
+
+ void updateShapeFromElement() override;
+ bool isEmpty() const override { return m_usePathFallback ? RenderSVGShape::isEmpty() : m_fillBoundingBox.isEmpty(); }
+ bool isRenderingDisabled() const override;
+ void fillShape(GraphicsContext&) const override;
+ void strokeShape(GraphicsContext&) const override;
+ bool shapeDependentStrokeContains(const FloatPoint&, PointCoordinateSpace = GlobalCoordinateSpace) override;
+ bool shapeDependentFillContains(const FloatPoint&, const WindRule) const override;
+
+private:
+ FloatRect m_innerStrokeRect;
+ FloatRect m_outerStrokeRect;
+ bool m_usePathFallback;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(LAYER_BASED_SVG_ENGINE)
Modified: trunk/Source/WebCore/rendering/svg/SVGResources.cpp (287833 => 287834)
--- trunk/Source/WebCore/rendering/svg/SVGResources.cpp 2022-01-10 12:48:26 UTC (rev 287833)
+++ trunk/Source/WebCore/rendering/svg/SVGResources.cpp 2022-01-10 13:10:42 UTC (rev 287834)
@@ -23,8 +23,8 @@
#include "FilterOperation.h"
#include "LegacyRenderSVGRoot.h"
#include "PathOperation.h"
-#include "RenderSVGResourceClipper.h"
-#include "RenderSVGResourceFilter.h"
+#include "RenderSVGResourceClipperInlines.h"
+#include "RenderSVGResourceFilterInlines.h"
#include "RenderSVGResourceMarkerInlines.h"
#include "RenderSVGResourceMaskerInlines.h"
#include "SVGElementTypeHelpers.h"
Modified: trunk/Source/WebCore/svg/SVGRectElement.cpp (287833 => 287834)
--- trunk/Source/WebCore/svg/SVGRectElement.cpp 2022-01-10 12:48:26 UTC (rev 287833)
+++ trunk/Source/WebCore/svg/SVGRectElement.cpp 2022-01-10 13:10:42 UTC (rev 287834)
@@ -24,6 +24,7 @@
#include "SVGRectElement.h"
#include "LegacyRenderSVGRect.h"
+#include "RenderSVGRect.h"
#include "RenderSVGResource.h"
#include "SVGElementInlines.h"
#include <wtf/IsoMallocInlines.h>
@@ -88,6 +89,12 @@
RenderPtr<RenderElement> SVGRectElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
{
+ // FIXME: [LBSE] Upstream enough code to allow the creation of RenderLayerModelObject based SVG renderers.
+#if ENABLE(LAYER_BASED_SVG_ENGINE)
+ if (false && document().settings().layerBasedSVGEngineEnabled())
+ return createRenderer<RenderSVGRect>(*this, WTFMove(style));
+#endif
+
return createRenderer<LegacyRenderSVGRect>(*this, WTFMove(style));
}