blob: 2f9e13de5f9ff89a2f5b547919e58f2be15e31a8 [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
8#include "Test.h"
9// This is a GR test
10#if SK_SUPPORT_GPU
11#include "GrClipMaskManager.h"
kkinnunen15302832015-12-01 04:35:26 -080012#include "GrContext.h"
bsalomon473addf2015-10-02 07:49:05 -070013
14// Ensure that the 'getConservativeBounds' calls are returning bounds clamped
15// to the render target
kkinnunen15302832015-12-01 04:35:26 -080016DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, context) {
bsalomon473addf2015-10-02 07:49:05 -070017 static const int kXSize = 100;
18 static const int kYSize = 100;
19
20 GrSurfaceDesc desc;
21 desc.fFlags = kRenderTarget_GrSurfaceFlag;
22 desc.fConfig = kAlpha_8_GrPixelConfig;
23 desc.fWidth = kXSize;
24 desc.fHeight = kYSize;
25
26 SkAutoTUnref<GrTexture> texture(
bsalomon5ec26ae2016-02-25 08:33:02 -080027 context->textureProvider()->createTexture(desc, SkBudgeted::kYes, nullptr, 0));
bsalomon473addf2015-10-02 07:49:05 -070028 if (!texture) {
29 return;
30 }
31
32 SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize);
33 SkRect screen = SkRect::Make(intScreen);
34
35 SkRect clipRect(screen);
36 clipRect.outset(10, 10);
37
38 // create a clip stack that will (trivially) reduce to a single rect that
39 // is larger than the screen
40 SkClipStack stack;
41 stack.clipDevRect(clipRect, SkRegion::kReplace_Op, false);
42
43 bool isIntersectionOfRects = true;
44 SkRect devStackBounds;
45
46 stack.getConservativeBounds(0, 0, kXSize, kYSize,
47 &devStackBounds,
48 &isIntersectionOfRects);
49
50 // make sure that the SkClipStack is behaving itself
51 REPORTER_ASSERT(reporter, screen == devStackBounds);
52 REPORTER_ASSERT(reporter, isIntersectionOfRects);
53
54 // wrap the SkClipStack in a GrClip
55 GrClip clipData;
56 clipData.setClipStack(&stack);
57
58 SkIRect devGrClipBound;
robertphillips7bceedc2015-12-01 12:51:26 -080059 clipData.getConservativeBounds(texture->width(), texture->height(),
bsalomon473addf2015-10-02 07:49:05 -070060 &devGrClipBound,
61 &isIntersectionOfRects);
62
63 // make sure that GrClip is behaving itself
64 REPORTER_ASSERT(reporter, intScreen == devGrClipBound);
65 REPORTER_ASSERT(reporter, isIntersectionOfRects);
66}
67
bsalomon473addf2015-10-02 07:49:05 -070068#endif