blob: 2486851bcb502873163d385cf153563e36151c4a [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"
[email protected]6331a1172012-10-18 11:35:138#include "base/debug/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"
[email protected]9794fb32013-08-29 09:49:5915#include "cc/trees/blocking_task_runner.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]de2cf8c2013-10-25 19:46:4619#include "ui/gfx/frame_time.h"
[email protected]94f206c12012-08-25 00:09:1420
[email protected]9c88e562012-09-14 22:21:3021namespace cc {
[email protected]94f206c12012-08-25 00:09:1422
[email protected]943528e2013-11-07 05:01:3223scoped_ptr<Proxy> SingleThreadProxy::Create(
24 LayerTreeHost* layer_tree_host,
25 LayerTreeHostSingleThreadClient* client) {
[email protected]a8a049c2013-03-11 23:27:0626 return make_scoped_ptr(
[email protected]943528e2013-11-07 05:01:3227 new SingleThreadProxy(layer_tree_host, client)).PassAs<Proxy>();
[email protected]94f206c12012-08-25 00:09:1428}
29
[email protected]943528e2013-11-07 05:01:3230SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host,
31 LayerTreeHostSingleThreadClient* client)
[email protected]810d40b72013-06-20 18:26:1532 : Proxy(NULL),
[email protected]a8a049c2013-03-11 23:27:0633 layer_tree_host_(layer_tree_host),
[email protected]943528e2013-11-07 05:01:3234 client_(client),
[email protected]a8a049c2013-03-11 23:27:0635 next_frame_is_newly_committed_frame_(false),
[email protected]dfbded22014-06-28 17:57:3236 inside_draw_(false) {
[email protected]a8a049c2013-03-11 23:27:0637 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
38 DCHECK(Proxy::IsMainThread());
39 DCHECK(layer_tree_host);
[email protected]1e4c352b2013-01-10 02:05:2340
[email protected]089102b2013-03-14 03:54:5641 // Impl-side painting not supported without threaded compositing.
[email protected]d9c086a2013-04-17 16:12:4842 CHECK(!layer_tree_host->settings().impl_side_painting)
43 << "Threaded compositing must be enabled to use impl-side painting.";
[email protected]94f206c12012-08-25 00:09:1444}
45
[email protected]e96e3432013-12-19 18:56:0746void SingleThreadProxy::Start() {
[email protected]a8a049c2013-03-11 23:27:0647 DebugScopedSetImplThread impl(this);
[email protected]804c8982013-03-13 16:32:2148 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
[email protected]a8a049c2013-03-11 23:27:0649}
50
51SingleThreadProxy::~SingleThreadProxy() {
52 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy");
53 DCHECK(Proxy::IsMainThread());
[email protected]04049fc2013-05-01 03:13:2054 // Make sure Stop() got called or never Started.
55 DCHECK(!layer_tree_host_impl_);
[email protected]a8a049c2013-03-11 23:27:0656}
57
[email protected]a8a049c2013-03-11 23:27:0658void SingleThreadProxy::FinishAllRendering() {
[email protected]ccc08dc2014-01-30 07:33:2059 TRACE_EVENT0("cc", "SingleThreadProxy::FinishAllRendering");
[email protected]a8a049c2013-03-11 23:27:0660 DCHECK(Proxy::IsMainThread());
61 {
[email protected]61de5812012-11-08 07:03:4462 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:2763 layer_tree_host_impl_->FinishAllRendering();
[email protected]a8a049c2013-03-11 23:27:0664 }
[email protected]94f206c12012-08-25 00:09:1465}
66
[email protected]a8a049c2013-03-11 23:27:0667bool SingleThreadProxy::IsStarted() const {
68 DCHECK(Proxy::IsMainThread());
[email protected]3209161d2013-03-29 19:17:3469 return layer_tree_host_impl_;
[email protected]94f206c12012-08-25 00:09:1470}
71
[email protected]14bd5542013-05-08 21:51:3072void SingleThreadProxy::SetLayerTreeHostClientReady() {
[email protected]ccc08dc2014-01-30 07:33:2073 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady");
[email protected]a8a049c2013-03-11 23:27:0674 // Scheduling is controlled by the embedder in the single thread case, so
75 // nothing to do.
76}
77
78void SingleThreadProxy::SetVisible(bool visible) {
[email protected]ccc08dc2014-01-30 07:33:2079 TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible");
[email protected]f7c01c82013-07-02 22:58:4680 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:2781 layer_tree_host_impl_->SetVisible(visible);
[email protected]dfbded22014-06-28 17:57:3282
[email protected]8ea875b2013-08-07 00:32:1283 // Changing visibility could change ShouldComposite().
[email protected]d9fce6722013-08-30 01:10:0184 UpdateBackgroundAnimateTicking();
[email protected]a8a049c2013-03-11 23:27:0685}
86
[email protected]04049fc2013-05-01 03:13:2087void SingleThreadProxy::CreateAndInitializeOutputSurface() {
88 TRACE_EVENT0(
89 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface");
[email protected]a8a049c2013-03-11 23:27:0690 DCHECK(Proxy::IsMainThread());
[email protected]497edf82014-05-20 21:53:1591 DCHECK(layer_tree_host_->output_surface_lost());
[email protected]94f206c12012-08-25 00:09:1492
[email protected]e96e3432013-12-19 18:56:0793 scoped_ptr<OutputSurface> output_surface =
94 layer_tree_host_->CreateOutputSurface();
[email protected]04049fc2013-05-01 03:13:2095
[email protected]da8e3b72b2014-04-25 02:33:4596 renderer_capabilities_for_main_thread_ = RendererCapabilities();
97
98 bool success = !!output_surface;
99 if (success) {
[email protected]819b9f52013-09-22 23:29:51100 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
[email protected]a8a049c2013-03-11 23:27:06101 DebugScopedSetImplThread impl(this);
[email protected]804c8982013-03-13 16:32:21102 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27103 layer_tree_host_impl_->resource_provider());
[email protected]da8e3b72b2014-04-25 02:33:45104 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass());
[email protected]04049fc2013-05-01 03:13:20105 }
106
[email protected]da8e3b72b2014-04-25 02:33:45107 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success);
[email protected]04049fc2013-05-01 03:13:20108
[email protected]dfbded22014-06-28 17:57:32109 if (!success) {
110 // Force another recreation attempt to happen by requesting another commit.
111 SetNeedsCommit();
[email protected]04049fc2013-05-01 03:13:20112 }
[email protected]94f206c12012-08-25 00:09:14113}
114
[email protected]a8a049c2013-03-11 23:27:06115const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const {
[email protected]04049fc2013-05-01 03:13:20116 DCHECK(Proxy::IsMainThread());
117 DCHECK(!layer_tree_host_->output_surface_lost());
[email protected]a8a049c2013-03-11 23:27:06118 return renderer_capabilities_for_main_thread_;
[email protected]94f206c12012-08-25 00:09:14119}
120
[email protected]8b9e52b2014-01-17 16:35:31121void SingleThreadProxy::SetNeedsAnimate() {
[email protected]ccc08dc2014-01-30 07:33:20122 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate");
[email protected]c5134172013-12-11 06:19:48123 DCHECK(Proxy::IsMainThread());
[email protected]06cbc31b2014-01-17 06:43:20124 client_->ScheduleAnimation();
[email protected]c5134172013-12-11 06:19:48125}
126
[email protected]8b9e52b2014-01-17 16:35:31127void SingleThreadProxy::SetNeedsUpdateLayers() {
[email protected]ccc08dc2014-01-30 07:33:20128 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers");
[email protected]8b9e52b2014-01-17 16:35:31129 DCHECK(Proxy::IsMainThread());
[email protected]dfbded22014-06-28 17:57:32130 client_->ScheduleComposite();
[email protected]8b9e52b2014-01-17 16:35:31131}
132
[email protected]dfbded22014-06-28 17:57:32133void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) {
[email protected]ccc08dc2014-01-30 07:33:20134 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit");
[email protected]a8a049c2013-03-11 23:27:06135 DCHECK(Proxy::IsMainThread());
136 // Commit immediately.
137 {
[email protected]819b9f52013-09-22 23:29:51138 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
[email protected]f7c01c82013-07-02 22:58:46139 DebugScopedSetImplThread impl(this);
140
[email protected]9794fb32013-08-29 09:49:59141 // This CapturePostTasks should be destroyed before CommitComplete() is
142 // called since that goes out to the embedder, and we want the embedder
143 // to receive its callbacks before that.
144 BlockingTaskRunner::CapturePostTasks blocked;
145
[email protected]c1bb5af2013-03-13 19:06:27146 layer_tree_host_impl_->BeginCommit();
[email protected]94f206c12012-08-25 00:09:14147
[email protected]5d2fec02013-11-28 20:08:33148 if (PrioritizedResourceManager* contents_texture_manager =
149 layer_tree_host_->contents_texture_manager()) {
150 contents_texture_manager->PushTexturePrioritiesToBackings();
[email protected]6e8c54922013-06-02 19:17:35151 }
[email protected]804c8982013-03-13 16:32:21152 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14153
[email protected]ed511b8d2013-03-25 03:29:29154 scoped_ptr<ResourceUpdateController> update_controller =
[email protected]a8a049c2013-03-11 23:27:06155 ResourceUpdateController::Create(
156 NULL,
[email protected]810d40b72013-06-20 18:26:15157 Proxy::MainThreadTaskRunner(),
[email protected]a8a049c2013-03-11 23:27:06158 queue.Pass(),
[email protected]c1bb5af2013-03-13 19:06:27159 layer_tree_host_impl_->resource_provider());
[email protected]ed511b8d2013-03-25 03:29:29160 update_controller->Finalize();
[email protected]94f206c12012-08-25 00:09:14161
[email protected]127bdc1a2013-09-11 01:44:48162 if (layer_tree_host_impl_->EvictedUIResourcesExist())
163 layer_tree_host_->RecreateUIResources();
164
[email protected]804c8982013-03-13 16:32:21165 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14166
[email protected]c1bb5af2013-03-13 19:06:27167 layer_tree_host_impl_->CommitComplete();
[email protected]94f206c12012-08-25 00:09:14168
[email protected]767f38d72014-03-18 21:26:41169#if DCHECK_IS_ON
[email protected]3519b872013-07-30 07:17:50170 // In the single-threaded case, the scale and scroll deltas should never be
[email protected]a8a049c2013-03-11 23:27:06171 // touched on the impl layer tree.
[email protected]ed511b8d2013-03-25 03:29:29172 scoped_ptr<ScrollAndScaleSet> scroll_info =
[email protected]c1bb5af2013-03-13 19:06:27173 layer_tree_host_impl_->ProcessScrollDeltas();
[email protected]ed511b8d2013-03-25 03:29:29174 DCHECK(!scroll_info->scrolls.size());
[email protected]3519b872013-07-30 07:17:50175 DCHECK_EQ(1.f, scroll_info->page_scale_delta);
[email protected]94f206c12012-08-25 00:09:14176#endif
[email protected]8b9af6b2012-09-27 00:36:36177
[email protected]922c6e1f2013-10-09 04:04:09178 RenderingStatsInstrumentation* stats_instrumentation =
179 layer_tree_host_->rendering_stats_instrumentation();
[email protected]1bbed7a2014-07-08 02:54:00180 benchmark_instrumentation::IssueMainThreadRenderingStatsEvent(
[email protected]adbe30f2013-10-11 21:12:33181 stats_instrumentation->main_thread_rendering_stats());
[email protected]a9dc0d0f2013-08-17 02:43:18182 stats_instrumentation->AccumulateAndClearMainThreadStats();
[email protected]a8a049c2013-03-11 23:27:06183 }
[email protected]804c8982013-03-13 16:32:21184 layer_tree_host_->CommitComplete();
[email protected]a8a049c2013-03-11 23:27:06185 next_frame_is_newly_committed_frame_ = true;
[email protected]94f206c12012-08-25 00:09:14186}
187
[email protected]a8a049c2013-03-11 23:27:06188void SingleThreadProxy::SetNeedsCommit() {
189 DCHECK(Proxy::IsMainThread());
[email protected]943528e2013-11-07 05:01:32190 client_->ScheduleComposite();
[email protected]94f206c12012-08-25 00:09:14191}
192
[email protected]0023fc72014-01-10 20:05:06193void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) {
[email protected]ccc08dc2014-01-30 07:33:20194 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw");
[email protected]1120afab2014-06-28 05:35:54195 SetNeedsRedrawRectOnImplThread(damage_rect);
[email protected]dfbded22014-06-28 17:57:32196 client_->ScheduleComposite();
[email protected]94f206c12012-08-25 00:09:14197}
198
[email protected]74b43cc2013-08-30 06:29:27199void SingleThreadProxy::SetNextCommitWaitsForActivation() {
200 // There is no activation here other than commit. So do nothing.
201}
202
[email protected]a8a049c2013-03-11 23:27:06203void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
[email protected]dfbded22014-06-28 17:57:32204 // Thread-only feature.
205 NOTREACHED();
[email protected]6b16679e2012-10-27 00:44:28206}
207
[email protected]dfbded22014-06-28 17:57:32208bool SingleThreadProxy::CommitRequested() const { return false; }
[email protected]a8a049c2013-03-11 23:27:06209
[email protected]dfbded22014-06-28 17:57:32210bool SingleThreadProxy::BeginMainFrameRequested() const { return false; }
[email protected]971728d2013-10-26 10:39:31211
[email protected]a8a049c2013-03-11 23:27:06212size_t SingleThreadProxy::MaxPartialTextureUpdates() const {
213 return std::numeric_limits<size_t>::max();
214}
215
216void SingleThreadProxy::Stop() {
217 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
218 DCHECK(Proxy::IsMainThread());
219 {
[email protected]819b9f52013-09-22 23:29:51220 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
[email protected]a8a049c2013-03-11 23:27:06221 DebugScopedSetImplThread impl(this);
222
[email protected]446b23d2014-05-16 18:24:18223 BlockingTaskRunner::CapturePostTasks blocked;
[email protected]804c8982013-03-13 16:32:21224 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27225 layer_tree_host_impl_->resource_provider());
[email protected]a8a049c2013-03-11 23:27:06226 layer_tree_host_impl_.reset();
227 }
[email protected]7aba6662013-03-12 10:17:34228 layer_tree_host_ = NULL;
[email protected]a8a049c2013-03-11 23:27:06229}
230
[email protected]3d9f7432013-04-06 00:35:18231void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
[email protected]ccc08dc2014-01-30 07:33:20232 TRACE_EVENT1(
233 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
[email protected]3d9f7432013-04-06 00:35:18234 DCHECK(Proxy::IsImplThread());
[email protected]d9fce6722013-08-30 01:10:01235 UpdateBackgroundAnimateTicking();
[email protected]3d9f7432013-04-06 00:35:18236}
237
[email protected]4f48f6e2013-08-27 06:33:38238void SingleThreadProxy::NotifyReadyToActivate() {
[email protected]dfbded22014-06-28 17:57:32239 // Thread-only feature.
[email protected]4f48f6e2013-08-27 06:33:38240 NOTREACHED();
241}
242
[email protected]c1bb5af2013-03-13 19:06:27243void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
[email protected]943528e2013-11-07 05:01:32244 client_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06245}
246
[email protected]43b8f982014-04-30 21:24:33247void SingleThreadProxy::SetNeedsAnimateOnImplThread() {
248 SetNeedsRedrawOnImplThread();
249}
250
[email protected]c48536a52013-09-14 00:02:08251void SingleThreadProxy::SetNeedsManageTilesOnImplThread() {
[email protected]dfbded22014-06-28 17:57:32252 // Thread-only/Impl-side-painting-only feature.
[email protected]c48536a52013-09-14 00:02:08253 NOTREACHED();
254}
255
[email protected]0023fc72014-01-10 20:05:06256void SingleThreadProxy::SetNeedsRedrawRectOnImplThread(
257 const gfx::Rect& damage_rect) {
[email protected]dfbded22014-06-28 17:57:32258 // TODO(brianderson): Once we move render_widget scheduling into this class,
259 // we can treat redraw requests more efficiently than CommitAndRedraw
260 // requests.
[email protected]1cd9f5552013-04-26 04:22:03261 layer_tree_host_impl_->SetViewportDamage(damage_rect);
[email protected]dfbded22014-06-28 17:57:32262 SetNeedsCommit();
[email protected]1cd9f5552013-04-26 04:22:03263}
264
[email protected]86126792013-03-16 20:07:54265void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06266 // Impl-side painting only.
267 NOTREACHED();
268}
269
[email protected]c1bb5af2013-03-13 19:06:27270void SingleThreadProxy::SetNeedsCommitOnImplThread() {
[email protected]943528e2013-11-07 05:01:32271 client_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06272}
273
[email protected]c1bb5af2013-03-13 19:06:27274void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
[email protected]85b57502014-03-11 15:37:48275 scoped_ptr<AnimationEventsVector> events) {
[email protected]ccc08dc2014-01-30 07:33:20276 TRACE_EVENT0(
277 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
[email protected]a8a049c2013-03-11 23:27:06278 DCHECK(Proxy::IsImplThread());
279 DebugScopedSetMainThread main(this);
[email protected]85b57502014-03-11 15:37:48280 layer_tree_host_->SetAnimationEvents(events.Pass());
[email protected]a8a049c2013-03-11 23:27:06281}
282
[email protected]c1bb5af2013-03-13 19:06:27283bool SingleThreadProxy::ReduceContentsTextureMemoryOnImplThread(
[email protected]a8a049c2013-03-11 23:27:06284 size_t limit_bytes,
285 int priority_cutoff) {
286 DCHECK(IsImplThread());
[email protected]5d2fec02013-11-28 20:08:33287 PrioritizedResourceManager* contents_texture_manager =
288 layer_tree_host_->contents_texture_manager();
289
290 ResourceProvider* resource_provider =
291 layer_tree_host_impl_->resource_provider();
292
293 if (!contents_texture_manager || !resource_provider)
[email protected]e7595ead2013-10-10 10:10:07294 return false;
[email protected]a8a049c2013-03-11 23:27:06295
[email protected]5d2fec02013-11-28 20:08:33296 return contents_texture_manager->ReduceMemoryOnImplThread(
297 limit_bytes, priority_cutoff, resource_provider);
[email protected]94f206c12012-08-25 00:09:14298}
299
[email protected]c1bb5af2013-03-13 19:06:27300bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
[email protected]a8a049c2013-03-11 23:27:06301
[email protected]fa339032014-02-18 22:11:59302void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() {
303 DCHECK(IsImplThread());
304 renderer_capabilities_for_main_thread_ =
305 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities();
306}
307
[email protected]c1bb5af2013-03-13 19:06:27308void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
[email protected]ccc08dc2014-01-30 07:33:20309 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread");
[email protected]dfbded22014-06-28 17:57:32310 // Cause a commit so we can notice the lost context.
311 SetNeedsCommitOnImplThread();
[email protected]4d7e46a2013-11-08 05:33:40312 client_->DidAbortSwapBuffers();
313}
314
315void SingleThreadProxy::DidSwapBuffersOnImplThread() {
316 client_->DidPostSwapBuffers();
317}
318
[email protected]c14902662014-04-18 05:06:11319void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() {
320 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread");
[email protected]dfbded22014-06-28 17:57:32321 client_->DidCompleteSwapBuffers();
[email protected]493067512012-09-19 23:34:10322}
323
[email protected]dfbded22014-06-28 17:57:32324// Called by the legacy scheduling path (e.g. where render_widget does the
325// scheduling)
[email protected]f0c2a242013-03-15 19:34:52326void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
[email protected]ccc08dc2014-01-30 07:33:20327 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately");
[email protected]51f81da2014-05-16 21:29:26328 DCHECK(Proxy::IsMainThread());
[email protected]497edf82014-05-20 21:53:15329 DCHECK(!layer_tree_host_->output_surface_lost());
[email protected]51f81da2014-05-16 21:29:26330
[email protected]dfbded22014-06-28 17:57:32331 layer_tree_host_->AnimateLayers(frame_begin_time);
332
333 if (PrioritizedResourceManager* contents_texture_manager =
334 layer_tree_host_->contents_texture_manager()) {
335 contents_texture_manager->UnlinkAndClearEvictedBackings();
336 contents_texture_manager->SetMaxMemoryLimitBytes(
337 layer_tree_host_impl_->memory_allocation_limit_bytes());
338 contents_texture_manager->SetExternalPriorityCutoff(
339 layer_tree_host_impl_->memory_allocation_priority_cutoff());
340 }
341
342 scoped_ptr<ResourceUpdateQueue> queue =
343 make_scoped_ptr(new ResourceUpdateQueue);
344 layer_tree_host_->UpdateLayers(queue.get());
345 layer_tree_host_->WillCommit();
346 DoCommit(queue.Pass());
347 layer_tree_host_->DidBeginMainFrame();
[email protected]e0341352013-04-06 05:01:20348
349 LayerTreeHostImpl::FrameData frame;
[email protected]dfbded22014-06-28 17:57:32350 if (DoComposite(frame_begin_time, &frame)) {
351 {
352 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
353 DebugScopedSetImplThread impl(this);
354
355 // This CapturePostTasks should be destroyed before
356 // DidCommitAndDrawFrame() is called since that goes out to the embedder,
357 // and we want the embedder to receive its callbacks before that.
358 // NOTE: This maintains consistent ordering with the ThreadProxy since
359 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
360 // there as the main thread is not blocked, so any posted tasks inside
361 // the swap buffers will execute first.
362 BlockingTaskRunner::CapturePostTasks blocked;
363
364 layer_tree_host_impl_->SwapBuffers(frame);
365 }
366 DidSwapFrame();
367 }
[email protected]74d9063c2013-01-18 03:14:47368}
369
[email protected]a8a049c2013-03-11 23:27:06370scoped_ptr<base::Value> SingleThreadProxy::AsValue() const {
371 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
372 {
373 // The following line casts away const modifiers because it is just
374 // setting debug state. We still want the AsValue() function and its
375 // call chain to be const throughout.
376 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
377
378 state->Set("layer_tree_host_impl",
[email protected]c1bb5af2013-03-13 19:06:27379 layer_tree_host_impl_->AsValue().release());
[email protected]a8a049c2013-03-11 23:27:06380 }
381 return state.PassAs<base::Value>();
[email protected]493067512012-09-19 23:34:10382}
383
[email protected]a8a049c2013-03-11 23:27:06384void SingleThreadProxy::ForceSerializeOnSwapBuffers() {
385 {
386 DebugScopedSetImplThread impl(this);
[email protected]04049fc2013-05-01 03:13:20387 if (layer_tree_host_impl_->renderer()) {
388 DCHECK(!layer_tree_host_->output_surface_lost());
[email protected]a8a049c2013-03-11 23:27:06389 layer_tree_host_impl_->renderer()->DoNoOp();
[email protected]04049fc2013-05-01 03:13:20390 }
[email protected]a8a049c2013-03-11 23:27:06391 }
[email protected]8947cbe2012-11-28 05:27:43392}
393
[email protected]5d8bec72014-07-03 03:03:11394bool SingleThreadProxy::SupportsImplScrolling() const {
395 return false;
396}
397
[email protected]3d9f7432013-04-06 00:35:18398bool SingleThreadProxy::ShouldComposite() const {
399 DCHECK(Proxy::IsImplThread());
400 return layer_tree_host_impl_->visible() &&
401 layer_tree_host_impl_->CanDraw();
402}
403
[email protected]d9fce6722013-08-30 01:10:01404void SingleThreadProxy::UpdateBackgroundAnimateTicking() {
405 DCHECK(Proxy::IsImplThread());
406 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
407 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer());
408}
409
[email protected]dfbded22014-06-28 17:57:32410bool SingleThreadProxy::DoComposite(
411 base::TimeTicks frame_begin_time,
412 LayerTreeHostImpl::FrameData* frame) {
[email protected]ccc08dc2014-01-30 07:33:20413 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite");
[email protected]04049fc2013-05-01 03:13:20414 DCHECK(!layer_tree_host_->output_surface_lost());
415
[email protected]dfbded22014-06-28 17:57:32416 bool lost_output_surface = false;
[email protected]a8a049c2013-03-11 23:27:06417 {
418 DebugScopedSetImplThread impl(this);
419 base::AutoReset<bool> mark_inside(&inside_draw_, true);
420
[email protected]3d9f7432013-04-06 00:35:18421 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
422 // frame, so can only be used when such a frame is possible. Since
423 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
424 // CanDraw() as well.
[email protected]2aae96792014-05-15 23:10:50425 if (!ShouldComposite()) {
[email protected]d9fce6722013-08-30 01:10:01426 UpdateBackgroundAnimateTicking();
[email protected]dfbded22014-06-28 17:57:32427 return false;
[email protected]3d9f7432013-04-06 00:35:18428 }
[email protected]a8a049c2013-03-11 23:27:06429
[email protected]fb7425a2013-04-22 16:28:55430 layer_tree_host_impl_->Animate(
[email protected]27152642014-03-11 20:42:00431 layer_tree_host_impl_->CurrentFrameTimeTicks());
[email protected]d9fce6722013-08-30 01:10:01432 UpdateBackgroundAnimateTicking();
[email protected]a8a049c2013-03-11 23:27:06433
[email protected]13044fe72013-12-02 20:52:19434 if (!layer_tree_host_impl_->IsContextLost()) {
[email protected]2aae96792014-05-15 23:10:50435 layer_tree_host_impl_->PrepareToDraw(frame);
[email protected]13044fe72013-12-02 20:52:19436 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time);
437 layer_tree_host_impl_->DidDrawAllLayers(*frame);
438 }
[email protected]dfbded22014-06-28 17:57:32439 lost_output_surface = layer_tree_host_impl_->IsContextLost();
[email protected]a8a049c2013-03-11 23:27:06440
[email protected]3d9f7432013-04-06 00:35:18441 bool start_ready_animations = true;
442 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
443
[email protected]8347d692013-05-17 23:22:38444 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame();
[email protected]a8a049c2013-03-11 23:27:06445 }
446
[email protected]dfbded22014-06-28 17:57:32447 if (lost_output_surface) {
448 layer_tree_host_->DidLoseOutputSurface();
449 return false;
[email protected]1120afab2014-06-28 05:35:54450 }
[email protected]1120afab2014-06-28 05:35:54451
[email protected]dfbded22014-06-28 17:57:32452 return true;
[email protected]a8a049c2013-03-11 23:27:06453}
454
[email protected]dfbded22014-06-28 17:57:32455void SingleThreadProxy::DidSwapFrame() {
[email protected]a8a049c2013-03-11 23:27:06456 if (next_frame_is_newly_committed_frame_) {
457 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21458 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06459 }
460}
461
462bool SingleThreadProxy::CommitPendingForTesting() { return false; }
463
[email protected]bc5e77c2012-11-05 20:00:49464} // namespace cc