Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/scheduler/renderer/renderer_scheduler_impl.h" | 5 #include "components/scheduler/renderer/renderer_scheduler_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 354 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
| 355 } | 355 } |
| 356 scheduler_->DidHandleInputEventOnCompositorThread( | 356 scheduler_->DidHandleInputEventOnCompositorThread( |
| 357 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin), | 357 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin), |
| 358 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 358 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
| 359 scheduler_->DidHandleInputEventOnCompositorThread( | 359 scheduler_->DidHandleInputEventOnCompositorThread( |
| 360 FakeInputEvent(blink::WebInputEvent::GestureScrollUpdate), | 360 FakeInputEvent(blink::WebInputEvent::GestureScrollUpdate), |
| 361 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 361 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
| 362 } | 362 } |
| 363 | 363 |
| 364 void SimulateMainThreadGestureWithCancelledScroll() { | 364 // Simulate a gesture where there is an active compositor scroll, but no |
| 365 // scroll updates are generated. Instead, the main thread handles | |
| 366 // non-canceleable touch events, making this an effectively main thread | |
| 367 // driven gesture. | |
| 368 void SimulateMainThreadGestureWithoutScrollUpdates() { | |
| 365 scheduler_->DidHandleInputEventOnCompositorThread( | 369 scheduler_->DidHandleInputEventOnCompositorThread( |
| 366 FakeInputEvent(blink::WebInputEvent::TouchStart), | 370 FakeInputEvent(blink::WebInputEvent::TouchStart), |
| 367 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 371 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
| 368 scheduler_->DidHandleInputEventOnCompositorThread( | 372 scheduler_->DidHandleInputEventOnCompositorThread( |
| 369 FakeInputEvent(blink::WebInputEvent::TouchMove), | 373 FakeInputEvent(blink::WebInputEvent::TouchMove), |
| 370 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 374 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
| 371 scheduler_->DidHandleInputEventOnCompositorThread( | 375 scheduler_->DidHandleInputEventOnCompositorThread( |
| 372 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin), | 376 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin), |
| 373 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 377 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
| 374 scheduler_->DidHandleInputEventOnCompositorThread( | 378 scheduler_->DidHandleInputEventOnCompositorThread( |
| 375 FakeInputEvent(blink::WebInputEvent::TouchMove), | 379 FakeInputEvent(blink::WebInputEvent::TouchMove), |
| 376 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 380 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
| 377 } | 381 } |
| 378 | 382 |
| 383 // Simulate a gesture where the main thread handles touch events but does not | |
| 384 // preventDefault(), allowing the gesture to turn into a compositor driven | |
| 385 // gesture. This function also verifies the necessary policy updates are | |
| 386 // scheduled. | |
| 387 void SimulateMainThreadGestureWithoutPreventDefault() { | |
| 388 scheduler_->DidHandleInputEventOnCompositorThread( | |
| 389 FakeInputEvent(blink::WebInputEvent::TouchStart), | |
| 390 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | |
| 391 | |
| 392 // Touchstart policy update. | |
| 393 EXPECT_TRUE(scheduler_->PolicyNeedsUpdateForTesting()); | |
| 394 scheduler_->ForceUpdatePolicy(); | |
|
alex clarke (OOO till 29th)
2016/05/11 17:06:52
Perhaps assert on the policy - to double check wha
Sami
2016/05/11 18:00:10
Good idea, done.
| |
| 395 EXPECT_FALSE(scheduler_->PolicyNeedsUpdateForTesting()); | |
| 396 | |
| 397 scheduler_->DidHandleInputEventOnCompositorThread( | |
| 398 FakeInputEvent(blink::WebInputEvent::TouchMove), | |
| 399 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | |
| 400 scheduler_->DidHandleInputEventOnCompositorThread( | |
| 401 FakeInputEvent(blink::WebInputEvent::GestureTapCancel), | |
| 402 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | |
| 403 scheduler_->DidHandleInputEventOnCompositorThread( | |
| 404 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin), | |
| 405 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | |
| 406 | |
| 407 // Main thread gesture policy update. | |
| 408 EXPECT_TRUE(scheduler_->PolicyNeedsUpdateForTesting()); | |
| 409 scheduler_->ForceUpdatePolicy(); | |
| 410 EXPECT_FALSE(scheduler_->PolicyNeedsUpdateForTesting()); | |
| 411 | |
| 412 scheduler_->DidHandleInputEventOnCompositorThread( | |
| 413 FakeInputEvent(blink::WebInputEvent::GestureScrollUpdate), | |
| 414 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | |
| 415 scheduler_->DidHandleInputEventOnCompositorThread( | |
| 416 FakeInputEvent(blink::WebInputEvent::TouchScrollStarted), | |
| 417 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | |
| 418 scheduler_->DidHandleInputEventOnCompositorThread( | |
| 419 FakeInputEvent(blink::WebInputEvent::TouchMove), | |
| 420 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | |
| 421 | |
| 422 // Compositor thread gesture policy update. | |
| 423 EXPECT_TRUE(scheduler_->PolicyNeedsUpdateForTesting()); | |
| 424 scheduler_->ForceUpdatePolicy(); | |
| 425 EXPECT_FALSE(scheduler_->PolicyNeedsUpdateForTesting()); | |
| 426 } | |
| 427 | |
| 379 void SimulateMainThreadGestureStart(TouchEventPolicy touch_event_policy, | 428 void SimulateMainThreadGestureStart(TouchEventPolicy touch_event_policy, |
| 380 blink::WebInputEvent::Type gesture_type) { | 429 blink::WebInputEvent::Type gesture_type) { |
| 381 if (touch_event_policy == TouchEventPolicy::SEND_TOUCH_START) { | 430 if (touch_event_policy == TouchEventPolicy::SEND_TOUCH_START) { |
| 382 scheduler_->DidHandleInputEventOnCompositorThread( | 431 scheduler_->DidHandleInputEventOnCompositorThread( |
| 383 FakeInputEvent(blink::WebInputEvent::TouchStart), | 432 FakeInputEvent(blink::WebInputEvent::TouchStart), |
| 384 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 433 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
| 385 scheduler_->DidHandleInputEventOnMainThread( | 434 scheduler_->DidHandleInputEventOnMainThread( |
| 386 FakeInputEvent(blink::WebInputEvent::TouchStart)); | 435 FakeInputEvent(blink::WebInputEvent::TouchStart)); |
| 387 | 436 |
| 388 scheduler_->DidHandleInputEventOnCompositorThread( | 437 scheduler_->DidHandleInputEventOnCompositorThread( |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 807 SimulateCompositorGestureStart(TouchEventPolicy::SEND_TOUCH_START); | 856 SimulateCompositorGestureStart(TouchEventPolicy::SEND_TOUCH_START); |
| 808 RunUntilIdle(); | 857 RunUntilIdle(); |
| 809 EXPECT_THAT(run_order, | 858 EXPECT_THAT(run_order, |
| 810 testing::ElementsAre(std::string("L1"), std::string("D1"), | 859 testing::ElementsAre(std::string("L1"), std::string("D1"), |
| 811 std::string("D2"), std::string("I1"), | 860 std::string("D2"), std::string("I1"), |
| 812 std::string("C1"), std::string("C2"))); | 861 std::string("C1"), std::string("C2"))); |
| 813 EXPECT_EQ(RendererScheduler::UseCase::COMPOSITOR_GESTURE, CurrentUseCase()); | 862 EXPECT_EQ(RendererScheduler::UseCase::COMPOSITOR_GESTURE, CurrentUseCase()); |
| 814 } | 863 } |
| 815 | 864 |
| 816 TEST_F(RendererSchedulerImplTest, | 865 TEST_F(RendererSchedulerImplTest, |
| 817 TestCompositorPolicy_MainThreadHandlesInput_WithCancelledScroll) { | 866 TestCompositorPolicy_MainThreadHandlesInput_WithoutScrollUpdates) { |
| 818 std::vector<std::string> run_order; | 867 std::vector<std::string> run_order; |
| 819 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); | 868 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); |
| 820 | 869 |
| 821 scheduler_->SetHasVisibleRenderWidgetWithTouchHandler(true); | 870 scheduler_->SetHasVisibleRenderWidgetWithTouchHandler(true); |
| 822 EnableIdleTasks(); | 871 EnableIdleTasks(); |
| 823 SimulateMainThreadGestureWithCancelledScroll(); | 872 SimulateMainThreadGestureWithoutScrollUpdates(); |
| 824 RunUntilIdle(); | 873 RunUntilIdle(); |
| 825 EXPECT_THAT(run_order, | 874 EXPECT_THAT(run_order, |
| 826 testing::ElementsAre(std::string("C1"), std::string("C2"), | 875 testing::ElementsAre(std::string("C1"), std::string("C2"), |
| 827 std::string("L1"), std::string("D1"), | 876 std::string("L1"), std::string("D1"), |
| 828 std::string("D2"), std::string("I1"))); | 877 std::string("D2"), std::string("I1"))); |
| 829 EXPECT_EQ(RendererScheduler::UseCase::MAIN_THREAD_GESTURE, CurrentUseCase()); | 878 EXPECT_EQ(RendererScheduler::UseCase::MAIN_THREAD_GESTURE, CurrentUseCase()); |
| 830 } | 879 } |
| 831 | 880 |
| 832 TEST_F(RendererSchedulerImplTest, | 881 TEST_F(RendererSchedulerImplTest, |
| 882 TestCompositorPolicy_MainThreadHandlesInput_WithoutPreventDefault) { | |
| 883 std::vector<std::string> run_order; | |
| 884 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); | |
| 885 | |
| 886 scheduler_->SetHasVisibleRenderWidgetWithTouchHandler(true); | |
| 887 EnableIdleTasks(); | |
| 888 SimulateMainThreadGestureWithoutPreventDefault(); | |
| 889 RunUntilIdle(); | |
| 890 EXPECT_THAT(run_order, | |
| 891 testing::ElementsAre(std::string("L1"), std::string("D1"), | |
| 892 std::string("D2"), std::string("I1"), | |
| 893 std::string("C1"), std::string("C2"))); | |
| 894 EXPECT_EQ(RendererScheduler::UseCase::COMPOSITOR_GESTURE, CurrentUseCase()); | |
| 895 } | |
| 896 | |
| 897 TEST_F(RendererSchedulerImplTest, | |
| 833 TestCompositorPolicy_CompositorHandlesInput_LongGestureDuration) { | 898 TestCompositorPolicy_CompositorHandlesInput_LongGestureDuration) { |
| 834 scheduler_->SetHasVisibleRenderWidgetWithTouchHandler(true); | 899 scheduler_->SetHasVisibleRenderWidgetWithTouchHandler(true); |
| 835 EnableIdleTasks(); | 900 EnableIdleTasks(); |
| 836 SimulateCompositorGestureStart(TouchEventPolicy::SEND_TOUCH_START); | 901 SimulateCompositorGestureStart(TouchEventPolicy::SEND_TOUCH_START); |
| 837 | 902 |
| 838 base::TimeTicks loop_end_time = | 903 base::TimeTicks loop_end_time = |
| 839 clock_->NowTicks() + base::TimeDelta::FromMilliseconds( | 904 clock_->NowTicks() + base::TimeDelta::FromMilliseconds( |
| 840 UserModel::kMedianGestureDurationMillis * 2); | 905 UserModel::kMedianGestureDurationMillis * 2); |
| 841 | 906 |
| 842 // The UseCase::COMPOSITOR_GESTURE usecase initially deprioritizes compositor | 907 // The UseCase::COMPOSITOR_GESTURE usecase initially deprioritizes compositor |
| (...skipping 2074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2917 } | 2982 } |
| 2918 | 2983 |
| 2919 // Timer tasks should not have been starved by the expensive compositor | 2984 // Timer tasks should not have been starved by the expensive compositor |
| 2920 // tasks. | 2985 // tasks. |
| 2921 EXPECT_EQ(TaskQueue::NORMAL_PRIORITY, | 2986 EXPECT_EQ(TaskQueue::NORMAL_PRIORITY, |
| 2922 scheduler_->CompositorTaskRunner()->GetQueuePriority()); | 2987 scheduler_->CompositorTaskRunner()->GetQueuePriority()); |
| 2923 EXPECT_EQ(1000u, run_order.size()); | 2988 EXPECT_EQ(1000u, run_order.size()); |
| 2924 } | 2989 } |
| 2925 | 2990 |
| 2926 } // namespace scheduler | 2991 } // namespace scheduler |
| OLD | NEW |