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 | } |
| 24 | if (!fScissorState.enabled()) { |
| 25 | return true; |
| 26 | } |
| 27 | return fScissorState.rect().contains(rect); |
| 28 | } |
| 29 | |
| 30 | void GrFixedClip::getConservativeBounds(int width, int height, SkIRect* devResult, |
| 31 | bool* isIntersectionOfRects) const { |
| 32 | devResult->setXYWH(0, 0, width, height); |
| 33 | if (fScissorState.enabled()) { |
| 34 | if (!devResult->intersect(fScissorState.rect())) { |
| 35 | devResult->setEmpty(); |
| 36 | } |
| 37 | } |
| 38 | if (isIntersectionOfRects) { |
| 39 | *isIntersectionOfRects = true; |
| 40 | } |
| 41 | } |
| 42 | |
robertphillips | 59cf61a | 2016-07-13 09:18:21 -0700 | [diff] [blame] | 43 | bool GrFixedClip::apply(GrContext*, |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 44 | GrDrawContext* drawContext, |
robertphillips | 59cf61a | 2016-07-13 09:18:21 -0700 | [diff] [blame] | 45 | const SkRect* devBounds, |
| 46 | bool isHWAntiAlias, |
| 47 | bool hasUserStencilSettings, |
| 48 | GrAppliedClip* out) const { |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 49 | SkASSERT(!fDeviceBounds.isLargest()); |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 50 | if (fScissorState.enabled()) { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 51 | SkIRect tightScissor; |
| 52 | if (!tightScissor.intersect(fScissorState.rect(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 53 | SkIRect::MakeWH(drawContext->width(), drawContext->height()))) { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 54 | return false; |
| 55 | } |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 56 | if (devBounds && IsOutsideClip(tightScissor, *devBounds)) { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 57 | return false; |
| 58 | } |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 59 | if (!devBounds || !IsInsideClip(fScissorState.rect(), *devBounds)) { |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame] | 60 | if (fHasStencilClip) { |
| 61 | out->makeScissoredStencil(tightScissor, &fDeviceBounds); |
| 62 | } else { |
| 63 | out->makeScissored(tightScissor); |
| 64 | } |
| 65 | return true; |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 66 | } |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 67 | } |
robertphillips | 5f2fa47 | 2016-05-19 11:36:25 -0700 | [diff] [blame] | 68 | |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 69 | out->makeStencil(fHasStencilClip, fDeviceBounds); |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 70 | return true; |
| 71 | } |