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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 base::Time wall_clock_time) OVERRIDE {} | 122 base::Time wall_clock_time) OVERRIDE {} |
123 virtual bool ReduceContentsTextureMemoryOnImplThread( | 123 virtual bool ReduceContentsTextureMemoryOnImplThread( |
124 size_t limit_bytes, int priority_cutoff) OVERRIDE { | 124 size_t limit_bytes, int priority_cutoff) OVERRIDE { |
125 return reduce_memory_result_; | 125 return reduce_memory_result_; |
126 } | 126 } |
127 virtual void ReduceWastedContentsTextureMemoryOnImplThread() OVERRIDE {} | 127 virtual void ReduceWastedContentsTextureMemoryOnImplThread() OVERRIDE {} |
128 virtual void SendManagedMemoryStats() OVERRIDE {} | 128 virtual void SendManagedMemoryStats() OVERRIDE {} |
129 virtual bool IsInsideDraw() OVERRIDE { return false; } | 129 virtual bool IsInsideDraw() OVERRIDE { return false; } |
130 virtual void RenewTreePriority() OVERRIDE {} | 130 virtual void RenewTreePriority() OVERRIDE {} |
131 virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) | 131 virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) |
132 OVERRIDE {} | 132 OVERRIDE { requested_scrollbar_animation_delay_ = delay; } |
133 virtual void DidActivatePendingTree() OVERRIDE {} | 133 virtual void DidActivatePendingTree() OVERRIDE {} |
134 | 134 |
135 void set_reduce_memory_result(bool reduce_memory_result) { | 135 void set_reduce_memory_result(bool reduce_memory_result) { |
136 reduce_memory_result_ = reduce_memory_result; | 136 reduce_memory_result_ = reduce_memory_result; |
137 } | 137 } |
138 | 138 |
139 void CreateLayerTreeHost(bool partial_swap, | 139 void CreateLayerTreeHost(bool partial_swap, |
140 scoped_ptr<OutputSurface> output_surface) { | 140 scoped_ptr<OutputSurface> output_surface) { |
141 LayerTreeSettings settings; | 141 LayerTreeSettings settings; |
142 settings.minimum_occlusion_tracking_size = gfx::Size(); | 142 settings.minimum_occlusion_tracking_size = gfx::Size(); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 | 277 |
278 scoped_ptr<LayerTreeHostImpl> host_impl_; | 278 scoped_ptr<LayerTreeHostImpl> host_impl_; |
279 FakeRenderingStatsInstrumentation stats_instrumentation_; | 279 FakeRenderingStatsInstrumentation stats_instrumentation_; |
280 bool did_try_initialize_renderer_; | 280 bool did_try_initialize_renderer_; |
281 bool on_can_draw_state_changed_called_; | 281 bool on_can_draw_state_changed_called_; |
282 bool has_pending_tree_; | 282 bool has_pending_tree_; |
283 bool did_request_commit_; | 283 bool did_request_commit_; |
284 bool did_request_redraw_; | 284 bool did_request_redraw_; |
285 bool did_upload_visible_tile_; | 285 bool did_upload_visible_tile_; |
286 bool reduce_memory_result_; | 286 bool reduce_memory_result_; |
287 base::TimeDelta requested_scrollbar_animation_delay_; | |
287 }; | 288 }; |
288 | 289 |
289 class TestWebGraphicsContext3DMakeCurrentFails | 290 class TestWebGraphicsContext3DMakeCurrentFails |
290 : public TestWebGraphicsContext3D { | 291 : public TestWebGraphicsContext3D { |
291 public: | 292 public: |
292 virtual bool makeContextCurrent() OVERRIDE { return false; } | 293 virtual bool makeContextCurrent() OVERRIDE { return false; } |
293 }; | 294 }; |
294 | 295 |
295 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { | 296 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { |
296 // Note: It is not possible to disable the renderer once it has been set, | 297 // Note: It is not possible to disable the renderer once it has been set, |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
982 host_impl_->Animate(end_time, base::Time()); | 983 host_impl_->Animate(end_time, base::Time()); |
983 EXPECT_TRUE(did_request_commit_); | 984 EXPECT_TRUE(did_request_commit_); |
984 | 985 |
985 scoped_ptr<ScrollAndScaleSet> scroll_info = | 986 scoped_ptr<ScrollAndScaleSet> scroll_info = |
986 host_impl_->ProcessScrollDeltas(); | 987 host_impl_->ProcessScrollDeltas(); |
987 EXPECT_EQ(scroll_info->page_scale_delta, 1); | 988 EXPECT_EQ(scroll_info->page_scale_delta, 1); |
988 ExpectNone(*scroll_info, scroll_layer->id()); | 989 ExpectNone(*scroll_info, scroll_layer->id()); |
989 } | 990 } |
990 } | 991 } |
991 | 992 |
993 TEST_F(LayerTreeHostImplTest, ScrollbarLinearFadeScheduling) { | |
994 LayerTreeSettings settings; | |
995 settings.use_linear_fade_scrollbar_animator = true; | |
996 settings.scrollbar_linear_fade_delay_ms = 20; | |
997 settings.scrollbar_linear_fade_length_ms = 20; | |
998 | |
999 host_impl_ = LayerTreeHostImpl::Create(settings, | |
1000 this, | |
1001 &proxy_, | |
1002 &stats_instrumentation_); | |
1003 host_impl_->InitializeRenderer(CreateOutputSurface()); | |
1004 host_impl_->SetViewportSize(gfx::Size(10, 10)); | |
1005 | |
1006 gfx::Size content_size(100, 100); | |
1007 scoped_ptr<LayerImpl> root = | |
1008 LayerImpl::Create(host_impl_->active_tree(), 1); | |
1009 root->SetBounds(content_size); | |
1010 root->SetContentBounds(content_size); | |
1011 | |
1012 scoped_ptr<LayerImpl> scroll = | |
1013 LayerImpl::Create(host_impl_->active_tree(), 2); | |
1014 scroll->SetScrollable(true); | |
1015 scroll->SetScrollOffset(gfx::Vector2d()); | |
1016 scroll->SetMaxScrollOffset(gfx::Vector2d(content_size.width(), | |
1017 content_size.height())); | |
1018 scroll->SetBounds(content_size); | |
1019 scroll->SetContentBounds(content_size); | |
1020 | |
1021 scoped_ptr<LayerImpl> contents = | |
1022 LayerImpl::Create(host_impl_->active_tree(), 3); | |
1023 contents->SetDrawsContent(true); | |
1024 contents->SetBounds(content_size); | |
1025 contents->SetContentBounds(content_size); | |
1026 | |
1027 scoped_ptr<ScrollbarLayerImpl> scrollbar = ScrollbarLayerImpl::Create( | |
1028 host_impl_->active_tree(), | |
1029 4, | |
1030 VERTICAL); | |
1031 scroll->SetVerticalScrollbarLayer(scrollbar.get()); | |
1032 | |
1033 scroll->AddChild(contents.Pass()); | |
1034 root->AddChild(scroll.Pass()); | |
1035 root->AddChild(scrollbar.PassAs<LayerImpl>()); | |
1036 | |
1037 host_impl_->active_tree()->SetRootLayer(root.Pass()); | |
1038 host_impl_->active_tree()->DidBecomeActive(); | |
1039 InitializeRendererAndDrawFrame(); | |
1040 | |
1041 base::TimeTicks fake_time = base::TimeTicks::Now(); | |
danakj
2013/06/14 18:36:43
nit: fake_now ?
| |
1042 host_impl_->SetCurrentPhysicalTimeTicksForTest(fake_time); | |
1043 | |
1044 // If no scroll happened recently, StartScrollbarAnimation should have no | |
1045 // effect. | |
1046 host_impl_->StartScrollbarAnimation(); | |
1047 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); | |
1048 EXPECT_FALSE(did_request_redraw_); | |
1049 | |
1050 // After a scroll, a fade animation should be scheduled about 20ms from now | |
1051 // (check greater than 10ms to avoid flakiness). | |
danakj
2013/06/14 18:36:43
this comment out of date
| |
1052 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel); | |
1053 host_impl_->ScrollEnd(); | |
1054 host_impl_->StartScrollbarAnimation(); | |
1055 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), | |
1056 requested_scrollbar_animation_delay_); | |
1057 EXPECT_FALSE(did_request_redraw_); | |
1058 requested_scrollbar_animation_delay_ = base::TimeDelta(); | |
1059 | |
1060 // After the fade begins, we should start getting redraws instead of a | |
1061 // scheduled animation. | |
1062 fake_time += base::TimeDelta::FromMilliseconds(25); | |
1063 host_impl_->SetCurrentPhysicalTimeTicksForTest(fake_time); | |
1064 host_impl_->StartScrollbarAnimation(); | |
1065 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); | |
1066 EXPECT_TRUE(did_request_redraw_); | |
1067 did_request_redraw_ = false; | |
1068 | |
1069 // If no scroll happened recently, StartScrollbarAnimation should have no | |
1070 // effect. | |
1071 fake_time += base::TimeDelta::FromMilliseconds(25); | |
1072 host_impl_->SetCurrentPhysicalTimeTicksForTest(fake_time); | |
1073 host_impl_->StartScrollbarAnimation(); | |
1074 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); | |
1075 EXPECT_FALSE(did_request_redraw_); | |
1076 | |
1077 // Setting the scroll offset outside a scroll should also cause the scrollbar | |
1078 // to appear and to schedule a fade. | |
1079 host_impl_->RootScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5)); | |
1080 host_impl_->StartScrollbarAnimation(); | |
1081 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), | |
1082 requested_scrollbar_animation_delay_); | |
1083 EXPECT_FALSE(did_request_redraw_); | |
1084 requested_scrollbar_animation_delay_ = base::TimeDelta(); | |
1085 | |
1086 // None of the above should have called CurrentFrameTimeTicks, so if we call | |
1087 // it now we should get the current time. | |
1088 fake_time += base::TimeDelta::FromMilliseconds(10); | |
1089 host_impl_->SetCurrentPhysicalTimeTicksForTest(fake_time); | |
1090 EXPECT_EQ(fake_time, host_impl_->CurrentFrameTimeTicks()); | |
1091 } | |
1092 | |
992 TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) { | 1093 TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) { |
993 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 1094 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
994 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 1095 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
995 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); | 1096 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); |
996 InitializeRendererAndDrawFrame(); | 1097 InitializeRendererAndDrawFrame(); |
997 { | 1098 { |
998 CompositorFrameMetadata metadata = | 1099 CompositorFrameMetadata metadata = |
999 host_impl_->MakeCompositorFrameMetadata(); | 1100 host_impl_->MakeCompositorFrameMetadata(); |
1000 EXPECT_EQ(gfx::Vector2dF(), metadata.root_scroll_offset); | 1101 EXPECT_EQ(gfx::Vector2dF(), metadata.root_scroll_offset); |
1001 EXPECT_EQ(1.f, metadata.page_scale_factor); | 1102 EXPECT_EQ(1.f, metadata.page_scale_factor); |
(...skipping 4865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5867 EXPECT_FALSE(did_try_initialize_renderer_); | 5968 EXPECT_FALSE(did_try_initialize_renderer_); |
5868 host_impl_->DeferredInitialize(scoped_refptr<ContextProvider>()); | 5969 host_impl_->DeferredInitialize(scoped_refptr<ContextProvider>()); |
5869 EXPECT_TRUE(did_try_initialize_renderer_); | 5970 EXPECT_TRUE(did_try_initialize_renderer_); |
5870 | 5971 |
5871 // Defer intialized GL draw. | 5972 // Defer intialized GL draw. |
5872 DrawFrame(); | 5973 DrawFrame(); |
5873 } | 5974 } |
5874 | 5975 |
5875 } // namespace | 5976 } // namespace |
5876 } // namespace cc | 5977 } // namespace cc |
OLD | NEW |