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"
12#include "GrScissorState.h"
13#include "GrWindowRectsState.h"
14
15/**
16 * GrFixedClip is a clip that gets implemented by fixed-function hardware.
17 */
18class GrFixedClip final : public GrClip {
19public:
20    GrFixedClip() = default;
21    explicit GrFixedClip(const SkIRect& scissorRect) : fScissorState(scissorRect) {}
22
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);
31    }
32
33    const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; }
34    bool hasWindowRectangles() const { return fWindowRectsState.enabled(); }
35
36    void disableWindowRectangles() { fWindowRectsState.setDisabled(); }
37
38    void setWindowRectangles(const GrWindowRectangles& windows, GrWindowRectsState::Mode mode) {
39        fWindowRectsState.set(windows, mode);
40    }
41
42    bool quickContains(const SkRect&) const override;
43    void getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const override;
44    bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const override;
45    bool apply(GrContext*, GrRenderTargetContext*, bool, bool, GrAppliedClip*,
46               SkRect*) const override;
47
48    static const GrFixedClip& Disabled();
49
50private:
51    GrScissorState       fScissorState;
52    GrWindowRectsState   fWindowRectsState;
53};
54
55#endif
56