Commit 52d3b855 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

HarfBuzz: Adjust parameterization of shape functions

Optimization part 2 of ~3

This is in preparation for a follow-on change that will change
RenderTextHarfBuzz::ShapeRun to take a single CommonParams, and a list
of all runs that share these parameters.

To that end, pull out explicit use of RenderTextHarfBuzz::common, and
pass the CommonParams explicitly, wherever possible.

Bug: 862773
Change-Id: Ia349c23ad58ab590c8ec6f05c6a9f1dcc253ab57
Reviewed-on: https://chromium-review.googlesource.com/1137891
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarLeonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575392}
parent 2eb74a3d
This diff is collapsed.
...@@ -78,6 +78,15 @@ struct GFX_EXPORT TextRunHarfBuzz { ...@@ -78,6 +78,15 @@ struct GFX_EXPORT TextRunHarfBuzz {
CommonParams(const CommonParams& other); CommonParams(const CommonParams& other);
CommonParams& operator=(const CommonParams& other); CommonParams& operator=(const CommonParams& other);
// Populate |font_size| and |baseline_offset| based on |primary_font|. Note
// that this will not populate |font|.
void ComputeFontSizeAndBaselineOffset(const Font& primary_font);
// Populate |font|, |skia_face|, and |render_params|. Return false if
// |skia_face| is nullptr.
bool SetFontAndRenderParams(const Font& font,
const FontRenderParams& render_params);
Font font; Font font;
sk_sp<SkTypeface> skia_face; sk_sp<SkTypeface> skia_face;
FontRenderParams render_params; FontRenderParams render_params;
...@@ -112,6 +121,7 @@ struct GFX_EXPORT TextRunHarfBuzz { ...@@ -112,6 +121,7 @@ struct GFX_EXPORT TextRunHarfBuzz {
// TextRunHarfBuzz::range). // TextRunHarfBuzz::range).
std::vector<uint32_t> glyph_to_char; std::vector<uint32_t> glyph_to_char;
size_t glyph_count = 0; size_t glyph_count = 0;
size_t missing_glyph_count = std::numeric_limits<size_t>::max();
}; };
Range range; Range range;
...@@ -237,30 +247,26 @@ class GFX_EXPORT RenderTextHarfBuzz : public RenderText { ...@@ -237,30 +247,26 @@ class GFX_EXPORT RenderTextHarfBuzz : public RenderText {
void ItemizeTextToRuns(const base::string16& string, void ItemizeTextToRuns(const base::string16& string,
internal::TextRunList* run_list_out); internal::TextRunList* run_list_out);
// Helper method for ShapeRun() that calls ShapeRunWithFont() with |text|,
// |run|, |font|, and |render_params|, returning true if the font provides
// all the glyphs needed for |run|, and false otherwise. Additionally updates
// |best_font|, |best_render_params|, and |best_missing_glyphs| if |font|
// has fewer than |best_missing_glyphs| missing glyphs.
bool CompareFamily(const base::string16& text,
const Font& font,
const FontRenderParams& render_params,
internal::TextRunHarfBuzz* run,
Font* best_font,
FontRenderParams* best_render_params,
size_t* best_missing_glyphs);
// Shape the glyphs of all runs in |run_list| using |text|. // Shape the glyphs of all runs in |run_list| using |text|.
void ShapeRunList(const base::string16& text, void ShapeRunList(const base::string16& text,
internal::TextRunList* run_list); internal::TextRunList* run_list);
// Shape the glyphs needed for the |run| within the |text|. // Shape the glyphs needed for the |run| within the |text|. This method will
// apply a number of fonts to |common_params| and assign to |run->common| and
// |run->shape| the common font parameters and resulting shape output with the
// smallest number of missing glyphs.
void ShapeRun(const base::string16& text, void ShapeRun(const base::string16& text,
const internal::TextRunHarfBuzz::CommonParams& common_params,
internal::TextRunHarfBuzz* run); internal::TextRunHarfBuzz* run);
bool ShapeRunWithFont(const base::string16& text,
const Font& font, // Shape the glyphs for |run| within |text| using the font specified by
const FontRenderParams& params, // |common_params|. If the resulting shaping has fewer missing glyphs than
internal::TextRunHarfBuzz* run); // |run->shape.missing_glyph_count|, then write |common_params| to
// |run->common| and write the shaping output to |run->shape|.
void ShapeRunWithFont(
const base::string16& text,
const internal::TextRunHarfBuzz::CommonParams& common_params,
internal::TextRunHarfBuzz* run);
// Makes sure that text runs for layout text are shaped. // Makes sure that text runs for layout text are shaped.
void EnsureLayoutRunList(); void EnsureLayoutRunList();
......
...@@ -551,9 +551,16 @@ class RenderTextHarfBuzzTest : public RenderTextTest { ...@@ -551,9 +551,16 @@ class RenderTextHarfBuzzTest : public RenderTextTest {
bool ShapeRunWithFont(const base::string16& text, bool ShapeRunWithFont(const base::string16& text,
const Font& font, const Font& font,
const FontRenderParams& params, const FontRenderParams& render_params,
internal::TextRunHarfBuzz* run) { internal::TextRunHarfBuzz* run) {
return GetRenderTextHarfBuzz()->ShapeRunWithFont(text, font, params, run); const Font& primary_font =
GetRenderTextHarfBuzz()->font_list().GetPrimaryFont();
run->common.ComputeFontSizeAndBaselineOffset(primary_font);
if (!run->common.SetFontAndRenderParams(font, render_params))
return false;
run->shape.missing_glyph_count = static_cast<size_t>(-1);
GetRenderTextHarfBuzz()->ShapeRunWithFont(text, run->common, run);
return true;
} }
int GetCursorYForTesting(int line_num = 0) { int GetCursorYForTesting(int line_num = 0) {
......
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