blob: 886d59b770b536df8acf5ccb9892d98cfb2b0d6f [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"
loysoe926437dd2016-01-14 22:55:3011#include "cc/animation/animation_events.h"
[email protected]adbe30f2013-10-11 21:12:3312#include "cc/debug/benchmark_instrumentation.h"
caseq7d2f4c92015-02-04 16:43:2713#include "cc/debug/devtools_instrumentation.h"
[email protected]7f0d825f2013-03-18 07:24:3014#include "cc/output/context_provider.h"
15#include "cc/output/output_surface.h"
[email protected]89e82672013-03-18 07:50:5616#include "cc/quads/draw_quad.h"
khushalsagar8ec07402016-09-10 03:13:1917#include "cc/resources/ui_resource_manager.h"
mithrof7a21502014-12-17 03:24:4818#include "cc/scheduler/commit_earlyout_reason.h"
briandersonc9f50352015-06-24 03:38:5819#include "cc/scheduler/compositor_timing_history.h"
danakj15ec5242016-06-15 22:13:3720#include "cc/scheduler/delay_based_time_source.h"
briandersonc9f50352015-06-24 03:38:5821#include "cc/scheduler/scheduler.h"
[email protected]556fd292013-03-18 08:03:0422#include "cc/trees/layer_tree_host.h"
jaydasika13c05062016-04-01 18:12:2723#include "cc/trees/layer_tree_host_common.h"
[email protected]943528e2013-11-07 05:01:3224#include "cc/trees/layer_tree_host_single_thread_client.h"
[email protected]556fd292013-03-18 08:03:0425#include "cc/trees/layer_tree_impl.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(
[email protected]943528e2013-11-07 05:01:3231 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
khushalsagar767dd522015-12-16 05:14:0538SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host,
39 LayerTreeHostSingleThreadClient* client,
40 TaskRunnerProvider* task_runner_provider)
khushalsagarb7db1fe2015-11-12 00:51:2741 : layer_tree_host_(layer_tree_host),
[email protected]943528e2013-11-07 05:01:3242 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),
jbauman8ab0f9e2014-10-15 02:30:3453 output_surface_creation_requested_(false),
danakjbe9c59ee2016-08-26 18:24:5654 output_surface_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
khushalsagar767dd522015-12-16 05:14:0562void SingleThreadProxy::Start(
danakj60bc3bc2016-04-09 00:24:4863 std::unique_ptr<BeginFrameSource> external_begin_frame_source) {
khushalsagar767dd522015-12-16 05:14:0564 DebugScopedSetImplThread impl(task_runner_provider_);
65 external_begin_frame_source_ = std::move(external_begin_frame_source);
66
khushalsagarcebe4942016-09-07 23:27:0167 const LayerTreeSettings& settings = layer_tree_host_->GetSettings();
68 if (settings.single_thread_proxy_scheduler && !scheduler_on_impl_thread_) {
69 SchedulerSettings scheduler_settings(settings.ToSchedulerSettings());
danakj5f2e92de2015-06-20 00:25:5870 scheduler_settings.commit_to_active_tree = CommitToActiveTree();
briandersonc9f50352015-06-24 03:38:5871
danakj60bc3bc2016-04-09 00:24:4872 std::unique_ptr<CompositorTimingHistory> compositor_timing_history(
briandersonc9f50352015-06-24 03:38:5873 new CompositorTimingHistory(
briandersonbb917dd2016-02-20 05:21:1474 scheduler_settings.using_synchronous_renderer_compositor,
briandersonc68220f2015-07-20 20:08:3575 CompositorTimingHistory::BROWSER_UMA,
khushalsagar767dd522015-12-16 05:14:0576 layer_tree_host_->rendering_stats_instrumentation()));
briandersonc9f50352015-06-24 03:38:5877
enne5593b842016-09-01 20:21:1678 // BFS must either be external or come from the output surface. If
79 // external, it must be provided. If from the output surface, it must
80 // not be provided.
81 // TODO(enne): Make all BFS come from the output surface.
khushalsagarcebe4942016-09-07 23:27:0182 DCHECK(settings.use_external_begin_frame_source ^
83 settings.use_output_surface_begin_frame_source);
84 DCHECK(!settings.use_external_begin_frame_source ||
enne5593b842016-09-01 20:21:1685 external_begin_frame_source_);
khushalsagarcebe4942016-09-07 23:27:0186 DCHECK(!settings.use_output_surface_begin_frame_source ||
87 !external_begin_frame_source_);
danakja04855a2015-11-18 20:39:1088 scheduler_on_impl_thread_ =
khushalsagarcebe4942016-09-07 23:27:0189 Scheduler::Create(this, scheduler_settings, layer_tree_host_->GetId(),
danakja04855a2015-11-18 20:39:1090 task_runner_provider_->MainThreadTaskRunner(),
enne5593b842016-09-01 20:21:1691 external_begin_frame_source_.get(),
92 std::move(compositor_timing_history));
danakjfcdaba122015-04-24 21:41:5293 }
[email protected]94f206c12012-08-25 00:09:1494
[email protected]804c8982013-03-13 16:32:2195 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
[email protected]a8a049c2013-03-11 23:27:0696}
97
98SingleThreadProxy::~SingleThreadProxy() {
99 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy");
khushalsagarb7db1fe2015-11-12 00:51:27100 DCHECK(task_runner_provider_->IsMainThread());
[email protected]04049fc2013-05-01 03:13:20101 // Make sure Stop() got called or never Started.
102 DCHECK(!layer_tree_host_impl_);
[email protected]a8a049c2013-03-11 23:27:06103}
104
[email protected]a8a049c2013-03-11 23:27:06105bool SingleThreadProxy::IsStarted() const {
khushalsagarb7db1fe2015-11-12 00:51:27106 DCHECK(task_runner_provider_->IsMainThread());
dcheng5d64b522016-01-20 01:41:02107 return !!layer_tree_host_impl_;
[email protected]94f206c12012-08-25 00:09:14108}
109
danakj009cdfdf2015-02-17 22:35:14110bool SingleThreadProxy::CommitToActiveTree() const {
111 // With SingleThreadProxy we skip the pending tree and commit directly to the
112 // active tree.
113 return true;
114}
115
[email protected]a8a049c2013-03-11 23:27:06116void SingleThreadProxy::SetVisible(bool visible) {
mithro46adf5a2014-11-19 14:52:40117 TRACE_EVENT1("cc", "SingleThreadProxy::SetVisible", "visible", visible);
khushalsagarb7db1fe2015-11-12 00:51:27118 DebugScopedSetImplThread impl(task_runner_provider_);
sunnypsc3f6e0c2015-07-25 01:00:59119
[email protected]c1bb5af2013-03-13 19:06:27120 layer_tree_host_impl_->SetVisible(visible);
sunnypsc3f6e0c2015-07-25 01:00:59121
[email protected]aeeedad2014-08-22 18:16:22122 if (scheduler_on_impl_thread_)
123 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
[email protected]a8a049c2013-03-11 23:27:06124}
125
enne2097cab2014-09-25 20:16:31126void SingleThreadProxy::RequestNewOutputSurface() {
khushalsagarb7db1fe2015-11-12 00:51:27127 DCHECK(task_runner_provider_->IsMainThread());
jbauman8ab0f9e2014-10-15 02:30:34128 output_surface_creation_callback_.Cancel();
129 if (output_surface_creation_requested_)
130 return;
131 output_surface_creation_requested_ = true;
enne2097cab2014-09-25 20:16:31132 layer_tree_host_->RequestNewOutputSurface();
133}
[email protected]94f206c12012-08-25 00:09:14134
revemand180dfc32015-09-24 00:19:43135void SingleThreadProxy::ReleaseOutputSurface() {
danakjbe9c59ee2016-08-26 18:24:56136 output_surface_lost_ = true;
sohan.jyoti3a33d872015-09-18 22:32:55137 if (scheduler_on_impl_thread_)
138 scheduler_on_impl_thread_->DidLoseOutputSurface();
139 return layer_tree_host_impl_->ReleaseOutputSurface();
140}
141
revemand180dfc32015-09-24 00:19:43142void SingleThreadProxy::SetOutputSurface(OutputSurface* output_surface) {
khushalsagarb7db1fe2015-11-12 00:51:27143 DCHECK(task_runner_provider_->IsMainThread());
enne5232fbb2015-01-27 21:22:41144 DCHECK(output_surface_creation_requested_);
[email protected]da8e3b72b2014-04-25 02:33:45145
enne7f8fdde2014-12-10 21:32:09146 bool success;
147 {
khushalsagarb7db1fe2015-11-12 00:51:27148 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
149 DebugScopedSetImplThread impl(task_runner_provider_);
revemand180dfc32015-09-24 00:19:43150 success = layer_tree_host_impl_->InitializeRenderer(output_surface);
[email protected]04049fc2013-05-01 03:13:20151 }
152
[email protected]aeeedad2014-08-22 18:16:22153 if (success) {
enne7f8fdde2014-12-10 21:32:09154 layer_tree_host_->DidInitializeOutputSurface();
[email protected]aeeedad2014-08-22 18:16:22155 if (scheduler_on_impl_thread_)
156 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface();
jbauman399aec1a2014-10-25 02:33:32157 else if (!inside_synchronous_composite_)
158 SetNeedsCommit();
enne5232fbb2015-01-27 21:22:41159 output_surface_creation_requested_ = false;
danakjbe9c59ee2016-08-26 18:24:56160 output_surface_lost_ = false;
enne7f8fdde2014-12-10 21:32:09161 } else {
enne5232fbb2015-01-27 21:22:41162 // DidFailToInitializeOutputSurface is treated as a RequestNewOutputSurface,
163 // and so output_surface_creation_requested remains true.
enne7f8fdde2014-12-10 21:32:09164 layer_tree_host_->DidFailToInitializeOutputSurface();
[email protected]04049fc2013-05-01 03:13:20165 }
[email protected]94f206c12012-08-25 00:09:14166}
167
[email protected]8b9e52b2014-01-17 16:35:31168void SingleThreadProxy::SetNeedsAnimate() {
[email protected]ccc08dc2014-01-30 07:33:20169 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate");
khushalsagarb7db1fe2015-11-12 00:51:27170 DCHECK(task_runner_provider_->IsMainThread());
danakj53eccbc2016-03-02 22:51:07171 client_->RequestScheduleAnimation();
brianderson49e101d22015-04-29 00:05:33172 if (animate_requested_)
173 return;
174 animate_requested_ = true;
khushalsagarb7db1fe2015-11-12 00:51:27175 DebugScopedSetImplThread impl(task_runner_provider_);
brianderson49e101d22015-04-29 00:05:33176 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01177 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
[email protected]c5134172013-12-11 06:19:48178}
179
[email protected]8b9e52b2014-01-17 16:35:31180void SingleThreadProxy::SetNeedsUpdateLayers() {
[email protected]ccc08dc2014-01-30 07:33:20181 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers");
khushalsagarb7db1fe2015-11-12 00:51:27182 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22183 SetNeedsCommit();
[email protected]8b9e52b2014-01-17 16:35:31184}
185
enne98f3a6c2014-10-09 20:09:44186void SingleThreadProxy::DoCommit() {
[email protected]ccc08dc2014-01-30 07:33:20187 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit");
khushalsagarb7db1fe2015-11-12 00:51:27188 DCHECK(task_runner_provider_->IsMainThread());
enne98f3a6c2014-10-09 20:09:44189
[email protected]aeeedad2014-08-22 18:16:22190 layer_tree_host_->WillCommit();
caseq7d2f4c92015-02-04 16:43:27191 devtools_instrumentation::ScopedCommitTrace commit_task(
khushalsagarcebe4942016-09-07 23:27:01192 layer_tree_host_->GetId());
[email protected]aeeedad2014-08-22 18:16:22193
[email protected]a8a049c2013-03-11 23:27:06194 // Commit immediately.
195 {
khushalsagarb7db1fe2015-11-12 00:51:27196 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
197 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]f7c01c82013-07-02 22:58:46198
[email protected]9794fb32013-08-29 09:49:59199 // This CapturePostTasks should be destroyed before CommitComplete() is
200 // called since that goes out to the embedder, and we want the embedder
201 // to receive its callbacks before that.
enne98f3a6c2014-10-09 20:09:44202 commit_blocking_task_runner_.reset(new BlockingTaskRunner::CapturePostTasks(
khushalsagarb7db1fe2015-11-12 00:51:27203 task_runner_provider_->blocking_main_thread_task_runner()));
[email protected]9794fb32013-08-29 09:49:59204
danakj94b7e4f2016-07-20 01:49:38205 layer_tree_host_impl_->ReadyToCommit();
[email protected]c1bb5af2013-03-13 19:06:27206 layer_tree_host_impl_->BeginCommit();
[email protected]94f206c12012-08-25 00:09:14207
[email protected]127bdc1a2013-09-11 01:44:48208 if (layer_tree_host_impl_->EvictedUIResourcesExist())
khushalsagar8ec07402016-09-10 03:13:19209 layer_tree_host_->GetUIResourceManager()->RecreateUIResources();
[email protected]127bdc1a2013-09-11 01:44:48210
[email protected]804c8982013-03-13 16:32:21211 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14212
danakj3c3973b2015-08-25 21:50:18213 if (scheduler_on_impl_thread_)
214 scheduler_on_impl_thread_->DidCommit();
215
216 layer_tree_host_impl_->CommitComplete();
217
danakj68803fc2015-06-19 20:55:53218 // Commit goes directly to the active tree, but we need to synchronously
219 // "activate" the tree still during commit to satisfy any potential
220 // SetNextCommitWaitsForActivation calls. Unfortunately, the tree
221 // might not be ready to draw, so DidActivateSyncTree must set
222 // the flag to force the tree to not draw until textures are ready.
223 NotifyReadyToActivate();
enne98f3a6c2014-10-09 20:09:44224 }
225}
226
227void SingleThreadProxy::CommitComplete() {
danakj3c3973b2015-08-25 21:50:18228 // Commit complete happens on the main side after activate to satisfy any
229 // SetNextCommitWaitsForActivation calls.
enne98f3a6c2014-10-09 20:09:44230 DCHECK(!layer_tree_host_impl_->pending_tree())
231 << "Activation is expected to have synchronously occurred by now.";
232 DCHECK(commit_blocking_task_runner_);
233
khushalsagarb7db1fe2015-11-12 00:51:27234 DebugScopedSetMainThread main(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44235 commit_blocking_task_runner_.reset();
[email protected]804c8982013-03-13 16:32:21236 layer_tree_host_->CommitComplete();
[email protected]aeeedad2014-08-22 18:16:22237 layer_tree_host_->DidBeginMainFrame();
[email protected]aeeedad2014-08-22 18:16:22238
[email protected]a8a049c2013-03-11 23:27:06239 next_frame_is_newly_committed_frame_ = true;
[email protected]94f206c12012-08-25 00:09:14240}
241
[email protected]a8a049c2013-03-11 23:27:06242void SingleThreadProxy::SetNeedsCommit() {
khushalsagarb7db1fe2015-11-12 00:51:27243 DCHECK(task_runner_provider_->IsMainThread());
danakj53eccbc2016-03-02 22:51:07244 client_->RequestScheduleComposite();
danakjfcdaba122015-04-24 21:41:52245 if (commit_requested_)
246 return;
brianderson49e101d22015-04-29 00:05:33247 commit_requested_ = true;
khushalsagarb7db1fe2015-11-12 00:51:27248 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22249 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01250 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
[email protected]94f206c12012-08-25 00:09:14251}
252
[email protected]0023fc72014-01-10 20:05:06253void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) {
[email protected]ccc08dc2014-01-30 07:33:20254 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw");
khushalsagarb7db1fe2015-11-12 00:51:27255 DCHECK(task_runner_provider_->IsMainThread());
256 DebugScopedSetImplThread impl(task_runner_provider_);
danakj53eccbc2016-03-02 22:51:07257 client_->RequestScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22258 SetNeedsRedrawRectOnImplThread(damage_rect);
[email protected]94f206c12012-08-25 00:09:14259}
260
[email protected]74b43cc2013-08-30 06:29:27261void SingleThreadProxy::SetNextCommitWaitsForActivation() {
enne98f3a6c2014-10-09 20:09:44262 // Activation always forced in commit, so nothing to do.
khushalsagarb7db1fe2015-11-12 00:51:27263 DCHECK(task_runner_provider_->IsMainThread());
[email protected]74b43cc2013-08-30 06:29:27264}
265
[email protected]a8a049c2013-03-11 23:27:06266void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
khushalsagarb7db1fe2015-11-12 00:51:27267 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22268 // Deferring commits only makes sense if there's a scheduler.
269 if (!scheduler_on_impl_thread_)
270 return;
271 if (defer_commits_ == defer_commits)
272 return;
273
274 if (defer_commits)
275 TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this);
276 else
277 TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this);
278
279 defer_commits_ = defer_commits;
simonhongc6309f792015-01-31 15:47:15280 scheduler_on_impl_thread_->SetDeferCommits(defer_commits);
[email protected]6b16679e2012-10-27 00:44:28281}
282
[email protected]174c6d42014-08-12 01:43:06283bool SingleThreadProxy::CommitRequested() const {
khushalsagarb7db1fe2015-11-12 00:51:27284 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22285 return commit_requested_;
[email protected]174c6d42014-08-12 01:43:06286}
[email protected]a8a049c2013-03-11 23:27:06287
[email protected]174c6d42014-08-12 01:43:06288bool SingleThreadProxy::BeginMainFrameRequested() const {
khushalsagarb7db1fe2015-11-12 00:51:27289 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22290 // If there is no scheduler, then there can be no pending begin frame,
291 // as all frames are all manually initiated by the embedder of cc.
292 if (!scheduler_on_impl_thread_)
293 return false;
294 return commit_requested_;
[email protected]174c6d42014-08-12 01:43:06295}
[email protected]971728d2013-10-26 10:39:31296
[email protected]a8a049c2013-03-11 23:27:06297void SingleThreadProxy::Stop() {
298 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
khushalsagarb7db1fe2015-11-12 00:51:27299 DCHECK(task_runner_provider_->IsMainThread());
[email protected]a8a049c2013-03-11 23:27:06300 {
khushalsagarb7db1fe2015-11-12 00:51:27301 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
302 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06303
danakja40dd4482016-06-28 01:14:10304 // Take away the OutputSurface before destroying things so it doesn't try
305 // to call into its client mid-shutdown.
306 layer_tree_host_impl_->ReleaseOutputSurface();
307
skyostil3976a3f2014-09-04 22:07:23308 BlockingTaskRunner::CapturePostTasks blocked(
khushalsagarb7db1fe2015-11-12 00:51:27309 task_runner_provider_->blocking_main_thread_task_runner());
danakjf446a072014-09-27 21:55:48310 scheduler_on_impl_thread_ = nullptr;
311 layer_tree_host_impl_ = nullptr;
[email protected]a8a049c2013-03-11 23:27:06312 }
[email protected]7aba6662013-03-12 10:17:34313 layer_tree_host_ = NULL;
[email protected]a8a049c2013-03-11 23:27:06314}
315
flackrf54e9b42016-05-31 15:20:10316void SingleThreadProxy::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) {
317 DCHECK(task_runner_provider_->IsMainThread());
318 DebugScopedSetImplThread impl(task_runner_provider_);
319 layer_tree_host_impl_->SetLayerTreeMutator(std::move(mutator));
320}
321
[email protected]3d9f7432013-04-06 00:35:18322void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
sunnypsad3235e2016-08-09 04:57:52323 TRACE_EVENT1("cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw",
324 can_draw);
khushalsagarb7db1fe2015-11-12 00:51:27325 DCHECK(task_runner_provider_->IsImplThread());
[email protected]aeeedad2014-08-22 18:16:22326 if (scheduler_on_impl_thread_)
327 scheduler_on_impl_thread_->SetCanDraw(can_draw);
[email protected]3d9f7432013-04-06 00:35:18328}
329
[email protected]4f48f6e2013-08-27 06:33:38330void SingleThreadProxy::NotifyReadyToActivate() {
enne98f3a6c2014-10-09 20:09:44331 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate");
khushalsagarb7db1fe2015-11-12 00:51:27332 DebugScopedSetImplThread impl(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44333 if (scheduler_on_impl_thread_)
334 scheduler_on_impl_thread_->NotifyReadyToActivate();
[email protected]4f48f6e2013-08-27 06:33:38335}
336
ernstmdfac03e2014-11-11 20:18:05337void SingleThreadProxy::NotifyReadyToDraw() {
weiliangc8dac5a62015-04-02 06:12:35338 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToDraw");
khushalsagarb7db1fe2015-11-12 00:51:27339 DebugScopedSetImplThread impl(task_runner_provider_);
weiliangc8dac5a62015-04-02 06:12:35340 if (scheduler_on_impl_thread_)
341 scheduler_on_impl_thread_->NotifyReadyToDraw();
ernstmdfac03e2014-11-11 20:18:05342}
343
[email protected]c1bb5af2013-03-13 19:06:27344void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
danakj53eccbc2016-03-02 22:51:07345 client_->RequestScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22346 if (scheduler_on_impl_thread_)
347 scheduler_on_impl_thread_->SetNeedsRedraw();
[email protected]a8a049c2013-03-11 23:27:06348}
349
danakja18e826a2015-12-03 00:27:03350void SingleThreadProxy::SetNeedsOneBeginImplFrameOnImplThread() {
351 TRACE_EVENT0("cc",
352 "SingleThreadProxy::SetNeedsOneBeginImplFrameOnImplThread");
danakj53eccbc2016-03-02 22:51:07353 client_->RequestScheduleComposite();
mithro719bf6792014-11-10 15:36:47354 if (scheduler_on_impl_thread_)
danakja18e826a2015-12-03 00:27:03355 scheduler_on_impl_thread_->SetNeedsOneBeginImplFrame();
[email protected]43b8f982014-04-30 21:24:33356}
357
vmiura59ea9b4042014-12-09 20:50:39358void SingleThreadProxy::SetNeedsPrepareTilesOnImplThread() {
359 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsPrepareTilesOnImplThread");
enne98f3a6c2014-10-09 20:09:44360 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39361 scheduler_on_impl_thread_->SetNeedsPrepareTiles();
[email protected]c48536a52013-09-14 00:02:08362}
363
[email protected]0023fc72014-01-10 20:05:06364void SingleThreadProxy::SetNeedsRedrawRectOnImplThread(
365 const gfx::Rect& damage_rect) {
[email protected]1cd9f5552013-04-26 04:22:03366 layer_tree_host_impl_->SetViewportDamage(damage_rect);
[email protected]aeeedad2014-08-22 18:16:22367 SetNeedsRedrawOnImplThread();
[email protected]1cd9f5552013-04-26 04:22:03368}
369
[email protected]c1bb5af2013-03-13 19:06:27370void SingleThreadProxy::SetNeedsCommitOnImplThread() {
danakj53eccbc2016-03-02 22:51:07371 client_->RequestScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22372 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01373 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
[email protected]a8a049c2013-03-11 23:27:06374}
375
sunnyps7d073dc2015-04-16 23:29:12376void SingleThreadProxy::SetVideoNeedsBeginFrames(bool needs_begin_frames) {
377 TRACE_EVENT1("cc", "SingleThreadProxy::SetVideoNeedsBeginFrames",
378 "needs_begin_frames", needs_begin_frames);
379 // In tests the layer tree is destroyed after the scheduler is.
380 if (scheduler_on_impl_thread_)
381 scheduler_on_impl_thread_->SetVideoNeedsBeginFrames(needs_begin_frames);
382}
383
[email protected]c1bb5af2013-03-13 19:06:27384void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
danakj60bc3bc2016-04-09 00:24:48385 std::unique_ptr<AnimationEvents> events) {
[email protected]ccc08dc2014-01-30 07:33:20386 TRACE_EVENT0(
387 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
khushalsagarb7db1fe2015-11-12 00:51:27388 DCHECK(task_runner_provider_->IsImplThread());
389 DebugScopedSetMainThread main(task_runner_provider_);
danakja04855a2015-11-18 20:39:10390 layer_tree_host_->SetAnimationEvents(std::move(events));
[email protected]a8a049c2013-03-11 23:27:06391}
392
sunnypsad3235e2016-08-09 04:57:52393bool SingleThreadProxy::IsInsideDraw() {
394 return inside_draw_;
395}
[email protected]a8a049c2013-03-11 23:27:06396
enne98f3a6c2014-10-09 20:09:44397void SingleThreadProxy::DidActivateSyncTree() {
danakj68803fc2015-06-19 20:55:53398 // Synchronously call to CommitComplete. Resetting
399 // |commit_blocking_task_runner| would make sure all tasks posted during
400 // commit/activation before CommitComplete.
401 CommitComplete();
enne98f3a6c2014-10-09 20:09:44402}
403
brianderson68749812015-07-07 22:39:39404void SingleThreadProxy::WillPrepareTiles() {
khushalsagarb7db1fe2015-11-12 00:51:27405 DCHECK(task_runner_provider_->IsImplThread());
brianderson68749812015-07-07 22:39:39406 if (scheduler_on_impl_thread_)
407 scheduler_on_impl_thread_->WillPrepareTiles();
408}
409
vmiura59ea9b4042014-12-09 20:50:39410void SingleThreadProxy::DidPrepareTiles() {
khushalsagarb7db1fe2015-11-12 00:51:27411 DCHECK(task_runner_provider_->IsImplThread());
enne98f3a6c2014-10-09 20:09:44412 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39413 scheduler_on_impl_thread_->DidPrepareTiles();
enne98f3a6c2014-10-09 20:09:44414}
415
rouslanf7ebd8832015-01-22 01:54:14416void SingleThreadProxy::DidCompletePageScaleAnimationOnImplThread() {
417 layer_tree_host_->DidCompletePageScaleAnimation();
418}
419
[email protected]c1bb5af2013-03-13 19:06:27420void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
[email protected]ccc08dc2014-01-30 07:33:20421 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22422 {
khushalsagarb7db1fe2015-11-12 00:51:27423 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22424 // This must happen before we notify the scheduler as it may try to recreate
425 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE.
426 layer_tree_host_->DidLoseOutputSurface();
427 }
[email protected]4d7e46a2013-11-08 05:33:40428 client_->DidAbortSwapBuffers();
[email protected]aeeedad2014-08-22 18:16:22429 if (scheduler_on_impl_thread_)
430 scheduler_on_impl_thread_->DidLoseOutputSurface();
danakjbe9c59ee2016-08-26 18:24:56431 output_surface_lost_ = true;
[email protected]4d7e46a2013-11-08 05:33:40432}
433
enne19c108582016-04-14 03:35:32434void SingleThreadProxy::SetBeginFrameSource(BeginFrameSource* source) {
khushalsagarcebe4942016-09-07 23:27:01435 DCHECK(layer_tree_host_->GetSettings().single_thread_proxy_scheduler);
enne19c108582016-04-14 03:35:32436 // TODO(enne): this overrides any preexisting begin frame source. Those
437 // other sources will eventually be removed and this will be the only path.
khushalsagarcebe4942016-09-07 23:27:01438 if (!layer_tree_host_->GetSettings().use_output_surface_begin_frame_source)
enne19c108582016-04-14 03:35:32439 return;
440 if (scheduler_on_impl_thread_)
441 scheduler_on_impl_thread_->SetBeginFrameSource(source);
442}
443
jbauman93a5a902015-03-13 22:16:55444void SingleThreadProxy::SetEstimatedParentDrawTime(base::TimeDelta draw_time) {
445 if (scheduler_on_impl_thread_)
446 scheduler_on_impl_thread_->SetEstimatedParentDrawTime(draw_time);
447}
448
[email protected]c14902662014-04-18 05:06:11449void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() {
miletusfed8c43b2015-01-26 20:04:52450 TRACE_EVENT0("cc,benchmark",
451 "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22452 if (scheduler_on_impl_thread_)
453 scheduler_on_impl_thread_->DidSwapBuffersComplete();
454 layer_tree_host_->DidCompleteSwapBuffers();
[email protected]493067512012-09-19 23:34:10455}
456
boliu7097ee5b2015-12-17 03:16:09457void SingleThreadProxy::OnDrawForOutputSurface(
458 bool resourceless_software_draw) {
sunnypseab5ac92015-04-02 20:26:13459 NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor.";
460}
461
[email protected]f0c2a242013-03-15 19:34:52462void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
miletusfed8c43b2015-01-26 20:04:52463 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately");
khushalsagarb7db1fe2015-11-12 00:51:27464 DCHECK(task_runner_provider_->IsMainThread());
mithro51693e382015-05-07 23:52:41465#if DCHECK_IS_ON()
mithroc76d70312015-05-04 23:51:13466 DCHECK(!inside_impl_frame_);
mithro51693e382015-05-07 23:52:41467#endif
jbauman399aec1a2014-10-25 02:33:32468 base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true);
469
danakjbe9c59ee2016-08-26 18:24:56470 if (output_surface_lost_) {
jbauman399aec1a2014-10-25 02:33:32471 RequestNewOutputSurface();
472 // RequestNewOutputSurface could have synchronously created an output
473 // surface, so check again before returning.
danakjbe9c59ee2016-08-26 18:24:56474 if (output_surface_lost_)
jbauman399aec1a2014-10-25 02:33:32475 return;
476 }
[email protected]51f81da2014-05-16 21:29:26477
mithroc76d70312015-05-04 23:51:13478 BeginFrameArgs begin_frame_args(BeginFrameArgs::Create(
479 BEGINFRAME_FROM_HERE, frame_begin_time, base::TimeTicks(),
480 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL));
481
482 // Start the impl frame.
enne98f3a6c2014-10-09 20:09:44483 {
khushalsagarb7db1fe2015-11-12 00:51:27484 DebugScopedSetImplThread impl(task_runner_provider_);
mithroc76d70312015-05-04 23:51:13485 WillBeginImplFrame(begin_frame_args);
486 }
487
488 // Run the "main thread" and get it to commit.
489 {
mithro51693e382015-05-07 23:52:41490#if DCHECK_IS_ON()
mithroc76d70312015-05-04 23:51:13491 DCHECK(inside_impl_frame_);
mithro51693e382015-05-07 23:52:41492#endif
enne98f3a6c2014-10-09 20:09:44493 DoBeginMainFrame(begin_frame_args);
494 DoCommit();
[email protected]e0341352013-04-06 05:01:20495
enne98f3a6c2014-10-09 20:09:44496 DCHECK_EQ(0u, layer_tree_host_->num_queued_swap_promises())
497 << "Commit should always succeed and transfer promises.";
498 }
499
mithroc76d70312015-05-04 23:51:13500 // Finish the impl frame.
enne98f3a6c2014-10-09 20:09:44501 {
khushalsagarb7db1fe2015-11-12 00:51:27502 DebugScopedSetImplThread impl(task_runner_provider_);
danakj68803fc2015-06-19 20:55:53503 layer_tree_host_impl_->ActivateSyncTree();
504 DCHECK(
505 !layer_tree_host_impl_->active_tree()->needs_update_draw_properties());
506 layer_tree_host_impl_->PrepareTiles();
507 layer_tree_host_impl_->SynchronouslyInitializeAllTiles();
enne69277cb2014-10-29 23:03:40508
danakj12e2f6e2015-08-19 22:25:44509 // TODO(danakj): Don't do this last... we prepared the wrong things. D:
510 layer_tree_host_impl_->Animate();
mithro719bf6792014-11-10 15:36:47511
enne98f3a6c2014-10-09 20:09:44512 LayerTreeHostImpl::FrameData frame;
mithro248d1722015-05-05 05:23:45513 DoComposite(&frame);
enne98f3a6c2014-10-09 20:09:44514
515 // DoComposite could abort, but because this is a synchronous composite
516 // another draw will never be scheduled, so break remaining promises.
517 layer_tree_host_impl_->active_tree()->BreakSwapPromises(
518 SwapPromise::SWAP_FAILS);
mithroc76d70312015-05-04 23:51:13519
mithro51693e382015-05-07 23:52:41520 DidFinishImplFrame();
enne98f3a6c2014-10-09 20:09:44521 }
[email protected]74d9063c2013-01-18 03:14:47522}
523
[email protected]5d8bec72014-07-03 03:03:11524bool SingleThreadProxy::SupportsImplScrolling() const {
525 return false;
526}
527
[email protected]3d9f7432013-04-06 00:35:18528bool SingleThreadProxy::ShouldComposite() const {
khushalsagarb7db1fe2015-11-12 00:51:27529 DCHECK(task_runner_provider_->IsImplThread());
sunnypsad3235e2016-08-09 04:57:52530 return layer_tree_host_impl_->visible() && layer_tree_host_impl_->CanDraw();
[email protected]3d9f7432013-04-06 00:35:18531}
532
jbauman8ab0f9e2014-10-15 02:30:34533void SingleThreadProxy::ScheduleRequestNewOutputSurface() {
534 if (output_surface_creation_callback_.IsCancelled() &&
535 !output_surface_creation_requested_) {
536 output_surface_creation_callback_.Reset(
537 base::Bind(&SingleThreadProxy::RequestNewOutputSurface,
538 weak_factory_.GetWeakPtr()));
khushalsagarb7db1fe2015-11-12 00:51:27539 task_runner_provider_->MainThreadTaskRunner()->PostTask(
jbauman8ab0f9e2014-10-15 02:30:34540 FROM_HERE, output_surface_creation_callback_.callback());
541 }
542}
543
mithro248d1722015-05-05 05:23:45544DrawResult SingleThreadProxy::DoComposite(LayerTreeHostImpl::FrameData* frame) {
[email protected]ccc08dc2014-01-30 07:33:20545 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite");
[email protected]04049fc2013-05-01 03:13:20546
enne98f3a6c2014-10-09 20:09:44547 DrawResult draw_result;
548 bool draw_frame;
[email protected]a8a049c2013-03-11 23:27:06549 {
khushalsagarb7db1fe2015-11-12 00:51:27550 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06551 base::AutoReset<bool> mark_inside(&inside_draw_, true);
552
[email protected]3d9f7432013-04-06 00:35:18553 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
554 // frame, so can only be used when such a frame is possible. Since
555 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
556 // CanDraw() as well.
[email protected]2aae96792014-05-15 23:10:50557 if (!ShouldComposite()) {
[email protected]aeeedad2014-08-22 18:16:22558 return DRAW_ABORTED_CANT_DRAW;
[email protected]3d9f7432013-04-06 00:35:18559 }
[email protected]a8a049c2013-03-11 23:27:06560
danakj097919e72016-09-07 19:50:55561 // This CapturePostTasks should be destroyed before
562 // DidCommitAndDrawFrame() is called since that goes out to the
563 // embedder, and we want the embedder to receive its callbacks before that.
564 // NOTE: This maintains consistent ordering with the ThreadProxy since
565 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
566 // there as the main thread is not blocked, so any posted tasks inside
567 // the swap buffers will execute first.
568 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
569 BlockingTaskRunner::CapturePostTasks blocked(
570 task_runner_provider_->blocking_main_thread_task_runner());
571
enne98f3a6c2014-10-09 20:09:44572 draw_result = layer_tree_host_impl_->PrepareToDraw(frame);
573 draw_frame = draw_result == DRAW_SUCCESS;
robliao27728e62015-03-21 07:39:34574 if (draw_frame) {
danakjaecfcfba2016-09-07 22:33:18575 if (layer_tree_host_impl_->DrawLayers(frame)) {
danakj097919e72016-09-07 19:50:55576 if (scheduler_on_impl_thread_)
577 scheduler_on_impl_thread_->DidSwapBuffers();
578 client_->DidPostSwapBuffers();
579 }
robliao27728e62015-03-21 07:39:34580 }
dnetob71e30c2014-08-25 23:27:20581 layer_tree_host_impl_->DidDrawAllLayers(*frame);
[email protected]a8a049c2013-03-11 23:27:06582
danakj097919e72016-09-07 19:50:55583 bool start_ready_animations = draw_frame;
[email protected]3d9f7432013-04-06 00:35:18584 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
[email protected]aeeedad2014-08-22 18:16:22585 }
[email protected]aeeedad2014-08-22 18:16:22586 DidCommitAndDrawFrame();
587
enne98f3a6c2014-10-09 20:09:44588 return draw_result;
[email protected]a8a049c2013-03-11 23:27:06589}
590
[email protected]aeeedad2014-08-22 18:16:22591void SingleThreadProxy::DidCommitAndDrawFrame() {
[email protected]a8a049c2013-03-11 23:27:06592 if (next_frame_is_newly_committed_frame_) {
khushalsagarb7db1fe2015-11-12 00:51:27593 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06594 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21595 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06596 }
597}
598
[email protected]4ea293f72014-08-13 03:03:17599bool SingleThreadProxy::MainFrameWillHappenForTesting() {
danakjfcdaba122015-04-24 21:41:52600 if (!scheduler_on_impl_thread_)
601 return false;
602 return scheduler_on_impl_thread_->MainFrameForTestingWillHappen();
[email protected]4ea293f72014-08-13 03:03:17603}
[email protected]a8a049c2013-03-11 23:27:06604
[email protected]aeeedad2014-08-22 18:16:22605void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) {
danakja18e826a2015-12-03 00:27:03606 DebugScopedSetImplThread impl(task_runner_provider_);
mithro51693e382015-05-07 23:52:41607#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02608 DCHECK(!inside_impl_frame_)
609 << "WillBeginImplFrame called while already inside an impl frame!";
610 inside_impl_frame_ = true;
mithro51693e382015-05-07 23:52:41611#endif
[email protected]aeeedad2014-08-22 18:16:22612 layer_tree_host_impl_->WillBeginImplFrame(args);
613}
614
brianderson266dc3a2015-11-12 03:16:40615void SingleThreadProxy::ScheduledActionSendBeginMainFrame(
616 const BeginFrameArgs& begin_frame_args) {
[email protected]aeeedad2014-08-22 18:16:22617 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame");
sunnypsad3235e2016-08-09 04:57:52618#if DCHECK_IS_ON()
[email protected]aeeedad2014-08-22 18:16:22619 // Although this proxy is single-threaded, it's problematic to synchronously
620 // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This
621 // could cause a commit to occur in between a series of SetNeedsCommit calls
622 // (i.e. property modifications) causing some to fall on one frame and some to
623 // fall on the next. Doing it asynchronously instead matches the semantics of
624 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a
625 // synchronous commit.
mithro69fd3bb52015-05-01 03:45:02626 DCHECK(inside_impl_frame_)
627 << "BeginMainFrame should only be sent inside a BeginImplFrame";
mithro51693e382015-05-07 23:52:41628#endif
mithro69fd3bb52015-05-01 03:45:02629
khushalsagarb7db1fe2015-11-12 00:51:27630 task_runner_provider_->MainThreadTaskRunner()->PostTask(
mithro69fd3bb52015-05-01 03:45:02631 FROM_HERE, base::Bind(&SingleThreadProxy::BeginMainFrame,
632 weak_factory_.GetWeakPtr(), begin_frame_args));
[email protected]aeeedad2014-08-22 18:16:22633}
634
rmcilroy0a19362a2015-02-18 12:34:25635void SingleThreadProxy::SendBeginMainFrameNotExpectedSoon() {
636 layer_tree_host_->BeginMainFrameNotExpectedSoon();
637}
638
mithro69fd3bb52015-05-01 03:45:02639void SingleThreadProxy::BeginMainFrame(const BeginFrameArgs& begin_frame_args) {
brianderson21aef162015-11-11 05:12:23640 if (scheduler_on_impl_thread_) {
641 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(
642 base::TimeTicks::Now());
643 }
644
danakjfcdaba122015-04-24 21:41:52645 commit_requested_ = false;
brianderson49e101d22015-04-29 00:05:33646 animate_requested_ = false;
danakjfcdaba122015-04-24 21:41:52647
[email protected]aeeedad2014-08-22 18:16:22648 if (defer_commits_) {
simonhongc6309f792015-01-31 15:47:15649 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit",
650 TRACE_EVENT_SCOPE_THREAD);
651 BeginMainFrameAbortedOnImplThread(
652 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT);
[email protected]aeeedad2014-08-22 18:16:22653 return;
654 }
655
enne98f3a6c2014-10-09 20:09:44656 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous
657 // commit.
[email protected]aeeedad2014-08-22 18:16:22658 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_);
659
khushalsagarcebe4942016-09-07 23:27:01660 if (!layer_tree_host_->IsVisible()) {
[email protected]aeeedad2014-08-22 18:16:22661 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD);
mithrof7a21502014-12-17 03:24:48662 BeginMainFrameAbortedOnImplThread(
663 CommitEarlyOutReason::ABORTED_NOT_VISIBLE);
[email protected]aeeedad2014-08-22 18:16:22664 return;
665 }
666
danakjfcdaba122015-04-24 21:41:52667 // Prevent new commits from being requested inside DoBeginMainFrame.
brianderson49e101d22015-04-29 00:05:33668 // Note: We do not want to prevent SetNeedsAnimate from requesting
669 // a commit here.
danakjfcdaba122015-04-24 21:41:52670 commit_requested_ = true;
671
enne98f3a6c2014-10-09 20:09:44672 DoBeginMainFrame(begin_frame_args);
673}
674
675void SingleThreadProxy::DoBeginMainFrame(
676 const BeginFrameArgs& begin_frame_args) {
tapted4b70c522016-08-13 09:09:32677 // In the single-threaded case, the scale deltas should never be touched on
678 // the impl layer tree. However, impl-side scroll deltas may be manipulated
679 // directly via the InputHandler on the UI thread.
680 std::unique_ptr<ScrollAndScaleSet> scroll_info =
681 layer_tree_host_impl_->ProcessScrollDeltas();
682 DCHECK_EQ(1.f, scroll_info->page_scale_delta);
683 layer_tree_host_->ApplyScrollAndScale(scroll_info.get());
684
enne98f3a6c2014-10-09 20:09:44685 layer_tree_host_->WillBeginMainFrame();
686 layer_tree_host_->BeginMainFrame(begin_frame_args);
687 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time);
wkorman7265db012015-11-03 04:08:25688 layer_tree_host_->RequestMainFrameUpdate();
enne98f3a6c2014-10-09 20:09:44689
danakjfcdaba122015-04-24 21:41:52690 // New commits requested inside UpdateLayers should be respected.
691 commit_requested_ = false;
692
danakj5f46636a2015-06-19 00:01:40693 layer_tree_host_->UpdateLayers();
enne98f3a6c2014-10-09 20:09:44694
mithrof7a21502014-12-17 03:24:48695 // TODO(enne): SingleThreadProxy does not support cancelling commits yet,
696 // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside
697 // thread_proxy.cc
brianderson21aef162015-11-11 05:12:23698 if (scheduler_on_impl_thread_)
enne98f3a6c2014-10-09 20:09:44699 scheduler_on_impl_thread_->NotifyReadyToCommit();
[email protected]aeeedad2014-08-22 18:16:22700}
701
mithrof7a21502014-12-17 03:24:48702void SingleThreadProxy::BeginMainFrameAbortedOnImplThread(
703 CommitEarlyOutReason reason) {
khushalsagarb7db1fe2015-11-12 00:51:27704 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22705 DCHECK(scheduler_on_impl_thread_->CommitPending());
706 DCHECK(!layer_tree_host_impl_->pending_tree());
707
sunnypsad3235e2016-08-09 04:57:52708 std::vector<std::unique_ptr<SwapPromise>> empty_swap_promises;
709 layer_tree_host_impl_->BeginMainFrameAborted(reason,
710 std::move(empty_swap_promises));
mithrof7a21502014-12-17 03:24:48711 scheduler_on_impl_thread_->BeginMainFrameAborted(reason);
[email protected]aeeedad2014-08-22 18:16:22712}
713
714DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
khushalsagarb7db1fe2015-11-12 00:51:27715 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22716 LayerTreeHostImpl::FrameData frame;
mithro248d1722015-05-05 05:23:45717 return DoComposite(&frame);
[email protected]aeeedad2014-08-22 18:16:22718}
719
720DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() {
721 NOTREACHED();
722 return INVALID_RESULT;
723}
724
725void SingleThreadProxy::ScheduledActionCommit() {
khushalsagarb7db1fe2015-11-12 00:51:27726 DebugScopedSetMainThread main(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44727 DoCommit();
[email protected]aeeedad2014-08-22 18:16:22728}
729
[email protected]aeeedad2014-08-22 18:16:22730void SingleThreadProxy::ScheduledActionActivateSyncTree() {
khushalsagarb7db1fe2015-11-12 00:51:27731 DebugScopedSetImplThread impl(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44732 layer_tree_host_impl_->ActivateSyncTree();
[email protected]aeeedad2014-08-22 18:16:22733}
734
735void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
khushalsagarb7db1fe2015-11-12 00:51:27736 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22737 DCHECK(scheduler_on_impl_thread_);
738 // If possible, create the output surface in a post task. Synchronously
739 // creating the output surface makes tests more awkward since this differs
740 // from the ThreadProxy behavior. However, sometimes there is no
741 // task runner.
khushalsagarb7db1fe2015-11-12 00:51:27742 if (task_runner_provider_->MainThreadTaskRunner()) {
jbauman8ab0f9e2014-10-15 02:30:34743 ScheduleRequestNewOutputSurface();
[email protected]aeeedad2014-08-22 18:16:22744 } else {
enne2097cab2014-09-25 20:16:31745 RequestNewOutputSurface();
[email protected]aeeedad2014-08-22 18:16:22746 }
747}
748
vmiura59ea9b4042014-12-09 20:50:39749void SingleThreadProxy::ScheduledActionPrepareTiles() {
750 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionPrepareTiles");
khushalsagarb7db1fe2015-11-12 00:51:27751 DebugScopedSetImplThread impl(task_runner_provider_);
vmiura59ea9b4042014-12-09 20:50:39752 layer_tree_host_impl_->PrepareTiles();
[email protected]aeeedad2014-08-22 18:16:22753}
754
sunnypseab5ac92015-04-02 20:26:13755void SingleThreadProxy::ScheduledActionInvalidateOutputSurface() {
756 NOTREACHED();
757}
758
khushalsagarc646cd62015-10-17 00:05:48759void SingleThreadProxy::UpdateTopControlsState(TopControlsState constraints,
760 TopControlsState current,
761 bool animate) {
762 NOTREACHED() << "Top Controls are used only in threaded mode";
763}
764
mithro51693e382015-05-07 23:52:41765void SingleThreadProxy::DidFinishImplFrame() {
766 layer_tree_host_impl_->DidFinishImplFrame();
767#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02768 DCHECK(inside_impl_frame_)
mithro51693e382015-05-07 23:52:41769 << "DidFinishImplFrame called while not inside an impl frame!";
mithro69fd3bb52015-05-01 03:45:02770 inside_impl_frame_ = false;
mithro51693e382015-05-07 23:52:41771#endif
[email protected]aeeedad2014-08-22 18:16:22772}
773
[email protected]bc5e77c2012-11-05 20:00:49774} // namespace cc