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 readback_state_(READBACK_STATE_IDLE), |
26 needs_forced_redraw_after_next_commit_(false), | 29 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE), |
27 needs_commit_(false), | 30 needs_commit_(false), |
28 needs_forced_commit_(false), | |
29 expect_immediate_begin_frame_for_main_thread_(false), | |
30 main_thread_needs_layer_textures_(false), | 31 main_thread_needs_layer_textures_(false), |
31 inside_begin_frame_(false), | 32 begin_frame_state_(BEGIN_FRAME_STATE_IDLE), |
| 33 commit_tree_has_been_drawn_(true), |
| 34 active_tree_has_been_drawn_(false), |
| 35 active_tree_is_null_(true), |
32 visible_(false), | 36 visible_(false), |
33 can_start_(false), | 37 can_start_(false), |
34 can_draw_(false), | 38 can_draw_(false), |
35 has_pending_tree_(false), | 39 has_pending_tree_(false), |
36 draw_if_possible_failed_(false), | 40 draw_if_possible_failed_(false), |
37 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), | 41 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), |
38 output_surface_state_(OUTPUT_SURFACE_LOST), | 42 output_surface_state_(OUTPUT_SURFACE_LOST), |
39 did_create_and_initialize_first_output_surface_(false) {} | 43 did_create_and_initialize_first_output_surface_(false) {} |
40 | 44 |
41 std::string SchedulerStateMachine::ToString() { | 45 std::string SchedulerStateMachine::ToString() { |
42 std::string str; | 46 std::string str; |
43 base::StringAppendF(&str, | 47 base::StringAppendF(&str, |
44 "settings_.impl_side_painting = %d; ", | 48 "settings_.impl_side_painting = %d; ", |
45 settings_.impl_side_painting); | 49 settings_.impl_side_painting); |
46 base::StringAppendF(&str, "commit_state_ = %d; ", commit_state_); | 50 base::StringAppendF(&str, "commit_state_ = %d; ", commit_state_); |
47 base::StringAppendF(&str, "commit_count_ = %d; ", commit_count_); | 51 base::StringAppendF(&str, "commit_count_ = %d; ", commit_count_); |
48 base::StringAppendF( | 52 base::StringAppendF(&str, "begin_frame_count_ = %d; ", |
49 &str, "current_frame_number_ = %d; ", current_frame_number_); | 53 begin_frame_count_); |
| 54 base::StringAppendF(&str, "draw_attempt_count_ = %d; ", |
| 55 draw_attempt_count_); |
50 base::StringAppendF(&str, | 56 base::StringAppendF(&str, |
51 "last_frame_number_where_draw_was_called_ = %d; ", | 57 "last_begin_frame_count_draw_was_called_ = %d; ", |
52 last_frame_number_where_draw_was_called_); | 58 last_begin_frame_count_draw_was_called_); |
53 base::StringAppendF( | 59 base::StringAppendF( |
54 &str, | 60 &str, |
55 "last_frame_number_where_tree_activation_attempted_ = %d; ", | 61 "last_draw_attempt_count_tree_activation_attempted_ = %d; ", |
56 last_frame_number_where_tree_activation_attempted_); | 62 last_draw_attempt_count_tree_activation_attempted_); |
57 base::StringAppendF( | 63 base::StringAppendF( |
58 &str, | 64 &str, |
59 "last_frame_number_where_check_for_completed_tile_uploads_called_ = %d; ", | 65 "last_draw_attempt_count_completed_tile_uploads_checked_ = %d; ", |
60 last_frame_number_where_check_for_completed_tile_uploads_called_); | 66 last_draw_attempt_count_completed_tile_uploads_checked_); |
61 base::StringAppendF( | 67 base::StringAppendF( |
62 &str, "consecutive_failed_draws_ = %d; ", consecutive_failed_draws_); | 68 &str, "consecutive_failed_draws_ = %d; ", consecutive_failed_draws_); |
63 base::StringAppendF( | 69 base::StringAppendF( |
64 &str, | 70 &str, |
65 "maximum_number_of_failed_draws_before_draw_is_forced_ = %d; ", | 71 "maximum_number_of_failed_draws_before_draw_is_forced_ = %d; ", |
66 maximum_number_of_failed_draws_before_draw_is_forced_); | 72 maximum_number_of_failed_draws_before_draw_is_forced_); |
67 base::StringAppendF(&str, "needs_redraw_ = %d; ", needs_redraw_); | 73 base::StringAppendF(&str, "needs_redraw_ = %d; ", needs_redraw_); |
68 base::StringAppendF( | 74 base::StringAppendF( |
69 &str, "swap_used_incomplete_tile_ = %d; ", swap_used_incomplete_tile_); | 75 &str, "swap_used_incomplete_tile_ = %d; ", swap_used_incomplete_tile_); |
70 base::StringAppendF( | 76 base::StringAppendF(&str, "readback_state_ = %d; ", readback_state_); |
71 &str, "needs_forced_redraw_ = %d; ", needs_forced_redraw_); | |
72 base::StringAppendF(&str, | 77 base::StringAppendF(&str, |
73 "needs_forced_redraw_after_next_commit_ = %d; ", | 78 "forced_redraw_state_ = %d; ", |
74 needs_forced_redraw_after_next_commit_); | 79 forced_redraw_state_); |
75 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_); | 80 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_); |
76 base::StringAppendF( | |
77 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); | |
78 base::StringAppendF(&str, | |
79 "expect_immediate_begin_frame_for_main_thread_ = %d; ", | |
80 expect_immediate_begin_frame_for_main_thread_); | |
81 base::StringAppendF(&str, | 81 base::StringAppendF(&str, |
82 "main_thread_needs_layer_textures_ = %d; ", | 82 "main_thread_needs_layer_textures_ = %d; ", |
83 main_thread_needs_layer_textures_); | 83 main_thread_needs_layer_textures_); |
84 base::StringAppendF(&str, "inside_begin_frame_ = %d; ", | 84 base::StringAppendF(&str, "begin_frame_state_ = %d; ", begin_frame_state_); |
85 inside_begin_frame_); | |
86 base::StringAppendF(&str, "last_frame_time_ = %"PRId64"; ", | 85 base::StringAppendF(&str, "last_frame_time_ = %"PRId64"; ", |
87 (last_begin_frame_args_.frame_time - base::TimeTicks()) | 86 (last_begin_frame_args_.frame_time - base::TimeTicks()) |
88 .InMilliseconds()); | 87 .InMilliseconds()); |
89 base::StringAppendF(&str, "last_deadline_ = %"PRId64"; ", | 88 base::StringAppendF(&str, "last_deadline_ = %"PRId64"; ", |
90 (last_begin_frame_args_.deadline - base::TimeTicks()).InMilliseconds()); | 89 (last_begin_frame_args_.deadline - base::TimeTicks()).InMilliseconds()); |
91 base::StringAppendF(&str, "last_interval_ = %"PRId64"; ", | 90 base::StringAppendF(&str, "last_interval_ = %"PRId64"; ", |
92 last_begin_frame_args_.interval.InMilliseconds()); | 91 last_begin_frame_args_.interval.InMilliseconds()); |
93 base::StringAppendF(&str, "visible_ = %d; ", visible_); | 92 base::StringAppendF(&str, "visible_ = %d; ", visible_); |
94 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); | 93 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); |
95 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); | 94 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); |
96 base::StringAppendF( | 95 base::StringAppendF( |
97 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); | 96 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); |
98 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); | 97 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); |
| 98 base::StringAppendF(&str, "commit_tree_has_been_drawn_ = %d; ", |
| 99 commit_tree_has_been_drawn_); |
| 100 base::StringAppendF(&str, "active_tree_has_been_drawn_ = %d; ", |
| 101 active_tree_has_been_drawn_); |
| 102 base::StringAppendF(&str, "active_tree_is_null_ = %d; ", |
| 103 active_tree_is_null_); |
99 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); | 104 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); |
100 base::StringAppendF( | 105 base::StringAppendF( |
101 &str, "output_surface_state_ = %d; ", output_surface_state_); | 106 &str, "output_surface_state_ = %d; ", output_surface_state_); |
102 return str; | 107 return str; |
103 } | 108 } |
104 | 109 |
105 bool SchedulerStateMachine::HasDrawnThisFrame() const { | 110 bool SchedulerStateMachine::HasDrawnThisFrame() const { |
106 return current_frame_number_ == last_frame_number_where_draw_was_called_; | 111 return begin_frame_count_ == last_begin_frame_count_draw_was_called_; |
107 } | 112 } |
108 | 113 |
109 bool SchedulerStateMachine::HasAttemptedTreeActivationThisFrame() const { | 114 bool SchedulerStateMachine::HasSentBeginFrameToMainThreadThisFrame() const { |
110 return current_frame_number_ == | 115 return begin_frame_count_ == |
111 last_frame_number_where_tree_activation_attempted_; | 116 last_begin_frame_count_begin_frame_sent_to_main_thread_; |
112 } | 117 } |
113 | 118 |
114 bool SchedulerStateMachine::HasCheckedForCompletedTileUploadsThisFrame() const { | 119 bool SchedulerStateMachine::HasAttemptedTreeActivationThisDrawAttempt() const { |
115 return current_frame_number_ == | 120 return draw_attempt_count_ == |
116 last_frame_number_where_check_for_completed_tile_uploads_called_; | 121 last_draw_attempt_count_tree_activation_attempted_; |
| 122 } |
| 123 |
| 124 bool SchedulerStateMachine:: |
| 125 HasCheckedForCompletedTileUploadsThisDrawAttempt() const { |
| 126 return draw_attempt_count_ == |
| 127 last_draw_attempt_count_completed_tile_uploads_checked_; |
117 } | 128 } |
118 | 129 |
119 bool SchedulerStateMachine::DrawSuspendedUntilCommit() const { | 130 bool SchedulerStateMachine::DrawSuspendedUntilCommit() const { |
120 if (!can_draw_) | 131 if (!can_draw_) |
121 return true; | 132 return true; |
122 if (!visible_) | 133 if (!visible_) |
123 return true; | 134 return true; |
124 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD) | 135 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD) |
125 return true; | 136 return true; |
126 return false; | 137 return false; |
127 } | 138 } |
128 | 139 |
129 bool SchedulerStateMachine::ScheduledToDraw() const { | 140 bool SchedulerStateMachine::ScheduledToDraw() const { |
130 if (!needs_redraw_) | 141 if (!needs_redraw_) |
131 return false; | 142 return false; |
132 if (DrawSuspendedUntilCommit()) | 143 if (DrawSuspendedUntilCommit()) |
133 return false; | 144 return false; |
134 return true; | 145 return true; |
135 } | 146 } |
136 | 147 |
137 bool SchedulerStateMachine::ShouldDraw() const { | 148 bool SchedulerStateMachine::ShouldDraw() const { |
138 if (needs_forced_redraw_) | 149 // After a readback, make sure not to draw again until we've replaced the |
139 return true; | 150 // readback commit with a real one. |
| 151 if (readback_state_ == READBACK_STATE_REPLACEMENT_COMMIT_PENDING || |
| 152 readback_state_ == READBACK_STATE_REPLACEMENT_COMMIT_ACTIVATING) |
| 153 return false; |
140 | 154 |
| 155 // Only draw outside of the BeginFrame deadline for readbacks or if we've |
| 156 // lost the outpust surface or are waiting for a forced draw. |
| 157 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) |
| 158 return commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
| 159 if (output_surface_state_ == OUTPUT_SURFACE_LOST) |
| 160 return commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW || |
| 161 commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
| 162 |
| 163 // Never draw outside of the BeginFrame deadline (except for readbacks). |
| 164 if (begin_frame_state_ != BEGIN_FRAME_STATE_INSIDE_DEADLINE) |
| 165 return false; |
| 166 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
| 167 return commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
| 168 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) |
| 169 return false; |
141 if (!ScheduledToDraw()) | 170 if (!ScheduledToDraw()) |
142 return false; | 171 return false; |
143 if (!inside_begin_frame_) | |
144 return false; | |
145 if (HasDrawnThisFrame()) | 172 if (HasDrawnThisFrame()) |
146 return false; | 173 return false; |
147 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) | 174 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) |
148 return false; | 175 return false; |
149 return true; | 176 return true; |
150 } | 177 } |
151 | 178 |
152 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { | 179 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { |
153 return has_pending_tree_ && inside_begin_frame_ && | 180 return !HasAttemptedTreeActivationThisDrawAttempt() && |
154 !HasAttemptedTreeActivationThisFrame(); | 181 has_pending_tree_ && |
| 182 (!can_draw_ || !visible_ || |
| 183 output_surface_state_ != OUTPUT_SURFACE_ACTIVE || |
| 184 ((active_tree_has_been_drawn_ || active_tree_is_null_) && |
| 185 begin_frame_state_ != BEGIN_FRAME_STATE_IDLE)); |
155 } | 186 } |
156 | 187 |
157 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const { | 188 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const { |
158 if (!settings_.impl_side_painting) | 189 if (!settings_.impl_side_painting) |
159 return false; | 190 return false; |
160 if (HasCheckedForCompletedTileUploadsThisFrame()) | 191 if (HasCheckedForCompletedTileUploadsThisDrawAttempt()) |
161 return false; | 192 return false; |
162 | 193 |
163 return ShouldAttemptTreeActivation() || ShouldDraw() || | 194 return ShouldAttemptTreeActivation() || ShouldDraw() || |
164 swap_used_incomplete_tile_; | 195 swap_used_incomplete_tile_; |
165 } | 196 } |
166 | 197 |
167 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { | 198 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { |
168 if (!main_thread_needs_layer_textures_) | 199 if (!main_thread_needs_layer_textures_) |
169 return false; | 200 return false; |
170 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) | 201 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) |
171 return true; | 202 return true; |
172 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); | 203 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); |
173 // Transfer the lock from impl thread to main thread immediately if the | 204 // Transfer the lock from impl thread to main thread immediately if the |
174 // impl thread is not even scheduled to draw. Guards against deadlocking. | 205 // impl thread is not even scheduled to draw. Guards against deadlocking. |
175 if (!ScheduledToDraw()) | 206 if (!ScheduledToDraw()) |
176 return true; | 207 return true; |
177 if (!BeginFrameNeededToDrawByImplThread()) | 208 if (!BeginFrameNeededToDrawByImplThread()) |
178 return true; | 209 return true; |
179 return false; | 210 return false; |
180 } | 211 } |
181 | 212 |
| 213 bool SchedulerStateMachine::ShouldSendBeginFrameToMainThread() const { |
| 214 if (HasSentBeginFrameToMainThreadThisFrame()) |
| 215 return false; |
| 216 |
| 217 if (readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED) |
| 218 return true; |
| 219 |
| 220 // TODO(brianderson): Allow sending BeginFrame to main thread while idle when |
| 221 // the main thread isn't consuming user input. |
| 222 if (begin_frame_state_ == BEGIN_FRAME_STATE_IDLE && |
| 223 BeginFrameNeededByImplThread()) |
| 224 return false; |
| 225 |
| 226 // Do not send begin frame to main thread in the deadline until we have drawn. |
| 227 if (begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_DEADLINE && |
| 228 !HasDrawnThisFrame()) |
| 229 return false; |
| 230 |
| 231 // We can't accept a commit if we have a pending tree. |
| 232 if (has_pending_tree_) |
| 233 return false; |
| 234 |
| 235 bool can_commit = needs_commit_ && |
| 236 (visible_ || |
| 237 forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); |
| 238 switch (commit_state_) { |
| 239 case COMMIT_STATE_IDLE: |
| 240 return can_commit && |
| 241 (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT || |
| 242 output_surface_state_ == OUTPUT_SURFACE_ACTIVE); |
| 243 |
| 244 // COMMIT_STATE_WAITING_FOR_ACTIVATION wants to enforce activation and |
| 245 // eventually a draw. |
| 246 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. |
| 247 // If can_draw_ is false or textures are not available, proceed to the |
| 248 // next step (similar as in COMMIT_STATE_IDLE). |
| 249 case COMMIT_STATE_WAITING_FOR_ACTIVATION: |
| 250 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: |
| 251 return can_commit && DrawSuspendedUntilCommit(); |
| 252 default: |
| 253 return false; |
| 254 } |
| 255 |
| 256 return false; |
| 257 } |
| 258 |
182 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { | 259 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
183 if (ShouldAcquireLayerTexturesForMainThread()) | 260 if (ShouldAcquireLayerTexturesForMainThread()) |
184 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; | 261 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; |
185 | 262 |
186 switch (commit_state_) { | 263 switch (commit_state_) { |
187 case COMMIT_STATE_IDLE: | 264 case COMMIT_STATE_IDLE: |
188 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | 265 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && |
189 needs_forced_redraw_) | 266 readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED) |
190 return ACTION_DRAW_FORCED; | |
191 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | |
192 needs_forced_commit_) | |
193 // TODO(enne): Should probably drop the active tree on force commit. | |
194 return has_pending_tree_ ? ACTION_NONE | 267 return has_pending_tree_ ? ACTION_NONE |
195 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | 268 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
196 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) | 269 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) |
197 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; | 270 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; |
198 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) | 271 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) |
199 return ACTION_NONE; | 272 return ACTION_NONE; |
200 if (ShouldCheckForCompletedTileUploads()) | 273 if (ShouldCheckForCompletedTileUploads()) |
201 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 274 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
202 if (ShouldAttemptTreeActivation()) | 275 if (ShouldAttemptTreeActivation()) |
203 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 276 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
204 if (ShouldDraw()) { | 277 if (ShouldDraw()) |
205 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 278 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; |
206 : ACTION_DRAW_IF_POSSIBLE; | 279 if (ShouldSendBeginFrameToMainThread()) { |
| 280 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
207 } | 281 } |
208 if (needs_commit_ && | |
209 ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE) | |
210 || needs_forced_commit_)) | |
211 // TODO(enne): Should probably drop the active tree on force commit. | |
212 return has_pending_tree_ ? ACTION_NONE | |
213 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | |
214 return ACTION_NONE; | 282 return ACTION_NONE; |
215 | 283 |
216 case COMMIT_STATE_FRAME_IN_PROGRESS: | 284 case COMMIT_STATE_FRAME_IN_PROGRESS: |
217 if (ShouldCheckForCompletedTileUploads()) | 285 if (ShouldCheckForCompletedTileUploads()) |
218 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 286 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
219 if (ShouldAttemptTreeActivation()) | 287 if (ShouldAttemptTreeActivation()) |
220 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 288 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
221 if (ShouldDraw()) { | 289 if (ShouldDraw()) |
222 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 290 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; |
223 : ACTION_DRAW_IF_POSSIBLE; | |
224 } | |
225 return ACTION_NONE; | 291 return ACTION_NONE; |
226 | 292 |
227 case COMMIT_STATE_READY_TO_COMMIT: | 293 case COMMIT_STATE_READY_TO_COMMIT: |
228 return ACTION_COMMIT; | 294 return ACTION_COMMIT; |
229 | 295 |
| 296 case COMMIT_STATE_WAITING_FOR_ACTIVATION: { |
| 297 if (ShouldCheckForCompletedTileUploads()) |
| 298 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
| 299 if (ShouldAttemptTreeActivation()) |
| 300 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
| 301 if (ShouldDraw()) |
| 302 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; |
| 303 if (ShouldSendBeginFrameToMainThread()) |
| 304 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
| 305 return ACTION_NONE; |
| 306 } |
| 307 |
230 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: { | 308 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: { |
231 if (ShouldCheckForCompletedTileUploads()) | 309 if (ShouldCheckForCompletedTileUploads()) |
232 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 310 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
233 if (ShouldAttemptTreeActivation()) | 311 if (ShouldAttemptTreeActivation()) |
234 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 312 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
235 if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) { | 313 if (ShouldDraw()) |
236 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 314 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; |
237 : ACTION_DRAW_IF_POSSIBLE; | 315 if (ShouldSendBeginFrameToMainThread()) |
238 } | 316 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
239 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If | |
240 // can_draw_ is false or textures are not available, proceed to the next | |
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; | 317 return ACTION_NONE; |
247 } | 318 } |
248 | 319 |
249 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: | 320 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: |
250 if (ShouldCheckForCompletedTileUploads()) | 321 if (ShouldCheckForCompletedTileUploads()) |
251 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 322 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
252 if (ShouldAttemptTreeActivation()) | 323 if (ShouldAttemptTreeActivation()) |
253 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 324 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
254 if (needs_forced_redraw_) | 325 if (ShouldDraw()) { |
255 return ACTION_DRAW_FORCED; | 326 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
| 327 return ACTION_DRAW_AND_SWAP_FORCED; |
| 328 else if (readback_state_ == |
| 329 READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) |
| 330 return ACTION_DRAW_AND_READBACK; |
| 331 NOTREACHED(); |
| 332 } |
256 return ACTION_NONE; | 333 return ACTION_NONE; |
257 } | 334 } |
258 NOTREACHED(); | 335 NOTREACHED(); |
259 return ACTION_NONE; | 336 return ACTION_NONE; |
260 } | 337 } |
261 | 338 |
262 void SchedulerStateMachine::UpdateState(Action action) { | 339 void SchedulerStateMachine::UpdateState(Action action) { |
263 switch (action) { | 340 switch (action) { |
264 case ACTION_NONE: | 341 case ACTION_NONE: |
265 return; | 342 return; |
266 | 343 |
267 case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS: | 344 case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS: |
268 last_frame_number_where_check_for_completed_tile_uploads_called_ = | 345 last_draw_attempt_count_completed_tile_uploads_checked_ = |
269 current_frame_number_; | 346 draw_attempt_count_; |
270 return; | 347 return; |
271 | 348 |
272 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: | 349 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: |
273 last_frame_number_where_tree_activation_attempted_ = | 350 last_draw_attempt_count_tree_activation_attempted_ = |
274 current_frame_number_; | 351 draw_attempt_count_; |
275 return; | 352 return; |
276 | 353 |
277 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: | 354 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
278 DCHECK(!has_pending_tree_); | 355 DCHECK(!has_pending_tree_); |
279 DCHECK(visible_ || needs_forced_commit_); | 356 DCHECK(visible_ || |
| 357 readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED || |
| 358 forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); |
280 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 359 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
281 needs_commit_ = false; | 360 needs_commit_ = false; |
282 needs_forced_commit_ = false; | 361 if (readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED) |
| 362 readback_state_ = READBACK_STATE_FORCED_COMMIT_PENDING; |
| 363 last_begin_frame_count_begin_frame_sent_to_main_thread_ = |
| 364 begin_frame_count_; |
283 return; | 365 return; |
284 | 366 |
285 case ACTION_COMMIT: | 367 case ACTION_COMMIT: |
286 commit_count_++; | 368 commit_count_++; |
287 if (expect_immediate_begin_frame_for_main_thread_) | |
288 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; | |
289 else | |
290 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | |
291 // When impl-side painting, we draw on activation instead of on commit. | |
292 if (!settings_.impl_side_painting) | |
293 needs_redraw_ = true; | |
294 if (draw_if_possible_failed_) | |
295 last_frame_number_where_draw_was_called_ = -1; | |
296 | 369 |
297 if (needs_forced_redraw_after_next_commit_) { | 370 if (settings_.impl_side_painting) { |
298 needs_forced_redraw_after_next_commit_ = false; | 371 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) |
299 needs_forced_redraw_ = true; | 372 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION; |
| 373 else if (readback_state_ == READBACK_STATE_FORCED_COMMIT_PENDING) |
| 374 readback_state_ = READBACK_STATE_WAITING_FOR_ACTIVATION; |
| 375 else if (readback_state_ == READBACK_STATE_REPLACEMENT_COMMIT_PENDING) |
| 376 readback_state_ = READBACK_STATE_REPLACEMENT_COMMIT_ACTIVATING; |
| 377 commit_state_ = COMMIT_STATE_WAITING_FOR_ACTIVATION; |
| 378 } else { |
| 379 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) { |
| 380 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; |
| 381 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
| 382 } else if (readback_state_ == READBACK_STATE_FORCED_COMMIT_PENDING || |
| 383 readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED) { |
| 384 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; |
| 385 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
| 386 } else { |
| 387 if (readback_state_ == READBACK_STATE_REPLACEMENT_COMMIT_PENDING) |
| 388 readback_state_ = READBACK_STATE_IDLE; |
| 389 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; |
| 390 } |
300 } | 391 } |
301 | 392 |
| 393 // When impl-side painting, we draw on activation instead of on commit. |
| 394 if (!settings_.impl_side_painting) { |
| 395 needs_redraw_ = true; |
| 396 if (draw_if_possible_failed_) |
| 397 last_begin_frame_count_draw_was_called_ = -1; |
| 398 } |
| 399 commit_tree_has_been_drawn_ = false; |
302 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; | 400 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; |
303 return; | 401 return; |
304 | 402 |
305 case ACTION_DRAW_FORCED: | 403 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: |
306 case ACTION_DRAW_IF_POSSIBLE: | 404 case ACTION_DRAW_AND_SWAP_FORCED: |
307 needs_redraw_ = false; | 405 case ACTION_DRAW_AND_READBACK: |
308 needs_forced_redraw_ = false; | |
309 draw_if_possible_failed_ = false; | |
310 swap_used_incomplete_tile_ = false; | |
311 if (inside_begin_frame_) | |
312 last_frame_number_where_draw_was_called_ = current_frame_number_; | |
313 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { | 406 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { |
314 DCHECK(expect_immediate_begin_frame_for_main_thread_); | 407 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) { |
315 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 408 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE; |
316 expect_immediate_begin_frame_for_main_thread_ = false; | 409 } else if (readback_state_ == |
| 410 READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) { |
| 411 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
| 412 readback_state_ = has_pending_tree_ ? |
| 413 READBACK_STATE_REPLACEMENT_COMMIT_ACTIVATING : |
| 414 READBACK_STATE_REPLACEMENT_COMMIT_PENDING; |
| 415 } |
317 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { | 416 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { |
318 commit_state_ = COMMIT_STATE_IDLE; | 417 commit_state_ = COMMIT_STATE_IDLE; |
319 } | 418 } |
| 419 needs_redraw_ = false; |
| 420 draw_if_possible_failed_ = false; |
| 421 swap_used_incomplete_tile_ = false; |
| 422 last_begin_frame_count_draw_was_called_ = begin_frame_count_; |
320 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) | 423 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) |
321 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 424 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
| 425 active_tree_has_been_drawn_ = true; |
| 426 commit_tree_has_been_drawn_ = true; |
322 return; | 427 return; |
323 | 428 |
324 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: | 429 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: |
325 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); | 430 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); |
326 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); | 431 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); |
327 output_surface_state_ = OUTPUT_SURFACE_CREATING; | 432 output_surface_state_ = OUTPUT_SURFACE_CREATING; |
328 return; | 433 return; |
329 | 434 |
330 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: | 435 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: |
331 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; | 436 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; |
332 main_thread_needs_layer_textures_ = false; | 437 main_thread_needs_layer_textures_ = false; |
333 return; | 438 return; |
334 } | 439 } |
335 } | 440 } |
336 | 441 |
| 442 void SchedulerStateMachine::AdvanceBeginFrameStateWhenNoActionsRemain() { |
| 443 switch (begin_frame_state_) { |
| 444 case BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME: |
| 445 begin_frame_state_ = BEGIN_FRAME_STATE_DEADLINE_PENDING; |
| 446 break; |
| 447 case BEGIN_FRAME_STATE_INSIDE_DEADLINE: |
| 448 begin_frame_state_ = BEGIN_FRAME_STATE_IDLE; |
| 449 break; |
| 450 case BEGIN_FRAME_STATE_IDLE: |
| 451 case BEGIN_FRAME_STATE_DEADLINE_PENDING: |
| 452 break; |
| 453 } |
| 454 } |
| 455 |
337 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { | 456 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { |
338 DCHECK(!main_thread_needs_layer_textures_); | 457 DCHECK(!main_thread_needs_layer_textures_); |
339 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); | 458 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); |
340 main_thread_needs_layer_textures_ = true; | 459 main_thread_needs_layer_textures_ = true; |
341 } | 460 } |
342 | 461 |
| 462 bool SchedulerStateMachine::BeginFrameNeededByImplThread() const { |
| 463 return BeginFrameNeededToDrawByImplThread() || |
| 464 BeginFrameProactivelyNeededByImplThread(); |
| 465 } |
| 466 |
343 bool SchedulerStateMachine::BeginFrameNeededToDrawByImplThread() const { | 467 bool SchedulerStateMachine::BeginFrameNeededToDrawByImplThread() const { |
344 // If we can't draw, don't tick until we are notified that we can draw again. | 468 // If we can't draw, don't tick until we are notified that we can draw again. |
345 if (!can_draw_) | 469 if (!can_draw_) |
346 return false; | 470 return false; |
347 | 471 |
348 if (needs_forced_redraw_) | 472 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
349 return true; | 473 return true; |
350 | 474 |
351 if (visible_ && swap_used_incomplete_tile_) | 475 if (visible_ && swap_used_incomplete_tile_) |
352 return true; | 476 return true; |
353 | 477 |
354 return needs_redraw_ && visible_ && | 478 return needs_redraw_ && visible_ && |
355 output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 479 output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
356 } | 480 } |
357 | 481 |
358 bool SchedulerStateMachine::ProactiveBeginFrameWantedByImplThread() const { | 482 bool SchedulerStateMachine::BeginFrameProactivelyNeededByImplThread() const { |
359 // Do not be proactive when invisible. | 483 if (settings_.using_synchronous_renderer_compositor) |
| 484 return false; |
| 485 |
| 486 if (!settings_.throttle_frame_production) |
| 487 return false; |
| 488 |
360 if (!visible_ || output_surface_state_ != OUTPUT_SURFACE_ACTIVE) | 489 if (!visible_ || output_surface_state_ != OUTPUT_SURFACE_ACTIVE) |
361 return false; | 490 return false; |
362 | 491 |
363 // We should proactively request a BeginFrame if a commit or a tree activation | 492 // We should proactively request a BeginFrame if a commit or a tree activation |
364 // is pending. | 493 // is pending. |
365 return (needs_commit_ || needs_forced_commit_ || | 494 return (needs_commit_ || |
366 commit_state_ != COMMIT_STATE_IDLE || has_pending_tree_); | 495 commit_state_ != COMMIT_STATE_IDLE || |
| 496 has_pending_tree_); |
367 } | 497 } |
368 | 498 |
369 void SchedulerStateMachine::DidEnterBeginFrame(const BeginFrameArgs& args) { | 499 void SchedulerStateMachine::OnBeginFrame(const BeginFrameArgs& args) { |
370 inside_begin_frame_ = true; | 500 begin_frame_count_++; |
| 501 draw_attempt_count_++; |
371 last_begin_frame_args_ = args; | 502 last_begin_frame_args_ = args; |
| 503 begin_frame_state_ = BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME; |
372 } | 504 } |
373 | 505 |
374 void SchedulerStateMachine::DidLeaveBeginFrame() { | 506 bool SchedulerStateMachine::ShouldTriggerBeginFrameDeadlineEarly() const { |
375 current_frame_number_++; | 507 // TODO(brianderson): This should take into account multiple commit sources. |
376 inside_begin_frame_ = false; | 508 return begin_frame_state_ == BEGIN_FRAME_STATE_DEADLINE_PENDING && |
| 509 WillDrawNewTree(); |
377 } | 510 } |
378 | 511 |
379 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 512 bool SchedulerStateMachine::InsideBeginFrame() const { |
| 513 return begin_frame_state_ != BEGIN_FRAME_STATE_IDLE; |
| 514 } |
| 515 |
| 516 bool SchedulerStateMachine::WillDrawNewTree() const { |
| 517 if (settings_.impl_side_painting) |
| 518 return !active_tree_has_been_drawn_; |
| 519 else |
| 520 return !commit_tree_has_been_drawn_; |
| 521 } |
| 522 |
| 523 void SchedulerStateMachine::OnBeginFrameDeadline() { |
| 524 DCHECK_EQ(begin_frame_state_, BEGIN_FRAME_STATE_DEADLINE_PENDING); |
| 525 begin_frame_deadline_count_++; |
| 526 draw_attempt_count_++; |
| 527 begin_frame_state_ = BEGIN_FRAME_STATE_INSIDE_DEADLINE; |
| 528 } |
| 529 |
| 530 void SchedulerStateMachine::SetVisible(bool visible) { |
| 531 visible_ = visible; |
| 532 } |
380 | 533 |
381 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 534 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
382 | 535 |
383 void SchedulerStateMachine::DidSwapUseIncompleteTile() { | 536 void SchedulerStateMachine::DidSwapUseIncompleteTile() { |
384 swap_used_incomplete_tile_ = true; | 537 swap_used_incomplete_tile_ = true; |
385 } | 538 } |
386 | 539 |
387 void SchedulerStateMachine::SetNeedsForcedRedraw() { | |
388 needs_forced_redraw_ = true; | |
389 } | |
390 | |
391 void SchedulerStateMachine::DidDrawIfPossibleCompleted(bool success) { | 540 void SchedulerStateMachine::DidDrawIfPossibleCompleted(bool success) { |
392 draw_if_possible_failed_ = !success; | 541 draw_if_possible_failed_ = !success; |
393 if (draw_if_possible_failed_) { | 542 if (draw_if_possible_failed_) { |
394 needs_redraw_ = true; | 543 needs_redraw_ = true; |
395 needs_commit_ = true; | 544 needs_commit_ = true; |
396 consecutive_failed_draws_++; | 545 consecutive_failed_draws_++; |
397 if (settings_.timeout_and_draw_when_animation_checkerboards && | 546 if (settings_.timeout_and_draw_when_animation_checkerboards && |
398 consecutive_failed_draws_ >= | 547 consecutive_failed_draws_ >= |
399 maximum_number_of_failed_draws_before_draw_is_forced_) { | 548 maximum_number_of_failed_draws_before_draw_is_forced_) { |
400 consecutive_failed_draws_ = 0; | 549 consecutive_failed_draws_ = 0; |
401 // We need to force a draw, but it doesn't make sense to do this until | 550 // We need to force a draw, but it doesn't make sense to do this until |
402 // we've committed and have new textures. | 551 // we've committed and have new textures. |
403 needs_forced_redraw_after_next_commit_ = true; | 552 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT; |
404 } | 553 } |
405 } else { | 554 } else { |
406 consecutive_failed_draws_ = 0; | 555 consecutive_failed_draws_ = 0; |
407 } | 556 } |
408 } | 557 } |
409 | 558 |
410 void SchedulerStateMachine::SetNeedsCommit() { needs_commit_ = true; } | 559 void SchedulerStateMachine::SetNeedsCommit() { needs_commit_ = true; } |
411 | 560 |
412 void SchedulerStateMachine::SetNeedsForcedCommit() { | 561 void SchedulerStateMachine::SetNeedsForcedCommitForReadback() { |
413 needs_forced_commit_ = true; | 562 DCHECK_EQ(readback_state_, READBACK_STATE_IDLE); |
414 expect_immediate_begin_frame_for_main_thread_ = true; | 563 readback_state_ = READBACK_STATE_FORCED_COMMIT_REQUESTED; |
415 } | 564 } |
416 | 565 |
417 void SchedulerStateMachine::FinishCommit() { | 566 void SchedulerStateMachine::FinishCommit() { |
418 DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || | 567 DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || |
419 (expect_immediate_begin_frame_for_main_thread_ && | 568 (readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED && |
420 commit_state_ != COMMIT_STATE_IDLE)) | 569 commit_state_ != COMMIT_STATE_IDLE)) |
421 << ToString(); | 570 << ToString(); |
422 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; | 571 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; |
423 } | 572 } |
424 | 573 |
425 void SchedulerStateMachine::BeginFrameAbortedByMainThread() { | 574 void SchedulerStateMachine::BeginFrameAbortedByMainThread() { |
426 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); | 575 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS) << ToString(); |
427 if (expect_immediate_begin_frame_for_main_thread_) { | 576 if (readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED) { |
428 expect_immediate_begin_frame_for_main_thread_ = false; | 577 readback_state_ = READBACK_STATE_IDLE; |
429 } else { | 578 } else { |
430 commit_state_ = COMMIT_STATE_IDLE; | 579 commit_state_ = COMMIT_STATE_IDLE; |
431 SetNeedsCommit(); | 580 SetNeedsCommit(); |
432 } | 581 } |
433 } | 582 } |
434 | 583 |
435 void SchedulerStateMachine::DidLoseOutputSurface() { | 584 void SchedulerStateMachine::DidLoseOutputSurface() { |
436 if (output_surface_state_ == OUTPUT_SURFACE_LOST || | 585 if (output_surface_state_ == OUTPUT_SURFACE_LOST || |
437 output_surface_state_ == OUTPUT_SURFACE_CREATING) | 586 output_surface_state_ == OUTPUT_SURFACE_CREATING) |
438 return; | 587 return; |
439 output_surface_state_ = OUTPUT_SURFACE_LOST; | 588 output_surface_state_ = OUTPUT_SURFACE_LOST; |
440 } | 589 } |
441 | 590 |
442 void SchedulerStateMachine::SetHasPendingTree(bool has_pending_tree) { | 591 void SchedulerStateMachine::SetHasTrees(bool has_pending_tree, |
| 592 bool active_tree_is_null) { |
| 593 if (has_pending_tree_ && !has_pending_tree) { |
| 594 // This is a new activation. |
| 595 draw_attempt_count_++; |
| 596 active_tree_has_been_drawn_ = false; |
| 597 |
| 598 if (draw_if_possible_failed_) |
| 599 last_begin_frame_count_draw_was_called_ = -1; |
| 600 |
| 601 if (COMMIT_STATE_WAITING_FOR_ACTIVATION == commit_state_) { |
| 602 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) { |
| 603 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
| 604 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; |
| 605 } else if (readback_state_ == READBACK_STATE_WAITING_FOR_ACTIVATION) { |
| 606 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
| 607 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; |
| 608 } else { |
| 609 commit_state_ = COMMIT_STATE_IDLE; |
| 610 if (readback_state_ == READBACK_STATE_REPLACEMENT_COMMIT_ACTIVATING) |
| 611 readback_state_ = READBACK_STATE_IDLE; |
| 612 } |
| 613 } |
| 614 } |
| 615 |
443 has_pending_tree_ = has_pending_tree; | 616 has_pending_tree_ = has_pending_tree; |
| 617 active_tree_is_null_ = active_tree_is_null; |
444 } | 618 } |
445 | 619 |
446 void SchedulerStateMachine::SetCanDraw(bool can) { can_draw_ = can; } | 620 void SchedulerStateMachine::SetCanDraw(bool can_draw) { |
| 621 can_draw_ = can_draw; |
| 622 } |
447 | 623 |
448 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { | 624 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { |
449 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); | 625 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); |
450 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | 626 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
451 | 627 |
452 if (did_create_and_initialize_first_output_surface_) { | 628 if (did_create_and_initialize_first_output_surface_) { |
453 // TODO(boliu): See if we can remove this when impl-side painting is always | 629 // TODO(boliu): See if we can remove this when impl-side painting is always |
454 // on. Does anything on the main thread need to update after recreate? | 630 // on. Does anything on the main thread need to update after recreate? |
455 needs_commit_ = true; | 631 needs_commit_ = true; |
456 // If anything has requested a redraw, we don't want to actually draw | 632 // If anything has requested a redraw, we don't want to actually draw |
457 // when the output surface is restored until things have a chance to | 633 // when the output surface is restored until things have a chance to |
458 // sort themselves out with a commit. | 634 // sort themselves out with a commit. |
459 needs_redraw_ = false; | 635 needs_redraw_ = false; |
460 } | 636 } |
461 did_create_and_initialize_first_output_surface_ = true; | 637 did_create_and_initialize_first_output_surface_ = true; |
462 } | 638 } |
463 | 639 |
464 bool SchedulerStateMachine::HasInitializedOutputSurface() const { | 640 bool SchedulerStateMachine::HasInitializedOutputSurface() const { |
465 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 641 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
466 } | 642 } |
467 | 643 |
468 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( | 644 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( |
469 int num_draws) { | 645 int num_draws) { |
470 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; | 646 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; |
471 } | 647 } |
472 | 648 |
473 } // namespace cc | 649 } // namespace cc |
OLD | NEW |