Index: content/renderer/scheduler/renderer_scheduler_impl.h |
diff --git a/content/renderer/scheduler/renderer_scheduler_impl.h b/content/renderer/scheduler/renderer_scheduler_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..555573d19f3a4dc0cada0bc4f2cdc8764065ad34 |
--- /dev/null |
+++ b/content/renderer/scheduler/renderer_scheduler_impl.h |
@@ -0,0 +1,123 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ |
+#define CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ |
+ |
+#include "base/atomicops.h" |
+#include "base/synchronization/lock.h" |
+#include "base/threading/thread_checker.h" |
+#include "content/renderer/scheduler/renderer_scheduler.h" |
+#include "content/renderer/scheduler/single_thread_idle_task_runner.h" |
+#include "content/renderer/scheduler/task_queue_manager.h" |
+ |
+namespace content { |
+ |
+class RendererSchedulerSelector; |
+ |
+class RendererSchedulerImpl : public RendererScheduler, |
+ private IdleTaskDeadlineSupplier { |
+ public: |
+ RendererSchedulerImpl(); |
+ virtual ~RendererSchedulerImpl(); |
+ |
+ // Returns the default task runner. |
+ scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner() override; |
+ |
+ // Returns the compositor task runner. |
+ scoped_refptr<base::SingleThreadTaskRunner> CompositorTaskRunner() override; |
+ |
+ // Returns the idle task runner. Tasks posted to this runner may be reordered |
+ // relative to other task types and may be starved for an arbitrarily long |
+ // time if no idle time is available. |
+ scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() override; |
+ |
+ // Called to notify about the start of a new frame. Must be called from the |
+ // main thread. |
+ void WillBeginFrame(const cc::BeginFrameArgs& args) override; |
+ |
+ // Called to notify that a previously begun frame was committed. Must be |
+ // called from the main thread. |
+ void DidCommitFrameToCompositor() override; |
+ |
+ // Tells the scheduler that the system received an input event. Can be called |
+ // on any thread. |
+ void DidReceiveInputEvent() override; |
+ |
+ // Returns true if there is high priority work pending on the main thread |
+ // and the caller should yield to let the scheduler service that work. |
+ // Must be called from the main thread. |
+ bool ShouldYieldForHighPriorityWork() override; |
+ |
+ protected: |
+ RendererSchedulerImpl( |
+ scoped_refptr<base::SingleThreadTaskRunner> main_task_runner); |
+ |
+ // Virtual for testing. |
+ virtual base::TimeTicks Now() const; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); |
+ friend base::WeakPtr<content::IdleTaskDeadlineSupplier>; |
+ friend class RendererSchedulerImplTest; |
+ |
+ enum QueueId { |
+ kDefaultTaskQueue, |
+ kCompositorTaskQueue, |
+ kIdleTaskQueue, |
+ kControlTaskQueue, |
+ // Must be the last entry. |
+ kTaskQueueCount, |
+ }; |
+ |
+ enum Policy { |
+ kNormalPriorityPolicy, |
+ kCompositorPriorityPolicy, |
+ }; |
+ |
+ // The time we should stay in CompositorPriority mode for after a touch event. |
+ static const int kCompositorPriorityAfterTouchMillis = 100; |
+ |
+ // Implementation of IdleTaskDeadlineSupplier |
+ virtual base::TimeTicks CurrentIdleTaskDeadline() const override; |
+ |
+ // Returns the current scheduler policy. This may involve updating the |
+ // current policy if a new signal has arrived. Must be called from the main |
+ // thread. |
+ Policy SchedulerPolicy(); |
+ |
+ // Posts a call to UpdatePolicy on the control runner to be run after |delay| |
+ void PostUpdatePolicyOnControlRunner(base::TimeDelta delay); |
+ |
+ // Updates the scheduler policy. Must be called from the main thread. |
+ void UpdatePolicy(); |
+ |
+ // Start and end an idle period. |
+ void StartIdlePeriod(); |
+ void EndIdlePeriod(); |
+ |
+ base::ThreadChecker main_thread_checker_; |
alexclarke
2014/10/24 15:56:30
I think it might be useful to group these by which
rmcilroy
2014/10/27 16:25:01
It's not easy to do this and still maintain constr
|
+ scoped_ptr<RendererSchedulerSelector> renderer_scheduler_selector_; |
+ TaskQueueManager task_queue_manager_; |
+ scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_; |
+ scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; |
+ |
+ // Don't access current_policy_ directly, instead use SchedulerPolicy(). |
+ base::subtle::AtomicWord policy_may_need_update_; |
+ Policy current_policy_; |
+ |
+ base::TimeTicks estimated_next_frame_begin_; |
+ |
+ // The incoming_signals_lock_ mutex protects access to last_input_time_ |
+ // and write access to policy_may_need_update_. |
+ base::Lock incoming_signals_lock_; |
+ base::TimeTicks last_input_time_; |
+ |
+ base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_; |
+ base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ |