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 "content/renderer/scheduler/renderer_scheduler_impl.h" | 5 #include "content/renderer/scheduler/renderer_scheduler_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "base/trace_event/trace_event_argument.h" | 10 #include "base/trace_event/trace_event_argument.h" |
11 #include "cc/output/begin_frame_args.h" | 11 #include "cc/output/begin_frame_args.h" |
12 #include "content/child/scheduler/nestable_single_thread_task_runner.h" | 12 #include "content/child/scheduler/nestable_single_thread_task_runner.h" |
13 #include "content/child/scheduler/prioritizing_task_queue_selector.h" | 13 #include "content/child/scheduler/prioritizing_task_queue_selector.h" |
14 #include "ui/gfx/frame_time.h" | 14 #include "ui/gfx/frame_time.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 RendererSchedulerImpl::RendererSchedulerImpl( | 18 RendererSchedulerImpl::RendererSchedulerImpl( |
19 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner) | 19 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner) |
20 : helper_(main_task_runner, | 20 : helper_(main_task_runner, |
21 this, | 21 this, |
22 "renderer.scheduler", | 22 "renderer.scheduler", |
23 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), | 23 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), |
24 TASK_QUEUE_COUNT, | 24 TASK_QUEUE_COUNT, |
25 base::TimeDelta()), | 25 base::TimeDelta()), |
26 control_task_runner_(helper_.ControlTaskRunner()), | 26 control_task_runner_(helper_.ControlTaskRunner()), |
27 compositor_task_runner_( | 27 compositor_task_runner_( |
28 helper_.SchedulerTaskQueueManager()->TaskRunnerForQueue( | 28 helper_.TaskRunnerForQueue(COMPOSITOR_TASK_QUEUE)), |
29 COMPOSITOR_TASK_QUEUE)), | 29 loading_task_runner_(helper_.TaskRunnerForQueue(LOADING_TASK_QUEUE)), |
30 loading_task_runner_( | 30 timer_task_runner_(helper_.TaskRunnerForQueue(TIMER_TASK_QUEUE)), |
31 helper_.SchedulerTaskQueueManager()->TaskRunnerForQueue( | |
32 LOADING_TASK_QUEUE)), | |
33 timer_task_runner_( | |
34 helper_.SchedulerTaskQueueManager()->TaskRunnerForQueue( | |
35 TIMER_TASK_QUEUE)), | |
36 delayed_update_policy_runner_( | 31 delayed_update_policy_runner_( |
37 base::Bind(&RendererSchedulerImpl::UpdatePolicy, | 32 base::Bind(&RendererSchedulerImpl::UpdatePolicy, |
38 base::Unretained(this)), | 33 base::Unretained(this)), |
39 helper_.ControlTaskRunner()), | 34 helper_.ControlTaskRunner()), |
40 current_policy_(Policy::NORMAL), | 35 current_policy_(Policy::NORMAL), |
41 renderer_hidden_(false), | 36 renderer_hidden_(false), |
42 last_input_type_(blink::WebInputEvent::Undefined), | 37 last_input_type_(blink::WebInputEvent::Undefined), |
43 input_stream_state_(InputStreamState::INACTIVE), | 38 input_stream_state_(InputStreamState::INACTIVE), |
44 policy_may_need_update_(&incoming_signals_lock_), | 39 policy_may_need_update_(&incoming_signals_lock_), |
45 timer_queue_suspend_count_(0), | 40 timer_queue_suspend_count_(0), |
46 weak_factory_(this) { | 41 weak_factory_(this) { |
47 update_policy_closure_ = base::Bind(&RendererSchedulerImpl::UpdatePolicy, | 42 update_policy_closure_ = base::Bind(&RendererSchedulerImpl::UpdatePolicy, |
48 weak_factory_.GetWeakPtr()); | 43 weak_factory_.GetWeakPtr()); |
49 end_renderer_hidden_idle_period_closure_.Reset(base::Bind( | 44 end_renderer_hidden_idle_period_closure_.Reset(base::Bind( |
50 &RendererSchedulerImpl::EndIdlePeriod, weak_factory_.GetWeakPtr())); | 45 &RendererSchedulerImpl::EndIdlePeriod, weak_factory_.GetWeakPtr())); |
51 | 46 |
52 for (size_t i = SchedulerHelper::TASK_QUEUE_COUNT; | 47 for (size_t i = SchedulerHelper::TASK_QUEUE_COUNT; |
53 i < TASK_QUEUE_COUNT; | 48 i < TASK_QUEUE_COUNT; |
54 i++) { | 49 i++) { |
55 helper_.SchedulerTaskQueueManager()->SetQueueName( | 50 helper_.SetQueueName(i, TaskQueueIdToString(static_cast<QueueId>(i))); |
56 i, TaskQueueIdToString(static_cast<QueueId>(i))); | |
57 } | 51 } |
58 TRACE_EVENT_OBJECT_CREATED_WITH_ID( | 52 TRACE_EVENT_OBJECT_CREATED_WITH_ID( |
59 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler", | 53 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler", |
60 this); | 54 this); |
61 } | 55 } |
62 | 56 |
63 RendererSchedulerImpl::~RendererSchedulerImpl() { | 57 RendererSchedulerImpl::~RendererSchedulerImpl() { |
64 TRACE_EVENT_OBJECT_DELETED_WITH_ID( | 58 TRACE_EVENT_OBJECT_DELETED_WITH_ID( |
65 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler", | 59 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler", |
66 this); | 60 this); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 // We only yield if we are in the compositor priority and there is compositor | 284 // We only yield if we are in the compositor priority and there is compositor |
291 // work outstanding, or if we are in the touchstart response priority. | 285 // work outstanding, or if we are in the touchstart response priority. |
292 // Note: even though the control queue is higher priority we don't yield for | 286 // Note: even though the control queue is higher priority we don't yield for |
293 // it since these tasks are not user-provided work and they are only intended | 287 // it since these tasks are not user-provided work and they are only intended |
294 // to run before the next task, not interrupt the tasks. | 288 // to run before the next task, not interrupt the tasks. |
295 switch (SchedulerPolicy()) { | 289 switch (SchedulerPolicy()) { |
296 case Policy::NORMAL: | 290 case Policy::NORMAL: |
297 return false; | 291 return false; |
298 | 292 |
299 case Policy::COMPOSITOR_PRIORITY: | 293 case Policy::COMPOSITOR_PRIORITY: |
300 return !helper_.SchedulerTaskQueueManager()->IsQueueEmpty( | 294 return !helper_.IsQueueEmpty(COMPOSITOR_TASK_QUEUE); |
301 COMPOSITOR_TASK_QUEUE); | |
302 | 295 |
303 case Policy::TOUCHSTART_PRIORITY: | 296 case Policy::TOUCHSTART_PRIORITY: |
304 return true; | 297 return true; |
305 | 298 |
306 default: | 299 default: |
307 NOTREACHED(); | 300 NOTREACHED(); |
308 return false; | 301 return false; |
309 } | 302 } |
310 } | 303 } |
311 | 304 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 base::TimeTicks now) const { | 447 base::TimeTicks now) const { |
455 helper_.CheckOnValidThread(); | 448 helper_.CheckOnValidThread(); |
456 // TODO(rmcilroy): Change this to DCHECK_EQ when crbug.com/463869 is fixed. | 449 // TODO(rmcilroy): Change this to DCHECK_EQ when crbug.com/463869 is fixed. |
457 DCHECK(input_stream_state_ != InputStreamState::INACTIVE); | 450 DCHECK(input_stream_state_ != InputStreamState::INACTIVE); |
458 incoming_signals_lock_.AssertAcquired(); | 451 incoming_signals_lock_.AssertAcquired(); |
459 | 452 |
460 base::TimeDelta escalated_priority_duration = | 453 base::TimeDelta escalated_priority_duration = |
461 base::TimeDelta::FromMilliseconds(kPriorityEscalationAfterInputMillis); | 454 base::TimeDelta::FromMilliseconds(kPriorityEscalationAfterInputMillis); |
462 base::TimeDelta time_left_in_policy; | 455 base::TimeDelta time_left_in_policy; |
463 if (last_input_process_time_on_main_.is_null() && | 456 if (last_input_process_time_on_main_.is_null() && |
464 !helper_.SchedulerTaskQueueManager()->IsQueueEmpty( | 457 !helper_.IsQueueEmpty(COMPOSITOR_TASK_QUEUE)) { |
465 COMPOSITOR_TASK_QUEUE)) { | |
466 // If the input event is still pending, go into input prioritized policy | 458 // If the input event is still pending, go into input prioritized policy |
467 // and check again later. | 459 // and check again later. |
468 time_left_in_policy = escalated_priority_duration; | 460 time_left_in_policy = escalated_priority_duration; |
469 } else { | 461 } else { |
470 // Otherwise make sure the input prioritization policy ends on time. | 462 // Otherwise make sure the input prioritization policy ends on time. |
471 base::TimeTicks new_priority_end( | 463 base::TimeTicks new_priority_end( |
472 std::max(last_input_receipt_time_on_compositor_, | 464 std::max(last_input_receipt_time_on_compositor_, |
473 last_input_process_time_on_main_) + | 465 last_input_process_time_on_main_) + |
474 escalated_priority_duration); | 466 escalated_priority_duration); |
475 time_left_in_policy = new_priority_end - now; | 467 time_left_in_policy = new_priority_end - now; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 // meaningful touchstart response and should not impact task priority. | 632 // meaningful touchstart response and should not impact task priority. |
641 return current_state; | 633 return current_state; |
642 | 634 |
643 default: | 635 default: |
644 break; | 636 break; |
645 } | 637 } |
646 return InputStreamState::ACTIVE; | 638 return InputStreamState::ACTIVE; |
647 } | 639 } |
648 | 640 |
649 } // namespace content | 641 } // namespace content |
OLD | NEW |