bsalomon@google.com | 170bd79 | 2012-12-05 22:26:11 +0000 | [diff] [blame] | 1 | /* |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 2 | * Copyright 2016 Google Inc. |
bsalomon@google.com | 170bd79 | 2012-12-05 22:26:11 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/core/SkClipOpPriv.h" |
| 9 | #include "src/gpu/GrAppliedClip.h" |
| 10 | #include "src/gpu/GrClip.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 11 | #include "src/gpu/GrColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/gpu/GrDrawingManager.h" |
| 13 | #include "src/gpu/GrFixedClip.h" |
| 14 | #include "src/gpu/GrPathRenderer.h" |
| 15 | #include "src/gpu/GrRecordingContextPriv.h" |
| 16 | #include "src/gpu/GrReducedClip.h" |
| 17 | #include "src/gpu/GrRenderTargetContext.h" |
| 18 | #include "src/gpu/GrRenderTargetContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrStencilClip.h" |
| 20 | #include "src/gpu/GrStencilSettings.h" |
| 21 | #include "src/gpu/GrStyle.h" |
| 22 | #include "src/gpu/GrUserStencilSettings.h" |
| 23 | #include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h" |
| 24 | #include "src/gpu/effects/GrConvexPolyEffect.h" |
| 25 | #include "src/gpu/effects/GrRRectEffect.h" |
| 26 | #include "src/gpu/effects/generated/GrAARectEffect.h" |
Michael Ludwig | 663afe5 | 2019-06-03 16:46:19 -0400 | [diff] [blame] | 27 | #include "src/gpu/geometry/GrShape.h" |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 28 | |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 29 | /** |
| 30 | * There are plenty of optimizations that could be added here. Maybe flips could be folded into |
| 31 | * earlier operations. Or would inserting flips and reversing earlier ops ever be a win? Perhaps |
| 32 | * for the case where the bounds are kInsideOut_BoundsType. We could restrict earlier operations |
| 33 | * based on later intersect operations, and perhaps remove intersect-rects. We could optionally |
| 34 | * take a rect in case the caller knows a bound on what is to be drawn through this clip. |
| 35 | */ |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 36 | GrReducedClip::GrReducedClip(const SkClipStack& stack, const SkRect& queryBounds, |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 37 | const GrCaps* caps, int maxWindowRectangles, int maxAnalyticFPs, |
| 38 | int maxCCPRClipPaths) |
| 39 | : fCaps(caps) |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 40 | , fMaxWindowRectangles(maxWindowRectangles) |
| 41 | , fMaxAnalyticFPs(maxAnalyticFPs) |
Chris Dalton | 1dec19a | 2018-04-27 13:05:19 -0600 | [diff] [blame] | 42 | , fMaxCCPRClipPaths(maxCCPRClipPaths) { |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 43 | SkASSERT(!queryBounds.isEmpty()); |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 44 | SkASSERT(fMaxWindowRectangles <= GrWindowRectangles::kMaxWindows); |
Chris Dalton | 1dec19a | 2018-04-27 13:05:19 -0600 | [diff] [blame] | 45 | SkASSERT(fMaxCCPRClipPaths <= fMaxAnalyticFPs); |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 46 | fHasScissor = false; |
| 47 | fAAClipRectGenID = SK_InvalidGenID; |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 48 | |
bsalomon@google.com | 170bd79 | 2012-12-05 22:26:11 +0000 | [diff] [blame] | 49 | if (stack.isWideOpen()) { |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 50 | fInitialState = InitialState::kAllIn; |
| 51 | return; |
bsalomon@google.com | 170bd79 | 2012-12-05 22:26:11 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | SkClipStack::BoundsType stackBoundsType; |
| 55 | SkRect stackBounds; |
| 56 | bool iior; |
| 57 | stack.getBounds(&stackBounds, &stackBoundsType, &iior); |
| 58 | |
Chris Dalton | 348060f | 2017-06-05 13:15:37 -0600 | [diff] [blame] | 59 | if (GrClip::IsOutsideClip(stackBounds, queryBounds)) { |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 60 | bool insideOut = SkClipStack::kInsideOut_BoundsType == stackBoundsType; |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 61 | fInitialState = insideOut ? InitialState::kAllIn : InitialState::kAllOut; |
| 62 | return; |
bsalomon@google.com | 170bd79 | 2012-12-05 22:26:11 +0000 | [diff] [blame] | 63 | } |
| 64 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 65 | if (iior) { |
| 66 | // "Is intersection of rects" means the clip is a single rect indicated by the stack bounds. |
| 67 | // This should only be true if aa/non-aa status matches among all elements. |
| 68 | SkASSERT(SkClipStack::kNormal_BoundsType == stackBoundsType); |
Robert Phillips | 9548c3b42 | 2019-01-08 12:35:43 -0500 | [diff] [blame] | 69 | |
| 70 | if (GrClip::IsInsideClip(stackBounds, queryBounds)) { |
| 71 | fInitialState = InitialState::kAllIn; |
| 72 | return; |
| 73 | } |
| 74 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 75 | SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart); |
Robert Phillips | 9548c3b42 | 2019-01-08 12:35:43 -0500 | [diff] [blame] | 76 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 77 | if (!iter.prev()->isAA() || GrClip::IsPixelAligned(stackBounds)) { |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 78 | // The clip is a non-aa rect. Here we just implement the entire thing using fScissor. |
Mike Klein | e26062a | 2017-10-31 20:56:54 +0000 | [diff] [blame] | 79 | stackBounds.round(&fScissor); |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 80 | fHasScissor = true; |
| 81 | fInitialState = fScissor.isEmpty() ? InitialState::kAllOut : InitialState::kAllIn; |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 82 | return; |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 83 | } |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 84 | |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 85 | SkRect tightBounds; |
| 86 | SkAssertResult(tightBounds.intersect(stackBounds, queryBounds)); |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 87 | fScissor = GrClip::GetPixelIBounds(tightBounds); |
| 88 | if (fScissor.isEmpty()) { |
Chris Dalton | 348060f | 2017-06-05 13:15:37 -0600 | [diff] [blame] | 89 | fInitialState = InitialState::kAllOut; |
| 90 | return; |
| 91 | } |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 92 | fHasScissor = true; |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 93 | |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 94 | fAAClipRect = stackBounds; |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 95 | fAAClipRectGenID = stack.getTopmostGenID(); |
| 96 | SkASSERT(SK_InvalidGenID != fAAClipRectGenID); |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 97 | |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 98 | fInitialState = InitialState::kAllIn; |
| 99 | } else { |
| 100 | SkRect tighterQuery = queryBounds; |
| 101 | if (SkClipStack::kNormal_BoundsType == stackBoundsType) { |
| 102 | // Tighten the query by introducing a new clip at the stack's pixel boundaries. (This |
| 103 | // new clip will be enforced by the scissor.) |
| 104 | SkAssertResult(tighterQuery.intersect(GrClip::GetPixelBounds(stackBounds))); |
| 105 | } |
| 106 | |
| 107 | fScissor = GrClip::GetPixelIBounds(tighterQuery); |
| 108 | if (fScissor.isEmpty()) { |
| 109 | fInitialState = InitialState::kAllOut; |
| 110 | return; |
| 111 | } |
| 112 | fHasScissor = true; |
| 113 | |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 114 | // Now that we have determined the bounds to use and filtered out the trivial cases, call |
| 115 | // the helper that actually walks the stack. |
| 116 | this->walkStack(stack, tighterQuery); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 119 | if (SK_InvalidGenID != fAAClipRectGenID && // Is there an AA clip rect? |
| 120 | ClipResult::kNotClipped == this->addAnalyticFP(fAAClipRect, Invert::kNo, GrAA::kYes)) { |
| 121 | if (fMaskElements.isEmpty()) { |
| 122 | // Use a replace since it is faster than intersect. |
| 123 | fMaskElements.addToHead(fAAClipRect, SkMatrix::I(), kReplace_SkClipOp, true /*doAA*/); |
| 124 | fInitialState = InitialState::kAllOut; |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 125 | } else { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 126 | fMaskElements.addToTail(fAAClipRect, SkMatrix::I(), kIntersect_SkClipOp, true /*doAA*/); |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 127 | } |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 128 | fMaskRequiresAA = true; |
| 129 | fMaskGenID = fAAClipRectGenID; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 130 | } |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 133 | void GrReducedClip::walkStack(const SkClipStack& stack, const SkRect& queryBounds) { |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 134 | // walk backwards until we get to: |
| 135 | // a) the beginning |
| 136 | // b) an operation that is known to make the bounds all inside/outside |
| 137 | // c) a replace operation |
| 138 | |
| 139 | enum class InitialTriState { |
| 140 | kUnknown = -1, |
| 141 | kAllIn = (int)GrReducedClip::InitialState::kAllIn, |
| 142 | kAllOut = (int)GrReducedClip::InitialState::kAllOut |
| 143 | } initialTriState = InitialTriState::kUnknown; |
| 144 | |
| 145 | // During our backwards walk, track whether we've seen ops that either grow or shrink the clip. |
| 146 | // TODO: track these per saved clip so that we can consider them on the forward pass. |
| 147 | bool embiggens = false; |
| 148 | bool emsmallens = false; |
| 149 | |
| 150 | // We use a slightly relaxed set of query bounds for element containment tests. This is to |
| 151 | // account for floating point rounding error that may have occurred during coord transforms. |
| 152 | SkRect relaxedQueryBounds = queryBounds.makeInset(GrClip::kBoundsTolerance, |
| 153 | GrClip::kBoundsTolerance); |
Chris Dalton | 6982400 | 2017-10-31 00:37:52 -0600 | [diff] [blame] | 154 | if (relaxedQueryBounds.isEmpty()) { |
| 155 | relaxedQueryBounds = queryBounds; |
| 156 | } |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 157 | |
| 158 | SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart); |
| 159 | int numAAElements = 0; |
| 160 | while (InitialTriState::kUnknown == initialTriState) { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 161 | const Element* element = iter.prev(); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 162 | if (nullptr == element) { |
| 163 | initialTriState = InitialTriState::kAllIn; |
| 164 | break; |
| 165 | } |
| 166 | if (SkClipStack::kEmptyGenID == element->getGenID()) { |
| 167 | initialTriState = InitialTriState::kAllOut; |
| 168 | break; |
| 169 | } |
| 170 | if (SkClipStack::kWideOpenGenID == element->getGenID()) { |
| 171 | initialTriState = InitialTriState::kAllIn; |
| 172 | break; |
| 173 | } |
| 174 | |
| 175 | bool skippable = false; |
| 176 | bool isFlip = false; // does this op just flip the in/out state of every point in the bounds |
| 177 | |
| 178 | switch (element->getOp()) { |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 179 | case kDifference_SkClipOp: |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 180 | // check if the shape subtracted either contains the entire bounds (and makes |
| 181 | // the clip empty) or is outside the bounds and therefore can be skipped. |
| 182 | if (element->isInverseFilled()) { |
| 183 | if (element->contains(relaxedQueryBounds)) { |
| 184 | skippable = true; |
| 185 | } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) { |
| 186 | initialTriState = InitialTriState::kAllOut; |
| 187 | skippable = true; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 188 | } else if (!embiggens) { |
| 189 | ClipResult result = this->clipInsideElement(element); |
| 190 | if (ClipResult::kMadeEmpty == result) { |
| 191 | return; |
| 192 | } |
| 193 | skippable = (ClipResult::kClipped == result); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 194 | } |
| 195 | } else { |
| 196 | if (element->contains(relaxedQueryBounds)) { |
| 197 | initialTriState = InitialTriState::kAllOut; |
| 198 | skippable = true; |
| 199 | } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) { |
| 200 | skippable = true; |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 201 | } else if (!embiggens) { |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 202 | ClipResult result = this->clipOutsideElement(element); |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 203 | if (ClipResult::kMadeEmpty == result) { |
| 204 | return; |
| 205 | } |
| 206 | skippable = (ClipResult::kClipped == result); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | if (!skippable) { |
| 210 | emsmallens = true; |
| 211 | } |
| 212 | break; |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 213 | case kIntersect_SkClipOp: |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 214 | // check if the shape intersected contains the entire bounds and therefore can |
| 215 | // be skipped or it is outside the entire bounds and therefore makes the clip |
| 216 | // empty. |
| 217 | if (element->isInverseFilled()) { |
| 218 | if (element->contains(relaxedQueryBounds)) { |
| 219 | initialTriState = InitialTriState::kAllOut; |
| 220 | skippable = true; |
| 221 | } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) { |
| 222 | skippable = true; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 223 | } else if (!embiggens) { |
| 224 | ClipResult result = this->clipOutsideElement(element); |
| 225 | if (ClipResult::kMadeEmpty == result) { |
| 226 | return; |
| 227 | } |
| 228 | skippable = (ClipResult::kClipped == result); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 229 | } |
| 230 | } else { |
| 231 | if (element->contains(relaxedQueryBounds)) { |
| 232 | skippable = true; |
| 233 | } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) { |
| 234 | initialTriState = InitialTriState::kAllOut; |
| 235 | skippable = true; |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 236 | } else if (!embiggens) { |
| 237 | ClipResult result = this->clipInsideElement(element); |
| 238 | if (ClipResult::kMadeEmpty == result) { |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 239 | return; |
| 240 | } |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 241 | skippable = (ClipResult::kClipped == result); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | if (!skippable) { |
| 245 | emsmallens = true; |
| 246 | } |
| 247 | break; |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 248 | case kUnion_SkClipOp: |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 249 | // If the union-ed shape contains the entire bounds then after this element |
| 250 | // the bounds is entirely inside the clip. If the union-ed shape is outside the |
| 251 | // bounds then this op can be skipped. |
| 252 | if (element->isInverseFilled()) { |
| 253 | if (element->contains(relaxedQueryBounds)) { |
| 254 | skippable = true; |
| 255 | } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) { |
| 256 | initialTriState = InitialTriState::kAllIn; |
| 257 | skippable = true; |
| 258 | } |
| 259 | } else { |
| 260 | if (element->contains(relaxedQueryBounds)) { |
| 261 | initialTriState = InitialTriState::kAllIn; |
| 262 | skippable = true; |
| 263 | } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) { |
| 264 | skippable = true; |
| 265 | } |
| 266 | } |
| 267 | if (!skippable) { |
| 268 | embiggens = true; |
| 269 | } |
| 270 | break; |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 271 | case kXOR_SkClipOp: |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 272 | // If the bounds is entirely inside the shape being xor-ed then the effect is |
| 273 | // to flip the inside/outside state of every point in the bounds. We may be |
| 274 | // able to take advantage of this in the forward pass. If the xor-ed shape |
| 275 | // doesn't intersect the bounds then it can be skipped. |
| 276 | if (element->isInverseFilled()) { |
| 277 | if (element->contains(relaxedQueryBounds)) { |
| 278 | skippable = true; |
| 279 | } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) { |
| 280 | isFlip = true; |
| 281 | } |
| 282 | } else { |
| 283 | if (element->contains(relaxedQueryBounds)) { |
| 284 | isFlip = true; |
| 285 | } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) { |
| 286 | skippable = true; |
| 287 | } |
| 288 | } |
| 289 | if (!skippable) { |
| 290 | emsmallens = embiggens = true; |
| 291 | } |
| 292 | break; |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 293 | case kReverseDifference_SkClipOp: |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 294 | // When the bounds is entirely within the rev-diff shape then this behaves like xor |
| 295 | // and reverses every point inside the bounds. If the shape is completely outside |
| 296 | // the bounds then we know after this element is applied that the bounds will be |
| 297 | // all outside the current clip.B |
| 298 | if (element->isInverseFilled()) { |
| 299 | if (element->contains(relaxedQueryBounds)) { |
| 300 | initialTriState = InitialTriState::kAllOut; |
| 301 | skippable = true; |
| 302 | } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) { |
| 303 | isFlip = true; |
| 304 | } |
| 305 | } else { |
| 306 | if (element->contains(relaxedQueryBounds)) { |
| 307 | isFlip = true; |
| 308 | } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) { |
| 309 | initialTriState = InitialTriState::kAllOut; |
| 310 | skippable = true; |
| 311 | } |
| 312 | } |
| 313 | if (!skippable) { |
| 314 | emsmallens = embiggens = true; |
| 315 | } |
| 316 | break; |
| 317 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 318 | case kReplace_SkClipOp: |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 319 | // Replace will always terminate our walk. We will either begin the forward walk |
| 320 | // at the replace op or detect here than the shape is either completely inside |
| 321 | // or completely outside the bounds. In this latter case it can be skipped by |
| 322 | // setting the correct value for initialTriState. |
| 323 | if (element->isInverseFilled()) { |
| 324 | if (element->contains(relaxedQueryBounds)) { |
| 325 | initialTriState = InitialTriState::kAllOut; |
| 326 | skippable = true; |
| 327 | } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) { |
| 328 | initialTriState = InitialTriState::kAllIn; |
| 329 | skippable = true; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 330 | } else if (!embiggens) { |
| 331 | ClipResult result = this->clipOutsideElement(element); |
| 332 | if (ClipResult::kMadeEmpty == result) { |
| 333 | return; |
| 334 | } |
| 335 | if (ClipResult::kClipped == result) { |
| 336 | initialTriState = InitialTriState::kAllIn; |
| 337 | skippable = true; |
| 338 | } |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 339 | } |
| 340 | } else { |
| 341 | if (element->contains(relaxedQueryBounds)) { |
| 342 | initialTriState = InitialTriState::kAllIn; |
| 343 | skippable = true; |
| 344 | } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) { |
| 345 | initialTriState = InitialTriState::kAllOut; |
| 346 | skippable = true; |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 347 | } else if (!embiggens) { |
| 348 | ClipResult result = this->clipInsideElement(element); |
| 349 | if (ClipResult::kMadeEmpty == result) { |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 350 | return; |
| 351 | } |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 352 | if (ClipResult::kClipped == result) { |
| 353 | initialTriState = InitialTriState::kAllIn; |
| 354 | skippable = true; |
| 355 | } |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | if (!skippable) { |
| 359 | initialTriState = InitialTriState::kAllOut; |
| 360 | embiggens = emsmallens = true; |
| 361 | } |
| 362 | break; |
| 363 | default: |
| 364 | SkDEBUGFAIL("Unexpected op."); |
| 365 | break; |
| 366 | } |
| 367 | if (!skippable) { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 368 | if (fMaskElements.isEmpty()) { |
| 369 | // This will be the last element. Record the stricter genID. |
| 370 | fMaskGenID = element->getGenID(); |
| 371 | } |
| 372 | |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 373 | // if it is a flip, change it to a bounds-filling rect |
| 374 | if (isFlip) { |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 375 | SkASSERT(kXOR_SkClipOp == element->getOp() || |
| 376 | kReverseDifference_SkClipOp == element->getOp()); |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 377 | fMaskElements.addToHead(SkRect::Make(fScissor), SkMatrix::I(), |
| 378 | kReverseDifference_SkClipOp, false); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 379 | } else { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 380 | Element* newElement = fMaskElements.addToHead(*element); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 381 | if (newElement->isAA()) { |
| 382 | ++numAAElements; |
| 383 | } |
| 384 | // Intersecting an inverse shape is the same as differencing the non-inverse shape. |
| 385 | // Replacing with an inverse shape is the same as setting initialState=kAllIn and |
| 386 | // differencing the non-inverse shape. |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 387 | bool isReplace = kReplace_SkClipOp == newElement->getOp(); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 388 | if (newElement->isInverseFilled() && |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 389 | (kIntersect_SkClipOp == newElement->getOp() || isReplace)) { |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 390 | newElement->invertShapeFillType(); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 391 | newElement->setOp(kDifference_SkClipOp); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 392 | if (isReplace) { |
| 393 | SkASSERT(InitialTriState::kAllOut == initialTriState); |
| 394 | initialTriState = InitialTriState::kAllIn; |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | if ((InitialTriState::kAllOut == initialTriState && !embiggens) || |
| 402 | (InitialTriState::kAllIn == initialTriState && !emsmallens)) { |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 403 | fMaskElements.reset(); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 404 | numAAElements = 0; |
| 405 | } else { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 406 | Element* element = fMaskElements.headIter().get(); |
| 407 | while (element) { |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 408 | bool skippable = false; |
| 409 | switch (element->getOp()) { |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 410 | case kDifference_SkClipOp: |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 411 | // subtracting from the empty set yields the empty set. |
| 412 | skippable = InitialTriState::kAllOut == initialTriState; |
| 413 | break; |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 414 | case kIntersect_SkClipOp: |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 415 | // intersecting with the empty set yields the empty set |
| 416 | if (InitialTriState::kAllOut == initialTriState) { |
| 417 | skippable = true; |
| 418 | } else { |
| 419 | // We can clear to zero and then simply draw the clip element. |
| 420 | initialTriState = InitialTriState::kAllOut; |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 421 | element->setOp(kReplace_SkClipOp); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 422 | } |
| 423 | break; |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 424 | case kUnion_SkClipOp: |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 425 | if (InitialTriState::kAllIn == initialTriState) { |
| 426 | // unioning the infinite plane with anything is a no-op. |
| 427 | skippable = true; |
| 428 | } else { |
| 429 | // unioning the empty set with a shape is the shape. |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 430 | element->setOp(kReplace_SkClipOp); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 431 | } |
| 432 | break; |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 433 | case kXOR_SkClipOp: |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 434 | if (InitialTriState::kAllOut == initialTriState) { |
| 435 | // xor could be changed to diff in the kAllIn case, not sure it's a win. |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 436 | element->setOp(kReplace_SkClipOp); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 437 | } |
| 438 | break; |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 439 | case kReverseDifference_SkClipOp: |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 440 | if (InitialTriState::kAllIn == initialTriState) { |
| 441 | // subtracting the whole plane will yield the empty set. |
| 442 | skippable = true; |
| 443 | initialTriState = InitialTriState::kAllOut; |
| 444 | } else { |
| 445 | // this picks up flips inserted in the backwards pass. |
| 446 | skippable = element->isInverseFilled() ? |
| 447 | GrClip::IsOutsideClip(element->getBounds(), queryBounds) : |
| 448 | element->contains(relaxedQueryBounds); |
| 449 | if (skippable) { |
| 450 | initialTriState = InitialTriState::kAllIn; |
| 451 | } else { |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 452 | element->setOp(kReplace_SkClipOp); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | break; |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 456 | case kReplace_SkClipOp: |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 457 | skippable = false; // we would have skipped it in the backwards walk if we |
| 458 | // could've. |
| 459 | break; |
| 460 | default: |
| 461 | SkDEBUGFAIL("Unexpected op."); |
| 462 | break; |
| 463 | } |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 464 | if (!skippable) { |
| 465 | break; |
| 466 | } else { |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 467 | if (element->isAA()) { |
| 468 | --numAAElements; |
| 469 | } |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 470 | fMaskElements.popHead(); |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 471 | element = fMaskElements.headIter().get(); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | } |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 475 | fMaskRequiresAA = numAAElements > 0; |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 476 | |
| 477 | SkASSERT(InitialTriState::kUnknown != initialTriState); |
| 478 | fInitialState = static_cast<GrReducedClip::InitialState>(initialTriState); |
| 479 | } |
| 480 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 481 | GrReducedClip::ClipResult GrReducedClip::clipInsideElement(const Element* element) { |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 482 | SkIRect elementIBounds; |
| 483 | if (!element->isAA()) { |
| 484 | element->getBounds().round(&elementIBounds); |
| 485 | } else { |
| 486 | elementIBounds = GrClip::GetPixelIBounds(element->getBounds()); |
| 487 | } |
| 488 | SkASSERT(fHasScissor); |
| 489 | if (!fScissor.intersect(elementIBounds)) { |
| 490 | this->makeEmpty(); |
| 491 | return ClipResult::kMadeEmpty; |
| 492 | } |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 493 | |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 494 | switch (element->getDeviceSpaceType()) { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 495 | case Element::DeviceSpaceType::kEmpty: |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 496 | return ClipResult::kMadeEmpty; |
| 497 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 498 | case Element::DeviceSpaceType::kRect: |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 499 | SkASSERT(element->getBounds() == element->getDeviceSpaceRect()); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 500 | SkASSERT(!element->isInverseFilled()); |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 501 | if (element->isAA()) { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 502 | if (SK_InvalidGenID == fAAClipRectGenID) { // No AA clip rect yet? |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 503 | fAAClipRect = element->getDeviceSpaceRect(); |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 504 | // fAAClipRectGenID is the value we should use for fMaskGenID if we end up |
| 505 | // moving the AA clip rect into the mask. The mask GenID is simply the topmost |
| 506 | // element's GenID. And since we walk the stack backwards, this means it's just |
| 507 | // the first element we don't skip during our walk. |
| 508 | fAAClipRectGenID = fMaskElements.isEmpty() ? element->getGenID() : fMaskGenID; |
| 509 | SkASSERT(SK_InvalidGenID != fAAClipRectGenID); |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 510 | } else if (!fAAClipRect.intersect(element->getDeviceSpaceRect())) { |
| 511 | this->makeEmpty(); |
| 512 | return ClipResult::kMadeEmpty; |
| 513 | } |
| 514 | } |
| 515 | return ClipResult::kClipped; |
| 516 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 517 | case Element::DeviceSpaceType::kRRect: |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 518 | SkASSERT(!element->isInverseFilled()); |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 519 | return this->addAnalyticFP(element->getDeviceSpaceRRect(), Invert::kNo, |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 520 | GrAA(element->isAA())); |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 521 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 522 | case Element::DeviceSpaceType::kPath: |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 523 | return this->addAnalyticFP(element->getDeviceSpacePath(), |
| 524 | Invert(element->isInverseFilled()), GrAA(element->isAA())); |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | SK_ABORT("Unexpected DeviceSpaceType"); |
| 528 | return ClipResult::kNotClipped; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 531 | GrReducedClip::ClipResult GrReducedClip::clipOutsideElement(const Element* element) { |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 532 | switch (element->getDeviceSpaceType()) { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 533 | case Element::DeviceSpaceType::kEmpty: |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 534 | return ClipResult::kMadeEmpty; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 535 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 536 | case Element::DeviceSpaceType::kRect: |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 537 | SkASSERT(!element->isInverseFilled()); |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 538 | if (fWindowRects.count() < fMaxWindowRectangles) { |
| 539 | // Clip out the inside of every rect. We won't be able to entirely skip the AA ones, |
| 540 | // but it saves processing time. |
| 541 | this->addWindowRectangle(element->getDeviceSpaceRect(), element->isAA()); |
| 542 | if (!element->isAA()) { |
| 543 | return ClipResult::kClipped; |
| 544 | } |
| 545 | } |
| 546 | return this->addAnalyticFP(element->getDeviceSpaceRect(), Invert::kYes, |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 547 | GrAA(element->isAA())); |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 548 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 549 | case Element::DeviceSpaceType::kRRect: { |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 550 | SkASSERT(!element->isInverseFilled()); |
Brian Osman | 554c1f0 | 2017-11-16 13:56:47 +0000 | [diff] [blame] | 551 | const SkRRect& clipRRect = element->getDeviceSpaceRRect(); |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 552 | ClipResult clipResult = this->addAnalyticFP(clipRRect, Invert::kYes, |
| 553 | GrAA(element->isAA())); |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 554 | if (fWindowRects.count() >= fMaxWindowRectangles) { |
| 555 | return clipResult; |
| 556 | } |
| 557 | |
| 558 | // Clip out the interiors of round rects with two window rectangles in the shape of a |
| 559 | // "plus". This doesn't let us skip the clip element, but still saves processing time. |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 560 | SkVector insetTL = clipRRect.radii(SkRRect::kUpperLeft_Corner); |
| 561 | SkVector insetBR = clipRRect.radii(SkRRect::kLowerRight_Corner); |
| 562 | if (SkRRect::kComplex_Type == clipRRect.getType()) { |
| 563 | const SkVector& insetTR = clipRRect.radii(SkRRect::kUpperRight_Corner); |
| 564 | const SkVector& insetBL = clipRRect.radii(SkRRect::kLowerLeft_Corner); |
| 565 | insetTL.fX = SkTMax(insetTL.x(), insetBL.x()); |
| 566 | insetTL.fY = SkTMax(insetTL.y(), insetTR.y()); |
| 567 | insetBR.fX = SkTMax(insetBR.x(), insetTR.x()); |
| 568 | insetBR.fY = SkTMax(insetBR.y(), insetBL.y()); |
| 569 | } |
| 570 | const SkRect& bounds = clipRRect.getBounds(); |
| 571 | if (insetTL.x() + insetBR.x() >= bounds.width() || |
| 572 | insetTL.y() + insetBR.y() >= bounds.height()) { |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 573 | return clipResult; // The interior "plus" is empty. |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | SkRect horzRect = SkRect::MakeLTRB(bounds.left(), bounds.top() + insetTL.y(), |
| 577 | bounds.right(), bounds.bottom() - insetBR.y()); |
| 578 | this->addWindowRectangle(horzRect, element->isAA()); |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 579 | |
| 580 | if (fWindowRects.count() < fMaxWindowRectangles) { |
| 581 | SkRect vertRect = SkRect::MakeLTRB(bounds.left() + insetTL.x(), bounds.top(), |
| 582 | bounds.right() - insetBR.x(), bounds.bottom()); |
| 583 | this->addWindowRectangle(vertRect, element->isAA()); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 586 | return clipResult; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 587 | } |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 588 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 589 | case Element::DeviceSpaceType::kPath: |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 590 | return this->addAnalyticFP(element->getDeviceSpacePath(), |
| 591 | Invert(!element->isInverseFilled()), GrAA(element->isAA())); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 592 | } |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 593 | |
| 594 | SK_ABORT("Unexpected DeviceSpaceType"); |
| 595 | return ClipResult::kNotClipped; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | inline void GrReducedClip::addWindowRectangle(const SkRect& elementInteriorRect, bool elementIsAA) { |
| 599 | SkIRect window; |
| 600 | if (!elementIsAA) { |
| 601 | elementInteriorRect.round(&window); |
| 602 | } else { |
| 603 | elementInteriorRect.roundIn(&window); |
| 604 | } |
| 605 | if (!window.isEmpty()) { // Skip very thin windows that round to zero or negative dimensions. |
| 606 | fWindowRects.addWindow(window); |
| 607 | } |
| 608 | } |
| 609 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 610 | GrClipEdgeType GrReducedClip::GetClipEdgeType(Invert invert, GrAA aa) { |
| 611 | if (Invert::kNo == invert) { |
| 612 | return (GrAA::kYes == aa) ? GrClipEdgeType::kFillAA : GrClipEdgeType::kFillBW; |
| 613 | } else { |
| 614 | return (GrAA::kYes == aa) ? GrClipEdgeType::kInverseFillAA : GrClipEdgeType::kInverseFillBW; |
| 615 | } |
| 616 | } |
| 617 | |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 618 | GrReducedClip::ClipResult GrReducedClip::addAnalyticFP(const SkRect& deviceSpaceRect, |
| 619 | Invert invert, GrAA aa) { |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 620 | if (this->numAnalyticFPs() >= fMaxAnalyticFPs) { |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 621 | return ClipResult::kNotClipped; |
| 622 | } |
| 623 | |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 624 | fAnalyticFPs.push_back(GrAARectEffect::Make(GetClipEdgeType(invert, aa), deviceSpaceRect)); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 625 | SkASSERT(fAnalyticFPs.back()); |
| 626 | |
| 627 | return ClipResult::kClipped; |
| 628 | } |
| 629 | |
| 630 | GrReducedClip::ClipResult GrReducedClip::addAnalyticFP(const SkRRect& deviceSpaceRRect, |
| 631 | Invert invert, GrAA aa) { |
| 632 | if (this->numAnalyticFPs() >= fMaxAnalyticFPs) { |
| 633 | return ClipResult::kNotClipped; |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 634 | } |
| 635 | |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 636 | if (auto fp = GrRRectEffect::Make(GetClipEdgeType(invert, aa), deviceSpaceRRect, |
| 637 | *fCaps->shaderCaps())) { |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 638 | fAnalyticFPs.push_back(std::move(fp)); |
| 639 | return ClipResult::kClipped; |
| 640 | } |
| 641 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 642 | SkPath deviceSpacePath; |
| 643 | deviceSpacePath.setIsVolatile(true); |
| 644 | deviceSpacePath.addRRect(deviceSpaceRRect); |
| 645 | return this->addAnalyticFP(deviceSpacePath, invert, aa); |
| 646 | } |
| 647 | |
| 648 | GrReducedClip::ClipResult GrReducedClip::addAnalyticFP(const SkPath& deviceSpacePath, |
| 649 | Invert invert, GrAA aa) { |
| 650 | if (this->numAnalyticFPs() >= fMaxAnalyticFPs) { |
| 651 | return ClipResult::kNotClipped; |
| 652 | } |
| 653 | |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 654 | if (auto fp = GrConvexPolyEffect::Make(GetClipEdgeType(invert, aa), deviceSpacePath)) { |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 655 | fAnalyticFPs.push_back(std::move(fp)); |
| 656 | return ClipResult::kClipped; |
| 657 | } |
| 658 | |
Chris Dalton | 1dec19a | 2018-04-27 13:05:19 -0600 | [diff] [blame] | 659 | if (fCCPRClipPaths.count() < fMaxCCPRClipPaths && GrAA::kYes == aa) { |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 660 | // Set aside CCPR paths for later. We will create their clip FPs once we know the ID of the |
| 661 | // opList they will operate in. |
| 662 | SkPath& ccprClipPath = fCCPRClipPaths.push_back(deviceSpacePath); |
| 663 | if (Invert::kYes == invert) { |
| 664 | ccprClipPath.toggleInverseFillType(); |
| 665 | } |
| 666 | return ClipResult::kClipped; |
| 667 | } |
| 668 | |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 669 | return ClipResult::kNotClipped; |
| 670 | } |
| 671 | |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 672 | void GrReducedClip::makeEmpty() { |
| 673 | fHasScissor = false; |
| 674 | fAAClipRectGenID = SK_InvalidGenID; |
| 675 | fWindowRects.reset(); |
| 676 | fMaskElements.reset(); |
| 677 | fInitialState = InitialState::kAllOut; |
bsalomon@google.com | 34cd70a | 2012-12-06 14:23:20 +0000 | [diff] [blame] | 678 | } |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 679 | |
| 680 | //////////////////////////////////////////////////////////////////////////////// |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 681 | // Create a 8-bit clip mask in alpha |
| 682 | |
| 683 | static bool stencil_element(GrRenderTargetContext* rtc, |
| 684 | const GrFixedClip& clip, |
| 685 | const GrUserStencilSettings* ss, |
| 686 | const SkMatrix& viewMatrix, |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 687 | const SkClipStack::Element* element) { |
| 688 | GrAA aa = GrAA(element->isAA()); |
| 689 | switch (element->getDeviceSpaceType()) { |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 690 | case SkClipStack::Element::DeviceSpaceType::kEmpty: |
| 691 | SkDEBUGFAIL("Should never get here with an empty element."); |
| 692 | break; |
Michael Ludwig | aa1b6b3 | 2019-05-29 14:43:13 -0400 | [diff] [blame] | 693 | case SkClipStack::Element::DeviceSpaceType::kRect: { |
| 694 | GrPaint paint; |
| 695 | paint.setCoverageSetOpXPFactory((SkRegion::Op)element->getOp(), |
| 696 | element->isInverseFilled()); |
| 697 | rtc->priv().stencilRect(clip, ss, std::move(paint), aa, viewMatrix, |
| 698 | element->getDeviceSpaceRect()); |
| 699 | return true; |
| 700 | } |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 701 | default: { |
| 702 | SkPath path; |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 703 | element->asDeviceSpacePath(&path); |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 704 | if (path.isInverseFillType()) { |
| 705 | path.toggleInverseFillType(); |
| 706 | } |
| 707 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 708 | return rtc->priv().drawAndStencilPath(clip, ss, (SkRegion::Op)element->getOp(), |
| 709 | element->isInverseFilled(), aa, viewMatrix, path); |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | |
| 713 | return false; |
| 714 | } |
| 715 | |
Michael Ludwig | aa1b6b3 | 2019-05-29 14:43:13 -0400 | [diff] [blame] | 716 | static void stencil_device_rect(GrRenderTargetContext* rtc, |
| 717 | const GrHardClip& clip, |
| 718 | const GrUserStencilSettings* ss, |
| 719 | GrAA aa, |
| 720 | const SkRect& rect) { |
| 721 | GrPaint paint; |
| 722 | paint.setXPFactory(GrDisableColorXPFactory::Get()); |
| 723 | rtc->priv().stencilRect(clip, ss, std::move(paint), aa, SkMatrix::I(), rect); |
| 724 | } |
| 725 | |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 726 | static void draw_element(GrRenderTargetContext* rtc, |
| 727 | const GrClip& clip, // TODO: can this just always be WideOpen? |
| 728 | GrPaint&& paint, |
| 729 | GrAA aa, |
| 730 | const SkMatrix& viewMatrix, |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 731 | const SkClipStack::Element* element) { |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 732 | // TODO: Draw rrects directly here. |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 733 | switch (element->getDeviceSpaceType()) { |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 734 | case SkClipStack::Element::DeviceSpaceType::kEmpty: |
| 735 | SkDEBUGFAIL("Should never get here with an empty element."); |
| 736 | break; |
| 737 | case SkClipStack::Element::DeviceSpaceType::kRect: |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 738 | rtc->drawRect(clip, std::move(paint), aa, viewMatrix, element->getDeviceSpaceRect()); |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 739 | break; |
| 740 | default: { |
| 741 | SkPath path; |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 742 | element->asDeviceSpacePath(&path); |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 743 | if (path.isInverseFillType()) { |
| 744 | path.toggleInverseFillType(); |
| 745 | } |
| 746 | |
| 747 | rtc->drawPath(clip, std::move(paint), aa, viewMatrix, path, GrStyle::SimpleFill()); |
| 748 | break; |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | bool GrReducedClip::drawAlphaClipMask(GrRenderTargetContext* rtc) const { |
| 754 | // The texture may be larger than necessary, this rect represents the part of the texture |
| 755 | // we populate with a rasterization of the clip. |
| 756 | GrFixedClip clip(SkIRect::MakeWH(fScissor.width(), fScissor.height())); |
| 757 | |
| 758 | if (!fWindowRects.empty()) { |
| 759 | clip.setWindowRectangles(fWindowRects.makeOffset(-fScissor.left(), -fScissor.top()), |
| 760 | GrWindowRectsState::Mode::kExclusive); |
| 761 | } |
| 762 | |
| 763 | // The scratch texture that we are drawing into can be substantially larger than the mask. Only |
| 764 | // clear the part that we care about. |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 765 | SkPMColor4f initialCoverage = |
| 766 | InitialState::kAllIn == this->initialState() ? SK_PMColor4fWHITE : SK_PMColor4fTRANSPARENT; |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 767 | rtc->priv().clear(clip, initialCoverage, GrRenderTargetContext::CanClearFullscreen::kYes); |
| 768 | |
| 769 | // Set the matrix so that rendered clip elements are transformed to mask space from clip space. |
| 770 | SkMatrix translate; |
| 771 | translate.setTranslate(SkIntToScalar(-fScissor.left()), SkIntToScalar(-fScissor.top())); |
| 772 | |
| 773 | // walk through each clip element and perform its set op |
| 774 | for (ElementList::Iter iter(fMaskElements); iter.get(); iter.next()) { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 775 | const Element* element = iter.get(); |
| 776 | SkRegion::Op op = (SkRegion::Op)element->getOp(); |
| 777 | GrAA aa = GrAA(element->isAA()); |
| 778 | bool invert = element->isInverseFilled(); |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 779 | if (invert || SkRegion::kIntersect_Op == op || SkRegion::kReverseDifference_Op == op) { |
| 780 | // draw directly into the result with the stencil set to make the pixels affected |
| 781 | // by the clip shape be non-zero. |
| 782 | static constexpr GrUserStencilSettings kStencilInElement( |
| 783 | GrUserStencilSettings::StaticInit< |
| 784 | 0xffff, |
| 785 | GrUserStencilTest::kAlways, |
| 786 | 0xffff, |
| 787 | GrUserStencilOp::kReplace, |
| 788 | GrUserStencilOp::kReplace, |
| 789 | 0xffff>() |
| 790 | ); |
| 791 | if (!stencil_element(rtc, clip, &kStencilInElement, translate, element)) { |
| 792 | return false; |
| 793 | } |
| 794 | |
| 795 | // Draw to the exterior pixels (those with a zero stencil value). |
| 796 | static constexpr GrUserStencilSettings kDrawOutsideElement( |
| 797 | GrUserStencilSettings::StaticInit< |
| 798 | 0x0000, |
| 799 | GrUserStencilTest::kEqual, |
| 800 | 0xffff, |
| 801 | GrUserStencilOp::kZero, |
| 802 | GrUserStencilOp::kZero, |
| 803 | 0xffff>() |
| 804 | ); |
Michael Ludwig | aa1b6b3 | 2019-05-29 14:43:13 -0400 | [diff] [blame] | 805 | |
| 806 | GrPaint paint; |
| 807 | paint.setCoverageSetOpXPFactory(op, !invert); |
| 808 | rtc->priv().stencilRect(clip, &kDrawOutsideElement, std::move(paint), GrAA::kNo, |
| 809 | translate, SkRect::Make(fScissor)); |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 810 | } else { |
| 811 | // all the remaining ops can just be directly draw into the accumulation buffer |
| 812 | GrPaint paint; |
| 813 | paint.setCoverageSetOpXPFactory(op, false); |
| 814 | |
| 815 | draw_element(rtc, clip, std::move(paint), aa, translate, element); |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | return true; |
| 820 | } |
| 821 | |
| 822 | //////////////////////////////////////////////////////////////////////////////// |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 823 | // Create a 1-bit clip mask in the stencil buffer. |
| 824 | |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 825 | bool GrReducedClip::drawStencilClipMask(GrRecordingContext* context, |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 826 | GrRenderTargetContext* renderTargetContext) const { |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 827 | // We set the current clip to the bounds so that our recursive draws are scissored to them. |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 828 | GrStencilClip stencilClip(fScissor, this->maskGenID()); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 829 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 830 | if (!fWindowRects.empty()) { |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 831 | stencilClip.fixedClip().setWindowRectangles(fWindowRects, |
| 832 | GrWindowRectsState::Mode::kExclusive); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 833 | } |
| 834 | |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 835 | bool initialState = InitialState::kAllIn == this->initialState(); |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 836 | renderTargetContext->priv().clearStencilClip(stencilClip.fixedClip(), initialState); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 837 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 838 | // walk through each clip element and perform its set op with the existing clip. |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 839 | for (ElementList::Iter iter(fMaskElements); iter.get(); iter.next()) { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 840 | const Element* element = iter.get(); |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 841 | // MIXED SAMPLES TODO: We can use stencil with mixed samples as well. |
| 842 | bool doStencilMSAA = element->isAA() && renderTargetContext->numSamples() > 1; |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 843 | // Since we are only drawing to the stencil buffer, we can use kMSAA even if the render |
| 844 | // target is mixed sampled. |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 845 | auto pathAAType = (doStencilMSAA) ? GrAAType::kMSAA : GrAAType::kNone; |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 846 | bool fillInverted = false; |
| 847 | |
| 848 | // This will be used to determine whether the clip shape can be rendered into the |
| 849 | // stencil with arbitrary stencil settings. |
| 850 | GrPathRenderer::StencilSupport stencilSupport; |
| 851 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 852 | SkRegion::Op op = (SkRegion::Op)element->getOp(); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 853 | |
| 854 | GrPathRenderer* pr = nullptr; |
| 855 | SkPath clipPath; |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 856 | if (Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()) { |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 857 | stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
| 858 | fillInverted = false; |
| 859 | } else { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 860 | element->asDeviceSpacePath(&clipPath); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 861 | fillInverted = clipPath.isInverseFillType(); |
| 862 | if (fillInverted) { |
| 863 | clipPath.toggleInverseFillType(); |
| 864 | } |
| 865 | |
| 866 | GrShape shape(clipPath, GrStyle::SimpleFill()); |
| 867 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 868 | canDrawArgs.fCaps = context->priv().caps(); |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 869 | canDrawArgs.fProxy = renderTargetContext->proxy(); |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 870 | canDrawArgs.fClipConservativeBounds = &stencilClip.fixedClip().scissorRect(); |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 871 | canDrawArgs.fViewMatrix = &SkMatrix::I(); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 872 | canDrawArgs.fShape = &shape; |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 873 | canDrawArgs.fAAType = pathAAType; |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 874 | canDrawArgs.fHasUserStencilSettings = false; |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 875 | canDrawArgs.fTargetIsWrappedVkSecondaryCB = renderTargetContext->wrapsVkSecondaryCB(); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 876 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 877 | GrDrawingManager* dm = context->priv().drawingManager(); |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 878 | pr = dm->getPathRenderer(canDrawArgs, false, GrPathRendererChain::DrawType::kStencil, |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 879 | &stencilSupport); |
| 880 | if (!pr) { |
| 881 | return false; |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | bool canRenderDirectToStencil = |
| 886 | GrPathRenderer::kNoRestriction_StencilSupport == stencilSupport; |
| 887 | bool drawDirectToClip; // Given the renderer, the element, |
| 888 | // fill rule, and set operation should |
| 889 | // we render the element directly to |
| 890 | // stencil bit used for clipping. |
| 891 | GrUserStencilSettings const* const* stencilPasses = |
| 892 | GrStencilSettings::GetClipPasses(op, canRenderDirectToStencil, fillInverted, |
| 893 | &drawDirectToClip); |
| 894 | |
| 895 | // draw the element to the client stencil bits if necessary |
| 896 | if (!drawDirectToClip) { |
| 897 | static constexpr GrUserStencilSettings kDrawToStencil( |
| 898 | GrUserStencilSettings::StaticInit< |
| 899 | 0x0000, |
| 900 | GrUserStencilTest::kAlways, |
| 901 | 0xffff, |
| 902 | GrUserStencilOp::kIncMaybeClamp, |
| 903 | GrUserStencilOp::kIncMaybeClamp, |
| 904 | 0xffff>() |
| 905 | ); |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 906 | if (Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()) { |
Michael Ludwig | aa1b6b3 | 2019-05-29 14:43:13 -0400 | [diff] [blame] | 907 | stencil_device_rect(renderTargetContext, stencilClip.fixedClip(), &kDrawToStencil, |
| 908 | GrAA(doStencilMSAA), element->getDeviceSpaceRect()); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 909 | } else { |
| 910 | if (!clipPath.isEmpty()) { |
| 911 | GrShape shape(clipPath, GrStyle::SimpleFill()); |
| 912 | if (canRenderDirectToStencil) { |
| 913 | GrPaint paint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 914 | paint.setXPFactory(GrDisableColorXPFactory::Get()); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 915 | |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 916 | GrPathRenderer::DrawPathArgs args{context, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 917 | std::move(paint), |
| 918 | &kDrawToStencil, |
| 919 | renderTargetContext, |
| 920 | &stencilClip.fixedClip(), |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 921 | &stencilClip.fixedClip().scissorRect(), |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 922 | &SkMatrix::I(), |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 923 | &shape, |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 924 | pathAAType, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 925 | false}; |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 926 | pr->drawPath(args); |
| 927 | } else { |
| 928 | GrPathRenderer::StencilPathArgs args; |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 929 | args.fContext = context; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 930 | args.fRenderTargetContext = renderTargetContext; |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 931 | args.fClip = &stencilClip.fixedClip(); |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 932 | args.fClipConservativeBounds = &stencilClip.fixedClip().scissorRect(); |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 933 | args.fViewMatrix = &SkMatrix::I(); |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 934 | args.fDoStencilMSAA = GrAA(doStencilMSAA); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 935 | args.fShape = &shape; |
| 936 | pr->stencilPath(args); |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | // now we modify the clip bit by rendering either the clip |
| 943 | // element directly or a bounding rect of the entire clip. |
| 944 | for (GrUserStencilSettings const* const* pass = stencilPasses; *pass; ++pass) { |
| 945 | if (drawDirectToClip) { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 946 | if (Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()) { |
Michael Ludwig | aa1b6b3 | 2019-05-29 14:43:13 -0400 | [diff] [blame] | 947 | stencil_device_rect(renderTargetContext, stencilClip, *pass, |
| 948 | GrAA(doStencilMSAA), element->getDeviceSpaceRect()); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 949 | } else { |
| 950 | GrShape shape(clipPath, GrStyle::SimpleFill()); |
| 951 | GrPaint paint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 952 | paint.setXPFactory(GrDisableColorXPFactory::Get()); |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 953 | GrPathRenderer::DrawPathArgs args{context, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 954 | std::move(paint), |
| 955 | *pass, |
| 956 | renderTargetContext, |
| 957 | &stencilClip, |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 958 | &stencilClip.fixedClip().scissorRect(), |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 959 | &SkMatrix::I(), |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 960 | &shape, |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 961 | pathAAType, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 962 | false}; |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 963 | pr->drawPath(args); |
| 964 | } |
| 965 | } else { |
| 966 | // The view matrix is setup to do clip space -> stencil space translation, so |
| 967 | // draw rect in clip space. |
Michael Ludwig | aa1b6b3 | 2019-05-29 14:43:13 -0400 | [diff] [blame] | 968 | stencil_device_rect(renderTargetContext, stencilClip, *pass, GrAA(doStencilMSAA), |
| 969 | SkRect::Make(fScissor)); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | } |
| 973 | return true; |
| 974 | } |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 975 | |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 976 | std::unique_ptr<GrFragmentProcessor> GrReducedClip::finishAndDetachAnalyticFPs( |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 977 | GrCoverageCountingPathRenderer* ccpr, uint32_t opListID) { |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 978 | // Make sure finishAndDetachAnalyticFPs hasn't been called already. |
| 979 | SkDEBUGCODE(for (const auto& fp : fAnalyticFPs) { SkASSERT(fp); }) |
| 980 | |
| 981 | if (!fCCPRClipPaths.empty()) { |
| 982 | fAnalyticFPs.reserve(fAnalyticFPs.count() + fCCPRClipPaths.count()); |
| 983 | for (const SkPath& ccprClipPath : fCCPRClipPaths) { |
Chris Dalton | 1dec19a | 2018-04-27 13:05:19 -0600 | [diff] [blame] | 984 | SkASSERT(ccpr); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 985 | SkASSERT(fHasScissor); |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 986 | auto fp = ccpr->makeClipProcessor(opListID, ccprClipPath, fScissor, *fCaps); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 987 | fAnalyticFPs.push_back(std::move(fp)); |
| 988 | } |
| 989 | fCCPRClipPaths.reset(); |
| 990 | } |
| 991 | |
| 992 | return GrFragmentProcessor::RunInSeries(fAnalyticFPs.begin(), fAnalyticFPs.count()); |
| 993 | } |