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