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

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: 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),
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_attempt_draw_was_called_(-1),
20 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), 20 last_frame_attempt_tree_activation_attempted_(-1),
21 last_frame_attempt_check_for_completed_tile_uploads_called_(-1),
21 consecutive_failed_draws_(0), 22 consecutive_failed_draws_(0),
22 maximum_number_of_failed_draws_before_draw_is_forced_(3), 23 maximum_number_of_failed_draws_before_draw_is_forced_(3),
23 needs_redraw_(false), 24 needs_redraw_(false),
24 swap_used_incomplete_tile_(false), 25 swap_used_incomplete_tile_(false),
25 needs_forced_redraw_(false), 26 needs_forced_redraw_(false),
26 needs_forced_redraw_after_next_commit_(false), 27 needs_forced_redraw_after_next_commit_(false),
27 needs_commit_(false), 28 needs_commit_(false),
28 needs_forced_commit_(false), 29 needs_forced_commit_(false),
29 expect_immediate_begin_frame_for_main_thread_(false), 30 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_IDLE),
33 active_tree_has_been_drawn_(true),
Sami 2013/06/14 15:59:20 Should this be false?
brianderson 2013/06/14 18:42:36 If the active tree has been drawn, then this patch
32 visible_(false), 34 visible_(false),
33 can_start_(false), 35 can_start_(false),
34 can_draw_(false), 36 can_draw_(false),
35 has_pending_tree_(false), 37 has_pending_tree_(false),
36 draw_if_possible_failed_(false), 38 draw_if_possible_failed_(false),
37 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), 39 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED),
38 output_surface_state_(OUTPUT_SURFACE_LOST), 40 output_surface_state_(OUTPUT_SURFACE_LOST),
39 did_create_and_initialize_first_output_surface_(false) {} 41 did_create_and_initialize_first_output_surface_(false) {}
40 42
41 std::string SchedulerStateMachine::ToString() { 43 std::string SchedulerStateMachine::ToString() {
42 std::string str; 44 std::string str;
43 base::StringAppendF(&str, 45 base::StringAppendF(&str,
44 "settings_.impl_side_painting = %d; ", 46 "settings_.impl_side_painting = %d; ",
45 settings_.impl_side_painting); 47 settings_.impl_side_painting);
46 base::StringAppendF(&str, "commit_state_ = %d; ", commit_state_); 48 base::StringAppendF(&str, "commit_state_ = %d; ", commit_state_);
47 base::StringAppendF(&str, "commit_count_ = %d; ", commit_count_); 49 base::StringAppendF(&str, "commit_count_ = %d; ", commit_count_);
48 base::StringAppendF( 50 base::StringAppendF(&str, "current_frame_number_ = %d; ",
49 &str, "current_frame_number_ = %d; ", current_frame_number_); 51 current_frame_number_);
52 base::StringAppendF(&str, "current_frame_attempt_ = %d; ",
53 current_frame_attempt_);
50 base::StringAppendF(&str, 54 base::StringAppendF(&str,
51 "last_frame_number_where_draw_was_called_ = %d; ", 55 "last_frame_attempt_draw_was_called_ = %d; ",
52 last_frame_number_where_draw_was_called_); 56 last_frame_attempt_draw_was_called_);
53 base::StringAppendF( 57 base::StringAppendF(
54 &str, 58 &str,
55 "last_frame_number_where_tree_activation_attempted_ = %d; ", 59 "last_frame_attempt_tree_activation_attempted_ = %d; ",
56 last_frame_number_where_tree_activation_attempted_); 60 last_frame_attempt_tree_activation_attempted_);
57 base::StringAppendF( 61 base::StringAppendF(
58 &str, 62 &str,
59 "last_frame_number_where_check_for_completed_tile_uploads_called_ = %d; ", 63 "last_frame_attempt_check_for_completed_tile_uploads_called_ = %d; ",
60 last_frame_number_where_check_for_completed_tile_uploads_called_); 64 last_frame_attempt_check_for_completed_tile_uploads_called_);
61 base::StringAppendF( 65 base::StringAppendF(
62 &str, "consecutive_failed_draws_ = %d; ", consecutive_failed_draws_); 66 &str, "consecutive_failed_draws_ = %d; ", consecutive_failed_draws_);
63 base::StringAppendF( 67 base::StringAppendF(
64 &str, 68 &str,
65 "maximum_number_of_failed_draws_before_draw_is_forced_ = %d; ", 69 "maximum_number_of_failed_draws_before_draw_is_forced_ = %d; ",
66 maximum_number_of_failed_draws_before_draw_is_forced_); 70 maximum_number_of_failed_draws_before_draw_is_forced_);
67 base::StringAppendF(&str, "needs_redraw_ = %d; ", needs_redraw_); 71 base::StringAppendF(&str, "needs_redraw_ = %d; ", needs_redraw_);
68 base::StringAppendF( 72 base::StringAppendF(
69 &str, "swap_used_incomplete_tile_ = %d; ", swap_used_incomplete_tile_); 73 &str, "swap_used_incomplete_tile_ = %d; ", swap_used_incomplete_tile_);
70 base::StringAppendF( 74 base::StringAppendF(
71 &str, "needs_forced_redraw_ = %d; ", needs_forced_redraw_); 75 &str, "needs_forced_redraw_ = %d; ", needs_forced_redraw_);
72 base::StringAppendF(&str, 76 base::StringAppendF(&str,
73 "needs_forced_redraw_after_next_commit_ = %d; ", 77 "needs_forced_redraw_after_next_commit_ = %d; ",
74 needs_forced_redraw_after_next_commit_); 78 needs_forced_redraw_after_next_commit_);
75 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_); 79 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_);
76 base::StringAppendF( 80 base::StringAppendF(
77 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); 81 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_);
78 base::StringAppendF(&str, 82 base::StringAppendF(&str,
79 "expect_immediate_begin_frame_for_main_thread_ = %d; ", 83 "expect_immediate_begin_frame_for_main_thread_ = %d; ",
80 expect_immediate_begin_frame_for_main_thread_); 84 expect_immediate_begin_frame_for_main_thread_);
81 base::StringAppendF(&str, 85 base::StringAppendF(&str,
82 "main_thread_needs_layer_textures_ = %d; ", 86 "main_thread_needs_layer_textures_ = %d; ",
83 main_thread_needs_layer_textures_); 87 main_thread_needs_layer_textures_);
84 base::StringAppendF(&str, "inside_begin_frame_ = %d; ", 88 base::StringAppendF(&str, "begin_frame_state_ = %d; ", begin_frame_state_);
85 inside_begin_frame_);
86 base::StringAppendF(&str, "last_frame_time_ = %"PRId64"; ", 89 base::StringAppendF(&str, "last_frame_time_ = %"PRId64"; ",
87 (last_begin_frame_args_.frame_time() - base::TimeTicks()) 90 (last_begin_frame_args_.frame_time() - base::TimeTicks())
88 .InMilliseconds()); 91 .InMilliseconds());
89 base::StringAppendF(&str, "last_deadline_ = %"PRId64"; ", 92 base::StringAppendF(&str, "last_deadline_ = %"PRId64"; ",
90 (last_begin_frame_args_.deadline() - base::TimeTicks()).InMilliseconds()); 93 (last_begin_frame_args_.deadline() - base::TimeTicks()).InMilliseconds());
91 base::StringAppendF(&str, "last_interval_ = %"PRId64"; ", 94 base::StringAppendF(&str, "last_interval_ = %"PRId64"; ",
92 last_begin_frame_args_.interval().InMilliseconds()); 95 last_begin_frame_args_.interval().InMilliseconds());
93 base::StringAppendF(&str, "visible_ = %d; ", visible_); 96 base::StringAppendF(&str, "visible_ = %d; ", visible_);
94 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); 97 base::StringAppendF(&str, "can_start_ = %d; ", can_start_);
95 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); 98 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_);
96 base::StringAppendF( 99 base::StringAppendF(
97 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); 100 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_);
98 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); 101 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_);
102 base::StringAppendF(&str, "active_tree_has_been_drawn_ = %d; ",
103 active_tree_has_been_drawn_);
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 current_frame_attempt_ == last_frame_attempt_draw_was_called_;
brianderson 2013/06/14 18:42:36 I should change back to use current_frame_number s
107 } 112 }
108 113
109 bool SchedulerStateMachine::HasAttemptedTreeActivationThisFrame() const { 114 bool SchedulerStateMachine::HasAttemptedTreeActivationThisFrame() const {
ajuma 2013/06/14 15:22:32 Calling this HasAttemptedTreeActivationThisFrameAt
brianderson 2013/06/14 18:42:36 Will do.
110 return current_frame_number_ == 115 return current_frame_attempt_ ==
111 last_frame_number_where_tree_activation_attempted_; 116 last_frame_attempt_tree_activation_attempted_;
112 } 117 }
113 118
114 bool SchedulerStateMachine::HasCheckedForCompletedTileUploadsThisFrame() const { 119 bool SchedulerStateMachine::HasCheckedForCompletedTileUploadsThisFrame() const {
115 return current_frame_number_ == 120 return current_frame_attempt_ ==
116 last_frame_number_where_check_for_completed_tile_uploads_called_; 121 last_frame_attempt_check_for_completed_tile_uploads_called_;
117 } 122 }
118 123
119 bool SchedulerStateMachine::DrawSuspendedUntilCommit() const { 124 bool SchedulerStateMachine::DrawSuspendedUntilCommit() const {
120 if (!can_draw_) 125 if (!can_draw_)
121 return true; 126 return true;
122 if (!visible_) 127 if (!visible_)
123 return true; 128 return true;
124 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD) 129 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD)
125 return true; 130 return true;
126 return false; 131 return false;
127 } 132 }
128 133
129 bool SchedulerStateMachine::ScheduledToDraw() const { 134 bool SchedulerStateMachine::ScheduledToDraw() const {
130 if (!needs_redraw_) 135 if (!needs_redraw_)
131 return false; 136 return false;
132 if (DrawSuspendedUntilCommit()) 137 if (DrawSuspendedUntilCommit())
133 return false; 138 return false;
134 return true; 139 return true;
135 } 140 }
136 141
137 bool SchedulerStateMachine::ShouldDraw() const { 142 bool SchedulerStateMachine::ShouldDraw() const {
138 if (needs_forced_redraw_) 143 if (needs_forced_redraw_)
139 return true; 144 return true;
140 145
141 if (!ScheduledToDraw()) 146 if (!ScheduledToDraw())
142 return false; 147 return false;
143 if (!inside_begin_frame_) 148 if (begin_frame_state_ != BEGIN_FRAME_DRAWING)
144 return false; 149 return false;
145 if (HasDrawnThisFrame()) 150 if (HasDrawnThisFrame())
146 return false; 151 return false;
147 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) 152 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE)
148 return false; 153 return false;
149 return true; 154 return true;
150 } 155 }
151 156
152 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { 157 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const {
153 return has_pending_tree_ && inside_begin_frame_ && 158 return active_tree_has_been_drawn_ &&
159 has_pending_tree_ &&
160 (begin_frame_state_ == BEGIN_FRAME_STARTING ||
161 begin_frame_state_ == BEGIN_FRAME_WAITING ||
162 begin_frame_state_ == BEGIN_FRAME_DRAWING) &&
154 !HasAttemptedTreeActivationThisFrame(); 163 !HasAttemptedTreeActivationThisFrame();
155 } 164 }
156 165
157 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const { 166 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const {
158 if (!settings_.impl_side_painting) 167 if (!settings_.impl_side_painting)
159 return false; 168 return false;
160 if (HasCheckedForCompletedTileUploadsThisFrame()) 169 if (HasCheckedForCompletedTileUploadsThisFrame())
161 return false; 170 return false;
162 171
163 return ShouldAttemptTreeActivation() || ShouldDraw() || 172 return ShouldAttemptTreeActivation() || ShouldDraw() ||
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 if (ShouldCheckForCompletedTileUploads()) 209 if (ShouldCheckForCompletedTileUploads())
201 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; 210 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS;
202 if (ShouldAttemptTreeActivation()) 211 if (ShouldAttemptTreeActivation())
203 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; 212 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
204 if (ShouldDraw()) { 213 if (ShouldDraw()) {
205 return needs_forced_redraw_ ? ACTION_DRAW_FORCED 214 return needs_forced_redraw_ ? ACTION_DRAW_FORCED
206 : ACTION_DRAW_IF_POSSIBLE; 215 : ACTION_DRAW_IF_POSSIBLE;
207 } 216 }
208 if (needs_commit_ && 217 if (needs_commit_ &&
209 ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE) 218 ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE)
210 || needs_forced_commit_)) 219 || needs_forced_commit_) &&
220 !has_pending_tree_ &&
221 begin_frame_state_ == BEGIN_FRAME_STARTING)
211 // TODO(enne): Should probably drop the active tree on force commit. 222 // TODO(enne): Should probably drop the active tree on force commit.
212 return has_pending_tree_ ? ACTION_NONE 223 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD;
213 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD;
214 return ACTION_NONE; 224 return ACTION_NONE;
215 225
216 case COMMIT_STATE_FRAME_IN_PROGRESS: 226 case COMMIT_STATE_FRAME_IN_PROGRESS:
217 if (ShouldCheckForCompletedTileUploads()) 227 if (ShouldCheckForCompletedTileUploads())
218 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; 228 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS;
219 if (ShouldAttemptTreeActivation()) 229 if (ShouldAttemptTreeActivation())
220 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; 230 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
221 if (ShouldDraw()) { 231 if (ShouldDraw()) {
222 return needs_forced_redraw_ ? ACTION_DRAW_FORCED 232 return needs_forced_redraw_ ? ACTION_DRAW_FORCED
223 : ACTION_DRAW_IF_POSSIBLE; 233 : ACTION_DRAW_IF_POSSIBLE;
224 } 234 }
225 return ACTION_NONE; 235 return ACTION_NONE;
226 236
227 case COMMIT_STATE_READY_TO_COMMIT: 237 case COMMIT_STATE_READY_TO_COMMIT:
228 return ACTION_COMMIT; 238 return ACTION_COMMIT;
229 239
230 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: { 240 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: {
231 if (ShouldCheckForCompletedTileUploads()) 241 if (ShouldCheckForCompletedTileUploads())
232 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; 242 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS;
233 if (ShouldAttemptTreeActivation()) 243 if (ShouldAttemptTreeActivation())
234 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; 244 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
235 if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) { 245 if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) {
236 return needs_forced_redraw_ ? ACTION_DRAW_FORCED 246 return needs_forced_redraw_ ? ACTION_DRAW_FORCED
237 : ACTION_DRAW_IF_POSSIBLE; 247 : ACTION_DRAW_IF_POSSIBLE;
238 } 248 }
239 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If 249 // 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 250 // can_draw_ is false or textures are not available, proceed to the next
241 // step (similar as in COMMIT_STATE_IDLE). 251 // step (similar as in COMMIT_STATE_IDLE).
242 bool can_commit = visible_ || needs_forced_commit_; 252 bool can_commit = visible_ || needs_forced_commit_;
243 if (needs_commit_ && can_commit && DrawSuspendedUntilCommit()) 253 if (needs_commit_ && can_commit && DrawSuspendedUntilCommit() &&
244 return has_pending_tree_ ? ACTION_NONE 254 !has_pending_tree_ && begin_frame_state_ == BEGIN_FRAME_STARTING)
245 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; 255 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD;
246 return ACTION_NONE; 256 return ACTION_NONE;
247 } 257 }
248 258
249 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: 259 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW:
250 if (ShouldCheckForCompletedTileUploads()) 260 if (ShouldCheckForCompletedTileUploads())
251 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; 261 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS;
252 if (ShouldAttemptTreeActivation()) 262 if (ShouldAttemptTreeActivation())
253 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; 263 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
254 if (needs_forced_redraw_) 264 if (needs_forced_redraw_)
255 return ACTION_DRAW_FORCED; 265 return ACTION_DRAW_FORCED;
256 return ACTION_NONE; 266 return ACTION_NONE;
257 } 267 }
258 NOTREACHED(); 268 NOTREACHED();
259 return ACTION_NONE; 269 return ACTION_NONE;
260 } 270 }
261 271
262 void SchedulerStateMachine::UpdateState(Action action) { 272 void SchedulerStateMachine::UpdateState(Action action) {
263 switch (action) { 273 switch (action) {
264 case ACTION_NONE: 274 case ACTION_NONE:
275 if (begin_frame_state_ == BEGIN_FRAME_STARTING)
276 begin_frame_state_ = BEGIN_FRAME_WAITING;
277 if (begin_frame_state_ == BEGIN_FRAME_DRAWING)
278 begin_frame_state_ = BEGIN_FRAME_IDLE;
265 return; 279 return;
266 280
267 case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS: 281 case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS:
268 last_frame_number_where_check_for_completed_tile_uploads_called_ = 282 last_frame_attempt_check_for_completed_tile_uploads_called_ =
269 current_frame_number_; 283 current_frame_attempt_;
270 return; 284 return;
271 285
272 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: 286 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED:
273 last_frame_number_where_tree_activation_attempted_ = 287 last_frame_attempt_tree_activation_attempted_ =
274 current_frame_number_; 288 current_frame_attempt_;
275 return; 289 return;
276 290
277 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: 291 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD:
278 DCHECK(!has_pending_tree_); 292 DCHECK(!has_pending_tree_);
279 DCHECK(visible_ || needs_forced_commit_); 293 DCHECK(visible_ || needs_forced_commit_);
280 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; 294 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS;
281 needs_commit_ = false; 295 needs_commit_ = false;
282 needs_forced_commit_ = false; 296 needs_forced_commit_ = false;
283 return; 297 return;
284 298
285 case ACTION_COMMIT: 299 case ACTION_COMMIT:
286 commit_count_++; 300 commit_count_++;
287 if (expect_immediate_begin_frame_for_main_thread_) 301 if (expect_immediate_begin_frame_for_main_thread_)
288 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; 302 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW;
289 else 303 else
290 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; 304 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW;
291 // When impl-side painting, we draw on activation instead of on commit. 305 // When impl-side painting, we draw on activation instead of on commit.
292 if (!settings_.impl_side_painting) 306 if (!settings_.impl_side_painting)
293 needs_redraw_ = true; 307 needs_redraw_ = true;
294 if (draw_if_possible_failed_) 308 if (draw_if_possible_failed_)
295 last_frame_number_where_draw_was_called_ = -1; 309 last_frame_attempt_draw_was_called_ = -1;
296 310
297 if (needs_forced_redraw_after_next_commit_) { 311 if (needs_forced_redraw_after_next_commit_) {
298 needs_forced_redraw_after_next_commit_ = false; 312 needs_forced_redraw_after_next_commit_ = false;
299 needs_forced_redraw_ = true; 313 needs_forced_redraw_ = true;
300 } 314 }
301 315
302 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; 316 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD;
303 return; 317 return;
304 318
305 case ACTION_DRAW_FORCED: 319 case ACTION_DRAW_FORCED:
306 case ACTION_DRAW_IF_POSSIBLE: 320 case ACTION_DRAW_IF_POSSIBLE:
307 needs_redraw_ = false; 321 needs_redraw_ = false;
308 needs_forced_redraw_ = false; 322 needs_forced_redraw_ = false;
309 draw_if_possible_failed_ = false; 323 draw_if_possible_failed_ = false;
310 swap_used_incomplete_tile_ = false; 324 swap_used_incomplete_tile_ = false;
311 if (inside_begin_frame_) 325 last_frame_attempt_draw_was_called_ = current_frame_attempt_;
312 last_frame_number_where_draw_was_called_ = current_frame_number_;
313 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { 326 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) {
314 DCHECK(expect_immediate_begin_frame_for_main_thread_); 327 DCHECK(expect_immediate_begin_frame_for_main_thread_);
315 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; 328 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS;
316 expect_immediate_begin_frame_for_main_thread_ = false; 329 expect_immediate_begin_frame_for_main_thread_ = false;
317 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { 330 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) {
318 commit_state_ = COMMIT_STATE_IDLE; 331 commit_state_ = COMMIT_STATE_IDLE;
319 } 332 }
320 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) 333 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD)
321 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; 334 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED;
335 active_tree_has_been_drawn_ = true;
322 return; 336 return;
323 337
324 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: 338 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION:
325 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); 339 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE);
326 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); 340 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST);
327 output_surface_state_ = OUTPUT_SURFACE_CREATING; 341 output_surface_state_ = OUTPUT_SURFACE_CREATING;
328 return; 342 return;
329 343
330 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: 344 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD:
331 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; 345 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD;
(...skipping 28 matching lines...) Expand all
360 if (needs_forced_redraw_) 374 if (needs_forced_redraw_)
361 return true; 375 return true;
362 376
363 if (visible_ && swap_used_incomplete_tile_) 377 if (visible_ && swap_used_incomplete_tile_)
364 return true; 378 return true;
365 379
366 return needs_redraw_ && visible_ && 380 return needs_redraw_ && visible_ &&
367 output_surface_state_ == OUTPUT_SURFACE_ACTIVE; 381 output_surface_state_ == OUTPUT_SURFACE_ACTIVE;
368 } 382 }
369 383
370 void SchedulerStateMachine::DidEnterBeginFrame(BeginFrameArgs args) { 384 void SchedulerStateMachine::StartBeginFrame(BeginFrameArgs args) {
371 inside_begin_frame_ = true; 385 current_frame_number_++;
386 current_frame_attempt_++;
372 last_begin_frame_args_ = args; 387 last_begin_frame_args_ = args;
388 if (active_tree_has_been_drawn_ && base::TimeTicks::Now() < args.deadline())
389 begin_frame_state_ = BEGIN_FRAME_STARTING;
390 else
391 begin_frame_state_ = BEGIN_FRAME_DRAWING;
373 } 392 }
374 393
375 void SchedulerStateMachine::DidLeaveBeginFrame() { 394 void SchedulerStateMachine::OnBeginFrameDeadline() {
376 current_frame_number_++; 395 current_frame_attempt_++;
377 inside_begin_frame_ = false; 396 if (begin_frame_state_ == BEGIN_FRAME_WAITING)
397 begin_frame_state_ = BEGIN_FRAME_DRAWING;
Sami 2013/06/14 15:59:20 Let me see if I got this right: 1. BeginFrame =>
brianderson 2013/06/14 18:42:36 Almost: 2.a Main thread processing starts => BEGIN
378 } 398 }
379 399
380 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } 400 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; }
381 401
382 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } 402 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; }
383 403
384 void SchedulerStateMachine::DidSwapUseIncompleteTile() { 404 void SchedulerStateMachine::DidSwapUseIncompleteTile() {
385 swap_used_incomplete_tile_ = true; 405 swap_used_incomplete_tile_ = true;
386 } 406 }
387 407
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } 454 }
435 455
436 void SchedulerStateMachine::DidLoseOutputSurface() { 456 void SchedulerStateMachine::DidLoseOutputSurface() {
437 if (output_surface_state_ == OUTPUT_SURFACE_LOST || 457 if (output_surface_state_ == OUTPUT_SURFACE_LOST ||
438 output_surface_state_ == OUTPUT_SURFACE_CREATING) 458 output_surface_state_ == OUTPUT_SURFACE_CREATING)
439 return; 459 return;
440 output_surface_state_ = OUTPUT_SURFACE_LOST; 460 output_surface_state_ = OUTPUT_SURFACE_LOST;
441 } 461 }
442 462
443 void SchedulerStateMachine::SetHasPendingTree(bool has_pending_tree) { 463 void SchedulerStateMachine::SetHasPendingTree(bool has_pending_tree) {
464 if (has_pending_tree_ && !has_pending_tree) {
465 // This is a new activation.
466 current_frame_attempt_++;
467 active_tree_has_been_drawn_ = false;
468 if (begin_frame_state_ == BEGIN_FRAME_STARTING) {
469 begin_frame_state_ = BEGIN_FRAME_DRAWING;
470 } else if (begin_frame_state_ == BEGIN_FRAME_WAITING) {
471 if (base::TimeTicks::Now() < last_begin_frame_args_.deadline())
472 begin_frame_state_ = BEGIN_FRAME_DRAWING;
473 else
474 begin_frame_state_ = BEGIN_FRAME_IDLE;
475 }
476 }
477
444 has_pending_tree_ = has_pending_tree; 478 has_pending_tree_ = has_pending_tree;
445 } 479 }
446 480
447 void SchedulerStateMachine::SetCanDraw(bool can) { can_draw_ = can; } 481 void SchedulerStateMachine::SetCanDraw(bool can) { can_draw_ = can; }
448 482
449 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { 483 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() {
450 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); 484 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING);
451 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; 485 output_surface_state_ = OUTPUT_SURFACE_ACTIVE;
452 486
453 if (did_create_and_initialize_first_output_surface_) { 487 if (did_create_and_initialize_first_output_surface_) {
(...skipping 11 matching lines...) Expand all
465 bool SchedulerStateMachine::HasInitializedOutputSurface() const { 499 bool SchedulerStateMachine::HasInitializedOutputSurface() const {
466 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; 500 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE;
467 } 501 }
468 502
469 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( 503 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(
470 int num_draws) { 504 int num_draws) {
471 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; 505 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws;
472 } 506 }
473 507
474 } // namespace cc 508 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698