aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrClip.cpp
blob: 5c4a27ccadb0453e73720084e454a6e29c7ee45b (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
/*
 * 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 "GrClip.h"

#include "GrSurface.h"
#include "SkRect.h"

///////////////////////////////////////////////////////////////////////////////

/**
 * getConservativeBounds returns the conservative bounding box of the clip
 * in device (as opposed to canvas) coordinates. If the bounding box is
 * the result of purely intersections of rects (with an initial replace)
 * isIntersectionOfRects will be set to true.
 */
void GrClip::getConservativeBounds(int width, int height, SkIRect* devResult,
                                   bool* isIntersectionOfRects) const {
    switch (fClipType) {
        case kWideOpen_ClipType: {
            devResult->setLTRB(0, 0, width, height);
            if (isIntersectionOfRects) {
                *isIntersectionOfRects = true;
            }
        } break;
        case kIRect_ClipType: {
            *devResult = this->irect();
            if (isIntersectionOfRects) {
                *isIntersectionOfRects = true;
            }
        } break;
        case kClipStack_ClipType: {
            SkRect devBounds;
            this->clipStack()->getConservativeBounds(-this->origin().fX,
                                                     -this->origin().fY,
                                                     width,
                                                     height,
                                                     &devBounds,
                                                     isIntersectionOfRects);
            devBounds.roundOut(devResult);
        } break;

    }
}

const GrClip& GrClip::WideOpen() {
    static const GrClip clip;
    return clip;
}