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

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

Issue 206793003: cc: Split animating and drawing into separate actions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments and rebased. Created 6 years, 8 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 public: 77 public:
78 LayerTreeHostImplTest() 78 LayerTreeHostImplTest()
79 : proxy_(base::MessageLoopProxy::current()), 79 : proxy_(base::MessageLoopProxy::current()),
80 always_impl_thread_(&proxy_), 80 always_impl_thread_(&proxy_),
81 always_main_thread_blocked_(&proxy_), 81 always_main_thread_blocked_(&proxy_),
82 shared_bitmap_manager_(new TestSharedBitmapManager()), 82 shared_bitmap_manager_(new TestSharedBitmapManager()),
83 on_can_draw_state_changed_called_(false), 83 on_can_draw_state_changed_called_(false),
84 did_notify_ready_to_activate_(false), 84 did_notify_ready_to_activate_(false),
85 did_request_commit_(false), 85 did_request_commit_(false),
86 did_request_redraw_(false), 86 did_request_redraw_(false),
87 did_request_animate_(false),
87 did_request_manage_tiles_(false), 88 did_request_manage_tiles_(false),
88 did_upload_visible_tile_(false), 89 did_upload_visible_tile_(false),
89 reduce_memory_result_(true), 90 reduce_memory_result_(true),
90 current_limit_bytes_(0), 91 current_limit_bytes_(0),
91 current_priority_cutoff_value_(0) { 92 current_priority_cutoff_value_(0) {
92 media::InitializeMediaLibraryForTesting(); 93 media::InitializeMediaLibraryForTesting();
93 } 94 }
94 95
95 LayerTreeSettings DefaultSettings() { 96 LayerTreeSettings DefaultSettings() {
96 LayerTreeSettings settings; 97 LayerTreeSettings settings;
(...skipping 21 matching lines...) Expand all
118 did_notify_ready_to_activate_ = true; 119 did_notify_ready_to_activate_ = true;
119 host_impl_->ActivatePendingTree(); 120 host_impl_->ActivatePendingTree();
120 } 121 }
121 virtual void SetNeedsRedrawOnImplThread() OVERRIDE { 122 virtual void SetNeedsRedrawOnImplThread() OVERRIDE {
122 did_request_redraw_ = true; 123 did_request_redraw_ = true;
123 } 124 }
124 virtual void SetNeedsRedrawRectOnImplThread( 125 virtual void SetNeedsRedrawRectOnImplThread(
125 const gfx::Rect& damage_rect) OVERRIDE { 126 const gfx::Rect& damage_rect) OVERRIDE {
126 did_request_redraw_ = true; 127 did_request_redraw_ = true;
127 } 128 }
129 virtual void SetNeedsAnimateOnImplThread() OVERRIDE {
130 did_request_animate_ = true;
131 }
128 virtual void SetNeedsManageTilesOnImplThread() OVERRIDE { 132 virtual void SetNeedsManageTilesOnImplThread() OVERRIDE {
129 did_request_manage_tiles_ = true; 133 did_request_manage_tiles_ = true;
130 } 134 }
131 virtual void DidInitializeVisibleTileOnImplThread() OVERRIDE { 135 virtual void DidInitializeVisibleTileOnImplThread() OVERRIDE {
132 did_upload_visible_tile_ = true; 136 did_upload_visible_tile_ = true;
133 } 137 }
134 virtual void SetNeedsCommitOnImplThread() OVERRIDE { 138 virtual void SetNeedsCommitOnImplThread() OVERRIDE {
135 did_request_commit_ = true; 139 did_request_commit_ = true;
136 } 140 }
137 virtual void PostAnimationEventsToMainThreadOnImplThread( 141 virtual void PostAnimationEventsToMainThreadOnImplThread(
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 DebugScopedSetImplThread always_impl_thread_; 387 DebugScopedSetImplThread always_impl_thread_;
384 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; 388 DebugScopedSetMainThreadBlocked always_main_thread_blocked_;
385 389
386 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; 390 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
387 scoped_ptr<LayerTreeHostImpl> host_impl_; 391 scoped_ptr<LayerTreeHostImpl> host_impl_;
388 FakeRenderingStatsInstrumentation stats_instrumentation_; 392 FakeRenderingStatsInstrumentation stats_instrumentation_;
389 bool on_can_draw_state_changed_called_; 393 bool on_can_draw_state_changed_called_;
390 bool did_notify_ready_to_activate_; 394 bool did_notify_ready_to_activate_;
391 bool did_request_commit_; 395 bool did_request_commit_;
392 bool did_request_redraw_; 396 bool did_request_redraw_;
397 bool did_request_animate_;
393 bool did_request_manage_tiles_; 398 bool did_request_manage_tiles_;
394 bool did_upload_visible_tile_; 399 bool did_upload_visible_tile_;
395 bool reduce_memory_result_; 400 bool reduce_memory_result_;
396 base::TimeDelta requested_scrollbar_animation_delay_; 401 base::TimeDelta requested_scrollbar_animation_delay_;
397 size_t current_limit_bytes_; 402 size_t current_limit_bytes_;
398 int current_priority_cutoff_value_; 403 int current_priority_cutoff_value_;
399 }; 404 };
400 405
401 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { 406 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) {
402 bool always_draw = false; 407 bool always_draw = false;
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); 896 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture);
892 host_impl_->PinchGestureBegin(); 897 host_impl_->PinchGestureBegin();
893 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); 898 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50));
894 // While the gesture is still active, the scroll layer should have a 899 // While the gesture is still active, the scroll layer should have a
895 // container size delta = container->bounds() * ((1.f - 900 // container size delta = container->bounds() * ((1.f -
896 // page_scale_delta)/()) 901 // page_scale_delta)/())
897 EXPECT_EQ(expected_container_size_delta, 902 EXPECT_EQ(expected_container_size_delta,
898 scroll_layer->FixedContainerSizeDelta()); 903 scroll_layer->FixedContainerSizeDelta());
899 host_impl_->PinchGestureEnd(); 904 host_impl_->PinchGestureEnd();
900 host_impl_->ScrollEnd(); 905 host_impl_->ScrollEnd();
906 EXPECT_FALSE(did_request_animate_);
901 EXPECT_TRUE(did_request_redraw_); 907 EXPECT_TRUE(did_request_redraw_);
902 EXPECT_TRUE(did_request_commit_); 908 EXPECT_TRUE(did_request_commit_);
903 EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds()); 909 EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds());
904 910
905 scoped_ptr<ScrollAndScaleSet> scroll_info = 911 scoped_ptr<ScrollAndScaleSet> scroll_info =
906 host_impl_->ProcessScrollDeltas(); 912 host_impl_->ProcessScrollDeltas();
907 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); 913 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta);
908 914
909 EXPECT_EQ(gfx::Vector2d(75, 75).ToString(), 915 EXPECT_EQ(gfx::Vector2d(75, 75).ToString(),
910 scroll_layer->MaxScrollOffset().ToString()); 916 scroll_layer->MaxScrollOffset().ToString());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 min_page_scale, 963 min_page_scale,
958 max_page_scale); 964 max_page_scale);
959 scroll_layer->SetScrollDelta(gfx::Vector2d()); 965 scroll_layer->SetScrollDelta(gfx::Vector2d());
960 966
961 float page_scale_delta = 2.f; 967 float page_scale_delta = 2.f;
962 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); 968 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture);
963 host_impl_->PinchGestureBegin(); 969 host_impl_->PinchGestureBegin();
964 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); 970 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50));
965 host_impl_->PinchGestureEnd(); 971 host_impl_->PinchGestureEnd();
966 host_impl_->ScrollEnd(); 972 host_impl_->ScrollEnd();
973 EXPECT_FALSE(did_request_animate_);
967 EXPECT_TRUE(did_request_redraw_); 974 EXPECT_TRUE(did_request_redraw_);
968 EXPECT_TRUE(did_request_commit_); 975 EXPECT_TRUE(did_request_commit_);
969 976
970 scoped_ptr<ScrollAndScaleSet> scroll_info = 977 scoped_ptr<ScrollAndScaleSet> scroll_info =
971 host_impl_->ProcessScrollDeltas(); 978 host_impl_->ProcessScrollDeltas();
972 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); 979 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta);
973 } 980 }
974 981
975 // Zoom-in clamping 982 // Zoom-in clamping
976 { 983 {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 base::TimeTicks halfway_through_animation = start_time + duration / 2; 1105 base::TimeTicks halfway_through_animation = start_time + duration / 2;
1099 base::TimeTicks end_time = start_time + duration; 1106 base::TimeTicks end_time = start_time + duration;
1100 1107
1101 // Non-anchor zoom-in 1108 // Non-anchor zoom-in
1102 { 1109 {
1103 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1110 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f,
1104 min_page_scale, 1111 min_page_scale,
1105 max_page_scale); 1112 max_page_scale);
1106 scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50)); 1113 scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50));
1107 1114
1115 did_request_redraw_ = false;
1116 did_request_animate_ = false;
1108 host_impl_->StartPageScaleAnimation(gfx::Vector2d(), false, 2.f, duration); 1117 host_impl_->StartPageScaleAnimation(gfx::Vector2d(), false, 2.f, duration);
1118 EXPECT_FALSE(did_request_redraw_);
1119 EXPECT_TRUE(did_request_animate_);
1120
1109 did_request_redraw_ = false; 1121 did_request_redraw_ = false;
1122 did_request_animate_ = false;
1110 host_impl_->Animate(start_time); 1123 host_impl_->Animate(start_time);
1111 EXPECT_TRUE(did_request_redraw_); 1124 EXPECT_TRUE(did_request_redraw_);
1125 EXPECT_TRUE(did_request_animate_);
1112 1126
1113 did_request_redraw_ = false; 1127 did_request_redraw_ = false;
1128 did_request_animate_ = false;
1114 host_impl_->Animate(halfway_through_animation); 1129 host_impl_->Animate(halfway_through_animation);
1115 EXPECT_TRUE(did_request_redraw_); 1130 EXPECT_TRUE(did_request_redraw_);
1131 EXPECT_TRUE(did_request_animate_);
1116 1132
1117 did_request_redraw_ = false; 1133 did_request_redraw_ = false;
1134 did_request_animate_ = false;
1118 did_request_commit_ = false; 1135 did_request_commit_ = false;
1119 host_impl_->Animate(end_time); 1136 host_impl_->Animate(end_time);
1120 EXPECT_TRUE(did_request_commit_); 1137 EXPECT_TRUE(did_request_commit_);
1138 EXPECT_FALSE(did_request_animate_);
1121 1139
1122 scoped_ptr<ScrollAndScaleSet> scroll_info = 1140 scoped_ptr<ScrollAndScaleSet> scroll_info =
1123 host_impl_->ProcessScrollDeltas(); 1141 host_impl_->ProcessScrollDeltas();
1124 EXPECT_EQ(scroll_info->page_scale_delta, 2); 1142 EXPECT_EQ(scroll_info->page_scale_delta, 2);
1125 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50)); 1143 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50));
1126 } 1144 }
1127 1145
1128 // Anchor zoom-out 1146 // Anchor zoom-out
1129 { 1147 {
1130 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1148 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f,
1131 min_page_scale, 1149 min_page_scale,
1132 max_page_scale); 1150 max_page_scale);
1133 scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50)); 1151 scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50));
1134 1152
1153 did_request_redraw_ = false;
1154 did_request_animate_ = false;
1135 host_impl_->StartPageScaleAnimation( 1155 host_impl_->StartPageScaleAnimation(
1136 gfx::Vector2d(25, 25), true, min_page_scale, duration); 1156 gfx::Vector2d(25, 25), true, min_page_scale, duration);
1157 EXPECT_FALSE(did_request_redraw_);
1158 EXPECT_TRUE(did_request_animate_);
1159
1137 did_request_redraw_ = false; 1160 did_request_redraw_ = false;
1161 did_request_animate_ = false;
1138 host_impl_->Animate(start_time); 1162 host_impl_->Animate(start_time);
1139 EXPECT_TRUE(did_request_redraw_); 1163 EXPECT_TRUE(did_request_redraw_);
1164 EXPECT_TRUE(did_request_animate_);
1140 1165
1141 did_request_redraw_ = false; 1166 did_request_redraw_ = false;
1142 did_request_commit_ = false; 1167 did_request_commit_ = false;
1168 did_request_animate_ = false;
1143 host_impl_->Animate(end_time); 1169 host_impl_->Animate(end_time);
1144 EXPECT_TRUE(did_request_redraw_); 1170 EXPECT_TRUE(did_request_redraw_);
1171 EXPECT_FALSE(did_request_animate_);
1145 EXPECT_TRUE(did_request_commit_); 1172 EXPECT_TRUE(did_request_commit_);
1146 1173
1147 scoped_ptr<ScrollAndScaleSet> scroll_info = 1174 scoped_ptr<ScrollAndScaleSet> scroll_info =
1148 host_impl_->ProcessScrollDeltas(); 1175 host_impl_->ProcessScrollDeltas();
1149 EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale); 1176 EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale);
1150 // Pushed to (0,0) via clamping against contents layer size. 1177 // Pushed to (0,0) via clamping against contents layer size.
1151 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50)); 1178 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50));
1152 } 1179 }
1153 } 1180 }
1154 1181
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 host_impl_->ScrollEnd(); 1310 host_impl_->ScrollEnd();
1284 host_impl_->StartScrollbarAnimation(); 1311 host_impl_->StartScrollbarAnimation();
1285 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); 1312 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1286 EXPECT_FALSE(did_request_redraw_); 1313 EXPECT_FALSE(did_request_redraw_);
1287 1314
1288 // After a scroll, a fade animation should be scheduled about 20ms from now. 1315 // After a scroll, a fade animation should be scheduled about 20ms from now.
1289 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel); 1316 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel);
1290 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0)); 1317 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0));
1291 host_impl_->ScrollEnd(); 1318 host_impl_->ScrollEnd();
1292 did_request_redraw_ = false; 1319 did_request_redraw_ = false;
1320 did_request_animate_ = false;
1293 host_impl_->StartScrollbarAnimation(); 1321 host_impl_->StartScrollbarAnimation();
1294 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), 1322 EXPECT_LT(base::TimeDelta::FromMilliseconds(19),
1295 requested_scrollbar_animation_delay_); 1323 requested_scrollbar_animation_delay_);
1296 EXPECT_FALSE(did_request_redraw_); 1324 EXPECT_FALSE(did_request_redraw_);
1325 EXPECT_FALSE(did_request_animate_);
1297 requested_scrollbar_animation_delay_ = base::TimeDelta(); 1326 requested_scrollbar_animation_delay_ = base::TimeDelta();
1298 1327
1299 // After the fade begins, we should start getting redraws instead of a 1328 // After the fade begins, we should start getting redraws instead of a
1300 // scheduled animation. 1329 // scheduled animation.
1301 fake_now += base::TimeDelta::FromMilliseconds(25); 1330 fake_now += base::TimeDelta::FromMilliseconds(25);
1302 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); 1331 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now);
1303 host_impl_->StartScrollbarAnimation(); 1332 host_impl_->StartScrollbarAnimation();
1304 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); 1333 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1305 EXPECT_TRUE(did_request_redraw_); 1334 EXPECT_TRUE(did_request_animate_);
1306 did_request_redraw_ = false; 1335 did_request_animate_ = false;
1307 1336
1308 // If no scroll happened recently, StartScrollbarAnimation should have no 1337 // If no scroll happened recently, StartScrollbarAnimation should have no
1309 // effect. 1338 // effect.
1310 fake_now += base::TimeDelta::FromMilliseconds(25); 1339 fake_now += base::TimeDelta::FromMilliseconds(25);
1311 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); 1340 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now);
1312 host_impl_->StartScrollbarAnimation(); 1341 host_impl_->StartScrollbarAnimation();
1313 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); 1342 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1314 EXPECT_FALSE(did_request_redraw_); 1343 EXPECT_FALSE(did_request_redraw_);
1315 1344
1316 // Setting the scroll offset outside a scroll should also cause the scrollbar 1345 // Setting the scroll offset outside a scroll should also cause the scrollbar
1317 // to appear and to schedule a fade. 1346 // to appear and to schedule a fade.
1318 host_impl_->InnerViewportScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5)); 1347 host_impl_->InnerViewportScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5));
1319 host_impl_->StartScrollbarAnimation(); 1348 host_impl_->StartScrollbarAnimation();
1320 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), 1349 EXPECT_LT(base::TimeDelta::FromMilliseconds(19),
1321 requested_scrollbar_animation_delay_); 1350 requested_scrollbar_animation_delay_);
1322 EXPECT_FALSE(did_request_redraw_); 1351 EXPECT_FALSE(did_request_redraw_);
1352 EXPECT_FALSE(did_request_animate_);
1323 requested_scrollbar_animation_delay_ = base::TimeDelta(); 1353 requested_scrollbar_animation_delay_ = base::TimeDelta();
1324 1354
1325 // None of the above should have called CurrentFrameTimeTicks, so if we call 1355 // None of the above should have called CurrentFrameTimeTicks, so if we call
1326 // it now we should get the current time. 1356 // it now we should get the current time.
1327 fake_now += base::TimeDelta::FromMilliseconds(10); 1357 fake_now += base::TimeDelta::FromMilliseconds(10);
1328 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); 1358 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now);
1329 EXPECT_EQ(fake_now, host_impl_->CurrentFrameTimeTicks()); 1359 EXPECT_EQ(fake_now, host_impl_->CurrentFrameTimeTicks());
1330 } 1360 }
1331 1361
1332 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( 1362 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale(
(...skipping 5012 matching lines...) Expand 10 before | Expand all | Expand 10 after
6345 EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes, 6375 EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes,
6346 300u * 1024u * 1024u); 6376 300u * 1024u * 1024u);
6347 EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes, 6377 EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes,
6348 150u * 1024u * 1024u); 6378 150u * 1024u * 1024u);
6349 EXPECT_EQ(host_impl_->global_tile_state().unused_memory_limit_in_bytes, 6379 EXPECT_EQ(host_impl_->global_tile_state().unused_memory_limit_in_bytes,
6350 75u * 1024u * 1024u); 6380 75u * 1024u * 1024u);
6351 } 6381 }
6352 6382
6353 } // namespace 6383 } // namespace
6354 } // namespace cc 6384 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698