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