Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: cc/scheduler/scheduler_state_machine.cc

Issue 16871016: cc: Use BeginFrameArgs (Closed) Base URL: http://git.chromium.org/chromium/src.git@bfargs2
Patch Set: address comments Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 current_frame_number_(0),
Sami 2013/06/21 10:27:43 Nit: I think it's a little confusing to have two c
18 last_frame_number_where_draw_was_called_(-1), 18 current_frame_attempt_(0),
19 last_frame_number_where_tree_activation_attempted_(-1), 19 last_frame_number_draw_was_called_(-1),
20 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), 20 last_frame_number_begin_frame_sent_to_main_thread_(-1),
21 last_frame_attempt_tree_activation_attempted_(-1),
22 last_frame_attempt_check_for_completed_tile_uploads_called_(-1),
21 consecutive_failed_draws_(0), 23 consecutive_failed_draws_(0),
22 maximum_number_of_failed_draws_before_draw_is_forced_(3), 24 maximum_number_of_failed_draws_before_draw_is_forced_(3),
23 needs_redraw_(false), 25 needs_redraw_(false),
24 swap_used_incomplete_tile_(false), 26 swap_used_incomplete_tile_(false),
25 needs_forced_redraw_(false), 27 needs_forced_redraw_(false),
26 needs_forced_redraw_after_next_commit_(false), 28 needs_forced_redraw_after_next_commit_(false),
27 needs_commit_(false), 29 needs_commit_(false),
28 needs_forced_commit_(false), 30 needs_forced_commit_(false),
29 expect_immediate_begin_frame_for_main_thread_(false), 31 expect_immediate_begin_frame_for_main_thread_(false),
30 main_thread_needs_layer_textures_(false), 32 main_thread_needs_layer_textures_(false),
31 inside_begin_frame_(false), 33 begin_frame_state_(BEGIN_FRAME_STATE_IDLE),
34 commit_tree_has_been_drawn_or_null_(true),
35 active_tree_has_been_drawn_or_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, "current_frame_number_ = %d; ",
49 &str, "current_frame_number_ = %d; ", current_frame_number_); 53 current_frame_number_);
54 base::StringAppendF(&str, "current_frame_attempt_ = %d; ",
55 current_frame_attempt_);
50 base::StringAppendF(&str, 56 base::StringAppendF(&str,
51 "last_frame_number_where_draw_was_called_ = %d; ", 57 "last_frame_number_draw_was_called_ = %d; ",
52 last_frame_number_where_draw_was_called_); 58 last_frame_number_draw_was_called_);
53 base::StringAppendF( 59 base::StringAppendF(
54 &str, 60 &str,
55 "last_frame_number_where_tree_activation_attempted_ = %d; ", 61 "last_frame_attempt_tree_activation_attempted_ = %d; ",
56 last_frame_number_where_tree_activation_attempted_); 62 last_frame_attempt_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_frame_attempt_check_for_completed_tile_uploads_called_ = %d; ",
60 last_frame_number_where_check_for_completed_tile_uploads_called_); 66 last_frame_attempt_check_for_completed_tile_uploads_called_);
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(
71 &str, "needs_forced_redraw_ = %d; ", needs_forced_redraw_); 77 &str, "needs_forced_redraw_ = %d; ", needs_forced_redraw_);
72 base::StringAppendF(&str, 78 base::StringAppendF(&str,
73 "needs_forced_redraw_after_next_commit_ = %d; ", 79 "needs_forced_redraw_after_next_commit_ = %d; ",
74 needs_forced_redraw_after_next_commit_); 80 needs_forced_redraw_after_next_commit_);
75 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_); 81 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_);
76 base::StringAppendF( 82 base::StringAppendF(
77 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); 83 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_);
78 base::StringAppendF(&str, 84 base::StringAppendF(&str,
79 "expect_immediate_begin_frame_for_main_thread_ = %d; ", 85 "expect_immediate_begin_frame_for_main_thread_ = %d; ",
80 expect_immediate_begin_frame_for_main_thread_); 86 expect_immediate_begin_frame_for_main_thread_);
81 base::StringAppendF(&str, 87 base::StringAppendF(&str,
82 "main_thread_needs_layer_textures_ = %d; ", 88 "main_thread_needs_layer_textures_ = %d; ",
83 main_thread_needs_layer_textures_); 89 main_thread_needs_layer_textures_);
84 base::StringAppendF(&str, "inside_begin_frame_ = %d; ", 90 base::StringAppendF(&str, "begin_frame_state_ = %d; ", begin_frame_state_);
85 inside_begin_frame_);
86 base::StringAppendF(&str, "last_frame_time_ = %"PRId64"; ", 91 base::StringAppendF(&str, "last_frame_time_ = %"PRId64"; ",
87 (last_begin_frame_args_.frame_time - base::TimeTicks()) 92 (last_begin_frame_args_.frame_time - base::TimeTicks())
88 .InMilliseconds()); 93 .InMilliseconds());
89 base::StringAppendF(&str, "last_deadline_ = %"PRId64"; ", 94 base::StringAppendF(&str, "last_deadline_ = %"PRId64"; ",
90 (last_begin_frame_args_.deadline - base::TimeTicks()).InMilliseconds()); 95 (last_begin_frame_args_.deadline - base::TimeTicks()).InMilliseconds());
91 base::StringAppendF(&str, "last_interval_ = %"PRId64"; ", 96 base::StringAppendF(&str, "last_interval_ = %"PRId64"; ",
92 last_begin_frame_args_.interval.InMilliseconds()); 97 last_begin_frame_args_.interval.InMilliseconds());
93 base::StringAppendF(&str, "visible_ = %d; ", visible_); 98 base::StringAppendF(&str, "visible_ = %d; ", visible_);
94 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); 99 base::StringAppendF(&str, "can_start_ = %d; ", can_start_);
95 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); 100 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_);
96 base::StringAppendF( 101 base::StringAppendF(
97 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); 102 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_);
98 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); 103 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_);
104 base::StringAppendF(&str, "commit_tree_has_been_drawn_or_null_ = %d; ",
105 commit_tree_has_been_drawn_or_null_);
106 base::StringAppendF(&str, "active_tree_has_been_drawn_or_null_ = %d; ",
107 active_tree_has_been_drawn_or_null_);
99 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); 108 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_);
100 base::StringAppendF( 109 base::StringAppendF(
101 &str, "output_surface_state_ = %d; ", output_surface_state_); 110 &str, "output_surface_state_ = %d; ", output_surface_state_);
102 return str; 111 return str;
103 } 112 }
104 113
105 bool SchedulerStateMachine::HasDrawnThisFrame() const { 114 bool SchedulerStateMachine::HasDrawnThisFrame() const {
106 return current_frame_number_ == last_frame_number_where_draw_was_called_; 115 return current_frame_number_ == last_frame_number_draw_was_called_;
107 } 116 }
108 117
109 bool SchedulerStateMachine::HasAttemptedTreeActivationThisFrame() const { 118 bool SchedulerStateMachine::HasSentBeginFrameToMainThreadThisFrame() const {
110 return current_frame_number_ == 119 return current_frame_number_ ==
111 last_frame_number_where_tree_activation_attempted_; 120 last_frame_number_begin_frame_sent_to_main_thread_;
112 } 121 }
113 122
114 bool SchedulerStateMachine::HasCheckedForCompletedTileUploadsThisFrame() const { 123 bool SchedulerStateMachine::HasAttemptedTreeActivationThisFrameAttempt() const {
115 return current_frame_number_ == 124 return current_frame_attempt_ ==
116 last_frame_number_where_check_for_completed_tile_uploads_called_; 125 last_frame_attempt_tree_activation_attempted_;
126 }
127
128 bool SchedulerStateMachine::
129 HasCheckedForCompletedTileUploadsThisFrameAttempt() const {
130 return current_frame_attempt_ ==
131 last_frame_attempt_check_for_completed_tile_uploads_called_;
117 } 132 }
118 133
119 bool SchedulerStateMachine::DrawSuspendedUntilCommit() const { 134 bool SchedulerStateMachine::DrawSuspendedUntilCommit() const {
120 if (!can_draw_) 135 if (!can_draw_)
121 return true; 136 return true;
122 if (!visible_) 137 if (!visible_)
123 return true; 138 return true;
124 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD) 139 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD)
125 return true; 140 return true;
126 return false; 141 return false;
127 } 142 }
128 143
129 bool SchedulerStateMachine::ScheduledToDraw() const { 144 bool SchedulerStateMachine::ScheduledToDraw() const {
130 if (!needs_redraw_) 145 if (!needs_redraw_)
131 return false; 146 return false;
132 if (DrawSuspendedUntilCommit()) 147 if (DrawSuspendedUntilCommit())
133 return false; 148 return false;
134 return true; 149 return true;
135 } 150 }
136 151
137 bool SchedulerStateMachine::ShouldDraw() const { 152 bool SchedulerStateMachine::ShouldDraw() const {
138 if (needs_forced_redraw_) 153 if (needs_forced_redraw_)
139 return true; 154 return true;
140 155
141 if (!ScheduledToDraw()) 156 if (!ScheduledToDraw())
142 return false; 157 return false;
143 if (!inside_begin_frame_) 158 if (begin_frame_state_ != BEGIN_FRAME_STATE_INSIDE_DEADLINE)
144 return false; 159 return false;
145 if (HasDrawnThisFrame()) 160 if (HasDrawnThisFrame())
146 return false; 161 return false;
147 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) 162 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE)
148 return false; 163 return false;
149 return true; 164 return true;
150 } 165 }
151 166
152 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { 167 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const {
153 return has_pending_tree_ && inside_begin_frame_ && 168 return active_tree_has_been_drawn_or_null_ &&
154 !HasAttemptedTreeActivationThisFrame(); 169 has_pending_tree_ &&
170 (begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME ||
171 begin_frame_state_ == BEGIN_FRAME_STATE_DEADLINE_PENDING ||
172 begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_DEADLINE) &&
173 !HasAttemptedTreeActivationThisFrameAttempt();
155 } 174 }
156 175
157 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const { 176 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const {
158 if (!settings_.impl_side_painting) 177 if (!settings_.impl_side_painting)
159 return false; 178 return false;
160 if (HasCheckedForCompletedTileUploadsThisFrame()) 179 if (HasCheckedForCompletedTileUploadsThisFrameAttempt())
161 return false; 180 return false;
162 181
163 return ShouldAttemptTreeActivation() || ShouldDraw() || 182 return ShouldAttemptTreeActivation() || ShouldDraw() ||
164 swap_used_incomplete_tile_; 183 swap_used_incomplete_tile_;
165 } 184 }
166 185
167 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { 186 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const {
168 if (!main_thread_needs_layer_textures_) 187 if (!main_thread_needs_layer_textures_)
169 return false; 188 return false;
170 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) 189 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED)
171 return true; 190 return true;
172 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); 191 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD);
173 // Transfer the lock from impl thread to main thread immediately if the 192 // Transfer the lock from impl thread to main thread immediately if the
174 // impl thread is not even scheduled to draw. Guards against deadlocking. 193 // impl thread is not even scheduled to draw. Guards against deadlocking.
175 if (!ScheduledToDraw()) 194 if (!ScheduledToDraw())
176 return true; 195 return true;
177 if (!BeginFrameNeededToDrawByImplThread()) 196 if (!BeginFrameNeededToDrawByImplThread())
178 return true; 197 return true;
179 return false; 198 return false;
180 } 199 }
181 200
201 bool SchedulerStateMachine::ShouldSendBeginFrameToMainThread() const {
202 if (HasSentBeginFrameToMainThreadThisFrame())
203 return false;
204
205 // We only request a new commit while idle if we aren't already going
206 // to draw a new commit.
207 if (WillDrawNewTree() &&
208 (begin_frame_state_ == BEGIN_FRAME_STATE_IDLE ||
209 begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_DEADLINE))
210 return false;
211
212 // We can't accept a commit if we have a pending tree.
213 if (has_pending_tree_)
214 return false;
215
216 switch (commit_state_) {
217 case COMMIT_STATE_IDLE:
218 return (needs_commit_ && (needs_forced_commit_ ||
219 (visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE)));
220
221 // COMMIT_STATE_WAITING_FOR_ACTIVATION wants to enforce activation and
222 // eventually a draw.
223 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw.
224 // If can_draw_ is false or textures are not available, proceed to the
225 // next step (similar as in COMMIT_STATE_IDLE).
226 case COMMIT_STATE_WAITING_FOR_ACTIVATION:
227 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: {
228 bool can_commit = visible_ || needs_forced_commit_;
Sami 2013/06/21 10:27:43 Nit: can_commit could be moved above this switch()
229 return (needs_commit_ && can_commit && DrawSuspendedUntilCommit());
230 }
231
232 default:
233 return false;
234 }
235
236 return false;
237 }
238
182 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { 239 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const {
183 if (ShouldAcquireLayerTexturesForMainThread()) 240 if (ShouldAcquireLayerTexturesForMainThread())
184 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; 241 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD;
185 242
186 switch (commit_state_) { 243 switch (commit_state_) {
187 case COMMIT_STATE_IDLE: 244 case COMMIT_STATE_IDLE:
188 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && 245 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE &&
189 needs_forced_redraw_) 246 needs_forced_redraw_)
190 return ACTION_DRAW_FORCED; 247 return ACTION_DRAW_FORCED;
191 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && 248 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE &&
192 needs_forced_commit_) 249 needs_forced_commit_)
193 // TODO(enne): Should probably drop the active tree on force commit. 250 // TODO(enne): Should probably drop the active tree on force commit.
194 return has_pending_tree_ ? ACTION_NONE 251 return has_pending_tree_ ? ACTION_NONE
195 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; 252 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD;
196 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) 253 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_)
197 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; 254 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION;
198 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) 255 if (output_surface_state_ == OUTPUT_SURFACE_CREATING)
199 return ACTION_NONE; 256 return ACTION_NONE;
200 if (ShouldCheckForCompletedTileUploads()) 257 if (ShouldCheckForCompletedTileUploads())
201 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; 258 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS;
202 if (ShouldAttemptTreeActivation()) 259 if (ShouldAttemptTreeActivation())
203 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; 260 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
204 if (ShouldDraw()) { 261 if (ShouldDraw()) {
205 return needs_forced_redraw_ ? ACTION_DRAW_FORCED 262 return needs_forced_redraw_ ? ACTION_DRAW_FORCED
206 : ACTION_DRAW_IF_POSSIBLE; 263 : ACTION_DRAW_IF_POSSIBLE;
207 } 264 }
208 if (needs_commit_ && 265 if (ShouldSendBeginFrameToMainThread())
Sami 2013/06/21 10:27:43 Nit: braces for multi-line 'if'.
209 ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE)
210 || needs_forced_commit_))
211 // TODO(enne): Should probably drop the active tree on force commit. 266 // TODO(enne): Should probably drop the active tree on force commit.
212 return has_pending_tree_ ? ACTION_NONE 267 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD;
213 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD;
214 return ACTION_NONE; 268 return ACTION_NONE;
215 269
216 case COMMIT_STATE_FRAME_IN_PROGRESS: 270 case COMMIT_STATE_FRAME_IN_PROGRESS:
217 if (ShouldCheckForCompletedTileUploads()) 271 if (ShouldCheckForCompletedTileUploads())
218 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; 272 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS;
219 if (ShouldAttemptTreeActivation()) 273 if (ShouldAttemptTreeActivation())
220 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; 274 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
221 if (ShouldDraw()) { 275 if (ShouldDraw()) {
222 return needs_forced_redraw_ ? ACTION_DRAW_FORCED 276 return needs_forced_redraw_ ? ACTION_DRAW_FORCED
223 : ACTION_DRAW_IF_POSSIBLE; 277 : ACTION_DRAW_IF_POSSIBLE;
224 } 278 }
225 return ACTION_NONE; 279 return ACTION_NONE;
226 280
227 case COMMIT_STATE_READY_TO_COMMIT: 281 case COMMIT_STATE_READY_TO_COMMIT:
228 return ACTION_COMMIT; 282 return ACTION_COMMIT;
229 283
284 case COMMIT_STATE_WAITING_FOR_ACTIVATION:
230 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: { 285 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: {
231 if (ShouldCheckForCompletedTileUploads()) 286 if (ShouldCheckForCompletedTileUploads())
232 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; 287 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS;
233 if (ShouldAttemptTreeActivation()) 288 if (ShouldAttemptTreeActivation())
234 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; 289 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
235 if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) { 290 if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) {
236 return needs_forced_redraw_ ? ACTION_DRAW_FORCED 291 return needs_forced_redraw_ ? ACTION_DRAW_FORCED
237 : ACTION_DRAW_IF_POSSIBLE; 292 : ACTION_DRAW_IF_POSSIBLE;
238 } 293 }
239 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If 294 if (ShouldSendBeginFrameToMainThread())
240 // can_draw_ is false or textures are not available, proceed to the next 295 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; 296 return ACTION_NONE;
247 } 297 }
248 298
249 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: 299 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW:
250 if (ShouldCheckForCompletedTileUploads()) 300 if (ShouldCheckForCompletedTileUploads())
251 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; 301 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS;
252 if (ShouldAttemptTreeActivation()) 302 if (ShouldAttemptTreeActivation())
253 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; 303 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
254 if (needs_forced_redraw_) 304 if (needs_forced_redraw_)
255 return ACTION_DRAW_FORCED; 305 return ACTION_DRAW_FORCED;
256 return ACTION_NONE; 306 return ACTION_NONE;
257 } 307 }
258 NOTREACHED(); 308 NOTREACHED();
259 return ACTION_NONE; 309 return ACTION_NONE;
260 } 310 }
261 311
262 void SchedulerStateMachine::UpdateState(Action action) { 312 void SchedulerStateMachine::UpdateState(Action action) {
263 switch (action) { 313 switch (action) {
264 case ACTION_NONE: 314 case ACTION_NONE:
315 if (begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME)
316 begin_frame_state_ = BEGIN_FRAME_STATE_DEADLINE_PENDING;
317 if (begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_DEADLINE) {
318 begin_frame_state_ = BEGIN_FRAME_STATE_IDLE;
319 current_frame_number_++;
320 }
265 return; 321 return;
266 322
267 case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS: 323 case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS:
268 last_frame_number_where_check_for_completed_tile_uploads_called_ = 324 last_frame_attempt_check_for_completed_tile_uploads_called_ =
269 current_frame_number_; 325 current_frame_attempt_;
270 return; 326 return;
271 327
272 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: 328 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED:
273 last_frame_number_where_tree_activation_attempted_ = 329 last_frame_attempt_tree_activation_attempted_ =
274 current_frame_number_; 330 current_frame_attempt_;
275 return; 331 return;
276 332
277 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: 333 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD:
278 DCHECK(!has_pending_tree_); 334 DCHECK(!has_pending_tree_);
279 DCHECK(visible_ || needs_forced_commit_); 335 DCHECK(visible_ || needs_forced_commit_);
280 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; 336 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS;
281 needs_commit_ = false; 337 needs_commit_ = false;
282 needs_forced_commit_ = false; 338 needs_forced_commit_ = false;
339 last_frame_number_begin_frame_sent_to_main_thread_ =
340 current_frame_number_;
283 return; 341 return;
284 342
285 case ACTION_COMMIT: 343 case ACTION_COMMIT:
286 commit_count_++; 344 commit_count_++;
287 if (expect_immediate_begin_frame_for_main_thread_) 345 if (expect_immediate_begin_frame_for_main_thread_)
288 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; 346 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW;
347 else if (settings_.impl_side_painting)
348 commit_state_ = COMMIT_STATE_WAITING_FOR_ACTIVATION;
289 else 349 else
290 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; 350 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW;
291 // When impl-side painting, we draw on activation instead of on commit. 351 // When impl-side painting, we draw on activation instead of on commit.
292 if (!settings_.impl_side_painting) 352 if (!settings_.impl_side_painting)
293 needs_redraw_ = true; 353 needs_redraw_ = true;
294 if (draw_if_possible_failed_) 354 if (draw_if_possible_failed_)
295 last_frame_number_where_draw_was_called_ = -1; 355 last_frame_number_draw_was_called_ = -1;
296 356
297 if (needs_forced_redraw_after_next_commit_) { 357 if (needs_forced_redraw_after_next_commit_) {
298 needs_forced_redraw_after_next_commit_ = false; 358 needs_forced_redraw_after_next_commit_ = false;
299 needs_forced_redraw_ = true; 359 needs_forced_redraw_ = true;
300 } 360 }
301 361 commit_tree_has_been_drawn_or_null_ = false;
302 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; 362 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD;
303 return; 363 return;
304 364
305 case ACTION_DRAW_FORCED: 365 case ACTION_DRAW_FORCED:
306 case ACTION_DRAW_IF_POSSIBLE: 366 case ACTION_DRAW_IF_POSSIBLE:
307 needs_redraw_ = false; 367 needs_redraw_ = false;
308 needs_forced_redraw_ = false; 368 needs_forced_redraw_ = false;
309 draw_if_possible_failed_ = false; 369 draw_if_possible_failed_ = false;
310 swap_used_incomplete_tile_ = false; 370 swap_used_incomplete_tile_ = false;
311 if (inside_begin_frame_) 371 last_frame_number_draw_was_called_ = current_frame_number_;
312 last_frame_number_where_draw_was_called_ = current_frame_number_;
313 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { 372 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) {
314 DCHECK(expect_immediate_begin_frame_for_main_thread_); 373 DCHECK(expect_immediate_begin_frame_for_main_thread_);
315 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; 374 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS;
316 expect_immediate_begin_frame_for_main_thread_ = false; 375 expect_immediate_begin_frame_for_main_thread_ = false;
317 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { 376 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) {
318 commit_state_ = COMMIT_STATE_IDLE; 377 commit_state_ = COMMIT_STATE_IDLE;
319 } 378 }
320 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) 379 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD)
321 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; 380 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED;
381 active_tree_has_been_drawn_or_null_ = true;
382 commit_tree_has_been_drawn_or_null_ = true;
322 return; 383 return;
323 384
324 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: 385 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION:
325 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); 386 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE);
326 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); 387 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST);
327 output_surface_state_ = OUTPUT_SURFACE_CREATING; 388 output_surface_state_ = OUTPUT_SURFACE_CREATING;
328 return; 389 return;
329 390
330 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: 391 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD:
331 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; 392 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 426
366 bool SchedulerStateMachine::ProactiveBeginFrameWantedByImplThread() const { 427 bool SchedulerStateMachine::ProactiveBeginFrameWantedByImplThread() const {
367 // We should proactively request a BeginFrame if a commit is pending. 428 // We should proactively request a BeginFrame if a commit is pending.
368 if (needs_commit_ || needs_forced_commit_ || 429 if (needs_commit_ || needs_forced_commit_ ||
369 commit_state_ != COMMIT_STATE_IDLE) 430 commit_state_ != COMMIT_STATE_IDLE)
370 return true; 431 return true;
371 432
372 return false; 433 return false;
373 } 434 }
374 435
375 void SchedulerStateMachine::DidEnterBeginFrame(const BeginFrameArgs& args) { 436 void SchedulerStateMachine::OnBeginFrame(const BeginFrameArgs& args) {
376 inside_begin_frame_ = true; 437 current_frame_attempt_++;
377 last_begin_frame_args_ = args; 438 last_begin_frame_args_ = args;
439 begin_frame_state_ = BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME;
378 } 440 }
379 441
380 void SchedulerStateMachine::DidLeaveBeginFrame() { 442 bool SchedulerStateMachine::ShouldTriggerBeginFrameDeadlineEarly() const {
381 current_frame_number_++; 443 return begin_frame_state_ == BEGIN_FRAME_STATE_DEADLINE_PENDING &&
382 inside_begin_frame_ = false; 444 WillDrawNewTree();
445 }
446
447 bool SchedulerStateMachine::InsideBeginFrame() const {
448 return begin_frame_state_ != BEGIN_FRAME_STATE_IDLE;
449 }
450
451 bool SchedulerStateMachine::WillDrawNewTree() const {
452 if (settings_.impl_side_painting)
453 return !active_tree_has_been_drawn_or_null_;
454 else
455 return !commit_tree_has_been_drawn_or_null_;
456 }
457
458 void SchedulerStateMachine::OnBeginFrameDeadline() {
459 current_frame_attempt_++;
460 if (begin_frame_state_ == BEGIN_FRAME_STATE_DEADLINE_PENDING)
461 begin_frame_state_ = BEGIN_FRAME_STATE_INSIDE_DEADLINE;
383 } 462 }
384 463
385 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } 464 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; }
386 465
387 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } 466 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; }
388 467
389 void SchedulerStateMachine::DidSwapUseIncompleteTile() { 468 void SchedulerStateMachine::DidSwapUseIncompleteTile() {
390 swap_used_incomplete_tile_ = true; 469 swap_used_incomplete_tile_ = true;
391 } 470 }
392 471
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 } 518 }
440 519
441 void SchedulerStateMachine::DidLoseOutputSurface() { 520 void SchedulerStateMachine::DidLoseOutputSurface() {
442 if (output_surface_state_ == OUTPUT_SURFACE_LOST || 521 if (output_surface_state_ == OUTPUT_SURFACE_LOST ||
443 output_surface_state_ == OUTPUT_SURFACE_CREATING) 522 output_surface_state_ == OUTPUT_SURFACE_CREATING)
444 return; 523 return;
445 output_surface_state_ = OUTPUT_SURFACE_LOST; 524 output_surface_state_ = OUTPUT_SURFACE_LOST;
446 } 525 }
447 526
448 void SchedulerStateMachine::SetHasPendingTree(bool has_pending_tree) { 527 void SchedulerStateMachine::SetHasPendingTree(bool has_pending_tree) {
528 if (has_pending_tree_ && !has_pending_tree) {
529 // This is a new activation.
530 current_frame_attempt_++;
531 active_tree_has_been_drawn_or_null_ = false;
532 if (COMMIT_STATE_WAITING_FOR_ACTIVATION == commit_state_)
533 commit_state_ = COMMIT_STATE_IDLE;
534 }
535
449 has_pending_tree_ = has_pending_tree; 536 has_pending_tree_ = has_pending_tree;
450 } 537 }
451 538
452 void SchedulerStateMachine::SetCanDraw(bool can) { can_draw_ = can; } 539 void SchedulerStateMachine::SetCanDraw(bool can) { can_draw_ = can; }
453 540
454 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { 541 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() {
455 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); 542 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING);
456 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; 543 output_surface_state_ = OUTPUT_SURFACE_ACTIVE;
457 544
458 if (did_create_and_initialize_first_output_surface_) { 545 if (did_create_and_initialize_first_output_surface_) {
(...skipping 11 matching lines...) Expand all
470 bool SchedulerStateMachine::HasInitializedOutputSurface() const { 557 bool SchedulerStateMachine::HasInitializedOutputSurface() const {
471 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; 558 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE;
472 } 559 }
473 560
474 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( 561 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(
475 int num_draws) { 562 int num_draws) {
476 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; 563 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws;
477 } 564 }
478 565
479 } // namespace cc 566 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698