Changeset 252835 in webkit


Ignore:
Timestamp:
Nov 23, 2019 1:36:33 PM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Defer run height/baseline adjustment computation until Line::close
https://bugs.webkit.org/show_bug.cgi?id=204550
<rdar://problem/57454497>

Reviewed by Antti Koivisto.

Currently we measure run height and adjust the line's baseline/height on every append.
We could do all that in Line::close after we've merged the neighboring runs.
([text][ ][content] vs. [text content])
This is about ~5% win on line-layout-simple.html

  • layout/inlineformatting/InlineLine.cpp:

(WebCore::Layout::Line::alignContentVertically):
(WebCore::Layout::Line::append):
(WebCore::Layout::Line::appendInlineContainerStart):
(WebCore::Layout::Line::appendInlineContainerEnd):
(WebCore::Layout::Line::appendTextContent):
(WebCore::Layout::Line::appendNonReplacedInlineBox):
(WebCore::Layout::Line::appendLineBreak):
(WebCore::Layout::Line::adjustBaselineAndLineHeight):
(WebCore::Layout::Line::runContentHeight const):
(WebCore::Layout::Line::alignContentVertically const): Deleted.
(WebCore::Layout::Line::inlineItemContentHeight const): Deleted.

  • layout/inlineformatting/InlineLine.h:

(WebCore::Layout::Line::Run::setLogicalHeight):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252832 r252835  
     12019-11-23  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Defer run height/baseline adjustment computation until Line::close
     4        https://bugs.webkit.org/show_bug.cgi?id=204550
     5        <rdar://problem/57454497>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Currently we measure run height and adjust the line's baseline/height on every append.
     10        We could do all that in Line::close after we've merged the neighboring runs.
     11        ([text][ ][content] vs. [text content])
     12        This is about ~5% win on line-layout-simple.html
     13
     14        * layout/inlineformatting/InlineLine.cpp:
     15        (WebCore::Layout::Line::alignContentVertically):
     16        (WebCore::Layout::Line::append):
     17        (WebCore::Layout::Line::appendInlineContainerStart):
     18        (WebCore::Layout::Line::appendInlineContainerEnd):
     19        (WebCore::Layout::Line::appendTextContent):
     20        (WebCore::Layout::Line::appendNonReplacedInlineBox):
     21        (WebCore::Layout::Line::appendLineBreak):
     22        (WebCore::Layout::Line::adjustBaselineAndLineHeight):
     23        (WebCore::Layout::Line::runContentHeight const):
     24        (WebCore::Layout::Line::alignContentVertically const): Deleted.
     25        (WebCore::Layout::Line::inlineItemContentHeight const): Deleted.
     26        * layout/inlineformatting/InlineLine.h:
     27        (WebCore::Layout::Line::Run::setLogicalHeight):
     28
    1292019-11-23  Andres Gonzalez  <andresg_22@apple.com>
    230
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp

    r252816 r252835  
    316316}
    317317
    318 void Line::alignContentVertically(RunList& runList) const
     318void Line::alignContentVertically(RunList& runList)
    319319{
    320320    ASSERT(!m_skipAlignment);
     321    for (auto& run : runList) {
     322        adjustBaselineAndLineHeight(run);
     323        run.setLogicalHeight(runContentHeight(run));
     324    }
     325
    321326    for (auto& run : runList) {
    322327        LayoutUnit logicalTop;
     
    480485void Line::append(const InlineItem& inlineItem, LayoutUnit logicalWidth)
    481486{
     487    if (inlineItem.isText())
     488        return appendTextContent(downcast<InlineTextItem>(inlineItem), logicalWidth);
    482489    if (inlineItem.isForcedLineBreak())
    483490        return appendLineBreak(inlineItem);
    484     if (is<InlineTextItem>(inlineItem))
    485         return appendTextContent(downcast<InlineTextItem>(inlineItem), logicalWidth);
    486491    if (inlineItem.isContainerStart())
    487492        return appendInlineContainerStart(inlineItem, logicalWidth);
     
    504509{
    505510    // This is really just a placeholder to mark the start of the inline level container <span>.
    506     auto logicalRect = Display::Rect { 0, contentLogicalWidth(), logicalWidth, 0 };
    507 
    508     if (!m_skipAlignment) {
    509         adjustBaselineAndLineHeight(inlineItem);
    510         logicalRect.setHeight(inlineItemContentHeight(inlineItem));
    511     }
    512     appendNonBreakableSpace(inlineItem, logicalRect);
     511    appendNonBreakableSpace(inlineItem, Display::Rect { 0, contentLogicalWidth(), logicalWidth, { } });
    513512}
    514513
     
    516515{
    517516    // This is really just a placeholder to mark the end of the inline level container </span>.
    518     auto logicalRect = Display::Rect { 0, contentLogicalRight(), logicalWidth, m_skipAlignment ? LayoutUnit() : inlineItemContentHeight(inlineItem) };
    519     appendNonBreakableSpace(inlineItem, logicalRect);
     517    appendNonBreakableSpace(inlineItem, Display::Rect { 0, contentLogicalRight(), logicalWidth, { } });
    520518}
    521519
     
    555553    };
    556554
    557     auto logicalRect = Display::Rect { };
    558     logicalRect.setLeft(contentLogicalWidth());
    559     logicalRect.setWidth(logicalWidth);
    560     if (!m_skipAlignment) {
    561         adjustBaselineAndLineHeight(inlineItem);
    562         logicalRect.setHeight(inlineItemContentHeight(inlineItem));
    563     }
    564 
    565555    auto collapsedRun = inlineItem.isCollapsible() && inlineItem.length() > 1;
    566556    auto contentStart = inlineItem.start();
    567557    auto contentLength =  collapsedRun ? 1 : inlineItem.length();
    568     auto lineRun = makeUnique<InlineItemRun>(inlineItem, logicalRect, Display::Run::TextContext { contentStart, contentLength, inlineItem.layoutBox().textContext()->content.substring(contentStart, contentLength) });
     558    auto lineRun = makeUnique<InlineItemRun>(inlineItem, Display::Rect { 0, contentLogicalWidth(), logicalWidth, { } },
     559        Display::Run::TextContext { contentStart, contentLength, inlineItem.layoutBox().textContext()->content.substring(contentStart, contentLength) });
    569560
    570561    auto collapsesToZeroAdvanceWidth = willCollapseCompletely();
     
    585576void Line::appendNonReplacedInlineBox(const InlineItem& inlineItem, LayoutUnit logicalWidth)
    586577{
    587     auto& boxGeometry = formattingContext().geometryForBox(inlineItem.layoutBox());
    588     auto horizontalMargin = boxGeometry.horizontalMargin();
    589     auto logicalRect = Display::Rect { };
    590 
    591     logicalRect.setLeft(contentLogicalWidth() + horizontalMargin.start);
    592     logicalRect.setWidth(logicalWidth);
    593     if (!m_skipAlignment) {
    594         adjustBaselineAndLineHeight(inlineItem);
    595         auto runHeight = formattingContext().geometryForBox(inlineItem.layoutBox()).marginBoxHeight();
    596         logicalRect.setHeight(runHeight);
    597     }
    598 
    599     m_inlineItemRuns.append(makeUnique<InlineItemRun>(inlineItem, logicalRect));
     578    auto horizontalMargin = formattingContext().geometryForBox(inlineItem.layoutBox()).horizontalMargin();
     579    m_inlineItemRuns.append(makeUnique<InlineItemRun>(inlineItem, Display::Rect { 0, contentLogicalWidth() + horizontalMargin.start, logicalWidth, { } }));
    600580    m_lineBox.expandHorizontally(logicalWidth + horizontalMargin.start + horizontalMargin.end);
    601581    m_lineBox.setIsConsideredNonEmpty();
     
    613593void Line::appendLineBreak(const InlineItem& inlineItem)
    614594{
    615     auto logicalRect = Display::Rect { };
    616     logicalRect.setLeft(contentLogicalWidth());
    617     logicalRect.setWidth({ });
    618     if (!m_skipAlignment) {
    619         adjustBaselineAndLineHeight(inlineItem);
    620         logicalRect.setHeight(logicalHeight());
    621     }
    622595    m_lineBox.setIsConsideredNonEmpty();
    623     m_inlineItemRuns.append(makeUnique<InlineItemRun>(inlineItem, logicalRect));
    624 }
    625 
    626 void Line::adjustBaselineAndLineHeight(const InlineItem& inlineItem)
    627 {
    628     ASSERT(!inlineItem.isContainerEnd());
    629     auto& layoutBox = inlineItem.layoutBox();
     596    m_inlineItemRuns.append(makeUnique<InlineItemRun>(inlineItem, Display::Rect { 0, contentLogicalWidth(), { }, { } }));
     597}
     598
     599void Line::adjustBaselineAndLineHeight(const Run& run)
     600{
     601    auto& baseline = m_lineBox.baseline();
     602    if (run.isText() || run.isForcedLineBreak()) {
     603        // For text content we set the baseline either through the initial strut (set by the formatting context root) or
     604        // through the inline container (start) -see above. Normally the text content itself does not stretch the line.
     605        if (!m_initialStrut)
     606            return;
     607        m_lineBox.setAscentIfGreater(m_initialStrut->ascent());
     608        m_lineBox.setDescentIfGreater(m_initialStrut->descent());
     609        m_lineBox.setLogicalHeightIfGreater(baseline.height());
     610        m_initialStrut = { };
     611        return;
     612    }
     613
     614    auto& layoutBox = run.layoutBox();
    630615    auto& style = layoutBox.style();
    631     auto& baseline = m_lineBox.baseline();
    632 
    633     if (inlineItem.isContainerStart()) {
     616    if (run.isContainerStart()) {
    634617        // Inline containers stretch the line by their font size.
    635618        // Vertical margins, paddings and borders don't contribute to the line height.
     
    648631    }
    649632
    650     if (inlineItem.isText() || inlineItem.isForcedLineBreak()) {
    651         // For text content we set the baseline either through the initial strut (set by the formatting context root) or
    652         // through the inline container (start) -see above. Normally the text content itself does not stretch the line.
    653         if (!m_initialStrut)
    654             return;
    655         m_lineBox.setAscentIfGreater(m_initialStrut->ascent());
    656         m_lineBox.setDescentIfGreater(m_initialStrut->descent());
    657         m_lineBox.setLogicalHeightIfGreater(baseline.height());
    658         m_initialStrut = { };
    659         return;
    660     }
    661 
    662     if (inlineItem.isBox()) {
     633    if (run.isContainerEnd()) {
     634        // The line's baseline and height have already been adjusted at ContainerStart.
     635        return;
     636    }
     637
     638    if (run.isBox()) {
    663639        auto& boxGeometry = formattingContext().geometryForBox(layoutBox);
    664640        auto marginBoxHeight = boxGeometry.marginBoxHeight();
     
    709685}
    710686
    711 LayoutUnit Line::inlineItemContentHeight(const InlineItem& inlineItem) const
     687LayoutUnit Line::runContentHeight(const Run& run) const
    712688{
    713689    ASSERT(!m_skipAlignment);
    714     auto& fontMetrics = inlineItem.style().fontMetrics();
    715     if (inlineItem.isForcedLineBreak() || is<InlineTextItem>(inlineItem))
     690    auto& fontMetrics = run.layoutBox().style().fontMetrics();
     691    if (run.isText() || run.isForcedLineBreak())
    716692        return fontMetrics.height();
    717693
    718     if (inlineItem.isContainerStart() || inlineItem.isContainerEnd())
     694    if (run.isContainerStart() || run.isContainerEnd())
    719695        return fontMetrics.height();
    720696
    721     auto& layoutBox = inlineItem.layoutBox();
     697    auto& layoutBox = run.layoutBox();
    722698    auto& boxGeometry = formattingContext().geometryForBox(layoutBox);
    723699    if (layoutBox.replaced() || layoutBox.isFloatingPositioned())
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.h

    r252807 r252835  
    9292        void moveHorizontally(LayoutUnit offset) { m_logicalRect.moveHorizontally(offset); }
    9393        void moveVertically(LayoutUnit offset) { m_logicalRect.moveVertically(offset); }
     94        void setLogicalHeight(LayoutUnit logicalHeight) { m_logicalRect.setHeight(logicalHeight); }
    9495
    9596        bool hasExpansionOpportunity() const { return m_expansionOpportunityCount; }
     
    136137    void removeTrailingTrimmableContent();
    137138    void alignContentHorizontally(RunList&, IsLastLineWithInlineContent) const;
    138     void alignContentVertically(RunList&) const;
     139    void alignContentVertically(RunList&);
    139140
    140     void adjustBaselineAndLineHeight(const InlineItem&);
    141     LayoutUnit inlineItemContentHeight(const InlineItem&) const;
     141    void adjustBaselineAndLineHeight(const Run&);
     142    LayoutUnit runContentHeight(const Run&) const;
    142143    bool isVisuallyEmpty() const;
    143144
Note: See TracChangeset for help on using the changeset viewer.