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