OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkRandom.h" | |
11 #include "SkShader.h" | 10 #include "SkShader.h" |
12 #include "SkString.h" | 11 #include "SkString.h" |
13 #include "SkBicubicImageFilter.h" | 12 #include "SkBicubicImageFilter.h" |
14 | 13 |
15 // This bench exercises SkBicubicImageFilter, upsampling a 40x40 input to | 14 // This bench exercises SkBicubicImageFilter, upsampling a 40x40 input to |
16 // 100x100, 400x100, 100x400, and 400x400. | 15 // 100x100, 400x100, 100x400, and 400x400. |
17 | 16 |
18 class BicubicBench : public SkBenchmark { | 17 class BicubicBench : public SkBenchmark { |
19 SkSize fScale; | 18 SkSize fScale; |
20 SkString fName; | 19 SkString fName; |
21 | 20 |
22 public: | 21 public: |
23 BicubicBench(void* param, float x, float y) | 22 BicubicBench(void* param, float x, float y) |
24 : INHERITED(param), fScale(SkSize::Make(SkFloatToScalar(x), SkFloatToSc
alar(y))) { | 23 : INHERITED(param), fScale(SkSize::Make(SkFloatToScalar(x), SkFloatToSc
alar(y))) { |
25 fName.printf("bicubic_%gx%g", | 24 fName.printf("bicubic_%gx%g", |
26 SkScalarToFloat(fScale.fWidth), SkScalarToFloat(fScale.fHeight)); | 25 SkScalarToFloat(fScale.fWidth), SkScalarToFloat(fScale.fHeight)); |
27 } | 26 } |
28 | 27 |
29 protected: | 28 protected: |
30 virtual const char* onGetName() { | 29 virtual const char* onGetName() { |
31 return fName.c_str(); | 30 return fName.c_str(); |
32 } | 31 } |
33 | 32 |
34 virtual void onDraw(SkCanvas* canvas) { | 33 virtual void onDraw(SkCanvas* canvas) { |
35 SkPaint paint; | 34 SkPaint paint; |
36 this->setupPaint(&paint); | 35 this->setupPaint(&paint); |
37 | 36 |
38 paint.setAntiAlias(true); | 37 paint.setAntiAlias(true); |
39 | 38 |
40 SkRandom rand; | |
41 SkRect r = SkRect::MakeWH(40, 40); | 39 SkRect r = SkRect::MakeWH(40, 40); |
42 SkAutoTUnref<SkImageFilter> bicubic(SkBicubicImageFilter::CreateMitchell
(fScale)); | 40 SkAutoTUnref<SkImageFilter> bicubic(SkBicubicImageFilter::CreateMitchell
(fScale)); |
43 paint.setImageFilter(bicubic); | 41 paint.setImageFilter(bicubic); |
44 canvas->save(); | 42 |
45 canvas->clipRect(r); | 43 for (int i = 0; i < this->getLoops(); i++) { |
46 canvas->drawOval(r, paint); | 44 canvas->save(); |
47 canvas->restore(); | 45 canvas->clipRect(r); |
| 46 canvas->drawOval(r, paint); |
| 47 canvas->restore(); |
| 48 } |
48 } | 49 } |
49 | 50 |
50 private: | 51 private: |
51 typedef SkBenchmark INHERITED; | 52 typedef SkBenchmark INHERITED; |
52 }; | 53 }; |
53 | 54 |
54 static SkBenchmark* Fact00(void* p) { return new BicubicBench(p, 10.0f, 10.0f);
} | 55 static SkBenchmark* Fact00(void* p) { return new BicubicBench(p, 10.0f, 10.0f);
} |
55 static SkBenchmark* Fact01(void* p) { return new BicubicBench(p, 2.5f, 10.0f); } | 56 static SkBenchmark* Fact01(void* p) { return new BicubicBench(p, 2.5f, 10.0f); } |
56 static SkBenchmark* Fact02(void* p) { return new BicubicBench(p, 10.0f, 2.5f); } | 57 static SkBenchmark* Fact02(void* p) { return new BicubicBench(p, 10.0f, 2.5f); } |
57 static SkBenchmark* Fact03(void* p) { return new BicubicBench(p, 2.5f, 2.5f); } | 58 static SkBenchmark* Fact03(void* p) { return new BicubicBench(p, 2.5f, 2.5f); } |
58 | 59 |
59 static BenchRegistry gReg00(Fact00); | 60 static BenchRegistry gReg00(Fact00); |
60 static BenchRegistry gReg01(Fact01); | 61 static BenchRegistry gReg01(Fact01); |
61 static BenchRegistry gReg02(Fact02); | 62 static BenchRegistry gReg02(Fact02); |
62 static BenchRegistry gReg03(Fact03); | 63 static BenchRegistry gReg03(Fact03); |
OLD | NEW |