csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | #ifndef GrAppliedClip_DEFINED |
| 9 | #define GrAppliedClip_DEFINED |
| 10 | |
Hal Canary | 6b20a55 | 2017-02-07 14:09:38 -0500 | [diff] [blame] | 11 | #include "GrFragmentProcessor.h" |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 12 | #include "GrScissorState.h" |
| 13 | #include "GrWindowRectsState.h" |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 14 | |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 15 | /** |
| 16 | * Produced by GrClip. It provides a set of modifications to the drawing state that are used to |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 17 | * create the final GrPipeline for a GrOp. |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 18 | */ |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 19 | class GrAppliedClip { |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 20 | public: |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 21 | GrAppliedClip() = default; |
| 22 | GrAppliedClip(GrAppliedClip&& that) = default; |
| 23 | GrAppliedClip(const GrAppliedClip&) = delete; |
| 24 | |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 25 | const GrScissorState& scissorState() const { return fScissorState; } |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 26 | const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; } |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 27 | GrFragmentProcessor* clipCoverageFragmentProcessor() const { return fClipCoverageFP.get(); } |
| 28 | bool hasStencilClip() const { return fHasStencilClip; } |
| 29 | |
| 30 | /** |
| 31 | * Intersects the applied clip with the provided rect. Returns false if the draw became empty. |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 32 | * 'clippedDrawBounds' will be intersected with 'irect'. This returns false if the clip becomes |
| 33 | * empty or the draw no longer intersects the clip. In either case the draw can be skipped. |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 34 | */ |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 35 | bool addScissor(const SkIRect& irect, SkRect* clippedDrawBounds) { |
| 36 | return fScissorState.intersect(irect) && clippedDrawBounds->intersect(SkRect::Make(irect)); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 37 | } |
| 38 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 39 | void addWindowRectangles(const GrWindowRectsState& windowState) { |
| 40 | SkASSERT(!fWindowRectsState.enabled()); |
| 41 | fWindowRectsState = windowState; |
| 42 | } |
| 43 | |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 44 | void addWindowRectangles(const GrWindowRectangles& windows, GrWindowRectsState::Mode mode) { |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 45 | SkASSERT(!fWindowRectsState.enabled()); |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 46 | fWindowRectsState.set(windows, mode); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void addCoverageFP(sk_sp<GrFragmentProcessor> fp) { |
| 50 | SkASSERT(!fClipCoverageFP); |
| 51 | fClipCoverageFP = fp; |
| 52 | } |
| 53 | |
| 54 | void addStencilClip() { |
| 55 | SkASSERT(!fHasStencilClip); |
| 56 | fHasStencilClip = true; |
| 57 | } |
| 58 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 59 | bool doesClip() const { |
| 60 | return fScissorState.enabled() || fClipCoverageFP || fHasStencilClip || |
| 61 | fWindowRectsState.enabled(); |
| 62 | } |
| 63 | |
| 64 | bool operator==(const GrAppliedClip& that) const { |
| 65 | if (fScissorState != that.fScissorState || fHasStencilClip != that.fHasStencilClip) { |
| 66 | return false; |
| 67 | } |
| 68 | if (SkToBool(fClipCoverageFP)) { |
| 69 | if (!SkToBool(that.fClipCoverageFP) || |
| 70 | !that.fClipCoverageFP->isEqual(*fClipCoverageFP)) { |
| 71 | return false; |
| 72 | } |
| 73 | } else if (SkToBool(that.fClipCoverageFP)) { |
| 74 | return false; |
| 75 | } |
| 76 | return fWindowRectsState == that.fWindowRectsState; |
| 77 | } |
| 78 | bool operator!=(const GrAppliedClip& that) const { return !(*this == that); } |
| 79 | |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 80 | private: |
| 81 | GrScissorState fScissorState; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 82 | GrWindowRectsState fWindowRectsState; |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 83 | sk_sp<GrFragmentProcessor> fClipCoverageFP; |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 84 | bool fHasStencilClip = false; |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | #endif |