| 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 #ifndef CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ | 5 #ifndef CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ |
| 6 #define CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ | 6 #define CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // requested, while external state includes things like the current time being | 41 // requested, while external state includes things like the current time being |
| 42 // near to the vblank time. | 42 // near to the vblank time. |
| 43 // | 43 // |
| 44 // The scheduler seperates "what to do next" from the updating of its internal | 44 // The scheduler seperates "what to do next" from the updating of its internal |
| 45 // state to make testing cleaner. | 45 // state to make testing cleaner. |
| 46 class CC_EXPORT SchedulerStateMachine { | 46 class CC_EXPORT SchedulerStateMachine { |
| 47 public: | 47 public: |
| 48 // settings must be valid for the lifetime of this class. | 48 // settings must be valid for the lifetime of this class. |
| 49 explicit SchedulerStateMachine(const SchedulerSettings& settings); | 49 explicit SchedulerStateMachine(const SchedulerSettings& settings); |
| 50 | 50 |
| 51 enum OutputSurfaceState { | 51 enum CompositorFrameSinkState { |
| 52 OUTPUT_SURFACE_NONE, | 52 COMPOSITOR_FRAME_SINK_NONE, |
| 53 OUTPUT_SURFACE_ACTIVE, | 53 COMPOSITOR_FRAME_SINK_ACTIVE, |
| 54 OUTPUT_SURFACE_CREATING, | 54 COMPOSITOR_FRAME_SINK_CREATING, |
| 55 OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT, | 55 COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT, |
| 56 OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION, | 56 COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION, |
| 57 }; | 57 }; |
| 58 static const char* OutputSurfaceStateToString(OutputSurfaceState state); | 58 static const char* CompositorFrameSinkStateToString( |
| 59 CompositorFrameSinkState state); |
| 59 | 60 |
| 60 // Note: BeginImplFrameState does not cycle through these states in a fixed | 61 // Note: BeginImplFrameState does not cycle through these states in a fixed |
| 61 // order on all platforms. It's up to the scheduler to set these correctly. | 62 // order on all platforms. It's up to the scheduler to set these correctly. |
| 62 enum BeginImplFrameState { | 63 enum BeginImplFrameState { |
| 63 BEGIN_IMPL_FRAME_STATE_IDLE, | 64 BEGIN_IMPL_FRAME_STATE_IDLE, |
| 64 BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, | 65 BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, |
| 65 BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, | 66 BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, |
| 66 }; | 67 }; |
| 67 static const char* BeginImplFrameStateToString(BeginImplFrameState state); | 68 static const char* BeginImplFrameStateToString(BeginImplFrameState state); |
| 68 | 69 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 bool PrepareTilesPending() const { return needs_prepare_tiles_; } | 114 bool PrepareTilesPending() const { return needs_prepare_tiles_; } |
| 114 | 115 |
| 115 enum Action { | 116 enum Action { |
| 116 ACTION_NONE, | 117 ACTION_NONE, |
| 117 ACTION_SEND_BEGIN_MAIN_FRAME, | 118 ACTION_SEND_BEGIN_MAIN_FRAME, |
| 118 ACTION_COMMIT, | 119 ACTION_COMMIT, |
| 119 ACTION_ACTIVATE_SYNC_TREE, | 120 ACTION_ACTIVATE_SYNC_TREE, |
| 120 ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 121 ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 121 ACTION_DRAW_AND_SWAP_FORCED, | 122 ACTION_DRAW_AND_SWAP_FORCED, |
| 122 ACTION_DRAW_AND_SWAP_ABORT, | 123 ACTION_DRAW_AND_SWAP_ABORT, |
| 123 ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 124 ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION, |
| 124 ACTION_PREPARE_TILES, | 125 ACTION_PREPARE_TILES, |
| 125 ACTION_INVALIDATE_OUTPUT_SURFACE, | 126 ACTION_INVALIDATE_COMPOSITOR_FRAME_SINK, |
| 126 }; | 127 }; |
| 127 static const char* ActionToString(Action action); | 128 static const char* ActionToString(Action action); |
| 128 | 129 |
| 129 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; | 130 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; |
| 130 void AsValueInto(base::trace_event::TracedValue* dict) const; | 131 void AsValueInto(base::trace_event::TracedValue* dict) const; |
| 131 | 132 |
| 132 Action NextAction() const; | 133 Action NextAction() const; |
| 133 void WillSendBeginMainFrame(); | 134 void WillSendBeginMainFrame(); |
| 134 void WillCommit(bool commit_had_no_updates); | 135 void WillCommit(bool commit_had_no_updates); |
| 135 void WillActivate(); | 136 void WillActivate(); |
| 136 void WillDraw(); | 137 void WillDraw(); |
| 137 void WillBeginOutputSurfaceCreation(); | 138 void WillBeginCompositorFrameSinkCreation(); |
| 138 void WillPrepareTiles(); | 139 void WillPrepareTiles(); |
| 139 void WillInvalidateOutputSurface(); | 140 void WillInvalidateCompositorFrameSink(); |
| 140 | 141 |
| 141 void DidDraw(DrawResult draw_result); | 142 void DidDraw(DrawResult draw_result); |
| 142 | 143 |
| 143 void AbortDrawAndSwap(); | 144 void AbortDrawAndSwap(); |
| 144 | 145 |
| 145 // Indicates whether the impl thread needs a BeginImplFrame callback in order | 146 // Indicates whether the impl thread needs a BeginImplFrame callback in order |
| 146 // to make progress. | 147 // to make progress. |
| 147 bool BeginFrameNeeded() const; | 148 bool BeginFrameNeeded() const; |
| 148 | 149 |
| 149 // Indicates that the system has entered and left a BeginImplFrame callback. | 150 // Indicates that the system has entered and left a BeginImplFrame callback. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 189 |
| 189 // If the scheduler attempted to draw and swap, this provides feedback | 190 // If the scheduler attempted to draw and swap, this provides feedback |
| 190 // regarding whether or not the swap actually occured. We might skip the | 191 // regarding whether or not the swap actually occured. We might skip the |
| 191 // swap when there is not damage, for example. | 192 // swap when there is not damage, for example. |
| 192 void DidSwapBuffers(); | 193 void DidSwapBuffers(); |
| 193 | 194 |
| 194 // Indicates whether a redraw is required because we are currently rendering | 195 // Indicates whether a redraw is required because we are currently rendering |
| 195 // with a low resolution or checkerboarded tile. | 196 // with a low resolution or checkerboarded tile. |
| 196 void SetSwapUsedIncompleteTile(bool used_incomplete_tile); | 197 void SetSwapUsedIncompleteTile(bool used_incomplete_tile); |
| 197 | 198 |
| 198 // Notification from the OutputSurface that a swap has been consumed. | 199 // Notification from the CompositorFrameSink that a swap has been consumed. |
| 199 void DidSwapBuffersComplete(); | 200 void DidSwapBuffersComplete(); |
| 200 | 201 |
| 201 int pending_swaps() const { return pending_swaps_; } | 202 int pending_swaps() const { return pending_swaps_; } |
| 202 | 203 |
| 203 // Indicates whether to prioritize impl thread latency (i.e., animation | 204 // Indicates whether to prioritize impl thread latency (i.e., animation |
| 204 // smoothness) over new content activation. | 205 // smoothness) over new content activation. |
| 205 void SetTreePrioritiesAndScrollState(TreePriority tree_priority, | 206 void SetTreePrioritiesAndScrollState(TreePriority tree_priority, |
| 206 ScrollHandlerState scroll_handler_state); | 207 ScrollHandlerState scroll_handler_state); |
| 207 | 208 |
| 208 // Indicates if the main thread will likely respond within 1 vsync. | 209 // Indicates if the main thread will likely respond within 1 vsync. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 251 |
| 251 // Indicates the active tree's visible tiles are ready to be drawn. | 252 // Indicates the active tree's visible tiles are ready to be drawn. |
| 252 void NotifyReadyToDraw(); | 253 void NotifyReadyToDraw(); |
| 253 | 254 |
| 254 bool has_pending_tree() const { return has_pending_tree_; } | 255 bool has_pending_tree() const { return has_pending_tree_; } |
| 255 bool active_tree_needs_first_draw() const { | 256 bool active_tree_needs_first_draw() const { |
| 256 return active_tree_needs_first_draw_; | 257 return active_tree_needs_first_draw_; |
| 257 } | 258 } |
| 258 | 259 |
| 259 void DidPrepareTiles(); | 260 void DidPrepareTiles(); |
| 260 void DidLoseOutputSurface(); | 261 void DidLoseCompositorFrameSink(); |
| 261 void DidCreateAndInitializeOutputSurface(); | 262 void DidCreateAndInitializeCompositorFrameSink(); |
| 262 bool HasInitializedOutputSurface() const; | 263 bool HasInitializedCompositorFrameSink() const; |
| 263 | 264 |
| 264 // True if we need to abort draws to make forward progress. | 265 // True if we need to abort draws to make forward progress. |
| 265 bool PendingDrawsShouldBeAborted() const; | 266 bool PendingDrawsShouldBeAborted() const; |
| 266 | 267 |
| 267 bool CouldSendBeginMainFrame() const; | 268 bool CouldSendBeginMainFrame() const; |
| 268 | 269 |
| 269 void SetDeferCommits(bool defer_commits); | 270 void SetDeferCommits(bool defer_commits); |
| 270 | 271 |
| 271 void SetVideoNeedsBeginFrames(bool video_needs_begin_frames); | 272 void SetVideoNeedsBeginFrames(bool video_needs_begin_frames); |
| 272 bool video_needs_begin_frames() const { return video_needs_begin_frames_; } | 273 bool video_needs_begin_frames() const { return video_needs_begin_frames_; } |
| 273 | 274 |
| 274 protected: | 275 protected: |
| 275 bool BeginFrameRequiredForAction() const; | 276 bool BeginFrameRequiredForAction() const; |
| 276 bool BeginFrameNeededForVideo() const; | 277 bool BeginFrameNeededForVideo() const; |
| 277 bool ProactiveBeginFrameWanted() const; | 278 bool ProactiveBeginFrameWanted() const; |
| 278 | 279 |
| 279 bool ShouldTriggerBeginImplFrameDeadlineImmediately() const; | 280 bool ShouldTriggerBeginImplFrameDeadlineImmediately() const; |
| 280 | 281 |
| 281 // True if we need to force activations to make forward progress. | 282 // True if we need to force activations to make forward progress. |
| 282 // TODO(sunnyps): Rename this to ShouldAbortCurrentFrame or similar. | 283 // TODO(sunnyps): Rename this to ShouldAbortCurrentFrame or similar. |
| 283 bool PendingActivationsShouldBeForced() const; | 284 bool PendingActivationsShouldBeForced() const; |
| 284 | 285 |
| 285 bool ShouldBeginOutputSurfaceCreation() const; | 286 bool ShouldBeginCompositorFrameSinkCreation() const; |
| 286 bool ShouldDraw() const; | 287 bool ShouldDraw() const; |
| 287 bool ShouldActivatePendingTree() const; | 288 bool ShouldActivatePendingTree() const; |
| 288 bool ShouldSendBeginMainFrame() const; | 289 bool ShouldSendBeginMainFrame() const; |
| 289 bool ShouldCommit() const; | 290 bool ShouldCommit() const; |
| 290 bool ShouldPrepareTiles() const; | 291 bool ShouldPrepareTiles() const; |
| 291 bool ShouldInvalidateOutputSurface() const; | 292 bool ShouldInvalidateCompositorFrameSink() const; |
| 292 | 293 |
| 293 void WillDrawInternal(); | 294 void WillDrawInternal(); |
| 294 void DidDrawInternal(DrawResult draw_result); | 295 void DidDrawInternal(DrawResult draw_result); |
| 295 | 296 |
| 296 const SchedulerSettings settings_; | 297 const SchedulerSettings settings_; |
| 297 | 298 |
| 298 OutputSurfaceState output_surface_state_; | 299 CompositorFrameSinkState compositor_frame_sink_state_; |
| 299 BeginImplFrameState begin_impl_frame_state_; | 300 BeginImplFrameState begin_impl_frame_state_; |
| 300 BeginMainFrameState begin_main_frame_state_; | 301 BeginMainFrameState begin_main_frame_state_; |
| 301 ForcedRedrawOnTimeoutState forced_redraw_state_; | 302 ForcedRedrawOnTimeoutState forced_redraw_state_; |
| 302 | 303 |
| 303 // These are used for tracing only. | 304 // These are used for tracing only. |
| 304 int commit_count_; | 305 int commit_count_; |
| 305 int current_frame_number_; | 306 int current_frame_number_; |
| 306 int last_frame_number_swap_performed_; | 307 int last_frame_number_swap_performed_; |
| 307 int last_frame_number_draw_performed_; | 308 int last_frame_number_draw_performed_; |
| 308 int last_frame_number_begin_main_frame_sent_; | 309 int last_frame_number_begin_main_frame_sent_; |
| 309 int last_frame_number_invalidate_output_surface_performed_; | 310 int last_frame_number_invalidate_compositor_frame_sink_performed_; |
| 310 | 311 |
| 311 // These are used to ensure that an action only happens once per frame, | 312 // These are used to ensure that an action only happens once per frame, |
| 312 // deadline, etc. | 313 // deadline, etc. |
| 313 bool draw_funnel_; | 314 bool draw_funnel_; |
| 314 bool send_begin_main_frame_funnel_; | 315 bool send_begin_main_frame_funnel_; |
| 315 bool invalidate_output_surface_funnel_; | 316 bool invalidate_compositor_frame_sink_funnel_; |
| 316 // prepare_tiles_funnel_ is "filled" each time PrepareTiles is called | 317 // prepare_tiles_funnel_ is "filled" each time PrepareTiles is called |
| 317 // and "drained" on each BeginImplFrame. If the funnel gets too full, | 318 // and "drained" on each BeginImplFrame. If the funnel gets too full, |
| 318 // we start throttling ACTION_PREPARE_TILES such that we average one | 319 // we start throttling ACTION_PREPARE_TILES such that we average one |
| 319 // PrepareTiles per BeginImplFrame. | 320 // PrepareTiles per BeginImplFrame. |
| 320 int prepare_tiles_funnel_; | 321 int prepare_tiles_funnel_; |
| 321 | 322 |
| 322 int consecutive_checkerboard_animations_; | 323 int consecutive_checkerboard_animations_; |
| 323 int max_pending_swaps_; | 324 int max_pending_swaps_; |
| 324 int pending_swaps_; | 325 int pending_swaps_; |
| 325 int swaps_with_current_output_surface_; | 326 int swaps_with_current_compositor_frame_sink_; |
| 326 bool needs_redraw_; | 327 bool needs_redraw_; |
| 327 bool needs_prepare_tiles_; | 328 bool needs_prepare_tiles_; |
| 328 bool needs_begin_main_frame_; | 329 bool needs_begin_main_frame_; |
| 329 bool needs_one_begin_impl_frame_; | 330 bool needs_one_begin_impl_frame_; |
| 330 bool visible_; | 331 bool visible_; |
| 331 bool begin_frame_source_paused_; | 332 bool begin_frame_source_paused_; |
| 332 bool resourceless_draw_; | 333 bool resourceless_draw_; |
| 333 bool can_draw_; | 334 bool can_draw_; |
| 334 bool has_pending_tree_; | 335 bool has_pending_tree_; |
| 335 bool pending_tree_is_ready_for_activation_; | 336 bool pending_tree_is_ready_for_activation_; |
| 336 bool active_tree_needs_first_draw_; | 337 bool active_tree_needs_first_draw_; |
| 337 bool did_create_and_initialize_first_output_surface_; | 338 bool did_create_and_initialize_first_compositor_frame_sink_; |
| 338 TreePriority tree_priority_; | 339 TreePriority tree_priority_; |
| 339 ScrollHandlerState scroll_handler_state_; | 340 ScrollHandlerState scroll_handler_state_; |
| 340 bool critical_begin_main_frame_to_activate_is_fast_; | 341 bool critical_begin_main_frame_to_activate_is_fast_; |
| 341 bool main_thread_missed_last_deadline_; | 342 bool main_thread_missed_last_deadline_; |
| 342 bool skip_next_begin_main_frame_to_reduce_latency_; | 343 bool skip_next_begin_main_frame_to_reduce_latency_; |
| 343 bool defer_commits_; | 344 bool defer_commits_; |
| 344 bool video_needs_begin_frames_; | 345 bool video_needs_begin_frames_; |
| 345 bool last_commit_had_no_updates_; | 346 bool last_commit_had_no_updates_; |
| 346 bool wait_for_ready_to_draw_; | 347 bool wait_for_ready_to_draw_; |
| 347 bool did_draw_in_last_frame_; | 348 bool did_draw_in_last_frame_; |
| 348 bool did_swap_in_last_frame_; | 349 bool did_swap_in_last_frame_; |
| 349 | 350 |
| 350 private: | 351 private: |
| 351 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); | 352 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); |
| 352 }; | 353 }; |
| 353 | 354 |
| 354 } // namespace cc | 355 } // namespace cc |
| 355 | 356 |
| 356 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ | 357 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ |
| OLD | NEW |