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