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