Title: [292340] branches/safari-613-branch/Source/WebCore/rendering
Revision
292340
Author
[email protected]
Date
2022-04-04 14:56:15 -0700 (Mon, 04 Apr 2022)

Log Message

Cherry-pick r291793. rdar://91259284

    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: branches/safari-613-branch/Source/WebCore/rendering/RenderCombineText.cpp (292339 => 292340)


--- branches/safari-613-branch/Source/WebCore/rendering/RenderCombineText.cpp	2022-04-04 21:56:12 UTC (rev 292339)
+++ branches/safari-613-branch/Source/WebCore/rendering/RenderCombineText.cpp	2022-04-04 21:56:15 UTC (rev 292340)
@@ -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: branches/safari-613-branch/Source/WebCore/rendering/RenderCombineText.h (292339 => 292340)


--- branches/safari-613-branch/Source/WebCore/rendering/RenderCombineText.h	2022-04-04 21:56:12 UTC (rev 292339)
+++ branches/safari-613-branch/Source/WebCore/rendering/RenderCombineText.h	2022-04-04 21:56:15 UTC (rev 292340)
@@ -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: branches/safari-613-branch/Source/WebCore/rendering/RenderText.cpp (292339 => 292340)


--- branches/safari-613-branch/Source/WebCore/rendering/RenderText.cpp	2022-04-04 21:56:12 UTC (rev 292339)
+++ branches/safari-613-branch/Source/WebCore/rendering/RenderText.cpp	2022-04-04 21:56:15 UTC (rev 292340)
@@ -703,19 +703,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
@@ -1541,16 +1546,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) {
@@ -1558,21 +1566,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: branches/safari-613-branch/Source/WebCore/rendering/RenderText.h (292339 => 292340)


--- branches/safari-613-branch/Source/WebCore/rendering/RenderText.h	2022-04-04 21:56:12 UTC (rev 292339)
+++ branches/safari-613-branch/Source/WebCore/rendering/RenderText.h	2022-04-04 21:56:15 UTC (rev 292340)
@@ -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