blob: cffbef8c3ba5708fafa00a27a619304360f9c600 [file] [log] [blame]
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001// 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
Greg Danielf91aeb22019-06-18 09:58:02 -04008#include "modules/skparagraph/include/FontCollection.h"
Julia Lavrovaa3552c52019-05-30 16:12:56 -04009#include "modules/skparagraph/include/Paragraph.h"
10#include "modules/skparagraph/src/ParagraphBuilderImpl.h"
Julia Lavrovaa3552c52019-05-30 16:12:56 -040011#include "modules/skparagraph/src/ParagraphImpl.h"
12#include "tools/Resources.h"
13
14#include <cfloat>
15
16using namespace skia::textlayout;
17namespace {
18struct ParagraphBench : public Benchmark {
19 ParagraphBench(SkScalar width, const char* r, const char* n)
20 : fResource(r), fName(n), fWidth(width) {}
21 sk_sp<SkData> fData;
22 const char* fResource;
23 const char* fName;
24 SkScalar fWidth;
25 const char* onGetName() override { return fName; }
26 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
27 void onDelayedSetup() override { fData = GetResourceAsData(fResource); }
28 void onDraw(int loops, SkCanvas*) override {
29 if (!fData) {
30 return;
31 }
32
33 const char* text = (const char*)fData->data();
34
35 sk_sp<FontCollection> fontCollection = sk_make_sp<FontCollection>();
36 ParagraphStyle paragraph_style;
37 paragraph_style.turnHintingOff();
38 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
39 builder.addText(text);
40 auto paragraph = builder.Build();
41
42 while (loops-- > 0) {
43 paragraph->layout(fWidth);
44 auto impl = static_cast<ParagraphImpl*>(paragraph.get());
45 impl->formatLines(fWidth);
46 }
47 }
48};
49} // namespace
50
51#define PARAGRAPH_BENCH(X) DEF_BENCH(return new ParagraphBench(500, "text/" #X ".txt", "paragraph_" #X);)
52//PARAGRAPH_BENCH(arabic)
53//PARAGRAPH_BENCH(emoji)
54PARAGRAPH_BENCH(english)
55#undef PARAGRAPH_BENCH
56
57#endif // !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_GOOGLE3)