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.
|
|
|
|
*/
|
2013-12-12 21:11:12 +00:00
|
|
|
|
2011-02-22 20:17:43 +00:00
|
|
|
#include "Test.h"
|
2012-11-26 21:38:37 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-12-05 22:26:11 +00:00
|
|
|
#include "GrReducedClip.h"
|
2012-11-26 21:38:37 +00:00
|
|
|
#endif
|
2011-02-22 20:17:43 +00:00
|
|
|
#include "SkClipStack.h"
|
2011-05-03 16:26:09 +00:00
|
|
|
#include "SkPath.h"
|
2012-11-26 21:19:43 +00:00
|
|
|
#include "SkRandom.h"
|
2011-05-03 16:26:09 +00:00
|
|
|
#include "SkRect.h"
|
2012-11-26 21:19:43 +00:00
|
|
|
#include "SkRegion.h"
|
2012-07-20 15:33:18 +00:00
|
|
|
|
2011-05-03 16:26:09 +00:00
|
|
|
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
|
|
|
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == s.getSaveCount());
|
|
|
|
|
2011-05-03 16:26:09 +00:00
|
|
|
// Build up a clip stack with a path, an empty clip, and a rect.
|
|
|
|
s.save();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == s.getSaveCount());
|
|
|
|
|
2011-05-03 16:26:09 +00:00
|
|
|
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();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == s.getSaveCount());
|
|
|
|
|
2011-05-03 16:26:09 +00:00
|
|
|
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();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 3 == s.getSaveCount());
|
|
|
|
|
2011-05-03 16:26:09 +00:00
|
|
|
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();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == s.getSaveCount());
|
2011-05-03 16:26:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, s != copy);
|
|
|
|
|
|
|
|
// Test that an equal, but not copied version is equal.
|
|
|
|
s.save();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 3 == s.getSaveCount());
|
2011-05-03 16:26:09 +00:00
|
|
|
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();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == s.getSaveCount());
|
2011-05-03 16:26:09 +00:00
|
|
|
s.save();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 3 == s.getSaveCount());
|
2011-05-03 16:26:09 +00:00
|
|
|
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);
|
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
// Test that version constructed with rect-path rather than a rect is still considered equal.
|
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);
|
2014-02-16 13:25:24 +00:00
|
|
|
REPORTER_ASSERT(reporter, s == copy);
|
2011-05-03 16:26:09 +00:00
|
|
|
|
|
|
|
// Test that different rects triggers not equal.
|
|
|
|
s.restore();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == s.getSaveCount());
|
2011-05-03 16:26:09 +00:00
|
|
|
s.save();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 3 == s.getSaveCount());
|
|
|
|
|
2011-05-03 16:26:09 +00:00
|
|
|
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();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == s.getSaveCount());
|
|
|
|
|
2011-05-03 16:26:09 +00:00
|
|
|
copy.restore();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == copy.getSaveCount());
|
2011-05-03 16:26:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, s == copy);
|
|
|
|
s.restore();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == s.getSaveCount());
|
2011-05-03 16:26:09 +00:00
|
|
|
copy.restore();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == copy.getSaveCount());
|
2011-05-03 16:26:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, s == copy);
|
|
|
|
|
|
|
|
// Test that different paths triggers not equal.
|
|
|
|
s.restore();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == s.getSaveCount());
|
2011-05-03 16:26:09 +00:00
|
|
|
s.save();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == s.getSaveCount());
|
|
|
|
|
2011-05-03 16:26:09 +00:00
|
|
|
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) {
|
2012-07-20 15:33:18 +00:00
|
|
|
SkClipStack::B2TIter iter(stack);
|
2011-02-22 20:17:43 +00:00
|
|
|
int counter = 0;
|
|
|
|
while (iter.next()) {
|
|
|
|
counter += 1;
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, count == counter);
|
|
|
|
}
|
|
|
|
|
2012-08-02 12:49:00 +00:00
|
|
|
// Exercise the SkClipStack's bottom to top and bidirectional iterators
|
|
|
|
// (including the skipToTopmost functionality)
|
2012-07-20 15:33:18 +00:00
|
|
|
static void test_iterators(skiatest::Reporter* reporter) {
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
static const SkRect gRects[] = {
|
|
|
|
{ 0, 0, 40, 40 },
|
|
|
|
{ 60, 0, 100, 40 },
|
|
|
|
{ 0, 60, 40, 100 },
|
|
|
|
{ 60, 60, 100, 100 }
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gRects); i++) {
|
|
|
|
// the union op will prevent these from being fused together
|
|
|
|
stack.clipDevRect(gRects[i], SkRegion::kUnion_Op, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_count(reporter, stack, 4);
|
|
|
|
|
|
|
|
// bottom to top iteration
|
|
|
|
{
|
2015-08-27 14:41:13 +00:00
|
|
|
const SkClipStack::Element* element = nullptr;
|
2012-07-20 15:33:18 +00:00
|
|
|
|
|
|
|
SkClipStack::B2TIter iter(stack);
|
|
|
|
int i;
|
|
|
|
|
2012-12-04 14:06:06 +00:00
|
|
|
for (i = 0, element = iter.next(); element; ++i, element = iter.next()) {
|
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::Element::kRect_Type == element->getType());
|
|
|
|
REPORTER_ASSERT(reporter, element->getRect() == gRects[i]);
|
2012-07-20 15:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkASSERT(i == 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
// top to bottom iteration
|
|
|
|
{
|
2015-08-27 14:41:13 +00:00
|
|
|
const SkClipStack::Element* element = nullptr;
|
2012-07-20 15:33:18 +00:00
|
|
|
|
|
|
|
SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart);
|
|
|
|
int i;
|
|
|
|
|
2012-12-04 14:06:06 +00:00
|
|
|
for (i = 3, element = iter.prev(); element; --i, element = iter.prev()) {
|
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::Element::kRect_Type == element->getType());
|
|
|
|
REPORTER_ASSERT(reporter, element->getRect() == gRects[i]);
|
2012-07-20 15:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkASSERT(i == -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// skipToTopmost
|
|
|
|
{
|
2015-08-27 14:41:13 +00:00
|
|
|
const SkClipStack::Element* element = nullptr;
|
2012-07-20 15:33:18 +00:00
|
|
|
|
|
|
|
SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart);
|
|
|
|
|
2012-12-04 14:06:06 +00:00
|
|
|
element = iter.skipToTopmost(SkRegion::kUnion_Op);
|
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::Element::kRect_Type == element->getType());
|
|
|
|
REPORTER_ASSERT(reporter, element->getRect() == gRects[3]);
|
2012-07-20 15:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 12:49:00 +00:00
|
|
|
// Exercise the SkClipStack's getConservativeBounds computation
|
2014-02-16 13:25:24 +00:00
|
|
|
static void test_bounds(skiatest::Reporter* reporter, SkClipStack::Element::Type primType) {
|
2012-07-24 13:54:00 +00:00
|
|
|
static const int gNumCases = 20;
|
|
|
|
static const SkRect gAnswerRectsBW[gNumCases] = {
|
|
|
|
// A op B
|
|
|
|
{ 40, 40, 50, 50 },
|
|
|
|
{ 10, 10, 50, 50 },
|
|
|
|
{ 10, 10, 80, 80 },
|
|
|
|
{ 10, 10, 80, 80 },
|
|
|
|
{ 40, 40, 80, 80 },
|
|
|
|
|
|
|
|
// invA op B
|
|
|
|
{ 40, 40, 80, 80 },
|
|
|
|
{ 0, 0, 100, 100 },
|
|
|
|
{ 0, 0, 100, 100 },
|
|
|
|
{ 0, 0, 100, 100 },
|
|
|
|
{ 40, 40, 50, 50 },
|
|
|
|
|
|
|
|
// A op invB
|
|
|
|
{ 10, 10, 50, 50 },
|
|
|
|
{ 40, 40, 50, 50 },
|
|
|
|
{ 0, 0, 100, 100 },
|
|
|
|
{ 0, 0, 100, 100 },
|
|
|
|
{ 0, 0, 100, 100 },
|
|
|
|
|
|
|
|
// invA op invB
|
|
|
|
{ 0, 0, 100, 100 },
|
|
|
|
{ 40, 40, 80, 80 },
|
|
|
|
{ 0, 0, 100, 100 },
|
|
|
|
{ 10, 10, 80, 80 },
|
|
|
|
{ 10, 10, 50, 50 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const SkRegion::Op gOps[] = {
|
|
|
|
SkRegion::kIntersect_Op,
|
|
|
|
SkRegion::kDifference_Op,
|
|
|
|
SkRegion::kUnion_Op,
|
|
|
|
SkRegion::kXOR_Op,
|
|
|
|
SkRegion::kReverseDifference_Op
|
|
|
|
};
|
|
|
|
|
|
|
|
SkRect rectA, rectB;
|
|
|
|
|
|
|
|
rectA.iset(10, 10, 50, 50);
|
|
|
|
rectB.iset(40, 40, 80, 80);
|
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
SkRRect rrectA, rrectB;
|
|
|
|
rrectA.setOval(rectA);
|
|
|
|
rrectB.setRectXY(rectB, SkIntToScalar(1), SkIntToScalar(2));
|
2012-07-24 13:54:00 +00:00
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
SkPath pathA, pathB;
|
|
|
|
|
|
|
|
pathA.addRoundRect(rectA, SkIntToScalar(5), SkIntToScalar(5));
|
|
|
|
pathB.addRoundRect(rectB, SkIntToScalar(5), SkIntToScalar(5));
|
2012-07-24 13:54:00 +00:00
|
|
|
|
|
|
|
SkClipStack stack;
|
2012-07-31 15:18:21 +00:00
|
|
|
SkRect devClipBound;
|
2012-07-24 22:07:50 +00:00
|
|
|
bool isIntersectionOfRects = false;
|
2012-07-24 13:54:00 +00:00
|
|
|
|
|
|
|
int testCase = 0;
|
2014-02-16 13:25:24 +00:00
|
|
|
int numBitTests = SkClipStack::Element::kPath_Type == primType ? 4 : 1;
|
2012-07-24 22:07:50 +00:00
|
|
|
for (int invBits = 0; invBits < numBitTests; ++invBits) {
|
2012-07-24 13:54:00 +00:00
|
|
|
for (size_t op = 0; op < SK_ARRAY_COUNT(gOps); ++op) {
|
|
|
|
|
|
|
|
stack.save();
|
|
|
|
bool doInvA = SkToBool(invBits & 1);
|
|
|
|
bool doInvB = SkToBool(invBits & 2);
|
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
pathA.setFillType(doInvA ? SkPath::kInverseEvenOdd_FillType :
|
2012-07-24 13:54:00 +00:00
|
|
|
SkPath::kEvenOdd_FillType);
|
2014-02-16 13:25:24 +00:00
|
|
|
pathB.setFillType(doInvB ? SkPath::kInverseEvenOdd_FillType :
|
2012-07-24 13:54:00 +00:00
|
|
|
SkPath::kEvenOdd_FillType);
|
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
switch (primType) {
|
|
|
|
case SkClipStack::Element::kEmpty_Type:
|
|
|
|
SkDEBUGFAIL("Don't call this with kEmpty.");
|
|
|
|
break;
|
|
|
|
case SkClipStack::Element::kRect_Type:
|
|
|
|
stack.clipDevRect(rectA, SkRegion::kIntersect_Op, false);
|
|
|
|
stack.clipDevRect(rectB, gOps[op], false);
|
|
|
|
break;
|
|
|
|
case SkClipStack::Element::kRRect_Type:
|
|
|
|
stack.clipDevRRect(rrectA, SkRegion::kIntersect_Op, false);
|
|
|
|
stack.clipDevRRect(rrectB, gOps[op], false);
|
|
|
|
break;
|
|
|
|
case SkClipStack::Element::kPath_Type:
|
|
|
|
stack.clipDevPath(pathA, SkRegion::kIntersect_Op, false);
|
|
|
|
stack.clipDevPath(pathB, gOps[op], false);
|
|
|
|
break;
|
2012-07-24 22:07:50 +00:00
|
|
|
}
|
2012-07-24 13:54:00 +00:00
|
|
|
|
2012-07-26 18:39:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, !stack.isWideOpen());
|
2013-11-05 15:03:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID != stack.getTopmostGenID());
|
2012-07-26 18:39:13 +00:00
|
|
|
|
2012-07-31 15:18:21 +00:00
|
|
|
stack.getConservativeBounds(0, 0, 100, 100, &devClipBound,
|
2012-07-24 22:07:50 +00:00
|
|
|
&isIntersectionOfRects);
|
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
if (SkClipStack::Element::kRect_Type == primType) {
|
2012-08-23 18:14:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, isIntersectionOfRects ==
|
2012-07-24 22:07:50 +00:00
|
|
|
(gOps[op] == SkRegion::kIntersect_Op));
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, !isIntersectionOfRects);
|
|
|
|
}
|
2012-07-24 13:54:00 +00:00
|
|
|
|
|
|
|
SkASSERT(testCase < gNumCases);
|
2012-07-31 15:18:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, devClipBound == gAnswerRectsBW[testCase]);
|
2012-07-24 13:54:00 +00:00
|
|
|
++testCase;
|
|
|
|
|
|
|
|
stack.restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-26 18:39:13 +00:00
|
|
|
// Test out 'isWideOpen' entry point
|
|
|
|
static void test_isWideOpen(skiatest::Reporter* reporter) {
|
2013-11-05 15:03:08 +00:00
|
|
|
{
|
|
|
|
// Empty stack is wide open. Wide open stack means that gen id is wide open.
|
|
|
|
SkClipStack stack;
|
|
|
|
REPORTER_ASSERT(reporter, stack.isWideOpen());
|
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID());
|
|
|
|
}
|
2012-07-26 18:39:13 +00:00
|
|
|
|
|
|
|
SkRect rectA, rectB;
|
|
|
|
|
|
|
|
rectA.iset(10, 10, 40, 40);
|
|
|
|
rectB.iset(50, 50, 80, 80);
|
|
|
|
|
|
|
|
// Stack should initially be wide open
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, stack.isWideOpen());
|
2013-11-05 15:03:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID());
|
2012-07-26 18:39:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test out case where the user specifies a union that includes everything
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
SkPath clipA, clipB;
|
|
|
|
|
|
|
|
clipA.addRoundRect(rectA, SkIntToScalar(5), SkIntToScalar(5));
|
|
|
|
clipA.setFillType(SkPath::kInverseEvenOdd_FillType);
|
|
|
|
|
|
|
|
clipB.addRoundRect(rectB, SkIntToScalar(5), SkIntToScalar(5));
|
|
|
|
clipB.setFillType(SkPath::kInverseEvenOdd_FillType);
|
|
|
|
|
|
|
|
stack.clipDevPath(clipA, SkRegion::kReplace_Op, false);
|
|
|
|
stack.clipDevPath(clipB, SkRegion::kUnion_Op, false);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, stack.isWideOpen());
|
2013-11-05 15:03:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID());
|
2012-07-26 18:39:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test out union w/ a wide open clip
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
stack.clipDevRect(rectA, SkRegion::kUnion_Op, false);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, stack.isWideOpen());
|
2013-11-05 15:03:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID());
|
2012-07-26 18:39:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test out empty difference from a wide open clip
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
SkRect emptyRect;
|
|
|
|
emptyRect.setEmpty();
|
|
|
|
|
|
|
|
stack.clipDevRect(emptyRect, SkRegion::kDifference_Op, false);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, stack.isWideOpen());
|
2013-11-05 15:03:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID());
|
2012-07-26 18:39:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test out return to wide open
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
stack.save();
|
|
|
|
|
|
|
|
stack.clipDevRect(rectA, SkRegion::kReplace_Op, false);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, !stack.isWideOpen());
|
2013-11-05 15:03:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID != stack.getTopmostGenID());
|
2012-07-26 18:39:13 +00:00
|
|
|
|
|
|
|
stack.restore();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, stack.isWideOpen());
|
2013-11-05 15:03:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID());
|
2012-07-26 18:39:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-05 17:40:04 +00:00
|
|
|
static int count(const SkClipStack& stack) {
|
2012-08-02 12:49:00 +00:00
|
|
|
|
|
|
|
SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart);
|
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
const SkClipStack::Element* element = nullptr;
|
2012-08-02 12:49:00 +00:00
|
|
|
int count = 0;
|
|
|
|
|
2012-12-04 14:06:06 +00:00
|
|
|
for (element = iter.prev(); element; element = iter.prev(), ++count) {
|
2012-08-02 12:49:00 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2012-12-10 14:57:54 +00:00
|
|
|
static void test_rect_inverse_fill(skiatest::Reporter* reporter) {
|
|
|
|
// non-intersecting rectangles
|
|
|
|
SkRect rect = SkRect::MakeLTRB(0, 0, 10, 10);
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(rect);
|
|
|
|
path.toggleInverseFillType();
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevPath(path, SkRegion::kIntersect_Op, false);
|
|
|
|
|
|
|
|
SkRect bounds;
|
|
|
|
SkClipStack::BoundsType boundsType;
|
|
|
|
stack.getBounds(&bounds, &boundsType);
|
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::kInsideOut_BoundsType == boundsType);
|
|
|
|
REPORTER_ASSERT(reporter, bounds == rect);
|
|
|
|
}
|
|
|
|
|
2013-06-11 11:01:48 +00:00
|
|
|
static void test_rect_replace(skiatest::Reporter* reporter) {
|
|
|
|
SkRect rect = SkRect::MakeWH(100, 100);
|
|
|
|
SkRect rect2 = SkRect::MakeXYWH(50, 50, 100, 100);
|
|
|
|
|
|
|
|
SkRect bound;
|
|
|
|
SkClipStack::BoundsType type;
|
|
|
|
bool isIntersectionOfRects;
|
|
|
|
|
|
|
|
// Adding a new rect with the replace operator should not increase
|
|
|
|
// the stack depth. BW replacing BW.
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
REPORTER_ASSERT(reporter, 0 == count(stack));
|
|
|
|
stack.clipDevRect(rect, SkRegion::kReplace_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
stack.clipDevRect(rect, SkRegion::kReplace_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adding a new rect with the replace operator should not increase
|
|
|
|
// the stack depth. AA replacing AA.
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
REPORTER_ASSERT(reporter, 0 == count(stack));
|
|
|
|
stack.clipDevRect(rect, SkRegion::kReplace_Op, true);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
stack.clipDevRect(rect, SkRegion::kReplace_Op, true);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adding a new rect with the replace operator should not increase
|
|
|
|
// the stack depth. BW replacing AA replacing BW.
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
REPORTER_ASSERT(reporter, 0 == count(stack));
|
|
|
|
stack.clipDevRect(rect, SkRegion::kReplace_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
stack.clipDevRect(rect, SkRegion::kReplace_Op, true);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
stack.clipDevRect(rect, SkRegion::kReplace_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure replace clip rects don't collapse too much.
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevRect(rect, SkRegion::kReplace_Op, false);
|
|
|
|
stack.clipDevRect(rect2, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
|
|
|
|
stack.save();
|
|
|
|
stack.clipDevRect(rect, SkRegion::kReplace_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == count(stack));
|
|
|
|
stack.getBounds(&bound, &type, &isIntersectionOfRects);
|
|
|
|
REPORTER_ASSERT(reporter, bound == rect);
|
|
|
|
stack.restore();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
|
|
|
|
stack.save();
|
|
|
|
stack.clipDevRect(rect, SkRegion::kReplace_Op, false);
|
|
|
|
stack.clipDevRect(rect, SkRegion::kReplace_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == count(stack));
|
|
|
|
stack.restore();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
|
|
|
|
stack.save();
|
|
|
|
stack.clipDevRect(rect, SkRegion::kReplace_Op, false);
|
|
|
|
stack.clipDevRect(rect2, SkRegion::kIntersect_Op, false);
|
|
|
|
stack.clipDevRect(rect, SkRegion::kReplace_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == count(stack));
|
|
|
|
stack.restore();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simplified path-based version of test_rect_replace.
|
|
|
|
static void test_path_replace(skiatest::Reporter* reporter) {
|
|
|
|
SkRect rect = SkRect::MakeWH(100, 100);
|
|
|
|
SkPath path;
|
|
|
|
path.addCircle(50, 50, 50);
|
|
|
|
|
|
|
|
// Replace operation doesn't grow the stack.
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
REPORTER_ASSERT(reporter, 0 == count(stack));
|
|
|
|
stack.clipDevPath(path, SkRegion::kReplace_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
stack.clipDevPath(path, SkRegion::kReplace_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replacing rect with path.
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevRect(rect, SkRegion::kReplace_Op, true);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
stack.clipDevPath(path, SkRegion::kReplace_Op, true);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 12:49:00 +00:00
|
|
|
// Test out SkClipStack's merging of rect clips. In particular exercise
|
|
|
|
// merging of aa vs. bw rects.
|
|
|
|
static void test_rect_merging(skiatest::Reporter* reporter) {
|
|
|
|
|
|
|
|
SkRect overlapLeft = SkRect::MakeLTRB(10, 10, 50, 50);
|
|
|
|
SkRect overlapRight = SkRect::MakeLTRB(40, 40, 80, 80);
|
|
|
|
|
|
|
|
SkRect nestedParent = SkRect::MakeLTRB(10, 10, 90, 90);
|
|
|
|
SkRect nestedChild = SkRect::MakeLTRB(40, 40, 60, 60);
|
|
|
|
|
|
|
|
SkRect bound;
|
|
|
|
SkClipStack::BoundsType type;
|
|
|
|
bool isIntersectionOfRects;
|
|
|
|
|
|
|
|
// all bw overlapping - should merge
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
stack.clipDevRect(overlapLeft, SkRegion::kReplace_Op, false);
|
|
|
|
|
|
|
|
stack.clipDevRect(overlapRight, SkRegion::kIntersect_Op, false);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
|
|
|
|
stack.getBounds(&bound, &type, &isIntersectionOfRects);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, isIntersectionOfRects);
|
|
|
|
}
|
|
|
|
|
|
|
|
// all aa overlapping - should merge
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
stack.clipDevRect(overlapLeft, SkRegion::kReplace_Op, true);
|
|
|
|
|
|
|
|
stack.clipDevRect(overlapRight, SkRegion::kIntersect_Op, true);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
|
|
|
|
stack.getBounds(&bound, &type, &isIntersectionOfRects);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, isIntersectionOfRects);
|
|
|
|
}
|
|
|
|
|
|
|
|
// mixed overlapping - should _not_ merge
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
stack.clipDevRect(overlapLeft, SkRegion::kReplace_Op, true);
|
|
|
|
|
|
|
|
stack.clipDevRect(overlapRight, SkRegion::kIntersect_Op, false);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 2 == count(stack));
|
|
|
|
|
|
|
|
stack.getBounds(&bound, &type, &isIntersectionOfRects);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, !isIntersectionOfRects);
|
|
|
|
}
|
|
|
|
|
|
|
|
// mixed nested (bw inside aa) - should merge
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
stack.clipDevRect(nestedParent, SkRegion::kReplace_Op, true);
|
|
|
|
|
|
|
|
stack.clipDevRect(nestedChild, SkRegion::kIntersect_Op, false);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
|
|
|
|
stack.getBounds(&bound, &type, &isIntersectionOfRects);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, isIntersectionOfRects);
|
|
|
|
}
|
|
|
|
|
|
|
|
// mixed nested (aa inside bw) - should merge
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
stack.clipDevRect(nestedParent, SkRegion::kReplace_Op, false);
|
|
|
|
|
|
|
|
stack.clipDevRect(nestedChild, SkRegion::kIntersect_Op, true);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
|
|
|
|
stack.getBounds(&bound, &type, &isIntersectionOfRects);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, isIntersectionOfRects);
|
|
|
|
}
|
|
|
|
|
|
|
|
// reverse nested (aa inside bw) - should _not_ merge
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
stack.clipDevRect(nestedChild, SkRegion::kReplace_Op, false);
|
|
|
|
|
|
|
|
stack.clipDevRect(nestedParent, SkRegion::kIntersect_Op, true);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 2 == count(stack));
|
|
|
|
|
|
|
|
stack.getBounds(&bound, &type, &isIntersectionOfRects);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, !isIntersectionOfRects);
|
|
|
|
}
|
|
|
|
}
|
2012-07-26 18:39:13 +00:00
|
|
|
|
2012-12-12 17:58:15 +00:00
|
|
|
static void test_quickContains(skiatest::Reporter* reporter) {
|
|
|
|
SkRect testRect = SkRect::MakeLTRB(10, 10, 40, 40);
|
|
|
|
SkRect insideRect = SkRect::MakeLTRB(20, 20, 30, 30);
|
|
|
|
SkRect intersectingRect = SkRect::MakeLTRB(25, 25, 50, 50);
|
|
|
|
SkRect outsideRect = SkRect::MakeLTRB(0, 0, 50, 50);
|
|
|
|
SkRect nonIntersectingRect = SkRect::MakeLTRB(100, 100, 110, 110);
|
|
|
|
|
|
|
|
SkPath insideCircle;
|
|
|
|
insideCircle.addCircle(25, 25, 5);
|
|
|
|
SkPath intersectingCircle;
|
|
|
|
intersectingCircle.addCircle(25, 40, 10);
|
|
|
|
SkPath outsideCircle;
|
|
|
|
outsideCircle.addCircle(25, 25, 50);
|
|
|
|
SkPath nonIntersectingCircle;
|
|
|
|
nonIntersectingCircle.addCircle(100, 100, 5);
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevRect(outsideRect, SkRegion::kDifference_Op, false);
|
|
|
|
// return false because quickContains currently does not care for kDifference_Op
|
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
2012-12-13 02:01:33 +00:00
|
|
|
|
2012-12-12 17:58:15 +00:00
|
|
|
// Replace Op tests
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevRect(outsideRect, SkRegion::kReplace_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevRect(insideRect, SkRegion::kIntersect_Op, false);
|
|
|
|
stack.save(); // To prevent in-place substitution by replace OP
|
|
|
|
stack.clipDevRect(outsideRect, SkRegion::kReplace_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
stack.restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevRect(outsideRect, SkRegion::kIntersect_Op, false);
|
|
|
|
stack.save(); // To prevent in-place substitution by replace OP
|
|
|
|
stack.clipDevRect(insideRect, SkRegion::kReplace_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
stack.restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify proper traversal of multi-element clip
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevRect(insideRect, SkRegion::kIntersect_Op, false);
|
|
|
|
// Use a path for second clip to prevent in-place intersection
|
|
|
|
stack.clipDevPath(outsideCircle, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intersect Op tests with rectangles
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevRect(outsideRect, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevRect(insideRect, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevRect(intersectingRect, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevRect(nonIntersectingRect, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intersect Op tests with circle paths
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevPath(outsideCircle, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevPath(insideCircle, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevPath(intersectingCircle, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevPath(nonIntersectingCircle, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intersect Op tests with inverse filled rectangles
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(outsideRect);
|
|
|
|
path.toggleInverseFillType();
|
|
|
|
stack.clipDevPath(path, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(insideRect);
|
|
|
|
path.toggleInverseFillType();
|
|
|
|
stack.clipDevPath(path, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(intersectingRect);
|
|
|
|
path.toggleInverseFillType();
|
|
|
|
stack.clipDevPath(path, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(nonIntersectingRect);
|
|
|
|
path.toggleInverseFillType();
|
|
|
|
stack.clipDevPath(path, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intersect Op tests with inverse filled circles
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path = outsideCircle;
|
|
|
|
path.toggleInverseFillType();
|
|
|
|
stack.clipDevPath(path, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path = insideCircle;
|
|
|
|
path.toggleInverseFillType();
|
|
|
|
stack.clipDevPath(path, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path = intersectingCircle;
|
|
|
|
path.toggleInverseFillType();
|
|
|
|
stack.clipDevPath(path, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path = nonIntersectingCircle;
|
|
|
|
path.toggleInverseFillType();
|
|
|
|
stack.clipDevPath(path, SkRegion::kIntersect_Op, false);
|
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-26 21:19:43 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-11-26 21:38:37 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-11-27 15:43:57 +00:00
|
|
|
// Functions that add a shape to the clip stack. The shape is computed from a rectangle.
|
|
|
|
// AA is always disabled since the clip stack reducer can cause changes in aa rasterization of the
|
|
|
|
// stack. A fractional edge repeated in different elements may be rasterized fewer times using the
|
|
|
|
// reduced stack.
|
|
|
|
typedef void (*AddElementFunc) (const SkRect& rect,
|
|
|
|
bool invert,
|
|
|
|
SkRegion::Op op,
|
|
|
|
SkClipStack* stack);
|
|
|
|
|
|
|
|
static void add_round_rect(const SkRect& rect, bool invert, SkRegion::Op op, SkClipStack* stack) {
|
2012-11-26 21:19:43 +00:00
|
|
|
SkScalar rx = rect.width() / 10;
|
2012-11-27 15:43:57 +00:00
|
|
|
SkScalar ry = rect.height() / 20;
|
|
|
|
if (invert) {
|
2014-02-16 13:25:24 +00:00
|
|
|
SkPath path;
|
|
|
|
path.addRoundRect(rect, rx, ry);
|
2012-11-27 15:43:57 +00:00
|
|
|
path.setFillType(SkPath::kInverseWinding_FillType);
|
2014-02-16 13:25:24 +00:00
|
|
|
stack->clipDevPath(path, op, false);
|
|
|
|
} else {
|
|
|
|
SkRRect rrect;
|
|
|
|
rrect.setRectXY(rect, rx, ry);
|
|
|
|
stack->clipDevRRect(rrect, op, false);
|
2012-11-27 15:43:57 +00:00
|
|
|
}
|
2012-11-26 21:19:43 +00:00
|
|
|
};
|
|
|
|
|
2012-11-27 15:43:57 +00:00
|
|
|
static void add_rect(const SkRect& rect, bool invert, SkRegion::Op op, SkClipStack* stack) {
|
|
|
|
if (invert) {
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(rect);
|
|
|
|
path.setFillType(SkPath::kInverseWinding_FillType);
|
|
|
|
stack->clipDevPath(path, op, false);
|
|
|
|
} else {
|
|
|
|
stack->clipDevRect(rect, op, false);
|
|
|
|
}
|
2012-11-26 21:19:43 +00:00
|
|
|
};
|
|
|
|
|
2012-11-27 15:43:57 +00:00
|
|
|
static void add_oval(const SkRect& rect, bool invert, SkRegion::Op op, SkClipStack* stack) {
|
2012-11-26 21:19:43 +00:00
|
|
|
SkPath path;
|
|
|
|
path.addOval(rect);
|
2012-11-27 15:43:57 +00:00
|
|
|
if (invert) {
|
|
|
|
path.setFillType(SkPath::kInverseWinding_FillType);
|
|
|
|
}
|
|
|
|
stack->clipDevPath(path, op, false);
|
2012-11-26 21:19:43 +00:00
|
|
|
};
|
|
|
|
|
2012-12-04 14:06:06 +00:00
|
|
|
static void add_elem_to_stack(const SkClipStack::Element& element, SkClipStack* stack) {
|
|
|
|
switch (element.getType()) {
|
|
|
|
case SkClipStack::Element::kRect_Type:
|
|
|
|
stack->clipDevRect(element.getRect(), element.getOp(), element.isAA());
|
|
|
|
break;
|
2014-02-16 13:25:24 +00:00
|
|
|
case SkClipStack::Element::kRRect_Type:
|
|
|
|
stack->clipDevRRect(element.getRRect(), element.getOp(), element.isAA());
|
|
|
|
break;
|
2012-12-04 14:06:06 +00:00
|
|
|
case SkClipStack::Element::kPath_Type:
|
|
|
|
stack->clipDevPath(element.getPath(), element.getOp(), element.isAA());
|
|
|
|
break;
|
|
|
|
case SkClipStack::Element::kEmpty_Type:
|
|
|
|
SkDEBUGFAIL("Why did the reducer produce an explicit empty.");
|
|
|
|
stack->clipEmpty();
|
|
|
|
break;
|
2012-11-26 21:19:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-04 14:06:06 +00:00
|
|
|
static void add_elem_to_region(const SkClipStack::Element& element,
|
2012-11-26 21:19:43 +00:00
|
|
|
const SkIRect& bounds,
|
|
|
|
SkRegion* region) {
|
|
|
|
SkRegion elemRegion;
|
|
|
|
SkRegion boundsRgn(bounds);
|
2014-02-16 13:25:24 +00:00
|
|
|
SkPath path;
|
2012-11-26 21:19:43 +00:00
|
|
|
|
2012-12-04 14:06:06 +00:00
|
|
|
switch (element.getType()) {
|
2014-02-16 13:25:24 +00:00
|
|
|
case SkClipStack::Element::kEmpty_Type:
|
|
|
|
elemRegion.setEmpty();
|
2012-12-04 14:06:06 +00:00
|
|
|
break;
|
2014-02-16 13:25:24 +00:00
|
|
|
default:
|
|
|
|
element.asPath(&path);
|
|
|
|
elemRegion.setPath(path, boundsRgn);
|
2012-12-04 14:06:06 +00:00
|
|
|
break;
|
2012-11-26 21:19:43 +00:00
|
|
|
}
|
2012-12-04 14:06:06 +00:00
|
|
|
region->op(elemRegion, element.getOp());
|
2012-11-26 21:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_reduced_clip_stack(skiatest::Reporter* reporter) {
|
|
|
|
// We construct random clip stacks, reduce them, and then rasterize both versions to verify that
|
2012-11-27 02:01:19 +00:00
|
|
|
// they are equal.
|
2012-11-26 21:19:43 +00:00
|
|
|
|
|
|
|
// All the clip elements will be contained within these bounds.
|
|
|
|
static const SkRect kBounds = SkRect::MakeWH(100, 100);
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kNumTests = 200,
|
|
|
|
kMinElemsPerTest = 1,
|
|
|
|
kMaxElemsPerTest = 50,
|
|
|
|
};
|
|
|
|
|
|
|
|
// min/max size of a clip element as a fraction of kBounds.
|
|
|
|
static const SkScalar kMinElemSizeFrac = SK_Scalar1 / 5;
|
|
|
|
static const SkScalar kMaxElemSizeFrac = SK_Scalar1;
|
|
|
|
|
|
|
|
static const SkRegion::Op kOps[] = {
|
|
|
|
SkRegion::kDifference_Op,
|
|
|
|
SkRegion::kIntersect_Op,
|
|
|
|
SkRegion::kUnion_Op,
|
|
|
|
SkRegion::kXOR_Op,
|
|
|
|
SkRegion::kReverseDifference_Op,
|
|
|
|
SkRegion::kReplace_Op,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Replace operations short-circuit the optimizer. We want to make sure that we test this code
|
|
|
|
// path a little bit but we don't want it to prevent us from testing many longer traversals in
|
|
|
|
// the optimizer.
|
|
|
|
static const int kReplaceDiv = 4 * kMaxElemsPerTest;
|
|
|
|
|
2012-11-27 15:43:57 +00:00
|
|
|
// We want to test inverse fills. However, they are quite rare in practice so don't over do it.
|
|
|
|
static const SkScalar kFractionInverted = SK_Scalar1 / kMaxElemsPerTest;
|
|
|
|
|
2012-11-26 21:19:43 +00:00
|
|
|
static const AddElementFunc kElementFuncs[] = {
|
|
|
|
add_rect,
|
|
|
|
add_round_rect,
|
|
|
|
add_oval,
|
|
|
|
};
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom r;
|
2012-11-26 21:19:43 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < kNumTests; ++i) {
|
|
|
|
// Randomly generate a clip stack.
|
|
|
|
SkClipStack stack;
|
|
|
|
int numElems = r.nextRangeU(kMinElemsPerTest, kMaxElemsPerTest);
|
|
|
|
for (int e = 0; e < numElems; ++e) {
|
|
|
|
SkRegion::Op op = kOps[r.nextULessThan(SK_ARRAY_COUNT(kOps))];
|
|
|
|
if (op == SkRegion::kReplace_Op) {
|
|
|
|
if (r.nextU() % kReplaceDiv) {
|
|
|
|
--e;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-11-27 02:01:19 +00:00
|
|
|
|
2012-11-26 21:19:43 +00:00
|
|
|
// saves can change the clip stack behavior when an element is added.
|
|
|
|
bool doSave = r.nextBool();
|
2012-11-27 02:01:19 +00:00
|
|
|
|
2012-11-26 21:19:43 +00:00
|
|
|
SkSize size = SkSize::Make(
|
|
|
|
SkScalarFloorToScalar(SkScalarMul(kBounds.width(), r.nextRangeScalar(kMinElemSizeFrac, kMaxElemSizeFrac))),
|
|
|
|
SkScalarFloorToScalar(SkScalarMul(kBounds.height(), r.nextRangeScalar(kMinElemSizeFrac, kMaxElemSizeFrac))));
|
|
|
|
|
|
|
|
SkPoint xy = {SkScalarFloorToScalar(r.nextRangeScalar(kBounds.fLeft, kBounds.fRight - size.fWidth)),
|
|
|
|
SkScalarFloorToScalar(r.nextRangeScalar(kBounds.fTop, kBounds.fBottom - size.fHeight))};
|
|
|
|
|
|
|
|
SkRect rect = SkRect::MakeXYWH(xy.fX, xy.fY, size.fWidth, size.fHeight);
|
|
|
|
|
2012-11-27 15:43:57 +00:00
|
|
|
bool invert = r.nextBiasedBool(kFractionInverted);
|
2014-02-16 13:25:24 +00:00
|
|
|
|
2012-11-27 15:43:57 +00:00
|
|
|
kElementFuncs[r.nextULessThan(SK_ARRAY_COUNT(kElementFuncs))](rect, invert, op, &stack);
|
2012-11-26 21:19:43 +00:00
|
|
|
if (doSave) {
|
|
|
|
stack.save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-04 15:22:12 +00:00
|
|
|
SkRect inflatedBounds = kBounds;
|
|
|
|
inflatedBounds.outset(kBounds.width() / 2, kBounds.height() / 2);
|
|
|
|
SkIRect inflatedIBounds;
|
|
|
|
inflatedBounds.roundOut(&inflatedIBounds);
|
|
|
|
|
2012-12-04 14:06:06 +00:00
|
|
|
typedef GrReducedClip::ElementList ElementList;
|
2012-11-26 21:19:43 +00:00
|
|
|
// Get the reduced version of the stack.
|
2012-12-04 14:06:06 +00:00
|
|
|
ElementList reducedClips;
|
2013-11-05 15:03:08 +00:00
|
|
|
int32_t reducedGenID;
|
2012-11-26 21:19:43 +00:00
|
|
|
GrReducedClip::InitialState initial;
|
2013-03-04 13:56:38 +00:00
|
|
|
SkIRect tBounds(inflatedIBounds);
|
2015-08-27 14:41:13 +00:00
|
|
|
SkIRect* tightBounds = r.nextBool() ? &tBounds : nullptr;
|
2012-12-06 14:23:20 +00:00
|
|
|
GrReducedClip::ReduceClipStack(stack,
|
|
|
|
inflatedIBounds,
|
|
|
|
&reducedClips,
|
2013-11-05 15:03:08 +00:00
|
|
|
&reducedGenID,
|
2012-12-06 14:23:20 +00:00
|
|
|
&initial,
|
|
|
|
tightBounds);
|
2012-11-26 21:19:43 +00:00
|
|
|
|
2013-11-05 15:03:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reducedGenID);
|
|
|
|
|
2012-11-26 21:19:43 +00:00
|
|
|
// Build a new clip stack based on the reduced clip elements
|
|
|
|
SkClipStack reducedStack;
|
|
|
|
if (GrReducedClip::kAllOut_InitialState == initial) {
|
|
|
|
// whether the result is bounded or not, the whole plane should start outside the clip.
|
|
|
|
reducedStack.clipEmpty();
|
|
|
|
}
|
2014-09-05 20:34:00 +00:00
|
|
|
for (ElementList::Iter iter = reducedClips.headIter(); iter.get(); iter.next()) {
|
2012-12-04 14:06:06 +00:00
|
|
|
add_elem_to_stack(*iter.get(), &reducedStack);
|
2012-11-26 21:19:43 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 14:23:20 +00:00
|
|
|
// GrReducedClipStack assumes that the final result is clipped to the returned bounds
|
2014-09-05 20:34:00 +00:00
|
|
|
if (tightBounds) {
|
2012-12-06 14:23:20 +00:00
|
|
|
reducedStack.clipDevRect(*tightBounds, SkRegion::kIntersect_Op);
|
|
|
|
}
|
|
|
|
|
2012-11-26 21:19:43 +00:00
|
|
|
// convert both the original stack and reduced stack to SkRegions and see if they're equal
|
|
|
|
SkRegion region;
|
|
|
|
SkRegion reducedRegion;
|
|
|
|
|
|
|
|
region.setRect(inflatedIBounds);
|
2012-12-04 14:06:06 +00:00
|
|
|
const SkClipStack::Element* element;
|
2012-11-26 21:19:43 +00:00
|
|
|
SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart);
|
2012-12-04 14:06:06 +00:00
|
|
|
while ((element = iter.next())) {
|
|
|
|
add_elem_to_region(*element, inflatedIBounds, ®ion);
|
2012-11-26 21:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reducedRegion.setRect(inflatedIBounds);
|
|
|
|
iter.reset(reducedStack, SkClipStack::Iter::kBottom_IterStart);
|
2012-12-04 14:06:06 +00:00
|
|
|
while ((element = iter.next())) {
|
|
|
|
add_elem_to_region(*element, inflatedIBounds, &reducedRegion);
|
2012-11-26 21:19:43 +00:00
|
|
|
}
|
2014-02-16 13:25:24 +00:00
|
|
|
SkString testCase;
|
|
|
|
testCase.printf("Iteration %d", i);
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, region == reducedRegion, testCase.c_str());
|
2012-11-26 21:19:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-08 00:21:10 +00:00
|
|
|
#ifdef SK_BUILD_FOR_WIN
|
2013-11-05 15:03:08 +00:00
|
|
|
#define SUPPRESS_VISIBILITY_WARNING
|
|
|
|
#else
|
|
|
|
#define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden")))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void test_reduced_clip_stack_genid(skiatest::Reporter* reporter) {
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevRect(SkRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_Op, true);
|
|
|
|
stack.clipDevRect(SkRect::MakeXYWH(0, 0, SkScalar(50.3), SkScalar(50.3)), SkRegion::kReplace_Op, true);
|
|
|
|
SkIRect inflatedIBounds = SkIRect::MakeXYWH(0, 0, 100, 100);
|
|
|
|
|
|
|
|
GrReducedClip::ElementList reducedClips;
|
|
|
|
int32_t reducedGenID;
|
|
|
|
GrReducedClip::InitialState initial;
|
|
|
|
SkIRect tightBounds;
|
|
|
|
|
|
|
|
GrReducedClip::ReduceClipStack(stack,
|
|
|
|
inflatedIBounds,
|
|
|
|
&reducedClips,
|
|
|
|
&reducedGenID,
|
|
|
|
&initial,
|
|
|
|
&tightBounds);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, reducedClips.count() == 1);
|
|
|
|
// Clips will be cached based on the generation id. Make sure the gen id is valid.
|
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reducedGenID);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
// Create a clip with following 25.3, 25.3 boxes which are 25 apart:
|
|
|
|
// A B
|
|
|
|
// C D
|
|
|
|
|
|
|
|
stack.clipDevRect(SkRect::MakeXYWH(0, 0, SkScalar(25.3), SkScalar(25.3)), SkRegion::kReplace_Op, true);
|
|
|
|
int32_t genIDA = stack.getTopmostGenID();
|
|
|
|
stack.clipDevRect(SkRect::MakeXYWH(50, 0, SkScalar(25.3), SkScalar(25.3)), SkRegion::kUnion_Op, true);
|
|
|
|
int32_t genIDB = stack.getTopmostGenID();
|
|
|
|
stack.clipDevRect(SkRect::MakeXYWH(0, 50, SkScalar(25.3), SkScalar(25.3)), SkRegion::kUnion_Op, true);
|
|
|
|
int32_t genIDC = stack.getTopmostGenID();
|
|
|
|
stack.clipDevRect(SkRect::MakeXYWH(50, 50, SkScalar(25.3), SkScalar(25.3)), SkRegion::kUnion_Op, true);
|
|
|
|
int32_t genIDD = stack.getTopmostGenID();
|
|
|
|
|
|
|
|
|
|
|
|
#define XYWH SkIRect::MakeXYWH
|
|
|
|
|
|
|
|
SkIRect unused;
|
|
|
|
unused.setEmpty();
|
|
|
|
SkIRect stackBounds = XYWH(0, 0, 76, 76);
|
|
|
|
|
|
|
|
// The base test is to test each rect in two ways:
|
|
|
|
// 1) The box dimensions. (Should reduce to "all in", no elements).
|
|
|
|
// 2) A bit over the box dimensions.
|
|
|
|
// In the case 2, test that the generation id is what is expected.
|
|
|
|
// The rects are of fractional size so that case 2 never gets optimized to an empty element
|
|
|
|
// list.
|
|
|
|
|
|
|
|
// Not passing in tighter bounds is tested for consistency.
|
|
|
|
static const struct SUPPRESS_VISIBILITY_WARNING {
|
|
|
|
SkIRect testBounds;
|
|
|
|
int reducedClipCount;
|
|
|
|
int32_t reducedGenID;
|
|
|
|
GrReducedClip::InitialState initialState;
|
|
|
|
SkIRect tighterBounds; // If this is empty, the query will not pass tighter bounds
|
|
|
|
// parameter.
|
|
|
|
} testCases[] = {
|
|
|
|
// Rect A.
|
|
|
|
{ XYWH(0, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip::kAllIn_InitialState, XYWH(0, 0, 25, 25) },
|
|
|
|
{ XYWH(0, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip::kAllIn_InitialState, unused },
|
|
|
|
{ XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::kAllOut_InitialState, XYWH(0, 0, 27, 27)},
|
|
|
|
{ XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::kAllOut_InitialState, unused },
|
|
|
|
|
|
|
|
// Rect B.
|
|
|
|
{ XYWH(50, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip::kAllIn_InitialState, XYWH(50, 0, 25, 25) },
|
|
|
|
{ XYWH(50, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip::kAllIn_InitialState, unused },
|
|
|
|
{ XYWH(50, 0, 27, 27), 1, genIDB, GrReducedClip::kAllOut_InitialState, XYWH(50, 0, 26, 27) },
|
|
|
|
{ XYWH(50, 0, 27, 27), 1, genIDB, GrReducedClip::kAllOut_InitialState, unused },
|
|
|
|
|
|
|
|
// Rect C.
|
|
|
|
{ XYWH(0, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip::kAllIn_InitialState, XYWH(0, 50, 25, 25) },
|
|
|
|
{ XYWH(0, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip::kAllIn_InitialState, unused },
|
|
|
|
{ XYWH(0, 50, 27, 27), 1, genIDC, GrReducedClip::kAllOut_InitialState, XYWH(0, 50, 27, 26) },
|
|
|
|
{ XYWH(0, 50, 27, 27), 1, genIDC, GrReducedClip::kAllOut_InitialState, unused },
|
|
|
|
|
|
|
|
// Rect D.
|
|
|
|
{ XYWH(50, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip::kAllIn_InitialState, unused },
|
|
|
|
{ XYWH(50, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip::kAllIn_InitialState, XYWH(50, 50, 25, 25)},
|
|
|
|
{ XYWH(50, 50, 27, 27), 1, genIDD, GrReducedClip::kAllOut_InitialState, unused },
|
|
|
|
{ XYWH(50, 50, 27, 27), 1, genIDD, GrReducedClip::kAllOut_InitialState, XYWH(50, 50, 26, 26)},
|
|
|
|
|
|
|
|
// Other tests:
|
|
|
|
{ XYWH(0, 0, 100, 100), 4, genIDD, GrReducedClip::kAllOut_InitialState, unused },
|
|
|
|
{ XYWH(0, 0, 100, 100), 4, genIDD, GrReducedClip::kAllOut_InitialState, stackBounds },
|
|
|
|
|
|
|
|
// Rect in the middle, touches none.
|
|
|
|
{ XYWH(26, 26, 24, 24), 0, SkClipStack::kEmptyGenID, GrReducedClip::kAllOut_InitialState, unused },
|
|
|
|
{ XYWH(26, 26, 24, 24), 0, SkClipStack::kEmptyGenID, GrReducedClip::kAllOut_InitialState, XYWH(26, 26, 24, 24) },
|
|
|
|
|
|
|
|
// Rect in the middle, touches all the rects. GenID is the last rect.
|
|
|
|
{ XYWH(24, 24, 27, 27), 4, genIDD, GrReducedClip::kAllOut_InitialState, unused },
|
|
|
|
{ XYWH(24, 24, 27, 27), 4, genIDD, GrReducedClip::kAllOut_InitialState, XYWH(24, 24, 27, 27) },
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef XYWH
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(testCases); ++i) {
|
|
|
|
GrReducedClip::ElementList reducedClips;
|
|
|
|
int32_t reducedGenID;
|
|
|
|
GrReducedClip::InitialState initial;
|
|
|
|
SkIRect tightBounds;
|
|
|
|
|
|
|
|
GrReducedClip::ReduceClipStack(stack,
|
|
|
|
testCases[i].testBounds,
|
|
|
|
&reducedClips,
|
|
|
|
&reducedGenID,
|
|
|
|
&initial,
|
2015-08-27 14:41:13 +00:00
|
|
|
testCases[i].tighterBounds.isEmpty() ? nullptr : &tightBounds);
|
2013-11-05 15:03:08 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, reducedClips.count() == testCases[i].reducedClipCount);
|
|
|
|
SkASSERT(reducedClips.count() == testCases[i].reducedClipCount);
|
|
|
|
REPORTER_ASSERT(reporter, reducedGenID == testCases[i].reducedGenID);
|
|
|
|
SkASSERT(reducedGenID == testCases[i].reducedGenID);
|
|
|
|
REPORTER_ASSERT(reporter, initial == testCases[i].initialState);
|
|
|
|
SkASSERT(initial == testCases[i].initialState);
|
|
|
|
if (!testCases[i].tighterBounds.isEmpty()) {
|
|
|
|
REPORTER_ASSERT(reporter, tightBounds == testCases[i].tighterBounds);
|
|
|
|
SkASSERT(tightBounds == testCases[i].tighterBounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_reduced_clip_stack_no_aa_crash(skiatest::Reporter* reporter) {
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_Op);
|
|
|
|
stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 50, 50), SkRegion::kReplace_Op);
|
|
|
|
SkIRect inflatedIBounds = SkIRect::MakeXYWH(0, 0, 100, 100);
|
|
|
|
|
|
|
|
GrReducedClip::ElementList reducedClips;
|
|
|
|
int32_t reducedGenID;
|
|
|
|
GrReducedClip::InitialState initial;
|
|
|
|
SkIRect tightBounds;
|
|
|
|
|
|
|
|
// At the time, this would crash.
|
|
|
|
GrReducedClip::ReduceClipStack(stack,
|
|
|
|
inflatedIBounds,
|
|
|
|
&reducedClips,
|
|
|
|
&reducedGenID,
|
|
|
|
&initial,
|
|
|
|
&tightBounds);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 0 == reducedClips.count());
|
|
|
|
}
|
|
|
|
|
2012-11-26 21:38:37 +00:00
|
|
|
#endif
|
2012-11-26 21:19:43 +00:00
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(ClipStack, reporter) {
|
2011-02-22 20:17:43 +00:00
|
|
|
SkClipStack stack;
|
|
|
|
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == stack.getSaveCount());
|
2011-02-22 20:17:43 +00:00
|
|
|
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
|
2012-07-20 15:33:18 +00:00
|
|
|
SkClipStack::B2TIter iter(stack);
|
2012-12-04 14:06:06 +00:00
|
|
|
const SkClipStack::Element* element = 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
|
|
|
|
2014-09-05 20:34:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, element);
|
2012-12-04 14:06:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::Element::kRect_Type == element->getType());
|
|
|
|
REPORTER_ASSERT(reporter, SkRegion::kIntersect_Op == element->getOp());
|
|
|
|
REPORTER_ASSERT(reporter, element->getRect() == answer);
|
2011-02-22 20:17:43 +00:00
|
|
|
// now check that we only had one in our iterator
|
|
|
|
REPORTER_ASSERT(reporter, !iter.next());
|
|
|
|
|
|
|
|
stack.reset();
|
2012-07-20 15:33:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == stack.getSaveCount());
|
2011-02-22 20:17:43 +00:00
|
|
|
assert_count(reporter, stack, 0);
|
2011-05-03 16:26:09 +00:00
|
|
|
|
|
|
|
test_assign_and_comparison(reporter);
|
2012-07-20 15:33:18 +00:00
|
|
|
test_iterators(reporter);
|
2014-02-16 13:25:24 +00:00
|
|
|
test_bounds(reporter, SkClipStack::Element::kRect_Type);
|
|
|
|
test_bounds(reporter, SkClipStack::Element::kRRect_Type);
|
|
|
|
test_bounds(reporter, SkClipStack::Element::kPath_Type);
|
2012-07-26 18:39:13 +00:00
|
|
|
test_isWideOpen(reporter);
|
2012-08-02 12:49:00 +00:00
|
|
|
test_rect_merging(reporter);
|
2013-06-11 11:01:48 +00:00
|
|
|
test_rect_replace(reporter);
|
2012-12-10 14:57:54 +00:00
|
|
|
test_rect_inverse_fill(reporter);
|
2013-06-11 11:01:48 +00:00
|
|
|
test_path_replace(reporter);
|
2012-12-12 17:58:15 +00:00
|
|
|
test_quickContains(reporter);
|
2012-11-26 21:42:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-11-28 14:42:41 +00:00
|
|
|
test_reduced_clip_stack(reporter);
|
2013-11-05 15:03:08 +00:00
|
|
|
test_reduced_clip_stack_genid(reporter);
|
|
|
|
test_reduced_clip_stack_no_aa_crash(reporter);
|
2012-11-26 21:42:32 +00:00
|
|
|
#endif
|
2011-02-22 20:17:43 +00:00
|
|
|
}
|