blob: 5c4a27ccadb0453e73720084e454a6e29c7ee45b [file] [log] [blame]
joshualitt44701df2015-02-23 14:44:57 -08001/*
2 * Copyright 2010 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#include "GrClip.h"
9
10#include "GrSurface.h"
11#include "SkRect.h"
12
13///////////////////////////////////////////////////////////////////////////////
14
15/**
16 * getConservativeBounds returns the conservative bounding box of the clip
17 * in device (as opposed to canvas) coordinates. If the bounding box is
18 * the result of purely intersections of rects (with an initial replace)
19 * isIntersectionOfRects will be set to true.
20 */
21void GrClip::getConservativeBounds(int width, int height, SkIRect* devResult,
22 bool* isIntersectionOfRects) const {
23 switch (fClipType) {
joshualitt44701df2015-02-23 14:44:57 -080024 case kWideOpen_ClipType: {
25 devResult->setLTRB(0, 0, width, height);
26 if (isIntersectionOfRects) {
27 *isIntersectionOfRects = true;
28 }
29 } break;
30 case kIRect_ClipType: {
31 *devResult = this->irect();
32 if (isIntersectionOfRects) {
33 *isIntersectionOfRects = true;
34 }
35 } break;
36 case kClipStack_ClipType: {
37 SkRect devBounds;
38 this->clipStack()->getConservativeBounds(-this->origin().fX,
39 -this->origin().fY,
40 width,
41 height,
42 &devBounds,
43 isIntersectionOfRects);
44 devBounds.roundOut(devResult);
45 } break;
46
47 }
48}
joshualitt9ece6a92015-02-23 17:03:33 -080049
50const GrClip& GrClip::WideOpen() {
joshualittab2f44c2015-02-24 06:47:14 -080051 static const GrClip clip;
joshualitt9ece6a92015-02-23 17:03:33 -080052 return clip;
53}