| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/layer_tree_host.h" | 7 #include "cc/layer_tree_host.h" |
| 8 | 8 |
| 9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
| 10 #include "cc/content_layer.h" | 10 #include "cc/content_layer.h" |
| 11 #include "cc/content_layer_client.h" | 11 #include "cc/content_layer_client.h" |
| 12 #include "cc/graphics_context.h" | 12 #include "cc/graphics_context.h" |
| 13 #include "cc/layer_tree_host_impl.h" | 13 #include "cc/layer_tree_host_impl.h" |
| 14 #include "cc/settings.h" | 14 #include "cc/settings.h" |
| 15 #include "cc/single_thread_proxy.h" | 15 #include "cc/single_thread_proxy.h" |
| 16 #include "cc/test/fake_web_compositor_output_surface.h" | 16 #include "cc/test/fake_web_compositor_output_surface.h" |
| 17 #include "cc/test/geometry_test_utils.h" | 17 #include "cc/test/geometry_test_utils.h" |
| 18 #include "cc/test/layer_tree_test_common.h" | 18 #include "cc/test/layer_tree_test_common.h" |
| 19 #include "cc/test/occlusion_tracker_test_common.h" | 19 #include "cc/test/occlusion_tracker_test_common.h" |
| 20 #include "cc/resource_update_queue.h" | 20 #include "cc/resource_update_queue.h" |
| 21 #include "cc/timing_function.h" | 21 #include "cc/timing_function.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "third_party/khronos/GLES2/gl2.h" | 23 #include "third_party/khronos/GLES2/gl2.h" |
| 24 #include "third_party/khronos/GLES2/gl2ext.h" | 24 #include "third_party/khronos/GLES2/gl2ext.h" |
| 25 #include "ui/gfx/point_conversions.h" | 25 #include "ui/gfx/point_conversions.h" |
| 26 #include "ui/gfx/size_conversions.h" | 26 #include "ui/gfx/size_conversions.h" |
| 27 #include "ui/gfx/vector2d_conversions.h" |
| 27 #include <public/WebLayerScrollClient.h> | 28 #include <public/WebLayerScrollClient.h> |
| 28 #include <public/WebSize.h> | 29 #include <public/WebSize.h> |
| 29 | 30 |
| 30 using namespace cc; | 31 using namespace cc; |
| 31 using namespace WebKit; | 32 using namespace WebKit; |
| 32 using namespace WebKitTests; | 33 using namespace WebKitTests; |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 36 class LayerTreeHostTest : public ThreadedTest { }; | 37 class LayerTreeHostTest : public ThreadedTest { }; |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 } | 828 } |
| 828 | 829 |
| 829 private: | 830 private: |
| 830 }; | 831 }; |
| 831 | 832 |
| 832 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestAnimationFinishedEvents) | 833 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestAnimationFinishedEvents) |
| 833 | 834 |
| 834 class LayerTreeHostTestScrollSimple : public LayerTreeHostTest { | 835 class LayerTreeHostTestScrollSimple : public LayerTreeHostTest { |
| 835 public: | 836 public: |
| 836 LayerTreeHostTestScrollSimple() | 837 LayerTreeHostTestScrollSimple() |
| 837 : m_initialScroll(IntPoint(10, 20)) | 838 : m_initialScroll(10, 20) |
| 838 , m_secondScroll(IntPoint(40, 5)) | 839 , m_secondScroll(40, 5) |
| 839 , m_scrollAmount(2, -1) | 840 , m_scrollAmount(2, -1) |
| 840 , m_scrolls(0) | 841 , m_scrolls(0) |
| 841 { | 842 { |
| 842 } | 843 } |
| 843 | 844 |
| 844 virtual void beginTest() OVERRIDE | 845 virtual void beginTest() OVERRIDE |
| 845 { | 846 { |
| 846 m_layerTreeHost->rootLayer()->setScrollable(true); | 847 m_layerTreeHost->rootLayer()->setScrollable(true); |
| 847 m_layerTreeHost->rootLayer()->setScrollPosition(m_initialScroll); | 848 m_layerTreeHost->rootLayer()->setScrollOffset(m_initialScroll); |
| 848 postSetNeedsCommitToMainThread(); | 849 postSetNeedsCommitToMainThread(); |
| 849 } | 850 } |
| 850 | 851 |
| 851 virtual void layout() OVERRIDE | 852 virtual void layout() OVERRIDE |
| 852 { | 853 { |
| 853 Layer* root = m_layerTreeHost->rootLayer(); | 854 Layer* root = m_layerTreeHost->rootLayer(); |
| 854 if (!m_layerTreeHost->commitNumber()) | 855 if (!m_layerTreeHost->commitNumber()) |
| 855 EXPECT_EQ(root->scrollPosition(), m_initialScroll); | 856 EXPECT_VECTOR_EQ(root->scrollOffset(), m_initialScroll); |
| 856 else { | 857 else { |
| 857 EXPECT_EQ(root->scrollPosition(), m_initialScroll + m_scrollAmount); | 858 EXPECT_VECTOR_EQ(root->scrollOffset(), m_initialScroll + m_scrollAmo
unt); |
| 858 | 859 |
| 859 // Pretend like Javascript updated the scroll position itself. | 860 // Pretend like Javascript updated the scroll position itself. |
| 860 root->setScrollPosition(m_secondScroll); | 861 root->setScrollOffset(m_secondScroll); |
| 861 } | 862 } |
| 862 } | 863 } |
| 863 | 864 |
| 864 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 865 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE |
| 865 { | 866 { |
| 866 LayerImpl* root = impl->rootLayer(); | 867 LayerImpl* root = impl->rootLayer(); |
| 867 EXPECT_EQ(root->scrollDelta(), IntSize()); | 868 EXPECT_VECTOR_EQ(root->scrollDelta(), gfx::Vector2d()); |
| 868 | 869 |
| 869 root->setScrollable(true); | 870 root->setScrollable(true); |
| 870 root->setMaxScrollPosition(IntSize(100, 100)); | 871 root->setMaxScrollOffset(gfx::Vector2d(100, 100)); |
| 871 root->scrollBy(m_scrollAmount); | 872 root->scrollBy(m_scrollAmount); |
| 872 | 873 |
| 873 if (!impl->sourceFrameNumber()) { | 874 if (!impl->sourceFrameNumber()) { |
| 874 EXPECT_EQ(root->scrollPosition(), m_initialScroll); | 875 EXPECT_VECTOR_EQ(root->scrollOffset(), m_initialScroll); |
| 875 EXPECT_EQ(root->scrollDelta(), m_scrollAmount); | 876 EXPECT_VECTOR_EQ(root->scrollDelta(), m_scrollAmount); |
| 876 postSetNeedsCommitToMainThread(); | 877 postSetNeedsCommitToMainThread(); |
| 877 } else if (impl->sourceFrameNumber() == 1) { | 878 } else if (impl->sourceFrameNumber() == 1) { |
| 878 EXPECT_EQ(root->scrollPosition(), m_secondScroll); | 879 EXPECT_VECTOR_EQ(root->scrollOffset(), m_secondScroll); |
| 879 EXPECT_EQ(root->scrollDelta(), m_scrollAmount); | 880 EXPECT_VECTOR_EQ(root->scrollDelta(), m_scrollAmount); |
| 880 endTest(); | 881 endTest(); |
| 881 } | 882 } |
| 882 } | 883 } |
| 883 | 884 |
| 884 virtual void applyScrollAndScale(const IntSize& scrollDelta, float scale) OV
ERRIDE | 885 virtual void applyScrollAndScale(gfx::Vector2d scrollDelta, float scale) OVE
RRIDE |
| 885 { | 886 { |
| 886 IntPoint position = m_layerTreeHost->rootLayer()->scrollPosition(); | 887 gfx::Vector2d offset = m_layerTreeHost->rootLayer()->scrollOffset(); |
| 887 m_layerTreeHost->rootLayer()->setScrollPosition(position + scrollDelta); | 888 m_layerTreeHost->rootLayer()->setScrollOffset(offset + scrollDelta); |
| 888 m_scrolls++; | 889 m_scrolls++; |
| 889 } | 890 } |
| 890 | 891 |
| 891 virtual void afterTest() OVERRIDE | 892 virtual void afterTest() OVERRIDE |
| 892 { | 893 { |
| 893 EXPECT_EQ(1, m_scrolls); | 894 EXPECT_EQ(1, m_scrolls); |
| 894 } | 895 } |
| 895 private: | 896 private: |
| 896 IntPoint m_initialScroll; | 897 gfx::Vector2d m_initialScroll; |
| 897 IntPoint m_secondScroll; | 898 gfx::Vector2d m_secondScroll; |
| 898 IntSize m_scrollAmount; | 899 gfx::Vector2d m_scrollAmount; |
| 899 int m_scrolls; | 900 int m_scrolls; |
| 900 }; | 901 }; |
| 901 | 902 |
| 902 TEST_F(LayerTreeHostTestScrollSimple, runMultiThread) | 903 TEST_F(LayerTreeHostTestScrollSimple, runMultiThread) |
| 903 { | 904 { |
| 904 runTest(true); | 905 runTest(true); |
| 905 } | 906 } |
| 906 | 907 |
| 907 class LayerTreeHostTestScrollMultipleRedraw : public LayerTreeHostTest { | 908 class LayerTreeHostTestScrollMultipleRedraw : public LayerTreeHostTest { |
| 908 public: | 909 public: |
| 909 LayerTreeHostTestScrollMultipleRedraw() | 910 LayerTreeHostTestScrollMultipleRedraw() |
| 910 : m_initialScroll(IntPoint(40, 10)) | 911 : m_initialScroll(40, 10) |
| 911 , m_scrollAmount(-3, 17) | 912 , m_scrollAmount(-3, 17) |
| 912 , m_scrolls(0) | 913 , m_scrolls(0) |
| 913 { | 914 { |
| 914 } | 915 } |
| 915 | 916 |
| 916 virtual void beginTest() OVERRIDE | 917 virtual void beginTest() OVERRIDE |
| 917 { | 918 { |
| 918 m_layerTreeHost->rootLayer()->setScrollable(true); | 919 m_layerTreeHost->rootLayer()->setScrollable(true); |
| 919 m_layerTreeHost->rootLayer()->setScrollPosition(m_initialScroll); | 920 m_layerTreeHost->rootLayer()->setScrollOffset(m_initialScroll); |
| 920 postSetNeedsCommitToMainThread(); | 921 postSetNeedsCommitToMainThread(); |
| 921 } | 922 } |
| 922 | 923 |
| 923 virtual void beginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE | 924 virtual void beginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE |
| 924 { | 925 { |
| 925 Layer* root = m_layerTreeHost->rootLayer(); | 926 Layer* root = m_layerTreeHost->rootLayer(); |
| 926 if (!m_layerTreeHost->commitNumber()) | 927 if (!m_layerTreeHost->commitNumber()) |
| 927 EXPECT_EQ(root->scrollPosition(), m_initialScroll); | 928 EXPECT_VECTOR_EQ(root->scrollOffset(), m_initialScroll); |
| 928 else if (m_layerTreeHost->commitNumber() == 1) | 929 else if (m_layerTreeHost->commitNumber() == 1) |
| 929 EXPECT_EQ(root->scrollPosition(), m_initialScroll + m_scrollAmount +
m_scrollAmount); | 930 EXPECT_VECTOR_EQ(root->scrollOffset(), m_initialScroll + m_scrollAmo
unt + m_scrollAmount); |
| 930 else if (m_layerTreeHost->commitNumber() == 2) | 931 else if (m_layerTreeHost->commitNumber() == 2) |
| 931 EXPECT_EQ(root->scrollPosition(), m_initialScroll + m_scrollAmount +
m_scrollAmount); | 932 EXPECT_VECTOR_EQ(root->scrollOffset(), m_initialScroll + m_scrollAmo
unt + m_scrollAmount); |
| 932 } | 933 } |
| 933 | 934 |
| 934 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 935 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE |
| 935 { | 936 { |
| 936 LayerImpl* root = impl->rootLayer(); | 937 LayerImpl* root = impl->rootLayer(); |
| 937 root->setScrollable(true); | 938 root->setScrollable(true); |
| 938 root->setMaxScrollPosition(IntSize(100, 100)); | 939 root->setMaxScrollOffset(gfx::Vector2d(100, 100)); |
| 939 | 940 |
| 940 if (!impl->sourceFrameNumber() && impl->sourceAnimationFrameNumber() ==
1) { | 941 if (!impl->sourceFrameNumber() && impl->sourceAnimationFrameNumber() ==
1) { |
| 941 // First draw after first commit. | 942 // First draw after first commit. |
| 942 EXPECT_EQ(root->scrollDelta(), IntSize()); | 943 EXPECT_VECTOR_EQ(root->scrollDelta(), gfx::Vector2d()); |
| 943 root->scrollBy(m_scrollAmount); | 944 root->scrollBy(m_scrollAmount); |
| 944 EXPECT_EQ(root->scrollDelta(), m_scrollAmount); | 945 EXPECT_VECTOR_EQ(root->scrollDelta(), m_scrollAmount); |
| 945 | 946 |
| 946 EXPECT_EQ(root->scrollPosition(), m_initialScroll); | 947 EXPECT_VECTOR_EQ(root->scrollOffset(), m_initialScroll); |
| 947 postSetNeedsRedrawToMainThread(); | 948 postSetNeedsRedrawToMainThread(); |
| 948 } else if (!impl->sourceFrameNumber() && impl->sourceAnimationFrameNumbe
r() == 2) { | 949 } else if (!impl->sourceFrameNumber() && impl->sourceAnimationFrameNumbe
r() == 2) { |
| 949 // Second draw after first commit. | 950 // Second draw after first commit. |
| 950 EXPECT_EQ(root->scrollDelta(), m_scrollAmount); | 951 EXPECT_EQ(root->scrollDelta(), m_scrollAmount); |
| 951 root->scrollBy(m_scrollAmount); | 952 root->scrollBy(m_scrollAmount); |
| 952 EXPECT_EQ(root->scrollDelta(), m_scrollAmount + m_scrollAmount); | 953 EXPECT_VECTOR_EQ(root->scrollDelta(), m_scrollAmount + m_scrollAmoun
t); |
| 953 | 954 |
| 954 EXPECT_EQ(root->scrollPosition(), m_initialScroll); | 955 EXPECT_VECTOR_EQ(root->scrollOffset(), m_initialScroll); |
| 955 postSetNeedsCommitToMainThread(); | 956 postSetNeedsCommitToMainThread(); |
| 956 } else if (impl->sourceFrameNumber() == 1) { | 957 } else if (impl->sourceFrameNumber() == 1) { |
| 957 // Third or later draw after second commit. | 958 // Third or later draw after second commit. |
| 958 EXPECT_GE(impl->sourceAnimationFrameNumber(), 3); | 959 EXPECT_GE(impl->sourceAnimationFrameNumber(), 3); |
| 959 EXPECT_EQ(root->scrollDelta(), IntSize()); | 960 EXPECT_VECTOR_EQ(root->scrollDelta(), gfx::Vector2d()); |
| 960 EXPECT_EQ(root->scrollPosition(), m_initialScroll + m_scrollAmount +
m_scrollAmount); | 961 EXPECT_VECTOR_EQ(root->scrollOffset(), m_initialScroll + m_scrollAmo
unt + m_scrollAmount); |
| 961 endTest(); | 962 endTest(); |
| 962 } | 963 } |
| 963 } | 964 } |
| 964 | 965 |
| 965 virtual void applyScrollAndScale(const IntSize& scrollDelta, float scale) OV
ERRIDE | 966 virtual void applyScrollAndScale(gfx::Vector2d scrollDelta, float scale) OVE
RRIDE |
| 966 { | 967 { |
| 967 IntPoint position = m_layerTreeHost->rootLayer()->scrollPosition(); | 968 gfx::Vector2d offset = m_layerTreeHost->rootLayer()->scrollOffset(); |
| 968 m_layerTreeHost->rootLayer()->setScrollPosition(position + scrollDelta); | 969 m_layerTreeHost->rootLayer()->setScrollOffset(offset + scrollDelta); |
| 969 m_scrolls++; | 970 m_scrolls++; |
| 970 } | 971 } |
| 971 | 972 |
| 972 virtual void afterTest() OVERRIDE | 973 virtual void afterTest() OVERRIDE |
| 973 { | 974 { |
| 974 EXPECT_EQ(1, m_scrolls); | 975 EXPECT_EQ(1, m_scrolls); |
| 975 } | 976 } |
| 976 private: | 977 private: |
| 977 IntPoint m_initialScroll; | 978 gfx::Vector2d m_initialScroll; |
| 978 IntSize m_scrollAmount; | 979 gfx::Vector2d m_scrollAmount; |
| 979 int m_scrolls; | 980 int m_scrolls; |
| 980 }; | 981 }; |
| 981 | 982 |
| 982 TEST_F(LayerTreeHostTestScrollMultipleRedraw, runMultiThread) | 983 TEST_F(LayerTreeHostTestScrollMultipleRedraw, runMultiThread) |
| 983 { | 984 { |
| 984 runTest(true); | 985 runTest(true); |
| 985 } | 986 } |
| 986 | 987 |
| 987 // This test verifies that properties on the layer tree host are commited to the
impl side. | 988 // This test verifies that properties on the layer tree host are commited to the
impl side. |
| 988 class LayerTreeHostTestCommit : public LayerTreeHostTest { | 989 class LayerTreeHostTestCommit : public LayerTreeHostTest { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 public: | 1023 public: |
| 1023 | 1024 |
| 1024 LayerTreeHostTestStartPageScaleAnimation() | 1025 LayerTreeHostTestStartPageScaleAnimation() |
| 1025 : m_animationRequested(false) | 1026 : m_animationRequested(false) |
| 1026 { | 1027 { |
| 1027 } | 1028 } |
| 1028 | 1029 |
| 1029 virtual void beginTest() OVERRIDE | 1030 virtual void beginTest() OVERRIDE |
| 1030 { | 1031 { |
| 1031 m_layerTreeHost->rootLayer()->setScrollable(true); | 1032 m_layerTreeHost->rootLayer()->setScrollable(true); |
| 1032 m_layerTreeHost->rootLayer()->setScrollPosition(IntPoint()); | 1033 m_layerTreeHost->rootLayer()->setScrollOffset(gfx::Vector2d()); |
| 1033 postSetNeedsCommitToMainThread(); | 1034 postSetNeedsCommitToMainThread(); |
| 1034 postSetNeedsRedrawToMainThread(); | 1035 postSetNeedsRedrawToMainThread(); |
| 1035 } | 1036 } |
| 1036 | 1037 |
| 1037 void requestStartPageScaleAnimation() | 1038 void requestStartPageScaleAnimation() |
| 1038 { | 1039 { |
| 1039 layerTreeHost()->startPageScaleAnimation(IntSize(), false, 1.25, base::T
imeDelta()); | 1040 layerTreeHost()->startPageScaleAnimation(gfx::Vector2d(), false, 1.25, b
ase::TimeDelta()); |
| 1040 } | 1041 } |
| 1041 | 1042 |
| 1042 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 1043 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE |
| 1043 { | 1044 { |
| 1044 impl->rootLayer()->setScrollable(true); | 1045 impl->rootLayer()->setScrollable(true); |
| 1045 impl->rootLayer()->setScrollPosition(IntPoint()); | 1046 impl->rootLayer()->setScrollOffset(gfx::Vector2d()); |
| 1046 impl->setPageScaleFactorAndLimits(impl->pageScaleFactor(), 0.5, 2); | 1047 impl->setPageScaleFactorAndLimits(impl->pageScaleFactor(), 0.5, 2); |
| 1047 | 1048 |
| 1048 // We request animation only once. | 1049 // We request animation only once. |
| 1049 if (!m_animationRequested) { | 1050 if (!m_animationRequested) { |
| 1050 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&LayerTreeHostTest
StartPageScaleAnimation::requestStartPageScaleAnimation, base::Unretained(this))
); | 1051 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&LayerTreeHostTest
StartPageScaleAnimation::requestStartPageScaleAnimation, base::Unretained(this))
); |
| 1051 m_animationRequested = true; | 1052 m_animationRequested = true; |
| 1052 } | 1053 } |
| 1053 } | 1054 } |
| 1054 | 1055 |
| 1055 virtual void applyScrollAndScale(const IntSize& scrollDelta, float scale) OV
ERRIDE | 1056 virtual void applyScrollAndScale(gfx::Vector2d scrollDelta, float scale) OVE
RRIDE |
| 1056 { | 1057 { |
| 1057 IntPoint position = m_layerTreeHost->rootLayer()->scrollPosition(); | 1058 gfx::Vector2d offset = m_layerTreeHost->rootLayer()->scrollOffset(); |
| 1058 m_layerTreeHost->rootLayer()->setScrollPosition(position + scrollDelta); | 1059 m_layerTreeHost->rootLayer()->setScrollOffset(offset + scrollDelta); |
| 1059 m_layerTreeHost->setPageScaleFactorAndLimits(scale, 0.5, 2); | 1060 m_layerTreeHost->setPageScaleFactorAndLimits(scale, 0.5, 2); |
| 1060 } | 1061 } |
| 1061 | 1062 |
| 1062 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | 1063 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE |
| 1063 { | 1064 { |
| 1064 impl->processScrollDeltas(); | 1065 impl->processScrollDeltas(); |
| 1065 // We get one commit before the first draw, and the animation doesn't ha
ppen until the second draw. | 1066 // We get one commit before the first draw, and the animation doesn't ha
ppen until the second draw. |
| 1066 if (impl->sourceFrameNumber() == 1) { | 1067 if (impl->sourceFrameNumber() == 1) { |
| 1067 EXPECT_EQ(1.25, impl->pageScaleFactor()); | 1068 EXPECT_EQ(1.25, impl->pageScaleFactor()); |
| 1068 endTest(); | 1069 endTest(); |
| (...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2083 | 2084 |
| 2084 virtual void beginTest() OVERRIDE | 2085 virtual void beginTest() OVERRIDE |
| 2085 { | 2086 { |
| 2086 m_layerTreeHost->rootLayer()->setScrollable(true); | 2087 m_layerTreeHost->rootLayer()->setScrollable(true); |
| 2087 postSetNeedsCommitToMainThread(); | 2088 postSetNeedsCommitToMainThread(); |
| 2088 } | 2089 } |
| 2089 | 2090 |
| 2090 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 2091 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE |
| 2091 { | 2092 { |
| 2092 LayerImpl* root = impl->rootLayer(); | 2093 LayerImpl* root = impl->rootLayer(); |
| 2093 root->setMaxScrollPosition(IntSize(100, 100)); | 2094 root->setMaxScrollOffset(gfx::Vector2d(100, 100)); |
| 2094 | 2095 |
| 2095 // Check that a fractional scroll delta is correctly accumulated over mu
ltiple commits. | 2096 // Check that a fractional scroll delta is correctly accumulated over mu
ltiple commits. |
| 2096 if (!impl->sourceFrameNumber()) { | 2097 if (!impl->sourceFrameNumber()) { |
| 2097 EXPECT_EQ(root->scrollPosition(), IntPoint(0, 0)); | 2098 EXPECT_VECTOR_EQ(root->scrollOffset(), gfx::Vector2d(0, 0)); |
| 2098 EXPECT_EQ(root->scrollDelta(), FloatSize(0, 0)); | 2099 EXPECT_VECTOR_EQ(root->scrollDelta(), gfx::Vector2d(0, 0)); |
| 2099 postSetNeedsCommitToMainThread(); | 2100 postSetNeedsCommitToMainThread(); |
| 2100 } else if (impl->sourceFrameNumber() == 1) { | 2101 } else if (impl->sourceFrameNumber() == 1) { |
| 2101 EXPECT_EQ(root->scrollPosition(), flooredIntPoint(m_scrollAmount)); | 2102 EXPECT_VECTOR_EQ(root->scrollOffset(), gfx::ToFlooredVector2d(m_scro
llAmount)); |
| 2102 EXPECT_EQ(root->scrollDelta(), FloatSize(fmod(m_scrollAmount.width()
, 1), 0)); | 2103 EXPECT_VECTOR_EQ(root->scrollDelta(), gfx::Vector2dF(fmod(m_scrollAm
ount.x(), 1), 0)); |
| 2103 postSetNeedsCommitToMainThread(); | 2104 postSetNeedsCommitToMainThread(); |
| 2104 } else if (impl->sourceFrameNumber() == 2) { | 2105 } else if (impl->sourceFrameNumber() == 2) { |
| 2105 EXPECT_EQ(root->scrollPosition(), flooredIntPoint(m_scrollAmount + m
_scrollAmount)); | 2106 EXPECT_VECTOR_EQ(root->scrollOffset(), gfx::ToFlooredVector2d(m_scro
llAmount + m_scrollAmount)); |
| 2106 EXPECT_EQ(root->scrollDelta(), FloatSize(fmod(2 * m_scrollAmount.wid
th(), 1), 0)); | 2107 EXPECT_VECTOR_EQ(root->scrollDelta(), gfx::Vector2dF(fmod(2 * m_scro
llAmount.x(), 1), 0)); |
| 2107 endTest(); | 2108 endTest(); |
| 2108 } | 2109 } |
| 2109 root->scrollBy(m_scrollAmount); | 2110 root->scrollBy(m_scrollAmount); |
| 2110 } | 2111 } |
| 2111 | 2112 |
| 2112 virtual void applyScrollAndScale(const IntSize& scrollDelta, float scale) OV
ERRIDE | 2113 virtual void applyScrollAndScale(gfx::Vector2d scrollDelta, float scale) OVE
RRIDE |
| 2113 { | 2114 { |
| 2114 IntPoint position = m_layerTreeHost->rootLayer()->scrollPosition(); | 2115 gfx::Vector2d offset = m_layerTreeHost->rootLayer()->scrollOffset(); |
| 2115 m_layerTreeHost->rootLayer()->setScrollPosition(position + scrollDelta); | 2116 m_layerTreeHost->rootLayer()->setScrollOffset(offset + scrollDelta); |
| 2116 } | 2117 } |
| 2117 | 2118 |
| 2118 virtual void afterTest() OVERRIDE | 2119 virtual void afterTest() OVERRIDE |
| 2119 { | 2120 { |
| 2120 } | 2121 } |
| 2121 private: | 2122 private: |
| 2122 FloatSize m_scrollAmount; | 2123 gfx::Vector2dF m_scrollAmount; |
| 2123 }; | 2124 }; |
| 2124 | 2125 |
| 2125 TEST_F(LayerTreeHostTestFractionalScroll, runMultiThread) | 2126 TEST_F(LayerTreeHostTestFractionalScroll, runMultiThread) |
| 2126 { | 2127 { |
| 2127 runTest(true); | 2128 runTest(true); |
| 2128 } | 2129 } |
| 2129 | 2130 |
| 2130 class LayerTreeHostTestFinishAllRendering : public LayerTreeHostTest { | 2131 class LayerTreeHostTestFinishAllRendering : public LayerTreeHostTest { |
| 2131 public: | 2132 public: |
| 2132 LayerTreeHostTestFinishAllRendering() | 2133 LayerTreeHostTestFinishAllRendering() |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2216 private: | 2217 private: |
| 2217 bool m_addedAnimation; | 2218 bool m_addedAnimation; |
| 2218 }; | 2219 }; |
| 2219 | 2220 |
| 2220 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLayerAddedWithAnimation) | 2221 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLayerAddedWithAnimation) |
| 2221 | 2222 |
| 2222 class LayerTreeHostTestScrollChildLayer : public LayerTreeHostTest, public WebLa
yerScrollClient { | 2223 class LayerTreeHostTestScrollChildLayer : public LayerTreeHostTest, public WebLa
yerScrollClient { |
| 2223 public: | 2224 public: |
| 2224 LayerTreeHostTestScrollChildLayer(float deviceScaleFactor) | 2225 LayerTreeHostTestScrollChildLayer(float deviceScaleFactor) |
| 2225 : m_deviceScaleFactor(deviceScaleFactor) | 2226 : m_deviceScaleFactor(deviceScaleFactor) |
| 2226 , m_initialScroll(IntPoint(10, 20)) | 2227 , m_initialScroll(10, 20) |
| 2227 , m_secondScroll(IntPoint(40, 5)) | 2228 , m_secondScroll(40, 5) |
| 2228 , m_scrollAmount(2, -1) | 2229 , m_scrollAmount(2, -1) |
| 2229 , m_rootScrolls(0) | 2230 , m_rootScrolls(0) |
| 2230 { | 2231 { |
| 2231 } | 2232 } |
| 2232 | 2233 |
| 2233 virtual void beginTest() OVERRIDE | 2234 virtual void beginTest() OVERRIDE |
| 2234 { | 2235 { |
| 2235 gfx::Size viewportSize(10, 10); | 2236 gfx::Size viewportSize(10, 10); |
| 2236 gfx::Size deviceViewportSize = gfx::ToCeiledSize(viewportSize.Scale(m_de
viceScaleFactor)); | 2237 gfx::Size deviceViewportSize = gfx::ToCeiledSize(viewportSize.Scale(m_de
viceScaleFactor)); |
| 2237 m_layerTreeHost->setViewportSize(viewportSize, deviceViewportSize); | 2238 m_layerTreeHost->setViewportSize(viewportSize, deviceViewportSize); |
| 2238 | 2239 |
| 2239 m_layerTreeHost->setDeviceScaleFactor(m_deviceScaleFactor); | 2240 m_layerTreeHost->setDeviceScaleFactor(m_deviceScaleFactor); |
| 2240 | 2241 |
| 2241 m_rootScrollLayer = ContentLayer::create(&m_mockDelegate); | 2242 m_rootScrollLayer = ContentLayer::create(&m_mockDelegate); |
| 2242 m_rootScrollLayer->setBounds(gfx::Size(110, 110)); | 2243 m_rootScrollLayer->setBounds(gfx::Size(110, 110)); |
| 2243 | 2244 |
| 2244 m_rootScrollLayer->setPosition(gfx::PointF(0, 0)); | 2245 m_rootScrollLayer->setPosition(gfx::PointF(0, 0)); |
| 2245 m_rootScrollLayer->setAnchorPoint(gfx::PointF(0, 0)); | 2246 m_rootScrollLayer->setAnchorPoint(gfx::PointF(0, 0)); |
| 2246 | 2247 |
| 2247 m_rootScrollLayer->setIsDrawable(true); | 2248 m_rootScrollLayer->setIsDrawable(true); |
| 2248 m_rootScrollLayer->setScrollable(true); | 2249 m_rootScrollLayer->setScrollable(true); |
| 2249 m_rootScrollLayer->setMaxScrollPosition(IntSize(100, 100)); | 2250 m_rootScrollLayer->setMaxScrollOffset(gfx::Vector2d(100, 100)); |
| 2250 m_layerTreeHost->rootLayer()->addChild(m_rootScrollLayer); | 2251 m_layerTreeHost->rootLayer()->addChild(m_rootScrollLayer); |
| 2251 | 2252 |
| 2252 m_childLayer = ContentLayer::create(&m_mockDelegate); | 2253 m_childLayer = ContentLayer::create(&m_mockDelegate); |
| 2253 m_childLayer->setLayerScrollClient(this); | 2254 m_childLayer->setLayerScrollClient(this); |
| 2254 m_childLayer->setBounds(gfx::Size(110, 110)); | 2255 m_childLayer->setBounds(gfx::Size(110, 110)); |
| 2255 | 2256 |
| 2256 // The scrolls will happen at 5, 5. If they are treated like device pixe
ls, then | 2257 // The scrolls will happen at 5, 5. If they are treated like device pixe
ls, then |
| 2257 // they will be at 2.5, 2.5 in logical pixels, and will miss this layer. | 2258 // they will be at 2.5, 2.5 in logical pixels, and will miss this layer. |
| 2258 m_childLayer->setPosition(gfx::PointF(5, 5)); | 2259 m_childLayer->setPosition(gfx::PointF(5, 5)); |
| 2259 m_childLayer->setAnchorPoint(gfx::PointF(0, 0)); | 2260 m_childLayer->setAnchorPoint(gfx::PointF(0, 0)); |
| 2260 | 2261 |
| 2261 m_childLayer->setIsDrawable(true); | 2262 m_childLayer->setIsDrawable(true); |
| 2262 m_childLayer->setScrollable(true); | 2263 m_childLayer->setScrollable(true); |
| 2263 m_childLayer->setMaxScrollPosition(IntSize(100, 100)); | 2264 m_childLayer->setMaxScrollOffset(gfx::Vector2d(100, 100)); |
| 2264 m_rootScrollLayer->addChild(m_childLayer); | 2265 m_rootScrollLayer->addChild(m_childLayer); |
| 2265 | 2266 |
| 2266 m_childLayer->setScrollPosition(m_initialScroll); | 2267 m_childLayer->setScrollOffset(m_initialScroll); |
| 2267 | 2268 |
| 2268 postSetNeedsCommitToMainThread(); | 2269 postSetNeedsCommitToMainThread(); |
| 2269 } | 2270 } |
| 2270 | 2271 |
| 2271 virtual void didScroll() OVERRIDE | 2272 virtual void didScroll() OVERRIDE |
| 2272 { | 2273 { |
| 2273 m_finalScrollPosition = m_childLayer->scrollPosition(); | 2274 m_finalScrollOffset = m_childLayer->scrollOffset(); |
| 2274 } | 2275 } |
| 2275 | 2276 |
| 2276 virtual void applyScrollAndScale(const IntSize& scrollDelta, float scale) OV
ERRIDE | 2277 virtual void applyScrollAndScale(gfx::Vector2d scrollDelta, float scale) OVE
RRIDE |
| 2277 { | 2278 { |
| 2278 IntPoint position = m_rootScrollLayer->scrollPosition(); | 2279 gfx::Vector2d offset = m_rootScrollLayer->scrollOffset(); |
| 2279 m_rootScrollLayer->setScrollPosition(position + scrollDelta); | 2280 m_rootScrollLayer->setScrollOffset(offset + scrollDelta); |
| 2280 m_rootScrolls++; | 2281 m_rootScrolls++; |
| 2281 } | 2282 } |
| 2282 | 2283 |
| 2283 virtual void layout() OVERRIDE | 2284 virtual void layout() OVERRIDE |
| 2284 { | 2285 { |
| 2285 EXPECT_EQ(IntPoint(), m_rootScrollLayer->scrollPosition()); | 2286 EXPECT_VECTOR_EQ(gfx::Vector2d(), m_rootScrollLayer->scrollOffset()); |
| 2286 | 2287 |
| 2287 switch (m_layerTreeHost->commitNumber()) { | 2288 switch (m_layerTreeHost->commitNumber()) { |
| 2288 case 0: | 2289 case 0: |
| 2289 EXPECT_POINT_EQ(m_initialScroll, m_childLayer->scrollPosition()); | 2290 EXPECT_VECTOR_EQ(m_initialScroll, m_childLayer->scrollOffset()); |
| 2290 break; | 2291 break; |
| 2291 case 1: | 2292 case 1: |
| 2292 EXPECT_POINT_EQ(m_initialScroll + m_scrollAmount, m_childLayer->scro
llPosition()); | 2293 EXPECT_VECTOR_EQ(m_initialScroll + m_scrollAmount, m_childLayer->scr
ollOffset()); |
| 2293 | 2294 |
| 2294 // Pretend like Javascript updated the scroll position itself. | 2295 // Pretend like Javascript updated the scroll position itself. |
| 2295 m_childLayer->setScrollPosition(m_secondScroll); | 2296 m_childLayer->setScrollOffset(m_secondScroll); |
| 2296 break; | 2297 break; |
| 2297 case 2: | 2298 case 2: |
| 2298 EXPECT_POINT_EQ(m_secondScroll + m_scrollAmount, m_childLayer->scrol
lPosition()); | 2299 EXPECT_VECTOR_EQ(m_secondScroll + m_scrollAmount, m_childLayer->scro
llOffset()); |
| 2299 break; | 2300 break; |
| 2300 } | 2301 } |
| 2301 } | 2302 } |
| 2302 | 2303 |
| 2303 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | 2304 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE |
| 2304 { | 2305 { |
| 2305 LayerImpl* root = impl->rootLayer(); | 2306 LayerImpl* root = impl->rootLayer(); |
| 2306 LayerImpl* rootScrollLayer = root->children()[0]; | 2307 LayerImpl* rootScrollLayer = root->children()[0]; |
| 2307 LayerImpl* childLayer = rootScrollLayer->children()[0]; | 2308 LayerImpl* childLayer = rootScrollLayer->children()[0]; |
| 2308 | 2309 |
| 2309 EXPECT_SIZE_EQ(root->scrollDelta(), IntSize()); | 2310 EXPECT_VECTOR_EQ(root->scrollDelta(), gfx::Vector2d()); |
| 2310 EXPECT_SIZE_EQ(rootScrollLayer->scrollDelta(), IntSize()); | 2311 EXPECT_VECTOR_EQ(rootScrollLayer->scrollDelta(), gfx::Vector2d()); |
| 2311 EXPECT_EQ(rootScrollLayer->bounds().width() * m_deviceScaleFactor, rootS
crollLayer->contentBounds().width()); | 2312 EXPECT_EQ(rootScrollLayer->bounds().width() * m_deviceScaleFactor, rootS
crollLayer->contentBounds().width()); |
| 2312 EXPECT_EQ(rootScrollLayer->bounds().height() * m_deviceScaleFactor, root
ScrollLayer->contentBounds().height()); | 2313 EXPECT_EQ(rootScrollLayer->bounds().height() * m_deviceScaleFactor, root
ScrollLayer->contentBounds().height()); |
| 2313 EXPECT_EQ(childLayer->bounds().width() * m_deviceScaleFactor, childLayer
->contentBounds().width()); | 2314 EXPECT_EQ(childLayer->bounds().width() * m_deviceScaleFactor, childLayer
->contentBounds().width()); |
| 2314 EXPECT_EQ(childLayer->bounds().height() * m_deviceScaleFactor, childLaye
r->contentBounds().height()); | 2315 EXPECT_EQ(childLayer->bounds().height() * m_deviceScaleFactor, childLaye
r->contentBounds().height()); |
| 2315 | 2316 |
| 2316 switch (impl->sourceFrameNumber()) { | 2317 switch (impl->sourceFrameNumber()) { |
| 2317 case 0: | 2318 case 0: |
| 2318 // Gesture scroll on impl thread. | 2319 // Gesture scroll on impl thread. |
| 2319 EXPECT_EQ(impl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Ge
sture), InputHandlerClient::ScrollStarted); | 2320 EXPECT_EQ(impl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Ge
sture), InputHandlerClient::ScrollStarted); |
| 2320 impl->scrollBy(gfx::Point(), m_scrollAmount); | 2321 impl->scrollBy(gfx::Point(), m_scrollAmount); |
| 2321 impl->scrollEnd(); | 2322 impl->scrollEnd(); |
| 2322 | 2323 |
| 2323 EXPECT_POINT_EQ(m_initialScroll, childLayer->scrollPosition()); | 2324 EXPECT_VECTOR_EQ(m_initialScroll, childLayer->scrollOffset()); |
| 2324 EXPECT_SIZE_EQ(m_scrollAmount, childLayer->scrollDelta()); | 2325 EXPECT_VECTOR_EQ(m_scrollAmount, childLayer->scrollDelta()); |
| 2325 break; | 2326 break; |
| 2326 case 1: | 2327 case 1: |
| 2327 // Wheel scroll on impl thread. | 2328 // Wheel scroll on impl thread. |
| 2328 EXPECT_EQ(impl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollStarted); | 2329 EXPECT_EQ(impl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollStarted); |
| 2329 impl->scrollBy(gfx::Point(), m_scrollAmount); | 2330 impl->scrollBy(gfx::Point(), m_scrollAmount); |
| 2330 impl->scrollEnd(); | 2331 impl->scrollEnd(); |
| 2331 | 2332 |
| 2332 EXPECT_POINT_EQ(m_secondScroll, childLayer->scrollPosition()); | 2333 EXPECT_VECTOR_EQ(m_secondScroll, childLayer->scrollOffset()); |
| 2333 EXPECT_SIZE_EQ(m_scrollAmount, childLayer->scrollDelta()); | 2334 EXPECT_VECTOR_EQ(m_scrollAmount, childLayer->scrollDelta()); |
| 2334 break; | 2335 break; |
| 2335 case 2: | 2336 case 2: |
| 2336 EXPECT_POINT_EQ(m_secondScroll + m_scrollAmount, childLayer->scrollP
osition()); | 2337 EXPECT_VECTOR_EQ(m_secondScroll + m_scrollAmount, childLayer->scroll
Offset()); |
| 2337 EXPECT_SIZE_EQ(IntSize(0, 0), childLayer->scrollDelta()); | 2338 EXPECT_VECTOR_EQ(gfx::Vector2d(0, 0), childLayer->scrollDelta()); |
| 2338 | 2339 |
| 2339 endTest(); | 2340 endTest(); |
| 2340 } | 2341 } |
| 2341 } | 2342 } |
| 2342 | 2343 |
| 2343 virtual void afterTest() OVERRIDE | 2344 virtual void afterTest() OVERRIDE |
| 2344 { | 2345 { |
| 2345 EXPECT_EQ(0, m_rootScrolls); | 2346 EXPECT_EQ(0, m_rootScrolls); |
| 2346 EXPECT_POINT_EQ(m_secondScroll + m_scrollAmount, m_finalScrollPosition); | 2347 EXPECT_VECTOR_EQ(m_secondScroll + m_scrollAmount, m_finalScrollOffset); |
| 2347 } | 2348 } |
| 2348 | 2349 |
| 2349 private: | 2350 private: |
| 2350 float m_deviceScaleFactor; | 2351 float m_deviceScaleFactor; |
| 2351 IntPoint m_initialScroll; | 2352 gfx::Vector2d m_initialScroll; |
| 2352 IntPoint m_secondScroll; | 2353 gfx::Vector2d m_secondScroll; |
| 2353 IntSize m_scrollAmount; | 2354 gfx::Vector2d m_scrollAmount; |
| 2354 int m_rootScrolls; | 2355 int m_rootScrolls; |
| 2355 IntPoint m_finalScrollPosition; | 2356 gfx::Vector2d m_finalScrollOffset; |
| 2356 | 2357 |
| 2357 MockContentLayerClient m_mockDelegate; | 2358 MockContentLayerClient m_mockDelegate; |
| 2358 scoped_refptr<Layer> m_rootScrollLayer; | 2359 scoped_refptr<Layer> m_rootScrollLayer; |
| 2359 scoped_refptr<Layer> m_childLayer; | 2360 scoped_refptr<Layer> m_childLayer; |
| 2360 }; | 2361 }; |
| 2361 | 2362 |
| 2362 class LayerTreeHostTestScrollChildLayerNormalDpi : public LayerTreeHostTestScrol
lChildLayer { | 2363 class LayerTreeHostTestScrollChildLayerNormalDpi : public LayerTreeHostTestScrol
lChildLayer { |
| 2363 public: | 2364 public: |
| 2364 LayerTreeHostTestScrollChildLayerNormalDpi() : LayerTreeHostTestScrollChildL
ayer(1) { } | 2365 LayerTreeHostTestScrollChildLayerNormalDpi() : LayerTreeHostTestScrollChildL
ayer(1) { } |
| 2365 }; | 2366 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2376 | 2377 |
| 2377 TEST_F(LayerTreeHostTestScrollChildLayerHighDpi, runMultiThread) | 2378 TEST_F(LayerTreeHostTestScrollChildLayerHighDpi, runMultiThread) |
| 2378 { | 2379 { |
| 2379 runTest(true); | 2380 runTest(true); |
| 2380 } | 2381 } |
| 2381 | 2382 |
| 2382 class LayerTreeHostTestScrollRootScrollLayer : public LayerTreeHostTest { | 2383 class LayerTreeHostTestScrollRootScrollLayer : public LayerTreeHostTest { |
| 2383 public: | 2384 public: |
| 2384 LayerTreeHostTestScrollRootScrollLayer(float deviceScaleFactor) | 2385 LayerTreeHostTestScrollRootScrollLayer(float deviceScaleFactor) |
| 2385 : m_deviceScaleFactor(deviceScaleFactor) | 2386 : m_deviceScaleFactor(deviceScaleFactor) |
| 2386 , m_initialScroll(IntPoint(10, 20)) | 2387 , m_initialScroll(10, 20) |
| 2387 , m_secondScroll(IntPoint(40, 5)) | 2388 , m_secondScroll(40, 5) |
| 2388 , m_scrollAmount(2, -1) | 2389 , m_scrollAmount(2, -1) |
| 2389 , m_rootScrolls(0) | 2390 , m_rootScrolls(0) |
| 2390 { | 2391 { |
| 2391 } | 2392 } |
| 2392 | 2393 |
| 2393 virtual void beginTest() OVERRIDE | 2394 virtual void beginTest() OVERRIDE |
| 2394 { | 2395 { |
| 2395 gfx::Size viewportSize(10, 10); | 2396 gfx::Size viewportSize(10, 10); |
| 2396 gfx::Size deviceViewportSize = gfx::ToCeiledSize(viewportSize.Scale(m_de
viceScaleFactor)); | 2397 gfx::Size deviceViewportSize = gfx::ToCeiledSize(viewportSize.Scale(m_de
viceScaleFactor)); |
| 2397 m_layerTreeHost->setViewportSize(viewportSize, deviceViewportSize); | 2398 m_layerTreeHost->setViewportSize(viewportSize, deviceViewportSize); |
| 2398 | 2399 |
| 2399 m_layerTreeHost->setDeviceScaleFactor(m_deviceScaleFactor); | 2400 m_layerTreeHost->setDeviceScaleFactor(m_deviceScaleFactor); |
| 2400 | 2401 |
| 2401 m_rootScrollLayer = ContentLayer::create(&m_mockDelegate); | 2402 m_rootScrollLayer = ContentLayer::create(&m_mockDelegate); |
| 2402 m_rootScrollLayer->setBounds(IntSize(110, 110)); | 2403 m_rootScrollLayer->setBounds(gfx::Size(110, 110)); |
| 2403 | 2404 |
| 2404 m_rootScrollLayer->setPosition(gfx::PointF(0, 0)); | 2405 m_rootScrollLayer->setPosition(gfx::PointF(0, 0)); |
| 2405 m_rootScrollLayer->setAnchorPoint(gfx::PointF(0, 0)); | 2406 m_rootScrollLayer->setAnchorPoint(gfx::PointF(0, 0)); |
| 2406 | 2407 |
| 2407 m_rootScrollLayer->setIsDrawable(true); | 2408 m_rootScrollLayer->setIsDrawable(true); |
| 2408 m_rootScrollLayer->setScrollable(true); | 2409 m_rootScrollLayer->setScrollable(true); |
| 2409 m_rootScrollLayer->setMaxScrollPosition(IntSize(100, 100)); | 2410 m_rootScrollLayer->setMaxScrollOffset(gfx::Vector2d(100, 100)); |
| 2410 m_layerTreeHost->rootLayer()->addChild(m_rootScrollLayer); | 2411 m_layerTreeHost->rootLayer()->addChild(m_rootScrollLayer); |
| 2411 | 2412 |
| 2412 m_rootScrollLayer->setScrollPosition(m_initialScroll); | 2413 m_rootScrollLayer->setScrollOffset(m_initialScroll); |
| 2413 | 2414 |
| 2414 postSetNeedsCommitToMainThread(); | 2415 postSetNeedsCommitToMainThread(); |
| 2415 } | 2416 } |
| 2416 | 2417 |
| 2417 virtual void applyScrollAndScale(const IntSize& scrollDelta, float scale) OV
ERRIDE | 2418 virtual void applyScrollAndScale(gfx::Vector2d scrollDelta, float scale) OVE
RRIDE |
| 2418 { | 2419 { |
| 2419 IntPoint position = m_rootScrollLayer->scrollPosition(); | 2420 gfx::Vector2d offset = m_rootScrollLayer->scrollOffset(); |
| 2420 m_rootScrollLayer->setScrollPosition(position + scrollDelta); | 2421 m_rootScrollLayer->setScrollOffset(offset + scrollDelta); |
| 2421 m_rootScrolls++; | 2422 m_rootScrolls++; |
| 2422 } | 2423 } |
| 2423 | 2424 |
| 2424 virtual void layout() OVERRIDE | 2425 virtual void layout() OVERRIDE |
| 2425 { | 2426 { |
| 2426 switch (m_layerTreeHost->commitNumber()) { | 2427 switch (m_layerTreeHost->commitNumber()) { |
| 2427 case 0: | 2428 case 0: |
| 2428 EXPECT_POINT_EQ(m_initialScroll, m_rootScrollLayer->scrollPosition()
); | 2429 EXPECT_VECTOR_EQ(m_initialScroll, m_rootScrollLayer->scrollOffset())
; |
| 2429 break; | 2430 break; |
| 2430 case 1: | 2431 case 1: |
| 2431 EXPECT_POINT_EQ(m_initialScroll + m_scrollAmount, m_rootScrollLayer-
>scrollPosition()); | 2432 EXPECT_VECTOR_EQ(m_initialScroll + m_scrollAmount, m_rootScrollLayer
->scrollOffset()); |
| 2432 | 2433 |
| 2433 // Pretend like Javascript updated the scroll position itself. | 2434 // Pretend like Javascript updated the scroll position itself. |
| 2434 m_rootScrollLayer->setScrollPosition(m_secondScroll); | 2435 m_rootScrollLayer->setScrollOffset(m_secondScroll); |
| 2435 break; | 2436 break; |
| 2436 case 2: | 2437 case 2: |
| 2437 EXPECT_POINT_EQ(m_secondScroll + m_scrollAmount, m_rootScrollLayer->
scrollPosition()); | 2438 EXPECT_VECTOR_EQ(m_secondScroll + m_scrollAmount, m_rootScrollLayer-
>scrollOffset()); |
| 2438 break; | 2439 break; |
| 2439 } | 2440 } |
| 2440 } | 2441 } |
| 2441 | 2442 |
| 2442 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | 2443 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE |
| 2443 { | 2444 { |
| 2444 LayerImpl* root = impl->rootLayer(); | 2445 LayerImpl* root = impl->rootLayer(); |
| 2445 LayerImpl* rootScrollLayer = root->children()[0]; | 2446 LayerImpl* rootScrollLayer = root->children()[0]; |
| 2446 | 2447 |
| 2447 EXPECT_SIZE_EQ(root->scrollDelta(), IntSize()); | 2448 EXPECT_VECTOR_EQ(root->scrollDelta(), gfx::Vector2d()); |
| 2448 EXPECT_EQ(rootScrollLayer->bounds().width() * m_deviceScaleFactor, rootS
crollLayer->contentBounds().width()); | 2449 EXPECT_EQ(rootScrollLayer->bounds().width() * m_deviceScaleFactor, rootS
crollLayer->contentBounds().width()); |
| 2449 EXPECT_EQ(rootScrollLayer->bounds().height() * m_deviceScaleFactor, root
ScrollLayer->contentBounds().height()); | 2450 EXPECT_EQ(rootScrollLayer->bounds().height() * m_deviceScaleFactor, root
ScrollLayer->contentBounds().height()); |
| 2450 | 2451 |
| 2451 switch (impl->sourceFrameNumber()) { | 2452 switch (impl->sourceFrameNumber()) { |
| 2452 case 0: | 2453 case 0: |
| 2453 // Gesture scroll on impl thread. | 2454 // Gesture scroll on impl thread. |
| 2454 EXPECT_EQ(impl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Ge
sture), InputHandlerClient::ScrollStarted); | 2455 EXPECT_EQ(impl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Ge
sture), InputHandlerClient::ScrollStarted); |
| 2455 impl->scrollBy(gfx::Point(), m_scrollAmount); | 2456 impl->scrollBy(gfx::Point(), m_scrollAmount); |
| 2456 impl->scrollEnd(); | 2457 impl->scrollEnd(); |
| 2457 | 2458 |
| 2458 EXPECT_POINT_EQ(m_initialScroll, rootScrollLayer->scrollPosition()); | 2459 EXPECT_VECTOR_EQ(m_initialScroll, rootScrollLayer->scrollOffset()); |
| 2459 EXPECT_SIZE_EQ(m_scrollAmount, rootScrollLayer->scrollDelta()); | 2460 EXPECT_VECTOR_EQ(m_scrollAmount, rootScrollLayer->scrollDelta()); |
| 2460 break; | 2461 break; |
| 2461 case 1: | 2462 case 1: |
| 2462 // Wheel scroll on impl thread. | 2463 // Wheel scroll on impl thread. |
| 2463 EXPECT_EQ(impl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollStarted); | 2464 EXPECT_EQ(impl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollStarted); |
| 2464 impl->scrollBy(gfx::Point(), m_scrollAmount); | 2465 impl->scrollBy(gfx::Point(), m_scrollAmount); |
| 2465 impl->scrollEnd(); | 2466 impl->scrollEnd(); |
| 2466 | 2467 |
| 2467 EXPECT_POINT_EQ(m_secondScroll, rootScrollLayer->scrollPosition()); | 2468 EXPECT_VECTOR_EQ(m_secondScroll, rootScrollLayer->scrollOffset()); |
| 2468 EXPECT_SIZE_EQ(m_scrollAmount, rootScrollLayer->scrollDelta()); | 2469 EXPECT_VECTOR_EQ(m_scrollAmount, rootScrollLayer->scrollDelta()); |
| 2469 break; | 2470 break; |
| 2470 case 2: | 2471 case 2: |
| 2471 EXPECT_POINT_EQ(m_secondScroll + m_scrollAmount, rootScrollLayer->sc
rollPosition()); | 2472 EXPECT_VECTOR_EQ(m_secondScroll + m_scrollAmount, rootScrollLayer->s
crollOffset()); |
| 2472 EXPECT_SIZE_EQ(IntSize(0, 0), rootScrollLayer->scrollDelta()); | 2473 EXPECT_VECTOR_EQ(gfx::Vector2d(0, 0), rootScrollLayer->scrollDelta()
); |
| 2473 | 2474 |
| 2474 endTest(); | 2475 endTest(); |
| 2475 } | 2476 } |
| 2476 } | 2477 } |
| 2477 | 2478 |
| 2478 virtual void afterTest() OVERRIDE | 2479 virtual void afterTest() OVERRIDE |
| 2479 { | 2480 { |
| 2480 EXPECT_EQ(2, m_rootScrolls); | 2481 EXPECT_EQ(2, m_rootScrolls); |
| 2481 } | 2482 } |
| 2482 | 2483 |
| 2483 private: | 2484 private: |
| 2484 float m_deviceScaleFactor; | 2485 float m_deviceScaleFactor; |
| 2485 IntPoint m_initialScroll; | 2486 gfx::Vector2d m_initialScroll; |
| 2486 IntPoint m_secondScroll; | 2487 gfx::Vector2d m_secondScroll; |
| 2487 IntSize m_scrollAmount; | 2488 gfx::Vector2d m_scrollAmount; |
| 2488 int m_rootScrolls; | 2489 int m_rootScrolls; |
| 2489 | 2490 |
| 2490 MockContentLayerClient m_mockDelegate; | 2491 MockContentLayerClient m_mockDelegate; |
| 2491 scoped_refptr<Layer> m_rootScrollLayer; | 2492 scoped_refptr<Layer> m_rootScrollLayer; |
| 2492 }; | 2493 }; |
| 2493 | 2494 |
| 2494 class LayerTreeHostTestScrollRootScrollLayerNormalDpi : public LayerTreeHostTest
ScrollRootScrollLayer { | 2495 class LayerTreeHostTestScrollRootScrollLayerNormalDpi : public LayerTreeHostTest
ScrollRootScrollLayer { |
| 2495 public: | 2496 public: |
| 2496 LayerTreeHostTestScrollRootScrollLayerNormalDpi() : LayerTreeHostTestScrollR
ootScrollLayer(1) { } | 2497 LayerTreeHostTestScrollRootScrollLayerNormalDpi() : LayerTreeHostTestScrollR
ootScrollLayer(1) { } |
| 2497 }; | 2498 }; |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3264 int m_numCommitsDeferred; | 3265 int m_numCommitsDeferred; |
| 3265 int m_numCompleteCommits; | 3266 int m_numCompleteCommits; |
| 3266 }; | 3267 }; |
| 3267 | 3268 |
| 3268 TEST_F(LayerTreeHostTestDeferCommits, runMultiThread) | 3269 TEST_F(LayerTreeHostTestDeferCommits, runMultiThread) |
| 3269 { | 3270 { |
| 3270 runTest(true); | 3271 runTest(true); |
| 3271 } | 3272 } |
| 3272 | 3273 |
| 3273 } // namespace | 3274 } // namespace |
| OLD | NEW |