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

Unified Diff: content/renderer/scheduler/renderer_scheduler.h

Issue 664963002: content: Add RendererScheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bug in calculating remaining_compositor_priority_time Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/scheduler/renderer_scheduler.h
diff --git a/content/renderer/scheduler/renderer_scheduler.h b/content/renderer/scheduler/renderer_scheduler.h
new file mode 100644
index 0000000000000000000000000000000000000000..e49717c5521989ea3eb509f036933570f5c54173
--- /dev/null
+++ b/content/renderer/scheduler/renderer_scheduler.h
@@ -0,0 +1,120 @@
+// 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_H_
+#define CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_H_
+
+#include "base/atomicops.h"
+#include "base/synchronization/lock.h"
+#include "base/threading/thread_checker.h"
+#include "content/renderer/scheduler/single_thread_idle_task_runner.h"
+#include "content/renderer/scheduler/task_queue_manager.h"
+
+namespace cc {
+struct BeginFrameArgs;
+}
+
+namespace content {
+
+class RendererSchedulerSelector;
+
+class RendererScheduler : private IdleTaskDeadlineSupplier {
+ public:
+ RendererScheduler();
+ virtual ~RendererScheduler();
+
+ // Returns the default task runner.
+ scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner();
+
+ // Returns the compositor task runner.
+ scoped_refptr<base::SingleThreadTaskRunner> CompositorTaskRunner();
+
+ // 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();
+
+ // Called to notify about the start of a new frame. Must be called from the
+ // main thread.
+ void WillBeginFrame(const cc::BeginFrameArgs& args);
+
+ // Called to notify that a previously begun frame was committed. Must be
+ // called from the main thread.
+ void DidCommitFrameToCompositor();
+
+ // Tells the scheduler that the system received an input event. Can be called
+ // on any thread.
+ void DidReceiveInputEvent();
+
+ // 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();
+
+ protected:
+ RendererScheduler(
+ 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.
+
+ // Virtual for testing.
+ virtual base::TimeTicks Now() const;
+
+ private:
+ friend base::WeakPtr<content::IdleTaskDeadlineSupplier>;
+ friend class RendererSchedulerTest;
+
+ 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();
+
+ // 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_;
+ 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::WeakPtrFactory<RendererScheduler> weak_factory_;
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_H_

Powered by Google App Engine
This is Rietveld 408576698