aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-31 11:47:29 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-31 11:47:29 +0000
commitc23a63b9e24ac2384466bc4f24ad10f010f25c75 (patch)
tree334b013a6d4b76493d253e1585c7fbd5c855f220
parentd829b5cbff1a6e149af4961f577368a6fb7c2e39 (diff)
Added test to ensure getConservativeBounds' result is clamped to render target
-rw-r--r--tests/ClipCacheTest.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/ClipCacheTest.cpp b/tests/ClipCacheTest.cpp
index 249bd585cc..e3ff24551f 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);
}
////////////////////////////////////////////////////////////////////////////////