aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrWindowRectsState.h
blob: 9d3b61b9cb350aa513e28683d7b8927f19b863c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrWindowRectsState_DEFINED
#define GrWindowRectsState_DEFINED

#include "GrWindowRectangles.h"

class GrWindowRectsState {
public:
    enum class Mode : bool {
        kExclusive,
        kInclusive
    };

    GrWindowRectsState() : fMode(Mode::kExclusive) {}
    GrWindowRectsState(const GrWindowRectangles& windows, const SkIPoint& origin, Mode mode)
        : fMode(mode)
        , fOrigin(origin)
        , fWindows(windows) {
    }

    bool enabled() const { return Mode::kInclusive == fMode || !fWindows.empty(); }
    Mode mode() const { return fMode; }
    const SkIPoint& origin() const { return fOrigin; }
    const GrWindowRectangles& windows() const { return fWindows; }
    int numWindows() const { return fWindows.count(); }

    void setDisabled() {
        fMode = Mode::kExclusive;
        fWindows.reset();
    }

    void set(const GrWindowRectangles& windows, const SkIPoint& origin, Mode mode) {
        fMode = mode;
        fOrigin = origin;
        fWindows = windows;
    }

    bool cheapEqualTo(const GrWindowRectsState& that) const {
        if (fMode != that.fMode) {
            return false;
        }
        if (!fWindows.empty() && fOrigin != that.fOrigin) {
            return false;
        }
        return fWindows == that.fWindows;
    }

private:
    Mode                 fMode;
    SkIPoint             fOrigin;
    GrWindowRectangles   fWindows;
};

#endif