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_SCHEDULER_H_ |
| 6 #define BLIMP_ENGINE_RENDERER_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 SchedulerClient { |
| 16 public: |
| 17 virtual ~SchedulerClient() {} |
| 18 |
| 19 // Used to notify the SchedulerClient to synchronously start the renderer's |
| 20 // main frame. |
| 21 virtual void StartMainFrameUpdate() = 0; |
| 22 }; |
| 23 |
| 24 // Responsible for scheduling frame updates sent to the client. |
| 25 // The Scheduler uses the state of frames sent to the client and the |
| 26 // acknowledgements for these frames from the client to make decisions regarding |
| 27 // when a frame should be produced on the engine. |
| 28 class Scheduler { |
| 29 public: |
| 30 Scheduler(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 31 SchedulerClient* client); |
| 32 virtual ~Scheduler(); |
| 33 |
| 34 // Called when the |client| wants to start a frame update on the engine. We |
| 35 // call it the main frame since this corresponds to a request to start the |
| 36 // main frame update for blink. |
| 37 void SetNeedsMainFrame(); |
| 38 |
| 39 // Called when a frame update is sent to the client. |
| 40 void DidSendFrameUpdateToClient(); |
| 41 |
| 42 // Called when an Ack is received for a frame sent to the client. |
| 43 void DidReceiveFrameUpdateAck(); |
| 44 |
| 45 base::TimeTicks next_frame_time() const { return next_frame_time_; } |
| 46 |
| 47 protected: |
| 48 // protected for testing. |
| 49 Scheduler(base::TimeDelta frame_delay, |
| 50 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 51 SchedulerClient* client); |
| 52 |
| 53 private: |
| 54 void ScheduleMainFrameIfNecessary(); |
| 55 |
| 56 // Returns true if a main frame update can be started. The Scheduler can not |
| 57 // produce new frames either if there is no request for main frames pending |
| 58 // or we are waiting for an ack for a frame previously sent to the client. |
| 59 bool CanProduceMainFrames() const; |
| 60 |
| 61 void StartMainFrame(); |
| 62 |
| 63 // Set to true if the |client_| has requested us to schedule main frames. |
| 64 bool needs_main_frame_ = false; |
| 65 |
| 66 // Set to true if a frame update was sent to the client and the ack is |
| 67 // pending. |
| 68 bool frame_ack_pending_ = false; |
| 69 |
| 70 // The time at which the next main frame update can be run. |
| 71 base::TimeTicks next_frame_time_; |
| 72 |
| 73 // The delay to use between consecutive frames. |
| 74 base::TimeDelta frame_delay_; |
| 75 |
| 76 base::OneShotTimer frame_tick_timer_; |
| 77 |
| 78 SchedulerClient* client_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(Scheduler); |
| 81 }; |
| 82 |
| 83 } // namespace engine |
| 84 } // namespace blimp |
| 85 |
| 86 #endif // BLIMP_ENGINE_RENDERER_SCHEDULER_H_ |
OLD | NEW |