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" |
| 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, |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 37 | const GrCaps* caps, int maxWindowRectangles, int maxAnalyticFPs, |
Chris Dalton | 1dec19a | 2018-04-27 13:05:19 -0600 | [diff] [blame] | 38 | int maxCCPRClipPaths) |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 39 | : fCaps(caps) |
| 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 | |
| 615 | GrReducedClip::ClipResult GrReducedClip::addAnalyticFP(const SkRect& deviceSpaceRect, |
| 616 | Invert invert, GrAA aa) { |
| 617 | if (this->numAnalyticFPs() >= fMaxAnalyticFPs) { |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 618 | return ClipResult::kNotClipped; |
| 619 | } |
| 620 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 621 | fAnalyticFPs.push_back(GrAARectEffect::Make(GetClipEdgeType(invert, aa), deviceSpaceRect)); |
| 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 | |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [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 | |
| 651 | if (auto fp = GrConvexPolyEffect::Make(GetClipEdgeType(invert, aa), deviceSpacePath)) { |
| 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. |
| 750 | GrColor initialCoverage = InitialState::kAllIn == this->initialState() ? -1 : 0; |
| 751 | rtc->priv().clear(clip, initialCoverage, GrRenderTargetContext::CanClearFullscreen::kYes); |
| 752 | |
| 753 | // Set the matrix so that rendered clip elements are transformed to mask space from clip space. |
| 754 | SkMatrix translate; |
| 755 | translate.setTranslate(SkIntToScalar(-fScissor.left()), SkIntToScalar(-fScissor.top())); |
| 756 | |
| 757 | // walk through each clip element and perform its set op |
| 758 | for (ElementList::Iter iter(fMaskElements); iter.get(); iter.next()) { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 759 | const Element* element = iter.get(); |
| 760 | SkRegion::Op op = (SkRegion::Op)element->getOp(); |
| 761 | GrAA aa = GrAA(element->isAA()); |
| 762 | bool invert = element->isInverseFilled(); |
Chris Dalton | c534808 | 2018-03-30 15:59:38 +0000 | [diff] [blame] | 763 | if (invert || SkRegion::kIntersect_Op == op || SkRegion::kReverseDifference_Op == op) { |
| 764 | // draw directly into the result with the stencil set to make the pixels affected |
| 765 | // by the clip shape be non-zero. |
| 766 | static constexpr GrUserStencilSettings kStencilInElement( |
| 767 | GrUserStencilSettings::StaticInit< |
| 768 | 0xffff, |
| 769 | GrUserStencilTest::kAlways, |
| 770 | 0xffff, |
| 771 | GrUserStencilOp::kReplace, |
| 772 | GrUserStencilOp::kReplace, |
| 773 | 0xffff>() |
| 774 | ); |
| 775 | if (!stencil_element(rtc, clip, &kStencilInElement, translate, element)) { |
| 776 | return false; |
| 777 | } |
| 778 | |
| 779 | // Draw to the exterior pixels (those with a zero stencil value). |
| 780 | static constexpr GrUserStencilSettings kDrawOutsideElement( |
| 781 | GrUserStencilSettings::StaticInit< |
| 782 | 0x0000, |
| 783 | GrUserStencilTest::kEqual, |
| 784 | 0xffff, |
| 785 | GrUserStencilOp::kZero, |
| 786 | GrUserStencilOp::kZero, |
| 787 | 0xffff>() |
| 788 | ); |
| 789 | if (!rtc->priv().drawAndStencilRect(clip, &kDrawOutsideElement, op, !invert, GrAA::kNo, |
| 790 | translate, SkRect::Make(fScissor))) { |
| 791 | return false; |
| 792 | } |
| 793 | } else { |
| 794 | // all the remaining ops can just be directly draw into the accumulation buffer |
| 795 | GrPaint paint; |
| 796 | paint.setCoverageSetOpXPFactory(op, false); |
| 797 | |
| 798 | draw_element(rtc, clip, std::move(paint), aa, translate, element); |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | return true; |
| 803 | } |
| 804 | |
| 805 | //////////////////////////////////////////////////////////////////////////////// |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 806 | // Create a 1-bit clip mask in the stencil buffer. |
| 807 | |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 808 | bool GrReducedClip::drawStencilClipMask(GrContext* context, |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 809 | GrRenderTargetContext* renderTargetContext) const { |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 810 | // 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] | 811 | GrStencilClip stencilClip(fScissor, this->maskGenID()); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 812 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 813 | if (!fWindowRects.empty()) { |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 814 | stencilClip.fixedClip().setWindowRectangles(fWindowRects, |
| 815 | GrWindowRectsState::Mode::kExclusive); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 816 | } |
| 817 | |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 818 | bool initialState = InitialState::kAllIn == this->initialState(); |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 819 | renderTargetContext->priv().clearStencilClip(stencilClip.fixedClip(), initialState); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 820 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 821 | // 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] | 822 | for (ElementList::Iter iter(fMaskElements); iter.get(); iter.next()) { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 823 | const Element* element = iter.get(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 824 | GrAAType aaType = GrAAType::kNone; |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 825 | if (element->isAA() && GrFSAAType::kNone != renderTargetContext->fsaaType()) { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 826 | aaType = GrAAType::kMSAA; |
| 827 | } |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 828 | |
| 829 | bool fillInverted = false; |
| 830 | |
| 831 | // This will be used to determine whether the clip shape can be rendered into the |
| 832 | // stencil with arbitrary stencil settings. |
| 833 | GrPathRenderer::StencilSupport stencilSupport; |
| 834 | |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 835 | SkRegion::Op op = (SkRegion::Op)element->getOp(); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 836 | |
| 837 | GrPathRenderer* pr = nullptr; |
| 838 | SkPath clipPath; |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 839 | if (Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()) { |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 840 | stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
| 841 | fillInverted = false; |
| 842 | } else { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 843 | element->asDeviceSpacePath(&clipPath); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 844 | fillInverted = clipPath.isInverseFillType(); |
| 845 | if (fillInverted) { |
| 846 | clipPath.toggleInverseFillType(); |
| 847 | } |
| 848 | |
| 849 | GrShape shape(clipPath, GrStyle::SimpleFill()); |
| 850 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 851 | canDrawArgs.fCaps = context->contextPriv().caps(); |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 852 | canDrawArgs.fClipConservativeBounds = &stencilClip.fixedClip().scissorRect(); |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 853 | canDrawArgs.fViewMatrix = &SkMatrix::I(); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 854 | canDrawArgs.fShape = &shape; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 855 | canDrawArgs.fAAType = aaType; |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 856 | canDrawArgs.fHasUserStencilSettings = false; |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 857 | |
| 858 | GrDrawingManager* dm = context->contextPriv().drawingManager(); |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 859 | pr = dm->getPathRenderer(canDrawArgs, false, GrPathRendererChain::DrawType::kStencil, |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 860 | &stencilSupport); |
| 861 | if (!pr) { |
| 862 | return false; |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | bool canRenderDirectToStencil = |
| 867 | GrPathRenderer::kNoRestriction_StencilSupport == stencilSupport; |
| 868 | bool drawDirectToClip; // Given the renderer, the element, |
| 869 | // fill rule, and set operation should |
| 870 | // we render the element directly to |
| 871 | // stencil bit used for clipping. |
| 872 | GrUserStencilSettings const* const* stencilPasses = |
| 873 | GrStencilSettings::GetClipPasses(op, canRenderDirectToStencil, fillInverted, |
| 874 | &drawDirectToClip); |
| 875 | |
| 876 | // draw the element to the client stencil bits if necessary |
| 877 | if (!drawDirectToClip) { |
| 878 | static constexpr GrUserStencilSettings kDrawToStencil( |
| 879 | GrUserStencilSettings::StaticInit< |
| 880 | 0x0000, |
| 881 | GrUserStencilTest::kAlways, |
| 882 | 0xffff, |
| 883 | GrUserStencilOp::kIncMaybeClamp, |
| 884 | GrUserStencilOp::kIncMaybeClamp, |
| 885 | 0xffff>() |
| 886 | ); |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 887 | if (Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()) { |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 888 | renderTargetContext->priv().stencilRect(stencilClip.fixedClip(), &kDrawToStencil, |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 889 | aaType, SkMatrix::I(), |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 890 | element->getDeviceSpaceRect()); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 891 | } else { |
| 892 | if (!clipPath.isEmpty()) { |
| 893 | GrShape shape(clipPath, GrStyle::SimpleFill()); |
| 894 | if (canRenderDirectToStencil) { |
| 895 | GrPaint paint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 896 | paint.setXPFactory(GrDisableColorXPFactory::Get()); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 897 | |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 898 | GrPathRenderer::DrawPathArgs args{context, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 899 | std::move(paint), |
| 900 | &kDrawToStencil, |
| 901 | renderTargetContext, |
| 902 | &stencilClip.fixedClip(), |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 903 | &stencilClip.fixedClip().scissorRect(), |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 904 | &SkMatrix::I(), |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 905 | &shape, |
| 906 | aaType, |
| 907 | false}; |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 908 | pr->drawPath(args); |
| 909 | } else { |
| 910 | GrPathRenderer::StencilPathArgs args; |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 911 | args.fContext = context; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 912 | args.fRenderTargetContext = renderTargetContext; |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 913 | args.fClip = &stencilClip.fixedClip(); |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 914 | args.fClipConservativeBounds = &stencilClip.fixedClip().scissorRect(); |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 915 | args.fViewMatrix = &SkMatrix::I(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 916 | args.fAAType = aaType; |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 917 | args.fShape = &shape; |
| 918 | pr->stencilPath(args); |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | // now we modify the clip bit by rendering either the clip |
| 925 | // element directly or a bounding rect of the entire clip. |
| 926 | for (GrUserStencilSettings const* const* pass = stencilPasses; *pass; ++pass) { |
| 927 | if (drawDirectToClip) { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 928 | if (Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()) { |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 929 | renderTargetContext->priv().stencilRect(stencilClip, *pass, aaType, |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 930 | SkMatrix::I(), |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 931 | element->getDeviceSpaceRect()); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 932 | } else { |
| 933 | GrShape shape(clipPath, GrStyle::SimpleFill()); |
| 934 | GrPaint paint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 935 | paint.setXPFactory(GrDisableColorXPFactory::Get()); |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 936 | GrPathRenderer::DrawPathArgs args{context, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 937 | std::move(paint), |
| 938 | *pass, |
| 939 | renderTargetContext, |
| 940 | &stencilClip, |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 941 | &stencilClip.fixedClip().scissorRect(), |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 942 | &SkMatrix::I(), |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 943 | &shape, |
| 944 | aaType, |
| 945 | false}; |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 946 | pr->drawPath(args); |
| 947 | } |
| 948 | } else { |
| 949 | // The view matrix is setup to do clip space -> stencil space translation, so |
| 950 | // draw rect in clip space. |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 951 | renderTargetContext->priv().stencilRect(stencilClip, *pass, aaType, SkMatrix::I(), |
Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 952 | SkRect::Make(fScissor)); |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | } |
| 956 | return true; |
| 957 | } |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 958 | |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 959 | std::unique_ptr<GrFragmentProcessor> GrReducedClip::finishAndDetachAnalyticFPs( |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 960 | GrCoverageCountingPathRenderer* ccpr, uint32_t opListID, int rtWidth, int rtHeight) { |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 961 | // Make sure finishAndDetachAnalyticFPs hasn't been called already. |
| 962 | SkDEBUGCODE(for (const auto& fp : fAnalyticFPs) { SkASSERT(fp); }) |
| 963 | |
| 964 | if (!fCCPRClipPaths.empty()) { |
| 965 | fAnalyticFPs.reserve(fAnalyticFPs.count() + fCCPRClipPaths.count()); |
| 966 | for (const SkPath& ccprClipPath : fCCPRClipPaths) { |
Chris Dalton | 1dec19a | 2018-04-27 13:05:19 -0600 | [diff] [blame] | 967 | SkASSERT(ccpr); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 968 | SkASSERT(fHasScissor); |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 969 | auto fp = ccpr->makeClipProcessor(opListID, ccprClipPath, fScissor, rtWidth, rtHeight, |
| 970 | *fCaps); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 971 | fAnalyticFPs.push_back(std::move(fp)); |
| 972 | } |
| 973 | fCCPRClipPaths.reset(); |
| 974 | } |
| 975 | |
| 976 | return GrFragmentProcessor::RunInSeries(fAnalyticFPs.begin(), fAnalyticFPs.count()); |
| 977 | } |