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