blob: 14bdddd54e6b9facd5120603c41f24da7786da34 [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]8e0176d2013-03-21 03:14:5238 CHECK(!layer_tree_host->settings().impl_side_painting);
[email protected]94f206c12012-08-25 00:09:1439}
40
[email protected]a8a049c2013-03-11 23:27:0641void SingleThreadProxy::Start() {
42 DebugScopedSetImplThread impl(this);
[email protected]804c8982013-03-13 16:32:2143 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
[email protected]a8a049c2013-03-11 23:27:0644}
45
46SingleThreadProxy::~SingleThreadProxy() {
47 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy");
48 DCHECK(Proxy::IsMainThread());
49 DCHECK(!layer_tree_host_impl_.get() &&
50 !layer_tree_host_); // make sure Stop() got called.
51}
52
53bool SingleThreadProxy::CompositeAndReadback(void* pixels, gfx::Rect rect) {
[email protected]ed511b8d2013-03-25 03:29:2954 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeAndReadback");
[email protected]a8a049c2013-03-11 23:27:0655 DCHECK(Proxy::IsMainThread());
56
[email protected]e0341352013-04-06 05:01:2057 gfx::Rect device_viewport_damage_rect = rect;
58
59 LayerTreeHostImpl::FrameData frame;
60 if (!CommitAndComposite(base::TimeTicks::Now(),
61 device_viewport_damage_rect,
62 &frame))
[email protected]a8a049c2013-03-11 23:27:0663 return false;
64
65 {
[email protected]61de5812012-11-08 07:03:4466 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:2767 layer_tree_host_impl_->Readback(pixels, rect);
[email protected]a8a049c2013-03-11 23:27:0668
[email protected]c1bb5af2013-03-13 19:06:2769 if (layer_tree_host_impl_->IsContextLost())
[email protected]a8a049c2013-03-11 23:27:0670 return false;
71
[email protected]e0341352013-04-06 05:01:2072 layer_tree_host_impl_->SwapBuffers(frame);
[email protected]a8a049c2013-03-11 23:27:0673 }
74 DidSwapFrame();
75
76 return true;
[email protected]94f206c12012-08-25 00:09:1477}
78
[email protected]a8a049c2013-03-11 23:27:0679void SingleThreadProxy::FinishAllRendering() {
80 DCHECK(Proxy::IsMainThread());
81 {
[email protected]61de5812012-11-08 07:03:4482 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:2783 layer_tree_host_impl_->FinishAllRendering();
[email protected]a8a049c2013-03-11 23:27:0684 }
[email protected]94f206c12012-08-25 00:09:1485}
86
[email protected]a8a049c2013-03-11 23:27:0687bool SingleThreadProxy::IsStarted() const {
88 DCHECK(Proxy::IsMainThread());
[email protected]3209161d2013-03-29 19:17:3489 return layer_tree_host_impl_;
[email protected]94f206c12012-08-25 00:09:1490}
91
[email protected]a8a049c2013-03-11 23:27:0692bool SingleThreadProxy::InitializeOutputSurface() {
93 DCHECK(Proxy::IsMainThread());
[email protected]ed511b8d2013-03-25 03:29:2994 scoped_ptr<OutputSurface> output_surface =
[email protected]804c8982013-03-13 16:32:2195 layer_tree_host_->CreateOutputSurface();
[email protected]ed511b8d2013-03-25 03:29:2996 if (!output_surface.get())
[email protected]a8a049c2013-03-11 23:27:0697 return false;
[email protected]ed511b8d2013-03-25 03:29:2998 output_surface_before_initialization_ = output_surface.Pass();
[email protected]a8a049c2013-03-11 23:27:0699 return true;
100}
[email protected]94f206c12012-08-25 00:09:14101
[email protected]a8a049c2013-03-11 23:27:06102void SingleThreadProxy::SetSurfaceReady() {
103 // Scheduling is controlled by the embedder in the single thread case, so
104 // nothing to do.
105}
106
107void SingleThreadProxy::SetVisible(bool visible) {
108 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:27109 layer_tree_host_impl_->SetVisible(visible);
[email protected]a8a049c2013-03-11 23:27:06110}
111
112bool SingleThreadProxy::InitializeRenderer() {
113 DCHECK(Proxy::IsMainThread());
114 DCHECK(output_surface_before_initialization_.get());
115 {
116 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:27117 bool ok = layer_tree_host_impl_->InitializeRenderer(
[email protected]a8a049c2013-03-11 23:27:06118 output_surface_before_initialization_.Pass());
119 if (ok) {
120 renderer_initialized_ = true;
121 renderer_capabilities_for_main_thread_ =
[email protected]c1bb5af2013-03-13 19:06:27122 layer_tree_host_impl_->GetRendererCapabilities();
[email protected]0a451722013-02-22 20:32:05123 }
[email protected]94f206c12012-08-25 00:09:14124
[email protected]a8a049c2013-03-11 23:27:06125 return ok;
126 }
127}
128
129bool SingleThreadProxy::RecreateOutputSurface() {
[email protected]ed511b8d2013-03-25 03:29:29130 TRACE_EVENT0("cc", "SingleThreadProxy::RecreateContext");
[email protected]a8a049c2013-03-11 23:27:06131 DCHECK(Proxy::IsMainThread());
132 DCHECK(output_surface_lost_);
133
[email protected]ed511b8d2013-03-25 03:29:29134 scoped_ptr<OutputSurface> output_surface =
[email protected]804c8982013-03-13 16:32:21135 layer_tree_host_->CreateOutputSurface();
[email protected]ed511b8d2013-03-25 03:29:29136 if (!output_surface.get())
[email protected]a8a049c2013-03-11 23:27:06137 return false;
138 scoped_refptr<cc::ContextProvider> offscreen_context_provider;
[email protected]e06e1122013-03-15 17:12:38139 if (created_offscreen_context_provider_) {
[email protected]a8a049c2013-03-11 23:27:06140 offscreen_context_provider =
141 layer_tree_host_->client()->OffscreenContextProviderForMainThread();
[email protected]e06e1122013-03-15 17:12:38142 if (!offscreen_context_provider)
[email protected]a8a049c2013-03-11 23:27:06143 return false;
144 }
145
146 bool initialized;
147 {
148 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
149 DebugScopedSetImplThread impl(this);
[email protected]804c8982013-03-13 16:32:21150 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27151 layer_tree_host_impl_->resource_provider());
[email protected]a8a049c2013-03-11 23:27:06152 initialized =
[email protected]ed511b8d2013-03-25 03:29:29153 layer_tree_host_impl_->InitializeRenderer(output_surface.Pass());
[email protected]a8a049c2013-03-11 23:27:06154 if (initialized) {
155 renderer_capabilities_for_main_thread_ =
[email protected]c1bb5af2013-03-13 19:06:27156 layer_tree_host_impl_->GetRendererCapabilities();
[email protected]e06e1122013-03-15 17:12:38157 layer_tree_host_impl_->resource_provider()->
158 set_offscreen_context_provider(offscreen_context_provider);
[email protected]a8a049c2013-03-11 23:27:06159 } else if (offscreen_context_provider) {
160 offscreen_context_provider->VerifyContexts();
[email protected]94f206c12012-08-25 00:09:14161 }
[email protected]a8a049c2013-03-11 23:27:06162 }
[email protected]94f206c12012-08-25 00:09:14163
[email protected]a8a049c2013-03-11 23:27:06164 if (initialized)
165 output_surface_lost_ = false;
[email protected]94f206c12012-08-25 00:09:14166
[email protected]a8a049c2013-03-11 23:27:06167 return initialized;
[email protected]94f206c12012-08-25 00:09:14168}
169
[email protected]a8a049c2013-03-11 23:27:06170const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const {
171 DCHECK(renderer_initialized_);
172 // Note: this gets called during the commit by the "impl" thread.
173 return renderer_capabilities_for_main_thread_;
[email protected]94f206c12012-08-25 00:09:14174}
175
[email protected]a8a049c2013-03-11 23:27:06176void SingleThreadProxy::SetNeedsAnimate() {
177 // Thread-only feature.
178 NOTREACHED();
[email protected]94f206c12012-08-25 00:09:14179}
180
[email protected]a8a049c2013-03-11 23:27:06181void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) {
182 DCHECK(Proxy::IsMainThread());
183 // Commit immediately.
184 {
185 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
186 DebugScopedSetImplThread impl(this);
[email protected]94f206c12012-08-25 00:09:14187
[email protected]372bad5f2013-03-21 16:38:43188 RenderingStatsInstrumentation* stats_instrumentation =
189 layer_tree_host_->rendering_stats_instrumentation();
[email protected]ed511b8d2013-03-25 03:29:29190 base::TimeTicks start_time = stats_instrumentation->StartRecording();
[email protected]372bad5f2013-03-21 16:38:43191
[email protected]c1bb5af2013-03-13 19:06:27192 layer_tree_host_impl_->BeginCommit();
[email protected]94f206c12012-08-25 00:09:14193
[email protected]804c8982013-03-13 16:32:21194 layer_tree_host_->contents_texture_manager()->
[email protected]b56c1302013-03-20 21:17:34195 PushTexturePrioritiesToBackings();
[email protected]804c8982013-03-13 16:32:21196 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14197
[email protected]ed511b8d2013-03-25 03:29:29198 scoped_ptr<ResourceUpdateController> update_controller =
[email protected]a8a049c2013-03-11 23:27:06199 ResourceUpdateController::Create(
200 NULL,
201 Proxy::MainThread(),
202 queue.Pass(),
[email protected]c1bb5af2013-03-13 19:06:27203 layer_tree_host_impl_->resource_provider());
[email protected]ed511b8d2013-03-25 03:29:29204 update_controller->Finalize();
[email protected]94f206c12012-08-25 00:09:14205
[email protected]804c8982013-03-13 16:32:21206 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14207
[email protected]c1bb5af2013-03-13 19:06:27208 layer_tree_host_impl_->CommitComplete();
[email protected]94f206c12012-08-25 00:09:14209
[email protected]1d993172012-10-18 18:15:04210#ifndef NDEBUG
[email protected]a8a049c2013-03-11 23:27:06211 // In the single-threaded case, the scroll deltas should never be
212 // touched on the impl layer tree.
[email protected]ed511b8d2013-03-25 03:29:29213 scoped_ptr<ScrollAndScaleSet> scroll_info =
[email protected]c1bb5af2013-03-13 19:06:27214 layer_tree_host_impl_->ProcessScrollDeltas();
[email protected]ed511b8d2013-03-25 03:29:29215 DCHECK(!scroll_info->scrolls.size());
[email protected]94f206c12012-08-25 00:09:14216#endif
[email protected]8b9af6b2012-09-27 00:36:36217
[email protected]ed511b8d2013-03-25 03:29:29218 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time);
[email protected]372bad5f2013-03-21 16:38:43219 stats_instrumentation->AddCommit(duration);
[email protected]a8a049c2013-03-11 23:27:06220 }
[email protected]804c8982013-03-13 16:32:21221 layer_tree_host_->CommitComplete();
[email protected]a8a049c2013-03-11 23:27:06222 next_frame_is_newly_committed_frame_ = true;
[email protected]94f206c12012-08-25 00:09:14223}
224
[email protected]a8a049c2013-03-11 23:27:06225void SingleThreadProxy::SetNeedsCommit() {
226 DCHECK(Proxy::IsMainThread());
[email protected]804c8982013-03-13 16:32:21227 layer_tree_host_->ScheduleComposite();
[email protected]94f206c12012-08-25 00:09:14228}
229
[email protected]878705be2013-04-15 22:44:02230void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) {
[email protected]a8a049c2013-03-11 23:27:06231 // FIXME: Once we move render_widget scheduling into this class, we can
[email protected]ed511b8d2013-03-25 03:29:29232 // treat redraw requests more efficiently than CommitAndRedraw requests.
[email protected]878705be2013-04-15 22:44:02233 layer_tree_host_impl_->SetViewportDamage(damage_rect);
[email protected]a8a049c2013-03-11 23:27:06234 SetNeedsCommit();
[email protected]94f206c12012-08-25 00:09:14235}
236
[email protected]c1bb5af2013-03-13 19:06:27237void SingleThreadProxy::OnHasPendingTreeStateChanged(bool have_pending_tree) {
[email protected]a8a049c2013-03-11 23:27:06238 // Thread-only feature.
239 NOTREACHED();
[email protected]2e7ca422012-12-20 02:57:27240}
241
[email protected]a8a049c2013-03-11 23:27:06242void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
243 // Thread-only feature.
244 NOTREACHED();
[email protected]6b16679e2012-10-27 00:44:28245}
246
[email protected]a8a049c2013-03-11 23:27:06247bool SingleThreadProxy::CommitRequested() const { return false; }
248
249size_t SingleThreadProxy::MaxPartialTextureUpdates() const {
250 return std::numeric_limits<size_t>::max();
251}
252
253void SingleThreadProxy::Stop() {
254 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
255 DCHECK(Proxy::IsMainThread());
256 {
257 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
258 DebugScopedSetImplThread impl(this);
259
[email protected]804c8982013-03-13 16:32:21260 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27261 layer_tree_host_impl_->resource_provider());
[email protected]a8a049c2013-03-11 23:27:06262 layer_tree_host_impl_.reset();
263 }
[email protected]7aba6662013-03-12 10:17:34264 layer_tree_host_ = NULL;
[email protected]a8a049c2013-03-11 23:27:06265}
266
[email protected]3d9f7432013-04-06 00:35:18267void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
268 DCHECK(Proxy::IsImplThread());
269 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(!ShouldComposite());
270}
271
[email protected]c1bb5af2013-03-13 19:06:27272void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
[email protected]804c8982013-03-13 16:32:21273 layer_tree_host_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06274}
275
[email protected]86126792013-03-16 20:07:54276void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06277 // Impl-side painting only.
278 NOTREACHED();
279}
280
[email protected]c1bb5af2013-03-13 19:06:27281void SingleThreadProxy::SetNeedsCommitOnImplThread() {
[email protected]804c8982013-03-13 16:32:21282 layer_tree_host_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06283}
284
[email protected]c1bb5af2013-03-13 19:06:27285void SingleThreadProxy::SetNeedsManageTilesOnImplThread() {
[email protected]804c8982013-03-13 16:32:21286 layer_tree_host_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06287}
288
[email protected]c1bb5af2013-03-13 19:06:27289void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
[email protected]a8a049c2013-03-11 23:27:06290 scoped_ptr<AnimationEventsVector> events,
291 base::Time wall_clock_time) {
292 DCHECK(Proxy::IsImplThread());
293 DebugScopedSetMainThread main(this);
[email protected]804c8982013-03-13 16:32:21294 layer_tree_host_->SetAnimationEvents(events.Pass(), wall_clock_time);
[email protected]a8a049c2013-03-11 23:27:06295}
296
[email protected]c1bb5af2013-03-13 19:06:27297bool SingleThreadProxy::ReduceContentsTextureMemoryOnImplThread(
[email protected]a8a049c2013-03-11 23:27:06298 size_t limit_bytes,
299 int priority_cutoff) {
300 DCHECK(IsImplThread());
[email protected]804c8982013-03-13 16:32:21301 if (!layer_tree_host_->contents_texture_manager())
[email protected]94f206c12012-08-25 00:09:14302 return false;
[email protected]a8a049c2013-03-11 23:27:06303
[email protected]b56c1302013-03-20 21:17:34304 return layer_tree_host_->contents_texture_manager()->ReduceMemoryOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27305 limit_bytes, priority_cutoff, layer_tree_host_impl_->resource_provider());
[email protected]94f206c12012-08-25 00:09:14306}
307
[email protected]c1bb5af2013-03-13 19:06:27308void SingleThreadProxy::ReduceWastedContentsTextureMemoryOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06309 // Impl-side painting only.
310 NOTREACHED();
[email protected]493067512012-09-19 23:34:10311}
312
[email protected]c1bb5af2013-03-13 19:06:27313void SingleThreadProxy::SendManagedMemoryStats() {
[email protected]a8a049c2013-03-11 23:27:06314 DCHECK(Proxy::IsImplThread());
315 if (!layer_tree_host_impl_.get())
316 return;
[email protected]804c8982013-03-13 16:32:21317 if (!layer_tree_host_->contents_texture_manager())
[email protected]a8a049c2013-03-11 23:27:06318 return;
[email protected]94f206c12012-08-25 00:09:14319
[email protected]804c8982013-03-13 16:32:21320 PrioritizedResourceManager* contents_texture_manager =
321 layer_tree_host_->contents_texture_manager();
[email protected]c1bb5af2013-03-13 19:06:27322 layer_tree_host_impl_->SendManagedMemoryStats(
[email protected]b56c1302013-03-20 21:17:34323 contents_texture_manager->MemoryVisibleBytes(),
324 contents_texture_manager->MemoryVisibleAndNearbyBytes(),
325 contents_texture_manager->MemoryUseBytes());
[email protected]94f206c12012-08-25 00:09:14326}
327
[email protected]c1bb5af2013-03-13 19:06:27328bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
[email protected]a8a049c2013-03-11 23:27:06329
[email protected]c1bb5af2013-03-13 19:06:27330void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06331 // Cause a commit so we can notice the lost context.
[email protected]c1bb5af2013-03-13 19:06:27332 SetNeedsCommitOnImplThread();
[email protected]493067512012-09-19 23:34:10333}
334
[email protected]a8a049c2013-03-11 23:27:06335// Called by the legacy scheduling path (e.g. where render_widget does the
336// scheduling)
[email protected]f0c2a242013-03-15 19:34:52337void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
[email protected]e0341352013-04-06 05:01:20338 gfx::Rect device_viewport_damage_rect;
339
340 LayerTreeHostImpl::FrameData frame;
341 if (CommitAndComposite(frame_begin_time,
342 device_viewport_damage_rect,
343 &frame)) {
344 layer_tree_host_impl_->SwapBuffers(frame);
[email protected]a8a049c2013-03-11 23:27:06345 DidSwapFrame();
346 }
[email protected]74d9063c2013-01-18 03:14:47347}
348
[email protected]a8a049c2013-03-11 23:27:06349scoped_ptr<base::Value> SingleThreadProxy::AsValue() const {
350 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
351 {
352 // The following line casts away const modifiers because it is just
353 // setting debug state. We still want the AsValue() function and its
354 // call chain to be const throughout.
355 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
356
357 state->Set("layer_tree_host_impl",
[email protected]c1bb5af2013-03-13 19:06:27358 layer_tree_host_impl_->AsValue().release());
[email protected]a8a049c2013-03-11 23:27:06359 }
360 return state.PassAs<base::Value>();
[email protected]493067512012-09-19 23:34:10361}
362
[email protected]a8a049c2013-03-11 23:27:06363void SingleThreadProxy::ForceSerializeOnSwapBuffers() {
364 {
365 DebugScopedSetImplThread impl(this);
366 if (renderer_initialized_)
367 layer_tree_host_impl_->renderer()->DoNoOp();
368 }
[email protected]8947cbe2012-11-28 05:27:43369}
370
[email protected]c1bb5af2013-03-13 19:06:27371void SingleThreadProxy::OnSwapBuffersCompleteOnImplThread() { NOTREACHED(); }
[email protected]94f206c12012-08-25 00:09:14372
[email protected]e0341352013-04-06 05:01:20373bool SingleThreadProxy::CommitAndComposite(
374 base::TimeTicks frame_begin_time,
375 gfx::Rect device_viewport_damage_rect,
376 LayerTreeHostImpl::FrameData* frame) {
[email protected]a8a049c2013-03-11 23:27:06377 DCHECK(Proxy::IsMainThread());
[email protected]b1969fa2012-10-17 20:16:29378
[email protected]804c8982013-03-13 16:32:21379 if (!layer_tree_host_->InitializeRendererIfNeeded())
[email protected]16288a42012-12-17 23:31:05380 return false;
[email protected]a8a049c2013-03-11 23:27:06381
382 scoped_refptr<cc::ContextProvider> offscreen_context_provider;
[email protected]804c8982013-03-13 16:32:21383 if (renderer_capabilities_for_main_thread_.using_offscreen_context3d &&
384 layer_tree_host_->needs_offscreen_context()) {
[email protected]a8a049c2013-03-11 23:27:06385 offscreen_context_provider =
386 layer_tree_host_->client()->OffscreenContextProviderForMainThread();
[email protected]e06e1122013-03-15 17:12:38387 if (offscreen_context_provider)
388 created_offscreen_context_provider_ = true;
[email protected]a8a049c2013-03-11 23:27:06389 }
390
[email protected]b56c1302013-03-20 21:17:34391 layer_tree_host_->contents_texture_manager()->UnlinkAndClearEvictedBackings();
[email protected]a8a049c2013-03-11 23:27:06392
393 scoped_ptr<ResourceUpdateQueue> queue =
394 make_scoped_ptr(new ResourceUpdateQueue);
[email protected]804c8982013-03-13 16:32:21395 layer_tree_host_->UpdateLayers(
[email protected]c1bb5af2013-03-13 19:06:27396 queue.get(), layer_tree_host_impl_->memory_allocation_limit_bytes());
[email protected]a8a049c2013-03-11 23:27:06397
[email protected]804c8982013-03-13 16:32:21398 layer_tree_host_->WillCommit();
[email protected]a8a049c2013-03-11 23:27:06399 DoCommit(queue.Pass());
[email protected]e0341352013-04-06 05:01:20400 bool result = DoComposite(offscreen_context_provider,
401 frame_begin_time,
402 device_viewport_damage_rect,
403 frame);
[email protected]804c8982013-03-13 16:32:21404 layer_tree_host_->DidBeginFrame();
[email protected]a8a049c2013-03-11 23:27:06405 return result;
[email protected]16288a42012-12-17 23:31:05406}
407
[email protected]3d9f7432013-04-06 00:35:18408bool SingleThreadProxy::ShouldComposite() const {
409 DCHECK(Proxy::IsImplThread());
410 return layer_tree_host_impl_->visible() &&
411 layer_tree_host_impl_->CanDraw();
412}
413
[email protected]a8a049c2013-03-11 23:27:06414bool SingleThreadProxy::DoComposite(
[email protected]f0c2a242013-03-15 19:34:52415 scoped_refptr<cc::ContextProvider> offscreen_context_provider,
[email protected]e0341352013-04-06 05:01:20416 base::TimeTicks frame_begin_time,
417 gfx::Rect device_viewport_damage_rect,
418 LayerTreeHostImpl::FrameData* frame) {
[email protected]a8a049c2013-03-11 23:27:06419 DCHECK(!output_surface_lost_);
420 {
421 DebugScopedSetImplThread impl(this);
422 base::AutoReset<bool> mark_inside(&inside_draw_, true);
423
[email protected]c1bb5af2013-03-13 19:06:27424 layer_tree_host_impl_->resource_provider()->
[email protected]e06e1122013-03-15 17:12:38425 set_offscreen_context_provider(offscreen_context_provider);
[email protected]a8a049c2013-03-11 23:27:06426
[email protected]3d9f7432013-04-06 00:35:18427 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
428 // frame, so can only be used when such a frame is possible. Since
429 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
430 // CanDraw() as well.
431 if (!ShouldComposite()) {
432 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true);
[email protected]a8a049c2013-03-11 23:27:06433 return false;
[email protected]3d9f7432013-04-06 00:35:18434 }
[email protected]a8a049c2013-03-11 23:27:06435
[email protected]c1bb5af2013-03-13 19:06:27436 layer_tree_host_impl_->Animate(base::TimeTicks::Now(), base::Time::Now());
[email protected]3d9f7432013-04-06 00:35:18437 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(false);
[email protected]a8a049c2013-03-11 23:27:06438
[email protected]e0341352013-04-06 05:01:20439 layer_tree_host_impl_->PrepareToDraw(frame, device_viewport_damage_rect);
440 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time);
441 layer_tree_host_impl_->DidDrawAllLayers(*frame);
[email protected]c1bb5af2013-03-13 19:06:27442 output_surface_lost_ = layer_tree_host_impl_->IsContextLost();
[email protected]a8a049c2013-03-11 23:27:06443
[email protected]3d9f7432013-04-06 00:35:18444 bool start_ready_animations = true;
445 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
446
[email protected]c1bb5af2013-03-13 19:06:27447 layer_tree_host_impl_->BeginNextFrame();
[email protected]a8a049c2013-03-11 23:27:06448 }
449
450 if (output_surface_lost_) {
451 cc::ContextProvider* offscreen_contexts = layer_tree_host_impl_->
[email protected]c1bb5af2013-03-13 19:06:27452 resource_provider()->offscreen_context_provider();
[email protected]a8a049c2013-03-11 23:27:06453 if (offscreen_contexts)
454 offscreen_contexts->VerifyContexts();
[email protected]804c8982013-03-13 16:32:21455 layer_tree_host_->DidLoseOutputSurface();
[email protected]a8a049c2013-03-11 23:27:06456 return false;
457 }
458
459 return true;
460}
461
462void SingleThreadProxy::DidSwapFrame() {
463 if (next_frame_is_newly_committed_frame_) {
464 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21465 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06466 }
467}
468
469bool SingleThreadProxy::CommitPendingForTesting() { return false; }
470
471skia::RefPtr<SkPicture> SingleThreadProxy::CapturePicture() {
472 // Impl-side painting only.
473 NOTREACHED();
474 return skia::RefPtr<SkPicture>();
[email protected]b9dcf43a2013-01-09 00:15:29475}
476
[email protected]bc5e77c2012-11-05 20:00:49477} // namespace cc