| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/proxy_main.h" | 5 #include "cc/trees/proxy_main.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "base/trace_event/trace_event_argument.h" | 11 #include "base/trace_event/trace_event_argument.h" |
| 12 #include "base/trace_event/trace_event_synthetic_delay.h" | 12 #include "base/trace_event/trace_event_synthetic_delay.h" |
| 13 #include "cc/base/completion_event.h" |
| 13 #include "cc/debug/benchmark_instrumentation.h" | 14 #include "cc/debug/benchmark_instrumentation.h" |
| 14 #include "cc/debug/devtools_instrumentation.h" | 15 #include "cc/debug/devtools_instrumentation.h" |
| 15 #include "cc/output/compositor_frame_sink.h" | 16 #include "cc/output/compositor_frame_sink.h" |
| 16 #include "cc/output/swap_promise.h" | 17 #include "cc/output/swap_promise.h" |
| 17 #include "cc/resources/ui_resource_manager.h" | 18 #include "cc/resources/ui_resource_manager.h" |
| 18 #include "cc/trees/blocking_task_runner.h" | 19 #include "cc/trees/blocking_task_runner.h" |
| 19 #include "cc/trees/layer_tree_host_in_process.h" | 20 #include "cc/trees/layer_tree_host_in_process.h" |
| 20 #include "cc/trees/mutator_host.h" | 21 #include "cc/trees/mutator_host.h" |
| 22 #include "cc/trees/proxy_impl.h" |
| 21 #include "cc/trees/scoped_abort_remaining_swap_promises.h" | 23 #include "cc/trees/scoped_abort_remaining_swap_promises.h" |
| 22 #include "cc/trees/threaded_channel.h" | |
| 23 | 24 |
| 24 namespace cc { | 25 namespace cc { |
| 25 | 26 |
| 26 std::unique_ptr<ProxyMain> ProxyMain::CreateThreaded( | |
| 27 LayerTreeHostInProcess* layer_tree_host, | |
| 28 TaskRunnerProvider* task_runner_provider) { | |
| 29 std::unique_ptr<ProxyMain> proxy_main( | |
| 30 new ProxyMain(layer_tree_host, task_runner_provider)); | |
| 31 proxy_main->SetChannel( | |
| 32 ThreadedChannel::Create(proxy_main.get(), task_runner_provider)); | |
| 33 return proxy_main; | |
| 34 } | |
| 35 | |
| 36 ProxyMain::ProxyMain(LayerTreeHostInProcess* layer_tree_host, | 27 ProxyMain::ProxyMain(LayerTreeHostInProcess* layer_tree_host, |
| 37 TaskRunnerProvider* task_runner_provider) | 28 TaskRunnerProvider* task_runner_provider) |
| 38 : layer_tree_host_(layer_tree_host), | 29 : layer_tree_host_(layer_tree_host), |
| 39 task_runner_provider_(task_runner_provider), | 30 task_runner_provider_(task_runner_provider), |
| 40 layer_tree_host_id_(layer_tree_host->GetId()), | 31 layer_tree_host_id_(layer_tree_host->GetId()), |
| 41 max_requested_pipeline_stage_(NO_PIPELINE_STAGE), | 32 max_requested_pipeline_stage_(NO_PIPELINE_STAGE), |
| 42 current_pipeline_stage_(NO_PIPELINE_STAGE), | 33 current_pipeline_stage_(NO_PIPELINE_STAGE), |
| 43 final_pipeline_stage_(NO_PIPELINE_STAGE), | 34 final_pipeline_stage_(NO_PIPELINE_STAGE), |
| 44 commit_waits_for_activation_(false), | 35 commit_waits_for_activation_(false), |
| 45 started_(false), | 36 started_(false), |
| 46 defer_commits_(false) { | 37 defer_commits_(false), |
| 38 weak_factory_(this) { |
| 47 TRACE_EVENT0("cc", "ProxyMain::ProxyMain"); | 39 TRACE_EVENT0("cc", "ProxyMain::ProxyMain"); |
| 48 DCHECK(task_runner_provider_); | 40 DCHECK(task_runner_provider_); |
| 49 DCHECK(IsMainThread()); | 41 DCHECK(IsMainThread()); |
| 50 } | 42 } |
| 51 | 43 |
| 52 ProxyMain::~ProxyMain() { | 44 ProxyMain::~ProxyMain() { |
| 53 TRACE_EVENT0("cc", "ProxyMain::~ProxyMain"); | 45 TRACE_EVENT0("cc", "ProxyMain::~ProxyMain"); |
| 54 DCHECK(IsMainThread()); | 46 DCHECK(IsMainThread()); |
| 55 DCHECK(!started_); | 47 DCHECK(!started_); |
| 56 } | 48 } |
| 57 | 49 |
| 58 void ProxyMain::SetChannel(std::unique_ptr<ChannelMain> channel_main) { | 50 void ProxyMain::InitializeOnImplThread(CompletionEvent* completion_event) { |
| 59 DCHECK(!channel_main_); | 51 DCHECK(task_runner_provider_->IsImplThread()); |
| 60 channel_main_ = std::move(channel_main); | 52 DCHECK(!proxy_impl_); |
| 53 proxy_impl_ = base::MakeUnique<ProxyImpl>( |
| 54 weak_factory_.GetWeakPtr(), layer_tree_host_, task_runner_provider_); |
| 55 completion_event->Signal(); |
| 56 } |
| 57 |
| 58 void ProxyMain::DestroyProxyImplOnImplThread( |
| 59 CompletionEvent* completion_event) { |
| 60 DCHECK(task_runner_provider_->IsImplThread()); |
| 61 proxy_impl_.reset(); |
| 62 completion_event->Signal(); |
| 61 } | 63 } |
| 62 | 64 |
| 63 void ProxyMain::DidReceiveCompositorFrameAck() { | 65 void ProxyMain::DidReceiveCompositorFrameAck() { |
| 64 DCHECK(IsMainThread()); | 66 DCHECK(IsMainThread()); |
| 65 layer_tree_host_->DidReceiveCompositorFrameAck(); | 67 layer_tree_host_->DidReceiveCompositorFrameAck(); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void ProxyMain::BeginMainFrameNotExpectedSoon() { | 70 void ProxyMain::BeginMainFrameNotExpectedSoon() { |
| 69 TRACE_EVENT0("cc", "ProxyMain::BeginMainFrameNotExpectedSoon"); | 71 TRACE_EVENT0("cc", "ProxyMain::BeginMainFrameNotExpectedSoon"); |
| 70 DCHECK(IsMainThread()); | 72 DCHECK(IsMainThread()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 base::TimeTicks begin_main_frame_start_time = base::TimeTicks::Now(); | 120 base::TimeTicks begin_main_frame_start_time = base::TimeTicks::Now(); |
| 119 | 121 |
| 120 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame"); | 122 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame"); |
| 121 DCHECK(IsMainThread()); | 123 DCHECK(IsMainThread()); |
| 122 DCHECK_EQ(NO_PIPELINE_STAGE, current_pipeline_stage_); | 124 DCHECK_EQ(NO_PIPELINE_STAGE, current_pipeline_stage_); |
| 123 | 125 |
| 124 if (defer_commits_) { | 126 if (defer_commits_) { |
| 125 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit", | 127 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit", |
| 126 TRACE_EVENT_SCOPE_THREAD); | 128 TRACE_EVENT_SCOPE_THREAD); |
| 127 std::vector<std::unique_ptr<SwapPromise>> empty_swap_promises; | 129 std::vector<std::unique_ptr<SwapPromise>> empty_swap_promises; |
| 128 channel_main_->BeginMainFrameAbortedOnImpl( | 130 ImplThreadTaskRunner()->PostTask( |
| 129 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT, | 131 FROM_HERE, base::Bind(&ProxyImpl::BeginMainFrameAbortedOnImpl, |
| 130 begin_main_frame_start_time, std::move(empty_swap_promises)); | 132 base::Unretained(proxy_impl_.get()), |
| 133 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT, |
| 134 begin_main_frame_start_time, |
| 135 base::Passed(&empty_swap_promises))); |
| 131 return; | 136 return; |
| 132 } | 137 } |
| 133 | 138 |
| 134 // If the commit finishes, LayerTreeHost will transfer its swap promises to | 139 // If the commit finishes, LayerTreeHost will transfer its swap promises to |
| 135 // LayerTreeImpl. The destructor of ScopedSwapPromiseChecker aborts the | 140 // LayerTreeImpl. The destructor of ScopedSwapPromiseChecker aborts the |
| 136 // remaining swap promises. | 141 // remaining swap promises. |
| 137 ScopedAbortRemainingSwapPromises swap_promise_checker( | 142 ScopedAbortRemainingSwapPromises swap_promise_checker( |
| 138 layer_tree_host_->GetSwapPromiseManager()); | 143 layer_tree_host_->GetSwapPromiseManager()); |
| 139 | 144 |
| 140 final_pipeline_stage_ = max_requested_pipeline_stage_; | 145 final_pipeline_stage_ = max_requested_pipeline_stage_; |
| 141 max_requested_pipeline_stage_ = NO_PIPELINE_STAGE; | 146 max_requested_pipeline_stage_ = NO_PIPELINE_STAGE; |
| 142 | 147 |
| 143 if (!layer_tree_host_->IsVisible()) { | 148 if (!layer_tree_host_->IsVisible()) { |
| 144 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); | 149 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); |
| 145 std::vector<std::unique_ptr<SwapPromise>> empty_swap_promises; | 150 std::vector<std::unique_ptr<SwapPromise>> empty_swap_promises; |
| 146 channel_main_->BeginMainFrameAbortedOnImpl( | 151 ImplThreadTaskRunner()->PostTask( |
| 147 CommitEarlyOutReason::ABORTED_NOT_VISIBLE, begin_main_frame_start_time, | 152 FROM_HERE, base::Bind(&ProxyImpl::BeginMainFrameAbortedOnImpl, |
| 148 std::move(empty_swap_promises)); | 153 base::Unretained(proxy_impl_.get()), |
| 154 CommitEarlyOutReason::ABORTED_NOT_VISIBLE, |
| 155 begin_main_frame_start_time, |
| 156 base::Passed(&empty_swap_promises))); |
| 149 return; | 157 return; |
| 150 } | 158 } |
| 151 | 159 |
| 152 current_pipeline_stage_ = ANIMATE_PIPELINE_STAGE; | 160 current_pipeline_stage_ = ANIMATE_PIPELINE_STAGE; |
| 153 | 161 |
| 154 layer_tree_host_->ApplyScrollAndScale( | 162 layer_tree_host_->ApplyScrollAndScale( |
| 155 begin_main_frame_state->scroll_info.get()); | 163 begin_main_frame_state->scroll_info.get()); |
| 156 | 164 |
| 157 if (begin_main_frame_state->begin_frame_callbacks) { | 165 if (begin_main_frame_state->begin_frame_callbacks) { |
| 158 for (auto& callback : *begin_main_frame_state->begin_frame_callbacks) | 166 for (auto& callback : *begin_main_frame_state->begin_frame_callbacks) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 181 final_pipeline_stage_ >= UPDATE_LAYERS_PIPELINE_STAGE; | 189 final_pipeline_stage_ >= UPDATE_LAYERS_PIPELINE_STAGE; |
| 182 bool updated = should_update_layers && layer_tree_host_->UpdateLayers(); | 190 bool updated = should_update_layers && layer_tree_host_->UpdateLayers(); |
| 183 | 191 |
| 184 layer_tree_host_->WillCommit(); | 192 layer_tree_host_->WillCommit(); |
| 185 devtools_instrumentation::ScopedCommitTrace commit_task( | 193 devtools_instrumentation::ScopedCommitTrace commit_task( |
| 186 layer_tree_host_->GetId()); | 194 layer_tree_host_->GetId()); |
| 187 | 195 |
| 188 current_pipeline_stage_ = COMMIT_PIPELINE_STAGE; | 196 current_pipeline_stage_ = COMMIT_PIPELINE_STAGE; |
| 189 if (!updated && can_cancel_this_commit) { | 197 if (!updated && can_cancel_this_commit) { |
| 190 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoUpdates", TRACE_EVENT_SCOPE_THREAD); | 198 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoUpdates", TRACE_EVENT_SCOPE_THREAD); |
| 191 channel_main_->BeginMainFrameAbortedOnImpl( | 199 std::vector<std::unique_ptr<SwapPromise>> swap_promises = |
| 192 CommitEarlyOutReason::FINISHED_NO_UPDATES, begin_main_frame_start_time, | 200 layer_tree_host_->GetSwapPromiseManager()->TakeSwapPromises(); |
| 193 layer_tree_host_->GetSwapPromiseManager()->TakeSwapPromises()); | 201 ImplThreadTaskRunner()->PostTask( |
| 202 FROM_HERE, |
| 203 base::Bind(&ProxyImpl::BeginMainFrameAbortedOnImpl, |
| 204 base::Unretained(proxy_impl_.get()), |
| 205 CommitEarlyOutReason::FINISHED_NO_UPDATES, |
| 206 begin_main_frame_start_time, base::Passed(&swap_promises))); |
| 194 | 207 |
| 195 // Although the commit is internally aborted, this is because it has been | 208 // Although the commit is internally aborted, this is because it has been |
| 196 // detected to be a no-op. From the perspective of an embedder, this commit | 209 // detected to be a no-op. From the perspective of an embedder, this commit |
| 197 // went through, and input should no longer be throttled, etc. | 210 // went through, and input should no longer be throttled, etc. |
| 198 current_pipeline_stage_ = NO_PIPELINE_STAGE; | 211 current_pipeline_stage_ = NO_PIPELINE_STAGE; |
| 199 layer_tree_host_->CommitComplete(); | 212 layer_tree_host_->CommitComplete(); |
| 200 layer_tree_host_->DidBeginMainFrame(); | 213 layer_tree_host_->DidBeginMainFrame(); |
| 201 return; | 214 return; |
| 202 } | 215 } |
| 203 | 216 |
| 204 // Notify the impl thread that the main thread is ready to commit. This will | 217 // Notify the impl thread that the main thread is ready to commit. This will |
| 205 // begin the commit process, which is blocking from the main thread's | 218 // begin the commit process, which is blocking from the main thread's |
| 206 // point of view, but asynchronously performed on the impl thread, | 219 // point of view, but asynchronously performed on the impl thread, |
| 207 // coordinated by the Scheduler. | 220 // coordinated by the Scheduler. |
| 208 { | 221 { |
| 209 TRACE_EVENT0("cc", "ProxyMain::BeginMainFrame::commit"); | 222 TRACE_EVENT0("cc", "ProxyMain::BeginMainFrame::commit"); |
| 210 | 223 |
| 211 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); | 224 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 212 | 225 |
| 213 // This CapturePostTasks should be destroyed before CommitComplete() is | 226 // This CapturePostTasks should be destroyed before CommitComplete() is |
| 214 // called since that goes out to the embedder, and we want the embedder | 227 // called since that goes out to the embedder, and we want the embedder |
| 215 // to receive its callbacks before that. | 228 // to receive its callbacks before that. |
| 216 BlockingTaskRunner::CapturePostTasks blocked( | 229 BlockingTaskRunner::CapturePostTasks blocked( |
| 217 task_runner_provider_->blocking_main_thread_task_runner()); | 230 task_runner_provider_->blocking_main_thread_task_runner()); |
| 218 | 231 |
| 219 bool hold_commit_for_activation = commit_waits_for_activation_; | 232 bool hold_commit_for_activation = commit_waits_for_activation_; |
| 220 commit_waits_for_activation_ = false; | 233 commit_waits_for_activation_ = false; |
| 221 CompletionEvent completion; | 234 CompletionEvent completion; |
| 222 channel_main_->NotifyReadyToCommitOnImpl(&completion, layer_tree_host_, | 235 ImplThreadTaskRunner()->PostTask( |
| 223 begin_main_frame_start_time, | 236 FROM_HERE, base::Bind(&ProxyImpl::NotifyReadyToCommitOnImpl, |
| 224 hold_commit_for_activation); | 237 base::Unretained(proxy_impl_.get()), &completion, |
| 238 layer_tree_host_, begin_main_frame_start_time, |
| 239 hold_commit_for_activation)); |
| 225 completion.Wait(); | 240 completion.Wait(); |
| 226 } | 241 } |
| 227 | 242 |
| 228 current_pipeline_stage_ = NO_PIPELINE_STAGE; | 243 current_pipeline_stage_ = NO_PIPELINE_STAGE; |
| 229 layer_tree_host_->CommitComplete(); | 244 layer_tree_host_->CommitComplete(); |
| 230 layer_tree_host_->DidBeginMainFrame(); | 245 layer_tree_host_->DidBeginMainFrame(); |
| 231 } | 246 } |
| 232 | 247 |
| 233 bool ProxyMain::IsStarted() const { | 248 bool ProxyMain::IsStarted() const { |
| 234 DCHECK(IsMainThread()); | 249 DCHECK(IsMainThread()); |
| 235 return started_; | 250 return started_; |
| 236 } | 251 } |
| 237 | 252 |
| 238 bool ProxyMain::CommitToActiveTree() const { | 253 bool ProxyMain::CommitToActiveTree() const { |
| 239 // With ProxyMain, we use a pending tree and activate it once it's ready to | 254 // With ProxyMain, we use a pending tree and activate it once it's ready to |
| 240 // draw to allow input to modify the active tree and draw during raster. | 255 // draw to allow input to modify the active tree and draw during raster. |
| 241 return false; | 256 return false; |
| 242 } | 257 } |
| 243 | 258 |
| 244 void ProxyMain::SetCompositorFrameSink( | 259 void ProxyMain::SetCompositorFrameSink( |
| 245 CompositorFrameSink* compositor_frame_sink) { | 260 CompositorFrameSink* compositor_frame_sink) { |
| 246 channel_main_->InitializeCompositorFrameSinkOnImpl(compositor_frame_sink); | 261 ImplThreadTaskRunner()->PostTask( |
| 262 FROM_HERE, |
| 263 base::Bind(&ProxyImpl::InitializeCompositorFrameSinkOnImpl, |
| 264 base::Unretained(proxy_impl_.get()), compositor_frame_sink)); |
| 247 } | 265 } |
| 248 | 266 |
| 249 void ProxyMain::SetVisible(bool visible) { | 267 void ProxyMain::SetVisible(bool visible) { |
| 250 TRACE_EVENT1("cc", "ProxyMain::SetVisible", "visible", visible); | 268 TRACE_EVENT1("cc", "ProxyMain::SetVisible", "visible", visible); |
| 251 channel_main_->SetVisibleOnImpl(visible); | 269 ImplThreadTaskRunner()->PostTask( |
| 270 FROM_HERE, base::Bind(&ProxyImpl::SetVisibleOnImpl, |
| 271 base::Unretained(proxy_impl_.get()), visible)); |
| 252 } | 272 } |
| 253 | 273 |
| 254 void ProxyMain::SetNeedsAnimate() { | 274 void ProxyMain::SetNeedsAnimate() { |
| 255 DCHECK(IsMainThread()); | 275 DCHECK(IsMainThread()); |
| 256 if (SendCommitRequestToImplThreadIfNeeded(ANIMATE_PIPELINE_STAGE)) { | 276 if (SendCommitRequestToImplThreadIfNeeded(ANIMATE_PIPELINE_STAGE)) { |
| 257 TRACE_EVENT_INSTANT0("cc", "ProxyMain::SetNeedsAnimate", | 277 TRACE_EVENT_INSTANT0("cc", "ProxyMain::SetNeedsAnimate", |
| 258 TRACE_EVENT_SCOPE_THREAD); | 278 TRACE_EVENT_SCOPE_THREAD); |
| 259 } | 279 } |
| 260 } | 280 } |
| 261 | 281 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 285 } | 305 } |
| 286 if (SendCommitRequestToImplThreadIfNeeded(COMMIT_PIPELINE_STAGE)) { | 306 if (SendCommitRequestToImplThreadIfNeeded(COMMIT_PIPELINE_STAGE)) { |
| 287 TRACE_EVENT_INSTANT0("cc", "ProxyMain::SetNeedsCommit", | 307 TRACE_EVENT_INSTANT0("cc", "ProxyMain::SetNeedsCommit", |
| 288 TRACE_EVENT_SCOPE_THREAD); | 308 TRACE_EVENT_SCOPE_THREAD); |
| 289 } | 309 } |
| 290 } | 310 } |
| 291 | 311 |
| 292 void ProxyMain::SetNeedsRedraw(const gfx::Rect& damage_rect) { | 312 void ProxyMain::SetNeedsRedraw(const gfx::Rect& damage_rect) { |
| 293 TRACE_EVENT0("cc", "ProxyMain::SetNeedsRedraw"); | 313 TRACE_EVENT0("cc", "ProxyMain::SetNeedsRedraw"); |
| 294 DCHECK(IsMainThread()); | 314 DCHECK(IsMainThread()); |
| 295 channel_main_->SetNeedsRedrawOnImpl(damage_rect); | 315 ImplThreadTaskRunner()->PostTask( |
| 316 FROM_HERE, base::Bind(&ProxyImpl::SetNeedsRedrawOnImpl, |
| 317 base::Unretained(proxy_impl_.get()), damage_rect)); |
| 296 } | 318 } |
| 297 | 319 |
| 298 void ProxyMain::SetNextCommitWaitsForActivation() { | 320 void ProxyMain::SetNextCommitWaitsForActivation() { |
| 299 DCHECK(IsMainThread()); | 321 DCHECK(IsMainThread()); |
| 300 commit_waits_for_activation_ = true; | 322 commit_waits_for_activation_ = true; |
| 301 } | 323 } |
| 302 | 324 |
| 303 void ProxyMain::NotifyInputThrottledUntilCommit() { | 325 void ProxyMain::NotifyInputThrottledUntilCommit() { |
| 304 DCHECK(IsMainThread()); | 326 DCHECK(IsMainThread()); |
| 305 channel_main_->SetInputThrottledUntilCommitOnImpl(true); | 327 ImplThreadTaskRunner()->PostTask( |
| 328 FROM_HERE, base::Bind(&ProxyImpl::SetInputThrottledUntilCommitOnImpl, |
| 329 base::Unretained(proxy_impl_.get()), true)); |
| 306 } | 330 } |
| 307 | 331 |
| 308 void ProxyMain::SetDeferCommits(bool defer_commits) { | 332 void ProxyMain::SetDeferCommits(bool defer_commits) { |
| 309 DCHECK(IsMainThread()); | 333 DCHECK(IsMainThread()); |
| 310 if (defer_commits_ == defer_commits) | 334 if (defer_commits_ == defer_commits) |
| 311 return; | 335 return; |
| 312 | 336 |
| 313 defer_commits_ = defer_commits; | 337 defer_commits_ = defer_commits; |
| 314 if (defer_commits_) | 338 if (defer_commits_) |
| 315 TRACE_EVENT_ASYNC_BEGIN0("cc", "ProxyMain::SetDeferCommits", this); | 339 TRACE_EVENT_ASYNC_BEGIN0("cc", "ProxyMain::SetDeferCommits", this); |
| 316 else | 340 else |
| 317 TRACE_EVENT_ASYNC_END0("cc", "ProxyMain::SetDeferCommits", this); | 341 TRACE_EVENT_ASYNC_END0("cc", "ProxyMain::SetDeferCommits", this); |
| 318 | 342 |
| 319 channel_main_->SetDeferCommitsOnImpl(defer_commits); | 343 ImplThreadTaskRunner()->PostTask( |
| 344 FROM_HERE, |
| 345 base::Bind(&ProxyImpl::SetDeferCommitsOnImpl, |
| 346 base::Unretained(proxy_impl_.get()), defer_commits)); |
| 320 } | 347 } |
| 321 | 348 |
| 322 bool ProxyMain::CommitRequested() const { | 349 bool ProxyMain::CommitRequested() const { |
| 323 DCHECK(IsMainThread()); | 350 DCHECK(IsMainThread()); |
| 324 // TODO(skyostil): Split this into something like CommitRequested() and | 351 // TODO(skyostil): Split this into something like CommitRequested() and |
| 325 // CommitInProgress(). | 352 // CommitInProgress(). |
| 326 return current_pipeline_stage_ != NO_PIPELINE_STAGE || | 353 return current_pipeline_stage_ != NO_PIPELINE_STAGE || |
| 327 max_requested_pipeline_stage_ >= COMMIT_PIPELINE_STAGE; | 354 max_requested_pipeline_stage_ >= COMMIT_PIPELINE_STAGE; |
| 328 } | 355 } |
| 329 | 356 |
| 330 bool ProxyMain::BeginMainFrameRequested() const { | 357 bool ProxyMain::BeginMainFrameRequested() const { |
| 331 DCHECK(IsMainThread()); | 358 DCHECK(IsMainThread()); |
| 332 return max_requested_pipeline_stage_ != NO_PIPELINE_STAGE; | 359 return max_requested_pipeline_stage_ != NO_PIPELINE_STAGE; |
| 333 } | 360 } |
| 334 | 361 |
| 335 void ProxyMain::MainThreadHasStoppedFlinging() { | 362 void ProxyMain::MainThreadHasStoppedFlinging() { |
| 336 DCHECK(IsMainThread()); | 363 DCHECK(IsMainThread()); |
| 337 channel_main_->MainThreadHasStoppedFlingingOnImpl(); | 364 ImplThreadTaskRunner()->PostTask( |
| 365 FROM_HERE, base::Bind(&ProxyImpl::MainThreadHasStoppedFlingingOnImpl, |
| 366 base::Unretained(proxy_impl_.get()))); |
| 338 } | 367 } |
| 339 | 368 |
| 340 void ProxyMain::Start() { | 369 void ProxyMain::Start() { |
| 341 DCHECK(IsMainThread()); | 370 DCHECK(IsMainThread()); |
| 342 DCHECK(layer_tree_host_->IsThreaded()); | 371 DCHECK(layer_tree_host_->IsThreaded()); |
| 343 DCHECK(channel_main_); | |
| 344 | 372 |
| 345 // Create LayerTreeHostImpl. | 373 { |
| 346 channel_main_->SynchronouslyInitializeImpl(layer_tree_host_); | 374 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 375 CompletionEvent completion; |
| 376 ImplThreadTaskRunner()->PostTask( |
| 377 FROM_HERE, base::Bind(&ProxyMain::InitializeOnImplThread, |
| 378 base::Unretained(this), &completion)); |
| 379 completion.Wait(); |
| 380 } |
| 347 | 381 |
| 348 started_ = true; | 382 started_ = true; |
| 349 } | 383 } |
| 350 | 384 |
| 351 void ProxyMain::Stop() { | 385 void ProxyMain::Stop() { |
| 352 TRACE_EVENT0("cc", "ProxyMain::Stop"); | 386 TRACE_EVENT0("cc", "ProxyMain::Stop"); |
| 353 DCHECK(IsMainThread()); | 387 DCHECK(IsMainThread()); |
| 354 DCHECK(started_); | 388 DCHECK(started_); |
| 355 | 389 |
| 356 channel_main_->SynchronouslyCloseImpl(); | 390 // Synchronously finishes pending GL operations and deletes the impl. |
| 391 // The two steps are done as separate post tasks, so that tasks posted |
| 392 // by the GL implementation due to the Finish can be executed by the |
| 393 // renderer before shutting it down. |
| 394 { |
| 395 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 396 CompletionEvent completion; |
| 397 ImplThreadTaskRunner()->PostTask( |
| 398 FROM_HERE, |
| 399 base::Bind(&ProxyImpl::FinishGLOnImpl, |
| 400 base::Unretained(proxy_impl_.get()), &completion)); |
| 401 completion.Wait(); |
| 402 } |
| 403 { |
| 404 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 405 CompletionEvent completion; |
| 406 ImplThreadTaskRunner()->PostTask( |
| 407 FROM_HERE, base::Bind(&ProxyMain::DestroyProxyImplOnImplThread, |
| 408 base::Unretained(this), &completion)); |
| 409 completion.Wait(); |
| 410 } |
| 357 | 411 |
| 412 weak_factory_.InvalidateWeakPtrs(); |
| 358 layer_tree_host_ = nullptr; | 413 layer_tree_host_ = nullptr; |
| 359 started_ = false; | 414 started_ = false; |
| 360 } | 415 } |
| 361 | 416 |
| 362 void ProxyMain::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) { | 417 void ProxyMain::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) { |
| 363 TRACE_EVENT0("compositor-worker", "ThreadProxy::SetMutator"); | 418 TRACE_EVENT0("compositor-worker", "ThreadProxy::SetMutator"); |
| 364 channel_main_->InitializeMutatorOnImpl(std::move(mutator)); | 419 ImplThreadTaskRunner()->PostTask( |
| 420 FROM_HERE, base::Bind(&ProxyImpl::InitializeMutatorOnImpl, |
| 421 base::Unretained(proxy_impl_.get()), |
| 422 base::Passed(std::move(mutator)))); |
| 365 } | 423 } |
| 366 | 424 |
| 367 bool ProxyMain::SupportsImplScrolling() const { | 425 bool ProxyMain::SupportsImplScrolling() const { |
| 368 return true; | 426 return true; |
| 369 } | 427 } |
| 370 | 428 |
| 371 bool ProxyMain::MainFrameWillHappenForTesting() { | 429 bool ProxyMain::MainFrameWillHappenForTesting() { |
| 372 DCHECK(IsMainThread()); | 430 DCHECK(IsMainThread()); |
| 373 bool main_frame_will_happen = false; | 431 bool main_frame_will_happen = false; |
| 374 { | 432 { |
| 375 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); | 433 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 376 CompletionEvent completion; | 434 CompletionEvent completion; |
| 377 channel_main_->MainFrameWillHappenOnImplForTesting(&completion, | 435 ImplThreadTaskRunner()->PostTask( |
| 378 &main_frame_will_happen); | 436 FROM_HERE, base::Bind(&ProxyImpl::MainFrameWillHappenOnImplForTesting, |
| 437 base::Unretained(proxy_impl_.get()), &completion, |
| 438 &main_frame_will_happen)); |
| 379 completion.Wait(); | 439 completion.Wait(); |
| 380 } | 440 } |
| 381 return main_frame_will_happen; | 441 return main_frame_will_happen; |
| 382 } | 442 } |
| 383 | 443 |
| 384 void ProxyMain::ReleaseCompositorFrameSink() { | 444 void ProxyMain::ReleaseCompositorFrameSink() { |
| 385 DCHECK(IsMainThread()); | 445 DCHECK(IsMainThread()); |
| 386 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); | 446 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 387 CompletionEvent completion; | 447 CompletionEvent completion; |
| 388 channel_main_->ReleaseCompositorFrameSinkOnImpl(&completion); | 448 ImplThreadTaskRunner()->PostTask( |
| 449 FROM_HERE, base::Bind(&ProxyImpl::ReleaseCompositorFrameSinkOnImpl, |
| 450 base::Unretained(proxy_impl_.get()), &completion)); |
| 389 completion.Wait(); | 451 completion.Wait(); |
| 390 } | 452 } |
| 391 | 453 |
| 392 void ProxyMain::UpdateBrowserControlsState(BrowserControlsState constraints, | 454 void ProxyMain::UpdateBrowserControlsState(BrowserControlsState constraints, |
| 393 BrowserControlsState current, | 455 BrowserControlsState current, |
| 394 bool animate) { | 456 bool animate) { |
| 395 DCHECK(IsMainThread()); | 457 DCHECK(IsMainThread()); |
| 396 channel_main_->UpdateBrowserControlsStateOnImpl(constraints, current, | 458 ImplThreadTaskRunner()->PostTask( |
| 397 animate); | 459 FROM_HERE, base::Bind(&ProxyImpl::UpdateBrowserControlsStateOnImpl, |
| 460 base::Unretained(proxy_impl_.get()), constraints, |
| 461 current, animate)); |
| 398 } | 462 } |
| 399 | 463 |
| 400 bool ProxyMain::SendCommitRequestToImplThreadIfNeeded( | 464 bool ProxyMain::SendCommitRequestToImplThreadIfNeeded( |
| 401 CommitPipelineStage required_stage) { | 465 CommitPipelineStage required_stage) { |
| 402 DCHECK(IsMainThread()); | 466 DCHECK(IsMainThread()); |
| 403 DCHECK_NE(NO_PIPELINE_STAGE, required_stage); | 467 DCHECK_NE(NO_PIPELINE_STAGE, required_stage); |
| 404 bool already_posted = max_requested_pipeline_stage_ != NO_PIPELINE_STAGE; | 468 bool already_posted = max_requested_pipeline_stage_ != NO_PIPELINE_STAGE; |
| 405 max_requested_pipeline_stage_ = | 469 max_requested_pipeline_stage_ = |
| 406 std::max(max_requested_pipeline_stage_, required_stage); | 470 std::max(max_requested_pipeline_stage_, required_stage); |
| 407 if (already_posted) | 471 if (already_posted) |
| 408 return false; | 472 return false; |
| 409 channel_main_->SetNeedsCommitOnImpl(); | 473 ImplThreadTaskRunner()->PostTask( |
| 474 FROM_HERE, base::Bind(&ProxyImpl::SetNeedsCommitOnImpl, |
| 475 base::Unretained(proxy_impl_.get()))); |
| 410 return true; | 476 return true; |
| 411 } | 477 } |
| 412 | 478 |
| 413 bool ProxyMain::IsMainThread() const { | 479 bool ProxyMain::IsMainThread() const { |
| 414 return task_runner_provider_->IsMainThread(); | 480 return task_runner_provider_->IsMainThread(); |
| 415 } | 481 } |
| 416 | 482 |
| 483 bool ProxyMain::IsImplThread() const { |
| 484 return task_runner_provider_->IsImplThread(); |
| 485 } |
| 486 |
| 487 base::SingleThreadTaskRunner* ProxyMain::ImplThreadTaskRunner() { |
| 488 return task_runner_provider_->ImplThreadTaskRunner(); |
| 489 } |
| 490 |
| 417 } // namespace cc | 491 } // namespace cc |
| OLD | NEW |