1 /*
2 * Copyright 2015 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 "include/core/SkMatrix.h"
9 #include "include/core/SkRect.h"
10 #include "src/core/SkClipOpPriv.h"
11 #include "src/core/SkClipStack.h"
12 #include "src/gpu/GrClipStackClip.h"
13 #include "tests/Test.h"
14
15 // Ensure that the 'getConservativeBounds' calls are returning bounds clamped
16 // to the render target
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds,reporter,ctxInfo)17 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, ctxInfo) {
18 static const int kXSize = 100;
19 static const int kYSize = 100;
20
21 const SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize);
22 const SkRect screen = SkRect::Make(intScreen);
23
24 SkRect clipRect(screen);
25 clipRect.outset(10, 10);
26
27 // create a clip stack that will (trivially) reduce to a single rect that
28 // is larger than the screen
29 SkClipStack stack;
30 stack.clipRect(clipRect, SkMatrix::I(), kReplace_SkClipOp, false);
31
32 bool isIntersectionOfRects = true;
33 SkRect devStackBounds;
34
35 stack.getConservativeBounds(0, 0, kXSize, kYSize,
36 &devStackBounds,
37 &isIntersectionOfRects);
38
39 // make sure that the SkClipStack is behaving itself
40 REPORTER_ASSERT(reporter, screen == devStackBounds);
41 REPORTER_ASSERT(reporter, isIntersectionOfRects);
42
43 // wrap the SkClipStack in a GrClip
44 GrClipStackClip clipData(&stack);
45
46 SkIRect devGrClipBound;
47 clipData.getConservativeBounds(kXSize, kYSize,
48 &devGrClipBound,
49 &isIntersectionOfRects);
50
51 // make sure that GrClip is behaving itself
52 REPORTER_ASSERT(reporter, intScreen == devGrClipBound);
53 REPORTER_ASSERT(reporter, isIntersectionOfRects);
54 }
55