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 "SkRandom.h" | 9 #include "SkRandom.h" |
10 #include "SkRegion.h" | 10 #include "SkRegion.h" |
11 #include "SkString.h" | 11 #include "SkString.h" |
12 | 12 |
13 static bool sect_proc(SkRegion& a, SkRegion& b) { | 13 static bool sect_proc(SkRegion& a, SkRegion& b) { |
14 SkRegion result; | 14 SkRegion result; |
15 return result.op(a, b, SkRegion::kIntersect_Op); | 15 return result.op(a, b, SkRegion::kIntersect_Op); |
16 } | 16 } |
17 | 17 |
18 class RegionContainBench : public SkBenchmark { | 18 class RegionContainBench : public SkBenchmark { |
19 public: | 19 public: |
20 typedef bool (*Proc)(SkRegion& a, SkRegion& b); | 20 typedef bool (*Proc)(SkRegion& a, SkRegion& b); |
21 SkRegion fA, fB; | 21 SkRegion fA, fB; |
22 Proc fProc; | 22 Proc fProc; |
23 SkString fName; | 23 SkString fName; |
24 | 24 |
25 enum { | 25 enum { |
26 W = 200, | 26 W = 200, |
27 H = 200, | 27 H = 200, |
28 COUNT = 10, | 28 COUNT = 10, |
29 N = SkBENCHLOOP(20000) | |
30 }; | 29 }; |
31 | 30 |
32 SkIRect randrect(SkRandom& rand, int i) { | 31 SkIRect randrect(SkRandom& rand, int i) { |
33 int w = rand.nextU() % W; | 32 int w = rand.nextU() % W; |
34 return SkIRect::MakeXYWH(0, i*H/COUNT, w, H/COUNT); | 33 return SkIRect::MakeXYWH(0, i*H/COUNT, w, H/COUNT); |
35 } | 34 } |
36 | 35 |
37 RegionContainBench(void* param, Proc proc, const char name[]) : INHERITED(pa
ram) { | 36 RegionContainBench(void* param, Proc proc, const char name[]) : INHERITED(pa
ram) { |
38 fProc = proc; | 37 fProc = proc; |
39 fName.printf("region_contains_%s", name); | 38 fName.printf("region_contains_%s", name); |
40 | 39 |
41 SkRandom rand; | 40 SkRandom rand; |
42 for (int i = 0; i < COUNT; i++) { | 41 for (int i = 0; i < COUNT; i++) { |
43 fA.op(randrect(rand, i), SkRegion::kXOR_Op); | 42 fA.op(randrect(rand, i), SkRegion::kXOR_Op); |
44 } | 43 } |
45 | 44 |
46 fB.setRect(0, 0, H, W); | 45 fB.setRect(0, 0, H, W); |
47 | 46 |
48 fIsRendering = false; | 47 fIsRendering = false; |
49 } | 48 } |
50 | 49 |
51 protected: | 50 protected: |
52 virtual const char* onGetName() { return fName.c_str(); } | 51 virtual const char* onGetName() { return fName.c_str(); } |
53 | 52 |
54 virtual void onDraw(SkCanvas*) { | 53 virtual void onDraw(SkCanvas*) { |
55 Proc proc = fProc; | 54 Proc proc = fProc; |
56 | 55 |
57 for (int i = 0; i < N; ++i) { | 56 for (int i = 0; i < this->getLoops(); ++i) { |
58 proc(fA, fB); | 57 proc(fA, fB); |
59 } | 58 } |
60 } | 59 } |
61 | 60 |
62 private: | 61 private: |
63 typedef SkBenchmark INHERITED; | 62 typedef SkBenchmark INHERITED; |
64 }; | 63 }; |
65 | 64 |
66 static SkBenchmark* gF0(void* p) { return SkNEW_ARGS(RegionContainBench, (p, sec
t_proc, "sect")); } | 65 static SkBenchmark* gF0(void* p) { return SkNEW_ARGS(RegionContainBench, (p, sec
t_proc, "sect")); } |
67 | 66 |
68 static BenchRegistry gR0(gF0); | 67 static BenchRegistry gR0(gF0); |
OLD | NEW |