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/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 root->draw_properties().visible_content_rect = gfx::Rect(0, 0, 10, 10); | 189 root->draw_properties().visible_content_rect = gfx::Rect(0, 0, 10, 10); |
190 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 190 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
191 } | 191 } |
192 | 192 |
193 static void ExpectClearedScrollDeltasRecursive(LayerImpl* layer) { | 193 static void ExpectClearedScrollDeltasRecursive(LayerImpl* layer) { |
194 ASSERT_EQ(layer->ScrollDelta(), gfx::Vector2d()); | 194 ASSERT_EQ(layer->ScrollDelta(), gfx::Vector2d()); |
195 for (size_t i = 0; i < layer->children().size(); ++i) | 195 for (size_t i = 0; i < layer->children().size(); ++i) |
196 ExpectClearedScrollDeltasRecursive(layer->children()[i]); | 196 ExpectClearedScrollDeltasRecursive(layer->children()[i]); |
197 } | 197 } |
198 | 198 |
199 static void ExpectContains(const ScrollAndScaleSet& scroll_info, | 199 // Some tests, e.g. ScrollAxisAlignedRotatedLayer generates float number |
200 int id, | 200 // which is supposed to be 0 but actually a very small value e.g. 6.12323e-16, |
201 const gfx::Vector2d& scroll_delta) { | 201 // that is exceeding our float equality test epsilon. In this case, we roll |
202 // our own version of float equality test. | |
203 static void ExpectContainsFloat(const ScrollAndScaleSet& scroll_info, | |
204 int id, | |
205 const gfx::Vector2dF& scroll_delta) { | |
202 int times_encountered = 0; | 206 int times_encountered = 0; |
203 | 207 |
204 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { | 208 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { |
205 if (scroll_info.scrolls[i].layer_id != id) | 209 if (scroll_info.scrolls[i].layer_id != id) |
206 continue; | 210 continue; |
207 EXPECT_VECTOR_EQ(scroll_delta, scroll_info.scrolls[i].scroll_delta); | 211 float diff_x = scroll_delta.x() - scroll_info.scrolls[i].scroll_delta.x(); |
212 float diff_y = scroll_delta.y() - scroll_info.scrolls[i].scroll_delta.y(); | |
213 EXPECT_TRUE(std::abs(diff_x) < 0.1e-10); | |
danakj
2014/09/18 21:23:49
You can use EXPECT_FLOAT_EQ for this probably. Or
Yufeng Shen (Slow to review)
2014/09/18 22:47:55
Done.
| |
214 EXPECT_TRUE(std::abs(diff_y) < 0.1e-10); | |
208 times_encountered++; | 215 times_encountered++; |
209 } | 216 } |
210 | 217 |
218 ASSERT_EQ(1, times_encountered); | |
219 } | |
220 | |
221 static void ExpectContains(const ScrollAndScaleSet& scroll_info, | |
222 int id, | |
223 const gfx::Vector2dF& scroll_delta) { | |
224 int times_encountered = 0; | |
225 | |
226 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { | |
227 if (scroll_info.scrolls[i].layer_id != id) | |
228 continue; | |
229 EXPECT_VECTOR2DF_EQ(scroll_delta, scroll_info.scrolls[i].scroll_delta); | |
danakj
2014/09/18 21:23:49
EXPECT_EQ?
Yufeng Shen (Slow to review)
2014/09/18 22:47:55
Done.
| |
230 times_encountered++; | |
231 } | |
232 | |
211 ASSERT_EQ(1, times_encountered); | 233 ASSERT_EQ(1, times_encountered); |
212 } | 234 } |
213 | 235 |
214 static void ExpectNone(const ScrollAndScaleSet& scroll_info, int id) { | 236 static void ExpectNone(const ScrollAndScaleSet& scroll_info, int id) { |
215 int times_encountered = 0; | 237 int times_encountered = 0; |
216 | 238 |
217 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { | 239 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { |
218 if (scroll_info.scrolls[i].layer_id != id) | 240 if (scroll_info.scrolls[i].layer_id != id) |
219 continue; | 241 continue; |
220 times_encountered++; | 242 times_encountered++; |
(...skipping 2727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2948 // Rotate the root layer 90 degrees counter-clockwise about its center. | 2970 // Rotate the root layer 90 degrees counter-clockwise about its center. |
2949 gfx::Transform rotate_transform; | 2971 gfx::Transform rotate_transform; |
2950 rotate_transform.Rotate(-90.0); | 2972 rotate_transform.Rotate(-90.0); |
2951 host_impl_->active_tree()->root_layer()->SetTransform(rotate_transform); | 2973 host_impl_->active_tree()->root_layer()->SetTransform(rotate_transform); |
2952 | 2974 |
2953 gfx::Size surface_size(50, 50); | 2975 gfx::Size surface_size(50, 50); |
2954 host_impl_->SetViewportSize(surface_size); | 2976 host_impl_->SetViewportSize(surface_size); |
2955 DrawFrame(); | 2977 DrawFrame(); |
2956 | 2978 |
2957 // Scroll to the right in screen coordinates with a gesture. | 2979 // Scroll to the right in screen coordinates with a gesture. |
2958 gfx::Vector2d gesture_scroll_delta(10, 0); | 2980 gfx::Vector2dF gesture_scroll_delta(10.0f, 0.0f); |
2959 EXPECT_EQ(InputHandler::ScrollStarted, | 2981 EXPECT_EQ(InputHandler::ScrollStarted, |
2960 host_impl_->ScrollBegin(gfx::Point(), | 2982 host_impl_->ScrollBegin(gfx::Point(), |
2961 InputHandler::Gesture)); | 2983 InputHandler::Gesture)); |
2962 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); | 2984 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); |
2963 host_impl_->ScrollEnd(); | 2985 host_impl_->ScrollEnd(); |
2964 | 2986 |
2965 // The layer should have scrolled down in its local coordinates. | 2987 // The layer should have scrolled down in its local coordinates. |
2966 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | 2988 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
2967 ExpectContains(*scroll_info.get(), | 2989 ExpectContainsFloat(*scroll_info.get(), |
2968 scroll_layer->id(), | 2990 scroll_layer->id(), |
2969 gfx::Vector2d(0, gesture_scroll_delta.x())); | 2991 gfx::Vector2dF(0.0f, gesture_scroll_delta.x())); |
2970 | 2992 |
2971 // Reset and scroll down with the wheel. | 2993 // Reset and scroll down with the wheel. |
2972 scroll_layer->SetScrollDelta(gfx::Vector2dF()); | 2994 scroll_layer->SetScrollDelta(gfx::Vector2dF()); |
2973 gfx::Vector2d wheel_scroll_delta(0, 10); | 2995 gfx::Vector2dF wheel_scroll_delta(0.0f, 10.0f); |
2974 EXPECT_EQ(InputHandler::ScrollStarted, | 2996 EXPECT_EQ(InputHandler::ScrollStarted, |
2975 host_impl_->ScrollBegin(gfx::Point(), | 2997 host_impl_->ScrollBegin(gfx::Point(), |
2976 InputHandler::Wheel)); | 2998 InputHandler::Wheel)); |
2977 host_impl_->ScrollBy(gfx::Point(), wheel_scroll_delta); | 2999 host_impl_->ScrollBy(gfx::Point(), wheel_scroll_delta); |
2978 host_impl_->ScrollEnd(); | 3000 host_impl_->ScrollEnd(); |
2979 | 3001 |
2980 // The layer should have scrolled down in its local coordinates. | 3002 // The layer should have scrolled down in its local coordinates. |
2981 scroll_info = host_impl_->ProcessScrollDeltas(); | 3003 scroll_info = host_impl_->ProcessScrollDeltas(); |
2982 ExpectContains(*scroll_info.get(), | 3004 ExpectContains(*scroll_info.get(), |
2983 scroll_layer->id(), | 3005 scroll_layer->id(), |
(...skipping 27 matching lines...) Expand all Loading... | |
3011 clip_layer->bounds().width() * 0.5f, clip_layer->bounds().height(), 0.f)); | 3033 clip_layer->bounds().width() * 0.5f, clip_layer->bounds().height(), 0.f)); |
3012 LayerImpl* child_ptr = child.get(); | 3034 LayerImpl* child_ptr = child.get(); |
3013 clip_layer->AddChild(child.Pass()); | 3035 clip_layer->AddChild(child.Pass()); |
3014 scroll_layer->AddChild(clip_layer.Pass()); | 3036 scroll_layer->AddChild(clip_layer.Pass()); |
3015 | 3037 |
3016 gfx::Size surface_size(50, 50); | 3038 gfx::Size surface_size(50, 50); |
3017 host_impl_->SetViewportSize(surface_size); | 3039 host_impl_->SetViewportSize(surface_size); |
3018 DrawFrame(); | 3040 DrawFrame(); |
3019 { | 3041 { |
3020 // Scroll down in screen coordinates with a gesture. | 3042 // Scroll down in screen coordinates with a gesture. |
3021 gfx::Vector2d gesture_scroll_delta(0, 10); | 3043 gfx::Vector2dF gesture_scroll_delta(0.0f, 10.0f); |
3022 EXPECT_EQ(InputHandler::ScrollStarted, | 3044 EXPECT_EQ(InputHandler::ScrollStarted, |
3023 host_impl_->ScrollBegin(gfx::Point(1, 1), | 3045 host_impl_->ScrollBegin(gfx::Point(1, 1), |
3024 InputHandler::Gesture)); | 3046 InputHandler::Gesture)); |
3025 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); | 3047 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); |
3026 host_impl_->ScrollEnd(); | 3048 host_impl_->ScrollEnd(); |
3027 | 3049 |
3028 // The child layer should have scrolled down in its local coordinates an | 3050 // The child layer should have scrolled down in its local coordinates an |
3029 // amount proportional to the angle between it and the input scroll delta. | 3051 // amount proportional to the angle between it and the input scroll delta. |
3030 gfx::Vector2d expected_scroll_delta( | 3052 gfx::Vector2dF expected_scroll_delta( |
3031 0, | 3053 0.0f, |
3032 gesture_scroll_delta.y() * | 3054 gesture_scroll_delta.y() * |
3033 std::cos(MathUtil::Deg2Rad(child_layer_angle))); | 3055 std::cos(MathUtil::Deg2Rad(child_layer_angle))); |
3034 scoped_ptr<ScrollAndScaleSet> scroll_info = | 3056 scoped_ptr<ScrollAndScaleSet> scroll_info = |
3035 host_impl_->ProcessScrollDeltas(); | 3057 host_impl_->ProcessScrollDeltas(); |
3036 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); | 3058 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); |
3037 | 3059 |
3038 // The root scroll layer should not have scrolled, because the input delta | 3060 // The root scroll layer should not have scrolled, because the input delta |
3039 // was close to the layer's axis of movement. | 3061 // was close to the layer's axis of movement. |
3040 EXPECT_EQ(scroll_info->scrolls.size(), 1u); | 3062 EXPECT_EQ(scroll_info->scrolls.size(), 1u); |
3041 } | 3063 } |
3042 { | 3064 { |
3043 // Now reset and scroll the same amount horizontally. | 3065 // Now reset and scroll the same amount horizontally. |
3044 child_ptr->SetScrollDelta(gfx::Vector2dF()); | 3066 child_ptr->SetScrollDelta(gfx::Vector2dF()); |
3045 gfx::Vector2d gesture_scroll_delta(10, 0); | 3067 gfx::Vector2dF gesture_scroll_delta(10.0f, 0.0f); |
3046 EXPECT_EQ(InputHandler::ScrollStarted, | 3068 EXPECT_EQ(InputHandler::ScrollStarted, |
3047 host_impl_->ScrollBegin(gfx::Point(1, 1), | 3069 host_impl_->ScrollBegin(gfx::Point(1, 1), |
3048 InputHandler::Gesture)); | 3070 InputHandler::Gesture)); |
3049 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); | 3071 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); |
3050 host_impl_->ScrollEnd(); | 3072 host_impl_->ScrollEnd(); |
3051 | 3073 |
3052 // The child layer should have scrolled down in its local coordinates an | 3074 // The child layer should have scrolled down in its local coordinates an |
3053 // amount proportional to the angle between it and the input scroll delta. | 3075 // amount proportional to the angle between it and the input scroll delta. |
3054 gfx::Vector2d expected_scroll_delta( | 3076 gfx::Vector2dF expected_scroll_delta( |
3055 0, | 3077 0.0f, |
3056 -gesture_scroll_delta.x() * | 3078 -gesture_scroll_delta.x() * |
3057 std::sin(MathUtil::Deg2Rad(child_layer_angle))); | 3079 std::sin(MathUtil::Deg2Rad(child_layer_angle))); |
3058 scoped_ptr<ScrollAndScaleSet> scroll_info = | 3080 scoped_ptr<ScrollAndScaleSet> scroll_info = |
3059 host_impl_->ProcessScrollDeltas(); | 3081 host_impl_->ProcessScrollDeltas(); |
3060 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); | 3082 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); |
3061 | 3083 |
3062 // The root scroll layer should have scrolled more, since the input scroll | 3084 // The root scroll layer should have scrolled more, since the input scroll |
3063 // delta was mostly orthogonal to the child layer's vertical scroll axis. | 3085 // delta was mostly orthogonal to the child layer's vertical scroll axis. |
3064 gfx::Vector2d expected_root_scroll_delta( | 3086 gfx::Vector2dF expected_root_scroll_delta( |
3065 gesture_scroll_delta.x() * | 3087 gesture_scroll_delta.x() * |
3066 std::pow(std::cos(MathUtil::Deg2Rad(child_layer_angle)), 2), | 3088 std::pow(std::cos(MathUtil::Deg2Rad(child_layer_angle)), 2), |
3067 0); | 3089 0.0f); |
3068 ExpectContains(*scroll_info.get(), | 3090 ExpectContains(*scroll_info.get(), |
3069 scroll_layer->id(), | 3091 scroll_layer->id(), |
3070 expected_root_scroll_delta); | 3092 expected_root_scroll_delta); |
3071 } | 3093 } |
3072 } | 3094 } |
3073 | 3095 |
3074 TEST_F(LayerTreeHostImplTest, ScrollScaledLayer) { | 3096 TEST_F(LayerTreeHostImplTest, ScrollScaledLayer) { |
3075 LayerImpl* scroll_layer = | 3097 LayerImpl* scroll_layer = |
3076 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 3098 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
3077 | 3099 |
(...skipping 4034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7112 // surface. | 7134 // surface. |
7113 EXPECT_EQ(0, num_lost_surfaces_); | 7135 EXPECT_EQ(0, num_lost_surfaces_); |
7114 host_impl_->DidLoseOutputSurface(); | 7136 host_impl_->DidLoseOutputSurface(); |
7115 EXPECT_EQ(1, num_lost_surfaces_); | 7137 EXPECT_EQ(1, num_lost_surfaces_); |
7116 host_impl_->DidLoseOutputSurface(); | 7138 host_impl_->DidLoseOutputSurface(); |
7117 EXPECT_LE(1, num_lost_surfaces_); | 7139 EXPECT_LE(1, num_lost_surfaces_); |
7118 } | 7140 } |
7119 | 7141 |
7120 } // namespace | 7142 } // namespace |
7121 } // namespace cc | 7143 } // namespace cc |
OLD | NEW |