Skip to content

Commit

Permalink
Do not synchronously measure SVG text every time it changes
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264669
rdar://problem/118451741

Reviewed by Simon Fraser.

This is a optimization done in the Blink fork https://chromium.googlesource.com/chromium/src.git/+/34c351416a102e4ee510badb86fbc4f57604ccd0 and found by Ahmad Saleem.

If SVG text is set multiple times in a row, we would
measure text synchronously for every set, even though just the last
measurement would count. This patch marks it as "need layout", so
we measure text in the next layout.

* Source/WebCore/rendering/svg/RenderSVGText.cpp:
(WebCore::RenderSVGText::subtreeTextDidChange):

Canonical link: https://commits.webkit.org/271678@main
  • Loading branch information
vitorroriz committed Dec 7, 2023
1 parent 0c06435 commit 97f84b2
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions Source/WebCore/rendering/svg/RenderSVGText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Copyright (C) 2008 Rob Buis <buis@kde.org>
* Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
* Copyright (C) Research In Motion Limited 2010-2012. All rights reserved.
* Copyright (C) 2012 Google Inc.
* Copyright (C) 2012-2023 Google Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -284,14 +284,12 @@ void RenderSVGText::subtreeTextDidChange(RenderSVGInlineText* text)
}

// The positioning elements cache depends on the size of each text renderer in the
// subtree. If this changes, clear the cache. It's going to be rebuilt below.
// subtree. If this changes, clear the cache. If this changes, clear the cache and mark it for rebuilding in the next layout.
m_layoutAttributesBuilder.clearTextPositioningElements();

checkLayoutAttributesConsistency(this, m_layoutAttributes);
for (RenderObject* descendant = text; descendant; descendant = descendant->nextInPreOrder(text)) {
if (is<RenderSVGInlineText>(*descendant))
m_layoutAttributesBuilder.buildLayoutAttributesForTextRenderer(downcast<RenderSVGInlineText>(*descendant));
}
setNeedsPositioningValuesUpdate();
setNeedsLayout();
}

static inline void updateFontInAllDescendants(RenderSVGText& text, SVGTextLayoutAttributesBuilder* builder = nullptr)
Expand Down

0 comments on commit 97f84b2

Please sign in to comment.