blob: a70e08f970cd5b2dd298afdd908f0901d5fe1299 [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]ccd6d9d2013-03-30 19:08:5836 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]0023fc72014-01-10 20:05:0658bool SingleThreadProxy::CompositeAndReadback(void* pixels,
59 const gfx::Rect& rect) {
[email protected]ed511b8d2013-03-25 03:29:2960 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeAndReadback");
[email protected]a8a049c2013-03-11 23:27:0661 DCHECK(Proxy::IsMainThread());
62
[email protected]e0341352013-04-06 05:01:2063 gfx::Rect device_viewport_damage_rect = rect;
64
65 LayerTreeHostImpl::FrameData frame;
[email protected]de2cf8c2013-10-25 19:46:4666 if (!CommitAndComposite(gfx::FrameTime::Now(),
[email protected]e0341352013-04-06 05:01:2067 device_viewport_damage_rect,
[email protected]2921d042013-05-10 05:01:3968 true, // for_readback
[email protected]e0341352013-04-06 05:01:2069 &frame))
[email protected]a8a049c2013-03-11 23:27:0670 return false;
71
72 {
[email protected]61de5812012-11-08 07:03:4473 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:2774 layer_tree_host_impl_->Readback(pixels, rect);
[email protected]a8a049c2013-03-11 23:27:0675
[email protected]c1bb5af2013-03-13 19:06:2776 if (layer_tree_host_impl_->IsContextLost())
[email protected]a8a049c2013-03-11 23:27:0677 return false;
[email protected]a8a049c2013-03-11 23:27:0678 }
[email protected]a8a049c2013-03-11 23:27:0679
80 return true;
[email protected]94f206c12012-08-25 00:09:1481}
82
[email protected]a8a049c2013-03-11 23:27:0683void SingleThreadProxy::FinishAllRendering() {
[email protected]ccc08dc2014-01-30 07:33:2084 TRACE_EVENT0("cc", "SingleThreadProxy::FinishAllRendering");
[email protected]a8a049c2013-03-11 23:27:0685 DCHECK(Proxy::IsMainThread());
86 {
[email protected]61de5812012-11-08 07:03:4487 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:2788 layer_tree_host_impl_->FinishAllRendering();
[email protected]a8a049c2013-03-11 23:27:0689 }
[email protected]94f206c12012-08-25 00:09:1490}
91
[email protected]a8a049c2013-03-11 23:27:0692bool SingleThreadProxy::IsStarted() const {
93 DCHECK(Proxy::IsMainThread());
[email protected]3209161d2013-03-29 19:17:3494 return layer_tree_host_impl_;
[email protected]94f206c12012-08-25 00:09:1495}
96
[email protected]14bd5542013-05-08 21:51:3097void SingleThreadProxy::SetLayerTreeHostClientReady() {
[email protected]ccc08dc2014-01-30 07:33:2098 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady");
[email protected]a8a049c2013-03-11 23:27:0699 // Scheduling is controlled by the embedder in the single thread case, so
100 // nothing to do.
101}
102
103void SingleThreadProxy::SetVisible(bool visible) {
[email protected]ccc08dc2014-01-30 07:33:20104 TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible");
[email protected]f7c01c82013-07-02 22:58:46105 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:27106 layer_tree_host_impl_->SetVisible(visible);
[email protected]8ea875b2013-08-07 00:32:12107
108 // Changing visibility could change ShouldComposite().
[email protected]d9fce6722013-08-30 01:10:01109 UpdateBackgroundAnimateTicking();
[email protected]a8a049c2013-03-11 23:27:06110}
111
[email protected]04049fc2013-05-01 03:13:20112void SingleThreadProxy::CreateAndInitializeOutputSurface() {
113 TRACE_EVENT0(
114 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface");
[email protected]a8a049c2013-03-11 23:27:06115 DCHECK(Proxy::IsMainThread());
[email protected]94f206c12012-08-25 00:09:14116
[email protected]e96e3432013-12-19 18:56:07117 scoped_ptr<OutputSurface> output_surface =
118 layer_tree_host_->CreateOutputSurface();
[email protected]04049fc2013-05-01 03:13:20119
[email protected]da8e3b72b2014-04-25 02:33:45120 renderer_capabilities_for_main_thread_ = RendererCapabilities();
121
122 bool success = !!output_surface;
123 if (success) {
[email protected]819b9f52013-09-22 23:29:51124 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
[email protected]a8a049c2013-03-11 23:27:06125 DebugScopedSetImplThread impl(this);
[email protected]804c8982013-03-13 16:32:21126 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27127 layer_tree_host_impl_->resource_provider());
[email protected]da8e3b72b2014-04-25 02:33:45128 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass());
[email protected]04049fc2013-05-01 03:13:20129 }
130
[email protected]da8e3b72b2014-04-25 02:33:45131 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success);
[email protected]04049fc2013-05-01 03:13:20132
[email protected]da8e3b72b2014-04-25 02:33:45133 if (!success) {
[email protected]04049fc2013-05-01 03:13:20134 // Force another recreation attempt to happen by requesting another commit.
135 SetNeedsCommit();
136 }
[email protected]94f206c12012-08-25 00:09:14137}
138
[email protected]a8a049c2013-03-11 23:27:06139const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const {
[email protected]04049fc2013-05-01 03:13:20140 DCHECK(Proxy::IsMainThread());
141 DCHECK(!layer_tree_host_->output_surface_lost());
[email protected]a8a049c2013-03-11 23:27:06142 return renderer_capabilities_for_main_thread_;
[email protected]94f206c12012-08-25 00:09:14143}
144
[email protected]8b9e52b2014-01-17 16:35:31145void SingleThreadProxy::SetNeedsAnimate() {
[email protected]ccc08dc2014-01-30 07:33:20146 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate");
[email protected]c5134172013-12-11 06:19:48147 DCHECK(Proxy::IsMainThread());
[email protected]06cbc31b2014-01-17 06:43:20148 client_->ScheduleAnimation();
[email protected]c5134172013-12-11 06:19:48149}
150
[email protected]8b9e52b2014-01-17 16:35:31151void SingleThreadProxy::SetNeedsUpdateLayers() {
[email protected]ccc08dc2014-01-30 07:33:20152 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers");
[email protected]8b9e52b2014-01-17 16:35:31153 DCHECK(Proxy::IsMainThread());
154 client_->ScheduleComposite();
155}
156
[email protected]a8a049c2013-03-11 23:27:06157void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) {
[email protected]ccc08dc2014-01-30 07:33:20158 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit");
[email protected]a8a049c2013-03-11 23:27:06159 DCHECK(Proxy::IsMainThread());
160 // Commit immediately.
161 {
[email protected]819b9f52013-09-22 23:29:51162 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
[email protected]f7c01c82013-07-02 22:58:46163 DebugScopedSetImplThread impl(this);
164
[email protected]9794fb32013-08-29 09:49:59165 // This CapturePostTasks should be destroyed before CommitComplete() is
166 // called since that goes out to the embedder, and we want the embedder
167 // to receive its callbacks before that.
168 BlockingTaskRunner::CapturePostTasks blocked;
169
[email protected]c1bb5af2013-03-13 19:06:27170 layer_tree_host_impl_->BeginCommit();
[email protected]94f206c12012-08-25 00:09:14171
[email protected]5d2fec02013-11-28 20:08:33172 if (PrioritizedResourceManager* contents_texture_manager =
173 layer_tree_host_->contents_texture_manager()) {
174 contents_texture_manager->PushTexturePrioritiesToBackings();
[email protected]6e8c54922013-06-02 19:17:35175 }
[email protected]804c8982013-03-13 16:32:21176 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14177
[email protected]ed511b8d2013-03-25 03:29:29178 scoped_ptr<ResourceUpdateController> update_controller =
[email protected]a8a049c2013-03-11 23:27:06179 ResourceUpdateController::Create(
180 NULL,
[email protected]810d40b72013-06-20 18:26:15181 Proxy::MainThreadTaskRunner(),
[email protected]a8a049c2013-03-11 23:27:06182 queue.Pass(),
[email protected]c1bb5af2013-03-13 19:06:27183 layer_tree_host_impl_->resource_provider());
[email protected]ed511b8d2013-03-25 03:29:29184 update_controller->Finalize();
[email protected]94f206c12012-08-25 00:09:14185
[email protected]127bdc1a2013-09-11 01:44:48186 if (layer_tree_host_impl_->EvictedUIResourcesExist())
187 layer_tree_host_->RecreateUIResources();
188
[email protected]804c8982013-03-13 16:32:21189 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14190
[email protected]c1bb5af2013-03-13 19:06:27191 layer_tree_host_impl_->CommitComplete();
[email protected]94f206c12012-08-25 00:09:14192
[email protected]767f38d72014-03-18 21:26:41193#if DCHECK_IS_ON
[email protected]3519b872013-07-30 07:17:50194 // In the single-threaded case, the scale and scroll deltas should never be
[email protected]a8a049c2013-03-11 23:27:06195 // touched on the impl layer tree.
[email protected]ed511b8d2013-03-25 03:29:29196 scoped_ptr<ScrollAndScaleSet> scroll_info =
[email protected]c1bb5af2013-03-13 19:06:27197 layer_tree_host_impl_->ProcessScrollDeltas();
[email protected]ed511b8d2013-03-25 03:29:29198 DCHECK(!scroll_info->scrolls.size());
[email protected]3519b872013-07-30 07:17:50199 DCHECK_EQ(1.f, scroll_info->page_scale_delta);
[email protected]94f206c12012-08-25 00:09:14200#endif
[email protected]8b9af6b2012-09-27 00:36:36201
[email protected]922c6e1f2013-10-09 04:04:09202 RenderingStatsInstrumentation* stats_instrumentation =
203 layer_tree_host_->rendering_stats_instrumentation();
[email protected]adbe30f2013-10-11 21:12:33204 BenchmarkInstrumentation::IssueMainThreadRenderingStatsEvent(
205 stats_instrumentation->main_thread_rendering_stats());
[email protected]a9dc0d0f2013-08-17 02:43:18206 stats_instrumentation->AccumulateAndClearMainThreadStats();
[email protected]a8a049c2013-03-11 23:27:06207 }
[email protected]804c8982013-03-13 16:32:21208 layer_tree_host_->CommitComplete();
[email protected]a8a049c2013-03-11 23:27:06209 next_frame_is_newly_committed_frame_ = true;
[email protected]94f206c12012-08-25 00:09:14210}
211
[email protected]a8a049c2013-03-11 23:27:06212void SingleThreadProxy::SetNeedsCommit() {
213 DCHECK(Proxy::IsMainThread());
[email protected]943528e2013-11-07 05:01:32214 client_->ScheduleComposite();
[email protected]94f206c12012-08-25 00:09:14215}
216
[email protected]0023fc72014-01-10 20:05:06217void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) {
[email protected]ccc08dc2014-01-30 07:33:20218 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw");
[email protected]1cd9f5552013-04-26 04:22:03219 SetNeedsRedrawRectOnImplThread(damage_rect);
[email protected]943528e2013-11-07 05:01:32220 client_->ScheduleComposite();
[email protected]94f206c12012-08-25 00:09:14221}
222
[email protected]74b43cc2013-08-30 06:29:27223void SingleThreadProxy::SetNextCommitWaitsForActivation() {
224 // There is no activation here other than commit. So do nothing.
225}
226
[email protected]a8a049c2013-03-11 23:27:06227void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
228 // Thread-only feature.
229 NOTREACHED();
[email protected]6b16679e2012-10-27 00:44:28230}
231
[email protected]a8a049c2013-03-11 23:27:06232bool SingleThreadProxy::CommitRequested() const { return false; }
233
[email protected]971728d2013-10-26 10:39:31234bool SingleThreadProxy::BeginMainFrameRequested() const { return false; }
235
[email protected]a8a049c2013-03-11 23:27:06236size_t SingleThreadProxy::MaxPartialTextureUpdates() const {
237 return std::numeric_limits<size_t>::max();
238}
239
240void SingleThreadProxy::Stop() {
241 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
242 DCHECK(Proxy::IsMainThread());
243 {
[email protected]819b9f52013-09-22 23:29:51244 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
[email protected]a8a049c2013-03-11 23:27:06245 DebugScopedSetImplThread impl(this);
246
[email protected]804c8982013-03-13 16:32:21247 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27248 layer_tree_host_impl_->resource_provider());
[email protected]a8a049c2013-03-11 23:27:06249 layer_tree_host_impl_.reset();
250 }
[email protected]7aba6662013-03-12 10:17:34251 layer_tree_host_ = NULL;
[email protected]a8a049c2013-03-11 23:27:06252}
253
[email protected]3d9f7432013-04-06 00:35:18254void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
[email protected]ccc08dc2014-01-30 07:33:20255 TRACE_EVENT1(
256 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
[email protected]3d9f7432013-04-06 00:35:18257 DCHECK(Proxy::IsImplThread());
[email protected]d9fce6722013-08-30 01:10:01258 UpdateBackgroundAnimateTicking();
[email protected]3d9f7432013-04-06 00:35:18259}
260
[email protected]4f48f6e2013-08-27 06:33:38261void SingleThreadProxy::NotifyReadyToActivate() {
262 // Thread-only feature.
263 NOTREACHED();
264}
265
[email protected]c1bb5af2013-03-13 19:06:27266void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
[email protected]943528e2013-11-07 05:01:32267 client_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06268}
269
[email protected]c48536a52013-09-14 00:02:08270void SingleThreadProxy::SetNeedsManageTilesOnImplThread() {
271 // Thread-only/Impl-side-painting-only feature.
272 NOTREACHED();
273}
274
[email protected]0023fc72014-01-10 20:05:06275void SingleThreadProxy::SetNeedsRedrawRectOnImplThread(
276 const gfx::Rect& damage_rect) {
[email protected]27d851ab2013-06-28 01:09:50277 // TODO(brianderson): Once we move render_widget scheduling into this class,
278 // we can treat redraw requests more efficiently than CommitAndRedraw
279 // requests.
[email protected]1cd9f5552013-04-26 04:22:03280 layer_tree_host_impl_->SetViewportDamage(damage_rect);
281 SetNeedsCommit();
282}
283
[email protected]86126792013-03-16 20:07:54284void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06285 // Impl-side painting only.
286 NOTREACHED();
287}
288
[email protected]c1bb5af2013-03-13 19:06:27289void SingleThreadProxy::SetNeedsCommitOnImplThread() {
[email protected]943528e2013-11-07 05:01:32290 client_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06291}
292
[email protected]c1bb5af2013-03-13 19:06:27293void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
[email protected]85b57502014-03-11 15:37:48294 scoped_ptr<AnimationEventsVector> events) {
[email protected]ccc08dc2014-01-30 07:33:20295 TRACE_EVENT0(
296 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
[email protected]a8a049c2013-03-11 23:27:06297 DCHECK(Proxy::IsImplThread());
298 DebugScopedSetMainThread main(this);
[email protected]85b57502014-03-11 15:37:48299 layer_tree_host_->SetAnimationEvents(events.Pass());
[email protected]a8a049c2013-03-11 23:27:06300}
301
[email protected]c1bb5af2013-03-13 19:06:27302bool SingleThreadProxy::ReduceContentsTextureMemoryOnImplThread(
[email protected]a8a049c2013-03-11 23:27:06303 size_t limit_bytes,
304 int priority_cutoff) {
305 DCHECK(IsImplThread());
[email protected]5d2fec02013-11-28 20:08:33306 PrioritizedResourceManager* contents_texture_manager =
307 layer_tree_host_->contents_texture_manager();
308
309 ResourceProvider* resource_provider =
310 layer_tree_host_impl_->resource_provider();
311
312 if (!contents_texture_manager || !resource_provider)
[email protected]e7595ead2013-10-10 10:10:07313 return false;
[email protected]a8a049c2013-03-11 23:27:06314
[email protected]5d2fec02013-11-28 20:08:33315 return contents_texture_manager->ReduceMemoryOnImplThread(
316 limit_bytes, priority_cutoff, resource_provider);
[email protected]94f206c12012-08-25 00:09:14317}
318
[email protected]c1bb5af2013-03-13 19:06:27319void SingleThreadProxy::SendManagedMemoryStats() {
[email protected]a8a049c2013-03-11 23:27:06320 DCHECK(Proxy::IsImplThread());
[email protected]384b2c5e2013-04-23 01:02:22321 if (!layer_tree_host_impl_)
[email protected]a8a049c2013-03-11 23:27:06322 return;
[email protected]804c8982013-03-13 16:32:21323 PrioritizedResourceManager* contents_texture_manager =
324 layer_tree_host_->contents_texture_manager();
[email protected]5d2fec02013-11-28 20:08:33325 if (!contents_texture_manager)
326 return;
327
[email protected]c1bb5af2013-03-13 19:06:27328 layer_tree_host_impl_->SendManagedMemoryStats(
[email protected]b56c1302013-03-20 21:17:34329 contents_texture_manager->MemoryVisibleBytes(),
330 contents_texture_manager->MemoryVisibleAndNearbyBytes(),
331 contents_texture_manager->MemoryUseBytes());
[email protected]94f206c12012-08-25 00:09:14332}
333
[email protected]c1bb5af2013-03-13 19:06:27334bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
[email protected]a8a049c2013-03-11 23:27:06335
[email protected]fa339032014-02-18 22:11:59336void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() {
337 DCHECK(IsImplThread());
338 renderer_capabilities_for_main_thread_ =
339 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities();
340}
341
[email protected]c1bb5af2013-03-13 19:06:27342void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
[email protected]ccc08dc2014-01-30 07:33:20343 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread");
[email protected]a8a049c2013-03-11 23:27:06344 // Cause a commit so we can notice the lost context.
[email protected]c1bb5af2013-03-13 19:06:27345 SetNeedsCommitOnImplThread();
[email protected]4d7e46a2013-11-08 05:33:40346 client_->DidAbortSwapBuffers();
347}
348
349void SingleThreadProxy::DidSwapBuffersOnImplThread() {
350 client_->DidPostSwapBuffers();
351}
352
[email protected]c14902662014-04-18 05:06:11353void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() {
354 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread");
[email protected]4d7e46a2013-11-08 05:33:40355 client_->DidCompleteSwapBuffers();
[email protected]493067512012-09-19 23:34:10356}
357
[email protected]a8a049c2013-03-11 23:27:06358// Called by the legacy scheduling path (e.g. where render_widget does the
359// scheduling)
[email protected]f0c2a242013-03-15 19:34:52360void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
[email protected]ccc08dc2014-01-30 07:33:20361 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately");
[email protected]e0341352013-04-06 05:01:20362 gfx::Rect device_viewport_damage_rect;
363
364 LayerTreeHostImpl::FrameData frame;
365 if (CommitAndComposite(frame_begin_time,
366 device_viewport_damage_rect,
[email protected]2921d042013-05-10 05:01:39367 false, // for_readback
[email protected]e0341352013-04-06 05:01:20368 &frame)) {
[email protected]819b9f52013-09-22 23:29:51369 {
370 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
371 DebugScopedSetImplThread impl(this);
372
373 // This CapturePostTasks should be destroyed before
374 // DidCommitAndDrawFrame() is called since that goes out to the embedder,
375 // and we want the embedder to receive its callbacks before that.
376 // NOTE: This maintains consistent ordering with the ThreadProxy since
377 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
378 // there as the main thread is not blocked, so any posted tasks inside
379 // the swap buffers will execute first.
380 BlockingTaskRunner::CapturePostTasks blocked;
381
382 layer_tree_host_impl_->SwapBuffers(frame);
383 }
[email protected]a8a049c2013-03-11 23:27:06384 DidSwapFrame();
385 }
[email protected]74d9063c2013-01-18 03:14:47386}
387
[email protected]a8a049c2013-03-11 23:27:06388scoped_ptr<base::Value> SingleThreadProxy::AsValue() const {
389 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
390 {
391 // The following line casts away const modifiers because it is just
392 // setting debug state. We still want the AsValue() function and its
393 // call chain to be const throughout.
394 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
395
396 state->Set("layer_tree_host_impl",
[email protected]c1bb5af2013-03-13 19:06:27397 layer_tree_host_impl_->AsValue().release());
[email protected]a8a049c2013-03-11 23:27:06398 }
399 return state.PassAs<base::Value>();
[email protected]493067512012-09-19 23:34:10400}
401
[email protected]a8a049c2013-03-11 23:27:06402void SingleThreadProxy::ForceSerializeOnSwapBuffers() {
403 {
404 DebugScopedSetImplThread impl(this);
[email protected]04049fc2013-05-01 03:13:20405 if (layer_tree_host_impl_->renderer()) {
406 DCHECK(!layer_tree_host_->output_surface_lost());
[email protected]a8a049c2013-03-11 23:27:06407 layer_tree_host_impl_->renderer()->DoNoOp();
[email protected]04049fc2013-05-01 03:13:20408 }
[email protected]a8a049c2013-03-11 23:27:06409 }
[email protected]8947cbe2012-11-28 05:27:43410}
411
[email protected]e0341352013-04-06 05:01:20412bool SingleThreadProxy::CommitAndComposite(
413 base::TimeTicks frame_begin_time,
[email protected]0023fc72014-01-10 20:05:06414 const gfx::Rect& device_viewport_damage_rect,
[email protected]2921d042013-05-10 05:01:39415 bool for_readback,
[email protected]e0341352013-04-06 05:01:20416 LayerTreeHostImpl::FrameData* frame) {
[email protected]ccc08dc2014-01-30 07:33:20417 TRACE_EVENT0("cc", "SingleThreadProxy::CommitAndComposite");
[email protected]a8a049c2013-03-11 23:27:06418 DCHECK(Proxy::IsMainThread());
[email protected]b1969fa2012-10-17 20:16:29419
[email protected]04049fc2013-05-01 03:13:20420 if (!layer_tree_host_->InitializeOutputSurfaceIfNeeded())
[email protected]16288a42012-12-17 23:31:05421 return false;
[email protected]a8a049c2013-03-11 23:27:06422
[email protected]d7763662013-05-09 18:14:37423 layer_tree_host_->AnimateLayers(frame_begin_time);
424
[email protected]5d2fec02013-11-28 20:08:33425 if (PrioritizedResourceManager* contents_texture_manager =
426 layer_tree_host_->contents_texture_manager()) {
427 contents_texture_manager->UnlinkAndClearEvictedBackings();
428 contents_texture_manager->SetMaxMemoryLimitBytes(
[email protected]990e050a2013-09-23 18:50:21429 layer_tree_host_impl_->memory_allocation_limit_bytes());
[email protected]5d2fec02013-11-28 20:08:33430 contents_texture_manager->SetExternalPriorityCutoff(
[email protected]990e050a2013-09-23 18:50:21431 layer_tree_host_impl_->memory_allocation_priority_cutoff());
[email protected]6e8c54922013-06-02 19:17:35432 }
[email protected]a8a049c2013-03-11 23:27:06433
434 scoped_ptr<ResourceUpdateQueue> queue =
435 make_scoped_ptr(new ResourceUpdateQueue);
[email protected]990e050a2013-09-23 18:50:21436 layer_tree_host_->UpdateLayers(queue.get());
[email protected]a8a049c2013-03-11 23:27:06437
[email protected]804c8982013-03-13 16:32:21438 layer_tree_host_->WillCommit();
[email protected]a024d0e2013-09-26 19:20:45439
[email protected]a8a049c2013-03-11 23:27:06440 DoCommit(queue.Pass());
[email protected]3b2eb882014-04-24 19:48:56441 bool result = DoComposite(
442 frame_begin_time, device_viewport_damage_rect, for_readback, frame);
[email protected]daea3d42013-10-23 17:04:50443 layer_tree_host_->DidBeginMainFrame();
[email protected]a8a049c2013-03-11 23:27:06444 return result;
[email protected]16288a42012-12-17 23:31:05445}
446
[email protected]3d9f7432013-04-06 00:35:18447bool SingleThreadProxy::ShouldComposite() const {
448 DCHECK(Proxy::IsImplThread());
449 return layer_tree_host_impl_->visible() &&
450 layer_tree_host_impl_->CanDraw();
451}
452
[email protected]d9fce6722013-08-30 01:10:01453void SingleThreadProxy::UpdateBackgroundAnimateTicking() {
454 DCHECK(Proxy::IsImplThread());
455 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
456 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer());
457}
458
[email protected]a8a049c2013-03-11 23:27:06459bool SingleThreadProxy::DoComposite(
[email protected]e0341352013-04-06 05:01:20460 base::TimeTicks frame_begin_time,
[email protected]0023fc72014-01-10 20:05:06461 const gfx::Rect& device_viewport_damage_rect,
[email protected]2921d042013-05-10 05:01:39462 bool for_readback,
[email protected]e0341352013-04-06 05:01:20463 LayerTreeHostImpl::FrameData* frame) {
[email protected]ccc08dc2014-01-30 07:33:20464 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite");
[email protected]04049fc2013-05-01 03:13:20465 DCHECK(!layer_tree_host_->output_surface_lost());
466
467 bool lost_output_surface = false;
[email protected]a8a049c2013-03-11 23:27:06468 {
469 DebugScopedSetImplThread impl(this);
470 base::AutoReset<bool> mark_inside(&inside_draw_, true);
471
[email protected]2921d042013-05-10 05:01:39472 bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels();
473
[email protected]3d9f7432013-04-06 00:35:18474 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
475 // frame, so can only be used when such a frame is possible. Since
476 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
477 // CanDraw() as well.
[email protected]2921d042013-05-10 05:01:39478 if (!ShouldComposite() || (for_readback && !can_do_readback)) {
[email protected]d9fce6722013-08-30 01:10:01479 UpdateBackgroundAnimateTicking();
[email protected]a8a049c2013-03-11 23:27:06480 return false;
[email protected]3d9f7432013-04-06 00:35:18481 }
[email protected]a8a049c2013-03-11 23:27:06482
[email protected]fb7425a2013-04-22 16:28:55483 layer_tree_host_impl_->Animate(
[email protected]27152642014-03-11 20:42:00484 layer_tree_host_impl_->CurrentFrameTimeTicks());
[email protected]d9fce6722013-08-30 01:10:01485 UpdateBackgroundAnimateTicking();
[email protected]a8a049c2013-03-11 23:27:06486
[email protected]13044fe72013-12-02 20:52:19487 if (!layer_tree_host_impl_->IsContextLost()) {
488 layer_tree_host_impl_->PrepareToDraw(frame, device_viewport_damage_rect);
489 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time);
490 layer_tree_host_impl_->DidDrawAllLayers(*frame);
491 }
[email protected]04049fc2013-05-01 03:13:20492 lost_output_surface = layer_tree_host_impl_->IsContextLost();
[email protected]a8a049c2013-03-11 23:27:06493
[email protected]3d9f7432013-04-06 00:35:18494 bool start_ready_animations = true;
495 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
496
[email protected]8347d692013-05-17 23:22:38497 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame();
[email protected]a8a049c2013-03-11 23:27:06498 }
499
[email protected]04049fc2013-05-01 03:13:20500 if (lost_output_surface) {
[email protected]804c8982013-03-13 16:32:21501 layer_tree_host_->DidLoseOutputSurface();
[email protected]a8a049c2013-03-11 23:27:06502 return false;
503 }
504
505 return true;
506}
507
508void SingleThreadProxy::DidSwapFrame() {
509 if (next_frame_is_newly_committed_frame_) {
510 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21511 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06512 }
513}
514
515bool SingleThreadProxy::CommitPendingForTesting() { return false; }
516
[email protected]bc5e77c2012-11-05 20:00:49517} // namespace cc