From 4ddb034139767b18487620b3eb1923c2142eb539 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Thu, 29 Jun 2017 15:04:54 -0700 Subject: [PATCH] Major efficiency improvements, new benches, and API change to allow changing font collections. Change-Id: Id33cdcd161d659310d28dd36f415dc01da2e03a7 --- engine/src/flutter/benchmarks/BUILD.gn | 1 + .../benchmarks/font_collection_benchmarks.cc | 23 +++++++-- .../benchmarks/paint_record_benchmarks.cc | 46 +++++++++++++++++ .../benchmarks/paragraph_benchmarks.cc | 27 ++++++---- .../paragraph_builder_benchmarks.cc | 21 ++++---- engine/src/flutter/src/font_collection.cc | 12 +++++ engine/src/flutter/src/font_collection.h | 16 ++++-- engine/src/flutter/src/paragraph.cc | 39 ++++++++------- engine/src/flutter/src/paragraph.h | 14 +++--- engine/src/flutter/src/paragraph_builder.cc | 17 +++++++ engine/src/flutter/src/paragraph_builder.h | 6 +++ .../flutter/tests/txt/paragraph_unittests.cc | 50 +++++++++++-------- engine/src/flutter/tests/txt/utils.cc | 2 +- 13 files changed, 202 insertions(+), 72 deletions(-) create mode 100644 engine/src/flutter/benchmarks/paint_record_benchmarks.cc diff --git a/engine/src/flutter/benchmarks/BUILD.gn b/engine/src/flutter/benchmarks/BUILD.gn index 3b637cc4c34..184d2a5a0bb 100644 --- a/engine/src/flutter/benchmarks/BUILD.gn +++ b/engine/src/flutter/benchmarks/BUILD.gn @@ -23,6 +23,7 @@ executable("benchmarks") { sources = [ "font_collection_benchmarks.cc", + "paint_record_benchmarks.cc", "paragraph_benchmarks.cc", "paragraph_builder_benchmarks.cc", "styled_runs_benchmarks.cc", diff --git a/engine/src/flutter/benchmarks/font_collection_benchmarks.cc b/engine/src/flutter/benchmarks/font_collection_benchmarks.cc index 99eb26eecfd..74737a8f702 100644 --- a/engine/src/flutter/benchmarks/font_collection_benchmarks.cc +++ b/engine/src/flutter/benchmarks/font_collection_benchmarks.cc @@ -19,6 +19,8 @@ #include "lib/ftl/command_line.h" #include "lib/ftl/logging.h" #include "lib/txt/src/font_collection.h" +#include "third_party/skia/include/ports/SkFontMgr.h" +#include "third_party/skia/include/ports/SkFontMgr_directory.h" #include "utils.h" namespace txt { @@ -32,18 +34,33 @@ static void BM_FAKE_BENCHMARK(benchmark::State& state) { } BENCHMARK(BM_FAKE_BENCHMARK); +static void BM_FontCollectionCustomInit(benchmark::State& state) { + while (state.KeepRunning()) { + benchmark::DoNotOptimize( + FontCollection::GetFontCollection(txt::GetFontDir())); + } +} +BENCHMARK(BM_FontCollectionCustomInit); + static void BM_FontCollectionInit(benchmark::State& state) { while (state.KeepRunning()) { - FontCollection::GetFontCollection(txt::GetFontDir()); + benchmark::DoNotOptimize(FontCollection::GetFontCollection()); } } BENCHMARK(BM_FontCollectionInit); +static void BM_FontCollectionSkFontMgr(benchmark::State& state) { + while (state.KeepRunning()) { + auto mgr = SkFontMgr_New_Custom_Directory(txt::GetFontDir().c_str()); + } +} +BENCHMARK(BM_FontCollectionSkFontMgr); + static void BM_FontCollectionGetMinikinFontCollectionForFamily( benchmark::State& state) { + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - FontCollection::GetFontCollection(txt::GetFontDir()) - .GetMinikinFontCollectionForFamily("Roboto"); + font_collection.GetMinikinFontCollectionForFamily("Roboto"); } } BENCHMARK(BM_FontCollectionGetMinikinFontCollectionForFamily); diff --git a/engine/src/flutter/benchmarks/paint_record_benchmarks.cc b/engine/src/flutter/benchmarks/paint_record_benchmarks.cc new file mode 100644 index 00000000000..f5f7143d726 --- /dev/null +++ b/engine/src/flutter/benchmarks/paint_record_benchmarks.cc @@ -0,0 +1,46 @@ +/* + * Copyright 2017 Google, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "third_party/benchmark/include/benchmark/benchmark_api.h" + +#include "lib/ftl/command_line.h" +#include "lib/ftl/logging.h" +#include "lib/txt/src/paint_record.h" +#include "lib/txt/src/text_style.h" +#include "utils.h" + +namespace txt { + +static void BM_PaintRecordInit(benchmark::State& state) { + TextStyle style; + + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); + paint.setTextSize(14); + paint.setFakeBoldText(false); + + SkTextBlobBuilder builder; + builder.allocRunPos(paint, 100); + auto text_blob = builder.make(); + + while (state.KeepRunning()) { + PaintRecord PaintRecord(style, text_blob, SkPaint::FontMetrics(), 0); + } +} +BENCHMARK(BM_PaintRecordInit); + +} // namespace txt diff --git a/engine/src/flutter/benchmarks/paragraph_benchmarks.cc b/engine/src/flutter/benchmarks/paragraph_benchmarks.cc index 7a694f6eb51..455b75e047e 100644 --- a/engine/src/flutter/benchmarks/paragraph_benchmarks.cc +++ b/engine/src/flutter/benchmarks/paragraph_benchmarks.cc @@ -43,15 +43,16 @@ static void BM_ParagraphShortLayout(benchmark::State& state) { txt::TextStyle text_style; text_style.color = SK_ColorBLACK; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.PushStyle(text_style); builder.AddText(u16_text); builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(300, txt::GetFontDir(), true); + paragraph->Layout(300, true); } } BENCHMARK(BM_ParagraphShortLayout); @@ -83,15 +84,16 @@ static void BM_ParagraphLongLayout(benchmark::State& state) { txt::TextStyle text_style; text_style.color = SK_ColorBLACK; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.PushStyle(text_style); builder.AddText(u16_text); builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(300, txt::GetFontDir(), true); + paragraph->Layout(300, true); } } BENCHMARK(BM_ParagraphLongLayout); @@ -106,14 +108,15 @@ static void BM_ParagraphManyStylesLayout(benchmark::State& state) { txt::TextStyle text_style; text_style.color = SK_ColorBLACK; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); - for (int i = 0; i < 100; ++i) { + txt::ParagraphBuilder builder(paragraph_style, &font_collection); + for (int i = 0; i < 1000; ++i) { builder.PushStyle(text_style); builder.AddText(u16_text); } auto paragraph = builder.Build(); - paragraph->Layout(300, txt::GetFontDir(), true); + paragraph->Layout(300, true); } } BENCHMARK(BM_ParagraphManyStylesLayout); @@ -128,15 +131,16 @@ static void BM_ParagraphTextBigO(benchmark::State& state) { txt::TextStyle text_style; text_style.color = SK_ColorBLACK; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.PushStyle(text_style); builder.AddText(u16_text); builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(300, txt::GetFontDir(), true); + paragraph->Layout(300, true); } state.SetComplexityN(state.range(0)); } @@ -155,15 +159,16 @@ static void BM_ParagraphStylesBigO(benchmark::State& state) { txt::TextStyle text_style; text_style.color = SK_ColorBLACK; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); for (int i = 0; i < state.range(0); ++i) { builder.PushStyle(text_style); builder.AddText(u16_text); } auto paragraph = builder.Build(); - paragraph->Layout(300, txt::GetFontDir(), true); + paragraph->Layout(300, true); } state.SetComplexityN(state.range(0)); } diff --git a/engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc b/engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc index e91ba4416d4..c589dfd9aef 100644 --- a/engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc +++ b/engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc @@ -17,6 +17,7 @@ #include "third_party/benchmark/include/benchmark/benchmark_api.h" #include "lib/ftl/logging.h" +#include "lib/txt/src/font_collection.h" #include "lib/txt/src/font_style.h" #include "lib/txt/src/font_weight.h" #include "lib/txt/src/paragraph.h" @@ -24,6 +25,7 @@ #include "lib/txt/src/text_align.h" #include "third_party/icu/source/common/unicode/unistr.h" #include "third_party/skia/include/core/SkColor.h" +#include "utils.h" namespace txt { @@ -40,8 +42,9 @@ static void BM_ParagraphBuilderPushStyle(benchmark::State& state) { txt::TextStyle text_style; text_style.color = SK_ColorBLACK; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.PushStyle(text_style); } } @@ -76,9 +79,9 @@ static void BM_ParagraphBuilderAddTextChar(benchmark::State& state) { const char* text = "Hello World"; txt::ParagraphStyle paragraph_style; - + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.AddText(text); } } @@ -91,9 +94,9 @@ static void BM_ParagraphBuilderAddTextU16stringShort(benchmark::State& state) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.AddText(u16_text); } } @@ -142,9 +145,9 @@ static void BM_ParagraphBuilderShortParagraphConstruct( txt::TextStyle text_style; text_style.color = SK_ColorBLACK; - + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.PushStyle(text_style); builder.AddText(u16_text); builder.Pop(); @@ -180,9 +183,9 @@ static void BM_ParagraphBuilderLongParagraphConstruct(benchmark::State& state) { txt::TextStyle text_style; text_style.color = SK_ColorBLACK; - + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.PushStyle(text_style); builder.AddText(u16_text); builder.Pop(); diff --git a/engine/src/flutter/src/font_collection.cc b/engine/src/flutter/src/font_collection.cc index 29837694949..009382d3f25 100644 --- a/engine/src/flutter/src/font_collection.cc +++ b/engine/src/flutter/src/font_collection.cc @@ -28,11 +28,13 @@ namespace txt { +// Will be deprecated when full compatibility with Flutter Engine is complete. FontCollection& FontCollection::GetFontCollection(std::string dir) { std::vector dirs = {dir}; return GetFontCollection(std::move(dirs)); } +// Will be deprecated when full compatibility with Flutter Engine is complete. FontCollection& FontCollection::GetFontCollection( std::vector dirs) { static FontCollection* collection = nullptr; @@ -41,10 +43,20 @@ FontCollection& FontCollection::GetFontCollection( return *collection; } +// Will be deprecated when full compatibility with Flutter Engine is complete. FontCollection& FontCollection::GetDefaultFontCollection() { return GetFontCollection(""); } +FontCollection::FontCollection() { + FontCollection(""); +} + +FontCollection::FontCollection(std::string dir) { + std::vector dirs = {dir}; + FontCollection(std::move(dirs)); +} + FontCollection::FontCollection(const std::vector& dirs) { #ifdef DIRECTORY_FONT_MANAGER_AVAILABLE for (std::string dir : dirs) { diff --git a/engine/src/flutter/src/font_collection.h b/engine/src/flutter/src/font_collection.h index b8a0c8a6de2..0a05bda86d2 100644 --- a/engine/src/flutter/src/font_collection.h +++ b/engine/src/flutter/src/font_collection.h @@ -35,15 +35,26 @@ namespace txt { class FontCollection { public: + // Will be deprecated when full compatibility with Flutter Engine is complete. static FontCollection& GetDefaultFontCollection(); + // Will be deprecated when full compatibility with Flutter Engine is complete. static FontCollection& GetFontCollection(std::string dir = ""); + // Will be deprecated when full compatibility with Flutter Engine is complete. static FontCollection& GetFontCollection(std::vector dirs); std::shared_ptr GetMinikinFontCollectionForFamily( const std::string& family); + FontCollection(const std::vector& dirs); + + FontCollection(std::string dir); + + FontCollection(); + + ~FontCollection(); + // Provides a set of all available family names. std::set GetFamilyNames(); @@ -62,12 +73,7 @@ class FontCollection { return DEFAULT_FAMILY_NAME; }; - FontCollection(const std::vector& dirs); - - ~FontCollection(); - // TODO(chinmaygarde): Caches go here. - FTL_DISALLOW_COPY_AND_ASSIGN(FontCollection); }; } // namespace txt diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index fbdc53c6a99..c6ee6be9794 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -125,24 +125,25 @@ void Paragraph::SetText(std::vector text, StyledRuns runs) { breaker_.setText(); } -void Paragraph::AddRunsToLineBreaker(const std::string& rootdir) { +void Paragraph::AddRunsToLineBreaker( + std::shared_ptr& collection, + std::string& prev_font_family) { minikin::FontStyle font; minikin::MinikinPaint paint; for (size_t i = 0; i < runs_.size(); ++i) { auto run = runs_.GetRun(i); - 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 = font_collection_->GetMinikinFontCollectionForFamily( + run.style.font_family); + } + prev_font_family = run.style.font_family; GetFontAndMinikinPaint(run.style, &font, &paint); breaker_.addStyleRun(&paint, collection, font, run.start, run.end, false); } } -void Paragraph::Layout(double width, - const std::string& rootdir, - bool force, - const double x_offset, - const double y_offset) { +void Paragraph::Layout(double width, bool force) { // Do not allow calling layout multiple times without changing anything. if (!needs_layout_ && !force) return; @@ -150,8 +151,11 @@ void Paragraph::Layout(double width, width_ = width; + std::shared_ptr collection = nullptr; + std::string prev_font_family = ""; + breaker_.setLineWidths(0.0f, 0, width_); - AddRunsToLineBreaker(rootdir); + AddRunsToLineBreaker(collection, prev_font_family); breaker_.setJustified(paragraph_style_.text_align == TextAlign::justify); size_t breaks_count = breaker_.computeBreaks(); const int* breaks = breaker_.getBreaks(); @@ -170,8 +174,8 @@ void Paragraph::Layout(double width, max_intrinsic_width_ = 0.0f; lines_ = 0; - SkScalar x = x_offset; - SkScalar y = y_offset; + SkScalar x = 0.0f; + SkScalar y = 0.0f; size_t break_index = 0; double letter_spacing_offset = 0.0f; double max_line_spacing = 0.0f; @@ -214,16 +218,13 @@ 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); // 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); + collection = font_collection_->GetMinikinFontCollectionForFamily( + run.style.font_family); } prev_font_family = run.style.font_family; GetFontAndMinikinPaint(run.style, &font, &minikin_paint); @@ -434,6 +435,10 @@ void Paragraph::SetParagraphStyle(const ParagraphStyle& style) { paragraph_style_ = style; } +void Paragraph::SetFontCollection(FontCollection* font_collection) { + font_collection_ = font_collection; +} + void Paragraph::Paint(SkCanvas* canvas, double x, double y) { for (const auto& record : records_) { SkPaint paint; diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index b4b90a4ee91..64739c8b95f 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -21,6 +21,7 @@ #include #include "lib/ftl/macros.h" +#include "lib/txt/src/font_collection.h" #include "lib/txt/src/paint_record.h" #include "lib/txt/src/paragraph_style.h" #include "lib/txt/src/styled_runs.h" @@ -38,11 +39,7 @@ class Paragraph { ~Paragraph(); - void Layout(double width, - const std::string& rootdir = "", - bool force = false, - const double x_offset = 0.0, - const double y_offset = 0.0); + void Layout(double width, bool force = false); void Paint(SkCanvas* canvas, double x, double y); @@ -81,6 +78,7 @@ class Paragraph { std::vector records_; std::vector line_widths_; ParagraphStyle paragraph_style_; + FontCollection* font_collection_; // TODO(garyq): Height of the paragraph after Layout(). SkScalar height_ = 0.0f; double width_ = 0.0f; @@ -95,7 +93,11 @@ class Paragraph { void SetParagraphStyle(const ParagraphStyle& style); - void AddRunsToLineBreaker(const std::string& rootdir = ""); + void SetFontCollection(FontCollection* font_collection); + + void AddRunsToLineBreaker( + std::shared_ptr& collection, + std::string& prev_font_family); void JustifyLine(std::vector& buffers, std::vector& buffer_sizes, diff --git a/engine/src/flutter/src/paragraph_builder.cc b/engine/src/flutter/src/paragraph_builder.cc index 3d980eae3a3..d3076774585 100644 --- a/engine/src/flutter/src/paragraph_builder.cc +++ b/engine/src/flutter/src/paragraph_builder.cc @@ -21,6 +21,10 @@ namespace txt { +ParagraphBuilder::ParagraphBuilder(ParagraphStyle style, + FontCollection* font_collection) + : paragraph_style_(style), font_collection_(font_collection) {} + ParagraphBuilder::ParagraphBuilder(ParagraphStyle style) : paragraph_style_(style) {} @@ -30,6 +34,10 @@ void ParagraphBuilder::SetParagraphStyle(const ParagraphStyle& style) { paragraph_style_ = style; } +void ParagraphBuilder::SetFontCollection(FontCollection* font_collection) { + font_collection_ = font_collection; +} + ParagraphBuilder::~ParagraphBuilder() = default; void ParagraphBuilder::PushStyle(const TextStyle& style) { @@ -71,10 +79,19 @@ void ParagraphBuilder::AddText(const char* text) { } std::unique_ptr ParagraphBuilder::Build() { + if (font_collection_ == nullptr) { + // Will be deprecated when full compatibility with Flutter Engine is + // complete. + FTL_LOG(WARNING) << "No font collection provided. Falling back to default " + "fonts."; + font_collection_ = &FontCollection::GetFontCollection(""); + } + runs_.EndRunIfNeeded(text_.size()); std::unique_ptr paragraph = std::make_unique(); paragraph->SetText(std::move(text_), std::move(runs_)); paragraph->SetParagraphStyle(paragraph_style_); + paragraph->SetFontCollection(font_collection_); return paragraph; } diff --git a/engine/src/flutter/src/paragraph_builder.h b/engine/src/flutter/src/paragraph_builder.h index 5df84ca72aa..07d92e69d62 100644 --- a/engine/src/flutter/src/paragraph_builder.h +++ b/engine/src/flutter/src/paragraph_builder.h @@ -21,6 +21,7 @@ #include #include "lib/ftl/macros.h" +#include "lib/txt/src/font_collection.h" #include "lib/txt/src/paragraph.h" #include "lib/txt/src/paragraph_style.h" #include "lib/txt/src/styled_runs.h" @@ -32,6 +33,8 @@ class ParagraphBuilder { public: explicit ParagraphBuilder(ParagraphStyle style); + ParagraphBuilder(ParagraphStyle style, FontCollection* font_collection); + ParagraphBuilder(); ~ParagraphBuilder(); @@ -48,6 +51,8 @@ class ParagraphBuilder { void SetParagraphStyle(const ParagraphStyle& style); + void SetFontCollection(FontCollection* font_collection); + std::unique_ptr Build(); private: @@ -55,6 +60,7 @@ class ParagraphBuilder { std::vector style_stack_; StyledRuns runs_; ParagraphStyle paragraph_style_; + FontCollection* font_collection_ = nullptr; FTL_DISALLOW_COPY_AND_ASSIGN(ParagraphBuilder); }; diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index d93ea32e3ed..187ccfa3029 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -34,7 +34,8 @@ TEST_F(RenderTest, SimpleParagraph) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.color = SK_ColorBLACK; @@ -44,7 +45,7 @@ TEST_F(RenderTest, SimpleParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth()); paragraph->Paint(GetCanvas(), 10.0, 15.0); @@ -66,7 +67,8 @@ TEST_F(RenderTest, SimpleRedParagraph) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.color = SK_ColorRED; @@ -77,7 +79,7 @@ TEST_F(RenderTest, SimpleRedParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth()); paragraph->Paint(GetCanvas(), 10.0, 15.0); @@ -119,7 +121,8 @@ TEST_F(RenderTest, RainbowParagraph) { txt::ParagraphStyle paragraph_style; paragraph_style.max_lines = 2; paragraph_style.text_align = TextAlign::left; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style1; text_style1.color = SK_ColorRED; @@ -162,7 +165,7 @@ TEST_F(RenderTest, RainbowParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth()); paragraph->Paint(GetCanvas(), 10.0, 50.0); @@ -191,7 +194,8 @@ TEST_F(RenderTest, DefaultStyleParagraph) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.color = SK_ColorRED; @@ -201,7 +205,7 @@ TEST_F(RenderTest, DefaultStyleParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth()); paragraph->Paint(GetCanvas(), 10.0, 15.0); @@ -221,7 +225,8 @@ TEST_F(RenderTest, BoldParagraph) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.font_size = 60; @@ -236,7 +241,7 @@ TEST_F(RenderTest, BoldParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth()); paragraph->Paint(GetCanvas(), 10.0, 60.0); @@ -277,7 +282,8 @@ TEST_F(RenderTest, LeftAlignParagraph) { txt::ParagraphStyle paragraph_style; paragraph_style.max_lines = 14; paragraph_style.text_align = TextAlign::left; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.font_size = 26; @@ -294,7 +300,7 @@ TEST_F(RenderTest, LeftAlignParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth() - 100, txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth() - 100); paragraph->Paint(GetCanvas(), 0, 0); ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); @@ -363,7 +369,8 @@ TEST_F(RenderTest, RightAlignParagraph) { txt::ParagraphStyle paragraph_style; paragraph_style.max_lines = 14; paragraph_style.text_align = TextAlign::right; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.font_size = 26; @@ -380,7 +387,7 @@ TEST_F(RenderTest, RightAlignParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth() - 100, txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth() - 100); paragraph->Paint(GetCanvas(), 0, 0); ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); @@ -464,7 +471,8 @@ TEST_F(RenderTest, CenterAlignParagraph) { txt::ParagraphStyle paragraph_style; paragraph_style.max_lines = 14; paragraph_style.text_align = TextAlign::center; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.font_size = 26; @@ -481,7 +489,7 @@ TEST_F(RenderTest, CenterAlignParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth() - 100, txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth() - 100); paragraph->Paint(GetCanvas(), 0, 0); ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); @@ -569,7 +577,8 @@ TEST_F(RenderTest, JustifyAlignParagraph) { txt::ParagraphStyle paragraph_style; paragraph_style.max_lines = 14; paragraph_style.text_align = TextAlign::justify; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.font_size = 26; @@ -586,7 +595,7 @@ TEST_F(RenderTest, JustifyAlignParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth() - 100, txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth() - 100); paragraph->Paint(GetCanvas(), 0, 0); ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); @@ -636,7 +645,8 @@ TEST_F(RenderTest, ItalicsParagraph) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.color = SK_ColorRED; @@ -649,7 +659,7 @@ TEST_F(RenderTest, ItalicsParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth()); paragraph->Paint(GetCanvas(), 10.0, 35.0); diff --git a/engine/src/flutter/tests/txt/utils.cc b/engine/src/flutter/tests/txt/utils.cc index 6ec90c2a5cd..0bee521a3fd 100644 --- a/engine/src/flutter/tests/txt/utils.cc +++ b/engine/src/flutter/tests/txt/utils.cc @@ -40,4 +40,4 @@ void SetCommandLine(ftl::CommandLine cmd) { gCommandLine = std::move(cmd); } -} // namespace txt +} // namespace txt \ No newline at end of file