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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkCommandLineFlags.h" | 10 #include "SkCommandLineFlags.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 enum { | 21 enum { |
22 W = 640, | 22 W = 640, |
23 H = 480, | 23 H = 480, |
24 N = 300, | 24 N = 300, |
25 }; | 25 }; |
26 SkRect fRects[N]; | 26 SkRect fRects[N]; |
27 SkColor fColors[N]; | 27 SkColor fColors[N]; |
28 | 28 |
29 RectBench(int shift, int stroke = 0) | 29 RectBench(int shift, int stroke = 0) |
30 : fShift(shift) | 30 : fShift(shift) |
31 , fStroke(stroke) { | 31 , fStroke(stroke) {} |
32 SkRandom rand; | |
33 const SkScalar offset = SK_Scalar1/3; | |
34 for (int i = 0; i < N; i++) { | |
35 int x = rand.nextU() % W; | |
36 int y = rand.nextU() % H; | |
37 int w = rand.nextU() % W; | |
38 int h = rand.nextU() % H; | |
39 w >>= shift; | |
40 h >>= shift; | |
41 x -= w/2; | |
42 y -= h/2; | |
43 fRects[i].set(SkIntToScalar(x), SkIntToScalar(y), | |
44 SkIntToScalar(x+w), SkIntToScalar(y+h)); | |
45 fRects[i].offset(offset, offset); | |
46 fColors[i] = rand.nextU() | 0xFF808080; | |
47 } | |
48 } | |
49 | 32 |
50 SkString fName; | 33 SkString fName; |
51 const char* computeName(const char root[]) { | 34 const char* computeName(const char root[]) { |
52 fName.printf("%s_%d", root, fShift); | 35 fName.printf("%s_%d", root, fShift); |
53 if (fStroke > 0) { | 36 if (fStroke > 0) { |
54 fName.appendf("_stroke_%d", fStroke); | 37 fName.appendf("_stroke_%d", fStroke); |
55 } | 38 } |
56 return fName.c_str(); | 39 return fName.c_str(); |
57 } | 40 } |
58 | 41 |
59 protected: | 42 protected: |
60 virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) { | 43 virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) { |
61 c->drawRect(r, p); | 44 c->drawRect(r, p); |
62 } | 45 } |
63 | 46 |
64 virtual const char* onGetName() { return computeName("rects"); } | 47 virtual const char* onGetName() { return computeName("rects"); } |
| 48 |
| 49 virtual void onPreDraw() { |
| 50 SkRandom rand; |
| 51 const SkScalar offset = SK_Scalar1/3; |
| 52 for (int i = 0; i < N; i++) { |
| 53 int x = rand.nextU() % W; |
| 54 int y = rand.nextU() % H; |
| 55 int w = rand.nextU() % W; |
| 56 int h = rand.nextU() % H; |
| 57 w >>= fShift; |
| 58 h >>= fShift; |
| 59 x -= w/2; |
| 60 y -= h/2; |
| 61 fRects[i].set(SkIntToScalar(x), SkIntToScalar(y), |
| 62 SkIntToScalar(x+w), SkIntToScalar(y+h)); |
| 63 fRects[i].offset(offset, offset); |
| 64 fColors[i] = rand.nextU() | 0xFF808080; |
| 65 } |
| 66 } |
| 67 |
65 virtual void onDraw(const int loops, SkCanvas* canvas) { | 68 virtual void onDraw(const int loops, SkCanvas* canvas) { |
66 SkPaint paint; | 69 SkPaint paint; |
67 if (fStroke > 0) { | 70 if (fStroke > 0) { |
68 paint.setStyle(SkPaint::kStroke_Style); | 71 paint.setStyle(SkPaint::kStroke_Style); |
69 paint.setStrokeWidth(SkIntToScalar(fStroke)); | 72 paint.setStrokeWidth(SkIntToScalar(fStroke)); |
70 } | 73 } |
71 for (int i = 0; i < loops; i++) { | 74 for (int i = 0; i < loops; i++) { |
72 paint.setColor(fColors[i % N]); | 75 paint.setColor(fColors[i % N]); |
73 this->setupPaint(&paint); | 76 this->setupPaint(&paint); |
74 this->drawThisRect(canvas, fRects[i % N], paint); | 77 this->drawThisRect(canvas, fRects[i % N], paint); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 BlitMaskBench::kMaskBlack, "maskblack") | 337 BlitMaskBench::kMaskBlack, "maskblack") |
335 ); ) | 338 ); ) |
336 DEF_BENCH( return SkNEW_ARGS(BlitMaskBench, | 339 DEF_BENCH( return SkNEW_ARGS(BlitMaskBench, |
337 (SkCanvas::kPoints_PointMode, | 340 (SkCanvas::kPoints_PointMode, |
338 BlitMaskBench::kMaskColor, "maskcolor") | 341 BlitMaskBench::kMaskColor, "maskcolor") |
339 ); ) | 342 ); ) |
340 DEF_BENCH( return SkNEW_ARGS(BlitMaskBench, | 343 DEF_BENCH( return SkNEW_ARGS(BlitMaskBench, |
341 (SkCanvas::kPoints_PointMode, | 344 (SkCanvas::kPoints_PointMode, |
342 BlitMaskBench::KMaskShader, "maskshader") | 345 BlitMaskBench::KMaskShader, "maskshader") |
343 ); ) | 346 ); ) |
OLD | NEW |