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" |
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 | |
| 43 | bool GrFixedClip::apply(GrClipMaskManager*, const GrPipelineBuilder& pipelineBuilder, |
| 44 | const SkRect* devBounds, GrAppliedClip* out) const { |
| 45 | if (fScissorState.enabled()) { |
| 46 | const GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
| 47 | SkIRect tightScissor; |
| 48 | if (!tightScissor.intersect(fScissorState.rect(), |
| 49 | SkIRect::MakeWH(rt->width(), rt->height()))) { |
| 50 | return false; |
| 51 | } |
| 52 | if (devBounds && !devBounds->intersects(SkRect::Make(tightScissor))) { |
| 53 | return false; |
| 54 | } |
robertphillips | 5f2fa47 | 2016-05-19 11:36:25 -0700 | [diff] [blame] | 55 | out->makeScissoredStencil(fHasStencilClip, tightScissor); |
| 56 | return true; |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 57 | } |
robertphillips | 5f2fa47 | 2016-05-19 11:36:25 -0700 | [diff] [blame] | 58 | |
| 59 | out->makeStencil(fHasStencilClip); |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 60 | return true; |
| 61 | } |
| 62 | |
| 63 | bool GrClipStackClip::quickContains(const SkRect& rect) const { |
| 64 | if (!fStack) { |
| 65 | return true; |
| 66 | } |
| 67 | return fStack->quickContains(rect.makeOffset(SkIntToScalar(fOrigin.x()), |
| 68 | SkIntToScalar(fOrigin.y()))); |
| 69 | } |
| 70 | |
| 71 | void GrClipStackClip::getConservativeBounds(int width, int height, SkIRect* devResult, |
| 72 | bool* isIntersectionOfRects) const { |
| 73 | if (!fStack) { |
| 74 | devResult->setXYWH(0, 0, width, height); |
| 75 | if (isIntersectionOfRects) { |
| 76 | *isIntersectionOfRects = true; |
| 77 | } |
| 78 | return; |
| 79 | } |
| 80 | SkRect devBounds; |
| 81 | fStack->getConservativeBounds(-fOrigin.x(), -fOrigin.y(), width, height, &devBounds, |
| 82 | isIntersectionOfRects); |
| 83 | devBounds.roundOut(devResult); |
| 84 | } |
| 85 | |
| 86 | bool GrClipStackClip::apply(GrClipMaskManager* clipMaskManager, |
| 87 | const GrPipelineBuilder& pipelineBuilder, const SkRect* devBounds, |
| 88 | GrAppliedClip* out) const { |
| 89 | // TODO: Collapse ClipMaskManager into this class.(?) |
| 90 | return clipMaskManager->setupClipping(pipelineBuilder, *this, devBounds, out); |
joshualitt | 9ece6a9 | 2015-02-23 17:03:33 -0800 | [diff] [blame] | 91 | } |