blob: 4afa522de7af06aefc7b92f63e1a1e36aab57f6a [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +00007
vandebo@chromium.org48543272011-02-08 19:28:07 +00008#include "SkColor.h"
9#include "SkXfermode.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000010#include "Test.h"
vandebo@chromium.org48543272011-02-08 19:28:07 +000011
caryclark@google.com42639cd2012-06-06 12:03:39 +000012static SkPMColor bogusXfermodeProc(SkPMColor src, SkPMColor dst) {
vandebo@chromium.org48543272011-02-08 19:28:07 +000013 return 42;
14}
15
reed@google.comc0d4aa22011-04-13 21:12:04 +000016#define ILLEGAL_MODE ((SkXfermode::Mode)-1)
17
vandebo@chromium.org48543272011-02-08 19:28:07 +000018static void test_asMode(skiatest::Reporter* reporter) {
19 for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) {
20 SkXfermode* xfer = SkXfermode::Create((SkXfermode::Mode) mode);
reed@google.comc0d4aa22011-04-13 21:12:04 +000021
22 SkXfermode::Mode reportedMode = ILLEGAL_MODE;
23 REPORTER_ASSERT(reporter, reportedMode != mode);
24
25 // test IsMode
reed@google.com44699382013-10-31 17:28:30 +000026 REPORTER_ASSERT(reporter, SkXfermode::AsMode(xfer, &reportedMode));
reed@google.comc0d4aa22011-04-13 21:12:04 +000027 REPORTER_ASSERT(reporter, reportedMode == mode);
28
29 // repeat that test, but with asMode instead
vandebo@chromium.org48543272011-02-08 19:28:07 +000030 if (xfer) {
reed@google.comc0d4aa22011-04-13 21:12:04 +000031 reportedMode = (SkXfermode::Mode) -1;
32 REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode));
33 REPORTER_ASSERT(reporter, reportedMode == mode);
34 xfer->unref();
35 } else {
rmistry@google.comd6176b02012-08-23 18:14:13 +000036 REPORTER_ASSERT(reporter, SkXfermode::kSrcOver_Mode == mode);
vandebo@chromium.org48543272011-02-08 19:28:07 +000037 }
38 }
39
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000040 SkXfermode* bogusXfer = SkProcXfermode::Create(bogusXfermodeProc);
tfarina@chromium.org06910782013-04-15 22:12:43 +000041 SkXfermode::Mode reportedMode = ILLEGAL_MODE;
vandebo@chromium.org48543272011-02-08 19:28:07 +000042 REPORTER_ASSERT(reporter, !bogusXfer->asMode(&reportedMode));
tfarina@chromium.org06910782013-04-15 22:12:43 +000043 REPORTER_ASSERT(reporter, reportedMode == ILLEGAL_MODE);
reed@google.com44699382013-10-31 17:28:30 +000044 REPORTER_ASSERT(reporter, !SkXfermode::AsMode(bogusXfer, &reportedMode));
tfarina@chromium.org06910782013-04-15 22:12:43 +000045 REPORTER_ASSERT(reporter, reportedMode == ILLEGAL_MODE);
vandebo@chromium.org48543272011-02-08 19:28:07 +000046 bogusXfer->unref();
47}
48
mike@reedtribe.org3565f0f2011-11-17 02:27:26 +000049static void test_IsMode(skiatest::Reporter* reporter) {
50 REPORTER_ASSERT(reporter, SkXfermode::IsMode(NULL,
51 SkXfermode::kSrcOver_Mode));
52
53 for (int i = 0; i <= SkXfermode::kLastMode; ++i) {
54 SkXfermode::Mode mode = (SkXfermode::Mode)i;
rmistry@google.comd6176b02012-08-23 18:14:13 +000055
mike@reedtribe.org3565f0f2011-11-17 02:27:26 +000056 SkXfermode* xfer = SkXfermode::Create(mode);
57 REPORTER_ASSERT(reporter, SkXfermode::IsMode(xfer, mode));
58 SkSafeUnref(xfer);
59
60 if (SkXfermode::kSrcOver_Mode != mode) {
61 REPORTER_ASSERT(reporter, !SkXfermode::IsMode(NULL, mode));
62 }
63 }
64}
65
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000066DEF_TEST(Xfermode, reporter) {
mike@reedtribe.org3565f0f2011-11-17 02:27:26 +000067 test_asMode(reporter);
68 test_IsMode(reporter);
69}