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. | |
| 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 // The frame update must be run synchronously, and if it results in any | |
| 24 // content changes sent to the blimp client, the scheduler must be informed | |
| 25 // using DidSendFrameUpdateToClient. | |
| 26 virtual void StartFrameUpdate() = 0; | |
| 27 }; | |
| 28 | |
| 29 // Responsible for scheduling frame updates sent to the client. | |
| 30 // The Scheduler uses the state of frames sent to the client and the | |
| 31 // acknowledgements for these frames from the client to make decisions regarding | |
| 32 // when a frame should be produced on the engine. | |
| 33 // The caller provides a SchedulerClient to be notified when a frame update | |
| 34 // should be produced. The SchedulerClient must outlive this class. | |
| 35 class FrameScheduler { | |
| 36 public: | |
| 37 FrameScheduler(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 38 FrameSchedulerClient* client); | |
| 39 virtual ~FrameScheduler(); | |
| 40 | |
| 41 // Called when the |client| wants to start a frame update on the engine. The | |
| 42 // |client| will be asynchronously informed of starting a frame update using | |
|
Wez
2016/10/25 21:50:09
nit: "|client->StartFrameUpdate() will be called[-
Khushal
2016/10/26 00:01:40
Done.
| |
| 43 // FrameSchedulerClient::StartFrameUpdate. | |
| 44 void ScheduleFrameUpdate(); | |
| 45 | |
| 46 // Called when a frame update is sent to the client. This must be followed | |
| 47 // with a DidReceiveFrameUpdateAck when the frame sent is ack-ed by the | |
| 48 // client. | |
|
Wez
2016/10/25 21:50:09
Make explicit that this MUST be called from within
Khushal
2016/10/26 00:01:40
I added a DCHECK to make sure it is only called fr
| |
| 49 void DidSendFrameUpdateToClient(); | |
| 50 | |
| 51 // Called when an Ack is received for a frame sent to the client. | |
| 52 void DidReceiveFrameUpdateAck(); | |
| 53 | |
| 54 protected: | |
| 55 // protected for testing. | |
| 56 FrameScheduler(base::TimeDelta frame_delay, | |
| 57 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 58 FrameSchedulerClient* client); | |
| 59 | |
| 60 private: | |
| 61 void ScheduleFrameUpdateIfNecessary(); | |
| 62 | |
| 63 // Returns true if a frame update can be started. The Scheduler can not | |
| 64 // produce new frames either if there is no request for frames pending or we | |
| 65 // are waiting for an ack for a frame previously sent to the client. | |
| 66 bool ShouldProduceFrameUpdates() const; | |
| 67 | |
| 68 void StartFrameUpdate(); | |
| 69 | |
| 70 // Set to true if the |client_| has requested us to schedule frames. | |
| 71 bool needs_frame_update_ = false; | |
| 72 | |
| 73 // Set to true if a frame update was sent to the client and the ack is | |
| 74 // pending. | |
| 75 bool frame_ack_pending_ = false; | |
| 76 | |
| 77 // The time at which the next main frame update can be run. | |
| 78 base::TimeTicks next_frame_time_; | |
| 79 | |
| 80 // The delay to use between consecutive frames. | |
| 81 base::TimeDelta frame_delay_; | |
| 82 | |
| 83 base::OneShotTimer frame_tick_timer_; | |
| 84 | |
| 85 FrameSchedulerClient* client_; | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(FrameScheduler); | |
| 88 }; | |
| 89 | |
| 90 } // namespace engine | |
| 91 } // namespace blimp | |
| 92 | |
| 93 #endif // BLIMP_ENGINE_RENDERER_FRAME_SCHEDULER_H_ | |
| OLD | NEW |