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 "SkRandom.h" | 9 #include "SkRandom.h" |
10 #include "SkRegion.h" | 10 #include "SkRegion.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 class RegionBench : public SkBenchmark { | 70 class RegionBench : public SkBenchmark { |
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 int fLoopMul; | |
78 | 77 |
79 enum { | 78 enum { |
80 W = 1024, | 79 W = 1024, |
81 H = 768, | 80 H = 768, |
82 N = SkBENCHLOOP(2000) | |
83 }; | 81 }; |
84 | 82 |
85 SkIRect randrect(SkRandom& rand) { | 83 SkIRect randrect(SkRandom& rand) { |
86 int x = rand.nextU() % W; | 84 int x = rand.nextU() % W; |
87 int y = rand.nextU() % H; | 85 int y = rand.nextU() % H; |
88 int w = rand.nextU() % W; | 86 int w = rand.nextU() % W; |
89 int h = rand.nextU() % H; | 87 int h = rand.nextU() % H; |
90 return SkIRect::MakeXYWH(x, y, w >> 1, h >> 1); | 88 return SkIRect::MakeXYWH(x, y, w >> 1, h >> 1); |
91 } | 89 } |
92 | 90 |
93 RegionBench(void* param, int count, Proc proc, const char name[], int mul =
1) : INHERITED(param) { | 91 RegionBench(void* param, int count, Proc proc, const char name[]) : INHERITE
D(param) { |
94 fProc = proc; | 92 fProc = proc; |
95 fName.printf("region_%s_%d", name, count); | 93 fName.printf("region_%s_%d", name, count); |
96 fLoopMul = mul; | |
97 | 94 |
98 SkRandom rand; | 95 SkRandom rand; |
99 for (int i = 0; i < count; i++) { | 96 for (int i = 0; i < count; i++) { |
100 fA.op(randrect(rand), SkRegion::kXOR_Op); | 97 fA.op(randrect(rand), SkRegion::kXOR_Op); |
101 fB.op(randrect(rand), SkRegion::kXOR_Op); | 98 fB.op(randrect(rand), SkRegion::kXOR_Op); |
102 } | 99 } |
103 fIsRendering = false; | 100 fIsRendering = false; |
104 } | 101 } |
105 | 102 |
106 protected: | 103 protected: |
107 virtual const char* onGetName() { return fName.c_str(); } | 104 virtual const char* onGetName() { return fName.c_str(); } |
108 | 105 |
109 virtual void onDraw(SkCanvas* canvas) { | 106 virtual void onDraw(SkCanvas* canvas) { |
110 Proc proc = fProc; | 107 Proc proc = fProc; |
111 int n = fLoopMul * N; | 108 for (int i = 0; i < this->getLoops(); ++i) { |
112 for (int i = 0; i < n; ++i) { | |
113 proc(fA, fB); | 109 proc(fA, fB); |
114 } | 110 } |
115 } | 111 } |
116 | 112 |
117 private: | 113 private: |
118 typedef SkBenchmark INHERITED; | 114 typedef SkBenchmark INHERITED; |
119 }; | 115 }; |
120 | 116 |
121 #define SMALL 16 | 117 #define SMALL 16 |
122 | 118 |
123 static SkBenchmark* gF0(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, uni
on_proc, "union")); } | 119 static SkBenchmark* gF0(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, uni
on_proc, "union")); } |
124 static SkBenchmark* gF1(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, sec
t_proc, "intersect")); } | 120 static SkBenchmark* gF1(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, sec
t_proc, "intersect")); } |
125 static SkBenchmark* gF2(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, dif
f_proc, "difference")); } | 121 static SkBenchmark* gF2(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, dif
f_proc, "difference")); } |
126 static SkBenchmark* gF3(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, dif
frect_proc, "differencerect")); } | 122 static SkBenchmark* gF3(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, dif
frect_proc, "differencerect")); } |
127 static SkBenchmark* gF4(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, dif
frectbig_proc, "differencerectbig")); } | 123 static SkBenchmark* gF4(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, dif
frectbig_proc, "differencerectbig")); } |
128 static SkBenchmark* gF5(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, con
tainsrect_proc, "containsrect", 100)); } | 124 static SkBenchmark* gF5(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, con
tainsrect_proc, "containsrect")); } |
129 static SkBenchmark* gF6(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, sec
tsrgn_proc, "intersectsrgn", 10)); } | 125 static SkBenchmark* gF6(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, sec
tsrgn_proc, "intersectsrgn")); } |
130 static SkBenchmark* gF7(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, sec
tsrect_proc, "intersectsrect", 200)); } | 126 static SkBenchmark* gF7(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, sec
tsrect_proc, "intersectsrect")); } |
131 static SkBenchmark* gF8(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, con
tainsxy_proc, "containsxy")); } | 127 static SkBenchmark* gF8(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, con
tainsxy_proc, "containsxy")); } |
132 | 128 |
133 static BenchRegistry gR0(gF0); | 129 static BenchRegistry gR0(gF0); |
134 static BenchRegistry gR1(gF1); | 130 static BenchRegistry gR1(gF1); |
135 static BenchRegistry gR2(gF2); | 131 static BenchRegistry gR2(gF2); |
136 static BenchRegistry gR3(gF3); | 132 static BenchRegistry gR3(gF3); |
137 static BenchRegistry gR4(gF4); | 133 static BenchRegistry gR4(gF4); |
138 static BenchRegistry gR5(gF5); | 134 static BenchRegistry gR5(gF5); |
139 static BenchRegistry gR6(gF6); | 135 static BenchRegistry gR6(gF6); |
140 static BenchRegistry gR7(gF7); | 136 static BenchRegistry gR7(gF7); |
141 static BenchRegistry gR8(gF8); | 137 static BenchRegistry gR8(gF8); |
OLD | NEW |