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 | |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 8 | #include "Test.h" |
| 9 | #include "SkClipStack.h" |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 10 | #include "SkPath.h" |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 11 | #include "SkRandom.h" |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 12 | #include "SkRect.h" |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 13 | #include "SkRegion.h" |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 14 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 15 | #if SK_SUPPORT_GPU |
| 16 | #include "GrReducedClip.h" |
| 17 | typedef GrReducedClip::ElementList ElementList; |
| 18 | typedef GrReducedClip::InitialState InitialState; |
| 19 | #endif |
| 20 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 21 | static void test_assign_and_comparison(skiatest::Reporter* reporter) { |
| 22 | SkClipStack s; |
reed@google.com | d9f2dea | 2011-10-12 14:43:27 +0000 | [diff] [blame] | 23 | bool doAA = false; |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 24 | |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 25 | REPORTER_ASSERT(reporter, 0 == s.getSaveCount()); |
| 26 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 27 | // Build up a clip stack with a path, an empty clip, and a rect. |
| 28 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 29 | REPORTER_ASSERT(reporter, 1 == s.getSaveCount()); |
| 30 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 31 | SkPath p; |
| 32 | p.moveTo(5, 6); |
| 33 | p.lineTo(7, 8); |
| 34 | p.lineTo(5, 9); |
| 35 | p.close(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 36 | s.clipPath(p, SkMatrix::I(), kIntersect_SkClipOp, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 37 | |
| 38 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 39 | REPORTER_ASSERT(reporter, 2 == s.getSaveCount()); |
| 40 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 41 | SkRect r = SkRect::MakeLTRB(1, 2, 3, 4); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 42 | s.clipRect(r, SkMatrix::I(), kIntersect_SkClipOp, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 43 | r = SkRect::MakeLTRB(10, 11, 12, 13); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 44 | s.clipRect(r, SkMatrix::I(), kIntersect_SkClipOp, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 45 | |
| 46 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 47 | REPORTER_ASSERT(reporter, 3 == s.getSaveCount()); |
| 48 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 49 | r = SkRect::MakeLTRB(14, 15, 16, 17); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 50 | s.clipRect(r, SkMatrix::I(), kUnion_SkClipOp, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 51 | |
| 52 | // Test that assignment works. |
| 53 | SkClipStack copy = s; |
| 54 | REPORTER_ASSERT(reporter, s == copy); |
| 55 | |
| 56 | // Test that different save levels triggers not equal. |
| 57 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 58 | REPORTER_ASSERT(reporter, 2 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 59 | REPORTER_ASSERT(reporter, s != copy); |
| 60 | |
| 61 | // Test that an equal, but not copied version is equal. |
| 62 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 63 | REPORTER_ASSERT(reporter, 3 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 64 | r = SkRect::MakeLTRB(14, 15, 16, 17); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 65 | s.clipRect(r, SkMatrix::I(), kUnion_SkClipOp, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 66 | REPORTER_ASSERT(reporter, s == copy); |
| 67 | |
| 68 | // Test that a different op on one level triggers not equal. |
| 69 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 70 | REPORTER_ASSERT(reporter, 2 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 71 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 72 | REPORTER_ASSERT(reporter, 3 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 73 | r = SkRect::MakeLTRB(14, 15, 16, 17); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 74 | s.clipRect(r, SkMatrix::I(), kIntersect_SkClipOp, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 75 | REPORTER_ASSERT(reporter, s != copy); |
| 76 | |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 77 | // 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] | 78 | s.restore(); |
| 79 | s.save(); |
| 80 | SkPath rp; |
| 81 | rp.addRect(r); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 82 | s.clipPath(rp, SkMatrix::I(), kUnion_SkClipOp, doAA); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 83 | REPORTER_ASSERT(reporter, s == copy); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 84 | |
| 85 | // Test that different rects triggers not equal. |
| 86 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 87 | REPORTER_ASSERT(reporter, 2 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 88 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 89 | REPORTER_ASSERT(reporter, 3 == s.getSaveCount()); |
| 90 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 91 | r = SkRect::MakeLTRB(24, 25, 26, 27); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 92 | s.clipRect(r, SkMatrix::I(), kUnion_SkClipOp, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 93 | REPORTER_ASSERT(reporter, s != copy); |
| 94 | |
| 95 | // Sanity check |
| 96 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 97 | REPORTER_ASSERT(reporter, 2 == s.getSaveCount()); |
| 98 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 99 | copy.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 100 | REPORTER_ASSERT(reporter, 2 == copy.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 101 | REPORTER_ASSERT(reporter, s == copy); |
| 102 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 103 | REPORTER_ASSERT(reporter, 1 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 104 | copy.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 105 | REPORTER_ASSERT(reporter, 1 == copy.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 106 | REPORTER_ASSERT(reporter, s == copy); |
| 107 | |
| 108 | // Test that different paths triggers not equal. |
| 109 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 110 | REPORTER_ASSERT(reporter, 0 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 111 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 112 | REPORTER_ASSERT(reporter, 1 == s.getSaveCount()); |
| 113 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 114 | p.addRect(r); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 115 | s.clipPath(p, SkMatrix::I(), kIntersect_SkClipOp, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 116 | REPORTER_ASSERT(reporter, s != copy); |
| 117 | } |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 118 | |
| 119 | static void assert_count(skiatest::Reporter* reporter, const SkClipStack& stack, |
| 120 | int count) { |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 121 | SkClipStack::B2TIter iter(stack); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 122 | int counter = 0; |
| 123 | while (iter.next()) { |
| 124 | counter += 1; |
| 125 | } |
| 126 | REPORTER_ASSERT(reporter, count == counter); |
| 127 | } |
| 128 | |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 129 | // Exercise the SkClipStack's bottom to top and bidirectional iterators |
| 130 | // (including the skipToTopmost functionality) |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 131 | static void test_iterators(skiatest::Reporter* reporter) { |
| 132 | SkClipStack stack; |
| 133 | |
| 134 | static const SkRect gRects[] = { |
| 135 | { 0, 0, 40, 40 }, |
| 136 | { 60, 0, 100, 40 }, |
| 137 | { 0, 60, 40, 100 }, |
| 138 | { 60, 60, 100, 100 } |
| 139 | }; |
| 140 | |
| 141 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRects); i++) { |
| 142 | // the union op will prevent these from being fused together |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 143 | stack.clipRect(gRects[i], SkMatrix::I(), kUnion_SkClipOp, false); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | assert_count(reporter, stack, 4); |
| 147 | |
| 148 | // bottom to top iteration |
| 149 | { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 150 | const SkClipStack::Element* element = nullptr; |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 151 | |
| 152 | SkClipStack::B2TIter iter(stack); |
| 153 | int i; |
| 154 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 155 | for (i = 0, element = iter.next(); element; ++i, element = iter.next()) { |
| 156 | REPORTER_ASSERT(reporter, SkClipStack::Element::kRect_Type == element->getType()); |
| 157 | REPORTER_ASSERT(reporter, element->getRect() == gRects[i]); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | SkASSERT(i == 4); |
| 161 | } |
| 162 | |
| 163 | // top to bottom iteration |
| 164 | { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 165 | const SkClipStack::Element* element = nullptr; |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 166 | |
| 167 | SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart); |
| 168 | int i; |
| 169 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 170 | for (i = 3, element = iter.prev(); element; --i, element = iter.prev()) { |
| 171 | REPORTER_ASSERT(reporter, SkClipStack::Element::kRect_Type == element->getType()); |
| 172 | REPORTER_ASSERT(reporter, element->getRect() == gRects[i]); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | SkASSERT(i == -1); |
| 176 | } |
| 177 | |
| 178 | // skipToTopmost |
| 179 | { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 180 | const SkClipStack::Element* element = nullptr; |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 181 | |
| 182 | SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart); |
| 183 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 184 | element = iter.skipToTopmost(kUnion_SkClipOp); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 185 | REPORTER_ASSERT(reporter, SkClipStack::Element::kRect_Type == element->getType()); |
| 186 | REPORTER_ASSERT(reporter, element->getRect() == gRects[3]); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 190 | // Exercise the SkClipStack's getConservativeBounds computation |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 191 | static void test_bounds(skiatest::Reporter* reporter, SkClipStack::Element::Type primType) { |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 192 | static const int gNumCases = 20; |
| 193 | static const SkRect gAnswerRectsBW[gNumCases] = { |
| 194 | // A op B |
| 195 | { 40, 40, 50, 50 }, |
| 196 | { 10, 10, 50, 50 }, |
| 197 | { 10, 10, 80, 80 }, |
| 198 | { 10, 10, 80, 80 }, |
| 199 | { 40, 40, 80, 80 }, |
| 200 | |
| 201 | // invA op B |
| 202 | { 40, 40, 80, 80 }, |
| 203 | { 0, 0, 100, 100 }, |
| 204 | { 0, 0, 100, 100 }, |
| 205 | { 0, 0, 100, 100 }, |
| 206 | { 40, 40, 50, 50 }, |
| 207 | |
| 208 | // A op invB |
| 209 | { 10, 10, 50, 50 }, |
| 210 | { 40, 40, 50, 50 }, |
| 211 | { 0, 0, 100, 100 }, |
| 212 | { 0, 0, 100, 100 }, |
| 213 | { 0, 0, 100, 100 }, |
| 214 | |
| 215 | // invA op invB |
| 216 | { 0, 0, 100, 100 }, |
| 217 | { 40, 40, 80, 80 }, |
| 218 | { 0, 0, 100, 100 }, |
| 219 | { 10, 10, 80, 80 }, |
| 220 | { 10, 10, 50, 50 }, |
| 221 | }; |
| 222 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 223 | static const SkClipOp gOps[] = { |
| 224 | kIntersect_SkClipOp, |
| 225 | kDifference_SkClipOp, |
| 226 | kUnion_SkClipOp, |
| 227 | kXOR_SkClipOp, |
| 228 | kReverseDifference_SkClipOp |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | SkRect rectA, rectB; |
| 232 | |
| 233 | rectA.iset(10, 10, 50, 50); |
| 234 | rectB.iset(40, 40, 80, 80); |
| 235 | |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 236 | SkRRect rrectA, rrectB; |
| 237 | rrectA.setOval(rectA); |
| 238 | rrectB.setRectXY(rectB, SkIntToScalar(1), SkIntToScalar(2)); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 239 | |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 240 | SkPath pathA, pathB; |
| 241 | |
| 242 | pathA.addRoundRect(rectA, SkIntToScalar(5), SkIntToScalar(5)); |
| 243 | pathB.addRoundRect(rectB, SkIntToScalar(5), SkIntToScalar(5)); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 244 | |
| 245 | SkClipStack stack; |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 246 | SkRect devClipBound; |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 247 | bool isIntersectionOfRects = false; |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 248 | |
| 249 | int testCase = 0; |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 250 | int numBitTests = SkClipStack::Element::kPath_Type == primType ? 4 : 1; |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 251 | for (int invBits = 0; invBits < numBitTests; ++invBits) { |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 252 | for (size_t op = 0; op < SK_ARRAY_COUNT(gOps); ++op) { |
| 253 | |
| 254 | stack.save(); |
| 255 | bool doInvA = SkToBool(invBits & 1); |
| 256 | bool doInvB = SkToBool(invBits & 2); |
| 257 | |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 258 | pathA.setFillType(doInvA ? SkPath::kInverseEvenOdd_FillType : |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 259 | SkPath::kEvenOdd_FillType); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 260 | pathB.setFillType(doInvB ? SkPath::kInverseEvenOdd_FillType : |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 261 | SkPath::kEvenOdd_FillType); |
| 262 | |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 263 | switch (primType) { |
| 264 | case SkClipStack::Element::kEmpty_Type: |
| 265 | SkDEBUGFAIL("Don't call this with kEmpty."); |
| 266 | break; |
| 267 | case SkClipStack::Element::kRect_Type: |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 268 | stack.clipRect(rectA, SkMatrix::I(), kIntersect_SkClipOp, false); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 269 | stack.clipRect(rectB, SkMatrix::I(), gOps[op], false); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 270 | break; |
| 271 | case SkClipStack::Element::kRRect_Type: |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 272 | stack.clipRRect(rrectA, SkMatrix::I(), kIntersect_SkClipOp, false); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 273 | stack.clipRRect(rrectB, SkMatrix::I(), gOps[op], false); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 274 | break; |
| 275 | case SkClipStack::Element::kPath_Type: |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 276 | stack.clipPath(pathA, SkMatrix::I(), kIntersect_SkClipOp, false); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 277 | stack.clipPath(pathB, SkMatrix::I(), gOps[op], false); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 278 | break; |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 279 | } |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 280 | |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 281 | REPORTER_ASSERT(reporter, !stack.isWideOpen()); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 282 | REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID != stack.getTopmostGenID()); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 283 | |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 284 | stack.getConservativeBounds(0, 0, 100, 100, &devClipBound, |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 285 | &isIntersectionOfRects); |
| 286 | |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 287 | if (SkClipStack::Element::kRect_Type == primType) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 288 | REPORTER_ASSERT(reporter, isIntersectionOfRects == |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 289 | (gOps[op] == kIntersect_SkClipOp)); |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 290 | } else { |
| 291 | REPORTER_ASSERT(reporter, !isIntersectionOfRects); |
| 292 | } |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 293 | |
| 294 | SkASSERT(testCase < gNumCases); |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 295 | REPORTER_ASSERT(reporter, devClipBound == gAnswerRectsBW[testCase]); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 296 | ++testCase; |
| 297 | |
| 298 | stack.restore(); |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 303 | // Test out 'isWideOpen' entry point |
| 304 | static void test_isWideOpen(skiatest::Reporter* reporter) { |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 305 | { |
| 306 | // Empty stack is wide open. Wide open stack means that gen id is wide open. |
| 307 | SkClipStack stack; |
| 308 | REPORTER_ASSERT(reporter, stack.isWideOpen()); |
| 309 | REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID()); |
| 310 | } |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 311 | |
| 312 | SkRect rectA, rectB; |
| 313 | |
| 314 | rectA.iset(10, 10, 40, 40); |
| 315 | rectB.iset(50, 50, 80, 80); |
| 316 | |
| 317 | // Stack should initially be wide open |
| 318 | { |
| 319 | SkClipStack stack; |
| 320 | |
| 321 | REPORTER_ASSERT(reporter, stack.isWideOpen()); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 322 | REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID()); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | // Test out case where the user specifies a union that includes everything |
| 326 | { |
| 327 | SkClipStack stack; |
| 328 | |
| 329 | SkPath clipA, clipB; |
| 330 | |
| 331 | clipA.addRoundRect(rectA, SkIntToScalar(5), SkIntToScalar(5)); |
| 332 | clipA.setFillType(SkPath::kInverseEvenOdd_FillType); |
| 333 | |
| 334 | clipB.addRoundRect(rectB, SkIntToScalar(5), SkIntToScalar(5)); |
| 335 | clipB.setFillType(SkPath::kInverseEvenOdd_FillType); |
| 336 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 337 | stack.clipPath(clipA, SkMatrix::I(), kReplace_SkClipOp, false); |
| 338 | stack.clipPath(clipB, SkMatrix::I(), kUnion_SkClipOp, false); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 339 | |
| 340 | REPORTER_ASSERT(reporter, stack.isWideOpen()); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 341 | REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID()); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | // Test out union w/ a wide open clip |
| 345 | { |
| 346 | SkClipStack stack; |
| 347 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 348 | stack.clipRect(rectA, SkMatrix::I(), kUnion_SkClipOp, false); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 349 | |
| 350 | REPORTER_ASSERT(reporter, stack.isWideOpen()); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 351 | REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID()); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | // Test out empty difference from a wide open clip |
| 355 | { |
| 356 | SkClipStack stack; |
| 357 | |
| 358 | SkRect emptyRect; |
| 359 | emptyRect.setEmpty(); |
| 360 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 361 | stack.clipRect(emptyRect, SkMatrix::I(), kDifference_SkClipOp, false); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 362 | |
| 363 | REPORTER_ASSERT(reporter, stack.isWideOpen()); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 364 | REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID()); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | // Test out return to wide open |
| 368 | { |
| 369 | SkClipStack stack; |
| 370 | |
| 371 | stack.save(); |
| 372 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 373 | stack.clipRect(rectA, SkMatrix::I(), kReplace_SkClipOp, false); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 374 | |
| 375 | REPORTER_ASSERT(reporter, !stack.isWideOpen()); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 376 | REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID != stack.getTopmostGenID()); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 377 | |
| 378 | stack.restore(); |
| 379 | |
| 380 | REPORTER_ASSERT(reporter, stack.isWideOpen()); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 381 | REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID()); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | |
bsalomon@google.com | 100abf4 | 2012-09-05 17:40:04 +0000 | [diff] [blame] | 385 | static int count(const SkClipStack& stack) { |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 386 | |
| 387 | SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart); |
| 388 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 389 | const SkClipStack::Element* element = nullptr; |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 390 | int count = 0; |
| 391 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 392 | for (element = iter.prev(); element; element = iter.prev(), ++count) { |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 393 | ; |
| 394 | } |
| 395 | |
| 396 | return count; |
| 397 | } |
| 398 | |
junov@chromium.org | edf32d5 | 2012-12-10 14:57:54 +0000 | [diff] [blame] | 399 | static void test_rect_inverse_fill(skiatest::Reporter* reporter) { |
| 400 | // non-intersecting rectangles |
| 401 | SkRect rect = SkRect::MakeLTRB(0, 0, 10, 10); |
| 402 | |
| 403 | SkPath path; |
| 404 | path.addRect(rect); |
| 405 | path.toggleInverseFillType(); |
| 406 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 407 | stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | edf32d5 | 2012-12-10 14:57:54 +0000 | [diff] [blame] | 408 | |
| 409 | SkRect bounds; |
| 410 | SkClipStack::BoundsType boundsType; |
| 411 | stack.getBounds(&bounds, &boundsType); |
| 412 | REPORTER_ASSERT(reporter, SkClipStack::kInsideOut_BoundsType == boundsType); |
| 413 | REPORTER_ASSERT(reporter, bounds == rect); |
| 414 | } |
| 415 | |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 416 | static void test_rect_replace(skiatest::Reporter* reporter) { |
| 417 | SkRect rect = SkRect::MakeWH(100, 100); |
| 418 | SkRect rect2 = SkRect::MakeXYWH(50, 50, 100, 100); |
| 419 | |
| 420 | SkRect bound; |
| 421 | SkClipStack::BoundsType type; |
| 422 | bool isIntersectionOfRects; |
| 423 | |
| 424 | // Adding a new rect with the replace operator should not increase |
| 425 | // the stack depth. BW replacing BW. |
| 426 | { |
| 427 | SkClipStack stack; |
| 428 | REPORTER_ASSERT(reporter, 0 == count(stack)); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 429 | stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 430 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 431 | stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 432 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 433 | } |
| 434 | |
| 435 | // Adding a new rect with the replace operator should not increase |
| 436 | // the stack depth. AA replacing AA. |
| 437 | { |
| 438 | SkClipStack stack; |
| 439 | REPORTER_ASSERT(reporter, 0 == count(stack)); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 440 | stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, true); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 441 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 442 | stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, true); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 443 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 444 | } |
| 445 | |
| 446 | // Adding a new rect with the replace operator should not increase |
| 447 | // the stack depth. BW replacing AA replacing BW. |
| 448 | { |
| 449 | SkClipStack stack; |
| 450 | REPORTER_ASSERT(reporter, 0 == count(stack)); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 451 | stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 452 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 453 | stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, true); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 454 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 455 | stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 456 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 457 | } |
| 458 | |
| 459 | // Make sure replace clip rects don't collapse too much. |
| 460 | { |
| 461 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 462 | stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, false); |
| 463 | stack.clipRect(rect2, SkMatrix::I(), kIntersect_SkClipOp, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 464 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 465 | |
| 466 | stack.save(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 467 | stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 468 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 469 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 470 | REPORTER_ASSERT(reporter, bound == rect); |
| 471 | stack.restore(); |
| 472 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 473 | |
| 474 | stack.save(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 475 | stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, false); |
| 476 | stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 477 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 478 | stack.restore(); |
| 479 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 480 | |
| 481 | stack.save(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 482 | stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, false); |
| 483 | stack.clipRect(rect2, SkMatrix::I(), kIntersect_SkClipOp, false); |
| 484 | stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 485 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 486 | stack.restore(); |
| 487 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | // Simplified path-based version of test_rect_replace. |
| 492 | static void test_path_replace(skiatest::Reporter* reporter) { |
| 493 | SkRect rect = SkRect::MakeWH(100, 100); |
| 494 | SkPath path; |
| 495 | path.addCircle(50, 50, 50); |
| 496 | |
| 497 | // Replace operation doesn't grow the stack. |
| 498 | { |
| 499 | SkClipStack stack; |
| 500 | REPORTER_ASSERT(reporter, 0 == count(stack)); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 501 | stack.clipPath(path, SkMatrix::I(), kReplace_SkClipOp, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 502 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 503 | stack.clipPath(path, SkMatrix::I(), kReplace_SkClipOp, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 504 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 505 | } |
| 506 | |
| 507 | // Replacing rect with path. |
| 508 | { |
| 509 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 510 | stack.clipRect(rect, SkMatrix::I(), kReplace_SkClipOp, true); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 511 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 512 | stack.clipPath(path, SkMatrix::I(), kReplace_SkClipOp, true); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 513 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 514 | } |
| 515 | } |
| 516 | |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 517 | // Test out SkClipStack's merging of rect clips. In particular exercise |
| 518 | // merging of aa vs. bw rects. |
| 519 | static void test_rect_merging(skiatest::Reporter* reporter) { |
| 520 | |
| 521 | SkRect overlapLeft = SkRect::MakeLTRB(10, 10, 50, 50); |
| 522 | SkRect overlapRight = SkRect::MakeLTRB(40, 40, 80, 80); |
| 523 | |
| 524 | SkRect nestedParent = SkRect::MakeLTRB(10, 10, 90, 90); |
| 525 | SkRect nestedChild = SkRect::MakeLTRB(40, 40, 60, 60); |
| 526 | |
| 527 | SkRect bound; |
| 528 | SkClipStack::BoundsType type; |
| 529 | bool isIntersectionOfRects; |
| 530 | |
| 531 | // all bw overlapping - should merge |
| 532 | { |
| 533 | SkClipStack stack; |
| 534 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 535 | stack.clipRect(overlapLeft, SkMatrix::I(), kReplace_SkClipOp, false); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 536 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 537 | stack.clipRect(overlapRight, SkMatrix::I(), kIntersect_SkClipOp, false); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 538 | |
| 539 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 540 | |
| 541 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 542 | |
| 543 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 544 | } |
| 545 | |
| 546 | // all aa overlapping - should merge |
| 547 | { |
| 548 | SkClipStack stack; |
| 549 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 550 | stack.clipRect(overlapLeft, SkMatrix::I(), kReplace_SkClipOp, true); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 551 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 552 | stack.clipRect(overlapRight, SkMatrix::I(), kIntersect_SkClipOp, true); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 553 | |
| 554 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 555 | |
| 556 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 557 | |
| 558 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 559 | } |
| 560 | |
| 561 | // mixed overlapping - should _not_ merge |
| 562 | { |
| 563 | SkClipStack stack; |
| 564 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 565 | stack.clipRect(overlapLeft, SkMatrix::I(), kReplace_SkClipOp, true); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 566 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 567 | stack.clipRect(overlapRight, SkMatrix::I(), kIntersect_SkClipOp, false); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 568 | |
| 569 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 570 | |
| 571 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 572 | |
| 573 | REPORTER_ASSERT(reporter, !isIntersectionOfRects); |
| 574 | } |
| 575 | |
| 576 | // mixed nested (bw inside aa) - should merge |
| 577 | { |
| 578 | SkClipStack stack; |
| 579 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 580 | stack.clipRect(nestedParent, SkMatrix::I(), kReplace_SkClipOp, true); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 581 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 582 | stack.clipRect(nestedChild, SkMatrix::I(), kIntersect_SkClipOp, false); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 583 | |
| 584 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 585 | |
| 586 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 587 | |
| 588 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 589 | } |
| 590 | |
| 591 | // mixed nested (aa inside bw) - should merge |
| 592 | { |
| 593 | SkClipStack stack; |
| 594 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 595 | stack.clipRect(nestedParent, SkMatrix::I(), kReplace_SkClipOp, false); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 596 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 597 | stack.clipRect(nestedChild, SkMatrix::I(), kIntersect_SkClipOp, true); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 598 | |
| 599 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 600 | |
| 601 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 602 | |
| 603 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 604 | } |
| 605 | |
| 606 | // reverse nested (aa inside bw) - should _not_ merge |
| 607 | { |
| 608 | SkClipStack stack; |
| 609 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 610 | stack.clipRect(nestedChild, SkMatrix::I(), kReplace_SkClipOp, false); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 611 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 612 | stack.clipRect(nestedParent, SkMatrix::I(), kIntersect_SkClipOp, true); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 613 | |
| 614 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 615 | |
| 616 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 617 | |
| 618 | REPORTER_ASSERT(reporter, !isIntersectionOfRects); |
| 619 | } |
| 620 | } |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 621 | |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 622 | static void test_quickContains(skiatest::Reporter* reporter) { |
| 623 | SkRect testRect = SkRect::MakeLTRB(10, 10, 40, 40); |
| 624 | SkRect insideRect = SkRect::MakeLTRB(20, 20, 30, 30); |
| 625 | SkRect intersectingRect = SkRect::MakeLTRB(25, 25, 50, 50); |
| 626 | SkRect outsideRect = SkRect::MakeLTRB(0, 0, 50, 50); |
| 627 | SkRect nonIntersectingRect = SkRect::MakeLTRB(100, 100, 110, 110); |
| 628 | |
| 629 | SkPath insideCircle; |
| 630 | insideCircle.addCircle(25, 25, 5); |
| 631 | SkPath intersectingCircle; |
| 632 | intersectingCircle.addCircle(25, 40, 10); |
| 633 | SkPath outsideCircle; |
| 634 | outsideCircle.addCircle(25, 25, 50); |
| 635 | SkPath nonIntersectingCircle; |
| 636 | nonIntersectingCircle.addCircle(100, 100, 5); |
| 637 | |
| 638 | { |
| 639 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 640 | stack.clipRect(outsideRect, SkMatrix::I(), kDifference_SkClipOp, false); |
| 641 | // return false because quickContains currently does not care for kDifference_SkClipOp |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 642 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 643 | } |
skia.committer@gmail.com | 306ab9d | 2012-12-13 02:01:33 +0000 | [diff] [blame] | 644 | |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 645 | // Replace Op tests |
| 646 | { |
| 647 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 648 | stack.clipRect(outsideRect, SkMatrix::I(), kReplace_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 649 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 650 | } |
| 651 | |
| 652 | { |
| 653 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 654 | stack.clipRect(insideRect, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 655 | stack.save(); // To prevent in-place substitution by replace OP |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 656 | stack.clipRect(outsideRect, SkMatrix::I(), kReplace_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 657 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 658 | stack.restore(); |
| 659 | } |
| 660 | |
| 661 | { |
| 662 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 663 | stack.clipRect(outsideRect, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 664 | stack.save(); // To prevent in-place substitution by replace OP |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 665 | stack.clipRect(insideRect, SkMatrix::I(), kReplace_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 666 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 667 | stack.restore(); |
| 668 | } |
| 669 | |
| 670 | // Verify proper traversal of multi-element clip |
| 671 | { |
| 672 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 673 | stack.clipRect(insideRect, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 674 | // Use a path for second clip to prevent in-place intersection |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 675 | stack.clipPath(outsideCircle, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 676 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 677 | } |
| 678 | |
| 679 | // Intersect Op tests with rectangles |
| 680 | { |
| 681 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 682 | stack.clipRect(outsideRect, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 683 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 684 | } |
| 685 | |
| 686 | { |
| 687 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 688 | stack.clipRect(insideRect, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 689 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 690 | } |
| 691 | |
| 692 | { |
| 693 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 694 | stack.clipRect(intersectingRect, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 695 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 696 | } |
| 697 | |
| 698 | { |
| 699 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 700 | stack.clipRect(nonIntersectingRect, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 701 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 702 | } |
| 703 | |
| 704 | // Intersect Op tests with circle paths |
| 705 | { |
| 706 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 707 | stack.clipPath(outsideCircle, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 708 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 709 | } |
| 710 | |
| 711 | { |
| 712 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 713 | stack.clipPath(insideCircle, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 714 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 715 | } |
| 716 | |
| 717 | { |
| 718 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 719 | stack.clipPath(intersectingCircle, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 720 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 721 | } |
| 722 | |
| 723 | { |
| 724 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 725 | stack.clipPath(nonIntersectingCircle, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 726 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 727 | } |
| 728 | |
| 729 | // Intersect Op tests with inverse filled rectangles |
| 730 | { |
| 731 | SkClipStack stack; |
| 732 | SkPath path; |
| 733 | path.addRect(outsideRect); |
| 734 | path.toggleInverseFillType(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 735 | stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 736 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 737 | } |
| 738 | |
| 739 | { |
| 740 | SkClipStack stack; |
| 741 | SkPath path; |
| 742 | path.addRect(insideRect); |
| 743 | path.toggleInverseFillType(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 744 | stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 745 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 746 | } |
| 747 | |
| 748 | { |
| 749 | SkClipStack stack; |
| 750 | SkPath path; |
| 751 | path.addRect(intersectingRect); |
| 752 | path.toggleInverseFillType(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 753 | stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 754 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 755 | } |
| 756 | |
| 757 | { |
| 758 | SkClipStack stack; |
| 759 | SkPath path; |
| 760 | path.addRect(nonIntersectingRect); |
| 761 | path.toggleInverseFillType(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 762 | stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 763 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 764 | } |
| 765 | |
| 766 | // Intersect Op tests with inverse filled circles |
| 767 | { |
| 768 | SkClipStack stack; |
| 769 | SkPath path = outsideCircle; |
| 770 | path.toggleInverseFillType(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 771 | stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 772 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 773 | } |
| 774 | |
| 775 | { |
| 776 | SkClipStack stack; |
| 777 | SkPath path = insideCircle; |
| 778 | path.toggleInverseFillType(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 779 | stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 780 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 781 | } |
| 782 | |
| 783 | { |
| 784 | SkClipStack stack; |
| 785 | SkPath path = intersectingCircle; |
| 786 | path.toggleInverseFillType(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 787 | stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 788 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 789 | } |
| 790 | |
| 791 | { |
| 792 | SkClipStack stack; |
| 793 | SkPath path = nonIntersectingCircle; |
| 794 | path.toggleInverseFillType(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 795 | stack.clipPath(path, SkMatrix::I(), kIntersect_SkClipOp, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 796 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 797 | } |
| 798 | } |
| 799 | |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 800 | static void set_region_to_stack(const SkClipStack& stack, const SkIRect& bounds, SkRegion* region) { |
| 801 | region->setRect(bounds); |
| 802 | SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart); |
| 803 | while (const SkClipStack::Element *element = iter.next()) { |
| 804 | SkRegion elemRegion; |
| 805 | SkRegion boundsRgn(bounds); |
| 806 | SkPath path; |
| 807 | |
| 808 | switch (element->getType()) { |
| 809 | case SkClipStack::Element::kEmpty_Type: |
| 810 | elemRegion.setEmpty(); |
| 811 | break; |
| 812 | default: |
| 813 | element->asPath(&path); |
| 814 | elemRegion.setPath(path, boundsRgn); |
| 815 | break; |
| 816 | } |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 817 | region->op(elemRegion, (SkRegion::Op)element->getOp()); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 818 | } |
| 819 | } |
| 820 | |
| 821 | static void test_invfill_diff_bug(skiatest::Reporter* reporter) { |
| 822 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 823 | stack.clipRect({10, 10, 20, 20}, SkMatrix::I(), kIntersect_SkClipOp, false); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 824 | |
| 825 | SkPath path; |
| 826 | path.addRect({30, 10, 40, 20}); |
| 827 | path.setFillType(SkPath::kInverseWinding_FillType); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 828 | stack.clipPath(path, SkMatrix::I(), kDifference_SkClipOp, false); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 829 | |
| 830 | REPORTER_ASSERT(reporter, SkClipStack::kEmptyGenID == stack.getTopmostGenID()); |
| 831 | |
| 832 | SkRect stackBounds; |
| 833 | SkClipStack::BoundsType stackBoundsType; |
| 834 | stack.getBounds(&stackBounds, &stackBoundsType); |
| 835 | |
| 836 | REPORTER_ASSERT(reporter, stackBounds.isEmpty()); |
| 837 | REPORTER_ASSERT(reporter, SkClipStack::kNormal_BoundsType == stackBoundsType); |
| 838 | |
| 839 | SkRegion region; |
| 840 | set_region_to_stack(stack, {0, 0, 50, 30}, ®ion); |
| 841 | |
| 842 | REPORTER_ASSERT(reporter, region.isEmpty()); |
| 843 | } |
| 844 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 845 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 846 | |
bsalomon@google.com | a4e13c8 | 2012-11-26 21:38:37 +0000 | [diff] [blame] | 847 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 848 | // Functions that add a shape to the clip stack. The shape is computed from a rectangle. |
| 849 | // AA is always disabled since the clip stack reducer can cause changes in aa rasterization of the |
| 850 | // stack. A fractional edge repeated in different elements may be rasterized fewer times using the |
| 851 | // reduced stack. |
| 852 | typedef void (*AddElementFunc) (const SkRect& rect, |
| 853 | bool invert, |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 854 | SkClipOp op, |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 855 | SkClipStack* stack, |
| 856 | bool doAA); |
bsalomon@google.com | a4e13c8 | 2012-11-26 21:38:37 +0000 | [diff] [blame] | 857 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 858 | static void add_round_rect(const SkRect& rect, bool invert, SkClipOp op, SkClipStack* stack, |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 859 | bool doAA) { |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 860 | SkScalar rx = rect.width() / 10; |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 861 | SkScalar ry = rect.height() / 20; |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 862 | if (invert) { |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 863 | SkPath path; |
| 864 | path.addRoundRect(rect, rx, ry); |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 865 | path.setFillType(SkPath::kInverseWinding_FillType); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 866 | stack->clipPath(path, SkMatrix::I(), op, doAA); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 867 | } else { |
| 868 | SkRRect rrect; |
| 869 | rrect.setRectXY(rect, rx, ry); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 870 | stack->clipRRect(rrect, SkMatrix::I(), op, doAA); |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 871 | } |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 872 | }; |
| 873 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 874 | static void add_rect(const SkRect& rect, bool invert, SkClipOp op, SkClipStack* stack, |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 875 | bool doAA) { |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 876 | if (invert) { |
| 877 | SkPath path; |
| 878 | path.addRect(rect); |
| 879 | path.setFillType(SkPath::kInverseWinding_FillType); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 880 | stack->clipPath(path, SkMatrix::I(), op, doAA); |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 881 | } else { |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 882 | stack->clipRect(rect, SkMatrix::I(), op, doAA); |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 883 | } |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 884 | }; |
| 885 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 886 | static void add_oval(const SkRect& rect, bool invert, SkClipOp op, SkClipStack* stack, |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 887 | bool doAA) { |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 888 | SkPath path; |
| 889 | path.addOval(rect); |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 890 | if (invert) { |
| 891 | path.setFillType(SkPath::kInverseWinding_FillType); |
| 892 | } |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 893 | stack->clipPath(path, SkMatrix::I(), op, doAA); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 894 | }; |
| 895 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 896 | static void add_elem_to_stack(const SkClipStack::Element& element, SkClipStack* stack) { |
| 897 | switch (element.getType()) { |
| 898 | case SkClipStack::Element::kRect_Type: |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 899 | stack->clipRect(element.getRect(), SkMatrix::I(), element.getOp(), element.isAA()); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 900 | break; |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 901 | case SkClipStack::Element::kRRect_Type: |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 902 | stack->clipRRect(element.getRRect(), SkMatrix::I(), element.getOp(), element.isAA()); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 903 | break; |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 904 | case SkClipStack::Element::kPath_Type: |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 905 | stack->clipPath(element.getPath(), SkMatrix::I(), element.getOp(), element.isAA()); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 906 | break; |
| 907 | case SkClipStack::Element::kEmpty_Type: |
| 908 | SkDEBUGFAIL("Why did the reducer produce an explicit empty."); |
| 909 | stack->clipEmpty(); |
| 910 | break; |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 911 | } |
| 912 | } |
| 913 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 914 | static void test_reduced_clip_stack(skiatest::Reporter* reporter) { |
| 915 | // We construct random clip stacks, reduce them, and then rasterize both versions to verify that |
skia.committer@gmail.com | 8ccf590 | 2012-11-27 02:01:19 +0000 | [diff] [blame] | 916 | // they are equal. |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 917 | |
| 918 | // All the clip elements will be contained within these bounds. |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 919 | static const SkIRect kIBounds = SkIRect::MakeWH(100, 100); |
| 920 | static const SkRect kBounds = SkRect::Make(kIBounds); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 921 | |
| 922 | enum { |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 923 | kNumTests = 250, |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 924 | kMinElemsPerTest = 1, |
| 925 | kMaxElemsPerTest = 50, |
| 926 | }; |
| 927 | |
| 928 | // min/max size of a clip element as a fraction of kBounds. |
| 929 | static const SkScalar kMinElemSizeFrac = SK_Scalar1 / 5; |
| 930 | static const SkScalar kMaxElemSizeFrac = SK_Scalar1; |
| 931 | |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 932 | static const SkClipOp kOps[] = { |
| 933 | kDifference_SkClipOp, |
| 934 | kIntersect_SkClipOp, |
| 935 | kUnion_SkClipOp, |
| 936 | kXOR_SkClipOp, |
| 937 | kReverseDifference_SkClipOp, |
| 938 | kReplace_SkClipOp, |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 939 | }; |
| 940 | |
| 941 | // Replace operations short-circuit the optimizer. We want to make sure that we test this code |
| 942 | // path a little bit but we don't want it to prevent us from testing many longer traversals in |
| 943 | // the optimizer. |
| 944 | static const int kReplaceDiv = 4 * kMaxElemsPerTest; |
| 945 | |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 946 | // We want to test inverse fills. However, they are quite rare in practice so don't over do it. |
| 947 | static const SkScalar kFractionInverted = SK_Scalar1 / kMaxElemsPerTest; |
| 948 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 949 | static const SkScalar kFractionAntialiased = 0.25; |
| 950 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 951 | static const AddElementFunc kElementFuncs[] = { |
| 952 | add_rect, |
| 953 | add_round_rect, |
| 954 | add_oval, |
| 955 | }; |
| 956 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 957 | SkRandom r; |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 958 | |
| 959 | for (int i = 0; i < kNumTests; ++i) { |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 960 | SkString testCase; |
| 961 | testCase.printf("Iteration %d", i); |
| 962 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 963 | // Randomly generate a clip stack. |
| 964 | SkClipStack stack; |
| 965 | int numElems = r.nextRangeU(kMinElemsPerTest, kMaxElemsPerTest); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 966 | bool doAA = r.nextBiasedBool(kFractionAntialiased); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 967 | for (int e = 0; e < numElems; ++e) { |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 968 | SkClipOp op = kOps[r.nextULessThan(SK_ARRAY_COUNT(kOps))]; |
| 969 | if (op == kReplace_SkClipOp) { |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 970 | if (r.nextU() % kReplaceDiv) { |
| 971 | --e; |
| 972 | continue; |
| 973 | } |
| 974 | } |
skia.committer@gmail.com | 8ccf590 | 2012-11-27 02:01:19 +0000 | [diff] [blame] | 975 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 976 | // saves can change the clip stack behavior when an element is added. |
| 977 | bool doSave = r.nextBool(); |
skia.committer@gmail.com | 8ccf590 | 2012-11-27 02:01:19 +0000 | [diff] [blame] | 978 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 979 | SkSize size = SkSize::Make( |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 980 | SkScalarMul(kBounds.width(), r.nextRangeScalar(kMinElemSizeFrac, kMaxElemSizeFrac)), |
| 981 | SkScalarMul(kBounds.height(), r.nextRangeScalar(kMinElemSizeFrac, kMaxElemSizeFrac))); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 982 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 983 | SkPoint xy = {r.nextRangeScalar(kBounds.fLeft, kBounds.fRight - size.fWidth), |
| 984 | r.nextRangeScalar(kBounds.fTop, kBounds.fBottom - size.fHeight)}; |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 985 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 986 | SkRect rect; |
| 987 | if (doAA) { |
| 988 | rect.setXYWH(xy.fX, xy.fY, size.fWidth, size.fHeight); |
| 989 | if (GrClip::IsPixelAligned(rect)) { |
| 990 | // Don't create an element that may accidentally become not antialiased. |
| 991 | rect.outset(0.5f, 0.5f); |
| 992 | } |
| 993 | SkASSERT(!GrClip::IsPixelAligned(rect)); |
| 994 | } else { |
| 995 | rect.setXYWH(SkScalarFloorToScalar(xy.fX), |
| 996 | SkScalarFloorToScalar(xy.fY), |
| 997 | SkScalarCeilToScalar(size.fWidth), |
| 998 | SkScalarCeilToScalar(size.fHeight)); |
| 999 | } |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1000 | |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 1001 | bool invert = r.nextBiasedBool(kFractionInverted); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 1002 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1003 | kElementFuncs[r.nextULessThan(SK_ARRAY_COUNT(kElementFuncs))](rect, invert, op, &stack, |
| 1004 | doAA); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1005 | if (doSave) { |
| 1006 | stack.save(); |
| 1007 | } |
| 1008 | } |
| 1009 | |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1010 | // Zero the memory we will new the GrReducedClip into. This ensures the elements gen ID |
| 1011 | // will be kInvalidGenID if left uninitialized. |
| 1012 | SkAlignedSTStorage<1, GrReducedClip> storage; |
| 1013 | memset(storage.get(), 0, sizeof(GrReducedClip)); |
| 1014 | GR_STATIC_ASSERT(0 == SkClipStack::kInvalidGenID); |
| 1015 | |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1016 | // Get the reduced version of the stack. |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1017 | SkRect queryBounds = kBounds; |
| 1018 | queryBounds.outset(kBounds.width() / 2, kBounds.height() / 2); |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1019 | const GrReducedClip* reduced = new (storage.get()) GrReducedClip(stack, queryBounds); |
bsalomon@google.com | a444430 | 2012-12-04 15:22:12 +0000 | [diff] [blame] | 1020 | |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1021 | REPORTER_ASSERT_MESSAGE(reporter, |
| 1022 | reduced->elements().isEmpty() || |
| 1023 | SkClipStack::kInvalidGenID != reduced->elementsGenID(), |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1024 | testCase.c_str()); |
| 1025 | |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1026 | if (!reduced->elements().isEmpty()) { |
| 1027 | REPORTER_ASSERT_MESSAGE(reporter, reduced->hasIBounds(), testCase.c_str()); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1028 | SkRect stackBounds; |
| 1029 | SkClipStack::BoundsType stackBoundsType; |
| 1030 | stack.getBounds(&stackBounds, &stackBoundsType); |
| 1031 | if (SkClipStack::kNormal_BoundsType == stackBoundsType) { |
| 1032 | // Unless GrReducedClip starts doing some heroic tightening of the clip bounds, this |
| 1033 | // will be true since the stack bounds are completely contained inside the query. |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1034 | REPORTER_ASSERT_MESSAGE(reporter, |
| 1035 | GrClip::IsInsideClip(reduced->ibounds(), stackBounds), |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1036 | testCase.c_str()); |
| 1037 | } |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1038 | REPORTER_ASSERT_MESSAGE(reporter, reduced->requiresAA() == doAA, testCase.c_str()); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1039 | } |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1040 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1041 | // Build a new clip stack based on the reduced clip elements |
| 1042 | SkClipStack reducedStack; |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1043 | if (GrReducedClip::InitialState::kAllOut == reduced->initialState()) { |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1044 | // whether the result is bounded or not, the whole plane should start outside the clip. |
| 1045 | reducedStack.clipEmpty(); |
| 1046 | } |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1047 | for (ElementList::Iter iter(reduced->elements()); iter.get(); iter.next()) { |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 1048 | add_elem_to_stack(*iter.get(), &reducedStack); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1049 | } |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1050 | |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1051 | SkIRect ibounds = reduced->hasIBounds() ? reduced->ibounds() : kIBounds; |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 1052 | |
bsalomon@google.com | 34cd70a | 2012-12-06 14:23:20 +0000 | [diff] [blame] | 1053 | // GrReducedClipStack assumes that the final result is clipped to the returned bounds |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 1054 | reducedStack.clipDevRect(ibounds, kIntersect_SkClipOp); |
| 1055 | stack.clipDevRect(ibounds, kIntersect_SkClipOp); |
bsalomon@google.com | 34cd70a | 2012-12-06 14:23:20 +0000 | [diff] [blame] | 1056 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1057 | // convert both the original stack and reduced stack to SkRegions and see if they're equal |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1058 | SkRegion region; |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 1059 | set_region_to_stack(stack, ibounds, ®ion); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 1060 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1061 | SkRegion reducedRegion; |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 1062 | set_region_to_stack(reducedStack, ibounds, &reducedRegion); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1063 | |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 1064 | REPORTER_ASSERT_MESSAGE(reporter, region == reducedRegion, testCase.c_str()); |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1065 | |
| 1066 | reduced->~GrReducedClip(); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | |
halcanary | 4dbbd04 | 2016-06-07 17:21:10 -0700 | [diff] [blame] | 1070 | #ifdef SK_BUILD_FOR_WIN |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1071 | #define SUPPRESS_VISIBILITY_WARNING |
| 1072 | #else |
| 1073 | #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden"))) |
| 1074 | #endif |
| 1075 | |
| 1076 | static void test_reduced_clip_stack_genid(skiatest::Reporter* reporter) { |
| 1077 | { |
| 1078 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 1079 | stack.clipRect(SkRect::MakeXYWH(0, 0, 100, 100), SkMatrix::I(), kReplace_SkClipOp, |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 1080 | true); |
| 1081 | stack.clipRect(SkRect::MakeXYWH(0, 0, SkScalar(50.3), SkScalar(50.3)), SkMatrix::I(), |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 1082 | kReplace_SkClipOp, true); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1083 | SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1084 | |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1085 | SkAlignedSTStorage<1, GrReducedClip> storage; |
| 1086 | memset(storage.get(), 0, sizeof(GrReducedClip)); |
| 1087 | GR_STATIC_ASSERT(0 == SkClipStack::kInvalidGenID); |
| 1088 | const GrReducedClip* reduced = new (storage.get()) GrReducedClip(stack, bounds); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1089 | |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1090 | REPORTER_ASSERT(reporter, reduced->elements().count() == 1); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1091 | // Clips will be cached based on the generation id. Make sure the gen id is valid. |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1092 | REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reduced->elementsGenID()); |
| 1093 | |
| 1094 | reduced->~GrReducedClip(); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1095 | } |
| 1096 | { |
| 1097 | SkClipStack stack; |
| 1098 | |
| 1099 | // Create a clip with following 25.3, 25.3 boxes which are 25 apart: |
| 1100 | // A B |
| 1101 | // C D |
| 1102 | |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 1103 | stack.clipRect(SkRect::MakeXYWH(0, 0, SkScalar(25.3), SkScalar(25.3)), SkMatrix::I(), |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 1104 | kReplace_SkClipOp, true); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1105 | int32_t genIDA = stack.getTopmostGenID(); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 1106 | stack.clipRect(SkRect::MakeXYWH(50, 0, SkScalar(25.3), SkScalar(25.3)), SkMatrix::I(), |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 1107 | kUnion_SkClipOp, true); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1108 | int32_t genIDB = stack.getTopmostGenID(); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 1109 | stack.clipRect(SkRect::MakeXYWH(0, 50, SkScalar(25.3), SkScalar(25.3)), SkMatrix::I(), |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 1110 | kUnion_SkClipOp, true); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1111 | int32_t genIDC = stack.getTopmostGenID(); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 1112 | stack.clipRect(SkRect::MakeXYWH(50, 50, SkScalar(25.3), SkScalar(25.3)), SkMatrix::I(), |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 1113 | kUnion_SkClipOp, true); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1114 | int32_t genIDD = stack.getTopmostGenID(); |
| 1115 | |
| 1116 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1117 | #define IXYWH SkIRect::MakeXYWH |
| 1118 | #define XYWH SkRect::MakeXYWH |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1119 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1120 | SkIRect stackBounds = IXYWH(0, 0, 76, 76); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1121 | |
| 1122 | // The base test is to test each rect in two ways: |
| 1123 | // 1) The box dimensions. (Should reduce to "all in", no elements). |
| 1124 | // 2) A bit over the box dimensions. |
| 1125 | // In the case 2, test that the generation id is what is expected. |
| 1126 | // The rects are of fractional size so that case 2 never gets optimized to an empty element |
| 1127 | // list. |
| 1128 | |
| 1129 | // Not passing in tighter bounds is tested for consistency. |
| 1130 | static const struct SUPPRESS_VISIBILITY_WARNING { |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1131 | SkRect testBounds; |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1132 | int reducedClipCount; |
| 1133 | int32_t reducedGenID; |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1134 | InitialState initialState; |
| 1135 | SkIRect clipIRect; |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1136 | // parameter. |
| 1137 | } testCases[] = { |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1138 | |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1139 | // Rect A. |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1140 | { XYWH(0, 0, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(0, 0, 25, 25) }, |
| 1141 | { XYWH(0.1f, 0.1f, 25.1f, 25.1f), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(0, 0, 26, 26) }, |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1142 | { XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::InitialState::kAllOut, IXYWH(0, 0, 27, 27)}, |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1143 | |
| 1144 | // Rect B. |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1145 | { XYWH(50, 0, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(50, 0, 25, 25) }, |
| 1146 | { XYWH(50, 0, 25.3f, 25.3f), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(50, 0, 26, 26) }, |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1147 | { XYWH(50, 0, 27, 27), 1, genIDB, GrReducedClip::InitialState::kAllOut, IXYWH(50, 0, 26, 27) }, |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1148 | |
| 1149 | // Rect C. |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1150 | { XYWH(0, 50, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(0, 50, 25, 25) }, |
| 1151 | { XYWH(0.2f, 50.1f, 25.1f, 25.2f), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(0, 50, 26, 26) }, |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1152 | { XYWH(0, 50, 27, 27), 1, genIDC, GrReducedClip::InitialState::kAllOut, IXYWH(0, 50, 27, 26) }, |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1153 | |
| 1154 | // Rect D. |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1155 | { XYWH(50, 50, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(50, 50, 25, 25)}, |
| 1156 | { XYWH(50.3f, 50.3f, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(50, 50, 26, 26)}, |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1157 | { XYWH(50, 50, 27, 27), 1, genIDD, GrReducedClip::InitialState::kAllOut, IXYWH(50, 50, 26, 26)}, |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1158 | |
| 1159 | // Other tests: |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1160 | { XYWH(0, 0, 100, 100), 4, genIDD, GrReducedClip::InitialState::kAllOut, stackBounds }, |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1161 | |
| 1162 | // Rect in the middle, touches none. |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1163 | { XYWH(26, 26, 24, 24), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllOut, IXYWH(26, 26, 24, 24) }, |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1164 | |
| 1165 | // Rect in the middle, touches all the rects. GenID is the last rect. |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1166 | { XYWH(24, 24, 27, 27), 4, genIDD, GrReducedClip::InitialState::kAllOut, IXYWH(24, 24, 27, 27) }, |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1167 | }; |
| 1168 | |
| 1169 | #undef XYWH |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1170 | #undef IXYWH |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1171 | |
| 1172 | for (size_t i = 0; i < SK_ARRAY_COUNT(testCases); ++i) { |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1173 | const GrReducedClip reduced(stack, testCases[i].testBounds); |
| 1174 | REPORTER_ASSERT(reporter, reduced.elements().count() == testCases[i].reducedClipCount); |
| 1175 | SkASSERT(reduced.elements().count() == testCases[i].reducedClipCount); |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1176 | if (reduced.elements().count()) { |
| 1177 | REPORTER_ASSERT(reporter, reduced.elementsGenID() == testCases[i].reducedGenID); |
| 1178 | SkASSERT(reduced.elementsGenID() == testCases[i].reducedGenID); |
| 1179 | } |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1180 | REPORTER_ASSERT(reporter, reduced.initialState() == testCases[i].initialState); |
| 1181 | SkASSERT(reduced.initialState() == testCases[i].initialState); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 1182 | REPORTER_ASSERT(reporter, reduced.hasIBounds()); |
| 1183 | SkASSERT(reduced.hasIBounds()); |
| 1184 | REPORTER_ASSERT(reporter, reduced.ibounds() == testCases[i].clipIRect); |
| 1185 | SkASSERT(reduced.ibounds() == testCases[i].clipIRect); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1186 | } |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | static void test_reduced_clip_stack_no_aa_crash(skiatest::Reporter* reporter) { |
| 1191 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 1192 | stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 100, 100), kReplace_SkClipOp); |
| 1193 | stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 50, 50), kReplace_SkClipOp); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1194 | SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1195 | |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1196 | // At the time, this would crash. |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1197 | const GrReducedClip reduced(stack, bounds); |
| 1198 | REPORTER_ASSERT(reporter, reduced.elements().isEmpty()); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1201 | enum class ClipMethod { |
| 1202 | kSkipDraw, |
| 1203 | kIgnoreClip, |
| 1204 | kScissor, |
| 1205 | kAAElements |
| 1206 | }; |
| 1207 | |
| 1208 | static void test_aa_query(skiatest::Reporter* reporter, const SkString& testName, |
| 1209 | const SkClipStack& stack, const SkMatrix& queryXform, |
| 1210 | const SkRect& preXformQuery, ClipMethod expectedMethod, |
| 1211 | int numExpectedElems = 0) { |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1212 | SkRect queryBounds; |
| 1213 | queryXform.mapRect(&queryBounds, preXformQuery); |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1214 | const GrReducedClip reduced(stack, queryBounds); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1215 | |
| 1216 | SkClipStack::BoundsType stackBoundsType; |
| 1217 | SkRect stackBounds; |
| 1218 | stack.getBounds(&stackBounds, &stackBoundsType); |
| 1219 | |
| 1220 | switch (expectedMethod) { |
| 1221 | case ClipMethod::kSkipDraw: |
| 1222 | SkASSERT(0 == numExpectedElems); |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1223 | REPORTER_ASSERT_MESSAGE(reporter, reduced.elements().isEmpty(), testName.c_str()); |
| 1224 | REPORTER_ASSERT_MESSAGE(reporter, |
| 1225 | GrReducedClip::InitialState::kAllOut == reduced.initialState(), |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1226 | testName.c_str()); |
| 1227 | return; |
| 1228 | case ClipMethod::kIgnoreClip: |
| 1229 | SkASSERT(0 == numExpectedElems); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 1230 | REPORTER_ASSERT_MESSAGE(reporter, |
| 1231 | !reduced.hasIBounds() || |
| 1232 | GrClip::IsInsideClip(reduced.ibounds(), queryBounds), |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1233 | testName.c_str()); |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1234 | REPORTER_ASSERT_MESSAGE(reporter, reduced.elements().isEmpty(), testName.c_str()); |
| 1235 | REPORTER_ASSERT_MESSAGE(reporter, |
| 1236 | GrReducedClip::InitialState::kAllIn == reduced.initialState(), |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1237 | testName.c_str()); |
| 1238 | return; |
| 1239 | case ClipMethod::kScissor: { |
| 1240 | SkASSERT(SkClipStack::kNormal_BoundsType == stackBoundsType); |
| 1241 | SkASSERT(0 == numExpectedElems); |
| 1242 | SkIRect expectedScissor; |
| 1243 | stackBounds.round(&expectedScissor); |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1244 | REPORTER_ASSERT_MESSAGE(reporter, reduced.elements().isEmpty(), testName.c_str()); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 1245 | REPORTER_ASSERT_MESSAGE(reporter, reduced.hasIBounds(), testName.c_str()); |
| 1246 | REPORTER_ASSERT_MESSAGE(reporter, expectedScissor == reduced.ibounds(), |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1247 | testName.c_str()); |
| 1248 | REPORTER_ASSERT_MESSAGE(reporter, |
| 1249 | GrReducedClip::InitialState::kAllIn == reduced.initialState(), |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1250 | testName.c_str()); |
| 1251 | return; |
| 1252 | } |
| 1253 | case ClipMethod::kAAElements: { |
| 1254 | SkIRect expectedClipIBounds = GrClip::GetPixelIBounds(queryBounds); |
| 1255 | if (SkClipStack::kNormal_BoundsType == stackBoundsType) { |
| 1256 | SkAssertResult(expectedClipIBounds.intersect(GrClip::GetPixelIBounds(stackBounds))); |
| 1257 | } |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1258 | REPORTER_ASSERT_MESSAGE(reporter, numExpectedElems == reduced.elements().count(), |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1259 | testName.c_str()); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 1260 | REPORTER_ASSERT_MESSAGE(reporter, reduced.hasIBounds(), testName.c_str()); |
| 1261 | REPORTER_ASSERT_MESSAGE(reporter, expectedClipIBounds == reduced.ibounds(), |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1262 | testName.c_str()); |
| 1263 | REPORTER_ASSERT_MESSAGE(reporter, reduced.requiresAA() == !reduced.elements().isEmpty(), |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1264 | testName.c_str()); |
| 1265 | break; |
| 1266 | } |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | static void test_reduced_clip_stack_aa(skiatest::Reporter* reporter) { |
| 1271 | constexpr SkScalar IL = 2, IT = 1, IR = 6, IB = 7; // Pixel aligned rect. |
| 1272 | constexpr SkScalar L = 2.2f, T = 1.7f, R = 5.8f, B = 7.3f; // Generic rect. |
| 1273 | constexpr SkScalar l = 3.3f, t = 2.8f, r = 4.7f, b = 6.2f; // Small rect contained in R. |
| 1274 | |
| 1275 | SkRect alignedRect = {IL, IT, IR, IB}; |
| 1276 | SkRect rect = {L, T, R, B}; |
| 1277 | SkRect innerRect = {l, t, r, b}; |
| 1278 | |
| 1279 | SkMatrix m; |
| 1280 | m.setIdentity(); |
| 1281 | |
| 1282 | constexpr SkScalar kMinScale = 2.0001f; |
| 1283 | constexpr SkScalar kMaxScale = 3; |
| 1284 | constexpr int kNumIters = 8; |
| 1285 | |
| 1286 | SkString name; |
| 1287 | SkRandom rand; |
| 1288 | |
| 1289 | for (int i = 0; i < kNumIters; ++i) { |
| 1290 | // Pixel-aligned rect (iior=true). |
| 1291 | name.printf("Pixel-aligned rect test, iter %i", i); |
| 1292 | SkClipStack stack; |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 1293 | stack.clipRect(alignedRect, SkMatrix::I(), kIntersect_SkClipOp, true); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1294 | test_aa_query(reporter, name, stack, m, {IL, IT, IR, IB}, ClipMethod::kIgnoreClip); |
| 1295 | test_aa_query(reporter, name, stack, m, {IL, IT-1, IR, IT}, ClipMethod::kSkipDraw); |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1296 | test_aa_query(reporter, name, stack, m, {IL, IT-2, IR, IB}, ClipMethod::kScissor); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1297 | |
| 1298 | // Rect (iior=true). |
| 1299 | name.printf("Rect test, iter %i", i); |
| 1300 | stack.reset(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 1301 | stack.clipRect(rect, SkMatrix::I(), kIntersect_SkClipOp, true); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1302 | test_aa_query(reporter, name, stack, m, {L, T, R, B}, ClipMethod::kIgnoreClip); |
| 1303 | test_aa_query(reporter, name, stack, m, {L-.1f, T, L, B}, ClipMethod::kSkipDraw); |
| 1304 | test_aa_query(reporter, name, stack, m, {L-.1f, T, L+.1f, B}, ClipMethod::kAAElements, 1); |
| 1305 | |
| 1306 | // Difference rect (iior=false, inside-out bounds). |
| 1307 | name.printf("Difference rect test, iter %i", i); |
| 1308 | stack.reset(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 1309 | stack.clipRect(rect, SkMatrix::I(), kDifference_SkClipOp, true); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1310 | test_aa_query(reporter, name, stack, m, {L, T, R, B}, ClipMethod::kSkipDraw); |
| 1311 | test_aa_query(reporter, name, stack, m, {L, T-.1f, R, T}, ClipMethod::kIgnoreClip); |
| 1312 | test_aa_query(reporter, name, stack, m, {L, T-.1f, R, T+.1f}, ClipMethod::kAAElements, 1); |
| 1313 | |
| 1314 | // Complex clip (iior=false, normal bounds). |
| 1315 | name.printf("Complex clip test, iter %i", i); |
| 1316 | stack.reset(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 1317 | stack.clipRect(rect, SkMatrix::I(), kIntersect_SkClipOp, true); |
| 1318 | stack.clipRect(innerRect, SkMatrix::I(), kXOR_SkClipOp, true); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1319 | test_aa_query(reporter, name, stack, m, {l, t, r, b}, ClipMethod::kSkipDraw); |
| 1320 | test_aa_query(reporter, name, stack, m, {r-.1f, t, R, b}, ClipMethod::kAAElements, 1); |
| 1321 | test_aa_query(reporter, name, stack, m, {r-.1f, t, R+.1f, b}, ClipMethod::kAAElements, 2); |
| 1322 | test_aa_query(reporter, name, stack, m, {r, t, R+.1f, b}, ClipMethod::kAAElements, 1); |
| 1323 | test_aa_query(reporter, name, stack, m, {r, t, R, b}, ClipMethod::kIgnoreClip); |
| 1324 | test_aa_query(reporter, name, stack, m, {R, T, R+.1f, B}, ClipMethod::kSkipDraw); |
| 1325 | |
| 1326 | // Complex clip where outer rect is pixel aligned (iior=false, normal bounds). |
| 1327 | name.printf("Aligned Complex clip test, iter %i", i); |
| 1328 | stack.reset(); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 1329 | stack.clipRect(alignedRect, SkMatrix::I(), kIntersect_SkClipOp, true); |
| 1330 | stack.clipRect(innerRect, SkMatrix::I(), kXOR_SkClipOp, true); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1331 | test_aa_query(reporter, name, stack, m, {l, t, r, b}, ClipMethod::kSkipDraw); |
| 1332 | test_aa_query(reporter, name, stack, m, {l, b-.1f, r, IB}, ClipMethod::kAAElements, 1); |
| 1333 | test_aa_query(reporter, name, stack, m, {l, b-.1f, r, IB+.1f}, ClipMethod::kAAElements, 1); |
| 1334 | test_aa_query(reporter, name, stack, m, {l, b, r, IB+.1f}, ClipMethod::kAAElements, 0); |
| 1335 | test_aa_query(reporter, name, stack, m, {l, b, r, IB}, ClipMethod::kIgnoreClip); |
| 1336 | test_aa_query(reporter, name, stack, m, {IL, IB, IR, IB+.1f}, ClipMethod::kSkipDraw); |
| 1337 | |
| 1338 | // Apply random transforms and try again. This ensures the clip stack reduction is hardened |
| 1339 | // against FP rounding error. |
| 1340 | SkScalar sx = rand.nextRangeScalar(kMinScale, kMaxScale); |
| 1341 | sx = SkScalarFloorToScalar(sx * alignedRect.width()) / alignedRect.width(); |
| 1342 | SkScalar sy = rand.nextRangeScalar(kMinScale, kMaxScale); |
| 1343 | sy = SkScalarFloorToScalar(sy * alignedRect.height()) / alignedRect.height(); |
| 1344 | SkScalar tx = SkScalarRoundToScalar(sx * alignedRect.x()) - sx * alignedRect.x(); |
| 1345 | SkScalar ty = SkScalarRoundToScalar(sy * alignedRect.y()) - sy * alignedRect.y(); |
| 1346 | |
| 1347 | SkMatrix xform = SkMatrix::MakeScale(sx, sy); |
| 1348 | xform.postTranslate(tx, ty); |
| 1349 | xform.mapRect(&alignedRect); |
| 1350 | xform.mapRect(&rect); |
| 1351 | xform.mapRect(&innerRect); |
| 1352 | m.postConcat(xform); |
| 1353 | } |
| 1354 | } |
| 1355 | |
bsalomon@google.com | a4e13c8 | 2012-11-26 21:38:37 +0000 | [diff] [blame] | 1356 | #endif |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1357 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 1358 | DEF_TEST(ClipStack, reporter) { |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 1359 | SkClipStack stack; |
| 1360 | |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 1361 | REPORTER_ASSERT(reporter, 0 == stack.getSaveCount()); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 1362 | assert_count(reporter, stack, 0); |
| 1363 | |
| 1364 | static const SkIRect gRects[] = { |
| 1365 | { 0, 0, 100, 100 }, |
| 1366 | { 25, 25, 125, 125 }, |
| 1367 | { 0, 0, 1000, 1000 }, |
| 1368 | { 0, 0, 75, 75 } |
| 1369 | }; |
| 1370 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRects); i++) { |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 1371 | stack.clipDevRect(gRects[i], kIntersect_SkClipOp); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | // 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] | 1375 | SkClipStack::B2TIter iter(stack); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 1376 | const SkClipStack::Element* element = iter.next(); |
epoger@google.com | 2047f00 | 2011-05-17 17:36:59 +0000 | [diff] [blame] | 1377 | SkRect answer; |
| 1378 | answer.iset(25, 25, 75, 75); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 1379 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1380 | REPORTER_ASSERT(reporter, element); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 1381 | REPORTER_ASSERT(reporter, SkClipStack::Element::kRect_Type == element->getType()); |
Mike Reed | 8e7432b | 2016-12-08 16:06:37 -0500 | [diff] [blame] | 1382 | REPORTER_ASSERT(reporter, kIntersect_SkClipOp == element->getOp()); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 1383 | REPORTER_ASSERT(reporter, element->getRect() == answer); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 1384 | // now check that we only had one in our iterator |
| 1385 | REPORTER_ASSERT(reporter, !iter.next()); |
| 1386 | |
| 1387 | stack.reset(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 1388 | REPORTER_ASSERT(reporter, 0 == stack.getSaveCount()); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 1389 | assert_count(reporter, stack, 0); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 1390 | |
| 1391 | test_assign_and_comparison(reporter); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 1392 | test_iterators(reporter); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 1393 | test_bounds(reporter, SkClipStack::Element::kRect_Type); |
| 1394 | test_bounds(reporter, SkClipStack::Element::kRRect_Type); |
| 1395 | test_bounds(reporter, SkClipStack::Element::kPath_Type); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 1396 | test_isWideOpen(reporter); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 1397 | test_rect_merging(reporter); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 1398 | test_rect_replace(reporter); |
junov@chromium.org | edf32d5 | 2012-12-10 14:57:54 +0000 | [diff] [blame] | 1399 | test_rect_inverse_fill(reporter); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 1400 | test_path_replace(reporter); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 1401 | test_quickContains(reporter); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 1402 | test_invfill_diff_bug(reporter); |
bsalomon@google.com | e7b3d29 | 2012-11-26 21:42:32 +0000 | [diff] [blame] | 1403 | #if SK_SUPPORT_GPU |
bsalomon@google.com | edb26fd | 2012-11-28 14:42:41 +0000 | [diff] [blame] | 1404 | test_reduced_clip_stack(reporter); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1405 | test_reduced_clip_stack_genid(reporter); |
| 1406 | test_reduced_clip_stack_no_aa_crash(reporter); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1407 | test_reduced_clip_stack_aa(reporter); |
bsalomon@google.com | e7b3d29 | 2012-11-26 21:42:32 +0000 | [diff] [blame] | 1408 | #endif |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 1409 | } |