csmartdalton | 02fa32c | 2016-08-19 13:29:27 -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 GrFixedClip_DEFINED |
| 9 | #define GrFixedClip_DEFINED |
| 10 | |
| 11 | #include "GrClip.h" |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 12 | #include "GrScissorState.h" |
| 13 | #include "GrWindowRectsState.h" |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 14 | |
| 15 | /** |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 16 | * Implements GrHardClip with scissor and window rectangles. |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 17 | */ |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 18 | class GrFixedClip final : public GrHardClip { |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 19 | public: |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 20 | GrFixedClip() = default; |
| 21 | explicit GrFixedClip(const SkIRect& scissorRect) : fScissorState(scissorRect) {} |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 22 | |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 23 | const GrScissorState& scissorState() const { return fScissorState; } |
| 24 | bool scissorEnabled() const { return fScissorState.enabled(); } |
| 25 | const SkIRect& scissorRect() const { SkASSERT(scissorEnabled()); return fScissorState.rect(); } |
| 26 | |
| 27 | void disableScissor() { fScissorState.setDisabled(); } |
| 28 | |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 29 | void setScissor(const SkIRect& irect) { |
| 30 | fScissorState.set(irect); |
| 31 | } |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 32 | bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& irect) { |
| 33 | return fScissorState.intersect(irect); |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 34 | } |
| 35 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 36 | const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; } |
| 37 | bool hasWindowRectangles() const { return fWindowRectsState.enabled(); } |
| 38 | |
| 39 | void disableWindowRectangles() { fWindowRectsState.setDisabled(); } |
| 40 | |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 41 | void setWindowRectangles(const GrWindowRectangles& windows, GrWindowRectsState::Mode mode) { |
| 42 | fWindowRectsState.set(windows, mode); |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 43 | } |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 44 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 45 | bool quickContains(const SkRect&) const override; |
| 46 | void getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const override; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 47 | bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const override; |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 48 | bool apply(int rtWidth, int rtHeight, GrAppliedHardClip*, SkRect*) const override; |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 49 | |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 50 | static const GrFixedClip& Disabled(); |
| 51 | |
| 52 | private: |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 53 | GrScissorState fScissorState; |
| 54 | GrWindowRectsState fWindowRectsState; |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | #endif |