Chromium Code Reviews| 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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "cc/base/thread.h" | 10 #include "cc/base/thread.h" |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 | 511 |
| 512 void ThreadProxy::MainThreadHasStoppedFlinging() { | 512 void ThreadProxy::MainThreadHasStoppedFlinging() { |
| 513 DCHECK(IsMainThread()); | 513 DCHECK(IsMainThread()); |
| 514 Proxy::ImplThread()->PostTask( | 514 Proxy::ImplThread()->PostTask( |
| 515 base::Bind(&ThreadProxy::MainThreadHasStoppedFlingingOnImplThread, | 515 base::Bind(&ThreadProxy::MainThreadHasStoppedFlingingOnImplThread, |
| 516 impl_thread_weak_ptr_)); | 516 impl_thread_weak_ptr_)); |
| 517 } | 517 } |
| 518 | 518 |
| 519 void ThreadProxy::MainThreadHasStoppedFlingingOnImplThread() { | 519 void ThreadProxy::MainThreadHasStoppedFlingingOnImplThread() { |
| 520 DCHECK(IsImplThread()); | 520 DCHECK(IsImplThread()); |
| 521 if (input_handler_client_on_impl_thread_) | 521 layer_tree_host_impl_->MainThreadHasStoppedFlinging(); |
| 522 input_handler_client_on_impl_thread_->MainThreadHasStoppedFlinging(); | |
| 523 } | 522 } |
| 524 | 523 |
| 525 void ThreadProxy::Start() { | 524 void ThreadProxy::Start() { |
| 526 DCHECK(IsMainThread()); | 525 DCHECK(IsMainThread()); |
| 527 DCHECK(Proxy::ImplThread()); | 526 DCHECK(Proxy::ImplThread()); |
| 528 // Create LayerTreeHostImpl. | 527 // Create LayerTreeHostImpl. |
| 529 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 528 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 530 CompletionEvent completion; | 529 CompletionEvent completion; |
| 531 scoped_ptr<InputHandlerClient> input_handler_client = | |
| 532 layer_tree_host_->CreateInputHandlerClient(); | |
| 533 Proxy::ImplThread()->PostTask( | 530 Proxy::ImplThread()->PostTask( |
| 534 base::Bind(&ThreadProxy::InitializeImplOnImplThread, | 531 base::Bind(&ThreadProxy::InitializeImplOnImplThread, |
| 535 base::Unretained(this), | 532 base::Unretained(this), |
| 536 &completion, | 533 &completion)); |
| 537 input_handler_client.release())); | |
| 538 completion.Wait(); | 534 completion.Wait(); |
| 539 | 535 |
| 540 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr(); | 536 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr(); |
| 541 | 537 |
| 542 started_ = true; | 538 started_ = true; |
| 543 } | 539 } |
| 544 | 540 |
| 545 void ThreadProxy::Stop() { | 541 void ThreadProxy::Stop() { |
| 546 TRACE_EVENT0("cc", "ThreadProxy::Stop"); | 542 TRACE_EVENT0("cc", "ThreadProxy::Stop"); |
| 547 DCHECK(IsMainThread()); | 543 DCHECK(IsMainThread()); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 875 result.did_swap = false; | 871 result.did_swap = false; |
| 876 DCHECK(IsImplThread()); | 872 DCHECK(IsImplThread()); |
| 877 DCHECK(layer_tree_host_impl_.get()); | 873 DCHECK(layer_tree_host_impl_.get()); |
| 878 if (!layer_tree_host_impl_) | 874 if (!layer_tree_host_impl_) |
| 879 return result; | 875 return result; |
| 880 | 876 |
| 881 DCHECK(layer_tree_host_impl_->renderer()); | 877 DCHECK(layer_tree_host_impl_->renderer()); |
| 882 if (!layer_tree_host_impl_->renderer()) | 878 if (!layer_tree_host_impl_->renderer()) |
| 883 return result; | 879 return result; |
| 884 | 880 |
| 885 base::TimeTicks monotonic_time = | 881 base::TimeTicks monotonic_time = |
|
danakj
2013/05/01 19:20:43
nit: These temp vars could go away and just call C
| |
| 886 layer_tree_host_impl_->CurrentFrameTimeTicks(); | 882 layer_tree_host_impl_->CurrentFrameTimeTicks(); |
| 887 base::Time wall_clock_time = layer_tree_host_impl_->CurrentFrameTime(); | 883 base::Time wall_clock_time = layer_tree_host_impl_->CurrentFrameTime(); |
| 888 | 884 |
| 889 if (input_handler_client_on_impl_thread_) | |
| 890 input_handler_client_on_impl_thread_->Animate(monotonic_time); | |
| 891 | |
| 892 layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); | 885 layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); |
| 893 layer_tree_host_impl_->Animate(monotonic_time, wall_clock_time); | 886 layer_tree_host_impl_->Animate(monotonic_time, wall_clock_time); |
| 894 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(false); | 887 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(false); |
| 895 | 888 |
| 896 // This method is called on a forced draw, regardless of whether we are able | 889 // This method is called on a forced draw, regardless of whether we are able |
| 897 // to produce a frame, as the calling site on main thread is blocked until its | 890 // to produce a frame, as the calling site on main thread is blocked until its |
| 898 // request completes, and we signal completion here. If CanDraw() is false, we | 891 // request completes, and we signal completion here. If CanDraw() is false, we |
| 899 // will indicate success=false to the caller, but we must still signal | 892 // will indicate success=false to the caller, but we must still signal |
| 900 // completion to avoid deadlock. | 893 // completion to avoid deadlock. |
| 901 | 894 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1073 DCHECK(layer_tree_host_); | 1066 DCHECK(layer_tree_host_); |
| 1074 LayerTreeHost::RecreateResult result = | 1067 LayerTreeHost::RecreateResult result = |
| 1075 layer_tree_host_->RecreateOutputSurface(); | 1068 layer_tree_host_->RecreateOutputSurface(); |
| 1076 if (result == LayerTreeHost::RecreateFailedButTryAgain) | 1069 if (result == LayerTreeHost::RecreateFailedButTryAgain) |
| 1077 Proxy::MainThread()->PostTask( | 1070 Proxy::MainThread()->PostTask( |
| 1078 output_surface_recreation_callback_.callback()); | 1071 output_surface_recreation_callback_.callback()); |
| 1079 else if (result == LayerTreeHost::RecreateSucceeded) | 1072 else if (result == LayerTreeHost::RecreateSucceeded) |
| 1080 output_surface_recreation_callback_.Cancel(); | 1073 output_surface_recreation_callback_.Cancel(); |
| 1081 } | 1074 } |
| 1082 | 1075 |
| 1083 void ThreadProxy::InitializeImplOnImplThread( | 1076 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { |
| 1084 CompletionEvent* completion, | |
| 1085 InputHandlerClient* input_handler_client) { | |
| 1086 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); | 1077 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); |
| 1087 DCHECK(IsImplThread()); | 1078 DCHECK(IsImplThread()); |
| 1088 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); | 1079 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); |
| 1089 const base::TimeDelta display_refresh_interval = | 1080 const base::TimeDelta display_refresh_interval = |
| 1090 base::TimeDelta::FromMicroseconds( | 1081 base::TimeDelta::FromMicroseconds( |
| 1091 base::Time::kMicrosecondsPerSecond / | 1082 base::Time::kMicrosecondsPerSecond / |
| 1092 layer_tree_host_->settings().refresh_rate); | 1083 layer_tree_host_->settings().refresh_rate); |
| 1093 scoped_ptr<FrameRateController> frame_rate_controller; | 1084 scoped_ptr<FrameRateController> frame_rate_controller; |
| 1094 if (render_vsync_enabled_) { | 1085 if (render_vsync_enabled_) { |
| 1095 if (render_vsync_notification_enabled_) { | 1086 if (render_vsync_notification_enabled_) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1106 const LayerTreeSettings& settings = layer_tree_host_->settings(); | 1097 const LayerTreeSettings& settings = layer_tree_host_->settings(); |
| 1107 SchedulerSettings scheduler_settings; | 1098 SchedulerSettings scheduler_settings; |
| 1108 scheduler_settings.impl_side_painting = settings.impl_side_painting; | 1099 scheduler_settings.impl_side_painting = settings.impl_side_painting; |
| 1109 scheduler_settings.timeout_and_draw_when_animation_checkerboards = | 1100 scheduler_settings.timeout_and_draw_when_animation_checkerboards = |
| 1110 settings.timeout_and_draw_when_animation_checkerboards; | 1101 settings.timeout_and_draw_when_animation_checkerboards; |
| 1111 scheduler_on_impl_thread_ = Scheduler::Create(this, | 1102 scheduler_on_impl_thread_ = Scheduler::Create(this, |
| 1112 frame_rate_controller.Pass(), | 1103 frame_rate_controller.Pass(), |
| 1113 scheduler_settings); | 1104 scheduler_settings); |
| 1114 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); | 1105 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); |
| 1115 | 1106 |
| 1116 input_handler_client_on_impl_thread_.reset(input_handler_client); | |
| 1117 if (input_handler_client_on_impl_thread_) { | |
| 1118 input_handler_client_on_impl_thread_->BindToHandler( | |
| 1119 layer_tree_host_impl_.get()); | |
| 1120 } | |
| 1121 | |
| 1122 impl_thread_weak_ptr_ = weak_factory_on_impl_thread_.GetWeakPtr(); | 1107 impl_thread_weak_ptr_ = weak_factory_on_impl_thread_.GetWeakPtr(); |
| 1123 completion->Signal(); | 1108 completion->Signal(); |
| 1124 } | 1109 } |
| 1125 | 1110 |
| 1126 void ThreadProxy::InitializeOutputSurfaceOnImplThread( | 1111 void ThreadProxy::InitializeOutputSurfaceOnImplThread( |
| 1127 scoped_ptr<OutputSurface> output_surface) { | 1112 scoped_ptr<OutputSurface> output_surface) { |
| 1128 TRACE_EVENT0("cc", "ThreadProxy::InitializeContextOnImplThread"); | 1113 TRACE_EVENT0("cc", "ThreadProxy::InitializeContextOnImplThread"); |
| 1129 DCHECK(IsImplThread()); | 1114 DCHECK(IsImplThread()); |
| 1130 output_surface_before_initialization_on_impl_thread_ = output_surface.Pass(); | 1115 output_surface_before_initialization_on_impl_thread_ = output_surface.Pass(); |
| 1131 } | 1116 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1156 | 1141 |
| 1157 completion->Signal(); | 1142 completion->Signal(); |
| 1158 } | 1143 } |
| 1159 | 1144 |
| 1160 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) { | 1145 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) { |
| 1161 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread"); | 1146 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread"); |
| 1162 DCHECK(IsImplThread()); | 1147 DCHECK(IsImplThread()); |
| 1163 layer_tree_host_->DeleteContentsTexturesOnImplThread( | 1148 layer_tree_host_->DeleteContentsTexturesOnImplThread( |
| 1164 layer_tree_host_impl_->resource_provider()); | 1149 layer_tree_host_impl_->resource_provider()); |
| 1165 layer_tree_host_impl_->EnableVSyncNotification(false); | 1150 layer_tree_host_impl_->EnableVSyncNotification(false); |
| 1166 input_handler_client_on_impl_thread_.reset(); | |
| 1167 layer_tree_host_impl_.reset(); | 1151 layer_tree_host_impl_.reset(); |
| 1168 scheduler_on_impl_thread_.reset(); | 1152 scheduler_on_impl_thread_.reset(); |
| 1169 weak_factory_on_impl_thread_.InvalidateWeakPtrs(); | 1153 weak_factory_on_impl_thread_.InvalidateWeakPtrs(); |
| 1170 vsync_client_ = NULL; | 1154 vsync_client_ = NULL; |
| 1171 completion->Signal(); | 1155 completion->Signal(); |
| 1172 } | 1156 } |
| 1173 | 1157 |
| 1174 size_t ThreadProxy::MaxPartialTextureUpdates() const { | 1158 size_t ThreadProxy::MaxPartialTextureUpdates() const { |
| 1175 return ResourceUpdateController::MaxPartialTextureUpdates(); | 1159 return ResourceUpdateController::MaxPartialTextureUpdates(); |
| 1176 } | 1160 } |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1353 | 1337 |
| 1354 void ThreadProxy::DidReceiveLastInputEventForVSync( | 1338 void ThreadProxy::DidReceiveLastInputEventForVSync( |
| 1355 base::TimeTicks frame_time) { | 1339 base::TimeTicks frame_time) { |
| 1356 if (render_vsync_notification_enabled_) { | 1340 if (render_vsync_notification_enabled_) { |
| 1357 TRACE_EVENT0("cc", "ThreadProxy::DidReceiveLastInputEventForVSync"); | 1341 TRACE_EVENT0("cc", "ThreadProxy::DidReceiveLastInputEventForVSync"); |
| 1358 DidVSync(frame_time); | 1342 DidVSync(frame_time); |
| 1359 } | 1343 } |
| 1360 } | 1344 } |
| 1361 | 1345 |
| 1362 } // namespace cc | 1346 } // namespace cc |
| OLD | NEW |