Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BLIMP_ENGINE_RENDERER_FRAME_SCHEDULER_H_ | |
| 6 #define BLIMP_ENGINE_RENDERER_FRAME_SCHEDULER_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/weak_ptr.h" | |
| 10 #include "base/timer/timer.h" | |
| 11 | |
| 12 namespace blimp { | |
| 13 namespace engine { | |
| 14 | |
| 15 class FrameSchedulerClient { | |
| 16 public: | |
| 17 virtual ~FrameSchedulerClient() {} | |
| 18 | |
| 19 // Used to notify the SchedulerClient to start the requested frame update. | |
|
Wez
2016/10/20 23:53:27
nit: SchedulerClient naming, here and elsewhere.
Wez
2016/10/25 21:50:09
Pingy
Khushal
2016/10/26 00:01:40
Done.
| |
| 20 // Calling this method marks the completion of the frame update request made | |
| 21 // to the scheduler. Any calls to schedule a frame after this will result in | |
| 22 // a new frame update. | |
| 23 virtual void StartFrameUpdate() = 0; | |
| 24 }; | |
| 25 | |
| 26 // Responsible for scheduling frame updates sent to the client. | |
| 27 // The Scheduler uses the state of frames sent to the client and the | |
| 28 // acknowledgements for these frames from the client to make decisions regarding | |
| 29 // when a frame should be produced on the engine. | |
| 30 // The caller provides a SchedulerClient to be notified when a frame update | |
| 31 // should be produced. The SchedulerClient must outlive this class. | |
| 32 class FrameScheduler { | |
| 33 public: | |
| 34 FrameScheduler(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 35 FrameSchedulerClient* client); | |
| 36 virtual ~FrameScheduler(); | |
| 37 | |
| 38 // Called when the |client| wants to start a frame update on the engine. | |
| 39 void ScheduleFrameUpdate(); | |
| 40 | |
| 41 // Called when a frame update is sent to the client. | |
| 42 void DidSendFrameUpdateToClient(); | |
| 43 | |
| 44 // Called when an Ack is received for a frame sent to the client. | |
| 45 void DidReceiveFrameUpdateAck(); | |
| 46 | |
| 47 base::TimeTicks next_frame_time() const { return next_frame_time_; } | |
|
Wez
2016/10/20 23:53:27
Can this be removed? I can't see anything using it
Khushal
2016/10/21 00:03:11
Oh, I think some test was. Will remove.
Khushal
2016/10/24 22:49:09
Done.
| |
| 48 | |
| 49 protected: | |
| 50 // protected for testing. | |
| 51 FrameScheduler(base::TimeDelta frame_delay, | |
| 52 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 53 FrameSchedulerClient* client); | |
| 54 | |
| 55 private: | |
| 56 void ScheduleFrameUpdateIfNecessary(); | |
| 57 | |
| 58 // Returns true if a frame update can be started. The Scheduler can not | |
| 59 // produce new frames either if there is no request for frames pending or we | |
| 60 // are waiting for an ack for a frame previously sent to the client. | |
| 61 bool ShouldProduceFrameUpdates() const; | |
| 62 | |
| 63 void StartFrameUpdate(); | |
| 64 | |
| 65 // Set to true if the |client_| has requested us to schedule frames. | |
| 66 bool needs_frame_update_ = false; | |
| 67 | |
| 68 // Set to true if a frame update was sent to the client and the ack is | |
| 69 // pending. | |
| 70 bool frame_ack_pending_ = false; | |
| 71 | |
| 72 // The time at which the next main frame update can be run. | |
| 73 base::TimeTicks next_frame_time_; | |
| 74 | |
| 75 // The delay to use between consecutive frames. | |
| 76 base::TimeDelta frame_delay_; | |
| 77 | |
| 78 base::OneShotTimer frame_tick_timer_; | |
| 79 | |
| 80 FrameSchedulerClient* client_; | |
| 81 | |
| 82 DISALLOW_COPY_AND_ASSIGN(FrameScheduler); | |
| 83 }; | |
| 84 | |
| 85 } // namespace engine | |
| 86 } // namespace blimp | |
| 87 | |
| 88 #endif // BLIMP_ENGINE_RENDERER_FRAME_SCHEDULER_H_ | |
| OLD | NEW |