bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 1 | /* |
| 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" |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 12 | #include "GrContext.h" |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 13 | |
| 14 | // Ensure that the 'getConservativeBounds' calls are returning bounds clamped |
| 15 | // to the render target |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 16 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, context) { |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 17 | 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( |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 27 | context->textureProvider()->createTexture(desc, SkBudgeted::kYes, nullptr, 0)); |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 28 | 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; |
robertphillips | 7bceedc | 2015-12-01 12:51:26 -0800 | [diff] [blame] | 59 | clipData.getConservativeBounds(texture->width(), texture->height(), |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 60 | &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 | |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 68 | #endif |