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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrClip.h" |
| 12 | #include "src/gpu/GrScissorState.h" |
| 13 | #include "src/gpu/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: |
Michael Ludwig | d1d997e | 2020-06-04 15:52:44 -0400 | [diff] [blame] | 20 | explicit GrFixedClip(const SkISize& rtDims) : fScissorState(rtDims) {} |
| 21 | GrFixedClip(const SkISize& rtDims, const SkIRect& scissorRect) |
| 22 | : GrFixedClip(rtDims) { |
| 23 | SkAssertResult(fScissorState.set(scissorRect)); |
| 24 | } |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 25 | |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 26 | const GrScissorState& scissorState() const { return fScissorState; } |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 27 | bool scissorEnabled() const { return fScissorState.enabled(); } |
Michael Ludwig | d1d997e | 2020-06-04 15:52:44 -0400 | [diff] [blame] | 28 | // Returns the scissor rect or rt bounds if the scissor test is not enabled. |
| 29 | const SkIRect& scissorRect() const { return fScissorState.rect(); } |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 30 | |
| 31 | void disableScissor() { fScissorState.setDisabled(); } |
| 32 | |
Michael Ludwig | d1d997e | 2020-06-04 15:52:44 -0400 | [diff] [blame] | 33 | bool SK_WARN_UNUSED_RESULT setScissor(const SkIRect& irect) { |
| 34 | return fScissorState.set(irect); |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 35 | } |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 36 | bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& irect) { |
| 37 | return fScissorState.intersect(irect); |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 38 | } |
| 39 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 40 | const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; } |
| 41 | bool hasWindowRectangles() const { return fWindowRectsState.enabled(); } |
| 42 | |
| 43 | void disableWindowRectangles() { fWindowRectsState.setDisabled(); } |
| 44 | |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 45 | void setWindowRectangles(const GrWindowRectangles& windows, GrWindowRectsState::Mode mode) { |
| 46 | fWindowRectsState.set(windows, mode); |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 47 | } |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 48 | |
Michael Ludwig | 4e3cab7 | 2020-06-30 11:12:46 -0400 | [diff] [blame] | 49 | SkIRect getConservativeBounds() const final; |
Michael Ludwig | 6397e80 | 2020-08-05 15:50:01 -0400 | [diff] [blame] | 50 | Effect apply(GrAppliedHardClip*, SkIRect*) const final; |
| 51 | PreClipResult preApply(const SkRect& drawBounds, GrAA aa) const final; |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 52 | |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 53 | private: |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 54 | GrScissorState fScissorState; |
| 55 | GrWindowRectsState fWindowRectsState; |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | #endif |