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 |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 11 | #include "GrClipStackClip.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 |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 16 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, ctxInfo) { |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 17 | static const int kXSize = 100; |
| 18 | static const int kYSize = 100; |
| 19 | |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 20 | const SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize); |
| 21 | const SkRect screen = SkRect::Make(intScreen); |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 22 | |
| 23 | SkRect clipRect(screen); |
| 24 | clipRect.outset(10, 10); |
| 25 | |
| 26 | // create a clip stack that will (trivially) reduce to a single rect that |
| 27 | // is larger than the screen |
| 28 | SkClipStack stack; |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 29 | stack.clipDevRect(clipRect, SkCanvas::kReplace_Op, false); |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 30 | |
| 31 | bool isIntersectionOfRects = true; |
| 32 | SkRect devStackBounds; |
| 33 | |
| 34 | stack.getConservativeBounds(0, 0, kXSize, kYSize, |
| 35 | &devStackBounds, |
| 36 | &isIntersectionOfRects); |
| 37 | |
| 38 | // make sure that the SkClipStack is behaving itself |
| 39 | REPORTER_ASSERT(reporter, screen == devStackBounds); |
| 40 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 41 | |
| 42 | // wrap the SkClipStack in a GrClip |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 43 | GrClipStackClip clipData(&stack); |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 44 | |
| 45 | SkIRect devGrClipBound; |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 46 | clipData.getConservativeBounds(kXSize, kYSize, |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 47 | &devGrClipBound, |
| 48 | &isIntersectionOfRects); |
| 49 | |
| 50 | // make sure that GrClip is behaving itself |
| 51 | REPORTER_ASSERT(reporter, intScreen == devGrClipBound); |
| 52 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 53 | } |
| 54 | |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 55 | #endif |