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