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
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkClipOp.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRRect.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkRegion.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2020-06-05 15:29:36 +00:00
|
|
|
#include "include/effects/SkGradientShader.h"
|
2019-05-06 21:17:19 +00:00
|
|
|
#include "include/private/SkTemplates.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "src/core/SkClipStack.h"
|
|
|
|
#include "tests/Test.h"
|
2016-07-22 15:59:08 +00:00
|
|
|
|
2018-03-12 17:46:21 +00:00
|
|
|
#include <cstring>
|
2019-05-06 21:17:19 +00:00
|
|
|
#include <initializer_list>
|
2018-03-12 17:46:21 +00:00
|
|
|
#include <new>
|
|
|
|
|
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();
|
2021-08-05 20:39:18 +00:00
|
|
|
s.clipPath(p, SkMatrix::I(), SkClipOp::kIntersect, 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());
|
|
|
|
|
2021-08-06 14:42:01 +00:00
|
|
|
SkRect r = SkRect::MakeLTRB(1, 2, 103, 104);
|
2021-08-05 20:39:18 +00:00
|
|
|
s.clipRect(r, SkMatrix::I(), SkClipOp::kIntersect, doAA);
|
2021-08-06 14:42:01 +00:00
|
|
|
r = SkRect::MakeLTRB(4, 5, 56, 57);
|
2021-08-05 20:39:18 +00:00
|
|
|
s.clipRect(r, SkMatrix::I(), SkClipOp::kIntersect, 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);
|
2021-08-06 14:42:01 +00:00
|
|
|
s.clipRect(r, SkMatrix::I(), SkClipOp::kDifference, 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);
|
2021-08-06 14:42:01 +00:00
|
|
|
s.clipRect(r, SkMatrix::I(), SkClipOp::kDifference, 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);
|
2021-08-05 20:39:18 +00:00
|
|
|
s.clipRect(r, SkMatrix::I(), SkClipOp::kIntersect, 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);
|
2021-08-06 14:42:01 +00:00
|
|
|
s.clipPath(rp, SkMatrix::I(), SkClipOp::kDifference, 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);
|
2021-08-06 14:42:01 +00:00
|
|
|
s.clipRect(r, SkMatrix::I(), SkClipOp::kDifference, doAA);
|
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, 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);
|
2021-08-05 20:39:18 +00:00
|
|
|
s.clipPath(p, SkMatrix::I(), SkClipOp::kIntersect, 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++) {
|
2021-08-06 14:42:01 +00:00
|
|
|
// the difference op will prevent these from being fused together
|
|
|
|
stack.clipRect(gRects[i], SkMatrix::I(), SkClipOp::kDifference, false);
|
2012-07-20 15:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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()) {
|
2017-08-30 15:37:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::Element::DeviceSpaceType::kRect ==
|
|
|
|
element->getDeviceSpaceType());
|
|
|
|
REPORTER_ASSERT(reporter, element->getDeviceSpaceRect() == 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()) {
|
2017-08-30 15:37:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::Element::DeviceSpaceType::kRect ==
|
|
|
|
element->getDeviceSpaceType());
|
|
|
|
REPORTER_ASSERT(reporter, element->getDeviceSpaceRect() == 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);
|
|
|
|
|
2021-08-06 14:42:01 +00:00
|
|
|
element = iter.skipToTopmost(SkClipOp::kDifference);
|
2017-08-30 15:37:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::Element::DeviceSpaceType::kRect ==
|
|
|
|
element->getDeviceSpaceType());
|
|
|
|
REPORTER_ASSERT(reporter, element->getDeviceSpaceRect() == gRects[3]);
|
2012-07-20 15:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 12:49:00 +00:00
|
|
|
// Exercise the SkClipStack's getConservativeBounds computation
|
2017-08-30 15:37:57 +00:00
|
|
|
static void test_bounds(skiatest::Reporter* reporter,
|
|
|
|
SkClipStack::Element::DeviceSpaceType primType) {
|
2021-08-06 15:19:26 +00:00
|
|
|
static const int gNumCases = 8;
|
2012-07-24 13:54:00 +00:00
|
|
|
static const SkRect gAnswerRectsBW[gNumCases] = {
|
|
|
|
// A op B
|
|
|
|
{ 40, 40, 50, 50 },
|
|
|
|
{ 10, 10, 50, 50 },
|
|
|
|
|
|
|
|
// invA op B
|
|
|
|
{ 40, 40, 80, 80 },
|
|
|
|
{ 0, 0, 100, 100 },
|
|
|
|
|
|
|
|
// A op invB
|
|
|
|
{ 10, 10, 50, 50 },
|
|
|
|
{ 40, 40, 50, 50 },
|
|
|
|
|
|
|
|
// invA op invB
|
|
|
|
{ 0, 0, 100, 100 },
|
|
|
|
{ 40, 40, 80, 80 },
|
|
|
|
};
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
static const SkClipOp gOps[] = {
|
2021-08-05 20:39:18 +00:00
|
|
|
SkClipOp::kIntersect,
|
2021-08-06 15:19:26 +00:00
|
|
|
SkClipOp::kDifference
|
2012-07-24 13:54:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SkRect rectA, rectB;
|
|
|
|
|
2019-08-24 23:39:13 +00:00
|
|
|
rectA.setLTRB(10, 10, 50, 50);
|
|
|
|
rectB.setLTRB(40, 40, 80, 80);
|
2012-07-24 13:54:00 +00:00
|
|
|
|
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;
|
2017-08-30 15:37:57 +00:00
|
|
|
int numBitTests = SkClipStack::Element::DeviceSpaceType::kPath == 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);
|
|
|
|
|
2019-11-26 17:17:17 +00:00
|
|
|
pathA.setFillType(doInvA ? SkPathFillType::kInverseEvenOdd :
|
|
|
|
SkPathFillType::kEvenOdd);
|
|
|
|
pathB.setFillType(doInvB ? SkPathFillType::kInverseEvenOdd :
|
|
|
|
SkPathFillType::kEvenOdd);
|
2012-07-24 13:54:00 +00:00
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
switch (primType) {
|
2020-06-05 15:29:36 +00:00
|
|
|
case SkClipStack::Element::DeviceSpaceType::kShader:
|
2017-08-30 15:37:57 +00:00
|
|
|
case SkClipStack::Element::DeviceSpaceType::kEmpty:
|
2020-06-05 15:29:36 +00:00
|
|
|
SkDEBUGFAIL("Don't call this with kEmpty or kShader.");
|
2014-02-16 13:25:24 +00:00
|
|
|
break;
|
2017-08-30 15:37:57 +00:00
|
|
|
case SkClipStack::Element::DeviceSpaceType::kRect:
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(rectA, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2016-10-03 15:36:16 +00:00
|
|
|
stack.clipRect(rectB, SkMatrix::I(), gOps[op], false);
|
2014-02-16 13:25:24 +00:00
|
|
|
break;
|
2017-08-30 15:37:57 +00:00
|
|
|
case SkClipStack::Element::DeviceSpaceType::kRRect:
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRRect(rrectA, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2016-10-03 15:36:16 +00:00
|
|
|
stack.clipRRect(rrectB, SkMatrix::I(), gOps[op], false);
|
2014-02-16 13:25:24 +00:00
|
|
|
break;
|
2017-08-30 15:37:57 +00:00
|
|
|
case SkClipStack::Element::DeviceSpaceType::kPath:
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(pathA, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2016-10-03 15:36:16 +00:00
|
|
|
stack.clipPath(pathB, SkMatrix::I(), gOps[op], false);
|
2014-02-16 13:25:24 +00:00
|
|
|
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);
|
|
|
|
|
2017-08-30 15:37:57 +00:00
|
|
|
if (SkClipStack::Element::DeviceSpaceType::kRect == primType) {
|
2012-08-23 18:14:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, isIntersectionOfRects ==
|
2021-08-05 20:39:18 +00:00
|
|
|
(gOps[op] == SkClipOp::kIntersect));
|
2012-07-24 22:07:50 +00:00
|
|
|
} 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;
|
|
|
|
|
2019-08-24 23:39:13 +00:00
|
|
|
rectA.setLTRB(10, 10, 40, 40);
|
|
|
|
rectB.setLTRB(50, 50, 80, 80);
|
2012-07-26 18:39:13 +00:00
|
|
|
|
|
|
|
// 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 empty difference from a wide open clip
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
SkRect emptyRect;
|
|
|
|
emptyRect.setEmpty();
|
|
|
|
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(emptyRect, SkMatrix::I(), SkClipOp::kDifference, false);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Test out return to wide open
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
stack.save();
|
|
|
|
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(rectA, SkMatrix::I(), SkClipOp::kIntersect, false);
|
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
|
|
|
|
|
|
|
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;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-10 14:57:54 +00:00
|
|
|
|
|
|
|
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));
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.replaceClip(rect, false);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.replaceClip(rect, false);
|
2013-06-11 11:01:48 +00:00
|
|
|
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));
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.replaceClip(rect, true);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.replaceClip(rect, true);
|
2013-06-11 11:01:48 +00:00
|
|
|
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));
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.replaceClip(rect, false);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.replaceClip(rect, true);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.replaceClip(rect, false);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure replace clip rects don't collapse too much.
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.replaceClip(rect, false);
|
|
|
|
stack.clipRect(rect2, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
|
|
|
|
stack.save();
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.replaceClip(rect, false);
|
2013-06-11 11:01:48 +00:00
|
|
|
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();
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.replaceClip(rect, false);
|
|
|
|
stack.replaceClip(rect, false);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == count(stack));
|
|
|
|
stack.restore();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
|
|
|
|
stack.save();
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.replaceClip(rect, false);
|
|
|
|
stack.clipRect(rect2, SkMatrix::I(), SkClipOp::kIntersect, false);
|
|
|
|
stack.replaceClip(rect, false);
|
2013-06-11 11:01:48 +00:00
|
|
|
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) {
|
2021-08-05 20:39:18 +00:00
|
|
|
auto replacePath = [](SkClipStack* stack, const SkPath& path, bool doAA) {
|
|
|
|
const SkRect wideOpen = SkRect::MakeLTRB(-1000, -1000, 1000, 1000);
|
|
|
|
stack->replaceClip(wideOpen, false);
|
|
|
|
stack->clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, doAA);
|
|
|
|
};
|
2013-06-11 11:01:48 +00:00
|
|
|
SkRect rect = SkRect::MakeWH(100, 100);
|
|
|
|
SkPath path;
|
|
|
|
path.addCircle(50, 50, 50);
|
|
|
|
|
2021-08-05 20:39:18 +00:00
|
|
|
// Emulating replace operations with more complex geometry is not atomic, it's a replace
|
|
|
|
// with a wide-open rect and then an intersection with the complex geometry. The replace can
|
|
|
|
// combine with prior elements, but the subsequent intersect cannot be combined so the stack
|
|
|
|
// continues to grow.
|
2013-06-11 11:01:48 +00:00
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
REPORTER_ASSERT(reporter, 0 == count(stack));
|
2021-08-05 20:39:18 +00:00
|
|
|
replacePath(&stack, path, false);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == count(stack));
|
|
|
|
replacePath(&stack, path, false);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == count(stack));
|
2013-06-11 11:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Replacing rect with path.
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.replaceClip(rect, true);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
2021-08-05 20:39:18 +00:00
|
|
|
replacePath(&stack, path, true);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == count(stack));
|
2013-06-11 11:01:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(overlapLeft, SkMatrix::I(), SkClipOp::kIntersect, false);
|
|
|
|
stack.clipRect(overlapRight, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-08-02 12:49:00 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
|
|
|
|
stack.getBounds(&bound, &type, &isIntersectionOfRects);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, isIntersectionOfRects);
|
|
|
|
}
|
|
|
|
|
|
|
|
// all aa overlapping - should merge
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(overlapLeft, SkMatrix::I(), SkClipOp::kIntersect, true);
|
|
|
|
stack.clipRect(overlapRight, SkMatrix::I(), SkClipOp::kIntersect, true);
|
2012-08-02 12:49:00 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
|
|
|
|
stack.getBounds(&bound, &type, &isIntersectionOfRects);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, isIntersectionOfRects);
|
|
|
|
}
|
|
|
|
|
|
|
|
// mixed overlapping - should _not_ merge
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(overlapLeft, SkMatrix::I(), SkClipOp::kIntersect, true);
|
|
|
|
stack.clipRect(overlapRight, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-08-02 12:49:00 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 2 == count(stack));
|
|
|
|
|
|
|
|
stack.getBounds(&bound, &type, &isIntersectionOfRects);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, !isIntersectionOfRects);
|
|
|
|
}
|
|
|
|
|
|
|
|
// mixed nested (bw inside aa) - should merge
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(nestedParent, SkMatrix::I(), SkClipOp::kIntersect, true);
|
|
|
|
stack.clipRect(nestedChild, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-08-02 12:49:00 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
|
|
|
|
stack.getBounds(&bound, &type, &isIntersectionOfRects);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, isIntersectionOfRects);
|
|
|
|
}
|
|
|
|
|
|
|
|
// mixed nested (aa inside bw) - should merge
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(nestedParent, SkMatrix::I(), SkClipOp::kIntersect, false);
|
|
|
|
stack.clipRect(nestedChild, SkMatrix::I(), SkClipOp::kIntersect, true);
|
2012-08-02 12:49:00 +00:00
|
|
|
|
|
|
|
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;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(nestedChild, SkMatrix::I(), SkClipOp::kIntersect, false);
|
|
|
|
stack.clipRect(nestedParent, SkMatrix::I(), SkClipOp::kIntersect, true);
|
2012-08-02 12:49:00 +00:00
|
|
|
|
|
|
|
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;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(outsideRect, SkMatrix::I(), SkClipOp::kDifference, false);
|
|
|
|
// return false because quickContains currently does not care for kDifference
|
2012-12-12 17:58:15 +00:00
|
|
|
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;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.replaceClip(outsideRect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(insideRect, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
stack.save(); // To prevent in-place substitution by replace OP
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.replaceClip(outsideRect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
stack.restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(outsideRect, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
stack.save(); // To prevent in-place substitution by replace OP
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.replaceClip(insideRect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
stack.restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify proper traversal of multi-element clip
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(insideRect, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
// Use a path for second clip to prevent in-place intersection
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(outsideCircle, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intersect Op tests with rectangles
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(outsideRect, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(insideRect, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(intersectingRect, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect(nonIntersectingRect, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intersect Op tests with circle paths
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(outsideCircle, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(insideCircle, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(intersectingCircle, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(nonIntersectingCircle, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intersect Op tests with inverse filled rectangles
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(outsideRect);
|
|
|
|
path.toggleInverseFillType();
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(insideRect);
|
|
|
|
path.toggleInverseFillType();
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(intersectingRect);
|
|
|
|
path.toggleInverseFillType();
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(nonIntersectingRect);
|
|
|
|
path.toggleInverseFillType();
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intersect Op tests with inverse filled circles
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path = outsideCircle;
|
|
|
|
path.toggleInverseFillType();
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path = insideCircle;
|
|
|
|
path.toggleInverseFillType();
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path = intersectingCircle;
|
|
|
|
path.toggleInverseFillType();
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path = nonIntersectingCircle;
|
|
|
|
path.toggleInverseFillType();
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-22 15:39:06 +00:00
|
|
|
static void set_region_to_stack(const SkClipStack& stack, const SkIRect& bounds, SkRegion* region) {
|
|
|
|
region->setRect(bounds);
|
|
|
|
SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart);
|
|
|
|
while (const SkClipStack::Element *element = iter.next()) {
|
|
|
|
SkRegion elemRegion;
|
|
|
|
SkRegion boundsRgn(bounds);
|
|
|
|
SkPath path;
|
|
|
|
|
2017-08-30 15:37:57 +00:00
|
|
|
switch (element->getDeviceSpaceType()) {
|
|
|
|
case SkClipStack::Element::DeviceSpaceType::kEmpty:
|
2016-07-22 15:39:06 +00:00
|
|
|
elemRegion.setEmpty();
|
|
|
|
break;
|
|
|
|
default:
|
2017-08-30 15:37:57 +00:00
|
|
|
element->asDeviceSpacePath(&path);
|
2016-07-22 15:39:06 +00:00
|
|
|
elemRegion.setPath(path, boundsRgn);
|
|
|
|
break;
|
|
|
|
}
|
2020-06-05 15:29:36 +00:00
|
|
|
|
2021-08-09 16:21:52 +00:00
|
|
|
region->op(elemRegion, element->isReplaceOp() ? SkRegion::kReplace_Op
|
|
|
|
: (SkRegion::Op) element->getOp());
|
2016-07-22 15:39:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_invfill_diff_bug(skiatest::Reporter* reporter) {
|
|
|
|
SkClipStack stack;
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipRect({10, 10, 20, 20}, SkMatrix::I(), SkClipOp::kIntersect, false);
|
2016-07-22 15:39:06 +00:00
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
path.addRect({30, 10, 40, 20});
|
2019-11-26 17:17:17 +00:00
|
|
|
path.setFillType(SkPathFillType::kInverseWinding);
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), SkClipOp::kDifference, false);
|
2016-07-22 15:39:06 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::kEmptyGenID == stack.getTopmostGenID());
|
|
|
|
|
|
|
|
SkRect stackBounds;
|
|
|
|
SkClipStack::BoundsType stackBoundsType;
|
|
|
|
stack.getBounds(&stackBounds, &stackBoundsType);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, stackBounds.isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::kNormal_BoundsType == stackBoundsType);
|
|
|
|
|
|
|
|
SkRegion region;
|
|
|
|
set_region_to_stack(stack, {0, 0, 50, 30}, ®ion);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, region.isEmpty());
|
|
|
|
}
|
|
|
|
|
2012-11-26 21:19:43 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-04-19 19:37:28 +00:00
|
|
|
static void test_is_rrect_deep_rect_stack(skiatest::Reporter* reporter) {
|
|
|
|
static constexpr SkRect kTargetBounds = SkRect::MakeWH(1000, 500);
|
|
|
|
// All antialiased or all not antialiased.
|
|
|
|
for (bool aa : {false, true}) {
|
|
|
|
SkClipStack stack;
|
|
|
|
for (int i = 0; i <= 100; ++i) {
|
|
|
|
stack.save();
|
|
|
|
stack.clipRect(SkRect::MakeLTRB(i, 0.5, kTargetBounds.width(), kTargetBounds.height()),
|
|
|
|
SkMatrix::I(), SkClipOp::kIntersect, aa);
|
|
|
|
}
|
|
|
|
SkRRect rrect;
|
|
|
|
bool isAA;
|
|
|
|
SkRRect expected = SkRRect::MakeRect(
|
|
|
|
SkRect::MakeLTRB(100, 0.5, kTargetBounds.width(), kTargetBounds.height()));
|
|
|
|
if (stack.isRRect(kTargetBounds, &rrect, &isAA)) {
|
|
|
|
REPORTER_ASSERT(reporter, rrect == expected);
|
|
|
|
REPORTER_ASSERT(reporter, aa == isAA);
|
|
|
|
} else {
|
|
|
|
ERRORF(reporter, "Expected to be an rrect.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Mixed AA and non-AA without simple containment.
|
|
|
|
SkClipStack stack;
|
|
|
|
for (int i = 0; i <= 100; ++i) {
|
|
|
|
bool aa = i & 0b1;
|
|
|
|
int j = 100 - i;
|
|
|
|
stack.save();
|
|
|
|
stack.clipRect(SkRect::MakeLTRB(i, j + 0.5, kTargetBounds.width(), kTargetBounds.height()),
|
|
|
|
SkMatrix::I(), SkClipOp::kIntersect, aa);
|
|
|
|
}
|
|
|
|
SkRRect rrect;
|
|
|
|
bool isAA;
|
|
|
|
REPORTER_ASSERT(reporter, !stack.isRRect(kTargetBounds, &rrect, &isAA));
|
|
|
|
}
|
|
|
|
|
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++) {
|
2021-08-05 20:39:18 +00:00
|
|
|
stack.clipDevRect(gRects[i], SkClipOp::kIntersect);
|
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;
|
2019-08-24 23:39:13 +00:00
|
|
|
answer.setLTRB(25, 25, 75, 75);
|
2011-02-22 20:17:43 +00:00
|
|
|
|
2014-09-05 20:34:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, element);
|
2017-08-30 15:37:57 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
SkClipStack::Element::DeviceSpaceType::kRect == element->getDeviceSpaceType());
|
2021-08-05 20:39:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkClipOp::kIntersect == element->getOp());
|
2017-08-30 15:37:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, element->getDeviceSpaceRect() == 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);
|
2017-08-30 15:37:57 +00:00
|
|
|
test_bounds(reporter, SkClipStack::Element::DeviceSpaceType::kRect);
|
|
|
|
test_bounds(reporter, SkClipStack::Element::DeviceSpaceType::kRRect);
|
|
|
|
test_bounds(reporter, SkClipStack::Element::DeviceSpaceType::kPath);
|
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);
|
2016-07-22 15:39:06 +00:00
|
|
|
test_invfill_diff_bug(reporter);
|
2019-04-19 19:37:28 +00:00
|
|
|
test_is_rrect_deep_rect_stack(reporter);
|
2011-02-22 20:17:43 +00:00
|
|
|
}
|