blob: 9901d084d95178e72119e89a91f4c8a26e26783f [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// Copyright 2011 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
[email protected]556fd292013-03-18 08:03:045#include "cc/trees/single_thread_proxy.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]74d9063c2013-01-18 03:14:477#include "base/auto_reset.h"
danakj60bc3bc2016-04-09 00:24:488#include "base/memory/ptr_util.h"
primianoc06e2382015-01-28 04:21:499#include "base/trace_event/trace_event.h"
chrishtr82b5d9502017-03-20 18:25:3310#include "cc/base/devtools_instrumentation.h"
11#include "cc/benchmarks/benchmark_instrumentation.h"
David Bokan1e37ebf2018-10-16 13:53:3712#include "cc/input/browser_controls_offset_manager.h"
khushalsagar8ec07402016-09-10 03:13:1913#include "cc/resources/ui_resource_manager.h"
mithrof7a21502014-12-17 03:24:4814#include "cc/scheduler/commit_earlyout_reason.h"
briandersonc9f50352015-06-24 03:38:5815#include "cc/scheduler/compositor_timing_history.h"
16#include "cc/scheduler/scheduler.h"
Brian Anderson242b9b02017-12-06 21:06:2617#include "cc/trees/latency_info_swap_promise.h"
danakjba65a0912017-09-21 16:38:4218#include "cc/trees/layer_tree_frame_sink.h"
khushalsagare0e4486e2017-01-25 03:15:0319#include "cc/trees/layer_tree_host.h"
jaydasika13c05062016-04-01 18:12:2720#include "cc/trees/layer_tree_host_common.h"
[email protected]943528e2013-11-07 05:01:3221#include "cc/trees/layer_tree_host_single_thread_client.h"
[email protected]556fd292013-03-18 08:03:0422#include "cc/trees/layer_tree_impl.h"
loysoc601b7b82016-11-10 02:56:4423#include "cc/trees/mutator_host.h"
jonrossa2ff4f82018-02-16 17:27:4624#include "cc/trees/render_frame_metadata_observer.h"
[email protected]aeeedad2014-08-22 18:16:2225#include "cc/trees/scoped_abort_remaining_swap_promises.h"
Fady Samuelc645ffe2017-07-24 17:28:2026#include "components/viz/common/frame_sinks/delay_based_time_source.h"
Xu Xing32549162017-07-17 22:25:4327#include "components/viz/common/gpu/context_provider.h"
[email protected]94f206c12012-08-25 00:09:1428
[email protected]9c88e562012-09-14 22:21:3029namespace cc {
[email protected]94f206c12012-08-25 00:09:1430
danakj60bc3bc2016-04-09 00:24:4831std::unique_ptr<Proxy> SingleThreadProxy::Create(
khushalsagare0e4486e2017-01-25 03:15:0332 LayerTreeHost* layer_tree_host,
[email protected]27e6a212014-07-18 15:51:2733 LayerTreeHostSingleThreadClient* client,
khushalsagar767dd522015-12-16 05:14:0534 TaskRunnerProvider* task_runner_provider) {
danakj60bc3bc2016-04-09 00:24:4835 return base::WrapUnique(
khushalsagar767dd522015-12-16 05:14:0536 new SingleThreadProxy(layer_tree_host, client, task_runner_provider));
[email protected]94f206c12012-08-25 00:09:1437}
38
khushalsagare0e4486e2017-01-25 03:15:0339SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host,
khushalsagar767dd522015-12-16 05:14:0540 LayerTreeHostSingleThreadClient* client,
41 TaskRunnerProvider* task_runner_provider)
khushalsagarb7db1fe2015-11-12 00:51:2742 : layer_tree_host_(layer_tree_host),
danakj6c872fc02016-10-22 04:29:4943 single_thread_client_(client),
khushalsagarb7db1fe2015-11-12 00:51:2744 task_runner_provider_(task_runner_provider),
[email protected]a8a049c2013-03-11 23:27:0645 next_frame_is_newly_committed_frame_(false),
mithro51693e382015-05-07 23:52:4146#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:0247 inside_impl_frame_(false),
mithro51693e382015-05-07 23:52:4148#endif
[email protected]aeeedad2014-08-22 18:16:2249 inside_draw_(false),
50 defer_commits_(false),
brianderson49e101d22015-04-29 00:05:3351 animate_requested_(false),
[email protected]aeeedad2014-08-22 18:16:2252 commit_requested_(false),
jbauman399aec1a2014-10-25 02:33:3253 inside_synchronous_composite_(false),
David Bokaneaa5cc82018-10-12 15:50:4054 needs_impl_frame_(false),
danakjc7afae52017-06-20 21:12:4155 layer_tree_frame_sink_creation_requested_(false),
56 layer_tree_frame_sink_lost_(true),
samans44b6dfc2017-04-19 16:50:5357 frame_sink_bound_weak_factory_(this),
[email protected]aeeedad2014-08-22 18:16:2258 weak_factory_(this) {
[email protected]a8a049c2013-03-11 23:27:0659 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
khushalsagarb7db1fe2015-11-12 00:51:2760 DCHECK(task_runner_provider_);
61 DCHECK(task_runner_provider_->IsMainThread());
[email protected]a8a049c2013-03-11 23:27:0662 DCHECK(layer_tree_host);
khushalsagar767dd522015-12-16 05:14:0563}
danakjfcdaba122015-04-24 21:41:5264
enne2b0ad682016-09-21 01:44:4765void SingleThreadProxy::Start() {
khushalsagar767dd522015-12-16 05:14:0566 DebugScopedSetImplThread impl(task_runner_provider_);
khushalsagar767dd522015-12-16 05:14:0567
khushalsagarcebe4942016-09-07 23:27:0168 const LayerTreeSettings& settings = layer_tree_host_->GetSettings();
khushalsagar6dc91d02017-02-28 05:10:0769 DCHECK(settings.single_thread_proxy_scheduler ||
70 !settings.enable_checker_imaging)
71 << "Checker-imaging is not supported in synchronous single threaded mode";
khushalsagarcebe4942016-09-07 23:27:0172 if (settings.single_thread_proxy_scheduler && !scheduler_on_impl_thread_) {
73 SchedulerSettings scheduler_settings(settings.ToSchedulerSettings());
danakj5f2e92de2015-06-20 00:25:5874 scheduler_settings.commit_to_active_tree = CommitToActiveTree();
briandersonc9f50352015-06-24 03:38:5875
danakj60bc3bc2016-04-09 00:24:4876 std::unique_ptr<CompositorTimingHistory> compositor_timing_history(
briandersonc9f50352015-06-24 03:38:5877 new CompositorTimingHistory(
briandersonbb917dd2016-02-20 05:21:1478 scheduler_settings.using_synchronous_renderer_compositor,
briandersonc68220f2015-07-20 20:08:3579 CompositorTimingHistory::BROWSER_UMA,
khushalsagar767dd522015-12-16 05:14:0580 layer_tree_host_->rendering_stats_instrumentation()));
enne2b0ad682016-09-21 01:44:4781 scheduler_on_impl_thread_.reset(
82 new Scheduler(this, scheduler_settings, layer_tree_host_->GetId(),
83 task_runner_provider_->MainThreadTaskRunner(),
84 std::move(compositor_timing_history)));
danakjfcdaba122015-04-24 21:41:5285 }
[email protected]94f206c12012-08-25 00:09:1486
Walter Kormanaa326e42017-08-22 23:04:4387 host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
[email protected]a8a049c2013-03-11 23:27:0688}
89
90SingleThreadProxy::~SingleThreadProxy() {
91 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy");
khushalsagarb7db1fe2015-11-12 00:51:2792 DCHECK(task_runner_provider_->IsMainThread());
[email protected]04049fc2013-05-01 03:13:2093 // Make sure Stop() got called or never Started.
Walter Kormanaa326e42017-08-22 23:04:4394 DCHECK(!host_impl_);
[email protected]a8a049c2013-03-11 23:27:0695}
96
[email protected]a8a049c2013-03-11 23:27:0697bool SingleThreadProxy::IsStarted() const {
khushalsagarb7db1fe2015-11-12 00:51:2798 DCHECK(task_runner_provider_->IsMainThread());
Walter Kormanaa326e42017-08-22 23:04:4399 return !!host_impl_;
[email protected]94f206c12012-08-25 00:09:14100}
101
danakj009cdfdf2015-02-17 22:35:14102bool SingleThreadProxy::CommitToActiveTree() const {
103 // With SingleThreadProxy we skip the pending tree and commit directly to the
104 // active tree.
105 return true;
106}
107
[email protected]a8a049c2013-03-11 23:27:06108void SingleThreadProxy::SetVisible(bool visible) {
mithro46adf5a2014-11-19 14:52:40109 TRACE_EVENT1("cc", "SingleThreadProxy::SetVisible", "visible", visible);
khushalsagarb7db1fe2015-11-12 00:51:27110 DebugScopedSetImplThread impl(task_runner_provider_);
sunnypsc3f6e0c2015-07-25 01:00:59111
Walter Kormanaa326e42017-08-22 23:04:43112 host_impl_->SetVisible(visible);
sunnypsc3f6e0c2015-07-25 01:00:59113
[email protected]aeeedad2014-08-22 18:16:22114 if (scheduler_on_impl_thread_)
Walter Kormanaa326e42017-08-22 23:04:43115 scheduler_on_impl_thread_->SetVisible(host_impl_->visible());
[email protected]a8a049c2013-03-11 23:27:06116}
117
danakjc7afae52017-06-20 21:12:41118void SingleThreadProxy::RequestNewLayerTreeFrameSink() {
khushalsagarb7db1fe2015-11-12 00:51:27119 DCHECK(task_runner_provider_->IsMainThread());
danakjc7afae52017-06-20 21:12:41120 layer_tree_frame_sink_creation_callback_.Cancel();
121 if (layer_tree_frame_sink_creation_requested_)
jbauman8ab0f9e2014-10-15 02:30:34122 return;
danakjc7afae52017-06-20 21:12:41123 layer_tree_frame_sink_creation_requested_ = true;
124 layer_tree_host_->RequestNewLayerTreeFrameSink();
enne2097cab2014-09-25 20:16:31125}
[email protected]94f206c12012-08-25 00:09:14126
danakjc7afae52017-06-20 21:12:41127void SingleThreadProxy::ReleaseLayerTreeFrameSink() {
128 layer_tree_frame_sink_lost_ = true;
samans44b6dfc2017-04-19 16:50:53129 frame_sink_bound_weak_factory_.InvalidateWeakPtrs();
sohan.jyoti3a33d872015-09-18 22:32:55130 if (scheduler_on_impl_thread_)
danakjc7afae52017-06-20 21:12:41131 scheduler_on_impl_thread_->DidLoseLayerTreeFrameSink();
Walter Kormanaa326e42017-08-22 23:04:43132 return host_impl_->ReleaseLayerTreeFrameSink();
sohan.jyoti3a33d872015-09-18 22:32:55133}
134
danakjc7afae52017-06-20 21:12:41135void SingleThreadProxy::SetLayerTreeFrameSink(
136 LayerTreeFrameSink* layer_tree_frame_sink) {
khushalsagarb7db1fe2015-11-12 00:51:27137 DCHECK(task_runner_provider_->IsMainThread());
danakjc7afae52017-06-20 21:12:41138 DCHECK(layer_tree_frame_sink_creation_requested_);
[email protected]da8e3b72b2014-04-25 02:33:45139
enne7f8fdde2014-12-10 21:32:09140 bool success;
141 {
khushalsagarb7db1fe2015-11-12 00:51:27142 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
143 DebugScopedSetImplThread impl(task_runner_provider_);
Xu Xing31616b92018-06-28 00:24:27144 success = host_impl_->InitializeFrameSink(layer_tree_frame_sink);
[email protected]04049fc2013-05-01 03:13:20145 }
146
[email protected]aeeedad2014-08-22 18:16:22147 if (success) {
samans44b6dfc2017-04-19 16:50:53148 frame_sink_bound_weak_ptr_ = frame_sink_bound_weak_factory_.GetWeakPtr();
danakjc7afae52017-06-20 21:12:41149 layer_tree_host_->DidInitializeLayerTreeFrameSink();
[email protected]aeeedad2014-08-22 18:16:22150 if (scheduler_on_impl_thread_)
danakjc7afae52017-06-20 21:12:41151 scheduler_on_impl_thread_->DidCreateAndInitializeLayerTreeFrameSink();
jbauman399aec1a2014-10-25 02:33:32152 else if (!inside_synchronous_composite_)
153 SetNeedsCommit();
danakjc7afae52017-06-20 21:12:41154 layer_tree_frame_sink_creation_requested_ = false;
155 layer_tree_frame_sink_lost_ = false;
enne7f8fdde2014-12-10 21:32:09156 } else {
danakjc7afae52017-06-20 21:12:41157 // DidFailToInitializeLayerTreeFrameSink is treated as a
158 // RequestNewLayerTreeFrameSink, and so
159 // layer_tree_frame_sink_creation_requested remains true.
160 layer_tree_host_->DidFailToInitializeLayerTreeFrameSink();
[email protected]04049fc2013-05-01 03:13:20161 }
[email protected]94f206c12012-08-25 00:09:14162}
163
[email protected]8b9e52b2014-01-17 16:35:31164void SingleThreadProxy::SetNeedsAnimate() {
[email protected]ccc08dc2014-01-30 07:33:20165 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate");
khushalsagarb7db1fe2015-11-12 00:51:27166 DCHECK(task_runner_provider_->IsMainThread());
danakj6c872fc02016-10-22 04:29:49167 single_thread_client_->RequestScheduleAnimation();
brianderson49e101d22015-04-29 00:05:33168 if (animate_requested_)
169 return;
170 animate_requested_ = true;
khushalsagarb7db1fe2015-11-12 00:51:27171 DebugScopedSetImplThread impl(task_runner_provider_);
brianderson49e101d22015-04-29 00:05:33172 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01173 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
[email protected]c5134172013-12-11 06:19:48174}
175
[email protected]8b9e52b2014-01-17 16:35:31176void SingleThreadProxy::SetNeedsUpdateLayers() {
[email protected]ccc08dc2014-01-30 07:33:20177 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers");
khushalsagarb7db1fe2015-11-12 00:51:27178 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22179 SetNeedsCommit();
[email protected]8b9e52b2014-01-17 16:35:31180}
181
enne98f3a6c2014-10-09 20:09:44182void SingleThreadProxy::DoCommit() {
[email protected]ccc08dc2014-01-30 07:33:20183 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit");
khushalsagarb7db1fe2015-11-12 00:51:27184 DCHECK(task_runner_provider_->IsMainThread());
enne98f3a6c2014-10-09 20:09:44185
[email protected]aeeedad2014-08-22 18:16:22186 layer_tree_host_->WillCommit();
caseq7d2f4c92015-02-04 16:43:27187 devtools_instrumentation::ScopedCommitTrace commit_task(
khushalsagarcebe4942016-09-07 23:27:01188 layer_tree_host_->GetId());
[email protected]aeeedad2014-08-22 18:16:22189
[email protected]a8a049c2013-03-11 23:27:06190 // Commit immediately.
191 {
khushalsagarb7db1fe2015-11-12 00:51:27192 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
193 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]f7c01c82013-07-02 22:58:46194
Walter Kormanaa326e42017-08-22 23:04:43195 host_impl_->ReadyToCommit();
196 host_impl_->BeginCommit();
[email protected]94f206c12012-08-25 00:09:14197
Walter Kormanaa326e42017-08-22 23:04:43198 if (host_impl_->EvictedUIResourcesExist())
khushalsagar8ec07402016-09-10 03:13:19199 layer_tree_host_->GetUIResourceManager()->RecreateUIResources();
[email protected]127bdc1a2013-09-11 01:44:48200
Walter Kormanaa326e42017-08-22 23:04:43201 layer_tree_host_->FinishCommitOnImplThread(host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14202
danakj3c3973b2015-08-25 21:50:18203 if (scheduler_on_impl_thread_)
204 scheduler_on_impl_thread_->DidCommit();
205
vmpstra840c6a2017-06-01 21:50:39206 IssueImageDecodeFinishedCallbacks();
Walter Kormanaa326e42017-08-22 23:04:43207 host_impl_->CommitComplete();
danakj3c3973b2015-08-25 21:50:18208
danakj68803fc2015-06-19 20:55:53209 // Commit goes directly to the active tree, but we need to synchronously
210 // "activate" the tree still during commit to satisfy any potential
211 // SetNextCommitWaitsForActivation calls. Unfortunately, the tree
212 // might not be ready to draw, so DidActivateSyncTree must set
213 // the flag to force the tree to not draw until textures are ready.
214 NotifyReadyToActivate();
enne98f3a6c2014-10-09 20:09:44215 }
216}
217
vmpstra840c6a2017-06-01 21:50:39218void SingleThreadProxy::IssueImageDecodeFinishedCallbacks() {
219 DCHECK(task_runner_provider_->IsImplThread());
220
Vladimir Levinbed5b372017-10-26 23:46:31221 layer_tree_host_->ImageDecodesFinished(
222 host_impl_->TakeCompletedImageDecodeRequests());
vmpstra840c6a2017-06-01 21:50:39223}
224
enne98f3a6c2014-10-09 20:09:44225void SingleThreadProxy::CommitComplete() {
danakj3c3973b2015-08-25 21:50:18226 // Commit complete happens on the main side after activate to satisfy any
227 // SetNextCommitWaitsForActivation calls.
Walter Kormanaa326e42017-08-22 23:04:43228 DCHECK(!host_impl_->pending_tree())
enne98f3a6c2014-10-09 20:09:44229 << "Activation is expected to have synchronously occurred by now.";
enne98f3a6c2014-10-09 20:09:44230
khushalsagarb7db1fe2015-11-12 00:51:27231 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]804c8982013-03-13 16:32:21232 layer_tree_host_->CommitComplete();
[email protected]aeeedad2014-08-22 18:16:22233 layer_tree_host_->DidBeginMainFrame();
[email protected]aeeedad2014-08-22 18:16:22234
[email protected]a8a049c2013-03-11 23:27:06235 next_frame_is_newly_committed_frame_ = true;
[email protected]94f206c12012-08-25 00:09:14236}
237
[email protected]a8a049c2013-03-11 23:27:06238void SingleThreadProxy::SetNeedsCommit() {
khushalsagarb7db1fe2015-11-12 00:51:27239 DCHECK(task_runner_provider_->IsMainThread());
danakj6c872fc02016-10-22 04:29:49240 single_thread_client_->RequestScheduleComposite();
danakjfcdaba122015-04-24 21:41:52241 if (commit_requested_)
242 return;
brianderson49e101d22015-04-29 00:05:33243 commit_requested_ = true;
khushalsagarb7db1fe2015-11-12 00:51:27244 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22245 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01246 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
[email protected]94f206c12012-08-25 00:09:14247}
248
[email protected]0023fc72014-01-10 20:05:06249void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) {
[email protected]ccc08dc2014-01-30 07:33:20250 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw");
khushalsagarb7db1fe2015-11-12 00:51:27251 DCHECK(task_runner_provider_->IsMainThread());
252 DebugScopedSetImplThread impl(task_runner_provider_);
Walter Kormanaa326e42017-08-22 23:04:43253 host_impl_->SetViewportDamage(damage_rect);
danakje41d978a2016-09-19 21:09:28254 SetNeedsRedrawOnImplThread();
[email protected]94f206c12012-08-25 00:09:14255}
256
[email protected]74b43cc2013-08-30 06:29:27257void SingleThreadProxy::SetNextCommitWaitsForActivation() {
enne98f3a6c2014-10-09 20:09:44258 // Activation always forced in commit, so nothing to do.
khushalsagarb7db1fe2015-11-12 00:51:27259 DCHECK(task_runner_provider_->IsMainThread());
[email protected]74b43cc2013-08-30 06:29:27260}
261
danakje6da4f12018-07-04 17:41:30262bool SingleThreadProxy::RequestedAnimatePending() {
David Bokaneaa5cc82018-10-12 15:50:40263 return animate_requested_ || commit_requested_ || needs_impl_frame_;
danakje6da4f12018-07-04 17:41:30264}
265
[email protected]a8a049c2013-03-11 23:27:06266void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
khushalsagarb7db1fe2015-11-12 00:51:27267 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22268 // Deferring commits only makes sense if there's a scheduler.
269 if (!scheduler_on_impl_thread_)
270 return;
271 if (defer_commits_ == defer_commits)
272 return;
273
274 if (defer_commits)
275 TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this);
276 else
277 TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this);
278
279 defer_commits_ = defer_commits;
simonhongc6309f792015-01-31 15:47:15280 scheduler_on_impl_thread_->SetDeferCommits(defer_commits);
[email protected]6b16679e2012-10-27 00:44:28281}
282
[email protected]174c6d42014-08-12 01:43:06283bool SingleThreadProxy::CommitRequested() const {
khushalsagarb7db1fe2015-11-12 00:51:27284 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22285 return commit_requested_;
[email protected]174c6d42014-08-12 01:43:06286}
[email protected]a8a049c2013-03-11 23:27:06287
[email protected]a8a049c2013-03-11 23:27:06288void SingleThreadProxy::Stop() {
289 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
khushalsagarb7db1fe2015-11-12 00:51:27290 DCHECK(task_runner_provider_->IsMainThread());
[email protected]a8a049c2013-03-11 23:27:06291 {
khushalsagarb7db1fe2015-11-12 00:51:27292 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
293 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06294
sunnypsda928f0a2016-10-08 00:32:53295 // Prevent the scheduler from performing actions while we're in an
296 // inconsistent state.
297 if (scheduler_on_impl_thread_)
298 scheduler_on_impl_thread_->Stop();
danakjc7afae52017-06-20 21:12:41299 // Take away the LayerTreeFrameSink before destroying things so it doesn't
danakj1120f4c2016-09-15 02:05:32300 // try to call into its client mid-shutdown.
Walter Kormanaa326e42017-08-22 23:04:43301 host_impl_->ReleaseLayerTreeFrameSink();
Khushal7899efd2018-01-08 18:01:16302
303 // It is important to destroy LTHI before the Scheduler since it can make
304 // callbacks that access it during destruction cleanup.
Walter Kormanaa326e42017-08-22 23:04:43305 host_impl_ = nullptr;
Khushal7899efd2018-01-08 18:01:16306 scheduler_on_impl_thread_ = nullptr;
[email protected]a8a049c2013-03-11 23:27:06307 }
sunnypsda928f0a2016-10-08 00:32:53308 layer_tree_host_ = nullptr;
[email protected]a8a049c2013-03-11 23:27:06309}
310
flackrf54e9b42016-05-31 15:20:10311void SingleThreadProxy::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) {
312 DCHECK(task_runner_provider_->IsMainThread());
313 DebugScopedSetImplThread impl(task_runner_provider_);
Walter Kormanaa326e42017-08-22 23:04:43314 host_impl_->SetLayerTreeMutator(std::move(mutator));
flackrf54e9b42016-05-31 15:20:10315}
316
[email protected]3d9f7432013-04-06 00:35:18317void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
sunnypsad3235e2016-08-09 04:57:52318 TRACE_EVENT1("cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw",
319 can_draw);
khushalsagarb7db1fe2015-11-12 00:51:27320 DCHECK(task_runner_provider_->IsImplThread());
[email protected]aeeedad2014-08-22 18:16:22321 if (scheduler_on_impl_thread_)
322 scheduler_on_impl_thread_->SetCanDraw(can_draw);
[email protected]3d9f7432013-04-06 00:35:18323}
324
[email protected]4f48f6e2013-08-27 06:33:38325void SingleThreadProxy::NotifyReadyToActivate() {
enne98f3a6c2014-10-09 20:09:44326 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate");
khushalsagarb7db1fe2015-11-12 00:51:27327 DebugScopedSetImplThread impl(task_runner_provider_);
rogerm8aeea932017-04-19 21:26:57328 if (scheduler_on_impl_thread_)
329 scheduler_on_impl_thread_->NotifyReadyToActivate();
[email protected]4f48f6e2013-08-27 06:33:38330}
331
ernstmdfac03e2014-11-11 20:18:05332void SingleThreadProxy::NotifyReadyToDraw() {
weiliangc8dac5a62015-04-02 06:12:35333 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToDraw");
khushalsagarb7db1fe2015-11-12 00:51:27334 DebugScopedSetImplThread impl(task_runner_provider_);
weiliangc8dac5a62015-04-02 06:12:35335 if (scheduler_on_impl_thread_)
336 scheduler_on_impl_thread_->NotifyReadyToDraw();
ernstmdfac03e2014-11-11 20:18:05337}
338
[email protected]c1bb5af2013-03-13 19:06:27339void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
danakj6c872fc02016-10-22 04:29:49340 single_thread_client_->RequestScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22341 if (scheduler_on_impl_thread_)
342 scheduler_on_impl_thread_->SetNeedsRedraw();
[email protected]a8a049c2013-03-11 23:27:06343}
344
danakja18e826a2015-12-03 00:27:03345void SingleThreadProxy::SetNeedsOneBeginImplFrameOnImplThread() {
346 TRACE_EVENT0("cc",
347 "SingleThreadProxy::SetNeedsOneBeginImplFrameOnImplThread");
danakj6c872fc02016-10-22 04:29:49348 single_thread_client_->RequestScheduleComposite();
mithro719bf6792014-11-10 15:36:47349 if (scheduler_on_impl_thread_)
danakja18e826a2015-12-03 00:27:03350 scheduler_on_impl_thread_->SetNeedsOneBeginImplFrame();
David Bokaneaa5cc82018-10-12 15:50:40351 needs_impl_frame_ = true;
[email protected]43b8f982014-04-30 21:24:33352}
353
vmiura59ea9b4042014-12-09 20:50:39354void SingleThreadProxy::SetNeedsPrepareTilesOnImplThread() {
355 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsPrepareTilesOnImplThread");
enne98f3a6c2014-10-09 20:09:44356 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39357 scheduler_on_impl_thread_->SetNeedsPrepareTiles();
[email protected]c48536a52013-09-14 00:02:08358}
359
[email protected]c1bb5af2013-03-13 19:06:27360void SingleThreadProxy::SetNeedsCommitOnImplThread() {
danakj6c872fc02016-10-22 04:29:49361 single_thread_client_->RequestScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22362 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01363 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
David Bokaneaa5cc82018-10-12 15:50:40364 commit_requested_ = true;
[email protected]a8a049c2013-03-11 23:27:06365}
366
sunnyps7d073dc2015-04-16 23:29:12367void SingleThreadProxy::SetVideoNeedsBeginFrames(bool needs_begin_frames) {
368 TRACE_EVENT1("cc", "SingleThreadProxy::SetVideoNeedsBeginFrames",
369 "needs_begin_frames", needs_begin_frames);
370 // In tests the layer tree is destroyed after the scheduler is.
371 if (scheduler_on_impl_thread_)
372 scheduler_on_impl_thread_->SetVideoNeedsBeginFrames(needs_begin_frames);
373}
374
[email protected]c1bb5af2013-03-13 19:06:27375void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
loysoc601b7b82016-11-10 02:56:44376 std::unique_ptr<MutatorEvents> events) {
[email protected]ccc08dc2014-01-30 07:33:20377 TRACE_EVENT0(
378 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
khushalsagarb7db1fe2015-11-12 00:51:27379 DCHECK(task_runner_provider_->IsImplThread());
380 DebugScopedSetMainThread main(task_runner_provider_);
danakja04855a2015-11-18 20:39:10381 layer_tree_host_->SetAnimationEvents(std::move(events));
[email protected]a8a049c2013-03-11 23:27:06382}
383
Xida Chend8bb3b22017-10-26 17:14:52384size_t SingleThreadProxy::CompositedAnimationsCount() const {
385 return 0;
386}
387
388size_t SingleThreadProxy::MainThreadAnimationsCount() const {
389 return 0;
390}
391
Stephen McGruer1619b422018-02-20 18:46:55392bool SingleThreadProxy::CurrentFrameHadRAF() const {
393 return false;
394}
395
396bool SingleThreadProxy::NextFrameHasPendingRAF() const {
397 return false;
398}
399
sunnypsad3235e2016-08-09 04:57:52400bool SingleThreadProxy::IsInsideDraw() {
401 return inside_draw_;
402}
[email protected]a8a049c2013-03-11 23:27:06403
enne98f3a6c2014-10-09 20:09:44404void SingleThreadProxy::DidActivateSyncTree() {
danakj68803fc2015-06-19 20:55:53405 CommitComplete();
enne98f3a6c2014-10-09 20:09:44406}
407
brianderson68749812015-07-07 22:39:39408void SingleThreadProxy::WillPrepareTiles() {
khushalsagarb7db1fe2015-11-12 00:51:27409 DCHECK(task_runner_provider_->IsImplThread());
brianderson68749812015-07-07 22:39:39410 if (scheduler_on_impl_thread_)
411 scheduler_on_impl_thread_->WillPrepareTiles();
412}
413
vmiura59ea9b4042014-12-09 20:50:39414void SingleThreadProxy::DidPrepareTiles() {
khushalsagarb7db1fe2015-11-12 00:51:27415 DCHECK(task_runner_provider_->IsImplThread());
enne98f3a6c2014-10-09 20:09:44416 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39417 scheduler_on_impl_thread_->DidPrepareTiles();
enne98f3a6c2014-10-09 20:09:44418}
419
rouslanf7ebd8832015-01-22 01:54:14420void SingleThreadProxy::DidCompletePageScaleAnimationOnImplThread() {
421 layer_tree_host_->DidCompletePageScaleAnimation();
422}
423
danakjc7afae52017-06-20 21:12:41424void SingleThreadProxy::DidLoseLayerTreeFrameSinkOnImplThread() {
danakj1120f4c2016-09-15 02:05:32425 TRACE_EVENT0("cc",
danakjc7afae52017-06-20 21:12:41426 "SingleThreadProxy::DidLoseLayerTreeFrameSinkOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22427 {
khushalsagarb7db1fe2015-11-12 00:51:27428 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22429 // This must happen before we notify the scheduler as it may try to recreate
430 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE.
danakjc7afae52017-06-20 21:12:41431 layer_tree_host_->DidLoseLayerTreeFrameSink();
[email protected]aeeedad2014-08-22 18:16:22432 }
danakjc7afae52017-06-20 21:12:41433 single_thread_client_->DidLoseLayerTreeFrameSink();
[email protected]aeeedad2014-08-22 18:16:22434 if (scheduler_on_impl_thread_)
danakjc7afae52017-06-20 21:12:41435 scheduler_on_impl_thread_->DidLoseLayerTreeFrameSink();
436 layer_tree_frame_sink_lost_ = true;
[email protected]4d7e46a2013-11-08 05:33:40437}
438
Fady Samuelc645ffe2017-07-24 17:28:20439void SingleThreadProxy::SetBeginFrameSource(viz::BeginFrameSource* source) {
enne19c108582016-04-14 03:35:32440 if (scheduler_on_impl_thread_)
441 scheduler_on_impl_thread_->SetBeginFrameSource(source);
442}
443
danakj9d124422016-10-14 03:15:08444void SingleThreadProxy::DidReceiveCompositorFrameAckOnImplThread() {
miletusfed8c43b2015-01-26 20:04:52445 TRACE_EVENT0("cc,benchmark",
danakj9d124422016-10-14 03:15:08446 "SingleThreadProxy::DidReceiveCompositorFrameAckOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22447 if (scheduler_on_impl_thread_)
danakj9d124422016-10-14 03:15:08448 scheduler_on_impl_thread_->DidReceiveCompositorFrameAck();
Karolina Soltys4d60b402018-10-01 19:28:20449 if (layer_tree_host_->GetSettings().send_compositor_frame_ack) {
450 // We do a PostTask here because freeing resources in some cases (such as in
451 // TextureLayer) is PostTasked and we want to make sure ack is received
452 // after resources are returned.
453 task_runner_provider_->MainThreadTaskRunner()->PostTask(
454 FROM_HERE, base::Bind(&SingleThreadProxy::DidReceiveCompositorFrameAck,
455 frame_sink_bound_weak_ptr_));
456 }
[email protected]493067512012-09-19 23:34:10457}
458
danakjc7afae52017-06-20 21:12:41459void SingleThreadProxy::OnDrawForLayerTreeFrameSink(
James Wallace-Leefbb0e3362018-06-18 23:57:47460 bool resourceless_software_draw,
461 bool skip_draw) {
sunnypseab5ac92015-04-02 20:26:13462 NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor.";
463}
464
Khushal8360fc92017-07-26 01:53:25465void SingleThreadProxy::NeedsImplSideInvalidation(
466 bool needs_first_draw_on_activation) {
Khushal4b6c41882018-02-16 09:02:10467 if (scheduler_on_impl_thread_) {
468 scheduler_on_impl_thread_->SetNeedsImplSideInvalidation(
469 needs_first_draw_on_activation);
470 }
khushalsagard3b8827d2017-02-18 18:42:54471}
472
vmpstra840c6a2017-06-01 21:50:39473void SingleThreadProxy::NotifyImageDecodeRequestFinished() {
474 // If we don't have a scheduler, then just issue the callbacks here.
475 // Otherwise, schedule a commit.
476 if (!scheduler_on_impl_thread_) {
477 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
478 DebugScopedSetImplThread impl(task_runner_provider_);
479
480 IssueImageDecodeFinishedCallbacks();
481 return;
482 }
483 SetNeedsCommitOnImplThread();
484}
485
Scott Violete979c012017-12-08 00:18:16486void SingleThreadProxy::DidPresentCompositorFrameOnImplThread(
Sadrul Habib Chowdhury3d4df2e82018-06-02 05:18:00487 uint32_t frame_token,
488 std::vector<LayerTreeHost::PresentationTimeCallback> callbacks,
Sadrul Habib Chowdhuryb62a97302018-06-06 03:33:48489 const gfx::PresentationFeedback& feedback) {
Sadrul Habib Chowdhury3d4df2e82018-06-02 05:18:00490 layer_tree_host_->DidPresentCompositorFrame(frame_token, std::move(callbacks),
Sadrul Habib Chowdhuryb62a97302018-06-06 03:33:48491 feedback);
Scott Violete979c012017-12-08 00:18:16492}
493
Dan Elphick95929fd52017-06-13 09:15:07494void SingleThreadProxy::RequestBeginMainFrameNotExpected(bool new_state) {
495 if (scheduler_on_impl_thread_) {
496 scheduler_on_impl_thread_->SetMainThreadWantsBeginMainFrameNotExpected(
497 new_state);
498 }
499}
500
Khushal4b6c41882018-02-16 09:02:10501void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time,
502 bool raster) {
miletusfed8c43b2015-01-26 20:04:52503 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately");
khushalsagarb7db1fe2015-11-12 00:51:27504 DCHECK(task_runner_provider_->IsMainThread());
mithro51693e382015-05-07 23:52:41505#if DCHECK_IS_ON()
mithroc76d70312015-05-04 23:51:13506 DCHECK(!inside_impl_frame_);
mithro51693e382015-05-07 23:52:41507#endif
jbauman399aec1a2014-10-25 02:33:32508 base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true);
509
danakjc7afae52017-06-20 21:12:41510 if (layer_tree_frame_sink_lost_) {
511 RequestNewLayerTreeFrameSink();
512 // RequestNewLayerTreeFrameSink could have synchronously created an output
jbauman399aec1a2014-10-25 02:33:32513 // surface, so check again before returning.
danakjc7afae52017-06-20 21:12:41514 if (layer_tree_frame_sink_lost_)
jbauman399aec1a2014-10-25 02:33:32515 return;
516 }
[email protected]51f81da2014-05-16 21:29:26517
Fady Samuelc296f5fb2017-07-21 04:02:19518 viz::BeginFrameArgs begin_frame_args(viz::BeginFrameArgs::Create(
519 BEGINFRAME_FROM_HERE, viz::BeginFrameArgs::kManualSourceId, 1,
520 frame_begin_time, base::TimeTicks(),
521 viz::BeginFrameArgs::DefaultInterval(), viz::BeginFrameArgs::NORMAL));
mithroc76d70312015-05-04 23:51:13522
523 // Start the impl frame.
enne98f3a6c2014-10-09 20:09:44524 {
khushalsagarb7db1fe2015-11-12 00:51:27525 DebugScopedSetImplThread impl(task_runner_provider_);
mithroc76d70312015-05-04 23:51:13526 WillBeginImplFrame(begin_frame_args);
527 }
528
529 // Run the "main thread" and get it to commit.
530 {
mithro51693e382015-05-07 23:52:41531#if DCHECK_IS_ON()
mithroc76d70312015-05-04 23:51:13532 DCHECK(inside_impl_frame_);
mithro51693e382015-05-07 23:52:41533#endif
danakje6da4f12018-07-04 17:41:30534 animate_requested_ = false;
David Bokaneaa5cc82018-10-12 15:50:40535 needs_impl_frame_ = false;
danakje6da4f12018-07-04 17:41:30536 // Prevent new commits from being requested inside DoBeginMainFrame.
537 // Note: We do not want to prevent SetNeedsAnimate from requesting
538 // a commit here.
539 commit_requested_ = true;
enne98f3a6c2014-10-09 20:09:44540 DoBeginMainFrame(begin_frame_args);
danakje6da4f12018-07-04 17:41:30541 commit_requested_ = false;
danakj97660d92017-03-27 14:11:49542 DoPainting();
enne98f3a6c2014-10-09 20:09:44543 DoCommit();
[email protected]e0341352013-04-06 05:01:20544
khushalsagar8297ae992016-09-14 20:51:23545 DCHECK_EQ(
546 0u,
547 layer_tree_host_->GetSwapPromiseManager()->num_queued_swap_promises())
enne98f3a6c2014-10-09 20:09:44548 << "Commit should always succeed and transfer promises.";
549 }
550
mithroc76d70312015-05-04 23:51:13551 // Finish the impl frame.
enne98f3a6c2014-10-09 20:09:44552 {
khushalsagarb7db1fe2015-11-12 00:51:27553 DebugScopedSetImplThread impl(task_runner_provider_);
Walter Kormanaa326e42017-08-22 23:04:43554 host_impl_->ActivateSyncTree();
Khushal4b6c41882018-02-16 09:02:10555 if (raster) {
556 host_impl_->PrepareTiles();
557 host_impl_->SynchronouslyInitializeAllTiles();
558 }
enne69277cb2014-10-29 23:03:40559
danakj12e2f6e2015-08-19 22:25:44560 // TODO(danakj): Don't do this last... we prepared the wrong things. D:
Walter Kormanaa326e42017-08-22 23:04:43561 host_impl_->Animate();
mithro719bf6792014-11-10 15:36:47562
Khushal4b6c41882018-02-16 09:02:10563 if (raster) {
564 LayerTreeHostImpl::FrameData frame;
Sadrul Habib Chowdhury4a7940b2018-06-22 16:45:14565 frame.begin_frame_ack = viz::BeginFrameAck(begin_frame_args, true);
Khushal4b6c41882018-02-16 09:02:10566 DoComposite(&frame);
567 }
enne98f3a6c2014-10-09 20:09:44568
569 // DoComposite could abort, but because this is a synchronous composite
570 // another draw will never be scheduled, so break remaining promises.
Walter Kormanaa326e42017-08-22 23:04:43571 host_impl_->active_tree()->BreakSwapPromises(SwapPromise::SWAP_FAILS);
mithroc76d70312015-05-04 23:51:13572
mithro51693e382015-05-07 23:52:41573 DidFinishImplFrame();
enne98f3a6c2014-10-09 20:09:44574 }
[email protected]74d9063c2013-01-18 03:14:47575}
576
[email protected]5d8bec72014-07-03 03:03:11577bool SingleThreadProxy::SupportsImplScrolling() const {
578 return false;
579}
580
[email protected]3d9f7432013-04-06 00:35:18581bool SingleThreadProxy::ShouldComposite() const {
khushalsagarb7db1fe2015-11-12 00:51:27582 DCHECK(task_runner_provider_->IsImplThread());
Walter Kormanaa326e42017-08-22 23:04:43583 return host_impl_->visible() && host_impl_->CanDraw();
[email protected]3d9f7432013-04-06 00:35:18584}
585
danakjc7afae52017-06-20 21:12:41586void SingleThreadProxy::ScheduleRequestNewLayerTreeFrameSink() {
587 if (layer_tree_frame_sink_creation_callback_.IsCancelled() &&
588 !layer_tree_frame_sink_creation_requested_) {
589 layer_tree_frame_sink_creation_callback_.Reset(
590 base::Bind(&SingleThreadProxy::RequestNewLayerTreeFrameSink,
jbauman8ab0f9e2014-10-15 02:30:34591 weak_factory_.GetWeakPtr()));
khushalsagarb7db1fe2015-11-12 00:51:27592 task_runner_provider_->MainThreadTaskRunner()->PostTask(
danakjc7afae52017-06-20 21:12:41593 FROM_HERE, layer_tree_frame_sink_creation_callback_.callback());
jbauman8ab0f9e2014-10-15 02:30:34594 }
595}
596
mithro248d1722015-05-05 05:23:45597DrawResult SingleThreadProxy::DoComposite(LayerTreeHostImpl::FrameData* frame) {
[email protected]ccc08dc2014-01-30 07:33:20598 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite");
[email protected]04049fc2013-05-01 03:13:20599
enne98f3a6c2014-10-09 20:09:44600 DrawResult draw_result;
601 bool draw_frame;
[email protected]a8a049c2013-03-11 23:27:06602 {
khushalsagarb7db1fe2015-11-12 00:51:27603 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06604 base::AutoReset<bool> mark_inside(&inside_draw_, true);
605
[email protected]3d9f7432013-04-06 00:35:18606 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
607 // frame, so can only be used when such a frame is possible. Since
608 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
609 // CanDraw() as well.
[email protected]2aae96792014-05-15 23:10:50610 if (!ShouldComposite()) {
[email protected]aeeedad2014-08-22 18:16:22611 return DRAW_ABORTED_CANT_DRAW;
[email protected]3d9f7432013-04-06 00:35:18612 }
[email protected]a8a049c2013-03-11 23:27:06613
danakj097919e72016-09-07 19:50:55614 // This CapturePostTasks should be destroyed before
615 // DidCommitAndDrawFrame() is called since that goes out to the
616 // embedder, and we want the embedder to receive its callbacks before that.
617 // NOTE: This maintains consistent ordering with the ThreadProxy since
618 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
619 // there as the main thread is not blocked, so any posted tasks inside
620 // the swap buffers will execute first.
621 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
danakj097919e72016-09-07 19:50:55622
Walter Kormanaa326e42017-08-22 23:04:43623 draw_result = host_impl_->PrepareToDraw(frame);
enne98f3a6c2014-10-09 20:09:44624 draw_frame = draw_result == DRAW_SUCCESS;
robliao27728e62015-03-21 07:39:34625 if (draw_frame) {
Walter Kormanaa326e42017-08-22 23:04:43626 if (host_impl_->DrawLayers(frame)) {
danakj097919e72016-09-07 19:50:55627 if (scheduler_on_impl_thread_)
danakjc7afae52017-06-20 21:12:41628 // Drawing implies we submitted a frame to the LayerTreeFrameSink.
danakj9d124422016-10-14 03:15:08629 scheduler_on_impl_thread_->DidSubmitCompositorFrame();
danakj6c872fc02016-10-22 04:29:49630 single_thread_client_->DidSubmitCompositorFrame();
danakj097919e72016-09-07 19:50:55631 }
robliao27728e62015-03-21 07:39:34632 }
Walter Kormanaa326e42017-08-22 23:04:43633 host_impl_->DidDrawAllLayers(*frame);
[email protected]a8a049c2013-03-11 23:27:06634
danakj097919e72016-09-07 19:50:55635 bool start_ready_animations = draw_frame;
Walter Kormanaa326e42017-08-22 23:04:43636 host_impl_->UpdateAnimationState(start_ready_animations);
[email protected]aeeedad2014-08-22 18:16:22637 }
638 DidCommitAndDrawFrame();
639
enne98f3a6c2014-10-09 20:09:44640 return draw_result;
[email protected]a8a049c2013-03-11 23:27:06641}
642
[email protected]aeeedad2014-08-22 18:16:22643void SingleThreadProxy::DidCommitAndDrawFrame() {
[email protected]a8a049c2013-03-11 23:27:06644 if (next_frame_is_newly_committed_frame_) {
khushalsagarb7db1fe2015-11-12 00:51:27645 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06646 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21647 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06648 }
649}
650
[email protected]4ea293f72014-08-13 03:03:17651bool SingleThreadProxy::MainFrameWillHappenForTesting() {
danakjfcdaba122015-04-24 21:41:52652 if (!scheduler_on_impl_thread_)
653 return false;
654 return scheduler_on_impl_thread_->MainFrameForTestingWillHappen();
[email protected]4ea293f72014-08-13 03:03:17655}
[email protected]a8a049c2013-03-11 23:27:06656
Fady Samueld26f7fb2018-06-19 04:13:37657void SingleThreadProxy::ClearHistory() {
Khushal2f9cdf22018-01-08 21:47:08658 DCHECK(task_runner_provider_->IsImplThread());
659 if (scheduler_on_impl_thread_)
Fady Samueld26f7fb2018-06-19 04:13:37660 scheduler_on_impl_thread_->ClearHistory();
Khushal2f9cdf22018-01-08 21:47:08661}
662
jonrossa2ff4f82018-02-16 17:27:46663void SingleThreadProxy::SetRenderFrameObserver(
664 std::unique_ptr<RenderFrameMetadataObserver> observer) {
jonrossc1877d6d2018-02-21 00:07:31665 host_impl_->SetRenderFrameObserver(std::move(observer));
jonrossa2ff4f82018-02-16 17:27:46666}
667
David Bokan1e37ebf2018-10-16 13:53:37668void SingleThreadProxy::UpdateBrowserControlsState(
669 BrowserControlsState constraints,
670 BrowserControlsState current,
671 bool animate) {
672 host_impl_->browser_controls_manager()->UpdateBrowserControlsState(
673 constraints, current, animate);
674}
675
James Wallace-Leee71cf582018-01-29 22:24:23676bool SingleThreadProxy::WillBeginImplFrame(const viz::BeginFrameArgs& args) {
danakja18e826a2015-12-03 00:27:03677 DebugScopedSetImplThread impl(task_runner_provider_);
mithro51693e382015-05-07 23:52:41678#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02679 DCHECK(!inside_impl_frame_)
680 << "WillBeginImplFrame called while already inside an impl frame!";
681 inside_impl_frame_ = true;
mithro51693e382015-05-07 23:52:41682#endif
James Wallace-Leee71cf582018-01-29 22:24:23683 return host_impl_->WillBeginImplFrame(args);
[email protected]aeeedad2014-08-22 18:16:22684}
685
brianderson266dc3a2015-11-12 03:16:40686void SingleThreadProxy::ScheduledActionSendBeginMainFrame(
Fady Samuelc296f5fb2017-07-21 04:02:19687 const viz::BeginFrameArgs& begin_frame_args) {
[email protected]aeeedad2014-08-22 18:16:22688 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame");
sunnypsad3235e2016-08-09 04:57:52689#if DCHECK_IS_ON()
[email protected]aeeedad2014-08-22 18:16:22690 // Although this proxy is single-threaded, it's problematic to synchronously
691 // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This
692 // could cause a commit to occur in between a series of SetNeedsCommit calls
693 // (i.e. property modifications) causing some to fall on one frame and some to
694 // fall on the next. Doing it asynchronously instead matches the semantics of
695 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a
696 // synchronous commit.
mithro69fd3bb52015-05-01 03:45:02697 DCHECK(inside_impl_frame_)
698 << "BeginMainFrame should only be sent inside a BeginImplFrame";
mithro51693e382015-05-07 23:52:41699#endif
mithro69fd3bb52015-05-01 03:45:02700
khushalsagarb7db1fe2015-11-12 00:51:27701 task_runner_provider_->MainThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22702 FROM_HERE, base::BindOnce(&SingleThreadProxy::BeginMainFrame,
703 weak_factory_.GetWeakPtr(), begin_frame_args));
Walter Kormanaa326e42017-08-22 23:04:43704 host_impl_->DidSendBeginMainFrame();
[email protected]aeeedad2014-08-22 18:16:22705}
706
rmcilroy0a19362a2015-02-18 12:34:25707void SingleThreadProxy::SendBeginMainFrameNotExpectedSoon() {
708 layer_tree_host_->BeginMainFrameNotExpectedSoon();
709}
710
delphick9db74aa2017-05-05 10:20:49711void SingleThreadProxy::ScheduledActionBeginMainFrameNotExpectedUntil(
712 base::TimeTicks time) {
713 layer_tree_host_->BeginMainFrameNotExpectedUntil(time);
714}
715
Fady Samuelc296f5fb2017-07-21 04:02:19716void SingleThreadProxy::BeginMainFrame(
717 const viz::BeginFrameArgs& begin_frame_args) {
Brian Anderson242b9b02017-12-06 21:06:26718 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous
719 // commit.
720 ScopedAbortRemainingSwapPromises swap_promise_checker(
721 layer_tree_host_->GetSwapPromiseManager());
722
brianderson21aef162015-11-11 05:12:23723 if (scheduler_on_impl_thread_) {
724 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(
725 base::TimeTicks::Now());
726 }
727
danakjfcdaba122015-04-24 21:41:52728 commit_requested_ = false;
David Bokaneaa5cc82018-10-12 15:50:40729 needs_impl_frame_ = false;
brianderson49e101d22015-04-29 00:05:33730 animate_requested_ = false;
danakjfcdaba122015-04-24 21:41:52731
[email protected]aeeedad2014-08-22 18:16:22732 if (defer_commits_) {
simonhongc6309f792015-01-31 15:47:15733 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit",
734 TRACE_EVENT_SCOPE_THREAD);
735 BeginMainFrameAbortedOnImplThread(
736 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT);
[email protected]aeeedad2014-08-22 18:16:22737 return;
738 }
739
khushalsagarcebe4942016-09-07 23:27:01740 if (!layer_tree_host_->IsVisible()) {
[email protected]aeeedad2014-08-22 18:16:22741 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD);
mithrof7a21502014-12-17 03:24:48742 BeginMainFrameAbortedOnImplThread(
743 CommitEarlyOutReason::ABORTED_NOT_VISIBLE);
[email protected]aeeedad2014-08-22 18:16:22744 return;
745 }
746
danakjfcdaba122015-04-24 21:41:52747 // Prevent new commits from being requested inside DoBeginMainFrame.
brianderson49e101d22015-04-29 00:05:33748 // Note: We do not want to prevent SetNeedsAnimate from requesting
749 // a commit here.
danakjfcdaba122015-04-24 21:41:52750 commit_requested_ = true;
751
enne98f3a6c2014-10-09 20:09:44752 DoBeginMainFrame(begin_frame_args);
danakj97660d92017-03-27 14:11:49753
754 // New commits requested inside UpdateLayers should be respected.
755 commit_requested_ = false;
756
757 // At this point the main frame may have deferred commits to avoid committing
758 // right now.
Eric Seckler8af8c0e52018-01-17 23:45:53759 if (defer_commits_ || begin_frame_args.animate_only) {
danakj97660d92017-03-27 14:11:49760 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit_InsideBeginMainFrame",
761 TRACE_EVENT_SCOPE_THREAD);
762 BeginMainFrameAbortedOnImplThread(
763 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT);
764 layer_tree_host_->DidBeginMainFrame();
765 return;
766 }
767
Brian Anderson242b9b02017-12-06 21:06:26768 // Queue the LATENCY_BEGIN_FRAME_UI_MAIN_COMPONENT swap promise only once we
769 // know we will commit since QueueSwapPromise itself requests a commit.
770 ui::LatencyInfo new_latency_info(ui::SourceEventType::FRAME);
771 new_latency_info.AddLatencyNumberWithTimestamp(
Sadrul Habib Chowdhury41154dc02018-06-09 04:25:01772 ui::LATENCY_BEGIN_FRAME_UI_MAIN_COMPONENT, begin_frame_args.frame_time,
Navid Zolghadr5870ee112018-05-18 19:08:30773 1);
Brian Anderson242b9b02017-12-06 21:06:26774 layer_tree_host_->QueueSwapPromise(
775 std::make_unique<LatencyInfoSwapPromise>(new_latency_info));
776
danakj97660d92017-03-27 14:11:49777 DoPainting();
enne98f3a6c2014-10-09 20:09:44778}
779
780void SingleThreadProxy::DoBeginMainFrame(
Fady Samuelc296f5fb2017-07-21 04:02:19781 const viz::BeginFrameArgs& begin_frame_args) {
Khushal4b6c41882018-02-16 09:02:10782 // The impl-side scroll deltas may be manipulated directly via the
783 // InputHandler on the UI thread and the scale deltas may change when they are
784 // clamped on the impl thread.
tapted4b70c522016-08-13 09:09:32785 std::unique_ptr<ScrollAndScaleSet> scroll_info =
Walter Kormanaa326e42017-08-22 23:04:43786 host_impl_->ProcessScrollDeltas();
tapted4b70c522016-08-13 09:09:32787 layer_tree_host_->ApplyScrollAndScale(scroll_info.get());
788
enne98f3a6c2014-10-09 20:09:44789 layer_tree_host_->WillBeginMainFrame();
790 layer_tree_host_->BeginMainFrame(begin_frame_args);
791 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time);
Robert Flack3ef2ffb2018-09-06 20:38:20792 layer_tree_host_->RequestMainFrameUpdate();
danakj97660d92017-03-27 14:11:49793}
enne98f3a6c2014-10-09 20:09:44794
danakj97660d92017-03-27 14:11:49795void SingleThreadProxy::DoPainting() {
danakj5f46636a2015-06-19 00:01:40796 layer_tree_host_->UpdateLayers();
enne98f3a6c2014-10-09 20:09:44797
mithrof7a21502014-12-17 03:24:48798 // TODO(enne): SingleThreadProxy does not support cancelling commits yet,
799 // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside
800 // thread_proxy.cc
brianderson21aef162015-11-11 05:12:23801 if (scheduler_on_impl_thread_)
enne98f3a6c2014-10-09 20:09:44802 scheduler_on_impl_thread_->NotifyReadyToCommit();
[email protected]aeeedad2014-08-22 18:16:22803}
804
mithrof7a21502014-12-17 03:24:48805void SingleThreadProxy::BeginMainFrameAbortedOnImplThread(
806 CommitEarlyOutReason reason) {
khushalsagarb7db1fe2015-11-12 00:51:27807 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22808 DCHECK(scheduler_on_impl_thread_->CommitPending());
Walter Kormanaa326e42017-08-22 23:04:43809 DCHECK(!host_impl_->pending_tree());
[email protected]aeeedad2014-08-22 18:16:22810
sunnypsad3235e2016-08-09 04:57:52811 std::vector<std::unique_ptr<SwapPromise>> empty_swap_promises;
Walter Kormanaa326e42017-08-22 23:04:43812 host_impl_->BeginMainFrameAborted(reason, std::move(empty_swap_promises));
mithrof7a21502014-12-17 03:24:48813 scheduler_on_impl_thread_->BeginMainFrameAborted(reason);
[email protected]aeeedad2014-08-22 18:16:22814}
815
danakj9d124422016-10-14 03:15:08816DrawResult SingleThreadProxy::ScheduledActionDrawIfPossible() {
khushalsagarb7db1fe2015-11-12 00:51:27817 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22818 LayerTreeHostImpl::FrameData frame;
esecklerdde665f2017-03-07 20:19:27819 frame.begin_frame_ack =
820 scheduler_on_impl_thread_->CurrentBeginFrameAckForActiveTree();
mithro248d1722015-05-05 05:23:45821 return DoComposite(&frame);
[email protected]aeeedad2014-08-22 18:16:22822}
823
danakj9d124422016-10-14 03:15:08824DrawResult SingleThreadProxy::ScheduledActionDrawForced() {
[email protected]aeeedad2014-08-22 18:16:22825 NOTREACHED();
826 return INVALID_RESULT;
827}
828
829void SingleThreadProxy::ScheduledActionCommit() {
khushalsagarb7db1fe2015-11-12 00:51:27830 DebugScopedSetMainThread main(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44831 DoCommit();
[email protected]aeeedad2014-08-22 18:16:22832}
833
[email protected]aeeedad2014-08-22 18:16:22834void SingleThreadProxy::ScheduledActionActivateSyncTree() {
khushalsagarb7db1fe2015-11-12 00:51:27835 DebugScopedSetImplThread impl(task_runner_provider_);
Walter Kormanaa326e42017-08-22 23:04:43836 host_impl_->ActivateSyncTree();
[email protected]aeeedad2014-08-22 18:16:22837}
838
danakjc7afae52017-06-20 21:12:41839void SingleThreadProxy::ScheduledActionBeginLayerTreeFrameSinkCreation() {
khushalsagarb7db1fe2015-11-12 00:51:27840 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22841 DCHECK(scheduler_on_impl_thread_);
842 // If possible, create the output surface in a post task. Synchronously
843 // creating the output surface makes tests more awkward since this differs
844 // from the ThreadProxy behavior. However, sometimes there is no
845 // task runner.
khushalsagarb7db1fe2015-11-12 00:51:27846 if (task_runner_provider_->MainThreadTaskRunner()) {
danakjc7afae52017-06-20 21:12:41847 ScheduleRequestNewLayerTreeFrameSink();
[email protected]aeeedad2014-08-22 18:16:22848 } else {
danakjc7afae52017-06-20 21:12:41849 RequestNewLayerTreeFrameSink();
[email protected]aeeedad2014-08-22 18:16:22850 }
851}
852
vmiura59ea9b4042014-12-09 20:50:39853void SingleThreadProxy::ScheduledActionPrepareTiles() {
854 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionPrepareTiles");
khushalsagarb7db1fe2015-11-12 00:51:27855 DebugScopedSetImplThread impl(task_runner_provider_);
Walter Kormanaa326e42017-08-22 23:04:43856 host_impl_->PrepareTiles();
[email protected]aeeedad2014-08-22 18:16:22857}
858
James Wallace-Leefbb0e3362018-06-18 23:57:47859void SingleThreadProxy::ScheduledActionInvalidateLayerTreeFrameSink(
860 bool needs_redraw) {
danakja5df53792018-04-26 18:36:39861 // This is an Android WebView codepath, which only uses multi-thread
862 // compositor. So this should not occur in single-thread mode.
863 NOTREACHED() << "Android Webview use-case, so multi-thread only";
sunnypseab5ac92015-04-02 20:26:13864}
865
khushalsagarab73d502017-02-24 02:26:46866void SingleThreadProxy::ScheduledActionPerformImplSideInvalidation() {
khushalsagar6dc91d02017-02-28 05:10:07867 DCHECK(scheduler_on_impl_thread_);
868
869 DebugScopedSetImplThread impl(task_runner_provider_);
Walter Kormanaa326e42017-08-22 23:04:43870 host_impl_->InvalidateContentOnImplSide();
khushalsagar6dc91d02017-02-28 05:10:07871
872 // Invalidations go directly to the active tree, so we synchronously call
873 // NotifyReadyToActivate to update the scheduler and LTHI state correctly.
874 // Since in single-threaded mode the scheduler will wait for a ready to draw
875 // signal from LTHI, the draw will remain blocked till the invalidated tiles
876 // are ready.
877 NotifyReadyToActivate();
khushalsagarab73d502017-02-24 02:26:46878}
879
mithro51693e382015-05-07 23:52:41880void SingleThreadProxy::DidFinishImplFrame() {
Walter Kormanaa326e42017-08-22 23:04:43881 host_impl_->DidFinishImplFrame();
mithro51693e382015-05-07 23:52:41882#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02883 DCHECK(inside_impl_frame_)
mithro51693e382015-05-07 23:52:41884 << "DidFinishImplFrame called while not inside an impl frame!";
mithro69fd3bb52015-05-01 03:45:02885 inside_impl_frame_ = false;
mithro51693e382015-05-07 23:52:41886#endif
[email protected]aeeedad2014-08-22 18:16:22887}
888
Fady Samuelc296f5fb2017-07-21 04:02:19889void SingleThreadProxy::DidNotProduceFrame(const viz::BeginFrameAck& ack) {
eseckler9404a232017-05-22 14:49:43890 DebugScopedSetImplThread impl(task_runner_provider_);
Walter Kormanaa326e42017-08-22 23:04:43891 host_impl_->DidNotProduceFrame(ack);
eseckler9404a232017-05-22 14:49:43892}
893
samans44b6dfc2017-04-19 16:50:53894void SingleThreadProxy::DidReceiveCompositorFrameAck() {
895 layer_tree_host_->DidReceiveCompositorFrameAck();
896}
897
[email protected]bc5e77c2012-11-05 20:00:49898} // namespace cc