Index: cc/layer_tree_host_impl_unittest.cc |
diff --git a/cc/layer_tree_host_impl_unittest.cc b/cc/layer_tree_host_impl_unittest.cc |
index 207aea8bd189f950ce7f9d1fa75f425cdd68919b..a3351a5ef1bd261f2f0d77ab5cb5c1ee4e150073 100644 |
--- a/cc/layer_tree_host_impl_unittest.cc |
+++ b/cc/layer_tree_host_impl_unittest.cc |
@@ -179,6 +179,29 @@ public: |
m_hostImpl->activeTree()->SetRootLayer(root.Pass()); |
} |
+ // Create a non-scrolling root and a scrollable child for tests that involve |
+ // application of the implTransform(). |
+ void createRootWithScrollingChildLayer(const gfx::Size& contentSize) |
+ { |
+ scoped_ptr<LayerImpl> root = LayerImpl::create(m_hostImpl->activeTree(), 1); |
+ root->setBounds(contentSize); |
+ root->setContentBounds(contentSize); |
+ root->setPosition(gfx::PointF(0, 0)); |
+ root->setAnchorPoint(gfx::PointF(0, 0)); |
+ |
+ scoped_ptr<LayerImpl> child = LayerImpl::create(m_hostImpl->activeTree(), 2); |
+ child->setScrollable(true); |
+ child->setScrollOffset(gfx::Vector2d(0, 0)); |
+ child->setDrawsContent(true); |
+ child->setBounds(contentSize); |
+ child->setContentBounds(contentSize); |
+ child->setPosition(gfx::PointF(0, 0)); |
+ child->setAnchorPoint(gfx::PointF(0, 0)); |
+ child->setMaxScrollOffset(gfx::Vector2d(contentSize.width() * 2, contentSize.height() * 2)); |
+ root->addChild(child.Pass()); |
+ m_hostImpl->activeTree()->SetRootLayer(root.Pass()); |
+ } |
+ |
scoped_ptr<LayerImpl> createScrollableLayer(int id, const gfx::Size& size) |
{ |
scoped_ptr<LayerImpl> layer = LayerImpl::create(m_hostImpl->activeTree(), id); |
@@ -1356,15 +1379,18 @@ TEST_P(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnImplThread) |
{ |
gfx::Size surfaceSize(10, 10); |
float pageScale = 2; |
- scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
- m_hostImpl->activeTree()->SetRootLayer(root.Pass()); |
+ |
+ createRootWithScrollingChildLayer(surfaceSize); |
m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); |
initializeRendererAndDrawFrame(); |
+ ASSERT_TRUE(m_hostImpl->rootLayer()->children().size() == 1); |
+ LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; |
+ |
gfx::Vector2d scrollDelta(0, 10); |
gfx::Vector2d expectedScrollDelta(scrollDelta); |
- gfx::Vector2d expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollOffset()); |
+ gfx::Vector2d expectedMaxScroll(m_hostImpl->rootScrollLayer()->maxScrollOffset()); |
EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
m_hostImpl->scrollEnd(); |
@@ -1377,15 +1403,17 @@ TEST_P(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnImplThread) |
// The scroll delta is not scaled because the main thread did not scale. |
scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas(); |
- expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScrollDelta); |
+ expectContains(*scrollInfo.get(), m_hostImpl->rootScrollLayer()->id(), expectedScrollDelta); |
// The scroll range should also have been updated. |
- EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollOffset(), expectedMaxScroll); |
+ EXPECT_EQ(m_hostImpl->rootScrollLayer()->maxScrollOffset(), expectedMaxScroll); |
// The page scale delta should match the new scale on the impl side. |
gfx::Transform expectedScale; |
expectedScale.Scale(pageScale, pageScale); |
- EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), expectedScale); |
+ // The impl transform is applied to the children of the root, which won't |
+ // in general be the rootScrollLayer(). |
+ EXPECT_EQ(child->implTransform(), expectedScale); |
} |
TEST_P(LayerTreeHostImplTest, pageScaleDeltaAppliedToRootScrollLayerOnly) |
@@ -1414,8 +1442,8 @@ TEST_P(LayerTreeHostImplTest, pageScaleDeltaAppliedToRootScrollLayerOnly) |
drawOneFrame(); |
// The page scale delta should only be applied to the scrollable root layer. |
- EXPECT_EQ(root->implTransform(), newPageScaleMatrix); |
- EXPECT_EQ(child->implTransform(), defaultPageScaleMatrix); |
+ EXPECT_EQ(root->implTransform(), defaultPageScaleMatrix); |
+ EXPECT_EQ(child->implTransform(), newPageScaleMatrix); |
EXPECT_EQ(grandChild->implTransform(), defaultPageScaleMatrix); |
// Make sure all the layers are drawn with the page scale delta applied, i.e., the page scale |
@@ -1425,8 +1453,9 @@ TEST_P(LayerTreeHostImplTest, pageScaleDeltaAppliedToRootScrollLayerOnly) |
m_hostImpl->drawLayers(frame); |
m_hostImpl->didDrawAllLayers(frame); |
- EXPECT_EQ(root->drawTransform().matrix().getDouble(0, 0), newPageScale); |
- EXPECT_EQ(root->drawTransform().matrix().getDouble(1, 1), newPageScale); |
+ // The page scale (via implTransform) is always applied below the root layer. |
+ EXPECT_EQ(1, root->drawTransform().matrix().getDouble(0, 0)); |
+ EXPECT_EQ(1, root->drawTransform().matrix().getDouble(1, 1)); |
EXPECT_EQ(child->drawTransform().matrix().getDouble(0, 0), newPageScale); |
EXPECT_EQ(child->drawTransform().matrix().getDouble(1, 1), newPageScale); |
EXPECT_EQ(grandChild->drawTransform().matrix().getDouble(0, 0), newPageScale); |
@@ -1471,9 +1500,10 @@ TEST_P(LayerTreeHostImplTest, scrollChildAndChangePageScaleOnMainThread) |
// The scroll range should not have changed. |
EXPECT_EQ(child->maxScrollOffset(), expectedMaxScroll); |
- // The page scale delta remains constant because the impl thread did not scale. |
- gfx::Transform identityTransform; |
- EXPECT_EQ(child->implTransform(), gfx::Transform()); |
+ gfx::Transform scaleTransform; |
+ if (m_hostImpl->settings().pageScalePinchZoomEnabled) |
+ scaleTransform.Scale(pageScale, pageScale); |
+ EXPECT_EQ(child->implTransform(), scaleTransform); |
} |
TEST_P(LayerTreeHostImplTest, scrollChildBeyondLimit) |
@@ -4019,11 +4049,12 @@ void LayerTreeHostImplTest::pinchZoomPanViewportForcesCommitRedraw(const float d |
gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(deviceScaleFactor), |
layoutSurfaceSize.height() * static_cast<int>(deviceScaleFactor)); |
float pageScale = 2; |
- scoped_ptr<LayerImpl> root = createScrollableLayer(1, layoutSurfaceSize); |
+ createRootWithScrollingChildLayer(layoutSurfaceSize); |
+ LayerImpl* root = m_hostImpl->rootLayer(); |
+ LayerImpl* child = root->children()[0]; |
// For this test we want to force scrolls to only pan the pinchZoomViewport |
// and not the document, we can verify commit/redraw are requested. |
- root->setMaxScrollOffset(gfx::Vector2d()); |
- m_hostImpl->activeTree()->SetRootLayer(root.Pass()); |
+ child->setMaxScrollOffset(gfx::Vector2d()); |
m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); |
m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); |
initializeRendererAndDrawFrame(); |
@@ -4038,7 +4069,7 @@ void LayerTreeHostImplTest::pinchZoomPanViewportForcesCommitRedraw(const float d |
expectedImplTransform.Scale(pageScale, pageScale); |
// Verify the pinch zoom took place. |
- EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); |
+ EXPECT_EQ(expectedImplTransform, child->implTransform()); |
// The implTransform ignores the scroll if !pageScalePinchZoomEnabled, |
// so no point in continuing without it. |
@@ -4091,11 +4122,12 @@ void LayerTreeHostImplTest::pinchZoomPanViewportTest(const float deviceScaleFact |
gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(deviceScaleFactor), |
layoutSurfaceSize.height() * static_cast<int>(deviceScaleFactor)); |
float pageScale = 2; |
- scoped_ptr<LayerImpl> root = createScrollableLayer(1, layoutSurfaceSize); |
+ createRootWithScrollingChildLayer(layoutSurfaceSize); |
+ LayerImpl* root = m_hostImpl->rootLayer(); |
+ LayerImpl* child = root->children()[0]; |
// For this test we want to force scrolls to move the pinchZoomViewport so |
// we can see the scroll component on the implTransform. |
- root->setMaxScrollOffset(gfx::Vector2d()); |
- m_hostImpl->activeTree()->SetRootLayer(root.Pass()); |
+ child->setMaxScrollOffset(gfx::Vector2d()); |
m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); |
m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); |
initializeRendererAndDrawFrame(); |
@@ -4109,7 +4141,7 @@ void LayerTreeHostImplTest::pinchZoomPanViewportTest(const float deviceScaleFact |
gfx::Transform expectedImplTransform; |
expectedImplTransform.Scale(pageScale, pageScale); |
- EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), expectedImplTransform); |
+ EXPECT_EQ(child->implTransform(), expectedImplTransform); |
// The implTransform ignores the scroll if !pageScalePinchZoomEnabled, |
// so no point in continuing without it. |
@@ -4129,7 +4161,7 @@ void LayerTreeHostImplTest::pinchZoomPanViewportTest(const float deviceScaleFact |
gfx::Vector2dF expectedTranslation = gfx::ScaleVector2d(scrollDelta, m_hostImpl->deviceScaleFactor()); |
expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslation.y()); |
- EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); |
+ EXPECT_EQ(expectedImplTransform, child->implTransform()); |
// No change expected. |
EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
// None of the scroll delta should have been used for document scroll. |
@@ -4147,7 +4179,7 @@ void LayerTreeHostImplTest::pinchZoomPanViewportTest(const float deviceScaleFact |
expectedTranslation = gfx::ScaleVector2d(scrollDelta, m_hostImpl->deviceScaleFactor()); |
expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslation.y()); |
- EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); |
+ EXPECT_EQ(expectedImplTransform, child->implTransform()); |
// No change expected. |
EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
// None of the scroll delta should have been used for document scroll. |
@@ -4175,11 +4207,12 @@ void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollTest(const float device |
gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(deviceScaleFactor), |
layoutSurfaceSize.height() * static_cast<int>(deviceScaleFactor)); |
float pageScale = 2; |
- scoped_ptr<LayerImpl> root = createScrollableLayer(1, layoutSurfaceSize); |
+ createRootWithScrollingChildLayer(layoutSurfaceSize); |
+ LayerImpl* root = m_hostImpl->rootLayer(); |
+ LayerImpl* child = root->children()[0]; |
// For this test we want to scrolls to move both the document and the |
// pinchZoomViewport so we can see some scroll component on the implTransform. |
- root->setMaxScrollOffset(gfx::Vector2d(3, 4)); |
- m_hostImpl->activeTree()->SetRootLayer(root.Pass()); |
+ child->setMaxScrollOffset(gfx::Vector2d(3, 4)); |
m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); |
m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); |
initializeRendererAndDrawFrame(); |
@@ -4193,7 +4226,7 @@ void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollTest(const float device |
gfx::Transform expectedImplTransform; |
expectedImplTransform.Scale(pageScale, pageScale); |
- EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); |
+ EXPECT_EQ(expectedImplTransform, child->implTransform()); |
// The implTransform ignores the scroll if !pageScalePinchZoomEnabled, |
// so no point in continuing without it. |
@@ -4213,11 +4246,11 @@ void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollTest(const float device |
// The scroll delta is not scaled because the main thread did not scale. |
scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas(); |
- expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScrollDelta); |
+ expectContains(*scrollInfo.get(), m_hostImpl->rootScrollLayer()->id(), expectedScrollDelta); |
EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
// Verify we did not change the implTransform this time. |
- EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); |
+ EXPECT_EQ(expectedImplTransform, child->implTransform()); |
// Further scrolling should move the pinchZoomViewport only. |
scrollDelta = gfx::Vector2d(2, 0); |
@@ -4231,11 +4264,11 @@ void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollTest(const float device |
gfx::Vector2dF expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_hostImpl->deviceScaleFactor()); |
expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslation.y()); |
- EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), expectedImplTransform); |
+ EXPECT_EQ(child->implTransform(), expectedImplTransform); |
// The scroll delta on the main thread should not have been affected by this. |
scrollInfo = m_hostImpl->processScrollDeltas(); |
- expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScrollDelta); |
+ expectContains(*scrollInfo.get(), m_hostImpl->rootScrollLayer()->id(), expectedScrollDelta); |
EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
// Perform same test sequence in y-direction also. |
@@ -4250,11 +4283,11 @@ void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollTest(const float device |
// The scroll delta is not scaled because the main thread did not scale. |
scrollInfo = m_hostImpl->processScrollDeltas(); |
- expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScrollDelta); |
+ expectContains(*scrollInfo.get(), m_hostImpl->rootScrollLayer()->id(), expectedScrollDelta); |
EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
// Verify we did not change the implTransform this time. |
- EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); |
+ EXPECT_EQ(expectedImplTransform, child->implTransform()); |
// pinchZoomViewport scroll only. |
scrollDelta = gfx::Vector2d(0, 1); |
@@ -4268,11 +4301,11 @@ void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollTest(const float device |
expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_hostImpl->deviceScaleFactor()); |
expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslation.y()); |
- EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); |
+ EXPECT_EQ(expectedImplTransform, child->implTransform()); |
// The scroll delta on the main thread should not have been affected by this. |
scrollInfo = m_hostImpl->processScrollDeltas(); |
- expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScrollDelta); |
+ expectContains(*scrollInfo.get(), m_hostImpl->rootScrollLayer()->id(), expectedScrollDelta); |
EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
} |
@@ -4298,11 +4331,12 @@ void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollBoundaryTest(const floa |
gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(deviceScaleFactor), |
layoutSurfaceSize.height() * static_cast<int>(deviceScaleFactor)); |
float pageScale = 2; |
- scoped_ptr<LayerImpl> root = createScrollableLayer(1, layoutSurfaceSize); |
+ createRootWithScrollingChildLayer(layoutSurfaceSize); |
+ LayerImpl* root = m_hostImpl->rootLayer(); |
+ LayerImpl* child = root->children()[0]; |
// For this test we want to scrolls to move both the document and the |
// pinchZoomViewport so we can see some scroll component on the implTransform. |
- root->setMaxScrollOffset(gfx::Vector2d(3, 4)); |
- m_hostImpl->activeTree()->SetRootLayer(root.Pass()); |
+ child->setMaxScrollOffset(gfx::Vector2d(3, 4)); |
m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); |
m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); |
initializeRendererAndDrawFrame(); |
@@ -4316,7 +4350,7 @@ void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollBoundaryTest(const floa |
gfx::Transform expectedImplTransform; |
expectedImplTransform.Scale(pageScale, pageScale); |
- EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); |
+ EXPECT_EQ(expectedImplTransform, child->implTransform()); |
// The implTransform ignores the scroll if !pageScalePinchZoomEnabled, |
// so no point in continuing without it. |
@@ -4336,14 +4370,14 @@ void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollBoundaryTest(const floa |
// The scroll delta is not scaled because the main thread did not scale. |
scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas(); |
- expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScrollDelta); |
+ expectContains(*scrollInfo.get(), m_hostImpl->rootScrollLayer()->id(), expectedScrollDelta); |
EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
gfx::Vector2d expectedPanDelta(2, 0); // This component gets handled by zoomViewport pan. |
gfx::Vector2dF expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_hostImpl->deviceScaleFactor()); |
expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslation.y()); |
- EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), expectedImplTransform); |
+ EXPECT_EQ(child->implTransform(), expectedImplTransform); |
// Perform same test sequence in y-direction also. |
scrollDelta = gfx::Vector2d(0, 5); |
@@ -4356,14 +4390,14 @@ void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollBoundaryTest(const floa |
// The scroll delta is not scaled because the main thread did not scale. |
scrollInfo = m_hostImpl->processScrollDeltas(); // This component gets handled by zoomViewport pan. |
- expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScrollDelta); |
+ expectContains(*scrollInfo.get(), m_hostImpl->rootScrollLayer()->id(), expectedScrollDelta); |
EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
expectedPanDelta = gfx::Vector2d(0, 1); |
expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_hostImpl->deviceScaleFactor()); |
expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslation.y()); |
- EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); |
+ EXPECT_EQ(expectedImplTransform, child->implTransform()); |
} |
TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportAndScrollBoundaryWithDeviceScaleFactor) |