OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkColor.h" | 8 #include "SkColor.h" |
9 #include "SkXfermode.h" | 9 #include "SkXfermode.h" |
10 #include "Test.h" | 10 #include "Test.h" |
11 | 11 |
12 #define ILLEGAL_MODE ((SkXfermode::Mode)-1) | 12 #define ILLEGAL_MODE ((SkXfermode::Mode)-1) |
13 | 13 |
14 static void test_asMode(skiatest::Reporter* reporter) { | 14 static void test_asMode(skiatest::Reporter* reporter) { |
15 for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) { | 15 for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) { |
16 SkXfermode* xfer = SkXfermode::Create((SkXfermode::Mode) mode); | 16 auto xfer = SkXfermode::Make((SkXfermode::Mode) mode); |
17 | 17 |
18 SkXfermode::Mode reportedMode = ILLEGAL_MODE; | 18 SkXfermode::Mode reportedMode = ILLEGAL_MODE; |
19 REPORTER_ASSERT(reporter, reportedMode != mode); | 19 REPORTER_ASSERT(reporter, reportedMode != mode); |
20 | 20 |
21 // test IsMode | 21 // test IsMode |
22 REPORTER_ASSERT(reporter, SkXfermode::AsMode(xfer, &reportedMode)); | 22 REPORTER_ASSERT(reporter, SkXfermode::AsMode(xfer, &reportedMode)); |
23 REPORTER_ASSERT(reporter, reportedMode == mode); | 23 REPORTER_ASSERT(reporter, reportedMode == mode); |
24 | 24 |
25 // repeat that test, but with asMode instead | 25 // repeat that test, but with asMode instead |
26 if (xfer) { | 26 if (xfer) { |
27 reportedMode = (SkXfermode::Mode) -1; | 27 reportedMode = (SkXfermode::Mode) -1; |
28 REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode)); | 28 REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode)); |
29 REPORTER_ASSERT(reporter, reportedMode == mode); | 29 REPORTER_ASSERT(reporter, reportedMode == mode); |
30 xfer->unref(); | |
31 } else { | 30 } else { |
32 REPORTER_ASSERT(reporter, SkXfermode::kSrcOver_Mode == mode); | 31 REPORTER_ASSERT(reporter, SkXfermode::kSrcOver_Mode == mode); |
33 } | 32 } |
34 } | 33 } |
35 } | 34 } |
36 | 35 |
37 static void test_IsMode(skiatest::Reporter* reporter) { | 36 static void test_IsMode(skiatest::Reporter* reporter) { |
38 REPORTER_ASSERT(reporter, SkXfermode::IsMode(nullptr, | 37 REPORTER_ASSERT(reporter, SkXfermode::IsMode(nullptr, |
39 SkXfermode::kSrcOver_Mode)); | 38 SkXfermode::kSrcOver_Mode)); |
40 | 39 |
41 for (int i = 0; i <= SkXfermode::kLastMode; ++i) { | 40 for (int i = 0; i <= SkXfermode::kLastMode; ++i) { |
42 SkXfermode::Mode mode = (SkXfermode::Mode)i; | 41 SkXfermode::Mode mode = (SkXfermode::Mode)i; |
43 | 42 |
44 SkXfermode* xfer = SkXfermode::Create(mode); | 43 auto xfer = SkXfermode::Make(mode); |
45 REPORTER_ASSERT(reporter, SkXfermode::IsMode(xfer, mode)); | 44 REPORTER_ASSERT(reporter, SkXfermode::IsMode(xfer, mode)); |
46 SkSafeUnref(xfer); | |
47 | 45 |
48 if (SkXfermode::kSrcOver_Mode != mode) { | 46 if (SkXfermode::kSrcOver_Mode != mode) { |
49 REPORTER_ASSERT(reporter, !SkXfermode::IsMode(nullptr, mode)); | 47 REPORTER_ASSERT(reporter, !SkXfermode::IsMode(nullptr, mode)); |
50 } | 48 } |
51 } | 49 } |
52 } | 50 } |
53 | 51 |
54 DEF_TEST(Xfermode, reporter) { | 52 DEF_TEST(Xfermode, reporter) { |
55 test_asMode(reporter); | 53 test_asMode(reporter); |
56 test_IsMode(reporter); | 54 test_IsMode(reporter); |
57 } | 55 } |
OLD | NEW |