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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 Proxy::MainThreadTaskRunner()->PostTask( | 390 Proxy::MainThreadTaskRunner()->PostTask( |
391 FROM_HERE, | 391 FROM_HERE, |
392 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); | 392 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); |
393 } | 393 } |
394 | 394 |
395 void ThreadProxy::SetNeedsBeginFrameOnImplThread(bool enable) { | 395 void ThreadProxy::SetNeedsBeginFrameOnImplThread(bool enable) { |
396 DCHECK(IsImplThread()); | 396 DCHECK(IsImplThread()); |
397 TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginFrameOnImplThread", | 397 TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginFrameOnImplThread", |
398 "enable", enable); | 398 "enable", enable); |
399 layer_tree_host_impl_->SetNeedsBeginFrame(enable); | 399 layer_tree_host_impl_->SetNeedsBeginFrame(enable); |
| 400 UpdateBackgroundAnimateTicking(); |
400 } | 401 } |
401 | 402 |
402 void ThreadProxy::BeginFrameOnImplThread(const BeginFrameArgs& args) { | 403 void ThreadProxy::BeginFrameOnImplThread(const BeginFrameArgs& args) { |
403 DCHECK(IsImplThread()); | 404 DCHECK(IsImplThread()); |
404 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnImplThread"); | 405 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnImplThread"); |
| 406 |
| 407 // Sample the frame time now. This time will be used for updating animations |
| 408 // when we draw. |
| 409 layer_tree_host_impl_->CurrentFrameTimeTicks(); |
| 410 |
405 scheduler_on_impl_thread_->BeginFrame(args); | 411 scheduler_on_impl_thread_->BeginFrame(args); |
406 } | 412 } |
407 | 413 |
| 414 void ThreadProxy::DidBeginFrameDeadlineOnImplThread() { |
| 415 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
| 416 } |
| 417 |
408 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) { | 418 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
409 DCHECK(IsImplThread()); | 419 DCHECK(IsImplThread()); |
410 TRACE_EVENT1( | 420 TRACE_EVENT1( |
411 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); | 421 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); |
412 scheduler_on_impl_thread_->SetCanDraw(can_draw); | 422 scheduler_on_impl_thread_->SetCanDraw(can_draw); |
413 UpdateBackgroundAnimateTicking(); | 423 UpdateBackgroundAnimateTicking(); |
414 } | 424 } |
415 | 425 |
416 void ThreadProxy::NotifyReadyToActivate() { | 426 void ThreadProxy::NotifyReadyToActivate() { |
417 TRACE_EVENT0("cc", "ThreadProxy::NotifyReadyToActivate"); | 427 TRACE_EVENT0("cc", "ThreadProxy::NotifyReadyToActivate"); |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 result.did_readback = false; | 1038 result.did_readback = false; |
1029 DCHECK(IsImplThread()); | 1039 DCHECK(IsImplThread()); |
1030 DCHECK(layer_tree_host_impl_.get()); | 1040 DCHECK(layer_tree_host_impl_.get()); |
1031 if (!layer_tree_host_impl_) | 1041 if (!layer_tree_host_impl_) |
1032 return result; | 1042 return result; |
1033 | 1043 |
1034 DCHECK(layer_tree_host_impl_->renderer()); | 1044 DCHECK(layer_tree_host_impl_->renderer()); |
1035 if (!layer_tree_host_impl_->renderer()) | 1045 if (!layer_tree_host_impl_->renderer()) |
1036 return result; | 1046 return result; |
1037 | 1047 |
1038 base::TimeTicks monotonic_time = | |
1039 layer_tree_host_impl_->CurrentFrameTimeTicks(); | |
1040 base::Time wall_clock_time = layer_tree_host_impl_->CurrentFrameTime(); | |
1041 | |
1042 // TODO(enne): This should probably happen post-animate. | |
1043 if (layer_tree_host_impl_->pending_tree()) | |
1044 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties(); | |
1045 layer_tree_host_impl_->Animate(monotonic_time, wall_clock_time); | |
1046 UpdateBackgroundAnimateTicking(); | |
1047 | |
1048 base::TimeTicks start_time = base::TimeTicks::HighResNow(); | 1048 base::TimeTicks start_time = base::TimeTicks::HighResNow(); |
1049 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); | 1049 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); |
1050 base::AutoReset<bool> mark_inside(&inside_draw_, true); | 1050 base::AutoReset<bool> mark_inside(&inside_draw_, true); |
1051 | 1051 |
| 1052 // Advance our animations. |
| 1053 base::TimeTicks monotonic_time = |
| 1054 layer_tree_host_impl_->CurrentFrameTimeTicks(); |
| 1055 base::Time wall_clock_time = layer_tree_host_impl_->CurrentFrameTime(); |
| 1056 layer_tree_host_impl_->Animate(monotonic_time, wall_clock_time); |
| 1057 |
1052 // This method is called on a forced draw, regardless of whether we are able | 1058 // This method is called on a forced draw, regardless of whether we are able |
1053 // to produce a frame, as the calling site on main thread is blocked until its | 1059 // to produce a frame, as the calling site on main thread is blocked until its |
1054 // request completes, and we signal completion here. If CanDraw() is false, we | 1060 // request completes, and we signal completion here. If CanDraw() is false, we |
1055 // will indicate success=false to the caller, but we must still signal | 1061 // will indicate success=false to the caller, but we must still signal |
1056 // completion to avoid deadlock. | 1062 // completion to avoid deadlock. |
1057 | 1063 |
1058 // We guard PrepareToDraw() with CanDraw() because it always returns a valid | 1064 // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
1059 // frame, so can only be used when such a frame is possible. Since | 1065 // frame, so can only be used when such a frame is possible. Since |
1060 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on | 1066 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
1061 // CanDraw() as well. | 1067 // CanDraw() as well. |
1062 | 1068 |
1063 // readback_request_on_impl_thread_ may be for the pending tree, do | |
1064 // not perform the readback unless explicitly requested. | |
1065 bool drawing_for_readback = | 1069 bool drawing_for_readback = |
1066 readback_requested && !!readback_request_on_impl_thread_; | 1070 readback_requested && !!readback_request_on_impl_thread_; |
1067 bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels(); | 1071 bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels(); |
1068 | 1072 |
1069 LayerTreeHostImpl::FrameData frame; | 1073 LayerTreeHostImpl::FrameData frame; |
1070 bool draw_frame = false; | 1074 bool draw_frame = false; |
1071 bool start_ready_animations = true; | |
1072 | 1075 |
1073 if (layer_tree_host_impl_->CanDraw() && | 1076 if (layer_tree_host_impl_->CanDraw() && |
1074 (!drawing_for_readback || can_do_readback)) { | 1077 (!drawing_for_readback || can_do_readback)) { |
1075 // If it is for a readback, make sure we draw the portion being read back. | 1078 // If it is for a readback, make sure we draw the portion being read back. |
1076 gfx::Rect readback_rect; | 1079 gfx::Rect readback_rect; |
1077 if (drawing_for_readback) | 1080 if (drawing_for_readback) |
1078 readback_rect = readback_request_on_impl_thread_->rect; | 1081 readback_rect = readback_request_on_impl_thread_->rect; |
1079 | 1082 |
1080 // Do not start animations if we skip drawing the frame to avoid | |
1081 // checkerboarding. | |
1082 if (layer_tree_host_impl_->PrepareToDraw(&frame, readback_rect) || | 1083 if (layer_tree_host_impl_->PrepareToDraw(&frame, readback_rect) || |
1083 forced_draw) | 1084 forced_draw) |
1084 draw_frame = true; | 1085 draw_frame = true; |
1085 else | |
1086 start_ready_animations = false; | |
1087 } | 1086 } |
1088 | 1087 |
1089 if (draw_frame) { | 1088 if (draw_frame) { |
1090 layer_tree_host_impl_->DrawLayers( | 1089 layer_tree_host_impl_->DrawLayers( |
1091 &frame, | 1090 &frame, |
1092 scheduler_on_impl_thread_->LastBeginFrameOnImplThreadTime()); | 1091 scheduler_on_impl_thread_->LastBeginFrameOnImplThreadTime()); |
1093 result.did_draw = true; | 1092 result.did_draw = true; |
1094 } | 1093 } |
1095 layer_tree_host_impl_->DidDrawAllLayers(frame); | 1094 layer_tree_host_impl_->DidDrawAllLayers(frame); |
| 1095 |
| 1096 bool start_ready_animations = draw_frame; |
1096 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | 1097 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
1097 | 1098 |
1098 // Check for a pending CompositeAndReadback. | 1099 // Check for a pending CompositeAndReadback. |
1099 if (drawing_for_readback) { | 1100 if (drawing_for_readback) { |
1100 DCHECK(!swap_requested); | 1101 DCHECK(!swap_requested); |
1101 result.did_readback = false; | 1102 result.did_readback = false; |
1102 if (draw_frame && !layer_tree_host_impl_->IsContextLost()) { | 1103 if (draw_frame && !layer_tree_host_impl_->IsContextLost()) { |
1103 layer_tree_host_impl_->Readback(readback_request_on_impl_thread_->pixels, | 1104 layer_tree_host_impl_->Readback(readback_request_on_impl_thread_->pixels, |
1104 readback_request_on_impl_thread_->rect); | 1105 readback_request_on_impl_thread_->rect); |
1105 result.did_readback = true; | 1106 result.did_readback = true; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndReadback"); | 1227 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndReadback"); |
1227 bool forced_draw = true; | 1228 bool forced_draw = true; |
1228 bool swap_requested = false; | 1229 bool swap_requested = false; |
1229 bool readback_requested = true; | 1230 bool readback_requested = true; |
1230 return DrawSwapReadbackInternal( | 1231 return DrawSwapReadbackInternal( |
1231 forced_draw, swap_requested, readback_requested); | 1232 forced_draw, swap_requested, readback_requested); |
1232 } | 1233 } |
1233 | 1234 |
1234 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { | 1235 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { |
1235 if (current_resource_update_controller_on_impl_thread_) | 1236 if (current_resource_update_controller_on_impl_thread_) |
1236 current_resource_update_controller_on_impl_thread_ | 1237 current_resource_update_controller_on_impl_thread_->PerformMoreUpdates( |
1237 ->PerformMoreUpdates(time); | 1238 time); |
1238 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | |
1239 } | 1239 } |
1240 | 1240 |
1241 base::TimeDelta ThreadProxy::DrawDurationEstimate() { | 1241 base::TimeDelta ThreadProxy::DrawDurationEstimate() { |
1242 base::TimeDelta historical_estimate = | 1242 base::TimeDelta historical_estimate = |
1243 draw_duration_history_.Percentile(kDrawDurationEstimationPercentile); | 1243 draw_duration_history_.Percentile(kDrawDurationEstimationPercentile); |
1244 base::TimeDelta padding = base::TimeDelta::FromMicroseconds( | 1244 base::TimeDelta padding = base::TimeDelta::FromMicroseconds( |
1245 kDrawDurationEstimatePaddingInMicroseconds); | 1245 kDrawDurationEstimatePaddingInMicroseconds); |
1246 return historical_estimate + padding; | 1246 return historical_estimate + padding; |
1247 } | 1247 } |
1248 | 1248 |
1249 base::TimeDelta ThreadProxy::BeginFrameToCommitDurationEstimate() { | 1249 base::TimeDelta ThreadProxy::BeginFrameToCommitDurationEstimate() { |
1250 return begin_frame_to_commit_duration_history_.Percentile( | 1250 return begin_frame_to_commit_duration_history_.Percentile( |
1251 kCommitAndActivationDurationEstimationPercentile); | 1251 kCommitAndActivationDurationEstimationPercentile); |
1252 } | 1252 } |
1253 | 1253 |
1254 base::TimeDelta ThreadProxy::CommitToActivateDurationEstimate() { | 1254 base::TimeDelta ThreadProxy::CommitToActivateDurationEstimate() { |
1255 return commit_to_activate_duration_history_.Percentile( | 1255 return commit_to_activate_duration_history_.Percentile( |
1256 kCommitAndActivationDurationEstimationPercentile); | 1256 kCommitAndActivationDurationEstimationPercentile); |
1257 } | 1257 } |
1258 | 1258 |
| 1259 void ThreadProxy::PostBeginFrameDeadline(const base::Closure& closure, |
| 1260 base::TimeTicks deadline) { |
| 1261 base::TimeDelta delta = deadline - base::TimeTicks::Now(); |
| 1262 if (delta <= base::TimeDelta()) |
| 1263 delta = base::TimeDelta(); |
| 1264 Proxy::ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE, closure, delta); |
| 1265 } |
| 1266 |
1259 void ThreadProxy::ReadyToFinalizeTextureUpdates() { | 1267 void ThreadProxy::ReadyToFinalizeTextureUpdates() { |
1260 DCHECK(IsImplThread()); | 1268 DCHECK(IsImplThread()); |
1261 scheduler_on_impl_thread_->FinishCommit(); | 1269 scheduler_on_impl_thread_->FinishCommit(); |
1262 } | 1270 } |
1263 | 1271 |
1264 void ThreadProxy::DidCommitAndDrawFrame() { | 1272 void ThreadProxy::DidCommitAndDrawFrame() { |
1265 DCHECK(IsMainThread()); | 1273 DCHECK(IsMainThread()); |
1266 if (!layer_tree_host_) | 1274 if (!layer_tree_host_) |
1267 return; | 1275 return; |
1268 layer_tree_host_->DidCommitAndDrawFrame(); | 1276 layer_tree_host_->DidCommitAndDrawFrame(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 scheduler_on_impl_thread_->HasInitializedOutputSurface(); | 1327 scheduler_on_impl_thread_->HasInitializedOutputSurface(); |
1320 completion->Signal(); | 1328 completion->Signal(); |
1321 } | 1329 } |
1322 | 1330 |
1323 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { | 1331 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { |
1324 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); | 1332 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); |
1325 DCHECK(IsImplThread()); | 1333 DCHECK(IsImplThread()); |
1326 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); | 1334 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); |
1327 const LayerTreeSettings& settings = layer_tree_host_->settings(); | 1335 const LayerTreeSettings& settings = layer_tree_host_->settings(); |
1328 SchedulerSettings scheduler_settings; | 1336 SchedulerSettings scheduler_settings; |
| 1337 scheduler_settings.deadline_scheduling_enabled = |
| 1338 settings.deadline_scheduling_enabled; |
1329 scheduler_settings.impl_side_painting = settings.impl_side_painting; | 1339 scheduler_settings.impl_side_painting = settings.impl_side_painting; |
1330 scheduler_settings.timeout_and_draw_when_animation_checkerboards = | 1340 scheduler_settings.timeout_and_draw_when_animation_checkerboards = |
1331 settings.timeout_and_draw_when_animation_checkerboards; | 1341 settings.timeout_and_draw_when_animation_checkerboards; |
1332 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = | 1342 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = |
1333 settings.maximum_number_of_failed_draws_before_draw_is_forced_; | 1343 settings.maximum_number_of_failed_draws_before_draw_is_forced_; |
1334 scheduler_settings.using_synchronous_renderer_compositor = | 1344 scheduler_settings.using_synchronous_renderer_compositor = |
1335 settings.using_synchronous_renderer_compositor; | 1345 settings.using_synchronous_renderer_compositor; |
1336 scheduler_settings.throttle_frame_production = | 1346 scheduler_settings.throttle_frame_production = |
1337 settings.throttle_frame_production; | 1347 settings.throttle_frame_production; |
1338 scheduler_on_impl_thread_ = Scheduler::Create(this, scheduler_settings); | 1348 scheduler_on_impl_thread_ = Scheduler::Create(this, scheduler_settings); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 completion_event_for_commit_held_on_tree_activation_ = NULL; | 1578 completion_event_for_commit_held_on_tree_activation_ = NULL; |
1569 } | 1579 } |
1570 | 1580 |
1571 UpdateBackgroundAnimateTicking(); | 1581 UpdateBackgroundAnimateTicking(); |
1572 | 1582 |
1573 commit_to_activate_duration_history_.InsertSample( | 1583 commit_to_activate_duration_history_.InsertSample( |
1574 base::TimeTicks::HighResNow() - commit_complete_time_); | 1584 base::TimeTicks::HighResNow() - commit_complete_time_); |
1575 } | 1585 } |
1576 | 1586 |
1577 } // namespace cc | 1587 } // namespace cc |
OLD | NEW |