blob: 26e47f739609538575fbd241842b84472af4d926 [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),
28 output_surface_lost_(false),
[email protected]e06e1122013-03-15 17:12:3829 created_offscreen_context_provider_(false),
[email protected]a8a049c2013-03-11 23:27:0630 renderer_initialized_(false),
31 next_frame_is_newly_committed_frame_(false),
[email protected]ccd6d9d2013-03-30 19:08:5832 inside_draw_(false) {
[email protected]a8a049c2013-03-11 23:27:0633 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
34 DCHECK(Proxy::IsMainThread());
35 DCHECK(layer_tree_host);
[email protected]1e4c352b2013-01-10 02:05:2336
[email protected]089102b2013-03-14 03:54:5637 // Impl-side painting not supported without threaded compositing.
[email protected]d9c086a2013-04-17 16:12:4838 CHECK(!layer_tree_host->settings().impl_side_painting)
39 << "Threaded compositing must be enabled to use impl-side painting.";
[email protected]94f206c12012-08-25 00:09:1440}
41
[email protected]a8a049c2013-03-11 23:27:0642void SingleThreadProxy::Start() {
43 DebugScopedSetImplThread impl(this);
[email protected]804c8982013-03-13 16:32:2144 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
[email protected]a8a049c2013-03-11 23:27:0645}
46
47SingleThreadProxy::~SingleThreadProxy() {
48 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy");
49 DCHECK(Proxy::IsMainThread());
50 DCHECK(!layer_tree_host_impl_.get() &&
51 !layer_tree_host_); // make sure Stop() got called.
52}
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,
63 &frame))
[email protected]a8a049c2013-03-11 23:27:0664 return false;
65
66 {
[email protected]61de5812012-11-08 07:03:4467 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:2768 layer_tree_host_impl_->Readback(pixels, rect);
[email protected]a8a049c2013-03-11 23:27:0669
[email protected]c1bb5af2013-03-13 19:06:2770 if (layer_tree_host_impl_->IsContextLost())
[email protected]a8a049c2013-03-11 23:27:0671 return false;
72
[email protected]e0341352013-04-06 05:01:2073 layer_tree_host_impl_->SwapBuffers(frame);
[email protected]a8a049c2013-03-11 23:27:0674 }
75 DidSwapFrame();
76
77 return true;
[email protected]94f206c12012-08-25 00:09:1478}
79
[email protected]a8a049c2013-03-11 23:27:0680void SingleThreadProxy::FinishAllRendering() {
81 DCHECK(Proxy::IsMainThread());
82 {
[email protected]61de5812012-11-08 07:03:4483 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:2784 layer_tree_host_impl_->FinishAllRendering();
[email protected]a8a049c2013-03-11 23:27:0685 }
[email protected]94f206c12012-08-25 00:09:1486}
87
[email protected]a8a049c2013-03-11 23:27:0688bool SingleThreadProxy::IsStarted() const {
89 DCHECK(Proxy::IsMainThread());
[email protected]3209161d2013-03-29 19:17:3490 return layer_tree_host_impl_;
[email protected]94f206c12012-08-25 00:09:1491}
92
[email protected]a8a049c2013-03-11 23:27:0693bool SingleThreadProxy::InitializeOutputSurface() {
94 DCHECK(Proxy::IsMainThread());
[email protected]ed511b8d2013-03-25 03:29:2995 scoped_ptr<OutputSurface> output_surface =
[email protected]804c8982013-03-13 16:32:2196 layer_tree_host_->CreateOutputSurface();
[email protected]ed511b8d2013-03-25 03:29:2997 if (!output_surface.get())
[email protected]a8a049c2013-03-11 23:27:0698 return false;
[email protected]ed511b8d2013-03-25 03:29:2999 output_surface_before_initialization_ = output_surface.Pass();
[email protected]a8a049c2013-03-11 23:27:06100 return true;
101}
[email protected]94f206c12012-08-25 00:09:14102
[email protected]a8a049c2013-03-11 23:27:06103void SingleThreadProxy::SetSurfaceReady() {
104 // Scheduling is controlled by the embedder in the single thread case, so
105 // nothing to do.
106}
107
108void SingleThreadProxy::SetVisible(bool visible) {
109 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:27110 layer_tree_host_impl_->SetVisible(visible);
[email protected]a8a049c2013-03-11 23:27:06111}
112
113bool SingleThreadProxy::InitializeRenderer() {
114 DCHECK(Proxy::IsMainThread());
115 DCHECK(output_surface_before_initialization_.get());
116 {
117 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:27118 bool ok = layer_tree_host_impl_->InitializeRenderer(
[email protected]a8a049c2013-03-11 23:27:06119 output_surface_before_initialization_.Pass());
120 if (ok) {
121 renderer_initialized_ = true;
122 renderer_capabilities_for_main_thread_ =
[email protected]c1bb5af2013-03-13 19:06:27123 layer_tree_host_impl_->GetRendererCapabilities();
[email protected]0a451722013-02-22 20:32:05124 }
[email protected]94f206c12012-08-25 00:09:14125
[email protected]a8a049c2013-03-11 23:27:06126 return ok;
127 }
128}
129
130bool SingleThreadProxy::RecreateOutputSurface() {
[email protected]ed511b8d2013-03-25 03:29:29131 TRACE_EVENT0("cc", "SingleThreadProxy::RecreateContext");
[email protected]a8a049c2013-03-11 23:27:06132 DCHECK(Proxy::IsMainThread());
133 DCHECK(output_surface_lost_);
134
[email protected]ed511b8d2013-03-25 03:29:29135 scoped_ptr<OutputSurface> output_surface =
[email protected]804c8982013-03-13 16:32:21136 layer_tree_host_->CreateOutputSurface();
[email protected]ed511b8d2013-03-25 03:29:29137 if (!output_surface.get())
[email protected]a8a049c2013-03-11 23:27:06138 return false;
139 scoped_refptr<cc::ContextProvider> offscreen_context_provider;
[email protected]e06e1122013-03-15 17:12:38140 if (created_offscreen_context_provider_) {
[email protected]a8a049c2013-03-11 23:27:06141 offscreen_context_provider =
142 layer_tree_host_->client()->OffscreenContextProviderForMainThread();
[email protected]e06e1122013-03-15 17:12:38143 if (!offscreen_context_provider)
[email protected]a8a049c2013-03-11 23:27:06144 return false;
145 }
146
147 bool initialized;
148 {
149 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
150 DebugScopedSetImplThread impl(this);
[email protected]804c8982013-03-13 16:32:21151 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27152 layer_tree_host_impl_->resource_provider());
[email protected]a8a049c2013-03-11 23:27:06153 initialized =
[email protected]ed511b8d2013-03-25 03:29:29154 layer_tree_host_impl_->InitializeRenderer(output_surface.Pass());
[email protected]a8a049c2013-03-11 23:27:06155 if (initialized) {
156 renderer_capabilities_for_main_thread_ =
[email protected]c1bb5af2013-03-13 19:06:27157 layer_tree_host_impl_->GetRendererCapabilities();
[email protected]e06e1122013-03-15 17:12:38158 layer_tree_host_impl_->resource_provider()->
159 set_offscreen_context_provider(offscreen_context_provider);
[email protected]a8a049c2013-03-11 23:27:06160 } else if (offscreen_context_provider) {
161 offscreen_context_provider->VerifyContexts();
[email protected]94f206c12012-08-25 00:09:14162 }
[email protected]a8a049c2013-03-11 23:27:06163 }
[email protected]94f206c12012-08-25 00:09:14164
[email protected]a8a049c2013-03-11 23:27:06165 if (initialized)
166 output_surface_lost_ = false;
[email protected]94f206c12012-08-25 00:09:14167
[email protected]a8a049c2013-03-11 23:27:06168 return initialized;
[email protected]94f206c12012-08-25 00:09:14169}
170
[email protected]a8a049c2013-03-11 23:27:06171const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const {
172 DCHECK(renderer_initialized_);
173 // Note: this gets called during the commit by the "impl" thread.
174 return renderer_capabilities_for_main_thread_;
[email protected]94f206c12012-08-25 00:09:14175}
176
[email protected]a8a049c2013-03-11 23:27:06177void SingleThreadProxy::SetNeedsAnimate() {
178 // Thread-only feature.
179 NOTREACHED();
[email protected]94f206c12012-08-25 00:09:14180}
181
[email protected]a8a049c2013-03-11 23:27:06182void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) {
183 DCHECK(Proxy::IsMainThread());
184 // Commit immediately.
185 {
186 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
187 DebugScopedSetImplThread impl(this);
[email protected]94f206c12012-08-25 00:09:14188
[email protected]372bad5f2013-03-21 16:38:43189 RenderingStatsInstrumentation* stats_instrumentation =
190 layer_tree_host_->rendering_stats_instrumentation();
[email protected]ed511b8d2013-03-25 03:29:29191 base::TimeTicks start_time = stats_instrumentation->StartRecording();
[email protected]372bad5f2013-03-21 16:38:43192
[email protected]c1bb5af2013-03-13 19:06:27193 layer_tree_host_impl_->BeginCommit();
[email protected]94f206c12012-08-25 00:09:14194
[email protected]804c8982013-03-13 16:32:21195 layer_tree_host_->contents_texture_manager()->
[email protected]b56c1302013-03-20 21:17:34196 PushTexturePrioritiesToBackings();
[email protected]804c8982013-03-13 16:32:21197 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14198
[email protected]ed511b8d2013-03-25 03:29:29199 scoped_ptr<ResourceUpdateController> update_controller =
[email protected]a8a049c2013-03-11 23:27:06200 ResourceUpdateController::Create(
201 NULL,
202 Proxy::MainThread(),
203 queue.Pass(),
[email protected]c1bb5af2013-03-13 19:06:27204 layer_tree_host_impl_->resource_provider());
[email protected]ed511b8d2013-03-25 03:29:29205 update_controller->Finalize();
[email protected]94f206c12012-08-25 00:09:14206
[email protected]804c8982013-03-13 16:32:21207 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14208
[email protected]c1bb5af2013-03-13 19:06:27209 layer_tree_host_impl_->CommitComplete();
[email protected]94f206c12012-08-25 00:09:14210
[email protected]1d993172012-10-18 18:15:04211#ifndef NDEBUG
[email protected]a8a049c2013-03-11 23:27:06212 // In the single-threaded case, the scroll deltas should never be
213 // touched on the impl layer tree.
[email protected]ed511b8d2013-03-25 03:29:29214 scoped_ptr<ScrollAndScaleSet> scroll_info =
[email protected]c1bb5af2013-03-13 19:06:27215 layer_tree_host_impl_->ProcessScrollDeltas();
[email protected]ed511b8d2013-03-25 03:29:29216 DCHECK(!scroll_info->scrolls.size());
[email protected]94f206c12012-08-25 00:09:14217#endif
[email protected]8b9af6b2012-09-27 00:36:36218
[email protected]ed511b8d2013-03-25 03:29:29219 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time);
[email protected]372bad5f2013-03-21 16:38:43220 stats_instrumentation->AddCommit(duration);
[email protected]a8a049c2013-03-11 23:27:06221 }
[email protected]804c8982013-03-13 16:32:21222 layer_tree_host_->CommitComplete();
[email protected]a8a049c2013-03-11 23:27:06223 next_frame_is_newly_committed_frame_ = true;
[email protected]94f206c12012-08-25 00:09:14224}
225
[email protected]a8a049c2013-03-11 23:27:06226void SingleThreadProxy::SetNeedsCommit() {
227 DCHECK(Proxy::IsMainThread());
[email protected]804c8982013-03-13 16:32:21228 layer_tree_host_->ScheduleComposite();
[email protected]94f206c12012-08-25 00:09:14229}
230
[email protected]878705be2013-04-15 22:44:02231void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) {
[email protected]a8a049c2013-03-11 23:27:06232 // FIXME: Once we move render_widget scheduling into this class, we can
[email protected]ed511b8d2013-03-25 03:29:29233 // treat redraw requests more efficiently than CommitAndRedraw requests.
[email protected]878705be2013-04-15 22:44:02234 layer_tree_host_impl_->SetViewportDamage(damage_rect);
[email protected]a8a049c2013-03-11 23:27:06235 SetNeedsCommit();
[email protected]94f206c12012-08-25 00:09:14236}
237
[email protected]c1bb5af2013-03-13 19:06:27238void SingleThreadProxy::OnHasPendingTreeStateChanged(bool have_pending_tree) {
[email protected]a8a049c2013-03-11 23:27:06239 // Thread-only feature.
240 NOTREACHED();
[email protected]2e7ca422012-12-20 02:57:27241}
242
[email protected]a8a049c2013-03-11 23:27:06243void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
244 // Thread-only feature.
245 NOTREACHED();
[email protected]6b16679e2012-10-27 00:44:28246}
247
[email protected]a8a049c2013-03-11 23:27:06248bool SingleThreadProxy::CommitRequested() const { return false; }
249
250size_t SingleThreadProxy::MaxPartialTextureUpdates() const {
251 return std::numeric_limits<size_t>::max();
252}
253
254void SingleThreadProxy::Stop() {
255 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
256 DCHECK(Proxy::IsMainThread());
257 {
258 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
259 DebugScopedSetImplThread impl(this);
260
[email protected]804c8982013-03-13 16:32:21261 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27262 layer_tree_host_impl_->resource_provider());
[email protected]a8a049c2013-03-11 23:27:06263 layer_tree_host_impl_.reset();
264 }
[email protected]7aba6662013-03-12 10:17:34265 layer_tree_host_ = NULL;
[email protected]a8a049c2013-03-11 23:27:06266}
267
[email protected]3d9f7432013-04-06 00:35:18268void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
269 DCHECK(Proxy::IsImplThread());
270 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(!ShouldComposite());
271}
272
[email protected]c1bb5af2013-03-13 19:06:27273void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
[email protected]804c8982013-03-13 16:32:21274 layer_tree_host_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06275}
276
[email protected]86126792013-03-16 20:07:54277void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06278 // Impl-side painting only.
279 NOTREACHED();
280}
281
[email protected]c1bb5af2013-03-13 19:06:27282void SingleThreadProxy::SetNeedsCommitOnImplThread() {
[email protected]804c8982013-03-13 16:32:21283 layer_tree_host_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06284}
285
[email protected]c1bb5af2013-03-13 19:06:27286void SingleThreadProxy::SetNeedsManageTilesOnImplThread() {
[email protected]804c8982013-03-13 16:32:21287 layer_tree_host_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06288}
289
[email protected]c1bb5af2013-03-13 19:06:27290void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
[email protected]a8a049c2013-03-11 23:27:06291 scoped_ptr<AnimationEventsVector> events,
292 base::Time wall_clock_time) {
293 DCHECK(Proxy::IsImplThread());
294 DebugScopedSetMainThread main(this);
[email protected]804c8982013-03-13 16:32:21295 layer_tree_host_->SetAnimationEvents(events.Pass(), wall_clock_time);
[email protected]a8a049c2013-03-11 23:27:06296}
297
[email protected]c1bb5af2013-03-13 19:06:27298bool SingleThreadProxy::ReduceContentsTextureMemoryOnImplThread(
[email protected]a8a049c2013-03-11 23:27:06299 size_t limit_bytes,
300 int priority_cutoff) {
301 DCHECK(IsImplThread());
[email protected]804c8982013-03-13 16:32:21302 if (!layer_tree_host_->contents_texture_manager())
[email protected]94f206c12012-08-25 00:09:14303 return false;
[email protected]a8a049c2013-03-11 23:27:06304
[email protected]b56c1302013-03-20 21:17:34305 return layer_tree_host_->contents_texture_manager()->ReduceMemoryOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27306 limit_bytes, priority_cutoff, layer_tree_host_impl_->resource_provider());
[email protected]94f206c12012-08-25 00:09:14307}
308
[email protected]c1bb5af2013-03-13 19:06:27309void SingleThreadProxy::ReduceWastedContentsTextureMemoryOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06310 // Impl-side painting only.
311 NOTREACHED();
[email protected]493067512012-09-19 23:34:10312}
313
[email protected]c1bb5af2013-03-13 19:06:27314void SingleThreadProxy::SendManagedMemoryStats() {
[email protected]a8a049c2013-03-11 23:27:06315 DCHECK(Proxy::IsImplThread());
316 if (!layer_tree_host_impl_.get())
317 return;
[email protected]804c8982013-03-13 16:32:21318 if (!layer_tree_host_->contents_texture_manager())
[email protected]a8a049c2013-03-11 23:27:06319 return;
[email protected]94f206c12012-08-25 00:09:14320
[email protected]804c8982013-03-13 16:32:21321 PrioritizedResourceManager* contents_texture_manager =
322 layer_tree_host_->contents_texture_manager();
[email protected]c1bb5af2013-03-13 19:06:27323 layer_tree_host_impl_->SendManagedMemoryStats(
[email protected]b56c1302013-03-20 21:17:34324 contents_texture_manager->MemoryVisibleBytes(),
325 contents_texture_manager->MemoryVisibleAndNearbyBytes(),
326 contents_texture_manager->MemoryUseBytes());
[email protected]94f206c12012-08-25 00:09:14327}
328
[email protected]c1bb5af2013-03-13 19:06:27329bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
[email protected]a8a049c2013-03-11 23:27:06330
[email protected]c1bb5af2013-03-13 19:06:27331void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06332 // Cause a commit so we can notice the lost context.
[email protected]c1bb5af2013-03-13 19:06:27333 SetNeedsCommitOnImplThread();
[email protected]493067512012-09-19 23:34:10334}
335
[email protected]a8a049c2013-03-11 23:27:06336// Called by the legacy scheduling path (e.g. where render_widget does the
337// scheduling)
[email protected]f0c2a242013-03-15 19:34:52338void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
[email protected]e0341352013-04-06 05:01:20339 gfx::Rect device_viewport_damage_rect;
340
341 LayerTreeHostImpl::FrameData frame;
342 if (CommitAndComposite(frame_begin_time,
343 device_viewport_damage_rect,
344 &frame)) {
345 layer_tree_host_impl_->SwapBuffers(frame);
[email protected]a8a049c2013-03-11 23:27:06346 DidSwapFrame();
347 }
[email protected]74d9063c2013-01-18 03:14:47348}
349
[email protected]a8a049c2013-03-11 23:27:06350scoped_ptr<base::Value> SingleThreadProxy::AsValue() const {
351 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
352 {
353 // The following line casts away const modifiers because it is just
354 // setting debug state. We still want the AsValue() function and its
355 // call chain to be const throughout.
356 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
357
358 state->Set("layer_tree_host_impl",
[email protected]c1bb5af2013-03-13 19:06:27359 layer_tree_host_impl_->AsValue().release());
[email protected]a8a049c2013-03-11 23:27:06360 }
361 return state.PassAs<base::Value>();
[email protected]493067512012-09-19 23:34:10362}
363
[email protected]a8a049c2013-03-11 23:27:06364void SingleThreadProxy::ForceSerializeOnSwapBuffers() {
365 {
366 DebugScopedSetImplThread impl(this);
367 if (renderer_initialized_)
368 layer_tree_host_impl_->renderer()->DoNoOp();
369 }
[email protected]8947cbe2012-11-28 05:27:43370}
371
[email protected]4aea68c82013-04-16 22:06:54372void SingleThreadProxy::OnSwapBuffersCompleteOnImplThread() { NOTREACHED(); }
373
[email protected]e0341352013-04-06 05:01:20374bool SingleThreadProxy::CommitAndComposite(
375 base::TimeTicks frame_begin_time,
376 gfx::Rect device_viewport_damage_rect,
377 LayerTreeHostImpl::FrameData* frame) {
[email protected]a8a049c2013-03-11 23:27:06378 DCHECK(Proxy::IsMainThread());
[email protected]b1969fa2012-10-17 20:16:29379
[email protected]804c8982013-03-13 16:32:21380 if (!layer_tree_host_->InitializeRendererIfNeeded())
[email protected]16288a42012-12-17 23:31:05381 return false;
[email protected]a8a049c2013-03-11 23:27:06382
383 scoped_refptr<cc::ContextProvider> offscreen_context_provider;
[email protected]804c8982013-03-13 16:32:21384 if (renderer_capabilities_for_main_thread_.using_offscreen_context3d &&
385 layer_tree_host_->needs_offscreen_context()) {
[email protected]a8a049c2013-03-11 23:27:06386 offscreen_context_provider =
387 layer_tree_host_->client()->OffscreenContextProviderForMainThread();
[email protected]e06e1122013-03-15 17:12:38388 if (offscreen_context_provider)
389 created_offscreen_context_provider_ = true;
[email protected]a8a049c2013-03-11 23:27:06390 }
391
[email protected]b56c1302013-03-20 21:17:34392 layer_tree_host_->contents_texture_manager()->UnlinkAndClearEvictedBackings();
[email protected]a8a049c2013-03-11 23:27:06393
394 scoped_ptr<ResourceUpdateQueue> queue =
395 make_scoped_ptr(new ResourceUpdateQueue);
[email protected]804c8982013-03-13 16:32:21396 layer_tree_host_->UpdateLayers(
[email protected]c1bb5af2013-03-13 19:06:27397 queue.get(), layer_tree_host_impl_->memory_allocation_limit_bytes());
[email protected]a8a049c2013-03-11 23:27:06398
[email protected]804c8982013-03-13 16:32:21399 layer_tree_host_->WillCommit();
[email protected]a8a049c2013-03-11 23:27:06400 DoCommit(queue.Pass());
[email protected]e0341352013-04-06 05:01:20401 bool result = DoComposite(offscreen_context_provider,
402 frame_begin_time,
403 device_viewport_damage_rect,
404 frame);
[email protected]804c8982013-03-13 16:32:21405 layer_tree_host_->DidBeginFrame();
[email protected]a8a049c2013-03-11 23:27:06406 return result;
[email protected]16288a42012-12-17 23:31:05407}
408
[email protected]3d9f7432013-04-06 00:35:18409bool SingleThreadProxy::ShouldComposite() const {
410 DCHECK(Proxy::IsImplThread());
411 return layer_tree_host_impl_->visible() &&
412 layer_tree_host_impl_->CanDraw();
413}
414
[email protected]a8a049c2013-03-11 23:27:06415bool SingleThreadProxy::DoComposite(
[email protected]f0c2a242013-03-15 19:34:52416 scoped_refptr<cc::ContextProvider> offscreen_context_provider,
[email protected]e0341352013-04-06 05:01:20417 base::TimeTicks frame_begin_time,
418 gfx::Rect device_viewport_damage_rect,
419 LayerTreeHostImpl::FrameData* frame) {
[email protected]a8a049c2013-03-11 23:27:06420 DCHECK(!output_surface_lost_);
421 {
422 DebugScopedSetImplThread impl(this);
423 base::AutoReset<bool> mark_inside(&inside_draw_, true);
424
[email protected]c1bb5af2013-03-13 19:06:27425 layer_tree_host_impl_->resource_provider()->
[email protected]e06e1122013-03-15 17:12:38426 set_offscreen_context_provider(offscreen_context_provider);
[email protected]a8a049c2013-03-11 23:27:06427
[email protected]3d9f7432013-04-06 00:35:18428 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
429 // frame, so can only be used when such a frame is possible. Since
430 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
431 // CanDraw() as well.
432 if (!ShouldComposite()) {
433 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true);
[email protected]a8a049c2013-03-11 23:27:06434 return false;
[email protected]3d9f7432013-04-06 00:35:18435 }
[email protected]a8a049c2013-03-11 23:27:06436
[email protected]c1bb5af2013-03-13 19:06:27437 layer_tree_host_impl_->Animate(base::TimeTicks::Now(), base::Time::Now());
[email protected]3d9f7432013-04-06 00:35:18438 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(false);
[email protected]a8a049c2013-03-11 23:27:06439
[email protected]e0341352013-04-06 05:01:20440 layer_tree_host_impl_->PrepareToDraw(frame, device_viewport_damage_rect);
441 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time);
442 layer_tree_host_impl_->DidDrawAllLayers(*frame);
[email protected]c1bb5af2013-03-13 19:06:27443 output_surface_lost_ = layer_tree_host_impl_->IsContextLost();
[email protected]a8a049c2013-03-11 23:27:06444
[email protected]3d9f7432013-04-06 00:35:18445 bool start_ready_animations = true;
446 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
447
[email protected]c1bb5af2013-03-13 19:06:27448 layer_tree_host_impl_->BeginNextFrame();
[email protected]a8a049c2013-03-11 23:27:06449 }
450
451 if (output_surface_lost_) {
452 cc::ContextProvider* offscreen_contexts = layer_tree_host_impl_->
[email protected]c1bb5af2013-03-13 19:06:27453 resource_provider()->offscreen_context_provider();
[email protected]a8a049c2013-03-11 23:27:06454 if (offscreen_contexts)
455 offscreen_contexts->VerifyContexts();
[email protected]804c8982013-03-13 16:32:21456 layer_tree_host_->DidLoseOutputSurface();
[email protected]a8a049c2013-03-11 23:27:06457 return false;
458 }
459
460 return true;
461}
462
463void SingleThreadProxy::DidSwapFrame() {
464 if (next_frame_is_newly_committed_frame_) {
465 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21466 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06467 }
468}
469
470bool SingleThreadProxy::CommitPendingForTesting() { return false; }
471
472skia::RefPtr<SkPicture> SingleThreadProxy::CapturePicture() {
473 // Impl-side painting only.
474 NOTREACHED();
475 return skia::RefPtr<SkPicture>();
[email protected]b9dcf43a2013-01-09 00:15:29476}
477
[email protected]bc5e77c2012-11-05 20:00:49478} // namespace cc