Index: blimp/engine/renderer/scheduler.h |
diff --git a/blimp/engine/renderer/scheduler.h b/blimp/engine/renderer/scheduler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2802a8daf95cd0f62685b6367029354e2009e686 |
--- /dev/null |
+++ b/blimp/engine/renderer/scheduler.h |
@@ -0,0 +1,66 @@ |
+// Copyright 2016 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 BLIMP_ENGINE_RENDERER_SCHEDULER_H_ |
+#define BLIMP_ENGINE_RENDERER_SCHEDULER_H_ |
+ |
+#include "base/macros.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/timer/timer.h" |
+ |
+namespace blimp { |
+namespace engine { |
+ |
+class SchedulerClient; |
+ |
+// Responsible for scheduling frame updates sent to the client. |
+class Scheduler { |
+ public: |
+ Scheduler(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
+ SchedulerClient* client); |
+ virtual ~Scheduler(); |
+ |
+ void SetNeedsMainFrame(); |
+ void DidSendFrameUpdateToClient(); |
+ void DidReceiveFrameUpdateAck(); |
+ |
+ base::TimeTicks next_frame_time() const { return next_frame_time_; } |
+ |
+ protected: |
+ // protected for testing. |
+ Scheduler(base::TimeDelta frame_delay, |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
+ SchedulerClient* client); |
+ |
+ private: |
+ void ScheduleMainFrameIfNecessary(); |
+ bool CanProduceMainFrames() const; |
+ void StartMainFrame(); |
+ |
+ // Set to true if the |client_| has requested us to schedule main frames. |
+ bool needs_main_frame_ = false; |
+ |
+ // Set to true if a frame update was sent to the client and the ack is |
+ // pending. |
+ bool frame_ack_pending_ = false; |
+ |
+ // The time at which the next main frame update can be run. |
+ base::TimeTicks next_frame_time_; |
+ |
+ // The delay to use between consecutive frames. |
+ base::TimeDelta frame_delay_; |
+ |
+ base::OneShotTimer frame_tick_timer_; |
+ |
+ SchedulerClient* client_; |
+ |
+ base::WeakPtrFactory<Scheduler> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Scheduler); |
+}; |
+ |
+} // namespace engine |
+} // namespace blimp |
+ |
+#endif // BLIMP_ENGINE_RENDERER_SCHEDULER_H_ |