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

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: Cleanup. 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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); 870 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture);
866 host_impl_->PinchGestureBegin(); 871 host_impl_->PinchGestureBegin();
867 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); 872 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50));
868 // While the gesture is still active, the scroll layer should have a 873 // While the gesture is still active, the scroll layer should have a
869 // container size delta = container->bounds() * ((1.f - 874 // container size delta = container->bounds() * ((1.f -
870 // page_scale_delta)/()) 875 // page_scale_delta)/())
871 EXPECT_EQ(expected_container_size_delta, 876 EXPECT_EQ(expected_container_size_delta,
872 scroll_layer->FixedContainerSizeDelta()); 877 scroll_layer->FixedContainerSizeDelta());
873 host_impl_->PinchGestureEnd(); 878 host_impl_->PinchGestureEnd();
874 host_impl_->ScrollEnd(); 879 host_impl_->ScrollEnd();
880 EXPECT_FALSE(did_request_animate_);
875 EXPECT_TRUE(did_request_redraw_); 881 EXPECT_TRUE(did_request_redraw_);
876 EXPECT_TRUE(did_request_commit_); 882 EXPECT_TRUE(did_request_commit_);
877 EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds()); 883 EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds());
878 884
879 scoped_ptr<ScrollAndScaleSet> scroll_info = 885 scoped_ptr<ScrollAndScaleSet> scroll_info =
880 host_impl_->ProcessScrollDeltas(); 886 host_impl_->ProcessScrollDeltas();
881 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); 887 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta);
882 888
883 EXPECT_EQ(gfx::Vector2d(75, 75).ToString(), 889 EXPECT_EQ(gfx::Vector2d(75, 75).ToString(),
884 scroll_layer->MaxScrollOffset().ToString()); 890 scroll_layer->MaxScrollOffset().ToString());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 min_page_scale, 937 min_page_scale,
932 max_page_scale); 938 max_page_scale);
933 scroll_layer->SetScrollDelta(gfx::Vector2d()); 939 scroll_layer->SetScrollDelta(gfx::Vector2d());
934 940
935 float page_scale_delta = 2.f; 941 float page_scale_delta = 2.f;
936 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); 942 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture);
937 host_impl_->PinchGestureBegin(); 943 host_impl_->PinchGestureBegin();
938 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); 944 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50));
939 host_impl_->PinchGestureEnd(); 945 host_impl_->PinchGestureEnd();
940 host_impl_->ScrollEnd(); 946 host_impl_->ScrollEnd();
947 EXPECT_FALSE(did_request_animate_);
941 EXPECT_TRUE(did_request_redraw_); 948 EXPECT_TRUE(did_request_redraw_);
942 EXPECT_TRUE(did_request_commit_); 949 EXPECT_TRUE(did_request_commit_);
943 950
944 scoped_ptr<ScrollAndScaleSet> scroll_info = 951 scoped_ptr<ScrollAndScaleSet> scroll_info =
945 host_impl_->ProcessScrollDeltas(); 952 host_impl_->ProcessScrollDeltas();
946 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); 953 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta);
947 } 954 }
948 955
949 // Zoom-in clamping 956 // Zoom-in clamping
950 { 957 {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 base::TimeTicks halfway_through_animation = start_time + duration / 2; 1079 base::TimeTicks halfway_through_animation = start_time + duration / 2;
1073 base::TimeTicks end_time = start_time + duration; 1080 base::TimeTicks end_time = start_time + duration;
1074 1081
1075 // Non-anchor zoom-in 1082 // Non-anchor zoom-in
1076 { 1083 {
1077 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1084 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f,
1078 min_page_scale, 1085 min_page_scale,
1079 max_page_scale); 1086 max_page_scale);
1080 scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50)); 1087 scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50));
1081 1088
1089 did_request_redraw_ = false;
1090 did_request_animate_ = false;
1082 host_impl_->StartPageScaleAnimation(gfx::Vector2d(), false, 2.f, duration); 1091 host_impl_->StartPageScaleAnimation(gfx::Vector2d(), false, 2.f, duration);
1092 EXPECT_FALSE(did_request_redraw_);
1093 EXPECT_TRUE(did_request_animate_);
1094
1083 did_request_redraw_ = false; 1095 did_request_redraw_ = false;
1096 did_request_animate_ = false;
1084 host_impl_->Animate(start_time); 1097 host_impl_->Animate(start_time);
1085 EXPECT_TRUE(did_request_redraw_); 1098 EXPECT_TRUE(did_request_redraw_);
1099 EXPECT_TRUE(did_request_animate_);
1086 1100
1087 did_request_redraw_ = false; 1101 did_request_redraw_ = false;
1102 did_request_animate_ = false;
1088 host_impl_->Animate(halfway_through_animation); 1103 host_impl_->Animate(halfway_through_animation);
1089 EXPECT_TRUE(did_request_redraw_); 1104 EXPECT_TRUE(did_request_redraw_);
1105 EXPECT_TRUE(did_request_animate_);
1090 1106
1091 did_request_redraw_ = false; 1107 did_request_redraw_ = false;
1108 did_request_animate_ = false;
1092 did_request_commit_ = false; 1109 did_request_commit_ = false;
1093 host_impl_->Animate(end_time); 1110 host_impl_->Animate(end_time);
1094 EXPECT_TRUE(did_request_commit_); 1111 EXPECT_TRUE(did_request_commit_);
1112 EXPECT_FALSE(did_request_animate_);
1095 1113
1096 scoped_ptr<ScrollAndScaleSet> scroll_info = 1114 scoped_ptr<ScrollAndScaleSet> scroll_info =
1097 host_impl_->ProcessScrollDeltas(); 1115 host_impl_->ProcessScrollDeltas();
1098 EXPECT_EQ(scroll_info->page_scale_delta, 2); 1116 EXPECT_EQ(scroll_info->page_scale_delta, 2);
1099 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50)); 1117 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50));
1100 } 1118 }
1101 1119
1102 // Anchor zoom-out 1120 // Anchor zoom-out
1103 { 1121 {
1104 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1122 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f,
1105 min_page_scale, 1123 min_page_scale,
1106 max_page_scale); 1124 max_page_scale);
1107 scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50)); 1125 scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50));
1108 1126
1127 did_request_redraw_ = false;
1128 did_request_animate_ = false;
1109 host_impl_->StartPageScaleAnimation( 1129 host_impl_->StartPageScaleAnimation(
1110 gfx::Vector2d(25, 25), true, min_page_scale, duration); 1130 gfx::Vector2d(25, 25), true, min_page_scale, duration);
1131 EXPECT_FALSE(did_request_redraw_);
1132 EXPECT_TRUE(did_request_animate_);
1133
1111 did_request_redraw_ = false; 1134 did_request_redraw_ = false;
1135 did_request_animate_ = false;
1112 host_impl_->Animate(start_time); 1136 host_impl_->Animate(start_time);
1113 EXPECT_TRUE(did_request_redraw_); 1137 EXPECT_TRUE(did_request_redraw_);
1138 EXPECT_TRUE(did_request_animate_);
1114 1139
1115 did_request_redraw_ = false; 1140 did_request_redraw_ = false;
1116 did_request_commit_ = false; 1141 did_request_commit_ = false;
1142 did_request_animate_ = false;
1117 host_impl_->Animate(end_time); 1143 host_impl_->Animate(end_time);
1118 EXPECT_TRUE(did_request_redraw_); 1144 EXPECT_TRUE(did_request_redraw_);
1145 EXPECT_FALSE(did_request_animate_);
1119 EXPECT_TRUE(did_request_commit_); 1146 EXPECT_TRUE(did_request_commit_);
1120 1147
1121 scoped_ptr<ScrollAndScaleSet> scroll_info = 1148 scoped_ptr<ScrollAndScaleSet> scroll_info =
1122 host_impl_->ProcessScrollDeltas(); 1149 host_impl_->ProcessScrollDeltas();
1123 EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale); 1150 EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale);
1124 // Pushed to (0,0) via clamping against contents layer size. 1151 // Pushed to (0,0) via clamping against contents layer size.
1125 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50)); 1152 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50));
1126 } 1153 }
1127 } 1154 }
1128 1155
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 host_impl_->ScrollEnd(); 1284 host_impl_->ScrollEnd();
1258 host_impl_->StartScrollbarAnimation(); 1285 host_impl_->StartScrollbarAnimation();
1259 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); 1286 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1260 EXPECT_FALSE(did_request_redraw_); 1287 EXPECT_FALSE(did_request_redraw_);
1261 1288
1262 // After a scroll, a fade animation should be scheduled about 20ms from now. 1289 // After a scroll, a fade animation should be scheduled about 20ms from now.
1263 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel); 1290 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel);
1264 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0)); 1291 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0));
1265 host_impl_->ScrollEnd(); 1292 host_impl_->ScrollEnd();
1266 did_request_redraw_ = false; 1293 did_request_redraw_ = false;
1294 did_request_animate_ = false;
1267 host_impl_->StartScrollbarAnimation(); 1295 host_impl_->StartScrollbarAnimation();
1268 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), 1296 EXPECT_LT(base::TimeDelta::FromMilliseconds(19),
1269 requested_scrollbar_animation_delay_); 1297 requested_scrollbar_animation_delay_);
1270 EXPECT_FALSE(did_request_redraw_); 1298 EXPECT_FALSE(did_request_redraw_);
1299 EXPECT_FALSE(did_request_animate_);
1271 requested_scrollbar_animation_delay_ = base::TimeDelta(); 1300 requested_scrollbar_animation_delay_ = base::TimeDelta();
1272 1301
1273 // After the fade begins, we should start getting redraws instead of a 1302 // After the fade begins, we should start getting redraws instead of a
1274 // scheduled animation. 1303 // scheduled animation.
1275 fake_now += base::TimeDelta::FromMilliseconds(25); 1304 fake_now += base::TimeDelta::FromMilliseconds(25);
1276 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); 1305 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now);
1277 host_impl_->StartScrollbarAnimation(); 1306 host_impl_->StartScrollbarAnimation();
1278 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); 1307 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1279 EXPECT_TRUE(did_request_redraw_); 1308 EXPECT_TRUE(did_request_animate_);
1280 did_request_redraw_ = false; 1309 did_request_animate_ = false;
1281 1310
1282 // If no scroll happened recently, StartScrollbarAnimation should have no 1311 // If no scroll happened recently, StartScrollbarAnimation should have no
1283 // effect. 1312 // effect.
1284 fake_now += base::TimeDelta::FromMilliseconds(25); 1313 fake_now += base::TimeDelta::FromMilliseconds(25);
1285 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); 1314 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now);
1286 host_impl_->StartScrollbarAnimation(); 1315 host_impl_->StartScrollbarAnimation();
1287 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); 1316 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1288 EXPECT_FALSE(did_request_redraw_); 1317 EXPECT_FALSE(did_request_redraw_);
1289 1318
1290 // Setting the scroll offset outside a scroll should also cause the scrollbar 1319 // Setting the scroll offset outside a scroll should also cause the scrollbar
1291 // to appear and to schedule a fade. 1320 // to appear and to schedule a fade.
1292 host_impl_->InnerViewportScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5)); 1321 host_impl_->InnerViewportScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5));
1293 host_impl_->StartScrollbarAnimation(); 1322 host_impl_->StartScrollbarAnimation();
1294 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), 1323 EXPECT_LT(base::TimeDelta::FromMilliseconds(19),
1295 requested_scrollbar_animation_delay_); 1324 requested_scrollbar_animation_delay_);
1296 EXPECT_FALSE(did_request_redraw_); 1325 EXPECT_FALSE(did_request_redraw_);
1326 EXPECT_FALSE(did_request_animate_);
1297 requested_scrollbar_animation_delay_ = base::TimeDelta(); 1327 requested_scrollbar_animation_delay_ = base::TimeDelta();
1298 1328
1299 // None of the above should have called CurrentFrameTimeTicks, so if we call 1329 // None of the above should have called CurrentFrameTimeTicks, so if we call
1300 // it now we should get the current time. 1330 // it now we should get the current time.
1301 fake_now += base::TimeDelta::FromMilliseconds(10); 1331 fake_now += base::TimeDelta::FromMilliseconds(10);
1302 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); 1332 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now);
1303 EXPECT_EQ(fake_now, host_impl_->CurrentFrameTimeTicks()); 1333 EXPECT_EQ(fake_now, host_impl_->CurrentFrameTimeTicks());
1304 } 1334 }
1305 1335
1306 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( 1336 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale(
(...skipping 4934 matching lines...) Expand 10 before | Expand all | Expand 10 after
6241 EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes, 6271 EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes,
6242 300u * 1024u * 1024u); 6272 300u * 1024u * 1024u);
6243 EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes, 6273 EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes,
6244 150u * 1024u * 1024u); 6274 150u * 1024u * 1024u);
6245 EXPECT_EQ(host_impl_->global_tile_state().unused_memory_limit_in_bytes, 6275 EXPECT_EQ(host_impl_->global_tile_state().unused_memory_limit_in_bytes,
6246 75u * 1024u * 1024u); 6276 75u * 1024u * 1024u);
6247 } 6277 }
6248 6278
6249 } // namespace 6279 } // namespace
6250 } // namespace cc 6280 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698