Skip to content

Commit 19fb3bc

Browse files
shallawaSaid Abou-Hallawa
authored andcommitted
SVG text with gradient fill is rendered very slow
https://bugs.webkit.org/show_bug.cgi?id=285799# rdar://73203473 Reviewed by Simon Fraser. Refactor applying the SVG gradient resource into two appliers: one for text (TextGradientClipper) and the other for PathOrShape (PathOrShapeGradientApplier). TextGradientClipper draws the text into a mask ImageBuffer. Then GraphicsContext is clipped to this ImageBuffer before the targetRect is filled with gradient. PathOrShapeGradientApplier fills or strokes the path (or the shape) with the gradient resource. Add the new text applier TextGradientCompositor which draws the text into a transparency layer with SourceIn. Then it fills the targetRect with the gradient into another transparency layer with SourceOver. Then these two layers are composited to GraphicsContext. TextGradientCompositor will be used for all cases except when rendering to a PDFDocument because PDF context does not support some CompositeOperation. In this case TextGradientClipper will be used to draw the text. * LayoutTests/imported/blink/svg/text/obb-paintserver.html: * LayoutTests/imported/mozilla/svg/text-scale-02.svg: * LayoutTests/imported/mozilla/svg/text/simple-fill-gradient.svg: * Source/WebCore/rendering/svg/legacy/LegacyRenderSVGResource.cpp: (WebCore::LegacyRenderSVGResource::fillAndStrokePathOrShape): (WebCore::LegacyRenderSVGResource::fillAndStrokePathOrShape const): Deleted. * Source/WebCore/rendering/svg/legacy/LegacyRenderSVGResource.h: * Source/WebCore/rendering/svg/legacy/LegacyRenderSVGResourceGradient.cpp: (WebCore::LegacyRenderSVGResourceGradient::gradientDataForRenderer): (WebCore::applyGradientResource): (WebCore::PathOrShapeGradientApplier::applyResource): (WebCore::PathOrShapeGradientApplier::postApplyResource): (WebCore::calculateGradientGeometry): (WebCore::calculateGradientUserspaceTransform): (WebCore::TextGradientClipper::applyResource): (WebCore::TextGradientClipper::postApplyResource): (WebCore::TextGradientCompositor::applyResource): (WebCore::TextGradientCompositor::postApplyResource): (WebCore::LegacyRenderSVGResourceGradient::applyResource): (WebCore::LegacyRenderSVGResourceGradient::postApplyResource): (WebCore::createMaskAndSwapContextForTextGradient): Deleted. (WebCore::clipToTextMask): Deleted. * Source/WebCore/rendering/svg/legacy/LegacyRenderSVGResourceGradient.h: Canonical link: https://commits.webkit.org/288788@main
1 parent 6a6a2c8 commit 19fb3bc

File tree

7 files changed

+232
-123
lines changed

7 files changed

+232
-123
lines changed

LayoutTests/imported/blink/svg/text/obb-paintserver.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<meta name="fuzzy" content="maxDifference=0-2; totalPixels=0-12500" />
2+
<meta name="fuzzy" content="maxDifference=0-2; totalPixels=0-13003" />
33
<svg width="200" height="400">
44
<linearGradient id="gradient" x1="0" x2="0" y1="0" y2="1">
55
<stop offset="0" stop-color="green"/>

LayoutTests/imported/mozilla/svg/text-scale-02.svg

Lines changed: 1 addition & 1 deletion
Loading

LayoutTests/imported/mozilla/svg/text/simple-fill-gradient.svg

Lines changed: 1 addition & 1 deletion
Loading

Source/WebCore/rendering/svg/legacy/LegacyRenderSVGResource.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (C) 2007 Rob Buis <[email protected]>
44
* Copyright (C) 2008 Dirk Schulze <[email protected]>
55
* Copyright (C) Research In Motion Limited 2010. All rights reserved.
6-
* Copyright (C) 2023 Apple Inc. All rights reserved.
6+
* Copyright (C) 2023-2025 Apple Inc. All rights reserved.
77
*
88
* This library is free software; you can redistribute it and/or
99
* modify it under the terms of the GNU Library General Public
@@ -264,7 +264,7 @@ void LegacyRenderSVGResource::markForLayoutAndParentResourceInvalidationIfNeeded
264264
}
265265
}
266266

267-
void LegacyRenderSVGResource::fillAndStrokePathOrShape(GraphicsContext& context, OptionSet<RenderSVGResourceMode> resourceMode, const Path* path, const RenderElement* shape) const
267+
void LegacyRenderSVGResource::fillAndStrokePathOrShape(GraphicsContext& context, OptionSet<RenderSVGResourceMode> resourceMode, const Path* path, const RenderElement* shape)
268268
{
269269
if (shape) {
270270
ASSERT(shape->isRenderOrLegacyRenderSVGShape());

Source/WebCore/rendering/svg/legacy/LegacyRenderSVGResource.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
3+
* Copyright (C) 2025 Apple Inc. All rights reserved.
34
*
45
* This library is free software; you can redistribute it and/or
56
* modify it under the terms of the GNU Library General Public
@@ -83,8 +84,7 @@ class LegacyRenderSVGResource {
8384
static void markForLayoutAndParentResourceInvalidation(RenderObject&, bool needsLayout = true);
8485
static void markForLayoutAndParentResourceInvalidationIfNeeded(RenderObject&, bool needsLayout, SingleThreadWeakHashSet<RenderObject>* visitedRenderers);
8586

86-
protected:
87-
void fillAndStrokePathOrShape(GraphicsContext&, OptionSet<RenderSVGResourceMode>, const Path*, const RenderElement* shape) const;
87+
static void fillAndStrokePathOrShape(GraphicsContext&, OptionSet<RenderSVGResourceMode>, const Path*, const RenderElement* shape);
8888
};
8989

9090
constexpr bool resourceWasApplied(OptionSet<LegacyRenderSVGResource::ApplyResult> result)

0 commit comments

Comments
 (0)