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 #include "base/values.h" | 10 #include "base/values.h" |
11 | 11 |
12 namespace cc { | 12 namespace cc { |
13 | 13 |
14 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) | 14 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
15 : settings_(settings), | 15 : settings_(settings), |
16 output_surface_state_(OUTPUT_SURFACE_LOST), | 16 output_surface_state_(OUTPUT_SURFACE_LOST), |
17 commit_state_(COMMIT_STATE_IDLE), | 17 commit_state_(COMMIT_STATE_IDLE), |
18 commit_count_(0), | 18 commit_count_(0), |
19 current_frame_number_(0), | 19 current_frame_number_(0), |
20 last_frame_number_where_begin_frame_sent_to_main_thread_(-1), | 20 last_frame_number_where_begin_frame_sent_to_main_thread_(-1), |
21 last_frame_number_where_draw_was_called_(-1), | 21 last_frame_number_where_draw_was_called_(-1), |
22 last_frame_number_where_tree_activation_attempted_(-1), | |
23 last_frame_number_where_update_visible_tiles_was_called_(-1), | 22 last_frame_number_where_update_visible_tiles_was_called_(-1), |
24 consecutive_failed_draws_(0), | 23 consecutive_failed_draws_(0), |
25 maximum_number_of_failed_draws_before_draw_is_forced_(3), | 24 maximum_number_of_failed_draws_before_draw_is_forced_(3), |
26 needs_redraw_(false), | 25 needs_redraw_(false), |
27 swap_used_incomplete_tile_(false), | 26 swap_used_incomplete_tile_(false), |
28 needs_forced_redraw_(false), | 27 needs_forced_redraw_(false), |
29 needs_forced_redraw_after_next_commit_(false), | 28 needs_forced_redraw_after_next_commit_(false), |
30 needs_commit_(false), | 29 needs_commit_(false), |
31 needs_forced_commit_(false), | 30 needs_forced_commit_(false), |
32 expect_immediate_begin_frame_for_main_thread_(false), | 31 expect_immediate_begin_frame_for_main_thread_(false), |
33 main_thread_needs_layer_textures_(false), | 32 main_thread_needs_layer_textures_(false), |
34 inside_begin_frame_(false), | 33 inside_begin_frame_(false), |
35 visible_(false), | 34 visible_(false), |
36 can_start_(false), | 35 can_start_(false), |
37 can_draw_(false), | 36 can_draw_(false), |
38 has_pending_tree_(false), | 37 has_pending_tree_(false), |
| 38 pending_tree_is_ready_for_activation_(false), |
| 39 active_tree_has_been_drawn_(false), |
39 draw_if_possible_failed_(false), | 40 draw_if_possible_failed_(false), |
40 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), | 41 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), |
41 did_create_and_initialize_first_output_surface_(false) {} | 42 did_create_and_initialize_first_output_surface_(false) {} |
42 | 43 |
43 const char* SchedulerStateMachine::OutputSurfaceStateToString( | 44 const char* SchedulerStateMachine::OutputSurfaceStateToString( |
44 OutputSurfaceState state) { | 45 OutputSurfaceState state) { |
45 switch (state) { | 46 switch (state) { |
46 case OUTPUT_SURFACE_ACTIVE: | 47 case OUTPUT_SURFACE_ACTIVE: |
47 return "OUTPUT_SURFACE_ACTIVE"; | 48 return "OUTPUT_SURFACE_ACTIVE"; |
48 case OUTPUT_SURFACE_LOST: | 49 case OUTPUT_SURFACE_LOST: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 const char* SchedulerStateMachine::ActionToString(Action action) { | 92 const char* SchedulerStateMachine::ActionToString(Action action) { |
92 switch (action) { | 93 switch (action) { |
93 case ACTION_NONE: | 94 case ACTION_NONE: |
94 return "ACTION_NONE"; | 95 return "ACTION_NONE"; |
95 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: | 96 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
96 return "ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD"; | 97 return "ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD"; |
97 case ACTION_COMMIT: | 98 case ACTION_COMMIT: |
98 return "ACTION_COMMIT"; | 99 return "ACTION_COMMIT"; |
99 case ACTION_UPDATE_VISIBLE_TILES: | 100 case ACTION_UPDATE_VISIBLE_TILES: |
100 return "ACTION_UPDATE_VISIBLE_TILES"; | 101 return "ACTION_UPDATE_VISIBLE_TILES"; |
101 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: | 102 case ACTION_ACTIVATE_PENDING_TREE: |
102 return "ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED"; | 103 return "ACTION_ACTIVATE_PENDING_TREE"; |
103 case ACTION_DRAW_IF_POSSIBLE: | 104 case ACTION_DRAW_IF_POSSIBLE: |
104 return "ACTION_DRAW_IF_POSSIBLE"; | 105 return "ACTION_DRAW_IF_POSSIBLE"; |
105 case ACTION_DRAW_FORCED: | 106 case ACTION_DRAW_FORCED: |
106 return "ACTION_DRAW_FORCED"; | 107 return "ACTION_DRAW_FORCED"; |
107 case ACTION_DRAW_AND_SWAP_ABORT: | 108 case ACTION_DRAW_AND_SWAP_ABORT: |
108 return "ACTION_DRAW_AND_SWAP_ABORT"; | 109 return "ACTION_DRAW_AND_SWAP_ABORT"; |
109 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: | 110 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: |
110 return "ACTION_BEGIN_OUTPUT_SURFACE_CREATION"; | 111 return "ACTION_BEGIN_OUTPUT_SURFACE_CREATION"; |
111 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: | 112 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: |
112 return "ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD"; | 113 return "ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD"; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 state->Set("major_timestamps_in_ms", timestamps_state.release()); | 156 state->Set("major_timestamps_in_ms", timestamps_state.release()); |
156 | 157 |
157 scoped_ptr<base::DictionaryValue> minor_state(new base::DictionaryValue); | 158 scoped_ptr<base::DictionaryValue> minor_state(new base::DictionaryValue); |
158 minor_state->SetInteger("commit_count", commit_count_); | 159 minor_state->SetInteger("commit_count", commit_count_); |
159 minor_state->SetInteger("current_frame_number", current_frame_number_); | 160 minor_state->SetInteger("current_frame_number", current_frame_number_); |
160 minor_state->SetInteger( | 161 minor_state->SetInteger( |
161 "last_frame_number_where_begin_frame_sent_to_main_thread", | 162 "last_frame_number_where_begin_frame_sent_to_main_thread", |
162 last_frame_number_where_begin_frame_sent_to_main_thread_); | 163 last_frame_number_where_begin_frame_sent_to_main_thread_); |
163 minor_state->SetInteger("last_frame_number_where_draw_was_called", | 164 minor_state->SetInteger("last_frame_number_where_draw_was_called", |
164 last_frame_number_where_draw_was_called_); | 165 last_frame_number_where_draw_was_called_); |
165 minor_state->SetInteger("last_frame_number_where_tree_activation_attempted", | |
166 last_frame_number_where_tree_activation_attempted_); | |
167 minor_state->SetInteger( | 166 minor_state->SetInteger( |
168 "last_frame_number_where_update_visible_tiles_was_called", | 167 "last_frame_number_where_update_visible_tiles_was_called", |
169 last_frame_number_where_update_visible_tiles_was_called_); | 168 last_frame_number_where_update_visible_tiles_was_called_); |
170 minor_state->SetInteger("consecutive_failed_draws", | 169 minor_state->SetInteger("consecutive_failed_draws", |
171 consecutive_failed_draws_); | 170 consecutive_failed_draws_); |
172 minor_state->SetInteger( | 171 minor_state->SetInteger( |
173 "maximum_number_of_failed_draws_before_draw_is_forced", | 172 "maximum_number_of_failed_draws_before_draw_is_forced", |
174 maximum_number_of_failed_draws_before_draw_is_forced_); | 173 maximum_number_of_failed_draws_before_draw_is_forced_); |
175 minor_state->SetBoolean("needs_redraw", needs_redraw_); | 174 minor_state->SetBoolean("needs_redraw", needs_redraw_); |
176 minor_state->SetBoolean("swap_used_incomplete_tile", | 175 minor_state->SetBoolean("swap_used_incomplete_tile", |
177 swap_used_incomplete_tile_); | 176 swap_used_incomplete_tile_); |
178 minor_state->SetBoolean("needs_forced_redraw", needs_forced_redraw_); | 177 minor_state->SetBoolean("needs_forced_redraw", needs_forced_redraw_); |
179 minor_state->SetBoolean("needs_forced_redraw_after_next_commit", | 178 minor_state->SetBoolean("needs_forced_redraw_after_next_commit", |
180 needs_forced_redraw_after_next_commit_); | 179 needs_forced_redraw_after_next_commit_); |
181 minor_state->SetBoolean("needs_commit", needs_commit_); | 180 minor_state->SetBoolean("needs_commit", needs_commit_); |
182 minor_state->SetBoolean("needs_forced_commit", needs_forced_commit_); | 181 minor_state->SetBoolean("needs_forced_commit", needs_forced_commit_); |
183 minor_state->SetBoolean("expect_immediate_begin_frame_for_main_thread", | 182 minor_state->SetBoolean("expect_immediate_begin_frame_for_main_thread", |
184 expect_immediate_begin_frame_for_main_thread_); | 183 expect_immediate_begin_frame_for_main_thread_); |
185 minor_state->SetBoolean("main_thread_needs_layer_textures", | 184 minor_state->SetBoolean("main_thread_needs_layer_textures", |
186 main_thread_needs_layer_textures_); | 185 main_thread_needs_layer_textures_); |
187 minor_state->SetBoolean("inside_begin_frame", inside_begin_frame_); | 186 minor_state->SetBoolean("inside_begin_frame", inside_begin_frame_); |
188 minor_state->SetBoolean("visible", visible_); | 187 minor_state->SetBoolean("visible", visible_); |
189 minor_state->SetBoolean("can_start", can_start_); | 188 minor_state->SetBoolean("can_start", can_start_); |
190 minor_state->SetBoolean("can_draw", can_draw_); | 189 minor_state->SetBoolean("can_draw", can_draw_); |
191 minor_state->SetBoolean("has_pending_tree", has_pending_tree_); | 190 minor_state->SetBoolean("has_pending_tree", has_pending_tree_); |
| 191 minor_state->SetBoolean("pending_tree_is_ready_for_activation_", |
| 192 pending_tree_is_ready_for_activation_); |
| 193 minor_state->SetBoolean("active_tree_has_been_drawn_", |
| 194 active_tree_has_been_drawn_); |
192 minor_state->SetBoolean("draw_if_possible_failed", draw_if_possible_failed_); | 195 minor_state->SetBoolean("draw_if_possible_failed", draw_if_possible_failed_); |
193 minor_state->SetBoolean("did_create_and_initialize_first_output_surface", | 196 minor_state->SetBoolean("did_create_and_initialize_first_output_surface", |
194 did_create_and_initialize_first_output_surface_); | 197 did_create_and_initialize_first_output_surface_); |
195 state->Set("minor_state", minor_state.release()); | 198 state->Set("minor_state", minor_state.release()); |
196 | 199 |
197 return state.PassAs<base::Value>(); | 200 return state.PassAs<base::Value>(); |
198 } | 201 } |
199 | 202 |
200 bool SchedulerStateMachine::HasDrawnThisFrame() const { | 203 bool SchedulerStateMachine::HasDrawnThisFrame() const { |
201 return current_frame_number_ == last_frame_number_where_draw_was_called_; | 204 return current_frame_number_ == last_frame_number_where_draw_was_called_; |
202 } | 205 } |
203 | 206 |
204 bool SchedulerStateMachine::HasAttemptedTreeActivationThisFrame() const { | |
205 return current_frame_number_ == | |
206 last_frame_number_where_tree_activation_attempted_; | |
207 } | |
208 | |
209 bool SchedulerStateMachine::HasUpdatedVisibleTilesThisFrame() const { | 207 bool SchedulerStateMachine::HasUpdatedVisibleTilesThisFrame() const { |
210 return current_frame_number_ == | 208 return current_frame_number_ == |
211 last_frame_number_where_update_visible_tiles_was_called_; | 209 last_frame_number_where_update_visible_tiles_was_called_; |
212 } | 210 } |
213 | 211 |
214 bool SchedulerStateMachine::HasSentBeginFrameToMainThreadThisFrame() const { | 212 bool SchedulerStateMachine::HasSentBeginFrameToMainThreadThisFrame() const { |
215 return current_frame_number_ == | 213 return current_frame_number_ == |
216 last_frame_number_where_begin_frame_sent_to_main_thread_; | 214 last_frame_number_where_begin_frame_sent_to_main_thread_; |
217 } | 215 } |
218 | 216 |
219 void SchedulerStateMachine::HandleCommitInternal(bool commit_was_aborted) { | 217 bool SchedulerStateMachine::PendingDrawsShouldBeAborted() const { |
220 commit_count_++; | 218 // These are all the cases where we normally cannot or do not want to draw |
| 219 // but, if needs_redraw_ is true and we do not draw to make forward progress, |
| 220 // we might deadlock with the main thread. |
| 221 // This should be a superset of PendingActivationsShouldBeForced() since |
| 222 // activation of the pending tree is blocked by drawing of the active tree and |
| 223 // the main thread might be blocked on activation of the most recent commit. |
| 224 if (PendingActivationsShouldBeForced()) |
| 225 return true; |
221 | 226 |
222 // If we are impl-side-painting but the commit was aborted, then we behave | 227 // Additional states where we should abort draws. |
223 // mostly as if we are not impl-side-painting since there is no pending tree. | 228 // Note: We don't force activation in these cases because doing so would |
224 bool commit_results_in_pending_tree = | 229 // result in checkerboarding on resize, becoming visible, etc. |
225 settings_.impl_side_painting && !commit_was_aborted; | |
226 | |
227 // Update the commit state. | |
228 if (expect_immediate_begin_frame_for_main_thread_) | |
229 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; | |
230 else if (!commit_was_aborted) | |
231 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | |
232 else | |
233 commit_state_ = COMMIT_STATE_IDLE; | |
234 | |
235 // Update the output surface state. | |
236 DCHECK_NE(output_surface_state_, | |
237 OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION); | |
238 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { | |
239 if (commit_results_in_pending_tree) { | |
240 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION; | |
241 } else { | |
242 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | |
243 needs_redraw_ = true; | |
244 } | |
245 } | |
246 | |
247 // if we don't have to wait for activation, update needs_redraw now. | |
248 if (!commit_results_in_pending_tree) { | |
249 if (!commit_was_aborted) | |
250 needs_redraw_ = true; | |
251 if (expect_immediate_begin_frame_for_main_thread_) | |
252 needs_redraw_ = true; | |
253 } | |
254 | |
255 // This post-commit work is common to both completed and aborted commits. | |
256 if (draw_if_possible_failed_) | |
257 last_frame_number_where_draw_was_called_ = -1; | |
258 | |
259 if (needs_forced_redraw_after_next_commit_) { | |
260 needs_forced_redraw_after_next_commit_ = false; | |
261 needs_forced_redraw_ = true; | |
262 } | |
263 | |
264 // If we are planing to draw with the new commit, lock the layer textures for | |
265 // use on the impl thread. Otherwise, leave them unlocked. | |
266 if (commit_results_in_pending_tree || needs_redraw_ || needs_forced_redraw_) | |
267 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; | |
268 else | |
269 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | |
270 } | |
271 | |
272 bool SchedulerStateMachine::PendingDrawsShouldBeAborted() const { | |
273 // These are all the cases where, if we do not abort draws to make | |
274 // forward progress, we might deadlock with the main thread. | |
275 if (!can_draw_) | 230 if (!can_draw_) |
276 return true; | 231 return true; |
277 if (!visible_) | 232 if (!visible_) |
278 return true; | 233 return true; |
279 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) | 234 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) |
280 return true; | |
281 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD) | |
282 return true; | 235 return true; |
283 return false; | 236 return false; |
284 } | 237 } |
285 | 238 |
| 239 bool SchedulerStateMachine::PendingActivationsShouldBeForced() const { |
| 240 // These are all the cases where, if we do not force activations to make |
| 241 // forward progress, we might deadlock with the main thread. |
| 242 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD) |
| 243 return true; |
| 244 if (output_surface_state_ == OUTPUT_SURFACE_LOST || |
| 245 output_surface_state_ == OUTPUT_SURFACE_CREATING || |
| 246 output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) |
| 247 return true; |
| 248 return false; |
| 249 } |
| 250 |
| 251 bool SchedulerStateMachine::ShouldBeginOutputSurfaceCreation() const { |
| 252 // Don't try to initialize too early. |
| 253 if (!can_start_) |
| 254 return false; |
| 255 |
| 256 // We need to create the output surface if we don't have one and we haven't |
| 257 // started creating one yet. |
| 258 return output_surface_state_ == OUTPUT_SURFACE_LOST; |
| 259 } |
| 260 |
286 bool SchedulerStateMachine::ShouldDraw() const { | 261 bool SchedulerStateMachine::ShouldDraw() const { |
| 262 // We should not draw or abort draws while we are waiting for the |
| 263 // first activation. Doing so will cause us to transition to |
| 264 // COMMIT_STATE_IDLE and start the 2nd commit before the 1st commit |
| 265 // has been drawn. It will also cause us to fail readbacks when we could |
| 266 // have succeeded by waiting a little longer. |
| 267 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) |
| 268 return false; |
| 269 |
| 270 // When we are waiting for a forced draw, only force draw once |
| 271 // needs_forced_redraw_ is true. |
| 272 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) |
| 273 return needs_forced_redraw_; |
| 274 |
287 // Always handle forced draws ASAP. | 275 // Always handle forced draws ASAP. |
288 if (needs_forced_redraw_) | 276 if (needs_forced_redraw_) |
289 return true; | 277 return true; |
290 | 278 |
291 // If we are going to abort draws, we should do so ASAP. | 279 // If we need to abort draws, we should do so ASAP since the draw could |
292 if (PendingDrawsShouldBeAborted()) { | 280 // be blocking other important actions (like output surface initialization), |
293 // TODO(brianderson): Remove the !has_pending_tree_ condition once | 281 // from occuring. If we are waiting for the first draw, then perfom the |
294 // the Scheduler controls activation. It's dangerous for us to rely on | 282 // aborted draw to keep things moving. If we are not waiting for the first |
295 // an eventual activation if we've lost the output surface. | 283 // draw however, we don't want to abort for no reason. |
296 return commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW && | 284 if (PendingDrawsShouldBeAborted()) |
297 !has_pending_tree_; | 285 return commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW; |
298 } | |
299 | 286 |
300 // After this line, we only want to draw once per frame. | 287 // After this line, we only want to draw once per frame. |
301 if (HasDrawnThisFrame()) | 288 if (HasDrawnThisFrame()) |
302 return false; | 289 return false; |
303 | 290 |
304 // We currently only draw within the BeginFrame. | 291 // We currently only draw within the BeginFrame. |
305 if (!inside_begin_frame_) | 292 if (!inside_begin_frame_) |
306 return false; | 293 return false; |
307 | 294 |
308 return needs_redraw_; | 295 return needs_redraw_; |
309 } | 296 } |
310 | 297 |
311 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { | 298 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { |
312 return has_pending_tree_ && inside_begin_frame_ && | 299 if (!main_thread_needs_layer_textures_) |
313 !HasAttemptedTreeActivationThisFrame(); | 300 return false; |
| 301 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) |
| 302 return true; |
| 303 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); |
| 304 return false; |
| 305 } |
| 306 |
| 307 bool SchedulerStateMachine::ShouldActivatePendingTree() const { |
| 308 // There is nothing to activate. |
| 309 if (!has_pending_tree_) |
| 310 return false; |
| 311 |
| 312 // We don't want to activate a second tree before drawing the first one. |
| 313 // Note: It is possible that there is no active tree to draw when |
| 314 // output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION, |
| 315 // so we don't block activation on draw in that case. |
| 316 if (!active_tree_has_been_drawn_ && |
| 317 output_surface_state_ != OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) |
| 318 return false; |
| 319 |
| 320 // If we want to force activation, do so ASAP. |
| 321 if (PendingActivationsShouldBeForced()) |
| 322 return true; |
| 323 |
| 324 // At this point, only activate if we are ready to activate. |
| 325 return pending_tree_is_ready_for_activation_; |
314 } | 326 } |
315 | 327 |
316 bool SchedulerStateMachine::ShouldUpdateVisibleTiles() const { | 328 bool SchedulerStateMachine::ShouldUpdateVisibleTiles() const { |
317 if (!settings_.impl_side_painting) | 329 if (!settings_.impl_side_painting) |
318 return false; | 330 return false; |
319 if (HasUpdatedVisibleTilesThisFrame()) | 331 if (HasUpdatedVisibleTilesThisFrame()) |
320 return false; | 332 return false; |
321 | 333 |
322 return ShouldAttemptTreeActivation() || ShouldDraw() || | 334 // There's no reason to check for tiles if we don't have an output surface. |
323 swap_used_incomplete_tile_; | 335 if (!HasInitializedOutputSurface()) |
| 336 return false; |
| 337 |
| 338 // We always want to update the most recent visible tiles before drawing |
| 339 // so we draw with fewer missing tiles. |
| 340 if (ShouldDraw()) |
| 341 return true; |
| 342 |
| 343 // If the last swap drew with checkerboard or missing tiles, we should |
| 344 // poll for any new visible tiles so we can be notified to draw again |
| 345 // when there are. |
| 346 if (swap_used_incomplete_tile_) |
| 347 return true; |
| 348 |
| 349 return false; |
324 } | 350 } |
325 | 351 |
326 bool SchedulerStateMachine::ShouldSendBeginFrameToMainThread() const { | 352 bool SchedulerStateMachine::ShouldSendBeginFrameToMainThread() const { |
327 if (!needs_commit_) | 353 if (!needs_commit_) |
328 return false; | 354 return false; |
329 | 355 |
330 // Only send BeginFrame to the main thread when idle. | 356 // Only send BeginFrame to the main thread when idle. |
331 if (commit_state_ != COMMIT_STATE_IDLE) | 357 if (commit_state_ != COMMIT_STATE_IDLE) |
332 return false; | 358 return false; |
333 | 359 |
(...skipping 18 matching lines...) Expand all Loading... |
352 if (!visible_) | 378 if (!visible_) |
353 return false; | 379 return false; |
354 | 380 |
355 // We shouldn't normally accept commits if there isn't an OutputSurface. | 381 // We shouldn't normally accept commits if there isn't an OutputSurface. |
356 if (!HasInitializedOutputSurface()) | 382 if (!HasInitializedOutputSurface()) |
357 return false; | 383 return false; |
358 | 384 |
359 return true; | 385 return true; |
360 } | 386 } |
361 | 387 |
362 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { | |
363 if (!main_thread_needs_layer_textures_) | |
364 return false; | |
365 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) | |
366 return true; | |
367 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); | |
368 return false; | |
369 } | |
370 | |
371 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { | 388 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
372 if (ShouldAcquireLayerTexturesForMainThread()) | 389 if (ShouldAcquireLayerTexturesForMainThread()) |
373 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; | 390 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; |
374 | 391 |
375 switch (commit_state_) { | 392 switch (commit_state_) { |
376 case COMMIT_STATE_IDLE: { | 393 case COMMIT_STATE_IDLE: |
377 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | |
378 needs_forced_redraw_) | |
379 return ACTION_DRAW_FORCED; | |
380 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | |
381 needs_forced_commit_) | |
382 // TODO(enne): Should probably drop the active tree on force commit. | |
383 return has_pending_tree_ ? ACTION_NONE | |
384 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | |
385 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) | |
386 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; | |
387 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) | |
388 return ACTION_NONE; | |
389 if (ShouldUpdateVisibleTiles()) | 394 if (ShouldUpdateVisibleTiles()) |
390 return ACTION_UPDATE_VISIBLE_TILES; | 395 return ACTION_UPDATE_VISIBLE_TILES; |
391 if (ShouldAttemptTreeActivation()) | 396 if (ShouldActivatePendingTree()) |
392 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 397 return ACTION_ACTIVATE_PENDING_TREE; |
393 if (ShouldDraw()) { | 398 if (ShouldDraw()) { |
394 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 399 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
395 : ACTION_DRAW_IF_POSSIBLE; | 400 : ACTION_DRAW_IF_POSSIBLE; |
396 } | 401 } |
397 if (ShouldSendBeginFrameToMainThread()) | 402 if (ShouldSendBeginFrameToMainThread()) |
398 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | 403 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
| 404 if (ShouldBeginOutputSurfaceCreation()) |
| 405 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; |
399 return ACTION_NONE; | 406 return ACTION_NONE; |
400 } | 407 |
401 case COMMIT_STATE_FRAME_IN_PROGRESS: | 408 case COMMIT_STATE_FRAME_IN_PROGRESS: |
402 if (ShouldUpdateVisibleTiles()) | 409 if (ShouldUpdateVisibleTiles()) |
403 return ACTION_UPDATE_VISIBLE_TILES; | 410 return ACTION_UPDATE_VISIBLE_TILES; |
404 if (ShouldAttemptTreeActivation()) | 411 if (ShouldActivatePendingTree()) |
405 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 412 return ACTION_ACTIVATE_PENDING_TREE; |
406 if (ShouldDraw()) { | 413 if (ShouldDraw()) { |
407 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 414 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
408 : ACTION_DRAW_IF_POSSIBLE; | 415 : ACTION_DRAW_IF_POSSIBLE; |
409 } | 416 } |
410 return ACTION_NONE; | 417 return ACTION_NONE; |
411 | 418 |
412 case COMMIT_STATE_READY_TO_COMMIT: | 419 case COMMIT_STATE_READY_TO_COMMIT: |
413 return ACTION_COMMIT; | 420 return ACTION_COMMIT; |
414 | 421 |
415 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: { | 422 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: |
416 if (ShouldUpdateVisibleTiles()) | 423 if (ShouldUpdateVisibleTiles()) |
417 return ACTION_UPDATE_VISIBLE_TILES; | 424 return ACTION_UPDATE_VISIBLE_TILES; |
418 if (ShouldAttemptTreeActivation()) | 425 if (ShouldActivatePendingTree()) |
419 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 426 return ACTION_ACTIVATE_PENDING_TREE; |
420 if (ShouldDraw()) { | 427 if (ShouldDraw()) { |
421 if (needs_forced_redraw_) | 428 if (needs_forced_redraw_) |
422 return ACTION_DRAW_FORCED; | 429 return ACTION_DRAW_FORCED; |
423 else if (PendingDrawsShouldBeAborted()) | 430 else if (PendingDrawsShouldBeAborted()) |
424 return ACTION_DRAW_AND_SWAP_ABORT; | 431 return ACTION_DRAW_AND_SWAP_ABORT; |
425 else | 432 else |
426 return ACTION_DRAW_IF_POSSIBLE; | 433 return ACTION_DRAW_IF_POSSIBLE; |
427 } | 434 } |
428 return ACTION_NONE; | 435 return ACTION_NONE; |
429 } | |
430 | 436 |
431 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: | 437 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: |
432 if (ShouldUpdateVisibleTiles()) | 438 if (ShouldUpdateVisibleTiles()) |
433 return ACTION_UPDATE_VISIBLE_TILES; | 439 return ACTION_UPDATE_VISIBLE_TILES; |
434 if (ShouldAttemptTreeActivation()) | 440 if (ShouldActivatePendingTree()) |
435 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 441 return ACTION_ACTIVATE_PENDING_TREE; |
436 if (needs_forced_redraw_) | 442 if (ShouldDraw()) |
437 return ACTION_DRAW_FORCED; | 443 return ACTION_DRAW_FORCED; |
438 return ACTION_NONE; | 444 return ACTION_NONE; |
439 } | 445 } |
440 NOTREACHED(); | 446 NOTREACHED(); |
441 return ACTION_NONE; | 447 return ACTION_NONE; |
442 } | 448 } |
443 | 449 |
444 void SchedulerStateMachine::UpdateState(Action action) { | 450 void SchedulerStateMachine::UpdateState(Action action) { |
445 switch (action) { | 451 switch (action) { |
446 case ACTION_NONE: | 452 case ACTION_NONE: |
447 return; | 453 return; |
448 | 454 |
449 case ACTION_UPDATE_VISIBLE_TILES: | 455 case ACTION_UPDATE_VISIBLE_TILES: |
450 last_frame_number_where_update_visible_tiles_was_called_ = | 456 last_frame_number_where_update_visible_tiles_was_called_ = |
451 current_frame_number_; | 457 current_frame_number_; |
452 return; | 458 return; |
453 | 459 |
454 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: | 460 case ACTION_ACTIVATE_PENDING_TREE: |
455 last_frame_number_where_tree_activation_attempted_ = | 461 UpdateStateOnActivation(); |
456 current_frame_number_; | |
457 return; | 462 return; |
458 | 463 |
459 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: | 464 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
460 DCHECK(!has_pending_tree_); | 465 DCHECK(!has_pending_tree_); |
461 if (!needs_forced_commit_ && | 466 if (!needs_forced_commit_ && |
462 output_surface_state_ != OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { | 467 output_surface_state_ != OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { |
463 DCHECK(visible_); | 468 DCHECK(visible_); |
464 DCHECK_GT(current_frame_number_, | 469 DCHECK_GT(current_frame_number_, |
465 last_frame_number_where_begin_frame_sent_to_main_thread_); | 470 last_frame_number_where_begin_frame_sent_to_main_thread_); |
466 } | 471 } |
467 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 472 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
468 needs_commit_ = false; | 473 needs_commit_ = false; |
469 needs_forced_commit_ = false; | 474 needs_forced_commit_ = false; |
470 last_frame_number_where_begin_frame_sent_to_main_thread_ = | 475 last_frame_number_where_begin_frame_sent_to_main_thread_ = |
471 current_frame_number_; | 476 current_frame_number_; |
472 return; | 477 return; |
473 | 478 |
474 case ACTION_COMMIT: { | 479 case ACTION_COMMIT: { |
475 bool commit_was_aborted = false; | 480 bool commit_was_aborted = false; |
476 HandleCommitInternal(commit_was_aborted); | 481 UpdateStateOnCommit(commit_was_aborted); |
477 return; | 482 return; |
478 } | 483 } |
479 | 484 |
480 case ACTION_DRAW_FORCED: | 485 case ACTION_DRAW_FORCED: |
481 case ACTION_DRAW_IF_POSSIBLE: { | 486 case ACTION_DRAW_IF_POSSIBLE: { |
482 bool did_swap = true; | 487 bool did_swap = true; |
483 UpdateStateOnDraw(did_swap); | 488 UpdateStateOnDraw(did_swap); |
484 return; | 489 return; |
485 } | 490 } |
486 | 491 |
487 case ACTION_DRAW_AND_SWAP_ABORT: { | 492 case ACTION_DRAW_AND_SWAP_ABORT: { |
488 bool did_swap = false; | 493 bool did_swap = false; |
489 UpdateStateOnDraw(did_swap); | 494 UpdateStateOnDraw(did_swap); |
490 return; | 495 return; |
491 } | 496 } |
492 | 497 |
493 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: | 498 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: |
494 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); | 499 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); |
495 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); | 500 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); |
496 output_surface_state_ = OUTPUT_SURFACE_CREATING; | 501 output_surface_state_ = OUTPUT_SURFACE_CREATING; |
497 return; | 502 return; |
498 | 503 |
499 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: | 504 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: |
500 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; | 505 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; |
501 main_thread_needs_layer_textures_ = false; | 506 main_thread_needs_layer_textures_ = false; |
502 return; | 507 return; |
503 } | 508 } |
504 } | 509 } |
505 | 510 |
| 511 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) { |
| 512 commit_count_++; |
| 513 |
| 514 // If we are impl-side-painting but the commit was aborted, then we behave |
| 515 // mostly as if we are not impl-side-painting since there is no pending tree. |
| 516 has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted; |
| 517 |
| 518 // Update the commit state. |
| 519 if (expect_immediate_begin_frame_for_main_thread_) |
| 520 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
| 521 else if (!commit_was_aborted) |
| 522 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; |
| 523 else |
| 524 commit_state_ = COMMIT_STATE_IDLE; |
| 525 |
| 526 // Update the output surface state. |
| 527 DCHECK_NE(output_surface_state_, OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION); |
| 528 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { |
| 529 if (has_pending_tree_) { |
| 530 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION; |
| 531 } else { |
| 532 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
| 533 needs_redraw_ = true; |
| 534 } |
| 535 } |
| 536 |
| 537 // Update state if we have a new active tree to draw, or if the active tree |
| 538 // was unchanged but we need to do a readback. |
| 539 if (!has_pending_tree_ && |
| 540 (!commit_was_aborted || expect_immediate_begin_frame_for_main_thread_)) { |
| 541 needs_redraw_ = true; |
| 542 active_tree_has_been_drawn_ = false; |
| 543 } |
| 544 |
| 545 // This post-commit work is common to both completed and aborted commits. |
| 546 pending_tree_is_ready_for_activation_ = false; |
| 547 |
| 548 if (draw_if_possible_failed_) |
| 549 last_frame_number_where_draw_was_called_ = -1; |
| 550 |
| 551 if (needs_forced_redraw_after_next_commit_) { |
| 552 needs_forced_redraw_after_next_commit_ = false; |
| 553 needs_forced_redraw_ = true; |
| 554 } |
| 555 |
| 556 // If we are planing to draw with the new commit, lock the layer textures for |
| 557 // use on the impl thread. Otherwise, leave them unlocked. |
| 558 if (has_pending_tree_ || needs_redraw_ || needs_forced_redraw_) |
| 559 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; |
| 560 else |
| 561 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
| 562 } |
| 563 |
| 564 void SchedulerStateMachine::UpdateStateOnActivation() { |
| 565 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) |
| 566 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
| 567 |
| 568 has_pending_tree_ = false; |
| 569 pending_tree_is_ready_for_activation_ = false; |
| 570 active_tree_has_been_drawn_ = false; |
| 571 needs_redraw_ = true; |
| 572 } |
| 573 |
506 void SchedulerStateMachine::UpdateStateOnDraw(bool did_swap) { | 574 void SchedulerStateMachine::UpdateStateOnDraw(bool did_swap) { |
507 if (inside_begin_frame_) | 575 if (inside_begin_frame_) |
508 last_frame_number_where_draw_was_called_ = current_frame_number_; | 576 last_frame_number_where_draw_was_called_ = current_frame_number_; |
509 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { | 577 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { |
510 DCHECK(expect_immediate_begin_frame_for_main_thread_); | 578 DCHECK(expect_immediate_begin_frame_for_main_thread_); |
511 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 579 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
512 expect_immediate_begin_frame_for_main_thread_ = false; | 580 expect_immediate_begin_frame_for_main_thread_ = false; |
513 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { | 581 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { |
514 commit_state_ = COMMIT_STATE_IDLE; | 582 commit_state_ = COMMIT_STATE_IDLE; |
515 } | 583 } |
516 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) | 584 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) |
517 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 585 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
518 | 586 |
519 needs_redraw_ = false; | 587 needs_redraw_ = false; |
520 needs_forced_redraw_ = false; | 588 needs_forced_redraw_ = false; |
521 draw_if_possible_failed_ = false; | 589 draw_if_possible_failed_ = false; |
| 590 active_tree_has_been_drawn_ = true; |
522 | 591 |
523 if (did_swap) | 592 if (did_swap) |
524 swap_used_incomplete_tile_ = false; | 593 swap_used_incomplete_tile_ = false; |
525 } | 594 } |
526 | 595 |
527 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { | 596 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { |
528 DCHECK(!main_thread_needs_layer_textures_); | 597 DCHECK(!main_thread_needs_layer_textures_); |
529 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); | 598 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); |
530 main_thread_needs_layer_textures_ = true; | 599 main_thread_needs_layer_textures_ = true; |
531 } | 600 } |
532 | 601 |
533 bool SchedulerStateMachine::BeginFrameNeededToDrawByImplThread() const { | 602 bool SchedulerStateMachine::BeginFrameNeededToDrawByImplThread() const { |
534 // TODO(brianderson): Remove this hack once the Scheduler controls activation, | |
535 // otherwise we can get stuck in OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION. | |
536 // It lies that we actually need to draw, but we won't actually draw | |
537 // if we can't. This will cause WebView to potentially have corruption | |
538 // in the first few frames, but this workaround is being removed soon. | |
539 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) | |
540 return true; | |
541 | |
542 // If we can't draw, don't tick until we are notified that we can draw again. | 603 // If we can't draw, don't tick until we are notified that we can draw again. |
543 if (!can_draw_) | 604 if (!can_draw_) |
544 return false; | 605 return false; |
545 | 606 |
546 if (needs_forced_redraw_) | 607 if (needs_forced_redraw_) |
547 return true; | 608 return true; |
548 | 609 |
549 if (visible_ && swap_used_incomplete_tile_) | 610 if (visible_ && swap_used_incomplete_tile_) |
550 return true; | 611 return true; |
551 | 612 |
552 return needs_redraw_ && visible_ && HasInitializedOutputSurface(); | 613 return needs_redraw_ && visible_ && HasInitializedOutputSurface(); |
553 } | 614 } |
554 | 615 |
555 bool SchedulerStateMachine::ProactiveBeginFrameWantedByImplThread() const { | 616 bool SchedulerStateMachine::ProactiveBeginFrameWantedByImplThread() const { |
| 617 // The output surface is the provider of BeginFrames for the impl thread, |
| 618 // so we are not going to get them even if we ask for them. |
| 619 if (!HasInitializedOutputSurface()) |
| 620 return false; |
| 621 |
556 // Do not be proactive when invisible. | 622 // Do not be proactive when invisible. |
557 if (!visible_ || output_surface_state_ != OUTPUT_SURFACE_ACTIVE) | 623 if (!visible_) |
558 return false; | 624 return false; |
559 | 625 |
560 // We should proactively request a BeginFrame if a commit or a tree activation | 626 // We should proactively request a BeginFrame if a commit or a tree activation |
561 // is pending. | 627 // is pending. |
562 return (needs_commit_ || needs_forced_commit_ || | 628 return (needs_commit_ || needs_forced_commit_ || |
563 commit_state_ != COMMIT_STATE_IDLE || has_pending_tree_); | 629 commit_state_ != COMMIT_STATE_IDLE || has_pending_tree_); |
564 } | 630 } |
565 | 631 |
566 void SchedulerStateMachine::DidEnterBeginFrame(const BeginFrameArgs& args) { | 632 void SchedulerStateMachine::DidEnterBeginFrame(const BeginFrameArgs& args) { |
567 current_frame_number_++; | 633 current_frame_number_++; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 (expect_immediate_begin_frame_for_main_thread_ && | 682 (expect_immediate_begin_frame_for_main_thread_ && |
617 commit_state_ != COMMIT_STATE_IDLE)) | 683 commit_state_ != COMMIT_STATE_IDLE)) |
618 << *AsValue(); | 684 << *AsValue(); |
619 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; | 685 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; |
620 } | 686 } |
621 | 687 |
622 void SchedulerStateMachine::BeginFrameAbortedByMainThread(bool did_handle) { | 688 void SchedulerStateMachine::BeginFrameAbortedByMainThread(bool did_handle) { |
623 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); | 689 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); |
624 if (did_handle) { | 690 if (did_handle) { |
625 bool commit_was_aborted = true; | 691 bool commit_was_aborted = true; |
626 HandleCommitInternal(commit_was_aborted); | 692 UpdateStateOnCommit(commit_was_aborted); |
627 } else if (expect_immediate_begin_frame_for_main_thread_) { | 693 } else if (expect_immediate_begin_frame_for_main_thread_) { |
628 expect_immediate_begin_frame_for_main_thread_ = false; | 694 expect_immediate_begin_frame_for_main_thread_ = false; |
629 } else { | 695 } else { |
630 commit_state_ = COMMIT_STATE_IDLE; | 696 commit_state_ = COMMIT_STATE_IDLE; |
631 SetNeedsCommit(); | 697 SetNeedsCommit(); |
632 } | 698 } |
633 } | 699 } |
634 | 700 |
635 void SchedulerStateMachine::DidLoseOutputSurface() { | 701 void SchedulerStateMachine::DidLoseOutputSurface() { |
636 if (output_surface_state_ == OUTPUT_SURFACE_LOST || | 702 if (output_surface_state_ == OUTPUT_SURFACE_LOST || |
637 output_surface_state_ == OUTPUT_SURFACE_CREATING) | 703 output_surface_state_ == OUTPUT_SURFACE_CREATING) |
638 return; | 704 return; |
639 output_surface_state_ = OUTPUT_SURFACE_LOST; | 705 output_surface_state_ = OUTPUT_SURFACE_LOST; |
640 needs_redraw_ = false; | 706 needs_redraw_ = false; |
641 } | 707 } |
642 | 708 |
643 void SchedulerStateMachine::SetHasPendingTree(bool has_pending_tree) { | 709 void SchedulerStateMachine::NotifyReadyToActivate() { |
644 if (has_pending_tree_ && !has_pending_tree) { | 710 if (has_pending_tree_) |
645 // There is a new active tree. | 711 pending_tree_is_ready_for_activation_ = true; |
646 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) | |
647 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | |
648 | |
649 needs_redraw_ = true; | |
650 } | |
651 has_pending_tree_ = has_pending_tree; | |
652 } | 712 } |
653 | 713 |
654 void SchedulerStateMachine::SetCanDraw(bool can) { can_draw_ = can; } | 714 void SchedulerStateMachine::SetCanDraw(bool can) { can_draw_ = can; } |
655 | 715 |
656 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { | 716 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { |
657 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); | 717 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); |
658 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT; | 718 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT; |
659 | 719 |
660 if (did_create_and_initialize_first_output_surface_) { | 720 if (did_create_and_initialize_first_output_surface_) { |
661 // TODO(boliu): See if we can remove this when impl-side painting is always | 721 // TODO(boliu): See if we can remove this when impl-side painting is always |
(...skipping 17 matching lines...) Expand all Loading... |
679 NOTREACHED(); | 739 NOTREACHED(); |
680 return false; | 740 return false; |
681 } | 741 } |
682 | 742 |
683 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( | 743 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( |
684 int num_draws) { | 744 int num_draws) { |
685 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; | 745 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; |
686 } | 746 } |
687 | 747 |
688 } // namespace cc | 748 } // namespace cc |
OLD | NEW |