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 |
| 17 // Responsible for scheduling frame updates sent to the client. |
| 18 class Scheduler { |
| 19 public: |
| 20 Scheduler(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 21 SchedulerClient* client); |
| 22 virtual ~Scheduler(); |
| 23 |
| 24 void SetNeedsMainFrame(); |
| 25 void DidSendFrameUpdateToClient(); |
| 26 void DidReceiveFrameUpdateAck(); |
| 27 |
| 28 base::TimeTicks next_frame_time() const { return next_frame_time_; } |
| 29 |
| 30 protected: |
| 31 // protected for testing. |
| 32 Scheduler(base::TimeDelta frame_delay, |
| 33 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 34 SchedulerClient* client); |
| 35 |
| 36 private: |
| 37 void ScheduleMainFrameIfNecessary(); |
| 38 bool CanProduceMainFrames() const; |
| 39 void StartMainFrame(); |
| 40 |
| 41 // Set to true if the |client_| has requested us to schedule main frames. |
| 42 bool needs_main_frame_ = false; |
| 43 |
| 44 // Set to true if a frame update was sent to the client and the ack is |
| 45 // pending. |
| 46 bool frame_ack_pending_ = false; |
| 47 |
| 48 // The time at which the next main frame update can be run. |
| 49 base::TimeTicks next_frame_time_; |
| 50 |
| 51 // The delay to use between consecutive frames. |
| 52 base::TimeDelta frame_delay_; |
| 53 |
| 54 base::OneShotTimer frame_tick_timer_; |
| 55 |
| 56 SchedulerClient* client_; |
| 57 |
| 58 base::WeakPtrFactory<Scheduler> weak_ptr_factory_; |
| 59 |
| 60 DISALLOW_COPY_AND_ASSIGN(Scheduler); |
| 61 }; |
| 62 |
| 63 } // namespace engine |
| 64 } // namespace blimp |
| 65 |
| 66 #endif // BLIMP_ENGINE_RENDERER_SCHEDULER_H_ |
OLD | NEW |