[go: nahoru, domu]

blob: 7549d9d13ef896f6414a4c213e6d47e05b4bff40 [file] [log] [blame]
khushalsagar0a226af2015-12-09 10:30:201// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "cc/trees/proxy_main.h"
6
7#include <algorithm>
8#include <string>
9
fdorayba121422016-12-23 19:51:4810#include "base/memory/ptr_util.h"
khushalsagar0a226af2015-12-09 10:30:2011#include "base/trace_event/trace_event.h"
12#include "base/trace_event/trace_event_argument.h"
13#include "base/trace_event/trace_event_synthetic_delay.h"
khushalsagar12020cd42016-11-21 09:22:4814#include "cc/base/completion_event.h"
chrishtr82b5d9502017-03-20 18:25:3315#include "cc/base/devtools_instrumentation.h"
16#include "cc/benchmarks/benchmark_instrumentation.h"
danakjc7afae52017-06-20 21:12:4117#include "cc/output/layer_tree_frame_sink.h"
khushalsagar0a226af2015-12-09 10:30:2018#include "cc/output/swap_promise.h"
khushalsagar8ec07402016-09-10 03:13:1919#include "cc/resources/ui_resource_manager.h"
khushalsagar0a226af2015-12-09 10:30:2020#include "cc/trees/blocking_task_runner.h"
khushalsagare0e4486e2017-01-25 03:15:0321#include "cc/trees/layer_tree_host.h"
loysoc601b7b82016-11-10 02:56:4422#include "cc/trees/mutator_host.h"
khushalsagar12020cd42016-11-21 09:22:4823#include "cc/trees/proxy_impl.h"
khushalsagar0a226af2015-12-09 10:30:2024#include "cc/trees/scoped_abort_remaining_swap_promises.h"
khushalsagar0a226af2015-12-09 10:30:2025
26namespace cc {
27
khushalsagare0e4486e2017-01-25 03:15:0328ProxyMain::ProxyMain(LayerTreeHost* layer_tree_host,
khushalsagar767dd522015-12-16 05:14:0529 TaskRunnerProvider* task_runner_provider)
khushalsagar0a226af2015-12-09 10:30:2030 : layer_tree_host_(layer_tree_host),
31 task_runner_provider_(task_runner_provider),
khushalsagarcebe4942016-09-07 23:27:0132 layer_tree_host_id_(layer_tree_host->GetId()),
khushalsagar0a226af2015-12-09 10:30:2033 max_requested_pipeline_stage_(NO_PIPELINE_STAGE),
34 current_pipeline_stage_(NO_PIPELINE_STAGE),
35 final_pipeline_stage_(NO_PIPELINE_STAGE),
36 commit_waits_for_activation_(false),
37 started_(false),
khushalsagar12020cd42016-11-21 09:22:4838 defer_commits_(false),
samans44b6dfc2017-04-19 16:50:5339 frame_sink_bound_weak_factory_(this),
khushalsagar12020cd42016-11-21 09:22:4840 weak_factory_(this) {
khushalsagar0a226af2015-12-09 10:30:2041 TRACE_EVENT0("cc", "ProxyMain::ProxyMain");
42 DCHECK(task_runner_provider_);
43 DCHECK(IsMainThread());
khushalsagar0a226af2015-12-09 10:30:2044}
45
46ProxyMain::~ProxyMain() {
47 TRACE_EVENT0("cc", "ProxyMain::~ProxyMain");
48 DCHECK(IsMainThread());
49 DCHECK(!started_);
50}
51
khushalsagar12020cd42016-11-21 09:22:4852void ProxyMain::InitializeOnImplThread(CompletionEvent* completion_event) {
53 DCHECK(task_runner_provider_->IsImplThread());
54 DCHECK(!proxy_impl_);
55 proxy_impl_ = base::MakeUnique<ProxyImpl>(
56 weak_factory_.GetWeakPtr(), layer_tree_host_, task_runner_provider_);
57 completion_event->Signal();
58}
59
60void ProxyMain::DestroyProxyImplOnImplThread(
61 CompletionEvent* completion_event) {
62 DCHECK(task_runner_provider_->IsImplThread());
63 proxy_impl_.reset();
64 completion_event->Signal();
khushalsagar0a226af2015-12-09 10:30:2065}
66
danakj9d124422016-10-14 03:15:0867void ProxyMain::DidReceiveCompositorFrameAck() {
khushalsagar0a226af2015-12-09 10:30:2068 DCHECK(IsMainThread());
danakj9d124422016-10-14 03:15:0869 layer_tree_host_->DidReceiveCompositorFrameAck();
khushalsagar0a226af2015-12-09 10:30:2070}
71
khushalsagar0a226af2015-12-09 10:30:2072void ProxyMain::BeginMainFrameNotExpectedSoon() {
73 TRACE_EVENT0("cc", "ProxyMain::BeginMainFrameNotExpectedSoon");
74 DCHECK(IsMainThread());
75 layer_tree_host_->BeginMainFrameNotExpectedSoon();
76}
77
delphick9db74aa2017-05-05 10:20:4978void ProxyMain::BeginMainFrameNotExpectedUntil(base::TimeTicks time) {
79 TRACE_EVENT0("cc", "ProxyMain::BeginMainFrameNotExpectedUntil");
80 DCHECK(IsMainThread());
81 layer_tree_host_->BeginMainFrameNotExpectedUntil(time);
82}
83
khushalsagar0a226af2015-12-09 10:30:2084void ProxyMain::DidCommitAndDrawFrame() {
85 DCHECK(IsMainThread());
86 layer_tree_host_->DidCommitAndDrawFrame();
87}
88
loysoc601b7b82016-11-10 02:56:4489void ProxyMain::SetAnimationEvents(std::unique_ptr<MutatorEvents> events) {
khushalsagar0a226af2015-12-09 10:30:2090 TRACE_EVENT0("cc", "ProxyMain::SetAnimationEvents");
91 DCHECK(IsMainThread());
92 layer_tree_host_->SetAnimationEvents(std::move(events));
93}
94
danakjc7afae52017-06-20 21:12:4195void ProxyMain::DidLoseLayerTreeFrameSink() {
96 TRACE_EVENT0("cc", "ProxyMain::DidLoseLayerTreeFrameSink");
khushalsagar0a226af2015-12-09 10:30:2097 DCHECK(IsMainThread());
danakjc7afae52017-06-20 21:12:4198 layer_tree_host_->DidLoseLayerTreeFrameSink();
khushalsagar0a226af2015-12-09 10:30:2099}
100
danakjc7afae52017-06-20 21:12:41101void ProxyMain::RequestNewLayerTreeFrameSink() {
102 TRACE_EVENT0("cc", "ProxyMain::RequestNewLayerTreeFrameSink");
khushalsagar0a226af2015-12-09 10:30:20103 DCHECK(IsMainThread());
danakjc7afae52017-06-20 21:12:41104 layer_tree_host_->RequestNewLayerTreeFrameSink();
khushalsagar0a226af2015-12-09 10:30:20105}
106
danakjc7afae52017-06-20 21:12:41107void ProxyMain::DidInitializeLayerTreeFrameSink(bool success) {
108 TRACE_EVENT0("cc", "ProxyMain::DidInitializeLayerTreeFrameSink");
khushalsagar0a226af2015-12-09 10:30:20109 DCHECK(IsMainThread());
110
danakj8c939192016-08-25 22:09:30111 if (!success)
danakjc7afae52017-06-20 21:12:41112 layer_tree_host_->DidFailToInitializeLayerTreeFrameSink();
danakj8c939192016-08-25 22:09:30113 else
danakjc7afae52017-06-20 21:12:41114 layer_tree_host_->DidInitializeLayerTreeFrameSink();
khushalsagar0a226af2015-12-09 10:30:20115}
116
117void ProxyMain::DidCompletePageScaleAnimation() {
118 DCHECK(IsMainThread());
119 layer_tree_host_->DidCompletePageScaleAnimation();
120}
121
khushalsagar0a226af2015-12-09 10:30:20122void ProxyMain::BeginMainFrame(
danakj60bc3bc2016-04-09 00:24:48123 std::unique_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) {
khushalsagar0a226af2015-12-09 10:30:20124 benchmark_instrumentation::ScopedBeginFrameTask begin_frame_task(
125 benchmark_instrumentation::kDoBeginFrame,
126 begin_main_frame_state->begin_frame_id);
127
128 base::TimeTicks begin_main_frame_start_time = base::TimeTicks::Now();
129
130 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame");
131 DCHECK(IsMainThread());
132 DCHECK_EQ(NO_PIPELINE_STAGE, current_pipeline_stage_);
133
vmpstrf386bcd2017-03-08 04:12:07134 // We need to issue image decode callbacks whether or not we will abort this
135 // commit, since the callbacks are only stored in |begin_main_frame_state|.
136 for (auto& callback :
137 begin_main_frame_state->completed_image_decode_callbacks) {
138 callback.Run();
139 }
140
khushalsagar0a226af2015-12-09 10:30:20141 if (defer_commits_) {
142 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit",
143 TRACE_EVENT_SCOPE_THREAD);
sunnypsad3235e2016-08-09 04:57:52144 std::vector<std::unique_ptr<SwapPromise>> empty_swap_promises;
khushalsagar12020cd42016-11-21 09:22:48145 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22146 FROM_HERE, base::BindOnce(&ProxyImpl::BeginMainFrameAbortedOnImpl,
147 base::Unretained(proxy_impl_.get()),
148 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT,
149 begin_main_frame_start_time,
150 base::Passed(&empty_swap_promises)));
khushalsagar0a226af2015-12-09 10:30:20151 return;
152 }
153
154 // If the commit finishes, LayerTreeHost will transfer its swap promises to
155 // LayerTreeImpl. The destructor of ScopedSwapPromiseChecker aborts the
156 // remaining swap promises.
khushalsagar8297ae992016-09-14 20:51:23157 ScopedAbortRemainingSwapPromises swap_promise_checker(
158 layer_tree_host_->GetSwapPromiseManager());
khushalsagar0a226af2015-12-09 10:30:20159
160 final_pipeline_stage_ = max_requested_pipeline_stage_;
161 max_requested_pipeline_stage_ = NO_PIPELINE_STAGE;
162
khushalsagarcebe4942016-09-07 23:27:01163 if (!layer_tree_host_->IsVisible()) {
khushalsagar0a226af2015-12-09 10:30:20164 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD);
sunnypsad3235e2016-08-09 04:57:52165 std::vector<std::unique_ptr<SwapPromise>> empty_swap_promises;
khushalsagar12020cd42016-11-21 09:22:48166 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22167 FROM_HERE, base::BindOnce(&ProxyImpl::BeginMainFrameAbortedOnImpl,
168 base::Unretained(proxy_impl_.get()),
169 CommitEarlyOutReason::ABORTED_NOT_VISIBLE,
170 begin_main_frame_start_time,
171 base::Passed(&empty_swap_promises)));
khushalsagar0a226af2015-12-09 10:30:20172 return;
173 }
174
khushalsagar0a226af2015-12-09 10:30:20175 current_pipeline_stage_ = ANIMATE_PIPELINE_STAGE;
176
177 layer_tree_host_->ApplyScrollAndScale(
178 begin_main_frame_state->scroll_info.get());
179
majidvp96452d02016-04-11 20:36:04180 if (begin_main_frame_state->begin_frame_callbacks) {
181 for (auto& callback : *begin_main_frame_state->begin_frame_callbacks)
182 callback.Run();
183 }
184
khushalsagar0a226af2015-12-09 10:30:20185 layer_tree_host_->WillBeginMainFrame();
186
187 layer_tree_host_->BeginMainFrame(begin_main_frame_state->begin_frame_args);
188 layer_tree_host_->AnimateLayers(
189 begin_main_frame_state->begin_frame_args.frame_time);
190
191 // Recreate all UI resources if there were evicted UI resources when the impl
192 // thread initiated the commit.
193 if (begin_main_frame_state->evicted_ui_resources)
khushalsagar8ec07402016-09-10 03:13:19194 layer_tree_host_->GetUIResourceManager()->RecreateUIResources();
khushalsagar0a226af2015-12-09 10:30:20195
196 layer_tree_host_->RequestMainFrameUpdate();
danakj97660d92017-03-27 14:11:49197
198 // At this point the main frame may have deferred commits to avoid committing
199 // right now.
200 if (defer_commits_) {
201 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit_InsideBeginMainFrame",
202 TRACE_EVENT_SCOPE_THREAD);
203 std::vector<std::unique_ptr<SwapPromise>> empty_swap_promises;
204 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22205 FROM_HERE, base::BindOnce(&ProxyImpl::BeginMainFrameAbortedOnImpl,
206 base::Unretained(proxy_impl_.get()),
207 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT,
208 begin_main_frame_start_time,
209 base::Passed(&empty_swap_promises)));
danakj97660d92017-03-27 14:11:49210 current_pipeline_stage_ = NO_PIPELINE_STAGE;
211 // We intentionally don't report CommitComplete() here since it was aborted
212 // prematurely and we're waiting to do another commit in the future.
213 layer_tree_host_->DidBeginMainFrame();
214 return;
215 }
216
khushalsagar0a226af2015-12-09 10:30:20217 TRACE_EVENT_SYNTHETIC_DELAY_END("cc.BeginMainFrame");
218
219 bool can_cancel_this_commit = final_pipeline_stage_ < COMMIT_PIPELINE_STAGE &&
220 !begin_main_frame_state->evicted_ui_resources;
221
222 current_pipeline_stage_ = UPDATE_LAYERS_PIPELINE_STAGE;
223 bool should_update_layers =
224 final_pipeline_stage_ >= UPDATE_LAYERS_PIPELINE_STAGE;
225 bool updated = should_update_layers && layer_tree_host_->UpdateLayers();
226
227 layer_tree_host_->WillCommit();
228 devtools_instrumentation::ScopedCommitTrace commit_task(
khushalsagarcebe4942016-09-07 23:27:01229 layer_tree_host_->GetId());
khushalsagar0a226af2015-12-09 10:30:20230
231 current_pipeline_stage_ = COMMIT_PIPELINE_STAGE;
232 if (!updated && can_cancel_this_commit) {
233 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoUpdates", TRACE_EVENT_SCOPE_THREAD);
khushalsagar12020cd42016-11-21 09:22:48234 std::vector<std::unique_ptr<SwapPromise>> swap_promises =
235 layer_tree_host_->GetSwapPromiseManager()->TakeSwapPromises();
236 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22237 FROM_HERE, base::BindOnce(&ProxyImpl::BeginMainFrameAbortedOnImpl,
238 base::Unretained(proxy_impl_.get()),
239 CommitEarlyOutReason::FINISHED_NO_UPDATES,
240 begin_main_frame_start_time,
241 base::Passed(&swap_promises)));
khushalsagar0a226af2015-12-09 10:30:20242
243 // Although the commit is internally aborted, this is because it has been
244 // detected to be a no-op. From the perspective of an embedder, this commit
245 // went through, and input should no longer be throttled, etc.
246 current_pipeline_stage_ = NO_PIPELINE_STAGE;
247 layer_tree_host_->CommitComplete();
248 layer_tree_host_->DidBeginMainFrame();
khushalsagar0a226af2015-12-09 10:30:20249 return;
250 }
251
252 // Notify the impl thread that the main thread is ready to commit. This will
253 // begin the commit process, which is blocking from the main thread's
254 // point of view, but asynchronously performed on the impl thread,
255 // coordinated by the Scheduler.
256 {
257 TRACE_EVENT0("cc", "ProxyMain::BeginMainFrame::commit");
258
259 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
260
261 // This CapturePostTasks should be destroyed before CommitComplete() is
262 // called since that goes out to the embedder, and we want the embedder
263 // to receive its callbacks before that.
264 BlockingTaskRunner::CapturePostTasks blocked(
265 task_runner_provider_->blocking_main_thread_task_runner());
266
267 bool hold_commit_for_activation = commit_waits_for_activation_;
268 commit_waits_for_activation_ = false;
269 CompletionEvent completion;
khushalsagar12020cd42016-11-21 09:22:48270 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22271 FROM_HERE,
272 base::BindOnce(&ProxyImpl::NotifyReadyToCommitOnImpl,
273 base::Unretained(proxy_impl_.get()), &completion,
274 layer_tree_host_, begin_main_frame_start_time,
275 hold_commit_for_activation));
Sunny Sachanandani40f18922017-04-21 20:02:57276 completion.Wait();
khushalsagar0a226af2015-12-09 10:30:20277 }
278
279 current_pipeline_stage_ = NO_PIPELINE_STAGE;
280 layer_tree_host_->CommitComplete();
281 layer_tree_host_->DidBeginMainFrame();
282}
283
khushalsagar0a226af2015-12-09 10:30:20284bool ProxyMain::IsStarted() const {
285 DCHECK(IsMainThread());
286 return started_;
287}
288
289bool ProxyMain::CommitToActiveTree() const {
290 // With ProxyMain, we use a pending tree and activate it once it's ready to
291 // draw to allow input to modify the active tree and draw during raster.
292 return false;
293}
294
danakjc7afae52017-06-20 21:12:41295void ProxyMain::SetLayerTreeFrameSink(
296 LayerTreeFrameSink* layer_tree_frame_sink) {
khushalsagar12020cd42016-11-21 09:22:48297 ImplThreadTaskRunner()->PostTask(
samans44b6dfc2017-04-19 16:50:53298 FROM_HERE,
danakjc7afae52017-06-20 21:12:41299 base::BindOnce(&ProxyImpl::InitializeLayerTreeFrameSinkOnImpl,
300 base::Unretained(proxy_impl_.get()), layer_tree_frame_sink,
samans44b6dfc2017-04-19 16:50:53301 frame_sink_bound_weak_factory_.GetWeakPtr()));
khushalsagar0a226af2015-12-09 10:30:20302}
303
304void ProxyMain::SetVisible(bool visible) {
305 TRACE_EVENT1("cc", "ProxyMain::SetVisible", "visible", visible);
khushalsagar12020cd42016-11-21 09:22:48306 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22307 FROM_HERE, base::BindOnce(&ProxyImpl::SetVisibleOnImpl,
308 base::Unretained(proxy_impl_.get()), visible));
khushalsagar0a226af2015-12-09 10:30:20309}
310
khushalsagar0a226af2015-12-09 10:30:20311void ProxyMain::SetNeedsAnimate() {
312 DCHECK(IsMainThread());
313 if (SendCommitRequestToImplThreadIfNeeded(ANIMATE_PIPELINE_STAGE)) {
314 TRACE_EVENT_INSTANT0("cc", "ProxyMain::SetNeedsAnimate",
315 TRACE_EVENT_SCOPE_THREAD);
316 }
317}
318
319void ProxyMain::SetNeedsUpdateLayers() {
320 DCHECK(IsMainThread());
321 // If we are currently animating, make sure we also update the layers.
322 if (current_pipeline_stage_ == ANIMATE_PIPELINE_STAGE) {
323 final_pipeline_stage_ =
324 std::max(final_pipeline_stage_, UPDATE_LAYERS_PIPELINE_STAGE);
325 return;
326 }
327 if (SendCommitRequestToImplThreadIfNeeded(UPDATE_LAYERS_PIPELINE_STAGE)) {
328 TRACE_EVENT_INSTANT0("cc", "ProxyMain::SetNeedsUpdateLayers",
329 TRACE_EVENT_SCOPE_THREAD);
330 }
331}
332
333void ProxyMain::SetNeedsCommit() {
334 DCHECK(IsMainThread());
335 // If we are currently animating, make sure we don't skip the commit. Note
336 // that requesting a commit during the layer update stage means we need to
337 // schedule another full commit.
338 if (current_pipeline_stage_ == ANIMATE_PIPELINE_STAGE) {
339 final_pipeline_stage_ =
340 std::max(final_pipeline_stage_, COMMIT_PIPELINE_STAGE);
341 return;
342 }
343 if (SendCommitRequestToImplThreadIfNeeded(COMMIT_PIPELINE_STAGE)) {
344 TRACE_EVENT_INSTANT0("cc", "ProxyMain::SetNeedsCommit",
345 TRACE_EVENT_SCOPE_THREAD);
346 }
347}
348
349void ProxyMain::SetNeedsRedraw(const gfx::Rect& damage_rect) {
350 TRACE_EVENT0("cc", "ProxyMain::SetNeedsRedraw");
351 DCHECK(IsMainThread());
khushalsagar12020cd42016-11-21 09:22:48352 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22353 FROM_HERE,
354 base::BindOnce(&ProxyImpl::SetNeedsRedrawOnImpl,
355 base::Unretained(proxy_impl_.get()), damage_rect));
khushalsagar0a226af2015-12-09 10:30:20356}
357
358void ProxyMain::SetNextCommitWaitsForActivation() {
359 DCHECK(IsMainThread());
360 commit_waits_for_activation_ = true;
361}
362
363void ProxyMain::NotifyInputThrottledUntilCommit() {
364 DCHECK(IsMainThread());
khushalsagar12020cd42016-11-21 09:22:48365 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22366 FROM_HERE, base::BindOnce(&ProxyImpl::SetInputThrottledUntilCommitOnImpl,
367 base::Unretained(proxy_impl_.get()), true));
khushalsagar0a226af2015-12-09 10:30:20368}
369
370void ProxyMain::SetDeferCommits(bool defer_commits) {
371 DCHECK(IsMainThread());
372 if (defer_commits_ == defer_commits)
373 return;
374
375 defer_commits_ = defer_commits;
376 if (defer_commits_)
377 TRACE_EVENT_ASYNC_BEGIN0("cc", "ProxyMain::SetDeferCommits", this);
378 else
379 TRACE_EVENT_ASYNC_END0("cc", "ProxyMain::SetDeferCommits", this);
380
khushalsagar12020cd42016-11-21 09:22:48381 ImplThreadTaskRunner()->PostTask(
382 FROM_HERE,
tzik4604bb52017-04-13 21:50:22383 base::BindOnce(&ProxyImpl::SetDeferCommitsOnImpl,
384 base::Unretained(proxy_impl_.get()), defer_commits));
khushalsagar0a226af2015-12-09 10:30:20385}
386
387bool ProxyMain::CommitRequested() const {
388 DCHECK(IsMainThread());
389 // TODO(skyostil): Split this into something like CommitRequested() and
390 // CommitInProgress().
391 return current_pipeline_stage_ != NO_PIPELINE_STAGE ||
392 max_requested_pipeline_stage_ >= COMMIT_PIPELINE_STAGE;
393}
394
khushalsagar0a226af2015-12-09 10:30:20395void ProxyMain::MainThreadHasStoppedFlinging() {
396 DCHECK(IsMainThread());
khushalsagar12020cd42016-11-21 09:22:48397 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22398 FROM_HERE, base::BindOnce(&ProxyImpl::MainThreadHasStoppedFlingingOnImpl,
399 base::Unretained(proxy_impl_.get())));
khushalsagar0a226af2015-12-09 10:30:20400}
401
enne2b0ad682016-09-21 01:44:47402void ProxyMain::Start() {
khushalsagar0a226af2015-12-09 10:30:20403 DCHECK(IsMainThread());
khushalsagarc7eae9d2016-11-12 04:43:42404 DCHECK(layer_tree_host_->IsThreaded());
khushalsagar0a226af2015-12-09 10:30:20405
khushalsagar12020cd42016-11-21 09:22:48406 {
407 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
408 CompletionEvent completion;
409 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22410 FROM_HERE, base::BindOnce(&ProxyMain::InitializeOnImplThread,
411 base::Unretained(this), &completion));
khushalsagar12020cd42016-11-21 09:22:48412 completion.Wait();
413 }
khushalsagar0a226af2015-12-09 10:30:20414
415 started_ = true;
416}
417
418void ProxyMain::Stop() {
419 TRACE_EVENT0("cc", "ProxyMain::Stop");
420 DCHECK(IsMainThread());
421 DCHECK(started_);
422
khushalsagar12020cd42016-11-21 09:22:48423 // Synchronously finishes pending GL operations and deletes the impl.
424 // The two steps are done as separate post tasks, so that tasks posted
425 // by the GL implementation due to the Finish can be executed by the
426 // renderer before shutting it down.
427 {
428 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
429 CompletionEvent completion;
430 ImplThreadTaskRunner()->PostTask(
431 FROM_HERE,
tzik4604bb52017-04-13 21:50:22432 base::BindOnce(&ProxyImpl::FinishGLOnImpl,
433 base::Unretained(proxy_impl_.get()), &completion));
khushalsagar12020cd42016-11-21 09:22:48434 completion.Wait();
435 }
436 {
437 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
438 CompletionEvent completion;
439 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22440 FROM_HERE, base::BindOnce(&ProxyMain::DestroyProxyImplOnImplThread,
441 base::Unretained(this), &completion));
khushalsagar12020cd42016-11-21 09:22:48442 completion.Wait();
443 }
khushalsagar0a226af2015-12-09 10:30:20444
khushalsagar12020cd42016-11-21 09:22:48445 weak_factory_.InvalidateWeakPtrs();
khushalsagar0a226af2015-12-09 10:30:20446 layer_tree_host_ = nullptr;
447 started_ = false;
448}
449
flackrf54e9b42016-05-31 15:20:10450void ProxyMain::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) {
451 TRACE_EVENT0("compositor-worker", "ThreadProxy::SetMutator");
khushalsagar12020cd42016-11-21 09:22:48452 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22453 FROM_HERE, base::BindOnce(&ProxyImpl::InitializeMutatorOnImpl,
454 base::Unretained(proxy_impl_.get()),
455 base::Passed(std::move(mutator))));
flackrf54e9b42016-05-31 15:20:10456}
457
khushalsagar0a226af2015-12-09 10:30:20458bool ProxyMain::SupportsImplScrolling() const {
459 return true;
460}
461
462bool ProxyMain::MainFrameWillHappenForTesting() {
463 DCHECK(IsMainThread());
464 bool main_frame_will_happen = false;
465 {
466 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
467 CompletionEvent completion;
khushalsagar12020cd42016-11-21 09:22:48468 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22469 FROM_HERE,
470 base::BindOnce(&ProxyImpl::MainFrameWillHappenOnImplForTesting,
471 base::Unretained(proxy_impl_.get()), &completion,
472 &main_frame_will_happen));
khushalsagar0a226af2015-12-09 10:30:20473 completion.Wait();
474 }
475 return main_frame_will_happen;
476}
477
danakjc7afae52017-06-20 21:12:41478void ProxyMain::ReleaseLayerTreeFrameSink() {
khushalsagar0a226af2015-12-09 10:30:20479 DCHECK(IsMainThread());
samans44b6dfc2017-04-19 16:50:53480 frame_sink_bound_weak_factory_.InvalidateWeakPtrs();
khushalsagar0a226af2015-12-09 10:30:20481 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
482 CompletionEvent completion;
khushalsagar12020cd42016-11-21 09:22:48483 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22484 FROM_HERE,
danakjc7afae52017-06-20 21:12:41485 base::BindOnce(&ProxyImpl::ReleaseLayerTreeFrameSinkOnImpl,
tzik4604bb52017-04-13 21:50:22486 base::Unretained(proxy_impl_.get()), &completion));
khushalsagar0a226af2015-12-09 10:30:20487 completion.Wait();
488}
489
mdjones2ee41afd2016-10-27 16:50:20490void ProxyMain::UpdateBrowserControlsState(BrowserControlsState constraints,
491 BrowserControlsState current,
492 bool animate) {
khushalsagar0a226af2015-12-09 10:30:20493 DCHECK(IsMainThread());
khushalsagar12020cd42016-11-21 09:22:48494 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22495 FROM_HERE, base::BindOnce(&ProxyImpl::UpdateBrowserControlsStateOnImpl,
496 base::Unretained(proxy_impl_.get()),
497 constraints, current, animate));
khushalsagar0a226af2015-12-09 10:30:20498}
499
Dan Elphick95929fd52017-06-13 09:15:07500void ProxyMain::RequestBeginMainFrameNotExpected(bool new_state) {
501 DCHECK(IsMainThread());
502 ImplThreadTaskRunner()->PostTask(
503 FROM_HERE,
504 base::BindOnce(&ProxyImpl::RequestBeginMainFrameNotExpected,
505 base::Unretained(proxy_impl_.get()), new_state));
506}
507
khushalsagar0a226af2015-12-09 10:30:20508bool ProxyMain::SendCommitRequestToImplThreadIfNeeded(
509 CommitPipelineStage required_stage) {
510 DCHECK(IsMainThread());
511 DCHECK_NE(NO_PIPELINE_STAGE, required_stage);
512 bool already_posted = max_requested_pipeline_stage_ != NO_PIPELINE_STAGE;
513 max_requested_pipeline_stage_ =
514 std::max(max_requested_pipeline_stage_, required_stage);
515 if (already_posted)
516 return false;
khushalsagar12020cd42016-11-21 09:22:48517 ImplThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22518 FROM_HERE, base::BindOnce(&ProxyImpl::SetNeedsCommitOnImpl,
519 base::Unretained(proxy_impl_.get())));
khushalsagar0a226af2015-12-09 10:30:20520 return true;
521}
522
523bool ProxyMain::IsMainThread() const {
524 return task_runner_provider_->IsMainThread();
525}
526
khushalsagar12020cd42016-11-21 09:22:48527bool ProxyMain::IsImplThread() const {
528 return task_runner_provider_->IsImplThread();
529}
530
531base::SingleThreadTaskRunner* ProxyMain::ImplThreadTaskRunner() {
532 return task_runner_provider_->ImplThreadTaskRunner();
533}
534
khushalsagar0a226af2015-12-09 10:30:20535} // namespace cc