blob: dac735b023da40c1225b1a95a1ce455455f1d849 [file] [log] [blame]
csmartdaltonbf4a8f92016-09-06 10:01:06 -07001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkRect.h"
Brian Salomond818ebf2018-07-02 14:08:49 +000012
csmartdaltonbf4a8f92016-09-06 10:01:06 -070013class GrScissorState {
14public:
Brian Salomond818ebf2018-07-02 14:08:49 +000015 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; }
csmartdaltonbf4a8f92016-09-06 10:01:06 -070019 bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& rect) {
Brian Salomond818ebf2018-07-02 14:08:49 +000020 if (!fEnabled) {
21 this->set(rect);
csmartdaltonbf4a8f92016-09-06 10:01:06 -070022 return true;
23 }
24 return fRect.intersect(rect);
25 }
26 bool operator==(const GrScissorState& other) const {
Brian Salomond818ebf2018-07-02 14:08:49 +000027 return fEnabled == other.fEnabled &&
28 (false == fEnabled || fRect == other.fRect);
csmartdaltonbf4a8f92016-09-06 10:01:06 -070029 }
30 bool operator!=(const GrScissorState& other) const { return !(*this == other); }
31
Brian Salomond818ebf2018-07-02 14:08:49 +000032 bool enabled() const { return fEnabled; }
Robert Phillipsff2f3802019-11-18 16:36:54 -050033 const SkIRect& rect() const {
34 SkASSERT(fEnabled);
35 return fRect;
36 }
csmartdaltonbf4a8f92016-09-06 10:01:06 -070037
38private:
Brian Salomond818ebf2018-07-02 14:08:49 +000039 bool fEnabled;
csmartdaltonbf4a8f92016-09-06 10:01:06 -070040 SkIRect fRect;
41};
42
43#endif