| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 4 * | 3 * |
| 5 * 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 |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 7 |
| 8 #include "Test.h" | 8 #include "Test.h" |
| 9 #include "TestClassDef.h" |
| 9 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 10 #include "SkXfermode.h" | 11 #include "SkXfermode.h" |
| 11 | 12 |
| 12 // our std SkAlpha255To256 | 13 // our std SkAlpha255To256 |
| 13 static int test_srcover0(unsigned dst, unsigned alpha) { | 14 static int test_srcover0(unsigned dst, unsigned alpha) { |
| 14 return alpha + SkAlphaMul(dst, SkAlpha255To256(255 - alpha)); | 15 return alpha + SkAlphaMul(dst, SkAlpha255To256(255 - alpha)); |
| 15 } | 16 } |
| 16 | 17 |
| 17 // faster hack +1 | 18 // faster hack +1 |
| 18 static int test_srcover1(unsigned dst, unsigned alpha) { | 19 static int test_srcover1(unsigned dst, unsigned alpha) { |
| 19 return alpha + SkAlphaMul(dst, 256 - alpha); | 20 return alpha + SkAlphaMul(dst, 256 - alpha); |
| 20 } | 21 } |
| 21 | 22 |
| 22 // slower "correct" | 23 // slower "correct" |
| 23 static int test_srcover2(unsigned dst, unsigned alpha) { | 24 static int test_srcover2(unsigned dst, unsigned alpha) { |
| 24 return alpha + SkMulDiv255Round(dst, 255 - alpha); | 25 return alpha + SkMulDiv255Round(dst, 255 - alpha); |
| 25 } | 26 } |
| 26 | 27 |
| 27 static void test_srcover_hack(skiatest::Reporter* reporter) { | 28 DEF_TEST(SrcOver, reporter) { |
| 28 /* Here's the idea. Can we ensure that when we blend on top of an opaque | 29 /* Here's the idea. Can we ensure that when we blend on top of an opaque |
| 29 dst, that the result always stay's opaque (i.e. exactly 255)? | 30 dst, that the result always stay's opaque (i.e. exactly 255)? |
| 30 */ | 31 */ |
| 31 | 32 |
| 32 unsigned i; | 33 unsigned i; |
| 33 int opaqueCounter0 = 0; | 34 int opaqueCounter0 = 0; |
| 34 int opaqueCounter1 = 0; | 35 int opaqueCounter1 = 0; |
| 35 int opaqueCounter2 = 0; | 36 int opaqueCounter2 = 0; |
| 36 for (i = 0; i <= 255; i++) { | 37 for (i = 0; i <= 255; i++) { |
| 37 unsigned result0 = test_srcover0(0xFF, i); | 38 unsigned result0 = test_srcover0(0xFF, i); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 67 #if 0 | 68 #if 0 |
| 68 // this shows where r1 (faster) differs from r2 (more exact) | 69 // this shows where r1 (faster) differs from r2 (more exact) |
| 69 if (r1 != r2) { | 70 if (r1 != r2) { |
| 70 SkDebugf("--- dst=%d i=%d r1=%d r2=%d exact=%g\n", | 71 SkDebugf("--- dst=%d i=%d r1=%d r2=%d exact=%g\n", |
| 71 dst, i, r1, r2, i + dst - dst*i/255.0f); | 72 dst, i, r1, r2, i + dst - dst*i/255.0f); |
| 72 } | 73 } |
| 73 #endif | 74 #endif |
| 74 } | 75 } |
| 75 } | 76 } |
| 76 } | 77 } |
| 77 | |
| 78 #include "TestClassDef.h" | |
| 79 DEFINE_TESTCLASS("SrcOver", SrcOverTestClass, test_srcover_hack) | |
| OLD | NEW |