blob: c8eb6b0fad6b33dc9811cb2169a976d8b519ab8e [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"
primianoc06e2382015-01-28 04:21:498#include "base/trace_event/trace_event.h"
[email protected]adbe30f2013-10-11 21:12:339#include "cc/debug/benchmark_instrumentation.h"
[email protected]7f0d825f2013-03-18 07:24:3010#include "cc/output/context_provider.h"
11#include "cc/output/output_surface.h"
[email protected]89e82672013-03-18 07:50:5612#include "cc/quads/draw_quad.h"
[email protected]e12dd0e2013-03-18 08:24:4013#include "cc/resources/prioritized_resource_manager.h"
14#include "cc/resources/resource_update_controller.h"
mithrof7a21502014-12-17 03:24:4815#include "cc/scheduler/commit_earlyout_reason.h"
[email protected]556fd292013-03-18 08:03:0416#include "cc/trees/layer_tree_host.h"
[email protected]943528e2013-11-07 05:01:3217#include "cc/trees/layer_tree_host_single_thread_client.h"
[email protected]556fd292013-03-18 08:03:0418#include "cc/trees/layer_tree_impl.h"
[email protected]aeeedad2014-08-22 18:16:2219#include "cc/trees/scoped_abort_remaining_swap_promises.h"
[email protected]de2cf8c2013-10-25 19:46:4620#include "ui/gfx/frame_time.h"
[email protected]94f206c12012-08-25 00:09:1421
[email protected]9c88e562012-09-14 22:21:3022namespace cc {
[email protected]94f206c12012-08-25 00:09:1423
[email protected]943528e2013-11-07 05:01:3224scoped_ptr<Proxy> SingleThreadProxy::Create(
25 LayerTreeHost* layer_tree_host,
[email protected]27e6a212014-07-18 15:51:2726 LayerTreeHostSingleThreadClient* client,
simonhonga7e3ac42014-11-11 20:50:2227 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
28 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
29 return make_scoped_ptr(new SingleThreadProxy(
30 layer_tree_host,
31 client,
32 main_task_runner,
33 external_begin_frame_source.Pass()));
[email protected]94f206c12012-08-25 00:09:1434}
35
[email protected]27e6a212014-07-18 15:51:2736SingleThreadProxy::SingleThreadProxy(
37 LayerTreeHost* layer_tree_host,
38 LayerTreeHostSingleThreadClient* client,
simonhonga7e3ac42014-11-11 20:50:2239 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
40 scoped_ptr<BeginFrameSource> external_begin_frame_source)
[email protected]27e6a212014-07-18 15:51:2741 : Proxy(main_task_runner, NULL),
[email protected]a8a049c2013-03-11 23:27:0642 layer_tree_host_(layer_tree_host),
[email protected]943528e2013-11-07 05:01:3243 client_(client),
[email protected]aeeedad2014-08-22 18:16:2244 timing_history_(layer_tree_host->rendering_stats_instrumentation()),
[email protected]a8a049c2013-03-11 23:27:0645 next_frame_is_newly_committed_frame_(false),
[email protected]aeeedad2014-08-22 18:16:2246 inside_draw_(false),
47 defer_commits_(false),
48 commit_was_deferred_(false),
49 commit_requested_(false),
jbauman399aec1a2014-10-25 02:33:3250 inside_synchronous_composite_(false),
jbauman8ab0f9e2014-10-15 02:30:3451 output_surface_creation_requested_(false),
simonhonga7e3ac42014-11-11 20:50:2252 external_begin_frame_source_(external_begin_frame_source.Pass()),
[email protected]aeeedad2014-08-22 18:16:2253 weak_factory_(this) {
[email protected]a8a049c2013-03-11 23:27:0654 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
55 DCHECK(Proxy::IsMainThread());
56 DCHECK(layer_tree_host);
[email protected]94f206c12012-08-25 00:09:1457}
58
[email protected]e96e3432013-12-19 18:56:0759void SingleThreadProxy::Start() {
[email protected]a8a049c2013-03-11 23:27:0660 DebugScopedSetImplThread impl(this);
[email protected]804c8982013-03-13 16:32:2161 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
[email protected]a8a049c2013-03-11 23:27:0662}
63
64SingleThreadProxy::~SingleThreadProxy() {
65 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy");
66 DCHECK(Proxy::IsMainThread());
[email protected]04049fc2013-05-01 03:13:2067 // Make sure Stop() got called or never Started.
68 DCHECK(!layer_tree_host_impl_);
[email protected]a8a049c2013-03-11 23:27:0669}
70
[email protected]a8a049c2013-03-11 23:27:0671void SingleThreadProxy::FinishAllRendering() {
[email protected]ccc08dc2014-01-30 07:33:2072 TRACE_EVENT0("cc", "SingleThreadProxy::FinishAllRendering");
[email protected]a8a049c2013-03-11 23:27:0673 DCHECK(Proxy::IsMainThread());
74 {
[email protected]61de5812012-11-08 07:03:4475 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:2776 layer_tree_host_impl_->FinishAllRendering();
[email protected]a8a049c2013-03-11 23:27:0677 }
[email protected]94f206c12012-08-25 00:09:1478}
79
[email protected]a8a049c2013-03-11 23:27:0680bool SingleThreadProxy::IsStarted() const {
81 DCHECK(Proxy::IsMainThread());
[email protected]3209161d2013-03-29 19:17:3482 return layer_tree_host_impl_;
[email protected]94f206c12012-08-25 00:09:1483}
84
[email protected]14bd5542013-05-08 21:51:3085void SingleThreadProxy::SetLayerTreeHostClientReady() {
[email protected]ccc08dc2014-01-30 07:33:2086 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady");
[email protected]a8a049c2013-03-11 23:27:0687 // Scheduling is controlled by the embedder in the single thread case, so
88 // nothing to do.
[email protected]aeeedad2014-08-22 18:16:2289 DCHECK(Proxy::IsMainThread());
90 DebugScopedSetImplThread impl(this);
91 if (layer_tree_host_->settings().single_thread_proxy_scheduler &&
92 !scheduler_on_impl_thread_) {
93 SchedulerSettings scheduler_settings(layer_tree_host_->settings());
weiliangc5efa0a12015-01-29 19:56:4694 // SingleThreadProxy should run in main thread low latency mode.
weiliangc57b14e4a2014-12-04 22:59:0995 scheduler_settings.main_thread_should_always_be_low_latency = true;
simonhonga7e3ac42014-11-11 20:50:2296 scheduler_on_impl_thread_ =
97 Scheduler::Create(this,
98 scheduler_settings,
99 layer_tree_host_->id(),
100 MainThreadTaskRunner(),
101 base::PowerMonitor::Get(),
102 external_begin_frame_source_.Pass());
[email protected]aeeedad2014-08-22 18:16:22103 scheduler_on_impl_thread_->SetCanStart();
104 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
105 }
[email protected]a8a049c2013-03-11 23:27:06106}
107
108void SingleThreadProxy::SetVisible(bool visible) {
mithro46adf5a2014-11-19 14:52:40109 TRACE_EVENT1("cc", "SingleThreadProxy::SetVisible", "visible", visible);
[email protected]f7c01c82013-07-02 22:58:46110 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:27111 layer_tree_host_impl_->SetVisible(visible);
[email protected]aeeedad2014-08-22 18:16:22112 if (scheduler_on_impl_thread_)
113 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
[email protected]8ea875b2013-08-07 00:32:12114 // Changing visibility could change ShouldComposite().
[email protected]a8a049c2013-03-11 23:27:06115}
116
bajones274110612015-01-06 20:53:59117void SingleThreadProxy::SetThrottleFrameProduction(bool throttle) {
118 TRACE_EVENT1("cc", "SingleThreadProxy::SetThrottleFrameProduction",
119 "throttle", throttle);
120 DebugScopedSetImplThread impl(this);
121 if (scheduler_on_impl_thread_)
122 scheduler_on_impl_thread_->SetThrottleFrameProduction(throttle);
123}
124
enne2097cab2014-09-25 20:16:31125void SingleThreadProxy::RequestNewOutputSurface() {
[email protected]a8a049c2013-03-11 23:27:06126 DCHECK(Proxy::IsMainThread());
[email protected]497edf82014-05-20 21:53:15127 DCHECK(layer_tree_host_->output_surface_lost());
jbauman8ab0f9e2014-10-15 02:30:34128 output_surface_creation_callback_.Cancel();
129 if (output_surface_creation_requested_)
130 return;
131 output_surface_creation_requested_ = true;
enne2097cab2014-09-25 20:16:31132 layer_tree_host_->RequestNewOutputSurface();
133}
[email protected]94f206c12012-08-25 00:09:14134
enne2097cab2014-09-25 20:16:31135void SingleThreadProxy::SetOutputSurface(
136 scoped_ptr<OutputSurface> output_surface) {
137 DCHECK(Proxy::IsMainThread());
138 DCHECK(layer_tree_host_->output_surface_lost());
enne5232fbb2015-01-27 21:22:41139 DCHECK(output_surface_creation_requested_);
[email protected]da8e3b72b2014-04-25 02:33:45140 renderer_capabilities_for_main_thread_ = RendererCapabilities();
141
enne7f8fdde2014-12-10 21:32:09142 bool success;
143 {
[email protected]819b9f52013-09-22 23:29:51144 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
[email protected]a8a049c2013-03-11 23:27:06145 DebugScopedSetImplThread impl(this);
[email protected]804c8982013-03-13 16:32:21146 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27147 layer_tree_host_impl_->resource_provider());
[email protected]da8e3b72b2014-04-25 02:33:45148 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass());
[email protected]04049fc2013-05-01 03:13:20149 }
150
[email protected]aeeedad2014-08-22 18:16:22151 if (success) {
enne7f8fdde2014-12-10 21:32:09152 layer_tree_host_->DidInitializeOutputSurface();
[email protected]aeeedad2014-08-22 18:16:22153 if (scheduler_on_impl_thread_)
154 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface();
jbauman399aec1a2014-10-25 02:33:32155 else if (!inside_synchronous_composite_)
156 SetNeedsCommit();
enne5232fbb2015-01-27 21:22:41157 output_surface_creation_requested_ = false;
enne7f8fdde2014-12-10 21:32:09158 } else {
enne5232fbb2015-01-27 21:22:41159 // DidFailToInitializeOutputSurface is treated as a RequestNewOutputSurface,
160 // and so output_surface_creation_requested remains true.
enne7f8fdde2014-12-10 21:32:09161 layer_tree_host_->DidFailToInitializeOutputSurface();
[email protected]04049fc2013-05-01 03:13:20162 }
[email protected]94f206c12012-08-25 00:09:14163}
164
[email protected]a8a049c2013-03-11 23:27:06165const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const {
[email protected]04049fc2013-05-01 03:13:20166 DCHECK(Proxy::IsMainThread());
167 DCHECK(!layer_tree_host_->output_surface_lost());
[email protected]a8a049c2013-03-11 23:27:06168 return renderer_capabilities_for_main_thread_;
[email protected]94f206c12012-08-25 00:09:14169}
170
[email protected]8b9e52b2014-01-17 16:35:31171void SingleThreadProxy::SetNeedsAnimate() {
[email protected]ccc08dc2014-01-30 07:33:20172 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate");
[email protected]c5134172013-12-11 06:19:48173 DCHECK(Proxy::IsMainThread());
[email protected]06cbc31b2014-01-17 06:43:20174 client_->ScheduleAnimation();
[email protected]aeeedad2014-08-22 18:16:22175 SetNeedsCommit();
[email protected]c5134172013-12-11 06:19:48176}
177
[email protected]8b9e52b2014-01-17 16:35:31178void SingleThreadProxy::SetNeedsUpdateLayers() {
[email protected]ccc08dc2014-01-30 07:33:20179 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers");
[email protected]8b9e52b2014-01-17 16:35:31180 DCHECK(Proxy::IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22181 SetNeedsCommit();
[email protected]8b9e52b2014-01-17 16:35:31182}
183
mithro719bf6792014-11-10 15:36:47184void SingleThreadProxy::DoAnimate() {
185 // Don't animate if there is no root layer.
186 // TODO(mithro): Both Animate and UpdateAnimationState already have a
187 // "!active_tree_->root_layer()" check?
188 if (!layer_tree_host_impl_->active_tree()->root_layer()) {
189 return;
190 }
191
192 layer_tree_host_impl_->Animate(
193 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time);
194
195 // If animations are not visible, update the animation state now as it
196 // won't happen in DoComposite.
197 if (!layer_tree_host_impl_->AnimationsAreVisible()) {
198 layer_tree_host_impl_->UpdateAnimationState(true);
199 }
200}
201
enne98f3a6c2014-10-09 20:09:44202void SingleThreadProxy::DoCommit() {
[email protected]ccc08dc2014-01-30 07:33:20203 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit");
[email protected]a8a049c2013-03-11 23:27:06204 DCHECK(Proxy::IsMainThread());
enne98f3a6c2014-10-09 20:09:44205
[email protected]aeeedad2014-08-22 18:16:22206 commit_requested_ = false;
[email protected]aeeedad2014-08-22 18:16:22207 layer_tree_host_->WillCommit();
208
[email protected]a8a049c2013-03-11 23:27:06209 // Commit immediately.
210 {
[email protected]819b9f52013-09-22 23:29:51211 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
[email protected]f7c01c82013-07-02 22:58:46212 DebugScopedSetImplThread impl(this);
213
[email protected]9794fb32013-08-29 09:49:59214 // This CapturePostTasks should be destroyed before CommitComplete() is
215 // called since that goes out to the embedder, and we want the embedder
216 // to receive its callbacks before that.
enne98f3a6c2014-10-09 20:09:44217 commit_blocking_task_runner_.reset(new BlockingTaskRunner::CapturePostTasks(
218 blocking_main_thread_task_runner()));
[email protected]9794fb32013-08-29 09:49:59219
[email protected]c1bb5af2013-03-13 19:06:27220 layer_tree_host_impl_->BeginCommit();
[email protected]94f206c12012-08-25 00:09:14221
[email protected]5d2fec02013-11-28 20:08:33222 if (PrioritizedResourceManager* contents_texture_manager =
223 layer_tree_host_->contents_texture_manager()) {
224 contents_texture_manager->PushTexturePrioritiesToBackings();
[email protected]6e8c54922013-06-02 19:17:35225 }
[email protected]804c8982013-03-13 16:32:21226 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14227
[email protected]ed511b8d2013-03-25 03:29:29228 scoped_ptr<ResourceUpdateController> update_controller =
[email protected]a8a049c2013-03-11 23:27:06229 ResourceUpdateController::Create(
230 NULL,
[email protected]aeeedad2014-08-22 18:16:22231 MainThreadTaskRunner(),
enne98f3a6c2014-10-09 20:09:44232 queue_for_commit_.Pass(),
[email protected]c1bb5af2013-03-13 19:06:27233 layer_tree_host_impl_->resource_provider());
[email protected]ed511b8d2013-03-25 03:29:29234 update_controller->Finalize();
[email protected]94f206c12012-08-25 00:09:14235
[email protected]127bdc1a2013-09-11 01:44:48236 if (layer_tree_host_impl_->EvictedUIResourcesExist())
237 layer_tree_host_->RecreateUIResources();
238
[email protected]804c8982013-03-13 16:32:21239 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14240
[email protected]c1bb5af2013-03-13 19:06:27241 layer_tree_host_impl_->CommitComplete();
[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
[email protected]a8a049c2013-03-11 23:27:06251 }
enne98f3a6c2014-10-09 20:09:44252
253 if (layer_tree_host_->settings().impl_side_painting) {
254 // TODO(enne): just commit directly to the active tree.
255 //
256 // Synchronously activate during commit to satisfy any potential
257 // SetNextCommitWaitsForActivation calls. Unfortunately, the tree
258 // might not be ready to draw, so DidActivateSyncTree must set
259 // the flag to force the tree to not draw until textures are ready.
260 NotifyReadyToActivate();
261 } else {
262 CommitComplete();
263 }
264}
265
266void SingleThreadProxy::CommitComplete() {
267 DCHECK(!layer_tree_host_impl_->pending_tree())
268 << "Activation is expected to have synchronously occurred by now.";
269 DCHECK(commit_blocking_task_runner_);
270
271 DebugScopedSetMainThread main(this);
272 commit_blocking_task_runner_.reset();
[email protected]804c8982013-03-13 16:32:21273 layer_tree_host_->CommitComplete();
[email protected]aeeedad2014-08-22 18:16:22274 layer_tree_host_->DidBeginMainFrame();
275 timing_history_.DidCommit();
276
[email protected]a8a049c2013-03-11 23:27:06277 next_frame_is_newly_committed_frame_ = true;
[email protected]94f206c12012-08-25 00:09:14278}
279
[email protected]a8a049c2013-03-11 23:27:06280void SingleThreadProxy::SetNeedsCommit() {
281 DCHECK(Proxy::IsMainThread());
[email protected]aeeedad2014-08-22 18:16:22282 DebugScopedSetImplThread impl(this);
[email protected]943528e2013-11-07 05:01:32283 client_->ScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22284 if (scheduler_on_impl_thread_)
285 scheduler_on_impl_thread_->SetNeedsCommit();
286 commit_requested_ = true;
[email protected]94f206c12012-08-25 00:09:14287}
288
[email protected]0023fc72014-01-10 20:05:06289void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) {
[email protected]ccc08dc2014-01-30 07:33:20290 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw");
[email protected]aeeedad2014-08-22 18:16:22291 DCHECK(Proxy::IsMainThread());
292 DebugScopedSetImplThread impl(this);
[email protected]2decdd782014-08-13 22:36:06293 client_->ScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22294 SetNeedsRedrawRectOnImplThread(damage_rect);
[email protected]94f206c12012-08-25 00:09:14295}
296
[email protected]74b43cc2013-08-30 06:29:27297void SingleThreadProxy::SetNextCommitWaitsForActivation() {
enne98f3a6c2014-10-09 20:09:44298 // Activation always forced in commit, so nothing to do.
[email protected]aeeedad2014-08-22 18:16:22299 DCHECK(Proxy::IsMainThread());
[email protected]74b43cc2013-08-30 06:29:27300}
301
[email protected]a8a049c2013-03-11 23:27:06302void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
[email protected]aeeedad2014-08-22 18:16:22303 DCHECK(Proxy::IsMainThread());
304 // Deferring commits only makes sense if there's a scheduler.
305 if (!scheduler_on_impl_thread_)
306 return;
307 if (defer_commits_ == defer_commits)
308 return;
309
310 if (defer_commits)
311 TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this);
312 else
313 TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this);
314
315 defer_commits_ = defer_commits;
316 if (!defer_commits_ && commit_was_deferred_) {
317 commit_was_deferred_ = false;
318 BeginMainFrame();
319 }
[email protected]6b16679e2012-10-27 00:44:28320}
321
[email protected]174c6d42014-08-12 01:43:06322bool SingleThreadProxy::CommitRequested() const {
[email protected]aeeedad2014-08-22 18:16:22323 DCHECK(Proxy::IsMainThread());
324 return commit_requested_;
[email protected]174c6d42014-08-12 01:43:06325}
[email protected]a8a049c2013-03-11 23:27:06326
[email protected]174c6d42014-08-12 01:43:06327bool SingleThreadProxy::BeginMainFrameRequested() const {
[email protected]aeeedad2014-08-22 18:16:22328 DCHECK(Proxy::IsMainThread());
329 // If there is no scheduler, then there can be no pending begin frame,
330 // as all frames are all manually initiated by the embedder of cc.
331 if (!scheduler_on_impl_thread_)
332 return false;
333 return commit_requested_;
[email protected]174c6d42014-08-12 01:43:06334}
[email protected]971728d2013-10-26 10:39:31335
[email protected]a8a049c2013-03-11 23:27:06336size_t SingleThreadProxy::MaxPartialTextureUpdates() const {
337 return std::numeric_limits<size_t>::max();
338}
339
340void SingleThreadProxy::Stop() {
341 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
342 DCHECK(Proxy::IsMainThread());
343 {
[email protected]819b9f52013-09-22 23:29:51344 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
[email protected]a8a049c2013-03-11 23:27:06345 DebugScopedSetImplThread impl(this);
346
skyostil3976a3f2014-09-04 22:07:23347 BlockingTaskRunner::CapturePostTasks blocked(
348 blocking_main_thread_task_runner());
[email protected]804c8982013-03-13 16:32:21349 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27350 layer_tree_host_impl_->resource_provider());
danakjf446a072014-09-27 21:55:48351 scheduler_on_impl_thread_ = nullptr;
352 layer_tree_host_impl_ = nullptr;
[email protected]a8a049c2013-03-11 23:27:06353 }
[email protected]7aba6662013-03-12 10:17:34354 layer_tree_host_ = NULL;
[email protected]a8a049c2013-03-11 23:27:06355}
356
[email protected]3d9f7432013-04-06 00:35:18357void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
[email protected]ccc08dc2014-01-30 07:33:20358 TRACE_EVENT1(
359 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
[email protected]3d9f7432013-04-06 00:35:18360 DCHECK(Proxy::IsImplThread());
[email protected]aeeedad2014-08-22 18:16:22361 if (scheduler_on_impl_thread_)
362 scheduler_on_impl_thread_->SetCanDraw(can_draw);
[email protected]3d9f7432013-04-06 00:35:18363}
364
[email protected]4f48f6e2013-08-27 06:33:38365void SingleThreadProxy::NotifyReadyToActivate() {
enne98f3a6c2014-10-09 20:09:44366 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate");
367 DebugScopedSetImplThread impl(this);
368 if (scheduler_on_impl_thread_)
369 scheduler_on_impl_thread_->NotifyReadyToActivate();
[email protected]4f48f6e2013-08-27 06:33:38370}
371
ernstmdfac03e2014-11-11 20:18:05372void SingleThreadProxy::NotifyReadyToDraw() {
373}
374
[email protected]c1bb5af2013-03-13 19:06:27375void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
[email protected]943528e2013-11-07 05:01:32376 client_->ScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22377 if (scheduler_on_impl_thread_)
378 scheduler_on_impl_thread_->SetNeedsRedraw();
[email protected]a8a049c2013-03-11 23:27:06379}
380
[email protected]43b8f982014-04-30 21:24:33381void SingleThreadProxy::SetNeedsAnimateOnImplThread() {
mithro719bf6792014-11-10 15:36:47382 client_->ScheduleComposite();
383 if (scheduler_on_impl_thread_)
384 scheduler_on_impl_thread_->SetNeedsAnimate();
[email protected]43b8f982014-04-30 21:24:33385}
386
vmiura59ea9b4042014-12-09 20:50:39387void SingleThreadProxy::SetNeedsPrepareTilesOnImplThread() {
388 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsPrepareTilesOnImplThread");
enne98f3a6c2014-10-09 20:09:44389 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39390 scheduler_on_impl_thread_->SetNeedsPrepareTiles();
[email protected]c48536a52013-09-14 00:02:08391}
392
[email protected]0023fc72014-01-10 20:05:06393void SingleThreadProxy::SetNeedsRedrawRectOnImplThread(
394 const gfx::Rect& damage_rect) {
[email protected]1cd9f5552013-04-26 04:22:03395 layer_tree_host_impl_->SetViewportDamage(damage_rect);
[email protected]aeeedad2014-08-22 18:16:22396 SetNeedsRedrawOnImplThread();
[email protected]1cd9f5552013-04-26 04:22:03397}
398
[email protected]c1bb5af2013-03-13 19:06:27399void SingleThreadProxy::SetNeedsCommitOnImplThread() {
[email protected]943528e2013-11-07 05:01:32400 client_->ScheduleComposite();
[email protected]aeeedad2014-08-22 18:16:22401 if (scheduler_on_impl_thread_)
402 scheduler_on_impl_thread_->SetNeedsCommit();
[email protected]a8a049c2013-03-11 23:27:06403}
404
[email protected]c1bb5af2013-03-13 19:06:27405void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
[email protected]85b57502014-03-11 15:37:48406 scoped_ptr<AnimationEventsVector> events) {
[email protected]ccc08dc2014-01-30 07:33:20407 TRACE_EVENT0(
408 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
[email protected]a8a049c2013-03-11 23:27:06409 DCHECK(Proxy::IsImplThread());
410 DebugScopedSetMainThread main(this);
[email protected]85b57502014-03-11 15:37:48411 layer_tree_host_->SetAnimationEvents(events.Pass());
[email protected]a8a049c2013-03-11 23:27:06412}
413
[email protected]c1bb5af2013-03-13 19:06:27414bool SingleThreadProxy::ReduceContentsTextureMemoryOnImplThread(
[email protected]a8a049c2013-03-11 23:27:06415 size_t limit_bytes,
416 int priority_cutoff) {
417 DCHECK(IsImplThread());
[email protected]5d2fec02013-11-28 20:08:33418 PrioritizedResourceManager* contents_texture_manager =
419 layer_tree_host_->contents_texture_manager();
420
421 ResourceProvider* resource_provider =
422 layer_tree_host_impl_->resource_provider();
423
424 if (!contents_texture_manager || !resource_provider)
[email protected]e7595ead2013-10-10 10:10:07425 return false;
[email protected]a8a049c2013-03-11 23:27:06426
[email protected]5d2fec02013-11-28 20:08:33427 return contents_texture_manager->ReduceMemoryOnImplThread(
428 limit_bytes, priority_cutoff, resource_provider);
[email protected]94f206c12012-08-25 00:09:14429}
430
[email protected]c1bb5af2013-03-13 19:06:27431bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
[email protected]a8a049c2013-03-11 23:27:06432
enne98f3a6c2014-10-09 20:09:44433void SingleThreadProxy::DidActivateSyncTree() {
434 // Non-impl-side painting finishes commit in DoCommit. Impl-side painting
435 // defers until here to simulate SetNextCommitWaitsForActivation.
436 if (layer_tree_host_impl_->settings().impl_side_painting) {
437 // This is required because NotifyReadyToActivate gets called when
438 // the pending tree is not actually ready in the SingleThreadProxy.
439 layer_tree_host_impl_->SetRequiresHighResToDraw();
440
weiliangc5efa0a12015-01-29 19:56:46441 // Synchronously call to CommitComplete. Resetting
442 // |commit_blocking_task_runner| would make sure all tasks posted during
443 // commit/activation before CommitComplete.
enne5bea30e72014-12-18 00:36:17444 CommitComplete();
enne98f3a6c2014-10-09 20:09:44445 }
446
enne98f3a6c2014-10-09 20:09:44447 timing_history_.DidActivateSyncTree();
448}
449
vmiura59ea9b4042014-12-09 20:50:39450void SingleThreadProxy::DidPrepareTiles() {
enne98f3a6c2014-10-09 20:09:44451 DCHECK(layer_tree_host_impl_->settings().impl_side_painting);
452 DCHECK(Proxy::IsImplThread());
453 if (scheduler_on_impl_thread_)
vmiura59ea9b4042014-12-09 20:50:39454 scheduler_on_impl_thread_->DidPrepareTiles();
enne98f3a6c2014-10-09 20:09:44455}
456
rouslanf7ebd8832015-01-22 01:54:14457void SingleThreadProxy::DidCompletePageScaleAnimationOnImplThread() {
458 layer_tree_host_->DidCompletePageScaleAnimation();
459}
460
[email protected]fa339032014-02-18 22:11:59461void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() {
462 DCHECK(IsImplThread());
463 renderer_capabilities_for_main_thread_ =
464 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities();
465}
466
[email protected]c1bb5af2013-03-13 19:06:27467void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
[email protected]ccc08dc2014-01-30 07:33:20468 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22469 {
470 DebugScopedSetMainThread main(this);
471 // This must happen before we notify the scheduler as it may try to recreate
472 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE.
473 layer_tree_host_->DidLoseOutputSurface();
474 }
[email protected]4d7e46a2013-11-08 05:33:40475 client_->DidAbortSwapBuffers();
[email protected]aeeedad2014-08-22 18:16:22476 if (scheduler_on_impl_thread_)
477 scheduler_on_impl_thread_->DidLoseOutputSurface();
[email protected]4d7e46a2013-11-08 05:33:40478}
479
weiliangcaf17af42014-12-15 22:17:02480void SingleThreadProxy::CommitVSyncParameters(base::TimeTicks timebase,
481 base::TimeDelta interval) {
482 if (scheduler_on_impl_thread_)
483 scheduler_on_impl_thread_->CommitVSyncParameters(timebase, interval);
484}
485
[email protected]4d7e46a2013-11-08 05:33:40486void SingleThreadProxy::DidSwapBuffersOnImplThread() {
[email protected]aeeedad2014-08-22 18:16:22487 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersOnImplThread");
488 if (scheduler_on_impl_thread_)
489 scheduler_on_impl_thread_->DidSwapBuffers();
[email protected]4d7e46a2013-11-08 05:33:40490 client_->DidPostSwapBuffers();
491}
492
[email protected]c14902662014-04-18 05:06:11493void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() {
miletusfed8c43b2015-01-26 20:04:52494 TRACE_EVENT0("cc,benchmark",
495 "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread");
[email protected]aeeedad2014-08-22 18:16:22496 if (scheduler_on_impl_thread_)
497 scheduler_on_impl_thread_->DidSwapBuffersComplete();
498 layer_tree_host_->DidCompleteSwapBuffers();
[email protected]493067512012-09-19 23:34:10499}
500
[email protected]f0c2a242013-03-15 19:34:52501void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
miletusfed8c43b2015-01-26 20:04:52502 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately");
[email protected]51f81da2014-05-16 21:29:26503 DCHECK(Proxy::IsMainThread());
jbauman399aec1a2014-10-25 02:33:32504 base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true);
505
506 if (layer_tree_host_->output_surface_lost()) {
507 RequestNewOutputSurface();
508 // RequestNewOutputSurface could have synchronously created an output
509 // surface, so check again before returning.
510 if (layer_tree_host_->output_surface_lost())
511 return;
512 }
[email protected]51f81da2014-05-16 21:29:26513
enne98f3a6c2014-10-09 20:09:44514 {
mithrobfa0ec02014-11-21 15:13:49515 BeginFrameArgs begin_frame_args(BeginFrameArgs::Create(
mithro06d1f3bf2014-12-02 02:19:15516 BEGINFRAME_FROM_HERE, frame_begin_time, base::TimeTicks(),
517 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::SYNCHRONOUS));
enne98f3a6c2014-10-09 20:09:44518 DoBeginMainFrame(begin_frame_args);
519 DoCommit();
[email protected]e0341352013-04-06 05:01:20520
enne98f3a6c2014-10-09 20:09:44521 DCHECK_EQ(0u, layer_tree_host_->num_queued_swap_promises())
522 << "Commit should always succeed and transfer promises.";
523 }
524
525 {
526 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
enne69277cb2014-10-29 23:03:40527 if (layer_tree_host_impl_->settings().impl_side_painting) {
528 layer_tree_host_impl_->ActivateSyncTree();
529 layer_tree_host_impl_->active_tree()->UpdateDrawProperties();
vmiura59ea9b4042014-12-09 20:50:39530 layer_tree_host_impl_->PrepareTiles();
enne69277cb2014-10-29 23:03:40531 layer_tree_host_impl_->SynchronouslyInitializeAllTiles();
532 }
533
mithro719bf6792014-11-10 15:36:47534 DoAnimate();
535
enne98f3a6c2014-10-09 20:09:44536 LayerTreeHostImpl::FrameData frame;
537 DoComposite(frame_begin_time, &frame);
538
539 // DoComposite could abort, but because this is a synchronous composite
540 // another draw will never be scheduled, so break remaining promises.
541 layer_tree_host_impl_->active_tree()->BreakSwapPromises(
542 SwapPromise::SWAP_FAILS);
543 }
[email protected]74d9063c2013-01-18 03:14:47544}
545
[email protected]d12aa932014-08-01 13:10:38546void SingleThreadProxy::AsValueInto(base::debug::TracedValue* state) const {
547 // The following line casts away const modifiers because it is just
548 // setting debug state. We still want the AsValue() function and its
549 // call chain to be const throughout.
550 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
[email protected]a8a049c2013-03-11 23:27:06551
[email protected]d12aa932014-08-01 13:10:38552 state->BeginDictionary("layer_tree_host_impl");
553 layer_tree_host_impl_->AsValueInto(state);
554 state->EndDictionary();
[email protected]493067512012-09-19 23:34:10555}
556
[email protected]a8a049c2013-03-11 23:27:06557void SingleThreadProxy::ForceSerializeOnSwapBuffers() {
558 {
559 DebugScopedSetImplThread impl(this);
[email protected]04049fc2013-05-01 03:13:20560 if (layer_tree_host_impl_->renderer()) {
561 DCHECK(!layer_tree_host_->output_surface_lost());
[email protected]a8a049c2013-03-11 23:27:06562 layer_tree_host_impl_->renderer()->DoNoOp();
[email protected]04049fc2013-05-01 03:13:20563 }
[email protected]a8a049c2013-03-11 23:27:06564 }
[email protected]8947cbe2012-11-28 05:27:43565}
566
[email protected]5d8bec72014-07-03 03:03:11567bool SingleThreadProxy::SupportsImplScrolling() const {
568 return false;
569}
570
[email protected]3d9f7432013-04-06 00:35:18571bool SingleThreadProxy::ShouldComposite() const {
572 DCHECK(Proxy::IsImplThread());
573 return layer_tree_host_impl_->visible() &&
574 layer_tree_host_impl_->CanDraw();
575}
576
jbauman8ab0f9e2014-10-15 02:30:34577void SingleThreadProxy::ScheduleRequestNewOutputSurface() {
578 if (output_surface_creation_callback_.IsCancelled() &&
579 !output_surface_creation_requested_) {
580 output_surface_creation_callback_.Reset(
581 base::Bind(&SingleThreadProxy::RequestNewOutputSurface,
582 weak_factory_.GetWeakPtr()));
583 MainThreadTaskRunner()->PostTask(
584 FROM_HERE, output_surface_creation_callback_.callback());
585 }
586}
587
[email protected]aeeedad2014-08-22 18:16:22588DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time,
589 LayerTreeHostImpl::FrameData* frame) {
[email protected]ccc08dc2014-01-30 07:33:20590 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite");
[email protected]04049fc2013-05-01 03:13:20591 DCHECK(!layer_tree_host_->output_surface_lost());
592
enne98f3a6c2014-10-09 20:09:44593 DrawResult draw_result;
594 bool draw_frame;
[email protected]a8a049c2013-03-11 23:27:06595 {
596 DebugScopedSetImplThread impl(this);
597 base::AutoReset<bool> mark_inside(&inside_draw_, true);
598
[email protected]3d9f7432013-04-06 00:35:18599 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
600 // frame, so can only be used when such a frame is possible. Since
601 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
602 // CanDraw() as well.
[email protected]2aae96792014-05-15 23:10:50603 if (!ShouldComposite()) {
[email protected]aeeedad2014-08-22 18:16:22604 return DRAW_ABORTED_CANT_DRAW;
[email protected]3d9f7432013-04-06 00:35:18605 }
[email protected]a8a049c2013-03-11 23:27:06606
[email protected]aeeedad2014-08-22 18:16:22607 timing_history_.DidStartDrawing();
608
enne98f3a6c2014-10-09 20:09:44609 draw_result = layer_tree_host_impl_->PrepareToDraw(frame);
610 draw_frame = draw_result == DRAW_SUCCESS;
611 if (draw_frame)
612 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time);
dnetob71e30c2014-08-25 23:27:20613 layer_tree_host_impl_->DidDrawAllLayers(*frame);
[email protected]a8a049c2013-03-11 23:27:06614
enne98f3a6c2014-10-09 20:09:44615 bool start_ready_animations = draw_frame;
[email protected]3d9f7432013-04-06 00:35:18616 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
[email protected]04c5900d2014-08-18 13:38:36617 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame();
[email protected]aeeedad2014-08-22 18:16:22618
619 timing_history_.DidFinishDrawing();
[email protected]a8a049c2013-03-11 23:27:06620 }
621
enne98f3a6c2014-10-09 20:09:44622 if (draw_frame) {
[email protected]aeeedad2014-08-22 18:16:22623 DebugScopedSetImplThread impl(this);
[email protected]174c6d42014-08-12 01:43:06624
dnetob71e30c2014-08-25 23:27:20625 // This CapturePostTasks should be destroyed before
626 // DidCommitAndDrawFrame() is called since that goes out to the
627 // embedder,
628 // and we want the embedder to receive its callbacks before that.
629 // NOTE: This maintains consistent ordering with the ThreadProxy since
630 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
631 // there as the main thread is not blocked, so any posted tasks inside
632 // the swap buffers will execute first.
633 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
[email protected]aeeedad2014-08-22 18:16:22634
skyostil3976a3f2014-09-04 22:07:23635 BlockingTaskRunner::CapturePostTasks blocked(
636 blocking_main_thread_task_runner());
dnetob71e30c2014-08-25 23:27:20637 layer_tree_host_impl_->SwapBuffers(*frame);
[email protected]aeeedad2014-08-22 18:16:22638 }
639 DidCommitAndDrawFrame();
640
enne98f3a6c2014-10-09 20:09:44641 return draw_result;
[email protected]a8a049c2013-03-11 23:27:06642}
643
[email protected]aeeedad2014-08-22 18:16:22644void SingleThreadProxy::DidCommitAndDrawFrame() {
[email protected]a8a049c2013-03-11 23:27:06645 if (next_frame_is_newly_committed_frame_) {
[email protected]aeeedad2014-08-22 18:16:22646 DebugScopedSetMainThread main(this);
[email protected]a8a049c2013-03-11 23:27:06647 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21648 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06649 }
650}
651
[email protected]4ea293f72014-08-13 03:03:17652bool SingleThreadProxy::MainFrameWillHappenForTesting() {
653 return false;
654}
[email protected]a8a049c2013-03-11 23:27:06655
simonhongd3d5f7f2014-11-21 16:38:03656void SingleThreadProxy::SetChildrenNeedBeginFrames(
657 bool children_need_begin_frames) {
658 scheduler_on_impl_thread_->SetChildrenNeedBeginFrames(
659 children_need_begin_frames);
660}
661
[email protected]aeeedad2014-08-22 18:16:22662void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) {
663 layer_tree_host_impl_->WillBeginImplFrame(args);
664}
665
666void SingleThreadProxy::ScheduledActionSendBeginMainFrame() {
667 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame");
668 // Although this proxy is single-threaded, it's problematic to synchronously
669 // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This
670 // could cause a commit to occur in between a series of SetNeedsCommit calls
671 // (i.e. property modifications) causing some to fall on one frame and some to
672 // fall on the next. Doing it asynchronously instead matches the semantics of
673 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a
674 // synchronous commit.
675 MainThreadTaskRunner()->PostTask(
676 FROM_HERE,
677 base::Bind(&SingleThreadProxy::BeginMainFrame,
678 weak_factory_.GetWeakPtr()));
679}
680
681void SingleThreadProxy::BeginMainFrame() {
682 if (defer_commits_) {
683 DCHECK(!commit_was_deferred_);
684 commit_was_deferred_ = true;
685 layer_tree_host_->DidDeferCommit();
686 return;
687 }
688
enne98f3a6c2014-10-09 20:09:44689 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous
690 // commit.
[email protected]aeeedad2014-08-22 18:16:22691 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_);
692
693 if (!layer_tree_host_->visible()) {
694 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD);
mithrof7a21502014-12-17 03:24:48695 BeginMainFrameAbortedOnImplThread(
696 CommitEarlyOutReason::ABORTED_NOT_VISIBLE);
[email protected]aeeedad2014-08-22 18:16:22697 return;
698 }
699
700 if (layer_tree_host_->output_surface_lost()) {
701 TRACE_EVENT_INSTANT0(
702 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD);
mithrof7a21502014-12-17 03:24:48703 BeginMainFrameAbortedOnImplThread(
704 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST);
[email protected]aeeedad2014-08-22 18:16:22705 return;
706 }
707
enne98f3a6c2014-10-09 20:09:44708 const BeginFrameArgs& begin_frame_args =
709 layer_tree_host_impl_->CurrentBeginFrameArgs();
710 DoBeginMainFrame(begin_frame_args);
711}
712
713void SingleThreadProxy::DoBeginMainFrame(
714 const BeginFrameArgs& begin_frame_args) {
715 layer_tree_host_->WillBeginMainFrame();
716 layer_tree_host_->BeginMainFrame(begin_frame_args);
717 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time);
718 layer_tree_host_->Layout();
719
720 if (PrioritizedResourceManager* contents_texture_manager =
721 layer_tree_host_->contents_texture_manager()) {
722 contents_texture_manager->UnlinkAndClearEvictedBackings();
723 contents_texture_manager->SetMaxMemoryLimitBytes(
724 layer_tree_host_impl_->memory_allocation_limit_bytes());
725 contents_texture_manager->SetExternalPriorityCutoff(
726 layer_tree_host_impl_->memory_allocation_priority_cutoff());
727 }
728
729 DCHECK(!queue_for_commit_);
730 queue_for_commit_ = make_scoped_ptr(new ResourceUpdateQueue);
731
732 layer_tree_host_->UpdateLayers(queue_for_commit_.get());
733
[email protected]aeeedad2014-08-22 18:16:22734 timing_history_.DidBeginMainFrame();
735
mithrof7a21502014-12-17 03:24:48736 // TODO(enne): SingleThreadProxy does not support cancelling commits yet,
737 // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside
738 // thread_proxy.cc
enne98f3a6c2014-10-09 20:09:44739 if (scheduler_on_impl_thread_) {
740 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted();
741 scheduler_on_impl_thread_->NotifyReadyToCommit();
742 }
[email protected]aeeedad2014-08-22 18:16:22743}
744
mithrof7a21502014-12-17 03:24:48745void SingleThreadProxy::BeginMainFrameAbortedOnImplThread(
746 CommitEarlyOutReason reason) {
[email protected]aeeedad2014-08-22 18:16:22747 DebugScopedSetImplThread impl(this);
748 DCHECK(scheduler_on_impl_thread_->CommitPending());
749 DCHECK(!layer_tree_host_impl_->pending_tree());
750
mithrof7a21502014-12-17 03:24:48751 layer_tree_host_impl_->BeginMainFrameAborted(reason);
752 scheduler_on_impl_thread_->BeginMainFrameAborted(reason);
[email protected]aeeedad2014-08-22 18:16:22753}
754
755DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
756 DebugScopedSetImplThread impl(this);
[email protected]aeeedad2014-08-22 18:16:22757 LayerTreeHostImpl::FrameData frame;
758 return DoComposite(layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time,
759 &frame);
760}
761
762DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() {
763 NOTREACHED();
764 return INVALID_RESULT;
765}
766
767void SingleThreadProxy::ScheduledActionCommit() {
768 DebugScopedSetMainThread main(this);
enne98f3a6c2014-10-09 20:09:44769 DoCommit();
[email protected]aeeedad2014-08-22 18:16:22770}
771
772void SingleThreadProxy::ScheduledActionAnimate() {
773 TRACE_EVENT0("cc", "ScheduledActionAnimate");
mithro719bf6792014-11-10 15:36:47774 DebugScopedSetImplThread impl(this);
775 DoAnimate();
[email protected]aeeedad2014-08-22 18:16:22776}
777
[email protected]aeeedad2014-08-22 18:16:22778void SingleThreadProxy::ScheduledActionActivateSyncTree() {
enne98f3a6c2014-10-09 20:09:44779 DebugScopedSetImplThread impl(this);
780 layer_tree_host_impl_->ActivateSyncTree();
[email protected]aeeedad2014-08-22 18:16:22781}
782
783void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
784 DebugScopedSetMainThread main(this);
785 DCHECK(scheduler_on_impl_thread_);
786 // If possible, create the output surface in a post task. Synchronously
787 // creating the output surface makes tests more awkward since this differs
788 // from the ThreadProxy behavior. However, sometimes there is no
789 // task runner.
790 if (Proxy::MainThreadTaskRunner()) {
jbauman8ab0f9e2014-10-15 02:30:34791 ScheduleRequestNewOutputSurface();
[email protected]aeeedad2014-08-22 18:16:22792 } else {
enne2097cab2014-09-25 20:16:31793 RequestNewOutputSurface();
[email protected]aeeedad2014-08-22 18:16:22794 }
795}
796
vmiura59ea9b4042014-12-09 20:50:39797void SingleThreadProxy::ScheduledActionPrepareTiles() {
798 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionPrepareTiles");
enne98f3a6c2014-10-09 20:09:44799 DCHECK(layer_tree_host_impl_->settings().impl_side_painting);
800 DebugScopedSetImplThread impl(this);
vmiura59ea9b4042014-12-09 20:50:39801 layer_tree_host_impl_->PrepareTiles();
[email protected]aeeedad2014-08-22 18:16:22802}
803
804void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) {
805}
806
807base::TimeDelta SingleThreadProxy::DrawDurationEstimate() {
808 return timing_history_.DrawDurationEstimate();
809}
810
811base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() {
812 return timing_history_.BeginMainFrameToCommitDurationEstimate();
813}
814
815base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() {
816 return timing_history_.CommitToActivateDurationEstimate();
817}
818
819void SingleThreadProxy::DidBeginImplFrameDeadline() {
820 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame();
821}
822
simonhongd3d5f7f2014-11-21 16:38:03823void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) {
824 layer_tree_host_->SendBeginFramesToChildren(args);
825}
826
[email protected]bc5e77c2012-11-05 20:00:49827} // namespace cc