aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-17 20:14:52 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-17 20:14:52 +0000
commita513efba950b5f66740c3721bbfc4ad51ae91689 (patch)
treedad36b7b59718f4513c907f9d65060a7822449a2
parent636d87a3f411507020a21c6b0641da795eb5d275 (diff)
add missing file
git-svn-id: http://skia.googlecode.com/svn/trunk@11332 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--tests/DeviceLooperTest.cpp141
1 files changed, 141 insertions, 0 deletions
diff --git a/tests/DeviceLooperTest.cpp b/tests/DeviceLooperTest.cpp
new file mode 100644
index 0000000000..1520900614
--- /dev/null
+++ b/tests/DeviceLooperTest.cpp
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Test.h"
+#include "SkDeviceLooper.h"
+#include "SkRasterClip.h"
+
+static void make_bm(SkBitmap* bm, int w, int h) {
+ bm->setConfig(SkBitmap::kA8_Config, w, h);
+ bm->allocPixels();
+}
+
+static bool equal(const SkRasterClip& a, const SkRasterClip& b) {
+ if (a.isBW()) {
+ return b.isBW() && a.bwRgn() == b.bwRgn();
+ } else {
+ return a.isAA() && a.aaRgn() == b.aaRgn();
+ }
+}
+
+static void test_simple(skiatest::Reporter* reporter) {
+ struct {
+ SkISize fDevSize;
+ SkIRect fRCBounds;
+ SkIRect fRect;
+ } const gRec[] = {
+ { { 4000, 10 }, { 0, 0, 4000, 10 }, { 0, 0, 4000, 4000 } },
+ { { 10, 4000 }, { 0, 0, 10, 4000 }, { 0, 0, 4000, 4000 } },
+ // very large devce, small rect
+ { { 32000, 10 }, { 0, 0, 32000, 10 }, { 0, 0, 4000, 4000 } },
+ { { 10, 32000 }, { 0, 0, 10, 32000 }, { 0, 0, 4000, 4000 } },
+ // very large device, small clip
+ { { 32000, 10 }, { 0, 0, 4000, 10 }, { 0, 0, 32000, 32000 } },
+ { { 10, 32000 }, { 0, 0, 10, 4000 }, { 0, 0, 32000, 32000 } },
+ };
+
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
+ SkBitmap bitmap;
+ make_bm(&bitmap, gRec[i].fDevSize.width(), gRec[i].fDevSize.height());
+
+ SkRasterClip rc(gRec[i].fRCBounds);
+
+ for (int aa = 0; aa <= 1; ++aa) {
+ SkDeviceLooper looper(bitmap, rc, gRec[i].fRect, SkToBool(aa));
+
+ bool valid = looper.next();
+ REPORTER_ASSERT(reporter, valid);
+ if (valid) {
+ REPORTER_ASSERT(reporter, looper.getBitmap().width() == bitmap.width());
+ REPORTER_ASSERT(reporter, looper.getBitmap().height() == bitmap.height());
+ REPORTER_ASSERT(reporter, equal(looper.getRC(), rc));
+
+ REPORTER_ASSERT(reporter, !looper.next());
+ }
+ }
+ // test that a rect that doesn't intersect returns no loops
+ {
+ SkIRect r = rc.getBounds();
+ r.offset(r.width(), 0);
+ SkDeviceLooper looper(bitmap, rc, r, false);
+ REPORTER_ASSERT(reporter, !looper.next());
+ }
+ }
+}
+
+// mask-bits are interpreted as the areas where the clip is visible
+// [ 0x01 0x02 ]
+// [ 0x04 0x08 ]
+//
+static void make_rgn(SkRegion* rgn, int w, int h, unsigned mask) {
+ SkASSERT(SkAlign2(w));
+ SkASSERT(SkAlign2(h));
+ w >>= 1;
+ h >>= 1;
+ const SkIRect baseR = SkIRect::MakeWH(w, h);
+
+ int bit = 1;
+ for (int y = 0; y <= 1; ++y) {
+ for (int x = 0; x <= 1; ++x) {
+ if (mask & bit) {
+ SkIRect r = baseR;
+ r.offset(x * w, y * h);
+ rgn->op(r, SkRegion::kUnion_Op);
+ }
+ bit <<= 1;
+ }
+ }
+}
+
+static void test_complex(skiatest::Reporter* reporter) {
+ // choose size values that will result in 4 quadrants, given fAA setting
+ const int BW_SIZE = 17 * 1000;
+ const int AA_SIZE = 7 * 1000;
+
+ struct {
+ SkISize fSize;
+ bool fAA;
+ } const gRec[] = {
+ { { BW_SIZE, BW_SIZE }, false },
+ { { AA_SIZE, AA_SIZE }, true },
+ };
+
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
+ const int w = gRec[i].fSize.width();
+ const int h = gRec[i].fSize.height();
+
+ SkBitmap bitmap;
+ make_bm(&bitmap, w, h);
+
+ const SkIRect rect = SkIRect::MakeWH(w, h);
+
+ // mask-bits are interpreted as the areas where the clip is visible
+ // [ 0x01 0x02 ]
+ // [ 0x04 0x08 ]
+ //
+ for (int mask = 0; mask <= 15; ++mask) {
+ SkRegion rgn;
+ make_rgn(&rgn, w, h, mask);
+
+ SkRasterClip rc;
+ rc.op(rgn, SkRegion::kReplace_Op);
+
+ SkDeviceLooper looper(bitmap, rc, rect, gRec[i].fAA);
+ while (looper.next()) {
+ REPORTER_ASSERT(reporter, !looper.getRC().isEmpty());
+ }
+ }
+ }
+}
+
+static void TestDeviceLooper(skiatest::Reporter* reporter) {
+ test_simple(reporter);
+ test_complex(reporter);
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("DeviceLooper", DeviceLooperClass, TestDeviceLooper)