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

Unified Diff: ui/gfx/render_text_harfbuzz.cc

Issue 674683003: Avoid extra FontRenderParams queries in RenderTextHarfBuzz. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: restore check that a family was actually found Created 6 years, 2 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 | « ui/gfx/render_text_harfbuzz.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_harfbuzz.cc
diff --git a/ui/gfx/render_text_harfbuzz.cc b/ui/gfx/render_text_harfbuzz.cc
index 7f151712dfd3b3b08664e088cc1004094d5f50c9..3ee533290ca729bb9871427740e29c597c6d1489 100644
--- a/ui/gfx/render_text_harfbuzz.cc
+++ b/ui/gfx/render_text_harfbuzz.cc
@@ -1070,82 +1070,83 @@ void RenderTextHarfBuzz::ItemizeText() {
ubidi_reorderLogical(&levels[0], num_runs, &logical_to_visual_[0]);
}
+bool RenderTextHarfBuzz::CompareFamily(
+ internal::TextRunHarfBuzz* run,
+ const std::string& family,
+ const gfx::FontRenderParams& render_params,
+ std::string* best_family,
+ gfx::FontRenderParams* best_render_params,
+ size_t* best_missing_glyphs) {
+ if (!ShapeRunWithFont(run, family, render_params))
+ return false;
+
+ const size_t missing_glyphs = run->CountMissingGlyphs();
+ if (missing_glyphs < *best_missing_glyphs) {
+ *best_family = family;
+ *best_render_params = render_params;
+ *best_missing_glyphs = missing_glyphs;
+ }
+ return missing_glyphs == 0;
+}
+
void RenderTextHarfBuzz::ShapeRun(internal::TextRunHarfBuzz* run) {
const Font& primary_font = font_list().GetPrimaryFont();
- const std::string primary_font_name = primary_font.GetFontName();
run->font_size = primary_font.GetFontSize();
- size_t best_font_missing = std::numeric_limits<size_t>::max();
- std::string best_font;
- std::string current_font;
+ std::string best_family;
+ FontRenderParams best_render_params;
+ size_t best_missing_glyphs = std::numeric_limits<size_t>::max();
- // Try shaping with |primary_font|.
- if (ShapeRunWithFont(run, primary_font_name)) {
- current_font = primary_font_name;
- size_t current_missing = run->CountMissingGlyphs();
- if (current_missing == 0)
- return;
- if (current_missing < best_font_missing) {
- best_font_missing = current_missing;
- best_font = current_font;
- }
- }
+ if (CompareFamily(run, primary_font.GetFontName(),
+ primary_font.GetFontRenderParams(),
+ &best_family, &best_render_params, &best_missing_glyphs))
+ return;
#if defined(OS_WIN)
Font uniscribe_font;
const base::char16* run_text = &(GetLayoutText()[run->range.start()]);
if (GetUniscribeFallbackFont(primary_font, run_text, run->range.length(),
&uniscribe_font) &&
- ShapeRunWithFont(run, uniscribe_font.GetFontName())) {
- current_font = uniscribe_font.GetFontName();
- size_t current_missing = run->CountMissingGlyphs();
- if (current_missing == 0)
- return;
- if (current_missing < best_font_missing) {
- best_font_missing = current_missing;
- best_font = current_font;
- }
- }
+ CompareFamily(run, uniscribe_font.GetFontName(),
+ uniscribe_font.GetFontRenderParams(),
+ &best_family, &best_render_params, &best_missing_glyphs))
+ return;
#endif
- // Try shaping with the fonts in the fallback list except the first, which is
- // |primary_font|.
- std::vector<std::string> fonts = GetFallbackFontFamilies(primary_font_name);
- for (size_t i = 1; i < fonts.size(); ++i) {
- if (!ShapeRunWithFont(run, fonts[i]))
- continue;
- current_font = fonts[i];
- size_t current_missing = run->CountMissingGlyphs();
- if (current_missing == 0)
+ // Skip the first fallback font, which is |primary_font|.
+ std::vector<std::string> fallback_families =
+ GetFallbackFontFamilies(primary_font.GetFontName());
+ for (size_t i = 1; i < fallback_families.size(); ++i) {
+ FontRenderParamsQuery query(false);
+ query.families.push_back(fallback_families[i]);
+ query.pixel_size = run->font_size;
+ query.style = run->font_style;
+ FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL);
+ if (CompareFamily(run, fallback_families[i], fallback_render_params,
+ &best_family, &best_render_params, &best_missing_glyphs))
return;
- if (current_missing < best_font_missing) {
- best_font_missing = current_missing;
- best_font = current_font;
- }
}
- if (!best_font.empty() &&
- (best_font == current_font || ShapeRunWithFont(run, best_font))) {
+ if (!best_family.empty() &&
+ (best_family == run->family ||
+ ShapeRunWithFont(run, best_family, best_render_params)))
return;
- }
run->glyph_count = 0;
run->width = 0.0f;
}
bool RenderTextHarfBuzz::ShapeRunWithFont(internal::TextRunHarfBuzz* run,
- const std::string& font_family) {
+ const std::string& font_family,
+ const FontRenderParams& params) {
const base::string16& text = GetLayoutText();
skia::RefPtr<SkTypeface> skia_face =
internal::CreateSkiaTypeface(font_family, run->font_style);
if (skia_face == NULL)
return false;
run->skia_face = skia_face;
- FontRenderParamsQuery query(false);
- query.families.push_back(font_family);
- query.pixel_size = run->font_size;
- query.style = run->font_style;
- run->render_params = GetFontRenderParams(query, NULL);
+ run->family = font_family;
+ run->render_params = params;
hb_font_t* harfbuzz_font = CreateHarfBuzzFont(
run->skia_face.get(), SkIntToScalar(run->font_size), run->render_params,
background_is_transparent());
« no previous file with comments | « ui/gfx/render_text_harfbuzz.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698