Coverage Report

Created: 2021-08-22 09:07

/src/skia/src/gpu/GrScissorState.h
Line
Count
Source (jump to first uncovered line)
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
11
#include "include/core/SkRect.h"
12
13
/**
14
 * The scissor state is stored as the scissor rectangle and the backing store bounds of the render
15
 * target that the scissor will apply to. If the render target is approximate fit and the padded
16
 * content should not be modified, the clip should apply the render target context's logical bounds
17
 * as part of the scissor (e.g. when stenciling). This puts the onus on the render target context
18
 * to intentionally discard the scissor at its logical bounds when drawing into the padded content
19
 * is acceptable (e.g. color-only updates).
20
 */
21
class GrScissorState {
22
public:
23
    // The disabled scissor state for a render target of the given size.
24
    explicit GrScissorState(const SkISize& rtDims)
25
            : fRTSize(rtDims)
26
251k
            , fRect(SkIRect::MakeSize(rtDims)) {}
27
28
147k
    void setDisabled() { fRect = SkIRect::MakeSize(fRTSize); }
29
145k
    bool set(const SkIRect& rect) {
30
145k
        this->setDisabled();
31
145k
        return this->intersect(rect);
32
145k
    }
33
34
146k
    bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& rect) {
35
146k
        if (!fRect.intersect(rect)) {
36
0
            fRect.setEmpty();
37
0
            return false;
38
146k
        } else {
39
146k
            return true;
40
146k
        }
41
146k
    }
42
43
    // If the scissor was configured for the backing store dimensions and it's acceptable to
44
    // draw outside the logical dimensions of the target, this will discard the scissor test if
45
    // the test wouldn't modify the logical dimensions.
46
2.03k
    bool relaxTest(const SkISize& logicalDimensions) {
47
2.03k
        SkASSERT(logicalDimensions.fWidth <= fRTSize.fWidth &&
48
2.03k
                 logicalDimensions.fHeight <= fRTSize.fHeight);
49
2.03k
        if (fRect.fLeft == 0 && fRect.fTop == 0 && fRect.fRight >= logicalDimensions.fWidth &&
50
2.02k
            fRect.fBottom >= logicalDimensions.fHeight) {
51
2.01k
            this->setDisabled();
52
2.01k
            return true;
53
13
        } else {
54
13
            return false;
55
13
        }
56
2.03k
    }
57
58
87.0k
    bool operator==(const GrScissorState& other) const {
59
87.0k
        return fRTSize == other.fRTSize && fRect == other.fRect;
60
87.0k
    }
61
0
    bool operator!=(const GrScissorState& other) const { return !(*this == other); }
62
63
328k
    bool enabled() const {
64
328k
        SkASSERT(fRect.isEmpty() || SkIRect::MakeSize(fRTSize).contains(fRect));
65
        // This is equivalent to a strict contains check on SkIRect::MakeSize(rtSize) w/o creating
66
        // the render target bounding rectangle.
67
328k
        return fRect.fLeft > 0 || fRect.fTop > 0 ||
68
322k
               fRect.fRight < fRTSize.fWidth || fRect.fBottom < fRTSize.fHeight;
69
328k
    }
70
71
    // Will always be equal to or contained in the rt bounds, or empty if scissor rectangles were
72
    // added that did not intersect with the render target or prior scissor.
73
107k
    const SkIRect& rect() const {
74
107k
        SkASSERT(fRect.isEmpty() || SkIRect::MakeSize(fRTSize).contains(fRect));
75
107k
        return fRect;
76
107k
    }
77
78
private:
79
    // The scissor is considered enabled if the rectangle does not cover the render target
80
    SkISize fRTSize;
81
    SkIRect fRect;
82
};
83
84
#endif