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"
|
|
|
|
#include "include/gpu/GrConfig.h"
|
|
|
|
#include "include/gpu/GrContext.h"
|
|
|
|
#include "include/private/GrResourceKey.h"
|
2019-05-06 21:17:19 +00:00
|
|
|
#include "include/private/SkTemplates.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "src/core/SkClipOpPriv.h"
|
|
|
|
#include "src/core/SkClipStack.h"
|
|
|
|
#include "src/core/SkTLList.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrClip.h"
|
|
|
|
#include "src/gpu/GrClipStackClip.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/GrReducedClip.h"
|
|
|
|
#include "src/gpu/GrResourceCache.h"
|
2020-03-05 19:14:18 +00:00
|
|
|
#include "src/gpu/GrTexture.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2019-05-06 21:17:19 +00:00
|
|
|
#include "tests/Test.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/GrContextFactory.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>
|
|
|
|
|
2019-05-06 21:17:19 +00:00
|
|
|
class GrCaps;
|
|
|
|
|
|
|
|
typedef GrReducedClip::ElementList ElementList;
|
|
|
|
typedef GrReducedClip::InitialState InitialState;
|
|
|
|
|
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();
|
2016-12-09 14:00:50 +00:00
|
|
|
s.clipPath(p, SkMatrix::I(), kIntersect_SkClipOp, 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);
|
2016-12-09 14:00:50 +00:00
|
|
|
s.clipRect(r, SkMatrix::I(), kIntersect_SkClipOp, doAA);
|
2011-05-03 16:26:09 +00:00
|
|
|
r = SkRect::MakeLTRB(10, 11, 12, 13);
|
2016-12-09 14:00:50 +00:00
|
|
|
s.clipRect(r, SkMatrix::I(), kIntersect_SkClipOp, 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);
|
2016-12-09 14:00:50 +00:00
|
|
|
s.clipRect(r, SkMatrix::I(), kUnion_SkClipOp, 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);
|
2016-12-09 14:00:50 +00:00
|
|
|
s.clipRect(r, SkMatrix::I(), kUnion_SkClipOp, 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);
|
2016-12-09 14:00:50 +00:00
|
|
|
s.clipRect(r, SkMatrix::I(), kIntersect_SkClipOp, 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);
|
2016-12-09 14:00:50 +00:00
|
|
|
s.clipPath(rp, SkMatrix::I(), kUnion_SkClipOp, 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);
|
2016-12-09 14:00:50 +00:00
|
|
|
s.clipRect(r, SkMatrix::I(), kUnion_SkClipOp, 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);
|
2016-12-09 14:00:50 +00:00
|
|
|
s.clipPath(p, SkMatrix::I(), kIntersect_SkClipOp, 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
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(gRects[i], SkMatrix::I(), kUnion_SkClipOp, 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);
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
element = iter.skipToTopmost(kUnion_SkClipOp);
|
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) {
|
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 },
|
|
|
|
};
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
static const SkClipOp gOps[] = {
|
|
|
|
kIntersect_SkClipOp,
|
|
|
|
kDifference_SkClipOp,
|
|
|
|
kUnion_SkClipOp,
|
|
|
|
kXOR_SkClipOp,
|
|
|
|
kReverseDifference_SkClipOp
|
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) {
|
2017-08-30 15:37:57 +00:00
|
|
|
case SkClipStack::Element::DeviceSpaceType::kEmpty:
|
2014-02-16 13:25:24 +00:00
|
|
|
SkDEBUGFAIL("Don't call this with kEmpty.");
|
|
|
|
break;
|
2017-08-30 15:37:57 +00:00
|
|
|
case SkClipStack::Element::DeviceSpaceType::kRect:
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rectA, SkMatrix::I(), kIntersect_SkClipOp, 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:
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRRect(rrectA, SkMatrix::I(), kIntersect_SkClipOp, 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:
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(pathA, SkMatrix::I(), kIntersect_SkClipOp, 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 ==
|
2016-12-09 14:00:50 +00:00
|
|
|
(gOps[op] == kIntersect_SkClipOp));
|
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 case where the user specifies a union that includes everything
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
SkPath clipA, clipB;
|
|
|
|
|
|
|
|
clipA.addRoundRect(rectA, SkIntToScalar(5), SkIntToScalar(5));
|
2019-11-26 17:17:17 +00:00
|
|
|
clipA.setFillType(SkPathFillType::kInverseEvenOdd);
|
2012-07-26 18:39:13 +00:00
|
|
|
|
|
|
|
clipB.addRoundRect(rectB, SkIntToScalar(5), SkIntToScalar(5));
|
2019-11-26 17:17:17 +00:00
|
|
|
clipB.setFillType(SkPathFillType::kInverseEvenOdd);
|
2012-07-26 18:39:13 +00:00
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(clipA, SkMatrix::I(), kReplace_SkClipOp, false);
|
|
|
|
stack.clipPath(clipB, SkMatrix::I(), kUnion_SkClipOp, 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 union w/ a wide open clip
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rectA, SkMatrix::I(), kUnion_SkClipOp, 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 empty difference from a wide open clip
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
SkRect emptyRect;
|
|
|
|
emptyRect.setEmpty();
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(emptyRect, SkMatrix::I(), kDifference_SkClipOp, 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();
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rectA, SkMatrix::I(), kReplace_SkClipOp, 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;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, 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));
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, false);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, 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));
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, true);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, 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));
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, false);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, true);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, 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;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, false);
|
|
|
|
stack.clipRect(rect2, SkMatrix::I(), kIntersect_SkClipOp, false);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
|
|
|
|
stack.save();
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, 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();
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, false);
|
|
|
|
stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, 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();
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, false);
|
|
|
|
stack.clipRect(rect2, SkMatrix::I(), kIntersect_SkClipOp, false);
|
|
|
|
stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, 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) {
|
|
|
|
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));
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), kReplace_SkClipOp, false);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), kReplace_SkClipOp, false);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replacing rect with path.
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, true);
|
2013-06-11 11:01:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == count(stack));
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), kReplace_SkClipOp, true);
|
2013-06-11 11:01:48 +00:00
|
|
|
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;
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(overlapLeft, SkMatrix::I(), kReplace_SkClipOp, false);
|
2012-08-02 12:49:00 +00:00
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(overlapRight, SkMatrix::I(), kIntersect_SkClipOp, 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;
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(overlapLeft, SkMatrix::I(), kReplace_SkClipOp, true);
|
2012-08-02 12:49:00 +00:00
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(overlapRight, SkMatrix::I(), kIntersect_SkClipOp, 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;
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(overlapLeft, SkMatrix::I(), kReplace_SkClipOp, true);
|
2012-08-02 12:49:00 +00:00
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(overlapRight, SkMatrix::I(), kIntersect_SkClipOp, 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;
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(nestedParent, SkMatrix::I(), kReplace_SkClipOp, true);
|
2012-08-02 12:49:00 +00:00
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(nestedChild, SkMatrix::I(), kIntersect_SkClipOp, 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;
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(nestedParent, SkMatrix::I(), kReplace_SkClipOp, false);
|
2012-08-02 12:49:00 +00:00
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(nestedChild, SkMatrix::I(), kIntersect_SkClipOp, 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;
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(nestedChild, SkMatrix::I(), kReplace_SkClipOp, false);
|
2012-08-02 12:49:00 +00:00
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(nestedParent, SkMatrix::I(), kIntersect_SkClipOp, 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;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(outsideRect, SkMatrix::I(), kDifference_SkClipOp, false);
|
|
|
|
// return false because quickContains currently does not care for kDifference_SkClipOp
|
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;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(outsideRect, SkMatrix::I(), kReplace_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(insideRect, SkMatrix::I(), kIntersect_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
stack.save(); // To prevent in-place substitution by replace OP
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(outsideRect, SkMatrix::I(), kReplace_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
stack.restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(outsideRect, SkMatrix::I(), kIntersect_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
stack.save(); // To prevent in-place substitution by replace OP
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(insideRect, SkMatrix::I(), kReplace_SkClipOp, 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;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(insideRect, SkMatrix::I(), kIntersect_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
// Use a path for second clip to prevent in-place intersection
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(outsideCircle, SkMatrix::I(), kIntersect_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intersect Op tests with rectangles
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(outsideRect, SkMatrix::I(), kIntersect_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(insideRect, SkMatrix::I(), kIntersect_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(intersectingRect, SkMatrix::I(), kIntersect_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(nonIntersectingRect, SkMatrix::I(), kIntersect_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intersect Op tests with circle paths
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(outsideCircle, SkMatrix::I(), kIntersect_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, true == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(insideCircle, SkMatrix::I(), kIntersect_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(intersectingCircle, SkMatrix::I(), kIntersect_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(nonIntersectingCircle, SkMatrix::I(), kIntersect_SkClipOp, 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();
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, 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();
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, 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();
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, 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();
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, 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();
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path = insideCircle;
|
|
|
|
path.toggleInverseFillType();
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path = intersectingCircle;
|
|
|
|
path.toggleInverseFillType();
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, false);
|
2012-12-12 17:58:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, false == stack.quickContains(testRect));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
SkPath path = nonIntersectingCircle;
|
|
|
|
path.toggleInverseFillType();
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, 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;
|
|
|
|
}
|
2016-09-20 15:42:38 +00:00
|
|
|
region->op(elemRegion, (SkRegion::Op)element->getOp());
|
2016-07-22 15:39:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_invfill_diff_bug(skiatest::Reporter* reporter) {
|
|
|
|
SkClipStack stack;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect({10, 10, 20, 20}, SkMatrix::I(), kIntersect_SkClipOp, 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);
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipPath(path, SkMatrix::I(), kDifference_SkClipOp, 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
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
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,
|
2016-12-09 14:00:50 +00:00
|
|
|
SkClipOp op,
|
2016-07-22 15:59:08 +00:00
|
|
|
SkClipStack* stack,
|
|
|
|
bool doAA);
|
2012-11-27 15:43:57 +00:00
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
static void add_round_rect(const SkRect& rect, bool invert, SkClipOp op, SkClipStack* stack,
|
2016-07-22 15:59:08 +00:00
|
|
|
bool doAA) {
|
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);
|
2019-11-26 17:17:17 +00:00
|
|
|
path.setFillType(SkPathFillType::kInverseWinding);
|
2016-10-03 15:36:16 +00:00
|
|
|
stack->clipPath(path, SkMatrix::I(), op, doAA);
|
2014-02-16 13:25:24 +00:00
|
|
|
} else {
|
|
|
|
SkRRect rrect;
|
|
|
|
rrect.setRectXY(rect, rx, ry);
|
2016-10-03 15:36:16 +00:00
|
|
|
stack->clipRRect(rrect, SkMatrix::I(), op, doAA);
|
2012-11-27 15:43:57 +00:00
|
|
|
}
|
2012-11-26 21:19:43 +00:00
|
|
|
};
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
static void add_rect(const SkRect& rect, bool invert, SkClipOp op, SkClipStack* stack,
|
2016-07-22 15:59:08 +00:00
|
|
|
bool doAA) {
|
2012-11-27 15:43:57 +00:00
|
|
|
if (invert) {
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(rect);
|
2019-11-26 17:17:17 +00:00
|
|
|
path.setFillType(SkPathFillType::kInverseWinding);
|
2016-10-03 15:36:16 +00:00
|
|
|
stack->clipPath(path, SkMatrix::I(), op, doAA);
|
2012-11-27 15:43:57 +00:00
|
|
|
} else {
|
2016-10-03 15:36:16 +00:00
|
|
|
stack->clipRect(rect, SkMatrix::I(), op, doAA);
|
2012-11-27 15:43:57 +00:00
|
|
|
}
|
2012-11-26 21:19:43 +00:00
|
|
|
};
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
static void add_oval(const SkRect& rect, bool invert, SkClipOp op, SkClipStack* stack,
|
2016-07-22 15:59:08 +00:00
|
|
|
bool doAA) {
|
2012-11-26 21:19:43 +00:00
|
|
|
SkPath path;
|
|
|
|
path.addOval(rect);
|
2012-11-27 15:43:57 +00:00
|
|
|
if (invert) {
|
2019-11-26 17:17:17 +00:00
|
|
|
path.setFillType(SkPathFillType::kInverseWinding);
|
2012-11-27 15:43:57 +00:00
|
|
|
}
|
2016-10-03 15:36:16 +00:00
|
|
|
stack->clipPath(path, SkMatrix::I(), op, doAA);
|
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) {
|
2017-08-30 15:37:57 +00:00
|
|
|
switch (element.getDeviceSpaceType()) {
|
|
|
|
case SkClipStack::Element::DeviceSpaceType::kRect:
|
|
|
|
stack->clipRect(element.getDeviceSpaceRect(), SkMatrix::I(), element.getOp(),
|
|
|
|
element.isAA());
|
2012-12-04 14:06:06 +00:00
|
|
|
break;
|
2017-08-30 15:37:57 +00:00
|
|
|
case SkClipStack::Element::DeviceSpaceType::kRRect:
|
|
|
|
stack->clipRRect(element.getDeviceSpaceRRect(), SkMatrix::I(), element.getOp(),
|
|
|
|
element.isAA());
|
2014-02-16 13:25:24 +00:00
|
|
|
break;
|
2017-08-30 15:37:57 +00:00
|
|
|
case SkClipStack::Element::DeviceSpaceType::kPath:
|
|
|
|
stack->clipPath(element.getDeviceSpacePath(), SkMatrix::I(), element.getOp(),
|
|
|
|
element.isAA());
|
2012-12-04 14:06:06 +00:00
|
|
|
break;
|
2017-08-30 15:37:57 +00:00
|
|
|
case SkClipStack::Element::DeviceSpaceType::kEmpty:
|
2012-12-04 14:06:06 +00:00
|
|
|
SkDEBUGFAIL("Why did the reducer produce an explicit empty.");
|
|
|
|
stack->clipEmpty();
|
|
|
|
break;
|
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.
|
2016-08-15 18:17:19 +00:00
|
|
|
static const SkIRect kIBounds = SkIRect::MakeWH(100, 100);
|
|
|
|
static const SkRect kBounds = SkRect::Make(kIBounds);
|
2012-11-26 21:19:43 +00:00
|
|
|
|
|
|
|
enum {
|
2016-07-22 15:59:08 +00:00
|
|
|
kNumTests = 250,
|
2012-11-26 21:19:43 +00:00
|
|
|
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;
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
static const SkClipOp kOps[] = {
|
|
|
|
kDifference_SkClipOp,
|
|
|
|
kIntersect_SkClipOp,
|
|
|
|
kUnion_SkClipOp,
|
|
|
|
kXOR_SkClipOp,
|
|
|
|
kReverseDifference_SkClipOp,
|
|
|
|
kReplace_SkClipOp,
|
2012-11-26 21:19:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2016-07-22 15:59:08 +00:00
|
|
|
static const SkScalar kFractionAntialiased = 0.25;
|
|
|
|
|
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) {
|
2016-07-22 15:59:08 +00:00
|
|
|
SkString testCase;
|
|
|
|
testCase.printf("Iteration %d", i);
|
|
|
|
|
2012-11-26 21:19:43 +00:00
|
|
|
// Randomly generate a clip stack.
|
|
|
|
SkClipStack stack;
|
|
|
|
int numElems = r.nextRangeU(kMinElemsPerTest, kMaxElemsPerTest);
|
2016-07-22 15:59:08 +00:00
|
|
|
bool doAA = r.nextBiasedBool(kFractionAntialiased);
|
2012-11-26 21:19:43 +00:00
|
|
|
for (int e = 0; e < numElems; ++e) {
|
2016-12-09 14:00:50 +00:00
|
|
|
SkClipOp op = kOps[r.nextULessThan(SK_ARRAY_COUNT(kOps))];
|
|
|
|
if (op == kReplace_SkClipOp) {
|
2012-11-26 21:19:43 +00:00
|
|
|
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(
|
2017-02-14 15:59:19 +00:00
|
|
|
kBounds.width() * r.nextRangeScalar(kMinElemSizeFrac, kMaxElemSizeFrac),
|
|
|
|
kBounds.height() * r.nextRangeScalar(kMinElemSizeFrac, kMaxElemSizeFrac));
|
2016-07-22 15:59:08 +00:00
|
|
|
|
|
|
|
SkPoint xy = {r.nextRangeScalar(kBounds.fLeft, kBounds.fRight - size.fWidth),
|
|
|
|
r.nextRangeScalar(kBounds.fTop, kBounds.fBottom - size.fHeight)};
|
|
|
|
|
|
|
|
SkRect rect;
|
|
|
|
if (doAA) {
|
|
|
|
rect.setXYWH(xy.fX, xy.fY, size.fWidth, size.fHeight);
|
|
|
|
if (GrClip::IsPixelAligned(rect)) {
|
|
|
|
// Don't create an element that may accidentally become not antialiased.
|
|
|
|
rect.outset(0.5f, 0.5f);
|
|
|
|
}
|
|
|
|
SkASSERT(!GrClip::IsPixelAligned(rect));
|
|
|
|
} else {
|
|
|
|
rect.setXYWH(SkScalarFloorToScalar(xy.fX),
|
|
|
|
SkScalarFloorToScalar(xy.fY),
|
|
|
|
SkScalarCeilToScalar(size.fWidth),
|
|
|
|
SkScalarCeilToScalar(size.fHeight));
|
|
|
|
}
|
2012-11-26 21:19:43 +00:00
|
|
|
|
2012-11-27 15:43:57 +00:00
|
|
|
bool invert = r.nextBiasedBool(kFractionInverted);
|
2014-02-16 13:25:24 +00:00
|
|
|
|
2016-07-22 15:59:08 +00:00
|
|
|
kElementFuncs[r.nextULessThan(SK_ARRAY_COUNT(kElementFuncs))](rect, invert, op, &stack,
|
|
|
|
doAA);
|
2012-11-26 21:19:43 +00:00
|
|
|
if (doSave) {
|
|
|
|
stack.save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 15:35:15 +00:00
|
|
|
auto context = GrContext::MakeMock(nullptr);
|
2019-02-04 18:26:26 +00:00
|
|
|
const GrCaps* caps = context->priv().caps();
|
2017-12-05 15:35:15 +00:00
|
|
|
|
2018-07-09 18:23:58 +00:00
|
|
|
// Zero the memory we will new the GrReducedClip into. This ensures the elements gen ID
|
|
|
|
// will be kInvalidGenID if left uninitialized.
|
|
|
|
SkAlignedSTStorage<1, GrReducedClip> storage;
|
|
|
|
memset(storage.get(), 0, sizeof(GrReducedClip));
|
2019-12-18 15:43:10 +00:00
|
|
|
static_assert(0 == SkClipStack::kInvalidGenID);
|
2018-07-09 18:23:58 +00:00
|
|
|
|
2016-08-08 16:55:06 +00:00
|
|
|
// Get the reduced version of the stack.
|
2016-07-22 15:59:08 +00:00
|
|
|
SkRect queryBounds = kBounds;
|
|
|
|
queryBounds.outset(kBounds.width() / 2, kBounds.height() / 2);
|
2018-10-15 20:09:54 +00:00
|
|
|
const GrReducedClip* reduced = new (storage.get()) GrReducedClip(stack, queryBounds, caps);
|
2012-12-04 15:22:12 +00:00
|
|
|
|
2018-07-09 18:23:58 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
reduced->maskElements().isEmpty() ||
|
|
|
|
SkClipStack::kInvalidGenID != reduced->maskGenID(),
|
|
|
|
testCase.c_str());
|
2016-07-22 15:59:08 +00:00
|
|
|
|
2018-07-09 18:23:58 +00:00
|
|
|
if (!reduced->maskElements().isEmpty()) {
|
|
|
|
REPORTER_ASSERT(reporter, reduced->hasScissor(), testCase.c_str());
|
2016-07-22 15:59:08 +00:00
|
|
|
SkRect stackBounds;
|
|
|
|
SkClipStack::BoundsType stackBoundsType;
|
|
|
|
stack.getBounds(&stackBounds, &stackBoundsType);
|
2018-07-09 18:23:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, reduced->maskRequiresAA() == doAA, testCase.c_str());
|
2016-07-22 15:59:08 +00:00
|
|
|
}
|
2013-11-05 15:03:08 +00:00
|
|
|
|
2012-11-26 21:19:43 +00:00
|
|
|
// Build a new clip stack based on the reduced clip elements
|
|
|
|
SkClipStack reducedStack;
|
2018-07-09 18:23:58 +00:00
|
|
|
if (GrReducedClip::InitialState::kAllOut == reduced->initialState()) {
|
2012-11-26 21:19:43 +00:00
|
|
|
// whether the result is bounded or not, the whole plane should start outside the clip.
|
|
|
|
reducedStack.clipEmpty();
|
|
|
|
}
|
2018-07-09 18:23:58 +00:00
|
|
|
for (ElementList::Iter iter(reduced->maskElements()); iter.get(); iter.next()) {
|
|
|
|
add_elem_to_stack(*iter.get(), &reducedStack);
|
2012-11-26 21:19:43 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 18:23:58 +00:00
|
|
|
SkIRect scissor = reduced->hasScissor() ? reduced->scissor() : kIBounds;
|
2016-08-15 18:17:19 +00:00
|
|
|
|
2012-12-06 14:23:20 +00:00
|
|
|
// GrReducedClipStack assumes that the final result is clipped to the returned bounds
|
2017-10-27 07:50:57 +00:00
|
|
|
reducedStack.clipDevRect(scissor, kIntersect_SkClipOp);
|
|
|
|
stack.clipDevRect(scissor, kIntersect_SkClipOp);
|
2012-12-06 14:23:20 +00:00
|
|
|
|
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;
|
2017-10-27 07:50:57 +00:00
|
|
|
set_region_to_stack(stack, scissor, ®ion);
|
2012-11-26 21:19:43 +00:00
|
|
|
|
2016-07-22 15:39:06 +00:00
|
|
|
SkRegion reducedRegion;
|
2017-10-27 07:50:57 +00:00
|
|
|
set_region_to_stack(reducedStack, scissor, &reducedRegion);
|
2012-11-26 21:19:43 +00:00
|
|
|
|
2018-01-29 14:50:47 +00:00
|
|
|
REPORTER_ASSERT(reporter, region == reducedRegion, testCase.c_str());
|
2018-07-09 18:23:58 +00:00
|
|
|
|
|
|
|
reduced->~GrReducedClip();
|
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
|
|
|
|
|
2018-07-09 18:23:58 +00:00
|
|
|
static void test_reduced_clip_stack_genid(skiatest::Reporter* reporter) {
|
2013-11-05 15:03:08 +00:00
|
|
|
{
|
|
|
|
SkClipStack stack;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(SkRect::MakeXYWH(0, 0, 100, 100), SkMatrix::I(), kReplace_SkClipOp,
|
2016-10-03 15:36:16 +00:00
|
|
|
true);
|
|
|
|
stack.clipRect(SkRect::MakeXYWH(0, 0, SkScalar(50.3), SkScalar(50.3)), SkMatrix::I(),
|
2016-12-09 14:00:50 +00:00
|
|
|
kReplace_SkClipOp, true);
|
2016-07-22 15:59:08 +00:00
|
|
|
SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100);
|
2013-11-05 15:03:08 +00:00
|
|
|
|
2017-12-05 15:35:15 +00:00
|
|
|
auto context = GrContext::MakeMock(nullptr);
|
2019-02-04 18:26:26 +00:00
|
|
|
const GrCaps* caps = context->priv().caps();
|
2017-12-05 15:35:15 +00:00
|
|
|
|
2018-07-09 18:23:58 +00:00
|
|
|
SkAlignedSTStorage<1, GrReducedClip> storage;
|
|
|
|
memset(storage.get(), 0, sizeof(GrReducedClip));
|
2019-12-18 15:43:10 +00:00
|
|
|
static_assert(0 == SkClipStack::kInvalidGenID);
|
2018-10-15 20:09:54 +00:00
|
|
|
const GrReducedClip* reduced = new (storage.get()) GrReducedClip(stack, bounds, caps);
|
2018-07-09 18:23:58 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, reduced->maskElements().count() == 1);
|
|
|
|
// Clips will be cached based on the generation id. Make sure the gen id is valid.
|
|
|
|
REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reduced->maskGenID());
|
|
|
|
|
|
|
|
reduced->~GrReducedClip();
|
2013-11-05 15:03:08 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
// Create a clip with following 25.3, 25.3 boxes which are 25 apart:
|
|
|
|
// A B
|
|
|
|
// C D
|
|
|
|
|
2016-10-03 15:36:16 +00:00
|
|
|
stack.clipRect(SkRect::MakeXYWH(0, 0, SkScalar(25.3), SkScalar(25.3)), SkMatrix::I(),
|
2016-12-09 14:00:50 +00:00
|
|
|
kReplace_SkClipOp, true);
|
2017-06-28 19:23:59 +00:00
|
|
|
uint32_t genIDA = stack.getTopmostGenID();
|
2016-10-03 15:36:16 +00:00
|
|
|
stack.clipRect(SkRect::MakeXYWH(50, 0, SkScalar(25.3), SkScalar(25.3)), SkMatrix::I(),
|
2016-12-09 14:00:50 +00:00
|
|
|
kUnion_SkClipOp, true);
|
2017-06-28 19:23:59 +00:00
|
|
|
uint32_t genIDB = stack.getTopmostGenID();
|
2016-10-03 15:36:16 +00:00
|
|
|
stack.clipRect(SkRect::MakeXYWH(0, 50, SkScalar(25.3), SkScalar(25.3)), SkMatrix::I(),
|
2016-12-09 14:00:50 +00:00
|
|
|
kUnion_SkClipOp, true);
|
2017-06-28 19:23:59 +00:00
|
|
|
uint32_t genIDC = stack.getTopmostGenID();
|
2016-10-03 15:36:16 +00:00
|
|
|
stack.clipRect(SkRect::MakeXYWH(50, 50, SkScalar(25.3), SkScalar(25.3)), SkMatrix::I(),
|
2016-12-09 14:00:50 +00:00
|
|
|
kUnion_SkClipOp, true);
|
2017-06-28 19:23:59 +00:00
|
|
|
uint32_t genIDD = stack.getTopmostGenID();
|
2013-11-05 15:03:08 +00:00
|
|
|
|
|
|
|
|
2016-07-22 15:59:08 +00:00
|
|
|
#define IXYWH SkIRect::MakeXYWH
|
|
|
|
#define XYWH SkRect::MakeXYWH
|
2013-11-05 15:03:08 +00:00
|
|
|
|
2016-07-22 15:59:08 +00:00
|
|
|
SkIRect stackBounds = IXYWH(0, 0, 76, 76);
|
2013-11-05 15:03:08 +00:00
|
|
|
|
|
|
|
// 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 {
|
2016-07-22 15:59:08 +00:00
|
|
|
SkRect testBounds;
|
2013-11-05 15:03:08 +00:00
|
|
|
int reducedClipCount;
|
2018-07-09 18:23:58 +00:00
|
|
|
uint32_t reducedGenID;
|
2016-07-22 15:59:08 +00:00
|
|
|
InitialState initialState;
|
|
|
|
SkIRect clipIRect;
|
2013-11-05 15:03:08 +00:00
|
|
|
// parameter.
|
|
|
|
} testCases[] = {
|
2016-08-08 16:55:06 +00:00
|
|
|
|
2013-11-05 15:03:08 +00:00
|
|
|
// Rect A.
|
2016-08-17 16:39:38 +00:00
|
|
|
{ XYWH(0, 0, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(0, 0, 25, 25) },
|
|
|
|
{ XYWH(0.1f, 0.1f, 25.1f, 25.1f), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(0, 0, 26, 26) },
|
2017-10-27 07:50:57 +00:00
|
|
|
{ XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::InitialState::kAllOut, IXYWH(0, 0, 26, 26)},
|
2013-11-05 15:03:08 +00:00
|
|
|
|
|
|
|
// Rect B.
|
2016-08-17 16:39:38 +00:00
|
|
|
{ XYWH(50, 0, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(50, 0, 25, 25) },
|
|
|
|
{ XYWH(50, 0, 25.3f, 25.3f), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(50, 0, 26, 26) },
|
2016-08-08 16:55:06 +00:00
|
|
|
{ XYWH(50, 0, 27, 27), 1, genIDB, GrReducedClip::InitialState::kAllOut, IXYWH(50, 0, 26, 27) },
|
2013-11-05 15:03:08 +00:00
|
|
|
|
|
|
|
// Rect C.
|
2016-08-17 16:39:38 +00:00
|
|
|
{ XYWH(0, 50, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(0, 50, 25, 25) },
|
|
|
|
{ XYWH(0.2f, 50.1f, 25.1f, 25.2f), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(0, 50, 26, 26) },
|
2016-08-08 16:55:06 +00:00
|
|
|
{ XYWH(0, 50, 27, 27), 1, genIDC, GrReducedClip::InitialState::kAllOut, IXYWH(0, 50, 27, 26) },
|
2013-11-05 15:03:08 +00:00
|
|
|
|
|
|
|
// Rect D.
|
2016-08-17 16:39:38 +00:00
|
|
|
{ XYWH(50, 50, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(50, 50, 25, 25)},
|
|
|
|
{ XYWH(50.3f, 50.3f, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(50, 50, 26, 26)},
|
2016-08-08 16:55:06 +00:00
|
|
|
{ XYWH(50, 50, 27, 27), 1, genIDD, GrReducedClip::InitialState::kAllOut, IXYWH(50, 50, 26, 26)},
|
2013-11-05 15:03:08 +00:00
|
|
|
|
|
|
|
// Other tests:
|
2016-08-08 16:55:06 +00:00
|
|
|
{ XYWH(0, 0, 100, 100), 4, genIDD, GrReducedClip::InitialState::kAllOut, stackBounds },
|
2013-11-05 15:03:08 +00:00
|
|
|
|
|
|
|
// Rect in the middle, touches none.
|
2016-08-17 16:39:38 +00:00
|
|
|
{ XYWH(26, 26, 24, 24), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllOut, IXYWH(26, 26, 24, 24) },
|
2013-11-05 15:03:08 +00:00
|
|
|
|
|
|
|
// Rect in the middle, touches all the rects. GenID is the last rect.
|
2016-08-08 16:55:06 +00:00
|
|
|
{ XYWH(24, 24, 27, 27), 4, genIDD, GrReducedClip::InitialState::kAllOut, IXYWH(24, 24, 27, 27) },
|
2013-11-05 15:03:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#undef XYWH
|
2016-07-22 15:59:08 +00:00
|
|
|
#undef IXYWH
|
2017-12-05 15:35:15 +00:00
|
|
|
auto context = GrContext::MakeMock(nullptr);
|
2019-02-04 18:26:26 +00:00
|
|
|
const GrCaps* caps = context->priv().caps();
|
2013-11-05 15:03:08 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(testCases); ++i) {
|
2018-10-15 20:09:54 +00:00
|
|
|
const GrReducedClip reduced(stack, testCases[i].testBounds, caps);
|
2017-10-27 07:50:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, reduced.maskElements().count() ==
|
|
|
|
testCases[i].reducedClipCount);
|
2018-07-09 18:23:58 +00:00
|
|
|
SkASSERT(reduced.maskElements().count() == testCases[i].reducedClipCount);
|
|
|
|
if (reduced.maskElements().count()) {
|
|
|
|
REPORTER_ASSERT(reporter, reduced.maskGenID() == testCases[i].reducedGenID);
|
|
|
|
SkASSERT(reduced.maskGenID() == testCases[i].reducedGenID);
|
2016-08-17 16:39:38 +00:00
|
|
|
}
|
2016-08-08 16:55:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, reduced.initialState() == testCases[i].initialState);
|
2018-07-09 18:23:58 +00:00
|
|
|
SkASSERT(reduced.initialState() == testCases[i].initialState);
|
2017-10-27 07:50:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, reduced.hasScissor());
|
2018-07-09 18:23:58 +00:00
|
|
|
SkASSERT(reduced.hasScissor());
|
2017-10-27 07:50:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, reduced.scissor() == testCases[i].clipIRect);
|
2018-07-09 18:23:58 +00:00
|
|
|
SkASSERT(reduced.scissor() == testCases[i].clipIRect);
|
2013-11-05 15:03:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_reduced_clip_stack_no_aa_crash(skiatest::Reporter* reporter) {
|
|
|
|
SkClipStack stack;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 100, 100), kReplace_SkClipOp);
|
|
|
|
stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 50, 50), kReplace_SkClipOp);
|
2016-07-22 15:59:08 +00:00
|
|
|
SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100);
|
2013-11-05 15:03:08 +00:00
|
|
|
|
2017-12-05 15:35:15 +00:00
|
|
|
auto context = GrContext::MakeMock(nullptr);
|
2019-02-04 18:26:26 +00:00
|
|
|
const GrCaps* caps = context->priv().caps();
|
2017-12-05 15:35:15 +00:00
|
|
|
|
2013-11-05 15:03:08 +00:00
|
|
|
// At the time, this would crash.
|
2018-10-15 20:09:54 +00:00
|
|
|
const GrReducedClip reduced(stack, bounds, caps);
|
2017-10-27 07:50:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, reduced.maskElements().isEmpty());
|
2013-11-05 15:03:08 +00:00
|
|
|
}
|
|
|
|
|
2016-07-22 15:59:08 +00:00
|
|
|
enum class ClipMethod {
|
|
|
|
kSkipDraw,
|
|
|
|
kIgnoreClip,
|
|
|
|
kScissor,
|
|
|
|
kAAElements
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_aa_query(skiatest::Reporter* reporter, const SkString& testName,
|
|
|
|
const SkClipStack& stack, const SkMatrix& queryXform,
|
|
|
|
const SkRect& preXformQuery, ClipMethod expectedMethod,
|
|
|
|
int numExpectedElems = 0) {
|
2017-12-05 15:35:15 +00:00
|
|
|
auto context = GrContext::MakeMock(nullptr);
|
2019-02-04 18:26:26 +00:00
|
|
|
const GrCaps* caps = context->priv().caps();
|
2017-12-05 15:35:15 +00:00
|
|
|
|
2016-07-22 15:59:08 +00:00
|
|
|
SkRect queryBounds;
|
|
|
|
queryXform.mapRect(&queryBounds, preXformQuery);
|
2018-10-15 20:09:54 +00:00
|
|
|
const GrReducedClip reduced(stack, queryBounds, caps);
|
2016-07-22 15:59:08 +00:00
|
|
|
|
|
|
|
SkClipStack::BoundsType stackBoundsType;
|
|
|
|
SkRect stackBounds;
|
|
|
|
stack.getBounds(&stackBounds, &stackBoundsType);
|
|
|
|
|
|
|
|
switch (expectedMethod) {
|
|
|
|
case ClipMethod::kSkipDraw:
|
|
|
|
SkASSERT(0 == numExpectedElems);
|
2018-01-29 14:50:47 +00:00
|
|
|
REPORTER_ASSERT(reporter, reduced.maskElements().isEmpty(), testName.c_str());
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
GrReducedClip::InitialState::kAllOut == reduced.initialState(),
|
|
|
|
testName.c_str());
|
2016-07-22 15:59:08 +00:00
|
|
|
return;
|
|
|
|
case ClipMethod::kIgnoreClip:
|
|
|
|
SkASSERT(0 == numExpectedElems);
|
2018-01-29 14:50:47 +00:00
|
|
|
REPORTER_ASSERT(
|
|
|
|
reporter,
|
|
|
|
!reduced.hasScissor() || GrClip::IsInsideClip(reduced.scissor(), queryBounds),
|
|
|
|
testName.c_str());
|
|
|
|
REPORTER_ASSERT(reporter, reduced.maskElements().isEmpty(), testName.c_str());
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
GrReducedClip::InitialState::kAllIn == reduced.initialState(),
|
|
|
|
testName.c_str());
|
2016-07-22 15:59:08 +00:00
|
|
|
return;
|
|
|
|
case ClipMethod::kScissor: {
|
|
|
|
SkASSERT(SkClipStack::kNormal_BoundsType == stackBoundsType);
|
|
|
|
SkASSERT(0 == numExpectedElems);
|
|
|
|
SkIRect expectedScissor;
|
|
|
|
stackBounds.round(&expectedScissor);
|
2018-01-29 14:50:47 +00:00
|
|
|
REPORTER_ASSERT(reporter, reduced.maskElements().isEmpty(), testName.c_str());
|
|
|
|
REPORTER_ASSERT(reporter, reduced.hasScissor(), testName.c_str());
|
|
|
|
REPORTER_ASSERT(reporter, expectedScissor == reduced.scissor(), testName.c_str());
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
GrReducedClip::InitialState::kAllIn == reduced.initialState(),
|
|
|
|
testName.c_str());
|
2016-07-22 15:59:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case ClipMethod::kAAElements: {
|
|
|
|
SkIRect expectedClipIBounds = GrClip::GetPixelIBounds(queryBounds);
|
|
|
|
if (SkClipStack::kNormal_BoundsType == stackBoundsType) {
|
|
|
|
SkAssertResult(expectedClipIBounds.intersect(GrClip::GetPixelIBounds(stackBounds)));
|
|
|
|
}
|
2018-01-29 14:50:47 +00:00
|
|
|
REPORTER_ASSERT(reporter, numExpectedElems == reduced.maskElements().count(),
|
|
|
|
testName.c_str());
|
|
|
|
REPORTER_ASSERT(reporter, reduced.hasScissor(), testName.c_str());
|
|
|
|
REPORTER_ASSERT(reporter, expectedClipIBounds == reduced.scissor(), testName.c_str());
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
reduced.maskElements().isEmpty() || reduced.maskRequiresAA(),
|
|
|
|
testName.c_str());
|
2016-07-22 15:59:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_reduced_clip_stack_aa(skiatest::Reporter* reporter) {
|
|
|
|
constexpr SkScalar IL = 2, IT = 1, IR = 6, IB = 7; // Pixel aligned rect.
|
|
|
|
constexpr SkScalar L = 2.2f, T = 1.7f, R = 5.8f, B = 7.3f; // Generic rect.
|
|
|
|
constexpr SkScalar l = 3.3f, t = 2.8f, r = 4.7f, b = 6.2f; // Small rect contained in R.
|
|
|
|
|
|
|
|
SkRect alignedRect = {IL, IT, IR, IB};
|
|
|
|
SkRect rect = {L, T, R, B};
|
|
|
|
SkRect innerRect = {l, t, r, b};
|
|
|
|
|
|
|
|
SkMatrix m;
|
|
|
|
m.setIdentity();
|
|
|
|
|
|
|
|
constexpr SkScalar kMinScale = 2.0001f;
|
|
|
|
constexpr SkScalar kMaxScale = 3;
|
|
|
|
constexpr int kNumIters = 8;
|
|
|
|
|
|
|
|
SkString name;
|
|
|
|
SkRandom rand;
|
|
|
|
|
|
|
|
for (int i = 0; i < kNumIters; ++i) {
|
|
|
|
// Pixel-aligned rect (iior=true).
|
|
|
|
name.printf("Pixel-aligned rect test, iter %i", i);
|
|
|
|
SkClipStack stack;
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(alignedRect, SkMatrix::I(), kIntersect_SkClipOp, true);
|
2016-07-22 15:59:08 +00:00
|
|
|
test_aa_query(reporter, name, stack, m, {IL, IT, IR, IB}, ClipMethod::kIgnoreClip);
|
|
|
|
test_aa_query(reporter, name, stack, m, {IL, IT-1, IR, IT}, ClipMethod::kSkipDraw);
|
2016-08-08 16:55:06 +00:00
|
|
|
test_aa_query(reporter, name, stack, m, {IL, IT-2, IR, IB}, ClipMethod::kScissor);
|
2016-07-22 15:59:08 +00:00
|
|
|
|
|
|
|
// Rect (iior=true).
|
|
|
|
name.printf("Rect test, iter %i", i);
|
|
|
|
stack.reset();
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rect, SkMatrix::I(), kIntersect_SkClipOp, true);
|
2016-07-22 15:59:08 +00:00
|
|
|
test_aa_query(reporter, name, stack, m, {L, T, R, B}, ClipMethod::kIgnoreClip);
|
|
|
|
test_aa_query(reporter, name, stack, m, {L-.1f, T, L, B}, ClipMethod::kSkipDraw);
|
|
|
|
test_aa_query(reporter, name, stack, m, {L-.1f, T, L+.1f, B}, ClipMethod::kAAElements, 1);
|
|
|
|
|
|
|
|
// Difference rect (iior=false, inside-out bounds).
|
|
|
|
name.printf("Difference rect test, iter %i", i);
|
|
|
|
stack.reset();
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rect, SkMatrix::I(), kDifference_SkClipOp, true);
|
2016-07-22 15:59:08 +00:00
|
|
|
test_aa_query(reporter, name, stack, m, {L, T, R, B}, ClipMethod::kSkipDraw);
|
|
|
|
test_aa_query(reporter, name, stack, m, {L, T-.1f, R, T}, ClipMethod::kIgnoreClip);
|
|
|
|
test_aa_query(reporter, name, stack, m, {L, T-.1f, R, T+.1f}, ClipMethod::kAAElements, 1);
|
|
|
|
|
|
|
|
// Complex clip (iior=false, normal bounds).
|
|
|
|
name.printf("Complex clip test, iter %i", i);
|
|
|
|
stack.reset();
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(rect, SkMatrix::I(), kIntersect_SkClipOp, true);
|
|
|
|
stack.clipRect(innerRect, SkMatrix::I(), kXOR_SkClipOp, true);
|
2016-07-22 15:59:08 +00:00
|
|
|
test_aa_query(reporter, name, stack, m, {l, t, r, b}, ClipMethod::kSkipDraw);
|
|
|
|
test_aa_query(reporter, name, stack, m, {r-.1f, t, R, b}, ClipMethod::kAAElements, 1);
|
|
|
|
test_aa_query(reporter, name, stack, m, {r-.1f, t, R+.1f, b}, ClipMethod::kAAElements, 2);
|
|
|
|
test_aa_query(reporter, name, stack, m, {r, t, R+.1f, b}, ClipMethod::kAAElements, 1);
|
|
|
|
test_aa_query(reporter, name, stack, m, {r, t, R, b}, ClipMethod::kIgnoreClip);
|
|
|
|
test_aa_query(reporter, name, stack, m, {R, T, R+.1f, B}, ClipMethod::kSkipDraw);
|
|
|
|
|
|
|
|
// Complex clip where outer rect is pixel aligned (iior=false, normal bounds).
|
|
|
|
name.printf("Aligned Complex clip test, iter %i", i);
|
|
|
|
stack.reset();
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRect(alignedRect, SkMatrix::I(), kIntersect_SkClipOp, true);
|
|
|
|
stack.clipRect(innerRect, SkMatrix::I(), kXOR_SkClipOp, true);
|
2016-07-22 15:59:08 +00:00
|
|
|
test_aa_query(reporter, name, stack, m, {l, t, r, b}, ClipMethod::kSkipDraw);
|
|
|
|
test_aa_query(reporter, name, stack, m, {l, b-.1f, r, IB}, ClipMethod::kAAElements, 1);
|
|
|
|
test_aa_query(reporter, name, stack, m, {l, b-.1f, r, IB+.1f}, ClipMethod::kAAElements, 1);
|
|
|
|
test_aa_query(reporter, name, stack, m, {l, b, r, IB+.1f}, ClipMethod::kAAElements, 0);
|
|
|
|
test_aa_query(reporter, name, stack, m, {l, b, r, IB}, ClipMethod::kIgnoreClip);
|
|
|
|
test_aa_query(reporter, name, stack, m, {IL, IB, IR, IB+.1f}, ClipMethod::kSkipDraw);
|
|
|
|
|
|
|
|
// Apply random transforms and try again. This ensures the clip stack reduction is hardened
|
|
|
|
// against FP rounding error.
|
|
|
|
SkScalar sx = rand.nextRangeScalar(kMinScale, kMaxScale);
|
|
|
|
sx = SkScalarFloorToScalar(sx * alignedRect.width()) / alignedRect.width();
|
|
|
|
SkScalar sy = rand.nextRangeScalar(kMinScale, kMaxScale);
|
|
|
|
sy = SkScalarFloorToScalar(sy * alignedRect.height()) / alignedRect.height();
|
|
|
|
SkScalar tx = SkScalarRoundToScalar(sx * alignedRect.x()) - sx * alignedRect.x();
|
|
|
|
SkScalar ty = SkScalarRoundToScalar(sy * alignedRect.y()) - sy * alignedRect.y();
|
|
|
|
|
|
|
|
SkMatrix xform = SkMatrix::MakeScale(sx, sy);
|
|
|
|
xform.postTranslate(tx, ty);
|
|
|
|
xform.mapRect(&alignedRect);
|
|
|
|
xform.mapRect(&rect);
|
|
|
|
xform.mapRect(&innerRect);
|
|
|
|
m.postConcat(xform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-05 19:15:37 +00:00
|
|
|
static void test_tiny_query_bounds_assertion_bug(skiatest::Reporter* reporter) {
|
|
|
|
// https://bugs.chromium.org/p/skia/issues/detail?id=5990
|
|
|
|
const SkRect clipBounds = SkRect::MakeXYWH(1.5f, 100, 1000, 1000);
|
|
|
|
|
|
|
|
SkClipStack rectStack;
|
|
|
|
rectStack.clipRect(clipBounds, SkMatrix::I(), kIntersect_SkClipOp, true);
|
|
|
|
|
|
|
|
SkPath clipPath;
|
|
|
|
clipPath.moveTo(clipBounds.left(), clipBounds.top());
|
|
|
|
clipPath.quadTo(clipBounds.right(), clipBounds.top(),
|
|
|
|
clipBounds.right(), clipBounds.bottom());
|
|
|
|
clipPath.quadTo(clipBounds.left(), clipBounds.bottom(),
|
|
|
|
clipBounds.left(), clipBounds.top());
|
|
|
|
SkClipStack pathStack;
|
|
|
|
pathStack.clipPath(clipPath, SkMatrix::I(), kIntersect_SkClipOp, true);
|
|
|
|
|
2017-12-05 15:35:15 +00:00
|
|
|
auto context = GrContext::MakeMock(nullptr);
|
2019-02-04 18:26:26 +00:00
|
|
|
const GrCaps* caps = context->priv().caps();
|
2017-12-05 15:35:15 +00:00
|
|
|
|
2017-06-05 19:15:37 +00:00
|
|
|
for (const SkClipStack& stack : {rectStack, pathStack}) {
|
|
|
|
for (SkRect queryBounds : {SkRect::MakeXYWH(53, 60, GrClip::kBoundsTolerance, 1000),
|
|
|
|
SkRect::MakeXYWH(53, 60, GrClip::kBoundsTolerance/2, 1000),
|
|
|
|
SkRect::MakeXYWH(53, 160, 1000, GrClip::kBoundsTolerance),
|
|
|
|
SkRect::MakeXYWH(53, 160, 1000, GrClip::kBoundsTolerance/2)}) {
|
2018-10-15 20:09:54 +00:00
|
|
|
const GrReducedClip reduced(stack, queryBounds, caps);
|
2017-10-27 07:50:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, !reduced.hasScissor());
|
|
|
|
REPORTER_ASSERT(reporter, reduced.maskElements().isEmpty());
|
2017-06-05 19:15:37 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
GrReducedClip::InitialState::kAllOut == reduced.initialState());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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++) {
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipDevRect(gRects[i], kIntersect_SkClipOp);
|
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());
|
2016-12-09 14:00:50 +00:00
|
|
|
REPORTER_ASSERT(reporter, kIntersect_SkClipOp == 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);
|
2018-05-31 18:27:17 +00:00
|
|
|
|
2012-11-28 14:42:41 +00:00
|
|
|
test_reduced_clip_stack(reporter);
|
2018-07-09 18:23:58 +00:00
|
|
|
test_reduced_clip_stack_genid(reporter);
|
2013-11-05 15:03:08 +00:00
|
|
|
test_reduced_clip_stack_no_aa_crash(reporter);
|
2016-07-22 15:59:08 +00:00
|
|
|
test_reduced_clip_stack_aa(reporter);
|
2017-06-05 19:15:37 +00:00
|
|
|
test_tiny_query_bounds_assertion_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
|
|
|
}
|
2017-01-06 18:54:58 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-02-24 13:37:13 +00:00
|
|
|
sk_sp<GrTextureProxy> GrClipStackClip::testingOnly_createClipMask(GrContext* context) const {
|
2017-01-06 18:54:58 +00:00
|
|
|
const GrReducedClip reducedClip(*fStack, SkRect::MakeWH(512, 512), 0);
|
2020-02-10 21:00:54 +00:00
|
|
|
return this->createSoftwareClipMask(context, reducedClip, nullptr).asTextureProxyRef();
|
2017-01-06 18:54:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that clip masks are freed up when the clip state that generated them goes away.
|
|
|
|
DEF_GPUTEST_FOR_ALL_CONTEXTS(ClipMaskCache, reporter, ctxInfo) {
|
|
|
|
// This test uses resource key tags which only function in debug builds.
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
SkClipStack stack;
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
path.addCircle(10, 10, 8);
|
|
|
|
path.addCircle(15, 15, 8);
|
2019-11-26 17:17:17 +00:00
|
|
|
path.setFillType(SkPathFillType::kEvenOdd);
|
2017-01-06 18:54:58 +00:00
|
|
|
|
2018-07-09 18:23:58 +00:00
|
|
|
static const char* kTag = GrClipStackClip::kMaskTestTag;
|
2019-02-04 18:26:26 +00:00
|
|
|
GrResourceCache* cache = context->priv().getResourceCache();
|
2017-01-06 18:54:58 +00:00
|
|
|
|
|
|
|
static constexpr int kN = 5;
|
|
|
|
|
|
|
|
for (int i = 0; i < kN; ++i) {
|
|
|
|
SkMatrix m;
|
|
|
|
m.setTranslate(0.5, 0.5);
|
|
|
|
stack.save();
|
|
|
|
stack.clipPath(path, m, SkClipOp::kIntersect, true);
|
2017-02-24 13:37:13 +00:00
|
|
|
sk_sp<GrTextureProxy> mask = GrClipStackClip(&stack).testingOnly_createClipMask(context);
|
2019-02-04 18:26:26 +00:00
|
|
|
mask->instantiate(context->priv().resourceProvider());
|
2018-07-31 21:25:29 +00:00
|
|
|
GrTexture* tex = mask->peekTexture();
|
2017-02-24 13:37:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == strcmp(tex->getUniqueKey().tag(), kTag));
|
2017-01-06 18:54:58 +00:00
|
|
|
// Make sure mask isn't pinned in cache.
|
|
|
|
mask.reset(nullptr);
|
|
|
|
context->flush();
|
|
|
|
REPORTER_ASSERT(reporter, i + 1 == cache->countUniqueKeysWithTag(kTag));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < kN; ++i) {
|
|
|
|
stack.restore();
|
|
|
|
cache->purgeAsNeeded();
|
|
|
|
REPORTER_ASSERT(reporter, kN - (i + 1) == cache->countUniqueKeysWithTag(kTag));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|