From 704aa0d2bf1f9b6d0bba9ef23349080f7720966c Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Wed, 28 Jun 2017 11:30:32 -0700 Subject: [PATCH] Only obtain new font if font has changed. Change-Id: I9a6316854e13ff5f01a34bbfca8750d223a90af8 --- .../benchmarks/font_collection_benchmarks.cc | 6 ++++-- engine/src/flutter/src/paragraph.cc | 14 ++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/benchmarks/font_collection_benchmarks.cc b/engine/src/flutter/benchmarks/font_collection_benchmarks.cc index 10751e324f..99eb26eecf 100644 --- a/engine/src/flutter/benchmarks/font_collection_benchmarks.cc +++ b/engine/src/flutter/benchmarks/font_collection_benchmarks.cc @@ -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); diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 0dda95b66a..fbdc53c6a9 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -214,12 +214,18 @@ void Paragraph::Layout(double width, } x_queue.clear(); }; - + std::shared_ptr 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);