Only obtain new font if font has changed.

Change-Id: I9a6316854e13ff5f01a34bbfca8750d223a90af8
This commit is contained in:
Gary Qian
2017-06-28 11:30:32 -07:00
parent f716e8115c
commit 704aa0d2bf
2 changed files with 14 additions and 6 deletions

View File

@@ -39,9 +39,11 @@ static void BM_FontCollectionInit(benchmark::State& state) {
}
BENCHMARK(BM_FontCollectionInit);
static void BM_FontCollectionGetMinikinFontCollectionForFamily(benchmark::State& state) {
static void BM_FontCollectionGetMinikinFontCollectionForFamily(
benchmark::State& state) {
while (state.KeepRunning()) {
FontCollection::GetFontCollection(txt::GetFontDir()).GetMinikinFontCollectionForFamily("Roboto");
FontCollection::GetFontCollection(txt::GetFontDir())
.GetMinikinFontCollectionForFamily("Roboto");
}
}
BENCHMARK(BM_FontCollectionGetMinikinFontCollectionForFamily);

View File

@@ -214,12 +214,18 @@ void Paragraph::Layout(double width,
}
x_queue.clear();
};
std::shared_ptr<minikin::FontCollection> collection = nullptr;
std::string prev_font_family = "";
for (size_t run_index = 0; run_index < runs_.size(); ++run_index) {
auto run = runs_.GetRun(run_index);
auto collection =
FontCollection::GetFontCollection(rootdir)
.GetMinikinFontCollectionForFamily(run.style.font_family);
// Only obtain new font family if the font has changed between runs.
if (run.style.font_family != prev_font_family || collection == nullptr) {
collection =
FontCollection::GetFontCollection(rootdir)
.GetMinikinFontCollectionForFamily(run.style.font_family);
}
prev_font_family = run.style.font_family;
GetFontAndMinikinPaint(run.style, &font, &minikin_paint);
GetPaint(run.style, &paint);