aboutsummaryrefslogtreecommitdiff
path: root/src/gpu/ganesh/GrFixedClip.cpp
blob: 81ca241ad8c7c2f88386a2b3f5a3ae6e63f3dbb9 (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
/*
 * Copyright 2010 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "src/gpu/ganesh/GrFixedClip.h"

#include "src/gpu/ganesh/GrAppliedClip.h"

SkIRect GrFixedClip::getConservativeBounds() const {
    return fScissorState.rect();
}

GrClip::PreClipResult GrFixedClip::preApply(const SkRect& drawBounds, GrAA aa) const {
    SkIRect pixelBounds = GetPixelIBounds(drawBounds, aa);
    if (!SkIRect::Intersects(fScissorState.rect(), pixelBounds)) {
        return Effect::kClippedOut;
    }

    if (fWindowRectsState.enabled()) {
        return Effect::kClipped;
    }

    if (!fScissorState.enabled() || fScissorState.rect().contains(pixelBounds)) {
        // Either no scissor or the scissor doesn't clip the draw
        return Effect::kUnclipped;
    }
    // Report the scissor as a degenerate round rect
    return {SkRect::Make(fScissorState.rect()), GrAA::kNo};
}

GrClip::Effect GrFixedClip::apply(GrAppliedHardClip* out, SkIRect* bounds) const {
    if (!SkIRect::Intersects(fScissorState.rect(), *bounds)) {
        return Effect::kClippedOut;
    }

    Effect effect = Effect::kUnclipped;
    if (fScissorState.enabled() && !fScissorState.rect().contains(*bounds)) {
        SkAssertResult(bounds->intersect(fScissorState.rect()));
        out->setScissor(*bounds);
        effect = Effect::kClipped;
    }

    if (fWindowRectsState.enabled()) {
        out->addWindowRectangles(fWindowRectsState);
        // We could iterate each window rectangle to check for intersection, but be conservative
        // and report that it's clipped
        effect = Effect::kClipped;
    }

    return effect;
}