OLD | NEW |
(Empty) | |
| 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" |
| 13 #include "GrContextFactory.h" |
| 14 #include "SkGpuDevice.h" |
| 15 |
| 16 // Ensure that the 'getConservativeBounds' calls are returning bounds clamped |
| 17 // to the render target |
| 18 static void test_clip_bounds(skiatest::Reporter* reporter, GrContext* context) { |
| 19 |
| 20 static const int kXSize = 100; |
| 21 static const int kYSize = 100; |
| 22 |
| 23 GrSurfaceDesc desc; |
| 24 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 25 desc.fConfig = kAlpha_8_GrPixelConfig; |
| 26 desc.fWidth = kXSize; |
| 27 desc.fHeight = kYSize; |
| 28 |
| 29 SkAutoTUnref<GrTexture> texture( |
| 30 context->textureProvider()->createTexture(desc, false, nullptr, 0)); |
| 31 if (!texture) { |
| 32 return; |
| 33 } |
| 34 |
| 35 SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize); |
| 36 SkRect screen = SkRect::Make(intScreen); |
| 37 |
| 38 SkRect clipRect(screen); |
| 39 clipRect.outset(10, 10); |
| 40 |
| 41 // create a clip stack that will (trivially) reduce to a single rect that |
| 42 // is larger than the screen |
| 43 SkClipStack stack; |
| 44 stack.clipDevRect(clipRect, SkRegion::kReplace_Op, false); |
| 45 |
| 46 bool isIntersectionOfRects = true; |
| 47 SkRect devStackBounds; |
| 48 |
| 49 stack.getConservativeBounds(0, 0, kXSize, kYSize, |
| 50 &devStackBounds, |
| 51 &isIntersectionOfRects); |
| 52 |
| 53 // make sure that the SkClipStack is behaving itself |
| 54 REPORTER_ASSERT(reporter, screen == devStackBounds); |
| 55 REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 56 |
| 57 // wrap the SkClipStack in a GrClip |
| 58 GrClip clipData; |
| 59 clipData.setClipStack(&stack); |
| 60 |
| 61 SkIRect devGrClipBound; |
| 62 clipData.getConservativeBounds(texture, |
| 63 &devGrClipBound, |
| 64 &isIntersectionOfRects); |
| 65 |
| 66 // make sure that GrClip is behaving itself |
| 67 REPORTER_ASSERT(reporter, intScreen == devGrClipBound); |
| 68 REPORTER_ASSERT(reporter, isIntersectionOfRects); |
| 69 } |
| 70 |
| 71 DEF_GPUTEST(GrClipBounds, reporter, factory) { |
| 72 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 73 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); |
| 74 if (!GrContextFactory::IsRenderingGLContext(glType)) { |
| 75 continue; |
| 76 } |
| 77 GrContext* context = factory->get(glType); |
| 78 if (nullptr == context) { |
| 79 continue; |
| 80 } |
| 81 test_clip_bounds(reporter, context); |
| 82 } |
| 83 } |
| 84 |
| 85 #endif |
OLD | NEW |