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 class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl { |
| 994 public: |
| 995 LayerTreeHostImplOverridePhysicalTime( |
| 996 const LayerTreeSettings& settings, |
| 997 LayerTreeHostImplClient* client, |
| 998 Proxy* proxy, |
| 999 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
| 1000 : LayerTreeHostImpl(settings, |
| 1001 client, |
| 1002 proxy, |
| 1003 rendering_stats_instrumentation) {} |
| 1004 |
| 1005 |
| 1006 virtual base::TimeTicks CurrentPhysicalTimeTicks() const OVERRIDE { |
| 1007 return fake_current_physical_time_; |
| 1008 } |
| 1009 |
| 1010 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { |
| 1011 fake_current_physical_time_ = fake_now; |
| 1012 } |
| 1013 |
| 1014 private: |
| 1015 base::TimeTicks fake_current_physical_time_; |
| 1016 }; |
| 1017 |
| 1018 TEST_F(LayerTreeHostImplTest, ScrollbarLinearFadeScheduling) { |
| 1019 LayerTreeSettings settings; |
| 1020 settings.use_linear_fade_scrollbar_animator = true; |
| 1021 settings.scrollbar_linear_fade_delay_ms = 20; |
| 1022 settings.scrollbar_linear_fade_length_ms = 20; |
| 1023 |
| 1024 LayerTreeHostImplOverridePhysicalTime* host_impl_override_time = |
| 1025 new LayerTreeHostImplOverridePhysicalTime( |
| 1026 settings, this, &proxy_, &stats_instrumentation_); |
| 1027 host_impl_ = make_scoped_ptr<LayerTreeHostImpl>(host_impl_override_time); |
| 1028 host_impl_->InitializeRenderer(CreateOutputSurface()); |
| 1029 host_impl_->SetViewportSize(gfx::Size(10, 10)); |
| 1030 |
| 1031 gfx::Size content_size(100, 100); |
| 1032 scoped_ptr<LayerImpl> root = |
| 1033 LayerImpl::Create(host_impl_->active_tree(), 1); |
| 1034 root->SetBounds(content_size); |
| 1035 root->SetContentBounds(content_size); |
| 1036 |
| 1037 scoped_ptr<LayerImpl> scroll = |
| 1038 LayerImpl::Create(host_impl_->active_tree(), 2); |
| 1039 scroll->SetScrollable(true); |
| 1040 scroll->SetScrollOffset(gfx::Vector2d()); |
| 1041 scroll->SetMaxScrollOffset(gfx::Vector2d(content_size.width(), |
| 1042 content_size.height())); |
| 1043 scroll->SetBounds(content_size); |
| 1044 scroll->SetContentBounds(content_size); |
| 1045 |
| 1046 scoped_ptr<LayerImpl> contents = |
| 1047 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 1048 contents->SetDrawsContent(true); |
| 1049 contents->SetBounds(content_size); |
| 1050 contents->SetContentBounds(content_size); |
| 1051 |
| 1052 scoped_ptr<ScrollbarLayerImpl> scrollbar = ScrollbarLayerImpl::Create( |
| 1053 host_impl_->active_tree(), |
| 1054 4, |
| 1055 VERTICAL); |
| 1056 scroll->SetVerticalScrollbarLayer(scrollbar.get()); |
| 1057 |
| 1058 scroll->AddChild(contents.Pass()); |
| 1059 root->AddChild(scroll.Pass()); |
| 1060 root->AddChild(scrollbar.PassAs<LayerImpl>()); |
| 1061 |
| 1062 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 1063 host_impl_->active_tree()->DidBecomeActive(); |
| 1064 InitializeRendererAndDrawFrame(); |
| 1065 |
| 1066 base::TimeTicks fake_now = base::TimeTicks::Now(); |
| 1067 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); |
| 1068 |
| 1069 // If no scroll happened recently, StartScrollbarAnimation should have no |
| 1070 // effect. |
| 1071 host_impl_->StartScrollbarAnimation(); |
| 1072 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); |
| 1073 EXPECT_FALSE(did_request_redraw_); |
| 1074 |
| 1075 // After a scroll, a fade animation should be scheduled about 20ms from now. |
| 1076 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel); |
| 1077 host_impl_->ScrollEnd(); |
| 1078 host_impl_->StartScrollbarAnimation(); |
| 1079 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), |
| 1080 requested_scrollbar_animation_delay_); |
| 1081 EXPECT_FALSE(did_request_redraw_); |
| 1082 requested_scrollbar_animation_delay_ = base::TimeDelta(); |
| 1083 |
| 1084 // After the fade begins, we should start getting redraws instead of a |
| 1085 // scheduled animation. |
| 1086 fake_now += base::TimeDelta::FromMilliseconds(25); |
| 1087 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); |
| 1088 host_impl_->StartScrollbarAnimation(); |
| 1089 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); |
| 1090 EXPECT_TRUE(did_request_redraw_); |
| 1091 did_request_redraw_ = false; |
| 1092 |
| 1093 // If no scroll happened recently, StartScrollbarAnimation should have no |
| 1094 // effect. |
| 1095 fake_now += base::TimeDelta::FromMilliseconds(25); |
| 1096 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); |
| 1097 host_impl_->StartScrollbarAnimation(); |
| 1098 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); |
| 1099 EXPECT_FALSE(did_request_redraw_); |
| 1100 |
| 1101 // Setting the scroll offset outside a scroll should also cause the scrollbar |
| 1102 // to appear and to schedule a fade. |
| 1103 host_impl_->RootScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5)); |
| 1104 host_impl_->StartScrollbarAnimation(); |
| 1105 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), |
| 1106 requested_scrollbar_animation_delay_); |
| 1107 EXPECT_FALSE(did_request_redraw_); |
| 1108 requested_scrollbar_animation_delay_ = base::TimeDelta(); |
| 1109 |
| 1110 // None of the above should have called CurrentFrameTimeTicks, so if we call |
| 1111 // it now we should get the current time. |
| 1112 fake_now += base::TimeDelta::FromMilliseconds(10); |
| 1113 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); |
| 1114 EXPECT_EQ(fake_now, host_impl_->CurrentFrameTimeTicks()); |
| 1115 } |
| 1116 |
992 TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) { | 1117 TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) { |
993 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 1118 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
994 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 1119 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
995 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); | 1120 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); |
996 InitializeRendererAndDrawFrame(); | 1121 InitializeRendererAndDrawFrame(); |
997 { | 1122 { |
998 CompositorFrameMetadata metadata = | 1123 CompositorFrameMetadata metadata = |
999 host_impl_->MakeCompositorFrameMetadata(); | 1124 host_impl_->MakeCompositorFrameMetadata(); |
1000 EXPECT_EQ(gfx::Vector2dF(), metadata.root_scroll_offset); | 1125 EXPECT_EQ(gfx::Vector2dF(), metadata.root_scroll_offset); |
1001 EXPECT_EQ(1.f, metadata.page_scale_factor); | 1126 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_); | 5992 EXPECT_FALSE(did_try_initialize_renderer_); |
5868 host_impl_->DeferredInitialize(scoped_refptr<ContextProvider>()); | 5993 host_impl_->DeferredInitialize(scoped_refptr<ContextProvider>()); |
5869 EXPECT_TRUE(did_try_initialize_renderer_); | 5994 EXPECT_TRUE(did_try_initialize_renderer_); |
5870 | 5995 |
5871 // Defer intialized GL draw. | 5996 // Defer intialized GL draw. |
5872 DrawFrame(); | 5997 DrawFrame(); |
5873 } | 5998 } |
5874 | 5999 |
5875 } // namespace | 6000 } // namespace |
5876 } // namespace cc | 6001 } // namespace cc |
OLD | NEW |