OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_SCHEDULER_SCHEDULER_H_ | 5 #ifndef CC_SCHEDULER_SCHEDULER_H_ |
6 #define CC_SCHEDULER_SCHEDULER_H_ | 6 #define CC_SCHEDULER_SCHEDULER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "cc/base/cc_export.h" | 13 #include "cc/base/cc_export.h" |
| 14 #include "cc/scheduler/frame_rate_controller.h" |
14 #include "cc/scheduler/scheduler_settings.h" | 15 #include "cc/scheduler/scheduler_settings.h" |
15 #include "cc/scheduler/scheduler_state_machine.h" | 16 #include "cc/scheduler/scheduler_state_machine.h" |
16 #include "cc/trees/layer_tree_host.h" | 17 #include "cc/trees/layer_tree_host.h" |
17 | 18 |
18 namespace cc { | 19 namespace cc { |
19 | 20 |
20 class Thread; | 21 class Thread; |
21 | 22 |
22 struct ScheduledActionDrawAndSwapResult { | 23 struct ScheduledActionDrawAndSwapResult { |
23 ScheduledActionDrawAndSwapResult() | 24 ScheduledActionDrawAndSwapResult() |
24 : did_draw(false), | 25 : did_draw(false), |
25 did_swap(false) {} | 26 did_swap(false) {} |
26 ScheduledActionDrawAndSwapResult(bool did_draw, bool did_swap) | 27 ScheduledActionDrawAndSwapResult(bool did_draw, bool did_swap) |
27 : did_draw(did_draw), | 28 : did_draw(did_draw), |
28 did_swap(did_swap) {} | 29 did_swap(did_swap) {} |
29 bool did_draw; | 30 bool did_draw; |
30 bool did_swap; | 31 bool did_swap; |
31 }; | 32 }; |
32 | 33 |
33 class SchedulerClient { | 34 class SchedulerClient { |
34 public: | 35 public: |
35 virtual void SetNeedsBeginFrameOnImplThread(bool enable) = 0; | |
36 virtual void ScheduledActionSendBeginFrameToMainThread() = 0; | 36 virtual void ScheduledActionSendBeginFrameToMainThread() = 0; |
37 virtual ScheduledActionDrawAndSwapResult | 37 virtual ScheduledActionDrawAndSwapResult |
38 ScheduledActionDrawAndSwapIfPossible() = 0; | 38 ScheduledActionDrawAndSwapIfPossible() = 0; |
39 virtual ScheduledActionDrawAndSwapResult | 39 virtual ScheduledActionDrawAndSwapResult |
40 ScheduledActionDrawAndSwapForced() = 0; | 40 ScheduledActionDrawAndSwapForced() = 0; |
41 virtual void ScheduledActionCommit() = 0; | 41 virtual void ScheduledActionCommit() = 0; |
42 virtual void ScheduledActionCheckForCompletedTileUploads() = 0; | 42 virtual void ScheduledActionCheckForCompletedTileUploads() = 0; |
43 virtual void ScheduledActionActivatePendingTreeIfNeeded() = 0; | 43 virtual void ScheduledActionActivatePendingTreeIfNeeded() = 0; |
44 virtual void ScheduledActionBeginOutputSurfaceCreation() = 0; | 44 virtual void ScheduledActionBeginOutputSurfaceCreation() = 0; |
45 virtual void ScheduledActionAcquireLayerTexturesForMainThread() = 0; | 45 virtual void ScheduledActionAcquireLayerTexturesForMainThread() = 0; |
46 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) = 0; | 46 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) = 0; |
47 virtual base::TimeDelta DrawDurationEstimate() = 0; | 47 virtual base::TimeDelta DrawDurationEstimate() = 0; |
48 | 48 |
49 protected: | 49 protected: |
50 virtual ~SchedulerClient() {} | 50 virtual ~SchedulerClient() {} |
51 }; | 51 }; |
52 | 52 |
53 class CC_EXPORT Scheduler { | 53 class CC_EXPORT Scheduler : FrameRateControllerClient { |
54 public: | 54 public: |
55 static scoped_ptr<Scheduler> Create( | 55 static scoped_ptr<Scheduler> Create( |
56 SchedulerClient* client, | 56 SchedulerClient* client, |
| 57 scoped_ptr<FrameRateController> frame_rate_controller, |
57 const SchedulerSettings& scheduler_settings) { | 58 const SchedulerSettings& scheduler_settings) { |
58 return make_scoped_ptr(new Scheduler(client, scheduler_settings)); | 59 return make_scoped_ptr(new Scheduler( |
| 60 client, frame_rate_controller.Pass(), scheduler_settings)); |
59 } | 61 } |
60 | 62 |
61 virtual ~Scheduler(); | 63 virtual ~Scheduler(); |
62 | 64 |
63 void SetCanStart(); | 65 void SetCanStart(); |
64 | 66 |
65 void SetVisible(bool visible); | 67 void SetVisible(bool visible); |
66 void SetCanDraw(bool can_draw); | 68 void SetCanDraw(bool can_draw); |
67 void SetHasPendingTree(bool has_pending_tree); | 69 void SetHasPendingTree(bool has_pending_tree); |
68 | 70 |
69 void SetNeedsCommit(); | 71 void SetNeedsCommit(); |
70 | 72 |
71 // Like SetNeedsCommit(), but ensures a commit will definitely happen even if | 73 // Like SetNeedsCommit(), but ensures a commit will definitely happen even if |
72 // we are not visible. | 74 // we are not visible. |
73 void SetNeedsForcedCommit(); | 75 void SetNeedsForcedCommit(); |
74 | 76 |
75 void SetNeedsRedraw(); | 77 void SetNeedsRedraw(); |
76 | 78 |
77 void SetMainThreadNeedsLayerTextures(); | 79 void SetMainThreadNeedsLayerTextures(); |
78 | 80 |
79 // Like SetNeedsRedraw(), but ensures the draw will definitely happen even if | 81 // Like SetNeedsRedraw(), but ensures the draw will definitely happen even if |
80 // we are not visible. | 82 // we are not visible. |
81 void SetNeedsForcedRedraw(); | 83 void SetNeedsForcedRedraw(); |
82 | 84 |
83 void DidSwapUseIncompleteTile(); | 85 void DidSwapUseIncompleteTile(); |
84 | 86 |
85 void FinishCommit(); | 87 void FinishCommit(); |
86 void BeginFrameAbortedByMainThread(); | 88 void BeginFrameAbortedByMainThread(); |
87 | 89 |
| 90 void SetMaxFramesPending(int max); |
| 91 int MaxFramesPending() const; |
| 92 int NumFramesPendingForTesting() const; |
| 93 |
| 94 void DidSwapBuffersComplete(); |
| 95 |
88 void DidLoseOutputSurface(); | 96 void DidLoseOutputSurface(); |
89 void DidCreateAndInitializeOutputSurface(); | 97 void DidCreateAndInitializeOutputSurface(); |
90 bool HasInitializedOutputSurface() const { | 98 bool HasInitializedOutputSurface() const { |
91 return state_machine_.HasInitializedOutputSurface(); | 99 return state_machine_.HasInitializedOutputSurface(); |
92 } | 100 } |
93 | 101 |
94 bool CommitPending() const { return state_machine_.CommitPending(); } | 102 bool CommitPending() const { return state_machine_.CommitPending(); } |
95 bool RedrawPending() const { return state_machine_.RedrawPending(); } | 103 bool RedrawPending() const { return state_machine_.RedrawPending(); } |
96 | 104 |
97 bool WillDrawIfNeeded() const; | 105 bool WillDrawIfNeeded() const; |
98 | 106 |
| 107 void SetTimebaseAndInterval(base::TimeTicks timebase, |
| 108 base::TimeDelta interval); |
| 109 |
99 base::TimeTicks AnticipatedDrawTime(); | 110 base::TimeTicks AnticipatedDrawTime(); |
100 | 111 |
101 base::TimeTicks LastBeginFrameOnImplThreadTime(); | 112 base::TimeTicks LastBeginFrameOnImplThreadTime(); |
102 | 113 |
103 void BeginFrame(base::TimeTicks frame_time); | 114 // FrameRateControllerClient implementation |
| 115 virtual void BeginFrame(bool throttled) OVERRIDE; |
104 | 116 |
105 std::string StateAsStringForTesting() { return state_machine_.ToString(); } | 117 std::string StateAsStringForTesting() { return state_machine_.ToString(); } |
106 | 118 |
107 private: | 119 private: |
108 Scheduler(SchedulerClient* client, | 120 Scheduler(SchedulerClient* client, |
| 121 scoped_ptr<FrameRateController> frame_rate_controller, |
109 const SchedulerSettings& scheduler_settings); | 122 const SchedulerSettings& scheduler_settings); |
110 | 123 |
111 void SetupNextBeginFrameIfNeeded(); | |
112 void DrawAndSwapIfPossible(); | |
113 void DrawAndSwapForced(); | |
114 void ProcessScheduledActions(); | 124 void ProcessScheduledActions(); |
115 | 125 |
116 const SchedulerSettings settings_; | 126 const SchedulerSettings settings_; |
117 SchedulerClient* client_; | 127 SchedulerClient* client_; |
118 | 128 scoped_ptr<FrameRateController> frame_rate_controller_; |
119 base::WeakPtrFactory<Scheduler> weak_factory_; | |
120 bool last_set_needs_begin_frame_; | |
121 bool has_pending_begin_frame_; | |
122 base::TimeTicks last_begin_frame_time_; | |
123 base::TimeDelta interval_; | |
124 | |
125 SchedulerStateMachine state_machine_; | 129 SchedulerStateMachine state_machine_; |
126 bool inside_process_scheduled_actions_; | 130 bool inside_process_scheduled_actions_; |
127 | 131 |
128 DISALLOW_COPY_AND_ASSIGN(Scheduler); | 132 DISALLOW_COPY_AND_ASSIGN(Scheduler); |
129 }; | 133 }; |
130 | 134 |
131 } // namespace cc | 135 } // namespace cc |
132 | 136 |
133 #endif // CC_SCHEDULER_SCHEDULER_H_ | 137 #endif // CC_SCHEDULER_SCHEDULER_H_ |
OLD | NEW |