| 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 |
| 189 void Scheduler::DrawAndReadback() { |
| 190 DrawSwapReadbackResult result = client_->ScheduledActionDrawAndReadback(); |
| 191 DCHECK(!result.did_swap); |
| 192 } |
| 193 |
| 195 void Scheduler::ProcessScheduledActions() { | 194 void Scheduler::ProcessScheduledActions() { |
| 196 // We do not allow ProcessScheduledActions to be recursive. | 195 // We do not allow ProcessScheduledActions to be recursive. |
| 197 // The top-level call will iteratively execute the next action for us anyway. | 196 // The top-level call will iteratively execute the next action for us anyway. |
| 198 if (inside_process_scheduled_actions_) | 197 if (inside_process_scheduled_actions_) |
| 199 return; | 198 return; |
| 200 | 199 |
| 201 base::AutoReset<bool> mark_inside(&inside_process_scheduled_actions_, true); | 200 base::AutoReset<bool> mark_inside(&inside_process_scheduled_actions_, true); |
| 202 | 201 |
| 203 SchedulerStateMachine::Action action; | 202 SchedulerStateMachine::Action action; |
| 204 do { | 203 do { |
| 204 state_machine_.CheckInvariants(); |
| 205 action = state_machine_.NextAction(); | 205 action = state_machine_.NextAction(); |
| 206 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), | 206 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
| 207 "SchedulerStateMachine", | 207 "SchedulerStateMachine", |
| 208 "state", | 208 "state", |
| 209 TracedValue::FromValue(state_machine_.AsValue().release())); | 209 TracedValue::FromValue(state_machine_.AsValue().release())); |
| 210 state_machine_.UpdateState(action); | 210 state_machine_.UpdateState(action); |
| 211 switch (action) { | 211 switch (action) { |
| 212 case SchedulerStateMachine::ACTION_NONE: | 212 case SchedulerStateMachine::ACTION_NONE: |
| 213 break; | 213 break; |
| 214 case SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: | 214 case SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
| 215 client_->ScheduledActionSendBeginFrameToMainThread(); | 215 client_->ScheduledActionSendBeginFrameToMainThread(); |
| 216 break; | 216 break; |
| 217 case SchedulerStateMachine::ACTION_COMMIT: | 217 case SchedulerStateMachine::ACTION_COMMIT: |
| 218 client_->ScheduledActionCommit(); | 218 client_->ScheduledActionCommit(); |
| 219 break; | 219 break; |
| 220 case SchedulerStateMachine::ACTION_UPDATE_VISIBLE_TILES: | 220 case SchedulerStateMachine::ACTION_UPDATE_VISIBLE_TILES: |
| 221 client_->ScheduledActionUpdateVisibleTiles(); | 221 client_->ScheduledActionUpdateVisibleTiles(); |
| 222 break; | 222 break; |
| 223 case SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE: | 223 case SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE: |
| 224 client_->ScheduledActionActivatePendingTree(); | 224 client_->ScheduledActionActivatePendingTree(); |
| 225 break; | 225 break; |
| 226 case SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE: | 226 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE: |
| 227 DrawAndSwapIfPossible(); | 227 DrawAndSwapIfPossible(); |
| 228 break; | 228 break; |
| 229 case SchedulerStateMachine::ACTION_DRAW_FORCED: | 229 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED: |
| 230 DrawAndSwapForced(); | 230 DrawAndSwapForced(); |
| 231 break; | 231 break; |
| 232 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT: | 232 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT: |
| 233 // No action is actually performed, but this allows the state machine to | 233 // No action is actually performed, but this allows the state machine to |
| 234 // advance out of its waiting to draw state without actually drawing. | 234 // advance out of its waiting to draw state without actually drawing. |
| 235 break; | 235 break; |
| 236 case SchedulerStateMachine::ACTION_DRAW_AND_READBACK: |
| 237 DrawAndReadback(); |
| 238 break; |
| 236 case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION: | 239 case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION: |
| 237 client_->ScheduledActionBeginOutputSurfaceCreation(); | 240 client_->ScheduledActionBeginOutputSurfaceCreation(); |
| 238 break; | 241 break; |
| 239 case SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: | 242 case SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: |
| 240 client_->ScheduledActionAcquireLayerTexturesForMainThread(); | 243 client_->ScheduledActionAcquireLayerTexturesForMainThread(); |
| 241 break; | 244 break; |
| 242 } | 245 } |
| 243 } while (action != SchedulerStateMachine::ACTION_NONE); | 246 } while (action != SchedulerStateMachine::ACTION_NONE); |
| 244 | 247 |
| 245 SetupNextBeginFrameIfNeeded(); | 248 SetupNextBeginFrameIfNeeded(); |
| 246 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime()); | 249 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime()); |
| 247 } | 250 } |
| 248 | 251 |
| 249 bool Scheduler::WillDrawIfNeeded() const { | 252 bool Scheduler::WillDrawIfNeeded() const { |
| 250 return !state_machine_.PendingDrawsShouldBeAborted(); | 253 return !state_machine_.PendingDrawsShouldBeAborted(); |
| 251 } | 254 } |
| 252 | 255 |
| 253 } // namespace cc | 256 } // namespace cc |
| OLD | NEW |