From c23a63b9e24ac2384466bc4f24ad10f010f25c75 Mon Sep 17 00:00:00 2001 From: "robertphillips@google.com" Date: Tue, 31 Jul 2012 11:47:29 +0000 Subject: [PATCH] Added test to ensure getConservativeBounds' result is clamped to render target http://codereview.appspot.com/6447063/ git-svn-id: http://skia.googlecode.com/svn/trunk@4846 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tests/ClipCacheTest.cpp | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tests/ClipCacheTest.cpp b/tests/ClipCacheTest.cpp index 249bd585c..e3ff24551 100644 --- a/tests/ClipCacheTest.cpp +++ b/tests/ClipCacheTest.cpp @@ -36,6 +36,75 @@ static GrTexture* createTexture(GrContext* context) { return texture; } +// Ensure that the 'getConservativeBounds' calls are returning bounds clamped +// to the render target +static void test_clip_bounds(skiatest::Reporter* reporter, GrContext* context) { + + static const int kXSize = 100; + static const int kYSize = 100; + + GrTextureDesc desc; + desc.fFlags = kRenderTarget_GrTextureFlagBit; + desc.fConfig = kAlpha_8_GrPixelConfig; + desc.fWidth = kXSize; + desc.fHeight = kYSize; + + GrTexture* texture = context->createUncachedTexture(desc, NULL, 0); + if (!texture) { + return; + } + + GrAutoUnref au(texture); + + SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize); + SkRect screen = SkRect::MakeWH(SkIntToScalar(kXSize), + SkIntToScalar(kYSize)); + SkRect clipRect(screen); + clipRect.outset(10, 10); + + // create a clip stack that will (trivially) reduce to a single rect that + // is larger than the screen + SkClipStack stack; + stack.clipDevRect(clipRect, SkRegion::kReplace_Op, false); + + bool isIntersectionOfRects = true; + SkRect stackBounds; + + stack.getConservativeBounds(0, 0, kXSize, kYSize, + &stackBounds, + &isIntersectionOfRects); + + // make sure that the SkClipStack is behaving itself + REPORTER_ASSERT(reporter, screen == stackBounds); + REPORTER_ASSERT(reporter, isIntersectionOfRects); + + // convert the SkClipStack to a GrClip + SkGrClipIterator iter; + iter.reset(stack); + + GrClip clip; + clip.setFromIterator(&iter, 0, 0, stackBounds); + + const GrRect& grBound = clip.getConservativeBounds(); + + // make sure that GrClip is behaving itself + REPORTER_ASSERT(reporter, clipRect == grBound); + REPORTER_ASSERT(reporter, clip.isRect()); + + // wrap the GrClip in a GrClipData + GrClipData clipData; + clipData.fClipStack = &clip; + + SkIRect intGrBound; + clipData.getConservativeBounds(texture, + &intGrBound, + &isIntersectionOfRects); + + // make sure that GrClipData is behaving itself + REPORTER_ASSERT(reporter, intScreen == intGrBound); + REPORTER_ASSERT(reporter, isIntersectionOfRects); +} + //////////////////////////////////////////////////////////////////////////////// // verify that the top state of the stack matches the passed in state static void check_state(skiatest::Reporter* reporter, @@ -164,6 +233,7 @@ static void test_cache(skiatest::Reporter* reporter, GrContext* context) { static void TestClipCache(skiatest::Reporter* reporter, GrContext* context) { test_cache(reporter, context); + test_clip_bounds(reporter, context); } ////////////////////////////////////////////////////////////////////////////////