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 requested | |
20 // frame. | |
21 virtual void StartFrameUpdate() = 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 // The user provides the SchedulerClient to be notified of when a frame update | |
29 // should be produced. The SchedulerClient must outlive this class. | |
30 class Scheduler { | |
31 public: | |
32 Scheduler(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
33 SchedulerClient* client); | |
34 virtual ~Scheduler(); | |
35 | |
36 // Called when the |client| wants to start a frame update on the engine. | |
37 void SetNeedsFrameUpdate(); | |
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(); | |
Wez
2016/10/19 22:01:34
nit: Rename this and the other two internal method
Khushal
2016/10/20 01:29:33
Done.
| |
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 frames. | |
64 bool needs_frame_update_ = 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 |