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 #include "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 | 366 |
367 for (int i = 0; i < loops; i++) { | 367 for (int i = 0; i < loops; i++) { |
368 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, p); | 368 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, p); |
369 } | 369 } |
370 } | 370 } |
371 | 371 |
372 private: | 372 private: |
373 typedef SkBenchmark INHERITED; | 373 typedef SkBenchmark INHERITED; |
374 }; | 374 }; |
375 | 375 |
| 376 // Want to test how we draw a dashed grid (like what is used in spreadsheets) of
many |
| 377 // small dashed lines switching back and forth between horizontal and vertical |
| 378 class DashGridBench : public SkBenchmark { |
| 379 SkString fName; |
| 380 int fStrokeWidth; |
| 381 bool fDoAA; |
| 382 |
| 383 SkAutoTUnref<SkPathEffect> fPathEffect; |
| 384 |
| 385 public: |
| 386 DashGridBench(int dashLength, int strokeWidth, bool doAA) { |
| 387 fName.printf("dashgrid_%d_%d%s", dashLength, strokeWidth, doAA ? "_aa" :
"_bw"); |
| 388 fStrokeWidth = strokeWidth; |
| 389 fDoAA = doAA; |
| 390 |
| 391 SkScalar vals[] = { SkIntToScalar(dashLength), SkIntToScalar(dashLength)
}; |
| 392 fPathEffect.reset(SkDashPathEffect::Create(vals, 2, SK_Scalar1)); |
| 393 } |
| 394 |
| 395 protected: |
| 396 virtual const char* onGetName() SK_OVERRIDE { |
| 397 return fName.c_str(); |
| 398 } |
| 399 |
| 400 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 401 SkPaint p; |
| 402 this->setupPaint(&p); |
| 403 p.setColor(SK_ColorBLACK); |
| 404 p.setStyle(SkPaint::kStroke_Style); |
| 405 p.setStrokeWidth(SkIntToScalar(fStrokeWidth)); |
| 406 p.setPathEffect(fPathEffect); |
| 407 p.setAntiAlias(fDoAA); |
| 408 |
| 409 SkPoint pts[4] = { |
| 410 { SkIntToScalar(0), 20.5f }, |
| 411 { SkIntToScalar(20), 20.5f }, |
| 412 { 20.5f, SkIntToScalar(0) }, |
| 413 { 20.5f, SkIntToScalar(20) } |
| 414 }; |
| 415 |
| 416 for (int i = 0; i < loops; ++i) { |
| 417 for (int j = 0; j < 10; ++j) { |
| 418 for (int k = 0; k < 10; ++k) { |
| 419 // Horizontal line |
| 420 SkPoint horPts[2]; |
| 421 horPts[0].fX = pts[0].fX + k * 22.f; |
| 422 horPts[0].fY = pts[0].fY + j * 22.f; |
| 423 horPts[1].fX = pts[1].fX + k * 22.f; |
| 424 horPts[1].fY = pts[1].fY + j * 22.f; |
| 425 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, horPts, p)
; |
| 426 |
| 427 // Vertical line |
| 428 SkPoint vertPts[2]; |
| 429 vertPts[0].fX = pts[2].fX + k * 22.f; |
| 430 vertPts[0].fY = pts[2].fY + j * 22.f; |
| 431 vertPts[1].fX = pts[3].fX + k * 22.f; |
| 432 vertPts[1].fY = pts[3].fY + j * 22.f; |
| 433 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, vertPts, p
); |
| 434 } |
| 435 } |
| 436 } |
| 437 } |
| 438 |
| 439 private: |
| 440 typedef SkBenchmark INHERITED; |
| 441 }; |
376 | 442 |
377 /////////////////////////////////////////////////////////////////////////////// | 443 /////////////////////////////////////////////////////////////////////////////// |
378 | 444 |
379 static const SkScalar gDots[] = { SK_Scalar1, SK_Scalar1 }; | 445 static const SkScalar gDots[] = { SK_Scalar1, SK_Scalar1 }; |
380 | 446 |
381 #define PARAM(array) array, SK_ARRAY_COUNT(array) | 447 #define PARAM(array) array, SK_ARRAY_COUNT(array) |
382 | 448 |
383 DEF_BENCH( return new DashBench(PARAM(gDots), 0); ) | 449 DEF_BENCH( return new DashBench(PARAM(gDots), 0); ) |
384 DEF_BENCH( return new DashBench(PARAM(gDots), 1); ) | 450 DEF_BENCH( return new DashBench(PARAM(gDots), 1); ) |
385 DEF_BENCH( return new DashBench(PARAM(gDots), 1, true); ) | 451 DEF_BENCH( return new DashBench(PARAM(gDots), 1, true); ) |
(...skipping 22 matching lines...) Expand all Loading... |
408 DEF_BENCH( return new GiantDashBench(GiantDashBench::kHori_LineType, 0); ) | 474 DEF_BENCH( return new GiantDashBench(GiantDashBench::kHori_LineType, 0); ) |
409 DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 0); ) | 475 DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 0); ) |
410 DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 0); ) | 476 DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 0); ) |
411 | 477 |
412 // pass 2 to explicitly avoid any 1-is-the-same-as-hairline special casing | 478 // pass 2 to explicitly avoid any 1-is-the-same-as-hairline special casing |
413 | 479 |
414 // hori_2 is just too slow to enable at the moment | 480 // hori_2 is just too slow to enable at the moment |
415 DEF_BENCH( return new GiantDashBench(GiantDashBench::kHori_LineType, 2); ) | 481 DEF_BENCH( return new GiantDashBench(GiantDashBench::kHori_LineType, 2); ) |
416 DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 2); ) | 482 DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 2); ) |
417 DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 2); ) | 483 DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 2); ) |
| 484 |
| 485 DEF_BENCH( return new DashGridBench(1, 1, true); ) |
| 486 DEF_BENCH( return new DashGridBench(1, 1, false); ) |
| 487 DEF_BENCH( return new DashGridBench(3, 1, true); ) |
| 488 DEF_BENCH( return new DashGridBench(3, 1, false); ) |
418 #endif | 489 #endif |
OLD | NEW |