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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkMatrix.h" |
| 9 | #include "include/core/SkRect.h" |
| 10 | #include "src/core/SkClipOpPriv.h" |
| 11 | #include "src/core/SkClipStack.h" |
| 12 | #include "src/gpu/GrClipStackClip.h" |
| 13 | #include "tests/Test.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 |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 17 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, ctxInfo) { |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 18 | static const int kXSize = 100; |
| 19 | static const int kYSize = 100; |
| 20 | |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 21 | const SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize); |
| 22 | const SkRect screen = SkRect::Make(intScreen); |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 23 | |
| 24 | SkRect clipRect(screen); |
| 25 | clipRect.outset(10, 10); |
| 26 | |
| 27 | // create a clip stack that will (trivially) reduce to a single rect that |
| 28 | // is larger than the screen |
| 29 | SkClipStack stack; |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 30 | stack.clipRect(clipRect, SkMatrix::I(), kReplace_SkClipOp, false); |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 31 | |
| 32 | bool isIntersectionOfRects = true; |
| 33 | SkRect devStackBounds; |
| 34 | |
| 35 | stack.getConservativeBounds(0, 0, kXSize, kYSize, |
| 36 | &devStackBounds, |
| 37 | &isIntersectionOfRects); |
| 38 | |
| 39 | // make sure that the SkClipStack is behaving itself |
| 40 | REPORTER_ASSERT(reporter, screen == devStackBounds); |
| 41 | REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 42 | |
| 43 | // wrap the SkClipStack in a GrClip |
Michael Ludwig | e06a897 | 2020-06-11 10:29:00 -0400 | [diff] [blame] | 44 | GrClipStackClip clipData({kXSize, kYSize}, &stack); |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 45 | |
Michael Ludwig | e06a897 | 2020-06-11 10:29:00 -0400 | [diff] [blame] | 46 | SkIRect devGrClipBound = clipData.getConservativeBounds(); |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 47 | |
| 48 | // make sure that GrClip is behaving itself |
| 49 | REPORTER_ASSERT(reporter, intScreen == devGrClipBound); |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 50 | } |