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