blob: 0c2314baa9529cbda0b3015f41efa115e6628946 [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]4456eee22012-10-19 18:16:385#include "cc/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]0a451722013-02-22 20:32:059#include "cc/context_provider.h"
[email protected]aa0a9d32012-10-24 01:58:1010#include "cc/draw_quad.h"
[email protected]d50c6862012-10-23 02:08:3111#include "cc/layer_tree_host.h"
[email protected]6f90b9e2013-01-17 23:42:0012#include "cc/layer_tree_impl.h"
[email protected]3be2171d2012-12-06 06:13:2013#include "cc/output_surface.h"
[email protected]cd98a8c32013-01-08 18:16:1714#include "cc/prioritized_resource_manager.h"
[email protected]b4da2032012-10-25 21:22:5515#include "cc/resource_update_controller.h"
[email protected]61de5812012-11-08 07:03:4416#include "cc/thread.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),
29 created_offscreen_context_provider(false),
30 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]a8a049c2013-03-11 23:27:0638 // Impl-side painting not supported without threaded compositing
39 DCHECK(!layer_tree_host->settings().implSidePainting);
[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) {
55 TRACE_EVENT0("cc", "SingleThreadProxy::compositeAndReadback");
56 DCHECK(Proxy::IsMainThread());
57
58 if (!CommitAndComposite())
59 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());
98 scoped_ptr<OutputSurface> outputSurface =
[email protected]804c8982013-03-13 16:32:2199 layer_tree_host_->CreateOutputSurface();
[email protected]a8a049c2013-03-11 23:27:06100 if (!outputSurface.get())
101 return false;
102 output_surface_before_initialization_ = outputSurface.Pass();
103 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() {
134 TRACE_EVENT0("cc", "SingleThreadProxy::recreateContext");
135 DCHECK(Proxy::IsMainThread());
136 DCHECK(output_surface_lost_);
137
138 scoped_ptr<OutputSurface> outputSurface =
[email protected]804c8982013-03-13 16:32:21139 layer_tree_host_->CreateOutputSurface();
[email protected]a8a049c2013-03-11 23:27:06140 if (!outputSurface.get())
141 return false;
142 scoped_refptr<cc::ContextProvider> offscreen_context_provider;
143 if (created_offscreen_context_provider) {
144 offscreen_context_provider =
145 layer_tree_host_->client()->OffscreenContextProviderForMainThread();
146 if (!offscreen_context_provider->InitializeOnMainThread())
147 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]c1bb5af2013-03-13 19:06:27157 layer_tree_host_impl_->InitializeRenderer(outputSurface.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();
161 layer_tree_host_impl_->resource_provider()
[email protected]a8a049c2013-03-11 23:27:06162 ->SetOffscreenContextProvider(offscreen_context_provider);
163 } 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]804c8982013-03-13 16:32:21174void SingleThreadProxy::CollectRenderingStats(RenderingStats* stats) {
[email protected]a8a049c2013-03-11 23:27:06175 stats->totalCommitTime = total_commit_time_;
176 stats->totalCommitCount = total_commit_count_;
[email protected]c1bb5af2013-03-13 19:06:27177 layer_tree_host_impl_->CollectRenderingStats(stats);
[email protected]94f206c12012-08-25 00:09:14178}
179
[email protected]a8a049c2013-03-11 23:27:06180const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const {
181 DCHECK(renderer_initialized_);
182 // Note: this gets called during the commit by the "impl" thread.
183 return renderer_capabilities_for_main_thread_;
[email protected]94f206c12012-08-25 00:09:14184}
185
[email protected]a8a049c2013-03-11 23:27:06186void SingleThreadProxy::SetNeedsAnimate() {
187 // Thread-only feature.
188 NOTREACHED();
[email protected]94f206c12012-08-25 00:09:14189}
190
[email protected]a8a049c2013-03-11 23:27:06191void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) {
192 DCHECK(Proxy::IsMainThread());
193 // Commit immediately.
194 {
195 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
196 DebugScopedSetImplThread impl(this);
[email protected]94f206c12012-08-25 00:09:14197
[email protected]a8a049c2013-03-11 23:27:06198 base::TimeTicks startTime = base::TimeTicks::HighResNow();
[email protected]c1bb5af2013-03-13 19:06:27199 layer_tree_host_impl_->BeginCommit();
[email protected]94f206c12012-08-25 00:09:14200
[email protected]804c8982013-03-13 16:32:21201 layer_tree_host_->contents_texture_manager()->
[email protected]a8a049c2013-03-11 23:27:06202 pushTexturePrioritiesToBackings();
[email protected]804c8982013-03-13 16:32:21203 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14204
[email protected]a8a049c2013-03-11 23:27:06205 scoped_ptr<ResourceUpdateController> updateController =
206 ResourceUpdateController::Create(
207 NULL,
208 Proxy::MainThread(),
209 queue.Pass(),
[email protected]c1bb5af2013-03-13 19:06:27210 layer_tree_host_impl_->resource_provider());
[email protected]a8a049c2013-03-11 23:27:06211 updateController->Finalize();
[email protected]94f206c12012-08-25 00:09:14212
[email protected]804c8982013-03-13 16:32:21213 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
[email protected]94f206c12012-08-25 00:09:14214
[email protected]c1bb5af2013-03-13 19:06:27215 layer_tree_host_impl_->CommitComplete();
[email protected]94f206c12012-08-25 00:09:14216
[email protected]1d993172012-10-18 18:15:04217#ifndef NDEBUG
[email protected]a8a049c2013-03-11 23:27:06218 // In the single-threaded case, the scroll deltas should never be
219 // touched on the impl layer tree.
220 scoped_ptr<ScrollAndScaleSet> scrollInfo =
[email protected]c1bb5af2013-03-13 19:06:27221 layer_tree_host_impl_->ProcessScrollDeltas();
[email protected]a8a049c2013-03-11 23:27:06222 DCHECK(!scrollInfo->scrolls.size());
[email protected]94f206c12012-08-25 00:09:14223#endif
[email protected]8b9af6b2012-09-27 00:36:36224
[email protected]a8a049c2013-03-11 23:27:06225 base::TimeTicks endTime = base::TimeTicks::HighResNow();
226 total_commit_time_ += endTime - startTime;
227 total_commit_count_++;
228 }
[email protected]804c8982013-03-13 16:32:21229 layer_tree_host_->CommitComplete();
[email protected]a8a049c2013-03-11 23:27:06230 next_frame_is_newly_committed_frame_ = true;
[email protected]94f206c12012-08-25 00:09:14231}
232
[email protected]a8a049c2013-03-11 23:27:06233void SingleThreadProxy::SetNeedsCommit() {
234 DCHECK(Proxy::IsMainThread());
[email protected]804c8982013-03-13 16:32:21235 layer_tree_host_->ScheduleComposite();
[email protected]94f206c12012-08-25 00:09:14236}
237
[email protected]a8a049c2013-03-11 23:27:06238void SingleThreadProxy::SetNeedsRedraw() {
239 // FIXME: Once we move render_widget scheduling into this class, we can
240 // treat redraw requests more efficiently than commitAndRedraw requests.
241 layer_tree_host_impl_->SetFullRootLayerDamage();
242 SetNeedsCommit();
[email protected]94f206c12012-08-25 00:09:14243}
244
[email protected]c1bb5af2013-03-13 19:06:27245void SingleThreadProxy::OnHasPendingTreeStateChanged(bool have_pending_tree) {
[email protected]a8a049c2013-03-11 23:27:06246 // Thread-only feature.
247 NOTREACHED();
[email protected]2e7ca422012-12-20 02:57:27248}
249
[email protected]a8a049c2013-03-11 23:27:06250void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
251 // Thread-only feature.
252 NOTREACHED();
[email protected]6b16679e2012-10-27 00:44:28253}
254
[email protected]a8a049c2013-03-11 23:27:06255bool SingleThreadProxy::CommitRequested() const { return false; }
256
257size_t SingleThreadProxy::MaxPartialTextureUpdates() const {
258 return std::numeric_limits<size_t>::max();
259}
260
261void SingleThreadProxy::Stop() {
262 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
263 DCHECK(Proxy::IsMainThread());
264 {
265 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
266 DebugScopedSetImplThread impl(this);
267
[email protected]804c8982013-03-13 16:32:21268 layer_tree_host_->DeleteContentsTexturesOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27269 layer_tree_host_impl_->resource_provider());
[email protected]a8a049c2013-03-11 23:27:06270 layer_tree_host_impl_.reset();
271 }
[email protected]7aba6662013-03-12 10:17:34272 layer_tree_host_ = NULL;
[email protected]a8a049c2013-03-11 23:27:06273}
274
[email protected]c1bb5af2013-03-13 19:06:27275void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
[email protected]804c8982013-03-13 16:32:21276 layer_tree_host_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06277}
278
[email protected]c1bb5af2013-03-13 19:06:27279void SingleThreadProxy::DidUploadVisibleHighResolutionTileOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06280 // Impl-side painting only.
281 NOTREACHED();
282}
283
[email protected]c1bb5af2013-03-13 19:06:27284void SingleThreadProxy::SetNeedsCommitOnImplThread() {
[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::SetNeedsManageTilesOnImplThread() {
[email protected]804c8982013-03-13 16:32:21289 layer_tree_host_->ScheduleComposite();
[email protected]a8a049c2013-03-11 23:27:06290}
291
[email protected]c1bb5af2013-03-13 19:06:27292void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
[email protected]a8a049c2013-03-11 23:27:06293 scoped_ptr<AnimationEventsVector> events,
294 base::Time wall_clock_time) {
295 DCHECK(Proxy::IsImplThread());
296 DebugScopedSetMainThread main(this);
[email protected]804c8982013-03-13 16:32:21297 layer_tree_host_->SetAnimationEvents(events.Pass(), wall_clock_time);
[email protected]a8a049c2013-03-11 23:27:06298}
299
[email protected]c1bb5af2013-03-13 19:06:27300bool SingleThreadProxy::ReduceContentsTextureMemoryOnImplThread(
[email protected]a8a049c2013-03-11 23:27:06301 size_t limit_bytes,
302 int priority_cutoff) {
303 DCHECK(IsImplThread());
[email protected]804c8982013-03-13 16:32:21304 if (!layer_tree_host_->contents_texture_manager())
[email protected]94f206c12012-08-25 00:09:14305 return false;
[email protected]a8a049c2013-03-11 23:27:06306
[email protected]804c8982013-03-13 16:32:21307 return layer_tree_host_->contents_texture_manager()->reduceMemoryOnImplThread(
[email protected]c1bb5af2013-03-13 19:06:27308 limit_bytes, priority_cutoff, layer_tree_host_impl_->resource_provider());
[email protected]94f206c12012-08-25 00:09:14309}
310
[email protected]c1bb5af2013-03-13 19:06:27311void SingleThreadProxy::ReduceWastedContentsTextureMemoryOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06312 // Impl-side painting only.
313 NOTREACHED();
[email protected]493067512012-09-19 23:34:10314}
315
[email protected]c1bb5af2013-03-13 19:06:27316void SingleThreadProxy::SendManagedMemoryStats() {
[email protected]a8a049c2013-03-11 23:27:06317 DCHECK(Proxy::IsImplThread());
318 if (!layer_tree_host_impl_.get())
319 return;
[email protected]804c8982013-03-13 16:32:21320 if (!layer_tree_host_->contents_texture_manager())
[email protected]a8a049c2013-03-11 23:27:06321 return;
[email protected]94f206c12012-08-25 00:09:14322
[email protected]804c8982013-03-13 16:32:21323 PrioritizedResourceManager* contents_texture_manager =
324 layer_tree_host_->contents_texture_manager();
[email protected]c1bb5af2013-03-13 19:06:27325 layer_tree_host_impl_->SendManagedMemoryStats(
[email protected]804c8982013-03-13 16:32:21326 contents_texture_manager->memoryVisibleBytes(),
327 contents_texture_manager->memoryVisibleAndNearbyBytes(),
328 contents_texture_manager->memoryUseBytes());
[email protected]94f206c12012-08-25 00:09:14329}
330
[email protected]c1bb5af2013-03-13 19:06:27331bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
[email protected]a8a049c2013-03-11 23:27:06332
[email protected]c1bb5af2013-03-13 19:06:27333void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
[email protected]a8a049c2013-03-11 23:27:06334 // Cause a commit so we can notice the lost context.
[email protected]c1bb5af2013-03-13 19:06:27335 SetNeedsCommitOnImplThread();
[email protected]493067512012-09-19 23:34:10336}
337
[email protected]a8a049c2013-03-11 23:27:06338// Called by the legacy scheduling path (e.g. where render_widget does the
339// scheduling)
340void SingleThreadProxy::CompositeImmediately() {
341 if (CommitAndComposite()) {
[email protected]c1bb5af2013-03-13 19:06:27342 layer_tree_host_impl_->SwapBuffers();
[email protected]a8a049c2013-03-11 23:27:06343 DidSwapFrame();
344 }
[email protected]74d9063c2013-01-18 03:14:47345}
346
[email protected]a8a049c2013-03-11 23:27:06347scoped_ptr<base::Value> SingleThreadProxy::AsValue() const {
348 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
349 {
350 // The following line casts away const modifiers because it is just
351 // setting debug state. We still want the AsValue() function and its
352 // call chain to be const throughout.
353 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
354
355 state->Set("layer_tree_host_impl",
[email protected]c1bb5af2013-03-13 19:06:27356 layer_tree_host_impl_->AsValue().release());
[email protected]a8a049c2013-03-11 23:27:06357 }
358 return state.PassAs<base::Value>();
[email protected]493067512012-09-19 23:34:10359}
360
[email protected]a8a049c2013-03-11 23:27:06361void SingleThreadProxy::ForceSerializeOnSwapBuffers() {
362 {
363 DebugScopedSetImplThread impl(this);
364 if (renderer_initialized_)
365 layer_tree_host_impl_->renderer()->DoNoOp();
366 }
[email protected]8947cbe2012-11-28 05:27:43367}
368
[email protected]c1bb5af2013-03-13 19:06:27369void SingleThreadProxy::OnSwapBuffersCompleteOnImplThread() { NOTREACHED(); }
[email protected]94f206c12012-08-25 00:09:14370
[email protected]a8a049c2013-03-11 23:27:06371bool SingleThreadProxy::CommitAndComposite() {
372 DCHECK(Proxy::IsMainThread());
[email protected]b1969fa2012-10-17 20:16:29373
[email protected]804c8982013-03-13 16:32:21374 if (!layer_tree_host_->InitializeRendererIfNeeded())
[email protected]16288a42012-12-17 23:31:05375 return false;
[email protected]a8a049c2013-03-11 23:27:06376
377 scoped_refptr<cc::ContextProvider> offscreen_context_provider;
[email protected]804c8982013-03-13 16:32:21378 if (renderer_capabilities_for_main_thread_.using_offscreen_context3d &&
379 layer_tree_host_->needs_offscreen_context()) {
[email protected]a8a049c2013-03-11 23:27:06380 offscreen_context_provider =
381 layer_tree_host_->client()->OffscreenContextProviderForMainThread();
382 if (offscreen_context_provider->InitializeOnMainThread())
383 created_offscreen_context_provider = true;
384 else
385 offscreen_context_provider = NULL;
386 }
387
[email protected]804c8982013-03-13 16:32:21388 layer_tree_host_->contents_texture_manager()->unlinkAndClearEvictedBackings();
[email protected]a8a049c2013-03-11 23:27:06389
390 scoped_ptr<ResourceUpdateQueue> queue =
391 make_scoped_ptr(new ResourceUpdateQueue);
[email protected]804c8982013-03-13 16:32:21392 layer_tree_host_->UpdateLayers(
[email protected]c1bb5af2013-03-13 19:06:27393 queue.get(), layer_tree_host_impl_->memory_allocation_limit_bytes());
[email protected]a8a049c2013-03-11 23:27:06394
[email protected]804c8982013-03-13 16:32:21395 layer_tree_host_->WillCommit();
[email protected]a8a049c2013-03-11 23:27:06396 DoCommit(queue.Pass());
397 bool result = DoComposite(offscreen_context_provider);
[email protected]804c8982013-03-13 16:32:21398 layer_tree_host_->DidBeginFrame();
[email protected]a8a049c2013-03-11 23:27:06399 return result;
[email protected]16288a42012-12-17 23:31:05400}
401
[email protected]a8a049c2013-03-11 23:27:06402bool SingleThreadProxy::DoComposite(
403 scoped_refptr<cc::ContextProvider> offscreen_context_provider) {
404 DCHECK(!output_surface_lost_);
405 {
406 DebugScopedSetImplThread impl(this);
407 base::AutoReset<bool> mark_inside(&inside_draw_, true);
408
[email protected]c1bb5af2013-03-13 19:06:27409 layer_tree_host_impl_->resource_provider()->
[email protected]a8a049c2013-03-11 23:27:06410 SetOffscreenContextProvider(offscreen_context_provider);
411
412 if (!layer_tree_host_impl_->visible())
413 return false;
414
[email protected]c1bb5af2013-03-13 19:06:27415 layer_tree_host_impl_->Animate(base::TimeTicks::Now(), base::Time::Now());
[email protected]a8a049c2013-03-11 23:27:06416
417 // We guard prepareToDraw() with canDraw() because it always returns a valid
418 // frame, so can only be used when such a frame is possible. Since
419 // drawLayers() depends on the result of prepareToDraw(), it is guarded on
420 // canDraw() as well.
[email protected]c1bb5af2013-03-13 19:06:27421 if (!layer_tree_host_impl_->CanDraw())
[email protected]a8a049c2013-03-11 23:27:06422 return false;
423
424 LayerTreeHostImpl::FrameData frame;
[email protected]c1bb5af2013-03-13 19:06:27425 layer_tree_host_impl_->PrepareToDraw(&frame);
426 layer_tree_host_impl_->DrawLayers(&frame);
427 layer_tree_host_impl_->DidDrawAllLayers(frame);
428 output_surface_lost_ = layer_tree_host_impl_->IsContextLost();
[email protected]a8a049c2013-03-11 23:27:06429
[email protected]c1bb5af2013-03-13 19:06:27430 layer_tree_host_impl_->BeginNextFrame();
[email protected]a8a049c2013-03-11 23:27:06431 }
432
433 if (output_surface_lost_) {
434 cc::ContextProvider* offscreen_contexts = layer_tree_host_impl_->
[email protected]c1bb5af2013-03-13 19:06:27435 resource_provider()->offscreen_context_provider();
[email protected]a8a049c2013-03-11 23:27:06436 if (offscreen_contexts)
437 offscreen_contexts->VerifyContexts();
[email protected]804c8982013-03-13 16:32:21438 layer_tree_host_->DidLoseOutputSurface();
[email protected]a8a049c2013-03-11 23:27:06439 return false;
440 }
441
442 return true;
443}
444
445void SingleThreadProxy::DidSwapFrame() {
446 if (next_frame_is_newly_committed_frame_) {
447 next_frame_is_newly_committed_frame_ = false;
[email protected]804c8982013-03-13 16:32:21448 layer_tree_host_->DidCommitAndDrawFrame();
[email protected]a8a049c2013-03-11 23:27:06449 }
450}
451
452bool SingleThreadProxy::CommitPendingForTesting() { return false; }
453
454skia::RefPtr<SkPicture> SingleThreadProxy::CapturePicture() {
455 // Impl-side painting only.
456 NOTREACHED();
457 return skia::RefPtr<SkPicture>();
[email protected]b9dcf43a2013-01-09 00:15:29458}
459
[email protected]bc5e77c2012-11-05 20:00:49460} // namespace cc