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