summaryrefslogtreecommitdiff
path: root/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-09-10 19:10:20 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-09-10 19:10:20 +0200
commit284837daa07b29d6a63a748544a90b1f5842ac5c (patch)
treeecd258180bde91fe741e0cfd2638beb3c6da7e8e /Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp
parent2e2ba8ff45915f40ed3e014101269c175f2a89a0 (diff)
downloadqtwebkit-284837daa07b29d6a63a748544a90b1f5842ac5c.tar.gz
Imported WebKit commit 68645295d2e3e09af2c942f092556f06aa5f8b0d (http://svn.webkit.org/repository/webkit/trunk@128073)
New snapshot
Diffstat (limited to 'Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp')
-rw-r--r--Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp385
1 files changed, 336 insertions, 49 deletions
diff --git a/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp b/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp
index 0b5aa6be6..3d008ce13 100644
--- a/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp
+++ b/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp
@@ -27,15 +27,16 @@
#include "CCLayerTreeHostCommon.h"
#include "CCAnimationTestCommon.h"
+#include "CCGeometryTestUtils.h"
#include "CCLayerAnimationController.h"
#include "CCLayerImpl.h"
#include "CCLayerSorter.h"
-#include "CCLayerTreeTestCommon.h"
#include "CCMathUtil.h"
#include "CCProxy.h"
#include "CCSingleThreadProxy.h"
#include "CCThread.h"
#include "ContentLayerChromium.h"
+#include "ContentLayerChromiumClient.h"
#include "LayerChromium.h"
#include <gmock/gmock.h>
@@ -46,27 +47,6 @@ using namespace WebCore;
using namespace WebKitTests;
using WebKit::WebTransformationMatrix;
-void WebKitTests::ExpectTransformationMatrixEq(WebTransformationMatrix expected,
- WebTransformationMatrix actual)
-{
- EXPECT_FLOAT_EQ((expected).m11(), (actual).m11());
- EXPECT_FLOAT_EQ((expected).m12(), (actual).m12());
- EXPECT_FLOAT_EQ((expected).m13(), (actual).m13());
- EXPECT_FLOAT_EQ((expected).m14(), (actual).m14());
- EXPECT_FLOAT_EQ((expected).m21(), (actual).m21());
- EXPECT_FLOAT_EQ((expected).m22(), (actual).m22());
- EXPECT_FLOAT_EQ((expected).m23(), (actual).m23());
- EXPECT_FLOAT_EQ((expected).m24(), (actual).m24());
- EXPECT_FLOAT_EQ((expected).m31(), (actual).m31());
- EXPECT_FLOAT_EQ((expected).m32(), (actual).m32());
- EXPECT_FLOAT_EQ((expected).m33(), (actual).m33());
- EXPECT_FLOAT_EQ((expected).m34(), (actual).m34());
- EXPECT_FLOAT_EQ((expected).m41(), (actual).m41());
- EXPECT_FLOAT_EQ((expected).m42(), (actual).m42());
- EXPECT_FLOAT_EQ((expected).m43(), (actual).m43());
- EXPECT_FLOAT_EQ((expected).m44(), (actual).m44());
-}
-
namespace {
template<typename LayerType>
@@ -672,6 +652,7 @@ TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceListForRenderSurfaceWithClipp
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint(30, 30), IntSize(10, 10), false);
parent->addChild(renderSurface1);
+ parent->setMasksToBounds(true);
renderSurface1->addChild(child);
renderSurface1->setForceRenderSurface(true);
@@ -1477,9 +1458,9 @@ TEST(CCLayerTreeHostCommonTest, verifyDrawableContentRectForLayers)
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
- EXPECT_INT_RECT_EQ(IntRect(IntPoint(5, 5), IntSize(10, 10)), grandChild1->drawableContentRect());
- EXPECT_INT_RECT_EQ(IntRect(IntPoint(15, 15), IntSize(5, 5)), grandChild3->drawableContentRect());
- EXPECT_INT_RECT_EQ(IntRect(IntPoint(15, 15), IntSize(5, 5)), grandChild3->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(IntPoint(5, 5), IntSize(10, 10)), grandChild1->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(IntPoint(15, 15), IntSize(5, 5)), grandChild3->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(IntPoint(15, 15), IntSize(5, 5)), grandChild3->drawableContentRect());
EXPECT_TRUE(grandChild4->drawableContentRect().isEmpty());
}
@@ -1549,9 +1530,9 @@ TEST(CCLayerTreeHostCommonTest, verifyClipRectIsPropagatedCorrectlyToSurfaces)
EXPECT_FALSE(grandChild4->renderSurface()); // Because grandChild4 is entirely clipped, it is expected to not have a renderSurface.
// Surfaces are clipped by their parent, but un-affected by the owning layer's masksToBounds.
- EXPECT_INT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild1->renderSurface()->clipRect());
- EXPECT_INT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild2->renderSurface()->clipRect());
- EXPECT_INT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild3->renderSurface()->clipRect());
+ EXPECT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild1->renderSurface()->clipRect());
+ EXPECT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild2->renderSurface()->clipRect());
+ EXPECT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild3->renderSurface()->clipRect());
}
TEST(CCLayerTreeHostCommonTest, verifyAnimationsForRenderSurfaceHierarchy)
@@ -1706,7 +1687,7 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectForIdentityTransform)
IntRect layerContentRect = IntRect(IntPoint(10, 10), IntSize(30, 30));
IntRect expected = IntRect(IntPoint(10, 10), IntSize(30, 30));
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
- EXPECT_INT_RECT_EQ(expected, actual);
+ EXPECT_RECT_EQ(expected, actual);
// Case 2: Layer is outside the surface rect.
layerContentRect = IntRect(IntPoint(120, 120), IntSize(30, 30));
@@ -1717,7 +1698,7 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectForIdentityTransform)
layerContentRect = IntRect(IntPoint(80, 80), IntSize(30, 30));
expected = IntRect(IntPoint(80, 80), IntSize(20, 20));
actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
- EXPECT_INT_RECT_EQ(expected, actual);
+ EXPECT_RECT_EQ(expected, actual);
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectForTranslations)
@@ -1733,7 +1714,7 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectForTranslations)
layerToSurfaceTransform.translate(10, 10);
IntRect expected = IntRect(IntPoint(0, 0), IntSize(30, 30));
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
- EXPECT_INT_RECT_EQ(expected, actual);
+ EXPECT_RECT_EQ(expected, actual);
// Case 2: Layer is outside the surface rect.
layerToSurfaceTransform.makeIdentity();
@@ -1746,7 +1727,7 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectForTranslations)
layerToSurfaceTransform.translate(80, 80);
expected = IntRect(IntPoint(0, 0), IntSize(20, 20));
actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
- EXPECT_INT_RECT_EQ(expected, actual);
+ EXPECT_RECT_EQ(expected, actual);
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor2DRotations)
@@ -1764,7 +1745,7 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor2DRotations)
layerToSurfaceTransform.rotate(45);
IntRect expected = IntRect(IntPoint(0, 0), IntSize(30, 30));
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
- EXPECT_INT_RECT_EQ(expected, actual);
+ EXPECT_RECT_EQ(expected, actual);
// Case 2: Layer is outside the surface rect.
layerToSurfaceTransform.makeIdentity();
@@ -1782,7 +1763,7 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor2DRotations)
layerToSurfaceTransform.rotate(45);
expected = IntRect(IntPoint(0, 0), IntSize(30, 30));
actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
- EXPECT_INT_RECT_EQ(expected, actual);
+ EXPECT_RECT_EQ(expected, actual);
// Case 4: The layer is rotated about its top-left corner, and translated upwards. In
// surface space, the layer is oriented diagonally, with only the top corner
@@ -1794,7 +1775,7 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor2DRotations)
layerToSurfaceTransform.rotate(45);
expected = IntRect(IntPoint(15, 0), IntSize(15, 30)); // right half of layer bounds.
actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
- EXPECT_INT_RECT_EQ(expected, actual);
+ EXPECT_RECT_EQ(expected, actual);
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform)
@@ -1810,7 +1791,7 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform)
layerToSurfaceTransform.rotate3d(0, 45, 0);
IntRect expected = IntRect(IntPoint(0, 0), IntSize(100, 100));
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
- EXPECT_INT_RECT_EQ(expected, actual);
+ EXPECT_RECT_EQ(expected, actual);
// Case 2: Orthographic projection of a layer rotated about y-axis by 45 degrees, but
// shifted to the side so only the right-half the layer would be visible on
@@ -1821,7 +1802,7 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform)
layerToSurfaceTransform.rotate3d(0, 45, 0); // rotates about the left edge of the layer
expected = IntRect(IntPoint(50, 0), IntSize(50, 100)); // right half of the layer.
actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
- EXPECT_INT_RECT_EQ(expected, actual);
+ EXPECT_RECT_EQ(expected, actual);
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform)
@@ -1848,7 +1829,7 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform)
IntRect expected = IntRect(IntPoint(-50, -50), IntSize(200, 200));
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
- EXPECT_INT_RECT_EQ(expected, actual);
+ EXPECT_RECT_EQ(expected, actual);
// Case 2: same projection as before, except that the layer is also translated to the
// side, so that only the right half of the layer should be visible.
@@ -1861,7 +1842,7 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform)
layerToSurfaceTransform.translate3d(-200, 0, 0);
expected = IntRect(IntPoint(50, -50), IntSize(100, 200)); // The right half of the layer's bounding rect.
actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
- EXPECT_INT_RECT_EQ(expected, actual);
+ EXPECT_RECT_EQ(expected, actual);
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicIsNotClippedBehindSurface)
@@ -1884,7 +1865,7 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicIsNotClippedBe
IntRect expected = IntRect(IntPoint(0, 0), IntSize(100, 100));
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
- EXPECT_INT_RECT_EQ(expected, actual);
+ EXPECT_RECT_EQ(expected, actual);
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW)
@@ -1950,7 +1931,313 @@ TEST(CCLayerTreeHostCommonTest, verifyVisibleRectForPerspectiveUnprojection)
// that the entire layer should still be considered visible.
IntRect expected = IntRect(IntPoint(-10, -10), IntSize(20, 20));
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
- EXPECT_INT_RECT_EQ(expected, actual);
+ EXPECT_RECT_EQ(expected, actual);
+}
+
+TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForSimpleLayers)
+{
+ RefPtr<LayerChromium> root = LayerChromium::create();
+ RefPtr<LayerChromiumWithForcedDrawsContent> child1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ RefPtr<LayerChromiumWithForcedDrawsContent> child2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ RefPtr<LayerChromiumWithForcedDrawsContent> child3 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ root->addChild(child1);
+ root->addChild(child2);
+ root->addChild(child3);
+
+ WebTransformationMatrix identityMatrix;
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
+ setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(50, 50), false);
+ setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false);
+ setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false);
+
+ executeCalculateDrawTransformsAndVisibility(root.get());
+
+ EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect());
+
+ // Layers that do not draw content should have empty visibleContentRects.
+ EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect());
+
+ // layer visibleContentRects are clipped by their targetSurface
+ EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 25, 25), child2->visibleContentRect());
+ EXPECT_TRUE(child3->visibleContentRect().isEmpty());
+
+ // layer drawableContentRects are not clipped.
+ EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect());
+}
+
+TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersClippedByLayer)
+{
+ RefPtr<LayerChromium> root = LayerChromium::create();
+ RefPtr<LayerChromium> child = LayerChromium::create();
+ RefPtr<LayerChromiumWithForcedDrawsContent> grandChild1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ RefPtr<LayerChromiumWithForcedDrawsContent> grandChild2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ RefPtr<LayerChromiumWithForcedDrawsContent> grandChild3 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ root->addChild(child);
+ child->addChild(grandChild1);
+ child->addChild(grandChild2);
+ child->addChild(grandChild3);
+
+ WebTransformationMatrix identityMatrix;
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
+ setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
+ setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false);
+ setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false);
+ setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false);
+
+ child->setMasksToBounds(true);
+ executeCalculateDrawTransformsAndVisibility(root.get());
+
+ ASSERT_FALSE(child->renderSurface());
+
+ EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect());
+
+ // Layers that do not draw content should have empty visibleContentRects.
+ EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), child->visibleContentRect());
+
+ // All grandchild visibleContentRects should be clipped by child.
+ EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), grandChild1->visibleContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 25, 25), grandChild2->visibleContentRect());
+ EXPECT_TRUE(grandChild3->visibleContentRect().isEmpty());
+
+ // All grandchild drawableContentRects should also be clipped by child.
+ EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), grandChild1->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(75, 75, 25, 25), grandChild2->drawableContentRect());
+ EXPECT_TRUE(grandChild3->drawableContentRect().isEmpty());
+}
+
+TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface)
+{
+ RefPtr<LayerChromium> root = LayerChromium::create();
+ RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
+ RefPtr<LayerChromiumWithForcedDrawsContent> child1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ RefPtr<LayerChromiumWithForcedDrawsContent> child2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ RefPtr<LayerChromiumWithForcedDrawsContent> child3 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ root->addChild(renderSurface1);
+ renderSurface1->addChild(child1);
+ renderSurface1->addChild(child2);
+ renderSurface1->addChild(child3);
+
+ WebTransformationMatrix identityMatrix;
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
+ setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false);
+ setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false);
+ setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false);
+ setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false);
+
+ renderSurface1->setForceRenderSurface(true);
+ executeCalculateDrawTransformsAndVisibility(root.get());
+
+ ASSERT_TRUE(renderSurface1->renderSurface());
+
+ EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect());
+
+ // Layers that do not draw content should have empty visibleContentRects.
+ EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect());
+
+ // An unclipped surface grows its drawableContentRect to include all drawable regions of the subtree.
+ EXPECT_RECT_EQ(IntRect(5, 5, 170, 170), renderSurface1->renderSurface()->drawableContentRect());
+
+ // All layers that draw content into the unclipped surface are also unclipped.
+ EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child2->visibleContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child3->visibleContentRect());
+
+ EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), child1->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect());
+}
+
+TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersInClippedRenderSurface)
+{
+ RefPtr<LayerChromium> root = LayerChromium::create();
+ RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
+ RefPtr<LayerChromiumWithForcedDrawsContent> child1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ RefPtr<LayerChromiumWithForcedDrawsContent> child2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ RefPtr<LayerChromiumWithForcedDrawsContent> child3 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ root->addChild(renderSurface1);
+ renderSurface1->addChild(child1);
+ renderSurface1->addChild(child2);
+ renderSurface1->addChild(child3);
+
+ WebTransformationMatrix identityMatrix;
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
+ setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false);
+ setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false);
+ setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false);
+ setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false);
+
+ root->setMasksToBounds(true);
+ renderSurface1->setForceRenderSurface(true);
+ executeCalculateDrawTransformsAndVisibility(root.get());
+
+ ASSERT_TRUE(renderSurface1->renderSurface());
+
+ EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect());
+
+ // Layers that do not draw content should have empty visibleContentRects.
+ EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect());
+
+ // A clipped surface grows its drawableContentRect to include all drawable regions of the subtree,
+ // but also gets clamped by the ancestor's clip.
+ EXPECT_RECT_EQ(IntRect(5, 5, 95, 95), renderSurface1->renderSurface()->drawableContentRect());
+
+ // All layers that draw content into the surface have their visibleContentRect clipped by the surface clipRect.
+ EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 25, 25), child2->visibleContentRect());
+ EXPECT_TRUE(child3->visibleContentRect().isEmpty());
+
+ // But the drawableContentRects are unclipped.
+ EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), child1->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect());
+}
+
+TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForSurfaceHierarchy)
+{
+ // Check that clipping does not propagate down surfaces.
+ RefPtr<LayerChromium> root = LayerChromium::create();
+ RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
+ RefPtr<LayerChromium> renderSurface2 = LayerChromium::create();
+ RefPtr<LayerChromiumWithForcedDrawsContent> child1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ RefPtr<LayerChromiumWithForcedDrawsContent> child2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ RefPtr<LayerChromiumWithForcedDrawsContent> child3 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ root->addChild(renderSurface1);
+ renderSurface1->addChild(renderSurface2);
+ renderSurface2->addChild(child1);
+ renderSurface2->addChild(child2);
+ renderSurface2->addChild(child3);
+
+ WebTransformationMatrix identityMatrix;
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
+ setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false);
+ setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(7, 13), false);
+ setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false);
+ setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false);
+ setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false);
+
+ root->setMasksToBounds(true);
+ renderSurface1->setForceRenderSurface(true);
+ renderSurface2->setForceRenderSurface(true);
+ executeCalculateDrawTransformsAndVisibility(root.get());
+
+ ASSERT_TRUE(renderSurface1->renderSurface());
+ ASSERT_TRUE(renderSurface2->renderSurface());
+
+ EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect());
+
+ // Layers that do not draw content should have empty visibleContentRects.
+ EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface2->visibleContentRect());
+
+ // A clipped surface grows its drawableContentRect to include all drawable regions of the subtree,
+ // but also gets clamped by the ancestor's clip.
+ EXPECT_RECT_EQ(IntRect(5, 5, 95, 95), renderSurface1->renderSurface()->drawableContentRect());
+
+ // renderSurface1 lives in the "unclipped universe" of renderSurface1, and is only
+ // implicitly clipped by renderSurface1's contentRect. So, renderSurface2 grows to
+ // enclose all drawable content of its subtree.
+ EXPECT_RECT_EQ(IntRect(5, 5, 170, 170), renderSurface2->renderSurface()->drawableContentRect());
+
+ // All layers that draw content into renderSurface2 think they are unclipped.
+ EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child2->visibleContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child3->visibleContentRect());
+
+ // drawableContentRects are also unclipped.
+ EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), child1->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect());
+}
+
+TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsWithTransformOnUnclippedSurface)
+{
+ // Layers that have non-axis aligned bounds (due to transforms) have an expanded,
+ // axis-aligned drawableContentRect and visibleContentRect.
+
+ RefPtr<LayerChromium> root = LayerChromium::create();
+ RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
+ RefPtr<LayerChromiumWithForcedDrawsContent> child1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ root->addChild(renderSurface1);
+ renderSurface1->addChild(child1);
+
+ WebTransformationMatrix identityMatrix;
+ WebTransformationMatrix childRotation;
+ childRotation.rotate(45);
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
+ setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false);
+ setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, FloatPoint(0.5, 0.5), FloatPoint(25, 25), IntSize(50, 50), false);
+
+ renderSurface1->setForceRenderSurface(true);
+ executeCalculateDrawTransformsAndVisibility(root.get());
+
+ ASSERT_TRUE(renderSurface1->renderSurface());
+
+ EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect());
+
+ // Layers that do not draw content should have empty visibleContentRects.
+ EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect());
+ EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect());
+
+ // The unclipped surface grows its drawableContentRect to include all drawable regions of the subtree.
+ int diagonalRadius = ceil(sqrt(2.0) * 25);
+ IntRect expectedSurfaceDrawableContent = IntRect(50 - diagonalRadius, 50 - diagonalRadius, diagonalRadius * 2, diagonalRadius * 2);
+ EXPECT_RECT_EQ(expectedSurfaceDrawableContent, renderSurface1->renderSurface()->drawableContentRect());
+
+ // All layers that draw content into the unclipped surface are also unclipped.
+ EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect());
+ EXPECT_RECT_EQ(expectedSurfaceDrawableContent, child1->drawableContentRect());
+}
+
+TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsWithTransformOnClippedSurface)
+{
+ // Layers that have non-axis aligned bounds (due to transforms) have an expanded,
+ // axis-aligned drawableContentRect and visibleContentRect.
+
+ RefPtr<LayerChromium> root = LayerChromium::create();
+ RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
+ RefPtr<LayerChromiumWithForcedDrawsContent> child1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
+ root->addChild(renderSurface1);
+ renderSurface1->addChild(child1);
+
+ WebTransformationMatrix identityMatrix;
+ WebTransformationMatrix childRotation;
+ childRotation.rotate(45);
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(50, 50), false);
+ setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false);
+ setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, FloatPoint(0.5, 0.5), FloatPoint(25, 25), IntSize(50, 50), false);
+
+ root->setMasksToBounds(true);
+ renderSurface1->setForceRenderSurface(true);
+ executeCalculateDrawTransformsAndVisibility(root.get());
+
+ ASSERT_TRUE(renderSurface1->renderSurface());
+
+ // The clipped surface clamps the drawableContentRect that encloses the rotated layer.
+ int diagonalRadius = ceil(sqrt(2.0) * 25);
+ IntRect unclippedSurfaceContent = IntRect(50 - diagonalRadius, 50 - diagonalRadius, diagonalRadius * 2, diagonalRadius * 2);
+ IntRect expectedSurfaceDrawableContent = intersection(unclippedSurfaceContent, IntRect(0, 0, 50, 50));
+ EXPECT_RECT_EQ(expectedSurfaceDrawableContent, renderSurface1->renderSurface()->drawableContentRect());
+
+ // On the clipped surface, only a quarter of the child1 is visible, but when rotating
+ // it back to child1's content space, the actual enclosing rect ends up covering the
+ // full left half of child1.
+ EXPECT_RECT_EQ(IntRect(0, 0, 26, 50), child1->visibleContentRect());
+
+ // The child's drawableContentRect is unclipped.
+ EXPECT_RECT_EQ(unclippedSurfaceContent, child1->drawableContentRect());
}
TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithoutPreserves3d)
@@ -2593,7 +2880,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSingleLayerWithScaledContents
// Sanity check the scenario we just created.
// The visibleContentRect for testLayer is actually 100x100, even though its layout size is 50x50, positioned at 25x25.
CCLayerImpl* testLayer = root->children()[0].get();
- EXPECT_INT_RECT_EQ(IntRect(IntPoint::zero(), IntSize(100, 100)), testLayer->visibleContentRect());
+ EXPECT_RECT_EQ(IntRect(IntPoint::zero(), IntSize(100, 100)), testLayer->visibleContentRect());
ASSERT_EQ(1u, renderSurfaceLayerList.size());
ASSERT_EQ(1u, root->renderSurface()->layerList().size());
@@ -3073,14 +3360,14 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists)
EXPECT_EQ(4, resultLayer->id());
}
-class MockContentLayerDelegate : public ContentLayerDelegate {
+class MockContentLayerChromiumClient : public ContentLayerChromiumClient {
public:
- MockContentLayerDelegate() { }
- virtual ~MockContentLayerDelegate() { }
+ MockContentLayerChromiumClient() { }
+ virtual ~MockContentLayerChromiumClient() { }
virtual void paintContents(SkCanvas*, const IntRect& clip, FloatRect& opaque) OVERRIDE { }
};
-PassRefPtr<ContentLayerChromium> createDrawableContentLayerChromium(ContentLayerDelegate* delegate)
+PassRefPtr<ContentLayerChromium> createDrawableContentLayerChromium(ContentLayerChromiumClient* delegate)
{
RefPtr<ContentLayerChromium> toReturn = ContentLayerChromium::create(delegate);
toReturn->setIsDrawable(true);
@@ -3090,7 +3377,7 @@ PassRefPtr<ContentLayerChromium> createDrawableContentLayerChromium(ContentLayer
TEST(CCLayerTreeHostCommonTest, verifyLayerTransformsInHighDPI)
{
// Verify draw and screen space transforms of layers not in a surface.
- MockContentLayerDelegate delegate;
+ MockContentLayerChromiumClient delegate;
WebTransformationMatrix identityMatrix;
RefPtr<ContentLayerChromium> parent = createDrawableContentLayerChromium(&delegate);
@@ -3162,7 +3449,7 @@ TEST(CCLayerTreeHostCommonTest, verifyLayerTransformsInHighDPI)
TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPI)
{
- MockContentLayerDelegate delegate;
+ MockContentLayerChromiumClient delegate;
WebTransformationMatrix identityMatrix;
RefPtr<ContentLayerChromium> parent = createDrawableContentLayerChromium(&delegate);
@@ -3214,7 +3501,7 @@ TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPI)
WebTransformationMatrix expectedDuplicateChildDrawTransform = child->drawTransform();
EXPECT_TRANSFORMATION_MATRIX_EQ(child->drawTransform(), duplicateChildNonOwner->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(child->screenSpaceTransform(), duplicateChildNonOwner->screenSpaceTransform());
- EXPECT_INT_RECT_EQ(child->drawableContentRect(), duplicateChildNonOwner->drawableContentRect());
+ EXPECT_RECT_EQ(child->drawableContentRect(), duplicateChildNonOwner->drawableContentRect());
EXPECT_EQ(child->contentBounds(), duplicateChildNonOwner->contentBounds());
WebTransformationMatrix expectedRenderSurfaceDrawTransform;