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 #include "cc/scheduler/scheduler_state_machine.h" | 5 #include "cc/scheduler/scheduler_state_machine.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 | 10 |
11 namespace cc { | 11 namespace cc { |
12 | 12 |
13 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) | 13 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
14 : settings_(settings), | 14 : settings_(settings), |
15 commit_state_(COMMIT_STATE_IDLE), | 15 commit_state_(COMMIT_STATE_IDLE), |
16 commit_count_(0), | 16 commit_count_(0), |
17 current_frame_number_(0), | 17 begin_frame_count_(0), |
18 last_frame_number_where_draw_was_called_(-1), | 18 begin_frame_deadline_count_(0), |
19 last_frame_number_where_tree_activation_attempted_(-1), | 19 draw_attempt_count_(0), |
20 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), | 20 last_begin_frame_count_draw_was_called_(-1), |
21 last_begin_frame_count_begin_frame_sent_to_main_thread_(-1), | |
22 last_draw_attempt_count_tree_activation_attempted_(-1), | |
23 last_draw_attempt_count_completed_tile_uploads_checked_(-1), | |
21 consecutive_failed_draws_(0), | 24 consecutive_failed_draws_(0), |
22 maximum_number_of_failed_draws_before_draw_is_forced_(3), | 25 maximum_number_of_failed_draws_before_draw_is_forced_(3), |
23 needs_redraw_(false), | 26 needs_redraw_(false), |
24 swap_used_incomplete_tile_(false), | 27 swap_used_incomplete_tile_(false), |
25 needs_forced_redraw_(false), | 28 needs_forced_redraw_(false), |
26 needs_forced_redraw_after_next_commit_(false), | 29 needs_forced_redraw_after_next_commit_(false), |
27 needs_commit_(false), | 30 needs_commit_(false), |
28 needs_forced_commit_(false), | 31 needs_forced_commit_(false), |
29 expect_immediate_begin_frame_for_main_thread_(false), | 32 expect_immediate_begin_frame_for_main_thread_(false), |
30 main_thread_needs_layer_textures_(false), | 33 main_thread_needs_layer_textures_(false), |
31 inside_begin_frame_(false), | 34 begin_frame_state_(BEGIN_FRAME_STATE_IDLE), |
35 commit_tree_has_been_drawn_(true), | |
36 active_tree_has_been_drawn_(false), | |
37 active_tree_is_null_(true), | |
32 visible_(false), | 38 visible_(false), |
33 can_start_(false), | 39 can_start_(false), |
34 can_draw_(false), | 40 can_draw_(false), |
35 has_pending_tree_(false), | 41 has_pending_tree_(false), |
36 draw_if_possible_failed_(false), | 42 draw_if_possible_failed_(false), |
37 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), | 43 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), |
38 output_surface_state_(OUTPUT_SURFACE_LOST), | 44 output_surface_state_(OUTPUT_SURFACE_LOST), |
39 did_create_and_initialize_first_output_surface_(false) {} | 45 did_create_and_initialize_first_output_surface_(false) {} |
40 | 46 |
41 std::string SchedulerStateMachine::ToString() { | 47 std::string SchedulerStateMachine::ToString() { |
42 std::string str; | 48 std::string str; |
43 base::StringAppendF(&str, | 49 base::StringAppendF(&str, |
44 "settings_.impl_side_painting = %d; ", | 50 "settings_.impl_side_painting = %d; ", |
45 settings_.impl_side_painting); | 51 settings_.impl_side_painting); |
46 base::StringAppendF(&str, "commit_state_ = %d; ", commit_state_); | 52 base::StringAppendF(&str, "commit_state_ = %d; ", commit_state_); |
47 base::StringAppendF(&str, "commit_count_ = %d; ", commit_count_); | 53 base::StringAppendF(&str, "commit_count_ = %d; ", commit_count_); |
48 base::StringAppendF( | 54 base::StringAppendF(&str, "begin_frame_count_ = %d; ", |
49 &str, "current_frame_number_ = %d; ", current_frame_number_); | 55 begin_frame_count_); |
56 base::StringAppendF(&str, "draw_attempt_count_ = %d; ", | |
57 draw_attempt_count_); | |
50 base::StringAppendF(&str, | 58 base::StringAppendF(&str, |
51 "last_frame_number_where_draw_was_called_ = %d; ", | 59 "last_begin_frame_count_draw_was_called_ = %d; ", |
52 last_frame_number_where_draw_was_called_); | 60 last_begin_frame_count_draw_was_called_); |
53 base::StringAppendF( | 61 base::StringAppendF( |
54 &str, | 62 &str, |
55 "last_frame_number_where_tree_activation_attempted_ = %d; ", | 63 "last_draw_attempt_count_tree_activation_attempted_ = %d; ", |
56 last_frame_number_where_tree_activation_attempted_); | 64 last_draw_attempt_count_tree_activation_attempted_); |
57 base::StringAppendF( | 65 base::StringAppendF( |
58 &str, | 66 &str, |
59 "last_frame_number_where_check_for_completed_tile_uploads_called_ = %d; ", | 67 "last_draw_attempt_count_completed_tile_uploads_checked_ = %d; ", |
60 last_frame_number_where_check_for_completed_tile_uploads_called_); | 68 last_draw_attempt_count_completed_tile_uploads_checked_); |
61 base::StringAppendF( | 69 base::StringAppendF( |
62 &str, "consecutive_failed_draws_ = %d; ", consecutive_failed_draws_); | 70 &str, "consecutive_failed_draws_ = %d; ", consecutive_failed_draws_); |
63 base::StringAppendF( | 71 base::StringAppendF( |
64 &str, | 72 &str, |
65 "maximum_number_of_failed_draws_before_draw_is_forced_ = %d; ", | 73 "maximum_number_of_failed_draws_before_draw_is_forced_ = %d; ", |
66 maximum_number_of_failed_draws_before_draw_is_forced_); | 74 maximum_number_of_failed_draws_before_draw_is_forced_); |
67 base::StringAppendF(&str, "needs_redraw_ = %d; ", needs_redraw_); | 75 base::StringAppendF(&str, "needs_redraw_ = %d; ", needs_redraw_); |
68 base::StringAppendF( | 76 base::StringAppendF( |
69 &str, "swap_used_incomplete_tile_ = %d; ", swap_used_incomplete_tile_); | 77 &str, "swap_used_incomplete_tile_ = %d; ", swap_used_incomplete_tile_); |
70 base::StringAppendF( | 78 base::StringAppendF( |
71 &str, "needs_forced_redraw_ = %d; ", needs_forced_redraw_); | 79 &str, "needs_forced_redraw_ = %d; ", needs_forced_redraw_); |
72 base::StringAppendF(&str, | 80 base::StringAppendF(&str, |
73 "needs_forced_redraw_after_next_commit_ = %d; ", | 81 "needs_forced_redraw_after_next_commit_ = %d; ", |
74 needs_forced_redraw_after_next_commit_); | 82 needs_forced_redraw_after_next_commit_); |
75 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_); | 83 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_); |
76 base::StringAppendF( | 84 base::StringAppendF( |
77 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); | 85 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); |
78 base::StringAppendF(&str, | 86 base::StringAppendF(&str, |
79 "expect_immediate_begin_frame_for_main_thread_ = %d; ", | 87 "expect_immediate_begin_frame_for_main_thread_ = %d; ", |
80 expect_immediate_begin_frame_for_main_thread_); | 88 expect_immediate_begin_frame_for_main_thread_); |
81 base::StringAppendF(&str, | 89 base::StringAppendF(&str, |
82 "main_thread_needs_layer_textures_ = %d; ", | 90 "main_thread_needs_layer_textures_ = %d; ", |
83 main_thread_needs_layer_textures_); | 91 main_thread_needs_layer_textures_); |
84 base::StringAppendF(&str, "inside_begin_frame_ = %d; ", | 92 base::StringAppendF(&str, "begin_frame_state_ = %d; ", begin_frame_state_); |
85 inside_begin_frame_); | |
86 base::StringAppendF(&str, "last_frame_time_ = %"PRId64"; ", | 93 base::StringAppendF(&str, "last_frame_time_ = %"PRId64"; ", |
87 (last_begin_frame_args_.frame_time - base::TimeTicks()) | 94 (last_begin_frame_args_.frame_time - base::TimeTicks()) |
88 .InMilliseconds()); | 95 .InMilliseconds()); |
89 base::StringAppendF(&str, "last_deadline_ = %"PRId64"; ", | 96 base::StringAppendF(&str, "last_deadline_ = %"PRId64"; ", |
90 (last_begin_frame_args_.deadline - base::TimeTicks()).InMilliseconds()); | 97 (last_begin_frame_args_.deadline - base::TimeTicks()).InMilliseconds()); |
91 base::StringAppendF(&str, "last_interval_ = %"PRId64"; ", | 98 base::StringAppendF(&str, "last_interval_ = %"PRId64"; ", |
92 last_begin_frame_args_.interval.InMilliseconds()); | 99 last_begin_frame_args_.interval.InMilliseconds()); |
93 base::StringAppendF(&str, "visible_ = %d; ", visible_); | 100 base::StringAppendF(&str, "visible_ = %d; ", visible_); |
94 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); | 101 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); |
95 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); | 102 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); |
96 base::StringAppendF( | 103 base::StringAppendF( |
97 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); | 104 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); |
98 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); | 105 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); |
106 base::StringAppendF(&str, "commit_tree_has_been_drawn_ = %d; ", | |
107 commit_tree_has_been_drawn_); | |
108 base::StringAppendF(&str, "active_tree_has_been_drawn_ = %d; ", | |
109 active_tree_has_been_drawn_); | |
110 base::StringAppendF(&str, "active_tree_is_null_ = %d; ", | |
111 active_tree_is_null_); | |
99 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); | 112 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); |
100 base::StringAppendF( | 113 base::StringAppendF( |
101 &str, "output_surface_state_ = %d; ", output_surface_state_); | 114 &str, "output_surface_state_ = %d; ", output_surface_state_); |
102 return str; | 115 return str; |
103 } | 116 } |
104 | 117 |
105 bool SchedulerStateMachine::HasDrawnThisFrame() const { | 118 bool SchedulerStateMachine::HasDrawnThisFrame() const { |
106 return current_frame_number_ == last_frame_number_where_draw_was_called_; | 119 return begin_frame_count_ == last_begin_frame_count_draw_was_called_; |
107 } | 120 } |
108 | 121 |
109 bool SchedulerStateMachine::HasAttemptedTreeActivationThisFrame() const { | 122 bool SchedulerStateMachine::HasSentBeginFrameToMainThreadThisFrame() const { |
110 return current_frame_number_ == | 123 return begin_frame_count_ == |
111 last_frame_number_where_tree_activation_attempted_; | 124 last_begin_frame_count_begin_frame_sent_to_main_thread_; |
112 } | 125 } |
113 | 126 |
114 bool SchedulerStateMachine::HasCheckedForCompletedTileUploadsThisFrame() const { | 127 bool SchedulerStateMachine::HasAttemptedTreeActivationThisDrawAttempt() const { |
115 return current_frame_number_ == | 128 return draw_attempt_count_ == |
116 last_frame_number_where_check_for_completed_tile_uploads_called_; | 129 last_draw_attempt_count_tree_activation_attempted_; |
130 } | |
131 | |
132 bool SchedulerStateMachine:: | |
133 HasCheckedForCompletedTileUploadsThisDrawAttempt() const { | |
134 return draw_attempt_count_ == | |
135 last_draw_attempt_count_completed_tile_uploads_checked_; | |
117 } | 136 } |
118 | 137 |
119 bool SchedulerStateMachine::DrawSuspendedUntilCommit() const { | 138 bool SchedulerStateMachine::DrawSuspendedUntilCommit() const { |
120 if (!can_draw_) | 139 if (!can_draw_) |
121 return true; | 140 return true; |
122 if (!visible_) | 141 if (!visible_) |
123 return true; | 142 return true; |
124 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD) | 143 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD) |
125 return true; | 144 return true; |
126 return false; | 145 return false; |
127 } | 146 } |
128 | 147 |
129 bool SchedulerStateMachine::ScheduledToDraw() const { | 148 bool SchedulerStateMachine::ScheduledToDraw() const { |
130 if (!needs_redraw_) | 149 if (!needs_redraw_) |
131 return false; | 150 return false; |
132 if (DrawSuspendedUntilCommit()) | 151 if (DrawSuspendedUntilCommit()) |
133 return false; | 152 return false; |
134 return true; | 153 return true; |
135 } | 154 } |
136 | 155 |
137 bool SchedulerStateMachine::ShouldDraw() const { | 156 bool SchedulerStateMachine::ShouldDraw() const { |
138 if (needs_forced_redraw_) | 157 if (needs_forced_redraw_) |
139 return true; | 158 return true; |
140 | 159 |
141 if (!ScheduledToDraw()) | 160 if (!ScheduledToDraw()) |
142 return false; | 161 return false; |
143 if (!inside_begin_frame_) | 162 if (begin_frame_state_ != BEGIN_FRAME_STATE_INSIDE_DEADLINE) |
144 return false; | 163 return false; |
145 if (HasDrawnThisFrame()) | 164 if (HasDrawnThisFrame()) |
146 return false; | 165 return false; |
147 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) | 166 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) |
148 return false; | 167 return false; |
149 return true; | 168 return true; |
150 } | 169 } |
151 | 170 |
152 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { | 171 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { |
153 return has_pending_tree_ && inside_begin_frame_ && | 172 return !HasAttemptedTreeActivationThisDrawAttempt() && |
154 !HasAttemptedTreeActivationThisFrame(); | 173 has_pending_tree_ && |
174 (!can_draw_ || !visible_ || | |
175 output_surface_state_ != OUTPUT_SURFACE_ACTIVE || | |
brianderson
2013/07/10 21:58:04
This is how I plan to handle lost output surfaces
| |
176 ((active_tree_has_been_drawn_ || active_tree_is_null_) && | |
177 begin_frame_state_ != BEGIN_FRAME_STATE_IDLE)); | |
155 } | 178 } |
156 | 179 |
157 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const { | 180 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const { |
158 if (!settings_.impl_side_painting) | 181 if (!settings_.impl_side_painting) |
159 return false; | 182 return false; |
160 if (HasCheckedForCompletedTileUploadsThisFrame()) | 183 if (HasCheckedForCompletedTileUploadsThisDrawAttempt()) |
161 return false; | 184 return false; |
162 | 185 |
163 return ShouldAttemptTreeActivation() || ShouldDraw() || | 186 return ShouldAttemptTreeActivation() || ShouldDraw() || |
164 swap_used_incomplete_tile_; | 187 swap_used_incomplete_tile_; |
165 } | 188 } |
166 | 189 |
167 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { | 190 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { |
168 if (!main_thread_needs_layer_textures_) | 191 if (!main_thread_needs_layer_textures_) |
169 return false; | 192 return false; |
170 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) | 193 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) |
171 return true; | 194 return true; |
172 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); | 195 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); |
173 // Transfer the lock from impl thread to main thread immediately if the | 196 // Transfer the lock from impl thread to main thread immediately if the |
174 // impl thread is not even scheduled to draw. Guards against deadlocking. | 197 // impl thread is not even scheduled to draw. Guards against deadlocking. |
175 if (!ScheduledToDraw()) | 198 if (!ScheduledToDraw()) |
176 return true; | 199 return true; |
177 if (!BeginFrameNeededToDrawByImplThread()) | 200 if (!BeginFrameNeededToDrawByImplThread()) |
178 return true; | 201 return true; |
179 return false; | 202 return false; |
180 } | 203 } |
181 | 204 |
205 bool SchedulerStateMachine::ShouldSendBeginFrameToMainThread() const { | |
206 if (HasSentBeginFrameToMainThreadThisFrame()) | |
207 return false; | |
208 | |
209 // TODO(brianderson): Allow sending BeginFrame to main thread while idle when | |
210 // the main thread isn't consuming user input. | |
211 bool can_expect_begin_frame = BeginFrameNeededToDrawByImplThread() || | |
212 ProactiveBeginFrameWantedByImplThread(); | |
213 if (begin_frame_state_ == BEGIN_FRAME_STATE_IDLE && | |
214 can_expect_begin_frame) | |
215 return false; | |
216 | |
217 // Do not send begin frame to main thread in the deadline until we have drawn. | |
218 if (begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_DEADLINE && | |
219 !HasDrawnThisFrame()) | |
220 return false; | |
221 | |
222 // We can't accept a commit if we have a pending tree. | |
223 if (has_pending_tree_) | |
224 return false; | |
225 | |
226 bool can_commit = needs_commit_ && (visible_ || needs_forced_commit_); | |
227 switch (commit_state_) { | |
228 case COMMIT_STATE_IDLE: | |
229 return can_commit && (needs_forced_commit_ || | |
230 output_surface_state_ == OUTPUT_SURFACE_ACTIVE); | |
231 | |
232 // COMMIT_STATE_WAITING_FOR_ACTIVATION wants to enforce activation and | |
233 // eventually a draw. | |
234 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. | |
235 // If can_draw_ is false or textures are not available, proceed to the | |
236 // next step (similar as in COMMIT_STATE_IDLE). | |
237 case COMMIT_STATE_WAITING_FOR_ACTIVATION: | |
238 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: | |
239 return can_commit && DrawSuspendedUntilCommit(); | |
240 default: | |
241 return false; | |
242 } | |
243 | |
244 return false; | |
245 } | |
246 | |
182 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { | 247 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
183 if (ShouldAcquireLayerTexturesForMainThread()) | 248 if (ShouldAcquireLayerTexturesForMainThread()) |
184 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; | 249 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; |
185 | 250 |
186 switch (commit_state_) { | 251 switch (commit_state_) { |
187 case COMMIT_STATE_IDLE: | 252 case COMMIT_STATE_IDLE: |
188 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | 253 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && |
189 needs_forced_redraw_) | 254 needs_forced_redraw_) |
190 return ACTION_DRAW_FORCED; | 255 return ACTION_DRAW_FORCED; |
191 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | 256 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && |
192 needs_forced_commit_) | 257 needs_forced_commit_) |
193 // TODO(enne): Should probably drop the active tree on force commit. | 258 // TODO(enne): Should probably drop the active tree on force commit. |
194 return has_pending_tree_ ? ACTION_NONE | 259 return has_pending_tree_ ? ACTION_NONE |
195 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | 260 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
196 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) | 261 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) |
197 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; | 262 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; |
198 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) | 263 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) |
199 return ACTION_NONE; | 264 return ACTION_NONE; |
200 if (ShouldCheckForCompletedTileUploads()) | 265 if (ShouldCheckForCompletedTileUploads()) |
201 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 266 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
202 if (ShouldAttemptTreeActivation()) | 267 if (ShouldAttemptTreeActivation()) |
203 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 268 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
204 if (ShouldDraw()) { | 269 if (ShouldDraw()) { |
205 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 270 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
206 : ACTION_DRAW_IF_POSSIBLE; | 271 : ACTION_DRAW_IF_POSSIBLE; |
207 } | 272 } |
208 if (needs_commit_ && | 273 if (ShouldSendBeginFrameToMainThread()) { |
209 ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE) | |
210 || needs_forced_commit_)) | |
211 // TODO(enne): Should probably drop the active tree on force commit. | 274 // TODO(enne): Should probably drop the active tree on force commit. |
212 return has_pending_tree_ ? ACTION_NONE | 275 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
213 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | 276 } |
214 return ACTION_NONE; | 277 return ACTION_NONE; |
215 | 278 |
216 case COMMIT_STATE_FRAME_IN_PROGRESS: | 279 case COMMIT_STATE_FRAME_IN_PROGRESS: |
217 if (ShouldCheckForCompletedTileUploads()) | 280 if (ShouldCheckForCompletedTileUploads()) |
218 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 281 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
219 if (ShouldAttemptTreeActivation()) | 282 if (ShouldAttemptTreeActivation()) |
220 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 283 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
221 if (ShouldDraw()) { | 284 if (ShouldDraw()) { |
222 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 285 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
223 : ACTION_DRAW_IF_POSSIBLE; | 286 : ACTION_DRAW_IF_POSSIBLE; |
224 } | 287 } |
225 return ACTION_NONE; | 288 return ACTION_NONE; |
226 | 289 |
227 case COMMIT_STATE_READY_TO_COMMIT: | 290 case COMMIT_STATE_READY_TO_COMMIT: |
228 return ACTION_COMMIT; | 291 return ACTION_COMMIT; |
229 | 292 |
293 case COMMIT_STATE_WAITING_FOR_ACTIVATION: { | |
294 if (ShouldCheckForCompletedTileUploads()) | |
295 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | |
296 if (ShouldAttemptTreeActivation()) | |
297 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | |
298 if (ShouldDraw()) { | |
299 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | |
300 : ACTION_DRAW_IF_POSSIBLE; | |
301 } | |
302 if (ShouldSendBeginFrameToMainThread()) | |
303 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | |
304 return ACTION_NONE; | |
305 } | |
306 | |
230 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: { | 307 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: { |
231 if (ShouldCheckForCompletedTileUploads()) | 308 if (ShouldCheckForCompletedTileUploads()) |
232 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 309 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
233 if (ShouldAttemptTreeActivation()) | 310 if (ShouldAttemptTreeActivation()) |
234 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 311 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
235 if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) { | 312 if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) { |
236 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 313 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
237 : ACTION_DRAW_IF_POSSIBLE; | 314 : ACTION_DRAW_IF_POSSIBLE; |
238 } | 315 } |
239 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If | 316 if (ShouldSendBeginFrameToMainThread()) |
240 // can_draw_ is false or textures are not available, proceed to the next | 317 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
241 // step (similar as in COMMIT_STATE_IDLE). | |
242 bool can_commit = visible_ || needs_forced_commit_; | |
243 if (needs_commit_ && can_commit && DrawSuspendedUntilCommit()) | |
244 return has_pending_tree_ ? ACTION_NONE | |
245 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | |
246 return ACTION_NONE; | 318 return ACTION_NONE; |
247 } | 319 } |
248 | 320 |
249 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: | 321 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: |
250 if (ShouldCheckForCompletedTileUploads()) | 322 if (ShouldCheckForCompletedTileUploads()) |
251 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 323 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
252 if (ShouldAttemptTreeActivation()) | 324 if (ShouldAttemptTreeActivation()) |
253 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 325 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
254 if (needs_forced_redraw_) | 326 if (needs_forced_redraw_) |
255 return ACTION_DRAW_FORCED; | 327 return ACTION_DRAW_FORCED; |
256 return ACTION_NONE; | 328 return ACTION_NONE; |
257 } | 329 } |
258 NOTREACHED(); | 330 NOTREACHED(); |
259 return ACTION_NONE; | 331 return ACTION_NONE; |
260 } | 332 } |
261 | 333 |
262 void SchedulerStateMachine::UpdateState(Action action) { | 334 void SchedulerStateMachine::UpdateState(Action action) { |
263 switch (action) { | 335 switch (action) { |
264 case ACTION_NONE: | 336 case ACTION_NONE: |
337 if (begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME) | |
338 begin_frame_state_ = BEGIN_FRAME_STATE_DEADLINE_PENDING; | |
339 if (begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_DEADLINE) | |
340 begin_frame_state_ = BEGIN_FRAME_STATE_IDLE; | |
265 return; | 341 return; |
266 | 342 |
267 case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS: | 343 case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS: |
268 last_frame_number_where_check_for_completed_tile_uploads_called_ = | 344 last_draw_attempt_count_completed_tile_uploads_checked_ = |
269 current_frame_number_; | 345 draw_attempt_count_; |
270 return; | 346 return; |
271 | 347 |
272 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: | 348 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: |
273 last_frame_number_where_tree_activation_attempted_ = | 349 last_draw_attempt_count_tree_activation_attempted_ = |
274 current_frame_number_; | 350 draw_attempt_count_; |
275 return; | 351 return; |
276 | 352 |
277 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: | 353 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
278 DCHECK(!has_pending_tree_); | 354 DCHECK(!has_pending_tree_); |
279 DCHECK(visible_ || needs_forced_commit_); | 355 DCHECK(visible_ || needs_forced_commit_); |
280 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 356 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
281 needs_commit_ = false; | 357 needs_commit_ = false; |
282 needs_forced_commit_ = false; | 358 needs_forced_commit_ = false; |
359 last_begin_frame_count_begin_frame_sent_to_main_thread_ = | |
360 begin_frame_count_; | |
283 return; | 361 return; |
284 | 362 |
285 case ACTION_COMMIT: | 363 case ACTION_COMMIT: |
286 commit_count_++; | 364 commit_count_++; |
287 if (expect_immediate_begin_frame_for_main_thread_) | 365 if (expect_immediate_begin_frame_for_main_thread_) |
288 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; | 366 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
367 else if (settings_.impl_side_painting) | |
368 commit_state_ = COMMIT_STATE_WAITING_FOR_ACTIVATION; | |
289 else | 369 else |
290 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | 370 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; |
291 // When impl-side painting, we draw on activation instead of on commit. | 371 // When impl-side painting, we draw on activation instead of on commit. |
292 if (!settings_.impl_side_painting) | 372 if (!settings_.impl_side_painting) |
293 needs_redraw_ = true; | 373 needs_redraw_ = true; |
294 if (draw_if_possible_failed_) | 374 if (draw_if_possible_failed_) |
295 last_frame_number_where_draw_was_called_ = -1; | 375 last_begin_frame_count_draw_was_called_ = -1; |
296 | 376 |
297 if (needs_forced_redraw_after_next_commit_) { | 377 if (needs_forced_redraw_after_next_commit_) { |
298 needs_forced_redraw_after_next_commit_ = false; | 378 needs_forced_redraw_after_next_commit_ = false; |
299 needs_forced_redraw_ = true; | 379 needs_forced_redraw_ = true; |
300 } | 380 } |
301 | 381 commit_tree_has_been_drawn_ = false; |
302 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; | 382 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; |
303 return; | 383 return; |
304 | 384 |
305 case ACTION_DRAW_FORCED: | 385 case ACTION_DRAW_FORCED: |
306 case ACTION_DRAW_IF_POSSIBLE: | 386 case ACTION_DRAW_IF_POSSIBLE: |
307 needs_redraw_ = false; | 387 needs_redraw_ = false; |
308 needs_forced_redraw_ = false; | 388 needs_forced_redraw_ = false; |
309 draw_if_possible_failed_ = false; | 389 draw_if_possible_failed_ = false; |
310 swap_used_incomplete_tile_ = false; | 390 swap_used_incomplete_tile_ = false; |
311 if (inside_begin_frame_) | 391 last_begin_frame_count_draw_was_called_ = begin_frame_count_; |
312 last_frame_number_where_draw_was_called_ = current_frame_number_; | |
313 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { | 392 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { |
314 DCHECK(expect_immediate_begin_frame_for_main_thread_); | 393 DCHECK(expect_immediate_begin_frame_for_main_thread_); |
315 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 394 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
316 expect_immediate_begin_frame_for_main_thread_ = false; | 395 expect_immediate_begin_frame_for_main_thread_ = false; |
317 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { | 396 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { |
318 commit_state_ = COMMIT_STATE_IDLE; | 397 commit_state_ = COMMIT_STATE_IDLE; |
319 } | 398 } |
320 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) | 399 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) |
321 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 400 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
401 active_tree_has_been_drawn_ = true; | |
402 commit_tree_has_been_drawn_ = true; | |
322 return; | 403 return; |
323 | 404 |
324 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: | 405 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: |
325 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); | 406 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); |
326 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); | 407 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); |
327 output_surface_state_ = OUTPUT_SURFACE_CREATING; | 408 output_surface_state_ = OUTPUT_SURFACE_CREATING; |
328 return; | 409 return; |
329 | 410 |
330 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: | 411 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: |
331 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; | 412 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; |
(...skipping 19 matching lines...) Expand all Loading... | |
351 return true; | 432 return true; |
352 | 433 |
353 if (visible_ && swap_used_incomplete_tile_) | 434 if (visible_ && swap_used_incomplete_tile_) |
354 return true; | 435 return true; |
355 | 436 |
356 return needs_redraw_ && visible_ && | 437 return needs_redraw_ && visible_ && |
357 output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 438 output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
358 } | 439 } |
359 | 440 |
360 bool SchedulerStateMachine::ProactiveBeginFrameWantedByImplThread() const { | 441 bool SchedulerStateMachine::ProactiveBeginFrameWantedByImplThread() const { |
361 // Do not be proactive when invisible. | 442 if (settings_.using_synchronous_renderer_compositor) |
362 if (!visible_ || output_surface_state_ != OUTPUT_SURFACE_ACTIVE) | 443 return false; |
444 | |
445 if (!settings_.throttle_frame_production) | |
446 return false; | |
447 | |
448 if ((!visible_ || output_surface_state_ != OUTPUT_SURFACE_ACTIVE) && | |
449 !(needs_forced_commit_ || needs_forced_redraw_)) | |
363 return false; | 450 return false; |
364 | 451 |
365 // We should proactively request a BeginFrame if a commit or a tree activation | 452 // We should proactively request a BeginFrame if a commit or a tree activation |
366 // is pending. | 453 // is pending. |
367 return (needs_commit_ || needs_forced_commit_ || | 454 return (needs_commit_ || needs_forced_commit_ || |
368 commit_state_ != COMMIT_STATE_IDLE || has_pending_tree_); | 455 commit_state_ != COMMIT_STATE_IDLE || has_pending_tree_); |
369 } | 456 } |
370 | 457 |
371 void SchedulerStateMachine::DidEnterBeginFrame(const BeginFrameArgs& args) { | 458 void SchedulerStateMachine::OnBeginFrame(const BeginFrameArgs& args) { |
372 inside_begin_frame_ = true; | 459 begin_frame_count_++; |
460 draw_attempt_count_++; | |
373 last_begin_frame_args_ = args; | 461 last_begin_frame_args_ = args; |
462 begin_frame_state_ = BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME; | |
374 } | 463 } |
375 | 464 |
376 void SchedulerStateMachine::DidLeaveBeginFrame() { | 465 bool SchedulerStateMachine::ShouldTriggerBeginFrameDeadlineEarly() const { |
377 current_frame_number_++; | 466 // TODO(brianderson): This should take into account multiple commit sources. |
378 inside_begin_frame_ = false; | 467 return begin_frame_state_ == BEGIN_FRAME_STATE_DEADLINE_PENDING && |
468 WillDrawNewTree(); | |
379 } | 469 } |
380 | 470 |
381 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 471 bool SchedulerStateMachine::InsideBeginFrame() const { |
472 return begin_frame_state_ != BEGIN_FRAME_STATE_IDLE; | |
473 } | |
474 | |
475 bool SchedulerStateMachine::WillDrawNewTree() const { | |
476 if (settings_.impl_side_painting) | |
477 return !active_tree_has_been_drawn_; | |
478 else | |
479 return !commit_tree_has_been_drawn_; | |
480 } | |
481 | |
482 void SchedulerStateMachine::OnBeginFrameDeadline() { | |
483 DCHECK_EQ(begin_frame_state_, BEGIN_FRAME_STATE_DEADLINE_PENDING); | |
484 begin_frame_deadline_count_++; | |
485 draw_attempt_count_++; | |
486 begin_frame_state_ = BEGIN_FRAME_STATE_INSIDE_DEADLINE; | |
487 } | |
488 | |
489 void SchedulerStateMachine::SetVisible(bool visible) { | |
490 visible_ = visible; | |
491 } | |
382 | 492 |
383 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 493 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
384 | 494 |
385 void SchedulerStateMachine::DidSwapUseIncompleteTile() { | 495 void SchedulerStateMachine::DidSwapUseIncompleteTile() { |
386 swap_used_incomplete_tile_ = true; | 496 swap_used_incomplete_tile_ = true; |
387 } | 497 } |
388 | 498 |
389 void SchedulerStateMachine::SetNeedsForcedRedraw() { | 499 void SchedulerStateMachine::SetNeedsForcedRedraw() { |
390 needs_forced_redraw_ = true; | 500 needs_forced_redraw_ = true; |
391 } | 501 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
434 } | 544 } |
435 } | 545 } |
436 | 546 |
437 void SchedulerStateMachine::DidLoseOutputSurface() { | 547 void SchedulerStateMachine::DidLoseOutputSurface() { |
438 if (output_surface_state_ == OUTPUT_SURFACE_LOST || | 548 if (output_surface_state_ == OUTPUT_SURFACE_LOST || |
439 output_surface_state_ == OUTPUT_SURFACE_CREATING) | 549 output_surface_state_ == OUTPUT_SURFACE_CREATING) |
440 return; | 550 return; |
441 output_surface_state_ = OUTPUT_SURFACE_LOST; | 551 output_surface_state_ = OUTPUT_SURFACE_LOST; |
442 } | 552 } |
443 | 553 |
444 void SchedulerStateMachine::SetHasPendingTree(bool has_pending_tree) { | 554 void SchedulerStateMachine::SetHasTrees(bool has_pending_tree, |
555 bool active_tree_is_null) { | |
556 if (has_pending_tree_ && !has_pending_tree) { | |
557 // This is a new activation. | |
558 draw_attempt_count_++; | |
559 active_tree_has_been_drawn_ = false; | |
560 if (COMMIT_STATE_WAITING_FOR_ACTIVATION == commit_state_) | |
561 commit_state_ = COMMIT_STATE_IDLE; | |
562 } | |
563 | |
445 has_pending_tree_ = has_pending_tree; | 564 has_pending_tree_ = has_pending_tree; |
565 active_tree_is_null_ = active_tree_is_null; | |
446 } | 566 } |
447 | 567 |
448 void SchedulerStateMachine::SetCanDraw(bool can) { can_draw_ = can; } | 568 void SchedulerStateMachine::SetCanDraw(bool can_draw) { |
569 can_draw_ = can_draw; | |
570 } | |
449 | 571 |
450 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { | 572 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { |
451 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); | 573 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); |
452 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | 574 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
453 | 575 |
454 if (did_create_and_initialize_first_output_surface_) { | 576 if (did_create_and_initialize_first_output_surface_) { |
455 // TODO(boliu): See if we can remove this when impl-side painting is always | 577 // TODO(boliu): See if we can remove this when impl-side painting is always |
456 // on. Does anything on the main thread need to update after recreate? | 578 // on. Does anything on the main thread need to update after recreate? |
457 needs_commit_ = true; | 579 needs_commit_ = true; |
458 // If anything has requested a redraw, we don't want to actually draw | 580 // If anything has requested a redraw, we don't want to actually draw |
459 // when the output surface is restored until things have a chance to | 581 // when the output surface is restored until things have a chance to |
460 // sort themselves out with a commit. | 582 // sort themselves out with a commit. |
461 needs_redraw_ = false; | 583 needs_redraw_ = false; |
462 } | 584 } |
463 did_create_and_initialize_first_output_surface_ = true; | 585 did_create_and_initialize_first_output_surface_ = true; |
464 } | 586 } |
465 | 587 |
466 bool SchedulerStateMachine::HasInitializedOutputSurface() const { | 588 bool SchedulerStateMachine::HasInitializedOutputSurface() const { |
467 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 589 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
468 } | 590 } |
469 | 591 |
470 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( | 592 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( |
471 int num_draws) { | 593 int num_draws) { |
472 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; | 594 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; |
473 } | 595 } |
474 | 596 |
475 } // namespace cc | 597 } // namespace cc |
OLD | NEW |