epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 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" |
| 11 | #include "SkRect.h" |
| 12 | |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 13 | |
| 14 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 15 | static void test_assign_and_comparison(skiatest::Reporter* reporter) { |
| 16 | SkClipStack s; |
reed@google.com | d9f2dea | 2011-10-12 14:43:27 +0000 | [diff] [blame] | 17 | bool doAA = false; |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 18 | |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 19 | REPORTER_ASSERT(reporter, 0 == s.getSaveCount()); |
| 20 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 21 | // Build up a clip stack with a path, an empty clip, and a rect. |
| 22 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 23 | REPORTER_ASSERT(reporter, 1 == s.getSaveCount()); |
| 24 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 25 | SkPath p; |
| 26 | p.moveTo(5, 6); |
| 27 | p.lineTo(7, 8); |
| 28 | p.lineTo(5, 9); |
| 29 | p.close(); |
reed@google.com | d9f2dea | 2011-10-12 14:43:27 +0000 | [diff] [blame] | 30 | s.clipDevPath(p, SkRegion::kIntersect_Op, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 31 | |
| 32 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 33 | REPORTER_ASSERT(reporter, 2 == s.getSaveCount()); |
| 34 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 35 | SkRect r = SkRect::MakeLTRB(1, 2, 3, 4); |
reed@google.com | d9f2dea | 2011-10-12 14:43:27 +0000 | [diff] [blame] | 36 | s.clipDevRect(r, SkRegion::kIntersect_Op, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 37 | r = SkRect::MakeLTRB(10, 11, 12, 13); |
reed@google.com | d9f2dea | 2011-10-12 14:43:27 +0000 | [diff] [blame] | 38 | s.clipDevRect(r, SkRegion::kIntersect_Op, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 39 | |
| 40 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 41 | REPORTER_ASSERT(reporter, 3 == s.getSaveCount()); |
| 42 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 43 | r = SkRect::MakeLTRB(14, 15, 16, 17); |
reed@google.com | d9f2dea | 2011-10-12 14:43:27 +0000 | [diff] [blame] | 44 | s.clipDevRect(r, SkRegion::kUnion_Op, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 45 | |
| 46 | // Test that assignment works. |
| 47 | SkClipStack copy = s; |
| 48 | REPORTER_ASSERT(reporter, s == copy); |
| 49 | |
| 50 | // Test that different save levels triggers not equal. |
| 51 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 52 | REPORTER_ASSERT(reporter, 2 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 53 | REPORTER_ASSERT(reporter, s != copy); |
| 54 | |
| 55 | // Test that an equal, but not copied version is equal. |
| 56 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 57 | REPORTER_ASSERT(reporter, 3 == s.getSaveCount()); |
| 58 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 59 | r = SkRect::MakeLTRB(14, 15, 16, 17); |
reed@google.com | d9f2dea | 2011-10-12 14:43:27 +0000 | [diff] [blame] | 60 | s.clipDevRect(r, SkRegion::kUnion_Op, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 61 | REPORTER_ASSERT(reporter, s == copy); |
| 62 | |
| 63 | // Test that a different op on one level triggers not equal. |
| 64 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 65 | REPORTER_ASSERT(reporter, 2 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 66 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 67 | REPORTER_ASSERT(reporter, 3 == s.getSaveCount()); |
| 68 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 69 | r = SkRect::MakeLTRB(14, 15, 16, 17); |
reed@google.com | d9f2dea | 2011-10-12 14:43:27 +0000 | [diff] [blame] | 70 | s.clipDevRect(r, SkRegion::kIntersect_Op, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 71 | REPORTER_ASSERT(reporter, s != copy); |
| 72 | |
| 73 | // Test that different state (clip type) triggers not equal. |
tomhudson@google.com | 4c43372 | 2012-03-09 16:48:20 +0000 | [diff] [blame] | 74 | // NO LONGER VALID: if a path contains only a rect, we turn |
| 75 | // it into a bare rect for performance reasons (working |
| 76 | // around Chromium/JavaScript bad pattern). |
| 77 | /* |
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); |
reed@google.com | d9f2dea | 2011-10-12 14:43:27 +0000 | [diff] [blame] | 82 | s.clipDevPath(rp, SkRegion::kUnion_Op, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 83 | REPORTER_ASSERT(reporter, s != copy); |
tomhudson@google.com | 4c43372 | 2012-03-09 16:48:20 +0000 | [diff] [blame] | 84 | */ |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 85 | |
| 86 | // Test that different rects triggers not equal. |
| 87 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 88 | REPORTER_ASSERT(reporter, 2 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 89 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 90 | REPORTER_ASSERT(reporter, 3 == s.getSaveCount()); |
| 91 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 92 | r = SkRect::MakeLTRB(24, 25, 26, 27); |
reed@google.com | d9f2dea | 2011-10-12 14:43:27 +0000 | [diff] [blame] | 93 | s.clipDevRect(r, SkRegion::kUnion_Op, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 94 | REPORTER_ASSERT(reporter, s != copy); |
| 95 | |
| 96 | // Sanity check |
| 97 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 98 | REPORTER_ASSERT(reporter, 2 == s.getSaveCount()); |
| 99 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 100 | copy.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 101 | REPORTER_ASSERT(reporter, 2 == copy.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 102 | REPORTER_ASSERT(reporter, s == copy); |
| 103 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 104 | REPORTER_ASSERT(reporter, 1 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 105 | copy.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 106 | REPORTER_ASSERT(reporter, 1 == copy.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 107 | REPORTER_ASSERT(reporter, s == copy); |
| 108 | |
| 109 | // Test that different paths triggers not equal. |
| 110 | s.restore(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 111 | REPORTER_ASSERT(reporter, 0 == s.getSaveCount()); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 112 | s.save(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 113 | REPORTER_ASSERT(reporter, 1 == s.getSaveCount()); |
| 114 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 115 | p.addRect(r); |
reed@google.com | d9f2dea | 2011-10-12 14:43:27 +0000 | [diff] [blame] | 116 | s.clipDevPath(p, SkRegion::kIntersect_Op, doAA); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 117 | REPORTER_ASSERT(reporter, s != copy); |
| 118 | } |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 119 | |
| 120 | static void assert_count(skiatest::Reporter* reporter, const SkClipStack& stack, |
| 121 | int count) { |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 122 | SkClipStack::B2TIter iter(stack); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 123 | int counter = 0; |
| 124 | while (iter.next()) { |
| 125 | counter += 1; |
| 126 | } |
| 127 | REPORTER_ASSERT(reporter, count == counter); |
| 128 | } |
| 129 | |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 130 | static void test_iterators(skiatest::Reporter* reporter) { |
| 131 | SkClipStack stack; |
| 132 | |
| 133 | static const SkRect gRects[] = { |
| 134 | { 0, 0, 40, 40 }, |
| 135 | { 60, 0, 100, 40 }, |
| 136 | { 0, 60, 40, 100 }, |
| 137 | { 60, 60, 100, 100 } |
| 138 | }; |
| 139 | |
| 140 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRects); i++) { |
| 141 | // the union op will prevent these from being fused together |
| 142 | stack.clipDevRect(gRects[i], SkRegion::kUnion_Op, false); |
| 143 | } |
| 144 | |
| 145 | assert_count(reporter, stack, 4); |
| 146 | |
| 147 | // bottom to top iteration |
| 148 | { |
| 149 | const SkClipStack::B2TIter::Clip* clip = NULL; |
| 150 | |
| 151 | SkClipStack::B2TIter iter(stack); |
| 152 | int i; |
| 153 | |
| 154 | for (i = 0, clip = iter.next(); clip; ++i, clip = iter.next()) { |
| 155 | REPORTER_ASSERT(reporter, *clip->fRect == gRects[i]); |
| 156 | } |
| 157 | |
| 158 | SkASSERT(i == 4); |
| 159 | } |
| 160 | |
| 161 | // top to bottom iteration |
| 162 | { |
| 163 | const SkClipStack::Iter::Clip* clip = NULL; |
| 164 | |
| 165 | SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart); |
| 166 | int i; |
| 167 | |
| 168 | for (i = 3, clip = iter.prev(); clip; --i, clip = iter.prev()) { |
| 169 | REPORTER_ASSERT(reporter, *clip->fRect == gRects[i]); |
| 170 | } |
| 171 | |
| 172 | SkASSERT(i == -1); |
| 173 | } |
| 174 | |
| 175 | // skipToTopmost |
| 176 | { |
| 177 | const SkClipStack::Iter::Clip*clip = NULL; |
| 178 | |
| 179 | SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart); |
| 180 | |
| 181 | clip = iter.skipToTopmost(SkRegion::kUnion_Op); |
| 182 | REPORTER_ASSERT(reporter, *clip->fRect == gRects[3]); |
| 183 | } |
| 184 | } |
| 185 | |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 186 | static void test_bounds(skiatest::Reporter* reporter, bool useRects) { |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 187 | |
| 188 | static const int gNumCases = 20; |
| 189 | static const SkRect gAnswerRectsBW[gNumCases] = { |
| 190 | // A op B |
| 191 | { 40, 40, 50, 50 }, |
| 192 | { 10, 10, 50, 50 }, |
| 193 | { 10, 10, 80, 80 }, |
| 194 | { 10, 10, 80, 80 }, |
| 195 | { 40, 40, 80, 80 }, |
| 196 | |
| 197 | // invA op B |
| 198 | { 40, 40, 80, 80 }, |
| 199 | { 0, 0, 100, 100 }, |
| 200 | { 0, 0, 100, 100 }, |
| 201 | { 0, 0, 100, 100 }, |
| 202 | { 40, 40, 50, 50 }, |
| 203 | |
| 204 | // A op invB |
| 205 | { 10, 10, 50, 50 }, |
| 206 | { 40, 40, 50, 50 }, |
| 207 | { 0, 0, 100, 100 }, |
| 208 | { 0, 0, 100, 100 }, |
| 209 | { 0, 0, 100, 100 }, |
| 210 | |
| 211 | // invA op invB |
| 212 | { 0, 0, 100, 100 }, |
| 213 | { 40, 40, 80, 80 }, |
| 214 | { 0, 0, 100, 100 }, |
| 215 | { 10, 10, 80, 80 }, |
| 216 | { 10, 10, 50, 50 }, |
| 217 | }; |
| 218 | |
| 219 | static const SkRegion::Op gOps[] = { |
| 220 | SkRegion::kIntersect_Op, |
| 221 | SkRegion::kDifference_Op, |
| 222 | SkRegion::kUnion_Op, |
| 223 | SkRegion::kXOR_Op, |
| 224 | SkRegion::kReverseDifference_Op |
| 225 | }; |
| 226 | |
| 227 | SkRect rectA, rectB; |
| 228 | |
| 229 | rectA.iset(10, 10, 50, 50); |
| 230 | rectB.iset(40, 40, 80, 80); |
| 231 | |
| 232 | SkPath clipA, clipB; |
| 233 | |
| 234 | clipA.addRoundRect(rectA, SkIntToScalar(5), SkIntToScalar(5)); |
| 235 | clipB.addRoundRect(rectB, SkIntToScalar(5), SkIntToScalar(5)); |
| 236 | |
| 237 | SkClipStack stack; |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame^] | 238 | SkRect devClipBound; |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 239 | bool isIntersectionOfRects = false; |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 240 | |
| 241 | int testCase = 0; |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 242 | int numBitTests = useRects ? 1 : 4; |
| 243 | for (int invBits = 0; invBits < numBitTests; ++invBits) { |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 244 | for (size_t op = 0; op < SK_ARRAY_COUNT(gOps); ++op) { |
| 245 | |
| 246 | stack.save(); |
| 247 | bool doInvA = SkToBool(invBits & 1); |
| 248 | bool doInvB = SkToBool(invBits & 2); |
| 249 | |
| 250 | clipA.setFillType(doInvA ? SkPath::kInverseEvenOdd_FillType : |
| 251 | SkPath::kEvenOdd_FillType); |
| 252 | clipB.setFillType(doInvB ? SkPath::kInverseEvenOdd_FillType : |
| 253 | SkPath::kEvenOdd_FillType); |
| 254 | |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 255 | if (useRects) { |
| 256 | stack.clipDevRect(rectA, SkRegion::kIntersect_Op, false); |
| 257 | stack.clipDevRect(rectB, gOps[op], false); |
| 258 | } else { |
| 259 | stack.clipDevPath(clipA, SkRegion::kIntersect_Op, false); |
| 260 | stack.clipDevPath(clipB, gOps[op], false); |
| 261 | } |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 262 | |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 263 | REPORTER_ASSERT(reporter, !stack.isWideOpen()); |
| 264 | |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame^] | 265 | stack.getConservativeBounds(0, 0, 100, 100, &devClipBound, |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 266 | &isIntersectionOfRects); |
| 267 | |
| 268 | if (useRects) { |
| 269 | REPORTER_ASSERT(reporter, isIntersectionOfRects == |
| 270 | (gOps[op] == SkRegion::kIntersect_Op)); |
| 271 | } else { |
| 272 | REPORTER_ASSERT(reporter, !isIntersectionOfRects); |
| 273 | } |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 274 | |
| 275 | SkASSERT(testCase < gNumCases); |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame^] | 276 | REPORTER_ASSERT(reporter, devClipBound == gAnswerRectsBW[testCase]); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 277 | ++testCase; |
| 278 | |
| 279 | stack.restore(); |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 284 | // Test out 'isWideOpen' entry point |
| 285 | static void test_isWideOpen(skiatest::Reporter* reporter) { |
| 286 | |
| 287 | SkRect rectA, rectB; |
| 288 | |
| 289 | rectA.iset(10, 10, 40, 40); |
| 290 | rectB.iset(50, 50, 80, 80); |
| 291 | |
| 292 | // Stack should initially be wide open |
| 293 | { |
| 294 | SkClipStack stack; |
| 295 | |
| 296 | REPORTER_ASSERT(reporter, stack.isWideOpen()); |
| 297 | } |
| 298 | |
| 299 | // Test out case where the user specifies a union that includes everything |
| 300 | { |
| 301 | SkClipStack stack; |
| 302 | |
| 303 | SkPath clipA, clipB; |
| 304 | |
| 305 | clipA.addRoundRect(rectA, SkIntToScalar(5), SkIntToScalar(5)); |
| 306 | clipA.setFillType(SkPath::kInverseEvenOdd_FillType); |
| 307 | |
| 308 | clipB.addRoundRect(rectB, SkIntToScalar(5), SkIntToScalar(5)); |
| 309 | clipB.setFillType(SkPath::kInverseEvenOdd_FillType); |
| 310 | |
| 311 | stack.clipDevPath(clipA, SkRegion::kReplace_Op, false); |
| 312 | stack.clipDevPath(clipB, SkRegion::kUnion_Op, false); |
| 313 | |
| 314 | REPORTER_ASSERT(reporter, stack.isWideOpen()); |
| 315 | } |
| 316 | |
| 317 | // Test out union w/ a wide open clip |
| 318 | { |
| 319 | SkClipStack stack; |
| 320 | |
| 321 | stack.clipDevRect(rectA, SkRegion::kUnion_Op, false); |
| 322 | |
| 323 | REPORTER_ASSERT(reporter, stack.isWideOpen()); |
| 324 | } |
| 325 | |
| 326 | // Test out empty difference from a wide open clip |
| 327 | { |
| 328 | SkClipStack stack; |
| 329 | |
| 330 | SkRect emptyRect; |
| 331 | emptyRect.setEmpty(); |
| 332 | |
| 333 | stack.clipDevRect(emptyRect, SkRegion::kDifference_Op, false); |
| 334 | |
| 335 | REPORTER_ASSERT(reporter, stack.isWideOpen()); |
| 336 | } |
| 337 | |
| 338 | // Test out return to wide open |
| 339 | { |
| 340 | SkClipStack stack; |
| 341 | |
| 342 | stack.save(); |
| 343 | |
| 344 | stack.clipDevRect(rectA, SkRegion::kReplace_Op, false); |
| 345 | |
| 346 | REPORTER_ASSERT(reporter, !stack.isWideOpen()); |
| 347 | |
| 348 | stack.restore(); |
| 349 | |
| 350 | REPORTER_ASSERT(reporter, stack.isWideOpen()); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 355 | static void TestClipStack(skiatest::Reporter* reporter) { |
| 356 | SkClipStack stack; |
| 357 | |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 358 | REPORTER_ASSERT(reporter, 0 == stack.getSaveCount()); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 359 | assert_count(reporter, stack, 0); |
| 360 | |
| 361 | static const SkIRect gRects[] = { |
| 362 | { 0, 0, 100, 100 }, |
| 363 | { 25, 25, 125, 125 }, |
| 364 | { 0, 0, 1000, 1000 }, |
| 365 | { 0, 0, 75, 75 } |
| 366 | }; |
| 367 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRects); i++) { |
reed@google.com | d9f2dea | 2011-10-12 14:43:27 +0000 | [diff] [blame] | 368 | stack.clipDevRect(gRects[i], SkRegion::kIntersect_Op); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | // 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] | 372 | SkClipStack::B2TIter iter(stack); |
| 373 | const SkClipStack::B2TIter::Clip* clip = iter.next(); |
epoger@google.com | 2047f00 | 2011-05-17 17:36:59 +0000 | [diff] [blame] | 374 | SkRect answer; |
| 375 | answer.iset(25, 25, 75, 75); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 376 | |
| 377 | REPORTER_ASSERT(reporter, clip); |
| 378 | REPORTER_ASSERT(reporter, clip->fRect); |
| 379 | REPORTER_ASSERT(reporter, !clip->fPath); |
| 380 | REPORTER_ASSERT(reporter, SkRegion::kIntersect_Op == clip->fOp); |
| 381 | REPORTER_ASSERT(reporter, *clip->fRect == answer); |
| 382 | // now check that we only had one in our iterator |
| 383 | REPORTER_ASSERT(reporter, !iter.next()); |
| 384 | |
| 385 | stack.reset(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 386 | REPORTER_ASSERT(reporter, 0 == stack.getSaveCount()); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 387 | assert_count(reporter, stack, 0); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 388 | |
| 389 | test_assign_and_comparison(reporter); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 390 | test_iterators(reporter); |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 391 | test_bounds(reporter, true); |
| 392 | test_bounds(reporter, false); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 393 | test_isWideOpen(reporter); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | #include "TestClassDef.h" |
| 397 | DEFINE_TESTCLASS("ClipStack", TestClipStackClass, TestClipStack) |