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

Unified Diff: Source/platform/fonts/Font.cpp

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/platform/fonts/Font.h ('k') | Source/platform/fonts/WidthCache.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/fonts/Font.cpp
diff --git a/Source/platform/fonts/Font.cpp b/Source/platform/fonts/Font.cpp
index ae4e2236c9c99044f53fed387ab5dda58b986a9c..0e37b836daa12fb56811319037cd8680a5ea3f53 100644
--- a/Source/platform/fonts/Font.cpp
+++ b/Source/platform/fonts/Font.cpp
@@ -213,31 +213,13 @@ void Font::drawEmphasisMarks(SkCanvas* canvas, const TextRunPaintInfo& runInfo,
drawGlyphBuffer(canvas, paint, runInfo, glyphBuffer, point, deviceScaleFactor);
}
-static inline void updateGlyphOverflowFromBounds(const FloatRectOutsets& glyphBounds,
- const FontMetrics& fontMetrics, GlyphOverflow* glyphOverflow)
-{
- glyphOverflow->top = ceilf(glyphOverflow->computeBounds ? glyphBounds.top() : std::max(0.0f, glyphBounds.top() - fontMetrics.floatAscent()));
- glyphOverflow->bottom = ceilf(glyphOverflow->computeBounds ? glyphBounds.bottom() : std::max(0.0f, glyphBounds.bottom() - fontMetrics.floatDescent()));
- glyphOverflow->left = ceilf(glyphBounds.left());
- glyphOverflow->right = ceilf(glyphBounds.right());
-}
-
-float Font::width(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
+float Font::width(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, FloatRect* glyphBounds) const
{
FontCachePurgePreventer purgePreventer;
- CodePath codePathToUse = codePath(TextRunPaintInfo(run));
-
- float result;
- FloatRectOutsets glyphBounds;
- if (codePathToUse == ComplexPath)
- result = floatWidthForComplexText(run, fallbackFonts, &glyphBounds);
- else
- result = floatWidthForSimpleText(run, fallbackFonts, glyphOverflow ? &glyphBounds : 0);
-
- if (glyphOverflow)
- updateGlyphOverflowFromBounds(glyphBounds, fontMetrics(), glyphOverflow);
- return result;
+ if (codePath(TextRunPaintInfo(run)) == ComplexPath)
+ return floatWidthForComplexText(run, fallbackFonts, glyphBounds);
+ return floatWidthForSimpleText(run, fallbackFonts, glyphBounds);
}
PassTextBlobPtr Font::buildTextBlob(const GlyphBuffer& glyphBuffer) const
@@ -688,7 +670,7 @@ void Font::drawTextBlob(SkCanvas* canvas, const SkPaint& paint, const SkTextBlob
canvas->drawTextBlob(blob, origin.x(), origin.y(), paint);
}
-float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, FloatRectOutsets* glyphBounds) const
+float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, FloatRect* outGlyphBounds) const
{
bool hasWordSpacingOrLetterSpacing = fontDescription().wordSpacing()
|| fontDescription().letterSpacing();
@@ -701,27 +683,25 @@ float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon
? m_fontFallbackList->widthCache().add(run, WidthCacheEntry())
: 0;
if (cacheEntry && cacheEntry->isValid()) {
- ASSERT(glyphBounds);
- *glyphBounds = cacheEntry->glyphBounds;
+ if (outGlyphBounds)
+ *outGlyphBounds = cacheEntry->glyphBounds;
return cacheEntry->width;
}
- FloatRect bounds;
- HarfBuzzShaper shaper(this, run, nullptr, fallbackFonts, glyphBounds ? &bounds : 0);
+ FloatRect glyphBounds;
+ HarfBuzzShaper shaper(this, run, nullptr, fallbackFonts, &glyphBounds);
if (!shaper.shape())
return 0;
- glyphBounds->setTop(-bounds.y());
- glyphBounds->setBottom(bounds.maxY());
- glyphBounds->setLeft(std::max(0.0f, -bounds.x()));
- glyphBounds->setRight(std::max(0.0f, bounds.maxX() - shaper.totalWidth()));
-
float result = shaper.totalWidth();
+
if (cacheEntry && (!fallbackFonts || fallbackFonts->isEmpty())) {
- cacheEntry->glyphBounds = *glyphBounds;
+ cacheEntry->glyphBounds = glyphBounds;
cacheEntry->width = result;
}
+ if (outGlyphBounds)
+ *outGlyphBounds = glyphBounds;
return result;
}
@@ -780,20 +760,11 @@ void Font::drawGlyphBuffer(SkCanvas* canvas, const SkPaint& paint, const TextRun
drawGlyphs(canvas, paint, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, point, runInfo.bounds, deviceScaleFactor);
}
-float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, FloatRectOutsets* glyphBounds) const
+float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, FloatRect* glyphBounds) const
{
- FloatRect bounds;
- SimpleShaper shaper(this, run, nullptr, fallbackFonts, glyphBounds ? &bounds : 0);
+ SimpleShaper shaper(this, run, nullptr, fallbackFonts, glyphBounds);
shaper.advance(run.length());
- float runWidth = shaper.runWidthSoFar();
-
- if (glyphBounds) {
- glyphBounds->setTop(-bounds.y());
- glyphBounds->setBottom(bounds.maxY());
- glyphBounds->setLeft(std::max(0.0f, -bounds.x()));
- glyphBounds->setRight(std::max(0.0f, bounds.maxX() - runWidth));
- }
- return runWidth;
+ return shaper.runWidthSoFar();
}
FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to, bool accountForGlyphBounds) const
« no previous file with comments | « Source/platform/fonts/Font.h ('k') | Source/platform/fonts/WidthCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698