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(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 61 | s.clipPath(p, SkMatrix::I(), SkClipOp::kIntersect, 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 | |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame^] | 66 | SkRect r = SkRect::MakeLTRB(1, 2, 103, 104); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 67 | s.clipRect(r, SkMatrix::I(), SkClipOp::kIntersect, doAA); |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame^] | 68 | r = SkRect::MakeLTRB(4, 5, 56, 57); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 69 | s.clipRect(r, SkMatrix::I(), SkClipOp::kIntersect, 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); |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame^] | 75 | s.clipRect(r, SkMatrix::I(), SkClipOp::kDifference, 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); |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame^] | 90 | s.clipRect(r, SkMatrix::I(), SkClipOp::kDifference, 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); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 99 | s.clipRect(r, SkMatrix::I(), SkClipOp::kIntersect, 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); |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame^] | 107 | s.clipPath(rp, SkMatrix::I(), SkClipOp::kDifference, 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); |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame^] | 117 | s.clipRect(r, SkMatrix::I(), SkClipOp::kDifference, 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); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 139 | s.clipPath(p, SkMatrix::I(), SkClipOp::kIntersect, 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++) { |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame^] | 166 | // the difference op will prevent these from being fused together |
| 167 | stack.clipRect(gRects[i], SkMatrix::I(), SkClipOp::kDifference, 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 | |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame^] | 210 | element = iter.skipToTopmost(SkClipOp::kDifference); |
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[] = { |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 252 | SkClipOp::kIntersect, |
| 253 | SkClipOp::kDifference, |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 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: |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 297 | stack.clipRect(rectA, SkMatrix::I(), SkClipOp::kIntersect, 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: |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 301 | stack.clipRRect(rrectA, SkMatrix::I(), SkClipOp::kIntersect, 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: |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 305 | stack.clipPath(pathA, SkMatrix::I(), SkClipOp::kIntersect, 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 == |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 318 | (gOps[op] == SkClipOp::kIntersect)); |
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 | |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 366 | stack.clipPath(clipA, SkMatrix::I(), SkClipOp::kIntersect, false); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 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 | |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 390 | stack.clipRect(emptyRect, SkMatrix::I(), SkClipOp::kDifference, 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 | |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 402 | stack.clipRect(rectA, SkMatrix::I(), SkClipOp::kIntersect, 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; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 435 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, 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)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 457 | stack.replaceClip(rect, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 458 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 459 | stack.replaceClip(rect, 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)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 468 | stack.replaceClip(rect, true); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 469 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 470 | stack.replaceClip(rect, 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)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 479 | stack.replaceClip(rect, false); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 480 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 481 | stack.replaceClip(rect, true); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 482 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 483 | stack.replaceClip(rect, 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; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 490 | stack.replaceClip(rect, false); |
| 491 | stack.clipRect(rect2, SkMatrix::I(), SkClipOp::kIntersect, 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(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 495 | stack.replaceClip(rect, 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(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 503 | stack.replaceClip(rect, false); |
| 504 | stack.replaceClip(rect, 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(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 510 | stack.replaceClip(rect, false); |
| 511 | stack.clipRect(rect2, SkMatrix::I(), SkClipOp::kIntersect, false); |
| 512 | stack.replaceClip(rect, 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) { |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 521 | auto replacePath = [](SkClipStack* stack, const SkPath& path, bool doAA) { |
| 522 | const SkRect wideOpen = SkRect::MakeLTRB(-1000, -1000, 1000, 1000); |
| 523 | stack->replaceClip(wideOpen, false); |
| 524 | stack->clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, doAA); |
| 525 | }; |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 526 | SkRect rect = SkRect::MakeWH(100, 100); |
| 527 | SkPath path; |
| 528 | path.addCircle(50, 50, 50); |
| 529 | |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 530 | // Emulating replace operations with more complex geometry is not atomic, it's a replace |
| 531 | // with a wide-open rect and then an intersection with the complex geometry. The replace can |
| 532 | // combine with prior elements, but the subsequent intersect cannot be combined so the stack |
| 533 | // continues to grow. |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 534 | { |
| 535 | SkClipStack stack; |
| 536 | REPORTER_ASSERT(reporter, 0 == count(stack)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 537 | replacePath(&stack, path, false); |
| 538 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 539 | replacePath(&stack, path, false); |
| 540 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | // Replacing rect with path. |
| 544 | { |
| 545 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 546 | stack.replaceClip(rect, true); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 547 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 548 | replacePath(&stack, path, true); |
| 549 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 553 | // Test out SkClipStack's merging of rect clips. In particular exercise |
| 554 | // merging of aa vs. bw rects. |
| 555 | static void test_rect_merging(skiatest::Reporter* reporter) { |
| 556 | |
| 557 | SkRect overlapLeft = SkRect::MakeLTRB(10, 10, 50, 50); |
| 558 | SkRect overlapRight = SkRect::MakeLTRB(40, 40, 80, 80); |
| 559 | |
| 560 | SkRect nestedParent = SkRect::MakeLTRB(10, 10, 90, 90); |
| 561 | SkRect nestedChild = SkRect::MakeLTRB(40, 40, 60, 60); |
| 562 | |
| 563 | SkRect bound; |
| 564 | SkClipStack::BoundsType type; |
| 565 | bool isIntersectionOfRects; |
| 566 | |
| 567 | // all bw overlapping - should merge |
| 568 | { |
| 569 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 570 | stack.clipRect(overlapLeft, SkMatrix::I(), SkClipOp::kIntersect, false); |
| 571 | stack.clipRect(overlapRight, SkMatrix::I(), SkClipOp::kIntersect, false); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 572 | |
| 573 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 574 | |
| 575 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 576 | |
| 577 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 578 | } |
| 579 | |
| 580 | // all aa overlapping - should merge |
| 581 | { |
| 582 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 583 | stack.clipRect(overlapLeft, SkMatrix::I(), SkClipOp::kIntersect, true); |
| 584 | stack.clipRect(overlapRight, SkMatrix::I(), SkClipOp::kIntersect, true); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 585 | |
| 586 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 587 | |
| 588 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 589 | |
| 590 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 591 | } |
| 592 | |
| 593 | // mixed overlapping - should _not_ merge |
| 594 | { |
| 595 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 596 | stack.clipRect(overlapLeft, SkMatrix::I(), SkClipOp::kIntersect, true); |
| 597 | stack.clipRect(overlapRight, SkMatrix::I(), SkClipOp::kIntersect, false); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 598 | |
| 599 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 600 | |
| 601 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 602 | |
| 603 | REPORTER_ASSERT(reporter, !isIntersectionOfRects); |
| 604 | } |
| 605 | |
| 606 | // mixed nested (bw inside aa) - should merge |
| 607 | { |
| 608 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 609 | stack.clipRect(nestedParent, SkMatrix::I(), SkClipOp::kIntersect, true); |
| 610 | stack.clipRect(nestedChild, SkMatrix::I(), SkClipOp::kIntersect, 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; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 622 | stack.clipRect(nestedParent, SkMatrix::I(), SkClipOp::kIntersect, false); |
| 623 | stack.clipRect(nestedChild, SkMatrix::I(), SkClipOp::kIntersect, true); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 624 | |
| 625 | REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 626 | |
| 627 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 628 | |
| 629 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 630 | } |
| 631 | |
| 632 | // reverse nested (aa inside bw) - should _not_ merge |
| 633 | { |
| 634 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 635 | stack.clipRect(nestedChild, SkMatrix::I(), SkClipOp::kIntersect, false); |
| 636 | stack.clipRect(nestedParent, SkMatrix::I(), SkClipOp::kIntersect, true); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 637 | |
| 638 | REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 639 | |
| 640 | stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 641 | |
| 642 | REPORTER_ASSERT(reporter, !isIntersectionOfRects); |
| 643 | } |
| 644 | } |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 645 | |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 646 | static void test_quickContains(skiatest::Reporter* reporter) { |
| 647 | SkRect testRect = SkRect::MakeLTRB(10, 10, 40, 40); |
| 648 | SkRect insideRect = SkRect::MakeLTRB(20, 20, 30, 30); |
| 649 | SkRect intersectingRect = SkRect::MakeLTRB(25, 25, 50, 50); |
| 650 | SkRect outsideRect = SkRect::MakeLTRB(0, 0, 50, 50); |
| 651 | SkRect nonIntersectingRect = SkRect::MakeLTRB(100, 100, 110, 110); |
| 652 | |
| 653 | SkPath insideCircle; |
| 654 | insideCircle.addCircle(25, 25, 5); |
| 655 | SkPath intersectingCircle; |
| 656 | intersectingCircle.addCircle(25, 40, 10); |
| 657 | SkPath outsideCircle; |
| 658 | outsideCircle.addCircle(25, 25, 50); |
| 659 | SkPath nonIntersectingCircle; |
| 660 | nonIntersectingCircle.addCircle(100, 100, 5); |
| 661 | |
| 662 | { |
| 663 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 664 | stack.clipRect(outsideRect, SkMatrix::I(), SkClipOp::kDifference, false); |
| 665 | // return false because quickContains currently does not care for kDifference |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 666 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 667 | } |
skia.committer@gmail.com | 306ab9d | 2012-12-13 02:01:33 +0000 | [diff] [blame] | 668 | |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 669 | // Replace Op tests |
| 670 | { |
| 671 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 672 | stack.replaceClip(outsideRect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 673 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 674 | } |
| 675 | |
| 676 | { |
| 677 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 678 | stack.clipRect(insideRect, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 679 | stack.save(); // To prevent in-place substitution by replace OP |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 680 | stack.replaceClip(outsideRect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 681 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 682 | stack.restore(); |
| 683 | } |
| 684 | |
| 685 | { |
| 686 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 687 | stack.clipRect(outsideRect, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 688 | stack.save(); // To prevent in-place substitution by replace OP |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 689 | stack.replaceClip(insideRect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 690 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 691 | stack.restore(); |
| 692 | } |
| 693 | |
| 694 | // Verify proper traversal of multi-element clip |
| 695 | { |
| 696 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 697 | stack.clipRect(insideRect, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 698 | // Use a path for second clip to prevent in-place intersection |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 699 | stack.clipPath(outsideCircle, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 700 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 701 | } |
| 702 | |
| 703 | // Intersect Op tests with rectangles |
| 704 | { |
| 705 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 706 | stack.clipRect(outsideRect, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 707 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 708 | } |
| 709 | |
| 710 | { |
| 711 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 712 | stack.clipRect(insideRect, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 713 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 714 | } |
| 715 | |
| 716 | { |
| 717 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 718 | stack.clipRect(intersectingRect, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 719 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 720 | } |
| 721 | |
| 722 | { |
| 723 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 724 | stack.clipRect(nonIntersectingRect, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 725 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 726 | } |
| 727 | |
| 728 | // Intersect Op tests with circle paths |
| 729 | { |
| 730 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 731 | stack.clipPath(outsideCircle, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 732 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 733 | } |
| 734 | |
| 735 | { |
| 736 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 737 | stack.clipPath(insideCircle, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 738 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 739 | } |
| 740 | |
| 741 | { |
| 742 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 743 | stack.clipPath(intersectingCircle, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 744 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 745 | } |
| 746 | |
| 747 | { |
| 748 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 749 | stack.clipPath(nonIntersectingCircle, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 750 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 751 | } |
| 752 | |
| 753 | // Intersect Op tests with inverse filled rectangles |
| 754 | { |
| 755 | SkClipStack stack; |
| 756 | SkPath path; |
| 757 | path.addRect(outsideRect); |
| 758 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 759 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 760 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 761 | } |
| 762 | |
| 763 | { |
| 764 | SkClipStack stack; |
| 765 | SkPath path; |
| 766 | path.addRect(insideRect); |
| 767 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 768 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 769 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 770 | } |
| 771 | |
| 772 | { |
| 773 | SkClipStack stack; |
| 774 | SkPath path; |
| 775 | path.addRect(intersectingRect); |
| 776 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 777 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 778 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 779 | } |
| 780 | |
| 781 | { |
| 782 | SkClipStack stack; |
| 783 | SkPath path; |
| 784 | path.addRect(nonIntersectingRect); |
| 785 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 786 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 787 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 788 | } |
| 789 | |
| 790 | // Intersect Op tests with inverse filled circles |
| 791 | { |
| 792 | SkClipStack stack; |
| 793 | SkPath path = outsideCircle; |
| 794 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 795 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 796 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 797 | } |
| 798 | |
| 799 | { |
| 800 | SkClipStack stack; |
| 801 | SkPath path = insideCircle; |
| 802 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 803 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 804 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 805 | } |
| 806 | |
| 807 | { |
| 808 | SkClipStack stack; |
| 809 | SkPath path = intersectingCircle; |
| 810 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 811 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 812 | REPORTER_ASSERT(reporter, false == stack.quickContains(testRect)); |
| 813 | } |
| 814 | |
| 815 | { |
| 816 | SkClipStack stack; |
| 817 | SkPath path = nonIntersectingCircle; |
| 818 | path.toggleInverseFillType(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 819 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kIntersect, false); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 820 | REPORTER_ASSERT(reporter, true == stack.quickContains(testRect)); |
| 821 | } |
| 822 | } |
| 823 | |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 824 | static void set_region_to_stack(const SkClipStack& stack, const SkIRect& bounds, SkRegion* region) { |
| 825 | region->setRect(bounds); |
| 826 | SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart); |
| 827 | while (const SkClipStack::Element *element = iter.next()) { |
| 828 | SkRegion elemRegion; |
| 829 | SkRegion boundsRgn(bounds); |
| 830 | SkPath path; |
| 831 | |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 832 | switch (element->getDeviceSpaceType()) { |
| 833 | case SkClipStack::Element::DeviceSpaceType::kEmpty: |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 834 | elemRegion.setEmpty(); |
| 835 | break; |
| 836 | default: |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 837 | element->asDeviceSpacePath(&path); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 838 | elemRegion.setPath(path, boundsRgn); |
| 839 | break; |
| 840 | } |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame] | 841 | |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 842 | region->op(elemRegion, element->getRegionOp()); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 843 | } |
| 844 | } |
| 845 | |
| 846 | static void test_invfill_diff_bug(skiatest::Reporter* reporter) { |
| 847 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 848 | stack.clipRect({10, 10, 20, 20}, SkMatrix::I(), SkClipOp::kIntersect, false); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 849 | |
| 850 | SkPath path; |
| 851 | path.addRect({30, 10, 40, 20}); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 852 | path.setFillType(SkPathFillType::kInverseWinding); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 853 | stack.clipPath(path, SkMatrix::I(), SkClipOp::kDifference, false); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 854 | |
| 855 | REPORTER_ASSERT(reporter, SkClipStack::kEmptyGenID == stack.getTopmostGenID()); |
| 856 | |
| 857 | SkRect stackBounds; |
| 858 | SkClipStack::BoundsType stackBoundsType; |
| 859 | stack.getBounds(&stackBounds, &stackBoundsType); |
| 860 | |
| 861 | REPORTER_ASSERT(reporter, stackBounds.isEmpty()); |
| 862 | REPORTER_ASSERT(reporter, SkClipStack::kNormal_BoundsType == stackBoundsType); |
| 863 | |
| 864 | SkRegion region; |
| 865 | set_region_to_stack(stack, {0, 0, 50, 30}, ®ion); |
| 866 | |
| 867 | REPORTER_ASSERT(reporter, region.isEmpty()); |
| 868 | } |
| 869 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 870 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 871 | |
Robert Phillips | 7cef678 | 2021-07-01 13:21:37 -0400 | [diff] [blame] | 872 | #if SK_GPU_V1 |
Robert Phillips | 1ca0da4 | 2021-06-14 15:27:19 -0400 | [diff] [blame] | 873 | #include "src/gpu/GrClipStackClip.h" |
| 874 | #include "src/gpu/GrReducedClip.h" |
Robert Phillips | 1a2e7de | 2021-07-29 11:23:48 -0400 | [diff] [blame] | 875 | #include "src/gpu/v1/SurfaceDrawContext_v1.h" |
Robert Phillips | 1ca0da4 | 2021-06-14 15:27:19 -0400 | [diff] [blame] | 876 | |
| 877 | typedef GrReducedClip::ElementList ElementList; |
| 878 | typedef GrReducedClip::InitialState InitialState; |
| 879 | |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 880 | // Functions that add a shape to the clip stack. The shape is computed from a rectangle. |
| 881 | // AA is always disabled since the clip stack reducer can cause changes in aa rasterization of the |
| 882 | // stack. A fractional edge repeated in different elements may be rasterized fewer times using the |
| 883 | // reduced stack. |
| 884 | typedef void (*AddElementFunc) (const SkRect& rect, |
| 885 | bool invert, |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 886 | SkClipOp op, |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 887 | SkClipStack* stack, |
| 888 | bool doAA); |
bsalomon@google.com | a4e13c8 | 2012-11-26 21:38:37 +0000 | [diff] [blame] | 889 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 890 | 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] | 891 | bool doAA) { |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 892 | SkScalar rx = rect.width() / 10; |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 893 | SkScalar ry = rect.height() / 20; |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 894 | if (invert) { |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 895 | SkPath path; |
| 896 | path.addRoundRect(rect, rx, ry); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 897 | path.setFillType(SkPathFillType::kInverseWinding); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 898 | stack->clipPath(path, SkMatrix::I(), op, doAA); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 899 | } else { |
| 900 | SkRRect rrect; |
| 901 | rrect.setRectXY(rect, rx, ry); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 902 | stack->clipRRect(rrect, SkMatrix::I(), op, doAA); |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 903 | } |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 904 | }; |
| 905 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 906 | static void add_rect(const SkRect& rect, bool invert, SkClipOp op, SkClipStack* stack, |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 907 | bool doAA) { |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 908 | if (invert) { |
| 909 | SkPath path; |
| 910 | path.addRect(rect); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 911 | path.setFillType(SkPathFillType::kInverseWinding); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 912 | stack->clipPath(path, SkMatrix::I(), op, doAA); |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 913 | } else { |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 914 | stack->clipRect(rect, SkMatrix::I(), op, doAA); |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 915 | } |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 916 | }; |
| 917 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 918 | static void add_oval(const SkRect& rect, bool invert, SkClipOp op, SkClipStack* stack, |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 919 | bool doAA) { |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 920 | SkPath path; |
| 921 | path.addOval(rect); |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 922 | if (invert) { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 923 | path.setFillType(SkPathFillType::kInverseWinding); |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 924 | } |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 925 | stack->clipPath(path, SkMatrix::I(), op, doAA); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 926 | }; |
| 927 | |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame] | 928 | static void add_shader(const SkRect& rect, bool invert, SkClipOp op, SkClipStack* stack, |
| 929 | bool doAA) { |
| 930 | // invert, op, and doAA don't apply to shaders at the SkClipStack level; this is handled earlier |
| 931 | // in the SkCanvas->SkDevice stack. Use rect to produce unique gradients, however. |
| 932 | SkPoint corners[2] = { {rect.fLeft, rect.fTop}, {rect.fRight, rect.fBottom} }; |
| 933 | SkColor colors[2] = { SK_ColorBLACK, SK_ColorTRANSPARENT }; |
| 934 | auto gradient = SkGradientShader::MakeLinear(corners, colors, nullptr, 2, SkTileMode::kDecal); |
| 935 | stack->clipShader(std::move(gradient)); |
| 936 | } |
Michael Ludwig | de00dc9 | 2020-06-05 10:56:32 -0400 | [diff] [blame] | 937 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 938 | static void add_elem_to_stack(const SkClipStack::Element& element, SkClipStack* stack) { |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 939 | if (element.isReplaceOp()) { |
| 940 | const SkRect resetBounds = SkRect::MakeLTRB(-10000.f, -10000.f, 10000.f, 10000.f); |
| 941 | stack->replaceClip(resetBounds, element.isAA()); |
| 942 | } |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 943 | switch (element.getDeviceSpaceType()) { |
| 944 | case SkClipStack::Element::DeviceSpaceType::kRect: |
| 945 | stack->clipRect(element.getDeviceSpaceRect(), SkMatrix::I(), element.getOp(), |
| 946 | element.isAA()); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 947 | break; |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 948 | case SkClipStack::Element::DeviceSpaceType::kRRect: |
| 949 | stack->clipRRect(element.getDeviceSpaceRRect(), SkMatrix::I(), element.getOp(), |
| 950 | element.isAA()); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 951 | break; |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 952 | case SkClipStack::Element::DeviceSpaceType::kPath: |
| 953 | stack->clipPath(element.getDeviceSpacePath(), SkMatrix::I(), element.getOp(), |
| 954 | element.isAA()); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 955 | break; |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame] | 956 | case SkClipStack::Element::DeviceSpaceType::kShader: |
| 957 | SkDEBUGFAIL("Why did the reducer put this in the mask elements."); |
| 958 | stack->clipShader(element.refShader()); |
| 959 | break; |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 960 | case SkClipStack::Element::DeviceSpaceType::kEmpty: |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 961 | SkDEBUGFAIL("Why did the reducer produce an explicit empty."); |
| 962 | stack->clipEmpty(); |
| 963 | break; |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame] | 967 | static void test_reduced_clip_stack(skiatest::Reporter* reporter, bool enableClipShader) { |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 968 | // 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] | 969 | // they are equal. |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 970 | |
| 971 | // All the clip elements will be contained within these bounds. |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 972 | static const SkIRect kIBounds = SkIRect::MakeWH(100, 100); |
| 973 | static const SkRect kBounds = SkRect::Make(kIBounds); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 974 | |
| 975 | enum { |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 976 | kNumTests = 250, |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 977 | kMinElemsPerTest = 1, |
| 978 | kMaxElemsPerTest = 50, |
| 979 | }; |
| 980 | |
| 981 | // min/max size of a clip element as a fraction of kBounds. |
| 982 | static const SkScalar kMinElemSizeFrac = SK_Scalar1 / 5; |
| 983 | static const SkScalar kMaxElemSizeFrac = SK_Scalar1; |
| 984 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 985 | static const SkClipOp kOps[] = { |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 986 | SkClipOp::kDifference, |
| 987 | SkClipOp::kIntersect, |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 988 | kUnion_SkClipOp, |
| 989 | kXOR_SkClipOp, |
| 990 | kReverseDifference_SkClipOp, |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 991 | }; |
| 992 | |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 993 | // We want to test inverse fills. However, they are quite rare in practice so don't over do it. |
| 994 | static const SkScalar kFractionInverted = SK_Scalar1 / kMaxElemsPerTest; |
| 995 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 996 | static const SkScalar kFractionAntialiased = 0.25; |
| 997 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 998 | static const AddElementFunc kElementFuncs[] = { |
| 999 | add_rect, |
| 1000 | add_round_rect, |
| 1001 | add_oval, |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame] | 1002 | add_shader |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1003 | }; |
| 1004 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 1005 | SkRandom r; |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1006 | |
| 1007 | for (int i = 0; i < kNumTests; ++i) { |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1008 | SkString testCase; |
| 1009 | testCase.printf("Iteration %d", i); |
| 1010 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1011 | // Randomly generate a clip stack. |
| 1012 | SkClipStack stack; |
| 1013 | int numElems = r.nextRangeU(kMinElemsPerTest, kMaxElemsPerTest); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1014 | bool doAA = r.nextBiasedBool(kFractionAntialiased); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1015 | for (int e = 0; e < numElems; ++e) { |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 1016 | size_t opLimit = enableClipShader ? ((size_t) SkClipOp::kIntersect + 1) |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame] | 1017 | : SK_ARRAY_COUNT(kOps); |
| 1018 | SkClipOp op = kOps[r.nextULessThan(opLimit)]; |
skia.committer@gmail.com | 8ccf590 | 2012-11-27 02:01:19 +0000 | [diff] [blame] | 1019 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1020 | // saves can change the clip stack behavior when an element is added. |
| 1021 | bool doSave = r.nextBool(); |
skia.committer@gmail.com | 8ccf590 | 2012-11-27 02:01:19 +0000 | [diff] [blame] | 1022 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1023 | SkSize size = SkSize::Make( |
Mike Reed | df85c38 | 2017-02-14 10:59:19 -0500 | [diff] [blame] | 1024 | kBounds.width() * r.nextRangeScalar(kMinElemSizeFrac, kMaxElemSizeFrac), |
| 1025 | kBounds.height() * r.nextRangeScalar(kMinElemSizeFrac, kMaxElemSizeFrac)); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1026 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1027 | SkPoint xy = {r.nextRangeScalar(kBounds.fLeft, kBounds.fRight - size.fWidth), |
| 1028 | r.nextRangeScalar(kBounds.fTop, kBounds.fBottom - size.fHeight)}; |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1029 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1030 | SkRect rect; |
| 1031 | if (doAA) { |
| 1032 | rect.setXYWH(xy.fX, xy.fY, size.fWidth, size.fHeight); |
| 1033 | if (GrClip::IsPixelAligned(rect)) { |
| 1034 | // Don't create an element that may accidentally become not antialiased. |
| 1035 | rect.outset(0.5f, 0.5f); |
| 1036 | } |
| 1037 | SkASSERT(!GrClip::IsPixelAligned(rect)); |
| 1038 | } else { |
| 1039 | rect.setXYWH(SkScalarFloorToScalar(xy.fX), |
| 1040 | SkScalarFloorToScalar(xy.fY), |
| 1041 | SkScalarCeilToScalar(size.fWidth), |
| 1042 | SkScalarCeilToScalar(size.fHeight)); |
| 1043 | } |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1044 | |
bsalomon@google.com | 705e840 | 2012-11-27 15:43:57 +0000 | [diff] [blame] | 1045 | bool invert = r.nextBiasedBool(kFractionInverted); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 1046 | |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame] | 1047 | size_t functionLimit = SK_ARRAY_COUNT(kElementFuncs); |
| 1048 | if (!enableClipShader) { |
| 1049 | functionLimit--; |
| 1050 | } |
| 1051 | kElementFuncs[r.nextULessThan(functionLimit)](rect, invert, op, &stack, doAA); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1052 | if (doSave) { |
| 1053 | stack.save(); |
| 1054 | } |
| 1055 | } |
| 1056 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1057 | sk_sp<GrDirectContext> context = GrDirectContext::MakeMock(nullptr); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 1058 | const GrCaps* caps = context->priv().caps(); |
Brian Salomon | 1447177 | 2017-12-05 10:35:15 -0500 | [diff] [blame] | 1059 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1060 | // Zero the memory we will new the GrReducedClip into. This ensures the elements gen ID |
| 1061 | // will be kInvalidGenID if left uninitialized. |
| 1062 | SkAlignedSTStorage<1, GrReducedClip> storage; |
| 1063 | memset(storage.get(), 0, sizeof(GrReducedClip)); |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 1064 | static_assert(0 == SkClipStack::kInvalidGenID); |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1065 | |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1066 | // Get the reduced version of the stack. |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1067 | SkRect queryBounds = kBounds; |
| 1068 | queryBounds.outset(kBounds.width() / 2, kBounds.height() / 2); |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 1069 | const GrReducedClip* reduced = new (storage.get()) GrReducedClip(stack, queryBounds, caps); |
bsalomon@google.com | a444430 | 2012-12-04 15:22:12 +0000 | [diff] [blame] | 1070 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1071 | REPORTER_ASSERT(reporter, |
| 1072 | reduced->maskElements().isEmpty() || |
| 1073 | SkClipStack::kInvalidGenID != reduced->maskGenID(), |
| 1074 | testCase.c_str()); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1075 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1076 | if (!reduced->maskElements().isEmpty()) { |
| 1077 | REPORTER_ASSERT(reporter, reduced->hasScissor(), testCase.c_str()); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1078 | SkRect stackBounds; |
| 1079 | SkClipStack::BoundsType stackBoundsType; |
| 1080 | stack.getBounds(&stackBounds, &stackBoundsType); |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1081 | REPORTER_ASSERT(reporter, reduced->maskRequiresAA() == doAA, testCase.c_str()); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1082 | } |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1083 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1084 | // Build a new clip stack based on the reduced clip elements |
| 1085 | SkClipStack reducedStack; |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1086 | if (GrReducedClip::InitialState::kAllOut == reduced->initialState()) { |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1087 | // whether the result is bounded or not, the whole plane should start outside the clip. |
| 1088 | reducedStack.clipEmpty(); |
| 1089 | } |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1090 | for (ElementList::Iter iter(reduced->maskElements()); iter.get(); iter.next()) { |
| 1091 | add_elem_to_stack(*iter.get(), &reducedStack); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1092 | } |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame] | 1093 | if (reduced->hasShader()) { |
| 1094 | REPORTER_ASSERT(reporter, enableClipShader); |
| 1095 | reducedStack.clipShader(reduced->shader()); |
| 1096 | } |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1097 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1098 | SkIRect scissor = reduced->hasScissor() ? reduced->scissor() : kIBounds; |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 1099 | |
bsalomon@google.com | 34cd70a | 2012-12-06 14:23:20 +0000 | [diff] [blame] | 1100 | // GrReducedClipStack assumes that the final result is clipped to the returned bounds |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 1101 | reducedStack.clipDevRect(scissor, SkClipOp::kIntersect); |
| 1102 | stack.clipDevRect(scissor, SkClipOp::kIntersect); |
bsalomon@google.com | 34cd70a | 2012-12-06 14:23:20 +0000 | [diff] [blame] | 1103 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1104 | // 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] | 1105 | SkRegion region; |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 1106 | set_region_to_stack(stack, scissor, ®ion); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 1107 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1108 | SkRegion reducedRegion; |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 1109 | set_region_to_stack(reducedStack, scissor, &reducedRegion); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1110 | |
Brian Salomon | 1c80e99 | 2018-01-29 09:50:47 -0500 | [diff] [blame] | 1111 | REPORTER_ASSERT(reporter, region == reducedRegion, testCase.c_str()); |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1112 | |
| 1113 | reduced->~GrReducedClip(); |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | |
halcanary | 4dbbd04 | 2016-06-07 17:21:10 -0700 | [diff] [blame] | 1117 | #ifdef SK_BUILD_FOR_WIN |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1118 | #define SUPPRESS_VISIBILITY_WARNING |
| 1119 | #else |
| 1120 | #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden"))) |
| 1121 | #endif |
| 1122 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1123 | static void test_reduced_clip_stack_genid(skiatest::Reporter* reporter) { |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1124 | { |
| 1125 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 1126 | stack.replaceClip(SkRect::MakeXYWH(0, 0, 100, 100), true); |
| 1127 | stack.replaceClip(SkRect::MakeXYWH(0, 0, 50.3f, 50.3f), true); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1128 | SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1129 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1130 | sk_sp<GrDirectContext> context = GrDirectContext::MakeMock(nullptr); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 1131 | const GrCaps* caps = context->priv().caps(); |
Brian Salomon | 1447177 | 2017-12-05 10:35:15 -0500 | [diff] [blame] | 1132 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1133 | SkAlignedSTStorage<1, GrReducedClip> storage; |
| 1134 | memset(storage.get(), 0, sizeof(GrReducedClip)); |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 1135 | static_assert(0 == SkClipStack::kInvalidGenID); |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 1136 | const GrReducedClip* reduced = new (storage.get()) GrReducedClip(stack, bounds, caps); |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1137 | |
| 1138 | REPORTER_ASSERT(reporter, reduced->maskElements().count() == 1); |
| 1139 | // Clips will be cached based on the generation id. Make sure the gen id is valid. |
| 1140 | REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reduced->maskGenID()); |
| 1141 | |
| 1142 | reduced->~GrReducedClip(); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1143 | } |
| 1144 | { |
| 1145 | SkClipStack stack; |
| 1146 | |
| 1147 | // Create a clip with following 25.3, 25.3 boxes which are 25 apart: |
| 1148 | // A B |
| 1149 | // C D |
| 1150 | |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 1151 | stack.replaceClip(SkRect::MakeXYWH(0, 0, 25.3f, 25.3f), true); |
Robert Phillips | 806be2d | 2017-06-28 15:23:59 -0400 | [diff] [blame] | 1152 | uint32_t genIDA = stack.getTopmostGenID(); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 1153 | 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] | 1154 | kUnion_SkClipOp, true); |
Robert Phillips | 806be2d | 2017-06-28 15:23:59 -0400 | [diff] [blame] | 1155 | uint32_t genIDB = stack.getTopmostGenID(); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 1156 | 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] | 1157 | kUnion_SkClipOp, true); |
Robert Phillips | 806be2d | 2017-06-28 15:23:59 -0400 | [diff] [blame] | 1158 | uint32_t genIDC = stack.getTopmostGenID(); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 1159 | 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] | 1160 | kUnion_SkClipOp, true); |
Robert Phillips | 806be2d | 2017-06-28 15:23:59 -0400 | [diff] [blame] | 1161 | uint32_t genIDD = stack.getTopmostGenID(); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1162 | |
| 1163 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1164 | #define IXYWH SkIRect::MakeXYWH |
| 1165 | #define XYWH SkRect::MakeXYWH |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1166 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1167 | SkIRect stackBounds = IXYWH(0, 0, 76, 76); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1168 | |
| 1169 | // The base test is to test each rect in two ways: |
| 1170 | // 1) The box dimensions. (Should reduce to "all in", no elements). |
| 1171 | // 2) A bit over the box dimensions. |
| 1172 | // In the case 2, test that the generation id is what is expected. |
| 1173 | // The rects are of fractional size so that case 2 never gets optimized to an empty element |
| 1174 | // list. |
| 1175 | |
| 1176 | // Not passing in tighter bounds is tested for consistency. |
| 1177 | static const struct SUPPRESS_VISIBILITY_WARNING { |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1178 | SkRect testBounds; |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1179 | int reducedClipCount; |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1180 | uint32_t reducedGenID; |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1181 | InitialState initialState; |
| 1182 | SkIRect clipIRect; |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1183 | // parameter. |
| 1184 | } testCases[] = { |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1185 | |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1186 | // Rect A. |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1187 | { XYWH(0, 0, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(0, 0, 25, 25) }, |
| 1188 | { 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] | 1189 | { 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] | 1190 | |
| 1191 | // Rect B. |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1192 | { XYWH(50, 0, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(50, 0, 25, 25) }, |
| 1193 | { 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] | 1194 | { 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] | 1195 | |
| 1196 | // Rect C. |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1197 | { XYWH(0, 50, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(0, 50, 25, 25) }, |
| 1198 | { 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] | 1199 | { 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] | 1200 | |
| 1201 | // Rect D. |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1202 | { XYWH(50, 50, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip::InitialState::kAllIn, IXYWH(50, 50, 25, 25)}, |
| 1203 | { 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] | 1204 | { 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] | 1205 | |
| 1206 | // Other tests: |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1207 | { 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] | 1208 | |
Michael Ludwig | de00dc9 | 2020-06-05 10:56:32 -0400 | [diff] [blame] | 1209 | // Rect in the middle, touches none (so should not be drawn) |
| 1210 | { 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] | 1211 | |
| 1212 | // Rect in the middle, touches all the rects. GenID is the last rect. |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1213 | { 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] | 1214 | }; |
| 1215 | |
| 1216 | #undef XYWH |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1217 | #undef IXYWH |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1218 | sk_sp<GrDirectContext> context = GrDirectContext::MakeMock(nullptr); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 1219 | const GrCaps* caps = context->priv().caps(); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1220 | |
| 1221 | for (size_t i = 0; i < SK_ARRAY_COUNT(testCases); ++i) { |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 1222 | const GrReducedClip reduced(stack, testCases[i].testBounds, caps); |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 1223 | REPORTER_ASSERT(reporter, reduced.maskElements().count() == |
| 1224 | testCases[i].reducedClipCount); |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1225 | if (reduced.maskElements().count()) { |
| 1226 | REPORTER_ASSERT(reporter, reduced.maskGenID() == testCases[i].reducedGenID); |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 1227 | } |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 1228 | REPORTER_ASSERT(reporter, reduced.initialState() == testCases[i].initialState); |
Michael Ludwig | de00dc9 | 2020-06-05 10:56:32 -0400 | [diff] [blame] | 1229 | |
| 1230 | bool expectsScissor = !testCases[i].clipIRect.isEmpty(); |
| 1231 | REPORTER_ASSERT(reporter, expectsScissor == reduced.hasScissor()); |
| 1232 | if (expectsScissor) { |
| 1233 | REPORTER_ASSERT(reporter, reduced.scissor() == testCases[i].clipIRect); |
| 1234 | } |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1235 | } |
| 1236 | } |
| 1237 | } |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1238 | static void test_reduced_clip_stack_no_aa_crash(skiatest::Reporter* reporter) { |
| 1239 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 1240 | stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 100, 100), SkClipOp::kIntersect); |
| 1241 | stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 50, 50), SkClipOp::kIntersect); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1242 | SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1243 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1244 | sk_sp<GrDirectContext> context = GrDirectContext::MakeMock(nullptr); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 1245 | const GrCaps* caps = context->priv().caps(); |
Brian Salomon | 1447177 | 2017-12-05 10:35:15 -0500 | [diff] [blame] | 1246 | |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1247 | // At the time, this would crash. |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 1248 | const GrReducedClip reduced(stack, bounds, caps); |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 1249 | REPORTER_ASSERT(reporter, reduced.maskElements().isEmpty()); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1252 | enum class ClipMethod { |
| 1253 | kSkipDraw, |
| 1254 | kIgnoreClip, |
| 1255 | kScissor, |
| 1256 | kAAElements |
| 1257 | }; |
| 1258 | |
| 1259 | static void test_aa_query(skiatest::Reporter* reporter, const SkString& testName, |
| 1260 | const SkClipStack& stack, const SkMatrix& queryXform, |
| 1261 | const SkRect& preXformQuery, ClipMethod expectedMethod, |
| 1262 | int numExpectedElems = 0) { |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1263 | sk_sp<GrDirectContext> context = GrDirectContext::MakeMock(nullptr); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 1264 | const GrCaps* caps = context->priv().caps(); |
Brian Salomon | 1447177 | 2017-12-05 10:35:15 -0500 | [diff] [blame] | 1265 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1266 | SkRect queryBounds; |
| 1267 | queryXform.mapRect(&queryBounds, preXformQuery); |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 1268 | const GrReducedClip reduced(stack, queryBounds, caps); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1269 | |
| 1270 | SkClipStack::BoundsType stackBoundsType; |
| 1271 | SkRect stackBounds; |
| 1272 | stack.getBounds(&stackBounds, &stackBoundsType); |
| 1273 | |
| 1274 | switch (expectedMethod) { |
| 1275 | case ClipMethod::kSkipDraw: |
| 1276 | SkASSERT(0 == numExpectedElems); |
Brian Salomon | 1c80e99 | 2018-01-29 09:50:47 -0500 | [diff] [blame] | 1277 | REPORTER_ASSERT(reporter, reduced.maskElements().isEmpty(), testName.c_str()); |
| 1278 | REPORTER_ASSERT(reporter, |
| 1279 | GrReducedClip::InitialState::kAllOut == reduced.initialState(), |
| 1280 | testName.c_str()); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1281 | return; |
| 1282 | case ClipMethod::kIgnoreClip: |
| 1283 | SkASSERT(0 == numExpectedElems); |
Brian Salomon | 1c80e99 | 2018-01-29 09:50:47 -0500 | [diff] [blame] | 1284 | REPORTER_ASSERT( |
| 1285 | reporter, |
| 1286 | !reduced.hasScissor() || GrClip::IsInsideClip(reduced.scissor(), queryBounds), |
| 1287 | testName.c_str()); |
| 1288 | REPORTER_ASSERT(reporter, reduced.maskElements().isEmpty(), testName.c_str()); |
| 1289 | REPORTER_ASSERT(reporter, |
| 1290 | GrReducedClip::InitialState::kAllIn == reduced.initialState(), |
| 1291 | testName.c_str()); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1292 | return; |
| 1293 | case ClipMethod::kScissor: { |
| 1294 | SkASSERT(SkClipStack::kNormal_BoundsType == stackBoundsType); |
| 1295 | SkASSERT(0 == numExpectedElems); |
| 1296 | SkIRect expectedScissor; |
| 1297 | stackBounds.round(&expectedScissor); |
Brian Salomon | 1c80e99 | 2018-01-29 09:50:47 -0500 | [diff] [blame] | 1298 | REPORTER_ASSERT(reporter, reduced.maskElements().isEmpty(), testName.c_str()); |
| 1299 | REPORTER_ASSERT(reporter, reduced.hasScissor(), testName.c_str()); |
| 1300 | REPORTER_ASSERT(reporter, expectedScissor == reduced.scissor(), testName.c_str()); |
| 1301 | REPORTER_ASSERT(reporter, |
| 1302 | GrReducedClip::InitialState::kAllIn == reduced.initialState(), |
| 1303 | testName.c_str()); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1304 | return; |
| 1305 | } |
| 1306 | case ClipMethod::kAAElements: { |
| 1307 | SkIRect expectedClipIBounds = GrClip::GetPixelIBounds(queryBounds); |
| 1308 | if (SkClipStack::kNormal_BoundsType == stackBoundsType) { |
| 1309 | SkAssertResult(expectedClipIBounds.intersect(GrClip::GetPixelIBounds(stackBounds))); |
| 1310 | } |
Brian Salomon | 1c80e99 | 2018-01-29 09:50:47 -0500 | [diff] [blame] | 1311 | REPORTER_ASSERT(reporter, numExpectedElems == reduced.maskElements().count(), |
| 1312 | testName.c_str()); |
| 1313 | REPORTER_ASSERT(reporter, reduced.hasScissor(), testName.c_str()); |
| 1314 | REPORTER_ASSERT(reporter, expectedClipIBounds == reduced.scissor(), testName.c_str()); |
| 1315 | REPORTER_ASSERT(reporter, |
| 1316 | reduced.maskElements().isEmpty() || reduced.maskRequiresAA(), |
| 1317 | testName.c_str()); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1318 | break; |
| 1319 | } |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | static void test_reduced_clip_stack_aa(skiatest::Reporter* reporter) { |
| 1324 | constexpr SkScalar IL = 2, IT = 1, IR = 6, IB = 7; // Pixel aligned rect. |
| 1325 | constexpr SkScalar L = 2.2f, T = 1.7f, R = 5.8f, B = 7.3f; // Generic rect. |
| 1326 | constexpr SkScalar l = 3.3f, t = 2.8f, r = 4.7f, b = 6.2f; // Small rect contained in R. |
| 1327 | |
| 1328 | SkRect alignedRect = {IL, IT, IR, IB}; |
| 1329 | SkRect rect = {L, T, R, B}; |
| 1330 | SkRect innerRect = {l, t, r, b}; |
| 1331 | |
| 1332 | SkMatrix m; |
| 1333 | m.setIdentity(); |
| 1334 | |
| 1335 | constexpr SkScalar kMinScale = 2.0001f; |
| 1336 | constexpr SkScalar kMaxScale = 3; |
| 1337 | constexpr int kNumIters = 8; |
| 1338 | |
| 1339 | SkString name; |
| 1340 | SkRandom rand; |
| 1341 | |
| 1342 | for (int i = 0; i < kNumIters; ++i) { |
| 1343 | // Pixel-aligned rect (iior=true). |
| 1344 | name.printf("Pixel-aligned rect test, iter %i", i); |
| 1345 | SkClipStack stack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 1346 | stack.clipRect(alignedRect, SkMatrix::I(), SkClipOp::kIntersect, true); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1347 | test_aa_query(reporter, name, stack, m, {IL, IT, IR, IB}, ClipMethod::kIgnoreClip); |
| 1348 | 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] | 1349 | 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] | 1350 | |
| 1351 | // Rect (iior=true). |
| 1352 | name.printf("Rect test, iter %i", i); |
| 1353 | stack.reset(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 1354 | stack.clipRect(rect, SkMatrix::I(), SkClipOp::kIntersect, true); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1355 | test_aa_query(reporter, name, stack, m, {L, T, R, B}, ClipMethod::kIgnoreClip); |
| 1356 | test_aa_query(reporter, name, stack, m, {L-.1f, T, L, B}, ClipMethod::kSkipDraw); |
| 1357 | test_aa_query(reporter, name, stack, m, {L-.1f, T, L+.1f, B}, ClipMethod::kAAElements, 1); |
| 1358 | |
| 1359 | // Difference rect (iior=false, inside-out bounds). |
| 1360 | name.printf("Difference rect test, iter %i", i); |
| 1361 | stack.reset(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 1362 | stack.clipRect(rect, SkMatrix::I(), SkClipOp::kDifference, true); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1363 | test_aa_query(reporter, name, stack, m, {L, T, R, B}, ClipMethod::kSkipDraw); |
| 1364 | test_aa_query(reporter, name, stack, m, {L, T-.1f, R, T}, ClipMethod::kIgnoreClip); |
| 1365 | test_aa_query(reporter, name, stack, m, {L, T-.1f, R, T+.1f}, ClipMethod::kAAElements, 1); |
| 1366 | |
| 1367 | // Complex clip (iior=false, normal bounds). |
| 1368 | name.printf("Complex clip test, iter %i", i); |
| 1369 | stack.reset(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 1370 | stack.clipRect(rect, SkMatrix::I(), SkClipOp::kIntersect, true); |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame^] | 1371 | stack.clipRect(innerRect, SkMatrix::I(), SkClipOp::kDifference, true); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1372 | test_aa_query(reporter, name, stack, m, {l, t, r, b}, ClipMethod::kSkipDraw); |
| 1373 | test_aa_query(reporter, name, stack, m, {r-.1f, t, R, b}, ClipMethod::kAAElements, 1); |
| 1374 | test_aa_query(reporter, name, stack, m, {r-.1f, t, R+.1f, b}, ClipMethod::kAAElements, 2); |
| 1375 | test_aa_query(reporter, name, stack, m, {r, t, R+.1f, b}, ClipMethod::kAAElements, 1); |
| 1376 | test_aa_query(reporter, name, stack, m, {r, t, R, b}, ClipMethod::kIgnoreClip); |
| 1377 | test_aa_query(reporter, name, stack, m, {R, T, R+.1f, B}, ClipMethod::kSkipDraw); |
| 1378 | |
| 1379 | // Complex clip where outer rect is pixel aligned (iior=false, normal bounds). |
| 1380 | name.printf("Aligned Complex clip test, iter %i", i); |
| 1381 | stack.reset(); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 1382 | stack.clipRect(alignedRect, SkMatrix::I(), SkClipOp::kIntersect, true); |
Michael Ludwig | a3a67ae | 2021-08-06 10:42:01 -0400 | [diff] [blame^] | 1383 | stack.clipRect(innerRect, SkMatrix::I(), SkClipOp::kDifference, true); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1384 | test_aa_query(reporter, name, stack, m, {l, t, r, b}, ClipMethod::kSkipDraw); |
| 1385 | test_aa_query(reporter, name, stack, m, {l, b-.1f, r, IB}, ClipMethod::kAAElements, 1); |
| 1386 | test_aa_query(reporter, name, stack, m, {l, b-.1f, r, IB+.1f}, ClipMethod::kAAElements, 1); |
| 1387 | test_aa_query(reporter, name, stack, m, {l, b, r, IB+.1f}, ClipMethod::kAAElements, 0); |
| 1388 | test_aa_query(reporter, name, stack, m, {l, b, r, IB}, ClipMethod::kIgnoreClip); |
| 1389 | test_aa_query(reporter, name, stack, m, {IL, IB, IR, IB+.1f}, ClipMethod::kSkipDraw); |
| 1390 | |
| 1391 | // Apply random transforms and try again. This ensures the clip stack reduction is hardened |
| 1392 | // against FP rounding error. |
| 1393 | SkScalar sx = rand.nextRangeScalar(kMinScale, kMaxScale); |
| 1394 | sx = SkScalarFloorToScalar(sx * alignedRect.width()) / alignedRect.width(); |
| 1395 | SkScalar sy = rand.nextRangeScalar(kMinScale, kMaxScale); |
| 1396 | sy = SkScalarFloorToScalar(sy * alignedRect.height()) / alignedRect.height(); |
| 1397 | SkScalar tx = SkScalarRoundToScalar(sx * alignedRect.x()) - sx * alignedRect.x(); |
| 1398 | SkScalar ty = SkScalarRoundToScalar(sy * alignedRect.y()) - sy * alignedRect.y(); |
| 1399 | |
Mike Reed | 1f60733 | 2020-05-21 12:11:27 -0400 | [diff] [blame] | 1400 | SkMatrix xform = SkMatrix::Scale(sx, sy); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1401 | xform.postTranslate(tx, ty); |
| 1402 | xform.mapRect(&alignedRect); |
| 1403 | xform.mapRect(&rect); |
| 1404 | xform.mapRect(&innerRect); |
| 1405 | m.postConcat(xform); |
| 1406 | } |
| 1407 | } |
| 1408 | |
Chris Dalton | 348060f | 2017-06-05 13:15:37 -0600 | [diff] [blame] | 1409 | static void test_tiny_query_bounds_assertion_bug(skiatest::Reporter* reporter) { |
| 1410 | // https://bugs.chromium.org/p/skia/issues/detail?id=5990 |
| 1411 | const SkRect clipBounds = SkRect::MakeXYWH(1.5f, 100, 1000, 1000); |
| 1412 | |
| 1413 | SkClipStack rectStack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 1414 | rectStack.clipRect(clipBounds, SkMatrix::I(), SkClipOp::kIntersect, true); |
Chris Dalton | 348060f | 2017-06-05 13:15:37 -0600 | [diff] [blame] | 1415 | |
| 1416 | SkPath clipPath; |
| 1417 | clipPath.moveTo(clipBounds.left(), clipBounds.top()); |
| 1418 | clipPath.quadTo(clipBounds.right(), clipBounds.top(), |
| 1419 | clipBounds.right(), clipBounds.bottom()); |
| 1420 | clipPath.quadTo(clipBounds.left(), clipBounds.bottom(), |
| 1421 | clipBounds.left(), clipBounds.top()); |
| 1422 | SkClipStack pathStack; |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 1423 | pathStack.clipPath(clipPath, SkMatrix::I(), SkClipOp::kIntersect, true); |
Chris Dalton | 348060f | 2017-06-05 13:15:37 -0600 | [diff] [blame] | 1424 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1425 | sk_sp<GrDirectContext> context = GrDirectContext::MakeMock(nullptr); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 1426 | const GrCaps* caps = context->priv().caps(); |
Brian Salomon | 1447177 | 2017-12-05 10:35:15 -0500 | [diff] [blame] | 1427 | |
Chris Dalton | 348060f | 2017-06-05 13:15:37 -0600 | [diff] [blame] | 1428 | for (const SkClipStack& stack : {rectStack, pathStack}) { |
| 1429 | for (SkRect queryBounds : {SkRect::MakeXYWH(53, 60, GrClip::kBoundsTolerance, 1000), |
| 1430 | SkRect::MakeXYWH(53, 60, GrClip::kBoundsTolerance/2, 1000), |
| 1431 | SkRect::MakeXYWH(53, 160, 1000, GrClip::kBoundsTolerance), |
| 1432 | SkRect::MakeXYWH(53, 160, 1000, GrClip::kBoundsTolerance/2)}) { |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 1433 | const GrReducedClip reduced(stack, queryBounds, caps); |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 1434 | REPORTER_ASSERT(reporter, !reduced.hasScissor()); |
| 1435 | REPORTER_ASSERT(reporter, reduced.maskElements().isEmpty()); |
Chris Dalton | 348060f | 2017-06-05 13:15:37 -0600 | [diff] [blame] | 1436 | REPORTER_ASSERT(reporter, |
| 1437 | GrReducedClip::InitialState::kAllOut == reduced.initialState()); |
| 1438 | } |
| 1439 | } |
| 1440 | } |
| 1441 | |
Robert Phillips | 7cef678 | 2021-07-01 13:21:37 -0400 | [diff] [blame] | 1442 | #endif // SK_GPU_V1 |
Robert Phillips | 1ca0da4 | 2021-06-14 15:27:19 -0400 | [diff] [blame] | 1443 | |
Brian Salomon | 1c0b05a | 2019-04-19 15:37:28 -0400 | [diff] [blame] | 1444 | static void test_is_rrect_deep_rect_stack(skiatest::Reporter* reporter) { |
| 1445 | static constexpr SkRect kTargetBounds = SkRect::MakeWH(1000, 500); |
| 1446 | // All antialiased or all not antialiased. |
| 1447 | for (bool aa : {false, true}) { |
| 1448 | SkClipStack stack; |
| 1449 | for (int i = 0; i <= 100; ++i) { |
| 1450 | stack.save(); |
| 1451 | stack.clipRect(SkRect::MakeLTRB(i, 0.5, kTargetBounds.width(), kTargetBounds.height()), |
| 1452 | SkMatrix::I(), SkClipOp::kIntersect, aa); |
| 1453 | } |
| 1454 | SkRRect rrect; |
| 1455 | bool isAA; |
| 1456 | SkRRect expected = SkRRect::MakeRect( |
| 1457 | SkRect::MakeLTRB(100, 0.5, kTargetBounds.width(), kTargetBounds.height())); |
| 1458 | if (stack.isRRect(kTargetBounds, &rrect, &isAA)) { |
| 1459 | REPORTER_ASSERT(reporter, rrect == expected); |
| 1460 | REPORTER_ASSERT(reporter, aa == isAA); |
| 1461 | } else { |
| 1462 | ERRORF(reporter, "Expected to be an rrect."); |
| 1463 | } |
| 1464 | } |
| 1465 | // Mixed AA and non-AA without simple containment. |
| 1466 | SkClipStack stack; |
| 1467 | for (int i = 0; i <= 100; ++i) { |
| 1468 | bool aa = i & 0b1; |
| 1469 | int j = 100 - i; |
| 1470 | stack.save(); |
| 1471 | stack.clipRect(SkRect::MakeLTRB(i, j + 0.5, kTargetBounds.width(), kTargetBounds.height()), |
| 1472 | SkMatrix::I(), SkClipOp::kIntersect, aa); |
| 1473 | } |
| 1474 | SkRRect rrect; |
| 1475 | bool isAA; |
| 1476 | REPORTER_ASSERT(reporter, !stack.isRRect(kTargetBounds, &rrect, &isAA)); |
| 1477 | } |
| 1478 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 1479 | DEF_TEST(ClipStack, reporter) { |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 1480 | SkClipStack stack; |
| 1481 | |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 1482 | REPORTER_ASSERT(reporter, 0 == stack.getSaveCount()); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 1483 | assert_count(reporter, stack, 0); |
| 1484 | |
| 1485 | static const SkIRect gRects[] = { |
| 1486 | { 0, 0, 100, 100 }, |
| 1487 | { 25, 25, 125, 125 }, |
| 1488 | { 0, 0, 1000, 1000 }, |
| 1489 | { 0, 0, 75, 75 } |
| 1490 | }; |
| 1491 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRects); i++) { |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 1492 | stack.clipDevRect(gRects[i], SkClipOp::kIntersect); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | // 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] | 1496 | SkClipStack::B2TIter iter(stack); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 1497 | const SkClipStack::Element* element = iter.next(); |
epoger@google.com | 2047f00 | 2011-05-17 17:36:59 +0000 | [diff] [blame] | 1498 | SkRect answer; |
Mike Reed | 92b3335 | 2019-08-24 19:39:13 -0400 | [diff] [blame] | 1499 | answer.setLTRB(25, 25, 75, 75); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 1500 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1501 | REPORTER_ASSERT(reporter, element); |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 1502 | REPORTER_ASSERT(reporter, |
| 1503 | SkClipStack::Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()); |
Michael Ludwig | d59d3e1 | 2021-08-05 16:39:18 -0400 | [diff] [blame] | 1504 | REPORTER_ASSERT(reporter, SkClipOp::kIntersect == element->getOp()); |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 1505 | REPORTER_ASSERT(reporter, element->getDeviceSpaceRect() == answer); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 1506 | // now check that we only had one in our iterator |
| 1507 | REPORTER_ASSERT(reporter, !iter.next()); |
| 1508 | |
| 1509 | stack.reset(); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 1510 | REPORTER_ASSERT(reporter, 0 == stack.getSaveCount()); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 1511 | assert_count(reporter, stack, 0); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 1512 | |
| 1513 | test_assign_and_comparison(reporter); |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 1514 | test_iterators(reporter); |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 1515 | test_bounds(reporter, SkClipStack::Element::DeviceSpaceType::kRect); |
| 1516 | test_bounds(reporter, SkClipStack::Element::DeviceSpaceType::kRRect); |
| 1517 | test_bounds(reporter, SkClipStack::Element::DeviceSpaceType::kPath); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 1518 | test_isWideOpen(reporter); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 1519 | test_rect_merging(reporter); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 1520 | test_rect_replace(reporter); |
junov@chromium.org | edf32d5 | 2012-12-10 14:57:54 +0000 | [diff] [blame] | 1521 | test_rect_inverse_fill(reporter); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 1522 | test_path_replace(reporter); |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 1523 | test_quickContains(reporter); |
csmartdalton | d50e240 | 2016-07-22 08:39:06 -0700 | [diff] [blame] | 1524 | test_invfill_diff_bug(reporter); |
Brian Osman | c7ad40f | 2018-05-31 14:27:17 -0400 | [diff] [blame] | 1525 | |
Robert Phillips | 7cef678 | 2021-07-01 13:21:37 -0400 | [diff] [blame] | 1526 | #if SK_GPU_V1 |
Michael Ludwig | 4e221bd | 2020-06-05 11:29:36 -0400 | [diff] [blame] | 1527 | test_reduced_clip_stack(reporter, /* clipShader */ false); |
| 1528 | test_reduced_clip_stack(reporter, /* clipShader */ true); |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1529 | test_reduced_clip_stack_genid(reporter); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 1530 | test_reduced_clip_stack_no_aa_crash(reporter); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 1531 | test_reduced_clip_stack_aa(reporter); |
Chris Dalton | 348060f | 2017-06-05 13:15:37 -0600 | [diff] [blame] | 1532 | test_tiny_query_bounds_assertion_bug(reporter); |
Robert Phillips | 1ca0da4 | 2021-06-14 15:27:19 -0400 | [diff] [blame] | 1533 | #endif |
Brian Salomon | 1c0b05a | 2019-04-19 15:37:28 -0400 | [diff] [blame] | 1534 | test_is_rrect_deep_rect_stack(reporter); |
reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame] | 1535 | } |
Brian Salomon | 19f0ed5 | 2017-01-06 13:54:58 -0500 | [diff] [blame] | 1536 | |
| 1537 | ////////////////////////////////////////////////////////////////////////////// |
| 1538 | |
Robert Phillips | 8faa340 | 2021-04-05 14:01:36 -0400 | [diff] [blame] | 1539 | // For the GrClipStack case, this is covered in GrClipStack_SWMask |
| 1540 | #if defined(SK_DISABLE_NEW_GR_CLIP_STACK) |
| 1541 | |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 1542 | sk_sp<GrTextureProxy> GrClipStackClip::testingOnly_createClipMask( |
| 1543 | GrRecordingContext* context) const { |
John Stiles | fe0de30 | 2020-08-14 10:52:06 -0400 | [diff] [blame] | 1544 | const GrReducedClip reducedClip(*fStack, SkRect::MakeWH(512, 512), nullptr); |
Greg Daniel | e32506b | 2020-02-10 16:00:54 -0500 | [diff] [blame] | 1545 | return this->createSoftwareClipMask(context, reducedClip, nullptr).asTextureProxyRef(); |
Brian Salomon | 19f0ed5 | 2017-01-06 13:54:58 -0500 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | // Verify that clip masks are freed up when the clip state that generated them goes away. |
| 1549 | DEF_GPUTEST_FOR_ALL_CONTEXTS(ClipMaskCache, reporter, ctxInfo) { |
| 1550 | // This test uses resource key tags which only function in debug builds. |
| 1551 | #ifdef SK_DEBUG |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 1552 | auto context = ctxInfo.directContext(); |
Brian Salomon | 19f0ed5 | 2017-01-06 13:54:58 -0500 | [diff] [blame] | 1553 | SkClipStack stack; |
| 1554 | |
| 1555 | SkPath path; |
| 1556 | path.addCircle(10, 10, 8); |
| 1557 | path.addCircle(15, 15, 8); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 1558 | path.setFillType(SkPathFillType::kEvenOdd); |
Brian Salomon | 19f0ed5 | 2017-01-06 13:54:58 -0500 | [diff] [blame] | 1559 | |
Michael Ludwig | e06a897 | 2020-06-11 10:29:00 -0400 | [diff] [blame] | 1560 | SkIRect stackBounds = path.getBounds().roundOut(); |
| 1561 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 1562 | static const char* kTag = GrClipStackClip::kMaskTestTag; |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 1563 | GrResourceCache* cache = context->priv().getResourceCache(); |
Brian Salomon | 19f0ed5 | 2017-01-06 13:54:58 -0500 | [diff] [blame] | 1564 | |
| 1565 | static constexpr int kN = 5; |
| 1566 | |
| 1567 | for (int i = 0; i < kN; ++i) { |
| 1568 | SkMatrix m; |
| 1569 | m.setTranslate(0.5, 0.5); |
| 1570 | stack.save(); |
| 1571 | stack.clipPath(path, m, SkClipOp::kIntersect, true); |
Michael Ludwig | e06a897 | 2020-06-11 10:29:00 -0400 | [diff] [blame] | 1572 | sk_sp<GrTextureProxy> mask = |
| 1573 | GrClipStackClip(stackBounds.size(), &stack).testingOnly_createClipMask(context); |
Adlai Holler | cc25d53 | 2021-02-10 13:58:34 +0000 | [diff] [blame] | 1574 | mask->instantiate(context->priv().resourceProvider()); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 1575 | GrTexture* tex = mask->peekTexture(); |
Robert Phillips | 875218e | 2017-02-24 08:37:13 -0500 | [diff] [blame] | 1576 | REPORTER_ASSERT(reporter, 0 == strcmp(tex->getUniqueKey().tag(), kTag)); |
Brian Salomon | 19f0ed5 | 2017-01-06 13:54:58 -0500 | [diff] [blame] | 1577 | // Make sure mask isn't pinned in cache. |
| 1578 | mask.reset(nullptr); |
Greg Daniel | 0a2464f | 2020-05-14 15:45:44 -0400 | [diff] [blame] | 1579 | context->flushAndSubmit(); |
Brian Salomon | 19f0ed5 | 2017-01-06 13:54:58 -0500 | [diff] [blame] | 1580 | REPORTER_ASSERT(reporter, i + 1 == cache->countUniqueKeysWithTag(kTag)); |
| 1581 | } |
| 1582 | |
| 1583 | for (int i = 0; i < kN; ++i) { |
| 1584 | stack.restore(); |
| 1585 | cache->purgeAsNeeded(); |
| 1586 | REPORTER_ASSERT(reporter, kN - (i + 1) == cache->countUniqueKeysWithTag(kTag)); |
| 1587 | } |
| 1588 | #endif |
| 1589 | } |
Robert Phillips | 8faa340 | 2021-04-05 14:01:36 -0400 | [diff] [blame] | 1590 | #endif // SK_DISABLE_NEW_GR_CLIP_STACK |