| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 main_thread_only_vars_unsafe_(this, layer_tree_host->id()), | 64 main_thread_only_vars_unsafe_(this, layer_tree_host->id()), |
| 65 main_thread_or_blocked_vars_unsafe_(layer_tree_host), | 65 main_thread_or_blocked_vars_unsafe_(layer_tree_host), |
| 66 compositor_thread_vars_unsafe_( | 66 compositor_thread_vars_unsafe_( |
| 67 this, | 67 this, |
| 68 layer_tree_host->id(), | 68 layer_tree_host->id(), |
| 69 layer_tree_host->rendering_stats_instrumentation(), | 69 layer_tree_host->rendering_stats_instrumentation(), |
| 70 external_begin_frame_source.Pass()) { | 70 external_begin_frame_source.Pass()) { |
| 71 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); | 71 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); |
| 72 DCHECK(IsMainThread()); | 72 DCHECK(IsMainThread()); |
| 73 DCHECK(this->layer_tree_host()); | 73 DCHECK(this->layer_tree_host()); |
| 74 // TODO(khushalsagar): Move this to LayerTreeHost#InitializeThreaded once |
| 75 // ThreadProxy is split. LayerTreeHost creates the channel and passes it to |
| 76 // ProxyMain#SetChannel. |
| 77 SetChannel(ThreadedChannel::Create(this, main_task_runner, impl_task_runner)); |
| 74 } | 78 } |
| 75 | 79 |
| 76 ThreadProxy::MainThreadOnly::MainThreadOnly(ThreadProxy* proxy, | 80 ThreadProxy::MainThreadOnly::MainThreadOnly(ThreadProxy* proxy, |
| 77 int layer_tree_host_id) | 81 int layer_tree_host_id) |
| 78 : layer_tree_host_id(layer_tree_host_id), | 82 : layer_tree_host_id(layer_tree_host_id), |
| 79 max_requested_pipeline_stage(NO_PIPELINE_STAGE), | 83 max_requested_pipeline_stage(NO_PIPELINE_STAGE), |
| 80 current_pipeline_stage(NO_PIPELINE_STAGE), | 84 current_pipeline_stage(NO_PIPELINE_STAGE), |
| 81 final_pipeline_stage(NO_PIPELINE_STAGE), | 85 final_pipeline_stage(NO_PIPELINE_STAGE), |
| 82 started(false), | 86 started(false), |
| 83 prepare_tiles_pending(false), | 87 prepare_tiles_pending(false), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 120 } |
| 117 | 121 |
| 118 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {} | 122 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {} |
| 119 | 123 |
| 120 ThreadProxy::~ThreadProxy() { | 124 ThreadProxy::~ThreadProxy() { |
| 121 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); | 125 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); |
| 122 DCHECK(IsMainThread()); | 126 DCHECK(IsMainThread()); |
| 123 DCHECK(!main().started); | 127 DCHECK(!main().started); |
| 124 } | 128 } |
| 125 | 129 |
| 130 void ThreadProxy::SetChannel(scoped_ptr<ThreadedChannel> threaded_channel) { |
| 131 threaded_channel_ = threaded_channel.Pass(); |
| 132 main().channel_main = threaded_channel_.get(); |
| 133 } |
| 134 |
| 126 void ThreadProxy::FinishAllRendering() { | 135 void ThreadProxy::FinishAllRendering() { |
| 127 DCHECK(Proxy::IsMainThread()); | 136 DCHECK(Proxy::IsMainThread()); |
| 128 DCHECK(!main().defer_commits); | 137 DCHECK(!main().defer_commits); |
| 129 | 138 |
| 130 // Make sure all GL drawing is finished on the impl thread. | 139 // Make sure all GL drawing is finished on the impl thread. |
| 131 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 140 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 132 CompletionEvent completion; | 141 CompletionEvent completion; |
| 133 Proxy::ImplThreadTaskRunner()->PostTask( | 142 Proxy::ImplThreadTaskRunner()->PostTask( |
| 134 FROM_HERE, | 143 FROM_HERE, |
| 135 base::Bind(&ThreadProxy::FinishAllRenderingOnImplThread, | 144 base::Bind(&ThreadProxy::FinishAllRenderingOnImplThread, |
| 136 impl_thread_weak_ptr_, | 145 impl_thread_weak_ptr_, |
| 137 &completion)); | 146 &completion)); |
| 138 completion.Wait(); | 147 completion.Wait(); |
| 139 } | 148 } |
| 140 | 149 |
| 141 bool ThreadProxy::IsStarted() const { | 150 bool ThreadProxy::IsStarted() const { |
| 142 DCHECK(Proxy::IsMainThread()); | 151 DCHECK(Proxy::IsMainThread()); |
| 143 return main().started; | 152 return main().started; |
| 144 } | 153 } |
| 145 | 154 |
| 146 bool ThreadProxy::CommitToActiveTree() const { | 155 bool ThreadProxy::CommitToActiveTree() const { |
| 147 // With ThreadProxy, we use a pending tree and activate it once it's ready to | 156 // With ThreadProxy, we use a pending tree and activate it once it's ready to |
| 148 // draw to allow input to modify the active tree and draw during raster. | 157 // draw to allow input to modify the active tree and draw during raster. |
| 149 return false; | 158 return false; |
| 150 } | 159 } |
| 151 | 160 |
| 152 void ThreadProxy::SetLayerTreeHostClientReady() { | 161 void ThreadProxy::SetLayerTreeHostClientReady() { |
| 153 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReady"); | 162 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReady"); |
| 154 Proxy::ImplThreadTaskRunner()->PostTask( | 163 main().channel_main->SetLayerTreeHostClientReadyOnImpl(); |
| 155 FROM_HERE, | |
| 156 base::Bind(&ThreadProxy::SetLayerTreeHostClientReadyOnImplThread, | |
| 157 impl_thread_weak_ptr_)); | |
| 158 } | 164 } |
| 159 | 165 |
| 160 void ThreadProxy::SetLayerTreeHostClientReadyOnImplThread() { | 166 void ThreadProxy::SetLayerTreeHostClientReadyOnImpl() { |
| 161 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReadyOnImplThread"); | 167 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReadyOnImplThread"); |
| 162 impl().scheduler->SetCanStart(); | 168 impl().scheduler->SetCanStart(); |
| 163 } | 169 } |
| 164 | 170 |
| 165 void ThreadProxy::SetVisible(bool visible) { | 171 void ThreadProxy::SetVisible(bool visible) { |
| 166 TRACE_EVENT1("cc", "ThreadProxy::SetVisible", "visible", visible); | 172 TRACE_EVENT1("cc", "ThreadProxy::SetVisible", "visible", visible); |
| 167 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 173 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 168 | 174 |
| 169 CompletionEvent completion; | 175 CompletionEvent completion; |
| 170 Proxy::ImplThreadTaskRunner()->PostTask( | 176 Proxy::ImplThreadTaskRunner()->PostTask( |
| 171 FROM_HERE, | 177 FROM_HERE, |
| 172 base::Bind(&ThreadProxy::SetVisibleOnImplThread, | 178 base::Bind(&ThreadProxy::SetVisibleOnImplThread, |
| 173 impl_thread_weak_ptr_, | 179 impl_thread_weak_ptr_, |
| 174 &completion, | 180 &completion, |
| 175 visible)); | 181 visible)); |
| 176 completion.Wait(); | 182 completion.Wait(); |
| 177 } | 183 } |
| 178 | 184 |
| 179 void ThreadProxy::SetVisibleOnImplThread(CompletionEvent* completion, | 185 void ThreadProxy::SetVisibleOnImplThread(CompletionEvent* completion, |
| 180 bool visible) { | 186 bool visible) { |
| 181 TRACE_EVENT1("cc", "ThreadProxy::SetVisibleOnImplThread", "visible", visible); | 187 TRACE_EVENT1("cc", "ThreadProxy::SetVisibleOnImplThread", "visible", visible); |
| 182 impl().layer_tree_host_impl->SetVisible(visible); | 188 impl().layer_tree_host_impl->SetVisible(visible); |
| 183 impl().scheduler->SetVisible(visible); | 189 impl().scheduler->SetVisible(visible); |
| 184 completion->Signal(); | 190 completion->Signal(); |
| 185 } | 191 } |
| 186 | 192 |
| 187 void ThreadProxy::SetThrottleFrameProduction(bool throttle) { | 193 void ThreadProxy::SetThrottleFrameProduction(bool throttle) { |
| 188 TRACE_EVENT1("cc", "ThreadProxy::SetThrottleFrameProduction", "throttle", | 194 TRACE_EVENT1("cc", "ThreadProxy::SetThrottleFrameProduction", "throttle", |
| 189 throttle); | 195 throttle); |
| 190 Proxy::ImplThreadTaskRunner()->PostTask( | 196 main().channel_main->SetThrottleFrameProductionOnImpl(throttle); |
| 191 FROM_HERE, | |
| 192 base::Bind(&ThreadProxy::SetThrottleFrameProductionOnImplThread, | |
| 193 impl_thread_weak_ptr_, throttle)); | |
| 194 } | 197 } |
| 195 | 198 |
| 196 void ThreadProxy::SetThrottleFrameProductionOnImplThread(bool throttle) { | 199 void ThreadProxy::SetThrottleFrameProductionOnImpl(bool throttle) { |
| 197 TRACE_EVENT1("cc", "ThreadProxy::SetThrottleFrameProductionOnImplThread", | 200 TRACE_EVENT1("cc", "ThreadProxy::SetThrottleFrameProductionOnImplThread", |
| 198 "throttle", throttle); | 201 "throttle", throttle); |
| 199 impl().scheduler->SetThrottleFrameProduction(throttle); | 202 impl().scheduler->SetThrottleFrameProduction(throttle); |
| 200 } | 203 } |
| 201 | 204 |
| 202 void ThreadProxy::DidLoseOutputSurface() { | 205 void ThreadProxy::DidLoseOutputSurface() { |
| 203 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurface"); | 206 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurface"); |
| 204 DCHECK(IsMainThread()); | 207 DCHECK(IsMainThread()); |
| 205 layer_tree_host()->DidLoseOutputSurface(); | 208 layer_tree_host()->DidLoseOutputSurface(); |
| 206 } | 209 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 351 |
| 349 void ThreadProxy::DidSwapBuffersOnImplThread() { | 352 void ThreadProxy::DidSwapBuffersOnImplThread() { |
| 350 impl().scheduler->DidSwapBuffers(); | 353 impl().scheduler->DidSwapBuffers(); |
| 351 } | 354 } |
| 352 | 355 |
| 353 void ThreadProxy::DidSwapBuffersCompleteOnImplThread() { | 356 void ThreadProxy::DidSwapBuffersCompleteOnImplThread() { |
| 354 TRACE_EVENT0("cc,benchmark", | 357 TRACE_EVENT0("cc,benchmark", |
| 355 "ThreadProxy::DidSwapBuffersCompleteOnImplThread"); | 358 "ThreadProxy::DidSwapBuffersCompleteOnImplThread"); |
| 356 DCHECK(IsImplThread()); | 359 DCHECK(IsImplThread()); |
| 357 impl().scheduler->DidSwapBuffersComplete(); | 360 impl().scheduler->DidSwapBuffersComplete(); |
| 358 Proxy::MainThreadTaskRunner()->PostTask( | 361 impl().channel_impl->DidCompleteSwapBuffers(); |
| 359 FROM_HERE, | |
| 360 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); | |
| 361 } | 362 } |
| 362 | 363 |
| 363 void ThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { | 364 void ThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { |
| 364 impl().layer_tree_host_impl->WillBeginImplFrame(args); | 365 impl().layer_tree_host_impl->WillBeginImplFrame(args); |
| 365 if (impl().last_processed_begin_main_frame_args.IsValid()) { | 366 if (impl().last_processed_begin_main_frame_args.IsValid()) { |
| 366 // Last processed begin main frame args records the frame args that we sent | 367 // Last processed begin main frame args records the frame args that we sent |
| 367 // to the main thread for the last frame that we've processed. If that is | 368 // to the main thread for the last frame that we've processed. If that is |
| 368 // set, that means the current frame is one past the frame in which we've | 369 // set, that means the current frame is one past the frame in which we've |
| 369 // finished the processing. | 370 // finished the processing. |
| 370 impl().layer_tree_host_impl->RecordMainFrameTiming( | 371 impl().layer_tree_host_impl->RecordMainFrameTiming( |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 | 1010 |
| 1010 void ThreadProxy::SetAnimationEvents(scoped_ptr<AnimationEventsVector> events) { | 1011 void ThreadProxy::SetAnimationEvents(scoped_ptr<AnimationEventsVector> events) { |
| 1011 TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents"); | 1012 TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents"); |
| 1012 DCHECK(IsMainThread()); | 1013 DCHECK(IsMainThread()); |
| 1013 layer_tree_host()->SetAnimationEvents(events.Pass()); | 1014 layer_tree_host()->SetAnimationEvents(events.Pass()); |
| 1014 } | 1015 } |
| 1015 | 1016 |
| 1016 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { | 1017 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { |
| 1017 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); | 1018 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); |
| 1018 DCHECK(IsImplThread()); | 1019 DCHECK(IsImplThread()); |
| 1020 |
| 1021 // TODO(khushalsagar): ThreadedChannel will create ProxyImpl here and pass a |
| 1022 // reference to itself. |
| 1023 impl().channel_impl = threaded_channel_.get(); |
| 1024 |
| 1019 impl().layer_tree_host_impl = | 1025 impl().layer_tree_host_impl = |
| 1020 layer_tree_host()->CreateLayerTreeHostImpl(this); | 1026 layer_tree_host()->CreateLayerTreeHostImpl(this); |
| 1021 | 1027 |
| 1022 SchedulerSettings scheduler_settings( | 1028 SchedulerSettings scheduler_settings( |
| 1023 layer_tree_host()->settings().ToSchedulerSettings()); | 1029 layer_tree_host()->settings().ToSchedulerSettings()); |
| 1024 | 1030 |
| 1025 scoped_ptr<CompositorTimingHistory> compositor_timing_history( | 1031 scoped_ptr<CompositorTimingHistory> compositor_timing_history( |
| 1026 new CompositorTimingHistory(CompositorTimingHistory::RENDERER_UMA, | 1032 new CompositorTimingHistory(CompositorTimingHistory::RENDERER_UMA, |
| 1027 impl().rendering_stats_instrumentation)); | 1033 impl().rendering_stats_instrumentation)); |
| 1028 | 1034 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 } | 1248 } |
| 1243 | 1249 |
| 1244 void ThreadProxy::PostFrameTimingEvents( | 1250 void ThreadProxy::PostFrameTimingEvents( |
| 1245 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | 1251 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
| 1246 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { | 1252 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
| 1247 DCHECK(IsMainThread()); | 1253 DCHECK(IsMainThread()); |
| 1248 layer_tree_host()->RecordFrameTimingEvents(composite_events.Pass(), | 1254 layer_tree_host()->RecordFrameTimingEvents(composite_events.Pass(), |
| 1249 main_frame_events.Pass()); | 1255 main_frame_events.Pass()); |
| 1250 } | 1256 } |
| 1251 | 1257 |
| 1258 base::WeakPtr<ProxyMain> ThreadProxy::GetMainWeakPtr() { |
| 1259 return main_thread_weak_ptr_; |
| 1260 } |
| 1261 |
| 1262 base::WeakPtr<ProxyImpl> ThreadProxy::GetImplWeakPtr() { |
| 1263 return impl_thread_weak_ptr_; |
| 1264 } |
| 1265 |
| 1252 } // namespace cc | 1266 } // namespace cc |
| OLD | NEW |