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..4a732aff475c8cee86520e9bd25e4399d29c7c2d |
--- /dev/null |
+++ b/blimp/engine/renderer/scheduler.h |
@@ -0,0 +1,86 @@ |
+// 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 { |
+ public: |
+ virtual ~SchedulerClient() {} |
+ |
+ // Used to notify the SchedulerClient to synchronously start the renderer's |
+ // main frame. |
+ virtual void StartMainFrameUpdate() = 0; |
+}; |
+ |
+// Responsible for scheduling frame updates sent to the client. |
+// The Scheduler uses the state of frames sent to the client and the |
+// acknowledgements for these frames from the client to make decisions regarding |
+// when a frame should be produced on the engine. |
Wez
2016/10/18 01:49:42
And how does it communicate that to the rest of th
Khushal
2016/10/18 05:10:04
Done.
|
+class Scheduler { |
+ public: |
+ Scheduler(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
+ SchedulerClient* client); |
+ virtual ~Scheduler(); |
+ |
+ // Called when the |client| wants to start a frame update on the engine. We |
+ // call it the main frame since this corresponds to a request to start the |
+ // main frame update for blink. |
+ void SetNeedsMainFrame(); |
+ |
+ // Called when a frame update is sent to the client. |
+ void DidSendFrameUpdateToClient(); |
+ |
+ // Called when an Ack is received for a frame sent to the client. |
+ 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(); |
+ |
+ // Returns true if a main frame update can be started. The Scheduler can not |
+ // produce new frames either if there is no request for main frames pending |
+ // or we are waiting for an ack for a frame previously sent to the client. |
+ 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_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Scheduler); |
+}; |
+ |
+} // namespace engine |
+} // namespace blimp |
+ |
+#endif // BLIMP_ENGINE_RENDERER_SCHEDULER_H_ |