blob: 7aa7cfc0ce644be1826bfd7237837117740f73a2 [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"
robliao27728e62015-03-21 07:39:349#include "base/profiler/scoped_tracker.h"
primianoc06e2382015-01-28 04:21:4910#include "base/trace_event/trace_event.h"
[email protected]adbe30f2013-10-11 21:12:3311#include "cc/debug/benchmark_instrumentation.h"
caseq7d2f4c92015-02-04 16:43:2712#include "cc/debug/devtools_instrumentation.h"
danakj1120f4c2016-09-15 02:05:3213#include "cc/output/compositor_frame_sink.h"
[email protected]7f0d825f2013-03-18 07:24:3014#include "cc/output/context_provider.h"
[email protected]89e82672013-03-18 07:50:5615#include "cc/quads/draw_quad.h"
khushalsagar8ec07402016-09-10 03:13:1916#include "cc/resources/ui_resource_manager.h"
mithrof7a21502014-12-17 03:24:4817#include "cc/scheduler/commit_earlyout_reason.h"
briandersonc9f50352015-06-24 03:38:5818#include "cc/scheduler/compositor_timing_history.h"
danakj15ec5242016-06-15 22:13:3719#include "cc/scheduler/delay_based_time_source.h"
briandersonc9f50352015-06-24 03:38:5820#include "cc/scheduler/scheduler.h"
khushalsagare0e4486e2017-01-25 03:15:0321#include "cc/trees/layer_tree_host.h"
jaydasika13c05062016-04-01 18:12:2722#include "cc/trees/layer_tree_host_common.h"
[email protected]943528e2013-11-07 05:01:3223#include "cc/trees/layer_tree_host_single_thread_client.h"
[email protected]556fd292013-03-18 08:03:0424#include "cc/trees/layer_tree_impl.h"
loysoc601b7b82016-11-10 02:56:4425#include "cc/trees/mutator_host.h"
[email protected]aeeedad2014-08-22 18:16:2226#include "cc/trees/scoped_abort_remaining_swap_promises.h"
[email protected]94f206c12012-08-25 00:09:1427
[email protected]9c88e562012-09-14 22:21:3028namespace cc {
[email protected]94f206c12012-08-25 00:09:1429
danakj60bc3bc2016-04-09 00:24:4830std::unique_ptr<Proxy> SingleThreadProxy::Create(
khushalsagare0e4486e2017-01-25 03:15:0331 LayerTreeHost* layer_tree_host,
[email protected]27e6a212014-07-18 15:51:2732 LayerTreeHostSingleThreadClient* client,
khushalsagar767dd522015-12-16 05:14:0533 TaskRunnerProvider* task_runner_provider) {
danakj60bc3bc2016-04-09 00:24:4834 return base::WrapUnique(
khushalsagar767dd522015-12-16 05:14:0535 new SingleThreadProxy(layer_tree_host, client, task_runner_provider));
[email protected]94f206c12012-08-25 00:09:1436}
37
khushalsagare0e4486e2017-01-25 03:15:0338SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host,
khushalsagar767dd522015-12-16 05:14:0539 LayerTreeHostSingleThreadClient* client,
40 TaskRunnerProvider* task_runner_provider)
khushalsagarb7db1fe2015-11-12 00:51:2741 : layer_tree_host_(layer_tree_host),
danakj6c872fc02016-10-22 04:29:4942 single_thread_client_(client),
khushalsagarb7db1fe2015-11-12 00:51:2743 task_runner_provider_(task_runner_provider),
[email protected]a8a049c2013-03-11 23:27:0644 next_frame_is_newly_committed_frame_(false),
mithro51693e382015-05-07 23:52:4145#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:0246 inside_impl_frame_(false),
mithro51693e382015-05-07 23:52:4147#endif
[email protected]aeeedad2014-08-22 18:16:2248 inside_draw_(false),
49 defer_commits_(false),
brianderson49e101d22015-04-29 00:05:3350 animate_requested_(false),
[email protected]aeeedad2014-08-22 18:16:2251 commit_requested_(false),
jbauman399aec1a2014-10-25 02:33:3252 inside_synchronous_composite_(false),
danakj1120f4c2016-09-15 02:05:3253 compositor_frame_sink_creation_requested_(false),
54 compositor_frame_sink_lost_(true),
[email protected]aeeedad2014-08-22 18:16:2255 weak_factory_(this) {
[email protected]a8a049c2013-03-11 23:27:0656 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
khushalsagarb7db1fe2015-11-12 00:51:2757 DCHECK(task_runner_provider_);
58 DCHECK(task_runner_provider_->IsMainThread());
[email protected]a8a049c2013-03-11 23:27:0659 DCHECK(layer_tree_host);
khushalsagar767dd522015-12-16 05:14:0560}
danakjfcdaba122015-04-24 21:41:5261
enne2b0ad682016-09-21 01:44:4762void SingleThreadProxy::Start() {
khushalsagar767dd522015-12-16 05:14:0563 DebugScopedSetImplThread impl(task_runner_provider_);
khushalsagar767dd522015-12-16 05:14:0564
khushalsagarcebe4942016-09-07 23:27:0165 const LayerTreeSettings& settings = layer_tree_host_->GetSettings();
66 if (settings.single_thread_proxy_scheduler && !scheduler_on_impl_thread_) {
67 SchedulerSettings scheduler_settings(settings.ToSchedulerSettings());
danakj5f2e92de2015-06-20 00:25:5868 scheduler_settings.commit_to_active_tree = CommitToActiveTree();
briandersonc9f50352015-06-24 03:38:5869
danakj60bc3bc2016-04-09 00:24:4870 std::unique_ptr<CompositorTimingHistory> compositor_timing_history(
briandersonc9f50352015-06-24 03:38:5871 new CompositorTimingHistory(
briandersonbb917dd2016-02-20 05:21:1472 scheduler_settings.using_synchronous_renderer_compositor,
briandersonc68220f2015-07-20 20:08:3573 CompositorTimingHistory::BROWSER_UMA,
khushalsagar767dd522015-12-16 05:14:0574 layer_tree_host_->rendering_stats_instrumentation()));
enne2b0ad682016-09-21 01:44:4775 scheduler_on_impl_thread_.reset(
76 new Scheduler(this, scheduler_settings, layer_tree_host_->GetId(),
77 task_runner_provider_->MainThreadTaskRunner(),
78 std::move(compositor_timing_history)));
danakjfcdaba122015-04-24 21:41:5279 }
[email protected]94f206c12012-08-25 00:09:1480
[email protected]804c8982013-03-13 16:32:2181 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
[email protected]a8a049c2013-03-11 23:27:0682}
83
84SingleThreadProxy::~SingleThreadProxy() {
85 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy");
khushalsagarb7db1fe2015-11-12 00:51:2786 DCHECK(task_runner_provider_->IsMainThread());
[email protected]04049fc2013-05-01 03:13:2087 // Make sure Stop() got called or never Started.
88 DCHECK(!layer_tree_host_impl_);
[email protected]a8a049c2013-03-11 23:27:0689}
90
[email protected]a8a049c2013-03-11 23:27:0691bool SingleThreadProxy::IsStarted() const {
khushalsagarb7db1fe2015-11-12 00:51:2792 DCHECK(task_runner_provider_->IsMainThread());
dcheng5d64b522016-01-20 01:41:0293 return !!layer_tree_host_impl_;
[email protected]94f206c12012-08-25 00:09:1494}
95
danakj009cdfdf2015-02-17 22:35:1496bool SingleThreadProxy::CommitToActiveTree() const {
97 // With SingleThreadProxy we skip the pending tree and commit directly to the
98 // active tree.
99 return true;
100}
101
[email protected]a8a049c2013-03-11 23:27:06102void SingleThreadProxy::SetVisible(bool visible) {
mithro46adf5a2014-11-19 14:52:40103 TRACE_EVENT1("cc", "SingleThreadProxy::SetVisible", "visible", visible);
khushalsagarb7db1fe2015-11-12 00:51:27104 DebugScopedSetImplThread impl(task_runner_provider_);
sunnypsc3f6e0c2015-07-25 01:00:59105
[email protected]c1bb5af2013-03-13 19:06:27106 layer_tree_host_impl_->SetVisible(visible);
sunnypsc3f6e0c2015-07-25 01:00:59107
[email protected]aeeedad2014-08-22 18:16:22108 if (scheduler_on_impl_thread_)
109 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
[email protected]a8a049c2013-03-11 23:27:06110}
111
danakj1120f4c2016-09-15 02:05:32112void SingleThreadProxy::RequestNewCompositorFrameSink() {
khushalsagarb7db1fe2015-11-12 00:51:27113 DCHECK(task_runner_provider_->IsMainThread());
danakj1120f4c2016-09-15 02:05:32114 compositor_frame_sink_creation_callback_.Cancel();
115 if (compositor_frame_sink_creation_requested_)
jbauman8ab0f9e2014-10-15 02:30:34116 return;
danakj1120f4c2016-09-15 02:05:32117 compositor_frame_sink_creation_requested_ = true;
118 layer_tree_host_->RequestNewCompositorFrameSink();
enne2097cab2014-09-25 20:16:31119}
[email protected]94f206c12012-08-25 00:09:14120
danakj1120f4c2016-09-15 02:05:32121void SingleThreadProxy::ReleaseCompositorFrameSink() {
122 compositor_frame_sink_lost_ = true;
sohan.jyoti3a33d872015-09-18 22:32:55123 if (scheduler_on_impl_thread_)
danakj1120f4c2016-09-15 02:05:32124 scheduler_on_impl_thread_->DidLoseCompositorFrameSink();
125 return layer_tree_host_impl_->ReleaseCompositorFrameSink();
sohan.jyoti3a33d872015-09-18 22:32:55126}
127
danakj1120f4c2016-09-15 02:05:32128void SingleThreadProxy::SetCompositorFrameSink(
129 CompositorFrameSink* compositor_frame_sink) {
khushalsagarb7db1fe2015-11-12 00:51:27130 DCHECK(task_runner_provider_->IsMainThread());
danakj1120f4c2016-09-15 02:05:32131 DCHECK(compositor_frame_sink_creation_requested_);
[email protected]da8e3b72b2014-04-25 02:33:45132
enne7f8fdde2014-12-10 21:32:09133 bool success;
134 {
khushalsagarb7db1fe2015-11-12 00:51:27135 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
136 DebugScopedSetImplThread impl(task_runner_provider_);
danakj1120f4c2016-09-15 02:05:32137 success = layer_tree_host_impl_->InitializeRenderer(compositor_frame_sink);
[email protected]04049fc2013-05-01 03:13:20138 }
139
[email protected]aeeedad2014-08-22 18:16:22140 if (success) {
danakj1120f4c2016-09-15 02:05:32141 layer_tree_host_->DidInitializeCompositorFrameSink();
[email protected]aeeedad2014-08-22 18:16:22142 if (scheduler_on_impl_thread_)
danakj1120f4c2016-09-15 02:05:32143 scheduler_on_impl_thread_->DidCreateAndInitializeCompositorFrameSink();
jbauman399aec1a2014-10-25 02:33:32144 else if (!inside_synchronous_composite_)
145 SetNeedsCommit();
danakj1120f4c2016-09-15 02:05:32146 compositor_frame_sink_creation_requested_ = false;
147 compositor_frame_sink_lost_ = false;
enne7f8fdde2014-12-10 21:32:09148 } else {
danakj1120f4c2016-09-15 02:05:32149 // DidFailToInitializeCompositorFrameSink is treated as a
150 // RequestNewCompositorFrameSink, and so
151 // compositor_frame_sink_creation_requested remains true.
152 layer_tree_host_->DidFailToInitializeCompositorFrameSink();
[email protected]04049fc2013-05-01 03:13:20153 }
[email protected]94f206c12012-08-25 00:09:14154}
155
[email protected]8b9e52b2014-01-17 16:35:31156void SingleThreadProxy::SetNeedsAnimate() {
[email protected]ccc08dc2014-01-30 07:33:20157 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate");
khushalsagarb7db1fe2015-11-12 00:51:27158 DCHECK(task_runner_provider_->IsMainThread());
danakj6c872fc02016-10-22 04:29:49159 single_thread_client_->RequestScheduleAnimation();
brianderson49e101d22015-04-29 00:05:33160 if (animate_requested_)
161 return;
162 animate_requested_ = true;
khushalsagarb7db1fe2015-11-12 00:51:27163 DebugScopedSetImplThread impl(task_runner_provider_);
brianderson49e101d22015-04-29 00:05:33164 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01165 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
[email protected]c5134172013-12-11 06:19:48166}
167
[email protected]8b9e52b2014-01-17 16:35:31168void SingleThreadProxy::SetNeedsUpdateLayers() {
[email protected]ccc08dc2014-01-30 07:33:20169 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers");
khushalsagarb7db1fe2015-11-12 00:51:27170 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22171 SetNeedsCommit();
[email protected]8b9e52b2014-01-17 16:35:31172}
173
enne98f3a6c2014-10-09 20:09:44174void SingleThreadProxy::DoCommit() {
[email protected]ccc08dc2014-01-30 07:33:20175 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit");
khushalsagarb7db1fe2015-11-12 00:51:27176 DCHECK(task_runner_provider_->IsMainThread());
enne98f3a6c2014-10-09 20:09:44177
[email protected]aeeedad2014-08-22 18:16:22178 layer_tree_host_->WillCommit();
caseq7d2f4c92015-02-04 16:43:27179 devtools_instrumentation::ScopedCommitTrace commit_task(
khushalsagarcebe4942016-09-07 23:27:01180 layer_tree_host_->GetId());
[email protected]aeeedad2014-08-22 18:16:22181
[email protected]a8a049c2013-03-11 23:27:06182 // Commit immediately.
183 {
khushalsagarb7db1fe2015-11-12 00:51:27184 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
185 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]f7c01c82013-07-02 22:58:46186
[email protected]9794fb32013-08-29 09:49:59187 // This CapturePostTasks should be destroyed before CommitComplete() is
188 // called since that goes out to the embedder, and we want the embedder
189 // to receive its callbacks before that.
enne98f3a6c2014-10-09 20:09:44190 commit_blocking_task_runner_.reset(new BlockingTaskRunner::CapturePostTasks(
khushalsagarb7db1fe2015-11-12 00:51:27191 task_runner_provider_->blocking_main_thread_task_runner()));
[email protected]9794fb32013-08-29 09:49:59192
danakj94b7e4f2016-07-20 01:49:38193 layer_tree_host_impl_->ReadyToCommit();
[email protected]c1bb5af2013-03-13 19:06:27194 layer_tree_host_impl_->BeginCommit();
[email protected]94f206c12012-08-25 00:09:14195
[email protected]127bdc1a2013-09-11 01:44:48196 if (layer_tree_host_impl_->EvictedUIResourcesExist())
khushalsagar8ec07402016-09-10 03:13:19197 layer_tree_host_->GetUIResourceManager()->RecreateUIResources();
[email protected]127bdc1a2013-09-11 01:44:48198
[email protected]804c8982013-03-13 16:32:21199 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14200
danakj3c3973b2015-08-25 21:50:18201 if (scheduler_on_impl_thread_)
202 scheduler_on_impl_thread_->DidCommit();
203
204 layer_tree_host_impl_->CommitComplete();
205
danakj68803fc2015-06-19 20:55:53206 // Commit goes directly to the active tree, but we need to synchronously
207 // "activate" the tree still during commit to satisfy any potential
208 // SetNextCommitWaitsForActivation calls. Unfortunately, the tree
209 // might not be ready to draw, so DidActivateSyncTree must set
210 // the flag to force the tree to not draw until textures are ready.
211 NotifyReadyToActivate();
enne98f3a6c2014-10-09 20:09:44212 }
213}
214
215void SingleThreadProxy::CommitComplete() {
danakj3c3973b2015-08-25 21:50:18216 // Commit complete happens on the main side after activate to satisfy any
217 // SetNextCommitWaitsForActivation calls.
enne98f3a6c2014-10-09 20:09:44218 DCHECK(!layer_tree_host_impl_->pending_tree())
219 << "Activation is expected to have synchronously occurred by now.";
220 DCHECK(commit_blocking_task_runner_);
221
khushalsagarb7db1fe2015-11-12 00:51:27222 DebugScopedSetMainThread main(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44223 commit_blocking_task_runner_.reset();
[email protected]804c8982013-03-13 16:32:21224 layer_tree_host_->CommitComplete();
[email protected]aeeedad2014-08-22 18:16:22225 layer_tree_host_->DidBeginMainFrame();
[email protected]aeeedad2014-08-22 18:16:22226
[email protected]a8a049c2013-03-11 23:27:06227 next_frame_is_newly_committed_frame_ = true;
[email protected]94f206c12012-08-25 00:09:14228}
229
[email protected]a8a049c2013-03-11 23:27:06230void SingleThreadProxy::SetNeedsCommit() {
khushalsagarb7db1fe2015-11-12 00:51:27231 DCHECK(task_runner_provider_->IsMainThread());
danakj6c872fc02016-10-22 04:29:49232 single_thread_client_->RequestScheduleComposite();
danakjfcdaba122015-04-24 21:41:52233 if (commit_requested_)
234 return;
brianderson49e101d22015-04-29 00:05:33235 commit_requested_ = true;
khushalsagarb7db1fe2015-11-12 00:51:27236 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22237 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01238 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
[email protected]94f206c12012-08-25 00:09:14239}
240
[email protected]0023fc72014-01-10 20:05:06241void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) {
[email protected]ccc08dc2014-01-30 07:33:20242 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw");
khushalsagarb7db1fe2015-11-12 00:51:27243 DCHECK(task_runner_provider_->IsMainThread());
244 DebugScopedSetImplThread impl(task_runner_provider_);
danakje41d978a2016-09-19 21:09:28245 layer_tree_host_impl_->SetViewportDamage(damage_rect);
246 SetNeedsRedrawOnImplThread();
[email protected]94f206c12012-08-25 00:09:14247}
248
[email protected]74b43cc2013-08-30 06:29:27249void SingleThreadProxy::SetNextCommitWaitsForActivation() {
enne98f3a6c2014-10-09 20:09:44250 // Activation always forced in commit, so nothing to do.
khushalsagarb7db1fe2015-11-12 00:51:27251 DCHECK(task_runner_provider_->IsMainThread());
[email protected]74b43cc2013-08-30 06:29:27252}
253
[email protected]a8a049c2013-03-11 23:27:06254void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
khushalsagarb7db1fe2015-11-12 00:51:27255 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22256 // Deferring commits only makes sense if there's a scheduler.
257 if (!scheduler_on_impl_thread_)
258 return;
259 if (defer_commits_ == defer_commits)
260 return;
261
262 if (defer_commits)
263 TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this);
264 else
265 TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this);
266
267 defer_commits_ = defer_commits;
simonhongc6309f792015-01-31 15:47:15268 scheduler_on_impl_thread_->SetDeferCommits(defer_commits);
[email protected]6b16679e2012-10-27 00:44:28269}
270
[email protected]174c6d42014-08-12 01:43:06271bool SingleThreadProxy::CommitRequested() const {
khushalsagarb7db1fe2015-11-12 00:51:27272 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22273 return commit_requested_;
[email protected]174c6d42014-08-12 01:43:06274}
[email protected]a8a049c2013-03-11 23:27:06275
[email protected]a8a049c2013-03-11 23:27:06276void SingleThreadProxy::Stop() {
277 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
khushalsagarb7db1fe2015-11-12 00:51:27278 DCHECK(task_runner_provider_->IsMainThread());
[email protected]a8a049c2013-03-11 23:27:06279 {
khushalsagarb7db1fe2015-11-12 00:51:27280 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
281 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06282
sunnypsda928f0a2016-10-08 00:32:53283 // Prevent the scheduler from performing actions while we're in an
284 // inconsistent state.
285 if (scheduler_on_impl_thread_)
286 scheduler_on_impl_thread_->Stop();
danakj1120f4c2016-09-15 02:05:32287 // Take away the CompositorFrameSink before destroying things so it doesn't
288 // try to call into its client mid-shutdown.
289 layer_tree_host_impl_->ReleaseCompositorFrameSink();
danakjf446a072014-09-27 21:55:48290 scheduler_on_impl_thread_ = nullptr;
291 layer_tree_host_impl_ = nullptr;
[email protected]a8a049c2013-03-11 23:27:06292 }
sunnypsda928f0a2016-10-08 00:32:53293 layer_tree_host_ = nullptr;
[email protected]a8a049c2013-03-11 23:27:06294}
295
flackrf54e9b42016-05-31 15:20:10296void SingleThreadProxy::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) {
297 DCHECK(task_runner_provider_->IsMainThread());
298 DebugScopedSetImplThread impl(task_runner_provider_);
299 layer_tree_host_impl_->SetLayerTreeMutator(std::move(mutator));
300}
301
[email protected]3d9f7432013-04-06 00:35:18302void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
sunnypsad3235e2016-08-09 04:57:52303 TRACE_EVENT1("cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw",
304 can_draw);
khushalsagarb7db1fe2015-11-12 00:51:27305 DCHECK(task_runner_provider_->IsImplThread());
[email protected]aeeedad2014-08-22 18:16:22306 if (scheduler_on_impl_thread_)
307 scheduler_on_impl_thread_->SetCanDraw(can_draw);
[email protected]3d9f7432013-04-06 00:35:18308}
309
[email protected]4f48f6e2013-08-27 06:33:38310void SingleThreadProxy::NotifyReadyToActivate() {
enne98f3a6c2014-10-09 20:09:44311 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate");
khushalsagarb7db1fe2015-11-12 00:51:27312 DebugScopedSetImplThread impl(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44313 if (scheduler_on_impl_thread_)
314 scheduler_on_impl_thread_->NotifyReadyToActivate();
[email protected]4f48f6e2013-08-27 06:33:38315}
316
ernstmdfac03e2014-11-11 20:18:05317void SingleThreadProxy::NotifyReadyToDraw() {
weiliangc8dac5a62015-04-02 06:12:35318 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToDraw");
khushalsagarb7db1fe2015-11-12 00:51:27319 DebugScopedSetImplThread impl(task_runner_provider_);
weiliangc8dac5a62015-04-02 06:12:35320 if (scheduler_on_impl_thread_)
321 scheduler_on_impl_thread_->NotifyReadyToDraw();
ernstmdfac03e2014-11-11 20:18:05322}
323
[email protected]c1bb5af2013-03-13 19:06:27324void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
danakj6c872fc02016-10-22 04:29:49325 single_thread_client_->RequestScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22326 if (scheduler_on_impl_thread_)
327 scheduler_on_impl_thread_->SetNeedsRedraw();
[email protected]a8a049c2013-03-11 23:27:06328}
329
danakja18e826a2015-12-03 00:27:03330void SingleThreadProxy::SetNeedsOneBeginImplFrameOnImplThread() {
331 TRACE_EVENT0("cc",
332 "SingleThreadProxy::SetNeedsOneBeginImplFrameOnImplThread");
danakj6c872fc02016-10-22 04:29:49333 single_thread_client_->RequestScheduleComposite();
mithro719bf6792014-11-10 15:36:47334 if (scheduler_on_impl_thread_)
danakja18e826a2015-12-03 00:27:03335 scheduler_on_impl_thread_->SetNeedsOneBeginImplFrame();
[email protected]43b8f982014-04-30 21:24:33336}
337
vmiura59ea9b4042014-12-09 20:50:39338void SingleThreadProxy::SetNeedsPrepareTilesOnImplThread() {
339 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsPrepareTilesOnImplThread");
enne98f3a6c2014-10-09 20:09:44340 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39341 scheduler_on_impl_thread_->SetNeedsPrepareTiles();
[email protected]c48536a52013-09-14 00:02:08342}
343
[email protected]c1bb5af2013-03-13 19:06:27344void SingleThreadProxy::SetNeedsCommitOnImplThread() {
danakj6c872fc02016-10-22 04:29:49345 single_thread_client_->RequestScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22346 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01347 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
[email protected]a8a049c2013-03-11 23:27:06348}
349
sunnyps7d073dc2015-04-16 23:29:12350void SingleThreadProxy::SetVideoNeedsBeginFrames(bool needs_begin_frames) {
351 TRACE_EVENT1("cc", "SingleThreadProxy::SetVideoNeedsBeginFrames",
352 "needs_begin_frames", needs_begin_frames);
353 // In tests the layer tree is destroyed after the scheduler is.
354 if (scheduler_on_impl_thread_)
355 scheduler_on_impl_thread_->SetVideoNeedsBeginFrames(needs_begin_frames);
356}
357
[email protected]c1bb5af2013-03-13 19:06:27358void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
loysoc601b7b82016-11-10 02:56:44359 std::unique_ptr<MutatorEvents> events) {
[email protected]ccc08dc2014-01-30 07:33:20360 TRACE_EVENT0(
361 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
khushalsagarb7db1fe2015-11-12 00:51:27362 DCHECK(task_runner_provider_->IsImplThread());
363 DebugScopedSetMainThread main(task_runner_provider_);
danakja04855a2015-11-18 20:39:10364 layer_tree_host_->SetAnimationEvents(std::move(events));
[email protected]a8a049c2013-03-11 23:27:06365}
366
sunnypsad3235e2016-08-09 04:57:52367bool SingleThreadProxy::IsInsideDraw() {
368 return inside_draw_;
369}
[email protected]a8a049c2013-03-11 23:27:06370
enne98f3a6c2014-10-09 20:09:44371void SingleThreadProxy::DidActivateSyncTree() {
danakj68803fc2015-06-19 20:55:53372 // Synchronously call to CommitComplete. Resetting
373 // |commit_blocking_task_runner| would make sure all tasks posted during
374 // commit/activation before CommitComplete.
375 CommitComplete();
enne98f3a6c2014-10-09 20:09:44376}
377
brianderson68749812015-07-07 22:39:39378void SingleThreadProxy::WillPrepareTiles() {
khushalsagarb7db1fe2015-11-12 00:51:27379 DCHECK(task_runner_provider_->IsImplThread());
brianderson68749812015-07-07 22:39:39380 if (scheduler_on_impl_thread_)
381 scheduler_on_impl_thread_->WillPrepareTiles();
382}
383
vmiura59ea9b4042014-12-09 20:50:39384void SingleThreadProxy::DidPrepareTiles() {
khushalsagarb7db1fe2015-11-12 00:51:27385 DCHECK(task_runner_provider_->IsImplThread());
enne98f3a6c2014-10-09 20:09:44386 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39387 scheduler_on_impl_thread_->DidPrepareTiles();
enne98f3a6c2014-10-09 20:09:44388}
389
rouslanf7ebd8832015-01-22 01:54:14390void SingleThreadProxy::DidCompletePageScaleAnimationOnImplThread() {
391 layer_tree_host_->DidCompletePageScaleAnimation();
392}
393
danakj1120f4c2016-09-15 02:05:32394void SingleThreadProxy::DidLoseCompositorFrameSinkOnImplThread() {
395 TRACE_EVENT0("cc",
396 "SingleThreadProxy::DidLoseCompositorFrameSinkOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22397 {
khushalsagarb7db1fe2015-11-12 00:51:27398 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22399 // This must happen before we notify the scheduler as it may try to recreate
400 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE.
danakj1120f4c2016-09-15 02:05:32401 layer_tree_host_->DidLoseCompositorFrameSink();
[email protected]aeeedad2014-08-22 18:16:22402 }
danakj6c872fc02016-10-22 04:29:49403 single_thread_client_->DidLoseCompositorFrameSink();
[email protected]aeeedad2014-08-22 18:16:22404 if (scheduler_on_impl_thread_)
danakj1120f4c2016-09-15 02:05:32405 scheduler_on_impl_thread_->DidLoseCompositorFrameSink();
406 compositor_frame_sink_lost_ = true;
[email protected]4d7e46a2013-11-08 05:33:40407}
408
enne19c108582016-04-14 03:35:32409void SingleThreadProxy::SetBeginFrameSource(BeginFrameSource* source) {
enne19c108582016-04-14 03:35:32410 if (scheduler_on_impl_thread_)
411 scheduler_on_impl_thread_->SetBeginFrameSource(source);
412}
413
danakj9d124422016-10-14 03:15:08414void SingleThreadProxy::DidReceiveCompositorFrameAckOnImplThread() {
miletusfed8c43b2015-01-26 20:04:52415 TRACE_EVENT0("cc,benchmark",
danakj9d124422016-10-14 03:15:08416 "SingleThreadProxy::DidReceiveCompositorFrameAckOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22417 if (scheduler_on_impl_thread_)
danakj9d124422016-10-14 03:15:08418 scheduler_on_impl_thread_->DidReceiveCompositorFrameAck();
419 layer_tree_host_->DidReceiveCompositorFrameAck();
[email protected]493067512012-09-19 23:34:10420}
421
danakj1120f4c2016-09-15 02:05:32422void SingleThreadProxy::OnDrawForCompositorFrameSink(
boliu7097ee5b2015-12-17 03:16:09423 bool resourceless_software_draw) {
sunnypseab5ac92015-04-02 20:26:13424 NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor.";
425}
426
[email protected]f0c2a242013-03-15 19:34:52427void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
miletusfed8c43b2015-01-26 20:04:52428 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately");
khushalsagarb7db1fe2015-11-12 00:51:27429 DCHECK(task_runner_provider_->IsMainThread());
mithro51693e382015-05-07 23:52:41430#if DCHECK_IS_ON()
mithroc76d70312015-05-04 23:51:13431 DCHECK(!inside_impl_frame_);
mithro51693e382015-05-07 23:52:41432#endif
jbauman399aec1a2014-10-25 02:33:32433 base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true);
434
danakj1120f4c2016-09-15 02:05:32435 if (compositor_frame_sink_lost_) {
436 RequestNewCompositorFrameSink();
437 // RequestNewCompositorFrameSink could have synchronously created an output
jbauman399aec1a2014-10-25 02:33:32438 // surface, so check again before returning.
danakj1120f4c2016-09-15 02:05:32439 if (compositor_frame_sink_lost_)
jbauman399aec1a2014-10-25 02:33:32440 return;
441 }
[email protected]51f81da2014-05-16 21:29:26442
mithroc76d70312015-05-04 23:51:13443 BeginFrameArgs begin_frame_args(BeginFrameArgs::Create(
eseckler1ce4fd52016-12-22 11:23:40444 BEGINFRAME_FROM_HERE, 0, 1, frame_begin_time, base::TimeTicks(),
mithroc76d70312015-05-04 23:51:13445 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL));
446
447 // Start the impl frame.
enne98f3a6c2014-10-09 20:09:44448 {
khushalsagarb7db1fe2015-11-12 00:51:27449 DebugScopedSetImplThread impl(task_runner_provider_);
mithroc76d70312015-05-04 23:51:13450 WillBeginImplFrame(begin_frame_args);
451 }
452
453 // Run the "main thread" and get it to commit.
454 {
mithro51693e382015-05-07 23:52:41455#if DCHECK_IS_ON()
mithroc76d70312015-05-04 23:51:13456 DCHECK(inside_impl_frame_);
mithro51693e382015-05-07 23:52:41457#endif
enne98f3a6c2014-10-09 20:09:44458 DoBeginMainFrame(begin_frame_args);
459 DoCommit();
[email protected]e0341352013-04-06 05:01:20460
khushalsagar8297ae992016-09-14 20:51:23461 DCHECK_EQ(
462 0u,
463 layer_tree_host_->GetSwapPromiseManager()->num_queued_swap_promises())
enne98f3a6c2014-10-09 20:09:44464 << "Commit should always succeed and transfer promises.";
465 }
466
mithroc76d70312015-05-04 23:51:13467 // Finish the impl frame.
enne98f3a6c2014-10-09 20:09:44468 {
khushalsagarb7db1fe2015-11-12 00:51:27469 DebugScopedSetImplThread impl(task_runner_provider_);
danakj68803fc2015-06-19 20:55:53470 layer_tree_host_impl_->ActivateSyncTree();
471 DCHECK(
472 !layer_tree_host_impl_->active_tree()->needs_update_draw_properties());
473 layer_tree_host_impl_->PrepareTiles();
474 layer_tree_host_impl_->SynchronouslyInitializeAllTiles();
enne69277cb2014-10-29 23:03:40475
danakj12e2f6e2015-08-19 22:25:44476 // TODO(danakj): Don't do this last... we prepared the wrong things. D:
477 layer_tree_host_impl_->Animate();
mithro719bf6792014-11-10 15:36:47478
enne98f3a6c2014-10-09 20:09:44479 LayerTreeHostImpl::FrameData frame;
mithro248d1722015-05-05 05:23:45480 DoComposite(&frame);
enne98f3a6c2014-10-09 20:09:44481
482 // DoComposite could abort, but because this is a synchronous composite
483 // another draw will never be scheduled, so break remaining promises.
484 layer_tree_host_impl_->active_tree()->BreakSwapPromises(
485 SwapPromise::SWAP_FAILS);
mithroc76d70312015-05-04 23:51:13486
mithro51693e382015-05-07 23:52:41487 DidFinishImplFrame();
enne98f3a6c2014-10-09 20:09:44488 }
[email protected]74d9063c2013-01-18 03:14:47489}
490
[email protected]5d8bec72014-07-03 03:03:11491bool SingleThreadProxy::SupportsImplScrolling() const {
492 return false;
493}
494
[email protected]3d9f7432013-04-06 00:35:18495bool SingleThreadProxy::ShouldComposite() const {
khushalsagarb7db1fe2015-11-12 00:51:27496 DCHECK(task_runner_provider_->IsImplThread());
sunnypsad3235e2016-08-09 04:57:52497 return layer_tree_host_impl_->visible() && layer_tree_host_impl_->CanDraw();
[email protected]3d9f7432013-04-06 00:35:18498}
499
danakj1120f4c2016-09-15 02:05:32500void SingleThreadProxy::ScheduleRequestNewCompositorFrameSink() {
501 if (compositor_frame_sink_creation_callback_.IsCancelled() &&
502 !compositor_frame_sink_creation_requested_) {
503 compositor_frame_sink_creation_callback_.Reset(
504 base::Bind(&SingleThreadProxy::RequestNewCompositorFrameSink,
jbauman8ab0f9e2014-10-15 02:30:34505 weak_factory_.GetWeakPtr()));
khushalsagarb7db1fe2015-11-12 00:51:27506 task_runner_provider_->MainThreadTaskRunner()->PostTask(
danakj1120f4c2016-09-15 02:05:32507 FROM_HERE, compositor_frame_sink_creation_callback_.callback());
jbauman8ab0f9e2014-10-15 02:30:34508 }
509}
510
mithro248d1722015-05-05 05:23:45511DrawResult SingleThreadProxy::DoComposite(LayerTreeHostImpl::FrameData* frame) {
[email protected]ccc08dc2014-01-30 07:33:20512 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite");
[email protected]04049fc2013-05-01 03:13:20513
enne98f3a6c2014-10-09 20:09:44514 DrawResult draw_result;
515 bool draw_frame;
[email protected]a8a049c2013-03-11 23:27:06516 {
khushalsagarb7db1fe2015-11-12 00:51:27517 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06518 base::AutoReset<bool> mark_inside(&inside_draw_, true);
519
[email protected]3d9f7432013-04-06 00:35:18520 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
521 // frame, so can only be used when such a frame is possible. Since
522 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
523 // CanDraw() as well.
[email protected]2aae96792014-05-15 23:10:50524 if (!ShouldComposite()) {
[email protected]aeeedad2014-08-22 18:16:22525 return DRAW_ABORTED_CANT_DRAW;
[email protected]3d9f7432013-04-06 00:35:18526 }
[email protected]a8a049c2013-03-11 23:27:06527
danakj097919e72016-09-07 19:50:55528 // This CapturePostTasks should be destroyed before
529 // DidCommitAndDrawFrame() is called since that goes out to the
530 // embedder, and we want the embedder to receive its callbacks before that.
531 // NOTE: This maintains consistent ordering with the ThreadProxy since
532 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
533 // there as the main thread is not blocked, so any posted tasks inside
534 // the swap buffers will execute first.
535 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
536 BlockingTaskRunner::CapturePostTasks blocked(
537 task_runner_provider_->blocking_main_thread_task_runner());
538
enne98f3a6c2014-10-09 20:09:44539 draw_result = layer_tree_host_impl_->PrepareToDraw(frame);
540 draw_frame = draw_result == DRAW_SUCCESS;
robliao27728e62015-03-21 07:39:34541 if (draw_frame) {
danakjaecfcfba2016-09-07 22:33:18542 if (layer_tree_host_impl_->DrawLayers(frame)) {
danakj097919e72016-09-07 19:50:55543 if (scheduler_on_impl_thread_)
danakj9d124422016-10-14 03:15:08544 // Drawing implies we submitted a frame to the CompositorFrameSink.
545 scheduler_on_impl_thread_->DidSubmitCompositorFrame();
danakj6c872fc02016-10-22 04:29:49546 single_thread_client_->DidSubmitCompositorFrame();
danakj097919e72016-09-07 19:50:55547 }
robliao27728e62015-03-21 07:39:34548 }
dnetob71e30c2014-08-25 23:27:20549 layer_tree_host_impl_->DidDrawAllLayers(*frame);
[email protected]a8a049c2013-03-11 23:27:06550
danakj097919e72016-09-07 19:50:55551 bool start_ready_animations = draw_frame;
[email protected]3d9f7432013-04-06 00:35:18552 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
[email protected]aeeedad2014-08-22 18:16:22553 }
554 DidCommitAndDrawFrame();
555
enne98f3a6c2014-10-09 20:09:44556 return draw_result;
[email protected]a8a049c2013-03-11 23:27:06557}
558
[email protected]aeeedad2014-08-22 18:16:22559void SingleThreadProxy::DidCommitAndDrawFrame() {
[email protected]a8a049c2013-03-11 23:27:06560 if (next_frame_is_newly_committed_frame_) {
khushalsagarb7db1fe2015-11-12 00:51:27561 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06562 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21563 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06564 }
565}
566
[email protected]4ea293f72014-08-13 03:03:17567bool SingleThreadProxy::MainFrameWillHappenForTesting() {
danakjfcdaba122015-04-24 21:41:52568 if (!scheduler_on_impl_thread_)
569 return false;
570 return scheduler_on_impl_thread_->MainFrameForTestingWillHappen();
[email protected]4ea293f72014-08-13 03:03:17571}
[email protected]a8a049c2013-03-11 23:27:06572
[email protected]aeeedad2014-08-22 18:16:22573void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) {
danakja18e826a2015-12-03 00:27:03574 DebugScopedSetImplThread impl(task_runner_provider_);
mithro51693e382015-05-07 23:52:41575#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02576 DCHECK(!inside_impl_frame_)
577 << "WillBeginImplFrame called while already inside an impl frame!";
578 inside_impl_frame_ = true;
mithro51693e382015-05-07 23:52:41579#endif
[email protected]aeeedad2014-08-22 18:16:22580 layer_tree_host_impl_->WillBeginImplFrame(args);
581}
582
brianderson266dc3a2015-11-12 03:16:40583void SingleThreadProxy::ScheduledActionSendBeginMainFrame(
584 const BeginFrameArgs& begin_frame_args) {
[email protected]aeeedad2014-08-22 18:16:22585 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame");
sunnypsad3235e2016-08-09 04:57:52586#if DCHECK_IS_ON()
[email protected]aeeedad2014-08-22 18:16:22587 // Although this proxy is single-threaded, it's problematic to synchronously
588 // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This
589 // could cause a commit to occur in between a series of SetNeedsCommit calls
590 // (i.e. property modifications) causing some to fall on one frame and some to
591 // fall on the next. Doing it asynchronously instead matches the semantics of
592 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a
593 // synchronous commit.
mithro69fd3bb52015-05-01 03:45:02594 DCHECK(inside_impl_frame_)
595 << "BeginMainFrame should only be sent inside a BeginImplFrame";
mithro51693e382015-05-07 23:52:41596#endif
mithro69fd3bb52015-05-01 03:45:02597
khushalsagarb7db1fe2015-11-12 00:51:27598 task_runner_provider_->MainThreadTaskRunner()->PostTask(
mithro69fd3bb52015-05-01 03:45:02599 FROM_HERE, base::Bind(&SingleThreadProxy::BeginMainFrame,
600 weak_factory_.GetWeakPtr(), begin_frame_args));
[email protected]aeeedad2014-08-22 18:16:22601}
602
rmcilroy0a19362a2015-02-18 12:34:25603void SingleThreadProxy::SendBeginMainFrameNotExpectedSoon() {
604 layer_tree_host_->BeginMainFrameNotExpectedSoon();
605}
606
mithro69fd3bb52015-05-01 03:45:02607void SingleThreadProxy::BeginMainFrame(const BeginFrameArgs& begin_frame_args) {
brianderson21aef162015-11-11 05:12:23608 if (scheduler_on_impl_thread_) {
609 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(
610 base::TimeTicks::Now());
611 }
612
danakjfcdaba122015-04-24 21:41:52613 commit_requested_ = false;
brianderson49e101d22015-04-29 00:05:33614 animate_requested_ = false;
danakjfcdaba122015-04-24 21:41:52615
[email protected]aeeedad2014-08-22 18:16:22616 if (defer_commits_) {
simonhongc6309f792015-01-31 15:47:15617 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit",
618 TRACE_EVENT_SCOPE_THREAD);
619 BeginMainFrameAbortedOnImplThread(
620 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT);
[email protected]aeeedad2014-08-22 18:16:22621 return;
622 }
623
enne98f3a6c2014-10-09 20:09:44624 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous
625 // commit.
khushalsagar8297ae992016-09-14 20:51:23626 ScopedAbortRemainingSwapPromises swap_promise_checker(
627 layer_tree_host_->GetSwapPromiseManager());
[email protected]aeeedad2014-08-22 18:16:22628
khushalsagarcebe4942016-09-07 23:27:01629 if (!layer_tree_host_->IsVisible()) {
[email protected]aeeedad2014-08-22 18:16:22630 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD);
mithrof7a21502014-12-17 03:24:48631 BeginMainFrameAbortedOnImplThread(
632 CommitEarlyOutReason::ABORTED_NOT_VISIBLE);
[email protected]aeeedad2014-08-22 18:16:22633 return;
634 }
635
danakjfcdaba122015-04-24 21:41:52636 // Prevent new commits from being requested inside DoBeginMainFrame.
brianderson49e101d22015-04-29 00:05:33637 // Note: We do not want to prevent SetNeedsAnimate from requesting
638 // a commit here.
danakjfcdaba122015-04-24 21:41:52639 commit_requested_ = true;
640
enne98f3a6c2014-10-09 20:09:44641 DoBeginMainFrame(begin_frame_args);
642}
643
644void SingleThreadProxy::DoBeginMainFrame(
645 const BeginFrameArgs& begin_frame_args) {
tapted4b70c522016-08-13 09:09:32646 // In the single-threaded case, the scale deltas should never be touched on
647 // the impl layer tree. However, impl-side scroll deltas may be manipulated
648 // directly via the InputHandler on the UI thread.
649 std::unique_ptr<ScrollAndScaleSet> scroll_info =
650 layer_tree_host_impl_->ProcessScrollDeltas();
651 DCHECK_EQ(1.f, scroll_info->page_scale_delta);
652 layer_tree_host_->ApplyScrollAndScale(scroll_info.get());
653
enne98f3a6c2014-10-09 20:09:44654 layer_tree_host_->WillBeginMainFrame();
655 layer_tree_host_->BeginMainFrame(begin_frame_args);
656 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time);
wkorman7265db012015-11-03 04:08:25657 layer_tree_host_->RequestMainFrameUpdate();
enne98f3a6c2014-10-09 20:09:44658
danakjfcdaba122015-04-24 21:41:52659 // New commits requested inside UpdateLayers should be respected.
660 commit_requested_ = false;
661
danakj5f46636a2015-06-19 00:01:40662 layer_tree_host_->UpdateLayers();
enne98f3a6c2014-10-09 20:09:44663
mithrof7a21502014-12-17 03:24:48664 // TODO(enne): SingleThreadProxy does not support cancelling commits yet,
665 // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside
666 // thread_proxy.cc
brianderson21aef162015-11-11 05:12:23667 if (scheduler_on_impl_thread_)
enne98f3a6c2014-10-09 20:09:44668 scheduler_on_impl_thread_->NotifyReadyToCommit();
[email protected]aeeedad2014-08-22 18:16:22669}
670
mithrof7a21502014-12-17 03:24:48671void SingleThreadProxy::BeginMainFrameAbortedOnImplThread(
672 CommitEarlyOutReason reason) {
khushalsagarb7db1fe2015-11-12 00:51:27673 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22674 DCHECK(scheduler_on_impl_thread_->CommitPending());
675 DCHECK(!layer_tree_host_impl_->pending_tree());
676
sunnypsad3235e2016-08-09 04:57:52677 std::vector<std::unique_ptr<SwapPromise>> empty_swap_promises;
678 layer_tree_host_impl_->BeginMainFrameAborted(reason,
679 std::move(empty_swap_promises));
mithrof7a21502014-12-17 03:24:48680 scheduler_on_impl_thread_->BeginMainFrameAborted(reason);
[email protected]aeeedad2014-08-22 18:16:22681}
682
danakj9d124422016-10-14 03:15:08683DrawResult SingleThreadProxy::ScheduledActionDrawIfPossible() {
khushalsagarb7db1fe2015-11-12 00:51:27684 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22685 LayerTreeHostImpl::FrameData frame;
mithro248d1722015-05-05 05:23:45686 return DoComposite(&frame);
[email protected]aeeedad2014-08-22 18:16:22687}
688
danakj9d124422016-10-14 03:15:08689DrawResult SingleThreadProxy::ScheduledActionDrawForced() {
[email protected]aeeedad2014-08-22 18:16:22690 NOTREACHED();
691 return INVALID_RESULT;
692}
693
694void SingleThreadProxy::ScheduledActionCommit() {
khushalsagarb7db1fe2015-11-12 00:51:27695 DebugScopedSetMainThread main(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44696 DoCommit();
[email protected]aeeedad2014-08-22 18:16:22697}
698
[email protected]aeeedad2014-08-22 18:16:22699void SingleThreadProxy::ScheduledActionActivateSyncTree() {
khushalsagarb7db1fe2015-11-12 00:51:27700 DebugScopedSetImplThread impl(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44701 layer_tree_host_impl_->ActivateSyncTree();
[email protected]aeeedad2014-08-22 18:16:22702}
703
danakj1120f4c2016-09-15 02:05:32704void SingleThreadProxy::ScheduledActionBeginCompositorFrameSinkCreation() {
khushalsagarb7db1fe2015-11-12 00:51:27705 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22706 DCHECK(scheduler_on_impl_thread_);
707 // If possible, create the output surface in a post task. Synchronously
708 // creating the output surface makes tests more awkward since this differs
709 // from the ThreadProxy behavior. However, sometimes there is no
710 // task runner.
khushalsagarb7db1fe2015-11-12 00:51:27711 if (task_runner_provider_->MainThreadTaskRunner()) {
danakj1120f4c2016-09-15 02:05:32712 ScheduleRequestNewCompositorFrameSink();
[email protected]aeeedad2014-08-22 18:16:22713 } else {
danakj1120f4c2016-09-15 02:05:32714 RequestNewCompositorFrameSink();
[email protected]aeeedad2014-08-22 18:16:22715 }
716}
717
vmiura59ea9b4042014-12-09 20:50:39718void SingleThreadProxy::ScheduledActionPrepareTiles() {
719 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionPrepareTiles");
khushalsagarb7db1fe2015-11-12 00:51:27720 DebugScopedSetImplThread impl(task_runner_provider_);
vmiura59ea9b4042014-12-09 20:50:39721 layer_tree_host_impl_->PrepareTiles();
[email protected]aeeedad2014-08-22 18:16:22722}
723
danakj1120f4c2016-09-15 02:05:32724void SingleThreadProxy::ScheduledActionInvalidateCompositorFrameSink() {
sunnypseab5ac92015-04-02 20:26:13725 NOTREACHED();
726}
727
mdjones2ee41afd2016-10-27 16:50:20728void SingleThreadProxy::UpdateBrowserControlsState(
729 BrowserControlsState constraints,
730 BrowserControlsState current,
731 bool animate) {
732 NOTREACHED() << "Browser Controls are used only in threaded mode";
khushalsagarc646cd62015-10-17 00:05:48733}
734
mithro51693e382015-05-07 23:52:41735void SingleThreadProxy::DidFinishImplFrame() {
736 layer_tree_host_impl_->DidFinishImplFrame();
737#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02738 DCHECK(inside_impl_frame_)
mithro51693e382015-05-07 23:52:41739 << "DidFinishImplFrame called while not inside an impl frame!";
mithro69fd3bb52015-05-01 03:45:02740 inside_impl_frame_ = false;
mithro51693e382015-05-07 23:52:41741#endif
[email protected]aeeedad2014-08-22 18:16:22742}
743
[email protected]bc5e77c2012-11-05 20:00:49744} // namespace cc