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 | |
| 8 | #include "GrClip.h" |
| 9 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 10 | #include "GrDrawContext.h" |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 11 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 12 | void GrNoClip::getConservativeBounds(int width, int height, SkIRect* devResult, |
| 13 | bool* isIntersectionOfRects) const { |
| 14 | devResult->setXYWH(0, 0, width, height); |
| 15 | if (isIntersectionOfRects) { |
| 16 | *isIntersectionOfRects = true; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 17 | } |
| 18 | } |
joshualitt | 9ece6a9 | 2015-02-23 17:03:33 -0800 | [diff] [blame] | 19 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 20 | bool GrFixedClip::quickContains(const SkRect& rect) const { |
| 21 | if (fHasStencilClip) { |
| 22 | return false; |
| 23 | } |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame^] | 24 | return !fScissorState.enabled() || GrClip::IsInsideClip(fScissorState.rect(), rect); |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | void GrFixedClip::getConservativeBounds(int width, int height, SkIRect* devResult, |
| 28 | bool* isIntersectionOfRects) const { |
| 29 | devResult->setXYWH(0, 0, width, height); |
| 30 | if (fScissorState.enabled()) { |
| 31 | if (!devResult->intersect(fScissorState.rect())) { |
| 32 | devResult->setEmpty(); |
| 33 | } |
| 34 | } |
| 35 | if (isIntersectionOfRects) { |
| 36 | *isIntersectionOfRects = true; |
| 37 | } |
| 38 | } |
| 39 | |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame^] | 40 | bool GrFixedClip::apply(GrContext*, GrDrawContext* drawContext, bool isHWAntiAlias, |
| 41 | bool hasUserStencilSettings, GrAppliedClip* out) const { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 42 | if (fScissorState.enabled()) { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 43 | SkIRect tightScissor; |
| 44 | if (!tightScissor.intersect(fScissorState.rect(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 45 | SkIRect::MakeWH(drawContext->width(), drawContext->height()))) { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 46 | return false; |
| 47 | } |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame^] | 48 | if (IsOutsideClip(tightScissor, out->clippedDrawBounds())) { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 49 | return false; |
| 50 | } |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame^] | 51 | if (!IsInsideClip(fScissorState.rect(), out->clippedDrawBounds())) { |
| 52 | out->addScissor(tightScissor); |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 53 | } |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 54 | } |
robertphillips | 5f2fa47 | 2016-05-19 11:36:25 -0700 | [diff] [blame] | 55 | |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame^] | 56 | if (fHasStencilClip) { |
| 57 | out->addStencilClip(); |
| 58 | } |
| 59 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 60 | return true; |
| 61 | } |