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. |
Wez
2016/10/13 16:53:52
Can you elaborate on *how* it schedules them? All
Khushal
2016/10/13 18:47:27
Added a comment. I don't think we need to get into
Wez
2016/10/18 01:49:42
I'm not asking for details of how we decide when t
Khushal
2016/10/18 05:10:03
Ah, added a comment about using the client interfa
|
+class Scheduler { |
+ public: |
+ Scheduler(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
+ SchedulerClient* client); |
Wez
2016/10/13 16:53:52
Who owns this? What is its lifetime?
Khushal
2016/10/13 18:47:27
I don't know if there is an established pattern fo
Wez
2016/10/18 01:49:42
If it is made explicit that |client| is a caller-s
Khushal
2016/10/18 05:10:03
The class takes the client in its ctor, I thought
Wez
2016/10/19 22:01:34
If you pass a bare pointer to a function, ctor, wh
Khushal
2016/10/20 01:29:32
I understand that in general when you take a bare
|
+ virtual ~Scheduler(); |
+ |
+ void SetNeedsMainFrame(); |
Wez
2016/10/13 16:53:52
What is a "main frame" in the context of this sche
Khushal
2016/10/13 18:47:27
Added a comment. I kept the word main frame mostly
Wez
2016/10/18 01:49:42
Understood. However, I think it would be clearer i
Khushal
2016/10/18 05:10:03
Sure, I don't really have a strong preference on t
Wez
2016/10/19 22:01:34
Perhaps... :P
Can we rename this to indicate what
Khushal
2016/10/20 01:29:33
Actually that comment will not be accurate. Since
|
+ void DidSendFrameUpdateToClient(); |
+ void DidReceiveFrameUpdateAck(); |
Wez
2016/10/13 16:53:52
SetNeedsMainFrame(), at least, needs explaining.
Khushal
2016/10/13 18:47:27
Done.
|
+ |
+ 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; |
Wez
2016/10/13 16:53:52
Under what circumstance can we _not_ produce "main
Khushal
2016/10/13 18:47:27
Done.
|
+ 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_; |
Wez
2016/10/13 16:53:52
nit: Initialize to nullptr here, just in case?
Khushal
2016/10/13 18:47:27
The ctor takes it as an argument, so is it necessa
Wez
2016/10/18 01:49:42
No, just suggested for consistency w/ the other me
|
+ |
+ base::WeakPtrFactory<Scheduler> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Scheduler); |
+}; |
+ |
+} // namespace engine |
+} // namespace blimp |
+ |
+#endif // BLIMP_ENGINE_RENDERER_SCHEDULER_H_ |