1 #include "SkBenchmark.h"
3 #include "SkFontHost.h"
6 #include "SkSfntUtils.h"
8 #include "SkTemplates.h"
10 /* Some considerations for performance:
11 short -vs- long strings (measuring overhead)
12 tiny -vs- large pointsize (measure blit -vs- overhead)
13 1 -vs- many point sizes (measure cache lookup)
14 normal -vs- subpixel -vs- lineartext (minor)
15 force purge after each draw to measure scaler
17 text -vs- postext - pathtext
19 class TextBench : public SkBenchmark {
27 TextBench(void* param, const char text[], int ps, bool linearText,
28 bool posText) : INHERITED(param) {
31 fPaint.setAntiAlias(true);
32 fPaint.setTextSize(SkIntToScalar(ps));
33 fPaint.setLinearText(linearText);
36 SkAutoTArray<SkScalar> storage(fText.size());
37 SkScalar* widths = storage.get();
38 fCount = fPaint.getTextWidths(fText.c_str(), fText.size(), widths);
39 fPos = new SkPoint[fCount];
41 for (int i = 0; i < fCount; i++) {
51 virtual ~TextBench() {
56 virtual const char* onGetName() {
57 fName.printf("text_%g", SkScalarToFloat(fPaint.getTextSize()));
58 if (fPaint.isLinearText()) {
59 fName.append("_linear");
67 virtual void onDraw(SkCanvas* canvas) {
68 const SkIPoint dim = this->getSize();
71 SkPaint paint(fPaint);
72 this->setupPaint(&paint);
74 const SkScalar x0 = SkIntToScalar(-10);
75 const SkScalar y0 = SkIntToScalar(-10);
76 const SkColor colors[] = { SK_ColorBLACK, SK_ColorGRAY };
78 for (size_t j = 0; j < SK_ARRAY_COUNT(colors); j++) {
79 paint.setColor(colors[j]);
80 for (int i = 0; i < N; i++) {
81 SkScalar x = x0 + rand.nextUScalar1() * dim.fX;
82 SkScalar y = y0 + rand.nextUScalar1() * dim.fY;
84 canvas->save(SkCanvas::kMatrix_SaveFlag);
85 canvas->translate(x, y);
86 canvas->drawPosText(fText.c_str(), fText.size(), fPos, paint);
89 canvas->drawText(fText.c_str(), fText.size(), x, y, paint);
96 typedef SkBenchmark INHERITED;
99 ///////////////////////////////////////////////////////////////////////////////
101 #define STR "Hamburgefons"
105 static SkBenchmark* Fact0(void* p) { return new TextBench(p, STR, SMALL, false, false); }
106 static SkBenchmark* Fact1(void* p) { return new TextBench(p, STR, SMALL, false, true); }
107 static SkBenchmark* Fact2(void* p) { return new TextBench(p, STR, SMALL, true, false); }
108 static SkBenchmark* Fact3(void* p) { return new TextBench(p, STR, SMALL, true, true); }
109 static SkBenchmark* Fact4(void* p) { return new TextBench(p, STR, BIG, false, false); }
110 static SkBenchmark* Fact5(void* p) { return new TextBench(p, STR, BIG, false, true); }
111 static SkBenchmark* Fact6(void* p) { return new TextBench(p, STR, BIG, true, false); }
112 static SkBenchmark* Fact7(void* p) { return new TextBench(p, STR, BIG, true, true); }
114 static BenchRegistry gReg0(Fact0);
115 static BenchRegistry gReg1(Fact1);
116 static BenchRegistry gReg2(Fact2);
117 static BenchRegistry gReg3(Fact3);
118 static BenchRegistry gReg4(Fact4);
119 static BenchRegistry gReg5(Fact5);
120 static BenchRegistry gReg6(Fact6);
121 static BenchRegistry gReg7(Fact7);