bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 1 | |
| 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" |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame^] | 13 | #include "GrContext.h" |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 14 | |
| 15 | // Ensure that the 'getConservativeBounds' calls are returning bounds clamped |
| 16 | // to the render target |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame^] | 17 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, context) { |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 18 | 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 | |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 69 | #endif |