Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
bench
ParagraphBench.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2012 Google Inc.
3
*
4
* Use of this source code is governed by a BSD-style license that can be
5
* found in the LICENSE file.
6
*/
7
8
#include "
bench/Benchmark.h
"
9
#include "
include/core/SkCanvas.h
"
10
#include "
include/core/SkData.h
"
11
#include "
include/core/SkFontMgr.h
"
12
#include "
include/core/SkPaint.h
"
13
#include "
include/core/SkString.h
"
14
#include "
tools/Resources.h
"
15
#include "
tools/fonts/FontToolUtils.h
"
16
17
#if defined(SK_ENABLE_PARAGRAPH)
18
19
#include "
modules/skparagraph/include/FontCollection.h
"
20
#include "
modules/skparagraph/include/ParagraphBuilder.h
"
21
#include "
modules/skparagraph/include/ParagraphStyle.h
"
22
23
class
ParagraphBench final :
public
Benchmark
{
24
SkString
fName
;
25
sk_sp<skia::textlayout::FontCollection>
fFontCollection;
26
skia::textlayout::TextStyle
fTStyle;
27
std::unique_ptr<skia::textlayout::Paragraph> fParagraph;
28
29
public
:
30
ParagraphBench() {
31
fName
.printf(
"skparagraph"
);
32
}
33
34
protected
:
35
const
char
*
onGetName
()
override
{
36
return
fName
.c_str();
37
}
38
39
bool
isSuitableFor
(Backend backend)
override
{
40
// fParagraph might have failed to be created in onDelayedSetup()
41
return
backend
== Backend::kNonRendering && !!fParagraph;
42
}
43
44
void
onDelayedSetup
()
override
{
45
fFontCollection = sk_make_sp<skia::textlayout::FontCollection>();
46
fFontCollection->setDefaultFontManager(
ToolUtils::TestFontMgr
());
47
48
fTStyle.
setFontFamilies
({
SkString
(
"Roboto"
)});
49
fTStyle.
setColor
(
SK_ColorBLACK
);
50
51
const
char
*
text
=
52
"This is a very long sentence to test if the text will properly wrap "
53
"around and go to the next line. Sometimes, short sentence. Longer "
54
"sentences are okay too because they are necessary. Very short. "
55
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
56
"tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
57
"veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
58
"commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
59
"velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
60
"occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
61
"mollit anim id est laborum. "
62
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
63
"tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
64
"veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
65
"commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
66
"velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
67
"occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
68
"mollit anim id est laborum."
;
69
skia::textlayout::ParagraphStyle
paragraph_style;
70
auto
builder
=
71
skia::textlayout::ParagraphBuilder::make
(paragraph_style, fFontCollection);
72
if
(!builder) {
73
return
;
74
}
75
76
builder
->pushStyle(fTStyle);
77
builder
->addText(
text
);
78
builder
->pop();
79
fParagraph =
builder
->Build();
80
81
// Call onDraw once to warm up the glyph cache otherwise nanobench will mis-calculate the
82
// loop count.
83
SkCanvas
canvas;
84
this->
onDraw
(1, &canvas);
85
}
86
87
void
onDraw
(
int
loops,
SkCanvas
* canvas)
override
{
88
for
(
int
i = 0; i < loops; ++i) {
89
fParagraph->markDirty();
90
fParagraph->layout(300);
91
}
92
}
93
94
private
:
95
using
INHERITED
=
Benchmark
;
96
};
97
98
DEF_BENCH
(
return
new
ParagraphBench; )
99
100
#endif
// SK_ENABLE_PARAGRAPH
Benchmark.h
DEF_BENCH
#define DEF_BENCH(code)
Definition
Benchmark.h:20
backend
const char * backend
Definition
CommonFlagsConfig.cpp:42
fName
const char * fName
Definition
FontCacheBench.cpp:71
FontCollection.h
FontToolUtils.h
ParagraphBuilder.h
ParagraphStyle.h
Resources.h
SkCanvas.h
SK_ColorBLACK
constexpr SkColor SK_ColorBLACK
Definition
SkColor.h:103
SkData.h
SkFontMgr.h
SkPaint.h
INHERITED
#define INHERITED(method,...)
Definition
SkRecorder.cpp:128
SkString.h
Benchmark
Definition
Benchmark.h:36
Benchmark::onDraw
virtual void onDraw(int loops, SkCanvas *)=0
Benchmark::isSuitableFor
virtual bool isSuitableFor(Backend backend)
Definition
Benchmark.h:55
Benchmark::onDelayedSetup
virtual void onDelayedSetup()
Definition
Benchmark.h:101
Benchmark::onGetName
virtual const char * onGetName()=0
Benchmark::Benchmark
Benchmark()
Definition
Benchmark.cpp:16
SkCanvas
Definition
SkCanvas.h:106
SkString
Definition
SkString.h:118
sk_sp
Definition
SkRefCnt.h:220
skia::textlayout::ParagraphBuilder::make
static std::unique_ptr< ParagraphBuilder > make(const ParagraphStyle &style, sk_sp< FontCollection > fontCollection, sk_sp< SkUnicode > unicode)
Definition
ParagraphBuilderImpl.cpp:82
skia::textlayout::TextStyle
Definition
TextStyle.h:151
skia::textlayout::TextStyle::setFontFamilies
void setFontFamilies(std::vector< SkString > families)
Definition
TextStyle.h:253
skia::textlayout::TextStyle::setColor
void setColor(SkColor color)
Definition
TextStyle.h:166
text
std::u16string text
Definition
keyboard_unittests.cc:332
ToolUtils::TestFontMgr
sk_sp< SkFontMgr > TestFontMgr()
Definition
FontToolUtils.cpp:247
dependency.builder
builder
Definition
dependency.py:1
skia::textlayout::ParagraphStyle
Definition
ParagraphStyle.h:78
Generated on Fri Apr 26 2024 06:15:25 for Flutter Engine by
1.9.8