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 | |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 8 | #include "GrFixedClip.h" |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 9 | |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 10 | #include "GrAppliedClip.h" |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 11 | #include "GrRenderTargetContext.h" |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 12 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 13 | bool GrFixedClip::quickContains(const SkRect& rect) const { |
| 14 | if (fWindowRectsState.enabled()) { |
| 15 | return false; |
| 16 | } |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 17 | return !fScissorState.enabled() || GrClip::IsInsideClip(fScissorState.rect(), rect); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | void GrFixedClip::getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const { |
| 21 | devResult->setXYWH(0, 0, w, h); |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 22 | if (fScissorState.enabled()) { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 23 | if (!devResult->intersect(fScissorState.rect())) { |
| 24 | devResult->setEmpty(); |
| 25 | } |
| 26 | } |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 27 | if (iior) { |
| 28 | *iior = true; |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 29 | } |
| 30 | } |
| 31 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 32 | bool GrFixedClip::isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const { |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 33 | if (fWindowRectsState.enabled()) { |
| 34 | return false; |
| 35 | } |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 36 | if (fScissorState.enabled()) { |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 37 | SkRect rect = SkRect::Make(fScissorState.rect()); |
| 38 | if (!rect.intersects(rtBounds)) { |
| 39 | return false; |
| 40 | } |
| 41 | rr->setRect(rect); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 42 | *aa = GrAA::kNo; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 43 | return true; |
| 44 | } |
| 45 | return false; |
| 46 | }; |
| 47 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 48 | bool GrFixedClip::apply(int rtWidth, int rtHeight, GrAppliedHardClip* out, SkRect* bounds) const { |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 49 | if (fScissorState.enabled()) { |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 50 | SkIRect tightScissor = SkIRect::MakeWH(rtWidth, rtHeight); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 51 | if (!tightScissor.intersect(fScissorState.rect())) { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 52 | return false; |
| 53 | } |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 54 | if (IsOutsideClip(tightScissor, *bounds)) { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 55 | return false; |
| 56 | } |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 57 | if (!IsInsideClip(fScissorState.rect(), *bounds)) { |
| 58 | out->addScissor(tightScissor, bounds); |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 59 | } |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 60 | } |
robertphillips | 5f2fa47 | 2016-05-19 11:36:25 -0700 | [diff] [blame] | 61 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 62 | if (fWindowRectsState.enabled()) { |
| 63 | out->addWindowRectangles(fWindowRectsState); |
| 64 | } |
| 65 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 66 | return true; |
| 67 | } |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 68 | |
| 69 | const GrFixedClip& GrFixedClip::Disabled() { |
| 70 | static const GrFixedClip disabled = GrFixedClip(); |
| 71 | return disabled; |
| 72 | } |