Changeset 114032 in webkit


Ignore:
Timestamp:
Apr 12, 2012, 2:06:50 PM (13 years ago)
Author:
hyatt@apple.com
Message:

https://bugs.webkit.org/show_bug.cgi?id=83817

This patch modifies RenderText so that it scans all of its characters up front to
determine whether or not the simple code path can be used for measurement/rendering
of the text for the whole run.

TextRun now has an additional field that indicates that the character scan is not
required, since the entire RenderText is known to be simple. This boolean is set
when constructing the TextRun from the places that make TextRuns from RenderTexts.

The character scan has been refactored into a static Font method so that it can be
called by RenderText. The scan of individual TextRuns is also done using the same method
so that the code is shared.

Reviewed by Dan Bernstein.

  • platform/graphics/Font.cpp:

(WebCore::Font::codePath):
(WebCore::Font::characterRangeCodePath):

  • platform/graphics/Font.h:
  • platform/graphics/TextRun.h:

(WebCore::TextRun::TextRun):
(WebCore::TextRun::characterScanForCodePath):
(WebCore::TextRun::setCharacterScanForCodePath):
(TextRun):

  • rendering/InlineTextBox.cpp:

(WebCore::InlineTextBox::constructTextRun):

  • rendering/RenderBlockLineLayout.cpp:

(WebCore::textWidth):

  • rendering/RenderText.cpp:

(WebCore::RenderText::RenderText):
(WebCore::RenderText::widthFromCache):
(WebCore::RenderText::setTextInternal):
(WebCore::RenderText::width):
(WebCore::RenderText::computeCanUseSimpleFontCodePath):
(WebCore):

  • rendering/RenderText.h:

(RenderText):
(WebCore::RenderText::canUseSimpleFontCodePath):

Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r114031 r114032  
     12012-04-12  David Hyatt  <hyatt@apple.com>
     2
     3        https://bugs.webkit.org/show_bug.cgi?id=83817
     4       
     5        This patch modifies RenderText so that it scans all of its characters up front to
     6        determine whether or not the simple code path can be used for measurement/rendering
     7        of the text for the whole run.
     8       
     9        TextRun now has an additional field that indicates that the character scan is not
     10        required, since the entire RenderText is known to be simple. This boolean is set
     11        when constructing the TextRun from the places that make TextRuns from RenderTexts.
     12       
     13        The character scan has been refactored into a static Font method so that it can be
     14        called by RenderText. The scan of individual TextRuns is also done using the same method
     15        so that the code is shared.
     16
     17        Reviewed by Dan Bernstein.
     18
     19        * platform/graphics/Font.cpp:
     20        (WebCore::Font::codePath):
     21        (WebCore::Font::characterRangeCodePath):
     22        * platform/graphics/Font.h:
     23        * platform/graphics/TextRun.h:
     24        (WebCore::TextRun::TextRun):
     25        (WebCore::TextRun::characterScanForCodePath):
     26        (WebCore::TextRun::setCharacterScanForCodePath):
     27        (TextRun):
     28        * rendering/InlineTextBox.cpp:
     29        (WebCore::InlineTextBox::constructTextRun):
     30        * rendering/RenderBlockLineLayout.cpp:
     31        (WebCore::textWidth):
     32        * rendering/RenderText.cpp:
     33        (WebCore::RenderText::RenderText):
     34        (WebCore::RenderText::widthFromCache):
     35        (WebCore::RenderText::setTextInternal):
     36        (WebCore::RenderText::width):
     37        (WebCore::RenderText::computeCanUseSimpleFontCodePath):
     38        (WebCore):
     39        * rendering/RenderText.h:
     40        (RenderText):
     41        (WebCore::RenderText::canUseSimpleFontCodePath):
     42
    1432012-04-12  Levi Weintraub  <leviw@chromium.org>
    244
  • trunk/Source/WebCore/platform/graphics/Font.cpp

    r113968 r114032  
    267267    if (m_fontDescription.featureSettings() && m_fontDescription.featureSettings()->size() > 0)
    268268        return Complex;
    269 
    270     CodePath result = Simple;
    271 
    272     // Start from 0 since drawing and highlighting also measure the characters before run->from
     269   
     270    if (run.length() > 1 && typesettingFeatures())
     271        return Complex;
     272
     273    if (!run.characterScanForCodePath())
     274        return Simple;
     275
     276    // Start from 0 since drawing and highlighting also measure the characters before run->from.
     277    return characterRangeCodePath(run.characters(), run.length());
     278}
     279
     280Font::CodePath Font::characterRangeCodePath(const UChar* characters, unsigned len)
     281{
    273282    // FIXME: Should use a UnicodeSet in ports where ICU is used. Note that we
    274283    // can't simply use UnicodeCharacter Property/class because some characters
     
    276285    // Alternatively, we may as well consider binary search over a sorted
    277286    // list of ranges.
    278     for (int i = 0; i < run.length(); i++) {
    279         const UChar c = run[i];
     287    CodePath result = Simple;
     288    for (unsigned i = 0; i < len; i++) {
     289        const UChar c = characters[i];
    280290        if (c < 0x2E5) // U+02E5 through U+02E9 (Modifier Letters : Tone letters) 
    281291            continue;
     
    384394            // High surrogate
    385395
    386             if (i == run.length() - 1)
    387                 continue;
    388 
    389             UChar next = run[++i];
     396            if (i == len - 1)
     397                continue;
     398
     399            UChar next = characters[++i];
    390400            if (!U16_IS_TRAIL(next))
    391401                continue;
     
    419429            return Complex;
    420430    }
    421 
    422     if (run.length() > 1 && typesettingFeatures())
    423         return Complex;
    424 
    425431    return result;
    426432}
  • trunk/Source/WebCore/platform/graphics/Font.h

    r113968 r114032  
    194194    enum CodePath { Auto, Simple, Complex, SimpleWithGlyphOverflow };
    195195    CodePath codePath(const TextRun&) const;
    196 
     196    static CodePath characterRangeCodePath(const UChar*, unsigned len);
     197   
    197198private:
    198199    enum ForTextEmphasisOrNot { NotForTextEmphasis, ForTextEmphasis };
  • trunk/Source/WebCore/platform/graphics/TextRun.h

    r95901 r114032  
    5959    typedef unsigned RoundingHacks;
    6060
    61     TextRun(const UChar* c, int len, bool allowTabs = false, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, RoundingHacks roundingHacks = RunRounding | WordRounding)
     61    TextRun(const UChar* c, int len, bool allowTabs = false, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding)
    6262        : m_characters(c)
    6363        , m_charactersLength(len)
     
    7272        , m_direction(direction)
    7373        , m_directionalOverride(directionalOverride)
     74        , m_characterScanForCodePath(characterScanForCodePath)
    7475        , m_applyRunRounding((roundingHacks & RunRounding) && s_allowsRoundingHacks)
    7576        , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRoundingHacks)
     
    7879    }
    7980
    80     TextRun(const String& s, bool allowTabs = false, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, RoundingHacks roundingHacks = RunRounding | WordRounding)
     81    TextRun(const String& s, bool allowTabs = false, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding)
    8182        : m_characters(s.characters())
    8283        , m_charactersLength(s.length())
     
    9192        , m_direction(direction)
    9293        , m_directionalOverride(directionalOverride)
     94        , m_characterScanForCodePath(characterScanForCodePath)
    9395        , m_applyRunRounding((roundingHacks & RunRounding) && s_allowsRoundingHacks)
    9496        , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRoundingHacks)
     
    123125    bool ltr() const { return m_direction == LTR; }
    124126    bool directionalOverride() const { return m_directionalOverride; }
     127    bool characterScanForCodePath() const { return m_characterScanForCodePath; }
    125128    bool applyRunRounding() const { return m_applyRunRounding; }
    126129    bool applyWordRounding() const { return m_applyWordRounding; }
     
    131134    void setDirection(TextDirection direction) { m_direction = direction; }
    132135    void setDirectionalOverride(bool override) { m_directionalOverride = override; }
     136    void setCharacterScanForCodePath(bool scan) { m_characterScanForCodePath = scan; }
    133137
    134138    class RenderingContext : public RefCounted<RenderingContext> {
     
    168172    TextDirection m_direction;
    169173    bool m_directionalOverride; // Was this direction set by an override character.
     174    bool m_characterScanForCodePath;
    170175    bool m_applyRunRounding;
    171176    bool m_applyWordRounding;
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r113059 r114032  
    13261326    ASSERT(maximumLength >= length);
    13271327
    1328     TextRun run(characters, length, textRenderer->allowTabs(), textPos(), expansion(), expansionBehavior(), direction(), dirOverride() || style->rtlOrdering() == VisualOrder);
     1328    TextRun run(characters, length, textRenderer->allowTabs(), textPos(), expansion(), expansionBehavior(), direction(), dirOverride() || style->rtlOrdering() == VisualOrder, !textRenderer->canUseSimpleFontCodePath());
    13291329    if (textRunNeedsRenderingContext(font))
    13301330        run.setRenderingContext(SVGTextRunRenderingContext::create(textRenderer));
  • trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp

    r113665 r114032  
    19481948    ASSERT(run.charactersLength() >= run.length());
    19491949
     1950    run.setCharacterScanForCodePath(!text->canUseSimpleFontCodePath());
    19501951    run.setAllowTabs(!collapseWhiteSpace);
    19511952    run.setXPos(xPos);
  • trunk/Source/WebCore/rendering/RenderText.cpp

    r113665 r114032  
    147147     , m_containsReversedText(false)
    148148     , m_isAllASCII(m_text.containsOnlyASCII())
     149     , m_canUseSimpleFontCodePath(computeCanUseSimpleFontCodePath())
    149150     , m_knownToHaveNoOverflowAndNoFallbackFonts(false)
    150151     , m_needsTranscoding(false)
     
    761762    ASSERT(run.charactersLength() >= run.length());
    762763
     764    run.setCharacterScanForCodePath(!canUseSimpleFontCodePath());
    763765    run.setAllowTabs(allowTabs());
    764766    run.setXPos(xPos);
     
    13311333
    13321334    m_isAllASCII = m_text.containsOnlyASCII();
     1335    m_canUseSimpleFontCodePath = computeCanUseSimpleFontCodePath();
    13331336}
    13341337
     
    14741477        ASSERT(run.charactersLength() >= run.length());
    14751478
     1479        run.setCharacterScanForCodePath(!canUseSimpleFontCodePath());
    14761480        run.setAllowTabs(allowTabs());
    14771481        run.setXPos(xPos);
     
    17941798}
    17951799
     1800bool RenderText::computeCanUseSimpleFontCodePath() const
     1801{
     1802    if (isAllASCII())
     1803        return true;
     1804    return Font::characterRangeCodePath(characters(), length()) == Font::Simple;
     1805}
     1806
    17961807#ifndef NDEBUG
    17971808
  • trunk/Source/WebCore/rendering/RenderText.h

    r112776 r114032  
    130130    virtual void computePreferredLogicalWidths(float leadWidth);
    131131    bool isAllCollapsibleWhitespace();
    132    
     132
     133    bool canUseSimpleFontCodePath() const { return m_canUseSimpleFontCodePath; }
    133134    bool knownToHaveNoOverflowAndNoFallbackFonts() const { return m_knownToHaveNoOverflowAndNoFallbackFonts; }
    134135
     
    149150    void computePreferredLogicalWidths(float leadWidth, HashSet<const SimpleFontData*>& fallbackFonts, GlyphOverflow&);
    150151
     152    bool computeCanUseSimpleFontCodePath() const;
     153   
    151154    // Make length() private so that callers that have a RenderText*
    152155    // will use the more efficient textLength() instead, while
     
    187190    bool m_containsReversedText : 1;
    188191    bool m_isAllASCII : 1;
     192    bool m_canUseSimpleFontCodePath : 1;
    189193    mutable bool m_knownToHaveNoOverflowAndNoFallbackFonts : 1;
    190194    bool m_needsTranscoding : 1;
Note: See TracChangeset for help on using the changeset viewer.