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/trees/thread_proxy.h" | 5 #include "cc/trees/thread_proxy.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
446 void ThreadProxy::SetNeedsBeginImplFrame(bool enable) { | 446 void ThreadProxy::SetNeedsBeginImplFrame(bool enable) { |
447 TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginImplFrame", "enable", enable); | 447 TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginImplFrame", "enable", enable); |
448 DCHECK(IsImplThread()); | 448 DCHECK(IsImplThread()); |
449 impl().layer_tree_host_impl->SetNeedsBeginImplFrame(enable); | 449 impl().layer_tree_host_impl->SetNeedsBeginImplFrame(enable); |
450 UpdateBackgroundAnimateTicking(); | 450 UpdateBackgroundAnimateTicking(); |
451 } | 451 } |
452 | 452 |
453 void ThreadProxy::BeginImplFrame(const BeginFrameArgs& args) { | 453 void ThreadProxy::BeginImplFrame(const BeginFrameArgs& args) { |
454 TRACE_EVENT0("cc", "ThreadProxy::BeginImplFrame"); | 454 TRACE_EVENT0("cc", "ThreadProxy::BeginImplFrame"); |
455 DCHECK(IsImplThread()); | 455 DCHECK(IsImplThread()); |
456 | |
457 // Sample the frame time now. This time will be used for updating animations | |
458 // when we draw. | |
459 impl().layer_tree_host_impl->UpdateCurrentFrameTime(); | |
460 | |
461 impl().scheduler->BeginImplFrame(args); | 456 impl().scheduler->BeginImplFrame(args); |
462 } | 457 } |
463 | 458 |
464 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) { | 459 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
465 TRACE_EVENT1( | 460 TRACE_EVENT1( |
466 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); | 461 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); |
467 DCHECK(IsImplThread()); | 462 DCHECK(IsImplThread()); |
468 impl().scheduler->SetCanDraw(can_draw); | 463 impl().scheduler->SetCanDraw(can_draw); |
469 UpdateBackgroundAnimateTicking(); | 464 UpdateBackgroundAnimateTicking(); |
470 } | 465 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 DCHECK(IsMainThread()); | 577 DCHECK(IsMainThread()); |
583 return main().commit_request_sent_to_impl_thread; | 578 return main().commit_request_sent_to_impl_thread; |
584 } | 579 } |
585 | 580 |
586 void ThreadProxy::SetNeedsRedrawOnImplThread() { | 581 void ThreadProxy::SetNeedsRedrawOnImplThread() { |
587 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsRedrawOnImplThread"); | 582 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsRedrawOnImplThread"); |
588 DCHECK(IsImplThread()); | 583 DCHECK(IsImplThread()); |
589 impl().scheduler->SetNeedsRedraw(); | 584 impl().scheduler->SetNeedsRedraw(); |
590 } | 585 } |
591 | 586 |
587 void ThreadProxy::SetNeedsAnimateOnImplThread() { | |
588 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsAnimateOnImplThread"); | |
589 DCHECK(IsImplThread()); | |
590 impl().scheduler->SetNeedsAnimate(); | |
591 } | |
592 | |
592 void ThreadProxy::SetNeedsManageTilesOnImplThread() { | 593 void ThreadProxy::SetNeedsManageTilesOnImplThread() { |
593 DCHECK(IsImplThread()); | 594 DCHECK(IsImplThread()); |
594 impl().scheduler->SetNeedsManageTiles(); | 595 impl().scheduler->SetNeedsManageTiles(); |
595 } | 596 } |
596 | 597 |
597 void ThreadProxy::SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) { | 598 void ThreadProxy::SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) { |
598 DCHECK(IsImplThread()); | 599 DCHECK(IsImplThread()); |
599 impl().layer_tree_host_impl->SetViewportDamage(damage_rect); | 600 impl().layer_tree_host_impl->SetViewportDamage(damage_rect); |
600 SetNeedsRedrawOnImplThread(); | 601 SetNeedsRedrawOnImplThread(); |
601 } | 602 } |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1046 DCHECK(impl().scheduler); | 1047 DCHECK(impl().scheduler); |
1047 DCHECK(impl().scheduler->CommitPending()); | 1048 DCHECK(impl().scheduler->CommitPending()); |
1048 DCHECK(!impl().layer_tree_host_impl->pending_tree()); | 1049 DCHECK(!impl().layer_tree_host_impl->pending_tree()); |
1049 | 1050 |
1050 if (did_handle) | 1051 if (did_handle) |
1051 SetInputThrottledUntilCommitOnImplThread(false); | 1052 SetInputThrottledUntilCommitOnImplThread(false); |
1052 impl().layer_tree_host_impl->BeginMainFrameAborted(did_handle); | 1053 impl().layer_tree_host_impl->BeginMainFrameAborted(did_handle); |
1053 impl().scheduler->BeginMainFrameAborted(did_handle); | 1054 impl().scheduler->BeginMainFrameAborted(did_handle); |
1054 } | 1055 } |
1055 | 1056 |
1057 void ThreadProxy::ScheduledActionAnimate() { | |
1058 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionAnimate"); | |
1059 DCHECK(IsImplThread()); | |
1060 | |
1061 impl().layer_tree_host_impl->UpdateCurrentFrameTime(); | |
brianderson
2014/04/01 16:05:11
I think we should keep the UpdateCurrentFrameTime(
Sami
2014/04/17 15:16:33
Yes, agreed. I've changed this back the way it was
| |
1062 UpdateBackgroundAnimateTicking(); | |
1063 | |
1064 if (!impl().animations_frozen_until_next_draw) { | |
1065 impl().animation_time = | |
1066 impl().layer_tree_host_impl->CurrentFrameTimeTicks(); | |
1067 } | |
1068 impl().layer_tree_host_impl->Animate(impl().animation_time); | |
1069 } | |
1070 | |
1056 void ThreadProxy::ScheduledActionCommit() { | 1071 void ThreadProxy::ScheduledActionCommit() { |
1057 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionCommit"); | 1072 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionCommit"); |
1058 DCHECK(IsImplThread()); | 1073 DCHECK(IsImplThread()); |
1059 DCHECK(IsMainThreadBlocked()); | 1074 DCHECK(IsMainThreadBlocked()); |
1060 DCHECK(impl().commit_completion_event); | 1075 DCHECK(impl().commit_completion_event); |
1061 DCHECK(impl().current_resource_update_controller); | 1076 DCHECK(impl().current_resource_update_controller); |
1062 | 1077 |
1063 // Complete all remaining texture updates. | 1078 // Complete all remaining texture updates. |
1064 impl().current_resource_update_controller->Finalize(); | 1079 impl().current_resource_update_controller->Finalize(); |
1065 impl().current_resource_update_controller.reset(); | 1080 impl().current_resource_update_controller.reset(); |
1066 | 1081 |
1067 if (impl().animations_frozen_until_next_draw) { | 1082 if (impl().animations_frozen_until_next_draw) { |
1068 impl().animation_freeze_time = | 1083 impl().animation_time = std::max( |
1069 std::max(impl().animation_freeze_time, | 1084 impl().animation_time, blocked_main().last_monotonic_frame_begin_time); |
1070 blocked_main().last_monotonic_frame_begin_time); | |
1071 } | 1085 } |
1072 | 1086 |
1073 blocked_main().main_thread_inside_commit = true; | 1087 blocked_main().main_thread_inside_commit = true; |
1074 impl().layer_tree_host_impl->BeginCommit(); | 1088 impl().layer_tree_host_impl->BeginCommit(); |
1075 layer_tree_host()->BeginCommitOnImplThread(impl().layer_tree_host_impl.get()); | 1089 layer_tree_host()->BeginCommitOnImplThread(impl().layer_tree_host_impl.get()); |
1076 layer_tree_host()->FinishCommitOnImplThread( | 1090 layer_tree_host()->FinishCommitOnImplThread( |
1077 impl().layer_tree_host_impl.get()); | 1091 impl().layer_tree_host_impl.get()); |
1078 blocked_main().main_thread_inside_commit = false; | 1092 blocked_main().main_thread_inside_commit = false; |
1079 | 1093 |
1080 bool hold_commit = layer_tree_host()->settings().impl_side_painting && | 1094 bool hold_commit = layer_tree_host()->settings().impl_side_painting && |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1138 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap"); | 1152 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap"); |
1139 DrawSwapReadbackResult result; | 1153 DrawSwapReadbackResult result; |
1140 | 1154 |
1141 DCHECK(IsImplThread()); | 1155 DCHECK(IsImplThread()); |
1142 DCHECK(impl().layer_tree_host_impl.get()); | 1156 DCHECK(impl().layer_tree_host_impl.get()); |
1143 | 1157 |
1144 impl().timing_history.DidStartDrawing(); | 1158 impl().timing_history.DidStartDrawing(); |
1145 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); | 1159 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); |
1146 base::AutoReset<bool> mark_inside(&impl().inside_draw, true); | 1160 base::AutoReset<bool> mark_inside(&impl().inside_draw, true); |
1147 | 1161 |
1148 // Advance our animations. | |
1149 base::TimeTicks monotonic_time; | |
1150 if (impl().animations_frozen_until_next_draw) | |
1151 monotonic_time = impl().animation_freeze_time; | |
1152 else | |
1153 monotonic_time = impl().layer_tree_host_impl->CurrentFrameTimeTicks(); | |
1154 | |
1155 // TODO(enne): This should probably happen post-animate. | |
1156 if (impl().layer_tree_host_impl->pending_tree()) | |
1157 impl().layer_tree_host_impl->pending_tree()->UpdateDrawProperties(); | |
1158 impl().layer_tree_host_impl->Animate(monotonic_time); | |
1159 | |
1160 // This method is called on a forced draw, regardless of whether we are able | 1162 // This method is called on a forced draw, regardless of whether we are able |
1161 // to produce a frame, as the calling site on main thread is blocked until its | 1163 // to produce a frame, as the calling site on main thread is blocked until its |
1162 // request completes, and we signal completion here. If CanDraw() is false, we | 1164 // request completes, and we signal completion here. If CanDraw() is false, we |
1163 // will indicate success=false to the caller, but we must still signal | 1165 // will indicate success=false to the caller, but we must still signal |
1164 // completion to avoid deadlock. | 1166 // completion to avoid deadlock. |
1165 | 1167 |
1166 // We guard PrepareToDraw() with CanDraw() because it always returns a valid | 1168 // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
1167 // frame, so can only be used when such a frame is possible. Since | 1169 // frame, so can only be used when such a frame is possible. Since |
1168 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on | 1170 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
1169 // CanDraw() as well. | 1171 // CanDraw() as well. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1202 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS && | 1204 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS && |
1203 !impl().layer_tree_host_impl->settings().impl_side_painting) { | 1205 !impl().layer_tree_host_impl->settings().impl_side_painting) { |
1204 // Without impl-side painting, the animated layer that is checkerboarding | 1206 // Without impl-side painting, the animated layer that is checkerboarding |
1205 // will continue to checkerboard until the next commit. If this layer | 1207 // will continue to checkerboard until the next commit. If this layer |
1206 // continues to move during the commit, it may continue to checkerboard | 1208 // continues to move during the commit, it may continue to checkerboard |
1207 // after the commit since the region rasterized during the commit will not | 1209 // after the commit since the region rasterized during the commit will not |
1208 // match the region that is currently visible; eventually this | 1210 // match the region that is currently visible; eventually this |
1209 // checkerboarding will be displayed when we force a draw. To avoid this, | 1211 // checkerboarding will be displayed when we force a draw. To avoid this, |
1210 // we freeze animations until we successfully draw. | 1212 // we freeze animations until we successfully draw. |
1211 impl().animations_frozen_until_next_draw = true; | 1213 impl().animations_frozen_until_next_draw = true; |
1212 impl().animation_freeze_time = monotonic_time; | |
1213 } else { | 1214 } else { |
1214 DCHECK_NE(DrawSwapReadbackResult::DRAW_SUCCESS, result.draw_result); | 1215 DCHECK_NE(DrawSwapReadbackResult::DRAW_SUCCESS, result.draw_result); |
1215 } | 1216 } |
1216 impl().layer_tree_host_impl->DidDrawAllLayers(frame); | 1217 impl().layer_tree_host_impl->DidDrawAllLayers(frame); |
1217 | 1218 |
1218 bool start_ready_animations = draw_frame; | 1219 bool start_ready_animations = draw_frame; |
1219 impl().layer_tree_host_impl->UpdateAnimationState(start_ready_animations); | 1220 impl().layer_tree_host_impl->UpdateAnimationState(start_ready_animations); |
1220 | 1221 |
1221 // Check for a pending CompositeAndReadback. | 1222 // Check for a pending CompositeAndReadback. |
1222 if (drawing_for_readback) { | 1223 if (drawing_for_readback) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1333 impl().layer_tree_host_impl->ManageTiles(); | 1334 impl().layer_tree_host_impl->ManageTiles(); |
1334 } | 1335 } |
1335 | 1336 |
1336 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapIfPossible() { | 1337 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapIfPossible() { |
1337 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap"); | 1338 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap"); |
1338 | 1339 |
1339 // SchedulerStateMachine::DidDrawIfPossibleCompleted isn't set up to | 1340 // SchedulerStateMachine::DidDrawIfPossibleCompleted isn't set up to |
1340 // handle DRAW_ABORTED_CANT_DRAW. Moreover, the scheduler should | 1341 // handle DRAW_ABORTED_CANT_DRAW. Moreover, the scheduler should |
1341 // never generate this call when it can't draw. | 1342 // never generate this call when it can't draw. |
1342 DCHECK(impl().layer_tree_host_impl->CanDraw()); | 1343 DCHECK(impl().layer_tree_host_impl->CanDraw()); |
1344 if (impl().layer_tree_host_impl->pending_tree()) | |
1345 impl().layer_tree_host_impl->pending_tree()->UpdateDrawProperties(); | |
brianderson
2014/04/01 16:05:11
Why was this moved here?
Sami
2014/04/17 15:16:33
Hmm, I was trying to keep it in DrawSwapReadbackIn
| |
1343 | 1346 |
1344 bool forced_draw = false; | 1347 bool forced_draw = false; |
1345 bool swap_requested = true; | 1348 bool swap_requested = true; |
1346 bool readback_requested = false; | 1349 bool readback_requested = false; |
1347 return DrawSwapReadbackInternal( | 1350 return DrawSwapReadbackInternal( |
1348 forced_draw, swap_requested, readback_requested); | 1351 forced_draw, swap_requested, readback_requested); |
1349 } | 1352 } |
1350 | 1353 |
1351 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapForced() { | 1354 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapForced() { |
1352 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwapForced"); | 1355 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwapForced"); |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1726 | 1729 |
1727 impl().timing_history.DidActivatePendingTree(); | 1730 impl().timing_history.DidActivatePendingTree(); |
1728 } | 1731 } |
1729 | 1732 |
1730 void ThreadProxy::DidManageTiles() { | 1733 void ThreadProxy::DidManageTiles() { |
1731 DCHECK(IsImplThread()); | 1734 DCHECK(IsImplThread()); |
1732 impl().scheduler->DidManageTiles(); | 1735 impl().scheduler->DidManageTiles(); |
1733 } | 1736 } |
1734 | 1737 |
1735 } // namespace cc | 1738 } // namespace cc |
OLD | NEW |