summaryrefslogtreecommitdiff
path: root/Source/WebKit/chromium/tests/CCQuadCullerTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit/chromium/tests/CCQuadCullerTest.cpp')
-rw-r--r--Source/WebKit/chromium/tests/CCQuadCullerTest.cpp156
1 files changed, 129 insertions, 27 deletions
diff --git a/Source/WebKit/chromium/tests/CCQuadCullerTest.cpp b/Source/WebKit/chromium/tests/CCQuadCullerTest.cpp
index ed15e6c10..299e5c7e5 100644
--- a/Source/WebKit/chromium/tests/CCQuadCullerTest.cpp
+++ b/Source/WebKit/chromium/tests/CCQuadCullerTest.cpp
@@ -26,6 +26,7 @@
#include "cc/CCQuadCuller.h"
+#include "cc/CCTileDrawQuad.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -36,37 +37,29 @@ namespace {
class CCQuadCullerTest : public testing::Test {
};
-class TestDrawQuad : public CCDrawQuad {
-public:
- TestDrawQuad(const CCSharedQuadState* state, Material m, const IntRect& rect)
- : CCDrawQuad(state, m, rect)
- {
- }
-
- static PassOwnPtr<TestDrawQuad> create(const CCSharedQuadState* state, Material m, const IntRect& rect)
- {
- return adoptPtr(new TestDrawQuad(state, m, rect));
- }
-};
+static PassOwnPtr<CCDrawQuad> MakeTileQuad(CCSharedQuadState* state, const IntRect& rect, const IntRect& opaqueRect = IntRect())
+{
+ return CCTileDrawQuad::create(state, rect, intersection(rect, opaqueRect), 1, IntPoint(1, 1), IntSize(100, 100), 0, false, false, false, false, false);
+}
-void setQuads(CCSharedQuadState* rootState, CCSharedQuadState* childState, CCQuadList& quadList)
+void setQuads(CCSharedQuadState* rootState, CCSharedQuadState* childState, CCQuadList& quadList, const IntRect& opaqueRect = IntRect())
{
quadList.clear();
- quadList.append(TestDrawQuad::create(rootState, CCDrawQuad::TiledContent, IntRect(IntPoint(), IntSize(100, 100))));
- quadList.append(TestDrawQuad::create(rootState, CCDrawQuad::TiledContent, IntRect(IntPoint(100, 0), IntSize(100, 100))));
- quadList.append(TestDrawQuad::create(rootState, CCDrawQuad::TiledContent, IntRect(IntPoint(200, 0), IntSize(100, 100))));
- quadList.append(TestDrawQuad::create(rootState, CCDrawQuad::TiledContent, IntRect(IntPoint(0, 100), IntSize(100, 100))));
- quadList.append(TestDrawQuad::create(rootState, CCDrawQuad::TiledContent, IntRect(IntPoint(100, 100), IntSize(100, 100))));
- quadList.append(TestDrawQuad::create(rootState, CCDrawQuad::TiledContent, IntRect(IntPoint(200, 100), IntSize(100, 100))));
- quadList.append(TestDrawQuad::create(rootState, CCDrawQuad::TiledContent, IntRect(IntPoint(0, 200), IntSize(100, 100))));
- quadList.append(TestDrawQuad::create(rootState, CCDrawQuad::TiledContent, IntRect(IntPoint(100, 200), IntSize(100, 100))));
- quadList.append(TestDrawQuad::create(rootState, CCDrawQuad::TiledContent, IntRect(IntPoint(200, 200), IntSize(100, 100))));
-
- quadList.append(TestDrawQuad::create(childState, CCDrawQuad::TiledContent, IntRect(IntPoint(), IntSize(100, 100))));
- quadList.append(TestDrawQuad::create(childState, CCDrawQuad::TiledContent, IntRect(IntPoint(100, 0), IntSize(100, 100))));
- quadList.append(TestDrawQuad::create(childState, CCDrawQuad::TiledContent, IntRect(IntPoint(0, 100), IntSize(100, 100))));
- quadList.append(TestDrawQuad::create(childState, CCDrawQuad::TiledContent, IntRect(IntPoint(100, 100), IntSize(100, 100))));
+ quadList.append(MakeTileQuad(rootState, IntRect(IntPoint(), IntSize(100, 100)), opaqueRect));
+ quadList.append(MakeTileQuad(rootState, IntRect(IntPoint(100, 0), IntSize(100, 100)), opaqueRect));
+ quadList.append(MakeTileQuad(rootState, IntRect(IntPoint(200, 0), IntSize(100, 100)), opaqueRect));
+ quadList.append(MakeTileQuad(rootState, IntRect(IntPoint(0, 100), IntSize(100, 100)), opaqueRect));
+ quadList.append(MakeTileQuad(rootState, IntRect(IntPoint(100, 100), IntSize(100, 100)), opaqueRect));
+ quadList.append(MakeTileQuad(rootState, IntRect(IntPoint(200, 100), IntSize(100, 100)), opaqueRect));
+ quadList.append(MakeTileQuad(rootState, IntRect(IntPoint(0, 200), IntSize(100, 100)), opaqueRect));
+ quadList.append(MakeTileQuad(rootState, IntRect(IntPoint(100, 200), IntSize(100, 100)), opaqueRect));
+ quadList.append(MakeTileQuad(rootState, IntRect(IntPoint(200, 200), IntSize(100, 100)), opaqueRect));
+
+ quadList.append(MakeTileQuad(childState, IntRect(IntPoint(), IntSize(100, 100)), opaqueRect));
+ quadList.append(MakeTileQuad(childState, IntRect(IntPoint(100, 0), IntSize(100, 100)), opaqueRect));
+ quadList.append(MakeTileQuad(childState, IntRect(IntPoint(0, 100), IntSize(100, 100)), opaqueRect));
+ quadList.append(MakeTileQuad(childState, IntRect(IntPoint(100, 100), IntSize(100, 100)), opaqueRect));
}
#define DECLARE_AND_INITIALIZE_TEST_QUADS \
@@ -129,6 +122,67 @@ TEST(CCQuadCullerTest, verifyCullCenterTileOnly)
EXPECT_EQ(quadList.size(), 13u);
CCQuadCuller::cullOccludedQuads(quadList);
EXPECT_EQ(quadList.size(), 12u);
+
+ IntRect quadVisibleRect1 = quadList[1].get()->quadVisibleRect();
+ EXPECT_EQ(quadVisibleRect1.height(), 50);
+
+ IntRect quadVisibleRect3 = quadList[3].get()->quadVisibleRect();
+ EXPECT_EQ(quadVisibleRect3.width(), 50);
+
+ // Next index is 4, not 5, since centre quad culled.
+ IntRect quadVisibleRect4 = quadList[4].get()->quadVisibleRect();
+ EXPECT_EQ(quadVisibleRect4.width(), 50);
+ EXPECT_EQ(quadVisibleRect4.x(), 250);
+
+ IntRect quadVisibleRect6 = quadList[6].get()->quadVisibleRect();
+ EXPECT_EQ(quadVisibleRect6.height(), 50);
+ EXPECT_EQ(quadVisibleRect6.y(), 250);
+}
+
+TEST(CCQuadCullerTest, verifyCullCenterTileNonIntegralSize1)
+{
+ DECLARE_AND_INITIALIZE_TEST_QUADS
+
+ childTransform.translate(100, 100);
+
+ // Create root layer tile with extent (99.1, 99.1) -> (200.9, 200.9) to make
+ // sure it doesn't get culled due to transform rounding.
+ TransformationMatrix rootTransform;
+ rootTransform.translate(99.1, 99.1);
+ rootTransform.scale(1.018);
+
+ OwnPtr<CCSharedQuadState> rootState = CCSharedQuadState::create(rootTransform, TransformationMatrix(), rootRect, IntRect(), 1.0, true);
+ OwnPtr<CCSharedQuadState> childState = CCSharedQuadState::create(childTransform, TransformationMatrix(), childRect, IntRect(), 1.0, true);
+
+ quadList.append(MakeTileQuad(rootState.get(), IntRect(IntPoint(), IntSize(100, 100))));
+ quadList.append(MakeTileQuad(childState.get(), IntRect(IntPoint(), IntSize(100, 100))));
+
+ EXPECT_EQ(quadList.size(), 2u);
+ CCQuadCuller::cullOccludedQuads(quadList);
+ EXPECT_EQ(quadList.size(), 2u);
+}
+
+TEST(CCQuadCullerTest, verifyCullCenterTileNonIntegralSize2)
+{
+ DECLARE_AND_INITIALIZE_TEST_QUADS
+
+ // Make the child quad slightly smaller than, and centred over, the root layer tile.
+ // Verify the child does not cause the quad below to be culled due to rounding.
+ childTransform.translate(100.1, 100.1);
+ childTransform.scale(0.982);
+
+ TransformationMatrix rootTransform;
+ rootTransform.translate(100, 100);
+
+ OwnPtr<CCSharedQuadState> rootState = CCSharedQuadState::create(rootTransform, TransformationMatrix(), rootRect, IntRect(), 1.0, true);
+ OwnPtr<CCSharedQuadState> childState = CCSharedQuadState::create(childTransform, TransformationMatrix(), childRect, IntRect(), 1.0, true);
+
+ quadList.append(MakeTileQuad(rootState.get(), IntRect(IntPoint(), IntSize(100, 100))));
+ quadList.append(MakeTileQuad(childState.get(), IntRect(IntPoint(), IntSize(100, 100))));
+
+ EXPECT_EQ(quadList.size(), 2u);
+ CCQuadCuller::cullOccludedQuads(quadList);
+ EXPECT_EQ(quadList.size(), 2u);
}
TEST(CCQuadCullerTest, verifyCullChildLinesUpBottomRight)
@@ -146,6 +200,54 @@ TEST(CCQuadCullerTest, verifyCullChildLinesUpBottomRight)
EXPECT_EQ(quadList.size(), 9u);
}
+TEST(CCQuadCullerTest, verifyCullSubRegion)
+{
+ DECLARE_AND_INITIALIZE_TEST_QUADS
+
+ childTransform.translate(50, 50);
+
+ OwnPtr<CCSharedQuadState> rootState = CCSharedQuadState::create(TransformationMatrix(), TransformationMatrix(), rootRect, IntRect(), 1.0, true);
+ OwnPtr<CCSharedQuadState> childState = CCSharedQuadState::create(childTransform, TransformationMatrix(), childRect, IntRect(), 1.0, false);
+ IntRect childOpaqueRect(childRect.x() + childRect.width() / 4, childRect.y() + childRect.height() / 4, childRect.width() / 2, childRect.height() / 2);
+
+ setQuads(rootState.get(), childState.get(), quadList, childOpaqueRect);
+ EXPECT_EQ(quadList.size(), 13u);
+ CCQuadCuller::cullOccludedQuads(quadList);
+ EXPECT_EQ(quadList.size(), 12u);
+}
+
+TEST(CCQuadCullerTest, verifyCullSubRegion2)
+{
+ DECLARE_AND_INITIALIZE_TEST_QUADS
+
+ childTransform.translate(50, 10);
+
+ OwnPtr<CCSharedQuadState> rootState = CCSharedQuadState::create(TransformationMatrix(), TransformationMatrix(), rootRect, IntRect(), 1.0, true);
+ OwnPtr<CCSharedQuadState> childState = CCSharedQuadState::create(childTransform, TransformationMatrix(), childRect, IntRect(), 1.0, false);
+ IntRect childOpaqueRect(childRect.x() + childRect.width() / 4, childRect.y() + childRect.height() / 4, childRect.width() / 2, childRect.height() * 3 / 4);
+
+ setQuads(rootState.get(), childState.get(), quadList, childOpaqueRect);
+ EXPECT_EQ(quadList.size(), 13u);
+ CCQuadCuller::cullOccludedQuads(quadList);
+ EXPECT_EQ(quadList.size(), 12u);
+}
+
+TEST(CCQuadCullerTest, verifyCullSubRegionCheckOvercull)
+{
+ DECLARE_AND_INITIALIZE_TEST_QUADS
+
+ childTransform.translate(50, 49);
+
+ OwnPtr<CCSharedQuadState> rootState = CCSharedQuadState::create(TransformationMatrix(), TransformationMatrix(), rootRect, IntRect(), 1.0, true);
+ OwnPtr<CCSharedQuadState> childState = CCSharedQuadState::create(childTransform, TransformationMatrix(), childRect, IntRect(), 1.0, false);
+ IntRect childOpaqueRect(childRect.x() + childRect.width() / 4, childRect.y() + childRect.height() / 4, childRect.width() / 2, childRect.height() / 2);
+
+ setQuads(rootState.get(), childState.get(), quadList, childOpaqueRect);
+ EXPECT_EQ(quadList.size(), 13u);
+ CCQuadCuller::cullOccludedQuads(quadList);
+ EXPECT_EQ(quadList.size(), 13u);
+}
+
TEST(CCQuadCullerTest, verifyNonAxisAlignedQuadsDontOcclude)
{
DECLARE_AND_INITIALIZE_TEST_QUADS