Debian Codegraph @

modules/skparagraph/bench/ParagraphBench.cpp

raw
1 // Copyright 2019 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3
4 #include "bench/Benchmark.h"
5
6 #if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_GOOGLE3)
7
8 #include "modules/skparagraph/include/FontCollection.h"
9 #include "modules/skparagraph/include/Paragraph.h"
10 #include "modules/skparagraph/src/ParagraphBuilderImpl.h"
11 #include "modules/skparagraph/src/ParagraphImpl.h"
12 #include "tools/Resources.h"
13 #include "tools/fonts/FontToolUtils.h"
14
15 #include <cfloat>
16 #include "include/core/SkPictureRecorder.h"
17 #include "modules/skparagraph/utils/TestFontCollection.h"
18
19 using namespace skia::textlayout;
20 namespace {
21 struct ParagraphBench : public Benchmark {
22 ParagraphBench(SkScalar width, const char* r, const char* n)
23 : fResource(r), fName(n), fWidth(width) {}
24 sk_sp<SkData> fData;
25 const char* fResource;
26 const char* fName;
27 SkScalar fWidth;
28 const char* onGetName() override { return fName; }
29 bool isSuitableFor(Backend backend) override { return backend == Backend::kNonRendering; }
30 void onDelayedSetup() override { fData = GetResourceAsData(fResource); }
31 void onDraw(int loops, SkCanvas*) override {
32 if (!fData) {
33 return;
34 }
35
36 const char* text = (const char*)fData->data();
37
38 auto fontCollection = sk_make_sp<FontCollection>();
39 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
40 ParagraphStyle paragraph_style;
41 paragraph_style.turnHintingOff();
42 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
43 builder.addText(text);
44 auto paragraph = builder.Build();
45
46 SkPictureRecorder rec;
47 SkCanvas* canvas = rec.beginRecording({0,0, 2000,3000});
48 while (loops-- > 0) {
49 paragraph->layout(fWidth);
50 auto impl = static_cast<ParagraphImpl*>(paragraph.get());
51 paragraph->paint(canvas, 0, 0);
52 paragraph->markDirty();
53 impl->resetCache();
54 }
55 }
56 };
57 } // namespace
58
59 #define PARAGRAPH_BENCH(X) DEF_BENCH(return new ParagraphBench(50000, "text/" #X ".txt", "paragraph_" #X);)
60 //PARAGRAPH_BENCH(arabic)
61 //PARAGRAPH_BENCH(emoji)
62 PARAGRAPH_BENCH(english)
63 #undef PARAGRAPH_BENCH
64
65 #endif // !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_GOOGLE3)