forked from firka/flutter
Remove rounding x values option as a workaround since jitter has been fixed. Paint benchmarks.
Change-Id: Ib74977f94768c096380a1cb9d6ec7d852fb52e4f
This commit is contained in:
@@ -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<SkBitmap> bitmap = std::make_unique<SkBitmap>();
|
||||
std::unique_ptr<SkCanvas> canvas = std::make_unique<SkCanvas>(*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<SkBitmap> bitmap = std::make_unique<SkBitmap>();
|
||||
std::unique_ptr<SkCanvas> canvas = std::make_unique<SkCanvas>(*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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user