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

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

Issue 26880010: gfx: Add FrameTime and DisplayTime classes (Closed) Base URL: http://git.chromium.org/chromium/src.git@checkHighResNow4
Patch Set: WIP Created 7 years, 1 month 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
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_host_unittest_animation.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 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 const LayerTreeSettings& settings, 1142 const LayerTreeSettings& settings,
1143 LayerTreeHostImplClient* client, 1143 LayerTreeHostImplClient* client,
1144 Proxy* proxy, 1144 Proxy* proxy,
1145 RenderingStatsInstrumentation* rendering_stats_instrumentation) 1145 RenderingStatsInstrumentation* rendering_stats_instrumentation)
1146 : LayerTreeHostImpl(settings, 1146 : LayerTreeHostImpl(settings,
1147 client, 1147 client,
1148 proxy, 1148 proxy,
1149 rendering_stats_instrumentation, 1149 rendering_stats_instrumentation,
1150 NULL) {} 1150 NULL) {}
1151 1151
1152 virtual base::TimeTicks CurrentPhysicalTimeTicks() const OVERRIDE { 1152 virtual base::TimeTicks CurrentPhysicalFrameTime() const OVERRIDE {
1153 return fake_current_physical_time_; 1153 return fake_current_physical_time_;
1154 } 1154 }
1155 1155
1156 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { 1156 void SetCurrentPhysicalFrameTimeForTest(base::TimeTicks fake_now) {
1157 fake_current_physical_time_ = fake_now; 1157 fake_current_physical_time_ = fake_now;
1158 } 1158 }
1159 1159
1160 private: 1160 private:
1161 base::TimeTicks fake_current_physical_time_; 1161 base::TimeTicks fake_current_physical_time_;
1162 }; 1162 };
1163 1163
1164 TEST_F(LayerTreeHostImplTest, ScrollbarLinearFadeScheduling) { 1164 TEST_F(LayerTreeHostImplTest, ScrollbarLinearFadeScheduling) {
1165 LayerTreeSettings settings; 1165 LayerTreeSettings settings;
1166 settings.scrollbar_animator = LayerTreeSettings::LinearFade; 1166 settings.scrollbar_animator = LayerTreeSettings::LinearFade;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 scroll->SetVerticalScrollbarLayer(scrollbar.get()); 1201 scroll->SetVerticalScrollbarLayer(scrollbar.get());
1202 1202
1203 scroll->AddChild(contents.Pass()); 1203 scroll->AddChild(contents.Pass());
1204 root->AddChild(scroll.Pass()); 1204 root->AddChild(scroll.Pass());
1205 root->AddChild(scrollbar.PassAs<LayerImpl>()); 1205 root->AddChild(scrollbar.PassAs<LayerImpl>());
1206 1206
1207 host_impl_->active_tree()->SetRootLayer(root.Pass()); 1207 host_impl_->active_tree()->SetRootLayer(root.Pass());
1208 host_impl_->active_tree()->DidBecomeActive(); 1208 host_impl_->active_tree()->DidBecomeActive();
1209 InitializeRendererAndDrawFrame(); 1209 InitializeRendererAndDrawFrame();
1210 1210
1211 base::TimeTicks fake_now = gfx::FrameTime::Now(); 1211 gfx::FrameTime fake_now = gfx::FrameTime::Now();
1212 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); 1212 host_impl_override_time->SetCurrentPhysicalFrameTimeForTest(fake_now);
1213 1213
1214 // If no scroll happened recently, StartScrollbarAnimation should have no 1214 // If no scroll happened recently, StartScrollbarAnimation should have no
1215 // effect. 1215 // effect.
1216 host_impl_->StartScrollbarAnimation(); 1216 host_impl_->StartScrollbarAnimation();
1217 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); 1217 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1218 EXPECT_FALSE(did_request_redraw_); 1218 EXPECT_FALSE(did_request_redraw_);
1219 1219
1220 // If no scroll happened during a scroll gesture, StartScrollbarAnimation 1220 // If no scroll happened during a scroll gesture, StartScrollbarAnimation
1221 // should have no effect. 1221 // should have no effect.
1222 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel); 1222 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel);
1223 host_impl_->ScrollEnd(); 1223 host_impl_->ScrollEnd();
1224 host_impl_->StartScrollbarAnimation(); 1224 host_impl_->StartScrollbarAnimation();
1225 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); 1225 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1226 EXPECT_FALSE(did_request_redraw_); 1226 EXPECT_FALSE(did_request_redraw_);
1227 1227
1228 // After a scroll, a fade animation should be scheduled about 20ms from now. 1228 // After a scroll, a fade animation should be scheduled about 20ms from now.
1229 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel); 1229 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel);
1230 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0)); 1230 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0));
1231 host_impl_->ScrollEnd(); 1231 host_impl_->ScrollEnd();
1232 did_request_redraw_ = false; 1232 did_request_redraw_ = false;
1233 host_impl_->StartScrollbarAnimation(); 1233 host_impl_->StartScrollbarAnimation();
1234 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), 1234 EXPECT_LT(base::TimeDelta::FromMilliseconds(19),
1235 requested_scrollbar_animation_delay_); 1235 requested_scrollbar_animation_delay_);
1236 EXPECT_FALSE(did_request_redraw_); 1236 EXPECT_FALSE(did_request_redraw_);
1237 requested_scrollbar_animation_delay_ = base::TimeDelta(); 1237 requested_scrollbar_animation_delay_ = base::TimeDelta();
1238 1238
1239 // After the fade begins, we should start getting redraws instead of a 1239 // After the fade begins, we should start getting redraws instead of a
1240 // scheduled animation. 1240 // scheduled animation.
1241 fake_now += base::TimeDelta::FromMilliseconds(25); 1241 fake_now += base::TimeDelta::FromMilliseconds(25);
1242 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); 1242 host_impl_override_time->SetCurrentPhysicalFrameTimeForTest(fake_now);
1243 host_impl_->StartScrollbarAnimation(); 1243 host_impl_->StartScrollbarAnimation();
1244 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); 1244 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1245 EXPECT_TRUE(did_request_redraw_); 1245 EXPECT_TRUE(did_request_redraw_);
1246 did_request_redraw_ = false; 1246 did_request_redraw_ = false;
1247 1247
1248 // If no scroll happened recently, StartScrollbarAnimation should have no 1248 // If no scroll happened recently, StartScrollbarAnimation should have no
1249 // effect. 1249 // effect.
1250 fake_now += base::TimeDelta::FromMilliseconds(25); 1250 fake_now += base::TimeDelta::FromMilliseconds(25);
1251 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); 1251 host_impl_override_time->SetCurrentPhysicalFrameTimeForTest(fake_now);
1252 host_impl_->StartScrollbarAnimation(); 1252 host_impl_->StartScrollbarAnimation();
1253 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); 1253 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1254 EXPECT_FALSE(did_request_redraw_); 1254 EXPECT_FALSE(did_request_redraw_);
1255 1255
1256 // Setting the scroll offset outside a scroll should also cause the scrollbar 1256 // Setting the scroll offset outside a scroll should also cause the scrollbar
1257 // to appear and to schedule a fade. 1257 // to appear and to schedule a fade.
1258 host_impl_->RootScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5)); 1258 host_impl_->RootScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5));
1259 host_impl_->StartScrollbarAnimation(); 1259 host_impl_->StartScrollbarAnimation();
1260 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), 1260 EXPECT_LT(base::TimeDelta::FromMilliseconds(19),
1261 requested_scrollbar_animation_delay_); 1261 requested_scrollbar_animation_delay_);
1262 EXPECT_FALSE(did_request_redraw_); 1262 EXPECT_FALSE(did_request_redraw_);
1263 requested_scrollbar_animation_delay_ = base::TimeDelta(); 1263 requested_scrollbar_animation_delay_ = base::TimeDelta();
1264 1264
1265 // None of the above should have called CurrentFrameTimeTicks, so if we call 1265 // None of the above should have called CurrentFrameTimeTicks, so if we call
1266 // it now we should get the current time. 1266 // it now we should get the current time.
1267 fake_now += base::TimeDelta::FromMilliseconds(10); 1267 fake_now += base::TimeDelta::FromMilliseconds(10);
1268 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); 1268 host_impl_override_time->SetCurrentPhysicalFrameTimeForTest(fake_now);
1269 EXPECT_EQ(fake_now, host_impl_->CurrentFrameTimeTicks()); 1269 EXPECT_EQ(fake_now, host_impl_->CurrentFrameTimeTicks());
1270 } 1270 }
1271 1271
1272 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( 1272 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale(
1273 float device_scale_factor) { 1273 float device_scale_factor) {
1274 LayerTreeSettings settings; 1274 LayerTreeSettings settings;
1275 settings.scrollbar_animator = LayerTreeSettings::Thinning; 1275 settings.scrollbar_animator = LayerTreeSettings::Thinning;
1276 1276
1277 gfx::Size viewport_size(300, 200); 1277 gfx::Size viewport_size(300, 200);
1278 gfx::Size device_viewport_size = gfx::ToFlooredSize( 1278 gfx::Size device_viewport_size = gfx::ToFlooredSize(
(...skipping 4190 matching lines...) Expand 10 before | Expand all | Expand 10 after
5469 // The root should have scrolled. 5469 // The root should have scrolled.
5470 ASSERT_EQ(2u, scroll_info->scrolls.size()); 5470 ASSERT_EQ(2u, scroll_info->scrolls.size());
5471 ExpectContains(*scroll_info.get(), 5471 ExpectContains(*scroll_info.get(),
5472 host_impl_->active_tree()->root_layer()->id(), 5472 host_impl_->active_tree()->root_layer()->id(),
5473 gfx::Vector2d(0, 10)); 5473 gfx::Vector2d(0, 10));
5474 } 5474 }
5475 } 5475 }
5476 5476
5477 } // namespace 5477 } // namespace
5478 } // namespace cc 5478 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_host_unittest_animation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698