blob: d6169022ffe97d422da738776999db8564190ac7 [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
bsalomon473addf2015-10-02 07:49:05 -070010// This is a GR test
11#if SK_SUPPORT_GPU
csmartdaltonc6f411e2016-08-05 22:32:12 -070012#include "GrClipStackClip.h"
Ben Wagnerb607a8f2018-03-12 13:46:21 -040013#include "SkClipOpPriv.h"
14#include "SkClipStack.h"
15#include "SkMatrix.h"
16#include "SkRect.h"
17#include "Test.h"
bsalomon473addf2015-10-02 07:49:05 -070018
19// Ensure that the 'getConservativeBounds' calls are returning bounds clamped
20// to the render target
bsalomon68d91342016-04-12 09:59:58 -070021DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, ctxInfo) {
bsalomon473addf2015-10-02 07:49:05 -070022 static const int kXSize = 100;
23 static const int kYSize = 100;
24
robertphillipsd4c741e2016-04-28 09:55:15 -070025 const SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize);
26 const SkRect screen = SkRect::Make(intScreen);
bsalomon473addf2015-10-02 07:49:05 -070027
28 SkRect clipRect(screen);
29 clipRect.outset(10, 10);
30
31 // create a clip stack that will (trivially) reduce to a single rect that
32 // is larger than the screen
33 SkClipStack stack;
Mike Reedc1f77742016-12-09 09:00:50 -050034 stack.clipRect(clipRect, SkMatrix::I(), kReplace_SkClipOp, false);
bsalomon473addf2015-10-02 07:49:05 -070035
36 bool isIntersectionOfRects = true;
37 SkRect devStackBounds;
38
39 stack.getConservativeBounds(0, 0, kXSize, kYSize,
40 &devStackBounds,
41 &isIntersectionOfRects);
42
43 // make sure that the SkClipStack is behaving itself
44 REPORTER_ASSERT(reporter, screen == devStackBounds);
45 REPORTER_ASSERT(reporter, isIntersectionOfRects);
46
47 // wrap the SkClipStack in a GrClip
cdalton846c0512016-05-13 10:25:00 -070048 GrClipStackClip clipData(&stack);
bsalomon473addf2015-10-02 07:49:05 -070049
50 SkIRect devGrClipBound;
robertphillipsd4c741e2016-04-28 09:55:15 -070051 clipData.getConservativeBounds(kXSize, kYSize,
bsalomon473addf2015-10-02 07:49:05 -070052 &devGrClipBound,
53 &isIntersectionOfRects);
54
55 // make sure that GrClip is behaving itself
56 REPORTER_ASSERT(reporter, intScreen == devGrClipBound);
57 REPORTER_ASSERT(reporter, isIntersectionOfRects);
58}
59
bsalomon473addf2015-10-02 07:49:05 -070060#endif