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