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 | /** |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 16 | * GrFixedClip is a clip that gets implemented by fixed-function hardware. |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 17 | */ |
| 18 | class GrFixedClip final : public GrClip { |
| 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 | |
| 29 | bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& irect) { |
| 30 | return fScissorState.intersect(irect); |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 31 | } |
| 32 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 33 | const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; } |
| 34 | bool hasWindowRectangles() const { return fWindowRectsState.enabled(); } |
| 35 | |
| 36 | void disableWindowRectangles() { fWindowRectsState.setDisabled(); } |
| 37 | |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 38 | void setWindowRectangles(const GrWindowRectangles& windows, GrWindowRectsState::Mode mode) { |
| 39 | fWindowRectsState.set(windows, mode); |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 40 | } |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 41 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 42 | bool quickContains(const SkRect&) const override; |
| 43 | void getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const override; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 44 | bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const override; |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 45 | bool apply(GrContext*, GrRenderTargetContext*, bool, bool, GrAppliedClip*, |
| 46 | SkRect*) const override; |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 47 | |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 48 | static const GrFixedClip& Disabled(); |
| 49 | |
| 50 | private: |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 51 | GrScissorState fScissorState; |
| 52 | GrWindowRectsState fWindowRectsState; |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | #endif |