Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Unified Diff: tests/ClipStackTest.cpp

Issue 48593003: Avoid re-rendering stencil clip for every draw with reducable clip stack (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/gpu/SkGpuDevice.cpp ('K') | « tests/ClipCacheTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ClipStackTest.cpp
diff --git a/tests/ClipStackTest.cpp b/tests/ClipStackTest.cpp
index 04b48b678364ee0f2bd44f532868c32a48e56cfd..03ef72ea8c559975289f2add381b669bde392cea 100644
--- a/tests/ClipStackTest.cpp
+++ b/tests/ClipStackTest.cpp
@@ -271,6 +271,7 @@ static void test_bounds(skiatest::Reporter* reporter, bool useRects) {
}
REPORTER_ASSERT(reporter, !stack.isWideOpen());
+ REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID != stack.getTopmostGenID());
stack.getConservativeBounds(0, 0, 100, 100, &devClipBound,
&isIntersectionOfRects);
@@ -293,6 +294,12 @@ static void test_bounds(skiatest::Reporter* reporter, bool useRects) {
// Test out 'isWideOpen' entry point
static void test_isWideOpen(skiatest::Reporter* reporter) {
+ {
+ // Empty stack is wide open. Wide open stack means that gen id is wide open.
+ SkClipStack stack;
+ REPORTER_ASSERT(reporter, stack.isWideOpen());
+ REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID());
+ }
SkRect rectA, rectB;
@@ -304,6 +311,7 @@ static void test_isWideOpen(skiatest::Reporter* reporter) {
SkClipStack stack;
REPORTER_ASSERT(reporter, stack.isWideOpen());
+ REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID());
}
// Test out case where the user specifies a union that includes everything
@@ -322,6 +330,7 @@ static void test_isWideOpen(skiatest::Reporter* reporter) {
stack.clipDevPath(clipB, SkRegion::kUnion_Op, false);
REPORTER_ASSERT(reporter, stack.isWideOpen());
+ REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID());
}
// Test out union w/ a wide open clip
@@ -331,6 +340,7 @@ static void test_isWideOpen(skiatest::Reporter* reporter) {
stack.clipDevRect(rectA, SkRegion::kUnion_Op, false);
REPORTER_ASSERT(reporter, stack.isWideOpen());
+ REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID());
}
// Test out empty difference from a wide open clip
@@ -343,6 +353,7 @@ static void test_isWideOpen(skiatest::Reporter* reporter) {
stack.clipDevRect(emptyRect, SkRegion::kDifference_Op, false);
REPORTER_ASSERT(reporter, stack.isWideOpen());
+ REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID());
}
// Test out return to wide open
@@ -354,10 +365,12 @@ static void test_isWideOpen(skiatest::Reporter* reporter) {
stack.clipDevRect(rectA, SkRegion::kReplace_Op, false);
REPORTER_ASSERT(reporter, !stack.isWideOpen());
+ REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID != stack.getTopmostGenID());
stack.restore();
REPORTER_ASSERT(reporter, stack.isWideOpen());
+ REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmostGenID());
}
}
@@ -950,6 +963,9 @@ static void test_reduced_clip_stack(skiatest::Reporter* reporter) {
&initial,
tightBounds);
+ REPORTER_ASSERT(reporter, reducedClips.count() == 0 ||
+ reducedClips.tail()->getGenID() != SkClipStack::kInvalidGenID);
+
// Build a new clip stack based on the reduced clip elements
SkClipStack reducedStack;
if (GrReducedClip::kAllOut_InitialState == initial) {
@@ -986,6 +1002,48 @@ static void test_reduced_clip_stack(skiatest::Reporter* reporter) {
}
}
+static void test_reduced_clip_stack_genid(skiatest::Reporter* reporter) {
+ SkClipStack stack;
+ stack.clipDevRect(SkRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_Op, true);
+ stack.clipDevRect(SkRect::MakeXYWH(0, 0, 50.3, 50.3), SkRegion::kReplace_Op, true);
+ SkIRect inflatedIBounds = SkIRect::MakeXYWH(0, 0, 100, 100);
+
+ GrReducedClip::ElementList reducedClips;
+ GrReducedClip::InitialState initial;
+ SkIRect tightBounds;
+
+ GrReducedClip::ReduceClipStack(stack,
+ inflatedIBounds,
+ &reducedClips,
+ &initial,
+ &tightBounds);
+
+ REPORTER_ASSERT(reporter, reducedClips.count() == 1);
+ // Clips will be cached based on the generation id. Make sure the gen id is valid.
+ REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reducedClips.head()->getGenID());
+
+}
+
+static void test_reduced_clip_stack_no_aa_crash(skiatest::Reporter* reporter) {
+ SkClipStack stack;
+ stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_Op);
+ stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 50, 50), SkRegion::kReplace_Op);
+ SkIRect inflatedIBounds = SkIRect::MakeXYWH(0, 0, 100, 100);
+
+ GrReducedClip::ElementList reducedClips;
+ GrReducedClip::InitialState initial;
+ SkIRect tightBounds;
+
+ // At the time, this would crash.
+ GrReducedClip::ReduceClipStack(stack,
+ inflatedIBounds,
+ &reducedClips,
+ &initial,
+ &tightBounds);
+
+ REPORTER_ASSERT(reporter, 0 == reducedClips.count());
+}
+
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1034,6 +1092,8 @@ static void TestClipStack(skiatest::Reporter* reporter) {
test_quickContains(reporter);
#if SK_SUPPORT_GPU
test_reduced_clip_stack(reporter);
+ test_reduced_clip_stack_genid(reporter);
+ test_reduced_clip_stack_no_aa_crash(reporter);
#endif
}
« src/gpu/SkGpuDevice.cpp ('K') | « tests/ClipCacheTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698