aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrFixedClip.h
blob: 8b3a9c1c9e9d7827f687a22be23b9f010502b0e8 (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 GrFixedClip_DEFINED
#define GrFixedClip_DEFINED

#include "GrClip.h"
#include "GrTypesPriv.h"

/**
 * GrFixedClip is a clip that gets implemented by fixed-function hardware.
 */
class GrFixedClip final : public GrClip {
public:
    GrFixedClip() = default;
    explicit GrFixedClip(const SkIRect& scissorRect) : fScissorState(scissorRect) {}

    const GrScissorState& scissorState() const { return fScissorState; }
    bool scissorEnabled() const { return fScissorState.enabled(); }
    const SkIRect& scissorRect() const { SkASSERT(scissorEnabled()); return fScissorState.rect(); }

    void disableScissor() { fScissorState.setDisabled(); }

    bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& irect) {
        return fScissorState.intersect(irect);
    }

    bool quickContains(const SkRect& rect) const final {
        return !fScissorState.enabled() || GrClip::IsInsideClip(fScissorState.rect(), rect);
    }
    void getConservativeBounds(int width, int height, SkIRect* devResult,
                               bool* isIntersectionOfRects) const final;

    bool isRRect(const SkRect& rtBounds, SkRRect* rr, bool* aa) const override {
        if (fScissorState.enabled()) {
            SkRect rect = SkRect::Make(fScissorState.rect());
            if (!rect.intersects(rtBounds)) {
                return false;
            }
            rr->setRect(rect);
            *aa = false;
            return true;
        }
        return false;
    };

    bool apply(GrContext*, GrDrawContext*, bool useHWAA, bool hasUserStencilSettings,
               GrAppliedClip* out) const final;

    static const GrFixedClip& Disabled();

private:
    GrScissorState   fScissorState;
};

#endif