OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
| 8 |
8 #include "Benchmark.h" | 9 #include "Benchmark.h" |
| 10 #include "Resources.h" |
9 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 12 #include "SkPaint.h" |
11 #include "SkRandom.h" | 13 #include "SkRandom.h" |
| 14 #include "SkStream.h" |
12 #include "SkString.h" | 15 #include "SkString.h" |
13 #include "SkTemplates.h" | 16 #include "SkTemplates.h" |
| 17 #include "SkTypeface.h" |
14 | 18 |
15 enum FontQuality { | 19 enum FontQuality { |
16 kBW, | 20 kBW, |
17 kAA, | 21 kAA, |
18 kLCD | 22 kLCD, |
19 }; | 23 }; |
20 | 24 |
21 static const char* fontQualityName(const SkPaint& paint) { | 25 static const char* fontQualityName(const SkPaint& paint) { |
22 if (!paint.isAntiAlias()) { | 26 if (!paint.isAntiAlias()) { |
23 return "BW"; | 27 return "BW"; |
24 } | 28 } |
25 if (paint.isLCDRenderText()) { | 29 if (paint.isLCDRenderText()) { |
26 return "LCD"; | 30 return "LCD"; |
27 } | 31 } |
28 return "AA"; | 32 return "AA"; |
29 } | 33 } |
30 | 34 |
31 /* Some considerations for performance: | 35 /* Some considerations for performance: |
32 short -vs- long strings (measuring overhead) | 36 short -vs- long strings (measuring overhead) |
33 tiny -vs- large pointsize (measure blit -vs- overhead) | 37 tiny -vs- large pointsize (measure blit -vs- overhead) |
34 1 -vs- many point sizes (measure cache lookup) | 38 1 -vs- many point sizes (measure cache lookup) |
35 normal -vs- subpixel -vs- lineartext (minor) | 39 normal -vs- subpixel -vs- lineartext (minor) |
36 force purge after each draw to measure scaler | 40 force purge after each draw to measure scaler |
37 textencoding? | 41 textencoding? |
38 text -vs- postext - pathtext | 42 text -vs- postext - pathtext |
39 */ | 43 */ |
40 class TextBench : public Benchmark { | 44 class TextBench : public Benchmark { |
41 SkPaint fPaint; | 45 SkPaint fPaint; |
42 SkString fText; | 46 SkString fText; |
43 SkString fName; | 47 SkString fName; |
44 FontQuality fFQ; | 48 FontQuality fFQ; |
45 bool fDoPos; | 49 bool fDoPos; |
| 50 bool fDoColorEmoji; |
| 51 SkAutoTUnref<SkTypeface> fColorEmojiTypeface; |
46 SkPoint* fPos; | 52 SkPoint* fPos; |
47 public: | 53 public: |
48 TextBench(const char text[], int ps, | 54 TextBench(const char text[], int ps, |
49 SkColor color, FontQuality fq, bool doPos = false) { | 55 SkColor color, FontQuality fq, bool doColorEmoji = false, bool doP
os = false) { |
50 fPos = NULL; | 56 fPos = NULL; |
51 fFQ = fq; | 57 fFQ = fq; |
52 fDoPos = doPos; | 58 fDoPos = doPos; |
| 59 fDoColorEmoji = doColorEmoji; |
53 fText.set(text); | 60 fText.set(text); |
54 | 61 |
55 fPaint.setAntiAlias(kBW != fq); | 62 fPaint.setAntiAlias(kBW != fq); |
56 fPaint.setLCDRenderText(kLCD == fq); | 63 fPaint.setLCDRenderText(kLCD == fq); |
57 fPaint.setTextSize(SkIntToScalar(ps)); | 64 fPaint.setTextSize(SkIntToScalar(ps)); |
58 fPaint.setColor(color); | 65 fPaint.setColor(color); |
59 | 66 |
| 67 if (doColorEmoji) { |
| 68 SkASSERT(kBW == fFQ); |
| 69 SkString filename = GetResourcePath("/Funkster.ttf"); |
| 70 SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(filename.c_str()
)); |
| 71 if (stream->isValid()) { |
| 72 fColorEmojiTypeface.reset(SkTypeface::CreateFromStream(stream.de
tach())); |
| 73 } else { |
| 74 SkDebugf("Could not find Funkster.ttf, please set --resourcePath
correctly.\n"); |
| 75 } |
| 76 } |
| 77 |
60 if (doPos) { | 78 if (doPos) { |
61 size_t len = strlen(text); | 79 size_t len = strlen(text); |
62 SkScalar* adv = new SkScalar[len]; | 80 SkScalar* adv = new SkScalar[len]; |
63 fPaint.getTextWidths(text, len, adv); | 81 fPaint.getTextWidths(text, len, adv); |
64 fPos = new SkPoint[len]; | 82 fPos = new SkPoint[len]; |
65 SkScalar x = 0; | 83 SkScalar x = 0; |
66 for (size_t i = 0; i < len; ++i) { | 84 for (size_t i = 0; i < len; ++i) { |
67 fPos[i].set(x, SkIntToScalar(50)); | 85 fPos[i].set(x, SkIntToScalar(50)); |
68 x += adv[i]; | 86 x += adv[i]; |
69 } | 87 } |
(...skipping 10 matching lines...) Expand all Loading... |
80 fName.printf("text_%g", SkScalarToFloat(fPaint.getTextSize())); | 98 fName.printf("text_%g", SkScalarToFloat(fPaint.getTextSize())); |
81 if (fDoPos) { | 99 if (fDoPos) { |
82 fName.append("_pos"); | 100 fName.append("_pos"); |
83 } | 101 } |
84 fName.appendf("_%s", fontQualityName(fPaint)); | 102 fName.appendf("_%s", fontQualityName(fPaint)); |
85 if (SK_ColorBLACK != fPaint.getColor()) { | 103 if (SK_ColorBLACK != fPaint.getColor()) { |
86 fName.appendf("_%02X", fPaint.getAlpha()); | 104 fName.appendf("_%02X", fPaint.getAlpha()); |
87 } else { | 105 } else { |
88 fName.append("_BK"); | 106 fName.append("_BK"); |
89 } | 107 } |
| 108 |
| 109 if (fDoColorEmoji && fColorEmojiTypeface) { |
| 110 fName.append("_ColorEmoji"); |
| 111 } |
| 112 |
90 return fName.c_str(); | 113 return fName.c_str(); |
91 } | 114 } |
92 | 115 |
93 virtual void onDraw(const int loops, SkCanvas* canvas) { | 116 virtual void onDraw(const int loops, SkCanvas* canvas) { |
94 const SkIPoint dim = this->getSize(); | 117 const SkIPoint dim = this->getSize(); |
95 SkRandom rand; | 118 SkRandom rand; |
96 | 119 |
97 SkPaint paint(fPaint); | 120 SkPaint paint(fPaint); |
98 this->setupPaint(&paint); | 121 this->setupPaint(&paint); |
99 // explicitly need these | 122 // explicitly need these |
100 paint.setColor(fPaint.getColor()); | 123 paint.setColor(fPaint.getColor()); |
101 paint.setAntiAlias(kBW != fFQ); | 124 paint.setAntiAlias(kBW != fFQ); |
102 paint.setLCDRenderText(kLCD == fFQ); | 125 paint.setLCDRenderText(kLCD == fFQ); |
103 | 126 |
| 127 if (fDoColorEmoji && fColorEmojiTypeface) { |
| 128 paint.setTypeface(fColorEmojiTypeface); |
| 129 } |
| 130 |
104 const SkScalar x0 = SkIntToScalar(-10); | 131 const SkScalar x0 = SkIntToScalar(-10); |
105 const SkScalar y0 = SkIntToScalar(-10); | 132 const SkScalar y0 = SkIntToScalar(-10); |
106 | 133 |
107 if (fDoPos) { | 134 if (fDoPos) { |
108 // realistically, the matrix is often at least translated, so we | 135 // realistically, the matrix is often at least translated, so we |
109 // do that since it exercises different code in drawPosText. | 136 // do that since it exercises different code in drawPosText. |
110 canvas->translate(SK_Scalar1, SK_Scalar1); | 137 canvas->translate(SK_Scalar1, SK_Scalar1); |
111 } | 138 } |
112 | 139 |
113 for (int i = 0; i < loops; i++) { | 140 for (int i = 0; i < loops; i++) { |
(...skipping 20 matching lines...) Expand all Loading... |
134 DEF_BENCH( return new TextBench(STR, 16, 0x88FF0000, kBW); ) | 161 DEF_BENCH( return new TextBench(STR, 16, 0x88FF0000, kBW); ) |
135 | 162 |
136 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kAA); ) | 163 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kAA); ) |
137 DEF_BENCH( return new TextBench(STR, 16, 0xFFFF0000, kAA); ) | 164 DEF_BENCH( return new TextBench(STR, 16, 0xFFFF0000, kAA); ) |
138 DEF_BENCH( return new TextBench(STR, 16, 0x88FF0000, kAA); ) | 165 DEF_BENCH( return new TextBench(STR, 16, 0x88FF0000, kAA); ) |
139 | 166 |
140 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kLCD); ) | 167 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kLCD); ) |
141 DEF_BENCH( return new TextBench(STR, 16, 0xFFFF0000, kLCD); ) | 168 DEF_BENCH( return new TextBench(STR, 16, 0xFFFF0000, kLCD); ) |
142 DEF_BENCH( return new TextBench(STR, 16, 0x88FF0000, kLCD); ) | 169 DEF_BENCH( return new TextBench(STR, 16, 0x88FF0000, kLCD); ) |
143 | 170 |
144 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kAA, true); ) | 171 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kBW, true); ) |
| 172 DEF_BENCH( return new TextBench(STR, 16, 0xFFFF0000, kBW, true); ) |
| 173 DEF_BENCH( return new TextBench(STR, 16, 0x88FF0000, kBW, true); ) |
| 174 |
| 175 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kBW, true, true); ) |
| 176 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kAA, false, true); ) |
OLD | NEW |