blob: d8df62ecadad0ad290e77d083e1606d54ceba58c [file] [log] [blame]
bsalomon473addf2015-10-02 07:49:05 -07001
2/*
3 * Copyright 2015 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include "Test.h"
10// This is a GR test
11#if SK_SUPPORT_GPU
12#include "GrClipMaskManager.h"
kkinnunen15302832015-12-01 04:35:26 -080013#include "GrContext.h"
bsalomon473addf2015-10-02 07:49:05 -070014
15// Ensure that the 'getConservativeBounds' calls are returning bounds clamped
16// to the render target
kkinnunen15302832015-12-01 04:35:26 -080017DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, context) {
bsalomon473addf2015-10-02 07:49:05 -070018 static const int kXSize = 100;
19 static const int kYSize = 100;
20
21 GrSurfaceDesc desc;
22 desc.fFlags = kRenderTarget_GrSurfaceFlag;
23 desc.fConfig = kAlpha_8_GrPixelConfig;
24 desc.fWidth = kXSize;
25 desc.fHeight = kYSize;
26
27 SkAutoTUnref<GrTexture> texture(
28 context->textureProvider()->createTexture(desc, false, nullptr, 0));
29 if (!texture) {
30 return;
31 }
32
33 SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize);
34 SkRect screen = SkRect::Make(intScreen);
35
36 SkRect clipRect(screen);
37 clipRect.outset(10, 10);
38
39 // create a clip stack that will (trivially) reduce to a single rect that
40 // is larger than the screen
41 SkClipStack stack;
42 stack.clipDevRect(clipRect, SkRegion::kReplace_Op, false);
43
44 bool isIntersectionOfRects = true;
45 SkRect devStackBounds;
46
47 stack.getConservativeBounds(0, 0, kXSize, kYSize,
48 &devStackBounds,
49 &isIntersectionOfRects);
50
51 // make sure that the SkClipStack is behaving itself
52 REPORTER_ASSERT(reporter, screen == devStackBounds);
53 REPORTER_ASSERT(reporter, isIntersectionOfRects);
54
55 // wrap the SkClipStack in a GrClip
56 GrClip clipData;
57 clipData.setClipStack(&stack);
58
59 SkIRect devGrClipBound;
60 clipData.getConservativeBounds(texture,
61 &devGrClipBound,
62 &isIntersectionOfRects);
63
64 // make sure that GrClip is behaving itself
65 REPORTER_ASSERT(reporter, intScreen == devGrClipBound);
66 REPORTER_ASSERT(reporter, isIntersectionOfRects);
67}
68
bsalomon473addf2015-10-02 07:49:05 -070069#endif