blob: f4007330011329151558931a8b3955779ab44ab3 [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,
[email protected]27e6a212014-07-18 15:51:2725 LayerTreeHostSingleThreadClient* client,
26 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) {
[email protected]a8a049c2013-03-11 23:27:0627 return make_scoped_ptr(
[email protected]27e6a212014-07-18 15:51:2728 new SingleThreadProxy(layer_tree_host, client, main_task_runner))
29 .PassAs<Proxy>();
[email protected]94f206c12012-08-25 00:09:1430}
31
[email protected]27e6a212014-07-18 15:51:2732SingleThreadProxy::SingleThreadProxy(
33 LayerTreeHost* layer_tree_host,
34 LayerTreeHostSingleThreadClient* client,
35 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner)
36 : Proxy(main_task_runner, NULL),
[email protected]a8a049c2013-03-11 23:27:0637 layer_tree_host_(layer_tree_host),
[email protected]943528e2013-11-07 05:01:3238 client_(client),
[email protected]a8a049c2013-03-11 23:27:0639 next_frame_is_newly_committed_frame_(false),
[email protected]2decdd782014-08-13 22:36:0640 inside_draw_(false) {
[email protected]a8a049c2013-03-11 23:27:0641 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
42 DCHECK(Proxy::IsMainThread());
43 DCHECK(layer_tree_host);
[email protected]1e4c352b2013-01-10 02:05:2344
[email protected]089102b2013-03-14 03:54:5645 // Impl-side painting not supported without threaded compositing.
[email protected]d9c086a2013-04-17 16:12:4846 CHECK(!layer_tree_host->settings().impl_side_painting)
47 << "Threaded compositing must be enabled to use impl-side painting.";
[email protected]94f206c12012-08-25 00:09:1448}
49
[email protected]e96e3432013-12-19 18:56:0750void SingleThreadProxy::Start() {
[email protected]a8a049c2013-03-11 23:27:0651 DebugScopedSetImplThread impl(this);
[email protected]804c8982013-03-13 16:32:2152 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
[email protected]a8a049c2013-03-11 23:27:0653}
54
55SingleThreadProxy::~SingleThreadProxy() {
56 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy");
57 DCHECK(Proxy::IsMainThread());
[email protected]04049fc2013-05-01 03:13:2058 // Make sure Stop() got called or never Started.
59 DCHECK(!layer_tree_host_impl_);
[email protected]a8a049c2013-03-11 23:27:0660}
61
[email protected]a8a049c2013-03-11 23:27:0662void SingleThreadProxy::FinishAllRendering() {
[email protected]ccc08dc2014-01-30 07:33:2063 TRACE_EVENT0("cc", "SingleThreadProxy::FinishAllRendering");
[email protected]a8a049c2013-03-11 23:27:0664 DCHECK(Proxy::IsMainThread());
65 {
[email protected]61de5812012-11-08 07:03:4466 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:2767 layer_tree_host_impl_->FinishAllRendering();
[email protected]a8a049c2013-03-11 23:27:0668 }
[email protected]94f206c12012-08-25 00:09:1469}
70
[email protected]a8a049c2013-03-11 23:27:0671bool SingleThreadProxy::IsStarted() const {
72 DCHECK(Proxy::IsMainThread());
[email protected]3209161d2013-03-29 19:17:3473 return layer_tree_host_impl_;
[email protected]94f206c12012-08-25 00:09:1474}
75
[email protected]14bd5542013-05-08 21:51:3076void SingleThreadProxy::SetLayerTreeHostClientReady() {
[email protected]ccc08dc2014-01-30 07:33:2077 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady");
[email protected]a8a049c2013-03-11 23:27:0678 // Scheduling is controlled by the embedder in the single thread case, so
79 // nothing to do.
[email protected]a8a049c2013-03-11 23:27:0680}
81
82void SingleThreadProxy::SetVisible(bool visible) {
[email protected]ccc08dc2014-01-30 07:33:2083 TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible");
[email protected]f7c01c82013-07-02 22:58:4684 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:2785 layer_tree_host_impl_->SetVisible(visible);
[email protected]2decdd782014-08-13 22:36:0686
[email protected]8ea875b2013-08-07 00:32:1287 // Changing visibility could change ShouldComposite().
[email protected]d9fce6722013-08-30 01:10:0188 UpdateBackgroundAnimateTicking();
[email protected]a8a049c2013-03-11 23:27:0689}
90
[email protected]04049fc2013-05-01 03:13:2091void SingleThreadProxy::CreateAndInitializeOutputSurface() {
92 TRACE_EVENT0(
93 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface");
[email protected]a8a049c2013-03-11 23:27:0694 DCHECK(Proxy::IsMainThread());
[email protected]497edf82014-05-20 21:53:1595 DCHECK(layer_tree_host_->output_surface_lost());
[email protected]94f206c12012-08-25 00:09:1496
[email protected]e96e3432013-12-19 18:56:0797 scoped_ptr<OutputSurface> output_surface =
98 layer_tree_host_->CreateOutputSurface();
[email protected]04049fc2013-05-01 03:13:2099
[email protected]da8e3b72b2014-04-25 02:33:45100 renderer_capabilities_for_main_thread_ = RendererCapabilities();
101
102 bool success = !!output_surface;
103 if (success) {
[email protected]819b9f52013-09-22 23:29:51104 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
[email protected]a8a049c2013-03-11 23:27:06105 DebugScopedSetImplThread impl(this);
[email protected]804c8982013-03-13 16:32:21106 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27107 layer_tree_host_impl_->resource_provider());
[email protected]da8e3b72b2014-04-25 02:33:45108 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass());
[email protected]04049fc2013-05-01 03:13:20109 }
110
[email protected]da8e3b72b2014-04-25 02:33:45111 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success);
[email protected]04049fc2013-05-01 03:13:20112
[email protected]2decdd782014-08-13 22:36:06113 if (!success) {
114 // Force another recreation attempt to happen by requesting another commit.
115 SetNeedsCommit();
[email protected]04049fc2013-05-01 03:13:20116 }
[email protected]94f206c12012-08-25 00:09:14117}
118
[email protected]a8a049c2013-03-11 23:27:06119const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const {
[email protected]04049fc2013-05-01 03:13:20120 DCHECK(Proxy::IsMainThread());
121 DCHECK(!layer_tree_host_->output_surface_lost());
[email protected]a8a049c2013-03-11 23:27:06122 return renderer_capabilities_for_main_thread_;
[email protected]94f206c12012-08-25 00:09:14123}
124
[email protected]8b9e52b2014-01-17 16:35:31125void SingleThreadProxy::SetNeedsAnimate() {
[email protected]ccc08dc2014-01-30 07:33:20126 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate");
[email protected]c5134172013-12-11 06:19:48127 DCHECK(Proxy::IsMainThread());
[email protected]06cbc31b2014-01-17 06:43:20128 client_->ScheduleAnimation();
[email protected]c5134172013-12-11 06:19:48129}
130
[email protected]8b9e52b2014-01-17 16:35:31131void SingleThreadProxy::SetNeedsUpdateLayers() {
[email protected]ccc08dc2014-01-30 07:33:20132 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers");
[email protected]8b9e52b2014-01-17 16:35:31133 DCHECK(Proxy::IsMainThread());
[email protected]2decdd782014-08-13 22:36:06134 client_->ScheduleComposite();
[email protected]8b9e52b2014-01-17 16:35:31135}
136
[email protected]2decdd782014-08-13 22:36:06137void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) {
[email protected]ccc08dc2014-01-30 07:33:20138 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit");
[email protected]a8a049c2013-03-11 23:27:06139 DCHECK(Proxy::IsMainThread());
[email protected]a8a049c2013-03-11 23:27:06140 // Commit immediately.
141 {
[email protected]819b9f52013-09-22 23:29:51142 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
[email protected]f7c01c82013-07-02 22:58:46143 DebugScopedSetImplThread impl(this);
144
[email protected]9794fb32013-08-29 09:49:59145 // This CapturePostTasks should be destroyed before CommitComplete() is
146 // called since that goes out to the embedder, and we want the embedder
147 // to receive its callbacks before that.
148 BlockingTaskRunner::CapturePostTasks blocked;
149
[email protected]c1bb5af2013-03-13 19:06:27150 layer_tree_host_impl_->BeginCommit();
[email protected]94f206c12012-08-25 00:09:14151
[email protected]5d2fec02013-11-28 20:08:33152 if (PrioritizedResourceManager* contents_texture_manager =
153 layer_tree_host_->contents_texture_manager()) {
154 contents_texture_manager->PushTexturePrioritiesToBackings();
[email protected]6e8c54922013-06-02 19:17:35155 }
[email protected]804c8982013-03-13 16:32:21156 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14157
[email protected]ed511b8d2013-03-25 03:29:29158 scoped_ptr<ResourceUpdateController> update_controller =
[email protected]a8a049c2013-03-11 23:27:06159 ResourceUpdateController::Create(
160 NULL,
[email protected]2decdd782014-08-13 22:36:06161 Proxy::MainThreadTaskRunner(),
[email protected]a8a049c2013-03-11 23:27:06162 queue.Pass(),
[email protected]c1bb5af2013-03-13 19:06:27163 layer_tree_host_impl_->resource_provider());
[email protected]ed511b8d2013-03-25 03:29:29164 update_controller->Finalize();
[email protected]94f206c12012-08-25 00:09:14165
[email protected]127bdc1a2013-09-11 01:44:48166 if (layer_tree_host_impl_->EvictedUIResourcesExist())
167 layer_tree_host_->RecreateUIResources();
168
[email protected]804c8982013-03-13 16:32:21169 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14170
[email protected]c1bb5af2013-03-13 19:06:27171 layer_tree_host_impl_->CommitComplete();
[email protected]94f206c12012-08-25 00:09:14172
[email protected]767f38d72014-03-18 21:26:41173#if DCHECK_IS_ON
[email protected]3519b872013-07-30 07:17:50174 // In the single-threaded case, the scale and scroll deltas should never be
[email protected]a8a049c2013-03-11 23:27:06175 // touched on the impl layer tree.
[email protected]ed511b8d2013-03-25 03:29:29176 scoped_ptr<ScrollAndScaleSet> scroll_info =
[email protected]c1bb5af2013-03-13 19:06:27177 layer_tree_host_impl_->ProcessScrollDeltas();
[email protected]ed511b8d2013-03-25 03:29:29178 DCHECK(!scroll_info->scrolls.size());
[email protected]3519b872013-07-30 07:17:50179 DCHECK_EQ(1.f, scroll_info->page_scale_delta);
[email protected]94f206c12012-08-25 00:09:14180#endif
[email protected]8b9af6b2012-09-27 00:36:36181
[email protected]922c6e1f2013-10-09 04:04:09182 RenderingStatsInstrumentation* stats_instrumentation =
183 layer_tree_host_->rendering_stats_instrumentation();
[email protected]1bbed7a2014-07-08 02:54:00184 benchmark_instrumentation::IssueMainThreadRenderingStatsEvent(
[email protected]adbe30f2013-10-11 21:12:33185 stats_instrumentation->main_thread_rendering_stats());
[email protected]a9dc0d0f2013-08-17 02:43:18186 stats_instrumentation->AccumulateAndClearMainThreadStats();
[email protected]a8a049c2013-03-11 23:27:06187 }
[email protected]804c8982013-03-13 16:32:21188 layer_tree_host_->CommitComplete();
[email protected]a8a049c2013-03-11 23:27:06189 next_frame_is_newly_committed_frame_ = true;
[email protected]94f206c12012-08-25 00:09:14190}
191
[email protected]a8a049c2013-03-11 23:27:06192void SingleThreadProxy::SetNeedsCommit() {
193 DCHECK(Proxy::IsMainThread());
[email protected]943528e2013-11-07 05:01:32194 client_->ScheduleComposite();
[email protected]94f206c12012-08-25 00:09:14195}
196
[email protected]0023fc72014-01-10 20:05:06197void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) {
[email protected]ccc08dc2014-01-30 07:33:20198 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw");
[email protected]174c6d42014-08-12 01:43:06199 SetNeedsRedrawRectOnImplThread(damage_rect);
[email protected]2decdd782014-08-13 22:36:06200 client_->ScheduleComposite();
[email protected]94f206c12012-08-25 00:09:14201}
202
[email protected]74b43cc2013-08-30 06:29:27203void SingleThreadProxy::SetNextCommitWaitsForActivation() {
204 // There is no activation here other than commit. So do nothing.
[email protected]74b43cc2013-08-30 06:29:27205}
206
[email protected]a8a049c2013-03-11 23:27:06207void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
[email protected]6b16679e2012-10-27 00:44:28208}
209
[email protected]174c6d42014-08-12 01:43:06210bool SingleThreadProxy::CommitRequested() const {
[email protected]2decdd782014-08-13 22:36:06211 return false;
[email protected]174c6d42014-08-12 01:43:06212}
[email protected]a8a049c2013-03-11 23:27:06213
[email protected]174c6d42014-08-12 01:43:06214bool SingleThreadProxy::BeginMainFrameRequested() const {
[email protected]2decdd782014-08-13 22:36:06215 return false;
[email protected]174c6d42014-08-12 01:43:06216}
[email protected]971728d2013-10-26 10:39:31217
[email protected]a8a049c2013-03-11 23:27:06218size_t SingleThreadProxy::MaxPartialTextureUpdates() const {
219 return std::numeric_limits<size_t>::max();
220}
221
222void SingleThreadProxy::Stop() {
223 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
224 DCHECK(Proxy::IsMainThread());
225 {
[email protected]819b9f52013-09-22 23:29:51226 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
[email protected]a8a049c2013-03-11 23:27:06227 DebugScopedSetImplThread impl(this);
228
[email protected]446b23d2014-05-16 18:24:18229 BlockingTaskRunner::CapturePostTasks blocked;
[email protected]804c8982013-03-13 16:32:21230 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27231 layer_tree_host_impl_->resource_provider());
[email protected]a8a049c2013-03-11 23:27:06232 layer_tree_host_impl_.reset();
233 }
[email protected]7aba6662013-03-12 10:17:34234 layer_tree_host_ = NULL;
[email protected]a8a049c2013-03-11 23:27:06235}
236
[email protected]3d9f7432013-04-06 00:35:18237void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
[email protected]ccc08dc2014-01-30 07:33:20238 TRACE_EVENT1(
239 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
[email protected]3d9f7432013-04-06 00:35:18240 DCHECK(Proxy::IsImplThread());
[email protected]d9fce6722013-08-30 01:10:01241 UpdateBackgroundAnimateTicking();
[email protected]3d9f7432013-04-06 00:35:18242}
243
[email protected]4f48f6e2013-08-27 06:33:38244void SingleThreadProxy::NotifyReadyToActivate() {
[email protected]2decdd782014-08-13 22:36:06245 // Thread-only feature.
[email protected]4f48f6e2013-08-27 06:33:38246 NOTREACHED();
247}
248
[email protected]c1bb5af2013-03-13 19:06:27249void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
[email protected]943528e2013-11-07 05:01:32250 client_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06251}
252
[email protected]43b8f982014-04-30 21:24:33253void SingleThreadProxy::SetNeedsAnimateOnImplThread() {
254 SetNeedsRedrawOnImplThread();
255}
256
[email protected]c48536a52013-09-14 00:02:08257void SingleThreadProxy::SetNeedsManageTilesOnImplThread() {
[email protected]2decdd782014-08-13 22:36:06258 // Thread-only/Impl-side-painting-only feature.
[email protected]c48536a52013-09-14 00:02:08259 NOTREACHED();
260}
261
[email protected]0023fc72014-01-10 20:05:06262void SingleThreadProxy::SetNeedsRedrawRectOnImplThread(
263 const gfx::Rect& damage_rect) {
[email protected]2decdd782014-08-13 22:36:06264 // TODO(brianderson): Once we move render_widget scheduling into this class,
265 // we can treat redraw requests more efficiently than CommitAndRedraw
266 // requests.
[email protected]1cd9f5552013-04-26 04:22:03267 layer_tree_host_impl_->SetViewportDamage(damage_rect);
[email protected]2decdd782014-08-13 22:36:06268 SetNeedsCommit();
[email protected]1cd9f5552013-04-26 04:22:03269}
270
[email protected]86126792013-03-16 20:07:54271void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06272 // Impl-side painting only.
273 NOTREACHED();
274}
275
[email protected]c1bb5af2013-03-13 19:06:27276void SingleThreadProxy::SetNeedsCommitOnImplThread() {
[email protected]943528e2013-11-07 05:01:32277 client_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06278}
279
[email protected]c1bb5af2013-03-13 19:06:27280void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
[email protected]85b57502014-03-11 15:37:48281 scoped_ptr<AnimationEventsVector> events) {
[email protected]ccc08dc2014-01-30 07:33:20282 TRACE_EVENT0(
283 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
[email protected]a8a049c2013-03-11 23:27:06284 DCHECK(Proxy::IsImplThread());
285 DebugScopedSetMainThread main(this);
[email protected]85b57502014-03-11 15:37:48286 layer_tree_host_->SetAnimationEvents(events.Pass());
[email protected]a8a049c2013-03-11 23:27:06287}
288
[email protected]c1bb5af2013-03-13 19:06:27289bool SingleThreadProxy::ReduceContentsTextureMemoryOnImplThread(
[email protected]a8a049c2013-03-11 23:27:06290 size_t limit_bytes,
291 int priority_cutoff) {
292 DCHECK(IsImplThread());
[email protected]5d2fec02013-11-28 20:08:33293 PrioritizedResourceManager* contents_texture_manager =
294 layer_tree_host_->contents_texture_manager();
295
296 ResourceProvider* resource_provider =
297 layer_tree_host_impl_->resource_provider();
298
299 if (!contents_texture_manager || !resource_provider)
[email protected]e7595ead2013-10-10 10:10:07300 return false;
[email protected]a8a049c2013-03-11 23:27:06301
[email protected]5d2fec02013-11-28 20:08:33302 return contents_texture_manager->ReduceMemoryOnImplThread(
303 limit_bytes, priority_cutoff, resource_provider);
[email protected]94f206c12012-08-25 00:09:14304}
305
[email protected]c1bb5af2013-03-13 19:06:27306bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
[email protected]a8a049c2013-03-11 23:27:06307
[email protected]fa339032014-02-18 22:11:59308void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() {
309 DCHECK(IsImplThread());
310 renderer_capabilities_for_main_thread_ =
311 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities();
312}
313
[email protected]c1bb5af2013-03-13 19:06:27314void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
[email protected]ccc08dc2014-01-30 07:33:20315 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread");
[email protected]2decdd782014-08-13 22:36:06316 // Cause a commit so we can notice the lost context.
317 SetNeedsCommitOnImplThread();
[email protected]4d7e46a2013-11-08 05:33:40318 client_->DidAbortSwapBuffers();
[email protected]4d7e46a2013-11-08 05:33:40319}
320
321void SingleThreadProxy::DidSwapBuffersOnImplThread() {
[email protected]4d7e46a2013-11-08 05:33:40322 client_->DidPostSwapBuffers();
323}
324
[email protected]c14902662014-04-18 05:06:11325void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() {
326 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread");
[email protected]2decdd782014-08-13 22:36:06327 client_->DidCompleteSwapBuffers();
[email protected]493067512012-09-19 23:34:10328}
329
[email protected]2decdd782014-08-13 22:36:06330// Called by the legacy scheduling path (e.g. where render_widget does the
331// scheduling)
[email protected]f0c2a242013-03-15 19:34:52332void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
[email protected]ccc08dc2014-01-30 07:33:20333 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately");
[email protected]51f81da2014-05-16 21:29:26334 DCHECK(Proxy::IsMainThread());
[email protected]497edf82014-05-20 21:53:15335 DCHECK(!layer_tree_host_->output_surface_lost());
[email protected]51f81da2014-05-16 21:29:26336
[email protected]2decdd782014-08-13 22:36:06337 layer_tree_host_->AnimateLayers(frame_begin_time);
338
339 if (PrioritizedResourceManager* contents_texture_manager =
340 layer_tree_host_->contents_texture_manager()) {
341 contents_texture_manager->UnlinkAndClearEvictedBackings();
342 contents_texture_manager->SetMaxMemoryLimitBytes(
343 layer_tree_host_impl_->memory_allocation_limit_bytes());
344 contents_texture_manager->SetExternalPriorityCutoff(
345 layer_tree_host_impl_->memory_allocation_priority_cutoff());
346 }
347
348 scoped_ptr<ResourceUpdateQueue> queue =
349 make_scoped_ptr(new ResourceUpdateQueue);
350 layer_tree_host_->UpdateLayers(queue.get());
351 layer_tree_host_->WillCommit();
352 DoCommit(queue.Pass());
353 layer_tree_host_->DidBeginMainFrame();
[email protected]e0341352013-04-06 05:01:20354
355 LayerTreeHostImpl::FrameData frame;
[email protected]2decdd782014-08-13 22:36:06356 if (DoComposite(frame_begin_time, &frame)) {
357 {
358 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
359 DebugScopedSetImplThread impl(this);
360
361 // This CapturePostTasks should be destroyed before
362 // DidCommitAndDrawFrame() is called since that goes out to the embedder,
363 // and we want the embedder to receive its callbacks before that.
364 // NOTE: This maintains consistent ordering with the ThreadProxy since
365 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
366 // there as the main thread is not blocked, so any posted tasks inside
367 // the swap buffers will execute first.
368 BlockingTaskRunner::CapturePostTasks blocked;
369
370 layer_tree_host_impl_->SwapBuffers(frame);
371 }
372 DidSwapFrame();
373 }
[email protected]74d9063c2013-01-18 03:14:47374}
375
[email protected]d12aa932014-08-01 13:10:38376void SingleThreadProxy::AsValueInto(base::debug::TracedValue* state) const {
377 // The following line casts away const modifiers because it is just
378 // setting debug state. We still want the AsValue() function and its
379 // call chain to be const throughout.
380 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
[email protected]a8a049c2013-03-11 23:27:06381
[email protected]d12aa932014-08-01 13:10:38382 state->BeginDictionary("layer_tree_host_impl");
383 layer_tree_host_impl_->AsValueInto(state);
384 state->EndDictionary();
[email protected]493067512012-09-19 23:34:10385}
386
[email protected]a8a049c2013-03-11 23:27:06387void SingleThreadProxy::ForceSerializeOnSwapBuffers() {
388 {
389 DebugScopedSetImplThread impl(this);
[email protected]04049fc2013-05-01 03:13:20390 if (layer_tree_host_impl_->renderer()) {
391 DCHECK(!layer_tree_host_->output_surface_lost());
[email protected]a8a049c2013-03-11 23:27:06392 layer_tree_host_impl_->renderer()->DoNoOp();
[email protected]04049fc2013-05-01 03:13:20393 }
[email protected]a8a049c2013-03-11 23:27:06394 }
[email protected]8947cbe2012-11-28 05:27:43395}
396
[email protected]5d8bec72014-07-03 03:03:11397bool SingleThreadProxy::SupportsImplScrolling() const {
398 return false;
399}
400
[email protected]3d9f7432013-04-06 00:35:18401bool SingleThreadProxy::ShouldComposite() const {
402 DCHECK(Proxy::IsImplThread());
403 return layer_tree_host_impl_->visible() &&
404 layer_tree_host_impl_->CanDraw();
405}
406
[email protected]d9fce6722013-08-30 01:10:01407void SingleThreadProxy::UpdateBackgroundAnimateTicking() {
408 DCHECK(Proxy::IsImplThread());
409 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
410 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer());
411}
412
[email protected]2decdd782014-08-13 22:36:06413bool SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time,
414 LayerTreeHostImpl::FrameData* frame) {
[email protected]ccc08dc2014-01-30 07:33:20415 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite");
[email protected]04049fc2013-05-01 03:13:20416 DCHECK(!layer_tree_host_->output_surface_lost());
417
[email protected]2decdd782014-08-13 22:36:06418 bool lost_output_surface = false;
[email protected]a8a049c2013-03-11 23:27:06419 {
420 DebugScopedSetImplThread impl(this);
421 base::AutoReset<bool> mark_inside(&inside_draw_, true);
422
[email protected]3d9f7432013-04-06 00:35:18423 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
424 // frame, so can only be used when such a frame is possible. Since
425 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
426 // CanDraw() as well.
[email protected]2aae96792014-05-15 23:10:50427 if (!ShouldComposite()) {
[email protected]d9fce6722013-08-30 01:10:01428 UpdateBackgroundAnimateTicking();
[email protected]2decdd782014-08-13 22:36:06429 return false;
[email protected]3d9f7432013-04-06 00:35:18430 }
[email protected]a8a049c2013-03-11 23:27:06431
[email protected]fb7425a2013-04-22 16:28:55432 layer_tree_host_impl_->Animate(
[email protected]27152642014-03-11 20:42:00433 layer_tree_host_impl_->CurrentFrameTimeTicks());
[email protected]d9fce6722013-08-30 01:10:01434 UpdateBackgroundAnimateTicking();
[email protected]a8a049c2013-03-11 23:27:06435
[email protected]13044fe72013-12-02 20:52:19436 if (!layer_tree_host_impl_->IsContextLost()) {
[email protected]2aae96792014-05-15 23:10:50437 layer_tree_host_impl_->PrepareToDraw(frame);
[email protected]2e316b272014-07-19 05:01:20438 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time);
[email protected]13044fe72013-12-02 20:52:19439 layer_tree_host_impl_->DidDrawAllLayers(*frame);
440 }
[email protected]2decdd782014-08-13 22:36:06441 lost_output_surface = layer_tree_host_impl_->IsContextLost();
[email protected]a8a049c2013-03-11 23:27:06442
[email protected]3d9f7432013-04-06 00:35:18443 bool start_ready_animations = true;
444 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
445
[email protected]8347d692013-05-17 23:22:38446 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame();
[email protected]a8a049c2013-03-11 23:27:06447 }
448
[email protected]2decdd782014-08-13 22:36:06449 if (lost_output_surface) {
450 layer_tree_host_->DidLoseOutputSurface();
451 return false;
[email protected]174c6d42014-08-12 01:43:06452 }
[email protected]174c6d42014-08-12 01:43:06453
[email protected]2decdd782014-08-13 22:36:06454 return true;
[email protected]a8a049c2013-03-11 23:27:06455}
456
[email protected]2decdd782014-08-13 22:36:06457void SingleThreadProxy::DidSwapFrame() {
[email protected]a8a049c2013-03-11 23:27:06458 if (next_frame_is_newly_committed_frame_) {
[email protected]a8a049c2013-03-11 23:27:06459 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21460 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06461 }
462}
463
[email protected]4ea293f72014-08-13 03:03:17464bool SingleThreadProxy::MainFrameWillHappenForTesting() {
465 return false;
466}
[email protected]a8a049c2013-03-11 23:27:06467
[email protected]bc5e77c2012-11-05 20:00:49468} // namespace cc