diff options
author | derat <derat@chromium.org> | 2014-10-24 07:47:47 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-24 14:48:06 +0000 |
commit | faf4a0632d4aa96f0f8b31021fb353eebc5509e6 (patch) | |
tree | c9b7f3f65befe907b63312beefce254bcac835b1 /ui/gfx/render_text_harfbuzz.cc | |
parent | c5bdcca1573b6dd37eb828877fff8d136f8c7e7b (diff) | |
download | chromium_src-faf4a0632d4aa96f0f8b31021fb353eebc5509e6.zip chromium_src-faf4a0632d4aa96f0f8b31021fb353eebc5509e6.tar.gz chromium_src-faf4a0632d4aa96f0f8b31021fb353eebc5509e6.tar.bz2 |
Avoid extra FontRenderParams queries in RenderTextHarfBuzz.
gfx::Font already contains a FontRenderParams struct. Make
RenderTextHarfBuzz use it when possible instead of always
querying for a new struct.
BUG=none
Review URL: https://codereview.chromium.org/674683003
Cr-Commit-Position: refs/heads/master@{#301101}
Diffstat (limited to 'ui/gfx/render_text_harfbuzz.cc')
-rw-r--r-- | ui/gfx/render_text_harfbuzz.cc | 95 |
1 files changed, 48 insertions, 47 deletions
diff --git a/ui/gfx/render_text_harfbuzz.cc b/ui/gfx/render_text_harfbuzz.cc index 7f15171..3ee5332 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()); |