joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010 Google Inc. |
| 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/gpu/GrFixedClip.h" |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "src/gpu/GrAppliedClip.h" |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 11 | |
Michael Ludwig | e06a897 | 2020-06-11 10:29:00 -0400 | [diff] [blame] | 12 | SkIRect GrFixedClip::getConservativeBounds() const { |
| 13 | return fScissorState.rect(); |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 14 | } |
| 15 | |
Michael Ludwig | 6397e80 | 2020-08-05 15:50:01 -0400 | [diff] [blame] | 16 | GrClip::PreClipResult GrFixedClip::preApply(const SkRect& drawBounds, GrAA aa) const { |
| 17 | SkIRect pixelBounds = GetPixelIBounds(drawBounds, aa); |
| 18 | if (!SkIRect::Intersects(fScissorState.rect(), pixelBounds)) { |
Michael Ludwig | 4e3cab7 | 2020-06-30 11:12:46 -0400 | [diff] [blame] | 19 | return Effect::kClippedOut; |
Michael Ludwig | e06a897 | 2020-06-11 10:29:00 -0400 | [diff] [blame] | 20 | } |
Michael Ludwig | 9716414 | 2020-06-24 10:33:43 -0400 | [diff] [blame] | 21 | |
Michael Ludwig | 4e3cab7 | 2020-06-30 11:12:46 -0400 | [diff] [blame] | 22 | if (fWindowRectsState.enabled()) { |
| 23 | return Effect::kClipped; |
Michael Ludwig | 9716414 | 2020-06-24 10:33:43 -0400 | [diff] [blame] | 24 | } |
Michael Ludwig | 4e3cab7 | 2020-06-30 11:12:46 -0400 | [diff] [blame] | 25 | |
Michael Ludwig | 6397e80 | 2020-08-05 15:50:01 -0400 | [diff] [blame] | 26 | if (!fScissorState.enabled() || fScissorState.rect().contains(pixelBounds)) { |
Michael Ludwig | 4e3cab7 | 2020-06-30 11:12:46 -0400 | [diff] [blame] | 27 | // Either no scissor or the scissor doesn't clip the draw |
| 28 | return Effect::kUnclipped; |
| 29 | } |
| 30 | // Report the scissor as a degenerate round rect |
| 31 | return {SkRect::Make(fScissorState.rect()), GrAA::kNo}; |
| 32 | } |
| 33 | |
Michael Ludwig | 6397e80 | 2020-08-05 15:50:01 -0400 | [diff] [blame] | 34 | GrClip::Effect GrFixedClip::apply(GrAppliedHardClip* out, SkIRect* bounds) const { |
| 35 | if (!SkIRect::Intersects(fScissorState.rect(), *bounds)) { |
Michael Ludwig | 4e3cab7 | 2020-06-30 11:12:46 -0400 | [diff] [blame] | 36 | return Effect::kClippedOut; |
| 37 | } |
| 38 | |
| 39 | Effect effect = Effect::kUnclipped; |
Michael Ludwig | 6397e80 | 2020-08-05 15:50:01 -0400 | [diff] [blame] | 40 | if (fScissorState.enabled() && !fScissorState.rect().contains(*bounds)) { |
| 41 | SkAssertResult(bounds->intersect(fScissorState.rect())); |
| 42 | out->setScissor(*bounds); |
Michael Ludwig | 4e3cab7 | 2020-06-30 11:12:46 -0400 | [diff] [blame] | 43 | effect = Effect::kClipped; |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 44 | } |
robertphillips | 5f2fa47 | 2016-05-19 11:36:25 -0700 | [diff] [blame] | 45 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 46 | if (fWindowRectsState.enabled()) { |
| 47 | out->addWindowRectangles(fWindowRectsState); |
Michael Ludwig | 4e3cab7 | 2020-06-30 11:12:46 -0400 | [diff] [blame] | 48 | // We could iterate each window rectangle to check for intersection, but be conservative |
| 49 | // and report that it's clipped |
| 50 | effect = Effect::kClipped; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Michael Ludwig | 4e3cab7 | 2020-06-30 11:12:46 -0400 | [diff] [blame] | 53 | return effect; |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 54 | } |