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 "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 union_proc(SkRegion& a, SkRegion& b) { | 13 static bool union_proc(SkRegion& a, SkRegion& b) { |
14 SkRegion result; | 14 SkRegion result; |
15 return result.op(a, b, SkRegion::kUnion_Op); | 15 return result.op(a, b, SkRegion::kUnion_Op); |
16 } | 16 } |
17 | 17 |
18 static bool sect_proc(SkRegion& a, SkRegion& b) { | 18 static bool sect_proc(SkRegion& a, SkRegion& b) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 const int dx = r.width() / 8; | 60 const int dx = r.width() / 8; |
61 const int dy = r.height() / 8; | 61 const int dy = r.height() / 8; |
62 for (int y = r.fTop; y < r.fBottom; y += dy) { | 62 for (int y = r.fTop; y < r.fBottom; y += dy) { |
63 for (int x = r.fLeft; x < r.fRight; x += dx) { | 63 for (int x = r.fLeft; x < r.fRight; x += dx) { |
64 (void)a.contains(x, y); | 64 (void)a.contains(x, y); |
65 } | 65 } |
66 } | 66 } |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 class RegionBench : public SkBenchmark { | 70 class RegionBench : public Benchmark { |
71 public: | 71 public: |
72 typedef bool (*Proc)(SkRegion& a, SkRegion& b); | 72 typedef bool (*Proc)(SkRegion& a, SkRegion& b); |
73 | 73 |
74 SkRegion fA, fB; | 74 SkRegion fA, fB; |
75 Proc fProc; | 75 Proc fProc; |
76 SkString fName; | 76 SkString fName; |
77 | 77 |
78 enum { | 78 enum { |
79 W = 1024, | 79 W = 1024, |
80 H = 768, | 80 H = 768, |
(...skipping 26 matching lines...) Expand all Loading... |
107 virtual const char* onGetName() { return fName.c_str(); } | 107 virtual const char* onGetName() { return fName.c_str(); } |
108 | 108 |
109 virtual void onDraw(const int loops, SkCanvas* canvas) { | 109 virtual void onDraw(const int loops, SkCanvas* canvas) { |
110 Proc proc = fProc; | 110 Proc proc = fProc; |
111 for (int i = 0; i < loops; ++i) { | 111 for (int i = 0; i < loops; ++i) { |
112 proc(fA, fB); | 112 proc(fA, fB); |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 private: | 116 private: |
117 typedef SkBenchmark INHERITED; | 117 typedef Benchmark INHERITED; |
118 }; | 118 }; |
119 | 119 |
120 class RectSectBench : public SkBenchmark { | 120 class RectSectBench : public Benchmark { |
121 enum { | 121 enum { |
122 N = 1000 | 122 N = 1000 |
123 }; | 123 }; |
124 SkRect fArray0[N]; | 124 SkRect fArray0[N]; |
125 SkRect fArray1[N]; | 125 SkRect fArray1[N]; |
126 SkString fName; | 126 SkString fName; |
127 bool fNewWay; | 127 bool fNewWay; |
128 | 128 |
129 public: | 129 public: |
130 static void RandRect(SkRect* r, SkRandom& rand) { | 130 static void RandRect(SkRect* r, SkRandom& rand) { |
(...skipping 29 matching lines...) Expand all Loading... |
160 } else { | 160 } else { |
161 for (int j = 0; j < N; ++j) { | 161 for (int j = 0; j < N; ++j) { |
162 SkRect r = fArray0[j]; | 162 SkRect r = fArray0[j]; |
163 r.intersect(fArray1[j]); | 163 r.intersect(fArray1[j]); |
164 } | 164 } |
165 } | 165 } |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 private: | 169 private: |
170 typedef SkBenchmark INHERITED; | 170 typedef Benchmark INHERITED; |
171 }; | 171 }; |
172 | 172 |
173 /////////////////////////////////////////////////////////////////////////////// | 173 /////////////////////////////////////////////////////////////////////////////// |
174 | 174 |
175 #define SMALL 16 | 175 #define SMALL 16 |
176 | 176 |
177 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, union_proc, "union")); ) | 177 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, union_proc, "union")); ) |
178 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, sect_proc, "intersect")); ) | 178 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, sect_proc, "intersect")); ) |
179 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, diff_proc, "difference")); ) | 179 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, diff_proc, "difference")); ) |
180 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, diffrect_proc, "differencerect
")); ) | 180 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, diffrect_proc, "differencerect
")); ) |
181 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, diffrectbig_proc, "differencer
ectbig")); ) | 181 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, diffrectbig_proc, "differencer
ectbig")); ) |
182 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, containsrect_proc, "containsre
ct")); ) | 182 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, containsrect_proc, "containsre
ct")); ) |
183 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, sectsrgn_proc, "intersectsrgn"
)); ) | 183 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, sectsrgn_proc, "intersectsrgn"
)); ) |
184 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, sectsrect_proc, "intersectsrec
t")); ) | 184 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, sectsrect_proc, "intersectsrec
t")); ) |
185 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, containsxy_proc, "containsxy")
); ) | 185 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, containsxy_proc, "containsxy")
); ) |
186 | 186 |
187 DEF_BENCH( return SkNEW_ARGS(RectSectBench, (false)); ) | 187 DEF_BENCH( return SkNEW_ARGS(RectSectBench, (false)); ) |
188 DEF_BENCH( return SkNEW_ARGS(RectSectBench, (true)); ) | 188 DEF_BENCH( return SkNEW_ARGS(RectSectBench, (true)); ) |
OLD | NEW |