Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1258)

Unified Diff: Source/core/layout/line/BreakingContextInlineHeaders.h

Issue 1179723002: Store glyph bounds in WordMeasurement to avoid slow path width calc (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/layout/LayoutTextCombine.cpp ('k') | Source/core/layout/line/GlyphOverflow.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/layout/line/BreakingContextInlineHeaders.h
diff --git a/Source/core/layout/line/BreakingContextInlineHeaders.h b/Source/core/layout/line/BreakingContextInlineHeaders.h
index 872c379a4897da50c82a8be1341df502e048a916..157128e0698558419f22473c6927a68cbbcbe5d3 100644
--- a/Source/core/layout/line/BreakingContextInlineHeaders.h
+++ b/Source/core/layout/line/BreakingContextInlineHeaders.h
@@ -509,20 +509,16 @@ ALWAYS_INLINE TextDirection textDirectionFromUnicode(WTF::Unicode::Direction dir
|| direction == WTF::Unicode::RightToLeftArabic ? RTL : LTR;
}
-ALWAYS_INLINE float textWidth(LayoutText* text, unsigned from, unsigned len, const Font& font, float xPos, bool collapseWhiteSpace, HashSet<const SimpleFontData*>* fallbackFonts = nullptr)
+ALWAYS_INLINE float textWidth(LayoutText* text, unsigned from, unsigned len, const Font& font, float xPos, bool collapseWhiteSpace, HashSet<const SimpleFontData*>* fallbackFonts = nullptr, FloatRect* glyphBounds = nullptr)
{
- if ((!from && len == text->textLength()) || text->style()->hasTextCombine()) {
- GlyphOverflow glyphOverflow;
- return text->width(from, len, font, xPos, text->style()->direction(), fallbackFonts,
- // LayoutText caches fallbackFonts and glyphOverflow together, and requires them to be both null or both non-null.
- fallbackFonts ? &glyphOverflow : nullptr);
- }
+ if ((!from && len == text->textLength()) || text->style()->hasTextCombine())
+ return text->width(from, len, font, xPos, text->style()->direction(), fallbackFonts, glyphBounds);
TextRun run = constructTextRun(text, font, text, from, len, text->styleRef());
run.setCodePath(text->canUseSimpleFontCodePath() ? TextRun::ForceSimple : TextRun::ForceComplex);
run.setTabSize(!collapseWhiteSpace, text->style()->tabSize());
run.setXPos(xPos);
- return font.width(run, fallbackFonts, nullptr);
+ return font.width(run, fallbackFonts, glyphBounds);
}
inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool& hyphenated)
@@ -643,9 +639,9 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
float additionalTempWidth;
if (wordTrailingSpaceWidth && c == spaceCharacter)
- additionalTempWidth = textWidth(layoutText, lastSpace, m_current.offset() + 1 - lastSpace, font, m_width.currentWidth(), m_collapseWhiteSpace, &wordMeasurement.fallbackFonts) - wordTrailingSpaceWidth;
+ additionalTempWidth = textWidth(layoutText, lastSpace, m_current.offset() + 1 - lastSpace, font, m_width.currentWidth(), m_collapseWhiteSpace, &wordMeasurement.fallbackFonts, &wordMeasurement.glyphBounds) - wordTrailingSpaceWidth;
else
- additionalTempWidth = textWidth(layoutText, lastSpace, m_current.offset() - lastSpace, font, m_width.currentWidth(), m_collapseWhiteSpace, &wordMeasurement.fallbackFonts);
+ additionalTempWidth = textWidth(layoutText, lastSpace, m_current.offset() - lastSpace, font, m_width.currentWidth(), m_collapseWhiteSpace, &wordMeasurement.fallbackFonts, &wordMeasurement.glyphBounds);
wordMeasurement.width = additionalTempWidth + wordSpacingForWordMeasurement;
additionalTempWidth += lastSpaceWordSpacing;
@@ -669,7 +665,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
// as candidate width for this line.
bool lineWasTooWide = false;
if (m_width.fitsOnLine() && m_currentCharacterIsSpace && m_currentStyle->breakOnlyAfterWhiteSpace() && !midWordBreak) {
- float charWidth = textWidth(layoutText, m_current.offset(), 1, font, m_width.currentWidth(), m_collapseWhiteSpace, &wordMeasurement.fallbackFonts) + (applyWordSpacing ? wordSpacing : 0);
+ float charWidth = textWidth(layoutText, m_current.offset(), 1, font, m_width.currentWidth(), m_collapseWhiteSpace, &wordMeasurement.fallbackFonts, &wordMeasurement.glyphBounds) + (applyWordSpacing ? wordSpacing : 0);
// Check if line is too big even without the extra space
// at the end of the line. If it is not, do nothing.
// If the line needs the extra whitespace to be too long,
@@ -805,7 +801,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
wordMeasurement.layoutText = layoutText;
// IMPORTANT: current.m_pos is > length here!
- float additionalTempWidth = m_ignoringSpaces ? 0 : textWidth(layoutText, lastSpace, m_current.offset() - lastSpace, font, m_width.currentWidth(), m_collapseWhiteSpace, &wordMeasurement.fallbackFonts);
+ float additionalTempWidth = m_ignoringSpaces ? 0 : textWidth(layoutText, lastSpace, m_current.offset() - lastSpace, font, m_width.currentWidth(), m_collapseWhiteSpace, &wordMeasurement.fallbackFonts, &wordMeasurement.glyphBounds);
wordMeasurement.startOffset = lastSpace;
wordMeasurement.endOffset = m_current.offset();
wordMeasurement.width = m_ignoringSpaces ? 0 : additionalTempWidth + wordSpacingForWordMeasurement;
« no previous file with comments | « Source/core/layout/LayoutTextCombine.cpp ('k') | Source/core/layout/line/GlyphOverflow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698