epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkCanvas.h" |
| 9 | #include "include/core/SkClipOp.h" |
| 10 | #include "include/core/SkImageInfo.h" |
| 11 | #include "include/core/SkMatrix.h" |
| 12 | #include "include/core/SkPath.h" |
| 13 | #include "include/core/SkPoint.h" |
| 14 | #include "include/core/SkRRect.h" |
| 15 | #include "include/core/SkRect.h" |
| 16 | #include "include/core/SkRefCnt.h" |
| 17 | #include "include/core/SkRegion.h" |
| 18 | #include "include/core/SkScalar.h" |
| 19 | #include "include/core/SkSize.h" |
| 20 | #include "include/core/SkString.h" |
| 21 | #include "include/core/SkSurface.h" |
| 22 | #include "include/core/SkTypes.h" |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame] | 23 | #include "include/effects/SkGradientShader.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "include/private/GrResourceKey.h" |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 25 | #include "include/private/SkTemplates.h" |
| 26 | #include "include/utils/SkRandom.h" |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 27 | #include "src/core/SkClipStack.h" |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 28 | #include "tests/Test.h" |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 29 | |
Ben Wagner | b607a8f | 2018-03-12 13:46:21 -0400 | [diff] [blame] | 30 | #include <cstring> |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 31 | #include <initializer_list> |
Ben Wagner | b607a8f | 2018-03-12 13:46:21 -0400 | [diff] [blame] | 32 | #include <new> |
| 33 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 34 | static void test_assign_and_comparison(skiatest::Reporter* reporter) { |
| 35 | SkClipStack s; |
reed@google.com | d9f2dea | 2011-10-12 14:43:27 +0000 | [diff] [blame] | 36 | bool doAA = false; |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 37 | |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 38 | REPORTER_ASSERT(reporter, 0 == s.getSaveCount()); |
| 39 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 40 | // Build up a clip stack with a path, an empty clip, and a rect. |
| 41 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 42 | REPORTER_ASSERT(reporter, 1 == s.getSaveCount()); |
| 43 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 44 | SkPath p; |
| 45 | p.moveTo(5, 6); |
| 46 | p.lineTo(7, 8); |
| 47 | p.lineTo(5, 9); |
| 48 | p.close(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 49 | s.clipPath(p, SkMatrix::I(), SkClipOp::kIntersect, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 50 | |
| 51 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 52 | REPORTER_ASSERT(reporter, 2 == s.getSaveCount()); |
| 53 | |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame] | 54 | SkRect r = SkRect::MakeLTRB(1, 2, 103, 104); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 55 | s.clipRect(r, SkMatrix::I(), SkClipOp::kIntersect, doAA); |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame] | 56 | r = SkRect::MakeLTRB(4, 5, 56, 57); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 57 | s.clipRect(r, SkMatrix::I(), SkClipOp::kIntersect, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 58 | |
| 59 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 60 | REPORTER_ASSERT(reporter, 3 == s.getSaveCount()); |
| 61 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 62 | r = SkRect::MakeLTRB(14, 15, 16, 17); |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame] | 63 | s.clipRect(r, SkMatrix::I(), SkClipOp::kDifference, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 64 | |
| 65 | // Test that assignment works. |
| 66 | SkClipStack copy = s; |
| 67 | REPORTER_ASSERT(reporter, s == copy); |
| 68 | |
| 69 | // Test that different save levels triggers not equal. |
| 70 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 71 | REPORTER_ASSERT(reporter, 2 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 72 | REPORTER_ASSERT(reporter, s != copy); |
| 73 | |
| 74 | // Test that an equal, but not copied version is equal. |
| 75 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 76 | REPORTER_ASSERT(reporter, 3 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 77 | r = SkRect::MakeLTRB(14, 15, 16, 17); |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame] | 78 | s.clipRect(r, SkMatrix::I(), SkClipOp::kDifference, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 79 | REPORTER_ASSERT(reporter, s == copy); |
| 80 | |
| 81 | // Test that a different op on one level triggers not equal. |
| 82 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 83 | REPORTER_ASSERT(reporter, 2 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 84 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 85 | REPORTER_ASSERT(reporter, 3 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 86 | r = SkRect::MakeLTRB(14, 15, 16, 17); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 87 | s.clipRect(r, SkMatrix::I(), SkClipOp::kIntersect, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 88 | REPORTER_ASSERT(reporter, s != copy); |
| 89 | |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 90 | // Test that version constructed with rect-path rather than a rect is still considered equal. |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 91 | s.restore(); |
| 92 | s.save(); |
| 93 | SkPath rp; |
| 94 | rp.addRect(r); |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame] | 95 | s.clipPath(rp, SkMatrix::I(), SkClipOp::kDifference, doAA); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 96 | REPORTER_ASSERT(reporter, s == copy); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 97 | |
| 98 | // Test that different rects triggers not equal. |
| 99 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 100 | REPORTER_ASSERT(reporter, 2 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 101 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 102 | REPORTER_ASSERT(reporter, 3 == s.getSaveCount()); |
| 103 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 104 | r = SkRect::MakeLTRB(24, 25, 26, 27); |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame] | 105 | s.clipRect(r, SkMatrix::I(), SkClipOp::kDifference, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 106 | REPORTER_ASSERT(reporter, s != copy); |
| 107 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 108 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 109 | REPORTER_ASSERT(reporter, 2 == s.getSaveCount()); |
| 110 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 111 | copy.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 112 | REPORTER_ASSERT(reporter, 2 == copy.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 113 | REPORTER_ASSERT(reporter, s == copy); |
| 114 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 115 | REPORTER_ASSERT(reporter, 1 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 116 | copy.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 117 | REPORTER_ASSERT(reporter, 1 == copy.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 118 | REPORTER_ASSERT(reporter, s == copy); |
| 119 | |
| 120 | // Test that different paths triggers not equal. |
| 121 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 122 | REPORTER_ASSERT(reporter, 0 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 123 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 124 | REPORTER_ASSERT(reporter, 1 == s.getSaveCount()); |
| 125 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 126 | p.addRect(r); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 127 | s.clipPath(p, SkMatrix::I(), SkClipOp::kIntersect, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 128 | REPORTER_ASSERT(reporter, s != copy); |
| 129 | } |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 130 | |
| 131 | static void assert_count(skiatest::Reporter* reporter, const SkClipStack& stack, |
| 132 | int count) { |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 133 | SkClipStack::B2TIter iter(stack); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 134 | int counter = 0; |
| 135 | while (iter.next()) { |
| 136 | counter += 1; |
| 137 | } |
| 138 | REPORTER_ASSERT(reporter, count == counter); |
| 139 | } |
| 140 | |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 141 | // Exercise the SkClipStack's bottom to top and bidirectional iterators |
| 142 | // (including the skipToTopmost functionality) |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 143 | static void test_iterators(skiatest::Reporter* reporter) { |
| 144 | SkClipStack stack; |
| 145 | |
| 146 | static const SkRect gRects[] = { |
| 147 | { 0, 0, 40, 40 }, |
| 148 | { 60, 0, 100, 40 }, |
| 149 | { 0, 60, 40, 100 }, |
| 150 | { 60, 60, 100, 100 } |
| 151 | }; |
| 152 | |
| 153 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRects); i++) { |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame] | 154 | // the difference op will prevent these from being fused together |
| 155 | stack.clipRect(gRects[i], SkMatrix::I(), SkClipOp::kDifference, false); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | assert_count(reporter, stack, 4); |
| 159 | |
| 160 | // bottom to top iteration |
| 161 | { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 162 | const SkClipStack::Element* element = nullptr; |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 163 | |
| 164 | SkClipStack::B2TIter iter(stack); |
| 165 | int i; |
| 166 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 167 | for (i = 0, element = iter.next(); element; ++i, element = iter.next()) { |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 168 | REPORTER_ASSERT(reporter, SkClipStack::Element::DeviceSpaceType::kRect == |
| 169 | element->getDeviceSpaceType()); |
| 170 | REPORTER_ASSERT(reporter, element->getDeviceSpaceRect() == gRects[i]); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | SkASSERT(i == 4); |
| 174 | } |
| 175 | |
| 176 | // top to bottom iteration |
| 177 | { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 178 | const SkClipStack::Element* element = nullptr; |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 179 | |
| 180 | SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart); |
| 181 | int i; |
| 182 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 183 | for (i = 3, element = iter.prev(); element; --i, element = iter.prev()) { |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 184 | REPORTER_ASSERT(reporter, SkClipStack::Element::DeviceSpaceType::kRect == |
| 185 | element->getDeviceSpaceType()); |
| 186 | REPORTER_ASSERT(reporter, element->getDeviceSpaceRect() == gRects[i]); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | SkASSERT(i == -1); |
| 190 | } |
| 191 | |
| 192 | // skipToTopmost |
| 193 | { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 194 | const SkClipStack::Element* element = nullptr; |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 195 | |
| 196 | SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart); |
| 197 | |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame] | 198 | element = iter.skipToTopmost(SkClipOp::kDifference); |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 199 | REPORTER_ASSERT(reporter, SkClipStack::Element::DeviceSpaceType::kRect == |
| 200 | element->getDeviceSpaceType()); |
| 201 | REPORTER_ASSERT(reporter, element->getDeviceSpaceRect() == gRects[3]); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 205 | // Exercise the SkClipStack's getConservativeBounds computation |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 206 | static void test_bounds(skiatest::Reporter* reporter, |
| 207 | SkClipStack::Element::DeviceSpaceType primType) { |
Michael Ludwig | a0438e6 | 2021-08-06 11:19:26 -0400 | [diff] [blame] | 208 | static const int gNumCases = 8; |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 209 | static const SkRect gAnswerRectsBW[gNumCases] = { |
| 210 | // A op B |
| 211 | { 40, 40, 50, 50 }, |
| 212 | { 10, 10, 50, 50 }, |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 213 | |
| 214 | // invA op B |
| 215 | { 40, 40, 80, 80 }, |
| 216 | { 0, 0, 100, 100 }, |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 217 | |
| 218 | // A op invB |
| 219 | { 10, 10, 50, 50 }, |
| 220 | { 40, 40, 50, 50 }, |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 221 | |
| 222 | // invA op invB |
| 223 | { 0, 0, 100, 100 }, |
| 224 | { 40, 40, 80, 80 }, |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 225 | }; |
| 226 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 227 | static const SkClipOp gOps[] = { |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 228 | SkClipOp::kIntersect, |
Michael Ludwig | a0438e6 | 2021-08-06 11:19:26 -0400 | [diff] [blame] | 229 | SkClipOp::kDifference |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 230 | }; |
| 231 | |
| 232 | SkRect rectA, rectB; |
| 233 | |
Mike Reed | 92b3335 | 2019-08-24 19:39:13 -0400 | [diff] [blame] | 234 | rectA.setLTRB(10, 10, 50, 50); |
| 235 | rectB.setLTRB(40, 40, 80, 80); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 236 | |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 237 | SkRRect rrectA, rrectB; |
| 238 | rrectA.setOval(rectA); |
| 239 | rrectB.setRectXY(rectB, SkIntToScalar(1), SkIntToScalar(2)); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 240 | |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 241 | SkPath pathA, pathB; |
| 242 | |
| 243 | pathA.addRoundRect(rectA, SkIntToScalar(5), SkIntToScalar(5)); |
| 244 | pathB.addRoundRect(rectB, SkIntToScalar(5), SkIntToScalar(5)); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 245 | |
| 246 | SkClipStack stack; |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 247 | SkRect devClipBound; |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 248 | bool isIntersectionOfRects = false; |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 249 | |
| 250 | int testCase = 0; |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 251 | int numBitTests = SkClipStack::Element::DeviceSpaceType::kPath == primType ? 4 : 1; |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 252 | for (int invBits = 0; invBits < numBitTests; ++invBits) { |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 253 | for (size_t op = 0; op < SK_ARRAY_COUNT(gOps); ++op) { |
| 254 | |
| 255 | stack.save(); |
| 256 | bool doInvA = SkToBool(invBits & 1); |
| 257 | bool doInvB = SkToBool(invBits & 2); |
| 258 | |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 259 | pathA.setFillType(doInvA ? SkPathFillType::kInverseEvenOdd : |
| 260 | SkPathFillType::kEvenOdd); |
| 261 | pathB.setFillType(doInvB ? SkPathFillType::kInverseEvenOdd : |
| 262 | SkPathFillType::kEvenOdd); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 263 | |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 264 | switch (primType) { |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame] | 265 | case SkClipStack::Element::DeviceSpaceType::kShader: |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 266 | case SkClipStack::Element::DeviceSpaceType::kEmpty: |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame] | 267 | SkDEBUGFAIL("Don't call this with kEmpty or kShader."); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 268 | break; |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 269 | case SkClipStack::Element::DeviceSpaceType::kRect: |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 270 | stack.clipRect(rectA, SkMatrix::I(), SkClipOp::kIntersect, false); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 271 | stack.clipRect(rectB, SkMatrix::I(), gOps[op], false); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 272 | break; |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 273 | case SkClipStack::Element::DeviceSpaceType::kRRect: |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 274 | stack.clipRRect(rrectA, SkMatrix::I(), SkClipOp::kIntersect, false); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 275 | stack.clipRRect(rrectB, SkMatrix::I(), gOps[op], false); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 276 | break; |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 277 | case SkClipStack::Element::DeviceSpaceType::kPath: |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 278 | stack.clipPath(pathA, SkMatrix::I(), SkClipOp::kIntersect, false); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 279 | stack.clipPath(pathB, SkMatrix::I(), gOps[op], false); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 280 | break; |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 281 | } |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 282 | |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 283 | REPORTER_ASSERT(reporter, !stack.isWideOpen()); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 284 | REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID != stack.getTopmostGenID()); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 285 | |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 286 | stack.getConservativeBounds(0, 0, 100, 100, &devClipBound, |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 287 | &isIntersectionOfRects); |
| 288 | |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 289 | if (SkClipStack::Element::DeviceSpaceType::kRect == primType) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 290 | REPORTER_ASSERT(reporter, isIntersectionOfRects == |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 291 | (gOps[op] == SkClipOp::kIntersect)); |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 292 | } else { |
| 293 | REPORTER_ASSERT(reporter, !isIntersectionOfRects); |
| 294 | } |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 295 | |
| 296 | SkASSERT(testCase < gNumCases); |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 297 | REPORTER_ASSERT(reporter, devClipBound == gAnswerRectsBW[testCase]); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 298 | ++testCase; |
| 299 | |
| 300 | stack.restore(); |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 305 | // Test out 'isWideOpen' entry point |
| 306 | static void test_isWideOpen(skiatest::Reporter* reporter) { |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 307 | { |
| 308 | // Empty stack is wide open. Wide open stack means that gen id is wide open. |
| 309 | SkClipStack stack; |
| 310 | REPORTER_ASSERT(reporter, stack.isWideOpen()); |
| 311 | REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID()); |
| 312 | } |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 313 | |
| 314 | SkRect rectA, rectB; |
| 315 | |
Mike Reed | 92b3335 | 2019-08-24 19:39:13 -0400 | [diff] [blame] | 316 | rectA.setLTRB(10, 10, 40, 40); |
| 317 | rectB.setLTRB(50, 50, 80, 80); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 318 | |
| 319 | // Stack should initially be wide open |
| 320 | { |
| 321 | SkClipStack stack; |
| 322 | |
| 323 | REPORTER_ASSERT(reporter, stack.isWideOpen()); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 324 | REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID()); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 325 | } |
| 326 | |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 327 | // Test out empty difference from a wide open clip |
| 328 | { |
| 329 | SkClipStack stack; |
| 330 | |
| 331 | SkRect emptyRect; |
| 332 | emptyRect.setEmpty(); |
| 333 | |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 334 | stack.clipRect(emptyRect, SkMatrix::I(), SkClipOp::kDifference, false); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 335 | |
| 336 | REPORTER_ASSERT(reporter, stack.isWideOpen()); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 337 | REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID()); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | // Test out return to wide open |
| 341 | { |
| 342 | SkClipStack stack; |
| 343 | |
| 344 | stack.save(); |
| 345 | |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 346 | stack.clipRect(rectA, SkMatrix::I(), SkClipOp::kIntersect, false); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 347 | |
| 348 | REPORTER_ASSERT(reporter, !stack.isWideOpen()); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 349 | REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID != stack.getTopmostGenID()); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 350 | |
| 351 | stack.restore(); |
| 352 | |
| 353 | REPORTER_ASSERT(reporter, stack.isWideOpen()); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 354 | REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID()); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 355 | } |
| 356 | } |
| 357 | |
bsalomon@google.com | 100abf4 | 2012-09-05 17:40:04 +0000 | [diff] [blame] | 358 | static int count(const SkClipStack& stack) { |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 359 | |
| 360 | SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart); |
| 361 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 362 | const SkClipStack::Element* element = nullptr; |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 363 | int count = 0; |
| 364 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 365 | for (element = iter.prev(); element; element = iter.prev(), ++count) { |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | return count; |
| 369 | } |
| 370 | |
junov@chromium.org | edf32d5 | 2012-12-10 14:57:54 +0000 | [diff] [blame] | 371 | static void test_rect_inverse_fill(skiatest::Reporter* reporter) { |
| 372 | // non-intersecting rectangles |
| 373 | SkRect rect = SkRect::MakeLTRB(0, 0, 10, 10); |
| 374 | |
| 375 | SkPath path; |
| 376 | path.addRect(rect); |
| 377 | path.toggleInverseFillType(); |
| 378 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 379 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | edf32d5 | 2012-12-10 14:57:54 +0000 | [diff] [blame] | 380 | |
| 381 | SkRect bounds; |
| 382 | SkClipStack::BoundsType boundsType; |
| 383 | stack.getBounds(&bounds, &boundsType); |
| 384 | REPORTER_ASSERT(reporter, SkClipStack::kInsideOut_BoundsType == boundsType); |
| 385 | REPORTER_ASSERT(reporter, bounds == rect); |
| 386 | } |
| 387 | |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 388 | static void test_rect_replace(skiatest::Reporter* reporter) { |
| 389 | SkRect rect = SkRect::MakeWH(100, 100); |
| 390 | SkRect rect2 = SkRect::MakeXYWH(50, 50, 100, 100); |
| 391 | |
| 392 | SkRect bound; |
| 393 | SkClipStack::BoundsType type; |
| 394 | bool isIntersectionOfRects; |
| 395 | |
| 396 | // Adding a new rect with the replace operator should not increase |
| 397 | // the stack depth. BW replacing BW. |
| 398 | { |
| 399 | SkClipStack stack; |
| 400 | REPORTER_ASSERT(reporter, 0 == count(stack)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 401 | stack.replaceClip(rect, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 402 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 403 | stack.replaceClip(rect, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 404 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 405 | } |
| 406 | |
| 407 | // Adding a new rect with the replace operator should not increase |
| 408 | // the stack depth. AA replacing AA. |
| 409 | { |
| 410 | SkClipStack stack; |
| 411 | REPORTER_ASSERT(reporter, 0 == count(stack)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 412 | stack.replaceClip(rect, true); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 413 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 414 | stack.replaceClip(rect, true); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 415 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 416 | } |
| 417 | |
| 418 | // Adding a new rect with the replace operator should not increase |
| 419 | // the stack depth. BW replacing AA replacing BW. |
| 420 | { |
| 421 | SkClipStack stack; |
| 422 | REPORTER_ASSERT(reporter, 0 == count(stack)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 423 | stack.replaceClip(rect, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 424 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 425 | stack.replaceClip(rect, true); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 426 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 427 | stack.replaceClip(rect, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 428 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 429 | } |
| 430 | |
| 431 | // Make sure replace clip rects don't collapse too much. |
| 432 | { |
| 433 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 434 | stack.replaceClip(rect, false); |
| 435 | stack.clipRect(rect2, SkMatrix::I(), SkClipOp::kIntersect, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 436 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 437 | |
| 438 | stack.save(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 439 | stack.replaceClip(rect, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 440 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 441 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 442 | REPORTER_ASSERT(reporter, bound == rect); |
| 443 | stack.restore(); |
| 444 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 445 | |
| 446 | stack.save(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 447 | stack.replaceClip(rect, false); |
| 448 | stack.replaceClip(rect, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 449 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 450 | stack.restore(); |
| 451 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 452 | |
| 453 | stack.save(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 454 | stack.replaceClip(rect, false); |
| 455 | stack.clipRect(rect2, SkMatrix::I(), SkClipOp::kIntersect, false); |
| 456 | stack.replaceClip(rect, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 457 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 458 | stack.restore(); |
| 459 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | // Simplified path-based version of test_rect_replace. |
| 464 | static void test_path_replace(skiatest::Reporter* reporter) { |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 465 | auto replacePath = [](SkClipStack* stack, const SkPath& path, bool doAA) { |
| 466 | const SkRect wideOpen = SkRect::MakeLTRB(-1000, -1000, 1000, 1000); |
| 467 | stack->replaceClip(wideOpen, false); |
| 468 | stack->clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, doAA); |
| 469 | }; |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 470 | SkRect rect = SkRect::MakeWH(100, 100); |
| 471 | SkPath path; |
| 472 | path.addCircle(50, 50, 50); |
| 473 | |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 474 | // Emulating replace operations with more complex geometry is not atomic, it's a replace |
| 475 | // with a wide-open rect and then an intersection with the complex geometry. The replace can |
| 476 | // combine with prior elements, but the subsequent intersect cannot be combined so the stack |
| 477 | // continues to grow. |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 478 | { |
| 479 | SkClipStack stack; |
| 480 | REPORTER_ASSERT(reporter, 0 == count(stack)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 481 | replacePath(&stack, path, false); |
| 482 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 483 | replacePath(&stack, path, false); |
| 484 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | // Replacing rect with path. |
| 488 | { |
| 489 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 490 | stack.replaceClip(rect, true); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 491 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 492 | replacePath(&stack, path, true); |
| 493 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 497 | // Test out SkClipStack's merging of rect clips. In particular exercise |
| 498 | // merging of aa vs. bw rects. |
| 499 | static void test_rect_merging(skiatest::Reporter* reporter) { |
| 500 | |
| 501 | SkRect overlapLeft = SkRect::MakeLTRB(10, 10, 50, 50); |
| 502 | SkRect overlapRight = SkRect::MakeLTRB(40, 40, 80, 80); |
| 503 | |
| 504 | SkRect nestedParent = SkRect::MakeLTRB(10, 10, 90, 90); |
| 505 | SkRect nestedChild = SkRect::MakeLTRB(40, 40, 60, 60); |
| 506 | |
| 507 | SkRect bound; |
| 508 | SkClipStack::BoundsType type; |
| 509 | bool isIntersectionOfRects; |
| 510 | |
| 511 | // all bw overlapping - should merge |
| 512 | { |
| 513 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 514 | stack.clipRect(overlapLeft, SkMatrix::I(), SkClipOp::kIntersect, false); |
| 515 | stack.clipRect(overlapRight, SkMatrix::I(), SkClipOp::kIntersect, false); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 516 | |
| 517 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 518 | |
| 519 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 520 | |
| 521 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 522 | } |
| 523 | |
| 524 | // all aa overlapping - should merge |
| 525 | { |
| 526 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 527 | stack.clipRect(overlapLeft, SkMatrix::I(), SkClipOp::kIntersect, true); |
| 528 | stack.clipRect(overlapRight, SkMatrix::I(), SkClipOp::kIntersect, true); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 529 | |
| 530 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 531 | |
| 532 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 533 | |
| 534 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 535 | } |
| 536 | |
| 537 | // mixed overlapping - should _not_ merge |
| 538 | { |
| 539 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 540 | stack.clipRect(overlapLeft, SkMatrix::I(), SkClipOp::kIntersect, true); |
| 541 | stack.clipRect(overlapRight, SkMatrix::I(), SkClipOp::kIntersect, false); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 542 | |
| 543 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 544 | |
| 545 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 546 | |
| 547 | REPORTER_ASSERT(reporter, !isIntersectionOfRects); |
| 548 | } |
| 549 | |
| 550 | // mixed nested (bw inside aa) - should merge |
| 551 | { |
| 552 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 553 | stack.clipRect(nestedParent, SkMatrix::I(), SkClipOp::kIntersect, true); |
| 554 | stack.clipRect(nestedChild, SkMatrix::I(), SkClipOp::kIntersect, false); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 555 | |
| 556 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 557 | |
| 558 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 559 | |
| 560 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 561 | } |
| 562 | |
| 563 | // mixed nested (aa inside bw) - should merge |
| 564 | { |
| 565 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 566 | stack.clipRect(nestedParent, SkMatrix::I(), SkClipOp::kIntersect, false); |
| 567 | stack.clipRect(nestedChild, SkMatrix::I(), SkClipOp::kIntersect, true); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 568 | |
| 569 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 570 | |
| 571 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 572 | |
| 573 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 574 | } |
| 575 | |
| 576 | // reverse nested (aa inside bw) - should _not_ merge |
| 577 | { |
| 578 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 579 | stack.clipRect(nestedChild, SkMatrix::I(), SkClipOp::kIntersect, false); |
| 580 | stack.clipRect(nestedParent, SkMatrix::I(), SkClipOp::kIntersect, true); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 581 | |
| 582 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 583 | |
| 584 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 585 | |
| 586 | REPORTER_ASSERT(reporter, !isIntersectionOfRects); |
| 587 | } |
| 588 | } |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 589 | |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 590 | static void test_quickContains(skiatest::Reporter* reporter) { |
| 591 | SkRect testRect = SkRect::MakeLTRB(10, 10, 40, 40); |
| 592 | SkRect insideRect = SkRect::MakeLTRB(20, 20, 30, 30); |
| 593 | SkRect intersectingRect = SkRect::MakeLTRB(25, 25, 50, 50); |
| 594 | SkRect outsideRect = SkRect::MakeLTRB(0, 0, 50, 50); |
| 595 | SkRect nonIntersectingRect = SkRect::MakeLTRB(100, 100, 110, 110); |
| 596 | |
| 597 | SkPath insideCircle; |
| 598 | insideCircle.addCircle(25, 25, 5); |
| 599 | SkPath intersectingCircle; |
| 600 | intersectingCircle.addCircle(25, 40, 10); |
| 601 | SkPath outsideCircle; |
| 602 | outsideCircle.addCircle(25, 25, 50); |
| 603 | SkPath nonIntersectingCircle; |
| 604 | nonIntersectingCircle.addCircle(100, 100, 5); |
| 605 | |
| 606 | { |
| 607 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 608 | stack.clipRect(outsideRect, SkMatrix::I(), SkClipOp::kDifference, false); |
| 609 | // return false because quickContains currently does not care for kDifference |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 610 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 611 | } |
skia.committer@gmail.com | 306ab9d | 2012-12-13 02:01:33 +0000 | [diff] [blame] | 612 | |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 613 | // Replace Op tests |
| 614 | { |
| 615 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 616 | stack.replaceClip(outsideRect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 617 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 618 | } |
| 619 | |
| 620 | { |
| 621 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 622 | stack.clipRect(insideRect, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 623 | stack.save(); // To prevent in-place substitution by replace OP |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 624 | stack.replaceClip(outsideRect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 625 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 626 | stack.restore(); |
| 627 | } |
| 628 | |
| 629 | { |
| 630 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 631 | stack.clipRect(outsideRect, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 632 | stack.save(); // To prevent in-place substitution by replace OP |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 633 | stack.replaceClip(insideRect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 634 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 635 | stack.restore(); |
| 636 | } |
| 637 | |
| 638 | // Verify proper traversal of multi-element clip |
| 639 | { |
| 640 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 641 | stack.clipRect(insideRect, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 642 | // Use a path for second clip to prevent in-place intersection |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 643 | stack.clipPath(outsideCircle, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 644 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 645 | } |
| 646 | |
| 647 | // Intersect Op tests with rectangles |
| 648 | { |
| 649 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 650 | stack.clipRect(outsideRect, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 651 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 652 | } |
| 653 | |
| 654 | { |
| 655 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 656 | stack.clipRect(insideRect, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 657 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 658 | } |
| 659 | |
| 660 | { |
| 661 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 662 | stack.clipRect(intersectingRect, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 663 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 664 | } |
| 665 | |
| 666 | { |
| 667 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 668 | stack.clipRect(nonIntersectingRect, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 669 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 670 | } |
| 671 | |
| 672 | // Intersect Op tests with circle paths |
| 673 | { |
| 674 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 675 | stack.clipPath(outsideCircle, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 676 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 677 | } |
| 678 | |
| 679 | { |
| 680 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 681 | stack.clipPath(insideCircle, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 682 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 683 | } |
| 684 | |
| 685 | { |
| 686 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 687 | stack.clipPath(intersectingCircle, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 688 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 689 | } |
| 690 | |
| 691 | { |
| 692 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 693 | stack.clipPath(nonIntersectingCircle, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 694 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 695 | } |
| 696 | |
| 697 | // Intersect Op tests with inverse filled rectangles |
| 698 | { |
| 699 | SkClipStack stack; |
| 700 | SkPath path; |
| 701 | path.addRect(outsideRect); |
| 702 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 703 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 704 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 705 | } |
| 706 | |
| 707 | { |
| 708 | SkClipStack stack; |
| 709 | SkPath path; |
| 710 | path.addRect(insideRect); |
| 711 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 712 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 713 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 714 | } |
| 715 | |
| 716 | { |
| 717 | SkClipStack stack; |
| 718 | SkPath path; |
| 719 | path.addRect(intersectingRect); |
| 720 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 721 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 722 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 723 | } |
| 724 | |
| 725 | { |
| 726 | SkClipStack stack; |
| 727 | SkPath path; |
| 728 | path.addRect(nonIntersectingRect); |
| 729 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 730 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 731 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 732 | } |
| 733 | |
| 734 | // Intersect Op tests with inverse filled circles |
| 735 | { |
| 736 | SkClipStack stack; |
| 737 | SkPath path = outsideCircle; |
| 738 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 739 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 740 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 741 | } |
| 742 | |
| 743 | { |
| 744 | SkClipStack stack; |
| 745 | SkPath path = insideCircle; |
| 746 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 747 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 748 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 749 | } |
| 750 | |
| 751 | { |
| 752 | SkClipStack stack; |
| 753 | SkPath path = intersectingCircle; |
| 754 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 755 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 756 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 757 | } |
| 758 | |
| 759 | { |
| 760 | SkClipStack stack; |
| 761 | SkPath path = nonIntersectingCircle; |
| 762 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 763 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 764 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 765 | } |
| 766 | } |
| 767 | |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 768 | static void set_region_to_stack(const SkClipStack& stack, const SkIRect& bounds, SkRegion* region) { |
| 769 | region->setRect(bounds); |
| 770 | SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart); |
| 771 | while (const SkClipStack::Element *element = iter.next()) { |
| 772 | SkRegion elemRegion; |
| 773 | SkRegion boundsRgn(bounds); |
| 774 | SkPath path; |
| 775 | |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 776 | switch (element->getDeviceSpaceType()) { |
| 777 | case SkClipStack::Element::DeviceSpaceType::kEmpty: |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 778 | elemRegion.setEmpty(); |
| 779 | break; |
| 780 | default: |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 781 | element->asDeviceSpacePath(&path); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 782 | elemRegion.setPath(path, boundsRgn); |
| 783 | break; |
| 784 | } |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame] | 785 | |
Michael Ludwig | e1d0040 | 2021-08-09 12:21:52 -0400 | [diff] [blame] | 786 | region->op(elemRegion, element->isReplaceOp() ? SkRegion::kReplace_Op |
| 787 | : (SkRegion::Op) element->getOp()); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 788 | } |
| 789 | } |
| 790 | |
| 791 | static void test_invfill_diff_bug(skiatest::Reporter* reporter) { |
| 792 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 793 | stack.clipRect({10, 10, 20, 20}, SkMatrix::I(), SkClipOp::kIntersect, false); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 794 | |
| 795 | SkPath path; |
| 796 | path.addRect({30, 10, 40, 20}); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 797 | path.setFillType(SkPathFillType::kInverseWinding); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 798 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kDifference, false); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 799 | |
| 800 | REPORTER_ASSERT(reporter, SkClipStack::kEmptyGenID == stack.getTopmostGenID()); |
| 801 | |
| 802 | SkRect stackBounds; |
| 803 | SkClipStack::BoundsType stackBoundsType; |
| 804 | stack.getBounds(&stackBounds, &stackBoundsType); |
| 805 | |
| 806 | REPORTER_ASSERT(reporter, stackBounds.isEmpty()); |
| 807 | REPORTER_ASSERT(reporter, SkClipStack::kNormal_BoundsType == stackBoundsType); |
| 808 | |
| 809 | SkRegion region; |
| 810 | set_region_to_stack(stack, {0, 0, 50, 30}, ®ion); |
| 811 | |
| 812 | REPORTER_ASSERT(reporter, region.isEmpty()); |
| 813 | } |
| 814 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 815 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 816 | |
Brian Salomon | 1c0b05a | 2019-04-19 15:37:28 -0400 | [diff] [blame] | 817 | static void test_is_rrect_deep_rect_stack(skiatest::Reporter* reporter) { |
| 818 | static constexpr SkRect kTargetBounds = SkRect::MakeWH(1000, 500); |
| 819 | // All antialiased or all not antialiased. |
| 820 | for (bool aa : {false, true}) { |
| 821 | SkClipStack stack; |
| 822 | for (int i = 0; i <= 100; ++i) { |
| 823 | stack.save(); |
| 824 | stack.clipRect(SkRect::MakeLTRB(i, 0.5, kTargetBounds.width(), kTargetBounds.height()), |
| 825 | SkMatrix::I(), SkClipOp::kIntersect, aa); |
| 826 | } |
| 827 | SkRRect rrect; |
| 828 | bool isAA; |
| 829 | SkRRect expected = SkRRect::MakeRect( |
| 830 | SkRect::MakeLTRB(100, 0.5, kTargetBounds.width(), kTargetBounds.height())); |
| 831 | if (stack.isRRect(kTargetBounds, &rrect, &isAA)) { |
| 832 | REPORTER_ASSERT(reporter, rrect == expected); |
| 833 | REPORTER_ASSERT(reporter, aa == isAA); |
| 834 | } else { |
| 835 | ERRORF(reporter, "Expected to be an rrect."); |
| 836 | } |
| 837 | } |
| 838 | // Mixed AA and non-AA without simple containment. |
| 839 | SkClipStack stack; |
| 840 | for (int i = 0; i <= 100; ++i) { |
| 841 | bool aa = i & 0b1; |
| 842 | int j = 100 - i; |
| 843 | stack.save(); |
| 844 | stack.clipRect(SkRect::MakeLTRB(i, j + 0.5, kTargetBounds.width(), kTargetBounds.height()), |
| 845 | SkMatrix::I(), SkClipOp::kIntersect, aa); |
| 846 | } |
| 847 | SkRRect rrect; |
| 848 | bool isAA; |
| 849 | REPORTER_ASSERT(reporter, !stack.isRRect(kTargetBounds, &rrect, &isAA)); |
| 850 | } |
| 851 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 852 | DEF_TEST(ClipStack, reporter) { |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 853 | SkClipStack stack; |
| 854 | |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 855 | REPORTER_ASSERT(reporter, 0 == stack.getSaveCount()); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 856 | assert_count(reporter, stack, 0); |
| 857 | |
| 858 | static const SkIRect gRects[] = { |
| 859 | { 0, 0, 100, 100 }, |
| 860 | { 25, 25, 125, 125 }, |
| 861 | { 0, 0, 1000, 1000 }, |
| 862 | { 0, 0, 75, 75 } |
| 863 | }; |
| 864 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRects); i++) { |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 865 | stack.clipDevRect(gRects[i], SkClipOp::kIntersect); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | // all of the above rects should have been intersected, leaving only 1 rect |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 869 | SkClipStack::B2TIter iter(stack); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 870 | const SkClipStack::Element* element = iter.next(); |
epoger@google.com | 2047f00 | 2011-05-17 17:36:59 +0000 | [diff] [blame] | 871 | SkRect answer; |
Mike Reed | 92b3335 | 2019-08-24 19:39:13 -0400 | [diff] [blame] | 872 | answer.setLTRB(25, 25, 75, 75); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 873 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 874 | REPORTER_ASSERT(reporter, element); |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 875 | REPORTER_ASSERT(reporter, |
| 876 | SkClipStack::Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 877 | REPORTER_ASSERT(reporter, SkClipOp::kIntersect == element->getOp()); |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 878 | REPORTER_ASSERT(reporter, element->getDeviceSpaceRect() == answer); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 879 | // now check that we only had one in our iterator |
| 880 | REPORTER_ASSERT(reporter, !iter.next()); |
| 881 | |
| 882 | stack.reset(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 883 | REPORTER_ASSERT(reporter, 0 == stack.getSaveCount()); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 884 | assert_count(reporter, stack, 0); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 885 | |
| 886 | test_assign_and_comparison(reporter); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 887 | test_iterators(reporter); |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 888 | test_bounds(reporter, SkClipStack::Element::DeviceSpaceType::kRect); |
| 889 | test_bounds(reporter, SkClipStack::Element::DeviceSpaceType::kRRect); |
| 890 | test_bounds(reporter, SkClipStack::Element::DeviceSpaceType::kPath); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 891 | test_isWideOpen(reporter); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 892 | test_rect_merging(reporter); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 893 | test_rect_replace(reporter); |
junov@chromium.org | edf32d5 | 2012-12-10 14:57:54 +0000 | [diff] [blame] | 894 | test_rect_inverse_fill(reporter); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 895 | test_path_replace(reporter); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 896 | test_quickContains(reporter); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 897 | test_invfill_diff_bug(reporter); |
Brian Salomon | 1c0b05a | 2019-04-19 15:37:28 -0400 | [diff] [blame] | 898 | test_is_rrect_deep_rect_stack(reporter); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 899 | } |