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 "SkMatrix.h" | 9 #include "SkMatrix.h" |
10 #include "SkMatrixUtils.h" | 10 #include "SkMatrixUtils.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 private: | 88 private: |
89 SkMatrix fM0, fM1, fM2; | 89 SkMatrix fM0, fM1, fM2; |
90 SkScalar fSX, fSY; | 90 SkScalar fSX, fSY; |
91 typedef MatrixBench INHERITED; | 91 typedef MatrixBench INHERITED; |
92 }; | 92 }; |
93 | 93 |
94 // having unknown values in our arrays can throw off the timing a lot, perhaps | 94 // having unknown values in our arrays can throw off the timing a lot, perhaps |
95 // handling NaN values is a lot slower. Anyway, this guy is just meant to put | 95 // handling NaN values is a lot slower. Anyway, this guy is just meant to put |
96 // reasonable values in our arrays. | 96 // reasonable values in our arrays. |
97 template <typename T> void init9(T array[9]) { | 97 template <typename T> void init9(T array[9]) { |
98 SkMWCRandom rand; | 98 SkRandom rand; |
99 for (int i = 0; i < 9; i++) { | 99 for (int i = 0; i < 9; i++) { |
100 array[i] = rand.nextSScalar1(); | 100 array[i] = rand.nextSScalar1(); |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 // Test the performance of setConcat() non-perspective case: | 104 // Test the performance of setConcat() non-perspective case: |
105 // using floating point precision only. | 105 // using floating point precision only. |
106 class FloatConcatMatrixBench : public MatrixBench { | 106 class FloatConcatMatrixBench : public MatrixBench { |
107 public: | 107 public: |
108 FloatConcatMatrixBench(void* p) : INHERITED(p, "concat_floatfloat") { | 108 FloatConcatMatrixBench(void* p) : INHERITED(p, "concat_floatfloat") { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 fMatrix.dirtyMatrixTypeCache(); | 254 fMatrix.dirtyMatrixTypeCache(); |
255 always_do(fMatrix.getType()); | 255 always_do(fMatrix.getType()); |
256 fMatrix.dirtyMatrixTypeCache(); | 256 fMatrix.dirtyMatrixTypeCache(); |
257 always_do(fMatrix.getType()); | 257 always_do(fMatrix.getType()); |
258 fMatrix.dirtyMatrixTypeCache(); | 258 fMatrix.dirtyMatrixTypeCache(); |
259 always_do(fMatrix.getType()); | 259 always_do(fMatrix.getType()); |
260 } | 260 } |
261 private: | 261 private: |
262 SkMatrix fMatrix; | 262 SkMatrix fMatrix; |
263 float fArray[9]; | 263 float fArray[9]; |
264 SkMWCRandom fRnd; | 264 SkRandom fRnd; |
265 typedef MatrixBench INHERITED; | 265 typedef MatrixBench INHERITED; |
266 }; | 266 }; |
267 | 267 |
268 class ScaleTransMixedMatrixBench : public MatrixBench { | 268 class ScaleTransMixedMatrixBench : public MatrixBench { |
269 public: | 269 public: |
270 ScaleTransMixedMatrixBench(void* p) : INHERITED(p, "scaletrans_mixed") { | 270 ScaleTransMixedMatrixBench(void* p) : INHERITED(p, "scaletrans_mixed") { |
271 fMatrix.setAll(fRandom.nextSScalar1(), fRandom.nextSScalar1(), fRandom.n
extSScalar1(), | 271 fMatrix.setAll(fRandom.nextSScalar1(), fRandom.nextSScalar1(), fRandom.n
extSScalar1(), |
272 fRandom.nextSScalar1(), fRandom.nextSScalar1(), fRandom.n
extSScalar1(), | 272 fRandom.nextSScalar1(), fRandom.nextSScalar1(), fRandom.n
extSScalar1(), |
273 fRandom.nextSScalar1(), fRandom.nextSScalar1(), fRandom.n
extSScalar1()); | 273 fRandom.nextSScalar1(), fRandom.nextSScalar1(), fRandom.n
extSScalar1()); |
274 int i; | 274 int i; |
(...skipping 20 matching lines...) Expand all Loading... |
295 dst += 1; | 295 dst += 1; |
296 } while (--count); | 296 } while (--count); |
297 } | 297 } |
298 private: | 298 private: |
299 enum { | 299 enum { |
300 kCount = SkBENCHLOOP(16) | 300 kCount = SkBENCHLOOP(16) |
301 }; | 301 }; |
302 SkMatrix fMatrix; | 302 SkMatrix fMatrix; |
303 SkPoint fSrc [16]; | 303 SkPoint fSrc [16]; |
304 SkPoint fDst [16]; | 304 SkPoint fDst [16]; |
305 SkMWCRandom fRandom; | 305 SkRandom fRandom; |
306 typedef MatrixBench INHERITED; | 306 typedef MatrixBench INHERITED; |
307 }; | 307 }; |
308 | 308 |
309 class ScaleTransDoubleMatrixBench : public MatrixBench { | 309 class ScaleTransDoubleMatrixBench : public MatrixBench { |
310 public: | 310 public: |
311 ScaleTransDoubleMatrixBench(void* p) : INHERITED(p, "scaletrans_double") { | 311 ScaleTransDoubleMatrixBench(void* p) : INHERITED(p, "scaletrans_double") { |
312 init9(fMatrix); | 312 init9(fMatrix); |
313 int i; | 313 int i; |
314 for (i = 0; i < kCount; i++) { | 314 for (i = 0; i < kCount; i++) { |
315 fSrc[i].fX = fRandom.nextSScalar1(); | 315 fSrc[i].fX = fRandom.nextSScalar1(); |
(...skipping 19 matching lines...) Expand all Loading... |
335 dst += 1; | 335 dst += 1; |
336 } while (--count); | 336 } while (--count); |
337 } | 337 } |
338 private: | 338 private: |
339 enum { | 339 enum { |
340 kCount = SkBENCHLOOP(16) | 340 kCount = SkBENCHLOOP(16) |
341 }; | 341 }; |
342 double fMatrix [9]; | 342 double fMatrix [9]; |
343 SkPoint fSrc [16]; | 343 SkPoint fSrc [16]; |
344 SkPoint fDst [16]; | 344 SkPoint fDst [16]; |
345 SkMWCRandom fRandom; | 345 SkRandom fRandom; |
346 typedef MatrixBench INHERITED; | 346 typedef MatrixBench INHERITED; |
347 }; | 347 }; |
348 | 348 |
349 class DecomposeMatrixBench : public MatrixBench { | 349 class DecomposeMatrixBench : public MatrixBench { |
350 public: | 350 public: |
351 DecomposeMatrixBench(void* param) : INHERITED(param, "decompose") {} | 351 DecomposeMatrixBench(void* param) : INHERITED(param, "decompose") {} |
352 | 352 |
353 protected: | 353 protected: |
354 virtual void onPreDraw() { | 354 virtual void onPreDraw() { |
355 for (int i = 0; i < 10; ++i) { | 355 for (int i = 0; i < 10; ++i) { |
356 SkScalar rot0 = (fRandom.nextBool()) ? fRandom.nextRangeF(-180, 180)
: 0.0f; | 356 SkScalar rot0 = (fRandom.nextBool()) ? fRandom.nextRangeF(-180, 180)
: 0.0f; |
357 SkScalar sx = fRandom.nextRangeF(-3000.f, 3000.f); | 357 SkScalar sx = fRandom.nextRangeF(-3000.f, 3000.f); |
358 SkScalar sy = (fRandom.nextBool()) ? fRandom.nextRangeF(-3000.f, 300
0.f) : sx; | 358 SkScalar sy = (fRandom.nextBool()) ? fRandom.nextRangeF(-3000.f, 300
0.f) : sx; |
359 SkScalar rot1 = fRandom.nextRangeF(-180, 180); | 359 SkScalar rot1 = fRandom.nextRangeF(-180, 180); |
360 fMatrix[i].setRotate(rot0); | 360 fMatrix[i].setRotate(rot0); |
361 fMatrix[i].postScale(sx, sy); | 361 fMatrix[i].postScale(sx, sy); |
362 fMatrix[i].postRotate(rot1); | 362 fMatrix[i].postRotate(rot1); |
363 } | 363 } |
364 } | 364 } |
365 virtual void performTest() { | 365 virtual void performTest() { |
366 SkPoint rotation1, scale, rotation2; | 366 SkPoint rotation1, scale, rotation2; |
367 for (int i = 0; i < 10; ++i) { | 367 for (int i = 0; i < 10; ++i) { |
368 (void) SkDecomposeUpper2x2(fMatrix[i], &rotation1, &scale, &rotation
2); | 368 (void) SkDecomposeUpper2x2(fMatrix[i], &rotation1, &scale, &rotation
2); |
369 } | 369 } |
370 } | 370 } |
371 private: | 371 private: |
372 SkMatrix fMatrix[10]; | 372 SkMatrix fMatrix[10]; |
373 SkMWCRandom fRandom; | 373 SkRandom fRandom; |
374 typedef MatrixBench INHERITED; | 374 typedef MatrixBench INHERITED; |
375 }; | 375 }; |
376 | 376 |
377 class InvertMapRectMatrixBench : public MatrixBench { | 377 class InvertMapRectMatrixBench : public MatrixBench { |
378 public: | 378 public: |
379 InvertMapRectMatrixBench(void* param, const char* name, int flags) | 379 InvertMapRectMatrixBench(void* param, const char* name, int flags) |
380 : INHERITED(param, name) | 380 : INHERITED(param, name) |
381 , fFlags(flags) { | 381 , fFlags(flags) { |
382 fMatrix.reset(); | 382 fMatrix.reset(); |
383 fIteration = 0; | 383 fIteration = 0; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 | 468 |
469 DEF_BENCH( return new InvertMapRectMatrixBench(p, | 469 DEF_BENCH( return new InvertMapRectMatrixBench(p, |
470 "invert_maprect_typemask_nonpersp", | 470 "invert_maprect_typemask_nonpersp", |
471 InvertMapRectMatrixBench::kUncachedTypeMask_Flag | | 471 InvertMapRectMatrixBench::kUncachedTypeMask_Flag | |
472 InvertMapRectMatrixBench::kScale_Flag | | 472 InvertMapRectMatrixBench::kScale_Flag | |
473 InvertMapRectMatrixBench::kRotate_Flag | | 473 InvertMapRectMatrixBench::kRotate_Flag | |
474 InvertMapRectMatrixBench::kTranslate_Flag); ) | 474 InvertMapRectMatrixBench::kTranslate_Flag); ) |
475 | 475 |
476 DEF_BENCH( return new ScaleTransMixedMatrixBench(p); ) | 476 DEF_BENCH( return new ScaleTransMixedMatrixBench(p); ) |
477 DEF_BENCH( return new ScaleTransDoubleMatrixBench(p); ) | 477 DEF_BENCH( return new ScaleTransDoubleMatrixBench(p); ) |
OLD | NEW |