Commit 82dff59b authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

Cache (size / units_per_em) in HarfBuzzFontData

SkTypeface::getUnitsPerEm() is not a fast function. This
patch caches (size / units_per_em) in HarfBuzzFontData.

Improves long-line-nowrap.html from 580ms to 547ms (~6%)

Bug: 636993
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: I4decd9f66e6b99b4798b1c7cc522999bba372aba
Reviewed-on: https://chromium-review.googlesource.com/1226773
Commit-Queue: Emil A Eklund <eae@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#591385}
parent f80e40ed
......@@ -211,10 +211,9 @@ static hb_position_t HarfBuzzGetGlyphHorizontalKerning(
int32_t kerning_adjustments[1] = {0};
if (typeface->getKerningPairAdjustments(glyphs, 2, kerning_adjustments)) {
SkScalar upm = SkIntToScalar(typeface->getUnitsPerEm());
SkScalar size = hb_font_data->paint_.getTextSize();
return SkiaTextMetrics::SkiaScalarToHarfBuzzPosition(
SkIntToScalar(kerning_adjustments[0]) * size / upm);
SkIntToScalar(kerning_adjustments[0]) *
hb_font_data->SizePerUnit(*typeface));
}
return 0;
......
......@@ -83,6 +83,14 @@ struct HarfBuzzFontData {
}
}
float SizePerUnit(const SkTypeface& typeface) const {
if (size_per_unit_ != kInvalidFallbackMetricsValue)
return size_per_unit_;
int units_per_em = typeface.getUnitsPerEm();
size_per_unit_ = paint_.getTextSize() / units_per_em;
return size_per_unit_;
}
scoped_refptr<OpenTypeVerticalData> VerticalData() {
if (!vertical_data_) {
DCHECK_NE(ascent_fallback_, kInvalidFallbackMetricsValue);
......@@ -101,7 +109,7 @@ struct HarfBuzzFontData {
// Capture these scaled fallback metrics from FontPlatformData so that a
// OpenTypeVerticalData object can be constructed from them when needed.
float size_per_unit_;
mutable float size_per_unit_;
float ascent_fallback_;
float height_fallback_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment