blob: 9c51d4ca36ca6fb89b427eb6c7e4d111aae0d922 [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]96baf3e2012-10-22 23:09:5520scoped_ptr<Proxy> SingleThreadProxy::create(LayerTreeHost* layerTreeHost)
[email protected]94f206c12012-08-25 00:09:1421{
[email protected]96baf3e2012-10-22 23:09:5522 return make_scoped_ptr(new SingleThreadProxy(layerTreeHost)).PassAs<Proxy>();
[email protected]94f206c12012-08-25 00:09:1423}
24
[email protected]96baf3e2012-10-22 23:09:5525SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layerTreeHost)
[email protected]61de5812012-11-08 07:03:4426 : Proxy(scoped_ptr<Thread>(NULL))
27 , m_layerTreeHost(layerTreeHost)
[email protected]3be2171d2012-12-06 06:13:2028 , m_outputSurfaceLost(false)
[email protected]0a451722013-02-22 20:32:0529 , m_createdOffscreenContextProvider(false)
[email protected]94f206c12012-08-25 00:09:1430 , m_rendererInitialized(false)
31 , m_nextFrameIsNewlyCommittedFrame(false)
[email protected]74d9063c2013-01-18 03:14:4732 , m_insideDraw(false)
[email protected]8b9af6b2012-09-27 00:36:3633 , m_totalCommitCount(0)
[email protected]94f206c12012-08-25 00:09:1434{
[email protected]96baf3e2012-10-22 23:09:5535 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
36 DCHECK(Proxy::isMainThread());
[email protected]1e4c352b2013-01-10 02:05:2337 DCHECK(layerTreeHost);
38
39 // Impl-side painting not supported without threaded compositing
40 DCHECK(!layerTreeHost->settings().implSidePainting);
[email protected]94f206c12012-08-25 00:09:1441}
42
[email protected]96baf3e2012-10-22 23:09:5543void SingleThreadProxy::start()
[email protected]94f206c12012-08-25 00:09:1444{
[email protected]61de5812012-11-08 07:03:4445 DebugScopedSetImplThread impl(this);
[email protected]94f206c12012-08-25 00:09:1446 m_layerTreeHostImpl = m_layerTreeHost->createLayerTreeHostImpl(this);
47}
48
[email protected]96baf3e2012-10-22 23:09:5549SingleThreadProxy::~SingleThreadProxy()
[email protected]94f206c12012-08-25 00:09:1450{
[email protected]96baf3e2012-10-22 23:09:5551 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy");
52 DCHECK(Proxy::isMainThread());
[email protected]1d993172012-10-18 18:15:0453 DCHECK(!m_layerTreeHostImpl.get() && !m_layerTreeHost); // make sure stop() got called.
[email protected]94f206c12012-08-25 00:09:1454}
55
[email protected]aad0a0072012-11-01 18:15:5856bool SingleThreadProxy::compositeAndReadback(void *pixels, const gfx::Rect& rect)
[email protected]94f206c12012-08-25 00:09:1457{
[email protected]96baf3e2012-10-22 23:09:5558 TRACE_EVENT0("cc", "SingleThreadProxy::compositeAndReadback");
59 DCHECK(Proxy::isMainThread());
[email protected]94f206c12012-08-25 00:09:1460
61 if (!commitAndComposite())
62 return false;
63
[email protected]e01dddb12013-01-23 03:57:0864 {
65 DebugScopedSetImplThread impl(this);
66 m_layerTreeHostImpl->readback(pixels, rect);
[email protected]94f206c12012-08-25 00:09:1467
[email protected]e01dddb12013-01-23 03:57:0868 if (m_layerTreeHostImpl->isContextLost())
69 return false;
[email protected]94f206c12012-08-25 00:09:1470
[email protected]e01dddb12013-01-23 03:57:0871 m_layerTreeHostImpl->swapBuffers();
72 }
[email protected]94f206c12012-08-25 00:09:1473 didSwapFrame();
74
75 return true;
76}
77
[email protected]c9c1ebe2012-11-05 20:46:1378void SingleThreadProxy::startPageScaleAnimation(gfx::Vector2d targetOffset, bool useAnchor, float scale, base::TimeDelta duration)
[email protected]94f206c12012-08-25 00:09:1479{
[email protected]c9c1ebe2012-11-05 20:46:1380 m_layerTreeHostImpl->startPageScaleAnimation(targetOffset, useAnchor, scale, base::TimeTicks::Now(), duration);
[email protected]94f206c12012-08-25 00:09:1481}
82
[email protected]96baf3e2012-10-22 23:09:5583void SingleThreadProxy::finishAllRendering()
[email protected]94f206c12012-08-25 00:09:1484{
[email protected]96baf3e2012-10-22 23:09:5585 DCHECK(Proxy::isMainThread());
[email protected]94f206c12012-08-25 00:09:1486 {
[email protected]61de5812012-11-08 07:03:4487 DebugScopedSetImplThread impl(this);
[email protected]94f206c12012-08-25 00:09:1488 m_layerTreeHostImpl->finishAllRendering();
89 }
90}
91
[email protected]96baf3e2012-10-22 23:09:5592bool SingleThreadProxy::isStarted() const
[email protected]94f206c12012-08-25 00:09:1493{
[email protected]96baf3e2012-10-22 23:09:5594 DCHECK(Proxy::isMainThread());
[email protected]519281762012-10-06 20:06:3995 return m_layerTreeHostImpl.get();
[email protected]94f206c12012-08-25 00:09:1496}
97
[email protected]3be2171d2012-12-06 06:13:2098bool SingleThreadProxy::initializeOutputSurface()
[email protected]94f206c12012-08-25 00:09:1499{
[email protected]96baf3e2012-10-22 23:09:55100 DCHECK(Proxy::isMainThread());
[email protected]3be2171d2012-12-06 06:13:20101 scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurface();
102 if (!outputSurface.get())
[email protected]94f206c12012-08-25 00:09:14103 return false;
[email protected]3be2171d2012-12-06 06:13:20104 m_outputSurfaceBeforeInitialization = outputSurface.Pass();
[email protected]94f206c12012-08-25 00:09:14105 return true;
106}
107
[email protected]96baf3e2012-10-22 23:09:55108void SingleThreadProxy::setSurfaceReady()
[email protected]94f206c12012-08-25 00:09:14109{
110 // Scheduling is controlled by the embedder in the single thread case, so nothing to do.
111}
112
[email protected]96baf3e2012-10-22 23:09:55113void SingleThreadProxy::setVisible(bool visible)
[email protected]94f206c12012-08-25 00:09:14114{
[email protected]61de5812012-11-08 07:03:44115 DebugScopedSetImplThread impl(this);
[email protected]94f206c12012-08-25 00:09:14116 m_layerTreeHostImpl->setVisible(visible);
117}
118
[email protected]96baf3e2012-10-22 23:09:55119bool SingleThreadProxy::initializeRenderer()
[email protected]94f206c12012-08-25 00:09:14120{
[email protected]96baf3e2012-10-22 23:09:55121 DCHECK(Proxy::isMainThread());
[email protected]3be2171d2012-12-06 06:13:20122 DCHECK(m_outputSurfaceBeforeInitialization.get());
[email protected]94f206c12012-08-25 00:09:14123 {
[email protected]61de5812012-11-08 07:03:44124 DebugScopedSetImplThread impl(this);
[email protected]3be2171d2012-12-06 06:13:20125 bool ok = m_layerTreeHostImpl->initializeRenderer(m_outputSurfaceBeforeInitialization.Pass());
[email protected]94f206c12012-08-25 00:09:14126 if (ok) {
127 m_rendererInitialized = true;
128 m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererCapabilities();
129 }
130
131 return ok;
132 }
133}
134
[email protected]3be2171d2012-12-06 06:13:20135bool SingleThreadProxy::recreateOutputSurface()
[email protected]94f206c12012-08-25 00:09:14136{
[email protected]96baf3e2012-10-22 23:09:55137 TRACE_EVENT0("cc", "SingleThreadProxy::recreateContext");
138 DCHECK(Proxy::isMainThread());
[email protected]3be2171d2012-12-06 06:13:20139 DCHECK(m_outputSurfaceLost);
[email protected]94f206c12012-08-25 00:09:14140
[email protected]3be2171d2012-12-06 06:13:20141 scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurface();
142 if (!outputSurface.get())
[email protected]94f206c12012-08-25 00:09:14143 return false;
[email protected]0a451722013-02-22 20:32:05144 scoped_refptr<cc::ContextProvider> offscreenContextProvider;
145 if (m_createdOffscreenContextProvider) {
146 offscreenContextProvider = m_layerTreeHost->client()->OffscreenContextProviderForMainThread();
147 if (!offscreenContextProvider->InitializeOnMainThread())
148 return false;
149 }
[email protected]94f206c12012-08-25 00:09:14150
151 bool initialized;
152 {
[email protected]61de5812012-11-08 07:03:44153 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
154 DebugScopedSetImplThread impl(this);
[email protected]f14764572012-12-20 03:15:13155 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider());
[email protected]3be2171d2012-12-06 06:13:20156 initialized = m_layerTreeHostImpl->initializeRenderer(outputSurface.Pass());
[email protected]94f206c12012-08-25 00:09:14157 if (initialized) {
158 m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererCapabilities();
[email protected]0a451722013-02-22 20:32:05159 m_layerTreeHostImpl->resourceProvider()->setOffscreenContextProvider(offscreenContextProvider);
160 } else if (offscreenContextProvider) {
161 offscreenContextProvider->VerifyContexts();
[email protected]94f206c12012-08-25 00:09:14162 }
163 }
164
165 if (initialized)
[email protected]3be2171d2012-12-06 06:13:20166 m_outputSurfaceLost = false;
[email protected]94f206c12012-08-25 00:09:14167
168 return initialized;
169}
170
[email protected]96baf3e2012-10-22 23:09:55171void SingleThreadProxy::renderingStats(RenderingStats* stats)
[email protected]94f206c12012-08-25 00:09:14172{
[email protected]121cc752013-01-16 09:12:45173 stats->totalCommitTime = m_totalCommitTime;
[email protected]8b9af6b2012-09-27 00:36:36174 stats->totalCommitCount = m_totalCommitCount;
[email protected]94f206c12012-08-25 00:09:14175 m_layerTreeHostImpl->renderingStats(stats);
176}
177
[email protected]96baf3e2012-10-22 23:09:55178const RendererCapabilities& SingleThreadProxy::rendererCapabilities() const
[email protected]94f206c12012-08-25 00:09:14179{
[email protected]1d993172012-10-18 18:15:04180 DCHECK(m_rendererInitialized);
[email protected]94f206c12012-08-25 00:09:14181 // Note: this gets called during the commit by the "impl" thread
182 return m_RendererCapabilitiesForMainThread;
183}
184
[email protected]96baf3e2012-10-22 23:09:55185void SingleThreadProxy::setNeedsAnimate()
[email protected]94f206c12012-08-25 00:09:14186{
[email protected]96baf3e2012-10-22 23:09:55187 // Thread-only feature
[email protected]1d993172012-10-18 18:15:04188 NOTREACHED();
[email protected]94f206c12012-08-25 00:09:14189}
190
[email protected]b4da2032012-10-25 21:22:55191void SingleThreadProxy::doCommit(scoped_ptr<ResourceUpdateQueue> queue)
[email protected]94f206c12012-08-25 00:09:14192{
[email protected]96baf3e2012-10-22 23:09:55193 DCHECK(Proxy::isMainThread());
[email protected]94f206c12012-08-25 00:09:14194 // Commit immediately
195 {
[email protected]61de5812012-11-08 07:03:44196 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
197 DebugScopedSetImplThread impl(this);
[email protected]94f206c12012-08-25 00:09:14198
[email protected]8b9af6b2012-09-27 00:36:36199 base::TimeTicks startTime = base::TimeTicks::HighResNow();
[email protected]94f206c12012-08-25 00:09:14200 m_layerTreeHostImpl->beginCommit();
201
[email protected]2c7d23f2012-10-15 20:43:25202 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings();
[email protected]94f206c12012-08-25 00:09:14203 m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get());
204
[email protected]b4da2032012-10-25 21:22:55205 scoped_ptr<ResourceUpdateController> updateController =
206 ResourceUpdateController::create(
[email protected]f961b792012-09-20 07:27:33207 NULL,
[email protected]96baf3e2012-10-22 23:09:55208 Proxy::mainThread(),
[email protected]b1b800c2012-10-16 05:03:59209 queue.Pass(),
[email protected]0a451722013-02-22 20:32:05210 m_layerTreeHostImpl->resourceProvider());
[email protected]f961b792012-09-20 07:27:33211 updateController->finalize();
[email protected]94f206c12012-08-25 00:09:14212
213 m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get());
214
215 m_layerTreeHostImpl->commitComplete();
216
[email protected]1d993172012-10-18 18:15:04217#ifndef NDEBUG
[email protected]94f206c12012-08-25 00:09:14218 // In the single-threaded case, the scroll deltas should never be
219 // touched on the impl layer tree.
[email protected]96baf3e2012-10-22 23:09:55220 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processScrollDeltas();
[email protected]1d993172012-10-18 18:15:04221 DCHECK(!scrollInfo->scrolls.size());
[email protected]94f206c12012-08-25 00:09:14222#endif
[email protected]8b9af6b2012-09-27 00:36:36223
224 base::TimeTicks endTime = base::TimeTicks::HighResNow();
225 m_totalCommitTime += endTime - startTime;
226 m_totalCommitCount++;
[email protected]94f206c12012-08-25 00:09:14227 }
228 m_layerTreeHost->commitComplete();
229 m_nextFrameIsNewlyCommittedFrame = true;
230}
231
[email protected]96baf3e2012-10-22 23:09:55232void SingleThreadProxy::setNeedsCommit()
[email protected]94f206c12012-08-25 00:09:14233{
[email protected]96baf3e2012-10-22 23:09:55234 DCHECK(Proxy::isMainThread());
[email protected]94f206c12012-08-25 00:09:14235 m_layerTreeHost->scheduleComposite();
236}
237
[email protected]96baf3e2012-10-22 23:09:55238void SingleThreadProxy::setNeedsRedraw()
[email protected]94f206c12012-08-25 00:09:14239{
240 // FIXME: Once we move render_widget scheduling into this class, we can
241 // treat redraw requests more efficiently than commitAndRedraw requests.
242 m_layerTreeHostImpl->setFullRootLayerDamage();
243 setNeedsCommit();
244}
245
[email protected]2e7ca422012-12-20 02:57:27246void SingleThreadProxy::onHasPendingTreeStateChanged(bool havePendingTree)
247{
248 // Thread-only feature.
249 NOTREACHED();
250}
251
[email protected]6b16679e2012-10-27 00:44:28252void SingleThreadProxy::setDeferCommits(bool deferCommits)
253{
254 // Thread-only feature.
255 NOTREACHED();
256}
257
[email protected]96baf3e2012-10-22 23:09:55258bool SingleThreadProxy::commitRequested() const
[email protected]94f206c12012-08-25 00:09:14259{
260 return false;
261}
262
[email protected]96baf3e2012-10-22 23:09:55263size_t SingleThreadProxy::maxPartialTextureUpdates() const
[email protected]493067512012-09-19 23:34:10264{
265 return std::numeric_limits<size_t>::max();
266}
267
[email protected]96baf3e2012-10-22 23:09:55268void SingleThreadProxy::stop()
[email protected]94f206c12012-08-25 00:09:14269{
[email protected]96baf3e2012-10-22 23:09:55270 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
271 DCHECK(Proxy::isMainThread());
[email protected]94f206c12012-08-25 00:09:14272 {
[email protected]61de5812012-11-08 07:03:44273 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
274 DebugScopedSetImplThread impl(this);
[email protected]94f206c12012-08-25 00:09:14275
[email protected]6f90b9e2013-01-17 23:42:00276 if (!m_layerTreeHostImpl->activeTree()->ContentsTexturesPurged())
[email protected]94f206c12012-08-25 00:09:14277 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider());
[email protected]519281762012-10-06 20:06:39278 m_layerTreeHostImpl.reset();
[email protected]94f206c12012-08-25 00:09:14279 }
280 m_layerTreeHost = 0;
281}
282
[email protected]96baf3e2012-10-22 23:09:55283void SingleThreadProxy::setNeedsRedrawOnImplThread()
[email protected]493067512012-09-19 23:34:10284{
285 m_layerTreeHost->scheduleComposite();
286}
287
[email protected]6367cda2013-01-23 00:21:13288void SingleThreadProxy::didUploadVisibleHighResolutionTileOnImplThread()
[email protected]74d9063c2013-01-18 03:14:47289{
290 // implSidePainting only.
291 NOTREACHED();
292}
293
[email protected]96baf3e2012-10-22 23:09:55294void SingleThreadProxy::setNeedsCommitOnImplThread()
[email protected]493067512012-09-19 23:34:10295{
296 m_layerTreeHost->scheduleComposite();
297}
298
[email protected]8947cbe2012-11-28 05:27:43299void SingleThreadProxy::setNeedsManageTilesOnImplThread()
300{
301 m_layerTreeHost->scheduleComposite();
302}
303
[email protected]30faac92012-10-29 00:06:29304void SingleThreadProxy::postAnimationEventsToMainThreadOnImplThread(scoped_ptr<AnimationEventsVector> events, base::Time wallClockTime)
[email protected]94f206c12012-08-25 00:09:14305{
[email protected]96baf3e2012-10-22 23:09:55306 DCHECK(Proxy::isImplThread());
[email protected]61de5812012-11-08 07:03:44307 DebugScopedSetMainThread main(this);
[email protected]ec1d6d52012-10-10 01:28:57308 m_layerTreeHost->setAnimationEvents(events.Pass(), wallClockTime);
[email protected]94f206c12012-08-25 00:09:14309}
310
[email protected]96baf3e2012-10-22 23:09:55311bool SingleThreadProxy::reduceContentsTextureMemoryOnImplThread(size_t limitBytes, int priorityCutoff)
[email protected]e1fc8b32012-09-18 20:29:09312{
[email protected]1d993172012-10-18 18:15:04313 DCHECK(isImplThread());
[email protected]b1969fa2012-10-17 20:16:29314 if (!m_layerTreeHost->contentsTextureManager())
315 return false;
316
[email protected]a0a00842012-10-22 22:50:28317 return m_layerTreeHost->contentsTextureManager()->reduceMemoryOnImplThread(limitBytes, priorityCutoff, m_layerTreeHostImpl->resourceProvider());
[email protected]e1fc8b32012-09-18 20:29:09318}
319
[email protected]29937ec2013-02-06 22:56:55320void SingleThreadProxy::reduceWastedContentsTextureMemoryOnImplThread()
321{
322 // implSidePainting only.
323 NOTREACHED();
324}
325
[email protected]3d21e022012-10-25 20:03:08326void SingleThreadProxy::sendManagedMemoryStats()
327{
328 DCHECK(Proxy::isImplThread());
[email protected]1235c9cc2012-10-27 03:33:46329 if (!m_layerTreeHostImpl.get())
330 return;
[email protected]1235c9cc2012-10-27 03:33:46331 if (!m_layerTreeHost->contentsTextureManager())
332 return;
333
[email protected]d3afa112012-12-08 06:24:28334 m_layerTreeHostImpl->sendManagedMemoryStats(
[email protected]1235c9cc2012-10-27 03:33:46335 m_layerTreeHost->contentsTextureManager()->memoryVisibleBytes(),
336 m_layerTreeHost->contentsTextureManager()->memoryVisibleAndNearbyBytes(),
337 m_layerTreeHost->contentsTextureManager()->memoryUseBytes());
[email protected]3d21e022012-10-25 20:03:08338}
339
[email protected]74d9063c2013-01-18 03:14:47340bool SingleThreadProxy::isInsideDraw()
341{
342 return m_insideDraw;
343}
344
[email protected]e01dddb12013-01-23 03:57:08345void SingleThreadProxy::didLoseOutputSurfaceOnImplThread()
346{
347 // Cause a commit so we can notice the lost context.
348 setNeedsCommitOnImplThread();
349}
350
[email protected]94f206c12012-08-25 00:09:14351// Called by the legacy scheduling path (e.g. where render_widget does the scheduling)
[email protected]96baf3e2012-10-22 23:09:55352void SingleThreadProxy::compositeImmediately()
[email protected]94f206c12012-08-25 00:09:14353{
354 if (commitAndComposite()) {
355 m_layerTreeHostImpl->swapBuffers();
356 didSwapFrame();
357 }
358}
359
[email protected]131a0c22013-02-12 18:31:08360scoped_ptr<base::Value> SingleThreadProxy::asValue() const
361{
362 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
363 {
364 // The following line casts away const modifiers because it is just
365 // setting debug state. We still want the asValue() function and its
366 // call chain to be const throughout.
367 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
368
369 state->Set("layer_tree_host_impl", m_layerTreeHostImpl->asValue().release());
370 }
371 return state.PassAs<base::Value>();
372}
373
[email protected]96baf3e2012-10-22 23:09:55374void SingleThreadProxy::forceSerializeOnSwapBuffers()
[email protected]94f206c12012-08-25 00:09:14375{
376 {
[email protected]61de5812012-11-08 07:03:44377 DebugScopedSetImplThread impl(this);
[email protected]94f206c12012-08-25 00:09:14378 if (m_rendererInitialized)
379 m_layerTreeHostImpl->renderer()->doNoOp();
380 }
381}
382
[email protected]96baf3e2012-10-22 23:09:55383void SingleThreadProxy::onSwapBuffersCompleteOnImplThread()
[email protected]493067512012-09-19 23:34:10384{
[email protected]1d993172012-10-18 18:15:04385 NOTREACHED();
[email protected]493067512012-09-19 23:34:10386}
387
[email protected]96baf3e2012-10-22 23:09:55388bool SingleThreadProxy::commitAndComposite()
[email protected]94f206c12012-08-25 00:09:14389{
[email protected]96baf3e2012-10-22 23:09:55390 DCHECK(Proxy::isMainThread());
[email protected]94f206c12012-08-25 00:09:14391
[email protected]94f206c12012-08-25 00:09:14392 if (!m_layerTreeHost->initializeRendererIfNeeded())
393 return false;
394
[email protected]0a451722013-02-22 20:32:05395 scoped_refptr<cc::ContextProvider> offscreenContextProvider;
396 if (m_RendererCapabilitiesForMainThread.usingOffscreenContext3d && m_layerTreeHost->needsOffscreenContext()) {
397 offscreenContextProvider = m_layerTreeHost->client()->OffscreenContextProviderForMainThread();
398 if (offscreenContextProvider->InitializeOnMainThread())
399 m_createdOffscreenContextProvider = true;
400 else
401 offscreenContextProvider = NULL;
402 }
403
[email protected]9fa7d382012-11-30 05:21:14404 m_layerTreeHost->contentsTextureManager()->unlinkAndClearEvictedBackings();
[email protected]94f206c12012-08-25 00:09:14405
[email protected]b4da2032012-10-25 21:22:55406 scoped_ptr<ResourceUpdateQueue> queue = make_scoped_ptr(new ResourceUpdateQueue);
[email protected]f961b792012-09-20 07:27:33407 m_layerTreeHost->updateLayers(*(queue.get()), m_layerTreeHostImpl->memoryAllocationLimitBytes());
[email protected]e1fc8b32012-09-18 20:29:09408
[email protected]94f206c12012-08-25 00:09:14409 m_layerTreeHost->willCommit();
[email protected]b1b800c2012-10-16 05:03:59410 doCommit(queue.Pass());
[email protected]0a451722013-02-22 20:32:05411 bool result = doComposite(offscreenContextProvider);
[email protected]94f206c12012-08-25 00:09:14412 m_layerTreeHost->didBeginFrame();
413 return result;
414}
415
[email protected]0a451722013-02-22 20:32:05416bool SingleThreadProxy::doComposite(scoped_refptr<cc::ContextProvider> offscreenContextProvider)
[email protected]94f206c12012-08-25 00:09:14417{
[email protected]3be2171d2012-12-06 06:13:20418 DCHECK(!m_outputSurfaceLost);
[email protected]94f206c12012-08-25 00:09:14419 {
[email protected]61de5812012-11-08 07:03:44420 DebugScopedSetImplThread impl(this);
[email protected]74d9063c2013-01-18 03:14:47421 base::AutoReset<bool> markInside(&m_insideDraw, true);
[email protected]94f206c12012-08-25 00:09:14422
[email protected]0a451722013-02-22 20:32:05423 m_layerTreeHostImpl->resourceProvider()->setOffscreenContextProvider(offscreenContextProvider);
424
[email protected]94f206c12012-08-25 00:09:14425 if (!m_layerTreeHostImpl->visible())
426 return false;
427
[email protected]30faac92012-10-29 00:06:29428 m_layerTreeHostImpl->animate(base::TimeTicks::Now(), base::Time::Now());
[email protected]94f206c12012-08-25 00:09:14429
430 // We guard prepareToDraw() with canDraw() because it always returns a valid frame, so can only
431 // be used when such a frame is possible. Since drawLayers() depends on the result of
432 // prepareToDraw(), it is guarded on canDraw() as well.
433 if (!m_layerTreeHostImpl->canDraw())
434 return false;
435
[email protected]96baf3e2012-10-22 23:09:55436 LayerTreeHostImpl::FrameData frame;
[email protected]94f206c12012-08-25 00:09:14437 m_layerTreeHostImpl->prepareToDraw(frame);
438 m_layerTreeHostImpl->drawLayers(frame);
439 m_layerTreeHostImpl->didDrawAllLayers(frame);
[email protected]e01dddb12013-01-23 03:57:08440 m_outputSurfaceLost = m_layerTreeHostImpl->isContextLost();
[email protected]829ad972013-01-28 23:36:10441
442 m_layerTreeHostImpl->beginNextFrame();
[email protected]94f206c12012-08-25 00:09:14443 }
444
[email protected]e01dddb12013-01-23 03:57:08445 if (m_outputSurfaceLost) {
[email protected]0a451722013-02-22 20:32:05446 if (cc::ContextProvider* offscreenContexts = m_layerTreeHostImpl->resourceProvider()->offscreenContextProvider())
447 offscreenContexts->VerifyContexts();
[email protected]3be2171d2012-12-06 06:13:20448 m_layerTreeHost->didLoseOutputSurface();
[email protected]94f206c12012-08-25 00:09:14449 return false;
450 }
451
452 return true;
453}
454
[email protected]96baf3e2012-10-22 23:09:55455void SingleThreadProxy::didSwapFrame()
[email protected]94f206c12012-08-25 00:09:14456{
457 if (m_nextFrameIsNewlyCommittedFrame) {
458 m_nextFrameIsNewlyCommittedFrame = false;
459 m_layerTreeHost->didCommitAndDrawFrame();
460 }
461}
462
[email protected]16288a42012-12-17 23:31:05463bool SingleThreadProxy::commitPendingForTesting()
464{
465 return false;
466}
467
[email protected]b9dcf43a2013-01-09 00:15:29468skia::RefPtr<SkPicture> SingleThreadProxy::capturePicture()
469{
470 // Requires impl-side painting, which is only supported in threaded compositing.
471 NOTREACHED();
472 return skia::RefPtr<SkPicture>();
473}
474
[email protected]bc5e77c2012-11-05 20:00:49475} // namespace cc