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-22 20:17:43 +00:00
|
|
|
#include "Test.h"
|
|
|
|
#include "SkClipStack.h"
|
2011-05-03 16:26:09 +00:00
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRect.h"
|
|
|
|
|
|
|
|
static void test_assign_and_comparison(skiatest::Reporter* reporter) {
|
|
|
|
SkClipStack s;
|
2011-10-12 14:43:27 +00:00
|
|
|
bool doAA = false;
|
2011-05-03 16:26:09 +00:00
|
|
|
|
|
|
|
// Build up a clip stack with a path, an empty clip, and a rect.
|
|
|
|
s.save();
|
|
|
|
SkPath p;
|
|
|
|
p.moveTo(5, 6);
|
|
|
|
p.lineTo(7, 8);
|
|
|
|
p.lineTo(5, 9);
|
|
|
|
p.close();
|
2011-10-12 14:43:27 +00:00
|
|
|
s.clipDevPath(p, SkRegion::kIntersect_Op, doAA);
|
2011-05-03 16:26:09 +00:00
|
|
|
|
|
|
|
s.save();
|
|
|
|
SkRect r = SkRect::MakeLTRB(1, 2, 3, 4);
|
2011-10-12 14:43:27 +00:00
|
|
|
s.clipDevRect(r, SkRegion::kIntersect_Op, doAA);
|
2011-05-03 16:26:09 +00:00
|
|
|
r = SkRect::MakeLTRB(10, 11, 12, 13);
|
2011-10-12 14:43:27 +00:00
|
|
|
s.clipDevRect(r, SkRegion::kIntersect_Op, doAA);
|
2011-05-03 16:26:09 +00:00
|
|
|
|
|
|
|
s.save();
|
|
|
|
r = SkRect::MakeLTRB(14, 15, 16, 17);
|
2011-10-12 14:43:27 +00:00
|
|
|
s.clipDevRect(r, SkRegion::kUnion_Op, doAA);
|
2011-05-03 16:26:09 +00:00
|
|
|
|
|
|
|
// Test that assignment works.
|
|
|
|
SkClipStack copy = s;
|
|
|
|
REPORTER_ASSERT(reporter, s == copy);
|
|
|
|
|
|
|
|
// Test that different save levels triggers not equal.
|
|
|
|
s.restore();
|
|
|
|
REPORTER_ASSERT(reporter, s != copy);
|
|
|
|
|
|
|
|
// Test that an equal, but not copied version is equal.
|
|
|
|
s.save();
|
|
|
|
r = SkRect::MakeLTRB(14, 15, 16, 17);
|
2011-10-12 14:43:27 +00:00
|
|
|
s.clipDevRect(r, SkRegion::kUnion_Op, doAA);
|
2011-05-03 16:26:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, s == copy);
|
|
|
|
|
|
|
|
// Test that a different op on one level triggers not equal.
|
|
|
|
s.restore();
|
|
|
|
s.save();
|
|
|
|
r = SkRect::MakeLTRB(14, 15, 16, 17);
|
2011-10-12 14:43:27 +00:00
|
|
|
s.clipDevRect(r, SkRegion::kIntersect_Op, doAA);
|
2011-05-03 16:26:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, s != copy);
|
|
|
|
|
|
|
|
// Test that different state (clip type) triggers not equal.
|
2012-03-09 16:48:20 +00:00
|
|
|
// NO LONGER VALID: if a path contains only a rect, we turn
|
|
|
|
// it into a bare rect for performance reasons (working
|
|
|
|
// around Chromium/JavaScript bad pattern).
|
|
|
|
/*
|
2011-05-03 16:26:09 +00:00
|
|
|
s.restore();
|
|
|
|
s.save();
|
|
|
|
SkPath rp;
|
|
|
|
rp.addRect(r);
|
2011-10-12 14:43:27 +00:00
|
|
|
s.clipDevPath(rp, SkRegion::kUnion_Op, doAA);
|
2011-05-03 16:26:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, s != copy);
|
2012-03-09 16:48:20 +00:00
|
|
|
*/
|
2011-05-03 16:26:09 +00:00
|
|
|
|
|
|
|
// Test that different rects triggers not equal.
|
|
|
|
s.restore();
|
|
|
|
s.save();
|
|
|
|
r = SkRect::MakeLTRB(24, 25, 26, 27);
|
2011-10-12 14:43:27 +00:00
|
|
|
s.clipDevRect(r, SkRegion::kUnion_Op, doAA);
|
2011-05-03 16:26:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, s != copy);
|
|
|
|
|
|
|
|
// Sanity check
|
|
|
|
s.restore();
|
|
|
|
copy.restore();
|
|
|
|
REPORTER_ASSERT(reporter, s == copy);
|
|
|
|
s.restore();
|
|
|
|
copy.restore();
|
|
|
|
REPORTER_ASSERT(reporter, s == copy);
|
|
|
|
|
|
|
|
// Test that different paths triggers not equal.
|
|
|
|
s.restore();
|
|
|
|
s.save();
|
|
|
|
p.addRect(r);
|
2011-10-12 14:43:27 +00:00
|
|
|
s.clipDevPath(p, SkRegion::kIntersect_Op, doAA);
|
2011-05-03 16:26:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, s != copy);
|
|
|
|
}
|
2011-02-22 20:17:43 +00:00
|
|
|
|
|
|
|
static void assert_count(skiatest::Reporter* reporter, const SkClipStack& stack,
|
|
|
|
int count) {
|
|
|
|
REPORTER_ASSERT(reporter, count == stack.getSaveCount());
|
|
|
|
|
|
|
|
SkClipStack::B2FIter iter(stack);
|
|
|
|
int counter = 0;
|
|
|
|
while (iter.next()) {
|
|
|
|
counter += 1;
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, count == counter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TestClipStack(skiatest::Reporter* reporter) {
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
assert_count(reporter, stack, 0);
|
|
|
|
|
|
|
|
static const SkIRect gRects[] = {
|
|
|
|
{ 0, 0, 100, 100 },
|
|
|
|
{ 25, 25, 125, 125 },
|
|
|
|
{ 0, 0, 1000, 1000 },
|
|
|
|
{ 0, 0, 75, 75 }
|
|
|
|
};
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gRects); i++) {
|
2011-10-12 14:43:27 +00:00
|
|
|
stack.clipDevRect(gRects[i], SkRegion::kIntersect_Op);
|
2011-02-22 20:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// all of the above rects should have been intersected, leaving only 1 rect
|
|
|
|
SkClipStack::B2FIter iter(stack);
|
|
|
|
const SkClipStack::B2FIter::Clip* clip = iter.next();
|
2011-05-17 17:36:59 +00:00
|
|
|
SkRect answer;
|
|
|
|
answer.iset(25, 25, 75, 75);
|
2011-02-22 20:17:43 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, clip);
|
|
|
|
REPORTER_ASSERT(reporter, clip->fRect);
|
|
|
|
REPORTER_ASSERT(reporter, !clip->fPath);
|
|
|
|
REPORTER_ASSERT(reporter, SkRegion::kIntersect_Op == clip->fOp);
|
|
|
|
REPORTER_ASSERT(reporter, *clip->fRect == answer);
|
|
|
|
// now check that we only had one in our iterator
|
|
|
|
REPORTER_ASSERT(reporter, !iter.next());
|
|
|
|
|
|
|
|
stack.reset();
|
|
|
|
assert_count(reporter, stack, 0);
|
2011-05-03 16:26:09 +00:00
|
|
|
|
|
|
|
test_assign_and_comparison(reporter);
|
2011-02-22 20:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "TestClassDef.h"
|
|
|
|
DEFINE_TESTCLASS("ClipStack", TestClipStackClass, TestClipStack)
|