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

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/renderer/renderer_scheduler_impl.cc

Issue 2266883002: scheduler: Reset gesture state at start of a mouse drag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 3 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
OLDNEW
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 "platform/scheduler/renderer/renderer_scheduler_impl.h" 5 #include "platform/scheduler/renderer/renderer_scheduler_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/stack_trace.h" 8 #include "base/debug/stack_trace.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 461
462 bool RendererSchedulerImpl::PolicyNeedsUpdateForTesting() { 462 bool RendererSchedulerImpl::PolicyNeedsUpdateForTesting() {
463 return policy_may_need_update_.IsSet(); 463 return policy_may_need_update_.IsSet();
464 } 464 }
465 465
466 // static 466 // static
467 bool RendererSchedulerImpl::ShouldPrioritizeInputEvent( 467 bool RendererSchedulerImpl::ShouldPrioritizeInputEvent(
468 const blink::WebInputEvent& web_input_event) { 468 const blink::WebInputEvent& web_input_event) {
469 // We regard MouseMove events with the left mouse button down as a signal 469 // We regard MouseMove events with the left mouse button down as a signal
470 // that the user is doing something requiring a smooth frame rate. 470 // that the user is doing something requiring a smooth frame rate.
471 if (web_input_event.type == blink::WebInputEvent::MouseMove && 471 if ((web_input_event.type == blink::WebInputEvent::MouseDown ||
alex clarke (OOO till 29th) 2016/08/22 11:30:09 Are we going to start blocking expensive tasks if
Sami 2016/08/22 13:25:14 Right, we wouldn't want to do blocking based on a
472 web_input_event.type == blink::WebInputEvent::MouseMove) &&
472 (web_input_event.modifiers & blink::WebInputEvent::LeftButtonDown)) { 473 (web_input_event.modifiers & blink::WebInputEvent::LeftButtonDown)) {
473 return true; 474 return true;
474 } 475 }
475 // Ignore all other mouse events because they probably don't signal user 476 // Ignore all other mouse events because they probably don't signal user
476 // interaction needing a smooth framerate. NOTE isMouseEventType returns false 477 // interaction needing a smooth framerate. NOTE isMouseEventType returns false
477 // for mouse wheel events, hence we regard them as user input. 478 // for mouse wheel events, hence we regard them as user input.
478 // Ignore keyboard events because it doesn't really make sense to enter 479 // Ignore keyboard events because it doesn't really make sense to enter
479 // compositor priority for them. 480 // compositor priority for them.
480 if (blink::WebInputEvent::isMouseEventType(web_input_event.type) || 481 if (blink::WebInputEvent::isMouseEventType(web_input_event.type) ||
481 blink::WebInputEvent::isKeyboardEventType(web_input_event.type)) { 482 blink::WebInputEvent::isKeyboardEventType(web_input_event.type)) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 UseCase previous_use_case = 522 UseCase previous_use_case =
522 ComputeCurrentUseCase(now, &unused_policy_duration); 523 ComputeCurrentUseCase(now, &unused_policy_duration);
523 bool was_awaiting_touch_start_response = 524 bool was_awaiting_touch_start_response =
524 AnyThread().awaiting_touch_start_response; 525 AnyThread().awaiting_touch_start_response;
525 526
526 AnyThread().user_model.DidStartProcessingInputEvent(type, now); 527 AnyThread().user_model.DidStartProcessingInputEvent(type, now);
527 528
528 if (input_event_state == InputEventState::EVENT_CONSUMED_BY_COMPOSITOR) 529 if (input_event_state == InputEventState::EVENT_CONSUMED_BY_COMPOSITOR)
529 AnyThread().user_model.DidFinishProcessingInputEvent(now); 530 AnyThread().user_model.DidFinishProcessingInputEvent(now);
530 531
531 if (type) { 532 if (type != blink::WebInputEvent::Undefined) {
alex clarke (OOO till 29th) 2016/08/22 11:30:09 Perhaps handle this as a case in the switch?
Sami 2016/08/22 13:25:15 Good idea -- makes more sense that way.
532 switch (type) { 533 switch (type) {
533 case blink::WebInputEvent::TouchStart: 534 case blink::WebInputEvent::TouchStart:
534 AnyThread().awaiting_touch_start_response = true; 535 AnyThread().awaiting_touch_start_response = true;
535 // This is just a fail-safe to reset the state of 536 // This is just a fail-safe to reset the state of
536 // |last_gesture_was_compositor_driven| to the default. We don't know 537 // |last_gesture_was_compositor_driven| to the default. We don't know
537 // yet where the gesture will run. 538 // yet where the gesture will run.
538 AnyThread().last_gesture_was_compositor_driven = false; 539 AnyThread().last_gesture_was_compositor_driven = false;
539 AnyThread().have_seen_touchstart = true; 540 AnyThread().have_seen_touchstart = true;
540 // Assume the default gesture is prevented until we see evidence 541 // Assume the default gesture is prevented until we see evidence
541 // otherwise. 542 // otherwise.
(...skipping 27 matching lines...) Expand all
569 AnyThread().fling_compositor_escalation_deadline = base::TimeTicks(); 570 AnyThread().fling_compositor_escalation_deadline = base::TimeTicks();
570 break; 571 break;
571 572
572 case blink::WebInputEvent::GestureTapDown: 573 case blink::WebInputEvent::GestureTapDown:
573 case blink::WebInputEvent::GestureShowPress: 574 case blink::WebInputEvent::GestureShowPress:
574 case blink::WebInputEvent::GestureScrollEnd: 575 case blink::WebInputEvent::GestureScrollEnd:
575 // With no observable effect, these meta events do not indicate a 576 // With no observable effect, these meta events do not indicate a
576 // meaningful touchstart response and should not impact task priority. 577 // meaningful touchstart response and should not impact task priority.
577 break; 578 break;
578 579
580 case blink::WebInputEvent::MouseDown:
581 // Reset tracking state at the start of a new mouse drag gesture.
582 AnyThread().last_gesture_was_compositor_driven = false;
583 AnyThread().default_gesture_prevented = true;
584 break;
585
586 case blink::WebInputEvent::MouseMove:
587 // Consider mouse movement with the left button held down (see
588 // ShouldPrioritizeInputEvent) similarly to a touch gesture.
589 AnyThread().last_gesture_was_compositor_driven =
590 input_event_state == InputEventState::EVENT_CONSUMED_BY_COMPOSITOR;
591 AnyThread().awaiting_touch_start_response = false;
592 break;
593
579 default: 594 default:
580 AnyThread().awaiting_touch_start_response = false; 595 AnyThread().awaiting_touch_start_response = false;
581 break; 596 break;
582 } 597 }
583 } 598 }
584 599
585 // Avoid unnecessary policy updates if the use case did not change. 600 // Avoid unnecessary policy updates if the use case did not change.
586 UseCase use_case = ComputeCurrentUseCase(now, &unused_policy_duration); 601 UseCase use_case = ComputeCurrentUseCase(now, &unused_policy_duration);
587 602
588 if (use_case != previous_use_case || 603 if (use_case != previous_use_case ||
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 // Yes a gesture has been established. Based on how the gesture is handled 1027 // Yes a gesture has been established. Based on how the gesture is handled
1013 // we need to choose between one of four use cases: 1028 // we need to choose between one of four use cases:
1014 // 1. COMPOSITOR_GESTURE where the gesture is processed only on the 1029 // 1. COMPOSITOR_GESTURE where the gesture is processed only on the
1015 // compositor thread. 1030 // compositor thread.
1016 // 2. MAIN_THREAD_GESTURE where the gesture is processed only on the main 1031 // 2. MAIN_THREAD_GESTURE where the gesture is processed only on the main
1017 // thread. 1032 // thread.
1018 // 3. MAIN_THREAD_CUSTOM_INPUT_HANDLING where the main thread processes a 1033 // 3. MAIN_THREAD_CUSTOM_INPUT_HANDLING where the main thread processes a
1019 // stream of input events and has prevented a default gesture from being 1034 // stream of input events and has prevented a default gesture from being
1020 // started. 1035 // started.
1021 // 4. SYNCHRONIZED_GESTURE where the gesture is processed on both threads. 1036 // 4. SYNCHRONIZED_GESTURE where the gesture is processed on both threads.
1022 // TODO(skyostil): Consider removing in_idle_period_ and
1023 // HadAnIdlePeriodRecently() unless we need them here.
1024 if (AnyThread().last_gesture_was_compositor_driven) { 1037 if (AnyThread().last_gesture_was_compositor_driven) {
1025 if (AnyThread().begin_main_frame_on_critical_path) { 1038 if (AnyThread().begin_main_frame_on_critical_path) {
1026 return UseCase::SYNCHRONIZED_GESTURE; 1039 return UseCase::SYNCHRONIZED_GESTURE;
1027 } else { 1040 } else {
1028 return UseCase::COMPOSITOR_GESTURE; 1041 return UseCase::COMPOSITOR_GESTURE;
1029 } 1042 }
1030 } 1043 }
1031 if (AnyThread().default_gesture_prevented) { 1044 if (AnyThread().default_gesture_prevented) {
1032 return UseCase::MAIN_THREAD_CUSTOM_INPUT_HANDLING; 1045 return UseCase::MAIN_THREAD_CUSTOM_INPUT_HANDLING;
1033 } else { 1046 } else {
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), 1287 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"),
1275 "RendererSchedulerImpl::OnNavigationStarted"); 1288 "RendererSchedulerImpl::OnNavigationStarted");
1276 base::AutoLock lock(any_thread_lock_); 1289 base::AutoLock lock(any_thread_lock_);
1277 AnyThread().rails_loading_priority_deadline = 1290 AnyThread().rails_loading_priority_deadline =
1278 helper_.scheduler_tqm_delegate()->NowTicks() + 1291 helper_.scheduler_tqm_delegate()->NowTicks() +
1279 base::TimeDelta::FromMilliseconds( 1292 base::TimeDelta::FromMilliseconds(
1280 kRailsInitialLoadingPrioritizationMillis); 1293 kRailsInitialLoadingPrioritizationMillis);
1281 ResetForNavigationLocked(); 1294 ResetForNavigationLocked();
1282 } 1295 }
1283 1296
1284 bool RendererSchedulerImpl::HadAnIdlePeriodRecently(base::TimeTicks now) const {
1285 return (now - AnyThread().last_idle_period_end_time) <=
1286 base::TimeDelta::FromMilliseconds(
1287 kIdlePeriodStarvationThresholdMillis);
1288 }
1289
1290 void RendererSchedulerImpl::SuspendTimerQueueWhenBackgrounded() { 1297 void RendererSchedulerImpl::SuspendTimerQueueWhenBackgrounded() {
1291 DCHECK(MainThreadOnly().renderer_backgrounded); 1298 DCHECK(MainThreadOnly().renderer_backgrounded);
1292 if (MainThreadOnly().timer_queue_suspended_when_backgrounded) 1299 if (MainThreadOnly().timer_queue_suspended_when_backgrounded)
1293 return; 1300 return;
1294 1301
1295 MainThreadOnly().timer_queue_suspended_when_backgrounded = true; 1302 MainThreadOnly().timer_queue_suspended_when_backgrounded = true;
1296 ForceUpdatePolicy(); 1303 ForceUpdatePolicy();
1297 } 1304 }
1298 1305
1299 void RendererSchedulerImpl::ResumeTimerQueueWhenForegrounded() { 1306 void RendererSchedulerImpl::ResumeTimerQueueWhenForegrounded() {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 case v8::PERFORMANCE_LOAD: 1495 case v8::PERFORMANCE_LOAD:
1489 return "load"; 1496 return "load";
1490 default: 1497 default:
1491 NOTREACHED(); 1498 NOTREACHED();
1492 return nullptr; 1499 return nullptr;
1493 } 1500 }
1494 } 1501 }
1495 1502
1496 } // namespace scheduler 1503 } // namespace scheduler
1497 } // namespace blink 1504 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698