blob: 32b17ad883498ec8fe975c70dc714725d1b19a00 [file] [log] [blame]
bsalomon473addf2015-10-02 07:49:05 -07001/*
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
Ben Wagnerb607a8f2018-03-12 13:46:21 -04008#include "SkTypes.h"
9
csmartdaltonc6f411e2016-08-05 22:32:12 -070010#include "GrClipStackClip.h"
Ben Wagnerb607a8f2018-03-12 13:46:21 -040011#include "SkClipOpPriv.h"
12#include "SkClipStack.h"
13#include "SkMatrix.h"
14#include "SkRect.h"
15#include "Test.h"
bsalomon473addf2015-10-02 07:49:05 -070016
17// Ensure that the 'getConservativeBounds' calls are returning bounds clamped
18// to the render target
bsalomon68d91342016-04-12 09:59:58 -070019DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, ctxInfo) {
bsalomon473addf2015-10-02 07:49:05 -070020 static const int kXSize = 100;
21 static const int kYSize = 100;
22
robertphillipsd4c741e2016-04-28 09:55:15 -070023 const SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize);
24 const SkRect screen = SkRect::Make(intScreen);
bsalomon473addf2015-10-02 07:49:05 -070025
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;
Mike Reedc1f77742016-12-09 09:00:50 -050032 stack.clipRect(clipRect, SkMatrix::I(), kReplace_SkClipOp, false);
bsalomon473addf2015-10-02 07:49:05 -070033
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
cdalton846c0512016-05-13 10:25:00 -070046 GrClipStackClip clipData(&stack);
bsalomon473addf2015-10-02 07:49:05 -070047
48 SkIRect devGrClipBound;
robertphillipsd4c741e2016-04-28 09:55:15 -070049 clipData.getConservativeBounds(kXSize, kYSize,
bsalomon473addf2015-10-02 07:49:05 -070050 &devGrClipBound,
51 &isIntersectionOfRects);
52
53 // make sure that GrClip is behaving itself
54 REPORTER_ASSERT(reporter, intScreen == devGrClipBound);
55 REPORTER_ASSERT(reporter, isIntersectionOfRects);
56}