19#include "flutter/fml/command_line.h"
20#include "flutter/fml/logging.h"
21#include "flutter/third_party/txt/tests/txt_test_utils.h"
22#include "third_party/benchmark/include/benchmark/benchmark.h"
23#include "third_party/icu/source/common/unicode/unistr.h"
39 bitmap_ = std::make_unique<SkBitmap>();
40 bitmap_->allocN32Pixels(1000, 1000);
52 const char*
text =
"Hello World";
58 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_);
59 builder->pushStyle(text_style);
60 builder->addText(
text);
62 auto paragraph = builder->Build();
63 while (
state.KeepRunning()) {
64 paragraph->markDirty();
65 paragraph->layout(300);
71 "This is a very long sentence to test if the text will properly wrap "
72 "around and go to the next line. Sometimes, short sentence. Longer "
73 "sentences are okay too because they are necessary. Very short. "
74 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
75 "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
76 "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
77 "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
78 "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
79 "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
80 "mollit anim id est laborum. "
81 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
82 "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
83 "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
84 "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
85 "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
86 "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
87 "mollit anim id est laborum.";
93 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_);
94 builder->pushStyle(text_style);
95 builder->addText(
text);
97 auto paragraph = builder->Build();
98 while (
state.KeepRunning()) {
99 paragraph->markDirty();
100 paragraph->layout(300);
106 "This is a very long sentence to test if the text will properly wrap "
107 "around and go to the next line. Sometimes, short sentence. Longer "
108 "sentences are okay too because they are necessary. Very short. "
109 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
110 "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
111 "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
112 "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
113 "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
114 "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
115 "mollit anim id est laborum. "
116 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
117 "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
118 "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
119 "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
120 "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
121 "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
122 "mollit anim id est laborum.";
124 paragraph_style.
setTextAlign(sktxt::TextAlign::kJustify);
129 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_);
130 builder->pushStyle(text_style);
131 builder->addText(
text);
133 auto paragraph = builder->Build();
134 while (
state.KeepRunning()) {
135 paragraph->markDirty();
136 paragraph->layout(300);
141 const char*
text =
"-";
147 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_);
148 for (
int i = 0; i < 1000; ++i) {
149 builder->pushStyle(text_style);
150 builder->addText(
text);
152 auto paragraph = builder->Build();
153 while (
state.KeepRunning()) {
154 paragraph->markDirty();
155 paragraph->layout(300);
160 std::vector<uint16_t>
text;
161 for (uint16_t i = 0; i <
state.range(0); ++i) {
162 text.push_back(i % 5 == 0 ?
' ' : i);
164 std::u16string u16_text(
text.data(),
text.data() +
text.size());
170 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_);
171 builder->pushStyle(text_style);
172 builder->addText(u16_text);
174 auto paragraph = builder->Build();
175 while (
state.KeepRunning()) {
176 paragraph->markDirty();
177 paragraph->layout(300);
183 ->Range(1 << 6, 1 << 14)
184 ->Complexity(benchmark::oN);
187 const char*
text =
"vry shrt ";
192 auto builder = sktxt::ParagraphBuilder::make(
195 for (
int i = 0; i < 1000; ++i) {
196 builder->pushStyle(text_style);
197 builder->addText(
text);
199 auto paragraph = builder->Build();
200 while (
state.KeepRunning()) {
201 paragraph->markDirty();
202 paragraph->layout(300);
208 ->Range(1 << 3, 1 << 12)
209 ->Complexity(benchmark::oN);
212 const char*
text =
"This is a simple sentence to test drawing.";
218 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_);
219 builder->pushStyle(text_style);
220 builder->addText(
text);
222 auto paragraph = builder->Build();
223 paragraph->layout(300);
225 while (
state.KeepRunning()) {
226 paragraph->paint(canvas_.get(),
offset % 700, 10);
233 "Hello world! This is a simple sentence to test drawing. Hello world! "
234 "This is a simple sentence to test drawing. Hello world! This is a "
235 "simple sentence to test drawing.Hello world! This is a simple sentence "
236 "to test drawing. Hello world! "
237 "This is a simple sentence to test drawing. Hello world! This is a "
238 "simple sentence to test drawing.Hello world! This is a simple sentence "
239 "to test drawing. Hello world! "
240 "This is a simple sentence to test drawing. Hello world! This is a "
241 "simple sentence to test drawing.Hello world! This is a simple sentence "
242 "to test drawing. Hello world! "
243 "This is a simple sentence to test drawing. Hello world! This is a "
244 "simple sentence to test drawing.Hello world! This is a simple sentence "
245 "to test drawing. Hello world! "
246 "This is a simple sentence to test drawing. Hello world! This is a "
247 "simple sentence to test drawing.Hello world! This is a simple sentence "
248 "to test drawing. Hello world! "
249 "This is a simple sentence to test drawing. Hello world! This is a "
250 "simple sentence to test drawing.";
256 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_);
257 builder->pushStyle(text_style);
258 builder->addText(
text);
260 auto paragraph = builder->Build();
261 paragraph->layout(300);
263 while (
state.KeepRunning()) {
264 paragraph->paint(canvas_.get(),
offset % 700, 10);
271 "Hello world! This is a simple sentence to test drawing. Hello world! "
272 "This is a simple sentence to test drawing.";
278 sktxt::TextDecoration::kLineThrough | sktxt::TextDecoration::kOverline |
279 sktxt::TextDecoration::kUnderline));
281 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_);
283 builder->pushStyle(text_style);
284 builder->addText(
text);
287 builder->pushStyle(text_style);
288 builder->addText(
text);
291 builder->pushStyle(text_style);
292 builder->addText(
text);
294 auto paragraph = builder->Build();
295 paragraph->layout(300);
297 while (
state.KeepRunning()) {
298 paragraph->paint(canvas_.get(),
offset % 700, 10);
304 const char*
text =
"Hello World";
309 while (
state.KeepRunning()) {
311 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_);
312 builder->pushStyle(text_style);
313 builder->addText(
text);
315 auto paragraph = builder->Build();
constexpr SkColor SK_ColorBLACK
constexpr SkColor SK_ColorWHITE
std::unique_ptr< SkCanvas > canvas_
void SetUp(const ::benchmark::State &state)
sk_sp< sktxt::TestFontCollection > font_collection_
std::unique_ptr< SkBitmap > bitmap_
void setDecorationStyle(TextDecorationStyle style)
void setFontFamilies(std::vector< SkString > families)
void setColor(SkColor color)
void setDecoration(TextDecoration decoration)
const std::string & GetFontDir()
BENCHMARK_DEFINE_F(SkParagraphFixture, TextBigO)(benchmark
BENCHMARK_F(SkParagraphFixture, ShortLayout)(benchmark
void setTextAlign(TextAlign align)