diff --git a/engine/src/flutter/benchmarks/paragraph_benchmarks.cc b/engine/src/flutter/benchmarks/paragraph_benchmarks.cc index ff8770b053..389c6e5824 100644 --- a/engine/src/flutter/benchmarks/paragraph_benchmarks.cc +++ b/engine/src/flutter/benchmarks/paragraph_benchmarks.cc @@ -254,6 +254,97 @@ static void BM_ParagraphPaintSimple(benchmark::State& state) { } BENCHMARK(BM_ParagraphPaintSimple); +static void BM_ParagraphPaintLarge(benchmark::State& state) { + const char* text = + "Hello world! This is a simple sentence to test drawing. Hello world! " + "This is a simple sentence to test drawing. Hello world! This is a " + "simple sentence to test drawing.Hello world! This is a simple sentence " + "to test drawing. Hello world! " + "This is a simple sentence to test drawing. Hello world! This is a " + "simple sentence to test drawing.Hello world! This is a simple sentence " + "to test drawing. Hello world! " + "This is a simple sentence to test drawing. Hello world! This is a " + "simple sentence to test drawing.Hello world! This is a simple sentence " + "to test drawing. Hello world! " + "This is a simple sentence to test drawing. Hello world! This is a " + "simple sentence to test drawing.Hello world! This is a simple sentence " + "to test drawing. Hello world! " + "This is a simple sentence to test drawing. Hello world! This is a " + "simple sentence to test drawing.Hello world! This is a simple sentence " + "to test drawing. Hello world! " + "This is a simple sentence to test drawing. Hello world! This is a " + "simple sentence to test drawing."; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + + txt::TextStyle text_style; + text_style.color = SK_ColorBLACK; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); + builder.PushStyle(text_style); + builder.AddText(u16_text); + auto paragraph = builder.Build(); + paragraph->Layout(300, true); + + std::unique_ptr bitmap = std::make_unique(); + std::unique_ptr canvas = std::make_unique(*bitmap); + bitmap->allocN32Pixels(1000, 1000); + canvas->clear(SK_ColorWHITE); + int offset = 0; + while (state.KeepRunning()) { + paragraph->Paint(canvas.get(), offset % 700, 10); + offset++; + } +} +BENCHMARK(BM_ParagraphPaintLarge); + +static void BM_ParagraphPaintDecoration(benchmark::State& state) { + const char* text = + "Hello world! This is a simple sentence to test drawing. Hello world! " + "This is a simple sentence to test drawing."; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + + txt::TextStyle text_style; + text_style.decoration = TextDecoration(0x1 | 0x2 | 0x4); + text_style.decoration_style = TextDecorationStyle(kSolid); + text_style.color = SK_ColorBLACK; + + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); + + builder.PushStyle(text_style); + builder.AddText(u16_text); + + text_style.decoration_style = TextDecorationStyle(kDotted); + builder.PushStyle(text_style); + builder.AddText(u16_text); + + text_style.decoration_style = TextDecorationStyle(kWavy); + builder.PushStyle(text_style); + builder.AddText(u16_text); + + auto paragraph = builder.Build(); + paragraph->Layout(300, true); + + std::unique_ptr bitmap = std::make_unique(); + std::unique_ptr canvas = std::make_unique(*bitmap); + bitmap->allocN32Pixels(1000, 1000); + canvas->clear(SK_ColorWHITE); + int offset = 0; + while (state.KeepRunning()) { + paragraph->Paint(canvas.get(), offset % 700, 10); + offset++; + } +} +BENCHMARK(BM_ParagraphPaintDecoration); + // ----------------------------------------------------------------------------- // // The following benchmarks break down the layout function and attempts to time diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 04b77f1488..9a0692ea0c 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -107,8 +107,7 @@ void GetFontAndMinikinPaint(const TextStyle& style, // Prevent spacing rounding in Minikin. This causes jitter when switching // between same text content with different runs composing it, however, it // also produces more accurate layouts. - paint->paintFlags |= - style.round_char_advances ? 0x00 : minikin::LinearTextFlag; + paint->paintFlags |= minikin::LinearTextFlag; } void GetPaint(const TextStyle& style, SkPaint* paint) { diff --git a/engine/src/flutter/src/text_style.cc b/engine/src/flutter/src/text_style.cc index 67da19a2a5..c902dcd1ac 100644 --- a/engine/src/flutter/src/text_style.cc +++ b/engine/src/flutter/src/text_style.cc @@ -44,8 +44,6 @@ bool TextStyle::equals(const TextStyle& other) const { return false; if (height != other.height) return false; - if (round_char_advances != other.round_char_advances) - return false; return true; } diff --git a/engine/src/flutter/src/text_style.h b/engine/src/flutter/src/text_style.h index bda359f028..74c112d60a 100644 --- a/engine/src/flutter/src/text_style.h +++ b/engine/src/flutter/src/text_style.h @@ -46,16 +46,6 @@ class TextStyle { double word_spacing = 0.0; double height = 1.0; - // When disabled, the x coordinates of glyphs will be rounded, eliminating - // potential mismatch between one long run and mutiple shorter runs of the - // same text. - // - // When set to false, there may be jitter when switching between same text - // content with different runs composing it, however, it also produces more - // accurate layouts. Setting to true removs this, but sacrifices layout - // accuracy. - bool round_char_advances = false; - bool equals(const TextStyle& other) const; };