| 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.h" | 5 #include "cc/scheduler/scheduler.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "cc/debug/traced_value.h" | 10 #include "cc/debug/traced_value.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 void Scheduler::NotifyReadyToActivate() { | 47 void Scheduler::NotifyReadyToActivate() { |
| 48 state_machine_.NotifyReadyToActivate(); | 48 state_machine_.NotifyReadyToActivate(); |
| 49 ProcessScheduledActions(); | 49 ProcessScheduledActions(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void Scheduler::SetNeedsCommit() { | 52 void Scheduler::SetNeedsCommit() { |
| 53 state_machine_.SetNeedsCommit(); | 53 state_machine_.SetNeedsCommit(); |
| 54 ProcessScheduledActions(); | 54 ProcessScheduledActions(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void Scheduler::SetNeedsForcedCommit() { | 57 void Scheduler::SetNeedsForcedCommitForReadback() { |
| 58 state_machine_.SetNeedsCommit(); | 58 state_machine_.SetNeedsCommit(); |
| 59 state_machine_.SetNeedsForcedCommit(); | 59 state_machine_.SetNeedsForcedCommitForReadback(); |
| 60 ProcessScheduledActions(); | 60 ProcessScheduledActions(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void Scheduler::SetNeedsRedraw() { | 63 void Scheduler::SetNeedsRedraw() { |
| 64 state_machine_.SetNeedsRedraw(); | 64 state_machine_.SetNeedsRedraw(); |
| 65 ProcessScheduledActions(); | 65 ProcessScheduledActions(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void Scheduler::DidSwapUseIncompleteTile() { | 68 void Scheduler::DidSwapUseIncompleteTile() { |
| 69 state_machine_.DidSwapUseIncompleteTile(); | 69 state_machine_.DidSwapUseIncompleteTile(); |
| 70 ProcessScheduledActions(); | 70 ProcessScheduledActions(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void Scheduler::SetNeedsForcedRedraw() { | |
| 74 state_machine_.SetNeedsForcedRedraw(); | |
| 75 ProcessScheduledActions(); | |
| 76 } | |
| 77 | |
| 78 void Scheduler::SetMainThreadNeedsLayerTextures() { | 73 void Scheduler::SetMainThreadNeedsLayerTextures() { |
| 79 state_machine_.SetMainThreadNeedsLayerTextures(); | 74 state_machine_.SetMainThreadNeedsLayerTextures(); |
| 80 ProcessScheduledActions(); | 75 ProcessScheduledActions(); |
| 81 } | 76 } |
| 82 | 77 |
| 83 void Scheduler::FinishCommit() { | 78 void Scheduler::FinishCommit() { |
| 84 TRACE_EVENT0("cc", "Scheduler::FinishCommit"); | 79 TRACE_EVENT0("cc", "Scheduler::FinishCommit"); |
| 85 state_machine_.FinishCommit(); | 80 state_machine_.FinishCommit(); |
| 86 ProcessScheduledActions(); | 81 ProcessScheduledActions(); |
| 87 } | 82 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 DCHECK(!has_pending_begin_frame_); | 166 DCHECK(!has_pending_begin_frame_); |
| 172 has_pending_begin_frame_ = true; | 167 has_pending_begin_frame_ = true; |
| 173 safe_to_expect_begin_frame_ = true; | 168 safe_to_expect_begin_frame_ = true; |
| 174 last_begin_frame_args_ = args; | 169 last_begin_frame_args_ = args; |
| 175 state_machine_.DidEnterBeginFrame(args); | 170 state_machine_.DidEnterBeginFrame(args); |
| 176 ProcessScheduledActions(); | 171 ProcessScheduledActions(); |
| 177 state_machine_.DidLeaveBeginFrame(); | 172 state_machine_.DidLeaveBeginFrame(); |
| 178 } | 173 } |
| 179 | 174 |
| 180 void Scheduler::DrawAndSwapIfPossible() { | 175 void Scheduler::DrawAndSwapIfPossible() { |
| 181 ScheduledActionDrawAndSwapResult result = | 176 DrawSwapReadbackResult result = |
| 182 client_->ScheduledActionDrawAndSwapIfPossible(); | 177 client_->ScheduledActionDrawAndSwapIfPossible(); |
| 183 state_machine_.DidDrawIfPossibleCompleted(result.did_draw); | 178 state_machine_.DidDrawIfPossibleCompleted(result.did_draw); |
| 184 if (result.did_swap) | 179 if (result.did_swap) |
| 185 has_pending_begin_frame_ = false; | 180 has_pending_begin_frame_ = false; |
| 186 } | 181 } |
| 187 | 182 |
| 188 void Scheduler::DrawAndSwapForced() { | 183 void Scheduler::DrawAndSwapForced() { |
| 189 ScheduledActionDrawAndSwapResult result = | 184 DrawSwapReadbackResult result = client_->ScheduledActionDrawAndSwapForced(); |
| 190 client_->ScheduledActionDrawAndSwapForced(); | |
| 191 if (result.did_swap) | 185 if (result.did_swap) |
| 192 has_pending_begin_frame_ = false; | 186 has_pending_begin_frame_ = false; |
| 193 } | 187 } |
| 194 | 188 |
| 195 void Scheduler::ProcessScheduledActions() { | 189 void Scheduler::ProcessScheduledActions() { |
| 196 // We do not allow ProcessScheduledActions to be recursive. | 190 // We do not allow ProcessScheduledActions to be recursive. |
| 197 // The top-level call will iteratively execute the next action for us anyway. | 191 // The top-level call will iteratively execute the next action for us anyway. |
| 198 if (inside_process_scheduled_actions_) | 192 if (inside_process_scheduled_actions_) |
| 199 return; | 193 return; |
| 200 | 194 |
| 201 base::AutoReset<bool> mark_inside(&inside_process_scheduled_actions_, true); | 195 base::AutoReset<bool> mark_inside(&inside_process_scheduled_actions_, true); |
| 202 | 196 |
| 203 SchedulerStateMachine::Action action; | 197 SchedulerStateMachine::Action action; |
| 204 do { | 198 do { |
| 199 state_machine_.CheckInvariants(); |
| 205 action = state_machine_.NextAction(); | 200 action = state_machine_.NextAction(); |
| 206 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), | 201 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
| 207 "SchedulerStateMachine", | 202 "SchedulerStateMachine", |
| 208 "state", | 203 "state", |
| 209 TracedValue::FromValue(state_machine_.AsValue().release())); | 204 TracedValue::FromValue(state_machine_.AsValue().release())); |
| 210 state_machine_.UpdateState(action); | 205 state_machine_.UpdateState(action); |
| 211 switch (action) { | 206 switch (action) { |
| 212 case SchedulerStateMachine::ACTION_NONE: | 207 case SchedulerStateMachine::ACTION_NONE: |
| 213 break; | 208 break; |
| 214 case SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: | 209 case SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
| 215 client_->ScheduledActionSendBeginFrameToMainThread(); | 210 client_->ScheduledActionSendBeginFrameToMainThread(); |
| 216 break; | 211 break; |
| 217 case SchedulerStateMachine::ACTION_COMMIT: | 212 case SchedulerStateMachine::ACTION_COMMIT: |
| 218 client_->ScheduledActionCommit(); | 213 client_->ScheduledActionCommit(); |
| 219 break; | 214 break; |
| 220 case SchedulerStateMachine::ACTION_UPDATE_VISIBLE_TILES: | 215 case SchedulerStateMachine::ACTION_UPDATE_VISIBLE_TILES: |
| 221 client_->ScheduledActionUpdateVisibleTiles(); | 216 client_->ScheduledActionUpdateVisibleTiles(); |
| 222 break; | 217 break; |
| 223 case SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE: | 218 case SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE: |
| 224 client_->ScheduledActionActivatePendingTree(); | 219 client_->ScheduledActionActivatePendingTree(); |
| 225 break; | 220 break; |
| 226 case SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE: | 221 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE: |
| 227 DrawAndSwapIfPossible(); | 222 DrawAndSwapIfPossible(); |
| 228 break; | 223 break; |
| 229 case SchedulerStateMachine::ACTION_DRAW_FORCED: | 224 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED: |
| 230 DrawAndSwapForced(); | 225 DrawAndSwapForced(); |
| 231 break; | 226 break; |
| 232 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT: | 227 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT: |
| 233 // No action is actually performed, but this allows the state machine to | 228 // No action is actually performed, but this allows the state machine to |
| 234 // advance out of its waiting to draw state without actually drawing. | 229 // advance out of its waiting to draw state without actually drawing. |
| 235 break; | 230 break; |
| 231 case SchedulerStateMachine::ACTION_DRAW_AND_READBACK: |
| 232 client_->ScheduledActionDrawAndReadback(); |
| 233 break; |
| 236 case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION: | 234 case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION: |
| 237 client_->ScheduledActionBeginOutputSurfaceCreation(); | 235 client_->ScheduledActionBeginOutputSurfaceCreation(); |
| 238 break; | 236 break; |
| 239 case SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: | 237 case SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: |
| 240 client_->ScheduledActionAcquireLayerTexturesForMainThread(); | 238 client_->ScheduledActionAcquireLayerTexturesForMainThread(); |
| 241 break; | 239 break; |
| 242 } | 240 } |
| 243 } while (action != SchedulerStateMachine::ACTION_NONE); | 241 } while (action != SchedulerStateMachine::ACTION_NONE); |
| 244 | 242 |
| 245 SetupNextBeginFrameIfNeeded(); | 243 SetupNextBeginFrameIfNeeded(); |
| 246 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime()); | 244 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime()); |
| 247 } | 245 } |
| 248 | 246 |
| 249 bool Scheduler::WillDrawIfNeeded() const { | 247 bool Scheduler::WillDrawIfNeeded() const { |
| 250 return !state_machine_.PendingDrawsShouldBeAborted(); | 248 return !state_machine_.PendingDrawsShouldBeAborted(); |
| 251 } | 249 } |
| 252 | 250 |
| 253 } // namespace cc | 251 } // namespace cc |
| OLD | NEW |