blob: 7fe1f565106808b68952ba9866a608188f381b81 [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]681ccff2013-03-18 06:13:529#include "cc/base/thread.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]556fd292013-03-18 08:03:0415#include "cc/trees/layer_tree_host.h"
16#include "cc/trees/layer_tree_impl.h"
[email protected]94f206c12012-08-25 00:09:1417
[email protected]9c88e562012-09-14 22:21:3018namespace cc {
[email protected]94f206c12012-08-25 00:09:1419
[email protected]a8a049c2013-03-11 23:27:0620scoped_ptr<Proxy> SingleThreadProxy::Create(LayerTreeHost* layer_tree_host) {
21 return make_scoped_ptr(
22 new SingleThreadProxy(layer_tree_host)).PassAs<Proxy>();
[email protected]94f206c12012-08-25 00:09:1423}
24
[email protected]a8a049c2013-03-11 23:27:0625SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host)
26 : Proxy(scoped_ptr<Thread>(NULL)),
27 layer_tree_host_(layer_tree_host),
[email protected]e06e1122013-03-15 17:12:3828 created_offscreen_context_provider_(false),
[email protected]a8a049c2013-03-11 23:27:0629 next_frame_is_newly_committed_frame_(false),
[email protected]ccd6d9d2013-03-30 19:08:5830 inside_draw_(false) {
[email protected]a8a049c2013-03-11 23:27:0631 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
32 DCHECK(Proxy::IsMainThread());
33 DCHECK(layer_tree_host);
[email protected]1e4c352b2013-01-10 02:05:2334
[email protected]089102b2013-03-14 03:54:5635 // Impl-side painting not supported without threaded compositing.
[email protected]d9c086a2013-04-17 16:12:4836 CHECK(!layer_tree_host->settings().impl_side_painting)
37 << "Threaded compositing must be enabled to use impl-side painting.";
[email protected]94f206c12012-08-25 00:09:1438}
39
[email protected]04049fc2013-05-01 03:13:2040void SingleThreadProxy::Start(scoped_ptr<OutputSurface> first_output_surface) {
41 DCHECK(first_output_surface);
[email protected]a8a049c2013-03-11 23:27:0642 DebugScopedSetImplThread impl(this);
[email protected]804c8982013-03-13 16:32:2143 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
[email protected]04049fc2013-05-01 03:13:2044 first_output_surface_ = first_output_surface.Pass();
[email protected]a8a049c2013-03-11 23:27:0645}
46
47SingleThreadProxy::~SingleThreadProxy() {
48 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy");
49 DCHECK(Proxy::IsMainThread());
[email protected]04049fc2013-05-01 03:13:2050 // Make sure Stop() got called or never Started.
51 DCHECK(!layer_tree_host_impl_);
[email protected]a8a049c2013-03-11 23:27:0652}
53
54bool SingleThreadProxy::CompositeAndReadback(void* pixels, gfx::Rect rect) {
[email protected]ed511b8d2013-03-25 03:29:2955 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeAndReadback");
[email protected]a8a049c2013-03-11 23:27:0656 DCHECK(Proxy::IsMainThread());
57
[email protected]e0341352013-04-06 05:01:2058 gfx::Rect device_viewport_damage_rect = rect;
59
60 LayerTreeHostImpl::FrameData frame;
61 if (!CommitAndComposite(base::TimeTicks::Now(),
62 device_viewport_damage_rect,
[email protected]2921d042013-05-10 05:01:3963 true, // for_readback
[email protected]e0341352013-04-06 05:01:2064 &frame))
[email protected]a8a049c2013-03-11 23:27:0665 return false;
66
67 {
[email protected]61de5812012-11-08 07:03:4468 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:2769 layer_tree_host_impl_->Readback(pixels, rect);
[email protected]a8a049c2013-03-11 23:27:0670
[email protected]c1bb5af2013-03-13 19:06:2771 if (layer_tree_host_impl_->IsContextLost())
[email protected]a8a049c2013-03-11 23:27:0672 return false;
73
[email protected]e0341352013-04-06 05:01:2074 layer_tree_host_impl_->SwapBuffers(frame);
[email protected]a8a049c2013-03-11 23:27:0675 }
76 DidSwapFrame();
77
78 return true;
[email protected]94f206c12012-08-25 00:09:1479}
80
[email protected]a8a049c2013-03-11 23:27:0681void SingleThreadProxy::FinishAllRendering() {
82 DCHECK(Proxy::IsMainThread());
83 {
[email protected]61de5812012-11-08 07:03:4484 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:2785 layer_tree_host_impl_->FinishAllRendering();
[email protected]a8a049c2013-03-11 23:27:0686 }
[email protected]94f206c12012-08-25 00:09:1487}
88
[email protected]a8a049c2013-03-11 23:27:0689bool SingleThreadProxy::IsStarted() const {
90 DCHECK(Proxy::IsMainThread());
[email protected]3209161d2013-03-29 19:17:3491 return layer_tree_host_impl_;
[email protected]94f206c12012-08-25 00:09:1492}
93
[email protected]14bd5542013-05-08 21:51:3094void SingleThreadProxy::SetLayerTreeHostClientReady() {
[email protected]a8a049c2013-03-11 23:27:0695 // Scheduling is controlled by the embedder in the single thread case, so
96 // nothing to do.
97}
98
99void SingleThreadProxy::SetVisible(bool visible) {
[email protected]fa8818f2013-05-29 21:25:18100 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:27101 layer_tree_host_impl_->SetVisible(visible);
[email protected]a8a049c2013-03-11 23:27:06102}
103
[email protected]04049fc2013-05-01 03:13:20104void SingleThreadProxy::CreateAndInitializeOutputSurface() {
105 TRACE_EVENT0(
106 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface");
[email protected]a8a049c2013-03-11 23:27:06107 DCHECK(Proxy::IsMainThread());
[email protected]94f206c12012-08-25 00:09:14108
[email protected]04049fc2013-05-01 03:13:20109 scoped_ptr<OutputSurface> output_surface = first_output_surface_.Pass();
[email protected]486544b2013-04-26 18:46:22110 if (!output_surface)
[email protected]04049fc2013-05-01 03:13:20111 output_surface = layer_tree_host_->CreateOutputSurface();
112 if (!output_surface) {
113 OnOutputSurfaceInitializeAttempted(false);
114 return;
115 }
116
[email protected]a8a049c2013-03-11 23:27:06117 scoped_refptr<cc::ContextProvider> offscreen_context_provider;
[email protected]e06e1122013-03-15 17:12:38118 if (created_offscreen_context_provider_) {
[email protected]a8a049c2013-03-11 23:27:06119 offscreen_context_provider =
120 layer_tree_host_->client()->OffscreenContextProviderForMainThread();
[email protected]04049fc2013-05-01 03:13:20121 if (!offscreen_context_provider) {
122 OnOutputSurfaceInitializeAttempted(false);
123 return;
124 }
[email protected]a8a049c2013-03-11 23:27:06125 }
126
[email protected]a8a049c2013-03-11 23:27:06127 {
128 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
129 DebugScopedSetImplThread impl(this);
[email protected]804c8982013-03-13 16:32:21130 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27131 layer_tree_host_impl_->resource_provider());
[email protected]04049fc2013-05-01 03:13:20132 }
133
134 bool initialized;
135 {
136 DebugScopedSetImplThread impl(this);
137
138 DCHECK(output_surface);
139 initialized = layer_tree_host_impl_->InitializeRenderer(
140 output_surface.Pass());
[email protected]a8a049c2013-03-11 23:27:06141 if (initialized) {
142 renderer_capabilities_for_main_thread_ =
[email protected]c1bb5af2013-03-13 19:06:27143 layer_tree_host_impl_->GetRendererCapabilities();
[email protected]04049fc2013-05-01 03:13:20144
[email protected]e06e1122013-03-15 17:12:38145 layer_tree_host_impl_->resource_provider()->
146 set_offscreen_context_provider(offscreen_context_provider);
[email protected]a8a049c2013-03-11 23:27:06147 } else if (offscreen_context_provider) {
148 offscreen_context_provider->VerifyContexts();
[email protected]94f206c12012-08-25 00:09:14149 }
[email protected]a8a049c2013-03-11 23:27:06150 }
[email protected]94f206c12012-08-25 00:09:14151
[email protected]04049fc2013-05-01 03:13:20152 OnOutputSurfaceInitializeAttempted(initialized);
153}
[email protected]94f206c12012-08-25 00:09:14154
[email protected]04049fc2013-05-01 03:13:20155void SingleThreadProxy::OnOutputSurfaceInitializeAttempted(bool success) {
156 LayerTreeHost::CreateResult result =
157 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success);
158 if (result == LayerTreeHost::CreateFailedButTryAgain) {
159 // Force another recreation attempt to happen by requesting another commit.
160 SetNeedsCommit();
161 }
[email protected]94f206c12012-08-25 00:09:14162}
163
[email protected]a8a049c2013-03-11 23:27:06164const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const {
[email protected]04049fc2013-05-01 03:13:20165 DCHECK(Proxy::IsMainThread());
166 DCHECK(!layer_tree_host_->output_surface_lost());
[email protected]a8a049c2013-03-11 23:27:06167 return renderer_capabilities_for_main_thread_;
[email protected]94f206c12012-08-25 00:09:14168}
169
[email protected]a8a049c2013-03-11 23:27:06170void SingleThreadProxy::SetNeedsAnimate() {
171 // Thread-only feature.
172 NOTREACHED();
[email protected]94f206c12012-08-25 00:09:14173}
174
[email protected]a8a049c2013-03-11 23:27:06175void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) {
176 DCHECK(Proxy::IsMainThread());
177 // Commit immediately.
178 {
[email protected]fa8818f2013-05-29 21:25:18179 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
180 DebugScopedSetImplThread impl(this);
181
[email protected]372bad5f2013-03-21 16:38:43182 RenderingStatsInstrumentation* stats_instrumentation =
183 layer_tree_host_->rendering_stats_instrumentation();
[email protected]ed511b8d2013-03-25 03:29:29184 base::TimeTicks start_time = stats_instrumentation->StartRecording();
[email protected]372bad5f2013-03-21 16:38:43185
[email protected]c1bb5af2013-03-13 19:06:27186 layer_tree_host_impl_->BeginCommit();
[email protected]94f206c12012-08-25 00:09:14187
[email protected]804c8982013-03-13 16:32:21188 layer_tree_host_->contents_texture_manager()->
[email protected]b56c1302013-03-20 21:17:34189 PushTexturePrioritiesToBackings();
[email protected]804c8982013-03-13 16:32:21190 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14191
[email protected]ed511b8d2013-03-25 03:29:29192 scoped_ptr<ResourceUpdateController> update_controller =
[email protected]a8a049c2013-03-11 23:27:06193 ResourceUpdateController::Create(
194 NULL,
195 Proxy::MainThread(),
196 queue.Pass(),
[email protected]c1bb5af2013-03-13 19:06:27197 layer_tree_host_impl_->resource_provider());
[email protected]ed511b8d2013-03-25 03:29:29198 update_controller->Finalize();
[email protected]94f206c12012-08-25 00:09:14199
[email protected]804c8982013-03-13 16:32:21200 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14201
[email protected]c1bb5af2013-03-13 19:06:27202 layer_tree_host_impl_->CommitComplete();
[email protected]94f206c12012-08-25 00:09:14203
[email protected]1d993172012-10-18 18:15:04204#ifndef NDEBUG
[email protected]a8a049c2013-03-11 23:27:06205 // In the single-threaded case, the scroll deltas should never be
206 // touched on the impl layer tree.
[email protected]ed511b8d2013-03-25 03:29:29207 scoped_ptr<ScrollAndScaleSet> scroll_info =
[email protected]c1bb5af2013-03-13 19:06:27208 layer_tree_host_impl_->ProcessScrollDeltas();
[email protected]ed511b8d2013-03-25 03:29:29209 DCHECK(!scroll_info->scrolls.size());
[email protected]94f206c12012-08-25 00:09:14210#endif
[email protected]8b9af6b2012-09-27 00:36:36211
[email protected]ed511b8d2013-03-25 03:29:29212 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time);
[email protected]372bad5f2013-03-21 16:38:43213 stats_instrumentation->AddCommit(duration);
[email protected]a8a049c2013-03-11 23:27:06214 }
[email protected]804c8982013-03-13 16:32:21215 layer_tree_host_->CommitComplete();
[email protected]a8a049c2013-03-11 23:27:06216 next_frame_is_newly_committed_frame_ = true;
[email protected]94f206c12012-08-25 00:09:14217}
218
[email protected]a8a049c2013-03-11 23:27:06219void SingleThreadProxy::SetNeedsCommit() {
220 DCHECK(Proxy::IsMainThread());
[email protected]804c8982013-03-13 16:32:21221 layer_tree_host_->ScheduleComposite();
[email protected]94f206c12012-08-25 00:09:14222}
223
[email protected]b9d4a362013-04-23 05:36:27224void SingleThreadProxy::SetNeedsRedraw(gfx::Rect damage_rect) {
[email protected]1cd9f5552013-04-26 04:22:03225 SetNeedsRedrawRectOnImplThread(damage_rect);
[email protected]94f206c12012-08-25 00:09:14226}
227
[email protected]c1bb5af2013-03-13 19:06:27228void SingleThreadProxy::OnHasPendingTreeStateChanged(bool have_pending_tree) {
[email protected]a8a049c2013-03-11 23:27:06229 // Thread-only feature.
230 NOTREACHED();
[email protected]2e7ca422012-12-20 02:57:27231}
232
[email protected]a8a049c2013-03-11 23:27:06233void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
234 // Thread-only feature.
235 NOTREACHED();
[email protected]6b16679e2012-10-27 00:44:28236}
237
[email protected]a8a049c2013-03-11 23:27:06238bool SingleThreadProxy::CommitRequested() const { return false; }
239
240size_t SingleThreadProxy::MaxPartialTextureUpdates() const {
241 return std::numeric_limits<size_t>::max();
242}
243
244void SingleThreadProxy::Stop() {
245 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
246 DCHECK(Proxy::IsMainThread());
247 {
248 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
249 DebugScopedSetImplThread impl(this);
250
[email protected]804c8982013-03-13 16:32:21251 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27252 layer_tree_host_impl_->resource_provider());
[email protected]a8a049c2013-03-11 23:27:06253 layer_tree_host_impl_.reset();
254 }
[email protected]7aba6662013-03-12 10:17:34255 layer_tree_host_ = NULL;
[email protected]a8a049c2013-03-11 23:27:06256}
257
[email protected]3d9f7432013-04-06 00:35:18258void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
259 DCHECK(Proxy::IsImplThread());
260 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(!ShouldComposite());
261}
262
[email protected]c1bb5af2013-03-13 19:06:27263void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
[email protected]804c8982013-03-13 16:32:21264 layer_tree_host_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06265}
266
[email protected]1cd9f5552013-04-26 04:22:03267void SingleThreadProxy::SetNeedsRedrawRectOnImplThread(gfx::Rect damage_rect) {
268 // FIXME: Once we move render_widget scheduling into this class, we can
269 // treat redraw requests more efficiently than CommitAndRedraw requests.
270 layer_tree_host_impl_->SetViewportDamage(damage_rect);
271 SetNeedsCommit();
272}
273
[email protected]86126792013-03-16 20:07:54274void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06275 // Impl-side painting only.
276 NOTREACHED();
277}
278
[email protected]c1bb5af2013-03-13 19:06:27279void SingleThreadProxy::SetNeedsCommitOnImplThread() {
[email protected]804c8982013-03-13 16:32:21280 layer_tree_host_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06281}
282
[email protected]c1bb5af2013-03-13 19:06:27283void SingleThreadProxy::SetNeedsManageTilesOnImplThread() {
[email protected]804c8982013-03-13 16:32:21284 layer_tree_host_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06285}
286
[email protected]c1bb5af2013-03-13 19:06:27287void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
[email protected]a8a049c2013-03-11 23:27:06288 scoped_ptr<AnimationEventsVector> events,
289 base::Time wall_clock_time) {
290 DCHECK(Proxy::IsImplThread());
291 DebugScopedSetMainThread main(this);
[email protected]804c8982013-03-13 16:32:21292 layer_tree_host_->SetAnimationEvents(events.Pass(), wall_clock_time);
[email protected]a8a049c2013-03-11 23:27:06293}
294
[email protected]c1bb5af2013-03-13 19:06:27295bool SingleThreadProxy::ReduceContentsTextureMemoryOnImplThread(
[email protected]a8a049c2013-03-11 23:27:06296 size_t limit_bytes,
297 int priority_cutoff) {
298 DCHECK(IsImplThread());
[email protected]804c8982013-03-13 16:32:21299 if (!layer_tree_host_->contents_texture_manager())
[email protected]94f206c12012-08-25 00:09:14300 return false;
[email protected]a8a049c2013-03-11 23:27:06301
[email protected]b56c1302013-03-20 21:17:34302 return layer_tree_host_->contents_texture_manager()->ReduceMemoryOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27303 limit_bytes, priority_cutoff, layer_tree_host_impl_->resource_provider());
[email protected]94f206c12012-08-25 00:09:14304}
305
[email protected]c1bb5af2013-03-13 19:06:27306void SingleThreadProxy::ReduceWastedContentsTextureMemoryOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06307 // Impl-side painting only.
308 NOTREACHED();
[email protected]493067512012-09-19 23:34:10309}
310
[email protected]c1bb5af2013-03-13 19:06:27311void SingleThreadProxy::SendManagedMemoryStats() {
[email protected]a8a049c2013-03-11 23:27:06312 DCHECK(Proxy::IsImplThread());
[email protected]384b2c5e2013-04-23 01:02:22313 if (!layer_tree_host_impl_)
[email protected]a8a049c2013-03-11 23:27:06314 return;
[email protected]804c8982013-03-13 16:32:21315 if (!layer_tree_host_->contents_texture_manager())
[email protected]a8a049c2013-03-11 23:27:06316 return;
[email protected]94f206c12012-08-25 00:09:14317
[email protected]804c8982013-03-13 16:32:21318 PrioritizedResourceManager* contents_texture_manager =
319 layer_tree_host_->contents_texture_manager();
[email protected]c1bb5af2013-03-13 19:06:27320 layer_tree_host_impl_->SendManagedMemoryStats(
[email protected]b56c1302013-03-20 21:17:34321 contents_texture_manager->MemoryVisibleBytes(),
322 contents_texture_manager->MemoryVisibleAndNearbyBytes(),
323 contents_texture_manager->MemoryUseBytes());
[email protected]94f206c12012-08-25 00:09:14324}
325
[email protected]c1bb5af2013-03-13 19:06:27326bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
[email protected]a8a049c2013-03-11 23:27:06327
[email protected]c1bb5af2013-03-13 19:06:27328void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06329 // Cause a commit so we can notice the lost context.
[email protected]c1bb5af2013-03-13 19:06:27330 SetNeedsCommitOnImplThread();
[email protected]493067512012-09-19 23:34:10331}
332
[email protected]a8a049c2013-03-11 23:27:06333// Called by the legacy scheduling path (e.g. where render_widget does the
334// scheduling)
[email protected]f0c2a242013-03-15 19:34:52335void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
[email protected]e0341352013-04-06 05:01:20336 gfx::Rect device_viewport_damage_rect;
337
338 LayerTreeHostImpl::FrameData frame;
339 if (CommitAndComposite(frame_begin_time,
340 device_viewport_damage_rect,
[email protected]2921d042013-05-10 05:01:39341 false, // for_readback
[email protected]e0341352013-04-06 05:01:20342 &frame)) {
343 layer_tree_host_impl_->SwapBuffers(frame);
[email protected]a8a049c2013-03-11 23:27:06344 DidSwapFrame();
345 }
[email protected]74d9063c2013-01-18 03:14:47346}
347
[email protected]a8a049c2013-03-11 23:27:06348scoped_ptr<base::Value> SingleThreadProxy::AsValue() const {
349 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
350 {
351 // The following line casts away const modifiers because it is just
352 // setting debug state. We still want the AsValue() function and its
353 // call chain to be const throughout.
354 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
355
356 state->Set("layer_tree_host_impl",
[email protected]c1bb5af2013-03-13 19:06:27357 layer_tree_host_impl_->AsValue().release());
[email protected]a8a049c2013-03-11 23:27:06358 }
359 return state.PassAs<base::Value>();
[email protected]493067512012-09-19 23:34:10360}
361
[email protected]a8a049c2013-03-11 23:27:06362void SingleThreadProxy::ForceSerializeOnSwapBuffers() {
363 {
364 DebugScopedSetImplThread impl(this);
[email protected]04049fc2013-05-01 03:13:20365 if (layer_tree_host_impl_->renderer()) {
366 DCHECK(!layer_tree_host_->output_surface_lost());
[email protected]a8a049c2013-03-11 23:27:06367 layer_tree_host_impl_->renderer()->DoNoOp();
[email protected]04049fc2013-05-01 03:13:20368 }
[email protected]a8a049c2013-03-11 23:27:06369 }
[email protected]8947cbe2012-11-28 05:27:43370}
371
[email protected]e0341352013-04-06 05:01:20372bool SingleThreadProxy::CommitAndComposite(
373 base::TimeTicks frame_begin_time,
374 gfx::Rect device_viewport_damage_rect,
[email protected]2921d042013-05-10 05:01:39375 bool for_readback,
[email protected]e0341352013-04-06 05:01:20376 LayerTreeHostImpl::FrameData* frame) {
[email protected]a8a049c2013-03-11 23:27:06377 DCHECK(Proxy::IsMainThread());
[email protected]b1969fa2012-10-17 20:16:29378
[email protected]04049fc2013-05-01 03:13:20379 if (!layer_tree_host_->InitializeOutputSurfaceIfNeeded())
[email protected]16288a42012-12-17 23:31:05380 return false;
[email protected]a8a049c2013-03-11 23:27:06381
[email protected]d7763662013-05-09 18:14:37382 layer_tree_host_->AnimateLayers(frame_begin_time);
383
[email protected]a8a049c2013-03-11 23:27:06384 scoped_refptr<cc::ContextProvider> offscreen_context_provider;
[email protected]804c8982013-03-13 16:32:21385 if (renderer_capabilities_for_main_thread_.using_offscreen_context3d &&
386 layer_tree_host_->needs_offscreen_context()) {
[email protected]a8a049c2013-03-11 23:27:06387 offscreen_context_provider =
388 layer_tree_host_->client()->OffscreenContextProviderForMainThread();
[email protected]e06e1122013-03-15 17:12:38389 if (offscreen_context_provider)
390 created_offscreen_context_provider_ = true;
[email protected]a8a049c2013-03-11 23:27:06391 }
392
[email protected]b56c1302013-03-20 21:17:34393 layer_tree_host_->contents_texture_manager()->UnlinkAndClearEvictedBackings();
[email protected]a8a049c2013-03-11 23:27:06394
395 scoped_ptr<ResourceUpdateQueue> queue =
396 make_scoped_ptr(new ResourceUpdateQueue);
[email protected]804c8982013-03-13 16:32:21397 layer_tree_host_->UpdateLayers(
[email protected]c1bb5af2013-03-13 19:06:27398 queue.get(), layer_tree_host_impl_->memory_allocation_limit_bytes());
[email protected]a8a049c2013-03-11 23:27:06399
[email protected]804c8982013-03-13 16:32:21400 layer_tree_host_->WillCommit();
[email protected]a8a049c2013-03-11 23:27:06401 DoCommit(queue.Pass());
[email protected]e0341352013-04-06 05:01:20402 bool result = DoComposite(offscreen_context_provider,
403 frame_begin_time,
404 device_viewport_damage_rect,
[email protected]2921d042013-05-10 05:01:39405 for_readback,
[email protected]e0341352013-04-06 05:01:20406 frame);
[email protected]804c8982013-03-13 16:32:21407 layer_tree_host_->DidBeginFrame();
[email protected]a8a049c2013-03-11 23:27:06408 return result;
[email protected]16288a42012-12-17 23:31:05409}
410
[email protected]3d9f7432013-04-06 00:35:18411bool SingleThreadProxy::ShouldComposite() const {
412 DCHECK(Proxy::IsImplThread());
413 return layer_tree_host_impl_->visible() &&
414 layer_tree_host_impl_->CanDraw();
415}
416
[email protected]a8a049c2013-03-11 23:27:06417bool SingleThreadProxy::DoComposite(
[email protected]f0c2a242013-03-15 19:34:52418 scoped_refptr<cc::ContextProvider> offscreen_context_provider,
[email protected]e0341352013-04-06 05:01:20419 base::TimeTicks frame_begin_time,
420 gfx::Rect device_viewport_damage_rect,
[email protected]2921d042013-05-10 05:01:39421 bool for_readback,
[email protected]e0341352013-04-06 05:01:20422 LayerTreeHostImpl::FrameData* frame) {
[email protected]04049fc2013-05-01 03:13:20423 DCHECK(!layer_tree_host_->output_surface_lost());
424
425 bool lost_output_surface = false;
[email protected]a8a049c2013-03-11 23:27:06426 {
427 DebugScopedSetImplThread impl(this);
428 base::AutoReset<bool> mark_inside(&inside_draw_, true);
429
[email protected]c1bb5af2013-03-13 19:06:27430 layer_tree_host_impl_->resource_provider()->
[email protected]e06e1122013-03-15 17:12:38431 set_offscreen_context_provider(offscreen_context_provider);
[email protected]a8a049c2013-03-11 23:27:06432
[email protected]2921d042013-05-10 05:01:39433 bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels();
434
[email protected]3d9f7432013-04-06 00:35:18435 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
436 // frame, so can only be used when such a frame is possible. Since
437 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
438 // CanDraw() as well.
[email protected]2921d042013-05-10 05:01:39439 if (!ShouldComposite() || (for_readback && !can_do_readback)) {
[email protected]3d9f7432013-04-06 00:35:18440 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true);
[email protected]a8a049c2013-03-11 23:27:06441 return false;
[email protected]3d9f7432013-04-06 00:35:18442 }
[email protected]a8a049c2013-03-11 23:27:06443
[email protected]fb7425a2013-04-22 16:28:55444 layer_tree_host_impl_->Animate(
445 layer_tree_host_impl_->CurrentFrameTimeTicks(),
446 layer_tree_host_impl_->CurrentFrameTime());
[email protected]3d9f7432013-04-06 00:35:18447 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(false);
[email protected]a8a049c2013-03-11 23:27:06448
[email protected]e0341352013-04-06 05:01:20449 layer_tree_host_impl_->PrepareToDraw(frame, device_viewport_damage_rect);
450 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time);
451 layer_tree_host_impl_->DidDrawAllLayers(*frame);
[email protected]04049fc2013-05-01 03:13:20452 lost_output_surface = layer_tree_host_impl_->IsContextLost();
[email protected]a8a049c2013-03-11 23:27:06453
[email protected]3d9f7432013-04-06 00:35:18454 bool start_ready_animations = true;
455 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
456
[email protected]8347d692013-05-17 23:22:38457 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame();
[email protected]a8a049c2013-03-11 23:27:06458 }
459
[email protected]04049fc2013-05-01 03:13:20460 if (lost_output_surface) {
[email protected]a8a049c2013-03-11 23:27:06461 cc::ContextProvider* offscreen_contexts = layer_tree_host_impl_->
[email protected]c1bb5af2013-03-13 19:06:27462 resource_provider()->offscreen_context_provider();
[email protected]a8a049c2013-03-11 23:27:06463 if (offscreen_contexts)
464 offscreen_contexts->VerifyContexts();
[email protected]804c8982013-03-13 16:32:21465 layer_tree_host_->DidLoseOutputSurface();
[email protected]a8a049c2013-03-11 23:27:06466 return false;
467 }
468
469 return true;
470}
471
472void SingleThreadProxy::DidSwapFrame() {
473 if (next_frame_is_newly_committed_frame_) {
474 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21475 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06476 }
477}
478
479bool SingleThreadProxy::CommitPendingForTesting() { return false; }
480
481skia::RefPtr<SkPicture> SingleThreadProxy::CapturePicture() {
482 // Impl-side painting only.
483 NOTREACHED();
484 return skia::RefPtr<SkPicture>();
[email protected]b9dcf43a2013-01-09 00:15:29485}
486
[email protected]bc5e77c2012-11-05 20:00:49487} // namespace cc