blob: 5288ae6d103db4df8cf47eff14730e697f7fcce7 [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"
robliao27728e62015-03-21 07:39:348#include "base/profiler/scoped_tracker.h"
primianoc06e2382015-01-28 04:21:499#include "base/trace_event/trace_event.h"
[email protected]adbe30f2013-10-11 21:12:3310#include "cc/debug/benchmark_instrumentation.h"
caseq7d2f4c92015-02-04 16:43:2711#include "cc/debug/devtools_instrumentation.h"
[email protected]7f0d825f2013-03-18 07:24:3012#include "cc/output/context_provider.h"
13#include "cc/output/output_surface.h"
[email protected]89e82672013-03-18 07:50:5614#include "cc/quads/draw_quad.h"
mithrof7a21502014-12-17 03:24:4815#include "cc/scheduler/commit_earlyout_reason.h"
briandersonc9f50352015-06-24 03:38:5816#include "cc/scheduler/compositor_timing_history.h"
17#include "cc/scheduler/scheduler.h"
[email protected]556fd292013-03-18 08:03:0418#include "cc/trees/layer_tree_host.h"
[email protected]943528e2013-11-07 05:01:3219#include "cc/trees/layer_tree_host_single_thread_client.h"
[email protected]556fd292013-03-18 08:03:0420#include "cc/trees/layer_tree_impl.h"
[email protected]aeeedad2014-08-22 18:16:2221#include "cc/trees/scoped_abort_remaining_swap_promises.h"
[email protected]94f206c12012-08-25 00:09:1422
[email protected]9c88e562012-09-14 22:21:3023namespace cc {
[email protected]94f206c12012-08-25 00:09:1424
[email protected]943528e2013-11-07 05:01:3225scoped_ptr<Proxy> SingleThreadProxy::Create(
26 LayerTreeHost* layer_tree_host,
[email protected]27e6a212014-07-18 15:51:2727 LayerTreeHostSingleThreadClient* client,
khushalsagarb7db1fe2015-11-12 00:51:2728 TaskRunnerProvider* task_runner_provider,
simonhonga7e3ac42014-11-11 20:50:2229 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
khushalsagarb7db1fe2015-11-12 00:51:2730 return make_scoped_ptr(
31 new SingleThreadProxy(layer_tree_host, client, task_runner_provider,
32 external_begin_frame_source.Pass()));
[email protected]94f206c12012-08-25 00:09:1433}
34
[email protected]27e6a212014-07-18 15:51:2735SingleThreadProxy::SingleThreadProxy(
36 LayerTreeHost* layer_tree_host,
37 LayerTreeHostSingleThreadClient* client,
khushalsagarb7db1fe2015-11-12 00:51:2738 TaskRunnerProvider* task_runner_provider,
simonhonga7e3ac42014-11-11 20:50:2239 scoped_ptr<BeginFrameSource> external_begin_frame_source)
khushalsagarb7db1fe2015-11-12 00:51:2740 : layer_tree_host_(layer_tree_host),
[email protected]943528e2013-11-07 05:01:3241 client_(client),
khushalsagarb7db1fe2015-11-12 00:51:2742 task_runner_provider_(task_runner_provider),
sunnypsf381ede2015-06-23 01:46:5343 external_begin_frame_source_(external_begin_frame_source.Pass()),
[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),
[email protected]aeeedad2014-08-22 18:16:2254 weak_factory_(this) {
[email protected]a8a049c2013-03-11 23:27:0655 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
khushalsagarb7db1fe2015-11-12 00:51:2756 DCHECK(task_runner_provider_);
57 DCHECK(task_runner_provider_->IsMainThread());
[email protected]a8a049c2013-03-11 23:27:0658 DCHECK(layer_tree_host);
danakjfcdaba122015-04-24 21:41:5259
60 if (layer_tree_host->settings().single_thread_proxy_scheduler &&
61 !scheduler_on_impl_thread_) {
62 SchedulerSettings scheduler_settings(
63 layer_tree_host->settings().ToSchedulerSettings());
danakj5f2e92de2015-06-20 00:25:5864 scheduler_settings.commit_to_active_tree = CommitToActiveTree();
briandersonc9f50352015-06-24 03:38:5865
66 scoped_ptr<CompositorTimingHistory> compositor_timing_history(
67 new CompositorTimingHistory(
briandersonc68220f2015-07-20 20:08:3568 CompositorTimingHistory::BROWSER_UMA,
briandersonc9f50352015-06-24 03:38:5869 layer_tree_host->rendering_stats_instrumentation()));
70
danakjfcdaba122015-04-24 21:41:5271 scheduler_on_impl_thread_ = Scheduler::Create(
72 this, scheduler_settings, layer_tree_host_->id(),
khushalsagarb7db1fe2015-11-12 00:51:2773 task_runner_provider_->MainThreadTaskRunner(),
74 external_begin_frame_source_.get(), compositor_timing_history.Pass());
danakjfcdaba122015-04-24 21:41:5275 }
[email protected]94f206c12012-08-25 00:09:1476}
77
[email protected]e96e3432013-12-19 18:56:0778void SingleThreadProxy::Start() {
khushalsagarb7db1fe2015-11-12 00:51:2779 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]804c8982013-03-13 16:32:2180 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
[email protected]a8a049c2013-03-11 23:27:0681}
82
83SingleThreadProxy::~SingleThreadProxy() {
84 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy");
khushalsagarb7db1fe2015-11-12 00:51:2785 DCHECK(task_runner_provider_->IsMainThread());
[email protected]04049fc2013-05-01 03:13:2086 // Make sure Stop() got called or never Started.
87 DCHECK(!layer_tree_host_impl_);
[email protected]a8a049c2013-03-11 23:27:0688}
89
[email protected]a8a049c2013-03-11 23:27:0690void SingleThreadProxy::FinishAllRendering() {
[email protected]ccc08dc2014-01-30 07:33:2091 TRACE_EVENT0("cc", "SingleThreadProxy::FinishAllRendering");
khushalsagarb7db1fe2015-11-12 00:51:2792 DCHECK(task_runner_provider_->IsMainThread());
[email protected]a8a049c2013-03-11 23:27:0693 {
khushalsagarb7db1fe2015-11-12 00:51:2794 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]c1bb5af2013-03-13 19:06:2795 layer_tree_host_impl_->FinishAllRendering();
[email protected]a8a049c2013-03-11 23:27:0696 }
[email protected]94f206c12012-08-25 00:09:1497}
98
[email protected]a8a049c2013-03-11 23:27:0699bool SingleThreadProxy::IsStarted() const {
khushalsagarb7db1fe2015-11-12 00:51:27100 DCHECK(task_runner_provider_->IsMainThread());
[email protected]3209161d2013-03-29 19:17:34101 return layer_tree_host_impl_;
[email protected]94f206c12012-08-25 00:09:14102}
103
danakj009cdfdf2015-02-17 22:35:14104bool SingleThreadProxy::CommitToActiveTree() const {
105 // With SingleThreadProxy we skip the pending tree and commit directly to the
106 // active tree.
107 return true;
108}
109
[email protected]a8a049c2013-03-11 23:27:06110void SingleThreadProxy::SetVisible(bool visible) {
mithro46adf5a2014-11-19 14:52:40111 TRACE_EVENT1("cc", "SingleThreadProxy::SetVisible", "visible", visible);
khushalsagarb7db1fe2015-11-12 00:51:27112 DebugScopedSetImplThread impl(task_runner_provider_);
sunnypsc3f6e0c2015-07-25 01:00:59113
[email protected]c1bb5af2013-03-13 19:06:27114 layer_tree_host_impl_->SetVisible(visible);
sunnypsc3f6e0c2015-07-25 01:00:59115
[email protected]aeeedad2014-08-22 18:16:22116 if (scheduler_on_impl_thread_)
117 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
[email protected]a8a049c2013-03-11 23:27:06118}
119
bajones274110612015-01-06 20:53:59120void SingleThreadProxy::SetThrottleFrameProduction(bool throttle) {
121 TRACE_EVENT1("cc", "SingleThreadProxy::SetThrottleFrameProduction",
122 "throttle", throttle);
khushalsagarb7db1fe2015-11-12 00:51:27123 DebugScopedSetImplThread impl(task_runner_provider_);
bajones274110612015-01-06 20:53:59124 if (scheduler_on_impl_thread_)
125 scheduler_on_impl_thread_->SetThrottleFrameProduction(throttle);
126}
127
enne2097cab2014-09-25 20:16:31128void SingleThreadProxy::RequestNewOutputSurface() {
khushalsagarb7db1fe2015-11-12 00:51:27129 DCHECK(task_runner_provider_->IsMainThread());
[email protected]497edf82014-05-20 21:53:15130 DCHECK(layer_tree_host_->output_surface_lost());
jbauman8ab0f9e2014-10-15 02:30:34131 output_surface_creation_callback_.Cancel();
132 if (output_surface_creation_requested_)
133 return;
134 output_surface_creation_requested_ = true;
enne2097cab2014-09-25 20:16:31135 layer_tree_host_->RequestNewOutputSurface();
136}
[email protected]94f206c12012-08-25 00:09:14137
revemand180dfc32015-09-24 00:19:43138void SingleThreadProxy::ReleaseOutputSurface() {
sieverse83e41d2015-09-18 23:33:26139 // |layer_tree_host_| should already be aware of this.
140 DCHECK(layer_tree_host_->output_surface_lost());
141
sohan.jyoti3a33d872015-09-18 22:32:55142 if (scheduler_on_impl_thread_)
143 scheduler_on_impl_thread_->DidLoseOutputSurface();
144 return layer_tree_host_impl_->ReleaseOutputSurface();
145}
146
revemand180dfc32015-09-24 00:19:43147void SingleThreadProxy::SetOutputSurface(OutputSurface* output_surface) {
khushalsagarb7db1fe2015-11-12 00:51:27148 DCHECK(task_runner_provider_->IsMainThread());
enne2097cab2014-09-25 20:16:31149 DCHECK(layer_tree_host_->output_surface_lost());
enne5232fbb2015-01-27 21:22:41150 DCHECK(output_surface_creation_requested_);
[email protected]da8e3b72b2014-04-25 02:33:45151 renderer_capabilities_for_main_thread_ = RendererCapabilities();
152
enne7f8fdde2014-12-10 21:32:09153 bool success;
154 {
khushalsagarb7db1fe2015-11-12 00:51:27155 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
156 DebugScopedSetImplThread impl(task_runner_provider_);
revemand180dfc32015-09-24 00:19:43157 success = layer_tree_host_impl_->InitializeRenderer(output_surface);
[email protected]04049fc2013-05-01 03:13:20158 }
159
[email protected]aeeedad2014-08-22 18:16:22160 if (success) {
enne7f8fdde2014-12-10 21:32:09161 layer_tree_host_->DidInitializeOutputSurface();
[email protected]aeeedad2014-08-22 18:16:22162 if (scheduler_on_impl_thread_)
163 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface();
jbauman399aec1a2014-10-25 02:33:32164 else if (!inside_synchronous_composite_)
165 SetNeedsCommit();
enne5232fbb2015-01-27 21:22:41166 output_surface_creation_requested_ = false;
enne7f8fdde2014-12-10 21:32:09167 } else {
enne5232fbb2015-01-27 21:22:41168 // DidFailToInitializeOutputSurface is treated as a RequestNewOutputSurface,
169 // and so output_surface_creation_requested remains true.
enne7f8fdde2014-12-10 21:32:09170 layer_tree_host_->DidFailToInitializeOutputSurface();
[email protected]04049fc2013-05-01 03:13:20171 }
[email protected]94f206c12012-08-25 00:09:14172}
173
[email protected]a8a049c2013-03-11 23:27:06174const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const {
khushalsagarb7db1fe2015-11-12 00:51:27175 DCHECK(task_runner_provider_->IsMainThread());
[email protected]04049fc2013-05-01 03:13:20176 DCHECK(!layer_tree_host_->output_surface_lost());
[email protected]a8a049c2013-03-11 23:27:06177 return renderer_capabilities_for_main_thread_;
[email protected]94f206c12012-08-25 00:09:14178}
179
[email protected]8b9e52b2014-01-17 16:35:31180void SingleThreadProxy::SetNeedsAnimate() {
[email protected]ccc08dc2014-01-30 07:33:20181 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate");
khushalsagarb7db1fe2015-11-12 00:51:27182 DCHECK(task_runner_provider_->IsMainThread());
[email protected]06cbc31b2014-01-17 06:43:20183 client_->ScheduleAnimation();
brianderson49e101d22015-04-29 00:05:33184 if (animate_requested_)
185 return;
186 animate_requested_ = true;
khushalsagarb7db1fe2015-11-12 00:51:27187 DebugScopedSetImplThread impl(task_runner_provider_);
brianderson49e101d22015-04-29 00:05:33188 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01189 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
[email protected]c5134172013-12-11 06:19:48190}
191
[email protected]8b9e52b2014-01-17 16:35:31192void SingleThreadProxy::SetNeedsUpdateLayers() {
[email protected]ccc08dc2014-01-30 07:33:20193 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers");
khushalsagarb7db1fe2015-11-12 00:51:27194 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22195 SetNeedsCommit();
[email protected]8b9e52b2014-01-17 16:35:31196}
197
enne98f3a6c2014-10-09 20:09:44198void SingleThreadProxy::DoCommit() {
[email protected]ccc08dc2014-01-30 07:33:20199 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit");
khushalsagarb7db1fe2015-11-12 00:51:27200 DCHECK(task_runner_provider_->IsMainThread());
enne98f3a6c2014-10-09 20:09:44201
robliao27728e62015-03-21 07:39:34202 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 is
203 // fixed.
204 tracked_objects::ScopedTracker tracking_profile1(
205 FROM_HERE_WITH_EXPLICIT_FUNCTION("461509 SingleThreadProxy::DoCommit1"));
[email protected]aeeedad2014-08-22 18:16:22206 layer_tree_host_->WillCommit();
caseq7d2f4c92015-02-04 16:43:27207 devtools_instrumentation::ScopedCommitTrace commit_task(
208 layer_tree_host_->id());
[email protected]aeeedad2014-08-22 18:16:22209
[email protected]a8a049c2013-03-11 23:27:06210 // Commit immediately.
211 {
robliao27728e62015-03-21 07:39:34212 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
213 // is fixed.
214 tracked_objects::ScopedTracker tracking_profile2(
215 FROM_HERE_WITH_EXPLICIT_FUNCTION(
216 "461509 SingleThreadProxy::DoCommit2"));
khushalsagarb7db1fe2015-11-12 00:51:27217 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
218 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]f7c01c82013-07-02 22:58:46219
[email protected]9794fb32013-08-29 09:49:59220 // This CapturePostTasks should be destroyed before CommitComplete() is
221 // called since that goes out to the embedder, and we want the embedder
222 // to receive its callbacks before that.
enne98f3a6c2014-10-09 20:09:44223 commit_blocking_task_runner_.reset(new BlockingTaskRunner::CapturePostTasks(
khushalsagarb7db1fe2015-11-12 00:51:27224 task_runner_provider_->blocking_main_thread_task_runner()));
[email protected]9794fb32013-08-29 09:49:59225
[email protected]c1bb5af2013-03-13 19:06:27226 layer_tree_host_impl_->BeginCommit();
[email protected]94f206c12012-08-25 00:09:14227
robliao27728e62015-03-21 07:39:34228 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
229 // is fixed.
robliao27728e62015-03-21 07:39:34230 tracked_objects::ScopedTracker tracking_profile6(
231 FROM_HERE_WITH_EXPLICIT_FUNCTION(
232 "461509 SingleThreadProxy::DoCommit6"));
[email protected]127bdc1a2013-09-11 01:44:48233 if (layer_tree_host_impl_->EvictedUIResourcesExist())
234 layer_tree_host_->RecreateUIResources();
235
robliao27728e62015-03-21 07:39:34236 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
237 // is fixed.
238 tracked_objects::ScopedTracker tracking_profile7(
239 FROM_HERE_WITH_EXPLICIT_FUNCTION(
240 "461509 SingleThreadProxy::DoCommit7"));
[email protected]804c8982013-03-13 16:32:21241 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14242
danakje649f572015-01-08 23:35:58243#if DCHECK_IS_ON()
[email protected]3519b872013-07-30 07:17:50244 // In the single-threaded case, the scale and scroll deltas should never be
[email protected]a8a049c2013-03-11 23:27:06245 // touched on the impl layer tree.
[email protected]ed511b8d2013-03-25 03:29:29246 scoped_ptr<ScrollAndScaleSet> scroll_info =
[email protected]c1bb5af2013-03-13 19:06:27247 layer_tree_host_impl_->ProcessScrollDeltas();
[email protected]ed511b8d2013-03-25 03:29:29248 DCHECK(!scroll_info->scrolls.size());
[email protected]3519b872013-07-30 07:17:50249 DCHECK_EQ(1.f, scroll_info->page_scale_delta);
[email protected]94f206c12012-08-25 00:09:14250#endif
enne98f3a6c2014-10-09 20:09:44251
danakj3c3973b2015-08-25 21:50:18252 if (scheduler_on_impl_thread_)
253 scheduler_on_impl_thread_->DidCommit();
254
255 layer_tree_host_impl_->CommitComplete();
256
danakj68803fc2015-06-19 20:55:53257 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
258 // is fixed.
259 tracked_objects::ScopedTracker tracking_profile8(
260 FROM_HERE_WITH_EXPLICIT_FUNCTION(
261 "461509 SingleThreadProxy::DoCommit8"));
262 // Commit goes directly to the active tree, but we need to synchronously
263 // "activate" the tree still during commit to satisfy any potential
264 // SetNextCommitWaitsForActivation calls. Unfortunately, the tree
265 // might not be ready to draw, so DidActivateSyncTree must set
266 // the flag to force the tree to not draw until textures are ready.
267 NotifyReadyToActivate();
enne98f3a6c2014-10-09 20:09:44268 }
269}
270
271void SingleThreadProxy::CommitComplete() {
danakj3c3973b2015-08-25 21:50:18272 // Commit complete happens on the main side after activate to satisfy any
273 // SetNextCommitWaitsForActivation calls.
enne98f3a6c2014-10-09 20:09:44274 DCHECK(!layer_tree_host_impl_->pending_tree())
275 << "Activation is expected to have synchronously occurred by now.";
276 DCHECK(commit_blocking_task_runner_);
277
khushalsagarb7db1fe2015-11-12 00:51:27278 DebugScopedSetMainThread main(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44279 commit_blocking_task_runner_.reset();
[email protected]804c8982013-03-13 16:32:21280 layer_tree_host_->CommitComplete();
[email protected]aeeedad2014-08-22 18:16:22281 layer_tree_host_->DidBeginMainFrame();
[email protected]aeeedad2014-08-22 18:16:22282
[email protected]a8a049c2013-03-11 23:27:06283 next_frame_is_newly_committed_frame_ = true;
[email protected]94f206c12012-08-25 00:09:14284}
285
[email protected]a8a049c2013-03-11 23:27:06286void SingleThreadProxy::SetNeedsCommit() {
khushalsagarb7db1fe2015-11-12 00:51:27287 DCHECK(task_runner_provider_->IsMainThread());
[email protected]943528e2013-11-07 05:01:32288 client_->ScheduleComposite();
danakjfcdaba122015-04-24 21:41:52289 if (commit_requested_)
290 return;
brianderson49e101d22015-04-29 00:05:33291 commit_requested_ = true;
khushalsagarb7db1fe2015-11-12 00:51:27292 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22293 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01294 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
[email protected]94f206c12012-08-25 00:09:14295}
296
[email protected]0023fc72014-01-10 20:05:06297void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) {
[email protected]ccc08dc2014-01-30 07:33:20298 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw");
khushalsagarb7db1fe2015-11-12 00:51:27299 DCHECK(task_runner_provider_->IsMainThread());
300 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]2decdd782014-08-13 22:36:06301 client_->ScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22302 SetNeedsRedrawRectOnImplThread(damage_rect);
[email protected]94f206c12012-08-25 00:09:14303}
304
[email protected]74b43cc2013-08-30 06:29:27305void SingleThreadProxy::SetNextCommitWaitsForActivation() {
enne98f3a6c2014-10-09 20:09:44306 // Activation always forced in commit, so nothing to do.
khushalsagarb7db1fe2015-11-12 00:51:27307 DCHECK(task_runner_provider_->IsMainThread());
[email protected]74b43cc2013-08-30 06:29:27308}
309
[email protected]a8a049c2013-03-11 23:27:06310void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
khushalsagarb7db1fe2015-11-12 00:51:27311 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22312 // Deferring commits only makes sense if there's a scheduler.
313 if (!scheduler_on_impl_thread_)
314 return;
315 if (defer_commits_ == defer_commits)
316 return;
317
318 if (defer_commits)
319 TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this);
320 else
321 TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this);
322
323 defer_commits_ = defer_commits;
simonhongc6309f792015-01-31 15:47:15324 scheduler_on_impl_thread_->SetDeferCommits(defer_commits);
[email protected]6b16679e2012-10-27 00:44:28325}
326
[email protected]174c6d42014-08-12 01:43:06327bool SingleThreadProxy::CommitRequested() const {
khushalsagarb7db1fe2015-11-12 00:51:27328 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22329 return commit_requested_;
[email protected]174c6d42014-08-12 01:43:06330}
[email protected]a8a049c2013-03-11 23:27:06331
[email protected]174c6d42014-08-12 01:43:06332bool SingleThreadProxy::BeginMainFrameRequested() const {
khushalsagarb7db1fe2015-11-12 00:51:27333 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22334 // If there is no scheduler, then there can be no pending begin frame,
335 // as all frames are all manually initiated by the embedder of cc.
336 if (!scheduler_on_impl_thread_)
337 return false;
338 return commit_requested_;
[email protected]174c6d42014-08-12 01:43:06339}
[email protected]971728d2013-10-26 10:39:31340
[email protected]a8a049c2013-03-11 23:27:06341void SingleThreadProxy::Stop() {
342 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
khushalsagarb7db1fe2015-11-12 00:51:27343 DCHECK(task_runner_provider_->IsMainThread());
[email protected]a8a049c2013-03-11 23:27:06344 {
khushalsagarb7db1fe2015-11-12 00:51:27345 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
346 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06347
skyostil3976a3f2014-09-04 22:07:23348 BlockingTaskRunner::CapturePostTasks blocked(
khushalsagarb7db1fe2015-11-12 00:51:27349 task_runner_provider_->blocking_main_thread_task_runner());
danakjf446a072014-09-27 21:55:48350 scheduler_on_impl_thread_ = nullptr;
351 layer_tree_host_impl_ = nullptr;
[email protected]a8a049c2013-03-11 23:27:06352 }
[email protected]7aba6662013-03-12 10:17:34353 layer_tree_host_ = NULL;
[email protected]a8a049c2013-03-11 23:27:06354}
355
boliu8ca83902015-10-23 04:36:13356void SingleThreadProxy::OnResourcelessSoftareDrawStateChanged(
357 bool resourceless_draw) {
358 NOTREACHED();
359}
360
[email protected]3d9f7432013-04-06 00:35:18361void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
[email protected]ccc08dc2014-01-30 07:33:20362 TRACE_EVENT1(
363 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
khushalsagarb7db1fe2015-11-12 00:51:27364 DCHECK(task_runner_provider_->IsImplThread());
[email protected]aeeedad2014-08-22 18:16:22365 if (scheduler_on_impl_thread_)
366 scheduler_on_impl_thread_->SetCanDraw(can_draw);
[email protected]3d9f7432013-04-06 00:35:18367}
368
[email protected]4f48f6e2013-08-27 06:33:38369void SingleThreadProxy::NotifyReadyToActivate() {
enne98f3a6c2014-10-09 20:09:44370 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate");
khushalsagarb7db1fe2015-11-12 00:51:27371 DebugScopedSetImplThread impl(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44372 if (scheduler_on_impl_thread_)
373 scheduler_on_impl_thread_->NotifyReadyToActivate();
[email protected]4f48f6e2013-08-27 06:33:38374}
375
ernstmdfac03e2014-11-11 20:18:05376void SingleThreadProxy::NotifyReadyToDraw() {
weiliangc8dac5a62015-04-02 06:12:35377 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToDraw");
khushalsagarb7db1fe2015-11-12 00:51:27378 DebugScopedSetImplThread impl(task_runner_provider_);
weiliangc8dac5a62015-04-02 06:12:35379 if (scheduler_on_impl_thread_)
380 scheduler_on_impl_thread_->NotifyReadyToDraw();
ernstmdfac03e2014-11-11 20:18:05381}
382
[email protected]c1bb5af2013-03-13 19:06:27383void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
[email protected]943528e2013-11-07 05:01:32384 client_->ScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22385 if (scheduler_on_impl_thread_)
386 scheduler_on_impl_thread_->SetNeedsRedraw();
[email protected]a8a049c2013-03-11 23:27:06387}
388
[email protected]43b8f982014-04-30 21:24:33389void SingleThreadProxy::SetNeedsAnimateOnImplThread() {
mithro719bf6792014-11-10 15:36:47390 client_->ScheduleComposite();
391 if (scheduler_on_impl_thread_)
392 scheduler_on_impl_thread_->SetNeedsAnimate();
[email protected]43b8f982014-04-30 21:24:33393}
394
vmiura59ea9b4042014-12-09 20:50:39395void SingleThreadProxy::SetNeedsPrepareTilesOnImplThread() {
396 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsPrepareTilesOnImplThread");
enne98f3a6c2014-10-09 20:09:44397 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39398 scheduler_on_impl_thread_->SetNeedsPrepareTiles();
[email protected]c48536a52013-09-14 00:02:08399}
400
[email protected]0023fc72014-01-10 20:05:06401void SingleThreadProxy::SetNeedsRedrawRectOnImplThread(
402 const gfx::Rect& damage_rect) {
[email protected]1cd9f5552013-04-26 04:22:03403 layer_tree_host_impl_->SetViewportDamage(damage_rect);
[email protected]aeeedad2014-08-22 18:16:22404 SetNeedsRedrawOnImplThread();
[email protected]1cd9f5552013-04-26 04:22:03405}
406
[email protected]c1bb5af2013-03-13 19:06:27407void SingleThreadProxy::SetNeedsCommitOnImplThread() {
[email protected]943528e2013-11-07 05:01:32408 client_->ScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22409 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01410 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
[email protected]a8a049c2013-03-11 23:27:06411}
412
sunnyps7d073dc2015-04-16 23:29:12413void SingleThreadProxy::SetVideoNeedsBeginFrames(bool needs_begin_frames) {
414 TRACE_EVENT1("cc", "SingleThreadProxy::SetVideoNeedsBeginFrames",
415 "needs_begin_frames", needs_begin_frames);
416 // In tests the layer tree is destroyed after the scheduler is.
417 if (scheduler_on_impl_thread_)
418 scheduler_on_impl_thread_->SetVideoNeedsBeginFrames(needs_begin_frames);
419}
420
[email protected]c1bb5af2013-03-13 19:06:27421void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
[email protected]85b57502014-03-11 15:37:48422 scoped_ptr<AnimationEventsVector> events) {
[email protected]ccc08dc2014-01-30 07:33:20423 TRACE_EVENT0(
424 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
khushalsagarb7db1fe2015-11-12 00:51:27425 DCHECK(task_runner_provider_->IsImplThread());
426 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]85b57502014-03-11 15:37:48427 layer_tree_host_->SetAnimationEvents(events.Pass());
[email protected]a8a049c2013-03-11 23:27:06428}
429
[email protected]c1bb5af2013-03-13 19:06:27430bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
[email protected]a8a049c2013-03-11 23:27:06431
enne98f3a6c2014-10-09 20:09:44432void SingleThreadProxy::DidActivateSyncTree() {
danakj68803fc2015-06-19 20:55:53433 // Synchronously call to CommitComplete. Resetting
434 // |commit_blocking_task_runner| would make sure all tasks posted during
435 // commit/activation before CommitComplete.
436 CommitComplete();
enne98f3a6c2014-10-09 20:09:44437}
438
brianderson68749812015-07-07 22:39:39439void SingleThreadProxy::WillPrepareTiles() {
khushalsagarb7db1fe2015-11-12 00:51:27440 DCHECK(task_runner_provider_->IsImplThread());
brianderson68749812015-07-07 22:39:39441 if (scheduler_on_impl_thread_)
442 scheduler_on_impl_thread_->WillPrepareTiles();
443}
444
vmiura59ea9b4042014-12-09 20:50:39445void SingleThreadProxy::DidPrepareTiles() {
khushalsagarb7db1fe2015-11-12 00:51:27446 DCHECK(task_runner_provider_->IsImplThread());
enne98f3a6c2014-10-09 20:09:44447 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39448 scheduler_on_impl_thread_->DidPrepareTiles();
enne98f3a6c2014-10-09 20:09:44449}
450
rouslanf7ebd8832015-01-22 01:54:14451void SingleThreadProxy::DidCompletePageScaleAnimationOnImplThread() {
452 layer_tree_host_->DidCompletePageScaleAnimation();
453}
454
[email protected]fa339032014-02-18 22:11:59455void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() {
khushalsagarb7db1fe2015-11-12 00:51:27456 DCHECK(task_runner_provider_->IsImplThread());
[email protected]fa339032014-02-18 22:11:59457 renderer_capabilities_for_main_thread_ =
458 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities();
459}
460
[email protected]c1bb5af2013-03-13 19:06:27461void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
[email protected]ccc08dc2014-01-30 07:33:20462 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22463 {
khushalsagarb7db1fe2015-11-12 00:51:27464 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22465 // This must happen before we notify the scheduler as it may try to recreate
466 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE.
467 layer_tree_host_->DidLoseOutputSurface();
468 }
[email protected]4d7e46a2013-11-08 05:33:40469 client_->DidAbortSwapBuffers();
[email protected]aeeedad2014-08-22 18:16:22470 if (scheduler_on_impl_thread_)
471 scheduler_on_impl_thread_->DidLoseOutputSurface();
[email protected]4d7e46a2013-11-08 05:33:40472}
473
weiliangcaf17af42014-12-15 22:17:02474void SingleThreadProxy::CommitVSyncParameters(base::TimeTicks timebase,
475 base::TimeDelta interval) {
476 if (scheduler_on_impl_thread_)
477 scheduler_on_impl_thread_->CommitVSyncParameters(timebase, interval);
478}
479
jbauman93a5a902015-03-13 22:16:55480void SingleThreadProxy::SetEstimatedParentDrawTime(base::TimeDelta draw_time) {
481 if (scheduler_on_impl_thread_)
482 scheduler_on_impl_thread_->SetEstimatedParentDrawTime(draw_time);
483}
484
alexst346f30c2015-03-25 13:24:05485void SingleThreadProxy::SetMaxSwapsPendingOnImplThread(int max) {
486 if (scheduler_on_impl_thread_)
487 scheduler_on_impl_thread_->SetMaxSwapsPending(max);
488}
489
[email protected]4d7e46a2013-11-08 05:33:40490void SingleThreadProxy::DidSwapBuffersOnImplThread() {
[email protected]aeeedad2014-08-22 18:16:22491 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersOnImplThread");
492 if (scheduler_on_impl_thread_)
493 scheduler_on_impl_thread_->DidSwapBuffers();
[email protected]4d7e46a2013-11-08 05:33:40494 client_->DidPostSwapBuffers();
495}
496
[email protected]c14902662014-04-18 05:06:11497void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() {
miletusfed8c43b2015-01-26 20:04:52498 TRACE_EVENT0("cc,benchmark",
499 "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22500 if (scheduler_on_impl_thread_)
501 scheduler_on_impl_thread_->DidSwapBuffersComplete();
502 layer_tree_host_->DidCompleteSwapBuffers();
[email protected]493067512012-09-19 23:34:10503}
504
sunnypseab5ac92015-04-02 20:26:13505void SingleThreadProxy::OnDrawForOutputSurface() {
506 NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor.";
507}
508
mpbed24c2c2015-06-05 20:57:13509void SingleThreadProxy::PostFrameTimingEventsOnImplThread(
510 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
511 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) {
512 layer_tree_host_->RecordFrameTimingEvents(composite_events.Pass(),
513 main_frame_events.Pass());
514}
515
[email protected]f0c2a242013-03-15 19:34:52516void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
miletusfed8c43b2015-01-26 20:04:52517 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately");
khushalsagarb7db1fe2015-11-12 00:51:27518 DCHECK(task_runner_provider_->IsMainThread());
mithro51693e382015-05-07 23:52:41519#if DCHECK_IS_ON()
mithroc76d70312015-05-04 23:51:13520 DCHECK(!inside_impl_frame_);
mithro51693e382015-05-07 23:52:41521#endif
jbauman399aec1a2014-10-25 02:33:32522 base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true);
523
524 if (layer_tree_host_->output_surface_lost()) {
525 RequestNewOutputSurface();
526 // RequestNewOutputSurface could have synchronously created an output
527 // surface, so check again before returning.
528 if (layer_tree_host_->output_surface_lost())
529 return;
530 }
[email protected]51f81da2014-05-16 21:29:26531
mithroc76d70312015-05-04 23:51:13532 BeginFrameArgs begin_frame_args(BeginFrameArgs::Create(
533 BEGINFRAME_FROM_HERE, frame_begin_time, base::TimeTicks(),
534 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL));
535
536 // Start the impl frame.
enne98f3a6c2014-10-09 20:09:44537 {
khushalsagarb7db1fe2015-11-12 00:51:27538 DebugScopedSetImplThread impl(task_runner_provider_);
mithroc76d70312015-05-04 23:51:13539 WillBeginImplFrame(begin_frame_args);
540 }
541
542 // Run the "main thread" and get it to commit.
543 {
mithro51693e382015-05-07 23:52:41544#if DCHECK_IS_ON()
mithroc76d70312015-05-04 23:51:13545 DCHECK(inside_impl_frame_);
mithro51693e382015-05-07 23:52:41546#endif
enne98f3a6c2014-10-09 20:09:44547 DoBeginMainFrame(begin_frame_args);
548 DoCommit();
[email protected]e0341352013-04-06 05:01:20549
enne98f3a6c2014-10-09 20:09:44550 DCHECK_EQ(0u, layer_tree_host_->num_queued_swap_promises())
551 << "Commit should always succeed and transfer promises.";
552 }
553
mithroc76d70312015-05-04 23:51:13554 // Finish the impl frame.
enne98f3a6c2014-10-09 20:09:44555 {
khushalsagarb7db1fe2015-11-12 00:51:27556 DebugScopedSetImplThread impl(task_runner_provider_);
danakj68803fc2015-06-19 20:55:53557 layer_tree_host_impl_->ActivateSyncTree();
558 DCHECK(
559 !layer_tree_host_impl_->active_tree()->needs_update_draw_properties());
560 layer_tree_host_impl_->PrepareTiles();
561 layer_tree_host_impl_->SynchronouslyInitializeAllTiles();
enne69277cb2014-10-29 23:03:40562
danakj12e2f6e2015-08-19 22:25:44563 // TODO(danakj): Don't do this last... we prepared the wrong things. D:
564 layer_tree_host_impl_->Animate();
mithro719bf6792014-11-10 15:36:47565
enne98f3a6c2014-10-09 20:09:44566 LayerTreeHostImpl::FrameData frame;
mithro248d1722015-05-05 05:23:45567 DoComposite(&frame);
enne98f3a6c2014-10-09 20:09:44568
569 // DoComposite could abort, but because this is a synchronous composite
570 // another draw will never be scheduled, so break remaining promises.
571 layer_tree_host_impl_->active_tree()->BreakSwapPromises(
572 SwapPromise::SWAP_FAILS);
mithroc76d70312015-05-04 23:51:13573
mithro51693e382015-05-07 23:52:41574 DidFinishImplFrame();
enne98f3a6c2014-10-09 20:09:44575 }
[email protected]74d9063c2013-01-18 03:14:47576}
577
[email protected]5d8bec72014-07-03 03:03:11578bool SingleThreadProxy::SupportsImplScrolling() const {
579 return false;
580}
581
[email protected]3d9f7432013-04-06 00:35:18582bool SingleThreadProxy::ShouldComposite() const {
khushalsagarb7db1fe2015-11-12 00:51:27583 DCHECK(task_runner_provider_->IsImplThread());
[email protected]3d9f7432013-04-06 00:35:18584 return layer_tree_host_impl_->visible() &&
585 layer_tree_host_impl_->CanDraw();
586}
587
jbauman8ab0f9e2014-10-15 02:30:34588void SingleThreadProxy::ScheduleRequestNewOutputSurface() {
589 if (output_surface_creation_callback_.IsCancelled() &&
590 !output_surface_creation_requested_) {
591 output_surface_creation_callback_.Reset(
592 base::Bind(&SingleThreadProxy::RequestNewOutputSurface,
593 weak_factory_.GetWeakPtr()));
khushalsagarb7db1fe2015-11-12 00:51:27594 task_runner_provider_->MainThreadTaskRunner()->PostTask(
jbauman8ab0f9e2014-10-15 02:30:34595 FROM_HERE, output_surface_creation_callback_.callback());
596 }
597}
598
mithro248d1722015-05-05 05:23:45599DrawResult SingleThreadProxy::DoComposite(LayerTreeHostImpl::FrameData* frame) {
[email protected]ccc08dc2014-01-30 07:33:20600 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite");
[email protected]04049fc2013-05-01 03:13:20601 DCHECK(!layer_tree_host_->output_surface_lost());
602
enne98f3a6c2014-10-09 20:09:44603 DrawResult draw_result;
604 bool draw_frame;
[email protected]a8a049c2013-03-11 23:27:06605 {
khushalsagarb7db1fe2015-11-12 00:51:27606 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06607 base::AutoReset<bool> mark_inside(&inside_draw_, true);
608
robliao27728e62015-03-21 07:39:34609 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
610 // is fixed.
611 tracked_objects::ScopedTracker tracking_profile1(
612 FROM_HERE_WITH_EXPLICIT_FUNCTION(
613 "461509 SingleThreadProxy::DoComposite1"));
614
[email protected]3d9f7432013-04-06 00:35:18615 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
616 // frame, so can only be used when such a frame is possible. Since
617 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
618 // CanDraw() as well.
[email protected]2aae96792014-05-15 23:10:50619 if (!ShouldComposite()) {
[email protected]aeeedad2014-08-22 18:16:22620 return DRAW_ABORTED_CANT_DRAW;
[email protected]3d9f7432013-04-06 00:35:18621 }
[email protected]a8a049c2013-03-11 23:27:06622
robliao27728e62015-03-21 07:39:34623 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
624 // is fixed.
625 tracked_objects::ScopedTracker tracking_profile2(
626 FROM_HERE_WITH_EXPLICIT_FUNCTION(
627 "461509 SingleThreadProxy::DoComposite2"));
enne98f3a6c2014-10-09 20:09:44628 draw_result = layer_tree_host_impl_->PrepareToDraw(frame);
629 draw_frame = draw_result == DRAW_SUCCESS;
robliao27728e62015-03-21 07:39:34630 if (draw_frame) {
631 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
632 // is fixed.
633 tracked_objects::ScopedTracker tracking_profile3(
634 FROM_HERE_WITH_EXPLICIT_FUNCTION(
635 "461509 SingleThreadProxy::DoComposite3"));
mithro248d1722015-05-05 05:23:45636 layer_tree_host_impl_->DrawLayers(frame);
robliao27728e62015-03-21 07:39:34637 }
638 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
639 // is fixed.
640 tracked_objects::ScopedTracker tracking_profile4(
641 FROM_HERE_WITH_EXPLICIT_FUNCTION(
642 "461509 SingleThreadProxy::DoComposite4"));
dnetob71e30c2014-08-25 23:27:20643 layer_tree_host_impl_->DidDrawAllLayers(*frame);
[email protected]a8a049c2013-03-11 23:27:06644
enne98f3a6c2014-10-09 20:09:44645 bool start_ready_animations = draw_frame;
robliao27728e62015-03-21 07:39:34646 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
647 // is fixed.
648 tracked_objects::ScopedTracker tracking_profile5(
649 FROM_HERE_WITH_EXPLICIT_FUNCTION(
650 "461509 SingleThreadProxy::DoComposite5"));
[email protected]3d9f7432013-04-06 00:35:18651 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
[email protected]aeeedad2014-08-22 18:16:22652
robliao27728e62015-03-21 07:39:34653 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
654 // is fixed.
655 tracked_objects::ScopedTracker tracking_profile7(
656 FROM_HERE_WITH_EXPLICIT_FUNCTION(
657 "461509 SingleThreadProxy::DoComposite7"));
[email protected]a8a049c2013-03-11 23:27:06658 }
659
enne98f3a6c2014-10-09 20:09:44660 if (draw_frame) {
khushalsagarb7db1fe2015-11-12 00:51:27661 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]174c6d42014-08-12 01:43:06662
dnetob71e30c2014-08-25 23:27:20663 // This CapturePostTasks should be destroyed before
664 // DidCommitAndDrawFrame() is called since that goes out to the
665 // embedder,
666 // and we want the embedder to receive its callbacks before that.
667 // NOTE: This maintains consistent ordering with the ThreadProxy since
668 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
669 // there as the main thread is not blocked, so any posted tasks inside
670 // the swap buffers will execute first.
khushalsagarb7db1fe2015-11-12 00:51:27671 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22672
skyostil3976a3f2014-09-04 22:07:23673 BlockingTaskRunner::CapturePostTasks blocked(
khushalsagarb7db1fe2015-11-12 00:51:27674 task_runner_provider_->blocking_main_thread_task_runner());
robliao27728e62015-03-21 07:39:34675 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
676 // is fixed.
677 tracked_objects::ScopedTracker tracking_profile8(
678 FROM_HERE_WITH_EXPLICIT_FUNCTION(
679 "461509 SingleThreadProxy::DoComposite8"));
dnetob71e30c2014-08-25 23:27:20680 layer_tree_host_impl_->SwapBuffers(*frame);
[email protected]aeeedad2014-08-22 18:16:22681 }
robliao27728e62015-03-21 07:39:34682 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 is
683 // fixed.
684 tracked_objects::ScopedTracker tracking_profile9(
685 FROM_HERE_WITH_EXPLICIT_FUNCTION(
686 "461509 SingleThreadProxy::DoComposite9"));
[email protected]aeeedad2014-08-22 18:16:22687 DidCommitAndDrawFrame();
688
enne98f3a6c2014-10-09 20:09:44689 return draw_result;
[email protected]a8a049c2013-03-11 23:27:06690}
691
[email protected]aeeedad2014-08-22 18:16:22692void SingleThreadProxy::DidCommitAndDrawFrame() {
[email protected]a8a049c2013-03-11 23:27:06693 if (next_frame_is_newly_committed_frame_) {
khushalsagarb7db1fe2015-11-12 00:51:27694 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06695 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21696 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06697 }
698}
699
[email protected]4ea293f72014-08-13 03:03:17700bool SingleThreadProxy::MainFrameWillHappenForTesting() {
danakjfcdaba122015-04-24 21:41:52701 if (layer_tree_host_->output_surface_lost())
702 return false;
703 if (!scheduler_on_impl_thread_)
704 return false;
705 return scheduler_on_impl_thread_->MainFrameForTestingWillHappen();
[email protected]4ea293f72014-08-13 03:03:17706}
[email protected]a8a049c2013-03-11 23:27:06707
simonhongd3d5f7f2014-11-21 16:38:03708void SingleThreadProxy::SetChildrenNeedBeginFrames(
709 bool children_need_begin_frames) {
710 scheduler_on_impl_thread_->SetChildrenNeedBeginFrames(
711 children_need_begin_frames);
712}
713
simonhong298590fe2015-03-25 06:51:13714void SingleThreadProxy::SetAuthoritativeVSyncInterval(
715 const base::TimeDelta& interval) {
716 scheduler_on_impl_thread_->SetAuthoritativeVSyncInterval(interval);
717}
718
[email protected]aeeedad2014-08-22 18:16:22719void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) {
mithro51693e382015-05-07 23:52:41720#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02721 DCHECK(!inside_impl_frame_)
722 << "WillBeginImplFrame called while already inside an impl frame!";
723 inside_impl_frame_ = true;
mithro51693e382015-05-07 23:52:41724#endif
[email protected]aeeedad2014-08-22 18:16:22725 layer_tree_host_impl_->WillBeginImplFrame(args);
726}
727
728void SingleThreadProxy::ScheduledActionSendBeginMainFrame() {
729 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame");
730 // Although this proxy is single-threaded, it's problematic to synchronously
731 // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This
732 // could cause a commit to occur in between a series of SetNeedsCommit calls
733 // (i.e. property modifications) causing some to fall on one frame and some to
734 // fall on the next. Doing it asynchronously instead matches the semantics of
735 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a
736 // synchronous commit.
mithro51693e382015-05-07 23:52:41737#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02738 DCHECK(inside_impl_frame_)
739 << "BeginMainFrame should only be sent inside a BeginImplFrame";
mithro51693e382015-05-07 23:52:41740#endif
mithro69fd3bb52015-05-01 03:45:02741 const BeginFrameArgs& begin_frame_args =
742 layer_tree_host_impl_->CurrentBeginFrameArgs();
743
khushalsagarb7db1fe2015-11-12 00:51:27744 task_runner_provider_->MainThreadTaskRunner()->PostTask(
mithro69fd3bb52015-05-01 03:45:02745 FROM_HERE, base::Bind(&SingleThreadProxy::BeginMainFrame,
746 weak_factory_.GetWeakPtr(), begin_frame_args));
[email protected]aeeedad2014-08-22 18:16:22747}
748
rmcilroy0a19362a2015-02-18 12:34:25749void SingleThreadProxy::SendBeginMainFrameNotExpectedSoon() {
750 layer_tree_host_->BeginMainFrameNotExpectedSoon();
751}
752
mithro69fd3bb52015-05-01 03:45:02753void SingleThreadProxy::BeginMainFrame(const BeginFrameArgs& begin_frame_args) {
brianderson21aef162015-11-11 05:12:23754 if (scheduler_on_impl_thread_) {
755 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(
756 base::TimeTicks::Now());
757 }
758
danakjfcdaba122015-04-24 21:41:52759 commit_requested_ = false;
brianderson49e101d22015-04-29 00:05:33760 animate_requested_ = false;
danakjfcdaba122015-04-24 21:41:52761
[email protected]aeeedad2014-08-22 18:16:22762 if (defer_commits_) {
simonhongc6309f792015-01-31 15:47:15763 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit",
764 TRACE_EVENT_SCOPE_THREAD);
765 BeginMainFrameAbortedOnImplThread(
766 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT);
[email protected]aeeedad2014-08-22 18:16:22767 return;
768 }
769
enne98f3a6c2014-10-09 20:09:44770 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous
771 // commit.
[email protected]aeeedad2014-08-22 18:16:22772 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_);
773
774 if (!layer_tree_host_->visible()) {
775 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD);
mithrof7a21502014-12-17 03:24:48776 BeginMainFrameAbortedOnImplThread(
777 CommitEarlyOutReason::ABORTED_NOT_VISIBLE);
[email protected]aeeedad2014-08-22 18:16:22778 return;
779 }
780
781 if (layer_tree_host_->output_surface_lost()) {
782 TRACE_EVENT_INSTANT0(
783 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD);
mithrof7a21502014-12-17 03:24:48784 BeginMainFrameAbortedOnImplThread(
785 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST);
[email protected]aeeedad2014-08-22 18:16:22786 return;
787 }
788
danakjfcdaba122015-04-24 21:41:52789 // Prevent new commits from being requested inside DoBeginMainFrame.
brianderson49e101d22015-04-29 00:05:33790 // Note: We do not want to prevent SetNeedsAnimate from requesting
791 // a commit here.
danakjfcdaba122015-04-24 21:41:52792 commit_requested_ = true;
793
enne98f3a6c2014-10-09 20:09:44794 DoBeginMainFrame(begin_frame_args);
795}
796
797void SingleThreadProxy::DoBeginMainFrame(
798 const BeginFrameArgs& begin_frame_args) {
799 layer_tree_host_->WillBeginMainFrame();
800 layer_tree_host_->BeginMainFrame(begin_frame_args);
801 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time);
wkorman7265db012015-11-03 04:08:25802 layer_tree_host_->RequestMainFrameUpdate();
enne98f3a6c2014-10-09 20:09:44803
danakjfcdaba122015-04-24 21:41:52804 // New commits requested inside UpdateLayers should be respected.
805 commit_requested_ = false;
806
danakj5f46636a2015-06-19 00:01:40807 layer_tree_host_->UpdateLayers();
enne98f3a6c2014-10-09 20:09:44808
mithrof7a21502014-12-17 03:24:48809 // TODO(enne): SingleThreadProxy does not support cancelling commits yet,
810 // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside
811 // thread_proxy.cc
brianderson21aef162015-11-11 05:12:23812 if (scheduler_on_impl_thread_)
enne98f3a6c2014-10-09 20:09:44813 scheduler_on_impl_thread_->NotifyReadyToCommit();
[email protected]aeeedad2014-08-22 18:16:22814}
815
mithrof7a21502014-12-17 03:24:48816void SingleThreadProxy::BeginMainFrameAbortedOnImplThread(
817 CommitEarlyOutReason reason) {
khushalsagarb7db1fe2015-11-12 00:51:27818 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22819 DCHECK(scheduler_on_impl_thread_->CommitPending());
820 DCHECK(!layer_tree_host_impl_->pending_tree());
821
mithrof7a21502014-12-17 03:24:48822 layer_tree_host_impl_->BeginMainFrameAborted(reason);
823 scheduler_on_impl_thread_->BeginMainFrameAborted(reason);
[email protected]aeeedad2014-08-22 18:16:22824}
825
826DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
khushalsagarb7db1fe2015-11-12 00:51:27827 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22828 LayerTreeHostImpl::FrameData frame;
mithro248d1722015-05-05 05:23:45829 return DoComposite(&frame);
[email protected]aeeedad2014-08-22 18:16:22830}
831
832DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() {
833 NOTREACHED();
834 return INVALID_RESULT;
835}
836
837void SingleThreadProxy::ScheduledActionCommit() {
khushalsagarb7db1fe2015-11-12 00:51:27838 DebugScopedSetMainThread main(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44839 DoCommit();
[email protected]aeeedad2014-08-22 18:16:22840}
841
842void SingleThreadProxy::ScheduledActionAnimate() {
843 TRACE_EVENT0("cc", "ScheduledActionAnimate");
khushalsagarb7db1fe2015-11-12 00:51:27844 DebugScopedSetImplThread impl(task_runner_provider_);
danakj12e2f6e2015-08-19 22:25:44845 layer_tree_host_impl_->Animate();
[email protected]aeeedad2014-08-22 18:16:22846}
847
[email protected]aeeedad2014-08-22 18:16:22848void SingleThreadProxy::ScheduledActionActivateSyncTree() {
khushalsagarb7db1fe2015-11-12 00:51:27849 DebugScopedSetImplThread impl(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44850 layer_tree_host_impl_->ActivateSyncTree();
[email protected]aeeedad2014-08-22 18:16:22851}
852
853void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
khushalsagarb7db1fe2015-11-12 00:51:27854 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22855 DCHECK(scheduler_on_impl_thread_);
856 // If possible, create the output surface in a post task. Synchronously
857 // creating the output surface makes tests more awkward since this differs
858 // from the ThreadProxy behavior. However, sometimes there is no
859 // task runner.
khushalsagarb7db1fe2015-11-12 00:51:27860 if (task_runner_provider_->MainThreadTaskRunner()) {
jbauman8ab0f9e2014-10-15 02:30:34861 ScheduleRequestNewOutputSurface();
[email protected]aeeedad2014-08-22 18:16:22862 } else {
enne2097cab2014-09-25 20:16:31863 RequestNewOutputSurface();
[email protected]aeeedad2014-08-22 18:16:22864 }
865}
866
vmiura59ea9b4042014-12-09 20:50:39867void SingleThreadProxy::ScheduledActionPrepareTiles() {
868 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionPrepareTiles");
khushalsagarb7db1fe2015-11-12 00:51:27869 DebugScopedSetImplThread impl(task_runner_provider_);
vmiura59ea9b4042014-12-09 20:50:39870 layer_tree_host_impl_->PrepareTiles();
[email protected]aeeedad2014-08-22 18:16:22871}
872
sunnypseab5ac92015-04-02 20:26:13873void SingleThreadProxy::ScheduledActionInvalidateOutputSurface() {
874 NOTREACHED();
875}
876
khushalsagarc646cd62015-10-17 00:05:48877void SingleThreadProxy::UpdateTopControlsState(TopControlsState constraints,
878 TopControlsState current,
879 bool animate) {
880 NOTREACHED() << "Top Controls are used only in threaded mode";
881}
882
mithro51693e382015-05-07 23:52:41883void SingleThreadProxy::DidFinishImplFrame() {
884 layer_tree_host_impl_->DidFinishImplFrame();
885#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02886 DCHECK(inside_impl_frame_)
mithro51693e382015-05-07 23:52:41887 << "DidFinishImplFrame called while not inside an impl frame!";
mithro69fd3bb52015-05-01 03:45:02888 inside_impl_frame_ = false;
mithro51693e382015-05-07 23:52:41889#endif
[email protected]aeeedad2014-08-22 18:16:22890}
891
simonhongd3d5f7f2014-11-21 16:38:03892void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) {
893 layer_tree_host_->SendBeginFramesToChildren(args);
894}
895
[email protected]bc5e77c2012-11-05 20:00:49896} // namespace cc