OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkPaint.h" | 10 #include "SkPaint.h" |
11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
12 #include "SkString.h" | 12 #include "SkString.h" |
13 | 13 |
14 | 14 |
15 // This bench simulates the calls Skia sees from various HTML5 canvas | 15 // This bench simulates the calls Skia sees from various HTML5 canvas |
16 // game bench marks | 16 // game bench marks |
17 class GameBench : public SkBenchmark { | 17 class GameBench : public SkBenchmark { |
18 public: | 18 public: |
19 enum Type { | 19 enum Type { |
20 kScale_Type, | 20 kScale_Type, |
21 kTranslate_Type, | 21 kTranslate_Type, |
22 kRotate_Type | 22 kRotate_Type |
23 }; | 23 }; |
24 | 24 |
25 GameBench(void* param, Type type, bool partialClear) | 25 GameBench(void* param, Type type, bool partialClear, bool aligned = false) |
26 : INHERITED(param) | 26 : INHERITED(param) |
27 , fType(type) | 27 , fType(type) |
28 , fPartialClear(partialClear) | 28 , fPartialClear(partialClear) |
| 29 , fAligned(aligned) |
29 , fName("game") | 30 , fName("game") |
30 , fNumSaved(0) | 31 , fNumSaved(0) |
31 , fInitialized(false) { | 32 , fInitialized(false) { |
32 | 33 |
33 switch (fType) { | 34 switch (fType) { |
34 case kScale_Type: | 35 case kScale_Type: |
35 fName.append("_scale"); | 36 fName.append("_scale"); |
36 break; | 37 break; |
37 case kTranslate_Type: | 38 case kTranslate_Type: |
38 fName.append("_trans"); | 39 fName.append("_trans"); |
39 break; | 40 break; |
40 case kRotate_Type: | 41 case kRotate_Type: |
41 fName.append("_rot"); | 42 fName.append("_rot"); |
42 break; | 43 break; |
43 }; | 44 }; |
44 | 45 |
| 46 if (aligned) { |
| 47 fName.append("_aligned"); |
| 48 } |
| 49 |
45 if (partialClear) { | 50 if (partialClear) { |
46 fName.append("_partial"); | 51 fName.append("_partial"); |
47 } else { | 52 } else { |
48 fName.append("_full"); | 53 fName.append("_full"); |
49 } | 54 } |
50 | 55 |
51 // It's HTML 5 canvas, so always AA | 56 // It's HTML 5 canvas, so always AA |
52 fName.append("_aa"); | 57 fName.append("_aa"); |
53 } | 58 } |
54 | 59 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 128 |
124 fNumSaved = 0; | 129 fNumSaved = 0; |
125 } | 130 } |
126 | 131 |
127 SkASSERT(fNumSaved < kNumBeforeClear); | 132 SkASSERT(fNumSaved < kNumBeforeClear); |
128 | 133 |
129 canvas->setMatrix(SkMatrix::I()); | 134 canvas->setMatrix(SkMatrix::I()); |
130 | 135 |
131 fSaved[fNumSaved][0] = transRand.nextRangeScalar(0.0f, maxTransX); | 136 fSaved[fNumSaved][0] = transRand.nextRangeScalar(0.0f, maxTransX); |
132 fSaved[fNumSaved][1] = transRand.nextRangeScalar(0.0f, maxTransY); | 137 fSaved[fNumSaved][1] = transRand.nextRangeScalar(0.0f, maxTransY); |
| 138 if (fAligned) { |
| 139 // make the translations integer aligned |
| 140 fSaved[fNumSaved][0] = SkScalarFloorToScalar(fSaved[fNumSaved][0
]); |
| 141 fSaved[fNumSaved][1] = SkScalarFloorToScalar(fSaved[fNumSaved][1
]); |
| 142 } |
133 | 143 |
134 mat.setTranslate(fSaved[fNumSaved][0], fSaved[fNumSaved][1]); | 144 mat.setTranslate(fSaved[fNumSaved][0], fSaved[fNumSaved][1]); |
135 | 145 |
136 if (kScale_Type == fType) { | 146 if (kScale_Type == fType) { |
137 fSaved[fNumSaved][2] = scaleRand.nextRangeScalar(0.5f, 1.5f); | 147 fSaved[fNumSaved][2] = scaleRand.nextRangeScalar(0.5f, 1.5f); |
138 mat.preScale(fSaved[fNumSaved][2], fSaved[fNumSaved][2]); | 148 mat.preScale(fSaved[fNumSaved][2], fSaved[fNumSaved][2]); |
139 } else if (kRotate_Type == fType) { | 149 } else if (kRotate_Type == fType) { |
140 fSaved[fNumSaved][2] = rotRand.nextRangeScalar(0.0f, 360.0f); | 150 fSaved[fNumSaved][2] = rotRand.nextRangeScalar(0.0f, 360.0f); |
141 mat.preRotate(fSaved[fNumSaved][2]); | 151 mat.preRotate(fSaved[fNumSaved][2]); |
142 } | 152 } |
(...skipping 10 matching lines...) Expand all Loading... |
153 static const int kNumRects = 100; | 163 static const int kNumRects = 100; |
154 static const int kNumBeforeClear = 10; | 164 static const int kNumBeforeClear = 10; |
155 #else | 165 #else |
156 static const int kNumRects = 5000; | 166 static const int kNumRects = 5000; |
157 static const int kNumBeforeClear = 300; | 167 static const int kNumBeforeClear = 300; |
158 #endif | 168 #endif |
159 | 169 |
160 | 170 |
161 Type fType; | 171 Type fType; |
162 bool fPartialClear; | 172 bool fPartialClear; |
| 173 bool fAligned; |
163 SkString fName; | 174 SkString fName; |
164 int fNumSaved; // num draws stored in 'fSaved' | 175 int fNumSaved; // num draws stored in 'fSaved' |
165 bool fInitialized; | 176 bool fInitialized; |
166 | 177 |
167 // 0 & 1 are always x & y translate. 2 is either scale or rotate. | 178 // 0 & 1 are always x & y translate. 2 is either scale or rotate. |
168 SkScalar fSaved[kNumBeforeClear][3]; | 179 SkScalar fSaved[kNumBeforeClear][3]; |
169 SkBitmap fCheckerboard; | 180 SkBitmap fCheckerboard; |
170 | 181 |
171 // Note: the resulting checker board has transparency | 182 // Note: the resulting checker board has transparency |
172 void makeCheckerboard() { | 183 void makeCheckerboard() { |
(...skipping 17 matching lines...) Expand all Loading... |
190 } | 201 } |
191 } | 202 } |
192 } | 203 } |
193 | 204 |
194 typedef SkBenchmark INHERITED; | 205 typedef SkBenchmark INHERITED; |
195 }; | 206 }; |
196 | 207 |
197 // Partial clear | 208 // Partial clear |
198 DEF_BENCH( return SkNEW_ARGS(GameBench, (p, GameBench::kScale_Type, false)); ) | 209 DEF_BENCH( return SkNEW_ARGS(GameBench, (p, GameBench::kScale_Type, false)); ) |
199 DEF_BENCH( return SkNEW_ARGS(GameBench, (p, GameBench::kTranslate_Type, false));
) | 210 DEF_BENCH( return SkNEW_ARGS(GameBench, (p, GameBench::kTranslate_Type, false));
) |
| 211 DEF_BENCH( return SkNEW_ARGS(GameBench, (p, GameBench::kTranslate_Type, false, t
rue)); ) |
200 DEF_BENCH( return SkNEW_ARGS(GameBench, (p, GameBench::kRotate_Type, false)); ) | 212 DEF_BENCH( return SkNEW_ARGS(GameBench, (p, GameBench::kRotate_Type, false)); ) |
201 | 213 |
202 // Full clear | 214 // Full clear |
203 DEF_BENCH( return SkNEW_ARGS(GameBench, (p, GameBench::kScale_Type, true)); ) | 215 DEF_BENCH( return SkNEW_ARGS(GameBench, (p, GameBench::kScale_Type, true)); ) |
204 DEF_BENCH( return SkNEW_ARGS(GameBench, (p, GameBench::kTranslate_Type, true));
) | 216 DEF_BENCH( return SkNEW_ARGS(GameBench, (p, GameBench::kTranslate_Type, true));
) |
| 217 DEF_BENCH( return SkNEW_ARGS(GameBench, (p, GameBench::kTranslate_Type, true, tr
ue)); ) |
205 DEF_BENCH( return SkNEW_ARGS(GameBench, (p, GameBench::kRotate_Type, true)); ) | 218 DEF_BENCH( return SkNEW_ARGS(GameBench, (p, GameBench::kRotate_Type, true)); ) |
OLD | NEW |