blob: f30413a15aeae9f665325a75e8101f5efcceb1ad [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"
jaydasika13c05062016-04-01 18:12:2721#include "cc/trees/layer_tree_host_common.h"
khushalsagar61567792016-09-17 00:13:5822#include "cc/trees/layer_tree_host_in_process.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(
khushalsagar61567792016-09-17 00:13:5831 LayerTreeHostInProcess* 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
khushalsagar61567792016-09-17 00:13:5838SingleThreadProxy::SingleThreadProxy(LayerTreeHostInProcess* 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]174c6d42014-08-12 01:43:06276bool SingleThreadProxy::BeginMainFrameRequested() const {
khushalsagarb7db1fe2015-11-12 00:51:27277 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22278 // If there is no scheduler, then there can be no pending begin frame,
279 // as all frames are all manually initiated by the embedder of cc.
280 if (!scheduler_on_impl_thread_)
281 return false;
282 return commit_requested_;
[email protected]174c6d42014-08-12 01:43:06283}
[email protected]971728d2013-10-26 10:39:31284
[email protected]a8a049c2013-03-11 23:27:06285void SingleThreadProxy::Stop() {
286 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
khushalsagarb7db1fe2015-11-12 00:51:27287 DCHECK(task_runner_provider_->IsMainThread());
[email protected]a8a049c2013-03-11 23:27:06288 {
khushalsagarb7db1fe2015-11-12 00:51:27289 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
290 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06291
sunnypsda928f0a2016-10-08 00:32:53292 // Prevent the scheduler from performing actions while we're in an
293 // inconsistent state.
294 if (scheduler_on_impl_thread_)
295 scheduler_on_impl_thread_->Stop();
danakj1120f4c2016-09-15 02:05:32296 // Take away the CompositorFrameSink before destroying things so it doesn't
297 // try to call into its client mid-shutdown.
298 layer_tree_host_impl_->ReleaseCompositorFrameSink();
danakjf446a072014-09-27 21:55:48299 scheduler_on_impl_thread_ = nullptr;
300 layer_tree_host_impl_ = nullptr;
[email protected]a8a049c2013-03-11 23:27:06301 }
sunnypsda928f0a2016-10-08 00:32:53302 layer_tree_host_ = nullptr;
[email protected]a8a049c2013-03-11 23:27:06303}
304
flackrf54e9b42016-05-31 15:20:10305void SingleThreadProxy::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) {
306 DCHECK(task_runner_provider_->IsMainThread());
307 DebugScopedSetImplThread impl(task_runner_provider_);
308 layer_tree_host_impl_->SetLayerTreeMutator(std::move(mutator));
309}
310
[email protected]3d9f7432013-04-06 00:35:18311void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
sunnypsad3235e2016-08-09 04:57:52312 TRACE_EVENT1("cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw",
313 can_draw);
khushalsagarb7db1fe2015-11-12 00:51:27314 DCHECK(task_runner_provider_->IsImplThread());
[email protected]aeeedad2014-08-22 18:16:22315 if (scheduler_on_impl_thread_)
316 scheduler_on_impl_thread_->SetCanDraw(can_draw);
[email protected]3d9f7432013-04-06 00:35:18317}
318
[email protected]4f48f6e2013-08-27 06:33:38319void SingleThreadProxy::NotifyReadyToActivate() {
enne98f3a6c2014-10-09 20:09:44320 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate");
khushalsagarb7db1fe2015-11-12 00:51:27321 DebugScopedSetImplThread impl(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44322 if (scheduler_on_impl_thread_)
323 scheduler_on_impl_thread_->NotifyReadyToActivate();
[email protected]4f48f6e2013-08-27 06:33:38324}
325
ernstmdfac03e2014-11-11 20:18:05326void SingleThreadProxy::NotifyReadyToDraw() {
weiliangc8dac5a62015-04-02 06:12:35327 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToDraw");
khushalsagarb7db1fe2015-11-12 00:51:27328 DebugScopedSetImplThread impl(task_runner_provider_);
weiliangc8dac5a62015-04-02 06:12:35329 if (scheduler_on_impl_thread_)
330 scheduler_on_impl_thread_->NotifyReadyToDraw();
ernstmdfac03e2014-11-11 20:18:05331}
332
[email protected]c1bb5af2013-03-13 19:06:27333void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
danakj6c872fc02016-10-22 04:29:49334 single_thread_client_->RequestScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22335 if (scheduler_on_impl_thread_)
336 scheduler_on_impl_thread_->SetNeedsRedraw();
[email protected]a8a049c2013-03-11 23:27:06337}
338
danakja18e826a2015-12-03 00:27:03339void SingleThreadProxy::SetNeedsOneBeginImplFrameOnImplThread() {
340 TRACE_EVENT0("cc",
341 "SingleThreadProxy::SetNeedsOneBeginImplFrameOnImplThread");
danakj6c872fc02016-10-22 04:29:49342 single_thread_client_->RequestScheduleComposite();
mithro719bf6792014-11-10 15:36:47343 if (scheduler_on_impl_thread_)
danakja18e826a2015-12-03 00:27:03344 scheduler_on_impl_thread_->SetNeedsOneBeginImplFrame();
[email protected]43b8f982014-04-30 21:24:33345}
346
vmiura59ea9b4042014-12-09 20:50:39347void SingleThreadProxy::SetNeedsPrepareTilesOnImplThread() {
348 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsPrepareTilesOnImplThread");
enne98f3a6c2014-10-09 20:09:44349 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39350 scheduler_on_impl_thread_->SetNeedsPrepareTiles();
[email protected]c48536a52013-09-14 00:02:08351}
352
[email protected]c1bb5af2013-03-13 19:06:27353void SingleThreadProxy::SetNeedsCommitOnImplThread() {
danakj6c872fc02016-10-22 04:29:49354 single_thread_client_->RequestScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22355 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01356 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
[email protected]a8a049c2013-03-11 23:27:06357}
358
sunnyps7d073dc2015-04-16 23:29:12359void SingleThreadProxy::SetVideoNeedsBeginFrames(bool needs_begin_frames) {
360 TRACE_EVENT1("cc", "SingleThreadProxy::SetVideoNeedsBeginFrames",
361 "needs_begin_frames", needs_begin_frames);
362 // In tests the layer tree is destroyed after the scheduler is.
363 if (scheduler_on_impl_thread_)
364 scheduler_on_impl_thread_->SetVideoNeedsBeginFrames(needs_begin_frames);
365}
366
[email protected]c1bb5af2013-03-13 19:06:27367void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
loysoc601b7b82016-11-10 02:56:44368 std::unique_ptr<MutatorEvents> events) {
[email protected]ccc08dc2014-01-30 07:33:20369 TRACE_EVENT0(
370 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
khushalsagarb7db1fe2015-11-12 00:51:27371 DCHECK(task_runner_provider_->IsImplThread());
372 DebugScopedSetMainThread main(task_runner_provider_);
danakja04855a2015-11-18 20:39:10373 layer_tree_host_->SetAnimationEvents(std::move(events));
[email protected]a8a049c2013-03-11 23:27:06374}
375
sunnypsad3235e2016-08-09 04:57:52376bool SingleThreadProxy::IsInsideDraw() {
377 return inside_draw_;
378}
[email protected]a8a049c2013-03-11 23:27:06379
enne98f3a6c2014-10-09 20:09:44380void SingleThreadProxy::DidActivateSyncTree() {
danakj68803fc2015-06-19 20:55:53381 // Synchronously call to CommitComplete. Resetting
382 // |commit_blocking_task_runner| would make sure all tasks posted during
383 // commit/activation before CommitComplete.
384 CommitComplete();
enne98f3a6c2014-10-09 20:09:44385}
386
brianderson68749812015-07-07 22:39:39387void SingleThreadProxy::WillPrepareTiles() {
khushalsagarb7db1fe2015-11-12 00:51:27388 DCHECK(task_runner_provider_->IsImplThread());
brianderson68749812015-07-07 22:39:39389 if (scheduler_on_impl_thread_)
390 scheduler_on_impl_thread_->WillPrepareTiles();
391}
392
vmiura59ea9b4042014-12-09 20:50:39393void SingleThreadProxy::DidPrepareTiles() {
khushalsagarb7db1fe2015-11-12 00:51:27394 DCHECK(task_runner_provider_->IsImplThread());
enne98f3a6c2014-10-09 20:09:44395 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39396 scheduler_on_impl_thread_->DidPrepareTiles();
enne98f3a6c2014-10-09 20:09:44397}
398
rouslanf7ebd8832015-01-22 01:54:14399void SingleThreadProxy::DidCompletePageScaleAnimationOnImplThread() {
400 layer_tree_host_->DidCompletePageScaleAnimation();
401}
402
danakj1120f4c2016-09-15 02:05:32403void SingleThreadProxy::DidLoseCompositorFrameSinkOnImplThread() {
404 TRACE_EVENT0("cc",
405 "SingleThreadProxy::DidLoseCompositorFrameSinkOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22406 {
khushalsagarb7db1fe2015-11-12 00:51:27407 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22408 // This must happen before we notify the scheduler as it may try to recreate
409 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE.
danakj1120f4c2016-09-15 02:05:32410 layer_tree_host_->DidLoseCompositorFrameSink();
[email protected]aeeedad2014-08-22 18:16:22411 }
danakj6c872fc02016-10-22 04:29:49412 single_thread_client_->DidLoseCompositorFrameSink();
[email protected]aeeedad2014-08-22 18:16:22413 if (scheduler_on_impl_thread_)
danakj1120f4c2016-09-15 02:05:32414 scheduler_on_impl_thread_->DidLoseCompositorFrameSink();
415 compositor_frame_sink_lost_ = true;
[email protected]4d7e46a2013-11-08 05:33:40416}
417
enne19c108582016-04-14 03:35:32418void SingleThreadProxy::SetBeginFrameSource(BeginFrameSource* source) {
enne19c108582016-04-14 03:35:32419 if (scheduler_on_impl_thread_)
420 scheduler_on_impl_thread_->SetBeginFrameSource(source);
421}
422
danakj9d124422016-10-14 03:15:08423void SingleThreadProxy::DidReceiveCompositorFrameAckOnImplThread() {
miletusfed8c43b2015-01-26 20:04:52424 TRACE_EVENT0("cc,benchmark",
danakj9d124422016-10-14 03:15:08425 "SingleThreadProxy::DidReceiveCompositorFrameAckOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22426 if (scheduler_on_impl_thread_)
danakj9d124422016-10-14 03:15:08427 scheduler_on_impl_thread_->DidReceiveCompositorFrameAck();
428 layer_tree_host_->DidReceiveCompositorFrameAck();
[email protected]493067512012-09-19 23:34:10429}
430
danakj1120f4c2016-09-15 02:05:32431void SingleThreadProxy::OnDrawForCompositorFrameSink(
boliu7097ee5b2015-12-17 03:16:09432 bool resourceless_software_draw) {
sunnypseab5ac92015-04-02 20:26:13433 NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor.";
434}
435
[email protected]f0c2a242013-03-15 19:34:52436void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
miletusfed8c43b2015-01-26 20:04:52437 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately");
khushalsagarb7db1fe2015-11-12 00:51:27438 DCHECK(task_runner_provider_->IsMainThread());
mithro51693e382015-05-07 23:52:41439#if DCHECK_IS_ON()
mithroc76d70312015-05-04 23:51:13440 DCHECK(!inside_impl_frame_);
mithro51693e382015-05-07 23:52:41441#endif
jbauman399aec1a2014-10-25 02:33:32442 base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true);
443
danakj1120f4c2016-09-15 02:05:32444 if (compositor_frame_sink_lost_) {
445 RequestNewCompositorFrameSink();
446 // RequestNewCompositorFrameSink could have synchronously created an output
jbauman399aec1a2014-10-25 02:33:32447 // surface, so check again before returning.
danakj1120f4c2016-09-15 02:05:32448 if (compositor_frame_sink_lost_)
jbauman399aec1a2014-10-25 02:33:32449 return;
450 }
[email protected]51f81da2014-05-16 21:29:26451
mithroc76d70312015-05-04 23:51:13452 BeginFrameArgs begin_frame_args(BeginFrameArgs::Create(
eseckler1ce4fd52016-12-22 11:23:40453 BEGINFRAME_FROM_HERE, 0, 1, frame_begin_time, base::TimeTicks(),
mithroc76d70312015-05-04 23:51:13454 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL));
455
456 // Start the impl frame.
enne98f3a6c2014-10-09 20:09:44457 {
khushalsagarb7db1fe2015-11-12 00:51:27458 DebugScopedSetImplThread impl(task_runner_provider_);
mithroc76d70312015-05-04 23:51:13459 WillBeginImplFrame(begin_frame_args);
460 }
461
462 // Run the "main thread" and get it to commit.
463 {
mithro51693e382015-05-07 23:52:41464#if DCHECK_IS_ON()
mithroc76d70312015-05-04 23:51:13465 DCHECK(inside_impl_frame_);
mithro51693e382015-05-07 23:52:41466#endif
enne98f3a6c2014-10-09 20:09:44467 DoBeginMainFrame(begin_frame_args);
468 DoCommit();
[email protected]e0341352013-04-06 05:01:20469
khushalsagar8297ae992016-09-14 20:51:23470 DCHECK_EQ(
471 0u,
472 layer_tree_host_->GetSwapPromiseManager()->num_queued_swap_promises())
enne98f3a6c2014-10-09 20:09:44473 << "Commit should always succeed and transfer promises.";
474 }
475
mithroc76d70312015-05-04 23:51:13476 // Finish the impl frame.
enne98f3a6c2014-10-09 20:09:44477 {
khushalsagarb7db1fe2015-11-12 00:51:27478 DebugScopedSetImplThread impl(task_runner_provider_);
danakj68803fc2015-06-19 20:55:53479 layer_tree_host_impl_->ActivateSyncTree();
480 DCHECK(
481 !layer_tree_host_impl_->active_tree()->needs_update_draw_properties());
482 layer_tree_host_impl_->PrepareTiles();
483 layer_tree_host_impl_->SynchronouslyInitializeAllTiles();
enne69277cb2014-10-29 23:03:40484
danakj12e2f6e2015-08-19 22:25:44485 // TODO(danakj): Don't do this last... we prepared the wrong things. D:
486 layer_tree_host_impl_->Animate();
mithro719bf6792014-11-10 15:36:47487
enne98f3a6c2014-10-09 20:09:44488 LayerTreeHostImpl::FrameData frame;
mithro248d1722015-05-05 05:23:45489 DoComposite(&frame);
enne98f3a6c2014-10-09 20:09:44490
491 // DoComposite could abort, but because this is a synchronous composite
492 // another draw will never be scheduled, so break remaining promises.
493 layer_tree_host_impl_->active_tree()->BreakSwapPromises(
494 SwapPromise::SWAP_FAILS);
mithroc76d70312015-05-04 23:51:13495
mithro51693e382015-05-07 23:52:41496 DidFinishImplFrame();
enne98f3a6c2014-10-09 20:09:44497 }
[email protected]74d9063c2013-01-18 03:14:47498}
499
[email protected]5d8bec72014-07-03 03:03:11500bool SingleThreadProxy::SupportsImplScrolling() const {
501 return false;
502}
503
[email protected]3d9f7432013-04-06 00:35:18504bool SingleThreadProxy::ShouldComposite() const {
khushalsagarb7db1fe2015-11-12 00:51:27505 DCHECK(task_runner_provider_->IsImplThread());
sunnypsad3235e2016-08-09 04:57:52506 return layer_tree_host_impl_->visible() && layer_tree_host_impl_->CanDraw();
[email protected]3d9f7432013-04-06 00:35:18507}
508
danakj1120f4c2016-09-15 02:05:32509void SingleThreadProxy::ScheduleRequestNewCompositorFrameSink() {
510 if (compositor_frame_sink_creation_callback_.IsCancelled() &&
511 !compositor_frame_sink_creation_requested_) {
512 compositor_frame_sink_creation_callback_.Reset(
513 base::Bind(&SingleThreadProxy::RequestNewCompositorFrameSink,
jbauman8ab0f9e2014-10-15 02:30:34514 weak_factory_.GetWeakPtr()));
khushalsagarb7db1fe2015-11-12 00:51:27515 task_runner_provider_->MainThreadTaskRunner()->PostTask(
danakj1120f4c2016-09-15 02:05:32516 FROM_HERE, compositor_frame_sink_creation_callback_.callback());
jbauman8ab0f9e2014-10-15 02:30:34517 }
518}
519
mithro248d1722015-05-05 05:23:45520DrawResult SingleThreadProxy::DoComposite(LayerTreeHostImpl::FrameData* frame) {
[email protected]ccc08dc2014-01-30 07:33:20521 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite");
[email protected]04049fc2013-05-01 03:13:20522
enne98f3a6c2014-10-09 20:09:44523 DrawResult draw_result;
524 bool draw_frame;
[email protected]a8a049c2013-03-11 23:27:06525 {
khushalsagarb7db1fe2015-11-12 00:51:27526 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06527 base::AutoReset<bool> mark_inside(&inside_draw_, true);
528
[email protected]3d9f7432013-04-06 00:35:18529 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
530 // frame, so can only be used when such a frame is possible. Since
531 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
532 // CanDraw() as well.
[email protected]2aae96792014-05-15 23:10:50533 if (!ShouldComposite()) {
[email protected]aeeedad2014-08-22 18:16:22534 return DRAW_ABORTED_CANT_DRAW;
[email protected]3d9f7432013-04-06 00:35:18535 }
[email protected]a8a049c2013-03-11 23:27:06536
danakj097919e72016-09-07 19:50:55537 // This CapturePostTasks should be destroyed before
538 // DidCommitAndDrawFrame() is called since that goes out to the
539 // embedder, and we want the embedder to receive its callbacks before that.
540 // NOTE: This maintains consistent ordering with the ThreadProxy since
541 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
542 // there as the main thread is not blocked, so any posted tasks inside
543 // the swap buffers will execute first.
544 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
545 BlockingTaskRunner::CapturePostTasks blocked(
546 task_runner_provider_->blocking_main_thread_task_runner());
547
enne98f3a6c2014-10-09 20:09:44548 draw_result = layer_tree_host_impl_->PrepareToDraw(frame);
549 draw_frame = draw_result == DRAW_SUCCESS;
robliao27728e62015-03-21 07:39:34550 if (draw_frame) {
danakjaecfcfba2016-09-07 22:33:18551 if (layer_tree_host_impl_->DrawLayers(frame)) {
danakj097919e72016-09-07 19:50:55552 if (scheduler_on_impl_thread_)
danakj9d124422016-10-14 03:15:08553 // Drawing implies we submitted a frame to the CompositorFrameSink.
554 scheduler_on_impl_thread_->DidSubmitCompositorFrame();
danakj6c872fc02016-10-22 04:29:49555 single_thread_client_->DidSubmitCompositorFrame();
danakj097919e72016-09-07 19:50:55556 }
robliao27728e62015-03-21 07:39:34557 }
dnetob71e30c2014-08-25 23:27:20558 layer_tree_host_impl_->DidDrawAllLayers(*frame);
[email protected]a8a049c2013-03-11 23:27:06559
danakj097919e72016-09-07 19:50:55560 bool start_ready_animations = draw_frame;
[email protected]3d9f7432013-04-06 00:35:18561 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
[email protected]aeeedad2014-08-22 18:16:22562 }
563 DidCommitAndDrawFrame();
564
enne98f3a6c2014-10-09 20:09:44565 return draw_result;
[email protected]a8a049c2013-03-11 23:27:06566}
567
[email protected]aeeedad2014-08-22 18:16:22568void SingleThreadProxy::DidCommitAndDrawFrame() {
[email protected]a8a049c2013-03-11 23:27:06569 if (next_frame_is_newly_committed_frame_) {
khushalsagarb7db1fe2015-11-12 00:51:27570 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06571 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21572 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06573 }
574}
575
[email protected]4ea293f72014-08-13 03:03:17576bool SingleThreadProxy::MainFrameWillHappenForTesting() {
danakjfcdaba122015-04-24 21:41:52577 if (!scheduler_on_impl_thread_)
578 return false;
579 return scheduler_on_impl_thread_->MainFrameForTestingWillHappen();
[email protected]4ea293f72014-08-13 03:03:17580}
[email protected]a8a049c2013-03-11 23:27:06581
[email protected]aeeedad2014-08-22 18:16:22582void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) {
danakja18e826a2015-12-03 00:27:03583 DebugScopedSetImplThread impl(task_runner_provider_);
mithro51693e382015-05-07 23:52:41584#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02585 DCHECK(!inside_impl_frame_)
586 << "WillBeginImplFrame called while already inside an impl frame!";
587 inside_impl_frame_ = true;
mithro51693e382015-05-07 23:52:41588#endif
[email protected]aeeedad2014-08-22 18:16:22589 layer_tree_host_impl_->WillBeginImplFrame(args);
590}
591
brianderson266dc3a2015-11-12 03:16:40592void SingleThreadProxy::ScheduledActionSendBeginMainFrame(
593 const BeginFrameArgs& begin_frame_args) {
[email protected]aeeedad2014-08-22 18:16:22594 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame");
sunnypsad3235e2016-08-09 04:57:52595#if DCHECK_IS_ON()
[email protected]aeeedad2014-08-22 18:16:22596 // Although this proxy is single-threaded, it's problematic to synchronously
597 // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This
598 // could cause a commit to occur in between a series of SetNeedsCommit calls
599 // (i.e. property modifications) causing some to fall on one frame and some to
600 // fall on the next. Doing it asynchronously instead matches the semantics of
601 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a
602 // synchronous commit.
mithro69fd3bb52015-05-01 03:45:02603 DCHECK(inside_impl_frame_)
604 << "BeginMainFrame should only be sent inside a BeginImplFrame";
mithro51693e382015-05-07 23:52:41605#endif
mithro69fd3bb52015-05-01 03:45:02606
khushalsagarb7db1fe2015-11-12 00:51:27607 task_runner_provider_->MainThreadTaskRunner()->PostTask(
mithro69fd3bb52015-05-01 03:45:02608 FROM_HERE, base::Bind(&SingleThreadProxy::BeginMainFrame,
609 weak_factory_.GetWeakPtr(), begin_frame_args));
[email protected]aeeedad2014-08-22 18:16:22610}
611
rmcilroy0a19362a2015-02-18 12:34:25612void SingleThreadProxy::SendBeginMainFrameNotExpectedSoon() {
613 layer_tree_host_->BeginMainFrameNotExpectedSoon();
614}
615
mithro69fd3bb52015-05-01 03:45:02616void SingleThreadProxy::BeginMainFrame(const BeginFrameArgs& begin_frame_args) {
brianderson21aef162015-11-11 05:12:23617 if (scheduler_on_impl_thread_) {
618 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(
619 base::TimeTicks::Now());
620 }
621
danakjfcdaba122015-04-24 21:41:52622 commit_requested_ = false;
brianderson49e101d22015-04-29 00:05:33623 animate_requested_ = false;
danakjfcdaba122015-04-24 21:41:52624
[email protected]aeeedad2014-08-22 18:16:22625 if (defer_commits_) {
simonhongc6309f792015-01-31 15:47:15626 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit",
627 TRACE_EVENT_SCOPE_THREAD);
628 BeginMainFrameAbortedOnImplThread(
629 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT);
[email protected]aeeedad2014-08-22 18:16:22630 return;
631 }
632
enne98f3a6c2014-10-09 20:09:44633 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous
634 // commit.
khushalsagar8297ae992016-09-14 20:51:23635 ScopedAbortRemainingSwapPromises swap_promise_checker(
636 layer_tree_host_->GetSwapPromiseManager());
[email protected]aeeedad2014-08-22 18:16:22637
khushalsagarcebe4942016-09-07 23:27:01638 if (!layer_tree_host_->IsVisible()) {
[email protected]aeeedad2014-08-22 18:16:22639 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD);
mithrof7a21502014-12-17 03:24:48640 BeginMainFrameAbortedOnImplThread(
641 CommitEarlyOutReason::ABORTED_NOT_VISIBLE);
[email protected]aeeedad2014-08-22 18:16:22642 return;
643 }
644
danakjfcdaba122015-04-24 21:41:52645 // Prevent new commits from being requested inside DoBeginMainFrame.
brianderson49e101d22015-04-29 00:05:33646 // Note: We do not want to prevent SetNeedsAnimate from requesting
647 // a commit here.
danakjfcdaba122015-04-24 21:41:52648 commit_requested_ = true;
649
enne98f3a6c2014-10-09 20:09:44650 DoBeginMainFrame(begin_frame_args);
651}
652
653void SingleThreadProxy::DoBeginMainFrame(
654 const BeginFrameArgs& begin_frame_args) {
tapted4b70c522016-08-13 09:09:32655 // In the single-threaded case, the scale deltas should never be touched on
656 // the impl layer tree. However, impl-side scroll deltas may be manipulated
657 // directly via the InputHandler on the UI thread.
658 std::unique_ptr<ScrollAndScaleSet> scroll_info =
659 layer_tree_host_impl_->ProcessScrollDeltas();
660 DCHECK_EQ(1.f, scroll_info->page_scale_delta);
661 layer_tree_host_->ApplyScrollAndScale(scroll_info.get());
662
enne98f3a6c2014-10-09 20:09:44663 layer_tree_host_->WillBeginMainFrame();
664 layer_tree_host_->BeginMainFrame(begin_frame_args);
665 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time);
wkorman7265db012015-11-03 04:08:25666 layer_tree_host_->RequestMainFrameUpdate();
enne98f3a6c2014-10-09 20:09:44667
danakjfcdaba122015-04-24 21:41:52668 // New commits requested inside UpdateLayers should be respected.
669 commit_requested_ = false;
670
danakj5f46636a2015-06-19 00:01:40671 layer_tree_host_->UpdateLayers();
enne98f3a6c2014-10-09 20:09:44672
mithrof7a21502014-12-17 03:24:48673 // TODO(enne): SingleThreadProxy does not support cancelling commits yet,
674 // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside
675 // thread_proxy.cc
brianderson21aef162015-11-11 05:12:23676 if (scheduler_on_impl_thread_)
enne98f3a6c2014-10-09 20:09:44677 scheduler_on_impl_thread_->NotifyReadyToCommit();
[email protected]aeeedad2014-08-22 18:16:22678}
679
mithrof7a21502014-12-17 03:24:48680void SingleThreadProxy::BeginMainFrameAbortedOnImplThread(
681 CommitEarlyOutReason reason) {
khushalsagarb7db1fe2015-11-12 00:51:27682 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22683 DCHECK(scheduler_on_impl_thread_->CommitPending());
684 DCHECK(!layer_tree_host_impl_->pending_tree());
685
sunnypsad3235e2016-08-09 04:57:52686 std::vector<std::unique_ptr<SwapPromise>> empty_swap_promises;
687 layer_tree_host_impl_->BeginMainFrameAborted(reason,
688 std::move(empty_swap_promises));
mithrof7a21502014-12-17 03:24:48689 scheduler_on_impl_thread_->BeginMainFrameAborted(reason);
[email protected]aeeedad2014-08-22 18:16:22690}
691
danakj9d124422016-10-14 03:15:08692DrawResult SingleThreadProxy::ScheduledActionDrawIfPossible() {
khushalsagarb7db1fe2015-11-12 00:51:27693 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22694 LayerTreeHostImpl::FrameData frame;
mithro248d1722015-05-05 05:23:45695 return DoComposite(&frame);
[email protected]aeeedad2014-08-22 18:16:22696}
697
danakj9d124422016-10-14 03:15:08698DrawResult SingleThreadProxy::ScheduledActionDrawForced() {
[email protected]aeeedad2014-08-22 18:16:22699 NOTREACHED();
700 return INVALID_RESULT;
701}
702
703void SingleThreadProxy::ScheduledActionCommit() {
khushalsagarb7db1fe2015-11-12 00:51:27704 DebugScopedSetMainThread main(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44705 DoCommit();
[email protected]aeeedad2014-08-22 18:16:22706}
707
[email protected]aeeedad2014-08-22 18:16:22708void SingleThreadProxy::ScheduledActionActivateSyncTree() {
khushalsagarb7db1fe2015-11-12 00:51:27709 DebugScopedSetImplThread impl(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44710 layer_tree_host_impl_->ActivateSyncTree();
[email protected]aeeedad2014-08-22 18:16:22711}
712
danakj1120f4c2016-09-15 02:05:32713void SingleThreadProxy::ScheduledActionBeginCompositorFrameSinkCreation() {
khushalsagarb7db1fe2015-11-12 00:51:27714 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22715 DCHECK(scheduler_on_impl_thread_);
716 // If possible, create the output surface in a post task. Synchronously
717 // creating the output surface makes tests more awkward since this differs
718 // from the ThreadProxy behavior. However, sometimes there is no
719 // task runner.
khushalsagarb7db1fe2015-11-12 00:51:27720 if (task_runner_provider_->MainThreadTaskRunner()) {
danakj1120f4c2016-09-15 02:05:32721 ScheduleRequestNewCompositorFrameSink();
[email protected]aeeedad2014-08-22 18:16:22722 } else {
danakj1120f4c2016-09-15 02:05:32723 RequestNewCompositorFrameSink();
[email protected]aeeedad2014-08-22 18:16:22724 }
725}
726
vmiura59ea9b4042014-12-09 20:50:39727void SingleThreadProxy::ScheduledActionPrepareTiles() {
728 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionPrepareTiles");
khushalsagarb7db1fe2015-11-12 00:51:27729 DebugScopedSetImplThread impl(task_runner_provider_);
vmiura59ea9b4042014-12-09 20:50:39730 layer_tree_host_impl_->PrepareTiles();
[email protected]aeeedad2014-08-22 18:16:22731}
732
danakj1120f4c2016-09-15 02:05:32733void SingleThreadProxy::ScheduledActionInvalidateCompositorFrameSink() {
sunnypseab5ac92015-04-02 20:26:13734 NOTREACHED();
735}
736
mdjones2ee41afd2016-10-27 16:50:20737void SingleThreadProxy::UpdateBrowserControlsState(
738 BrowserControlsState constraints,
739 BrowserControlsState current,
740 bool animate) {
741 NOTREACHED() << "Browser Controls are used only in threaded mode";
khushalsagarc646cd62015-10-17 00:05:48742}
743
mithro51693e382015-05-07 23:52:41744void SingleThreadProxy::DidFinishImplFrame() {
745 layer_tree_host_impl_->DidFinishImplFrame();
746#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02747 DCHECK(inside_impl_frame_)
mithro51693e382015-05-07 23:52:41748 << "DidFinishImplFrame called while not inside an impl frame!";
mithro69fd3bb52015-05-01 03:45:02749 inside_impl_frame_ = false;
mithro51693e382015-05-07 23:52:41750#endif
[email protected]aeeedad2014-08-22 18:16:22751}
752
[email protected]bc5e77c2012-11-05 20:00:49753} // namespace cc