csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -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 GrScissorState_DEFINED |
| 9 | #define GrScissorState_DEFINED |
| 10 | |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 11 | #include "SkRect.h" |
| 12 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 13 | class GrScissorState { |
| 14 | public: |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 15 | GrScissorState() : fEnabled(false) {} |
| 16 | GrScissorState(const SkIRect& rect) : fEnabled(true), fRect(rect) {} |
| 17 | void setDisabled() { fEnabled = false; } |
| 18 | void set(const SkIRect& rect) { fRect = rect; fEnabled = true; } |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 19 | bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& rect) { |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 20 | if (!fEnabled) { |
| 21 | this->set(rect); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 22 | return true; |
| 23 | } |
| 24 | return fRect.intersect(rect); |
| 25 | } |
| 26 | bool operator==(const GrScissorState& other) const { |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 27 | return fEnabled == other.fEnabled && |
| 28 | (false == fEnabled || fRect == other.fRect); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 29 | } |
| 30 | bool operator!=(const GrScissorState& other) const { return !(*this == other); } |
| 31 | |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 32 | bool enabled() const { return fEnabled; } |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 33 | const SkIRect& rect() const { return fRect; } |
| 34 | |
| 35 | private: |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 36 | bool fEnabled; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 37 | SkIRect fRect; |
| 38 | }; |
| 39 | |
| 40 | #endif |