Title: [291793] trunk/Source/WebCore
Revision
291793
Author
[email protected]
Date
2022-03-24 06:47:41 -0700 (Thu, 24 Mar 2022)

Log Message

Devirtualize RenderText::width
https://bugs.webkit.org/show_bug.cgi?id=238285

Reviewed by Antti Koivisto.

RenderCombineText handling is moved to RenderText (we already handle combine text in RenderText::widthFromCache).

* rendering/RenderCombineText.cpp:
(WebCore::RenderCombineText::combineTextIfNeeded): These are all non-text-combine callsites.
(WebCore::RenderCombineText::width const): Deleted.
* rendering/RenderCombineText.h:
* rendering/RenderText.cpp:
(WebCore::combineTextWidth): RenderCombineText::combinedTextWidth returns the same value as RenderCombineText::width.
(WebCore::RenderText::widthFromCache const):
(WebCore::RenderText::width const):
* rendering/RenderText.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (291792 => 291793)


--- trunk/Source/WebCore/ChangeLog	2022-03-24 13:04:00 UTC (rev 291792)
+++ trunk/Source/WebCore/ChangeLog	2022-03-24 13:47:41 UTC (rev 291793)
@@ -1,3 +1,22 @@
+2022-03-24  Alan Bujtas  <[email protected]>
+
+        Devirtualize RenderText::width
+        https://bugs.webkit.org/show_bug.cgi?id=238285
+
+        Reviewed by Antti Koivisto.
+
+        RenderCombineText handling is moved to RenderText (we already handle combine text in RenderText::widthFromCache).
+
+        * rendering/RenderCombineText.cpp:
+        (WebCore::RenderCombineText::combineTextIfNeeded): These are all non-text-combine callsites.
+        (WebCore::RenderCombineText::width const): Deleted.
+        * rendering/RenderCombineText.h:
+        * rendering/RenderText.cpp:
+        (WebCore::combineTextWidth): RenderCombineText::combinedTextWidth returns the same value as RenderCombineText::width.
+        (WebCore::RenderText::widthFromCache const):
+        (WebCore::RenderText::width const):
+        * rendering/RenderText.h:
+
 2022-03-24  Kimmo Kinnunen  <[email protected]>
 
         REGRESSION (r287807): WEBGL_multi_draw validation rejecting valid arguments

Modified: trunk/Source/WebCore/rendering/RenderCombineText.cpp (291792 => 291793)


--- trunk/Source/WebCore/rendering/RenderCombineText.cpp	2022-03-24 13:04:00 UTC (rev 291792)
+++ trunk/Source/WebCore/rendering/RenderCombineText.cpp	2022-03-24 13:47:41 UTC (rev 291793)
@@ -68,14 +68,6 @@
     combineTextIfNeeded();
 }
 
-float RenderCombineText::width(unsigned from, unsigned length, const FontCascade& font, float xPosition, HashSet<const Font*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
-{
-    if (m_isCombined)
-        return !length ? 0 : font.size();
-
-    return RenderText::width(from, length, font, xPosition, fallbackFonts, glyphOverflow);
-}
-
 std::optional<FloatPoint> RenderCombineText::computeTextOrigin(const FloatRect& boxRect) const
 {
     if (!m_isCombined)
@@ -148,7 +140,7 @@
             compressedFont.update(fontSelector);
             
             glyphOverflow.left = glyphOverflow.top = glyphOverflow.right = glyphOverflow.bottom = 0;
-            float runWidth = RenderText::width(0, text().length(), compressedFont, 0, nullptr, &glyphOverflow);
+            float runWidth = width(0, text().length(), compressedFont, 0, nullptr, &glyphOverflow);
             if (runWidth <= emWidth) {
                 combinedTextWidth = runWidth;
                 m_isCombined = true;
@@ -178,7 +170,7 @@
             compressedFont.update(fontSelector);
             
             glyphOverflow.left = glyphOverflow.top = glyphOverflow.right = glyphOverflow.bottom = 0;
-            float runWidth = RenderText::width(0, text().length(), compressedFont, 0, nullptr, &glyphOverflow);
+            float runWidth = width(0, text().length(), compressedFont, 0, nullptr, &glyphOverflow);
             if (runWidth <= emWidth) {
                 combinedTextWidth = runWidth;
                 m_isCombined = true;

Modified: trunk/Source/WebCore/rendering/RenderCombineText.h (291792 => 291793)


--- trunk/Source/WebCore/rendering/RenderCombineText.h	2022-03-24 13:04:00 UTC (rev 291792)
+++ trunk/Source/WebCore/rendering/RenderCombineText.h	2022-03-24 13:47:41 UTC (rev 291793)
@@ -45,7 +45,6 @@
     void node() const = delete;
 
     bool isCombineText() const override { return true; }
-    float width(unsigned from, unsigned length, const FontCascade&, float xPosition, HashSet<const Font*>* fallbackFonts = 0, GlyphOverflow* = 0) const override;
     const char* renderName() const override { return "RenderCombineText"; }
     void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;
     void setRenderedText(const String&) override;

Modified: trunk/Source/WebCore/rendering/RenderText.cpp (291792 => 291793)


--- trunk/Source/WebCore/rendering/RenderText.cpp	2022-03-24 13:04:00 UTC (rev 291792)
+++ trunk/Source/WebCore/rendering/RenderText.cpp	2022-03-24 13:47:41 UTC (rev 291793)
@@ -704,19 +704,24 @@
     return createVisiblePosition(0, Affinity::Downstream);
 }
 
-ALWAYS_INLINE float RenderText::widthFromCache(const FontCascade& f, unsigned start, unsigned len, float xPos, HashSet<const Font*>* fallbackFonts, GlyphOverflow* glyphOverflow, const RenderStyle& style) const
+static inline std::optional<float> combineTextWidth(const RenderText& renderer, const FontCascade& fontCascade, const RenderStyle& style)
 {
-    if (style.hasTextCombine() && is<RenderCombineText>(*this)) {
-        const RenderCombineText& combineText = downcast<RenderCombineText>(*this);
-        if (combineText.isCombined())
-            return combineText.combinedTextWidth(f);
-    }
+    if (!style.hasTextCombine() || !is<RenderCombineText>(renderer))
+        return { };
+    auto& combineTextRenderer = downcast<RenderCombineText>(renderer);
+    return combineTextRenderer.isCombined() ? std::make_optional(combineTextRenderer.combinedTextWidth(fontCascade)) : std::nullopt;
+}
 
-    TextRun run = RenderBlock::constructTextRun(*this, start, len, style);
+ALWAYS_INLINE float RenderText::widthFromCache(const FontCascade& fontCascade, unsigned start, unsigned length, float xPos, HashSet<const Font*>* fallbackFonts, GlyphOverflow* glyphOverflow, const RenderStyle& style) const
+{
+    if (auto width = combineTextWidth(*this, fontCascade, style))
+        return *width;
+
+    TextRun run = RenderBlock::constructTextRun(*this, start, length, style);
     run.setCharacterScanForCodePath(!canUseSimpleFontCodePath());
     run.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
     run.setXPos(xPos);
-    return f.width(run, fallbackFonts, glyphOverflow);
+    return fontCascade.width(run, fallbackFonts, glyphOverflow);
 }
 
 ALWAYS_INLINE float RenderText::widthFromCacheConsideringPossibleTrailingSpace(const RenderStyle& style, const FontCascade& font, unsigned startIndex, unsigned wordLen, float xPos, bool currentCharacterIsSpace, WordTrailingSpace& wordTrailingSpace, HashSet<const Font*>& fallbackFonts, GlyphOverflow& glyphOverflow) const
@@ -1542,16 +1547,19 @@
     return width(from, len, lineStyle.fontCascade(), xPos, fallbackFonts, glyphOverflow);
 }
 
-float RenderText::width(unsigned from, unsigned len, const FontCascade& f, float xPos, HashSet<const Font*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
+float RenderText::width(unsigned from, unsigned length, const FontCascade& fontCascade, float xPos, HashSet<const Font*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
 {
-    ASSERT(from + len <= text().length());
-    if (!text().length())
-        return 0;
+    ASSERT(from + length <= text().length());
+    if (!text().length() || !length)
+        return 0.f;
 
-    const RenderStyle& style = this->style();
-    float w;
-    if (&f == &style.fontCascade()) {
-        if (!style.preserveNewline() && !from && len == text().length() && (!glyphOverflow || !glyphOverflow->computeBounds)) {
+    auto& style = this->style();
+    if (auto width = combineTextWidth(*this, fontCascade, style))
+        return *width;
+
+    float width = 0.f;
+    if (&fontCascade == &style.fontCascade()) {
+        if (!style.preserveNewline() && !from && length == text().length() && (!glyphOverflow || !glyphOverflow->computeBounds)) {
             if (fallbackFonts) {
                 ASSERT(glyphOverflow);
                 if (preferredLogicalWidthsDirty() || !m_knownToHaveNoOverflowAndNoFallbackFonts) {
@@ -1559,21 +1567,21 @@
                     if (fallbackFonts->isEmpty() && !glyphOverflow->left && !glyphOverflow->right && !glyphOverflow->top && !glyphOverflow->bottom)
                         m_knownToHaveNoOverflowAndNoFallbackFonts = true;
                 }
-                w = m_maxWidth;
+                width = m_maxWidth;
             } else
-                w = maxLogicalWidth();
+                width = maxLogicalWidth();
         } else
-            w = widthFromCache(f, from, len, xPos, fallbackFonts, glyphOverflow, style);
+            width = widthFromCache(fontCascade, from, length, xPos, fallbackFonts, glyphOverflow, style);
     } else {
-        TextRun run = RenderBlock::constructTextRun(*this, from, len, style);
+        TextRun run = RenderBlock::constructTextRun(*this, from, length, style);
         run.setCharacterScanForCodePath(!canUseSimpleFontCodePath());
         run.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
         run.setXPos(xPos);
 
-        w = f.width(run, fallbackFonts, glyphOverflow);
+        width = fontCascade.width(run, fallbackFonts, glyphOverflow);
     }
 
-    return clampTo(w, 0.f);
+    return clampTo(width, 0.f);
 }
 
 IntRect RenderText::linesBoundingBox() const

Modified: trunk/Source/WebCore/rendering/RenderText.h (291792 => 291793)


--- trunk/Source/WebCore/rendering/RenderText.h	2022-03-24 13:04:00 UTC (rev 291792)
+++ trunk/Source/WebCore/rendering/RenderText.h	2022-03-24 13:47:41 UTC (rev 291793)
@@ -91,8 +91,8 @@
 
     void positionLineBox(LegacyInlineTextBox&);
 
-    virtual float width(unsigned from, unsigned length, const FontCascade&, float xPos, HashSet<const Font*>* fallbackFonts = nullptr, GlyphOverflow* = nullptr) const;
-    virtual float width(unsigned from, unsigned length, float xPos, bool firstLine = false, HashSet<const Font*>* fallbackFonts = nullptr, GlyphOverflow* = nullptr) const;
+    float width(unsigned from, unsigned length, const FontCascade&, float xPos, HashSet<const Font*>* fallbackFonts = nullptr, GlyphOverflow* = nullptr) const;
+    float width(unsigned from, unsigned length, float xPos, bool firstLine = false, HashSet<const Font*>* fallbackFonts = nullptr, GlyphOverflow* = nullptr) const;
 
     float minLogicalWidth() const;
     float maxLogicalWidth() const;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to