2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2011-02-08 19:28:07 +00:00
|
|
|
#include "Test.h"
|
|
|
|
#include "SkColor.h"
|
|
|
|
#include "SkXfermode.h"
|
|
|
|
|
2012-06-06 12:03:39 +00:00
|
|
|
static SkPMColor bogusXfermodeProc(SkPMColor src, SkPMColor dst) {
|
2011-02-08 19:28:07 +00:00
|
|
|
return 42;
|
|
|
|
}
|
|
|
|
|
2011-04-13 21:12:04 +00:00
|
|
|
#define ILLEGAL_MODE ((SkXfermode::Mode)-1)
|
|
|
|
|
2011-02-08 19:28:07 +00:00
|
|
|
static void test_asMode(skiatest::Reporter* reporter) {
|
|
|
|
for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) {
|
|
|
|
SkXfermode* xfer = SkXfermode::Create((SkXfermode::Mode) mode);
|
2011-04-13 21:12:04 +00:00
|
|
|
|
|
|
|
SkXfermode::Mode reportedMode = ILLEGAL_MODE;
|
|
|
|
REPORTER_ASSERT(reporter, reportedMode != mode);
|
|
|
|
|
|
|
|
// test IsMode
|
2013-10-31 17:28:30 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkXfermode::AsMode(xfer, &reportedMode));
|
2011-04-13 21:12:04 +00:00
|
|
|
REPORTER_ASSERT(reporter, reportedMode == mode);
|
|
|
|
|
|
|
|
// repeat that test, but with asMode instead
|
2011-02-08 19:28:07 +00:00
|
|
|
if (xfer) {
|
2011-04-13 21:12:04 +00:00
|
|
|
reportedMode = (SkXfermode::Mode) -1;
|
|
|
|
REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode));
|
|
|
|
REPORTER_ASSERT(reporter, reportedMode == mode);
|
|
|
|
xfer->unref();
|
|
|
|
} else {
|
2012-08-23 18:14:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkXfermode::kSrcOver_Mode == mode);
|
2011-02-08 19:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkXfermode* bogusXfer = new SkProcXfermode(bogusXfermodeProc);
|
2013-04-15 22:12:43 +00:00
|
|
|
SkXfermode::Mode reportedMode = ILLEGAL_MODE;
|
2011-02-08 19:28:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, !bogusXfer->asMode(&reportedMode));
|
2013-04-15 22:12:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, reportedMode == ILLEGAL_MODE);
|
2013-10-31 17:28:30 +00:00
|
|
|
REPORTER_ASSERT(reporter, !SkXfermode::AsMode(bogusXfer, &reportedMode));
|
2013-04-15 22:12:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, reportedMode == ILLEGAL_MODE);
|
2011-02-08 19:28:07 +00:00
|
|
|
bogusXfer->unref();
|
|
|
|
}
|
|
|
|
|
2011-11-17 02:27:26 +00:00
|
|
|
static void test_IsMode(skiatest::Reporter* reporter) {
|
|
|
|
REPORTER_ASSERT(reporter, SkXfermode::IsMode(NULL,
|
|
|
|
SkXfermode::kSrcOver_Mode));
|
|
|
|
|
|
|
|
for (int i = 0; i <= SkXfermode::kLastMode; ++i) {
|
|
|
|
SkXfermode::Mode mode = (SkXfermode::Mode)i;
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-11-17 02:27:26 +00:00
|
|
|
SkXfermode* xfer = SkXfermode::Create(mode);
|
|
|
|
REPORTER_ASSERT(reporter, SkXfermode::IsMode(xfer, mode));
|
|
|
|
SkSafeUnref(xfer);
|
|
|
|
|
|
|
|
if (SkXfermode::kSrcOver_Mode != mode) {
|
|
|
|
REPORTER_ASSERT(reporter, !SkXfermode::IsMode(NULL, mode));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_xfermodes(skiatest::Reporter* reporter) {
|
|
|
|
test_asMode(reporter);
|
|
|
|
test_IsMode(reporter);
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:28:07 +00:00
|
|
|
#include "TestClassDef.h"
|
2011-11-17 02:27:26 +00:00
|
|
|
DEFINE_TESTCLASS("Xfermode", XfermodeTestClass, test_xfermodes)
|