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 | |
Ben Wagner | b607a8f | 2018-03-12 13:46:21 -0400 | [diff] [blame] | 8 | #include "SkTypes.h" |
| 9 | |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 10 | // This is a GR test |
| 11 | #if SK_SUPPORT_GPU |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 12 | #include "GrClipStackClip.h" |
Ben Wagner | b607a8f | 2018-03-12 13:46:21 -0400 | [diff] [blame] | 13 | #include "SkClipOpPriv.h" |
| 14 | #include "SkClipStack.h" |
| 15 | #include "SkMatrix.h" |
| 16 | #include "SkRect.h" |
| 17 | #include "Test.h" |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 18 | |
| 19 | // Ensure that the 'getConservativeBounds' calls are returning bounds clamped |
| 20 | // to the render target |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 21 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, ctxInfo) { |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 22 | static const int kXSize = 100; |
| 23 | static const int kYSize = 100; |
| 24 | |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 25 | const SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize); |
| 26 | const SkRect screen = SkRect::Make(intScreen); |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 27 | |
| 28 | SkRect clipRect(screen); |
| 29 | clipRect.outset(10, 10); |
| 30 | |
| 31 | // create a clip stack that will (trivially) reduce to a single rect that |
| 32 | // is larger than the screen |
| 33 | SkClipStack stack; |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 34 | stack.clipRect(clipRect, SkMatrix::I(), kReplace_SkClipOp, false); |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 35 | |
| 36 | bool isIntersectionOfRects = true; |
| 37 | SkRect devStackBounds; |
| 38 | |
| 39 | stack.getConservativeBounds(0, 0, kXSize, kYSize, |
| 40 | &devStackBounds, |
| 41 | &isIntersectionOfRects); |
| 42 | |
| 43 | // make sure that the SkClipStack is behaving itself |
| 44 | REPORTER_ASSERT(reporter, screen == devStackBounds); |
| 45 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 46 | |
| 47 | // wrap the SkClipStack in a GrClip |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 48 | GrClipStackClip clipData(&stack); |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 49 | |
| 50 | SkIRect devGrClipBound; |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 51 | clipData.getConservativeBounds(kXSize, kYSize, |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 52 | &devGrClipBound, |
| 53 | &isIntersectionOfRects); |
| 54 | |
| 55 | // make sure that GrClip is behaving itself |
| 56 | REPORTER_ASSERT(reporter, intScreen == devGrClipBound); |
| 57 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 58 | } |
| 59 | |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 60 | #endif |