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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 setupScrollAndContentsLayers(gfx::Size(100, 100)); | 565 setupScrollAndContentsLayers(gfx::Size(100, 100)); |
566 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); | 566 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
567 initializeRendererAndDrawFrame(); | 567 initializeRendererAndDrawFrame(); |
568 | 568 |
569 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); | 569 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); |
570 DCHECK(scrollLayer); | 570 DCHECK(scrollLayer); |
571 | 571 |
572 const float minPageScale = 1, maxPageScale = 4; | 572 const float minPageScale = 1, maxPageScale = 4; |
573 const gfx::Transform identityScaleTransform; | 573 const gfx::Transform identityScaleTransform; |
574 | 574 |
575 // The impl-based pinch zoom should not adjust the max scroll position. | |
576 { | |
577 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | |
578 scrollLayer->setImplTransform(identityScaleTransform); | |
579 scrollLayer->setScrollDelta(gfx::Vector2d()); | |
580 | |
581 float pageScaleDelta = 2; | |
582 m_hostImpl->pinchGestureBegin(); | |
583 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(50, 50)); | |
584 m_hostImpl->pinchGestureEnd(); | |
585 EXPECT_TRUE(m_didRequestRedraw); | |
586 EXPECT_TRUE(m_didRequestCommit); | |
587 | |
588 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | |
589 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); | |
590 | |
591 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollOffset(), gfx::Vector2d(50,
50)); | |
592 } | |
593 | |
594 // Scrolling after a pinch gesture should always be in local space. The scr
oll deltas do not | 575 // Scrolling after a pinch gesture should always be in local space. The scr
oll deltas do not |
595 // have the page scale factor applied. | 576 // have the page scale factor applied. |
596 { | 577 { |
597 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 578 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
598 scrollLayer->setImplTransform(identityScaleTransform); | 579 scrollLayer->setImplTransform(identityScaleTransform); |
599 scrollLayer->setScrollDelta(gfx::Vector2d()); | 580 scrollLayer->setScrollDelta(gfx::Vector2d()); |
600 | 581 |
601 float pageScaleDelta = 2; | 582 float pageScaleDelta = 2; |
602 m_hostImpl->pinchGestureBegin(); | 583 m_hostImpl->pinchGestureBegin(); |
603 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(0, 0)); | 584 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(0, 0)); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 EXPECT_TRUE(m_didRequestRedraw); | 747 EXPECT_TRUE(m_didRequestRedraw); |
767 EXPECT_TRUE(m_didRequestCommit); | 748 EXPECT_TRUE(m_didRequestCommit); |
768 | 749 |
769 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | 750 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
770 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); | 751 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); |
771 // Pushed to (0,0) via clamping against contents layer size. | 752 // Pushed to (0,0) via clamping against contents layer size. |
772 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(-50, -50)); | 753 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(-50, -50)); |
773 } | 754 } |
774 } | 755 } |
775 | 756 |
776 TEST_P(LayerTreeHostImplTest, inhibitScrollAndPageScaleUpdatesWhilePinchZooming) | |
777 { | |
778 setupScrollAndContentsLayers(gfx::Size(100, 100)); | |
779 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); | |
780 initializeRendererAndDrawFrame(); | |
781 | |
782 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); | |
783 DCHECK(scrollLayer); | |
784 | |
785 const float minPageScale = m_hostImpl->settings().pageScalePinchZoomEnabled
? 1 : 0.5; | |
786 const float maxPageScale = 4; | |
787 | |
788 // Pinch zoom in. | |
789 { | |
790 // Start a pinch in gesture at the bottom right corner of the viewport. | |
791 const float zoomInDelta = 2; | |
792 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | |
793 m_hostImpl->pinchGestureBegin(); | |
794 m_hostImpl->pinchGestureUpdate(zoomInDelta, gfx::Point(50, 50)); | |
795 | |
796 // Because we are pinch zooming in, we shouldn't get any scroll or page | |
797 // scale deltas. | |
798 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | |
799 EXPECT_EQ(scrollInfo->pageScaleDelta, 1); | |
800 EXPECT_EQ(scrollInfo->scrolls.size(), 0u); | |
801 | |
802 // Once the gesture ends, we get the final scroll and page scale values. | |
803 m_hostImpl->pinchGestureEnd(); | |
804 scrollInfo = m_hostImpl->processScrollDeltas(); | |
805 EXPECT_EQ(scrollInfo->pageScaleDelta, zoomInDelta); | |
806 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) { | |
807 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(25, 25)
); | |
808 } else { | |
809 EXPECT_TRUE(scrollInfo->scrolls.empty()); | |
810 } | |
811 } | |
812 | |
813 // Pinch zoom out. | |
814 { | |
815 // Start a pinch out gesture at the bottom right corner of the viewport. | |
816 const float zoomOutDelta = 0.75; | |
817 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | |
818 m_hostImpl->pinchGestureBegin(); | |
819 m_hostImpl->pinchGestureUpdate(zoomOutDelta, gfx::Point(50, 50)); | |
820 | |
821 // Since we are pinch zooming out, we should get an update to zoom all | |
822 // the way out to the minimum page scale. | |
823 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); | |
824 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) { | |
825 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); | |
826 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(0, 0)); | |
827 } else { | |
828 EXPECT_EQ(scrollInfo->pageScaleDelta, 1); | |
829 EXPECT_TRUE(scrollInfo->scrolls.empty()); | |
830 } | |
831 | |
832 // Once the gesture ends, we get the final scroll and page scale values. | |
833 m_hostImpl->pinchGestureEnd(); | |
834 scrollInfo = m_hostImpl->processScrollDeltas(); | |
835 if (m_hostImpl->settings().pageScalePinchZoomEnabled) { | |
836 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); | |
837 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(25, 25)
); | |
838 } else { | |
839 EXPECT_EQ(scrollInfo->pageScaleDelta, zoomOutDelta); | |
840 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(8, 8)); | |
841 } | |
842 } | |
843 } | |
844 | |
845 TEST_P(LayerTreeHostImplTest, inhibitScrollAndPageScaleUpdatesWhileAnimatingPage
Scale) | |
846 { | |
847 setupScrollAndContentsLayers(gfx::Size(100, 100)); | |
848 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); | |
849 initializeRendererAndDrawFrame(); | |
850 | |
851 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); | |
852 DCHECK(scrollLayer); | |
853 | |
854 const float minPageScale = 0.5; | |
855 const float maxPageScale = 4; | |
856 const base::TimeTicks startTime = base::TimeTicks() + base::TimeDelta::FromS
econds(1); | |
857 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); | |
858 const base::TimeTicks halfwayThroughAnimation = startTime + duration / 2; | |
859 const base::TimeTicks endTime = startTime + duration; | |
860 | |
861 const float pageScaleDelta = 2; | |
862 gfx::Vector2d target(25, 25); | |
863 gfx::Vector2d scaledTarget = target; | |
864 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) | |
865 scaledTarget = gfx::Vector2d(12, 12); | |
866 | |
867 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | |
868 m_hostImpl->startPageScaleAnimation(target, false, pageScaleDelta, startTime
, duration); | |
869 | |
870 // We should immediately get the final zoom and scroll values for the | |
871 // animation. | |
872 m_hostImpl->animate(halfwayThroughAnimation, base::Time()); | |
873 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | |
874 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); | |
875 expectContains(*scrollInfo, scrollLayer->id(), scaledTarget); | |
876 | |
877 // Scrolling during the animation is ignored. | |
878 const gfx::Vector2d scrollDelta(0, 10); | |
879 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(target.x(), target.y()), InputH
andlerClient::Wheel), InputHandlerClient::ScrollStarted); | |
880 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); | |
881 m_hostImpl->scrollEnd(); | |
882 | |
883 // The final page scale and scroll deltas should match what we got | |
884 // earlier. | |
885 m_hostImpl->animate(endTime, base::Time()); | |
886 scrollInfo = m_hostImpl->processScrollDeltas(); | |
887 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); | |
888 expectContains(*scrollInfo, scrollLayer->id(), scaledTarget); | |
889 } | |
890 | |
891 TEST_P(LayerTreeHostImplTest, compositorFrameMetadata) | 757 TEST_P(LayerTreeHostImplTest, compositorFrameMetadata) |
892 { | 758 { |
893 setupScrollAndContentsLayers(gfx::Size(100, 100)); | 759 setupScrollAndContentsLayers(gfx::Size(100, 100)); |
894 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); | 760 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
895 m_hostImpl->setPageScaleFactorAndLimits(1.0f, 0.5f, 4.0f); | 761 m_hostImpl->setPageScaleFactorAndLimits(1.0f, 0.5f, 4.0f); |
896 initializeRendererAndDrawFrame(); | 762 initializeRendererAndDrawFrame(); |
897 | 763 |
898 { | 764 { |
899 CompositorFrameMetadata metadata = m_hostImpl->makeCompositorFrameMetada
ta(); | 765 CompositorFrameMetadata metadata = m_hostImpl->makeCompositorFrameMetada
ta(); |
900 EXPECT_EQ(gfx::Vector2dF(0.0f, 0.0f), metadata.root_scroll_offset); | 766 EXPECT_EQ(gfx::Vector2dF(0.0f, 0.0f), metadata.root_scroll_offset); |
(...skipping 3101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4002 int testCaseIndex = 0; | 3868 int testCaseIndex = 0; |
4003 while (removeRenderPassesCases[testCaseIndex].name) { | 3869 while (removeRenderPassesCases[testCaseIndex].name) { |
4004 RenderPassRemovalTestData testData; | 3870 RenderPassRemovalTestData testData; |
4005 configureRenderPassTestData(removeRenderPassesCases[testCaseIndex].initS
cript, testData, renderer.get()); | 3871 configureRenderPassTestData(removeRenderPassesCases[testCaseIndex].initS
cript, testData, renderer.get()); |
4006 LayerTreeHostImpl::removeRenderPasses(LayerTreeHostImpl::CullRenderPasse
sWithCachedTextures(*renderer), testData); | 3872 LayerTreeHostImpl::removeRenderPasses(LayerTreeHostImpl::CullRenderPasse
sWithCachedTextures(*renderer), testData); |
4007 verifyRenderPassTestData(removeRenderPassesCases[testCaseIndex], testDat
a); | 3873 verifyRenderPassTestData(removeRenderPassesCases[testCaseIndex], testDat
a); |
4008 testCaseIndex++; | 3874 testCaseIndex++; |
4009 } | 3875 } |
4010 } | 3876 } |
4011 | 3877 |
4012 // Make sure that scrolls that only pan the pinch viewport, and not the document
, | |
4013 // still force redraw/commit. | |
4014 void LayerTreeHostImplTest::pinchZoomPanViewportForcesCommitRedraw(const float d
eviceScaleFactor) | |
4015 { | |
4016 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); | |
4017 | |
4018 gfx::Size layoutSurfaceSize(10, 20); | |
4019 gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(dev
iceScaleFactor), | |
4020 layoutSurfaceSize.height() * static_cast<int>(de
viceScaleFactor)); | |
4021 float pageScale = 2; | |
4022 scoped_ptr<LayerImpl> root = createScrollableLayer(1, layoutSurfaceSize); | |
4023 // 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. | |
4025 root->setMaxScrollOffset(gfx::Vector2d()); | |
4026 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); | |
4027 m_hostImpl->activeTree()->DidBecomeActive(); | |
4028 m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); | |
4029 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); | |
4030 initializeRendererAndDrawFrame(); | |
4031 | |
4032 // Set new page scale on impl thread by pinching. | |
4033 m_hostImpl->pinchGestureBegin(); | |
4034 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); | |
4035 m_hostImpl->pinchGestureEnd(); | |
4036 drawOneFrame(); | |
4037 | |
4038 gfx::Transform expectedImplTransform; | |
4039 expectedImplTransform.Scale(pageScale, pageScale); | |
4040 | |
4041 // Verify the pinch zoom took place. | |
4042 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | |
4043 | |
4044 // The implTransform ignores the scroll if !pageScalePinchZoomEnabled, | |
4045 // so no point in continuing without it. | |
4046 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) | |
4047 return; | |
4048 | |
4049 m_didRequestCommit = false; | |
4050 m_didRequestRedraw = false; | |
4051 | |
4052 // This scroll will force the viewport to pan horizontally. | |
4053 gfx::Vector2d scrollDelta(5, 0); | |
4054 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | |
4055 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); | |
4056 m_hostImpl->scrollEnd(); | |
4057 | |
4058 EXPECT_EQ(true, m_didRequestCommit); | |
4059 EXPECT_EQ(true, m_didRequestRedraw); | |
4060 | |
4061 m_didRequestCommit = false; | |
4062 m_didRequestRedraw = false; | |
4063 | |
4064 // This scroll will force the viewport to pan vertically. | |
4065 scrollDelta = gfx::Vector2d(0, 5); | |
4066 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | |
4067 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); | |
4068 m_hostImpl->scrollEnd(); | |
4069 | |
4070 EXPECT_EQ(true, m_didRequestCommit); | |
4071 EXPECT_EQ(true, m_didRequestRedraw); | |
4072 } | |
4073 | |
4074 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportForcesCommitDeviceScaleFactor1
) | |
4075 { | |
4076 pinchZoomPanViewportForcesCommitRedraw(1); | |
4077 } | |
4078 | |
4079 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportForcesCommitDeviceScaleFactor2
) | |
4080 { | |
4081 pinchZoomPanViewportForcesCommitRedraw(2); | |
4082 } | |
4083 | |
4084 // The following test confirms correct operation of scroll of the pinchZoomViewp
ort. | |
4085 // The device scale factor directly affects computation of the implTransform, so | |
4086 // we test the two most common use cases. | |
4087 void LayerTreeHostImplTest::pinchZoomPanViewportTest(const float deviceScaleFact
or) | |
4088 { | |
4089 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); | |
4090 | |
4091 gfx::Size layoutSurfaceSize(10, 20); | |
4092 gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(dev
iceScaleFactor), | |
4093 layoutSurfaceSize.height() * static_cast<int>(de
viceScaleFactor)); | |
4094 float pageScale = 2; | |
4095 scoped_ptr<LayerImpl> root = createScrollableLayer(1, layoutSurfaceSize); | |
4096 // For this test we want to force scrolls to move the pinchZoomViewport so | |
4097 // we can see the scroll component on the implTransform. | |
4098 root->setMaxScrollOffset(gfx::Vector2d()); | |
4099 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); | |
4100 m_hostImpl->activeTree()->DidBecomeActive(); | |
4101 m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); | |
4102 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); | |
4103 initializeRendererAndDrawFrame(); | |
4104 | |
4105 // Set new page scale on impl thread by pinching. | |
4106 m_hostImpl->pinchGestureBegin(); | |
4107 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); | |
4108 m_hostImpl->pinchGestureEnd(); | |
4109 drawOneFrame(); | |
4110 | |
4111 gfx::Transform expectedImplTransform; | |
4112 expectedImplTransform.Scale(pageScale, pageScale); | |
4113 | |
4114 EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), expectedImplTransform); | |
4115 | |
4116 // The implTransform ignores the scroll if !pageScalePinchZoomEnabled, | |
4117 // so no point in continuing without it. | |
4118 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) | |
4119 return; | |
4120 | |
4121 gfx::Vector2d scrollDelta(5, 0); | |
4122 // TODO(wjmaclean): Fix the math here so that the expectedTranslation is | |
4123 // scaled instead of the scroll input. | |
4124 gfx::Vector2d scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVect
or2d(scrollDelta, m_hostImpl->totalPageScaleFactorForTesting())); | |
4125 gfx::Vector2d expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollOffset()); | |
4126 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | |
4127 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | |
4128 m_hostImpl->scrollEnd(); | |
4129 drawOneFrame(); | |
4130 | |
4131 gfx::Vector2dF expectedTranslation = gfx::ScaleVector2d(scrollDelta, m_hostI
mpl->deviceScaleFactor()); | |
4132 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); | |
4133 | |
4134 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | |
4135 // No change expected. | |
4136 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | |
4137 // None of the scroll delta should have been used for document scroll. | |
4138 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | |
4139 expectNone(*scrollInfo.get(), m_hostImpl->rootLayer()->id()); | |
4140 | |
4141 // Test scroll in y-direction also. | |
4142 scrollDelta = gfx::Vector2d(0, 5); | |
4143 scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVector2d(scrollDel
ta, m_hostImpl->totalPageScaleFactorForTesting())); | |
4144 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | |
4145 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | |
4146 m_hostImpl->scrollEnd(); | |
4147 drawOneFrame(); | |
4148 | |
4149 expectedTranslation = gfx::ScaleVector2d(scrollDelta, m_hostImpl->deviceScal
eFactor()); | |
4150 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); | |
4151 | |
4152 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | |
4153 // No change expected. | |
4154 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | |
4155 // None of the scroll delta should have been used for document scroll. | |
4156 scrollInfo = m_hostImpl->processScrollDeltas(); | |
4157 expectNone(*scrollInfo.get(), m_hostImpl->rootLayer()->id()); | |
4158 } | |
4159 | |
4160 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportWithDeviceScaleFactor1) | |
4161 { | |
4162 pinchZoomPanViewportTest(1); | |
4163 } | |
4164 | |
4165 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportWithDeviceScaleFactor2) | |
4166 { | |
4167 pinchZoomPanViewportTest(2); | |
4168 } | |
4169 | |
4170 // This test verifies the correct behaviour of the document-then-pinchZoomViewpo
rt | |
4171 // scrolling model, in both x- and y-directions. | |
4172 void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollTest(const float device
ScaleFactor) | |
4173 { | |
4174 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); | |
4175 | |
4176 gfx::Size layoutSurfaceSize(10, 20); | |
4177 gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(dev
iceScaleFactor), | |
4178 layoutSurfaceSize.height() * static_cast<int>(de
viceScaleFactor)); | |
4179 float pageScale = 2; | |
4180 scoped_ptr<LayerImpl> root = createScrollableLayer(1, layoutSurfaceSize); | |
4181 // For this test we want to scrolls to move both the document and the | |
4182 // pinchZoomViewport so we can see some scroll component on the implTransfor
m. | |
4183 root->setMaxScrollOffset(gfx::Vector2d(3, 4)); | |
4184 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); | |
4185 m_hostImpl->activeTree()->DidBecomeActive(); | |
4186 m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); | |
4187 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); | |
4188 initializeRendererAndDrawFrame(); | |
4189 | |
4190 // Set new page scale on impl thread by pinching. | |
4191 m_hostImpl->pinchGestureBegin(); | |
4192 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); | |
4193 m_hostImpl->pinchGestureEnd(); | |
4194 drawOneFrame(); | |
4195 | |
4196 gfx::Transform expectedImplTransform; | |
4197 expectedImplTransform.Scale(pageScale, pageScale); | |
4198 | |
4199 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | |
4200 | |
4201 // The implTransform ignores the scroll if !pageScalePinchZoomEnabled, | |
4202 // so no point in continuing without it. | |
4203 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) | |
4204 return; | |
4205 | |
4206 // Scroll document only: scrollDelta chosen to move document horizontally | |
4207 // to its max scroll offset. | |
4208 gfx::Vector2d scrollDelta(3, 0); | |
4209 gfx::Vector2d scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVect
or2d(scrollDelta, m_hostImpl->totalPageScaleFactorForTesting())); | |
4210 gfx::Vector2d expectedScrollDelta(scrollDelta); | |
4211 gfx::Vector2d expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollOffset()); | |
4212 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | |
4213 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | |
4214 m_hostImpl->scrollEnd(); | |
4215 drawOneFrame(); | |
4216 | |
4217 // The scroll delta is not scaled because the main thread did not scale. | |
4218 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | |
4219 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | |
4220 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | |
4221 | |
4222 // Verify we did not change the implTransform this time. | |
4223 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | |
4224 | |
4225 // Further scrolling should move the pinchZoomViewport only. | |
4226 scrollDelta = gfx::Vector2d(2, 0); | |
4227 scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVector2d(scrollDel
ta, m_hostImpl->totalPageScaleFactorForTesting())); | |
4228 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | |
4229 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | |
4230 m_hostImpl->scrollEnd(); | |
4231 drawOneFrame(); | |
4232 | |
4233 gfx::Vector2d expectedPanDelta(scrollDelta); | |
4234 gfx::Vector2dF expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_
hostImpl->deviceScaleFactor()); | |
4235 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); | |
4236 | |
4237 EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), expectedImplTransform); | |
4238 | |
4239 // The scroll delta on the main thread should not have been affected by this
. | |
4240 scrollInfo = m_hostImpl->processScrollDeltas(); | |
4241 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | |
4242 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | |
4243 | |
4244 // Perform same test sequence in y-direction also. | |
4245 // Document only scroll. | |
4246 scrollDelta = gfx::Vector2d(0, 4); | |
4247 scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVector2d(scrollDel
ta, m_hostImpl->totalPageScaleFactorForTesting())); | |
4248 expectedScrollDelta += scrollDelta; | |
4249 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | |
4250 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | |
4251 m_hostImpl->scrollEnd(); | |
4252 drawOneFrame(); | |
4253 | |
4254 // The scroll delta is not scaled because the main thread did not scale. | |
4255 scrollInfo = m_hostImpl->processScrollDeltas(); | |
4256 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | |
4257 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | |
4258 | |
4259 // Verify we did not change the implTransform this time. | |
4260 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | |
4261 | |
4262 // pinchZoomViewport scroll only. | |
4263 scrollDelta = gfx::Vector2d(0, 1); | |
4264 scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVector2d(scrollDel
ta, m_hostImpl->totalPageScaleFactorForTesting())); | |
4265 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | |
4266 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | |
4267 m_hostImpl->scrollEnd(); | |
4268 drawOneFrame(); | |
4269 | |
4270 expectedPanDelta = scrollDelta; | |
4271 expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_hostImpl->devic
eScaleFactor()); | |
4272 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); | |
4273 | |
4274 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | |
4275 | |
4276 // The scroll delta on the main thread should not have been affected by this
. | |
4277 scrollInfo = m_hostImpl->processScrollDeltas(); | |
4278 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | |
4279 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | |
4280 } | |
4281 | |
4282 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportAndScrollWithDeviceScaleFactor
) | |
4283 { | |
4284 pinchZoomPanViewportAndScrollTest(1); | |
4285 } | |
4286 | |
4287 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportAndScrollWithDeviceScaleFactor
2) | |
4288 { | |
4289 pinchZoomPanViewportAndScrollTest(2); | |
4290 } | |
4291 | |
4292 // This test verifies the correct behaviour of the document-then-pinchZoomViewpo
rt | |
4293 // scrolling model, in both x- and y-directions, but this time using a single sc
roll | |
4294 // that crosses the 'boundary' of what will cause document-only scroll and what
will | |
4295 // cause both document-scroll and zoomViewport panning. | |
4296 void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollBoundaryTest(const floa
t deviceScaleFactor) | |
4297 { | |
4298 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); | |
4299 | |
4300 gfx::Size layoutSurfaceSize(10, 20); | |
4301 gfx::Size deviceSurfaceSize(layoutSurfaceSize.width() * static_cast<int>(dev
iceScaleFactor), | |
4302 layoutSurfaceSize.height() * static_cast<int>(de
viceScaleFactor)); | |
4303 float pageScale = 2; | |
4304 scoped_ptr<LayerImpl> root = createScrollableLayer(1, layoutSurfaceSize); | |
4305 // For this test we want to scrolls to move both the document and the | |
4306 // pinchZoomViewport so we can see some scroll component on the implTransfor
m. | |
4307 root->setMaxScrollOffset(gfx::Vector2d(3, 4)); | |
4308 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); | |
4309 m_hostImpl->activeTree()->DidBecomeActive(); | |
4310 m_hostImpl->setViewportSize(layoutSurfaceSize, deviceSurfaceSize); | |
4311 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); | |
4312 initializeRendererAndDrawFrame(); | |
4313 | |
4314 // Set new page scale on impl thread by pinching. | |
4315 m_hostImpl->pinchGestureBegin(); | |
4316 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); | |
4317 m_hostImpl->pinchGestureEnd(); | |
4318 drawOneFrame(); | |
4319 | |
4320 gfx::Transform expectedImplTransform; | |
4321 expectedImplTransform.Scale(pageScale, pageScale); | |
4322 | |
4323 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | |
4324 | |
4325 // The implTransform ignores the scroll if !pageScalePinchZoomEnabled, | |
4326 // so no point in continuing without it. | |
4327 if (!m_hostImpl->settings().pageScalePinchZoomEnabled) | |
4328 return; | |
4329 | |
4330 // Scroll document and pann zoomViewport in one scroll-delta. | |
4331 gfx::Vector2d scrollDelta(5, 0); | |
4332 gfx::Vector2d scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVect
or2d(scrollDelta, m_hostImpl->totalPageScaleFactorForTesting())); | |
4333 gfx::Vector2d expectedScrollDelta(gfx::Vector2d(3, 0)); // This component ge
ts handled by document scroll. | |
4334 gfx::Vector2d expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollOffset()); | |
4335 | |
4336 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | |
4337 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | |
4338 m_hostImpl->scrollEnd(); | |
4339 drawOneFrame(); | |
4340 | |
4341 // The scroll delta is not scaled because the main thread did not scale. | |
4342 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; | |
4343 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | |
4344 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | |
4345 | |
4346 gfx::Vector2d expectedPanDelta(2, 0); // This component gets handled by zoom
Viewport pan. | |
4347 gfx::Vector2dF expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_
hostImpl->deviceScaleFactor()); | |
4348 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); | |
4349 | |
4350 EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), expectedImplTransform); | |
4351 | |
4352 // Perform same test sequence in y-direction also. | |
4353 scrollDelta = gfx::Vector2d(0, 5); | |
4354 scrollDeltaInZoomedViewport = ToFlooredVector2d(gfx::ScaleVector2d(scrollDel
ta, m_hostImpl->totalPageScaleFactorForTesting())); | |
4355 expectedScrollDelta += gfx::Vector2d(0, 4); // This component gets handled b
y document scroll. | |
4356 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po
int(0, 0), InputHandlerClient::Gesture)); | |
4357 m_hostImpl->scrollBy(gfx::Point(), scrollDeltaInZoomedViewport); | |
4358 m_hostImpl->scrollEnd(); | |
4359 drawOneFrame(); | |
4360 | |
4361 // The scroll delta is not scaled because the main thread did not scale. | |
4362 scrollInfo = m_hostImpl->processScrollDeltas(); // This component gets handl
ed by zoomViewport pan. | |
4363 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | |
4364 EXPECT_EQ(expectedMaxScroll, m_hostImpl->rootLayer()->maxScrollOffset()); | |
4365 | |
4366 expectedPanDelta = gfx::Vector2d(0, 1); | |
4367 expectedTranslation = gfx::ScaleVector2d(expectedPanDelta, m_hostImpl->devic
eScaleFactor()); | |
4368 expectedImplTransform.Translate(-expectedTranslation.x(), -expectedTranslati
on.y()); | |
4369 | |
4370 EXPECT_EQ(expectedImplTransform, m_hostImpl->rootLayer()->implTransform()); | |
4371 } | |
4372 | |
4373 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportAndScrollBoundaryWithDeviceSca
leFactor) | |
4374 { | |
4375 pinchZoomPanViewportAndScrollBoundaryTest(1); | |
4376 } | |
4377 | |
4378 TEST_P(LayerTreeHostImplTest, pinchZoomPanViewportAndScrollBoundaryWithDeviceSca
leFactor2) | |
4379 { | |
4380 pinchZoomPanViewportAndScrollBoundaryTest(2); | |
4381 } | |
4382 | |
4383 class LayerTreeHostImplTestWithDelegatingRenderer : public LayerTreeHostImplTest
{ | 3878 class LayerTreeHostImplTestWithDelegatingRenderer : public LayerTreeHostImplTest
{ |
4384 protected: | 3879 protected: |
4385 virtual scoped_ptr<OutputSurface> createOutputSurface() | 3880 virtual scoped_ptr<OutputSurface> createOutputSurface() |
4386 { | 3881 { |
4387 // Creates an output surface with a parent to use a delegating renderer. | 3882 // Creates an output surface with a parent to use a delegating renderer. |
4388 WebKit::WebGraphicsContext3D::Attributes attrs; | 3883 WebKit::WebGraphicsContext3D::Attributes attrs; |
4389 return FakeOutputSurface::CreateDelegating3d(FakeWebGraphicsContext3D::C
reate(attrs).PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); | 3884 return FakeOutputSurface::CreateDelegating3d(FakeWebGraphicsContext3D::C
reate(attrs).PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); |
4390 } | 3885 } |
4391 | 3886 |
4392 void drawFrameAndTestDamage(const gfx::RectF& expectedDamage) { | 3887 void drawFrameAndTestDamage(const gfx::RectF& expectedDamage) { |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4676 m_hostImpl->didDrawAllLayers(frame); | 4171 m_hostImpl->didDrawAllLayers(frame); |
4677 } | 4172 } |
4678 } | 4173 } |
4679 | 4174 |
4680 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, | 4175 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, |
4681 LayerTreeHostImplTest, | 4176 LayerTreeHostImplTest, |
4682 ::testing::Values(false, true)); | 4177 ::testing::Values(false, true)); |
4683 | 4178 |
4684 } // namespace | 4179 } // namespace |
4685 } // namespace cc | 4180 } // namespace cc |
OLD | NEW |