blob: 2d219756c3ce23a69de126f86bc88a480a573d98 [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// Copyright 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]556fd292013-03-18 08:03:045#include "cc/trees/single_thread_proxy.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]74d9063c2013-01-18 03:14:477#include "base/auto_reset.h"
danakj60bc3bc2016-04-09 00:24:488#include "base/memory/ptr_util.h"
robliao27728e62015-03-21 07:39:349#include "base/profiler/scoped_tracker.h"
primianoc06e2382015-01-28 04:21:4910#include "base/trace_event/trace_event.h"
loysoe926437dd2016-01-14 22:55:3011#include "cc/animation/animation_events.h"
[email protected]adbe30f2013-10-11 21:12:3312#include "cc/debug/benchmark_instrumentation.h"
caseq7d2f4c92015-02-04 16:43:2713#include "cc/debug/devtools_instrumentation.h"
[email protected]7f0d825f2013-03-18 07:24:3014#include "cc/output/context_provider.h"
15#include "cc/output/output_surface.h"
[email protected]89e82672013-03-18 07:50:5616#include "cc/quads/draw_quad.h"
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"
19#include "cc/scheduler/scheduler.h"
[email protected]556fd292013-03-18 08:03:0420#include "cc/trees/layer_tree_host.h"
jaydasika13c05062016-04-01 18:12:2721#include "cc/trees/layer_tree_host_common.h"
[email protected]943528e2013-11-07 05:01:3222#include "cc/trees/layer_tree_host_single_thread_client.h"
[email protected]556fd292013-03-18 08:03:0423#include "cc/trees/layer_tree_impl.h"
[email protected]aeeedad2014-08-22 18:16:2224#include "cc/trees/scoped_abort_remaining_swap_promises.h"
[email protected]94f206c12012-08-25 00:09:1425
[email protected]9c88e562012-09-14 22:21:3026namespace cc {
[email protected]94f206c12012-08-25 00:09:1427
danakj60bc3bc2016-04-09 00:24:4828std::unique_ptr<Proxy> SingleThreadProxy::Create(
[email protected]943528e2013-11-07 05:01:3229 LayerTreeHost* layer_tree_host,
[email protected]27e6a212014-07-18 15:51:2730 LayerTreeHostSingleThreadClient* client,
khushalsagar767dd522015-12-16 05:14:0531 TaskRunnerProvider* task_runner_provider) {
danakj60bc3bc2016-04-09 00:24:4832 return base::WrapUnique(
khushalsagar767dd522015-12-16 05:14:0533 new SingleThreadProxy(layer_tree_host, client, task_runner_provider));
[email protected]94f206c12012-08-25 00:09:1434}
35
khushalsagar767dd522015-12-16 05:14:0536SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host,
37 LayerTreeHostSingleThreadClient* client,
38 TaskRunnerProvider* task_runner_provider)
khushalsagarb7db1fe2015-11-12 00:51:2739 : layer_tree_host_(layer_tree_host),
[email protected]943528e2013-11-07 05:01:3240 client_(client),
khushalsagarb7db1fe2015-11-12 00:51:2741 task_runner_provider_(task_runner_provider),
[email protected]a8a049c2013-03-11 23:27:0642 next_frame_is_newly_committed_frame_(false),
mithro51693e382015-05-07 23:52:4143#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:0244 inside_impl_frame_(false),
mithro51693e382015-05-07 23:52:4145#endif
[email protected]aeeedad2014-08-22 18:16:2246 inside_draw_(false),
47 defer_commits_(false),
brianderson49e101d22015-04-29 00:05:3348 animate_requested_(false),
[email protected]aeeedad2014-08-22 18:16:2249 commit_requested_(false),
jbauman399aec1a2014-10-25 02:33:3250 inside_synchronous_composite_(false),
jbauman8ab0f9e2014-10-15 02:30:3451 output_surface_creation_requested_(false),
[email protected]aeeedad2014-08-22 18:16:2252 weak_factory_(this) {
[email protected]a8a049c2013-03-11 23:27:0653 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
khushalsagarb7db1fe2015-11-12 00:51:2754 DCHECK(task_runner_provider_);
55 DCHECK(task_runner_provider_->IsMainThread());
[email protected]a8a049c2013-03-11 23:27:0656 DCHECK(layer_tree_host);
khushalsagar767dd522015-12-16 05:14:0557}
danakjfcdaba122015-04-24 21:41:5258
khushalsagar767dd522015-12-16 05:14:0559void SingleThreadProxy::Start(
danakj60bc3bc2016-04-09 00:24:4860 std::unique_ptr<BeginFrameSource> external_begin_frame_source) {
khushalsagar767dd522015-12-16 05:14:0561 DebugScopedSetImplThread impl(task_runner_provider_);
62 external_begin_frame_source_ = std::move(external_begin_frame_source);
63
64 if (layer_tree_host_->settings().single_thread_proxy_scheduler &&
danakjfcdaba122015-04-24 21:41:5265 !scheduler_on_impl_thread_) {
66 SchedulerSettings scheduler_settings(
khushalsagar767dd522015-12-16 05:14:0567 layer_tree_host_->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()));
briandersonc9f50352015-06-24 03:38:5875
enne19c108582016-04-14 03:35:3276 BeginFrameSource* frame_source = nullptr;
77 if (!layer_tree_host_->settings().use_output_surface_begin_frame_source) {
78 frame_source = external_begin_frame_source_.get();
79 if (!scheduler_settings.throttle_frame_production) {
80 // Unthrottled source takes precedence over external sources.
81 unthrottled_begin_frame_source_.reset(new BackToBackBeginFrameSource(
82 task_runner_provider_->MainThreadTaskRunner()));
83 frame_source = unthrottled_begin_frame_source_.get();
84 }
85 if (!frame_source) {
86 synthetic_begin_frame_source_.reset(new SyntheticBeginFrameSource(
87 task_runner_provider_->MainThreadTaskRunner(),
88 BeginFrameArgs::DefaultInterval()));
89 frame_source = synthetic_begin_frame_source_.get();
90 }
enneb9bf3772016-03-16 21:51:1191 }
92
danakja04855a2015-11-18 20:39:1093 scheduler_on_impl_thread_ =
94 Scheduler::Create(this, scheduler_settings, layer_tree_host_->id(),
95 task_runner_provider_->MainThreadTaskRunner(),
enneb9bf3772016-03-16 21:51:1196 frame_source, std::move(compositor_timing_history));
danakjfcdaba122015-04-24 21:41:5297 }
[email protected]94f206c12012-08-25 00:09:1498
[email protected]804c8982013-03-13 16:32:2199 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
[email protected]a8a049c2013-03-11 23:27:06100}
101
102SingleThreadProxy::~SingleThreadProxy() {
103 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy");
khushalsagarb7db1fe2015-11-12 00:51:27104 DCHECK(task_runner_provider_->IsMainThread());
[email protected]04049fc2013-05-01 03:13:20105 // Make sure Stop() got called or never Started.
106 DCHECK(!layer_tree_host_impl_);
[email protected]a8a049c2013-03-11 23:27:06107}
108
[email protected]a8a049c2013-03-11 23:27:06109void SingleThreadProxy::FinishAllRendering() {
[email protected]ccc08dc2014-01-30 07:33:20110 TRACE_EVENT0("cc", "SingleThreadProxy::FinishAllRendering");
khushalsagarb7db1fe2015-11-12 00:51:27111 DCHECK(task_runner_provider_->IsMainThread());
[email protected]a8a049c2013-03-11 23:27:06112 {
khushalsagarb7db1fe2015-11-12 00:51:27113 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]c1bb5af2013-03-13 19:06:27114 layer_tree_host_impl_->FinishAllRendering();
[email protected]a8a049c2013-03-11 23:27:06115 }
[email protected]94f206c12012-08-25 00:09:14116}
117
[email protected]a8a049c2013-03-11 23:27:06118bool SingleThreadProxy::IsStarted() const {
khushalsagarb7db1fe2015-11-12 00:51:27119 DCHECK(task_runner_provider_->IsMainThread());
dcheng5d64b522016-01-20 01:41:02120 return !!layer_tree_host_impl_;
[email protected]94f206c12012-08-25 00:09:14121}
122
danakj009cdfdf2015-02-17 22:35:14123bool SingleThreadProxy::CommitToActiveTree() const {
124 // With SingleThreadProxy we skip the pending tree and commit directly to the
125 // active tree.
126 return true;
127}
128
[email protected]a8a049c2013-03-11 23:27:06129void SingleThreadProxy::SetVisible(bool visible) {
mithro46adf5a2014-11-19 14:52:40130 TRACE_EVENT1("cc", "SingleThreadProxy::SetVisible", "visible", visible);
khushalsagarb7db1fe2015-11-12 00:51:27131 DebugScopedSetImplThread impl(task_runner_provider_);
sunnypsc3f6e0c2015-07-25 01:00:59132
[email protected]c1bb5af2013-03-13 19:06:27133 layer_tree_host_impl_->SetVisible(visible);
sunnypsc3f6e0c2015-07-25 01:00:59134
[email protected]aeeedad2014-08-22 18:16:22135 if (scheduler_on_impl_thread_)
136 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
[email protected]a8a049c2013-03-11 23:27:06137}
138
enne2097cab2014-09-25 20:16:31139void SingleThreadProxy::RequestNewOutputSurface() {
khushalsagarb7db1fe2015-11-12 00:51:27140 DCHECK(task_runner_provider_->IsMainThread());
[email protected]497edf82014-05-20 21:53:15141 DCHECK(layer_tree_host_->output_surface_lost());
jbauman8ab0f9e2014-10-15 02:30:34142 output_surface_creation_callback_.Cancel();
143 if (output_surface_creation_requested_)
144 return;
145 output_surface_creation_requested_ = true;
enne2097cab2014-09-25 20:16:31146 layer_tree_host_->RequestNewOutputSurface();
147}
[email protected]94f206c12012-08-25 00:09:14148
revemand180dfc32015-09-24 00:19:43149void SingleThreadProxy::ReleaseOutputSurface() {
sieverse83e41d2015-09-18 23:33:26150 // |layer_tree_host_| should already be aware of this.
151 DCHECK(layer_tree_host_->output_surface_lost());
152
sohan.jyoti3a33d872015-09-18 22:32:55153 if (scheduler_on_impl_thread_)
154 scheduler_on_impl_thread_->DidLoseOutputSurface();
155 return layer_tree_host_impl_->ReleaseOutputSurface();
156}
157
revemand180dfc32015-09-24 00:19:43158void SingleThreadProxy::SetOutputSurface(OutputSurface* output_surface) {
khushalsagarb7db1fe2015-11-12 00:51:27159 DCHECK(task_runner_provider_->IsMainThread());
enne2097cab2014-09-25 20:16:31160 DCHECK(layer_tree_host_->output_surface_lost());
enne5232fbb2015-01-27 21:22:41161 DCHECK(output_surface_creation_requested_);
[email protected]da8e3b72b2014-04-25 02:33:45162 renderer_capabilities_for_main_thread_ = RendererCapabilities();
163
enne7f8fdde2014-12-10 21:32:09164 bool success;
165 {
khushalsagarb7db1fe2015-11-12 00:51:27166 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
167 DebugScopedSetImplThread impl(task_runner_provider_);
revemand180dfc32015-09-24 00:19:43168 success = layer_tree_host_impl_->InitializeRenderer(output_surface);
[email protected]04049fc2013-05-01 03:13:20169 }
170
[email protected]aeeedad2014-08-22 18:16:22171 if (success) {
enne7f8fdde2014-12-10 21:32:09172 layer_tree_host_->DidInitializeOutputSurface();
[email protected]aeeedad2014-08-22 18:16:22173 if (scheduler_on_impl_thread_)
174 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface();
jbauman399aec1a2014-10-25 02:33:32175 else if (!inside_synchronous_composite_)
176 SetNeedsCommit();
enne5232fbb2015-01-27 21:22:41177 output_surface_creation_requested_ = false;
enne7f8fdde2014-12-10 21:32:09178 } else {
enne5232fbb2015-01-27 21:22:41179 // DidFailToInitializeOutputSurface is treated as a RequestNewOutputSurface,
180 // and so output_surface_creation_requested remains true.
enne7f8fdde2014-12-10 21:32:09181 layer_tree_host_->DidFailToInitializeOutputSurface();
[email protected]04049fc2013-05-01 03:13:20182 }
[email protected]94f206c12012-08-25 00:09:14183}
184
[email protected]a8a049c2013-03-11 23:27:06185const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const {
khushalsagarb7db1fe2015-11-12 00:51:27186 DCHECK(task_runner_provider_->IsMainThread());
[email protected]04049fc2013-05-01 03:13:20187 DCHECK(!layer_tree_host_->output_surface_lost());
[email protected]a8a049c2013-03-11 23:27:06188 return renderer_capabilities_for_main_thread_;
[email protected]94f206c12012-08-25 00:09:14189}
190
[email protected]8b9e52b2014-01-17 16:35:31191void SingleThreadProxy::SetNeedsAnimate() {
[email protected]ccc08dc2014-01-30 07:33:20192 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate");
khushalsagarb7db1fe2015-11-12 00:51:27193 DCHECK(task_runner_provider_->IsMainThread());
danakj53eccbc2016-03-02 22:51:07194 client_->RequestScheduleAnimation();
brianderson49e101d22015-04-29 00:05:33195 if (animate_requested_)
196 return;
197 animate_requested_ = true;
khushalsagarb7db1fe2015-11-12 00:51:27198 DebugScopedSetImplThread impl(task_runner_provider_);
brianderson49e101d22015-04-29 00:05:33199 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01200 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
[email protected]c5134172013-12-11 06:19:48201}
202
[email protected]8b9e52b2014-01-17 16:35:31203void SingleThreadProxy::SetNeedsUpdateLayers() {
[email protected]ccc08dc2014-01-30 07:33:20204 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers");
khushalsagarb7db1fe2015-11-12 00:51:27205 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22206 SetNeedsCommit();
[email protected]8b9e52b2014-01-17 16:35:31207}
208
enne98f3a6c2014-10-09 20:09:44209void SingleThreadProxy::DoCommit() {
[email protected]ccc08dc2014-01-30 07:33:20210 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit");
khushalsagarb7db1fe2015-11-12 00:51:27211 DCHECK(task_runner_provider_->IsMainThread());
enne98f3a6c2014-10-09 20:09:44212
robliao27728e62015-03-21 07:39:34213 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 is
214 // fixed.
215 tracked_objects::ScopedTracker tracking_profile1(
216 FROM_HERE_WITH_EXPLICIT_FUNCTION("461509 SingleThreadProxy::DoCommit1"));
[email protected]aeeedad2014-08-22 18:16:22217 layer_tree_host_->WillCommit();
caseq7d2f4c92015-02-04 16:43:27218 devtools_instrumentation::ScopedCommitTrace commit_task(
219 layer_tree_host_->id());
[email protected]aeeedad2014-08-22 18:16:22220
vmpstrd6dce2602016-05-18 20:19:04221 layer_tree_host_->ReportFixedRasterScaleUseCounters(
222 layer_tree_host_impl_->has_fixed_raster_scale_blurry_content(),
223 layer_tree_host_impl_
224 ->HasFixedRasterScalePotentialPerformanceRegression());
225
[email protected]a8a049c2013-03-11 23:27:06226 // Commit immediately.
227 {
robliao27728e62015-03-21 07:39:34228 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
229 // is fixed.
230 tracked_objects::ScopedTracker tracking_profile2(
231 FROM_HERE_WITH_EXPLICIT_FUNCTION(
232 "461509 SingleThreadProxy::DoCommit2"));
khushalsagarb7db1fe2015-11-12 00:51:27233 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
234 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]f7c01c82013-07-02 22:58:46235
[email protected]9794fb32013-08-29 09:49:59236 // This CapturePostTasks should be destroyed before CommitComplete() is
237 // called since that goes out to the embedder, and we want the embedder
238 // to receive its callbacks before that.
enne98f3a6c2014-10-09 20:09:44239 commit_blocking_task_runner_.reset(new BlockingTaskRunner::CapturePostTasks(
khushalsagarb7db1fe2015-11-12 00:51:27240 task_runner_provider_->blocking_main_thread_task_runner()));
[email protected]9794fb32013-08-29 09:49:59241
[email protected]c1bb5af2013-03-13 19:06:27242 layer_tree_host_impl_->BeginCommit();
[email protected]94f206c12012-08-25 00:09:14243
robliao27728e62015-03-21 07:39:34244 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
245 // is fixed.
robliao27728e62015-03-21 07:39:34246 tracked_objects::ScopedTracker tracking_profile6(
247 FROM_HERE_WITH_EXPLICIT_FUNCTION(
248 "461509 SingleThreadProxy::DoCommit6"));
[email protected]127bdc1a2013-09-11 01:44:48249 if (layer_tree_host_impl_->EvictedUIResourcesExist())
250 layer_tree_host_->RecreateUIResources();
251
robliao27728e62015-03-21 07:39:34252 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
253 // is fixed.
254 tracked_objects::ScopedTracker tracking_profile7(
255 FROM_HERE_WITH_EXPLICIT_FUNCTION(
256 "461509 SingleThreadProxy::DoCommit7"));
[email protected]804c8982013-03-13 16:32:21257 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14258
danakje649f572015-01-08 23:35:58259#if DCHECK_IS_ON()
[email protected]3519b872013-07-30 07:17:50260 // In the single-threaded case, the scale and scroll deltas should never be
[email protected]a8a049c2013-03-11 23:27:06261 // touched on the impl layer tree.
danakj60bc3bc2016-04-09 00:24:48262 std::unique_ptr<ScrollAndScaleSet> scroll_info =
[email protected]c1bb5af2013-03-13 19:06:27263 layer_tree_host_impl_->ProcessScrollDeltas();
[email protected]ed511b8d2013-03-25 03:29:29264 DCHECK(!scroll_info->scrolls.size());
[email protected]3519b872013-07-30 07:17:50265 DCHECK_EQ(1.f, scroll_info->page_scale_delta);
[email protected]94f206c12012-08-25 00:09:14266#endif
enne98f3a6c2014-10-09 20:09:44267
danakj3c3973b2015-08-25 21:50:18268 if (scheduler_on_impl_thread_)
269 scheduler_on_impl_thread_->DidCommit();
270
271 layer_tree_host_impl_->CommitComplete();
272
danakj68803fc2015-06-19 20:55:53273 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
274 // is fixed.
275 tracked_objects::ScopedTracker tracking_profile8(
276 FROM_HERE_WITH_EXPLICIT_FUNCTION(
277 "461509 SingleThreadProxy::DoCommit8"));
278 // Commit goes directly to the active tree, but we need to synchronously
279 // "activate" the tree still during commit to satisfy any potential
280 // SetNextCommitWaitsForActivation calls. Unfortunately, the tree
281 // might not be ready to draw, so DidActivateSyncTree must set
282 // the flag to force the tree to not draw until textures are ready.
283 NotifyReadyToActivate();
enne98f3a6c2014-10-09 20:09:44284 }
285}
286
287void SingleThreadProxy::CommitComplete() {
danakj3c3973b2015-08-25 21:50:18288 // Commit complete happens on the main side after activate to satisfy any
289 // SetNextCommitWaitsForActivation calls.
enne98f3a6c2014-10-09 20:09:44290 DCHECK(!layer_tree_host_impl_->pending_tree())
291 << "Activation is expected to have synchronously occurred by now.";
292 DCHECK(commit_blocking_task_runner_);
293
khushalsagarb7db1fe2015-11-12 00:51:27294 DebugScopedSetMainThread main(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44295 commit_blocking_task_runner_.reset();
[email protected]804c8982013-03-13 16:32:21296 layer_tree_host_->CommitComplete();
[email protected]aeeedad2014-08-22 18:16:22297 layer_tree_host_->DidBeginMainFrame();
[email protected]aeeedad2014-08-22 18:16:22298
[email protected]a8a049c2013-03-11 23:27:06299 next_frame_is_newly_committed_frame_ = true;
[email protected]94f206c12012-08-25 00:09:14300}
301
[email protected]a8a049c2013-03-11 23:27:06302void SingleThreadProxy::SetNeedsCommit() {
khushalsagarb7db1fe2015-11-12 00:51:27303 DCHECK(task_runner_provider_->IsMainThread());
danakj53eccbc2016-03-02 22:51:07304 client_->RequestScheduleComposite();
danakjfcdaba122015-04-24 21:41:52305 if (commit_requested_)
306 return;
brianderson49e101d22015-04-29 00:05:33307 commit_requested_ = true;
khushalsagarb7db1fe2015-11-12 00:51:27308 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22309 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01310 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
[email protected]94f206c12012-08-25 00:09:14311}
312
[email protected]0023fc72014-01-10 20:05:06313void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) {
[email protected]ccc08dc2014-01-30 07:33:20314 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw");
khushalsagarb7db1fe2015-11-12 00:51:27315 DCHECK(task_runner_provider_->IsMainThread());
316 DebugScopedSetImplThread impl(task_runner_provider_);
danakj53eccbc2016-03-02 22:51:07317 client_->RequestScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22318 SetNeedsRedrawRectOnImplThread(damage_rect);
[email protected]94f206c12012-08-25 00:09:14319}
320
[email protected]74b43cc2013-08-30 06:29:27321void SingleThreadProxy::SetNextCommitWaitsForActivation() {
enne98f3a6c2014-10-09 20:09:44322 // Activation always forced in commit, so nothing to do.
khushalsagarb7db1fe2015-11-12 00:51:27323 DCHECK(task_runner_provider_->IsMainThread());
[email protected]74b43cc2013-08-30 06:29:27324}
325
[email protected]a8a049c2013-03-11 23:27:06326void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
khushalsagarb7db1fe2015-11-12 00:51:27327 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22328 // Deferring commits only makes sense if there's a scheduler.
329 if (!scheduler_on_impl_thread_)
330 return;
331 if (defer_commits_ == defer_commits)
332 return;
333
334 if (defer_commits)
335 TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this);
336 else
337 TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this);
338
339 defer_commits_ = defer_commits;
simonhongc6309f792015-01-31 15:47:15340 scheduler_on_impl_thread_->SetDeferCommits(defer_commits);
[email protected]6b16679e2012-10-27 00:44:28341}
342
[email protected]174c6d42014-08-12 01:43:06343bool SingleThreadProxy::CommitRequested() const {
khushalsagarb7db1fe2015-11-12 00:51:27344 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22345 return commit_requested_;
[email protected]174c6d42014-08-12 01:43:06346}
[email protected]a8a049c2013-03-11 23:27:06347
[email protected]174c6d42014-08-12 01:43:06348bool SingleThreadProxy::BeginMainFrameRequested() const {
khushalsagarb7db1fe2015-11-12 00:51:27349 DCHECK(task_runner_provider_->IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22350 // If there is no scheduler, then there can be no pending begin frame,
351 // as all frames are all manually initiated by the embedder of cc.
352 if (!scheduler_on_impl_thread_)
353 return false;
354 return commit_requested_;
[email protected]174c6d42014-08-12 01:43:06355}
[email protected]971728d2013-10-26 10:39:31356
[email protected]a8a049c2013-03-11 23:27:06357void SingleThreadProxy::Stop() {
358 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
khushalsagarb7db1fe2015-11-12 00:51:27359 DCHECK(task_runner_provider_->IsMainThread());
[email protected]a8a049c2013-03-11 23:27:06360 {
khushalsagarb7db1fe2015-11-12 00:51:27361 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
362 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06363
skyostil3976a3f2014-09-04 22:07:23364 BlockingTaskRunner::CapturePostTasks blocked(
khushalsagarb7db1fe2015-11-12 00:51:27365 task_runner_provider_->blocking_main_thread_task_runner());
danakjf446a072014-09-27 21:55:48366 scheduler_on_impl_thread_ = nullptr;
367 layer_tree_host_impl_ = nullptr;
[email protected]a8a049c2013-03-11 23:27:06368 }
[email protected]7aba6662013-03-12 10:17:34369 layer_tree_host_ = NULL;
[email protected]a8a049c2013-03-11 23:27:06370}
371
flackrf54e9b42016-05-31 15:20:10372void SingleThreadProxy::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) {
373 DCHECK(task_runner_provider_->IsMainThread());
374 DebugScopedSetImplThread impl(task_runner_provider_);
375 layer_tree_host_impl_->SetLayerTreeMutator(std::move(mutator));
376}
377
[email protected]3d9f7432013-04-06 00:35:18378void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
[email protected]ccc08dc2014-01-30 07:33:20379 TRACE_EVENT1(
380 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
khushalsagarb7db1fe2015-11-12 00:51:27381 DCHECK(task_runner_provider_->IsImplThread());
[email protected]aeeedad2014-08-22 18:16:22382 if (scheduler_on_impl_thread_)
383 scheduler_on_impl_thread_->SetCanDraw(can_draw);
[email protected]3d9f7432013-04-06 00:35:18384}
385
[email protected]4f48f6e2013-08-27 06:33:38386void SingleThreadProxy::NotifyReadyToActivate() {
enne98f3a6c2014-10-09 20:09:44387 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate");
khushalsagarb7db1fe2015-11-12 00:51:27388 DebugScopedSetImplThread impl(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44389 if (scheduler_on_impl_thread_)
390 scheduler_on_impl_thread_->NotifyReadyToActivate();
[email protected]4f48f6e2013-08-27 06:33:38391}
392
ernstmdfac03e2014-11-11 20:18:05393void SingleThreadProxy::NotifyReadyToDraw() {
weiliangc8dac5a62015-04-02 06:12:35394 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToDraw");
khushalsagarb7db1fe2015-11-12 00:51:27395 DebugScopedSetImplThread impl(task_runner_provider_);
weiliangc8dac5a62015-04-02 06:12:35396 if (scheduler_on_impl_thread_)
397 scheduler_on_impl_thread_->NotifyReadyToDraw();
ernstmdfac03e2014-11-11 20:18:05398}
399
[email protected]c1bb5af2013-03-13 19:06:27400void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
danakj53eccbc2016-03-02 22:51:07401 client_->RequestScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22402 if (scheduler_on_impl_thread_)
403 scheduler_on_impl_thread_->SetNeedsRedraw();
[email protected]a8a049c2013-03-11 23:27:06404}
405
danakja18e826a2015-12-03 00:27:03406void SingleThreadProxy::SetNeedsOneBeginImplFrameOnImplThread() {
407 TRACE_EVENT0("cc",
408 "SingleThreadProxy::SetNeedsOneBeginImplFrameOnImplThread");
danakj53eccbc2016-03-02 22:51:07409 client_->RequestScheduleComposite();
mithro719bf6792014-11-10 15:36:47410 if (scheduler_on_impl_thread_)
danakja18e826a2015-12-03 00:27:03411 scheduler_on_impl_thread_->SetNeedsOneBeginImplFrame();
[email protected]43b8f982014-04-30 21:24:33412}
413
vmiura59ea9b4042014-12-09 20:50:39414void SingleThreadProxy::SetNeedsPrepareTilesOnImplThread() {
415 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsPrepareTilesOnImplThread");
enne98f3a6c2014-10-09 20:09:44416 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39417 scheduler_on_impl_thread_->SetNeedsPrepareTiles();
[email protected]c48536a52013-09-14 00:02:08418}
419
[email protected]0023fc72014-01-10 20:05:06420void SingleThreadProxy::SetNeedsRedrawRectOnImplThread(
421 const gfx::Rect& damage_rect) {
[email protected]1cd9f5552013-04-26 04:22:03422 layer_tree_host_impl_->SetViewportDamage(damage_rect);
[email protected]aeeedad2014-08-22 18:16:22423 SetNeedsRedrawOnImplThread();
[email protected]1cd9f5552013-04-26 04:22:03424}
425
[email protected]c1bb5af2013-03-13 19:06:27426void SingleThreadProxy::SetNeedsCommitOnImplThread() {
danakj53eccbc2016-03-02 22:51:07427 client_->RequestScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22428 if (scheduler_on_impl_thread_)
mithroe77254b32015-07-22 09:36:01429 scheduler_on_impl_thread_->SetNeedsBeginMainFrame();
[email protected]a8a049c2013-03-11 23:27:06430}
431
sunnyps7d073dc2015-04-16 23:29:12432void SingleThreadProxy::SetVideoNeedsBeginFrames(bool needs_begin_frames) {
433 TRACE_EVENT1("cc", "SingleThreadProxy::SetVideoNeedsBeginFrames",
434 "needs_begin_frames", needs_begin_frames);
435 // In tests the layer tree is destroyed after the scheduler is.
436 if (scheduler_on_impl_thread_)
437 scheduler_on_impl_thread_->SetVideoNeedsBeginFrames(needs_begin_frames);
438}
439
[email protected]c1bb5af2013-03-13 19:06:27440void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
danakj60bc3bc2016-04-09 00:24:48441 std::unique_ptr<AnimationEvents> events) {
[email protected]ccc08dc2014-01-30 07:33:20442 TRACE_EVENT0(
443 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
khushalsagarb7db1fe2015-11-12 00:51:27444 DCHECK(task_runner_provider_->IsImplThread());
445 DebugScopedSetMainThread main(task_runner_provider_);
danakja04855a2015-11-18 20:39:10446 layer_tree_host_->SetAnimationEvents(std::move(events));
[email protected]a8a049c2013-03-11 23:27:06447}
448
[email protected]c1bb5af2013-03-13 19:06:27449bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
[email protected]a8a049c2013-03-11 23:27:06450
enne98f3a6c2014-10-09 20:09:44451void SingleThreadProxy::DidActivateSyncTree() {
danakj68803fc2015-06-19 20:55:53452 // Synchronously call to CommitComplete. Resetting
453 // |commit_blocking_task_runner| would make sure all tasks posted during
454 // commit/activation before CommitComplete.
455 CommitComplete();
enne98f3a6c2014-10-09 20:09:44456}
457
brianderson68749812015-07-07 22:39:39458void SingleThreadProxy::WillPrepareTiles() {
khushalsagarb7db1fe2015-11-12 00:51:27459 DCHECK(task_runner_provider_->IsImplThread());
brianderson68749812015-07-07 22:39:39460 if (scheduler_on_impl_thread_)
461 scheduler_on_impl_thread_->WillPrepareTiles();
462}
463
vmiura59ea9b4042014-12-09 20:50:39464void SingleThreadProxy::DidPrepareTiles() {
khushalsagarb7db1fe2015-11-12 00:51:27465 DCHECK(task_runner_provider_->IsImplThread());
enne98f3a6c2014-10-09 20:09:44466 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39467 scheduler_on_impl_thread_->DidPrepareTiles();
enne98f3a6c2014-10-09 20:09:44468}
469
rouslanf7ebd8832015-01-22 01:54:14470void SingleThreadProxy::DidCompletePageScaleAnimationOnImplThread() {
471 layer_tree_host_->DidCompletePageScaleAnimation();
472}
473
[email protected]fa339032014-02-18 22:11:59474void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() {
khushalsagarb7db1fe2015-11-12 00:51:27475 DCHECK(task_runner_provider_->IsImplThread());
[email protected]fa339032014-02-18 22:11:59476 renderer_capabilities_for_main_thread_ =
477 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities();
478}
479
[email protected]c1bb5af2013-03-13 19:06:27480void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
[email protected]ccc08dc2014-01-30 07:33:20481 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22482 {
khushalsagarb7db1fe2015-11-12 00:51:27483 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22484 // This must happen before we notify the scheduler as it may try to recreate
485 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE.
486 layer_tree_host_->DidLoseOutputSurface();
487 }
[email protected]4d7e46a2013-11-08 05:33:40488 client_->DidAbortSwapBuffers();
[email protected]aeeedad2014-08-22 18:16:22489 if (scheduler_on_impl_thread_)
490 scheduler_on_impl_thread_->DidLoseOutputSurface();
[email protected]4d7e46a2013-11-08 05:33:40491}
492
weiliangcaf17af42014-12-15 22:17:02493void SingleThreadProxy::CommitVSyncParameters(base::TimeTicks timebase,
494 base::TimeDelta interval) {
enne0c2638eb2016-05-10 01:34:57495 if (interval.is_zero()) {
enneb9bf3772016-03-16 21:51:11496 // TODO(brianderson): We should not be receiving 0 intervals.
497 interval = BeginFrameArgs::DefaultInterval();
498 }
499
enneb9bf3772016-03-16 21:51:11500 if (synthetic_begin_frame_source_)
501 synthetic_begin_frame_source_->OnUpdateVSyncParameters(timebase, interval);
weiliangcaf17af42014-12-15 22:17:02502}
503
enne19c108582016-04-14 03:35:32504void SingleThreadProxy::SetBeginFrameSource(BeginFrameSource* source) {
505 DCHECK(layer_tree_host_->settings().single_thread_proxy_scheduler);
506 // TODO(enne): this overrides any preexisting begin frame source. Those
507 // other sources will eventually be removed and this will be the only path.
508 if (!layer_tree_host_->settings().use_output_surface_begin_frame_source)
509 return;
510 if (scheduler_on_impl_thread_)
511 scheduler_on_impl_thread_->SetBeginFrameSource(source);
512}
513
jbauman93a5a902015-03-13 22:16:55514void SingleThreadProxy::SetEstimatedParentDrawTime(base::TimeDelta draw_time) {
515 if (scheduler_on_impl_thread_)
516 scheduler_on_impl_thread_->SetEstimatedParentDrawTime(draw_time);
517}
518
[email protected]4d7e46a2013-11-08 05:33:40519void SingleThreadProxy::DidSwapBuffersOnImplThread() {
[email protected]aeeedad2014-08-22 18:16:22520 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersOnImplThread");
521 if (scheduler_on_impl_thread_)
522 scheduler_on_impl_thread_->DidSwapBuffers();
[email protected]4d7e46a2013-11-08 05:33:40523 client_->DidPostSwapBuffers();
524}
525
[email protected]c14902662014-04-18 05:06:11526void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() {
miletusfed8c43b2015-01-26 20:04:52527 TRACE_EVENT0("cc,benchmark",
528 "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22529 if (scheduler_on_impl_thread_)
530 scheduler_on_impl_thread_->DidSwapBuffersComplete();
531 layer_tree_host_->DidCompleteSwapBuffers();
[email protected]493067512012-09-19 23:34:10532}
533
boliu7097ee5b2015-12-17 03:16:09534void SingleThreadProxy::OnDrawForOutputSurface(
535 bool resourceless_software_draw) {
sunnypseab5ac92015-04-02 20:26:13536 NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor.";
537}
538
[email protected]f0c2a242013-03-15 19:34:52539void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
miletusfed8c43b2015-01-26 20:04:52540 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately");
khushalsagarb7db1fe2015-11-12 00:51:27541 DCHECK(task_runner_provider_->IsMainThread());
mithro51693e382015-05-07 23:52:41542#if DCHECK_IS_ON()
mithroc76d70312015-05-04 23:51:13543 DCHECK(!inside_impl_frame_);
mithro51693e382015-05-07 23:52:41544#endif
jbauman399aec1a2014-10-25 02:33:32545 base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true);
546
547 if (layer_tree_host_->output_surface_lost()) {
548 RequestNewOutputSurface();
549 // RequestNewOutputSurface could have synchronously created an output
550 // surface, so check again before returning.
551 if (layer_tree_host_->output_surface_lost())
552 return;
553 }
[email protected]51f81da2014-05-16 21:29:26554
mithroc76d70312015-05-04 23:51:13555 BeginFrameArgs begin_frame_args(BeginFrameArgs::Create(
556 BEGINFRAME_FROM_HERE, frame_begin_time, base::TimeTicks(),
557 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL));
558
559 // Start the impl frame.
enne98f3a6c2014-10-09 20:09:44560 {
khushalsagarb7db1fe2015-11-12 00:51:27561 DebugScopedSetImplThread impl(task_runner_provider_);
mithroc76d70312015-05-04 23:51:13562 WillBeginImplFrame(begin_frame_args);
563 }
564
565 // Run the "main thread" and get it to commit.
566 {
mithro51693e382015-05-07 23:52:41567#if DCHECK_IS_ON()
mithroc76d70312015-05-04 23:51:13568 DCHECK(inside_impl_frame_);
mithro51693e382015-05-07 23:52:41569#endif
enne98f3a6c2014-10-09 20:09:44570 DoBeginMainFrame(begin_frame_args);
571 DoCommit();
[email protected]e0341352013-04-06 05:01:20572
enne98f3a6c2014-10-09 20:09:44573 DCHECK_EQ(0u, layer_tree_host_->num_queued_swap_promises())
574 << "Commit should always succeed and transfer promises.";
575 }
576
mithroc76d70312015-05-04 23:51:13577 // Finish the impl frame.
enne98f3a6c2014-10-09 20:09:44578 {
khushalsagarb7db1fe2015-11-12 00:51:27579 DebugScopedSetImplThread impl(task_runner_provider_);
danakj68803fc2015-06-19 20:55:53580 layer_tree_host_impl_->ActivateSyncTree();
581 DCHECK(
582 !layer_tree_host_impl_->active_tree()->needs_update_draw_properties());
583 layer_tree_host_impl_->PrepareTiles();
584 layer_tree_host_impl_->SynchronouslyInitializeAllTiles();
enne69277cb2014-10-29 23:03:40585
danakj12e2f6e2015-08-19 22:25:44586 // TODO(danakj): Don't do this last... we prepared the wrong things. D:
587 layer_tree_host_impl_->Animate();
mithro719bf6792014-11-10 15:36:47588
enne98f3a6c2014-10-09 20:09:44589 LayerTreeHostImpl::FrameData frame;
mithro248d1722015-05-05 05:23:45590 DoComposite(&frame);
enne98f3a6c2014-10-09 20:09:44591
592 // DoComposite could abort, but because this is a synchronous composite
593 // another draw will never be scheduled, so break remaining promises.
594 layer_tree_host_impl_->active_tree()->BreakSwapPromises(
595 SwapPromise::SWAP_FAILS);
mithroc76d70312015-05-04 23:51:13596
mithro51693e382015-05-07 23:52:41597 DidFinishImplFrame();
enne98f3a6c2014-10-09 20:09:44598 }
[email protected]74d9063c2013-01-18 03:14:47599}
600
[email protected]5d8bec72014-07-03 03:03:11601bool SingleThreadProxy::SupportsImplScrolling() const {
602 return false;
603}
604
[email protected]3d9f7432013-04-06 00:35:18605bool SingleThreadProxy::ShouldComposite() const {
khushalsagarb7db1fe2015-11-12 00:51:27606 DCHECK(task_runner_provider_->IsImplThread());
[email protected]3d9f7432013-04-06 00:35:18607 return layer_tree_host_impl_->visible() &&
608 layer_tree_host_impl_->CanDraw();
609}
610
jbauman8ab0f9e2014-10-15 02:30:34611void SingleThreadProxy::ScheduleRequestNewOutputSurface() {
612 if (output_surface_creation_callback_.IsCancelled() &&
613 !output_surface_creation_requested_) {
614 output_surface_creation_callback_.Reset(
615 base::Bind(&SingleThreadProxy::RequestNewOutputSurface,
616 weak_factory_.GetWeakPtr()));
khushalsagarb7db1fe2015-11-12 00:51:27617 task_runner_provider_->MainThreadTaskRunner()->PostTask(
jbauman8ab0f9e2014-10-15 02:30:34618 FROM_HERE, output_surface_creation_callback_.callback());
619 }
620}
621
mithro248d1722015-05-05 05:23:45622DrawResult SingleThreadProxy::DoComposite(LayerTreeHostImpl::FrameData* frame) {
[email protected]ccc08dc2014-01-30 07:33:20623 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite");
[email protected]04049fc2013-05-01 03:13:20624 DCHECK(!layer_tree_host_->output_surface_lost());
625
enne98f3a6c2014-10-09 20:09:44626 DrawResult draw_result;
627 bool draw_frame;
[email protected]a8a049c2013-03-11 23:27:06628 {
khushalsagarb7db1fe2015-11-12 00:51:27629 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06630 base::AutoReset<bool> mark_inside(&inside_draw_, true);
631
robliao27728e62015-03-21 07:39:34632 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
633 // is fixed.
634 tracked_objects::ScopedTracker tracking_profile1(
635 FROM_HERE_WITH_EXPLICIT_FUNCTION(
636 "461509 SingleThreadProxy::DoComposite1"));
637
[email protected]3d9f7432013-04-06 00:35:18638 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
639 // frame, so can only be used when such a frame is possible. Since
640 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
641 // CanDraw() as well.
[email protected]2aae96792014-05-15 23:10:50642 if (!ShouldComposite()) {
[email protected]aeeedad2014-08-22 18:16:22643 return DRAW_ABORTED_CANT_DRAW;
[email protected]3d9f7432013-04-06 00:35:18644 }
[email protected]a8a049c2013-03-11 23:27:06645
robliao27728e62015-03-21 07:39:34646 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
647 // is fixed.
648 tracked_objects::ScopedTracker tracking_profile2(
649 FROM_HERE_WITH_EXPLICIT_FUNCTION(
650 "461509 SingleThreadProxy::DoComposite2"));
enne98f3a6c2014-10-09 20:09:44651 draw_result = layer_tree_host_impl_->PrepareToDraw(frame);
652 draw_frame = draw_result == DRAW_SUCCESS;
robliao27728e62015-03-21 07:39:34653 if (draw_frame) {
654 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
655 // is fixed.
656 tracked_objects::ScopedTracker tracking_profile3(
657 FROM_HERE_WITH_EXPLICIT_FUNCTION(
658 "461509 SingleThreadProxy::DoComposite3"));
mithro248d1722015-05-05 05:23:45659 layer_tree_host_impl_->DrawLayers(frame);
robliao27728e62015-03-21 07:39:34660 }
661 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
662 // is fixed.
663 tracked_objects::ScopedTracker tracking_profile4(
664 FROM_HERE_WITH_EXPLICIT_FUNCTION(
665 "461509 SingleThreadProxy::DoComposite4"));
dnetob71e30c2014-08-25 23:27:20666 layer_tree_host_impl_->DidDrawAllLayers(*frame);
[email protected]a8a049c2013-03-11 23:27:06667
enne98f3a6c2014-10-09 20:09:44668 bool start_ready_animations = draw_frame;
robliao27728e62015-03-21 07:39:34669 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
670 // is fixed.
671 tracked_objects::ScopedTracker tracking_profile5(
672 FROM_HERE_WITH_EXPLICIT_FUNCTION(
673 "461509 SingleThreadProxy::DoComposite5"));
[email protected]3d9f7432013-04-06 00:35:18674 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
[email protected]aeeedad2014-08-22 18:16:22675
robliao27728e62015-03-21 07:39:34676 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
677 // is fixed.
678 tracked_objects::ScopedTracker tracking_profile7(
679 FROM_HERE_WITH_EXPLICIT_FUNCTION(
680 "461509 SingleThreadProxy::DoComposite7"));
[email protected]a8a049c2013-03-11 23:27:06681 }
682
enne98f3a6c2014-10-09 20:09:44683 if (draw_frame) {
khushalsagarb7db1fe2015-11-12 00:51:27684 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]174c6d42014-08-12 01:43:06685
dnetob71e30c2014-08-25 23:27:20686 // This CapturePostTasks should be destroyed before
687 // DidCommitAndDrawFrame() is called since that goes out to the
688 // embedder,
689 // and we want the embedder to receive its callbacks before that.
690 // NOTE: This maintains consistent ordering with the ThreadProxy since
691 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
692 // there as the main thread is not blocked, so any posted tasks inside
693 // the swap buffers will execute first.
khushalsagarb7db1fe2015-11-12 00:51:27694 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22695
skyostil3976a3f2014-09-04 22:07:23696 BlockingTaskRunner::CapturePostTasks blocked(
khushalsagarb7db1fe2015-11-12 00:51:27697 task_runner_provider_->blocking_main_thread_task_runner());
robliao27728e62015-03-21 07:39:34698 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
699 // is fixed.
700 tracked_objects::ScopedTracker tracking_profile8(
701 FROM_HERE_WITH_EXPLICIT_FUNCTION(
702 "461509 SingleThreadProxy::DoComposite8"));
dnetob71e30c2014-08-25 23:27:20703 layer_tree_host_impl_->SwapBuffers(*frame);
[email protected]aeeedad2014-08-22 18:16:22704 }
robliao27728e62015-03-21 07:39:34705 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 is
706 // fixed.
707 tracked_objects::ScopedTracker tracking_profile9(
708 FROM_HERE_WITH_EXPLICIT_FUNCTION(
709 "461509 SingleThreadProxy::DoComposite9"));
[email protected]aeeedad2014-08-22 18:16:22710 DidCommitAndDrawFrame();
711
enne98f3a6c2014-10-09 20:09:44712 return draw_result;
[email protected]a8a049c2013-03-11 23:27:06713}
714
[email protected]aeeedad2014-08-22 18:16:22715void SingleThreadProxy::DidCommitAndDrawFrame() {
[email protected]a8a049c2013-03-11 23:27:06716 if (next_frame_is_newly_committed_frame_) {
khushalsagarb7db1fe2015-11-12 00:51:27717 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]a8a049c2013-03-11 23:27:06718 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21719 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06720 }
721}
722
[email protected]4ea293f72014-08-13 03:03:17723bool SingleThreadProxy::MainFrameWillHappenForTesting() {
danakjfcdaba122015-04-24 21:41:52724 if (layer_tree_host_->output_surface_lost())
725 return false;
726 if (!scheduler_on_impl_thread_)
727 return false;
728 return scheduler_on_impl_thread_->MainFrameForTestingWillHappen();
[email protected]4ea293f72014-08-13 03:03:17729}
[email protected]a8a049c2013-03-11 23:27:06730
[email protected]aeeedad2014-08-22 18:16:22731void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) {
danakja18e826a2015-12-03 00:27:03732 DebugScopedSetImplThread impl(task_runner_provider_);
mithro51693e382015-05-07 23:52:41733#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02734 DCHECK(!inside_impl_frame_)
735 << "WillBeginImplFrame called while already inside an impl frame!";
736 inside_impl_frame_ = true;
mithro51693e382015-05-07 23:52:41737#endif
[email protected]aeeedad2014-08-22 18:16:22738 layer_tree_host_impl_->WillBeginImplFrame(args);
739}
740
brianderson266dc3a2015-11-12 03:16:40741void SingleThreadProxy::ScheduledActionSendBeginMainFrame(
742 const BeginFrameArgs& begin_frame_args) {
[email protected]aeeedad2014-08-22 18:16:22743 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame");
744 // Although this proxy is single-threaded, it's problematic to synchronously
745 // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This
746 // could cause a commit to occur in between a series of SetNeedsCommit calls
747 // (i.e. property modifications) causing some to fall on one frame and some to
748 // fall on the next. Doing it asynchronously instead matches the semantics of
749 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a
750 // synchronous commit.
mithro51693e382015-05-07 23:52:41751#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02752 DCHECK(inside_impl_frame_)
753 << "BeginMainFrame should only be sent inside a BeginImplFrame";
mithro51693e382015-05-07 23:52:41754#endif
mithro69fd3bb52015-05-01 03:45:02755
khushalsagarb7db1fe2015-11-12 00:51:27756 task_runner_provider_->MainThreadTaskRunner()->PostTask(
mithro69fd3bb52015-05-01 03:45:02757 FROM_HERE, base::Bind(&SingleThreadProxy::BeginMainFrame,
758 weak_factory_.GetWeakPtr(), begin_frame_args));
[email protected]aeeedad2014-08-22 18:16:22759}
760
rmcilroy0a19362a2015-02-18 12:34:25761void SingleThreadProxy::SendBeginMainFrameNotExpectedSoon() {
762 layer_tree_host_->BeginMainFrameNotExpectedSoon();
763}
764
mithro69fd3bb52015-05-01 03:45:02765void SingleThreadProxy::BeginMainFrame(const BeginFrameArgs& begin_frame_args) {
brianderson21aef162015-11-11 05:12:23766 if (scheduler_on_impl_thread_) {
767 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(
768 base::TimeTicks::Now());
769 }
770
danakjfcdaba122015-04-24 21:41:52771 commit_requested_ = false;
brianderson49e101d22015-04-29 00:05:33772 animate_requested_ = false;
danakjfcdaba122015-04-24 21:41:52773
[email protected]aeeedad2014-08-22 18:16:22774 if (defer_commits_) {
simonhongc6309f792015-01-31 15:47:15775 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit",
776 TRACE_EVENT_SCOPE_THREAD);
777 BeginMainFrameAbortedOnImplThread(
778 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT);
[email protected]aeeedad2014-08-22 18:16:22779 return;
780 }
781
enne98f3a6c2014-10-09 20:09:44782 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous
783 // commit.
[email protected]aeeedad2014-08-22 18:16:22784 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_);
785
786 if (!layer_tree_host_->visible()) {
787 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD);
mithrof7a21502014-12-17 03:24:48788 BeginMainFrameAbortedOnImplThread(
789 CommitEarlyOutReason::ABORTED_NOT_VISIBLE);
[email protected]aeeedad2014-08-22 18:16:22790 return;
791 }
792
793 if (layer_tree_host_->output_surface_lost()) {
794 TRACE_EVENT_INSTANT0(
795 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD);
mithrof7a21502014-12-17 03:24:48796 BeginMainFrameAbortedOnImplThread(
797 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST);
[email protected]aeeedad2014-08-22 18:16:22798 return;
799 }
800
danakjfcdaba122015-04-24 21:41:52801 // Prevent new commits from being requested inside DoBeginMainFrame.
brianderson49e101d22015-04-29 00:05:33802 // Note: We do not want to prevent SetNeedsAnimate from requesting
803 // a commit here.
danakjfcdaba122015-04-24 21:41:52804 commit_requested_ = true;
805
enne98f3a6c2014-10-09 20:09:44806 DoBeginMainFrame(begin_frame_args);
807}
808
809void SingleThreadProxy::DoBeginMainFrame(
810 const BeginFrameArgs& begin_frame_args) {
811 layer_tree_host_->WillBeginMainFrame();
812 layer_tree_host_->BeginMainFrame(begin_frame_args);
813 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time);
wkorman7265db012015-11-03 04:08:25814 layer_tree_host_->RequestMainFrameUpdate();
enne98f3a6c2014-10-09 20:09:44815
danakjfcdaba122015-04-24 21:41:52816 // New commits requested inside UpdateLayers should be respected.
817 commit_requested_ = false;
818
danakj5f46636a2015-06-19 00:01:40819 layer_tree_host_->UpdateLayers();
enne98f3a6c2014-10-09 20:09:44820
mithrof7a21502014-12-17 03:24:48821 // TODO(enne): SingleThreadProxy does not support cancelling commits yet,
822 // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside
823 // thread_proxy.cc
brianderson21aef162015-11-11 05:12:23824 if (scheduler_on_impl_thread_)
enne98f3a6c2014-10-09 20:09:44825 scheduler_on_impl_thread_->NotifyReadyToCommit();
[email protected]aeeedad2014-08-22 18:16:22826}
827
mithrof7a21502014-12-17 03:24:48828void SingleThreadProxy::BeginMainFrameAbortedOnImplThread(
829 CommitEarlyOutReason reason) {
khushalsagarb7db1fe2015-11-12 00:51:27830 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22831 DCHECK(scheduler_on_impl_thread_->CommitPending());
832 DCHECK(!layer_tree_host_impl_->pending_tree());
833
mithrof7a21502014-12-17 03:24:48834 layer_tree_host_impl_->BeginMainFrameAborted(reason);
835 scheduler_on_impl_thread_->BeginMainFrameAborted(reason);
[email protected]aeeedad2014-08-22 18:16:22836}
837
838DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
khushalsagarb7db1fe2015-11-12 00:51:27839 DebugScopedSetImplThread impl(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22840 LayerTreeHostImpl::FrameData frame;
mithro248d1722015-05-05 05:23:45841 return DoComposite(&frame);
[email protected]aeeedad2014-08-22 18:16:22842}
843
844DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() {
845 NOTREACHED();
846 return INVALID_RESULT;
847}
848
849void SingleThreadProxy::ScheduledActionCommit() {
khushalsagarb7db1fe2015-11-12 00:51:27850 DebugScopedSetMainThread main(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44851 DoCommit();
[email protected]aeeedad2014-08-22 18:16:22852}
853
[email protected]aeeedad2014-08-22 18:16:22854void SingleThreadProxy::ScheduledActionActivateSyncTree() {
khushalsagarb7db1fe2015-11-12 00:51:27855 DebugScopedSetImplThread impl(task_runner_provider_);
enne98f3a6c2014-10-09 20:09:44856 layer_tree_host_impl_->ActivateSyncTree();
[email protected]aeeedad2014-08-22 18:16:22857}
858
859void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
khushalsagarb7db1fe2015-11-12 00:51:27860 DebugScopedSetMainThread main(task_runner_provider_);
[email protected]aeeedad2014-08-22 18:16:22861 DCHECK(scheduler_on_impl_thread_);
862 // If possible, create the output surface in a post task. Synchronously
863 // creating the output surface makes tests more awkward since this differs
864 // from the ThreadProxy behavior. However, sometimes there is no
865 // task runner.
khushalsagarb7db1fe2015-11-12 00:51:27866 if (task_runner_provider_->MainThreadTaskRunner()) {
jbauman8ab0f9e2014-10-15 02:30:34867 ScheduleRequestNewOutputSurface();
[email protected]aeeedad2014-08-22 18:16:22868 } else {
enne2097cab2014-09-25 20:16:31869 RequestNewOutputSurface();
[email protected]aeeedad2014-08-22 18:16:22870 }
871}
872
vmiura59ea9b4042014-12-09 20:50:39873void SingleThreadProxy::ScheduledActionPrepareTiles() {
874 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionPrepareTiles");
khushalsagarb7db1fe2015-11-12 00:51:27875 DebugScopedSetImplThread impl(task_runner_provider_);
vmiura59ea9b4042014-12-09 20:50:39876 layer_tree_host_impl_->PrepareTiles();
[email protected]aeeedad2014-08-22 18:16:22877}
878
sunnypseab5ac92015-04-02 20:26:13879void SingleThreadProxy::ScheduledActionInvalidateOutputSurface() {
880 NOTREACHED();
881}
882
khushalsagarc646cd62015-10-17 00:05:48883void SingleThreadProxy::UpdateTopControlsState(TopControlsState constraints,
884 TopControlsState current,
885 bool animate) {
886 NOTREACHED() << "Top Controls are used only in threaded mode";
887}
888
mithro51693e382015-05-07 23:52:41889void SingleThreadProxy::DidFinishImplFrame() {
890 layer_tree_host_impl_->DidFinishImplFrame();
891#if DCHECK_IS_ON()
mithro69fd3bb52015-05-01 03:45:02892 DCHECK(inside_impl_frame_)
mithro51693e382015-05-07 23:52:41893 << "DidFinishImplFrame called while not inside an impl frame!";
mithro69fd3bb52015-05-01 03:45:02894 inside_impl_frame_ = false;
mithro51693e382015-05-07 23:52:41895#endif
[email protected]aeeedad2014-08-22 18:16:22896}
897
[email protected]bc5e77c2012-11-05 20:00:49898} // namespace cc