blob: 2e3b7c613c182bfe100db25d4da18b51ba8b0d48 [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),
Stephen Chenney6d3f5ce2018-11-14 02:08:0550 defer_main_frame_update_(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
Stephen Chenney6d3f5ce2018-11-14 02:08:05266void SingleThreadProxy::SetDeferMainFrameUpdate(bool defer_main_frame_update) {
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;
Stephen Chenney6d3f5ce2018-11-14 02:08:05271 if (defer_main_frame_update_ == defer_main_frame_update)
[email protected]aeeedad2014-08-22 18:16:22272 return;
273
Stephen Chenney6d3f5ce2018-11-14 02:08:05274 if (defer_main_frame_update)
275 TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferMainFrameUpdate",
276 this);
[email protected]aeeedad2014-08-22 18:16:22277 else
Stephen Chenney6d3f5ce2018-11-14 02:08:05278 TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferMainFrameUpdate",
279 this);
[email protected]aeeedad2014-08-22 18:16:22280
Stephen Chenney6d3f5ce2018-11-14 02:08:05281 defer_main_frame_update_ = defer_main_frame_update;
282 scheduler_on_impl_thread_->SetDeferMainFrameUpdate(defer_main_frame_update);
[email protected]6b16679e2012-10-27 00:44:28283}
284
[email protected]174c6d42014-08-12 01:43:06285bool SingleThreadProxy::CommitRequested() const {
khushalsagarb7db1fe2015-11-12 00:51:27286 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22287 return commit_requested_;
[email protected]174c6d42014-08-12 01:43:06288}
[email protected]a8a049c2013-03-11 23:27:06289
[email protected]a8a049c2013-03-11 23:27:06290void SingleThreadProxy::Stop() {
291 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
khushalsagarb7db1fe2015-11-12 00:51:27292 DCHECK(task_runner_provider_->IsMainThread());
[email protected]a8a049c2013-03-11 23:27:06293 {
khushalsagarb7db1fe2015-11-12 00:51:27294 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
295 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06296
sunnypsda928f0a2016-10-08 00:32:53297 // Prevent the scheduler from performing actions while we're in an
298 // inconsistent state.
299 if (scheduler_on_impl_thread_)
300 scheduler_on_impl_thread_->Stop();
danakjc7afae52017-06-20 21:12:41301 // Take away the LayerTreeFrameSink before destroying things so it doesn't
danakj1120f4c2016-09-15 02:05:32302 // try to call into its client mid-shutdown.
Walter Kormanaa326e42017-08-22 23:04:43303 host_impl_->ReleaseLayerTreeFrameSink();
Khushal7899efd2018-01-08 18:01:16304
305 // It is important to destroy LTHI before the Scheduler since it can make
306 // callbacks that access it during destruction cleanup.
Walter Kormanaa326e42017-08-22 23:04:43307 host_impl_ = nullptr;
Khushal7899efd2018-01-08 18:01:16308 scheduler_on_impl_thread_ = nullptr;
[email protected]a8a049c2013-03-11 23:27:06309 }
sunnypsda928f0a2016-10-08 00:32:53310 layer_tree_host_ = nullptr;
[email protected]a8a049c2013-03-11 23:27:06311}
312
flackrf54e9b42016-05-31 15:20:10313void SingleThreadProxy::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) {
314 DCHECK(task_runner_provider_->IsMainThread());
315 DebugScopedSetImplThread impl(task_runner_provider_);
Walter Kormanaa326e42017-08-22 23:04:43316 host_impl_->SetLayerTreeMutator(std::move(mutator));
flackrf54e9b42016-05-31 15:20:10317}
318
[email protected]3d9f7432013-04-06 00:35:18319void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
sunnypsad3235e2016-08-09 04:57:52320 TRACE_EVENT1("cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw",
321 can_draw);
khushalsagarb7db1fe2015-11-12 00:51:27322 DCHECK(task_runner_provider_->IsImplThread());
[email protected]aeeedad2014-08-22 18:16:22323 if (scheduler_on_impl_thread_)
324 scheduler_on_impl_thread_->SetCanDraw(can_draw);
[email protected]3d9f7432013-04-06 00:35:18325}
326
[email protected]4f48f6e2013-08-27 06:33:38327void SingleThreadProxy::NotifyReadyToActivate() {
enne98f3a6c2014-10-09 20:09:44328 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate");
khushalsagarb7db1fe2015-11-12 00:51:27329 DebugScopedSetImplThread impl(task_runner_provider_);
rogerm8aeea932017-04-19 21:26:57330 if (scheduler_on_impl_thread_)
331 scheduler_on_impl_thread_->NotifyReadyToActivate();
[email protected]4f48f6e2013-08-27 06:33:38332}
333
ernstmdfac03e2014-11-11 20:18:05334void SingleThreadProxy::NotifyReadyToDraw() {
weiliangc8dac5a62015-04-02 06:12:35335 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToDraw");
khushalsagarb7db1fe2015-11-12 00:51:27336 DebugScopedSetImplThread impl(task_runner_provider_);
weiliangc8dac5a62015-04-02 06:12:35337 if (scheduler_on_impl_thread_)
338 scheduler_on_impl_thread_->NotifyReadyToDraw();
ernstmdfac03e2014-11-11 20:18:05339}
340
[email protected]c1bb5af2013-03-13 19:06:27341void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
danakj6c872fc02016-10-22 04:29:49342 single_thread_client_->RequestScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22343 if (scheduler_on_impl_thread_)
344 scheduler_on_impl_thread_->SetNeedsRedraw();
[email protected]a8a049c2013-03-11 23:27:06345}
346
danakja18e826a2015-12-03 00:27:03347void SingleThreadProxy::SetNeedsOneBeginImplFrameOnImplThread() {
348 TRACE_EVENT0("cc",
349 "SingleThreadProxy::SetNeedsOneBeginImplFrameOnImplThread");
danakj6c872fc02016-10-22 04:29:49350 single_thread_client_->RequestScheduleComposite();
mithro719bf6792014-11-10 15:36:47351 if (scheduler_on_impl_thread_)
danakja18e826a2015-12-03 00:27:03352 scheduler_on_impl_thread_->SetNeedsOneBeginImplFrame();
David Bokaneaa5cc82018-10-12 15:50:40353 needs_impl_frame_ = true;
[email protected]43b8f982014-04-30 21:24:33354}
355
vmiura59ea9b4042014-12-09 20:50:39356void SingleThreadProxy::SetNeedsPrepareTilesOnImplThread() {
357 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsPrepareTilesOnImplThread");
enne98f3a6c2014-10-09 20:09:44358 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39359 scheduler_on_impl_thread_->SetNeedsPrepareTiles();
[email protected]c48536a52013-09-14 00:02:08360}
361
[email protected]c1bb5af2013-03-13 19:06:27362void SingleThreadProxy::SetNeedsCommitOnImplThread() {
danakj6c872fc02016-10-22 04:29:49363 single_thread_client_->RequestScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22364 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01365 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
David Bokaneaa5cc82018-10-12 15:50:40366 commit_requested_ = true;
[email protected]a8a049c2013-03-11 23:27:06367}
368
sunnyps7d073dc2015-04-16 23:29:12369void SingleThreadProxy::SetVideoNeedsBeginFrames(bool needs_begin_frames) {
370 TRACE_EVENT1("cc", "SingleThreadProxy::SetVideoNeedsBeginFrames",
371 "needs_begin_frames", needs_begin_frames);
372 // In tests the layer tree is destroyed after the scheduler is.
373 if (scheduler_on_impl_thread_)
374 scheduler_on_impl_thread_->SetVideoNeedsBeginFrames(needs_begin_frames);
375}
376
[email protected]c1bb5af2013-03-13 19:06:27377void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
loysoc601b7b82016-11-10 02:56:44378 std::unique_ptr<MutatorEvents> events) {
[email protected]ccc08dc2014-01-30 07:33:20379 TRACE_EVENT0(
380 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
khushalsagarb7db1fe2015-11-12 00:51:27381 DCHECK(task_runner_provider_->IsImplThread());
382 DebugScopedSetMainThread main(task_runner_provider_);
danakja04855a2015-11-18 20:39:10383 layer_tree_host_->SetAnimationEvents(std::move(events));
[email protected]a8a049c2013-03-11 23:27:06384}
385
Xida Chend8bb3b22017-10-26 17:14:52386size_t SingleThreadProxy::CompositedAnimationsCount() const {
387 return 0;
388}
389
390size_t SingleThreadProxy::MainThreadAnimationsCount() const {
391 return 0;
392}
393
Stephen McGruer1619b422018-02-20 18:46:55394bool SingleThreadProxy::CurrentFrameHadRAF() const {
395 return false;
396}
397
398bool SingleThreadProxy::NextFrameHasPendingRAF() const {
399 return false;
400}
401
sunnypsad3235e2016-08-09 04:57:52402bool SingleThreadProxy::IsInsideDraw() {
403 return inside_draw_;
404}
[email protected]a8a049c2013-03-11 23:27:06405
enne98f3a6c2014-10-09 20:09:44406void SingleThreadProxy::DidActivateSyncTree() {
danakj68803fc2015-06-19 20:55:53407 CommitComplete();
enne98f3a6c2014-10-09 20:09:44408}
409
brianderson68749812015-07-07 22:39:39410void SingleThreadProxy::WillPrepareTiles() {
khushalsagarb7db1fe2015-11-12 00:51:27411 DCHECK(task_runner_provider_->IsImplThread());
brianderson68749812015-07-07 22:39:39412 if (scheduler_on_impl_thread_)
413 scheduler_on_impl_thread_->WillPrepareTiles();
414}
415
vmiura59ea9b4042014-12-09 20:50:39416void SingleThreadProxy::DidPrepareTiles() {
khushalsagarb7db1fe2015-11-12 00:51:27417 DCHECK(task_runner_provider_->IsImplThread());
enne98f3a6c2014-10-09 20:09:44418 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39419 scheduler_on_impl_thread_->DidPrepareTiles();
enne98f3a6c2014-10-09 20:09:44420}
421
rouslanf7ebd8832015-01-22 01:54:14422void SingleThreadProxy::DidCompletePageScaleAnimationOnImplThread() {
423 layer_tree_host_->DidCompletePageScaleAnimation();
424}
425
danakjc7afae52017-06-20 21:12:41426void SingleThreadProxy::DidLoseLayerTreeFrameSinkOnImplThread() {
danakj1120f4c2016-09-15 02:05:32427 TRACE_EVENT0("cc",
danakjc7afae52017-06-20 21:12:41428 "SingleThreadProxy::DidLoseLayerTreeFrameSinkOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22429 {
khushalsagarb7db1fe2015-11-12 00:51:27430 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22431 // This must happen before we notify the scheduler as it may try to recreate
432 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE.
danakjc7afae52017-06-20 21:12:41433 layer_tree_host_->DidLoseLayerTreeFrameSink();
[email protected]aeeedad2014-08-22 18:16:22434 }
danakjc7afae52017-06-20 21:12:41435 single_thread_client_->DidLoseLayerTreeFrameSink();
[email protected]aeeedad2014-08-22 18:16:22436 if (scheduler_on_impl_thread_)
danakjc7afae52017-06-20 21:12:41437 scheduler_on_impl_thread_->DidLoseLayerTreeFrameSink();
438 layer_tree_frame_sink_lost_ = true;
[email protected]4d7e46a2013-11-08 05:33:40439}
440
Fady Samuelc645ffe2017-07-24 17:28:20441void SingleThreadProxy::SetBeginFrameSource(viz::BeginFrameSource* source) {
enne19c108582016-04-14 03:35:32442 if (scheduler_on_impl_thread_)
443 scheduler_on_impl_thread_->SetBeginFrameSource(source);
444}
445
danakj9d124422016-10-14 03:15:08446void SingleThreadProxy::DidReceiveCompositorFrameAckOnImplThread() {
miletusfed8c43b2015-01-26 20:04:52447 TRACE_EVENT0("cc,benchmark",
danakj9d124422016-10-14 03:15:08448 "SingleThreadProxy::DidReceiveCompositorFrameAckOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22449 if (scheduler_on_impl_thread_)
danakj9d124422016-10-14 03:15:08450 scheduler_on_impl_thread_->DidReceiveCompositorFrameAck();
Karolina Soltys4d60b402018-10-01 19:28:20451 if (layer_tree_host_->GetSettings().send_compositor_frame_ack) {
452 // We do a PostTask here because freeing resources in some cases (such as in
453 // TextureLayer) is PostTasked and we want to make sure ack is received
454 // after resources are returned.
455 task_runner_provider_->MainThreadTaskRunner()->PostTask(
456 FROM_HERE, base::Bind(&SingleThreadProxy::DidReceiveCompositorFrameAck,
457 frame_sink_bound_weak_ptr_));
458 }
[email protected]493067512012-09-19 23:34:10459}
460
danakjc7afae52017-06-20 21:12:41461void SingleThreadProxy::OnDrawForLayerTreeFrameSink(
James Wallace-Leefbb0e3362018-06-18 23:57:47462 bool resourceless_software_draw,
463 bool skip_draw) {
sunnypseab5ac92015-04-02 20:26:13464 NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor.";
465}
466
Khushal8360fc92017-07-26 01:53:25467void SingleThreadProxy::NeedsImplSideInvalidation(
468 bool needs_first_draw_on_activation) {
Khushal4b6c41882018-02-16 09:02:10469 if (scheduler_on_impl_thread_) {
470 scheduler_on_impl_thread_->SetNeedsImplSideInvalidation(
471 needs_first_draw_on_activation);
472 }
khushalsagard3b8827d2017-02-18 18:42:54473}
474
vmpstra840c6a2017-06-01 21:50:39475void SingleThreadProxy::NotifyImageDecodeRequestFinished() {
476 // If we don't have a scheduler, then just issue the callbacks here.
477 // Otherwise, schedule a commit.
478 if (!scheduler_on_impl_thread_) {
479 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
480 DebugScopedSetImplThread impl(task_runner_provider_);
481
482 IssueImageDecodeFinishedCallbacks();
483 return;
484 }
485 SetNeedsCommitOnImplThread();
486}
487
Scott Violete979c012017-12-08 00:18:16488void SingleThreadProxy::DidPresentCompositorFrameOnImplThread(
Sadrul Habib Chowdhury3d4df2e82018-06-02 05:18:00489 uint32_t frame_token,
490 std::vector<LayerTreeHost::PresentationTimeCallback> callbacks,
Sadrul Habib Chowdhuryb62a97302018-06-06 03:33:48491 const gfx::PresentationFeedback& feedback) {
Sadrul Habib Chowdhury3d4df2e82018-06-02 05:18:00492 layer_tree_host_->DidPresentCompositorFrame(frame_token, std::move(callbacks),
Sadrul Habib Chowdhuryb62a97302018-06-06 03:33:48493 feedback);
Scott Violete979c012017-12-08 00:18:16494}
495
Dan Elphick95929fd52017-06-13 09:15:07496void SingleThreadProxy::RequestBeginMainFrameNotExpected(bool new_state) {
497 if (scheduler_on_impl_thread_) {
498 scheduler_on_impl_thread_->SetMainThreadWantsBeginMainFrameNotExpected(
499 new_state);
500 }
501}
502
Khushal4b6c41882018-02-16 09:02:10503void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time,
504 bool raster) {
miletusfed8c43b2015-01-26 20:04:52505 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately");
khushalsagarb7db1fe2015-11-12 00:51:27506 DCHECK(task_runner_provider_->IsMainThread());
mithro51693e382015-05-07 23:52:41507#if DCHECK_IS_ON()
mithroc76d70312015-05-04 23:51:13508 DCHECK(!inside_impl_frame_);
mithro51693e382015-05-07 23:52:41509#endif
jbauman399aec1a2014-10-25 02:33:32510 base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true);
511
danakjc7afae52017-06-20 21:12:41512 if (layer_tree_frame_sink_lost_) {
513 RequestNewLayerTreeFrameSink();
514 // RequestNewLayerTreeFrameSink could have synchronously created an output
jbauman399aec1a2014-10-25 02:33:32515 // surface, so check again before returning.
danakjc7afae52017-06-20 21:12:41516 if (layer_tree_frame_sink_lost_)
jbauman399aec1a2014-10-25 02:33:32517 return;
518 }
[email protected]51f81da2014-05-16 21:29:26519
Fady Samuelc296f5fb2017-07-21 04:02:19520 viz::BeginFrameArgs begin_frame_args(viz::BeginFrameArgs::Create(
521 BEGINFRAME_FROM_HERE, viz::BeginFrameArgs::kManualSourceId, 1,
522 frame_begin_time, base::TimeTicks(),
523 viz::BeginFrameArgs::DefaultInterval(), viz::BeginFrameArgs::NORMAL));
mithroc76d70312015-05-04 23:51:13524
525 // Start the impl frame.
enne98f3a6c2014-10-09 20:09:44526 {
khushalsagarb7db1fe2015-11-12 00:51:27527 DebugScopedSetImplThread impl(task_runner_provider_);
mithroc76d70312015-05-04 23:51:13528 WillBeginImplFrame(begin_frame_args);
529 }
530
531 // Run the "main thread" and get it to commit.
532 {
mithro51693e382015-05-07 23:52:41533#if DCHECK_IS_ON()
mithroc76d70312015-05-04 23:51:13534 DCHECK(inside_impl_frame_);
mithro51693e382015-05-07 23:52:41535#endif
danakje6da4f12018-07-04 17:41:30536 animate_requested_ = false;
David Bokaneaa5cc82018-10-12 15:50:40537 needs_impl_frame_ = false;
danakje6da4f12018-07-04 17:41:30538 // Prevent new commits from being requested inside DoBeginMainFrame.
539 // Note: We do not want to prevent SetNeedsAnimate from requesting
540 // a commit here.
541 commit_requested_ = true;
enne98f3a6c2014-10-09 20:09:44542 DoBeginMainFrame(begin_frame_args);
danakje6da4f12018-07-04 17:41:30543 commit_requested_ = false;
danakj97660d92017-03-27 14:11:49544 DoPainting();
enne98f3a6c2014-10-09 20:09:44545 DoCommit();
[email protected]e0341352013-04-06 05:01:20546
khushalsagar8297ae992016-09-14 20:51:23547 DCHECK_EQ(
548 0u,
549 layer_tree_host_->GetSwapPromiseManager()->num_queued_swap_promises())
enne98f3a6c2014-10-09 20:09:44550 << "Commit should always succeed and transfer promises.";
551 }
552
mithroc76d70312015-05-04 23:51:13553 // Finish the impl frame.
enne98f3a6c2014-10-09 20:09:44554 {
khushalsagarb7db1fe2015-11-12 00:51:27555 DebugScopedSetImplThread impl(task_runner_provider_);
Walter Kormanaa326e42017-08-22 23:04:43556 host_impl_->ActivateSyncTree();
Khushal4b6c41882018-02-16 09:02:10557 if (raster) {
558 host_impl_->PrepareTiles();
559 host_impl_->SynchronouslyInitializeAllTiles();
560 }
enne69277cb2014-10-29 23:03:40561
danakj12e2f6e2015-08-19 22:25:44562 // TODO(danakj): Don't do this last... we prepared the wrong things. D:
Walter Kormanaa326e42017-08-22 23:04:43563 host_impl_->Animate();
mithro719bf6792014-11-10 15:36:47564
Khushal4b6c41882018-02-16 09:02:10565 if (raster) {
566 LayerTreeHostImpl::FrameData frame;
Sadrul Habib Chowdhury4a7940b2018-06-22 16:45:14567 frame.begin_frame_ack = viz::BeginFrameAck(begin_frame_args, true);
Khushal4b6c41882018-02-16 09:02:10568 DoComposite(&frame);
569 }
enne98f3a6c2014-10-09 20:09:44570
571 // DoComposite could abort, but because this is a synchronous composite
572 // another draw will never be scheduled, so break remaining promises.
Walter Kormanaa326e42017-08-22 23:04:43573 host_impl_->active_tree()->BreakSwapPromises(SwapPromise::SWAP_FAILS);
mithroc76d70312015-05-04 23:51:13574
mithro51693e382015-05-07 23:52:41575 DidFinishImplFrame();
enne98f3a6c2014-10-09 20:09:44576 }
[email protected]74d9063c2013-01-18 03:14:47577}
578
[email protected]5d8bec72014-07-03 03:03:11579bool SingleThreadProxy::SupportsImplScrolling() const {
580 return false;
581}
582
[email protected]3d9f7432013-04-06 00:35:18583bool SingleThreadProxy::ShouldComposite() const {
khushalsagarb7db1fe2015-11-12 00:51:27584 DCHECK(task_runner_provider_->IsImplThread());
Walter Kormanaa326e42017-08-22 23:04:43585 return host_impl_->visible() && host_impl_->CanDraw();
[email protected]3d9f7432013-04-06 00:35:18586}
587
danakjc7afae52017-06-20 21:12:41588void SingleThreadProxy::ScheduleRequestNewLayerTreeFrameSink() {
589 if (layer_tree_frame_sink_creation_callback_.IsCancelled() &&
590 !layer_tree_frame_sink_creation_requested_) {
591 layer_tree_frame_sink_creation_callback_.Reset(
592 base::Bind(&SingleThreadProxy::RequestNewLayerTreeFrameSink,
jbauman8ab0f9e2014-10-15 02:30:34593 weak_factory_.GetWeakPtr()));
khushalsagarb7db1fe2015-11-12 00:51:27594 task_runner_provider_->MainThreadTaskRunner()->PostTask(
danakjc7afae52017-06-20 21:12:41595 FROM_HERE, layer_tree_frame_sink_creation_callback_.callback());
jbauman8ab0f9e2014-10-15 02:30:34596 }
597}
598
mithro248d1722015-05-05 05:23:45599DrawResult SingleThreadProxy::DoComposite(LayerTreeHostImpl::FrameData* frame) {
[email protected]ccc08dc2014-01-30 07:33:20600 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite");
[email protected]04049fc2013-05-01 03:13:20601
enne98f3a6c2014-10-09 20:09:44602 DrawResult draw_result;
603 bool draw_frame;
[email protected]a8a049c2013-03-11 23:27:06604 {
khushalsagarb7db1fe2015-11-12 00:51:27605 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06606 base::AutoReset<bool> mark_inside(&inside_draw_, true);
607
[email protected]3d9f7432013-04-06 00:35:18608 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
609 // frame, so can only be used when such a frame is possible. Since
610 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
611 // CanDraw() as well.
[email protected]2aae96792014-05-15 23:10:50612 if (!ShouldComposite()) {
[email protected]aeeedad2014-08-22 18:16:22613 return DRAW_ABORTED_CANT_DRAW;
[email protected]3d9f7432013-04-06 00:35:18614 }
[email protected]a8a049c2013-03-11 23:27:06615
danakj097919e72016-09-07 19:50:55616 // This CapturePostTasks should be destroyed before
617 // DidCommitAndDrawFrame() is called since that goes out to the
618 // embedder, and we want the embedder to receive its callbacks before that.
619 // NOTE: This maintains consistent ordering with the ThreadProxy since
620 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
621 // there as the main thread is not blocked, so any posted tasks inside
622 // the swap buffers will execute first.
623 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
danakj097919e72016-09-07 19:50:55624
Walter Kormanaa326e42017-08-22 23:04:43625 draw_result = host_impl_->PrepareToDraw(frame);
enne98f3a6c2014-10-09 20:09:44626 draw_frame = draw_result == DRAW_SUCCESS;
robliao27728e62015-03-21 07:39:34627 if (draw_frame) {
Walter Kormanaa326e42017-08-22 23:04:43628 if (host_impl_->DrawLayers(frame)) {
danakj097919e72016-09-07 19:50:55629 if (scheduler_on_impl_thread_)
danakjc7afae52017-06-20 21:12:41630 // Drawing implies we submitted a frame to the LayerTreeFrameSink.
danakj9d124422016-10-14 03:15:08631 scheduler_on_impl_thread_->DidSubmitCompositorFrame();
danakj6c872fc02016-10-22 04:29:49632 single_thread_client_->DidSubmitCompositorFrame();
danakj097919e72016-09-07 19:50:55633 }
robliao27728e62015-03-21 07:39:34634 }
Walter Kormanaa326e42017-08-22 23:04:43635 host_impl_->DidDrawAllLayers(*frame);
[email protected]a8a049c2013-03-11 23:27:06636
danakj097919e72016-09-07 19:50:55637 bool start_ready_animations = draw_frame;
Walter Kormanaa326e42017-08-22 23:04:43638 host_impl_->UpdateAnimationState(start_ready_animations);
[email protected]aeeedad2014-08-22 18:16:22639 }
640 DidCommitAndDrawFrame();
641
enne98f3a6c2014-10-09 20:09:44642 return draw_result;
[email protected]a8a049c2013-03-11 23:27:06643}
644
[email protected]aeeedad2014-08-22 18:16:22645void SingleThreadProxy::DidCommitAndDrawFrame() {
[email protected]a8a049c2013-03-11 23:27:06646 if (next_frame_is_newly_committed_frame_) {
khushalsagarb7db1fe2015-11-12 00:51:27647 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06648 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21649 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06650 }
651}
652
[email protected]4ea293f72014-08-13 03:03:17653bool SingleThreadProxy::MainFrameWillHappenForTesting() {
danakjfcdaba122015-04-24 21:41:52654 if (!scheduler_on_impl_thread_)
655 return false;
656 return scheduler_on_impl_thread_->MainFrameForTestingWillHappen();
[email protected]4ea293f72014-08-13 03:03:17657}
[email protected]a8a049c2013-03-11 23:27:06658
Fady Samueld26f7fb2018-06-19 04:13:37659void SingleThreadProxy::ClearHistory() {
Khushal2f9cdf22018-01-08 21:47:08660 DCHECK(task_runner_provider_->IsImplThread());
661 if (scheduler_on_impl_thread_)
Fady Samueld26f7fb2018-06-19 04:13:37662 scheduler_on_impl_thread_->ClearHistory();
Khushal2f9cdf22018-01-08 21:47:08663}
664
jonrossa2ff4f82018-02-16 17:27:46665void SingleThreadProxy::SetRenderFrameObserver(
666 std::unique_ptr<RenderFrameMetadataObserver> observer) {
jonrossc1877d6d2018-02-21 00:07:31667 host_impl_->SetRenderFrameObserver(std::move(observer));
jonrossa2ff4f82018-02-16 17:27:46668}
669
David Bokan1e37ebf2018-10-16 13:53:37670void SingleThreadProxy::UpdateBrowserControlsState(
671 BrowserControlsState constraints,
672 BrowserControlsState current,
673 bool animate) {
674 host_impl_->browser_controls_manager()->UpdateBrowserControlsState(
675 constraints, current, animate);
676}
677
James Wallace-Leee71cf582018-01-29 22:24:23678bool SingleThreadProxy::WillBeginImplFrame(const viz::BeginFrameArgs& args) {
danakja18e826a2015-12-03 00:27:03679 DebugScopedSetImplThread impl(task_runner_provider_);
mithro51693e382015-05-07 23:52:41680#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02681 DCHECK(!inside_impl_frame_)
682 << "WillBeginImplFrame called while already inside an impl frame!";
683 inside_impl_frame_ = true;
mithro51693e382015-05-07 23:52:41684#endif
James Wallace-Leee71cf582018-01-29 22:24:23685 return host_impl_->WillBeginImplFrame(args);
[email protected]aeeedad2014-08-22 18:16:22686}
687
brianderson266dc3a2015-11-12 03:16:40688void SingleThreadProxy::ScheduledActionSendBeginMainFrame(
Fady Samuelc296f5fb2017-07-21 04:02:19689 const viz::BeginFrameArgs& begin_frame_args) {
[email protected]aeeedad2014-08-22 18:16:22690 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame");
sunnypsad3235e2016-08-09 04:57:52691#if DCHECK_IS_ON()
[email protected]aeeedad2014-08-22 18:16:22692 // Although this proxy is single-threaded, it's problematic to synchronously
693 // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This
694 // could cause a commit to occur in between a series of SetNeedsCommit calls
695 // (i.e. property modifications) causing some to fall on one frame and some to
696 // fall on the next. Doing it asynchronously instead matches the semantics of
697 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a
698 // synchronous commit.
mithro69fd3bb52015-05-01 03:45:02699 DCHECK(inside_impl_frame_)
700 << "BeginMainFrame should only be sent inside a BeginImplFrame";
mithro51693e382015-05-07 23:52:41701#endif
mithro69fd3bb52015-05-01 03:45:02702
Zhenyao Mo5b30cf32018-12-01 00:31:25703 host_impl_->WillSendBeginMainFrame();
khushalsagarb7db1fe2015-11-12 00:51:27704 task_runner_provider_->MainThreadTaskRunner()->PostTask(
tzik4604bb52017-04-13 21:50:22705 FROM_HERE, base::BindOnce(&SingleThreadProxy::BeginMainFrame,
706 weak_factory_.GetWeakPtr(), begin_frame_args));
Walter Kormanaa326e42017-08-22 23:04:43707 host_impl_->DidSendBeginMainFrame();
[email protected]aeeedad2014-08-22 18:16:22708}
709
kylechard96169b2018-11-02 00:55:00710void SingleThreadProxy::FrameIntervalUpdated(base::TimeDelta interval) {
711 DebugScopedSetMainThread main(task_runner_provider_);
712 single_thread_client_->FrameIntervalUpdated(interval);
713}
714
rmcilroy0a19362a2015-02-18 12:34:25715void SingleThreadProxy::SendBeginMainFrameNotExpectedSoon() {
716 layer_tree_host_->BeginMainFrameNotExpectedSoon();
717}
718
delphick9db74aa2017-05-05 10:20:49719void SingleThreadProxy::ScheduledActionBeginMainFrameNotExpectedUntil(
720 base::TimeTicks time) {
721 layer_tree_host_->BeginMainFrameNotExpectedUntil(time);
722}
723
Fady Samuelc296f5fb2017-07-21 04:02:19724void SingleThreadProxy::BeginMainFrame(
725 const viz::BeginFrameArgs& begin_frame_args) {
Brian Anderson242b9b02017-12-06 21:06:26726 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous
727 // commit.
728 ScopedAbortRemainingSwapPromises swap_promise_checker(
729 layer_tree_host_->GetSwapPromiseManager());
730
brianderson21aef162015-11-11 05:12:23731 if (scheduler_on_impl_thread_) {
732 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(
733 base::TimeTicks::Now());
734 }
735
danakjfcdaba122015-04-24 21:41:52736 commit_requested_ = false;
David Bokaneaa5cc82018-10-12 15:50:40737 needs_impl_frame_ = false;
brianderson49e101d22015-04-29 00:05:33738 animate_requested_ = false;
danakjfcdaba122015-04-24 21:41:52739
Stephen Chenney6d3f5ce2018-11-14 02:08:05740 if (defer_main_frame_update_) {
simonhongc6309f792015-01-31 15:47:15741 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit",
742 TRACE_EVENT_SCOPE_THREAD);
743 BeginMainFrameAbortedOnImplThread(
744 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT);
[email protected]aeeedad2014-08-22 18:16:22745 return;
746 }
747
khushalsagarcebe4942016-09-07 23:27:01748 if (!layer_tree_host_->IsVisible()) {
[email protected]aeeedad2014-08-22 18:16:22749 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD);
mithrof7a21502014-12-17 03:24:48750 BeginMainFrameAbortedOnImplThread(
751 CommitEarlyOutReason::ABORTED_NOT_VISIBLE);
[email protected]aeeedad2014-08-22 18:16:22752 return;
753 }
754
danakjfcdaba122015-04-24 21:41:52755 // Prevent new commits from being requested inside DoBeginMainFrame.
brianderson49e101d22015-04-29 00:05:33756 // Note: We do not want to prevent SetNeedsAnimate from requesting
757 // a commit here.
danakjfcdaba122015-04-24 21:41:52758 commit_requested_ = true;
759
enne98f3a6c2014-10-09 20:09:44760 DoBeginMainFrame(begin_frame_args);
danakj97660d92017-03-27 14:11:49761
762 // New commits requested inside UpdateLayers should be respected.
763 commit_requested_ = false;
764
765 // At this point the main frame may have deferred commits to avoid committing
766 // right now.
Stephen Chenney6d3f5ce2018-11-14 02:08:05767 if (defer_main_frame_update_ || begin_frame_args.animate_only) {
danakj97660d92017-03-27 14:11:49768 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit_InsideBeginMainFrame",
769 TRACE_EVENT_SCOPE_THREAD);
770 BeginMainFrameAbortedOnImplThread(
771 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT);
772 layer_tree_host_->DidBeginMainFrame();
773 return;
774 }
775
Brian Anderson242b9b02017-12-06 21:06:26776 // Queue the LATENCY_BEGIN_FRAME_UI_MAIN_COMPONENT swap promise only once we
777 // know we will commit since QueueSwapPromise itself requests a commit.
778 ui::LatencyInfo new_latency_info(ui::SourceEventType::FRAME);
779 new_latency_info.AddLatencyNumberWithTimestamp(
Sadrul Habib Chowdhury41154dc02018-06-09 04:25:01780 ui::LATENCY_BEGIN_FRAME_UI_MAIN_COMPONENT, begin_frame_args.frame_time,
Navid Zolghadr5870ee112018-05-18 19:08:30781 1);
Brian Anderson242b9b02017-12-06 21:06:26782 layer_tree_host_->QueueSwapPromise(
783 std::make_unique<LatencyInfoSwapPromise>(new_latency_info));
784
danakj97660d92017-03-27 14:11:49785 DoPainting();
enne98f3a6c2014-10-09 20:09:44786}
787
788void SingleThreadProxy::DoBeginMainFrame(
Fady Samuelc296f5fb2017-07-21 04:02:19789 const viz::BeginFrameArgs& begin_frame_args) {
Khushal4b6c41882018-02-16 09:02:10790 // The impl-side scroll deltas may be manipulated directly via the
791 // InputHandler on the UI thread and the scale deltas may change when they are
792 // clamped on the impl thread.
tapted4b70c522016-08-13 09:09:32793 std::unique_ptr<ScrollAndScaleSet> scroll_info =
Walter Kormanaa326e42017-08-22 23:04:43794 host_impl_->ProcessScrollDeltas();
tapted4b70c522016-08-13 09:09:32795 layer_tree_host_->ApplyScrollAndScale(scroll_info.get());
796
enne98f3a6c2014-10-09 20:09:44797 layer_tree_host_->WillBeginMainFrame();
798 layer_tree_host_->BeginMainFrame(begin_frame_args);
799 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time);
Stephen Chenneyec4312612018-11-21 12:40:16800 layer_tree_host_->RequestMainFrameUpdate(
801 false /* record_main_frame_metrics */);
danakj97660d92017-03-27 14:11:49802}
enne98f3a6c2014-10-09 20:09:44803
danakj97660d92017-03-27 14:11:49804void SingleThreadProxy::DoPainting() {
danakj5f46636a2015-06-19 00:01:40805 layer_tree_host_->UpdateLayers();
enne98f3a6c2014-10-09 20:09:44806
mithrof7a21502014-12-17 03:24:48807 // TODO(enne): SingleThreadProxy does not support cancelling commits yet,
808 // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside
809 // thread_proxy.cc
brianderson21aef162015-11-11 05:12:23810 if (scheduler_on_impl_thread_)
enne98f3a6c2014-10-09 20:09:44811 scheduler_on_impl_thread_->NotifyReadyToCommit();
[email protected]aeeedad2014-08-22 18:16:22812}
813
mithrof7a21502014-12-17 03:24:48814void SingleThreadProxy::BeginMainFrameAbortedOnImplThread(
815 CommitEarlyOutReason reason) {
khushalsagarb7db1fe2015-11-12 00:51:27816 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22817 DCHECK(scheduler_on_impl_thread_->CommitPending());
Walter Kormanaa326e42017-08-22 23:04:43818 DCHECK(!host_impl_->pending_tree());
[email protected]aeeedad2014-08-22 18:16:22819
sunnypsad3235e2016-08-09 04:57:52820 std::vector<std::unique_ptr<SwapPromise>> empty_swap_promises;
Walter Kormanaa326e42017-08-22 23:04:43821 host_impl_->BeginMainFrameAborted(reason, std::move(empty_swap_promises));
mithrof7a21502014-12-17 03:24:48822 scheduler_on_impl_thread_->BeginMainFrameAborted(reason);
[email protected]aeeedad2014-08-22 18:16:22823}
824
danakj9d124422016-10-14 03:15:08825DrawResult SingleThreadProxy::ScheduledActionDrawIfPossible() {
khushalsagarb7db1fe2015-11-12 00:51:27826 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22827 LayerTreeHostImpl::FrameData frame;
esecklerdde665f2017-03-07 20:19:27828 frame.begin_frame_ack =
829 scheduler_on_impl_thread_->CurrentBeginFrameAckForActiveTree();
mithro248d1722015-05-05 05:23:45830 return DoComposite(&frame);
[email protected]aeeedad2014-08-22 18:16:22831}
832
danakj9d124422016-10-14 03:15:08833DrawResult SingleThreadProxy::ScheduledActionDrawForced() {
[email protected]aeeedad2014-08-22 18:16:22834 NOTREACHED();
835 return INVALID_RESULT;
836}
837
838void SingleThreadProxy::ScheduledActionCommit() {
khushalsagarb7db1fe2015-11-12 00:51:27839 DebugScopedSetMainThread main(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44840 DoCommit();
[email protected]aeeedad2014-08-22 18:16:22841}
842
[email protected]aeeedad2014-08-22 18:16:22843void SingleThreadProxy::ScheduledActionActivateSyncTree() {
khushalsagarb7db1fe2015-11-12 00:51:27844 DebugScopedSetImplThread impl(task_runner_provider_);
Walter Kormanaa326e42017-08-22 23:04:43845 host_impl_->ActivateSyncTree();
[email protected]aeeedad2014-08-22 18:16:22846}
847
danakjc7afae52017-06-20 21:12:41848void SingleThreadProxy::ScheduledActionBeginLayerTreeFrameSinkCreation() {
khushalsagarb7db1fe2015-11-12 00:51:27849 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22850 DCHECK(scheduler_on_impl_thread_);
851 // If possible, create the output surface in a post task. Synchronously
852 // creating the output surface makes tests more awkward since this differs
853 // from the ThreadProxy behavior. However, sometimes there is no
854 // task runner.
khushalsagarb7db1fe2015-11-12 00:51:27855 if (task_runner_provider_->MainThreadTaskRunner()) {
danakjc7afae52017-06-20 21:12:41856 ScheduleRequestNewLayerTreeFrameSink();
[email protected]aeeedad2014-08-22 18:16:22857 } else {
danakjc7afae52017-06-20 21:12:41858 RequestNewLayerTreeFrameSink();
[email protected]aeeedad2014-08-22 18:16:22859 }
860}
861
vmiura59ea9b4042014-12-09 20:50:39862void SingleThreadProxy::ScheduledActionPrepareTiles() {
863 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionPrepareTiles");
khushalsagarb7db1fe2015-11-12 00:51:27864 DebugScopedSetImplThread impl(task_runner_provider_);
Walter Kormanaa326e42017-08-22 23:04:43865 host_impl_->PrepareTiles();
[email protected]aeeedad2014-08-22 18:16:22866}
867
James Wallace-Leefbb0e3362018-06-18 23:57:47868void SingleThreadProxy::ScheduledActionInvalidateLayerTreeFrameSink(
869 bool needs_redraw) {
danakja5df53792018-04-26 18:36:39870 // This is an Android WebView codepath, which only uses multi-thread
871 // compositor. So this should not occur in single-thread mode.
872 NOTREACHED() << "Android Webview use-case, so multi-thread only";
sunnypseab5ac92015-04-02 20:26:13873}
874
khushalsagarab73d502017-02-24 02:26:46875void SingleThreadProxy::ScheduledActionPerformImplSideInvalidation() {
khushalsagar6dc91d02017-02-28 05:10:07876 DCHECK(scheduler_on_impl_thread_);
877
878 DebugScopedSetImplThread impl(task_runner_provider_);
Walter Kormanaa326e42017-08-22 23:04:43879 host_impl_->InvalidateContentOnImplSide();
khushalsagar6dc91d02017-02-28 05:10:07880
881 // Invalidations go directly to the active tree, so we synchronously call
882 // NotifyReadyToActivate to update the scheduler and LTHI state correctly.
883 // Since in single-threaded mode the scheduler will wait for a ready to draw
884 // signal from LTHI, the draw will remain blocked till the invalidated tiles
885 // are ready.
886 NotifyReadyToActivate();
khushalsagarab73d502017-02-24 02:26:46887}
888
mithro51693e382015-05-07 23:52:41889void SingleThreadProxy::DidFinishImplFrame() {
Walter Kormanaa326e42017-08-22 23:04:43890 host_impl_->DidFinishImplFrame();
mithro51693e382015-05-07 23:52:41891#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02892 DCHECK(inside_impl_frame_)
mithro51693e382015-05-07 23:52:41893 << "DidFinishImplFrame called while not inside an impl frame!";
mithro69fd3bb52015-05-01 03:45:02894 inside_impl_frame_ = false;
mithro51693e382015-05-07 23:52:41895#endif
[email protected]aeeedad2014-08-22 18:16:22896}
897
Fady Samuelc296f5fb2017-07-21 04:02:19898void SingleThreadProxy::DidNotProduceFrame(const viz::BeginFrameAck& ack) {
eseckler9404a232017-05-22 14:49:43899 DebugScopedSetImplThread impl(task_runner_provider_);
Walter Kormanaa326e42017-08-22 23:04:43900 host_impl_->DidNotProduceFrame(ack);
eseckler9404a232017-05-22 14:49:43901}
902
yiyix807099e2018-11-09 05:24:28903void SingleThreadProxy::WillNotReceiveBeginFrame() {
904 host_impl_->DidNotNeedBeginFrame();
905}
906
samans44b6dfc2017-04-19 16:50:53907void SingleThreadProxy::DidReceiveCompositorFrameAck() {
908 layer_tree_host_->DidReceiveCompositorFrameAck();
909}
910
[email protected]bc5e77c2012-11-05 20:00:49911} // namespace cc