blob: 03973c2768cea2f174650febd47999283ba998b7 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#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"
bsalomon473addf2015-10-02 07:49:05 -070014
15// Ensure that the 'getConservativeBounds' calls are returning bounds clamped
16// to the render target
bsalomon68d91342016-04-12 09:59:58 -070017DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, ctxInfo) {
bsalomon473addf2015-10-02 07:49:05 -070018 static const int kXSize = 100;
19 static const int kYSize = 100;
20
robertphillipsd4c741e2016-04-28 09:55:15 -070021 const SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize);
22 const SkRect screen = SkRect::Make(intScreen);
bsalomon473addf2015-10-02 07:49:05 -070023
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;
Mike Reedc1f77742016-12-09 09:00:50 -050030 stack.clipRect(clipRect, SkMatrix::I(), kReplace_SkClipOp, false);
bsalomon473addf2015-10-02 07:49:05 -070031
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
Michael Ludwige06a8972020-06-11 10:29:00 -040044 GrClipStackClip clipData({kXSize, kYSize}, &stack);
bsalomon473addf2015-10-02 07:49:05 -070045
Michael Ludwige06a8972020-06-11 10:29:00 -040046 SkIRect devGrClipBound = clipData.getConservativeBounds();
bsalomon473addf2015-10-02 07:49:05 -070047
48 // make sure that GrClip is behaving itself
49 REPORTER_ASSERT(reporter, intScreen == devGrClipBound);
bsalomon473addf2015-10-02 07:49:05 -070050}