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 "GrContext.h" 14 15 // Ensure that the 'getConservativeBounds' calls are returning bounds clamped 16 // to the render target 17 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, context) { 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, SkBudgeted::kYes, 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->width(), texture->height(), 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 69 #endif 70