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