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 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 11 | #include "GrScissorState.h" |
| 12 | #include "GrWindowRectsState.h" |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 13 | |
| 14 | class GrFragmentProcessor; |
| 15 | |
| 16 | /** |
| 17 | * 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] | 18 | * create the final GrPipeline for a GrOp. |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 19 | */ |
| 20 | class GrAppliedClip : public SkNoncopyable { |
| 21 | public: |
| 22 | GrAppliedClip(const SkRect& drawBounds) |
| 23 | : fHasStencilClip(false) |
| 24 | , fClippedDrawBounds(drawBounds) { |
| 25 | } |
| 26 | |
| 27 | const GrScissorState& scissorState() const { return fScissorState; } |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 28 | const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; } |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 29 | GrFragmentProcessor* clipCoverageFragmentProcessor() const { return fClipCoverageFP.get(); } |
| 30 | bool hasStencilClip() const { return fHasStencilClip; } |
| 31 | |
| 32 | /** |
| 33 | * Intersects the applied clip with the provided rect. Returns false if the draw became empty. |
| 34 | */ |
| 35 | bool addScissor(const SkIRect& irect) { |
| 36 | return fScissorState.intersect(irect) && fClippedDrawBounds.intersect(SkRect::Make(irect)); |
| 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 | |
| 44 | void addWindowRectangles(const GrWindowRectangles& windows, const SkIPoint& origin, |
| 45 | GrWindowRectsState::Mode mode) { |
| 46 | SkASSERT(!fWindowRectsState.enabled()); |
| 47 | fWindowRectsState.set(windows, origin, mode); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void addCoverageFP(sk_sp<GrFragmentProcessor> fp) { |
| 51 | SkASSERT(!fClipCoverageFP); |
| 52 | fClipCoverageFP = fp; |
| 53 | } |
| 54 | |
| 55 | void addStencilClip() { |
| 56 | SkASSERT(!fHasStencilClip); |
| 57 | fHasStencilClip = true; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns the device bounds of the draw after clip has been applied. TODO: Ideally this would |
| 62 | * consider the combined effect of all clipping techniques in play (scissor, stencil, fp, etc.). |
| 63 | */ |
| 64 | const SkRect& clippedDrawBounds() const { return fClippedDrawBounds; } |
| 65 | |
| 66 | private: |
| 67 | GrScissorState fScissorState; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 68 | GrWindowRectsState fWindowRectsState; |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 69 | sk_sp<GrFragmentProcessor> fClipCoverageFP; |
| 70 | bool fHasStencilClip; |
| 71 | SkRect fClippedDrawBounds; |
| 72 | typedef SkNoncopyable INHERITED; |
| 73 | }; |
| 74 | |
| 75 | #endif |