[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] | 6331a117 | 2012-10-18 11:35:13 | [diff] [blame] | 7 | #include "base/debug/trace_event.h" |
[email protected] | aa0a9d3 | 2012-10-24 01:58:10 | [diff] [blame] | 8 | #include "cc/draw_quad.h" |
[email protected] | d50c686 | 2012-10-23 02:08:31 | [diff] [blame] | 9 | #include "cc/layer_tree_host.h" |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 10 | #include "cc/output_surface.h" |
[email protected] | cd98a8c3 | 2013-01-08 18:16:17 | [diff] [blame^] | 11 | #include "cc/prioritized_resource_manager.h" |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 12 | #include "cc/resource_update_controller.h" |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 13 | #include "cc/thread.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] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 23 | : Proxy(scoped_ptr<Thread>(NULL)) |
| 24 | , m_layerTreeHost(layerTreeHost) |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 25 | , m_outputSurfaceLost(false) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 26 | , m_rendererInitialized(false) |
| 27 | , m_nextFrameIsNewlyCommittedFrame(false) |
[email protected] | 8b9af6b | 2012-09-27 00:36:36 | [diff] [blame] | 28 | , m_totalCommitCount(0) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 29 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 30 | TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
| 31 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 32 | } |
| 33 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 34 | void SingleThreadProxy::start() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 35 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 36 | DebugScopedSetImplThread impl(this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 37 | m_layerTreeHostImpl = m_layerTreeHost->createLayerTreeHostImpl(this); |
| 38 | } |
| 39 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 40 | SingleThreadProxy::~SingleThreadProxy() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 41 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 42 | TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); |
| 43 | DCHECK(Proxy::isMainThread()); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 44 | DCHECK(!m_layerTreeHostImpl.get() && !m_layerTreeHost); // make sure stop() got called. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 45 | } |
| 46 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 47 | bool SingleThreadProxy::compositeAndReadback(void *pixels, const gfx::Rect& rect) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 48 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 49 | TRACE_EVENT0("cc", "SingleThreadProxy::compositeAndReadback"); |
| 50 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 51 | |
| 52 | if (!commitAndComposite()) |
| 53 | return false; |
| 54 | |
| 55 | m_layerTreeHostImpl->readback(pixels, rect); |
| 56 | |
| 57 | if (m_layerTreeHostImpl->isContextLost()) |
| 58 | return false; |
| 59 | |
| 60 | m_layerTreeHostImpl->swapBuffers(); |
| 61 | didSwapFrame(); |
| 62 | |
| 63 | return true; |
| 64 | } |
| 65 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 66 | void SingleThreadProxy::startPageScaleAnimation(gfx::Vector2d targetOffset, bool useAnchor, float scale, base::TimeDelta duration) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 67 | { |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 68 | m_layerTreeHostImpl->startPageScaleAnimation(targetOffset, useAnchor, scale, base::TimeTicks::Now(), duration); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 69 | } |
| 70 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 71 | void SingleThreadProxy::finishAllRendering() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 72 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 73 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 74 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 75 | DebugScopedSetImplThread impl(this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 76 | m_layerTreeHostImpl->finishAllRendering(); |
| 77 | } |
| 78 | } |
| 79 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 80 | bool SingleThreadProxy::isStarted() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 81 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 82 | DCHECK(Proxy::isMainThread()); |
[email protected] | 51928176 | 2012-10-06 20:06:39 | [diff] [blame] | 83 | return m_layerTreeHostImpl.get(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 84 | } |
| 85 | |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 86 | bool SingleThreadProxy::initializeOutputSurface() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 87 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 88 | DCHECK(Proxy::isMainThread()); |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 89 | scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurface(); |
| 90 | if (!outputSurface.get()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 91 | return false; |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 92 | m_outputSurfaceBeforeInitialization = outputSurface.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 93 | return true; |
| 94 | } |
| 95 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 96 | void SingleThreadProxy::setSurfaceReady() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 97 | { |
| 98 | // Scheduling is controlled by the embedder in the single thread case, so nothing to do. |
| 99 | } |
| 100 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 101 | void SingleThreadProxy::setVisible(bool visible) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 102 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 103 | DebugScopedSetImplThread impl(this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 104 | m_layerTreeHostImpl->setVisible(visible); |
| 105 | } |
| 106 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 107 | bool SingleThreadProxy::initializeRenderer() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 108 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 109 | DCHECK(Proxy::isMainThread()); |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 110 | DCHECK(m_outputSurfaceBeforeInitialization.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 111 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 112 | DebugScopedSetImplThread impl(this); |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 113 | bool ok = m_layerTreeHostImpl->initializeRenderer(m_outputSurfaceBeforeInitialization.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 114 | if (ok) { |
| 115 | m_rendererInitialized = true; |
| 116 | m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererCapabilities(); |
| 117 | } |
| 118 | |
| 119 | return ok; |
| 120 | } |
| 121 | } |
| 122 | |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 123 | bool SingleThreadProxy::recreateOutputSurface() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 124 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 125 | TRACE_EVENT0("cc", "SingleThreadProxy::recreateContext"); |
| 126 | DCHECK(Proxy::isMainThread()); |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 127 | DCHECK(m_outputSurfaceLost); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 128 | |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 129 | scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurface(); |
| 130 | if (!outputSurface.get()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 131 | return false; |
| 132 | |
| 133 | bool initialized; |
| 134 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 135 | DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
| 136 | DebugScopedSetImplThread impl(this); |
[email protected] | f1476457 | 2012-12-20 03:15:13 | [diff] [blame] | 137 | m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider()); |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 138 | initialized = m_layerTreeHostImpl->initializeRenderer(outputSurface.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) |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 145 | m_outputSurfaceLost = false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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::setNeedsAnimate() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 165 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 166 | // Thread-only feature |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 167 | NOTREACHED(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 168 | } |
| 169 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 170 | void SingleThreadProxy::doCommit(scoped_ptr<ResourceUpdateQueue> queue) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 171 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 172 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 173 | // Commit immediately |
| 174 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 175 | DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
| 176 | DebugScopedSetImplThread impl(this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 177 | |
[email protected] | 8b9af6b | 2012-09-27 00:36:36 | [diff] [blame] | 178 | base::TimeTicks startTime = base::TimeTicks::HighResNow(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 179 | m_layerTreeHostImpl->beginCommit(); |
| 180 | |
[email protected] | 2c7d23f | 2012-10-15 20:43:25 | [diff] [blame] | 181 | m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 182 | m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get()); |
| 183 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 184 | scoped_ptr<ResourceUpdateController> updateController = |
| 185 | ResourceUpdateController::create( |
[email protected] | f961b79 | 2012-09-20 07:27:33 | [diff] [blame] | 186 | NULL, |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 187 | Proxy::mainThread(), |
[email protected] | b1b800c | 2012-10-16 05:03:59 | [diff] [blame] | 188 | queue.Pass(), |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 189 | m_layerTreeHostImpl->resourceProvider(), |
| 190 | hasImplThread()); |
[email protected] | f961b79 | 2012-09-20 07:27:33 | [diff] [blame] | 191 | updateController->finalize(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 192 | |
| 193 | m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get()); |
| 194 | |
| 195 | m_layerTreeHostImpl->commitComplete(); |
| 196 | |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 197 | #ifndef NDEBUG |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 198 | // In the single-threaded case, the scroll deltas should never be |
| 199 | // touched on the impl layer tree. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 200 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processScrollDeltas(); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 201 | DCHECK(!scrollInfo->scrolls.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 202 | #endif |
[email protected] | 8b9af6b | 2012-09-27 00:36:36 | [diff] [blame] | 203 | |
| 204 | base::TimeTicks endTime = base::TimeTicks::HighResNow(); |
| 205 | m_totalCommitTime += endTime - startTime; |
| 206 | m_totalCommitCount++; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 207 | } |
| 208 | m_layerTreeHost->commitComplete(); |
| 209 | m_nextFrameIsNewlyCommittedFrame = true; |
| 210 | } |
| 211 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 212 | void SingleThreadProxy::setNeedsCommit() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 213 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 214 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 215 | m_layerTreeHost->scheduleComposite(); |
| 216 | } |
| 217 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 218 | void SingleThreadProxy::setNeedsRedraw() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 219 | { |
| 220 | // FIXME: Once we move render_widget scheduling into this class, we can |
| 221 | // treat redraw requests more efficiently than commitAndRedraw requests. |
| 222 | m_layerTreeHostImpl->setFullRootLayerDamage(); |
| 223 | setNeedsCommit(); |
| 224 | } |
| 225 | |
[email protected] | 2e7ca42 | 2012-12-20 02:57:27 | [diff] [blame] | 226 | void SingleThreadProxy::onHasPendingTreeStateChanged(bool havePendingTree) |
| 227 | { |
| 228 | // Thread-only feature. |
| 229 | NOTREACHED(); |
| 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 | 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 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 253 | DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
| 254 | DebugScopedSetImplThread impl(this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 273 | void SingleThreadProxy::setNeedsManageTilesOnImplThread() |
| 274 | { |
| 275 | m_layerTreeHost->scheduleComposite(); |
| 276 | } |
| 277 | |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 278 | void SingleThreadProxy::postAnimationEventsToMainThreadOnImplThread(scoped_ptr<AnimationEventsVector> events, base::Time wallClockTime) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 279 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 280 | DCHECK(Proxy::isImplThread()); |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 281 | DebugScopedSetMainThread main(this); |
[email protected] | ec1d6d5 | 2012-10-10 01:28:57 | [diff] [blame] | 282 | m_layerTreeHost->setAnimationEvents(events.Pass(), wallClockTime); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 283 | } |
| 284 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 285 | bool SingleThreadProxy::reduceContentsTextureMemoryOnImplThread(size_t limitBytes, int priorityCutoff) |
[email protected] | e1fc8b3 | 2012-09-18 20:29:09 | [diff] [blame] | 286 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 287 | DCHECK(isImplThread()); |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 288 | if (!m_layerTreeHost->contentsTextureManager()) |
| 289 | return false; |
| 290 | |
[email protected] | a0a0084 | 2012-10-22 22:50:28 | [diff] [blame] | 291 | return m_layerTreeHost->contentsTextureManager()->reduceMemoryOnImplThread(limitBytes, priorityCutoff, m_layerTreeHostImpl->resourceProvider()); |
[email protected] | e1fc8b3 | 2012-09-18 20:29:09 | [diff] [blame] | 292 | } |
| 293 | |
[email protected] | 3d21e02 | 2012-10-25 20:03:08 | [diff] [blame] | 294 | void SingleThreadProxy::sendManagedMemoryStats() |
| 295 | { |
| 296 | DCHECK(Proxy::isImplThread()); |
[email protected] | 1235c9cc | 2012-10-27 03:33:46 | [diff] [blame] | 297 | if (!m_layerTreeHostImpl.get()) |
| 298 | return; |
[email protected] | 1235c9cc | 2012-10-27 03:33:46 | [diff] [blame] | 299 | if (!m_layerTreeHost->contentsTextureManager()) |
| 300 | return; |
| 301 | |
[email protected] | d3afa11 | 2012-12-08 06:24:28 | [diff] [blame] | 302 | m_layerTreeHostImpl->sendManagedMemoryStats( |
[email protected] | 1235c9cc | 2012-10-27 03:33:46 | [diff] [blame] | 303 | m_layerTreeHost->contentsTextureManager()->memoryVisibleBytes(), |
| 304 | m_layerTreeHost->contentsTextureManager()->memoryVisibleAndNearbyBytes(), |
| 305 | m_layerTreeHost->contentsTextureManager()->memoryUseBytes()); |
[email protected] | 3d21e02 | 2012-10-25 20:03:08 | [diff] [blame] | 306 | } |
| 307 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 308 | // 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] | 309 | void SingleThreadProxy::compositeImmediately() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 310 | { |
| 311 | if (commitAndComposite()) { |
| 312 | m_layerTreeHostImpl->swapBuffers(); |
| 313 | didSwapFrame(); |
| 314 | } |
| 315 | } |
| 316 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 317 | void SingleThreadProxy::forceSerializeOnSwapBuffers() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 318 | { |
| 319 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 320 | DebugScopedSetImplThread impl(this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 321 | if (m_rendererInitialized) |
| 322 | m_layerTreeHostImpl->renderer()->doNoOp(); |
| 323 | } |
| 324 | } |
| 325 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 326 | void SingleThreadProxy::onSwapBuffersCompleteOnImplThread() |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 327 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 328 | NOTREACHED(); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 329 | } |
| 330 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 331 | bool SingleThreadProxy::commitAndComposite() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 332 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 333 | DCHECK(Proxy::isMainThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 334 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 335 | if (!m_layerTreeHost->initializeRendererIfNeeded()) |
| 336 | return false; |
| 337 | |
[email protected] | 9fa7d38 | 2012-11-30 05:21:14 | [diff] [blame] | 338 | m_layerTreeHost->contentsTextureManager()->unlinkAndClearEvictedBackings(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 339 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 340 | scoped_ptr<ResourceUpdateQueue> queue = make_scoped_ptr(new ResourceUpdateQueue); |
[email protected] | f961b79 | 2012-09-20 07:27:33 | [diff] [blame] | 341 | m_layerTreeHost->updateLayers(*(queue.get()), m_layerTreeHostImpl->memoryAllocationLimitBytes()); |
[email protected] | e1fc8b3 | 2012-09-18 20:29:09 | [diff] [blame] | 342 | |
| 343 | if (m_layerTreeHostImpl->contentsTexturesPurged()) |
| 344 | m_layerTreeHostImpl->resetContentsTexturesPurged(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 345 | |
| 346 | m_layerTreeHost->willCommit(); |
[email protected] | b1b800c | 2012-10-16 05:03:59 | [diff] [blame] | 347 | doCommit(queue.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 348 | bool result = doComposite(); |
| 349 | m_layerTreeHost->didBeginFrame(); |
| 350 | return result; |
| 351 | } |
| 352 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 353 | bool SingleThreadProxy::doComposite() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 354 | { |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 355 | DCHECK(!m_outputSurfaceLost); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 356 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 357 | DebugScopedSetImplThread impl(this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 358 | |
| 359 | if (!m_layerTreeHostImpl->visible()) |
| 360 | return false; |
| 361 | |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 362 | m_layerTreeHostImpl->animate(base::TimeTicks::Now(), base::Time::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 363 | |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 364 | if (m_layerTreeHostImpl->settings().implSidePainting) |
| 365 | m_layerTreeHostImpl->manageTiles(); |
| 366 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 367 | // We guard prepareToDraw() with canDraw() because it always returns a valid frame, so can only |
| 368 | // be used when such a frame is possible. Since drawLayers() depends on the result of |
| 369 | // prepareToDraw(), it is guarded on canDraw() as well. |
| 370 | if (!m_layerTreeHostImpl->canDraw()) |
| 371 | return false; |
| 372 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 373 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 374 | m_layerTreeHostImpl->prepareToDraw(frame); |
| 375 | m_layerTreeHostImpl->drawLayers(frame); |
| 376 | m_layerTreeHostImpl->didDrawAllLayers(frame); |
| 377 | } |
| 378 | |
| 379 | if (m_layerTreeHostImpl->isContextLost()) { |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 380 | m_outputSurfaceLost = true; |
| 381 | m_layerTreeHost->didLoseOutputSurface(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 382 | return false; |
| 383 | } |
| 384 | |
| 385 | return true; |
| 386 | } |
| 387 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 388 | void SingleThreadProxy::didSwapFrame() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 389 | { |
| 390 | if (m_nextFrameIsNewlyCommittedFrame) { |
| 391 | m_nextFrameIsNewlyCommittedFrame = false; |
| 392 | m_layerTreeHost->didCommitAndDrawFrame(); |
| 393 | } |
| 394 | } |
| 395 | |
[email protected] | 16288a4 | 2012-12-17 23:31:05 | [diff] [blame] | 396 | bool SingleThreadProxy::commitPendingForTesting() |
| 397 | { |
| 398 | return false; |
| 399 | } |
| 400 | |
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 401 | } // namespace cc |