Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: bench/TextBench.cpp

Issue 1144023002: Move font loading in gm tests and benches out of constructors (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | bench/TextBlobBench.cpp » ('j') | gm/typeface.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
9 #include "Benchmark.h" 9 #include "Benchmark.h"
10 #include "Resources.h" 10 #include "Resources.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 SkPaint fPaint; 45 SkPaint fPaint;
46 SkString fText; 46 SkString fText;
47 SkString fName; 47 SkString fName;
48 FontQuality fFQ; 48 FontQuality fFQ;
49 bool fDoPos; 49 bool fDoPos;
50 bool fDoColorEmoji; 50 bool fDoColorEmoji;
51 SkAutoTUnref<SkTypeface> fColorEmojiTypeface; 51 SkAutoTUnref<SkTypeface> fColorEmojiTypeface;
52 SkPoint* fPos; 52 SkPoint* fPos;
53 public: 53 public:
54 TextBench(const char text[], int ps, 54 TextBench(const char text[], int ps,
55 SkColor color, FontQuality fq, bool doColorEmoji = false, bool doP os = false) { 55 SkColor color, FontQuality fq, bool doColorEmoji = false, bool doP os = false)
56 fPos = NULL; 56 : fText(text)
57 fFQ = fq; 57 , fFQ(fq)
58 fDoPos = doPos; 58 , fDoPos(doPos)
59 fDoColorEmoji = doColorEmoji; 59 , fDoColorEmoji(doColorEmoji)
60 fText.set(text); 60 , fPos(NULL) {
61
62 fPaint.setAntiAlias(kBW != fq); 61 fPaint.setAntiAlias(kBW != fq);
63 fPaint.setLCDRenderText(kLCD == fq); 62 fPaint.setLCDRenderText(kLCD == fq);
64 fPaint.setTextSize(SkIntToScalar(ps)); 63 fPaint.setTextSize(SkIntToScalar(ps));
65 fPaint.setColor(color); 64 fPaint.setColor(color);
65 }
66 66
67 if (doColorEmoji) { 67 virtual ~TextBench() {
68 delete[] fPos;
69 }
70
71 protected:
72 void onPreDraw() override {
73 if (fDoColorEmoji) {
68 SkASSERT(kBW == fFQ); 74 SkASSERT(kBW == fFQ);
69 fColorEmojiTypeface.reset(GetResourceAsTypeface("/fonts/Funkster.ttf ")); 75 fColorEmojiTypeface.reset(GetResourceAsTypeface("/fonts/Funkster.ttf "));
70 } 76 }
71 77
72 if (doPos) { 78 if (fDoPos) {
73 size_t len = strlen(text); 79 size_t len = fText.size();
74 SkScalar* adv = new SkScalar[len]; 80 SkScalar* adv = new SkScalar[len];
75 fPaint.getTextWidths(text, len, adv); 81 fPaint.getTextWidths(fText.c_str(), len, adv);
76 fPos = new SkPoint[len]; 82 fPos = new SkPoint[len];
77 SkScalar x = 0; 83 SkScalar x = 0;
78 for (size_t i = 0; i < len; ++i) { 84 for (size_t i = 0; i < len; ++i) {
79 fPos[i].set(x, SkIntToScalar(50)); 85 fPos[i].set(x, SkIntToScalar(50));
80 x += adv[i]; 86 x += adv[i];
81 } 87 }
82 delete[] adv; 88 delete[] adv;
83 } 89 }
84 } 90 }
85 91
86 virtual ~TextBench() {
87 delete[] fPos;
88 }
89 92
90 protected:
91 virtual const char* onGetName() { 93 virtual const char* onGetName() {
92 fName.printf("text_%g", SkScalarToFloat(fPaint.getTextSize())); 94 fName.printf("text_%g", SkScalarToFloat(fPaint.getTextSize()));
mtklein 2015/05/21 13:09:25 Kind of weird that this builds fName in place then
93 if (fDoPos) { 95 if (fDoPos) {
94 fName.append("_pos"); 96 fName.append("_pos");
95 } 97 }
96 fName.appendf("_%s", fontQualityName(fPaint)); 98 fName.appendf("_%s", fontQualityName(fPaint));
97 if (SK_ColorBLACK != fPaint.getColor()) { 99 if (SK_ColorBLACK != fPaint.getColor()) {
98 fName.appendf("_%02X", fPaint.getAlpha()); 100 fName.appendf("_%02X", fPaint.getAlpha());
99 } else { 101 } else {
100 fName.append("_BK"); 102 fName.append("_BK");
101 } 103 }
102 104
103 if (fDoColorEmoji && fColorEmojiTypeface) { 105 if (fDoColorEmoji) {
104 fName.append("_ColorEmoji"); 106 fName.append("_ColorEmoji");
105 } 107 }
106 108
107 return fName.c_str(); 109 return fName.c_str();
108 } 110 }
109 111
110 virtual void onDraw(const int loops, SkCanvas* canvas) { 112 virtual void onDraw(const int loops, SkCanvas* canvas) {
111 const SkIPoint dim = this->getSize(); 113 const SkIPoint dim = this->getSize();
112 SkRandom rand; 114 SkRandom rand;
113 115
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kLCD); ) 163 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kLCD); )
162 DEF_BENCH( return new TextBench(STR, 16, 0xFFFF0000, kLCD); ) 164 DEF_BENCH( return new TextBench(STR, 16, 0xFFFF0000, kLCD); )
163 DEF_BENCH( return new TextBench(STR, 16, 0x88FF0000, kLCD); ) 165 DEF_BENCH( return new TextBench(STR, 16, 0x88FF0000, kLCD); )
164 166
165 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kBW, true); ) 167 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kBW, true); )
166 DEF_BENCH( return new TextBench(STR, 16, 0xFFFF0000, kBW, true); ) 168 DEF_BENCH( return new TextBench(STR, 16, 0xFFFF0000, kBW, true); )
167 DEF_BENCH( return new TextBench(STR, 16, 0x88FF0000, kBW, true); ) 169 DEF_BENCH( return new TextBench(STR, 16, 0x88FF0000, kBW, true); )
168 170
169 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kBW, true, true); ) 171 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kBW, true, true); )
170 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kAA, false, true); ) 172 DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kAA, false, true); )
OLDNEW
« no previous file with comments | « no previous file | bench/TextBlobBench.cpp » ('j') | gm/typeface.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698