Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 16925007: Fix scrollbar fade animation scheduling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Apply time override using virtual method and apply nits Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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 host_impl_ = make_scoped_ptr(new LayerTreeHostImplOverridePhysicalTime(
1025 settings, this, &proxy_, &stats_instrumentation_))
1026 .PassAs<LayerTreeHostImpl>();
1027 LayerTreeHostImplOverridePhysicalTime* host_impl_override_time =
danakj 2013/06/14 21:25:23 nit: you could save the raw pointer before making
aelias_OOO_until_Jul13 2013/06/14 22:19:02 Done.
1028 static_cast<LayerTreeHostImplOverridePhysicalTime*>(host_impl_.get());
1029 host_impl_->InitializeRenderer(CreateOutputSurface());
1030 host_impl_->SetViewportSize(gfx::Size(10, 10));
1031
1032 gfx::Size content_size(100, 100);
1033 scoped_ptr<LayerImpl> root =
1034 LayerImpl::Create(host_impl_->active_tree(), 1);
1035 root->SetBounds(content_size);
1036 root->SetContentBounds(content_size);
1037
1038 scoped_ptr<LayerImpl> scroll =
1039 LayerImpl::Create(host_impl_->active_tree(), 2);
1040 scroll->SetScrollable(true);
1041 scroll->SetScrollOffset(gfx::Vector2d());
1042 scroll->SetMaxScrollOffset(gfx::Vector2d(content_size.width(),
1043 content_size.height()));
1044 scroll->SetBounds(content_size);
1045 scroll->SetContentBounds(content_size);
1046
1047 scoped_ptr<LayerImpl> contents =
1048 LayerImpl::Create(host_impl_->active_tree(), 3);
1049 contents->SetDrawsContent(true);
1050 contents->SetBounds(content_size);
1051 contents->SetContentBounds(content_size);
1052
1053 scoped_ptr<ScrollbarLayerImpl> scrollbar = ScrollbarLayerImpl::Create(
1054 host_impl_->active_tree(),
1055 4,
1056 VERTICAL);
1057 scroll->SetVerticalScrollbarLayer(scrollbar.get());
1058
1059 scroll->AddChild(contents.Pass());
1060 root->AddChild(scroll.Pass());
1061 root->AddChild(scrollbar.PassAs<LayerImpl>());
1062
1063 host_impl_->active_tree()->SetRootLayer(root.Pass());
1064 host_impl_->active_tree()->DidBecomeActive();
1065 InitializeRendererAndDrawFrame();
1066
1067 base::TimeTicks fake_time = base::TimeTicks::Now();
1068 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_time);
1069
1070 // If no scroll happened recently, StartScrollbarAnimation should have no
1071 // effect.
1072 host_impl_->StartScrollbarAnimation();
1073 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1074 EXPECT_FALSE(did_request_redraw_);
1075
1076 // After a scroll, a fade animation should be scheduled about 20ms from now.
1077 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel);
1078 host_impl_->ScrollEnd();
1079 host_impl_->StartScrollbarAnimation();
1080 EXPECT_LT(base::TimeDelta::FromMilliseconds(19),
1081 requested_scrollbar_animation_delay_);
1082 EXPECT_FALSE(did_request_redraw_);
1083 requested_scrollbar_animation_delay_ = base::TimeDelta();
1084
1085 // After the fade begins, we should start getting redraws instead of a
1086 // scheduled animation.
1087 fake_time += base::TimeDelta::FromMilliseconds(25);
1088 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_time);
1089 host_impl_->StartScrollbarAnimation();
1090 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1091 EXPECT_TRUE(did_request_redraw_);
1092 did_request_redraw_ = false;
1093
1094 // If no scroll happened recently, StartScrollbarAnimation should have no
1095 // effect.
1096 fake_time += base::TimeDelta::FromMilliseconds(25);
1097 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_time);
1098 host_impl_->StartScrollbarAnimation();
1099 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1100 EXPECT_FALSE(did_request_redraw_);
1101
1102 // Setting the scroll offset outside a scroll should also cause the scrollbar
1103 // to appear and to schedule a fade.
1104 host_impl_->RootScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5));
1105 host_impl_->StartScrollbarAnimation();
1106 EXPECT_LT(base::TimeDelta::FromMilliseconds(19),
1107 requested_scrollbar_animation_delay_);
1108 EXPECT_FALSE(did_request_redraw_);
1109 requested_scrollbar_animation_delay_ = base::TimeDelta();
1110
1111 // None of the above should have called CurrentFrameTimeTicks, so if we call
1112 // it now we should get the current time.
1113 fake_time += base::TimeDelta::FromMilliseconds(10);
1114 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_time);
1115 EXPECT_EQ(fake_time, host_impl_->CurrentFrameTimeTicks());
1116 }
1117
992 TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) { 1118 TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
993 SetupScrollAndContentsLayers(gfx::Size(100, 100)); 1119 SetupScrollAndContentsLayers(gfx::Size(100, 100));
994 host_impl_->SetViewportSize(gfx::Size(50, 50)); 1120 host_impl_->SetViewportSize(gfx::Size(50, 50));
995 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); 1121 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f);
996 InitializeRendererAndDrawFrame(); 1122 InitializeRendererAndDrawFrame();
997 { 1123 {
998 CompositorFrameMetadata metadata = 1124 CompositorFrameMetadata metadata =
999 host_impl_->MakeCompositorFrameMetadata(); 1125 host_impl_->MakeCompositorFrameMetadata();
1000 EXPECT_EQ(gfx::Vector2dF(), metadata.root_scroll_offset); 1126 EXPECT_EQ(gfx::Vector2dF(), metadata.root_scroll_offset);
1001 EXPECT_EQ(1.f, metadata.page_scale_factor); 1127 EXPECT_EQ(1.f, metadata.page_scale_factor);
(...skipping 4865 matching lines...) Expand 10 before | Expand all | Expand 10 after
5867 EXPECT_FALSE(did_try_initialize_renderer_); 5993 EXPECT_FALSE(did_try_initialize_renderer_);
5868 host_impl_->DeferredInitialize(scoped_refptr<ContextProvider>()); 5994 host_impl_->DeferredInitialize(scoped_refptr<ContextProvider>());
5869 EXPECT_TRUE(did_try_initialize_renderer_); 5995 EXPECT_TRUE(did_try_initialize_renderer_);
5870 5996
5871 // Defer intialized GL draw. 5997 // Defer intialized GL draw.
5872 DrawFrame(); 5998 DrawFrame();
5873 } 5999 }
5874 6000
5875 } // namespace 6001 } // namespace
5876 } // namespace cc 6002 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698