| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrReducedClip.h" | 8 #include "GrReducedClip.h" |
| 9 | 9 |
| 10 #include "GrClip.h" | 10 #include "GrClip.h" |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 if (element->isAA()) { | 309 if (element->isAA()) { |
| 310 --numAAElements; | 310 --numAAElements; |
| 311 } | 311 } |
| 312 result->popHead(); | 312 result->popHead(); |
| 313 element = result->headIter().get(); | 313 element = result->headIter().get(); |
| 314 } | 314 } |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 *requiresAA = numAAElements > 0; | 317 *requiresAA = numAAElements > 0; |
| 318 | 318 |
| 319 if (0 == result->count()) { | |
| 320 if (initialState == InitialTriState::kAllIn) { | |
| 321 *resultGenID = SkClipStack::kWideOpenGenID; | |
| 322 } else { | |
| 323 *resultGenID = SkClipStack::kEmptyGenID; | |
| 324 } | |
| 325 } | |
| 326 | |
| 327 SkASSERT(SkClipStack::kInvalidGenID != *resultGenID); | |
| 328 SkASSERT(InitialTriState::kUnknown != initialState); | 319 SkASSERT(InitialTriState::kUnknown != initialState); |
| 329 return static_cast<GrReducedClip::InitialState>(initialState); | 320 return static_cast<GrReducedClip::InitialState>(initialState); |
| 330 } | 321 } |
| 331 | 322 |
| 332 /* | 323 /* |
| 333 There are plenty of optimizations that could be added here. Maybe flips could be
folded into | 324 There are plenty of optimizations that could be added here. Maybe flips could be
folded into |
| 334 earlier operations. Or would inserting flips and reversing earlier ops ever be a
win? Perhaps | 325 earlier operations. Or would inserting flips and reversing earlier ops ever be a
win? Perhaps |
| 335 for the case where the bounds are kInsideOut_BoundsType. We could restrict earli
er operations | 326 for the case where the bounds are kInsideOut_BoundsType. We could restrict earli
er operations |
| 336 based on later intersect operations, and perhaps remove intersect-rects. We coul
d optionally | 327 based on later intersect operations, and perhaps remove intersect-rects. We coul
d optionally |
| 337 take a rect in case the caller knows a bound on what is to be drawn through this
clip. | 328 take a rect in case the caller knows a bound on what is to be drawn through this
clip. |
| 338 */ | 329 */ |
| 339 GrReducedClip::GrReducedClip(const SkClipStack& stack, const SkRect& queryBounds
) { | 330 GrReducedClip::GrReducedClip(const SkClipStack& stack, const SkRect& queryBounds
) { |
| 340 SkASSERT(!queryBounds.isEmpty()); | 331 SkASSERT(!queryBounds.isEmpty()); |
| 341 | |
| 342 // The clip established by the element list might be cached based on the las
t | |
| 343 // generation id. When we make early returns, we do not know what was the ge
neration | |
| 344 // id that lead to the state. Make a conservative guess. | |
| 345 fGenID = stack.getTopmostGenID(); | |
| 346 fHasIBounds = false; | 332 fHasIBounds = false; |
| 347 | 333 |
| 348 if (stack.isWideOpen()) { | 334 if (stack.isWideOpen()) { |
| 349 fInitialState = InitialState::kAllIn; | 335 fInitialState = InitialState::kAllIn; |
| 350 return; | 336 return; |
| 351 } | 337 } |
| 352 | 338 |
| 353 SkClipStack::BoundsType stackBoundsType; | 339 SkClipStack::BoundsType stackBoundsType; |
| 354 SkRect stackBounds; | 340 SkRect stackBounds; |
| 355 bool iior; | 341 bool iior; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 380 } | 366 } |
| 381 | 367 |
| 382 SkRect tightBounds; | 368 SkRect tightBounds; |
| 383 SkAssertResult(tightBounds.intersect(stackBounds, queryBounds)); | 369 SkAssertResult(tightBounds.intersect(stackBounds, queryBounds)); |
| 384 fIBounds = GrClip::GetPixelIBounds(tightBounds); | 370 fIBounds = GrClip::GetPixelIBounds(tightBounds); |
| 385 SkASSERT(!fIBounds.isEmpty()); // Empty should have been blocked by IsOu
tsideClip above. | 371 SkASSERT(!fIBounds.isEmpty()); // Empty should have been blocked by IsOu
tsideClip above. |
| 386 fHasIBounds = true; | 372 fHasIBounds = true; |
| 387 | 373 |
| 388 // Implement the clip with an AA rect element. | 374 // Implement the clip with an AA rect element. |
| 389 fElements.addToHead(stackBounds, SkRegion::kReplace_Op, true/*doAA*/); | 375 fElements.addToHead(stackBounds, SkRegion::kReplace_Op, true/*doAA*/); |
| 376 fElementsGenID = stack.getTopmostGenID(); |
| 390 fRequiresAA = true; | 377 fRequiresAA = true; |
| 391 | 378 |
| 392 fInitialState = InitialState::kAllOut; | 379 fInitialState = InitialState::kAllOut; |
| 393 return; | 380 return; |
| 394 } | 381 } |
| 395 | 382 |
| 396 SkRect tighterQuery = queryBounds; | 383 SkRect tighterQuery = queryBounds; |
| 397 if (SkClipStack::kNormal_BoundsType == stackBoundsType) { | 384 if (SkClipStack::kNormal_BoundsType == stackBoundsType) { |
| 398 // Tighten the query by introducing a new clip at the stack's pixel boun
daries. (This new | 385 // Tighten the query by introducing a new clip at the stack's pixel boun
daries. (This new |
| 399 // clip will be enforced by the scissor through fIBounds.) | 386 // clip will be enforced by the scissor through fIBounds.) |
| 400 SkAssertResult(tighterQuery.intersect(GrClip::GetPixelBounds(stackBounds
))); | 387 SkAssertResult(tighterQuery.intersect(GrClip::GetPixelBounds(stackBounds
))); |
| 401 } | 388 } |
| 402 | 389 |
| 403 fIBounds = GrClip::GetPixelIBounds(tighterQuery); | 390 fIBounds = GrClip::GetPixelIBounds(tighterQuery); |
| 404 SkASSERT(!fIBounds.isEmpty()); // Empty should have been blocked by IsOutsid
eClip above. | 391 SkASSERT(!fIBounds.isEmpty()); // Empty should have been blocked by IsOutsid
eClip above. |
| 405 fHasIBounds = true; | 392 fHasIBounds = true; |
| 406 | 393 |
| 407 // Now that we have determined the bounds to use and filtered out the trivia
l cases, call the | 394 // Now that we have determined the bounds to use and filtered out the trivia
l cases, call the |
| 408 // helper that actually walks the stack. | 395 // helper that actually walks the stack. |
| 409 fInitialState = reduced_stack_walker(stack, tighterQuery, fIBounds, &fElemen
ts, &fGenID, | 396 fInitialState = reduced_stack_walker(stack, tighterQuery, fIBounds, &fElemen
ts, &fElementsGenID, |
| 410 &fRequiresAA); | 397 &fRequiresAA); |
| 411 } | 398 } |
| OLD | NEW |