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

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: 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
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 // If no scroll happened recently, StartScrollbarAnimation should have no
1042 // effect.
1043 host_impl_->StartScrollbarAnimation();
1044 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1045 EXPECT_FALSE(did_request_redraw_);
1046
1047 // After a scroll, a fade animation should be scheduled about 20ms from now
1048 // (check greater than 10ms to avoid flakiness).
1049 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel);
1050 host_impl_->ScrollEnd();
1051 host_impl_->StartScrollbarAnimation();
1052 EXPECT_LT(base::TimeDelta::FromMilliseconds(10),
1053 requested_scrollbar_animation_delay_);
1054 EXPECT_FALSE(did_request_redraw_);
1055 requested_scrollbar_animation_delay_ = base::TimeDelta();
1056
1057 // After the fade begins, we should start getting redraws instead of a
1058 // scheduled animation.
1059 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(25));
danakj 2013/06/14 17:40:39 This timing stuff is going to be a disaster on xp
1060 host_impl_->StartScrollbarAnimation();
1061 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1062 EXPECT_TRUE(did_request_redraw_);
1063 did_request_redraw_ = false;
1064
1065 // If no scroll happened recently, StartScrollbarAnimation should have no
1066 // effect.
1067 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(25));
1068 host_impl_->StartScrollbarAnimation();
1069 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1070 EXPECT_FALSE(did_request_redraw_);
1071
1072 // Setting the scroll offset outside a scroll should also cause the scrollbar
1073 // to appear and to schedule a fade.
1074 host_impl_->RootScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5));
1075 host_impl_->StartScrollbarAnimation();
1076 EXPECT_LT(base::TimeDelta::FromMilliseconds(10),
1077 requested_scrollbar_animation_delay_);
1078 EXPECT_FALSE(did_request_redraw_);
1079 requested_scrollbar_animation_delay_ = base::TimeDelta();
1080
1081 // None of the above should have called CurrentFrameTimeTicks, so if we call
1082 // it now we should get the current time.
1083 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
1084 EXPECT_GT(base::TimeDelta::FromMilliseconds(5),
1085 base::TimeTicks::Now() - host_impl_->CurrentFrameTimeTicks());
1086 }
1087
992 TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) { 1088 TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
993 SetupScrollAndContentsLayers(gfx::Size(100, 100)); 1089 SetupScrollAndContentsLayers(gfx::Size(100, 100));
994 host_impl_->SetViewportSize(gfx::Size(50, 50)); 1090 host_impl_->SetViewportSize(gfx::Size(50, 50));
995 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); 1091 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f);
996 InitializeRendererAndDrawFrame(); 1092 InitializeRendererAndDrawFrame();
997 { 1093 {
998 CompositorFrameMetadata metadata = 1094 CompositorFrameMetadata metadata =
999 host_impl_->MakeCompositorFrameMetadata(); 1095 host_impl_->MakeCompositorFrameMetadata();
1000 EXPECT_EQ(gfx::Vector2dF(), metadata.root_scroll_offset); 1096 EXPECT_EQ(gfx::Vector2dF(), metadata.root_scroll_offset);
1001 EXPECT_EQ(1.f, metadata.page_scale_factor); 1097 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_); 5963 EXPECT_FALSE(did_try_initialize_renderer_);
5868 host_impl_->DeferredInitialize(scoped_refptr<ContextProvider>()); 5964 host_impl_->DeferredInitialize(scoped_refptr<ContextProvider>());
5869 EXPECT_TRUE(did_try_initialize_renderer_); 5965 EXPECT_TRUE(did_try_initialize_renderer_);
5870 5966
5871 // Defer intialized GL draw. 5967 // Defer intialized GL draw.
5872 DrawFrame(); 5968 DrawFrame();
5873 } 5969 }
5874 5970
5875 } // namespace 5971 } // namespace
5876 } // namespace cc 5972 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698