blob: d2df4ffc3523a0552ca6933c52f672eda7a58151 [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),
32 inside_draw_(false),
33 total_commit_count_(0) {
34 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
35 DCHECK(Proxy::IsMainThread());
36 DCHECK(layer_tree_host);
[email protected]1e4c352b2013-01-10 02:05:2337
[email protected]089102b2013-03-14 03:54:5638 // Impl-side painting not supported without threaded compositing.
[email protected]8e0176d2013-03-21 03:14:5239 CHECK(!layer_tree_host->settings().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]f0c2a242013-03-15 19:34:5258 if (!CommitAndComposite(base::TimeTicks::Now()))
[email protected]a8a049c2013-03-11 23:27:0659 return false;
60
61 {
[email protected]61de5812012-11-08 07:03:4462 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:2763 layer_tree_host_impl_->Readback(pixels, rect);
[email protected]a8a049c2013-03-11 23:27:0664
[email protected]c1bb5af2013-03-13 19:06:2765 if (layer_tree_host_impl_->IsContextLost())
[email protected]a8a049c2013-03-11 23:27:0666 return false;
67
[email protected]c1bb5af2013-03-13 19:06:2768 layer_tree_host_impl_->SwapBuffers();
[email protected]a8a049c2013-03-11 23:27:0669 }
70 DidSwapFrame();
71
72 return true;
[email protected]94f206c12012-08-25 00:09:1473}
74
[email protected]a8a049c2013-03-11 23:27:0675void SingleThreadProxy::StartPageScaleAnimation(gfx::Vector2d target_offset,
76 bool use_anchor,
77 float scale,
78 base::TimeDelta duration) {
[email protected]c1bb5af2013-03-13 19:06:2779 layer_tree_host_impl_->StartPageScaleAnimation(
[email protected]a8a049c2013-03-11 23:27:0680 target_offset, use_anchor, scale, base::TimeTicks::Now(), duration);
[email protected]94f206c12012-08-25 00:09:1481}
82
[email protected]a8a049c2013-03-11 23:27:0683void SingleThreadProxy::FinishAllRendering() {
84 DCHECK(Proxy::IsMainThread());
85 {
[email protected]61de5812012-11-08 07:03:4486 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:2787 layer_tree_host_impl_->FinishAllRendering();
[email protected]a8a049c2013-03-11 23:27:0688 }
[email protected]94f206c12012-08-25 00:09:1489}
90
[email protected]a8a049c2013-03-11 23:27:0691bool SingleThreadProxy::IsStarted() const {
92 DCHECK(Proxy::IsMainThread());
93 return layer_tree_host_impl_.get();
[email protected]94f206c12012-08-25 00:09:1494}
95
[email protected]a8a049c2013-03-11 23:27:0696bool SingleThreadProxy::InitializeOutputSurface() {
97 DCHECK(Proxy::IsMainThread());
[email protected]ed511b8d2013-03-25 03:29:2998 scoped_ptr<OutputSurface> output_surface =
[email protected]804c8982013-03-13 16:32:2199 layer_tree_host_->CreateOutputSurface();
[email protected]ed511b8d2013-03-25 03:29:29100 if (!output_surface.get())
[email protected]a8a049c2013-03-11 23:27:06101 return false;
[email protected]ed511b8d2013-03-25 03:29:29102 output_surface_before_initialization_ = output_surface.Pass();
[email protected]a8a049c2013-03-11 23:27:06103 return true;
104}
[email protected]94f206c12012-08-25 00:09:14105
[email protected]a8a049c2013-03-11 23:27:06106void SingleThreadProxy::SetSurfaceReady() {
107 // Scheduling is controlled by the embedder in the single thread case, so
108 // nothing to do.
109}
110
111void SingleThreadProxy::SetVisible(bool visible) {
112 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:27113 layer_tree_host_impl_->SetVisible(visible);
[email protected]a8a049c2013-03-11 23:27:06114}
115
116bool SingleThreadProxy::InitializeRenderer() {
117 DCHECK(Proxy::IsMainThread());
118 DCHECK(output_surface_before_initialization_.get());
119 {
120 DebugScopedSetImplThread impl(this);
[email protected]c1bb5af2013-03-13 19:06:27121 bool ok = layer_tree_host_impl_->InitializeRenderer(
[email protected]a8a049c2013-03-11 23:27:06122 output_surface_before_initialization_.Pass());
123 if (ok) {
124 renderer_initialized_ = true;
125 renderer_capabilities_for_main_thread_ =
[email protected]c1bb5af2013-03-13 19:06:27126 layer_tree_host_impl_->GetRendererCapabilities();
[email protected]0a451722013-02-22 20:32:05127 }
[email protected]94f206c12012-08-25 00:09:14128
[email protected]a8a049c2013-03-11 23:27:06129 return ok;
130 }
131}
132
133bool SingleThreadProxy::RecreateOutputSurface() {
[email protected]ed511b8d2013-03-25 03:29:29134 TRACE_EVENT0("cc", "SingleThreadProxy::RecreateContext");
[email protected]a8a049c2013-03-11 23:27:06135 DCHECK(Proxy::IsMainThread());
136 DCHECK(output_surface_lost_);
137
[email protected]ed511b8d2013-03-25 03:29:29138 scoped_ptr<OutputSurface> output_surface =
[email protected]804c8982013-03-13 16:32:21139 layer_tree_host_->CreateOutputSurface();
[email protected]ed511b8d2013-03-25 03:29:29140 if (!output_surface.get())
[email protected]a8a049c2013-03-11 23:27:06141 return false;
142 scoped_refptr<cc::ContextProvider> offscreen_context_provider;
[email protected]e06e1122013-03-15 17:12:38143 if (created_offscreen_context_provider_) {
[email protected]a8a049c2013-03-11 23:27:06144 offscreen_context_provider =
145 layer_tree_host_->client()->OffscreenContextProviderForMainThread();
[email protected]e06e1122013-03-15 17:12:38146 if (!offscreen_context_provider)
[email protected]a8a049c2013-03-11 23:27:06147 return false;
148 }
149
150 bool initialized;
151 {
152 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
153 DebugScopedSetImplThread impl(this);
[email protected]804c8982013-03-13 16:32:21154 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27155 layer_tree_host_impl_->resource_provider());
[email protected]a8a049c2013-03-11 23:27:06156 initialized =
[email protected]ed511b8d2013-03-25 03:29:29157 layer_tree_host_impl_->InitializeRenderer(output_surface.Pass());
[email protected]a8a049c2013-03-11 23:27:06158 if (initialized) {
159 renderer_capabilities_for_main_thread_ =
[email protected]c1bb5af2013-03-13 19:06:27160 layer_tree_host_impl_->GetRendererCapabilities();
[email protected]e06e1122013-03-15 17:12:38161 layer_tree_host_impl_->resource_provider()->
162 set_offscreen_context_provider(offscreen_context_provider);
[email protected]a8a049c2013-03-11 23:27:06163 } else if (offscreen_context_provider) {
164 offscreen_context_provider->VerifyContexts();
[email protected]94f206c12012-08-25 00:09:14165 }
[email protected]a8a049c2013-03-11 23:27:06166 }
[email protected]94f206c12012-08-25 00:09:14167
[email protected]a8a049c2013-03-11 23:27:06168 if (initialized)
169 output_surface_lost_ = false;
[email protected]94f206c12012-08-25 00:09:14170
[email protected]a8a049c2013-03-11 23:27:06171 return initialized;
[email protected]94f206c12012-08-25 00:09:14172}
173
[email protected]a8a049c2013-03-11 23:27:06174const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const {
175 DCHECK(renderer_initialized_);
176 // Note: this gets called during the commit by the "impl" thread.
177 return renderer_capabilities_for_main_thread_;
[email protected]94f206c12012-08-25 00:09:14178}
179
[email protected]a8a049c2013-03-11 23:27:06180void SingleThreadProxy::SetNeedsAnimate() {
181 // Thread-only feature.
182 NOTREACHED();
[email protected]94f206c12012-08-25 00:09:14183}
184
[email protected]a8a049c2013-03-11 23:27:06185void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) {
186 DCHECK(Proxy::IsMainThread());
187 // Commit immediately.
188 {
189 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
190 DebugScopedSetImplThread impl(this);
[email protected]94f206c12012-08-25 00:09:14191
[email protected]372bad5f2013-03-21 16:38:43192 RenderingStatsInstrumentation* stats_instrumentation =
193 layer_tree_host_->rendering_stats_instrumentation();
[email protected]ed511b8d2013-03-25 03:29:29194 base::TimeTicks start_time = stats_instrumentation->StartRecording();
[email protected]372bad5f2013-03-21 16:38:43195
[email protected]c1bb5af2013-03-13 19:06:27196 layer_tree_host_impl_->BeginCommit();
[email protected]94f206c12012-08-25 00:09:14197
[email protected]804c8982013-03-13 16:32:21198 layer_tree_host_->contents_texture_manager()->
[email protected]b56c1302013-03-20 21:17:34199 PushTexturePrioritiesToBackings();
[email protected]804c8982013-03-13 16:32:21200 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14201
[email protected]ed511b8d2013-03-25 03:29:29202 scoped_ptr<ResourceUpdateController> update_controller =
[email protected]a8a049c2013-03-11 23:27:06203 ResourceUpdateController::Create(
204 NULL,
205 Proxy::MainThread(),
206 queue.Pass(),
[email protected]c1bb5af2013-03-13 19:06:27207 layer_tree_host_impl_->resource_provider());
[email protected]ed511b8d2013-03-25 03:29:29208 update_controller->Finalize();
[email protected]94f206c12012-08-25 00:09:14209
[email protected]804c8982013-03-13 16:32:21210 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14211
[email protected]c1bb5af2013-03-13 19:06:27212 layer_tree_host_impl_->CommitComplete();
[email protected]94f206c12012-08-25 00:09:14213
[email protected]1d993172012-10-18 18:15:04214#ifndef NDEBUG
[email protected]a8a049c2013-03-11 23:27:06215 // In the single-threaded case, the scroll deltas should never be
216 // touched on the impl layer tree.
[email protected]ed511b8d2013-03-25 03:29:29217 scoped_ptr<ScrollAndScaleSet> scroll_info =
[email protected]c1bb5af2013-03-13 19:06:27218 layer_tree_host_impl_->ProcessScrollDeltas();
[email protected]ed511b8d2013-03-25 03:29:29219 DCHECK(!scroll_info->scrolls.size());
[email protected]94f206c12012-08-25 00:09:14220#endif
[email protected]8b9af6b2012-09-27 00:36:36221
[email protected]ed511b8d2013-03-25 03:29:29222 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time);
[email protected]372bad5f2013-03-21 16:38:43223 stats_instrumentation->AddCommit(duration);
[email protected]a8a049c2013-03-11 23:27:06224 }
[email protected]804c8982013-03-13 16:32:21225 layer_tree_host_->CommitComplete();
[email protected]a8a049c2013-03-11 23:27:06226 next_frame_is_newly_committed_frame_ = true;
[email protected]94f206c12012-08-25 00:09:14227}
228
[email protected]a8a049c2013-03-11 23:27:06229void SingleThreadProxy::SetNeedsCommit() {
230 DCHECK(Proxy::IsMainThread());
[email protected]804c8982013-03-13 16:32:21231 layer_tree_host_->ScheduleComposite();
[email protected]94f206c12012-08-25 00:09:14232}
233
[email protected]a8a049c2013-03-11 23:27:06234void SingleThreadProxy::SetNeedsRedraw() {
235 // FIXME: Once we move render_widget scheduling into this class, we can
[email protected]ed511b8d2013-03-25 03:29:29236 // treat redraw requests more efficiently than CommitAndRedraw requests.
[email protected]a8a049c2013-03-11 23:27:06237 layer_tree_host_impl_->SetFullRootLayerDamage();
238 SetNeedsCommit();
[email protected]94f206c12012-08-25 00:09:14239}
240
[email protected]c1bb5af2013-03-13 19:06:27241void SingleThreadProxy::OnHasPendingTreeStateChanged(bool have_pending_tree) {
[email protected]a8a049c2013-03-11 23:27:06242 // Thread-only feature.
243 NOTREACHED();
[email protected]2e7ca422012-12-20 02:57:27244}
245
[email protected]a8a049c2013-03-11 23:27:06246void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
247 // Thread-only feature.
248 NOTREACHED();
[email protected]6b16679e2012-10-27 00:44:28249}
250
[email protected]a8a049c2013-03-11 23:27:06251bool SingleThreadProxy::CommitRequested() const { return false; }
252
253size_t SingleThreadProxy::MaxPartialTextureUpdates() const {
254 return std::numeric_limits<size_t>::max();
255}
256
257void SingleThreadProxy::Stop() {
258 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
259 DCHECK(Proxy::IsMainThread());
260 {
261 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
262 DebugScopedSetImplThread impl(this);
263
[email protected]804c8982013-03-13 16:32:21264 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27265 layer_tree_host_impl_->resource_provider());
[email protected]a8a049c2013-03-11 23:27:06266 layer_tree_host_impl_.reset();
267 }
[email protected]7aba6662013-03-12 10:17:34268 layer_tree_host_ = NULL;
[email protected]a8a049c2013-03-11 23:27:06269}
270
[email protected]c1bb5af2013-03-13 19:06:27271void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
[email protected]804c8982013-03-13 16:32:21272 layer_tree_host_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06273}
274
[email protected]86126792013-03-16 20:07:54275void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06276 // Impl-side painting only.
277 NOTREACHED();
278}
279
[email protected]c1bb5af2013-03-13 19:06:27280void SingleThreadProxy::SetNeedsCommitOnImplThread() {
[email protected]804c8982013-03-13 16:32:21281 layer_tree_host_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06282}
283
[email protected]c1bb5af2013-03-13 19:06:27284void SingleThreadProxy::SetNeedsManageTilesOnImplThread() {
[email protected]804c8982013-03-13 16:32:21285 layer_tree_host_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06286}
287
[email protected]c1bb5af2013-03-13 19:06:27288void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
[email protected]a8a049c2013-03-11 23:27:06289 scoped_ptr<AnimationEventsVector> events,
290 base::Time wall_clock_time) {
291 DCHECK(Proxy::IsImplThread());
292 DebugScopedSetMainThread main(this);
[email protected]804c8982013-03-13 16:32:21293 layer_tree_host_->SetAnimationEvents(events.Pass(), wall_clock_time);
[email protected]a8a049c2013-03-11 23:27:06294}
295
[email protected]c1bb5af2013-03-13 19:06:27296bool SingleThreadProxy::ReduceContentsTextureMemoryOnImplThread(
[email protected]a8a049c2013-03-11 23:27:06297 size_t limit_bytes,
298 int priority_cutoff) {
299 DCHECK(IsImplThread());
[email protected]804c8982013-03-13 16:32:21300 if (!layer_tree_host_->contents_texture_manager())
[email protected]94f206c12012-08-25 00:09:14301 return false;
[email protected]a8a049c2013-03-11 23:27:06302
[email protected]b56c1302013-03-20 21:17:34303 return layer_tree_host_->contents_texture_manager()->ReduceMemoryOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27304 limit_bytes, priority_cutoff, layer_tree_host_impl_->resource_provider());
[email protected]94f206c12012-08-25 00:09:14305}
306
[email protected]c1bb5af2013-03-13 19:06:27307void SingleThreadProxy::ReduceWastedContentsTextureMemoryOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06308 // Impl-side painting only.
309 NOTREACHED();
[email protected]493067512012-09-19 23:34:10310}
311
[email protected]c1bb5af2013-03-13 19:06:27312void SingleThreadProxy::SendManagedMemoryStats() {
[email protected]a8a049c2013-03-11 23:27:06313 DCHECK(Proxy::IsImplThread());
314 if (!layer_tree_host_impl_.get())
315 return;
[email protected]804c8982013-03-13 16:32:21316 if (!layer_tree_host_->contents_texture_manager())
[email protected]a8a049c2013-03-11 23:27:06317 return;
[email protected]94f206c12012-08-25 00:09:14318
[email protected]804c8982013-03-13 16:32:21319 PrioritizedResourceManager* contents_texture_manager =
320 layer_tree_host_->contents_texture_manager();
[email protected]c1bb5af2013-03-13 19:06:27321 layer_tree_host_impl_->SendManagedMemoryStats(
[email protected]b56c1302013-03-20 21:17:34322 contents_texture_manager->MemoryVisibleBytes(),
323 contents_texture_manager->MemoryVisibleAndNearbyBytes(),
324 contents_texture_manager->MemoryUseBytes());
[email protected]94f206c12012-08-25 00:09:14325}
326
[email protected]c1bb5af2013-03-13 19:06:27327bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
[email protected]a8a049c2013-03-11 23:27:06328
[email protected]c1bb5af2013-03-13 19:06:27329void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06330 // Cause a commit so we can notice the lost context.
[email protected]c1bb5af2013-03-13 19:06:27331 SetNeedsCommitOnImplThread();
[email protected]493067512012-09-19 23:34:10332}
333
[email protected]a8a049c2013-03-11 23:27:06334// Called by the legacy scheduling path (e.g. where render_widget does the
335// scheduling)
[email protected]f0c2a242013-03-15 19:34:52336void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
337 if (CommitAndComposite(frame_begin_time)) {
[email protected]c1bb5af2013-03-13 19:06:27338 layer_tree_host_impl_->SwapBuffers();
[email protected]a8a049c2013-03-11 23:27:06339 DidSwapFrame();
340 }
[email protected]74d9063c2013-01-18 03:14:47341}
342
[email protected]a8a049c2013-03-11 23:27:06343scoped_ptr<base::Value> SingleThreadProxy::AsValue() const {
344 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
345 {
346 // The following line casts away const modifiers because it is just
347 // setting debug state. We still want the AsValue() function and its
348 // call chain to be const throughout.
349 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
350
351 state->Set("layer_tree_host_impl",
[email protected]c1bb5af2013-03-13 19:06:27352 layer_tree_host_impl_->AsValue().release());
[email protected]a8a049c2013-03-11 23:27:06353 }
354 return state.PassAs<base::Value>();
[email protected]493067512012-09-19 23:34:10355}
356
[email protected]a8a049c2013-03-11 23:27:06357void SingleThreadProxy::ForceSerializeOnSwapBuffers() {
358 {
359 DebugScopedSetImplThread impl(this);
360 if (renderer_initialized_)
361 layer_tree_host_impl_->renderer()->DoNoOp();
362 }
[email protected]8947cbe2012-11-28 05:27:43363}
364
[email protected]c1bb5af2013-03-13 19:06:27365void SingleThreadProxy::OnSwapBuffersCompleteOnImplThread() { NOTREACHED(); }
[email protected]94f206c12012-08-25 00:09:14366
[email protected]f0c2a242013-03-15 19:34:52367bool SingleThreadProxy::CommitAndComposite(base::TimeTicks frame_begin_time) {
[email protected]a8a049c2013-03-11 23:27:06368 DCHECK(Proxy::IsMainThread());
[email protected]b1969fa2012-10-17 20:16:29369
[email protected]804c8982013-03-13 16:32:21370 if (!layer_tree_host_->InitializeRendererIfNeeded())
[email protected]16288a42012-12-17 23:31:05371 return false;
[email protected]a8a049c2013-03-11 23:27:06372
373 scoped_refptr<cc::ContextProvider> offscreen_context_provider;
[email protected]804c8982013-03-13 16:32:21374 if (renderer_capabilities_for_main_thread_.using_offscreen_context3d &&
375 layer_tree_host_->needs_offscreen_context()) {
[email protected]a8a049c2013-03-11 23:27:06376 offscreen_context_provider =
377 layer_tree_host_->client()->OffscreenContextProviderForMainThread();
[email protected]e06e1122013-03-15 17:12:38378 if (offscreen_context_provider)
379 created_offscreen_context_provider_ = true;
[email protected]a8a049c2013-03-11 23:27:06380 }
381
[email protected]b56c1302013-03-20 21:17:34382 layer_tree_host_->contents_texture_manager()->UnlinkAndClearEvictedBackings();
[email protected]a8a049c2013-03-11 23:27:06383
384 scoped_ptr<ResourceUpdateQueue> queue =
385 make_scoped_ptr(new ResourceUpdateQueue);
[email protected]804c8982013-03-13 16:32:21386 layer_tree_host_->UpdateLayers(
[email protected]c1bb5af2013-03-13 19:06:27387 queue.get(), layer_tree_host_impl_->memory_allocation_limit_bytes());
[email protected]a8a049c2013-03-11 23:27:06388
[email protected]804c8982013-03-13 16:32:21389 layer_tree_host_->WillCommit();
[email protected]a8a049c2013-03-11 23:27:06390 DoCommit(queue.Pass());
[email protected]f0c2a242013-03-15 19:34:52391 bool result = DoComposite(offscreen_context_provider, frame_begin_time);
[email protected]804c8982013-03-13 16:32:21392 layer_tree_host_->DidBeginFrame();
[email protected]a8a049c2013-03-11 23:27:06393 return result;
[email protected]16288a42012-12-17 23:31:05394}
395
[email protected]a8a049c2013-03-11 23:27:06396bool SingleThreadProxy::DoComposite(
[email protected]f0c2a242013-03-15 19:34:52397 scoped_refptr<cc::ContextProvider> offscreen_context_provider,
398 base::TimeTicks frame_begin_time) {
[email protected]a8a049c2013-03-11 23:27:06399 DCHECK(!output_surface_lost_);
400 {
401 DebugScopedSetImplThread impl(this);
402 base::AutoReset<bool> mark_inside(&inside_draw_, true);
403
[email protected]c1bb5af2013-03-13 19:06:27404 layer_tree_host_impl_->resource_provider()->
[email protected]e06e1122013-03-15 17:12:38405 set_offscreen_context_provider(offscreen_context_provider);
[email protected]a8a049c2013-03-11 23:27:06406
407 if (!layer_tree_host_impl_->visible())
408 return false;
409
[email protected]c1bb5af2013-03-13 19:06:27410 layer_tree_host_impl_->Animate(base::TimeTicks::Now(), base::Time::Now());
[email protected]a8a049c2013-03-11 23:27:06411
412 // We guard prepareToDraw() with canDraw() because it always returns a valid
413 // frame, so can only be used when such a frame is possible. Since
414 // drawLayers() depends on the result of prepareToDraw(), it is guarded on
415 // canDraw() as well.
[email protected]c1bb5af2013-03-13 19:06:27416 if (!layer_tree_host_impl_->CanDraw())
[email protected]a8a049c2013-03-11 23:27:06417 return false;
418
419 LayerTreeHostImpl::FrameData frame;
[email protected]c1bb5af2013-03-13 19:06:27420 layer_tree_host_impl_->PrepareToDraw(&frame);
[email protected]f0c2a242013-03-15 19:34:52421 layer_tree_host_impl_->DrawLayers(&frame, frame_begin_time);
[email protected]c1bb5af2013-03-13 19:06:27422 layer_tree_host_impl_->DidDrawAllLayers(frame);
423 output_surface_lost_ = layer_tree_host_impl_->IsContextLost();
[email protected]a8a049c2013-03-11 23:27:06424
[email protected]c1bb5af2013-03-13 19:06:27425 layer_tree_host_impl_->BeginNextFrame();
[email protected]a8a049c2013-03-11 23:27:06426 }
427
428 if (output_surface_lost_) {
429 cc::ContextProvider* offscreen_contexts = layer_tree_host_impl_->
[email protected]c1bb5af2013-03-13 19:06:27430 resource_provider()->offscreen_context_provider();
[email protected]a8a049c2013-03-11 23:27:06431 if (offscreen_contexts)
432 offscreen_contexts->VerifyContexts();
[email protected]804c8982013-03-13 16:32:21433 layer_tree_host_->DidLoseOutputSurface();
[email protected]a8a049c2013-03-11 23:27:06434 return false;
435 }
436
437 return true;
438}
439
440void SingleThreadProxy::DidSwapFrame() {
441 if (next_frame_is_newly_committed_frame_) {
442 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21443 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06444 }
445}
446
447bool SingleThreadProxy::CommitPendingForTesting() { return false; }
448
449skia::RefPtr<SkPicture> SingleThreadProxy::CapturePicture() {
450 // Impl-side painting only.
451 NOTREACHED();
452 return skia::RefPtr<SkPicture>();
[email protected]b9dcf43a2013-01-09 00:15:29453}
454
[email protected]bc5e77c2012-11-05 20:00:49455} // namespace cc