[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1 | // 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] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 5 | #include "cc/single_thread_proxy.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
[email protected] | 74d9063c | 2013-01-18 03:14:47 | [diff] [blame] | 7 | #include "base/auto_reset.h" |
[email protected] | 6331a117 | 2012-10-18 11:35:13 | [diff] [blame] | 8 | #include "base/debug/trace_event.h" |
[email protected] | 0a45172 | 2013-02-22 20:32:05 | [diff] [blame^] | 9 | #include "cc/context_provider.h" |
[email protected] | aa0a9d3 | 2012-10-24 01:58:10 | [diff] [blame] | 10 | #include "cc/draw_quad.h" |
[email protected] | d50c686 | 2012-10-23 02:08:31 | [diff] [blame] | 11 | #include "cc/layer_tree_host.h" |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 12 | #include "cc/layer_tree_impl.h" |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 13 | #include "cc/output_surface.h" |
[email protected] | cd98a8c3 | 2013-01-08 18:16:17 | [diff] [blame] | 14 | #include "cc/prioritized_resource_manager.h" |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 15 | #include "cc/resource_update_controller.h" |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 16 | #include "cc/thread.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 17 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 18 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 19 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 20 | scoped_ptr<Proxy> SingleThreadProxy::create(LayerTreeHost* layerTreeHost) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 21 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 22 | return make_scoped_ptr(new SingleThreadProxy(layerTreeHost)).PassAs<Proxy>(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 23 | } |
| 24 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 25 | SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layerTreeHost) |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 26 | : Proxy(scoped_ptr<Thread>(NULL)) |
| 27 | , m_layerTreeHost(layerTreeHost) |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 28 | , m_outputSurfaceLost(false) |
[email protected] | 0a45172 | 2013-02-22 20:32:05 | [diff] [blame^] | 29 | , m_createdOffscreenContextProvider(false) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 30 | , m_rendererInitialized(false) |
| 31 | , m_nextFrameIsNewlyCommittedFrame(false) |
[email protected] | 74d9063c | 2013-01-18 03:14:47 | [diff] [blame] | 32 | , m_insideDraw(false) |
[email protected] | 8b9af6b | 2012-09-27 00:36:36 | [diff] [blame] | 33 | , m_totalCommitCount(0) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 34 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 35 | TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
| 36 | DCHECK(Proxy::isMainThread()); |
[email protected] | 1e4c352b | 2013-01-10 02:05:23 | [diff] [blame] | 37 | DCHECK(layerTreeHost); |
| 38 | |
| 39 | // Impl-side painting not supported without threaded compositing |
| 40 | DCHECK(!layerTreeHost->settings().implSidePainting); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 41 | } |
| 42 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 43 | void SingleThreadProxy::start() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 44 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 45 | DebugScopedSetImplThread impl(this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 46 | m_layerTreeHostImpl = m_layerTreeHost->createLayerTreeHostImpl(this); |
| 47 | } |
| 48 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 49 | SingleThreadProxy::~SingleThreadProxy() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 50 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 51 | TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); |
| 52 | DCHECK(Proxy::isMainThread()); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 53 | DCHECK(!m_layerTreeHostImpl.get() && !m_layerTreeHost); // make sure stop() got called. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 54 | } |
| 55 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 56 | bool SingleThreadProxy::compositeAndReadback(void *pixels, const gfx::Rect& rect) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 57 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 58 | TRACE_EVENT0("cc", "SingleThreadProxy::compositeAndReadback"); |
| 59 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 60 | |
| 61 | if (!commitAndComposite()) |
| 62 | return false; |
| 63 | |
[email protected] | e01dddb1 | 2013-01-23 03:57:08 | [diff] [blame] | 64 | { |
| 65 | DebugScopedSetImplThread impl(this); |
| 66 | m_layerTreeHostImpl->readback(pixels, rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 67 | |
[email protected] | e01dddb1 | 2013-01-23 03:57:08 | [diff] [blame] | 68 | if (m_layerTreeHostImpl->isContextLost()) |
| 69 | return false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 70 | |
[email protected] | e01dddb1 | 2013-01-23 03:57:08 | [diff] [blame] | 71 | m_layerTreeHostImpl->swapBuffers(); |
| 72 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 73 | didSwapFrame(); |
| 74 | |
| 75 | return true; |
| 76 | } |
| 77 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 78 | void SingleThreadProxy::startPageScaleAnimation(gfx::Vector2d targetOffset, bool useAnchor, float scale, base::TimeDelta duration) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 79 | { |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 80 | m_layerTreeHostImpl->startPageScaleAnimation(targetOffset, useAnchor, scale, base::TimeTicks::Now(), duration); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 81 | } |
| 82 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 83 | void SingleThreadProxy::finishAllRendering() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 84 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 85 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 86 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 87 | DebugScopedSetImplThread impl(this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 88 | m_layerTreeHostImpl->finishAllRendering(); |
| 89 | } |
| 90 | } |
| 91 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 92 | bool SingleThreadProxy::isStarted() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 93 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 94 | DCHECK(Proxy::isMainThread()); |
[email protected] | 51928176 | 2012-10-06 20:06:39 | [diff] [blame] | 95 | return m_layerTreeHostImpl.get(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 96 | } |
| 97 | |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 98 | bool SingleThreadProxy::initializeOutputSurface() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 99 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 100 | DCHECK(Proxy::isMainThread()); |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 101 | scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurface(); |
| 102 | if (!outputSurface.get()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 103 | return false; |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 104 | m_outputSurfaceBeforeInitialization = outputSurface.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 105 | return true; |
| 106 | } |
| 107 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 108 | void SingleThreadProxy::setSurfaceReady() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 109 | { |
| 110 | // Scheduling is controlled by the embedder in the single thread case, so nothing to do. |
| 111 | } |
| 112 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 113 | void SingleThreadProxy::setVisible(bool visible) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 114 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 115 | DebugScopedSetImplThread impl(this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 116 | m_layerTreeHostImpl->setVisible(visible); |
| 117 | } |
| 118 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 119 | bool SingleThreadProxy::initializeRenderer() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 120 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 121 | DCHECK(Proxy::isMainThread()); |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 122 | DCHECK(m_outputSurfaceBeforeInitialization.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 123 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 124 | DebugScopedSetImplThread impl(this); |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 125 | bool ok = m_layerTreeHostImpl->initializeRenderer(m_outputSurfaceBeforeInitialization.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 126 | if (ok) { |
| 127 | m_rendererInitialized = true; |
| 128 | m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererCapabilities(); |
| 129 | } |
| 130 | |
| 131 | return ok; |
| 132 | } |
| 133 | } |
| 134 | |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 135 | bool SingleThreadProxy::recreateOutputSurface() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 136 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 137 | TRACE_EVENT0("cc", "SingleThreadProxy::recreateContext"); |
| 138 | DCHECK(Proxy::isMainThread()); |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 139 | DCHECK(m_outputSurfaceLost); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 140 | |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 141 | scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurface(); |
| 142 | if (!outputSurface.get()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 143 | return false; |
[email protected] | 0a45172 | 2013-02-22 20:32:05 | [diff] [blame^] | 144 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 150 | |
| 151 | bool initialized; |
| 152 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 153 | DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
| 154 | DebugScopedSetImplThread impl(this); |
[email protected] | f1476457 | 2012-12-20 03:15:13 | [diff] [blame] | 155 | m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider()); |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 156 | initialized = m_layerTreeHostImpl->initializeRenderer(outputSurface.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 157 | if (initialized) { |
| 158 | m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererCapabilities(); |
[email protected] | 0a45172 | 2013-02-22 20:32:05 | [diff] [blame^] | 159 | m_layerTreeHostImpl->resourceProvider()->setOffscreenContextProvider(offscreenContextProvider); |
| 160 | } else if (offscreenContextProvider) { |
| 161 | offscreenContextProvider->VerifyContexts(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | |
| 165 | if (initialized) |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 166 | m_outputSurfaceLost = false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 167 | |
| 168 | return initialized; |
| 169 | } |
| 170 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 171 | void SingleThreadProxy::renderingStats(RenderingStats* stats) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 172 | { |
[email protected] | 121cc75 | 2013-01-16 09:12:45 | [diff] [blame] | 173 | stats->totalCommitTime = m_totalCommitTime; |
[email protected] | 8b9af6b | 2012-09-27 00:36:36 | [diff] [blame] | 174 | stats->totalCommitCount = m_totalCommitCount; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 175 | m_layerTreeHostImpl->renderingStats(stats); |
| 176 | } |
| 177 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 178 | const RendererCapabilities& SingleThreadProxy::rendererCapabilities() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 179 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 180 | DCHECK(m_rendererInitialized); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 181 | // Note: this gets called during the commit by the "impl" thread |
| 182 | return m_RendererCapabilitiesForMainThread; |
| 183 | } |
| 184 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 185 | void SingleThreadProxy::setNeedsAnimate() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 186 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 187 | // Thread-only feature |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 188 | NOTREACHED(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 189 | } |
| 190 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 191 | void SingleThreadProxy::doCommit(scoped_ptr<ResourceUpdateQueue> queue) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 192 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 193 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 194 | // Commit immediately |
| 195 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 196 | DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
| 197 | DebugScopedSetImplThread impl(this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 198 | |
[email protected] | 8b9af6b | 2012-09-27 00:36:36 | [diff] [blame] | 199 | base::TimeTicks startTime = base::TimeTicks::HighResNow(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 200 | m_layerTreeHostImpl->beginCommit(); |
| 201 | |
[email protected] | 2c7d23f | 2012-10-15 20:43:25 | [diff] [blame] | 202 | m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 203 | m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get()); |
| 204 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 205 | scoped_ptr<ResourceUpdateController> updateController = |
| 206 | ResourceUpdateController::create( |
[email protected] | f961b79 | 2012-09-20 07:27:33 | [diff] [blame] | 207 | NULL, |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 208 | Proxy::mainThread(), |
[email protected] | b1b800c | 2012-10-16 05:03:59 | [diff] [blame] | 209 | queue.Pass(), |
[email protected] | 0a45172 | 2013-02-22 20:32:05 | [diff] [blame^] | 210 | m_layerTreeHostImpl->resourceProvider()); |
[email protected] | f961b79 | 2012-09-20 07:27:33 | [diff] [blame] | 211 | updateController->finalize(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 212 | |
| 213 | m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get()); |
| 214 | |
| 215 | m_layerTreeHostImpl->commitComplete(); |
| 216 | |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 217 | #ifndef NDEBUG |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 218 | // In the single-threaded case, the scroll deltas should never be |
| 219 | // touched on the impl layer tree. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 220 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processScrollDeltas(); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 221 | DCHECK(!scrollInfo->scrolls.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 222 | #endif |
[email protected] | 8b9af6b | 2012-09-27 00:36:36 | [diff] [blame] | 223 | |
| 224 | base::TimeTicks endTime = base::TimeTicks::HighResNow(); |
| 225 | m_totalCommitTime += endTime - startTime; |
| 226 | m_totalCommitCount++; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 227 | } |
| 228 | m_layerTreeHost->commitComplete(); |
| 229 | m_nextFrameIsNewlyCommittedFrame = true; |
| 230 | } |
| 231 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 232 | void SingleThreadProxy::setNeedsCommit() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 233 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 234 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 235 | m_layerTreeHost->scheduleComposite(); |
| 236 | } |
| 237 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 238 | void SingleThreadProxy::setNeedsRedraw() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 239 | { |
| 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] | 2e7ca42 | 2012-12-20 02:57:27 | [diff] [blame] | 246 | void SingleThreadProxy::onHasPendingTreeStateChanged(bool havePendingTree) |
| 247 | { |
| 248 | // Thread-only feature. |
| 249 | NOTREACHED(); |
| 250 | } |
| 251 | |
[email protected] | 6b16679e | 2012-10-27 00:44:28 | [diff] [blame] | 252 | void SingleThreadProxy::setDeferCommits(bool deferCommits) |
| 253 | { |
| 254 | // Thread-only feature. |
| 255 | NOTREACHED(); |
| 256 | } |
| 257 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 258 | bool SingleThreadProxy::commitRequested() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 259 | { |
| 260 | return false; |
| 261 | } |
| 262 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 263 | size_t SingleThreadProxy::maxPartialTextureUpdates() const |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 264 | { |
| 265 | return std::numeric_limits<size_t>::max(); |
| 266 | } |
| 267 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 268 | void SingleThreadProxy::stop() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 269 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 270 | TRACE_EVENT0("cc", "SingleThreadProxy::stop"); |
| 271 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 272 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 273 | DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
| 274 | DebugScopedSetImplThread impl(this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 275 | |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 276 | if (!m_layerTreeHostImpl->activeTree()->ContentsTexturesPurged()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 277 | m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider()); |
[email protected] | 51928176 | 2012-10-06 20:06:39 | [diff] [blame] | 278 | m_layerTreeHostImpl.reset(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 279 | } |
| 280 | m_layerTreeHost = 0; |
| 281 | } |
| 282 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 283 | void SingleThreadProxy::setNeedsRedrawOnImplThread() |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 284 | { |
| 285 | m_layerTreeHost->scheduleComposite(); |
| 286 | } |
| 287 | |
[email protected] | 6367cda | 2013-01-23 00:21:13 | [diff] [blame] | 288 | void SingleThreadProxy::didUploadVisibleHighResolutionTileOnImplThread() |
[email protected] | 74d9063c | 2013-01-18 03:14:47 | [diff] [blame] | 289 | { |
| 290 | // implSidePainting only. |
| 291 | NOTREACHED(); |
| 292 | } |
| 293 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 294 | void SingleThreadProxy::setNeedsCommitOnImplThread() |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 295 | { |
| 296 | m_layerTreeHost->scheduleComposite(); |
| 297 | } |
| 298 | |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 299 | void SingleThreadProxy::setNeedsManageTilesOnImplThread() |
| 300 | { |
| 301 | m_layerTreeHost->scheduleComposite(); |
| 302 | } |
| 303 | |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 304 | void SingleThreadProxy::postAnimationEventsToMainThreadOnImplThread(scoped_ptr<AnimationEventsVector> events, base::Time wallClockTime) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 305 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 306 | DCHECK(Proxy::isImplThread()); |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 307 | DebugScopedSetMainThread main(this); |
[email protected] | ec1d6d5 | 2012-10-10 01:28:57 | [diff] [blame] | 308 | m_layerTreeHost->setAnimationEvents(events.Pass(), wallClockTime); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 309 | } |
| 310 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 311 | bool SingleThreadProxy::reduceContentsTextureMemoryOnImplThread(size_t limitBytes, int priorityCutoff) |
[email protected] | e1fc8b3 | 2012-09-18 20:29:09 | [diff] [blame] | 312 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 313 | DCHECK(isImplThread()); |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 314 | if (!m_layerTreeHost->contentsTextureManager()) |
| 315 | return false; |
| 316 | |
[email protected] | a0a0084 | 2012-10-22 22:50:28 | [diff] [blame] | 317 | return m_layerTreeHost->contentsTextureManager()->reduceMemoryOnImplThread(limitBytes, priorityCutoff, m_layerTreeHostImpl->resourceProvider()); |
[email protected] | e1fc8b3 | 2012-09-18 20:29:09 | [diff] [blame] | 318 | } |
| 319 | |
[email protected] | 29937ec | 2013-02-06 22:56:55 | [diff] [blame] | 320 | void SingleThreadProxy::reduceWastedContentsTextureMemoryOnImplThread() |
| 321 | { |
| 322 | // implSidePainting only. |
| 323 | NOTREACHED(); |
| 324 | } |
| 325 | |
[email protected] | 3d21e02 | 2012-10-25 20:03:08 | [diff] [blame] | 326 | void SingleThreadProxy::sendManagedMemoryStats() |
| 327 | { |
| 328 | DCHECK(Proxy::isImplThread()); |
[email protected] | 1235c9cc | 2012-10-27 03:33:46 | [diff] [blame] | 329 | if (!m_layerTreeHostImpl.get()) |
| 330 | return; |
[email protected] | 1235c9cc | 2012-10-27 03:33:46 | [diff] [blame] | 331 | if (!m_layerTreeHost->contentsTextureManager()) |
| 332 | return; |
| 333 | |
[email protected] | d3afa11 | 2012-12-08 06:24:28 | [diff] [blame] | 334 | m_layerTreeHostImpl->sendManagedMemoryStats( |
[email protected] | 1235c9cc | 2012-10-27 03:33:46 | [diff] [blame] | 335 | m_layerTreeHost->contentsTextureManager()->memoryVisibleBytes(), |
| 336 | m_layerTreeHost->contentsTextureManager()->memoryVisibleAndNearbyBytes(), |
| 337 | m_layerTreeHost->contentsTextureManager()->memoryUseBytes()); |
[email protected] | 3d21e02 | 2012-10-25 20:03:08 | [diff] [blame] | 338 | } |
| 339 | |
[email protected] | 74d9063c | 2013-01-18 03:14:47 | [diff] [blame] | 340 | bool SingleThreadProxy::isInsideDraw() |
| 341 | { |
| 342 | return m_insideDraw; |
| 343 | } |
| 344 | |
[email protected] | e01dddb1 | 2013-01-23 03:57:08 | [diff] [blame] | 345 | void SingleThreadProxy::didLoseOutputSurfaceOnImplThread() |
| 346 | { |
| 347 | // Cause a commit so we can notice the lost context. |
| 348 | setNeedsCommitOnImplThread(); |
| 349 | } |
| 350 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 351 | // Called by the legacy scheduling path (e.g. where render_widget does the scheduling) |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 352 | void SingleThreadProxy::compositeImmediately() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 353 | { |
| 354 | if (commitAndComposite()) { |
| 355 | m_layerTreeHostImpl->swapBuffers(); |
| 356 | didSwapFrame(); |
| 357 | } |
| 358 | } |
| 359 | |
[email protected] | 131a0c2 | 2013-02-12 18:31:08 | [diff] [blame] | 360 | scoped_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] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 374 | void SingleThreadProxy::forceSerializeOnSwapBuffers() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 375 | { |
| 376 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 377 | DebugScopedSetImplThread impl(this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 378 | if (m_rendererInitialized) |
| 379 | m_layerTreeHostImpl->renderer()->doNoOp(); |
| 380 | } |
| 381 | } |
| 382 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 383 | void SingleThreadProxy::onSwapBuffersCompleteOnImplThread() |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 384 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 385 | NOTREACHED(); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 386 | } |
| 387 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 388 | bool SingleThreadProxy::commitAndComposite() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 389 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 390 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 391 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 392 | if (!m_layerTreeHost->initializeRendererIfNeeded()) |
| 393 | return false; |
| 394 | |
[email protected] | 0a45172 | 2013-02-22 20:32:05 | [diff] [blame^] | 395 | 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] | 9fa7d38 | 2012-11-30 05:21:14 | [diff] [blame] | 404 | m_layerTreeHost->contentsTextureManager()->unlinkAndClearEvictedBackings(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 405 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 406 | scoped_ptr<ResourceUpdateQueue> queue = make_scoped_ptr(new ResourceUpdateQueue); |
[email protected] | f961b79 | 2012-09-20 07:27:33 | [diff] [blame] | 407 | m_layerTreeHost->updateLayers(*(queue.get()), m_layerTreeHostImpl->memoryAllocationLimitBytes()); |
[email protected] | e1fc8b3 | 2012-09-18 20:29:09 | [diff] [blame] | 408 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 409 | m_layerTreeHost->willCommit(); |
[email protected] | b1b800c | 2012-10-16 05:03:59 | [diff] [blame] | 410 | doCommit(queue.Pass()); |
[email protected] | 0a45172 | 2013-02-22 20:32:05 | [diff] [blame^] | 411 | bool result = doComposite(offscreenContextProvider); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 412 | m_layerTreeHost->didBeginFrame(); |
| 413 | return result; |
| 414 | } |
| 415 | |
[email protected] | 0a45172 | 2013-02-22 20:32:05 | [diff] [blame^] | 416 | bool SingleThreadProxy::doComposite(scoped_refptr<cc::ContextProvider> offscreenContextProvider) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 417 | { |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 418 | DCHECK(!m_outputSurfaceLost); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 419 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 420 | DebugScopedSetImplThread impl(this); |
[email protected] | 74d9063c | 2013-01-18 03:14:47 | [diff] [blame] | 421 | base::AutoReset<bool> markInside(&m_insideDraw, true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 422 | |
[email protected] | 0a45172 | 2013-02-22 20:32:05 | [diff] [blame^] | 423 | m_layerTreeHostImpl->resourceProvider()->setOffscreenContextProvider(offscreenContextProvider); |
| 424 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 425 | if (!m_layerTreeHostImpl->visible()) |
| 426 | return false; |
| 427 | |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 428 | m_layerTreeHostImpl->animate(base::TimeTicks::Now(), base::Time::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 429 | |
| 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] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 436 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 437 | m_layerTreeHostImpl->prepareToDraw(frame); |
| 438 | m_layerTreeHostImpl->drawLayers(frame); |
| 439 | m_layerTreeHostImpl->didDrawAllLayers(frame); |
[email protected] | e01dddb1 | 2013-01-23 03:57:08 | [diff] [blame] | 440 | m_outputSurfaceLost = m_layerTreeHostImpl->isContextLost(); |
[email protected] | 829ad97 | 2013-01-28 23:36:10 | [diff] [blame] | 441 | |
| 442 | m_layerTreeHostImpl->beginNextFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 443 | } |
| 444 | |
[email protected] | e01dddb1 | 2013-01-23 03:57:08 | [diff] [blame] | 445 | if (m_outputSurfaceLost) { |
[email protected] | 0a45172 | 2013-02-22 20:32:05 | [diff] [blame^] | 446 | if (cc::ContextProvider* offscreenContexts = m_layerTreeHostImpl->resourceProvider()->offscreenContextProvider()) |
| 447 | offscreenContexts->VerifyContexts(); |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 448 | m_layerTreeHost->didLoseOutputSurface(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 449 | return false; |
| 450 | } |
| 451 | |
| 452 | return true; |
| 453 | } |
| 454 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 455 | void SingleThreadProxy::didSwapFrame() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 456 | { |
| 457 | if (m_nextFrameIsNewlyCommittedFrame) { |
| 458 | m_nextFrameIsNewlyCommittedFrame = false; |
| 459 | m_layerTreeHost->didCommitAndDrawFrame(); |
| 460 | } |
| 461 | } |
| 462 | |
[email protected] | 16288a4 | 2012-12-17 23:31:05 | [diff] [blame] | 463 | bool SingleThreadProxy::commitPendingForTesting() |
| 464 | { |
| 465 | return false; |
| 466 | } |
| 467 | |
[email protected] | b9dcf43a | 2013-01-09 00:15:29 | [diff] [blame] | 468 | skia::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] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 475 | } // namespace cc |