Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_H_ | |
| 6 #define CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_H_ | |
| 7 | |
| 8 #include "base/atomicops.h" | |
| 9 #include "base/synchronization/lock.h" | |
| 10 #include "base/threading/thread_checker.h" | |
| 11 #include "content/renderer/scheduler/single_thread_idle_task_runner.h" | |
| 12 #include "content/renderer/scheduler/task_queue_manager.h" | |
| 13 | |
| 14 namespace cc { | |
| 15 struct BeginFrameArgs; | |
| 16 } | |
| 17 | |
| 18 namespace content { | |
| 19 | |
| 20 class RendererSchedulerSelector; | |
| 21 | |
| 22 class RendererScheduler : private IdleTaskDeadlineSupplier { | |
| 23 public: | |
| 24 RendererScheduler(); | |
| 25 virtual ~RendererScheduler(); | |
| 26 | |
| 27 // Returns the default task runner. | |
| 28 scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner(); | |
| 29 | |
| 30 // Returns the compositor task runner. | |
| 31 scoped_refptr<base::SingleThreadTaskRunner> CompositorTaskRunner(); | |
| 32 | |
| 33 // Returns the idle task runner. Tasks posted to this runner may be reordered | |
| 34 // relative to other task types and may be starved for an arbitrarily long | |
| 35 // time if no idle time is available. | |
| 36 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner(); | |
| 37 | |
| 38 // Called to notify about the start of a new frame. Must be called from the | |
| 39 // main thread. | |
| 40 void WillBeginFrame(const cc::BeginFrameArgs& args); | |
| 41 | |
| 42 // Called to notify that a previously begun frame was committed. Must be | |
| 43 // called from the main thread. | |
| 44 void DidCommitFrameToCompositor(); | |
| 45 | |
| 46 // Tells the scheduler that the system received an input event. Can be called | |
| 47 // on any thread. | |
| 48 void DidReceiveInputEvent(); | |
| 49 | |
| 50 // Returns true if there is high priority work pending on the main thread | |
| 51 // and the caller should yield to let the scheduler service that work. | |
| 52 // Must be called from the main thread. | |
| 53 bool ShouldYieldForHighPriorityWork(); | |
| 54 | |
| 55 protected: | |
| 56 RendererScheduler( | |
| 57 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_); | |
|
Sami
2014/10/24 10:46:13
Extra underscore at the end.
rmcilroy
2014/10/24 14:58:29
Done.
| |
| 58 | |
| 59 // Virtual for testing. | |
| 60 virtual base::TimeTicks Now() const; | |
| 61 | |
| 62 private: | |
| 63 friend base::WeakPtr<content::IdleTaskDeadlineSupplier>; | |
| 64 friend class RendererSchedulerTest; | |
| 65 | |
| 66 enum QueueId { | |
| 67 kDefaultTaskQueue, | |
| 68 kCompositorTaskQueue, | |
| 69 kIdleTaskQueue, | |
| 70 kControlTaskQueue, | |
| 71 // Must be the last entry. | |
| 72 kTaskQueueCount, | |
| 73 }; | |
| 74 | |
| 75 enum Policy { | |
| 76 kNormalPriorityPolicy, | |
| 77 kCompositorPriorityPolicy, | |
| 78 }; | |
| 79 | |
| 80 // The time we should stay in CompositorPriority mode for after a touch event. | |
| 81 static const int kCompositorPriorityAfterTouchMillis = 100; | |
| 82 | |
| 83 // Implementation of IdleTaskDeadlineSupplier | |
| 84 virtual base::TimeTicks CurrentIdleTaskDeadline() const override; | |
| 85 | |
| 86 // Returns the current scheduler policy. This may involve updating the | |
| 87 // current policy if a new signal has arrived. Must be called from the main | |
| 88 // thread. | |
| 89 Policy SchedulerPolicy(); | |
| 90 | |
| 91 // Updates the scheduler policy. Must be called from the main thread. | |
| 92 void UpdatePolicy(); | |
| 93 | |
| 94 // Start and end an idle period. | |
| 95 void StartIdlePeriod(); | |
| 96 void EndIdlePeriod(); | |
| 97 | |
| 98 base::ThreadChecker main_thread_checker_; | |
| 99 scoped_ptr<RendererSchedulerSelector> renderer_scheduler_selector_; | |
| 100 TaskQueueManager task_queue_manager_; | |
| 101 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_; | |
| 102 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; | |
| 103 | |
| 104 // Don't access current_policy_ directly, instead use SchedulerPolicy(). | |
| 105 base::subtle::AtomicWord policy_may_need_update_; | |
| 106 Policy current_policy_; | |
| 107 | |
| 108 base::TimeTicks estimated_next_frame_begin_; | |
| 109 | |
| 110 // The incoming_signals_lock_ mutex protects access to last_input_time_ | |
| 111 // and write access to policy_may_need_update_. | |
| 112 base::Lock incoming_signals_lock_; | |
| 113 base::TimeTicks last_input_time_; | |
| 114 | |
| 115 base::WeakPtrFactory<RendererScheduler> weak_factory_; | |
| 116 }; | |
| 117 | |
| 118 } // namespace content | |
| 119 | |
| 120 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_H_ | |
| OLD | NEW |