blob: d37c83f11a67cddee5393b6e40e7e23d91ea2fa7 [file] [log] [blame]
bsalomon@google.com170bd792012-12-05 22:26:11 +00001/*
csmartdalton77f2fae2016-08-08 09:55:06 -07002 * Copyright 2016 Google Inc.
bsalomon@google.com170bd792012-12-05 22:26:11 +00003 *
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
csmartdaltonbde96c62016-08-31 12:54:46 -070010#include "GrAppliedClip.h"
csmartdaltoncbecb082016-07-22 08:59:08 -070011#include "GrClip.h"
csmartdaltonbde96c62016-08-31 12:54:46 -070012#include "GrColor.h"
13#include "GrContextPriv.h"
Brian Osman11052242016-10-27 14:47:55 -040014#include "GrRenderTargetContext.h"
15#include "GrRenderTargetContextPriv.h"
csmartdaltonbde96c62016-08-31 12:54:46 -070016#include "GrDrawingManager.h"
17#include "GrFixedClip.h"
18#include "GrPathRenderer.h"
csmartdaltonc633abb2016-11-01 08:55:55 -070019#include "GrStencilSettings.h"
Chris Daltonbbfd5162017-11-07 13:35:22 -070020#include "GrStencilClip.h"
csmartdaltonbde96c62016-08-31 12:54:46 -070021#include "GrStyle.h"
22#include "GrUserStencilSettings.h"
Mike Reedebfce6d2016-12-12 10:02:12 -050023#include "SkClipOpPriv.h"
csmartdaltoncbecb082016-07-22 08:59:08 -070024
csmartdalton5ecbbbe2016-08-23 13:26:40 -070025/**
26 * There are plenty of optimizations that could be added here. Maybe flips could be folded into
27 * earlier operations. Or would inserting flips and reversing earlier ops ever be a win? Perhaps
28 * for the case where the bounds are kInsideOut_BoundsType. We could restrict earlier operations
29 * based on later intersect operations, and perhaps remove intersect-rects. We could optionally
30 * take a rect in case the caller knows a bound on what is to be drawn through this clip.
31 */
csmartdaltonbf4a8f92016-09-06 10:01:06 -070032GrReducedClip::GrReducedClip(const SkClipStack& stack, const SkRect& queryBounds,
Chris Daltond8d15932017-11-01 19:21:24 +000033 int maxWindowRectangles) {
csmartdaltoncbecb082016-07-22 08:59:08 -070034 SkASSERT(!queryBounds.isEmpty());
Chris Dalton79471932017-10-27 01:50:57 -060035 fHasScissor = false;
36 fAAClipRectGenID = SK_InvalidGenID;
csmartdaltoncbecb082016-07-22 08:59:08 -070037
bsalomon@google.com170bd792012-12-05 22:26:11 +000038 if (stack.isWideOpen()) {
csmartdalton77f2fae2016-08-08 09:55:06 -070039 fInitialState = InitialState::kAllIn;
40 return;
bsalomon@google.com170bd792012-12-05 22:26:11 +000041 }
42
43 SkClipStack::BoundsType stackBoundsType;
44 SkRect stackBounds;
45 bool iior;
46 stack.getBounds(&stackBounds, &stackBoundsType, &iior);
47
Chris Dalton348060f2017-06-05 13:15:37 -060048 if (GrClip::IsOutsideClip(stackBounds, queryBounds)) {
csmartdaltoncbecb082016-07-22 08:59:08 -070049 bool insideOut = SkClipStack::kInsideOut_BoundsType == stackBoundsType;
csmartdalton77f2fae2016-08-08 09:55:06 -070050 fInitialState = insideOut ? InitialState::kAllIn : InitialState::kAllOut;
51 return;
bsalomon@google.com170bd792012-12-05 22:26:11 +000052 }
53
csmartdaltoncbecb082016-07-22 08:59:08 -070054 if (iior) {
55 // "Is intersection of rects" means the clip is a single rect indicated by the stack bounds.
56 // This should only be true if aa/non-aa status matches among all elements.
57 SkASSERT(SkClipStack::kNormal_BoundsType == stackBoundsType);
58 SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart);
59 if (!iter.prev()->isAA() || GrClip::IsPixelAligned(stackBounds)) {
Chris Dalton79471932017-10-27 01:50:57 -060060 // The clip is a non-aa rect. Here we just implement the entire thing using fScissor.
Mike Kleine26062a2017-10-31 20:56:54 +000061 stackBounds.round(&fScissor);
Chris Dalton79471932017-10-27 01:50:57 -060062 fHasScissor = true;
63 fInitialState = fScissor.isEmpty() ? InitialState::kAllOut : InitialState::kAllIn;
csmartdalton77f2fae2016-08-08 09:55:06 -070064 return;
csmartdaltoncbecb082016-07-22 08:59:08 -070065 }
66 if (GrClip::IsInsideClip(stackBounds, queryBounds)) {
csmartdalton77f2fae2016-08-08 09:55:06 -070067 fInitialState = InitialState::kAllIn;
68 return;
csmartdaltoncbecb082016-07-22 08:59:08 -070069 }
70
csmartdaltond211e782016-08-15 11:17:19 -070071 SkRect tightBounds;
72 SkAssertResult(tightBounds.intersect(stackBounds, queryBounds));
Chris Dalton79471932017-10-27 01:50:57 -060073 fScissor = GrClip::GetPixelIBounds(tightBounds);
74 if (fScissor.isEmpty()) {
Chris Dalton348060f2017-06-05 13:15:37 -060075 fInitialState = InitialState::kAllOut;
76 return;
77 }
Chris Dalton79471932017-10-27 01:50:57 -060078 fHasScissor = true;
csmartdaltoncbecb082016-07-22 08:59:08 -070079
Chris Dalton79471932017-10-27 01:50:57 -060080 fAAClipRect = stackBounds;
81 fAAClipRectGenID = stack.getTopmostGenID();
82 SkASSERT(SK_InvalidGenID != fAAClipRectGenID);
csmartdalton77f2fae2016-08-08 09:55:06 -070083
Chris Dalton79471932017-10-27 01:50:57 -060084 fInitialState = InitialState::kAllIn;
85 } else {
86 SkRect tighterQuery = queryBounds;
87 if (SkClipStack::kNormal_BoundsType == stackBoundsType) {
88 // Tighten the query by introducing a new clip at the stack's pixel boundaries. (This
89 // new clip will be enforced by the scissor.)
90 SkAssertResult(tighterQuery.intersect(GrClip::GetPixelBounds(stackBounds)));
91 }
92
93 fScissor = GrClip::GetPixelIBounds(tighterQuery);
94 if (fScissor.isEmpty()) {
95 fInitialState = InitialState::kAllOut;
96 return;
97 }
98 fHasScissor = true;
99
Chris Daltond8d15932017-11-01 19:21:24 +0000100 // Now that we have determined the bounds to use and filtered out the trivial cases, call the
101 // helper that actually walks the stack.
102 this->walkStack(stack, tighterQuery, maxWindowRectangles);
csmartdaltoncbecb082016-07-22 08:59:08 -0700103 }
104
Chris Daltond8d15932017-11-01 19:21:24 +0000105 if (SK_InvalidGenID != fAAClipRectGenID) { // Is there an AA clip rect?
Chris Dalton79471932017-10-27 01:50:57 -0600106 if (fMaskElements.isEmpty()) {
107 // Use a replace since it is faster than intersect.
108 fMaskElements.addToHead(fAAClipRect, SkMatrix::I(), kReplace_SkClipOp, true /*doAA*/);
109 fInitialState = InitialState::kAllOut;
110 } else {
111 fMaskElements.addToTail(fAAClipRect, SkMatrix::I(), kIntersect_SkClipOp, true /*doAA*/);
112 }
113 fMaskRequiresAA = true;
114 fMaskGenID = fAAClipRectGenID;
Chris Daltond8d15932017-11-01 19:21:24 +0000115 fAAClipRectGenID = SK_InvalidGenID;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700116 }
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700117}
118
Chris Daltond8d15932017-11-01 19:21:24 +0000119void GrReducedClip::walkStack(const SkClipStack& stack, const SkRect& queryBounds,
120 int maxWindowRectangles) {
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700121 // walk backwards until we get to:
122 // a) the beginning
123 // b) an operation that is known to make the bounds all inside/outside
124 // c) a replace operation
125
126 enum class InitialTriState {
127 kUnknown = -1,
128 kAllIn = (int)GrReducedClip::InitialState::kAllIn,
129 kAllOut = (int)GrReducedClip::InitialState::kAllOut
130 } initialTriState = InitialTriState::kUnknown;
131
132 // During our backwards walk, track whether we've seen ops that either grow or shrink the clip.
133 // TODO: track these per saved clip so that we can consider them on the forward pass.
134 bool embiggens = false;
135 bool emsmallens = false;
136
137 // We use a slightly relaxed set of query bounds for element containment tests. This is to
138 // account for floating point rounding error that may have occurred during coord transforms.
139 SkRect relaxedQueryBounds = queryBounds.makeInset(GrClip::kBoundsTolerance,
140 GrClip::kBoundsTolerance);
Chris Dalton69824002017-10-31 00:37:52 -0600141 if (relaxedQueryBounds.isEmpty()) {
142 relaxedQueryBounds = queryBounds;
143 }
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700144
145 SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart);
146 int numAAElements = 0;
147 while (InitialTriState::kUnknown == initialTriState) {
148 const Element* element = iter.prev();
149 if (nullptr == element) {
150 initialTriState = InitialTriState::kAllIn;
151 break;
152 }
153 if (SkClipStack::kEmptyGenID == element->getGenID()) {
154 initialTriState = InitialTriState::kAllOut;
155 break;
156 }
157 if (SkClipStack::kWideOpenGenID == element->getGenID()) {
158 initialTriState = InitialTriState::kAllIn;
159 break;
160 }
161
162 bool skippable = false;
163 bool isFlip = false; // does this op just flip the in/out state of every point in the bounds
164
165 switch (element->getOp()) {
Mike Reedc1f77742016-12-09 09:00:50 -0500166 case kDifference_SkClipOp:
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700167 // check if the shape subtracted either contains the entire bounds (and makes
168 // the clip empty) or is outside the bounds and therefore can be skipped.
169 if (element->isInverseFilled()) {
170 if (element->contains(relaxedQueryBounds)) {
171 skippable = true;
172 } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) {
173 initialTriState = InitialTriState::kAllOut;
174 skippable = true;
175 }
176 } else {
177 if (element->contains(relaxedQueryBounds)) {
178 initialTriState = InitialTriState::kAllOut;
179 skippable = true;
180 } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) {
181 skippable = true;
Chris Dalton79471932017-10-27 01:50:57 -0600182 } else if (!embiggens) {
Chris Daltond8d15932017-11-01 19:21:24 +0000183 ClipResult result = this->clipOutsideElement(element, maxWindowRectangles);
Chris Dalton79471932017-10-27 01:50:57 -0600184 if (ClipResult::kMadeEmpty == result) {
185 return;
186 }
187 skippable = (ClipResult::kClipped == result);
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700188 }
189 }
190 if (!skippable) {
191 emsmallens = true;
192 }
193 break;
Mike Reedc1f77742016-12-09 09:00:50 -0500194 case kIntersect_SkClipOp:
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700195 // check if the shape intersected contains the entire bounds and therefore can
196 // be skipped or it is outside the entire bounds and therefore makes the clip
197 // empty.
198 if (element->isInverseFilled()) {
199 if (element->contains(relaxedQueryBounds)) {
200 initialTriState = InitialTriState::kAllOut;
201 skippable = true;
202 } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) {
203 skippable = true;
204 }
205 } else {
206 if (element->contains(relaxedQueryBounds)) {
207 skippable = true;
208 } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) {
209 initialTriState = InitialTriState::kAllOut;
210 skippable = true;
Chris Dalton79471932017-10-27 01:50:57 -0600211 } else if (!embiggens) {
212 ClipResult result = this->clipInsideElement(element);
213 if (ClipResult::kMadeEmpty == result) {
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700214 return;
215 }
Chris Dalton79471932017-10-27 01:50:57 -0600216 skippable = (ClipResult::kClipped == result);
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700217 }
218 }
219 if (!skippable) {
220 emsmallens = true;
221 }
222 break;
Mike Reedc1f77742016-12-09 09:00:50 -0500223 case kUnion_SkClipOp:
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700224 // If the union-ed shape contains the entire bounds then after this element
225 // the bounds is entirely inside the clip. If the union-ed shape is outside the
226 // bounds then this op can be skipped.
227 if (element->isInverseFilled()) {
228 if (element->contains(relaxedQueryBounds)) {
229 skippable = true;
230 } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) {
231 initialTriState = InitialTriState::kAllIn;
232 skippable = true;
233 }
234 } else {
235 if (element->contains(relaxedQueryBounds)) {
236 initialTriState = InitialTriState::kAllIn;
237 skippable = true;
238 } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) {
239 skippable = true;
240 }
241 }
242 if (!skippable) {
243 embiggens = true;
244 }
245 break;
Mike Reedc1f77742016-12-09 09:00:50 -0500246 case kXOR_SkClipOp:
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700247 // If the bounds is entirely inside the shape being xor-ed then the effect is
248 // to flip the inside/outside state of every point in the bounds. We may be
249 // able to take advantage of this in the forward pass. If the xor-ed shape
250 // doesn't intersect the bounds then it can be skipped.
251 if (element->isInverseFilled()) {
252 if (element->contains(relaxedQueryBounds)) {
253 skippable = true;
254 } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) {
255 isFlip = true;
256 }
257 } else {
258 if (element->contains(relaxedQueryBounds)) {
259 isFlip = true;
260 } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) {
261 skippable = true;
262 }
263 }
264 if (!skippable) {
265 emsmallens = embiggens = true;
266 }
267 break;
Mike Reedc1f77742016-12-09 09:00:50 -0500268 case kReverseDifference_SkClipOp:
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700269 // When the bounds is entirely within the rev-diff shape then this behaves like xor
270 // and reverses every point inside the bounds. If the shape is completely outside
271 // the bounds then we know after this element is applied that the bounds will be
272 // all outside the current clip.B
273 if (element->isInverseFilled()) {
274 if (element->contains(relaxedQueryBounds)) {
275 initialTriState = InitialTriState::kAllOut;
276 skippable = true;
277 } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) {
278 isFlip = true;
279 }
280 } else {
281 if (element->contains(relaxedQueryBounds)) {
282 isFlip = true;
283 } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) {
284 initialTriState = InitialTriState::kAllOut;
285 skippable = true;
286 }
287 }
288 if (!skippable) {
289 emsmallens = embiggens = true;
290 }
291 break;
292
Mike Reedc1f77742016-12-09 09:00:50 -0500293 case kReplace_SkClipOp:
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700294 // Replace will always terminate our walk. We will either begin the forward walk
295 // at the replace op or detect here than the shape is either completely inside
296 // or completely outside the bounds. In this latter case it can be skipped by
297 // setting the correct value for initialTriState.
298 if (element->isInverseFilled()) {
299 if (element->contains(relaxedQueryBounds)) {
300 initialTriState = InitialTriState::kAllOut;
301 skippable = true;
302 } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) {
303 initialTriState = InitialTriState::kAllIn;
304 skippable = true;
305 }
306 } else {
307 if (element->contains(relaxedQueryBounds)) {
308 initialTriState = InitialTriState::kAllIn;
309 skippable = true;
310 } else if (GrClip::IsOutsideClip(element->getBounds(), queryBounds)) {
311 initialTriState = InitialTriState::kAllOut;
312 skippable = true;
Chris Dalton79471932017-10-27 01:50:57 -0600313 } else if (!embiggens) {
314 ClipResult result = this->clipInsideElement(element);
315 if (ClipResult::kMadeEmpty == result) {
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700316 return;
317 }
Chris Dalton79471932017-10-27 01:50:57 -0600318 if (ClipResult::kClipped == result) {
319 initialTriState = InitialTriState::kAllIn;
320 skippable = true;
321 }
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700322 }
323 }
324 if (!skippable) {
325 initialTriState = InitialTriState::kAllOut;
326 embiggens = emsmallens = true;
327 }
328 break;
329 default:
330 SkDEBUGFAIL("Unexpected op.");
331 break;
332 }
333 if (!skippable) {
Chris Dalton79471932017-10-27 01:50:57 -0600334 if (fMaskElements.isEmpty()) {
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700335 // This will be the last element. Record the stricter genID.
Chris Dalton79471932017-10-27 01:50:57 -0600336 fMaskGenID = element->getGenID();
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700337 }
338
339 // if it is a flip, change it to a bounds-filling rect
340 if (isFlip) {
Mike Reedc1f77742016-12-09 09:00:50 -0500341 SkASSERT(kXOR_SkClipOp == element->getOp() ||
342 kReverseDifference_SkClipOp == element->getOp());
Chris Dalton79471932017-10-27 01:50:57 -0600343 fMaskElements.addToHead(SkRect::Make(fScissor), SkMatrix::I(),
344 kReverseDifference_SkClipOp, false);
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700345 } else {
Chris Dalton79471932017-10-27 01:50:57 -0600346 Element* newElement = fMaskElements.addToHead(*element);
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700347 if (newElement->isAA()) {
348 ++numAAElements;
349 }
350 // Intersecting an inverse shape is the same as differencing the non-inverse shape.
351 // Replacing with an inverse shape is the same as setting initialState=kAllIn and
352 // differencing the non-inverse shape.
Mike Reedc1f77742016-12-09 09:00:50 -0500353 bool isReplace = kReplace_SkClipOp == newElement->getOp();
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700354 if (newElement->isInverseFilled() &&
Mike Reedc1f77742016-12-09 09:00:50 -0500355 (kIntersect_SkClipOp == newElement->getOp() || isReplace)) {
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700356 newElement->invertShapeFillType();
Mike Reedc1f77742016-12-09 09:00:50 -0500357 newElement->setOp(kDifference_SkClipOp);
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700358 if (isReplace) {
359 SkASSERT(InitialTriState::kAllOut == initialTriState);
360 initialTriState = InitialTriState::kAllIn;
361 }
362 }
363 }
364 }
365 }
366
367 if ((InitialTriState::kAllOut == initialTriState && !embiggens) ||
368 (InitialTriState::kAllIn == initialTriState && !emsmallens)) {
Chris Dalton79471932017-10-27 01:50:57 -0600369 fMaskElements.reset();
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700370 numAAElements = 0;
371 } else {
Chris Dalton79471932017-10-27 01:50:57 -0600372 Element* element = fMaskElements.headIter().get();
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700373 while (element) {
374 bool skippable = false;
375 switch (element->getOp()) {
Mike Reedc1f77742016-12-09 09:00:50 -0500376 case kDifference_SkClipOp:
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700377 // subtracting from the empty set yields the empty set.
378 skippable = InitialTriState::kAllOut == initialTriState;
379 break;
Mike Reedc1f77742016-12-09 09:00:50 -0500380 case kIntersect_SkClipOp:
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700381 // intersecting with the empty set yields the empty set
382 if (InitialTriState::kAllOut == initialTriState) {
383 skippable = true;
384 } else {
385 // We can clear to zero and then simply draw the clip element.
386 initialTriState = InitialTriState::kAllOut;
Mike Reedc1f77742016-12-09 09:00:50 -0500387 element->setOp(kReplace_SkClipOp);
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700388 }
389 break;
Mike Reedc1f77742016-12-09 09:00:50 -0500390 case kUnion_SkClipOp:
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700391 if (InitialTriState::kAllIn == initialTriState) {
392 // unioning the infinite plane with anything is a no-op.
393 skippable = true;
394 } else {
395 // unioning the empty set with a shape is the shape.
Mike Reedc1f77742016-12-09 09:00:50 -0500396 element->setOp(kReplace_SkClipOp);
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700397 }
398 break;
Mike Reedc1f77742016-12-09 09:00:50 -0500399 case kXOR_SkClipOp:
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700400 if (InitialTriState::kAllOut == initialTriState) {
401 // xor could be changed to diff in the kAllIn case, not sure it's a win.
Mike Reedc1f77742016-12-09 09:00:50 -0500402 element->setOp(kReplace_SkClipOp);
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700403 }
404 break;
Mike Reedc1f77742016-12-09 09:00:50 -0500405 case kReverseDifference_SkClipOp:
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700406 if (InitialTriState::kAllIn == initialTriState) {
407 // subtracting the whole plane will yield the empty set.
408 skippable = true;
409 initialTriState = InitialTriState::kAllOut;
410 } else {
411 // this picks up flips inserted in the backwards pass.
412 skippable = element->isInverseFilled() ?
413 GrClip::IsOutsideClip(element->getBounds(), queryBounds) :
414 element->contains(relaxedQueryBounds);
415 if (skippable) {
416 initialTriState = InitialTriState::kAllIn;
417 } else {
Mike Reedc1f77742016-12-09 09:00:50 -0500418 element->setOp(kReplace_SkClipOp);
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700419 }
420 }
421 break;
Mike Reedc1f77742016-12-09 09:00:50 -0500422 case kReplace_SkClipOp:
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700423 skippable = false; // we would have skipped it in the backwards walk if we
424 // could've.
425 break;
426 default:
427 SkDEBUGFAIL("Unexpected op.");
428 break;
429 }
430 if (!skippable) {
431 break;
432 } else {
433 if (element->isAA()) {
434 --numAAElements;
435 }
Chris Dalton79471932017-10-27 01:50:57 -0600436 fMaskElements.popHead();
437 element = fMaskElements.headIter().get();
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700438 }
439 }
440 }
Chris Dalton79471932017-10-27 01:50:57 -0600441 fMaskRequiresAA = numAAElements > 0;
csmartdalton5ecbbbe2016-08-23 13:26:40 -0700442
443 SkASSERT(InitialTriState::kUnknown != initialTriState);
444 fInitialState = static_cast<GrReducedClip::InitialState>(initialTriState);
445}
446
Chris Dalton79471932017-10-27 01:50:57 -0600447GrReducedClip::ClipResult GrReducedClip::clipInsideElement(const Element* element) {
448 SkIRect elementIBounds;
449 if (!element->isAA()) {
450 element->getBounds().round(&elementIBounds);
451 } else {
452 elementIBounds = GrClip::GetPixelIBounds(element->getBounds());
453 }
454 SkASSERT(fHasScissor);
455 if (!fScissor.intersect(elementIBounds)) {
456 this->makeEmpty();
457 return ClipResult::kMadeEmpty;
458 }
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700459
Chris Dalton79471932017-10-27 01:50:57 -0600460 switch (element->getDeviceSpaceType()) {
461 case Element::DeviceSpaceType::kEmpty:
462 return ClipResult::kMadeEmpty;
463
464 case Element::DeviceSpaceType::kRect:
465 SkASSERT(element->getBounds() == element->getDeviceSpaceRect());
466 if (element->isAA()) {
467 if (SK_InvalidGenID == fAAClipRectGenID) { // No AA clip rect yet?
468 fAAClipRect = element->getDeviceSpaceRect();
469 // fAAClipRectGenID is the value we should use for fMaskGenID if we end up
470 // moving the AA clip rect into the mask. The mask GenID is simply the topmost
471 // element's GenID. And since we walk the stack backwards, this means it's just
472 // the first element we don't skip during our walk.
473 fAAClipRectGenID = fMaskElements.isEmpty() ? element->getGenID() : fMaskGenID;
474 SkASSERT(SK_InvalidGenID != fAAClipRectGenID);
475 } else if (!fAAClipRect.intersect(element->getDeviceSpaceRect())) {
476 this->makeEmpty();
477 return ClipResult::kMadeEmpty;
478 }
479 }
480 return ClipResult::kClipped;
481
482 case Element::DeviceSpaceType::kRRect:
483 case Element::DeviceSpaceType::kPath:
Chris Daltond8d15932017-11-01 19:21:24 +0000484 return ClipResult::kNotClipped;
Chris Dalton79471932017-10-27 01:50:57 -0600485 }
486
487 SK_ABORT("Unexpected DeviceSpaceType");
488 return ClipResult::kNotClipped;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700489}
490
Chris Daltond8d15932017-11-01 19:21:24 +0000491GrReducedClip::ClipResult GrReducedClip::clipOutsideElement(const Element* element,
492 int maxWindowRectangles) {
493 if (fWindowRects.count() >= maxWindowRectangles) {
494 return ClipResult::kNotClipped;
495 }
496
Chris Dalton79471932017-10-27 01:50:57 -0600497 switch (element->getDeviceSpaceType()) {
498 case Element::DeviceSpaceType::kEmpty:
499 return ClipResult::kMadeEmpty;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700500
Chris Dalton79471932017-10-27 01:50:57 -0600501 case Element::DeviceSpaceType::kRect:
Chris Daltond8d15932017-11-01 19:21:24 +0000502 // Clip out the inside of every rect. We won't be able to entirely skip the AA ones, but
503 // it saves processing time.
504 this->addWindowRectangle(element->getDeviceSpaceRect(), element->isAA());
505 return !element->isAA() ? ClipResult::kClipped : ClipResult::kNotClipped;
Chris Dalton79471932017-10-27 01:50:57 -0600506
507 case Element::DeviceSpaceType::kRRect: {
Chris Daltond29e0da2017-11-01 11:40:58 -0600508 // Clip out the interiors of round rects with two window rectangles in the shape of a
Chris Daltond8d15932017-11-01 19:21:24 +0000509 // plus. It doesn't allow us to skip the clip element, but still saves processing time.
510 const SkRRect& clipRRect = element->getDeviceSpaceRRect();
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700511 SkVector insetTL = clipRRect.radii(SkRRect::kUpperLeft_Corner);
512 SkVector insetBR = clipRRect.radii(SkRRect::kLowerRight_Corner);
513 if (SkRRect::kComplex_Type == clipRRect.getType()) {
514 const SkVector& insetTR = clipRRect.radii(SkRRect::kUpperRight_Corner);
515 const SkVector& insetBL = clipRRect.radii(SkRRect::kLowerLeft_Corner);
516 insetTL.fX = SkTMax(insetTL.x(), insetBL.x());
517 insetTL.fY = SkTMax(insetTL.y(), insetTR.y());
518 insetBR.fX = SkTMax(insetBR.x(), insetTR.x());
519 insetBR.fY = SkTMax(insetBR.y(), insetBL.y());
520 }
521 const SkRect& bounds = clipRRect.getBounds();
522 if (insetTL.x() + insetBR.x() >= bounds.width() ||
523 insetTL.y() + insetBR.y() >= bounds.height()) {
Chris Daltond8d15932017-11-01 19:21:24 +0000524 return ClipResult::kNotClipped; // The interior "plus" is empty.
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700525 }
526
527 SkRect horzRect = SkRect::MakeLTRB(bounds.left(), bounds.top() + insetTL.y(),
528 bounds.right(), bounds.bottom() - insetBR.y());
529 this->addWindowRectangle(horzRect, element->isAA());
Chris Daltond8d15932017-11-01 19:21:24 +0000530 if (fWindowRects.count() >= maxWindowRectangles) {
531 return ClipResult::kNotClipped;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700532 }
533
Chris Daltond8d15932017-11-01 19:21:24 +0000534 SkRect vertRect = SkRect::MakeLTRB(bounds.left() + insetTL.x(), bounds.top(),
535 bounds.right() - insetBR.x(), bounds.bottom());
536 this->addWindowRectangle(vertRect, element->isAA());
537 return ClipResult::kNotClipped;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700538 }
Chris Dalton79471932017-10-27 01:50:57 -0600539
540 case Element::DeviceSpaceType::kPath:
Chris Daltond8d15932017-11-01 19:21:24 +0000541 return ClipResult::kNotClipped;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700542 }
Chris Dalton79471932017-10-27 01:50:57 -0600543
544 SK_ABORT("Unexpected DeviceSpaceType");
545 return ClipResult::kNotClipped;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700546}
547
548inline void GrReducedClip::addWindowRectangle(const SkRect& elementInteriorRect, bool elementIsAA) {
549 SkIRect window;
550 if (!elementIsAA) {
551 elementInteriorRect.round(&window);
552 } else {
553 elementInteriorRect.roundIn(&window);
554 }
555 if (!window.isEmpty()) { // Skip very thin windows that round to zero or negative dimensions.
556 fWindowRects.addWindow(window);
557 }
558}
559
Chris Dalton79471932017-10-27 01:50:57 -0600560void GrReducedClip::makeEmpty() {
561 fHasScissor = false;
562 fAAClipRectGenID = SK_InvalidGenID;
563 fWindowRects.reset();
564 fMaskElements.reset();
565 fInitialState = InitialState::kAllOut;
bsalomon@google.com34cd70a2012-12-06 14:23:20 +0000566}
csmartdaltonbde96c62016-08-31 12:54:46 -0700567
568////////////////////////////////////////////////////////////////////////////////
569// Create a 8-bit clip mask in alpha
570
Brian Osman11052242016-10-27 14:47:55 -0400571static bool stencil_element(GrRenderTargetContext* rtc,
csmartdaltonbde96c62016-08-31 12:54:46 -0700572 const GrFixedClip& clip,
573 const GrUserStencilSettings* ss,
574 const SkMatrix& viewMatrix,
575 const SkClipStack::Element* element) {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500576 GrAA aa = GrBoolToAA(element->isAA());
Brian Salomonf3b46e52017-08-30 11:37:57 -0400577 switch (element->getDeviceSpaceType()) {
Chris Dalton79471932017-10-27 01:50:57 -0600578 case SkClipStack::Element::DeviceSpaceType::kEmpty:
csmartdaltonbde96c62016-08-31 12:54:46 -0700579 SkDEBUGFAIL("Should never get here with an empty element.");
580 break;
Chris Dalton79471932017-10-27 01:50:57 -0600581 case SkClipStack::Element::DeviceSpaceType::kRect:
Brian Salomonf3b46e52017-08-30 11:37:57 -0400582 return rtc->priv().drawAndStencilRect(clip, ss, (SkRegion::Op)element->getOp(),
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500583 element->isInverseFilled(), aa, viewMatrix,
Brian Salomonf3b46e52017-08-30 11:37:57 -0400584 element->getDeviceSpaceRect());
csmartdaltonbde96c62016-08-31 12:54:46 -0700585 break;
586 default: {
587 SkPath path;
Brian Salomonf3b46e52017-08-30 11:37:57 -0400588 element->asDeviceSpacePath(&path);
csmartdaltonbde96c62016-08-31 12:54:46 -0700589 if (path.isInverseFillType()) {
590 path.toggleInverseFillType();
591 }
592
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500593 return rtc->priv().drawAndStencilPath(clip, ss, (SkRegion::Op)element->getOp(),
594 element->isInverseFilled(), aa, viewMatrix, path);
csmartdaltonbde96c62016-08-31 12:54:46 -0700595 break;
596 }
597 }
598
599 return false;
600}
601
Brian Osman11052242016-10-27 14:47:55 -0400602static void draw_element(GrRenderTargetContext* rtc,
Brian Salomon82f44312017-01-11 13:42:54 -0500603 const GrClip& clip, // TODO: can this just always be WideOpen?
604 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500605 GrAA aa,
csmartdaltonbde96c62016-08-31 12:54:46 -0700606 const SkMatrix& viewMatrix,
607 const SkClipStack::Element* element) {
csmartdaltonbde96c62016-08-31 12:54:46 -0700608 // TODO: Draw rrects directly here.
Brian Salomonf3b46e52017-08-30 11:37:57 -0400609 switch (element->getDeviceSpaceType()) {
Chris Dalton79471932017-10-27 01:50:57 -0600610 case SkClipStack::Element::DeviceSpaceType::kEmpty:
csmartdaltonbde96c62016-08-31 12:54:46 -0700611 SkDEBUGFAIL("Should never get here with an empty element.");
612 break;
Chris Dalton79471932017-10-27 01:50:57 -0600613 case SkClipStack::Element::DeviceSpaceType::kRect:
Brian Salomonf3b46e52017-08-30 11:37:57 -0400614 rtc->drawRect(clip, std::move(paint), aa, viewMatrix, element->getDeviceSpaceRect());
csmartdaltonbde96c62016-08-31 12:54:46 -0700615 break;
616 default: {
617 SkPath path;
Brian Salomonf3b46e52017-08-30 11:37:57 -0400618 element->asDeviceSpacePath(&path);
csmartdaltonbde96c62016-08-31 12:54:46 -0700619 if (path.isInverseFillType()) {
620 path.toggleInverseFillType();
621 }
622
Brian Salomon82f44312017-01-11 13:42:54 -0500623 rtc->drawPath(clip, std::move(paint), aa, viewMatrix, path, GrStyle::SimpleFill());
csmartdaltonbde96c62016-08-31 12:54:46 -0700624 break;
625 }
626 }
627}
628
Brian Osman11052242016-10-27 14:47:55 -0400629bool GrReducedClip::drawAlphaClipMask(GrRenderTargetContext* rtc) const {
csmartdaltonbde96c62016-08-31 12:54:46 -0700630 // The texture may be larger than necessary, this rect represents the part of the texture
631 // we populate with a rasterization of the clip.
Chris Dalton79471932017-10-27 01:50:57 -0600632 GrFixedClip clip(SkIRect::MakeWH(fScissor.width(), fScissor.height()));
csmartdaltonbde96c62016-08-31 12:54:46 -0700633
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700634 if (!fWindowRects.empty()) {
Chris Dalton79471932017-10-27 01:50:57 -0600635 clip.setWindowRectangles(fWindowRects.makeOffset(-fScissor.left(), -fScissor.top()),
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700636 GrWindowRectsState::Mode::kExclusive);
637 }
638
csmartdaltonbde96c62016-08-31 12:54:46 -0700639 // The scratch texture that we are drawing into can be substantially larger than the mask. Only
640 // clear the part that we care about.
641 GrColor initialCoverage = InitialState::kAllIn == this->initialState() ? -1 : 0;
Brian Osman693a5402016-10-27 15:13:22 -0400642 rtc->priv().clear(clip, initialCoverage, true);
csmartdaltonbde96c62016-08-31 12:54:46 -0700643
644 // Set the matrix so that rendered clip elements are transformed to mask space from clip space.
645 SkMatrix translate;
Chris Dalton79471932017-10-27 01:50:57 -0600646 translate.setTranslate(SkIntToScalar(-fScissor.left()), SkIntToScalar(-fScissor.top()));
csmartdaltonbde96c62016-08-31 12:54:46 -0700647
648 // walk through each clip element and perform its set op
Chris Dalton79471932017-10-27 01:50:57 -0600649 for (ElementList::Iter iter(fMaskElements); iter.get(); iter.next()) {
csmartdaltonbde96c62016-08-31 12:54:46 -0700650 const Element* element = iter.get();
reed73603f32016-09-20 08:42:38 -0700651 SkRegion::Op op = (SkRegion::Op)element->getOp();
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500652 GrAA aa = GrBoolToAA(element->isAA());
csmartdaltonbde96c62016-08-31 12:54:46 -0700653 bool invert = element->isInverseFilled();
654 if (invert || SkRegion::kIntersect_Op == op || SkRegion::kReverseDifference_Op == op) {
655 // draw directly into the result with the stencil set to make the pixels affected
656 // by the clip shape be non-zero.
657 static constexpr GrUserStencilSettings kStencilInElement(
658 GrUserStencilSettings::StaticInit<
659 0xffff,
660 GrUserStencilTest::kAlways,
661 0xffff,
662 GrUserStencilOp::kReplace,
663 GrUserStencilOp::kReplace,
664 0xffff>()
665 );
Brian Osman11052242016-10-27 14:47:55 -0400666 if (!stencil_element(rtc, clip, &kStencilInElement, translate, element)) {
csmartdaltonbde96c62016-08-31 12:54:46 -0700667 return false;
668 }
669
670 // Draw to the exterior pixels (those with a zero stencil value).
671 static constexpr GrUserStencilSettings kDrawOutsideElement(
672 GrUserStencilSettings::StaticInit<
673 0x0000,
674 GrUserStencilTest::kEqual,
675 0xffff,
676 GrUserStencilOp::kZero,
677 GrUserStencilOp::kZero,
678 0xffff>()
679 );
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500680 if (!rtc->priv().drawAndStencilRect(clip, &kDrawOutsideElement, op, !invert, GrAA::kNo,
Chris Dalton79471932017-10-27 01:50:57 -0600681 translate, SkRect::Make(fScissor))) {
csmartdaltonbde96c62016-08-31 12:54:46 -0700682 return false;
683 }
684 } else {
685 // all the remaining ops can just be directly draw into the accumulation buffer
686 GrPaint paint;
csmartdaltonbde96c62016-08-31 12:54:46 -0700687 paint.setCoverageSetOpXPFactory(op, false);
688
Brian Salomon82f44312017-01-11 13:42:54 -0500689 draw_element(rtc, clip, std::move(paint), aa, translate, element);
csmartdaltonbde96c62016-08-31 12:54:46 -0700690 }
691 }
692
693 return true;
694}
695
696////////////////////////////////////////////////////////////////////////////////
697// Create a 1-bit clip mask in the stencil buffer.
698
csmartdaltonbde96c62016-08-31 12:54:46 -0700699bool GrReducedClip::drawStencilClipMask(GrContext* context,
Brian Salomon9a767722017-03-13 17:57:28 -0400700 GrRenderTargetContext* renderTargetContext) const {
csmartdaltonbde96c62016-08-31 12:54:46 -0700701 // We set the current clip to the bounds so that our recursive draws are scissored to them.
Chris Daltonbbfd5162017-11-07 13:35:22 -0700702 GrStencilClip stencilClip(fScissor, this->maskGenID());
csmartdaltonbde96c62016-08-31 12:54:46 -0700703
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700704 if (!fWindowRects.empty()) {
Chris Daltonbbfd5162017-11-07 13:35:22 -0700705 stencilClip.fixedClip().setWindowRectangles(fWindowRects,
706 GrWindowRectsState::Mode::kExclusive);
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700707 }
708
csmartdaltonbde96c62016-08-31 12:54:46 -0700709 bool initialState = InitialState::kAllIn == this->initialState();
Jim Van Verth6a40abc2017-11-02 16:56:09 +0000710 renderTargetContext->priv().clearStencilClip(stencilClip.fixedClip(), initialState);
csmartdaltonbde96c62016-08-31 12:54:46 -0700711
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500712 // walk through each clip element and perform its set op with the existing clip.
Chris Dalton79471932017-10-27 01:50:57 -0600713 for (ElementList::Iter iter(fMaskElements); iter.get(); iter.next()) {
csmartdaltonbde96c62016-08-31 12:54:46 -0700714 const Element* element = iter.get();
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500715 GrAAType aaType = GrAAType::kNone;
Brian Salomon7c8460e2017-05-12 11:36:10 -0400716 if (element->isAA() && GrFSAAType::kNone != renderTargetContext->fsaaType()) {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500717 aaType = GrAAType::kMSAA;
718 }
csmartdaltonbde96c62016-08-31 12:54:46 -0700719
720 bool fillInverted = false;
721
722 // This will be used to determine whether the clip shape can be rendered into the
723 // stencil with arbitrary stencil settings.
724 GrPathRenderer::StencilSupport stencilSupport;
725
reed73603f32016-09-20 08:42:38 -0700726 SkRegion::Op op = (SkRegion::Op)element->getOp();
csmartdaltonbde96c62016-08-31 12:54:46 -0700727
728 GrPathRenderer* pr = nullptr;
729 SkPath clipPath;
Brian Salomonf3b46e52017-08-30 11:37:57 -0400730 if (Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()) {
csmartdaltonbde96c62016-08-31 12:54:46 -0700731 stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
732 fillInverted = false;
733 } else {
Brian Salomonf3b46e52017-08-30 11:37:57 -0400734 element->asDeviceSpacePath(&clipPath);
csmartdaltonbde96c62016-08-31 12:54:46 -0700735 fillInverted = clipPath.isInverseFillType();
736 if (fillInverted) {
737 clipPath.toggleInverseFillType();
738 }
739
740 GrShape shape(clipPath, GrStyle::SimpleFill());
741 GrPathRenderer::CanDrawPathArgs canDrawArgs;
Eric Karl5c779752017-05-08 12:02:07 -0700742 canDrawArgs.fCaps = context->caps();
Chris Daltondb91c6e2017-09-08 16:25:08 -0600743 canDrawArgs.fClipConservativeBounds = &stencilClip.fixedClip().scissorRect();
Brian Salomon9a767722017-03-13 17:57:28 -0400744 canDrawArgs.fViewMatrix = &SkMatrix::I();
csmartdaltonbde96c62016-08-31 12:54:46 -0700745 canDrawArgs.fShape = &shape;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500746 canDrawArgs.fAAType = aaType;
csmartdaltonbde96c62016-08-31 12:54:46 -0700747 canDrawArgs.fHasUserStencilSettings = false;
csmartdaltonbde96c62016-08-31 12:54:46 -0700748
749 GrDrawingManager* dm = context->contextPriv().drawingManager();
Brian Salomon82125e92016-12-10 09:35:48 -0500750 pr = dm->getPathRenderer(canDrawArgs, false, GrPathRendererChain::DrawType::kStencil,
csmartdaltonbde96c62016-08-31 12:54:46 -0700751 &stencilSupport);
752 if (!pr) {
753 return false;
754 }
755 }
756
757 bool canRenderDirectToStencil =
758 GrPathRenderer::kNoRestriction_StencilSupport == stencilSupport;
759 bool drawDirectToClip; // Given the renderer, the element,
760 // fill rule, and set operation should
761 // we render the element directly to
762 // stencil bit used for clipping.
763 GrUserStencilSettings const* const* stencilPasses =
764 GrStencilSettings::GetClipPasses(op, canRenderDirectToStencil, fillInverted,
765 &drawDirectToClip);
766
767 // draw the element to the client stencil bits if necessary
768 if (!drawDirectToClip) {
769 static constexpr GrUserStencilSettings kDrawToStencil(
770 GrUserStencilSettings::StaticInit<
771 0x0000,
772 GrUserStencilTest::kAlways,
773 0xffff,
774 GrUserStencilOp::kIncMaybeClamp,
775 GrUserStencilOp::kIncMaybeClamp,
776 0xffff>()
777 );
Brian Salomonf3b46e52017-08-30 11:37:57 -0400778 if (Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()) {
Brian Osman693a5402016-10-27 15:13:22 -0400779 renderTargetContext->priv().stencilRect(stencilClip.fixedClip(), &kDrawToStencil,
Brian Salomonf3b46e52017-08-30 11:37:57 -0400780 aaType, SkMatrix::I(),
781 element->getDeviceSpaceRect());
csmartdaltonbde96c62016-08-31 12:54:46 -0700782 } else {
783 if (!clipPath.isEmpty()) {
784 GrShape shape(clipPath, GrStyle::SimpleFill());
785 if (canRenderDirectToStencil) {
786 GrPaint paint;
Brian Salomona1633922017-01-09 11:46:10 -0500787 paint.setXPFactory(GrDisableColorXPFactory::Get());
csmartdaltonbde96c62016-08-31 12:54:46 -0700788
Robert Phillips256c37b2017-03-01 14:32:46 -0500789 GrPathRenderer::DrawPathArgs args{context,
Brian Salomon82f44312017-01-11 13:42:54 -0500790 std::move(paint),
791 &kDrawToStencil,
792 renderTargetContext,
793 &stencilClip.fixedClip(),
Chris Daltondb91c6e2017-09-08 16:25:08 -0600794 &stencilClip.fixedClip().scissorRect(),
Brian Salomon9a767722017-03-13 17:57:28 -0400795 &SkMatrix::I(),
Brian Salomon82f44312017-01-11 13:42:54 -0500796 &shape,
797 aaType,
798 false};
csmartdaltonbde96c62016-08-31 12:54:46 -0700799 pr->drawPath(args);
800 } else {
801 GrPathRenderer::StencilPathArgs args;
Robert Phillips256c37b2017-03-01 14:32:46 -0500802 args.fContext = context;
Brian Osman11052242016-10-27 14:47:55 -0400803 args.fRenderTargetContext = renderTargetContext;
csmartdaltonbde96c62016-08-31 12:54:46 -0700804 args.fClip = &stencilClip.fixedClip();
Chris Daltondb91c6e2017-09-08 16:25:08 -0600805 args.fClipConservativeBounds = &stencilClip.fixedClip().scissorRect();
Brian Salomon9a767722017-03-13 17:57:28 -0400806 args.fViewMatrix = &SkMatrix::I();
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500807 args.fAAType = aaType;
csmartdaltonbde96c62016-08-31 12:54:46 -0700808 args.fShape = &shape;
809 pr->stencilPath(args);
810 }
811 }
812 }
813 }
814
815 // now we modify the clip bit by rendering either the clip
816 // element directly or a bounding rect of the entire clip.
817 for (GrUserStencilSettings const* const* pass = stencilPasses; *pass; ++pass) {
818 if (drawDirectToClip) {
Brian Salomonf3b46e52017-08-30 11:37:57 -0400819 if (Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()) {
Brian Salomon9a767722017-03-13 17:57:28 -0400820 renderTargetContext->priv().stencilRect(stencilClip, *pass, aaType,
Brian Salomonf3b46e52017-08-30 11:37:57 -0400821 SkMatrix::I(),
822 element->getDeviceSpaceRect());
csmartdaltonbde96c62016-08-31 12:54:46 -0700823 } else {
824 GrShape shape(clipPath, GrStyle::SimpleFill());
825 GrPaint paint;
Brian Salomona1633922017-01-09 11:46:10 -0500826 paint.setXPFactory(GrDisableColorXPFactory::Get());
Robert Phillips256c37b2017-03-01 14:32:46 -0500827 GrPathRenderer::DrawPathArgs args{context,
Brian Salomon82f44312017-01-11 13:42:54 -0500828 std::move(paint),
829 *pass,
830 renderTargetContext,
831 &stencilClip,
Chris Daltondb91c6e2017-09-08 16:25:08 -0600832 &stencilClip.fixedClip().scissorRect(),
Brian Salomon9a767722017-03-13 17:57:28 -0400833 &SkMatrix::I(),
Brian Salomon82f44312017-01-11 13:42:54 -0500834 &shape,
835 aaType,
836 false};
csmartdaltonbde96c62016-08-31 12:54:46 -0700837 pr->drawPath(args);
838 }
839 } else {
840 // The view matrix is setup to do clip space -> stencil space translation, so
841 // draw rect in clip space.
Brian Salomon9a767722017-03-13 17:57:28 -0400842 renderTargetContext->priv().stencilRect(stencilClip, *pass, aaType, SkMatrix::I(),
Chris Dalton79471932017-10-27 01:50:57 -0600843 SkRect::Make(fScissor));
csmartdaltonbde96c62016-08-31 12:54:46 -0700844 }
845 }
846 }
847 return true;
848}