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 "Test.h" | 8 #include "Test.h" |
9 #include "SkFloatBits.h" | 9 #include "SkFloatBits.h" |
10 #include "SkFloatingPoint.h" | 10 #include "SkFloatingPoint.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 }; | 41 }; |
42 | 42 |
43 for (size_t i = 0; i < SK_ARRAY_COUNT(gVals); ++i) { | 43 for (size_t i = 0; i < SK_ARRAY_COUNT(gVals); ++i) { |
44 test_floor_value(reporter, gVals[i]); | 44 test_floor_value(reporter, gVals[i]); |
45 // test_floor_value(reporter, -gVals[i]); | 45 // test_floor_value(reporter, -gVals[i]); |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 /////////////////////////////////////////////////////////////////////////////// | 49 /////////////////////////////////////////////////////////////////////////////// |
50 | 50 |
| 51 // test that SkMul16ShiftRound and SkMulDiv255Round return the same result |
| 52 static void test_muldivround(skiatest::Reporter* reporter) { |
| 53 #if 0 |
| 54 // this "complete" test is too slow, so we test a random sampling of it |
| 55 |
| 56 for (int a = 0; a <= 32767; ++a) { |
| 57 for (int b = 0; b <= 32767; ++b) { |
| 58 unsigned prod0 = SkMul16ShiftRound(a, b, 8); |
| 59 unsigned prod1 = SkMulDiv255Round(a, b); |
| 60 SkASSERT(prod0 == prod1); |
| 61 } |
| 62 } |
| 63 #endif |
| 64 |
| 65 SkRandom rand; |
| 66 for (int i = 0; i < 10000; ++i) { |
| 67 unsigned a = rand.nextU() & 0x7FFF; |
| 68 unsigned b = rand.nextU() & 0x7FFF; |
| 69 |
| 70 unsigned prod0 = SkMul16ShiftRound(a, b, 8); |
| 71 unsigned prod1 = SkMulDiv255Round(a, b); |
| 72 |
| 73 REPORTER_ASSERT(reporter, prod0 == prod1); |
| 74 } |
| 75 } |
| 76 |
51 static float float_blend(int src, int dst, float unit) { | 77 static float float_blend(int src, int dst, float unit) { |
52 return dst + (src - dst) * unit; | 78 return dst + (src - dst) * unit; |
53 } | 79 } |
54 | 80 |
55 static int blend31(int src, int dst, int a31) { | 81 static int blend31(int src, int dst, int a31) { |
56 return dst + ((src - dst) * a31 * 2114 >> 16); | 82 return dst + ((src - dst) * a31 * 2114 >> 16); |
57 // return dst + ((src - dst) * a31 * 33 >> 10); | 83 // return dst + ((src - dst) * a31 * 33 >> 10); |
58 } | 84 } |
59 | 85 |
60 static int blend31_slow(int src, int dst, int a31) { | 86 static int blend31_slow(int src, int dst, int a31) { |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 #endif | 614 #endif |
589 | 615 |
590 #ifdef SK_SCALAR_IS_FLOAT | 616 #ifdef SK_SCALAR_IS_FLOAT |
591 test_blend(reporter); | 617 test_blend(reporter); |
592 #endif | 618 #endif |
593 | 619 |
594 if (false) test_floor(reporter); | 620 if (false) test_floor(reporter); |
595 | 621 |
596 // disable for now | 622 // disable for now |
597 if (false) test_blend31(); // avoid bit rot, suppress warning | 623 if (false) test_blend31(); // avoid bit rot, suppress warning |
| 624 |
| 625 test_muldivround(reporter); |
598 } | 626 } |
599 | 627 |
600 #include "TestClassDef.h" | 628 #include "TestClassDef.h" |
601 DEFINE_TESTCLASS("Math", MathTestClass, TestMath) | 629 DEFINE_TESTCLASS("Math", MathTestClass, TestMath) |
OLD | NEW |