OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/single_thread_proxy.h" | 5 #include "cc/single_thread_proxy.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "cc/context_provider.h" |
9 #include "cc/draw_quad.h" | 10 #include "cc/draw_quad.h" |
10 #include "cc/layer_tree_host.h" | 11 #include "cc/layer_tree_host.h" |
11 #include "cc/layer_tree_impl.h" | 12 #include "cc/layer_tree_impl.h" |
12 #include "cc/output_surface.h" | 13 #include "cc/output_surface.h" |
13 #include "cc/prioritized_resource_manager.h" | 14 #include "cc/prioritized_resource_manager.h" |
14 #include "cc/resource_update_controller.h" | 15 #include "cc/resource_update_controller.h" |
15 #include "cc/thread.h" | 16 #include "cc/thread.h" |
16 | 17 |
17 namespace cc { | 18 namespace cc { |
18 | 19 |
19 scoped_ptr<Proxy> SingleThreadProxy::create(LayerTreeHost* layerTreeHost) | 20 scoped_ptr<Proxy> SingleThreadProxy::create(LayerTreeHost* layerTreeHost) |
20 { | 21 { |
21 return make_scoped_ptr(new SingleThreadProxy(layerTreeHost)).PassAs<Proxy>()
; | 22 return make_scoped_ptr(new SingleThreadProxy(layerTreeHost)).PassAs<Proxy>()
; |
22 } | 23 } |
23 | 24 |
24 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layerTreeHost) | 25 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layerTreeHost) |
25 : Proxy(scoped_ptr<Thread>(NULL)) | 26 : Proxy(scoped_ptr<Thread>(NULL)) |
26 , m_layerTreeHost(layerTreeHost) | 27 , m_layerTreeHost(layerTreeHost) |
27 , m_outputSurfaceLost(false) | 28 , m_outputSurfaceLost(false) |
| 29 , m_createdOffscreenContextProvider(false) |
28 , m_rendererInitialized(false) | 30 , m_rendererInitialized(false) |
29 , m_nextFrameIsNewlyCommittedFrame(false) | 31 , m_nextFrameIsNewlyCommittedFrame(false) |
30 , m_insideDraw(false) | 32 , m_insideDraw(false) |
31 , m_totalCommitCount(0) | 33 , m_totalCommitCount(0) |
32 { | 34 { |
33 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); | 35 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
34 DCHECK(Proxy::isMainThread()); | 36 DCHECK(Proxy::isMainThread()); |
35 DCHECK(layerTreeHost); | 37 DCHECK(layerTreeHost); |
36 | 38 |
37 // Impl-side painting not supported without threaded compositing | 39 // Impl-side painting not supported without threaded compositing |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 134 |
133 bool SingleThreadProxy::recreateOutputSurface() | 135 bool SingleThreadProxy::recreateOutputSurface() |
134 { | 136 { |
135 TRACE_EVENT0("cc", "SingleThreadProxy::recreateContext"); | 137 TRACE_EVENT0("cc", "SingleThreadProxy::recreateContext"); |
136 DCHECK(Proxy::isMainThread()); | 138 DCHECK(Proxy::isMainThread()); |
137 DCHECK(m_outputSurfaceLost); | 139 DCHECK(m_outputSurfaceLost); |
138 | 140 |
139 scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurfa
ce(); | 141 scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurfa
ce(); |
140 if (!outputSurface.get()) | 142 if (!outputSurface.get()) |
141 return false; | 143 return false; |
| 144 scoped_refptr<cc::ContextProvider> offscreenContextProvider; |
| 145 if (m_createdOffscreenContextProvider) { |
| 146 offscreenContextProvider = m_layerTreeHost->client()->OffscreenContextPr
oviderForMainThread(); |
| 147 if (!offscreenContextProvider->InitializeOnMainThread()) |
| 148 return false; |
| 149 } |
142 | 150 |
143 bool initialized; | 151 bool initialized; |
144 { | 152 { |
145 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); | 153 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
146 DebugScopedSetImplThread impl(this); | 154 DebugScopedSetImplThread impl(this); |
147 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl-
>resourceProvider()); | 155 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl-
>resourceProvider()); |
148 initialized = m_layerTreeHostImpl->initializeRenderer(outputSurface.Pass
()); | 156 initialized = m_layerTreeHostImpl->initializeRenderer(outputSurface.Pass
()); |
149 if (initialized) { | 157 if (initialized) { |
150 m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererC
apabilities(); | 158 m_RendererCapabilitiesForMainThread = m_layerTreeHostImpl->rendererC
apabilities(); |
| 159 m_layerTreeHostImpl->resourceProvider()->setOffscreenContextProvider
(offscreenContextProvider); |
| 160 } else if (offscreenContextProvider) { |
| 161 offscreenContextProvider->VerifyContexts(); |
151 } | 162 } |
152 } | 163 } |
153 | 164 |
154 if (initialized) | 165 if (initialized) |
155 m_outputSurfaceLost = false; | 166 m_outputSurfaceLost = false; |
156 | 167 |
157 return initialized; | 168 return initialized; |
158 } | 169 } |
159 | 170 |
160 void SingleThreadProxy::renderingStats(RenderingStats* stats) | 171 void SingleThreadProxy::renderingStats(RenderingStats* stats) |
(...skipping 28 matching lines...) Expand all Loading... |
189 m_layerTreeHostImpl->beginCommit(); | 200 m_layerTreeHostImpl->beginCommit(); |
190 | 201 |
191 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackin
gs(); | 202 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackin
gs(); |
192 m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get()); | 203 m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get()); |
193 | 204 |
194 scoped_ptr<ResourceUpdateController> updateController = | 205 scoped_ptr<ResourceUpdateController> updateController = |
195 ResourceUpdateController::create( | 206 ResourceUpdateController::create( |
196 NULL, | 207 NULL, |
197 Proxy::mainThread(), | 208 Proxy::mainThread(), |
198 queue.Pass(), | 209 queue.Pass(), |
199 m_layerTreeHostImpl->resourceProvider(), | 210 m_layerTreeHostImpl->resourceProvider()); |
200 hasImplThread()); | |
201 updateController->finalize(); | 211 updateController->finalize(); |
202 | 212 |
203 m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get()); | 213 m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get()); |
204 | 214 |
205 m_layerTreeHostImpl->commitComplete(); | 215 m_layerTreeHostImpl->commitComplete(); |
206 | 216 |
207 #ifndef NDEBUG | 217 #ifndef NDEBUG |
208 // In the single-threaded case, the scroll deltas should never be | 218 // In the single-threaded case, the scroll deltas should never be |
209 // touched on the impl layer tree. | 219 // touched on the impl layer tree. |
210 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processS
crollDeltas(); | 220 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processS
crollDeltas(); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 NOTREACHED(); | 385 NOTREACHED(); |
376 } | 386 } |
377 | 387 |
378 bool SingleThreadProxy::commitAndComposite() | 388 bool SingleThreadProxy::commitAndComposite() |
379 { | 389 { |
380 DCHECK(Proxy::isMainThread()); | 390 DCHECK(Proxy::isMainThread()); |
381 | 391 |
382 if (!m_layerTreeHost->initializeRendererIfNeeded()) | 392 if (!m_layerTreeHost->initializeRendererIfNeeded()) |
383 return false; | 393 return false; |
384 | 394 |
| 395 scoped_refptr<cc::ContextProvider> offscreenContextProvider; |
| 396 if (m_RendererCapabilitiesForMainThread.usingOffscreenContext3d && m_layerTr
eeHost->needsOffscreenContext()) { |
| 397 offscreenContextProvider = m_layerTreeHost->client()->OffscreenContextPr
oviderForMainThread(); |
| 398 if (offscreenContextProvider->InitializeOnMainThread()) |
| 399 m_createdOffscreenContextProvider = true; |
| 400 else |
| 401 offscreenContextProvider = NULL; |
| 402 } |
| 403 |
385 m_layerTreeHost->contentsTextureManager()->unlinkAndClearEvictedBackings(); | 404 m_layerTreeHost->contentsTextureManager()->unlinkAndClearEvictedBackings(); |
386 | 405 |
387 scoped_ptr<ResourceUpdateQueue> queue = make_scoped_ptr(new ResourceUpdateQu
eue); | 406 scoped_ptr<ResourceUpdateQueue> queue = make_scoped_ptr(new ResourceUpdateQu
eue); |
388 m_layerTreeHost->updateLayers(*(queue.get()), m_layerTreeHostImpl->memoryAll
ocationLimitBytes()); | 407 m_layerTreeHost->updateLayers(*(queue.get()), m_layerTreeHostImpl->memoryAll
ocationLimitBytes()); |
389 | 408 |
390 m_layerTreeHost->willCommit(); | 409 m_layerTreeHost->willCommit(); |
391 doCommit(queue.Pass()); | 410 doCommit(queue.Pass()); |
392 bool result = doComposite(); | 411 bool result = doComposite(offscreenContextProvider); |
393 m_layerTreeHost->didBeginFrame(); | 412 m_layerTreeHost->didBeginFrame(); |
394 return result; | 413 return result; |
395 } | 414 } |
396 | 415 |
397 bool SingleThreadProxy::doComposite() | 416 bool SingleThreadProxy::doComposite(scoped_refptr<cc::ContextProvider> offscreen
ContextProvider) |
398 { | 417 { |
399 DCHECK(!m_outputSurfaceLost); | 418 DCHECK(!m_outputSurfaceLost); |
400 { | 419 { |
401 DebugScopedSetImplThread impl(this); | 420 DebugScopedSetImplThread impl(this); |
402 base::AutoReset<bool> markInside(&m_insideDraw, true); | 421 base::AutoReset<bool> markInside(&m_insideDraw, true); |
403 | 422 |
| 423 m_layerTreeHostImpl->resourceProvider()->setOffscreenContextProvider(off
screenContextProvider); |
| 424 |
404 if (!m_layerTreeHostImpl->visible()) | 425 if (!m_layerTreeHostImpl->visible()) |
405 return false; | 426 return false; |
406 | 427 |
407 m_layerTreeHostImpl->animate(base::TimeTicks::Now(), base::Time::Now()); | 428 m_layerTreeHostImpl->animate(base::TimeTicks::Now(), base::Time::Now()); |
408 | 429 |
409 // We guard prepareToDraw() with canDraw() because it always returns a v
alid frame, so can only | 430 // We guard prepareToDraw() with canDraw() because it always returns a v
alid frame, so can only |
410 // be used when such a frame is possible. Since drawLayers() depends on
the result of | 431 // be used when such a frame is possible. Since drawLayers() depends on
the result of |
411 // prepareToDraw(), it is guarded on canDraw() as well. | 432 // prepareToDraw(), it is guarded on canDraw() as well. |
412 if (!m_layerTreeHostImpl->canDraw()) | 433 if (!m_layerTreeHostImpl->canDraw()) |
413 return false; | 434 return false; |
414 | 435 |
415 LayerTreeHostImpl::FrameData frame; | 436 LayerTreeHostImpl::FrameData frame; |
416 m_layerTreeHostImpl->prepareToDraw(frame); | 437 m_layerTreeHostImpl->prepareToDraw(frame); |
417 m_layerTreeHostImpl->drawLayers(frame); | 438 m_layerTreeHostImpl->drawLayers(frame); |
418 m_layerTreeHostImpl->didDrawAllLayers(frame); | 439 m_layerTreeHostImpl->didDrawAllLayers(frame); |
419 m_outputSurfaceLost = m_layerTreeHostImpl->isContextLost(); | 440 m_outputSurfaceLost = m_layerTreeHostImpl->isContextLost(); |
420 | 441 |
421 m_layerTreeHostImpl->beginNextFrame(); | 442 m_layerTreeHostImpl->beginNextFrame(); |
422 } | 443 } |
423 | 444 |
424 if (m_outputSurfaceLost) { | 445 if (m_outputSurfaceLost) { |
| 446 if (cc::ContextProvider* offscreenContexts = m_layerTreeHostImpl->resour
ceProvider()->offscreenContextProvider()) |
| 447 offscreenContexts->VerifyContexts(); |
425 m_layerTreeHost->didLoseOutputSurface(); | 448 m_layerTreeHost->didLoseOutputSurface(); |
426 return false; | 449 return false; |
427 } | 450 } |
428 | 451 |
429 return true; | 452 return true; |
430 } | 453 } |
431 | 454 |
432 void SingleThreadProxy::didSwapFrame() | 455 void SingleThreadProxy::didSwapFrame() |
433 { | 456 { |
434 if (m_nextFrameIsNewlyCommittedFrame) { | 457 if (m_nextFrameIsNewlyCommittedFrame) { |
435 m_nextFrameIsNewlyCommittedFrame = false; | 458 m_nextFrameIsNewlyCommittedFrame = false; |
436 m_layerTreeHost->didCommitAndDrawFrame(); | 459 m_layerTreeHost->didCommitAndDrawFrame(); |
437 } | 460 } |
438 } | 461 } |
439 | 462 |
440 bool SingleThreadProxy::commitPendingForTesting() | 463 bool SingleThreadProxy::commitPendingForTesting() |
441 { | 464 { |
442 return false; | 465 return false; |
443 } | 466 } |
444 | 467 |
445 skia::RefPtr<SkPicture> SingleThreadProxy::capturePicture() | 468 skia::RefPtr<SkPicture> SingleThreadProxy::capturePicture() |
446 { | 469 { |
447 // Requires impl-side painting, which is only supported in threaded composit
ing. | 470 // Requires impl-side painting, which is only supported in threaded composit
ing. |
448 NOTREACHED(); | 471 NOTREACHED(); |
449 return skia::RefPtr<SkPicture>(); | 472 return skia::RefPtr<SkPicture>(); |
450 } | 473 } |
451 | 474 |
452 } // namespace cc | 475 } // namespace cc |
OLD | NEW |