[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 | |
| 5 | #include "config.h" |
| 6 | |
[email protected] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 7 | #include "cc/single_thread_proxy.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 8 | |
| 9 | #include "CCDrawQuad.h" |
| 10 | #include "CCGraphicsContext.h" |
[email protected] | 6331a117 | 2012-10-18 11:35:13 | [diff] [blame] | 11 | #include "base/debug/trace_event.h" |
[email protected] | d50c686 | 2012-10-23 02:08:31 | [diff] [blame^] | 12 | #include "cc/layer_tree_host.h" |
[email protected] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 13 | #include "cc/texture_update_controller.h" |
[email protected] | da2c912 | 2012-10-20 23:13:06 | [diff] [blame] | 14 | #include "cc/timer.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 15 | #include <wtf/CurrentTime.h> |
| 16 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 17 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 18 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 19 | scoped_ptr<Proxy> SingleThreadProxy::create(LayerTreeHost* layerTreeHost) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 20 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 21 | return make_scoped_ptr(new SingleThreadProxy(layerTreeHost)).PassAs<Proxy>(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 22 | } |
| 23 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 24 | SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layerTreeHost) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 25 | : m_layerTreeHost(layerTreeHost) |
| 26 | , m_contextLost(false) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 27 | , m_rendererInitialized(false) |
| 28 | , m_nextFrameIsNewlyCommittedFrame(false) |
[email protected] | 8b9af6b | 2012-09-27 00:36:36 | [diff] [blame] | 29 | , m_totalCommitCount(0) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 30 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 31 | TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
| 32 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 33 | } |
| 34 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 35 | void SingleThreadProxy::start() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 36 | { |
| 37 | DebugScopedSetImplThread impl; |
| 38 | m_layerTreeHostImpl = m_layerTreeHost->createLayerTreeHostImpl(this); |
| 39 | } |
| 40 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 41 | SingleThreadProxy::~SingleThreadProxy() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 42 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 43 | TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); |
| 44 | DCHECK(Proxy::isMainThread()); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 45 | DCHECK(!m_layerTreeHostImpl.get() && !m_layerTreeHost); // make sure stop() got called. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 46 | } |
| 47 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 48 | bool SingleThreadProxy::compositeAndReadback(void *pixels, const IntRect& rect) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 49 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 50 | TRACE_EVENT0("cc", "SingleThreadProxy::compositeAndReadback"); |
| 51 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 52 | |
| 53 | if (!commitAndComposite()) |
| 54 | return false; |
| 55 | |
| 56 | m_layerTreeHostImpl->readback(pixels, rect); |
| 57 | |
| 58 | if (m_layerTreeHostImpl->isContextLost()) |
| 59 | return false; |
| 60 | |
| 61 | m_layerTreeHostImpl->swapBuffers(); |
| 62 | didSwapFrame(); |
| 63 | |
| 64 | return true; |
| 65 | } |
| 66 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 67 | void SingleThreadProxy::startPageScaleAnimation(const IntSize& targetPosition, bool useAnchor, float scale, double duration) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 68 | { |
| 69 | m_layerTreeHostImpl->startPageScaleAnimation(targetPosition, useAnchor, scale, monotonicallyIncreasingTime(), duration); |
| 70 | } |
| 71 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 72 | void SingleThreadProxy::finishAllRendering() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 73 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 74 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 75 | { |
| 76 | DebugScopedSetImplThread impl; |
| 77 | m_layerTreeHostImpl->finishAllRendering(); |
| 78 | } |
| 79 | } |
| 80 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 81 | bool SingleThreadProxy::isStarted() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 82 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 83 | DCHECK(Proxy::isMainThread()); |
[email protected] | 51928176 | 2012-10-06 20:06:39 | [diff] [blame] | 84 | return m_layerTreeHostImpl.get(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 85 | } |
| 86 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 87 | bool SingleThreadProxy::initializeContext() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 88 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 89 | DCHECK(Proxy::isMainThread()); |
| 90 | scoped_ptr<GraphicsContext> context = m_layerTreeHost->createContext(); |
[email protected] | e28efacd | 2012-10-06 17:07:49 | [diff] [blame] | 91 | if (!context.get()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 92 | return false; |
[email protected] | e28efacd | 2012-10-06 17:07:49 | [diff] [blame] | 93 | m_contextBeforeInitialization = context.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 94 | return true; |
| 95 | } |
| 96 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 97 | void SingleThreadProxy::setSurfaceReady() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 98 | { |
| 99 | // Scheduling is controlled by the embedder in the single thread case, so nothing to do. |
| 100 | } |
| 101 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 102 | void SingleThreadProxy::setVisible(bool visible) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 103 | { |
| 104 | DebugScopedSetImplThread impl; |
| 105 | m_layerTreeHostImpl->setVisible(visible); |
| 106 | } |
| 107 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 108 | bool SingleThreadProxy::initializeRenderer() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 109 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 110 | DCHECK(Proxy::isMainThread()); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 111 | DCHECK(m_contextBeforeInitialization.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 112 | { |
| 113 | DebugScopedSetImplThread impl; |
[email protected] | e28efacd | 2012-10-06 17:07:49 | [diff] [blame] | 114 | bool ok = m_layerTreeHostImpl->initializeRenderer(m_contextBeforeInitialization.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 115 | if (ok) { |
| 116 | m_rendererInitialized = true; |
| 117 | m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererCapabilities(); |
| 118 | } |
| 119 | |
| 120 | return ok; |
| 121 | } |
| 122 | } |
| 123 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 124 | bool SingleThreadProxy::recreateContext() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 125 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 126 | TRACE_EVENT0("cc", "SingleThreadProxy::recreateContext"); |
| 127 | DCHECK(Proxy::isMainThread()); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 128 | DCHECK(m_contextLost); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 129 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 130 | scoped_ptr<GraphicsContext> context = m_layerTreeHost->createContext(); |
[email protected] | e28efacd | 2012-10-06 17:07:49 | [diff] [blame] | 131 | if (!context.get()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 132 | return false; |
| 133 | |
| 134 | bool initialized; |
| 135 | { |
[email protected] | d74ca3b | 2012-09-12 23:11:12 | [diff] [blame] | 136 | DebugScopedSetMainThreadBlocked mainThreadBlocked; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 137 | DebugScopedSetImplThread impl; |
| 138 | if (!m_layerTreeHostImpl->contentsTexturesPurged()) |
| 139 | m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider()); |
[email protected] | e28efacd | 2012-10-06 17:07:49 | [diff] [blame] | 140 | initialized = m_layerTreeHostImpl->initializeRenderer(context.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 141 | if (initialized) { |
| 142 | m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererCapabilities(); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | if (initialized) |
| 147 | m_contextLost = false; |
| 148 | |
| 149 | return initialized; |
| 150 | } |
| 151 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 152 | void SingleThreadProxy::renderingStats(RenderingStats* stats) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 153 | { |
[email protected] | 8b9af6b | 2012-09-27 00:36:36 | [diff] [blame] | 154 | stats->totalCommitTimeInSeconds = m_totalCommitTime.InSecondsF(); |
| 155 | stats->totalCommitCount = m_totalCommitCount; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 156 | m_layerTreeHostImpl->renderingStats(stats); |
| 157 | } |
| 158 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 159 | const RendererCapabilities& SingleThreadProxy::rendererCapabilities() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 160 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 161 | DCHECK(m_rendererInitialized); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 162 | // Note: this gets called during the commit by the "impl" thread |
| 163 | return m_RendererCapabilitiesForMainThread; |
| 164 | } |
| 165 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 166 | void SingleThreadProxy::loseContext() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 167 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 168 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 169 | m_layerTreeHost->didLoseContext(); |
| 170 | m_contextLost = true; |
| 171 | } |
| 172 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 173 | void SingleThreadProxy::setNeedsAnimate() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 174 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 175 | // Thread-only feature |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 176 | NOTREACHED(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 177 | } |
| 178 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 179 | void SingleThreadProxy::doCommit(scoped_ptr<TextureUpdateQueue> queue) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 180 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 181 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 182 | // Commit immediately |
| 183 | { |
| 184 | DebugScopedSetMainThreadBlocked mainThreadBlocked; |
| 185 | DebugScopedSetImplThread impl; |
| 186 | |
[email protected] | 8b9af6b | 2012-09-27 00:36:36 | [diff] [blame] | 187 | base::TimeTicks startTime = base::TimeTicks::HighResNow(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 188 | m_layerTreeHostImpl->beginCommit(); |
| 189 | |
[email protected] | 2c7d23f | 2012-10-15 20:43:25 | [diff] [blame] | 190 | m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 191 | m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get()); |
| 192 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 193 | scoped_ptr<TextureUpdateController> updateController = |
| 194 | TextureUpdateController::create( |
[email protected] | f961b79 | 2012-09-20 07:27:33 | [diff] [blame] | 195 | NULL, |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 196 | Proxy::mainThread(), |
[email protected] | b1b800c | 2012-10-16 05:03:59 | [diff] [blame] | 197 | queue.Pass(), |
[email protected] | e224959 | 2012-10-19 06:59:09 | [diff] [blame] | 198 | m_layerTreeHostImpl->resourceProvider()); |
[email protected] | f961b79 | 2012-09-20 07:27:33 | [diff] [blame] | 199 | updateController->finalize(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 200 | |
| 201 | m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get()); |
| 202 | |
| 203 | m_layerTreeHostImpl->commitComplete(); |
| 204 | |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 205 | #ifndef NDEBUG |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 206 | // In the single-threaded case, the scroll deltas should never be |
| 207 | // touched on the impl layer tree. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 208 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processScrollDeltas(); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 209 | DCHECK(!scrollInfo->scrolls.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 210 | #endif |
[email protected] | 8b9af6b | 2012-09-27 00:36:36 | [diff] [blame] | 211 | |
| 212 | base::TimeTicks endTime = base::TimeTicks::HighResNow(); |
| 213 | m_totalCommitTime += endTime - startTime; |
| 214 | m_totalCommitCount++; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 215 | } |
| 216 | m_layerTreeHost->commitComplete(); |
| 217 | m_nextFrameIsNewlyCommittedFrame = true; |
| 218 | } |
| 219 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 220 | void SingleThreadProxy::setNeedsCommit() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 221 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 222 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 223 | m_layerTreeHost->scheduleComposite(); |
| 224 | } |
| 225 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 226 | void SingleThreadProxy::setNeedsRedraw() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 227 | { |
| 228 | // FIXME: Once we move render_widget scheduling into this class, we can |
| 229 | // treat redraw requests more efficiently than commitAndRedraw requests. |
| 230 | m_layerTreeHostImpl->setFullRootLayerDamage(); |
| 231 | setNeedsCommit(); |
| 232 | } |
| 233 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 234 | bool SingleThreadProxy::commitRequested() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 235 | { |
| 236 | return false; |
| 237 | } |
| 238 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 239 | void SingleThreadProxy::didAddAnimation() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 240 | { |
| 241 | } |
| 242 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 243 | size_t SingleThreadProxy::maxPartialTextureUpdates() const |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 244 | { |
| 245 | return std::numeric_limits<size_t>::max(); |
| 246 | } |
| 247 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 248 | void SingleThreadProxy::stop() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 249 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 250 | TRACE_EVENT0("cc", "SingleThreadProxy::stop"); |
| 251 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 252 | { |
| 253 | DebugScopedSetMainThreadBlocked mainThreadBlocked; |
| 254 | DebugScopedSetImplThread impl; |
| 255 | |
| 256 | if (!m_layerTreeHostImpl->contentsTexturesPurged()) |
| 257 | m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider()); |
[email protected] | 51928176 | 2012-10-06 20:06:39 | [diff] [blame] | 258 | m_layerTreeHostImpl.reset(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 259 | } |
| 260 | m_layerTreeHost = 0; |
| 261 | } |
| 262 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 263 | void SingleThreadProxy::setNeedsRedrawOnImplThread() |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 264 | { |
| 265 | m_layerTreeHost->scheduleComposite(); |
| 266 | } |
| 267 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 268 | void SingleThreadProxy::setNeedsCommitOnImplThread() |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 269 | { |
| 270 | m_layerTreeHost->scheduleComposite(); |
| 271 | } |
| 272 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 273 | void SingleThreadProxy::postAnimationEventsToMainThreadOnImplThread(scoped_ptr<AnimationEventsVector> events, double wallClockTime) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 274 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 275 | DCHECK(Proxy::isImplThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 276 | DebugScopedSetMainThread main; |
[email protected] | ec1d6d5 | 2012-10-10 01:28:57 | [diff] [blame] | 277 | m_layerTreeHost->setAnimationEvents(events.Pass(), wallClockTime); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 278 | } |
| 279 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 280 | bool SingleThreadProxy::reduceContentsTextureMemoryOnImplThread(size_t limitBytes, int priorityCutoff) |
[email protected] | e1fc8b3 | 2012-09-18 20:29:09 | [diff] [blame] | 281 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 282 | DCHECK(isImplThread()); |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 283 | if (!m_layerTreeHost->contentsTextureManager()) |
| 284 | return false; |
| 285 | |
[email protected] | a0a0084 | 2012-10-22 22:50:28 | [diff] [blame] | 286 | return m_layerTreeHost->contentsTextureManager()->reduceMemoryOnImplThread(limitBytes, priorityCutoff, m_layerTreeHostImpl->resourceProvider()); |
[email protected] | e1fc8b3 | 2012-09-18 20:29:09 | [diff] [blame] | 287 | } |
| 288 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 289 | // 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] | 290 | void SingleThreadProxy::compositeImmediately() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 291 | { |
| 292 | if (commitAndComposite()) { |
| 293 | m_layerTreeHostImpl->swapBuffers(); |
| 294 | didSwapFrame(); |
| 295 | } |
| 296 | } |
| 297 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 298 | void SingleThreadProxy::forceSerializeOnSwapBuffers() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 299 | { |
| 300 | { |
| 301 | DebugScopedSetImplThread impl; |
| 302 | if (m_rendererInitialized) |
| 303 | m_layerTreeHostImpl->renderer()->doNoOp(); |
| 304 | } |
| 305 | } |
| 306 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 307 | void SingleThreadProxy::onSwapBuffersCompleteOnImplThread() |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 308 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 309 | NOTREACHED(); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 310 | } |
| 311 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 312 | bool SingleThreadProxy::commitAndComposite() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 313 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 314 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 315 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 316 | if (!m_layerTreeHost->initializeRendererIfNeeded()) |
| 317 | return false; |
| 318 | |
[email protected] | e1fc8b3 | 2012-09-18 20:29:09 | [diff] [blame] | 319 | // Unlink any texture backings that were deleted |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 320 | PrioritizedTextureManager::BackingList evictedContentsTexturesBackings; |
[email protected] | e1fc8b3 | 2012-09-18 20:29:09 | [diff] [blame] | 321 | { |
| 322 | DebugScopedSetImplThread implThread; |
[email protected] | 2c7d23f | 2012-10-15 20:43:25 | [diff] [blame] | 323 | m_layerTreeHost->contentsTextureManager()->getEvictedBackings(evictedContentsTexturesBackings); |
[email protected] | e1fc8b3 | 2012-09-18 20:29:09 | [diff] [blame] | 324 | } |
[email protected] | 2c7d23f | 2012-10-15 20:43:25 | [diff] [blame] | 325 | m_layerTreeHost->contentsTextureManager()->unlinkEvictedBackings(evictedContentsTexturesBackings); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 326 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 327 | scoped_ptr<TextureUpdateQueue> queue = make_scoped_ptr(new TextureUpdateQueue); |
[email protected] | f961b79 | 2012-09-20 07:27:33 | [diff] [blame] | 328 | m_layerTreeHost->updateLayers(*(queue.get()), m_layerTreeHostImpl->memoryAllocationLimitBytes()); |
[email protected] | e1fc8b3 | 2012-09-18 20:29:09 | [diff] [blame] | 329 | |
| 330 | if (m_layerTreeHostImpl->contentsTexturesPurged()) |
| 331 | m_layerTreeHostImpl->resetContentsTexturesPurged(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 332 | |
| 333 | m_layerTreeHost->willCommit(); |
[email protected] | b1b800c | 2012-10-16 05:03:59 | [diff] [blame] | 334 | doCommit(queue.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 335 | bool result = doComposite(); |
| 336 | m_layerTreeHost->didBeginFrame(); |
| 337 | return result; |
| 338 | } |
| 339 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 340 | bool SingleThreadProxy::doComposite() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 341 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 342 | DCHECK(!m_contextLost); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 343 | { |
| 344 | DebugScopedSetImplThread impl; |
| 345 | |
| 346 | if (!m_layerTreeHostImpl->visible()) |
| 347 | return false; |
| 348 | |
| 349 | double monotonicTime = monotonicallyIncreasingTime(); |
| 350 | double wallClockTime = currentTime(); |
| 351 | m_layerTreeHostImpl->animate(monotonicTime, wallClockTime); |
| 352 | |
| 353 | // We guard prepareToDraw() with canDraw() because it always returns a valid frame, so can only |
| 354 | // be used when such a frame is possible. Since drawLayers() depends on the result of |
| 355 | // prepareToDraw(), it is guarded on canDraw() as well. |
| 356 | if (!m_layerTreeHostImpl->canDraw()) |
| 357 | return false; |
| 358 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 359 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 360 | m_layerTreeHostImpl->prepareToDraw(frame); |
| 361 | m_layerTreeHostImpl->drawLayers(frame); |
| 362 | m_layerTreeHostImpl->didDrawAllLayers(frame); |
| 363 | } |
| 364 | |
| 365 | if (m_layerTreeHostImpl->isContextLost()) { |
| 366 | m_contextLost = true; |
| 367 | m_layerTreeHost->didLoseContext(); |
| 368 | return false; |
| 369 | } |
| 370 | |
| 371 | return true; |
| 372 | } |
| 373 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 374 | void SingleThreadProxy::didSwapFrame() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 375 | { |
| 376 | if (m_nextFrameIsNewlyCommittedFrame) { |
| 377 | m_nextFrameIsNewlyCommittedFrame = false; |
| 378 | m_layerTreeHost->didCommitAndDrawFrame(); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | } |