OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/layer_tree_host_impl.h" | 5 #include "cc/layer_tree_host_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 scoped_ptr<LayerImpl> contents = LayerImpl::create(m_hostImpl->activeTre
e(), 2); | 172 scoped_ptr<LayerImpl> contents = LayerImpl::create(m_hostImpl->activeTre
e(), 2); |
173 contents->setDrawsContent(true); | 173 contents->setDrawsContent(true); |
174 contents->setBounds(contentSize); | 174 contents->setBounds(contentSize); |
175 contents->setContentBounds(contentSize); | 175 contents->setContentBounds(contentSize); |
176 contents->setPosition(gfx::PointF(0, 0)); | 176 contents->setPosition(gfx::PointF(0, 0)); |
177 contents->setAnchorPoint(gfx::PointF(0, 0)); | 177 contents->setAnchorPoint(gfx::PointF(0, 0)); |
178 root->addChild(contents.Pass()); | 178 root->addChild(contents.Pass()); |
179 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); | 179 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); |
180 } | 180 } |
181 | 181 |
| 182 // Create a non-scrolling root and a scrollable child for tests that involve |
| 183 // application of the implTransform(). |
| 184 void createRootWithScrollingChildLayer(const gfx::Size& contentSize) |
| 185 { |
| 186 scoped_ptr<LayerImpl> root = LayerImpl::create(m_hostImpl->activeTree(),
1); |
| 187 root->setBounds(contentSize); |
| 188 root->setContentBounds(contentSize); |
| 189 root->setPosition(gfx::PointF(0, 0)); |
| 190 root->setAnchorPoint(gfx::PointF(0, 0)); |
| 191 |
| 192 scoped_ptr<LayerImpl> child = LayerImpl::create(m_hostImpl->activeTree()
, 2); |
| 193 child->setScrollable(true); |
| 194 child->setScrollOffset(gfx::Vector2d(0, 0)); |
| 195 child->setDrawsContent(true); |
| 196 child->setBounds(contentSize); |
| 197 child->setContentBounds(contentSize); |
| 198 child->setPosition(gfx::PointF(0, 0)); |
| 199 child->setAnchorPoint(gfx::PointF(0, 0)); |
| 200 child->setMaxScrollOffset(gfx::Vector2d(contentSize.width() * 2, content
Size.height() * 2)); |
| 201 root->addChild(child.Pass()); |
| 202 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); |
| 203 } |
| 204 |
182 scoped_ptr<LayerImpl> createScrollableLayer(int id, const gfx::Size& size) | 205 scoped_ptr<LayerImpl> createScrollableLayer(int id, const gfx::Size& size) |
183 { | 206 { |
184 scoped_ptr<LayerImpl> layer = LayerImpl::create(m_hostImpl->activeTree()
, id); | 207 scoped_ptr<LayerImpl> layer = LayerImpl::create(m_hostImpl->activeTree()
, id); |
185 layer->setScrollable(true); | 208 layer->setScrollable(true); |
186 layer->setDrawsContent(true); | 209 layer->setDrawsContent(true); |
187 layer->setBounds(size); | 210 layer->setBounds(size); |
188 layer->setContentBounds(size); | 211 layer->setContentBounds(size); |
189 layer->setMaxScrollOffset(gfx::Vector2d(size.width() * 2, size.height()
* 2)); | 212 layer->setMaxScrollOffset(gfx::Vector2d(size.width() * 2, size.height()
* 2)); |
190 return layer.Pass(); | 213 return layer.Pass(); |
191 } | 214 } |
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->implTransform().matrix().getDouble(3
, 0)); | 1372 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->implTransform().matrix().getDouble(3
, 0)); |
1350 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->implTransform().matrix().getDouble(3
, 1)); | 1373 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->implTransform().matrix().getDouble(3
, 1)); |
1351 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->implTransform().matrix().getDouble(3
, 2)); | 1374 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->implTransform().matrix().getDouble(3
, 2)); |
1352 EXPECT_EQ(1.0, m_hostImpl->rootLayer()->implTransform().matrix().getDouble(3
, 3)); | 1375 EXPECT_EQ(1.0, m_hostImpl->rootLayer()->implTransform().matrix().getDouble(3
, 3)); |
1353 } | 1376 } |
1354 | 1377 |
1355 TEST_P(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnImplThread) | 1378 TEST_P(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnImplThread) |
1356 { | 1379 { |
1357 gfx::Size surfaceSize(10, 10); | 1380 gfx::Size surfaceSize(10, 10); |
1358 float pageScale = 2; | 1381 float pageScale = 2; |
1359 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); | 1382 |
1360 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); | 1383 createRootWithScrollingChildLayer(surfaceSize); |
1361 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1384 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
1362 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); | 1385 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); |
1363 initializeRendererAndDrawFrame(); | 1386 initializeRendererAndDrawFrame(); |
1364 | 1387 |
| 1388 ASSERT_TRUE(m_hostImpl->rootLayer()->children().size() == 1); |
| 1389 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; |
| 1390 |
1365 gfx::Vector2d scrollDelta(0, 10); | 1391 gfx::Vector2d scrollDelta(0, 10); |
1366 gfx::Vector2d expectedScrollDelta(scrollDelta); | 1392 gfx::Vector2d expectedScrollDelta(scrollDelta); |
1367 gfx::Vector2d expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollOffset()); | 1393 gfx::Vector2d expectedMaxScroll(m_hostImpl->rootScrollLayer()->maxScrollOffs
et()); |
1368 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); | 1394 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); |
1369 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); | 1395 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); |
1370 m_hostImpl->scrollEnd(); | 1396 m_hostImpl->scrollEnd(); |
1371 | 1397 |
1372 // Set new page scale on impl thread by pinching. | 1398 // Set new page scale on impl thread by pinching. |
1373 m_hostImpl->pinchGestureBegin(); | 1399 m_hostImpl->pinchGestureBegin(); |
1374 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); | 1400 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); |
1375 m_hostImpl->pinchGestureEnd(); | 1401 m_hostImpl->pinchGestureEnd(); |
1376 drawOneFrame(); | 1402 drawOneFrame(); |
1377 | 1403 |
1378 // The scroll delta is not scaled because the main thread did not scale. | 1404 // The scroll delta is not scaled because the main thread did not scale. |
1379 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | 1405 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
1380 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | 1406 expectContains(*scrollInfo.get(), m_hostImpl->rootScrollLayer()->id(), expec
tedScrollDelta); |
1381 | 1407 |
1382 // The scroll range should also have been updated. | 1408 // The scroll range should also have been updated. |
1383 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollOffset(), expectedMaxScroll); | 1409 EXPECT_EQ(m_hostImpl->rootScrollLayer()->maxScrollOffset(), expectedMaxScrol
l); |
1384 | 1410 |
1385 // The page scale delta should match the new scale on the impl side. | 1411 // The page scale delta should match the new scale on the impl side. |
1386 gfx::Transform expectedScale; | 1412 gfx::Transform expectedScale; |
1387 expectedScale.Scale(pageScale, pageScale); | 1413 expectedScale.Scale(pageScale, pageScale); |
1388 EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), expectedScale); | 1414 // The impl transform is applied to the children of the root, which won't |
| 1415 // in general be the rootScrollLayer(). |
| 1416 EXPECT_EQ(child->implTransform(), expectedScale); |
1389 } | 1417 } |
1390 | 1418 |
1391 TEST_P(LayerTreeHostImplTest, pageScaleDeltaAppliedToRootScrollLayerOnly) | 1419 TEST_P(LayerTreeHostImplTest, pageScaleDeltaAppliedToRootScrollLayerOnly) |
1392 { | 1420 { |
1393 gfx::Size surfaceSize(10, 10); | 1421 gfx::Size surfaceSize(10, 10); |
1394 float defaultPageScale = 1; | 1422 float defaultPageScale = 1; |
1395 gfx::Transform defaultPageScaleMatrix; | 1423 gfx::Transform defaultPageScaleMatrix; |
1396 | 1424 |
1397 float newPageScale = 2; | 1425 float newPageScale = 2; |
1398 gfx::Transform newPageScaleMatrix; | 1426 gfx::Transform newPageScaleMatrix; |
1399 newPageScaleMatrix.Scale(newPageScale, newPageScale); | 1427 newPageScaleMatrix.Scale(newPageScale, newPageScale); |
1400 | 1428 |
1401 // Create a normal scrollable root layer and another scrollable child layer. | 1429 // Create a normal scrollable root layer and another scrollable child layer. |
1402 setupScrollAndContentsLayers(surfaceSize); | 1430 setupScrollAndContentsLayers(surfaceSize); |
1403 LayerImpl* root = m_hostImpl->rootLayer(); | 1431 LayerImpl* root = m_hostImpl->rootLayer(); |
1404 LayerImpl* child = root->children()[0]; | 1432 LayerImpl* child = root->children()[0]; |
1405 | 1433 |
1406 scoped_ptr<LayerImpl> scrollableChild = createScrollableLayer(3, surfaceSize
); | 1434 scoped_ptr<LayerImpl> scrollableChild = createScrollableLayer(3, surfaceSize
); |
1407 child->addChild(scrollableChild.Pass()); | 1435 child->addChild(scrollableChild.Pass()); |
1408 LayerImpl* grandChild = child->children()[0]; | 1436 LayerImpl* grandChild = child->children()[0]; |
1409 | 1437 |
1410 // Set new page scale on impl thread by pinching. | 1438 // Set new page scale on impl thread by pinching. |
1411 m_hostImpl->pinchGestureBegin(); | 1439 m_hostImpl->pinchGestureBegin(); |
1412 m_hostImpl->pinchGestureUpdate(newPageScale, gfx::Point()); | 1440 m_hostImpl->pinchGestureUpdate(newPageScale, gfx::Point()); |
1413 m_hostImpl->pinchGestureEnd(); | 1441 m_hostImpl->pinchGestureEnd(); |
1414 drawOneFrame(); | 1442 drawOneFrame(); |
1415 | 1443 |
1416 // The page scale delta should only be applied to the scrollable root layer. | 1444 // The page scale delta should only be applied to the scrollable root layer. |
1417 EXPECT_EQ(root->implTransform(), newPageScaleMatrix); | 1445 EXPECT_EQ(root->implTransform(), defaultPageScaleMatrix); |
1418 EXPECT_EQ(child->implTransform(), defaultPageScaleMatrix); | 1446 EXPECT_EQ(child->implTransform(), newPageScaleMatrix); |
1419 EXPECT_EQ(grandChild->implTransform(), defaultPageScaleMatrix); | 1447 EXPECT_EQ(grandChild->implTransform(), defaultPageScaleMatrix); |
1420 | 1448 |
1421 // Make sure all the layers are drawn with the page scale delta applied, i.e
., the page scale | 1449 // Make sure all the layers are drawn with the page scale delta applied, i.e
., the page scale |
1422 // delta on the root layer is applied hierarchically. | 1450 // delta on the root layer is applied hierarchically. |
1423 LayerTreeHostImpl::FrameData frame; | 1451 LayerTreeHostImpl::FrameData frame; |
1424 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 1452 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
1425 m_hostImpl->drawLayers(frame); | 1453 m_hostImpl->drawLayers(frame); |
1426 m_hostImpl->didDrawAllLayers(frame); | 1454 m_hostImpl->didDrawAllLayers(frame); |
1427 | 1455 |
1428 EXPECT_EQ(root->drawTransform().matrix().getDouble(0, 0), newPageScale); | 1456 // The page scale (via implTransform) is always applied below the root layer
. |
1429 EXPECT_EQ(root->drawTransform().matrix().getDouble(1, 1), newPageScale); | 1457 EXPECT_EQ(1, root->drawTransform().matrix().getDouble(0, 0)); |
| 1458 EXPECT_EQ(1, root->drawTransform().matrix().getDouble(1, 1)); |
1430 EXPECT_EQ(child->drawTransform().matrix().getDouble(0, 0), newPageScale); | 1459 EXPECT_EQ(child->drawTransform().matrix().getDouble(0, 0), newPageScale); |
1431 EXPECT_EQ(child->drawTransform().matrix().getDouble(1, 1), newPageScale); | 1460 EXPECT_EQ(child->drawTransform().matrix().getDouble(1, 1), newPageScale); |
1432 EXPECT_EQ(grandChild->drawTransform().matrix().getDouble(0, 0), newPageScale
); | 1461 EXPECT_EQ(grandChild->drawTransform().matrix().getDouble(0, 0), newPageScale
); |
1433 EXPECT_EQ(grandChild->drawTransform().matrix().getDouble(1, 1), newPageScale
); | 1462 EXPECT_EQ(grandChild->drawTransform().matrix().getDouble(1, 1), newPageScale
); |
1434 } | 1463 } |
1435 | 1464 |
1436 TEST_P(LayerTreeHostImplTest, scrollChildAndChangePageScaleOnMainThread) | 1465 TEST_P(LayerTreeHostImplTest, scrollChildAndChangePageScaleOnMainThread) |
1437 { | 1466 { |
1438 gfx::Size surfaceSize(10, 10); | 1467 gfx::Size surfaceSize(10, 10); |
1439 scoped_ptr<LayerImpl> root = LayerImpl::create(m_hostImpl->activeTree(), 1); | 1468 scoped_ptr<LayerImpl> root = LayerImpl::create(m_hostImpl->activeTree(), 1); |
(...skipping 24 matching lines...) Expand all Loading... |
1464 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) { | 1493 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) { |
1465 // The scale should apply to the scroll delta. | 1494 // The scale should apply to the scroll delta. |
1466 expectedScrollDelta = gfx::ToFlooredVector2d(gfx::ScaleVector2d(expected
ScrollDelta, pageScale)); | 1495 expectedScrollDelta = gfx::ToFlooredVector2d(gfx::ScaleVector2d(expected
ScrollDelta, pageScale)); |
1467 } | 1496 } |
1468 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | 1497 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
1469 expectContains(*scrollInfo.get(), scrollLayerId, expectedScrollDelta); | 1498 expectContains(*scrollInfo.get(), scrollLayerId, expectedScrollDelta); |
1470 | 1499 |
1471 // The scroll range should not have changed. | 1500 // The scroll range should not have changed. |
1472 EXPECT_EQ(child->maxScrollOffset(), expectedMaxScroll); | 1501 EXPECT_EQ(child->maxScrollOffset(), expectedMaxScroll); |
1473 | 1502 |
1474 // The page scale delta remains constant because the impl thread did not sca
le. | 1503 gfx::Transform scaleTransform; |
1475 gfx::Transform identityTransform; | 1504 if (m_hostImpl->settings().pageScalePinchZoomEnabled) |
1476 EXPECT_EQ(child->implTransform(), gfx::Transform()); | 1505 scaleTransform.Scale(pageScale, pageScale); |
| 1506 EXPECT_EQ(child->implTransform(), scaleTransform); |
1477 } | 1507 } |
1478 | 1508 |
1479 TEST_P(LayerTreeHostImplTest, scrollChildBeyondLimit) | 1509 TEST_P(LayerTreeHostImplTest, scrollChildBeyondLimit) |
1480 { | 1510 { |
1481 // Scroll a child layer beyond its maximum scroll range and make sure the | 1511 // Scroll a child layer beyond its maximum scroll range and make sure the |
1482 // parent layer is scrolled on the axis on which the child was unable to | 1512 // parent layer is scrolled on the axis on which the child was unable to |
1483 // scroll. | 1513 // scroll. |
1484 gfx::Size surfaceSize(10, 10); | 1514 gfx::Size surfaceSize(10, 10); |
1485 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); | 1515 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
1486 | 1516 |
(...skipping 2525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4012 // Make sure that scrolls that only pan the pinch viewport, and not the document
, | 4042 // Make sure that scrolls that only pan the pinch viewport, and not the document
, |
4013 // still force redraw/commit. | 4043 // still force redraw/commit. |
4014 void LayerTreeHostImplTest::pinchZoomPanViewportForcesCommitRedraw(const float d
eviceScaleFactor) | 4044 void LayerTreeHostImplTest::pinchZoomPanViewportForcesCommitRedraw(const float d
eviceScaleFactor) |
4015 { | 4045 { |
4016 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); | 4046 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); |
4017 | 4047 |
4018 gfx::Size layoutSurfaceSize(10, 20); | 4048 gfx::Size layoutSurfaceSize(10, 20); |
4019 gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(dev
iceScaleFactor), | 4049 gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(dev
iceScaleFactor), |
4020 layoutSurfaceSize.height() * static_cast<int>(de
viceScaleFactor)); | 4050 layoutSurfaceSize.height() * static_cast<int>(de
viceScaleFactor)); |
4021 float pageScale = 2; | 4051 float pageScale = 2; |
4022 scoped_ptr<LayerImpl> root = createScrollableLayer(1, layoutSurfaceSize); | 4052 createRootWithScrollingChildLayer(layoutSurfaceSize); |
| 4053 LayerImpl* root = m_hostImpl->rootLayer(); |
| 4054 LayerImpl* child = root->children()[0]; |
4023 // For this test we want to force scrolls to only pan the pinchZoomViewport | 4055 // For this test we want to force scrolls to only pan the pinchZoomViewport |
4024 // and not the document, we can verify commit/redraw are requested. | 4056 // and not the document, we can verify commit/redraw are requested. |
4025 root->setMaxScrollOffset(gfx::Vector2d()); | 4057 child->setMaxScrollOffset(gfx::Vector2d()); |
4026 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); | |
4027 m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); | 4058 m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); |
4028 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); | 4059 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); |
4029 initializeRendererAndDrawFrame(); | 4060 initializeRendererAndDrawFrame(); |
4030 | 4061 |
4031 // Set new page scale on impl thread by pinching. | 4062 // Set new page scale on impl thread by pinching. |
4032 m_hostImpl->pinchGestureBegin(); | 4063 m_hostImpl->pinchGestureBegin(); |
4033 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); | 4064 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); |
4034 m_hostImpl->pinchGestureEnd(); | 4065 m_hostImpl->pinchGestureEnd(); |
4035 drawOneFrame(); | 4066 drawOneFrame(); |
4036 | 4067 |
4037 gfx::Transform expectedImplTransform; | 4068 gfx::Transform expectedImplTransform; |
4038 expectedImplTransform.Scale(pageScale, pageScale); | 4069 expectedImplTransform.Scale(pageScale, pageScale); |
4039 | 4070 |
4040 // Verify the pinch zoom took place. | 4071 // Verify the pinch zoom took place. |
4041 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | 4072 EXPECT_EQ(expectedImplTransform, child->implTransform()); |
4042 | 4073 |
4043 // The implTransform ignores the scroll if !pageScalePinchZoomEnabled, | 4074 // The implTransform ignores the scroll if !pageScalePinchZoomEnabled, |
4044 // so no point in continuing without it. | 4075 // so no point in continuing without it. |
4045 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) | 4076 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) |
4046 return; | 4077 return; |
4047 | 4078 |
4048 m_didRequestCommit = false; | 4079 m_didRequestCommit = false; |
4049 m_didRequestRedraw = false; | 4080 m_didRequestRedraw = false; |
4050 | 4081 |
4051 // This scroll will force the viewport to pan horizontally. | 4082 // This scroll will force the viewport to pan horizontally. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4084 // The device scale factor directly affects computation of the implTransform, so | 4115 // The device scale factor directly affects computation of the implTransform, so |
4085 // we test the two most common use cases. | 4116 // we test the two most common use cases. |
4086 void LayerTreeHostImplTest::pinchZoomPanViewportTest(const float deviceScaleFact
or) | 4117 void LayerTreeHostImplTest::pinchZoomPanViewportTest(const float deviceScaleFact
or) |
4087 { | 4118 { |
4088 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); | 4119 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); |
4089 | 4120 |
4090 gfx::Size layoutSurfaceSize(10, 20); | 4121 gfx::Size layoutSurfaceSize(10, 20); |
4091 gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(dev
iceScaleFactor), | 4122 gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(dev
iceScaleFactor), |
4092 layoutSurfaceSize.height() * static_cast<int>(de
viceScaleFactor)); | 4123 layoutSurfaceSize.height() * static_cast<int>(de
viceScaleFactor)); |
4093 float pageScale = 2; | 4124 float pageScale = 2; |
4094 scoped_ptr<LayerImpl> root = createScrollableLayer(1, layoutSurfaceSize); | 4125 createRootWithScrollingChildLayer(layoutSurfaceSize); |
| 4126 LayerImpl* root = m_hostImpl->rootLayer(); |
| 4127 LayerImpl* child = root->children()[0]; |
4095 // For this test we want to force scrolls to move the pinchZoomViewport so | 4128 // For this test we want to force scrolls to move the pinchZoomViewport so |
4096 // we can see the scroll component on the implTransform. | 4129 // we can see the scroll component on the implTransform. |
4097 root->setMaxScrollOffset(gfx::Vector2d()); | 4130 child->setMaxScrollOffset(gfx::Vector2d()); |
4098 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); | |
4099 m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); | 4131 m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); |
4100 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); | 4132 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); |
4101 initializeRendererAndDrawFrame(); | 4133 initializeRendererAndDrawFrame(); |
4102 | 4134 |
4103 // Set new page scale on impl thread by pinching. | 4135 // Set new page scale on impl thread by pinching. |
4104 m_hostImpl->pinchGestureBegin(); | 4136 m_hostImpl->pinchGestureBegin(); |
4105 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); | 4137 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); |
4106 m_hostImpl->pinchGestureEnd(); | 4138 m_hostImpl->pinchGestureEnd(); |
4107 drawOneFrame(); | 4139 drawOneFrame(); |
4108 | 4140 |
4109 gfx::Transform expectedImplTransform; | 4141 gfx::Transform expectedImplTransform; |
4110 expectedImplTransform.Scale(pageScale, pageScale); | 4142 expectedImplTransform.Scale(pageScale, pageScale); |
4111 | 4143 |
4112 EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), expectedImplTransform); | 4144 EXPECT_EQ(child->implTransform(), expectedImplTransform); |
4113 | 4145 |
4114 // The implTransform ignores the scroll if !pageScalePinchZoomEnabled, | 4146 // The implTransform ignores the scroll if !pageScalePinchZoomEnabled, |
4115 // so no point in continuing without it. | 4147 // so no point in continuing without it. |
4116 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) | 4148 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) |
4117 return; | 4149 return; |
4118 | 4150 |
4119 gfx::Vector2d scrollDelta(5, 0); | 4151 gfx::Vector2d scrollDelta(5, 0); |
4120 // TODO(wjmaclean): Fix the math here so that the expectedTranslation is | 4152 // TODO(wjmaclean): Fix the math here so that the expectedTranslation is |
4121 // scaled instead of the scroll input. | 4153 // scaled instead of the scroll input. |
4122 gfx::Vector2d scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVect
or2d(scrollDelta, m_hostImpl->totalPageScaleFactorForTesting())); | 4154 gfx::Vector2d scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVect
or2d(scrollDelta, m_hostImpl->totalPageScaleFactorForTesting())); |
4123 gfx::Vector2d expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollOffset()); | 4155 gfx::Vector2d expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollOffset()); |
4124 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | 4156 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); |
4125 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | 4157 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); |
4126 m_hostImpl->scrollEnd(); | 4158 m_hostImpl->scrollEnd(); |
4127 drawOneFrame(); | 4159 drawOneFrame(); |
4128 | 4160 |
4129 gfx::Vector2dF expectedTranslation = gfx::ScaleVector2d(scrollDelta, m_hostI
mpl->deviceScaleFactor()); | 4161 gfx::Vector2dF expectedTranslation = gfx::ScaleVector2d(scrollDelta, m_hostI
mpl->deviceScaleFactor()); |
4130 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); | 4162 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); |
4131 | 4163 |
4132 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | 4164 EXPECT_EQ(expectedImplTransform, child->implTransform()); |
4133 // No change expected. | 4165 // No change expected. |
4134 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | 4166 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
4135 // None of the scroll delta should have been used for document scroll. | 4167 // None of the scroll delta should have been used for document scroll. |
4136 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | 4168 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
4137 expectNone(*scrollInfo.get(), m_hostImpl->rootLayer()->id()); | 4169 expectNone(*scrollInfo.get(), m_hostImpl->rootLayer()->id()); |
4138 | 4170 |
4139 // Test scroll in y-direction also. | 4171 // Test scroll in y-direction also. |
4140 scrollDelta = gfx::Vector2d(0, 5); | 4172 scrollDelta = gfx::Vector2d(0, 5); |
4141 scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVector2d(scrollDel
ta, m_hostImpl->totalPageScaleFactorForTesting())); | 4173 scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVector2d(scrollDel
ta, m_hostImpl->totalPageScaleFactorForTesting())); |
4142 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | 4174 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); |
4143 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | 4175 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); |
4144 m_hostImpl->scrollEnd(); | 4176 m_hostImpl->scrollEnd(); |
4145 drawOneFrame(); | 4177 drawOneFrame(); |
4146 | 4178 |
4147 expectedTranslation = gfx::ScaleVector2d(scrollDelta, m_hostImpl->deviceScal
eFactor()); | 4179 expectedTranslation = gfx::ScaleVector2d(scrollDelta, m_hostImpl->deviceScal
eFactor()); |
4148 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); | 4180 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); |
4149 | 4181 |
4150 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | 4182 EXPECT_EQ(expectedImplTransform, child->implTransform()); |
4151 // No change expected. | 4183 // No change expected. |
4152 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | 4184 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
4153 // None of the scroll delta should have been used for document scroll. | 4185 // None of the scroll delta should have been used for document scroll. |
4154 scrollInfo = m_hostImpl->processScrollDeltas(); | 4186 scrollInfo = m_hostImpl->processScrollDeltas(); |
4155 expectNone(*scrollInfo.get(), m_hostImpl->rootLayer()->id()); | 4187 expectNone(*scrollInfo.get(), m_hostImpl->rootLayer()->id()); |
4156 } | 4188 } |
4157 | 4189 |
4158 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportWithDeviceScaleFactor1) | 4190 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportWithDeviceScaleFactor1) |
4159 { | 4191 { |
4160 pinchZoomPanViewportTest(1); | 4192 pinchZoomPanViewportTest(1); |
4161 } | 4193 } |
4162 | 4194 |
4163 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportWithDeviceScaleFactor2) | 4195 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportWithDeviceScaleFactor2) |
4164 { | 4196 { |
4165 pinchZoomPanViewportTest(2); | 4197 pinchZoomPanViewportTest(2); |
4166 } | 4198 } |
4167 | 4199 |
4168 // This test verifies the correct behaviour of the document-then-pinchZoomViewpo
rt | 4200 // This test verifies the correct behaviour of the document-then-pinchZoomViewpo
rt |
4169 // scrolling model, in both x- and y-directions. | 4201 // scrolling model, in both x- and y-directions. |
4170 void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollTest(const float device
ScaleFactor) | 4202 void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollTest(const float device
ScaleFactor) |
4171 { | 4203 { |
4172 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); | 4204 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); |
4173 | 4205 |
4174 gfx::Size layoutSurfaceSize(10, 20); | 4206 gfx::Size layoutSurfaceSize(10, 20); |
4175 gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(dev
iceScaleFactor), | 4207 gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(dev
iceScaleFactor), |
4176 layoutSurfaceSize.height() * static_cast<int>(de
viceScaleFactor)); | 4208 layoutSurfaceSize.height() * static_cast<int>(de
viceScaleFactor)); |
4177 float pageScale = 2; | 4209 float pageScale = 2; |
4178 scoped_ptr<LayerImpl> root = createScrollableLayer(1, layoutSurfaceSize); | 4210 createRootWithScrollingChildLayer(layoutSurfaceSize); |
| 4211 LayerImpl* root = m_hostImpl->rootLayer(); |
| 4212 LayerImpl* child = root->children()[0]; |
4179 // For this test we want to scrolls to move both the document and the | 4213 // For this test we want to scrolls to move both the document and the |
4180 // pinchZoomViewport so we can see some scroll component on the implTransfor
m. | 4214 // pinchZoomViewport so we can see some scroll component on the implTransfor
m. |
4181 root->setMaxScrollOffset(gfx::Vector2d(3, 4)); | 4215 child->setMaxScrollOffset(gfx::Vector2d(3, 4)); |
4182 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); | |
4183 m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); | 4216 m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); |
4184 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); | 4217 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); |
4185 initializeRendererAndDrawFrame(); | 4218 initializeRendererAndDrawFrame(); |
4186 | 4219 |
4187 // Set new page scale on impl thread by pinching. | 4220 // Set new page scale on impl thread by pinching. |
4188 m_hostImpl->pinchGestureBegin(); | 4221 m_hostImpl->pinchGestureBegin(); |
4189 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); | 4222 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); |
4190 m_hostImpl->pinchGestureEnd(); | 4223 m_hostImpl->pinchGestureEnd(); |
4191 drawOneFrame(); | 4224 drawOneFrame(); |
4192 | 4225 |
4193 gfx::Transform expectedImplTransform; | 4226 gfx::Transform expectedImplTransform; |
4194 expectedImplTransform.Scale(pageScale, pageScale); | 4227 expectedImplTransform.Scale(pageScale, pageScale); |
4195 | 4228 |
4196 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | 4229 EXPECT_EQ(expectedImplTransform, child->implTransform()); |
4197 | 4230 |
4198 // The implTransform ignores the scroll if !pageScalePinchZoomEnabled, | 4231 // The implTransform ignores the scroll if !pageScalePinchZoomEnabled, |
4199 // so no point in continuing without it. | 4232 // so no point in continuing without it. |
4200 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) | 4233 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) |
4201 return; | 4234 return; |
4202 | 4235 |
4203 // Scroll document only: scrollDelta chosen to move document horizontally | 4236 // Scroll document only: scrollDelta chosen to move document horizontally |
4204 // to its max scroll offset. | 4237 // to its max scroll offset. |
4205 gfx::Vector2d scrollDelta(3, 0); | 4238 gfx::Vector2d scrollDelta(3, 0); |
4206 gfx::Vector2d scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVect
or2d(scrollDelta, m_hostImpl->totalPageScaleFactorForTesting())); | 4239 gfx::Vector2d scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVect
or2d(scrollDelta, m_hostImpl->totalPageScaleFactorForTesting())); |
4207 gfx::Vector2d expectedScrollDelta(scrollDelta); | 4240 gfx::Vector2d expectedScrollDelta(scrollDelta); |
4208 gfx::Vector2d expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollOffset()); | 4241 gfx::Vector2d expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollOffset()); |
4209 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | 4242 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); |
4210 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | 4243 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); |
4211 m_hostImpl->scrollEnd(); | 4244 m_hostImpl->scrollEnd(); |
4212 drawOneFrame(); | 4245 drawOneFrame(); |
4213 | 4246 |
4214 // The scroll delta is not scaled because the main thread did not scale. | 4247 // The scroll delta is not scaled because the main thread did not scale. |
4215 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | 4248 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
4216 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | 4249 expectContains(*scrollInfo.get(), m_hostImpl->rootScrollLayer()->id(), expec
tedScrollDelta); |
4217 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | 4250 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
4218 | 4251 |
4219 // Verify we did not change the implTransform this time. | 4252 // Verify we did not change the implTransform this time. |
4220 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | 4253 EXPECT_EQ(expectedImplTransform, child->implTransform()); |
4221 | 4254 |
4222 // Further scrolling should move the pinchZoomViewport only. | 4255 // Further scrolling should move the pinchZoomViewport only. |
4223 scrollDelta = gfx::Vector2d(2, 0); | 4256 scrollDelta = gfx::Vector2d(2, 0); |
4224 scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVector2d(scrollDel
ta, m_hostImpl->totalPageScaleFactorForTesting())); | 4257 scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVector2d(scrollDel
ta, m_hostImpl->totalPageScaleFactorForTesting())); |
4225 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | 4258 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); |
4226 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | 4259 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); |
4227 m_hostImpl->scrollEnd(); | 4260 m_hostImpl->scrollEnd(); |
4228 drawOneFrame(); | 4261 drawOneFrame(); |
4229 | 4262 |
4230 gfx::Vector2d expectedPanDelta(scrollDelta); | 4263 gfx::Vector2d expectedPanDelta(scrollDelta); |
4231 gfx::Vector2dF expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_
hostImpl->deviceScaleFactor()); | 4264 gfx::Vector2dF expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_
hostImpl->deviceScaleFactor()); |
4232 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); | 4265 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); |
4233 | 4266 |
4234 EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), expectedImplTransform); | 4267 EXPECT_EQ(child->implTransform(), expectedImplTransform); |
4235 | 4268 |
4236 // The scroll delta on the main thread should not have been affected by this
. | 4269 // The scroll delta on the main thread should not have been affected by this
. |
4237 scrollInfo = m_hostImpl->processScrollDeltas(); | 4270 scrollInfo = m_hostImpl->processScrollDeltas(); |
4238 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | 4271 expectContains(*scrollInfo.get(), m_hostImpl->rootScrollLayer()->id(), expec
tedScrollDelta); |
4239 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | 4272 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
4240 | 4273 |
4241 // Perform same test sequence in y-direction also. | 4274 // Perform same test sequence in y-direction also. |
4242 // Document only scroll. | 4275 // Document only scroll. |
4243 scrollDelta = gfx::Vector2d(0, 4); | 4276 scrollDelta = gfx::Vector2d(0, 4); |
4244 scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVector2d(scrollDel
ta, m_hostImpl->totalPageScaleFactorForTesting())); | 4277 scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVector2d(scrollDel
ta, m_hostImpl->totalPageScaleFactorForTesting())); |
4245 expectedScrollDelta += scrollDelta; | 4278 expectedScrollDelta += scrollDelta; |
4246 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | 4279 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); |
4247 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | 4280 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); |
4248 m_hostImpl->scrollEnd(); | 4281 m_hostImpl->scrollEnd(); |
4249 drawOneFrame(); | 4282 drawOneFrame(); |
4250 | 4283 |
4251 // The scroll delta is not scaled because the main thread did not scale. | 4284 // The scroll delta is not scaled because the main thread did not scale. |
4252 scrollInfo = m_hostImpl->processScrollDeltas(); | 4285 scrollInfo = m_hostImpl->processScrollDeltas(); |
4253 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | 4286 expectContains(*scrollInfo.get(), m_hostImpl->rootScrollLayer()->id(), expec
tedScrollDelta); |
4254 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | 4287 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
4255 | 4288 |
4256 // Verify we did not change the implTransform this time. | 4289 // Verify we did not change the implTransform this time. |
4257 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | 4290 EXPECT_EQ(expectedImplTransform, child->implTransform()); |
4258 | 4291 |
4259 // pinchZoomViewport scroll only. | 4292 // pinchZoomViewport scroll only. |
4260 scrollDelta = gfx::Vector2d(0, 1); | 4293 scrollDelta = gfx::Vector2d(0, 1); |
4261 scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVector2d(scrollDel
ta, m_hostImpl->totalPageScaleFactorForTesting())); | 4294 scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVector2d(scrollDel
ta, m_hostImpl->totalPageScaleFactorForTesting())); |
4262 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | 4295 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); |
4263 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | 4296 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); |
4264 m_hostImpl->scrollEnd(); | 4297 m_hostImpl->scrollEnd(); |
4265 drawOneFrame(); | 4298 drawOneFrame(); |
4266 | 4299 |
4267 expectedPanDelta = scrollDelta; | 4300 expectedPanDelta = scrollDelta; |
4268 expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_hostImpl->devic
eScaleFactor()); | 4301 expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_hostImpl->devic
eScaleFactor()); |
4269 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); | 4302 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); |
4270 | 4303 |
4271 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | 4304 EXPECT_EQ(expectedImplTransform, child->implTransform()); |
4272 | 4305 |
4273 // The scroll delta on the main thread should not have been affected by this
. | 4306 // The scroll delta on the main thread should not have been affected by this
. |
4274 scrollInfo = m_hostImpl->processScrollDeltas(); | 4307 scrollInfo = m_hostImpl->processScrollDeltas(); |
4275 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | 4308 expectContains(*scrollInfo.get(), m_hostImpl->rootScrollLayer()->id(), expec
tedScrollDelta); |
4276 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | 4309 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
4277 } | 4310 } |
4278 | 4311 |
4279 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportAndScrollWithDeviceScaleFactor
) | 4312 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportAndScrollWithDeviceScaleFactor
) |
4280 { | 4313 { |
4281 pinchZoomPanViewportAndScrollTest(1); | 4314 pinchZoomPanViewportAndScrollTest(1); |
4282 } | 4315 } |
4283 | 4316 |
4284 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportAndScrollWithDeviceScaleFactor
2) | 4317 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportAndScrollWithDeviceScaleFactor
2) |
4285 { | 4318 { |
4286 pinchZoomPanViewportAndScrollTest(2); | 4319 pinchZoomPanViewportAndScrollTest(2); |
4287 } | 4320 } |
4288 | 4321 |
4289 // This test verifies the correct behaviour of the document-then-pinchZoomViewpo
rt | 4322 // This test verifies the correct behaviour of the document-then-pinchZoomViewpo
rt |
4290 // scrolling model, in both x- and y-directions, but this time using a single sc
roll | 4323 // scrolling model, in both x- and y-directions, but this time using a single sc
roll |
4291 // that crosses the 'boundary' of what will cause document-only scroll and what
will | 4324 // that crosses the 'boundary' of what will cause document-only scroll and what
will |
4292 // cause both document-scroll and zoomViewport panning. | 4325 // cause both document-scroll and zoomViewport panning. |
4293 void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollBoundaryTest(const floa
t deviceScaleFactor) | 4326 void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollBoundaryTest(const floa
t deviceScaleFactor) |
4294 { | 4327 { |
4295 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); | 4328 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); |
4296 | 4329 |
4297 gfx::Size layoutSurfaceSize(10, 20); | 4330 gfx::Size layoutSurfaceSize(10, 20); |
4298 gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(dev
iceScaleFactor), | 4331 gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(dev
iceScaleFactor), |
4299 layoutSurfaceSize.height() * static_cast<int>(de
viceScaleFactor)); | 4332 layoutSurfaceSize.height() * static_cast<int>(de
viceScaleFactor)); |
4300 float pageScale = 2; | 4333 float pageScale = 2; |
4301 scoped_ptr<LayerImpl> root = createScrollableLayer(1, layoutSurfaceSize); | 4334 createRootWithScrollingChildLayer(layoutSurfaceSize); |
| 4335 LayerImpl* root = m_hostImpl->rootLayer(); |
| 4336 LayerImpl* child = root->children()[0]; |
4302 // For this test we want to scrolls to move both the document and the | 4337 // For this test we want to scrolls to move both the document and the |
4303 // pinchZoomViewport so we can see some scroll component on the implTransfor
m. | 4338 // pinchZoomViewport so we can see some scroll component on the implTransfor
m. |
4304 root->setMaxScrollOffset(gfx::Vector2d(3, 4)); | 4339 child->setMaxScrollOffset(gfx::Vector2d(3, 4)); |
4305 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); | |
4306 m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); | 4340 m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); |
4307 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); | 4341 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); |
4308 initializeRendererAndDrawFrame(); | 4342 initializeRendererAndDrawFrame(); |
4309 | 4343 |
4310 // Set new page scale on impl thread by pinching. | 4344 // Set new page scale on impl thread by pinching. |
4311 m_hostImpl->pinchGestureBegin(); | 4345 m_hostImpl->pinchGestureBegin(); |
4312 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); | 4346 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); |
4313 m_hostImpl->pinchGestureEnd(); | 4347 m_hostImpl->pinchGestureEnd(); |
4314 drawOneFrame(); | 4348 drawOneFrame(); |
4315 | 4349 |
4316 gfx::Transform expectedImplTransform; | 4350 gfx::Transform expectedImplTransform; |
4317 expectedImplTransform.Scale(pageScale, pageScale); | 4351 expectedImplTransform.Scale(pageScale, pageScale); |
4318 | 4352 |
4319 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | 4353 EXPECT_EQ(expectedImplTransform, child->implTransform()); |
4320 | 4354 |
4321 // The implTransform ignores the scroll if !pageScalePinchZoomEnabled, | 4355 // The implTransform ignores the scroll if !pageScalePinchZoomEnabled, |
4322 // so no point in continuing without it. | 4356 // so no point in continuing without it. |
4323 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) | 4357 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) |
4324 return; | 4358 return; |
4325 | 4359 |
4326 // Scroll document and pann zoomViewport in one scroll-delta. | 4360 // Scroll document and pann zoomViewport in one scroll-delta. |
4327 gfx::Vector2d scrollDelta(5, 0); | 4361 gfx::Vector2d scrollDelta(5, 0); |
4328 gfx::Vector2d scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVect
or2d(scrollDelta, m_hostImpl->totalPageScaleFactorForTesting())); | 4362 gfx::Vector2d scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVect
or2d(scrollDelta, m_hostImpl->totalPageScaleFactorForTesting())); |
4329 gfx::Vector2d expectedScrollDelta(gfx::Vector2d(3, 0)); // This component ge
ts handled by document scroll. | 4363 gfx::Vector2d expectedScrollDelta(gfx::Vector2d(3, 0)); // This component ge
ts handled by document scroll. |
4330 gfx::Vector2d expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollOffset()); | 4364 gfx::Vector2d expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollOffset()); |
4331 | 4365 |
4332 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | 4366 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); |
4333 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | 4367 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); |
4334 m_hostImpl->scrollEnd(); | 4368 m_hostImpl->scrollEnd(); |
4335 drawOneFrame(); | 4369 drawOneFrame(); |
4336 | 4370 |
4337 // The scroll delta is not scaled because the main thread did not scale. | 4371 // The scroll delta is not scaled because the main thread did not scale. |
4338 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | 4372 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
4339 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | 4373 expectContains(*scrollInfo.get(), m_hostImpl->rootScrollLayer()->id(), expec
tedScrollDelta); |
4340 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | 4374 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
4341 | 4375 |
4342 gfx::Vector2d expectedPanDelta(2, 0); // This component gets handled by zoom
Viewport pan. | 4376 gfx::Vector2d expectedPanDelta(2, 0); // This component gets handled by zoom
Viewport pan. |
4343 gfx::Vector2dF expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_
hostImpl->deviceScaleFactor()); | 4377 gfx::Vector2dF expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_
hostImpl->deviceScaleFactor()); |
4344 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); | 4378 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); |
4345 | 4379 |
4346 EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), expectedImplTransform); | 4380 EXPECT_EQ(child->implTransform(), expectedImplTransform); |
4347 | 4381 |
4348 // Perform same test sequence in y-direction also. | 4382 // Perform same test sequence in y-direction also. |
4349 scrollDelta = gfx::Vector2d(0, 5); | 4383 scrollDelta = gfx::Vector2d(0, 5); |
4350 scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVector2d(scrollDel
ta, m_hostImpl->totalPageScaleFactorForTesting())); | 4384 scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVector2d(scrollDel
ta, m_hostImpl->totalPageScaleFactorForTesting())); |
4351 expectedScrollDelta += gfx::Vector2d(0, 4); // This component gets handled b
y document scroll. | 4385 expectedScrollDelta += gfx::Vector2d(0, 4); // This component gets handled b
y document scroll. |
4352 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | 4386 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); |
4353 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | 4387 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); |
4354 m_hostImpl->scrollEnd(); | 4388 m_hostImpl->scrollEnd(); |
4355 drawOneFrame(); | 4389 drawOneFrame(); |
4356 | 4390 |
4357 // The scroll delta is not scaled because the main thread did not scale. | 4391 // The scroll delta is not scaled because the main thread did not scale. |
4358 scrollInfo = m_hostImpl->processScrollDeltas(); // This component gets handl
ed by zoomViewport pan. | 4392 scrollInfo = m_hostImpl->processScrollDeltas(); // This component gets handl
ed by zoomViewport pan. |
4359 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | 4393 expectContains(*scrollInfo.get(), m_hostImpl->rootScrollLayer()->id(), expec
tedScrollDelta); |
4360 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | 4394 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); |
4361 | 4395 |
4362 expectedPanDelta = gfx::Vector2d(0, 1); | 4396 expectedPanDelta = gfx::Vector2d(0, 1); |
4363 expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_hostImpl->devic
eScaleFactor()); | 4397 expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_hostImpl->devic
eScaleFactor()); |
4364 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); | 4398 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); |
4365 | 4399 |
4366 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | 4400 EXPECT_EQ(expectedImplTransform, child->implTransform()); |
4367 } | 4401 } |
4368 | 4402 |
4369 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportAndScrollBoundaryWithDeviceSca
leFactor) | 4403 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportAndScrollBoundaryWithDeviceSca
leFactor) |
4370 { | 4404 { |
4371 pinchZoomPanViewportAndScrollBoundaryTest(1); | 4405 pinchZoomPanViewportAndScrollBoundaryTest(1); |
4372 } | 4406 } |
4373 | 4407 |
4374 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportAndScrollBoundaryWithDeviceSca
leFactor2) | 4408 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportAndScrollBoundaryWithDeviceSca
leFactor2) |
4375 { | 4409 { |
4376 pinchZoomPanViewportAndScrollBoundaryTest(2); | 4410 pinchZoomPanViewportAndScrollBoundaryTest(2); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4414 gfx::Rect noDamage = gfx::Rect(m_hostImpl->deviceViewportSize()); | 4448 gfx::Rect noDamage = gfx::Rect(m_hostImpl->deviceViewportSize()); |
4415 drawFrameAndTestDamage(noDamage); | 4449 drawFrameAndTestDamage(noDamage); |
4416 } | 4450 } |
4417 | 4451 |
4418 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, | 4452 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, |
4419 LayerTreeHostImplTest, | 4453 LayerTreeHostImplTest, |
4420 ::testing::Values(false, true)); | 4454 ::testing::Values(false, true)); |
4421 | 4455 |
4422 } // namespace | 4456 } // namespace |
4423 } // namespace cc | 4457 } // namespace cc |
OLD | NEW |