Changeset 59588 in webkit


Ignore:
Timestamp:
May 16, 2010 6:43:49 PM (14 years ago)
Author:
mitz@apple.com
Message:

Move transient glyph overflow and fallback font data from a global to the stack
https://bugs.webkit.org/show_bug.cgi?id=39050

Reviewed by Darin Adler.

  • rendering/InlineFlowBox.cpp:

(WebCore::InlineFlowBox::placeBoxesHorizontally): Added a GlyphOverflowAndFallbackFontsMap
parameter. Read glyph overflow from the map.
(WebCore::InlineFlowBox::computeLogicalBoxHeights): Added a GlyphOverflowAndFallbackFontsMap
parameter. Read fallback fonts from the map.
(WebCore::InlineFlowBox::computeVerticalOverflow): Added a GlyphOverflowAndFallbackFontsMap
parameter. Read glyph overflow from the map.

  • rendering/InlineFlowBox.h:
  • rendering/InlineTextBox.cpp: Removed setFallbackFonts(), fallbackFonts(), setGlyphOverflow(),

and glyphOverflow(). Removed s_glyphOverflowAndFallbackFontsMap.

  • rendering/InlineTextBox.h:
  • rendering/RenderBlock.h:
  • rendering/RenderBlockLineLayout.cpp:

(WebCore::RenderBlock::computeHorizontalPositionsForLine): Added a GlyphOverflowAndFallbackFontsMap
parameter. Write fallback fonts and glyph overflow into the map.
(WebCore::RenderBlock::computeVerticalPositionsForLine): Added a GlyphOverflowAndFallbackFontsMap
parameter. Pass it down to verticallyAlignBoxes().
(WebCore::RenderBlock::layoutInlineChildren): Create a GlyphOverflowAndFallbackFontsMap on the
stack and pass it down to computeHorizontalPositionsForLine(), computeVerticalPositionsForLine(),
and verticallyAlignBoxes().

  • rendering/RootInlineBox.cpp:

(WebCore::RootInlineBox::verticallyAlignBoxes): Added a GlyphOverflowAndFallbackFontsMap parameter.
Pass it down to computeLogicalBoxHeights() and computeVerticalOverflow().

  • rendering/RootInlineBox.h:
  • rendering/SVGRootInlineBox.cpp:

(WebCore::SVGRootInlineBox::layoutInlineBoxes): Updated.

Location:
trunk/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r59585 r59588  
     12010-05-16  Dan Bernstein  <mitz@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Move transient glyph overflow and fallback font data from a global to the stack
     6        https://bugs.webkit.org/show_bug.cgi?id=39050
     7
     8        * rendering/InlineFlowBox.cpp:
     9        (WebCore::InlineFlowBox::placeBoxesHorizontally): Added a GlyphOverflowAndFallbackFontsMap
     10        parameter. Read glyph overflow from the map.
     11        (WebCore::InlineFlowBox::computeLogicalBoxHeights): Added a GlyphOverflowAndFallbackFontsMap
     12        parameter. Read fallback fonts from the map.
     13        (WebCore::InlineFlowBox::computeVerticalOverflow): Added a GlyphOverflowAndFallbackFontsMap
     14        parameter. Read glyph overflow from the map.
     15        * rendering/InlineFlowBox.h:
     16        * rendering/InlineTextBox.cpp: Removed setFallbackFonts(), fallbackFonts(), setGlyphOverflow(),
     17        and glyphOverflow(). Removed s_glyphOverflowAndFallbackFontsMap.
     18        * rendering/InlineTextBox.h:
     19        * rendering/RenderBlock.h:
     20        * rendering/RenderBlockLineLayout.cpp:
     21        (WebCore::RenderBlock::computeHorizontalPositionsForLine): Added a GlyphOverflowAndFallbackFontsMap
     22        parameter. Write fallback fonts and glyph overflow into the map.
     23        (WebCore::RenderBlock::computeVerticalPositionsForLine): Added a GlyphOverflowAndFallbackFontsMap
     24        parameter. Pass it down to verticallyAlignBoxes().
     25        (WebCore::RenderBlock::layoutInlineChildren): Create a GlyphOverflowAndFallbackFontsMap on the
     26        stack and pass it down to computeHorizontalPositionsForLine(), computeVerticalPositionsForLine(),
     27        and verticallyAlignBoxes().
     28        * rendering/RootInlineBox.cpp:
     29        (WebCore::RootInlineBox::verticallyAlignBoxes): Added a GlyphOverflowAndFallbackFontsMap parameter.
     30        Pass it down to computeLogicalBoxHeights() and computeVerticalOverflow().
     31        * rendering/RootInlineBox.h:
     32        * rendering/SVGRootInlineBox.cpp:
     33        (WebCore::SVGRootInlineBox::layoutInlineBoxes): Updated.
     34
    1352010-05-12  Tony Chang  <tony@chromium.org>
    236
  • trunk/WebCore/rendering/InlineFlowBox.cpp

    r59274 r59588  
    253253}
    254254
    255 int InlineFlowBox::placeBoxesHorizontally(int xPos, bool& needsWordSpacing)
     255int InlineFlowBox::placeBoxesHorizontally(int xPos, bool& needsWordSpacing, GlyphOverflowAndFallbackFontsMap& textBoxDataMap)
    256256{
    257257    // Set our x position.
     
    290290            rightLayoutOverflow = max(xPos + text->width() - letterSpacing, rightLayoutOverflow);
    291291
    292             GlyphOverflow* glyphOverflow = static_cast<InlineTextBox*>(curr)->glyphOverflow();
     292            GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.find(static_cast<InlineTextBox*>(curr));
     293            GlyphOverflow* glyphOverflow = it == textBoxDataMap.end() ? 0 : &it->second.second;
    293294
    294295            int leftGlyphOverflow = -strokeOverflow - (glyphOverflow ? glyphOverflow->left : 0);
     
    320321                InlineFlowBox* flow = static_cast<InlineFlowBox*>(curr);
    321322                xPos += flow->marginLeft();
    322                 xPos = flow->placeBoxesHorizontally(xPos, needsWordSpacing);
     323                xPos = flow->placeBoxesHorizontally(xPos, needsWordSpacing, textBoxDataMap);
    323324                xPos += flow->marginRight();
    324325                leftLayoutOverflow = min(leftLayoutOverflow, flow->leftLayoutOverflow());
     
    392393
    393394void InlineFlowBox::computeLogicalBoxHeights(int& maxPositionTop, int& maxPositionBottom,
    394                                              int& maxAscent, int& maxDescent, bool strictMode)
     395                                             int& maxAscent, int& maxDescent, bool strictMode, GlyphOverflowAndFallbackFontsMap& textBoxDataMap)
    395396{
    396397    if (isRootInlineBox()) {
     
    417418        int baseline;
    418419        Vector<const SimpleFontData*>* usedFonts = 0;
    419         if (curr->isInlineTextBox())
    420             usedFonts = static_cast<InlineTextBox*>(curr)->fallbackFonts();
     420        if (curr->isInlineTextBox()) {
     421            GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.find(static_cast<InlineTextBox*>(curr));
     422            usedFonts = it == textBoxDataMap.end() ? 0 : &it->second.first;
     423        }
    421424
    422425        if (usedFonts) {
     
    469472
    470473        if (curr->isInlineFlowBox())
    471             static_cast<InlineFlowBox*>(curr)->computeLogicalBoxHeights(maxPositionTop, maxPositionBottom, maxAscent, maxDescent, strictMode);
     474            static_cast<InlineFlowBox*>(curr)->computeLogicalBoxHeights(maxPositionTop, maxPositionBottom, maxAscent, maxDescent, strictMode, textBoxDataMap);
    472475    }
    473476}
     
    536539}
    537540
    538 void InlineFlowBox::computeVerticalOverflow(int lineTop, int lineBottom, bool strictMode)
     541void InlineFlowBox::computeVerticalOverflow(int lineTop, int lineBottom, bool strictMode, GlyphOverflowAndFallbackFontsMap& textBoxDataMap)
    539542{
    540543    int boxHeight = height();
     
    573576            int strokeOverflow = static_cast<int>(ceilf(rt->style()->textStrokeWidth() / 2.0f));
    574577
    575             GlyphOverflow* glyphOverflow = static_cast<InlineTextBox*>(curr)->glyphOverflow();
     578            GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.find(static_cast<InlineTextBox*>(curr));
     579            GlyphOverflow* glyphOverflow = it == textBoxDataMap.end() ? 0 : &it->second.second;
    576580
    577581            int topGlyphOverflow = -strokeOverflow - (glyphOverflow ? glyphOverflow->top : 0);
     
    589593        } else  if (curr->renderer()->isRenderInline()) {
    590594            InlineFlowBox* flow = static_cast<InlineFlowBox*>(curr);
    591             flow->computeVerticalOverflow(lineTop, lineBottom, strictMode);
     595            flow->computeVerticalOverflow(lineTop, lineBottom, strictMode, textBoxDataMap);
    592596            topLayoutOverflow = min(topLayoutOverflow, flow->topLayoutOverflow());
    593597            bottomLayoutOverflow = max(bottomLayoutOverflow, flow->bottomLayoutOverflow());
  • trunk/WebCore/rendering/InlineFlowBox.h

    r59274 r59588  
    2929class HitTestRequest;
    3030class HitTestResult;
     31class InlineTextBox;
    3132class RenderLineBoxList;
     33
     34typedef HashMap<const InlineTextBox*, pair<Vector<const SimpleFontData*>, GlyphOverflow> > GlyphOverflowAndFallbackFontsMap;
    3235
    3336class InlineFlowBox : public InlineBox {
     
    125128    int getFlowSpacingWidth();
    126129    bool onEndChain(RenderObject* endObject);
    127     virtual int placeBoxesHorizontally(int x, bool& needsWordSpacing);
     130    virtual int placeBoxesHorizontally(int x, bool& needsWordSpacing, GlyphOverflowAndFallbackFontsMap&);
    128131    void computeLogicalBoxHeights(int& maxPositionTop, int& maxPositionBottom,
    129                                   int& maxAscent, int& maxDescent, bool strictMode);
     132                                  int& maxAscent, int& maxDescent, bool strictMode, GlyphOverflowAndFallbackFontsMap&);
    130133    void adjustMaxAscentAndDescent(int& maxAscent, int& maxDescent,
    131134                                   int maxPositionTop, int maxPositionBottom);
    132135    void placeBoxesVertically(int y, int maxHeight, int maxAscent, bool strictMode, int& lineTop, int& lineBottom);
    133     void computeVerticalOverflow(int lineTop, int lineBottom, bool strictMode);
     136    void computeVerticalOverflow(int lineTop, int lineBottom, bool strictMode, GlyphOverflowAndFallbackFontsMap&);
    134137
    135138    void removeChild(InlineBox* child);
  • trunk/WebCore/rendering/InlineTextBox.cpp

    r59274 r59588  
    10251025}
    10261026
    1027 void InlineTextBox::setFallbackFonts(const HashSet<const SimpleFontData*>& fallbackFonts)
    1028 {
    1029     if (!s_glyphOverflowAndFallbackFontsMap)
    1030         s_glyphOverflowAndFallbackFontsMap = new GlyphOverflowAndFallbackFontsMap;
    1031 
    1032     GlyphOverflowAndFallbackFontsMap::iterator it = s_glyphOverflowAndFallbackFontsMap->add(this, make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).first;
    1033     ASSERT(it->second.first.isEmpty());
    1034     copyToVector(fallbackFonts, it->second.first);
    1035 }
    1036 
    1037 Vector<const SimpleFontData*>* InlineTextBox::fallbackFonts() const
    1038 {
    1039     if (!s_glyphOverflowAndFallbackFontsMap)
    1040         return 0;
    1041 
    1042     GlyphOverflowAndFallbackFontsMap::iterator it = s_glyphOverflowAndFallbackFontsMap->find(this);
    1043     if (it == s_glyphOverflowAndFallbackFontsMap->end())
    1044         return 0;
    1045 
    1046     return &it->second.first;
    1047 }
    1048 
    1049 InlineTextBox::GlyphOverflowAndFallbackFontsMap* InlineTextBox::s_glyphOverflowAndFallbackFontsMap = 0;
    1050 
    1051 void InlineTextBox::setGlyphOverflow(const GlyphOverflow& glyphOverflow)
    1052 {
    1053     if (!s_glyphOverflowAndFallbackFontsMap)
    1054         s_glyphOverflowAndFallbackFontsMap = new GlyphOverflowAndFallbackFontsMap;
    1055 
    1056     GlyphOverflowAndFallbackFontsMap::iterator it = s_glyphOverflowAndFallbackFontsMap->add(this, make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).first;
    1057     it->second.second = glyphOverflow;
    1058 }
    1059 
    1060 GlyphOverflow* InlineTextBox::glyphOverflow() const
    1061 {
    1062     if (!s_glyphOverflowAndFallbackFontsMap)
    1063         return 0;
    1064     GlyphOverflowAndFallbackFontsMap::iterator it = s_glyphOverflowAndFallbackFontsMap->find(this);
    1065     if (it == s_glyphOverflowAndFallbackFontsMap->end())
    1066         return 0;
    1067 
    1068     return &it->second.second;
    1069 }
    1070 
    10711027} // namespace WebCore
  • trunk/WebCore/rendering/InlineTextBox.h

    r59274 r59588  
    6464    void offsetRun(int d) { m_start += d; }
    6565
    66     void setFallbackFonts(const HashSet<const SimpleFontData*>&);
    67     Vector<const SimpleFontData*>* fallbackFonts() const;
    68 
    69     void setGlyphOverflow(const GlyphOverflow&);
    70     GlyphOverflow* glyphOverflow() const;
    71 
    72     static void clearGlyphOverflowAndFallbackFontMap()
    73     {
    74         if (s_glyphOverflowAndFallbackFontsMap)
    75             s_glyphOverflowAndFallbackFontsMap->clear();
    76     }
    77 
    7866    unsigned short truncation() { return m_truncation; }
    7967
     
    139127                      // denote no truncation (the whole run paints) and full truncation (nothing paints at all).
    140128
    141     typedef HashMap<const InlineTextBox*, pair<Vector<const SimpleFontData*>, GlyphOverflow> > GlyphOverflowAndFallbackFontsMap;
    142     static GlyphOverflowAndFallbackFontsMap* s_glyphOverflowAndFallbackFontsMap;
    143 
    144129protected:
    145130    void paintCompositionBackground(GraphicsContext*, int tx, int ty, RenderStyle*, const Font&, int startPos, int endPos);
  • trunk/WebCore/rendering/RenderBlock.h

    r57096 r59588  
    265265    RootInlineBox* constructLine(unsigned runCount, BidiRun* firstRun, BidiRun* lastRun, bool firstLine, bool lastLine, RenderObject* endObject);
    266266    InlineFlowBox* createLineBoxes(RenderObject*, bool firstLine);
    267     void computeHorizontalPositionsForLine(RootInlineBox*, bool firstLine, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd);
    268     void computeVerticalPositionsForLine(RootInlineBox*, BidiRun*);
     267    void computeHorizontalPositionsForLine(RootInlineBox*, bool firstLine, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd, GlyphOverflowAndFallbackFontsMap&);
     268    void computeVerticalPositionsForLine(RootInlineBox*, BidiRun*, GlyphOverflowAndFallbackFontsMap&);
    269269    void deleteEllipsisLineBoxes();
    270270    void checkLinesForTextOverflow();
  • trunk/WebCore/rendering/RenderBlockLineLayout.cpp

    r59274 r59588  
    310310}
    311311
    312 void RenderBlock::computeHorizontalPositionsForLine(RootInlineBox* lineBox, bool firstLine, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd)
     312void RenderBlock::computeHorizontalPositionsForLine(RootInlineBox* lineBox, bool firstLine, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd, GlyphOverflowAndFallbackFontsMap& textBoxDataMap)
    313313{
    314314    // First determine our total width.
     
    350350            ) {
    351351                ASSERT(r->m_box->isText());
    352                 static_cast<InlineTextBox*>(r->m_box)->setFallbackFonts(fallbackFonts);
     352                GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(static_cast<InlineTextBox*>(r->m_box), make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).first;
     353                ASSERT(it->second.first.isEmpty());
     354                copyToVector(fallbackFonts, it->second.first);
    353355            }
    354356            if ((glyphOverflow.top || glyphOverflow.bottom || glyphOverflow.left || glyphOverflow.right)
     
    358360            ) {
    359361                ASSERT(r->m_box->isText());
    360                 static_cast<InlineTextBox*>(r->m_box)->setGlyphOverflow(glyphOverflow);
     362                GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(static_cast<InlineTextBox*>(r->m_box), make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).first;
     363                it->second.second = glyphOverflow;
    361364            }
    362365        } else if (!r->m_object->isRenderInline()) {
     
    475478    // compute accurate widths for the inline flow boxes).
    476479    needsWordSpacing = false;
    477     lineBox->placeBoxesHorizontally(x, needsWordSpacing);
    478 }
    479 
    480 void RenderBlock::computeVerticalPositionsForLine(RootInlineBox* lineBox, BidiRun* firstRun)
    481 {
    482     setHeight(lineBox->verticallyAlignBoxes(height()));
     480    lineBox->placeBoxesHorizontally(x, needsWordSpacing, textBoxDataMap);
     481}
     482
     483void RenderBlock::computeVerticalPositionsForLine(RootInlineBox* lineBox, BidiRun* firstRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap)
     484{
     485    setHeight(lineBox->verticallyAlignBoxes(height(), textBoxDataMap));
    483486    lineBox->setBlockHeight(height());
    484487
     
    740743
    741744                        // Now we position all of our text runs horizontally.
    742                         computeHorizontalPositionsForLine(lineBox, firstLine, resolver.firstRun(), trailingSpaceRun, end.atEnd());
     745                        GlyphOverflowAndFallbackFontsMap textBoxDataMap;
     746                        computeHorizontalPositionsForLine(lineBox, firstLine, resolver.firstRun(), trailingSpaceRun, end.atEnd(), textBoxDataMap);
    743747
    744748                        // Now position our text runs vertically.
    745                         computeVerticalPositionsForLine(lineBox, resolver.firstRun());
    746                         InlineTextBox::clearGlyphOverflowAndFallbackFontMap();
     749                        computeVerticalPositionsForLine(lineBox, resolver.firstRun(), textBoxDataMap);
    747750
    748751#if ENABLE(SVG)
     
    840843                m_lineBoxes.appendLineBox(trailingFloatsLineBox);
    841844                trailingFloatsLineBox->setConstructed();
    842                 trailingFloatsLineBox->verticallyAlignBoxes(height());
     845                GlyphOverflowAndFallbackFontsMap textBoxDataMap;
     846                trailingFloatsLineBox->verticallyAlignBoxes(height(), textBoxDataMap);
    843847                trailingFloatsLineBox->setHeight(0);
    844848                trailingFloatsLineBox->setVerticalOverflowPositions(height(), bottomLayoutOverflow, height(), bottomVisualOverflow);
  • trunk/WebCore/rendering/RootInlineBox.cpp

    r59274 r59588  
    203203}
    204204
    205 int RootInlineBox::verticallyAlignBoxes(int heightOfBlock)
     205int RootInlineBox::verticallyAlignBoxes(int heightOfBlock, GlyphOverflowAndFallbackFontsMap& textBoxDataMap)
    206206{
    207207    int maxPositionTop = 0;
     
    217217    bool strictMode = (curr && curr->document()->inStrictMode());
    218218
    219     computeLogicalBoxHeights(maxPositionTop, maxPositionBottom, maxAscent, maxDescent, strictMode);
     219    computeLogicalBoxHeights(maxPositionTop, maxPositionBottom, maxAscent, maxDescent, strictMode, textBoxDataMap);
    220220
    221221    if (maxAscent + maxDescent < max(maxPositionTop, maxPositionBottom))
     
    226226    int lineBottom = heightOfBlock;
    227227    placeBoxesVertically(heightOfBlock, maxHeight, maxAscent, strictMode, lineTop, lineBottom);
    228     computeVerticalOverflow(lineTop, lineBottom, strictMode);
     228    computeVerticalOverflow(lineTop, lineBottom, strictMode, textBoxDataMap);
    229229    setLineTopBottomPositions(lineTop, lineBottom);
    230230   
  • trunk/WebCore/rendering/RootInlineBox.h

    r55928 r59588  
    6262    int selectionHeight() const { return max(0, selectionBottom() - selectionTop()); }
    6363
    64     virtual int verticallyAlignBoxes(int heightOfBlock);
     64    virtual int verticallyAlignBoxes(int heightOfBlock, GlyphOverflowAndFallbackFontsMap&);
    6565    void setLineTopBottomPositions(int top, int bottom);
    6666
  • trunk/WebCore/rendering/SVGRootInlineBox.cpp

    r59148 r59588  
    896896        static_cast<SVGRootInlineBox*>(start)->setHeight(highY - lowY);
    897897
    898         start->computeVerticalOverflow(top, bottom, true);
     898        GlyphOverflowAndFallbackFontsMap textBoxDataMap;
     899        start->computeVerticalOverflow(top, bottom, true, textBoxDataMap);
    899900        static_cast<SVGRootInlineBox*>(start)->setLineTopBottomPositions(top, bottom);
    900901    }
Note: See TracChangeset for help on using the changeset viewer.