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 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 10 | #include "GrClipMaskManager.h" |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 11 | #include "GrDrawContext.h" |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 12 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 13 | void GrNoClip::getConservativeBounds(int width, int height, SkIRect* devResult, |
| 14 | bool* isIntersectionOfRects) const { |
| 15 | devResult->setXYWH(0, 0, width, height); |
| 16 | if (isIntersectionOfRects) { |
| 17 | *isIntersectionOfRects = true; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 18 | } |
| 19 | } |
joshualitt | 9ece6a9 | 2015-02-23 17:03:33 -0800 | [diff] [blame] | 20 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 21 | bool GrFixedClip::quickContains(const SkRect& rect) const { |
| 22 | if (fHasStencilClip) { |
| 23 | return false; |
| 24 | } |
| 25 | if (!fScissorState.enabled()) { |
| 26 | return true; |
| 27 | } |
| 28 | return fScissorState.rect().contains(rect); |
| 29 | } |
| 30 | |
| 31 | void GrFixedClip::getConservativeBounds(int width, int height, SkIRect* devResult, |
| 32 | bool* isIntersectionOfRects) const { |
| 33 | devResult->setXYWH(0, 0, width, height); |
| 34 | if (fScissorState.enabled()) { |
| 35 | if (!devResult->intersect(fScissorState.rect())) { |
| 36 | devResult->setEmpty(); |
| 37 | } |
| 38 | } |
| 39 | if (isIntersectionOfRects) { |
| 40 | *isIntersectionOfRects = true; |
| 41 | } |
| 42 | } |
| 43 | |
robertphillips | 59cf61a | 2016-07-13 09:18:21 -0700 | [diff] [blame] | 44 | bool GrFixedClip::apply(GrContext*, |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 45 | GrDrawContext* drawContext, |
robertphillips | 59cf61a | 2016-07-13 09:18:21 -0700 | [diff] [blame] | 46 | const SkRect* devBounds, |
| 47 | bool isHWAntiAlias, |
| 48 | bool hasUserStencilSettings, |
| 49 | GrAppliedClip* out) const { |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 50 | SkASSERT(!fDeviceBounds.isLargest()); |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 51 | if (fScissorState.enabled()) { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 52 | SkIRect tightScissor; |
| 53 | if (!tightScissor.intersect(fScissorState.rect(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 54 | SkIRect::MakeWH(drawContext->width(), drawContext->height()))) { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 55 | return false; |
| 56 | } |
| 57 | if (devBounds && !devBounds->intersects(SkRect::Make(tightScissor))) { |
| 58 | return false; |
| 59 | } |
csmartdalton | 97f6cd5 | 2016-07-13 13:37:08 -0700 | [diff] [blame^] | 60 | if (!devBounds || !CanIgnoreScissor(fScissorState.rect(), *devBounds)) { |
| 61 | if (fHasStencilClip) { |
| 62 | out->makeScissoredStencil(tightScissor, &fDeviceBounds); |
| 63 | } else { |
| 64 | out->makeScissored(tightScissor); |
| 65 | } |
| 66 | return true; |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 67 | } |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 68 | } |
robertphillips | 5f2fa47 | 2016-05-19 11:36:25 -0700 | [diff] [blame] | 69 | |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 70 | out->makeStencil(fHasStencilClip, fDeviceBounds); |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 71 | return true; |
| 72 | } |
| 73 | |
| 74 | bool GrClipStackClip::quickContains(const SkRect& rect) const { |
| 75 | if (!fStack) { |
| 76 | return true; |
| 77 | } |
| 78 | return fStack->quickContains(rect.makeOffset(SkIntToScalar(fOrigin.x()), |
| 79 | SkIntToScalar(fOrigin.y()))); |
| 80 | } |
| 81 | |
| 82 | void GrClipStackClip::getConservativeBounds(int width, int height, SkIRect* devResult, |
| 83 | bool* isIntersectionOfRects) const { |
| 84 | if (!fStack) { |
| 85 | devResult->setXYWH(0, 0, width, height); |
| 86 | if (isIntersectionOfRects) { |
| 87 | *isIntersectionOfRects = true; |
| 88 | } |
| 89 | return; |
| 90 | } |
| 91 | SkRect devBounds; |
| 92 | fStack->getConservativeBounds(-fOrigin.x(), -fOrigin.y(), width, height, &devBounds, |
| 93 | isIntersectionOfRects); |
| 94 | devBounds.roundOut(devResult); |
| 95 | } |
| 96 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 97 | bool GrClipStackClip::apply(GrContext* context, |
robertphillips | 59cf61a | 2016-07-13 09:18:21 -0700 | [diff] [blame] | 98 | GrDrawContext* drawContext, |
| 99 | const SkRect* devBounds, |
| 100 | bool useHWAA, |
| 101 | bool hasUserStencilSettings, |
| 102 | GrAppliedClip* out) const { |
| 103 | return GrClipMaskManager::SetupClipping(context, drawContext, *this, devBounds, |
| 104 | useHWAA, hasUserStencilSettings, out); |
joshualitt | 9ece6a9 | 2015-02-23 17:03:33 -0800 | [diff] [blame] | 105 | } |