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 "Benchmark.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkPaint.h" | |
11 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
12 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
| 12 #include "SkPaint.h" |
13 #include "SkRandom.h" | 13 #include "SkRandom.h" |
14 #include "SkString.h" | 14 #include "SkString.h" |
15 | 15 |
16 static void draw_into_bitmap(const SkBitmap& bm) { | 16 static void draw_into_bitmap(const SkBitmap& bm) { |
17 const int w = bm.width(); | 17 const int w = bm.width(); |
18 const int h = bm.height(); | 18 const int h = bm.height(); |
19 | 19 |
20 SkCanvas canvas(bm); | 20 SkCanvas canvas(bm); |
21 SkPaint p; | 21 SkPaint p; |
22 p.setAntiAlias(true); | 22 p.setAntiAlias(true); |
23 p.setColor(SK_ColorRED); | 23 p.setColor(SK_ColorRED); |
24 canvas.drawCircle(SkIntToScalar(w)/2, SkIntToScalar(h)/2, | 24 canvas.drawCircle(SkIntToScalar(w)/2, SkIntToScalar(h)/2, |
25 SkIntToScalar(SkMin32(w, h))*3/8, p); | 25 SkIntToScalar(SkMin32(w, h))*3/8, p); |
26 | 26 |
27 SkRect r; | 27 SkRect r; |
28 r.set(0, 0, SkIntToScalar(w), SkIntToScalar(h)); | 28 r.set(0, 0, SkIntToScalar(w), SkIntToScalar(h)); |
29 p.setStyle(SkPaint::kStroke_Style); | 29 p.setStyle(SkPaint::kStroke_Style); |
30 p.setStrokeWidth(SkIntToScalar(4)); | 30 p.setStrokeWidth(SkIntToScalar(4)); |
31 p.setColor(SK_ColorBLUE); | 31 p.setColor(SK_ColorBLUE); |
32 canvas.drawRect(r, p); | 32 canvas.drawRect(r, p); |
33 } | 33 } |
34 | 34 |
35 /* Variants for bitmaprect | 35 /* Variants for bitmaprect |
36 src : entire bitmap, subset, fractional subset | 36 src : entire bitmap, subset, fractional subset |
37 dst : same size as src, diff size | 37 dst : same size as src, diff size |
38 paint : filter-p | 38 paint : filter-p |
39 */ | 39 */ |
40 | 40 |
41 class BitmapRectBench : public SkBenchmark { | 41 class BitmapRectBench : public Benchmark { |
42 SkBitmap fBitmap; | 42 SkBitmap fBitmap; |
43 bool fSlightMatrix; | 43 bool fSlightMatrix; |
44 uint8_t fAlpha; | 44 uint8_t fAlpha; |
45 SkPaint::FilterLevel fFilterLevel; | 45 SkPaint::FilterLevel fFilterLevel; |
46 SkString fName; | 46 SkString fName; |
47 SkRect fSrcR, fDstR; | 47 SkRect fSrcR, fDstR; |
48 | 48 |
49 static const int kWidth = 128; | 49 static const int kWidth = 128; |
50 static const int kHeight = 128; | 50 static const int kHeight = 128; |
51 public: | 51 public: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 this->setupPaint(&paint); | 94 this->setupPaint(&paint); |
95 paint.setFilterLevel(fFilterLevel); | 95 paint.setFilterLevel(fFilterLevel); |
96 paint.setAlpha(fAlpha); | 96 paint.setAlpha(fAlpha); |
97 | 97 |
98 for (int i = 0; i < loops; i++) { | 98 for (int i = 0; i < loops; i++) { |
99 canvas->drawBitmapRectToRect(fBitmap, &fSrcR, fDstR, &paint); | 99 canvas->drawBitmapRectToRect(fBitmap, &fSrcR, fDstR, &paint); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 private: | 103 private: |
104 typedef SkBenchmark INHERITED; | 104 typedef Benchmark INHERITED; |
105 }; | 105 }; |
106 | 106 |
107 DEF_BENCH(return new BitmapRectBench(0xFF, SkPaint::kNone_FilterLevel, false)) | 107 DEF_BENCH(return new BitmapRectBench(0xFF, SkPaint::kNone_FilterLevel, false)) |
108 DEF_BENCH(return new BitmapRectBench(0x80, SkPaint::kNone_FilterLevel, false)) | 108 DEF_BENCH(return new BitmapRectBench(0x80, SkPaint::kNone_FilterLevel, false)) |
109 DEF_BENCH(return new BitmapRectBench(0xFF, SkPaint::kLow_FilterLevel, false)) | 109 DEF_BENCH(return new BitmapRectBench(0xFF, SkPaint::kLow_FilterLevel, false)) |
110 DEF_BENCH(return new BitmapRectBench(0x80, SkPaint::kLow_FilterLevel, false)) | 110 DEF_BENCH(return new BitmapRectBench(0x80, SkPaint::kLow_FilterLevel, false)) |
111 | 111 |
112 DEF_BENCH(return new BitmapRectBench(0xFF, SkPaint::kNone_FilterLevel, true)) | 112 DEF_BENCH(return new BitmapRectBench(0xFF, SkPaint::kNone_FilterLevel, true)) |
113 DEF_BENCH(return new BitmapRectBench(0xFF, SkPaint::kLow_FilterLevel, true)) | 113 DEF_BENCH(return new BitmapRectBench(0xFF, SkPaint::kLow_FilterLevel, true)) |
OLD | NEW |