ClipStackTest.cpp revision bdee9fc778d4387d805d717f2cd7fc7074991fdb
1bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com#include "Test.h" 2bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com#include "SkClipStack.h" 3bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com 4bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.comstatic void assert_count(skiatest::Reporter* reporter, const SkClipStack& stack, 5bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com int count) { 6bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com REPORTER_ASSERT(reporter, count == stack.getSaveCount()); 7bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com 8bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com SkClipStack::B2FIter iter(stack); 9bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com int counter = 0; 10bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com while (iter.next()) { 11bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com counter += 1; 12bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com } 13bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com REPORTER_ASSERT(reporter, count == counter); 14bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com} 15bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com 16bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.comstatic void TestClipStack(skiatest::Reporter* reporter) { 17bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com SkClipStack stack; 18bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com 19bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com assert_count(reporter, stack, 0); 20bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com 21bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com static const SkIRect gRects[] = { 22bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com { 0, 0, 100, 100 }, 23bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com { 25, 25, 125, 125 }, 24bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com { 0, 0, 1000, 1000 }, 25bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com { 0, 0, 75, 75 } 26bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com }; 27bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com for (size_t i = 0; i < SK_ARRAY_COUNT(gRects); i++) { 28bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com stack.clipDevRect(gRects[i]); 29bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com } 30bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com 31bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com // all of the above rects should have been intersected, leaving only 1 rect 32bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com SkClipStack::B2FIter iter(stack); 33bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com const SkClipStack::B2FIter::Clip* clip = iter.next(); 34bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com const SkRect answer = { 25, 25, 75, 75 }; 35bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com 36bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com REPORTER_ASSERT(reporter, clip); 37bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com REPORTER_ASSERT(reporter, clip->fRect); 38bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com REPORTER_ASSERT(reporter, !clip->fPath); 39bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com REPORTER_ASSERT(reporter, SkRegion::kIntersect_Op == clip->fOp); 40bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com REPORTER_ASSERT(reporter, *clip->fRect == answer); 41bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com // now check that we only had one in our iterator 42bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com REPORTER_ASSERT(reporter, !iter.next()); 43bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com 44bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com stack.reset(); 45bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com assert_count(reporter, stack, 0); 46bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com} 47bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com 48bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.com#include "TestClassDef.h" 49bdee9fc778d4387d805d717f2cd7fc7074991fdbreed@google.comDEFINE_TESTCLASS("ClipStack", TestClipStackClass, TestClipStack) 50