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

Side by Side Diff: bench/GradientBench.cpp

Issue 99893003: Simplify benchmark internal API. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « bench/GrResourceCacheBench.cpp ('k') | bench/HairlinePathBench.cpp » ('j') | no next file with comments »
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 #include "SkBenchmark.h" 8 #include "SkBenchmark.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 virtual ~GradientBench() { 197 virtual ~GradientBench() {
198 fShader->unref(); 198 fShader->unref();
199 } 199 }
200 200
201 protected: 201 protected:
202 virtual const char* onGetName() { 202 virtual const char* onGetName() {
203 return fName.c_str(); 203 return fName.c_str();
204 } 204 }
205 205
206 virtual void onDraw(SkCanvas* canvas) { 206 virtual void onDraw(const int loops, SkCanvas* canvas) {
207 SkPaint paint; 207 SkPaint paint;
208 this->setupPaint(&paint); 208 this->setupPaint(&paint);
209 209
210 paint.setShader(fShader); 210 paint.setShader(fShader);
211 211
212 SkRect r = { 0, 0, SkIntToScalar(W), SkIntToScalar(H) }; 212 SkRect r = { 0, 0, SkIntToScalar(W), SkIntToScalar(H) };
213 for (int i = 0; i < this->getLoops() * kRepeat; i++) { 213 for (int i = 0; i < loops * kRepeat; i++) {
214 switch (fGeomType) { 214 switch (fGeomType) {
215 case kRect_GeomType: 215 case kRect_GeomType:
216 canvas->drawRect(r, paint); 216 canvas->drawRect(r, paint);
217 break; 217 break;
218 case kOval_GeomType: 218 case kOval_GeomType:
219 canvas->drawOval(r, paint); 219 canvas->drawOval(r, paint);
220 break; 220 break;
221 } 221 }
222 } 222 }
223 } 223 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 Gradient2Bench(bool hasAlpha) { 266 Gradient2Bench(bool hasAlpha) {
267 fName.printf("gradient_create_%s", hasAlpha ? "alpha" : "opaque"); 267 fName.printf("gradient_create_%s", hasAlpha ? "alpha" : "opaque");
268 fHasAlpha = hasAlpha; 268 fHasAlpha = hasAlpha;
269 } 269 }
270 270
271 protected: 271 protected:
272 virtual const char* onGetName() { 272 virtual const char* onGetName() {
273 return fName.c_str(); 273 return fName.c_str();
274 } 274 }
275 275
276 virtual void onDraw(SkCanvas* canvas) { 276 virtual void onDraw(const int loops, SkCanvas* canvas) {
277 SkPaint paint; 277 SkPaint paint;
278 this->setupPaint(&paint); 278 this->setupPaint(&paint);
279 279
280 const SkRect r = { 0, 0, SkIntToScalar(4), SkIntToScalar(4) }; 280 const SkRect r = { 0, 0, SkIntToScalar(4), SkIntToScalar(4) };
281 const SkPoint pts[] = { 281 const SkPoint pts[] = {
282 { 0, 0 }, 282 { 0, 0 },
283 { SkIntToScalar(100), SkIntToScalar(100) }, 283 { SkIntToScalar(100), SkIntToScalar(100) },
284 }; 284 };
285 285
286 for (int i = 0; i < this->getLoops(); i++) { 286 for (int i = 0; i < loops; i++) {
287 const int gray = i % 256; 287 const int gray = i % 256;
288 const int alpha = fHasAlpha ? gray : 0xFF; 288 const int alpha = fHasAlpha ? gray : 0xFF;
289 SkColor colors[] = { 289 SkColor colors[] = {
290 SK_ColorBLACK, 290 SK_ColorBLACK,
291 SkColorSetARGB(alpha, gray, gray, gray), 291 SkColorSetARGB(alpha, gray, gray, gray),
292 SK_ColorWHITE }; 292 SK_ColorWHITE };
293 SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, 293 SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL,
294 SK_ARRAY_COUNT(colors), 294 SK_ARRAY_COUNT(colors),
295 SkShader::kClamp_TileMo de); 295 SkShader::kClamp_TileMo de);
296 paint.setShader(s)->unref(); 296 paint.setShader(s)->unref();
297 canvas->drawRect(r, paint); 297 canvas->drawRect(r, paint);
298 } 298 }
299 } 299 }
300 300
301 private: 301 private:
302 typedef SkBenchmark INHERITED; 302 typedef SkBenchmark INHERITED;
303 }; 303 };
304 304
305 DEF_BENCH( return new Gradient2Bench(false); ) 305 DEF_BENCH( return new Gradient2Bench(false); )
306 DEF_BENCH( return new Gradient2Bench(true); ) 306 DEF_BENCH( return new Gradient2Bench(true); )
OLDNEW
« no previous file with comments | « bench/GrResourceCacheBench.cpp ('k') | bench/HairlinePathBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698