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/draw_quad.h" | 9 #include "cc/draw_quad.h" |
10 #include "cc/layer_tree_host.h" | 10 #include "cc/layer_tree_host.h" |
11 #include "cc/layer_tree_impl.h" | 11 #include "cc/layer_tree_impl.h" |
12 #include "cc/output_surface.h" | 12 #include "cc/output_surface.h" |
13 #include "cc/prioritized_resource_manager.h" | 13 #include "cc/prioritized_resource_manager.h" |
14 #include "cc/resource_update_controller.h" | 14 #include "cc/resource_update_controller.h" |
15 #include "cc/thread.h" | 15 #include "cc/thread.h" |
| 16 #include "ui/gl/context_provider.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<ui::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); |
151 } | 160 } |
152 } | 161 } |
153 | 162 |
154 if (initialized) | 163 if (initialized) |
155 m_outputSurfaceLost = false; | 164 m_outputSurfaceLost = false; |
156 | 165 |
157 return initialized; | 166 return initialized; |
158 } | 167 } |
159 | 168 |
160 void SingleThreadProxy::renderingStats(RenderingStats* stats) | 169 void SingleThreadProxy::renderingStats(RenderingStats* stats) |
(...skipping 28 matching lines...) Expand all Loading... |
189 m_layerTreeHostImpl->beginCommit(); | 198 m_layerTreeHostImpl->beginCommit(); |
190 | 199 |
191 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackin
gs(); | 200 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackin
gs(); |
192 m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get()); | 201 m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get()); |
193 | 202 |
194 scoped_ptr<ResourceUpdateController> updateController = | 203 scoped_ptr<ResourceUpdateController> updateController = |
195 ResourceUpdateController::create( | 204 ResourceUpdateController::create( |
196 NULL, | 205 NULL, |
197 Proxy::mainThread(), | 206 Proxy::mainThread(), |
198 queue.Pass(), | 207 queue.Pass(), |
199 m_layerTreeHostImpl->resourceProvider(), | 208 m_layerTreeHostImpl->resourceProvider()); |
200 hasImplThread()); | |
201 updateController->finalize(); | 209 updateController->finalize(); |
202 | 210 |
203 m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get()); | 211 m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get()); |
204 | 212 |
205 m_layerTreeHostImpl->commitComplete(); | 213 m_layerTreeHostImpl->commitComplete(); |
206 | 214 |
207 #ifndef NDEBUG | 215 #ifndef NDEBUG |
208 // In the single-threaded case, the scroll deltas should never be | 216 // In the single-threaded case, the scroll deltas should never be |
209 // touched on the impl layer tree. | 217 // touched on the impl layer tree. |
210 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processS
crollDeltas(); | 218 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processS
crollDeltas(); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 NOTREACHED(); | 383 NOTREACHED(); |
376 } | 384 } |
377 | 385 |
378 bool SingleThreadProxy::commitAndComposite() | 386 bool SingleThreadProxy::commitAndComposite() |
379 { | 387 { |
380 DCHECK(Proxy::isMainThread()); | 388 DCHECK(Proxy::isMainThread()); |
381 | 389 |
382 if (!m_layerTreeHost->initializeRendererIfNeeded()) | 390 if (!m_layerTreeHost->initializeRendererIfNeeded()) |
383 return false; | 391 return false; |
384 | 392 |
| 393 scoped_refptr<ui::ContextProvider> offscreenContextProvider; |
| 394 if (m_RendererCapabilitiesForMainThread.usingOffscreenContext3d && m_layerTr
eeHost->needsOffscreenContext()) { |
| 395 offscreenContextProvider = m_layerTreeHost->client()->OffscreenContextPr
oviderForMainThread(); |
| 396 if (offscreenContextProvider->InitializeOnMainThread()) |
| 397 m_createdOffscreenContextProvider = true; |
| 398 else |
| 399 offscreenContextProvider = NULL; |
| 400 } |
| 401 |
385 m_layerTreeHost->contentsTextureManager()->unlinkAndClearEvictedBackings(); | 402 m_layerTreeHost->contentsTextureManager()->unlinkAndClearEvictedBackings(); |
386 | 403 |
387 scoped_ptr<ResourceUpdateQueue> queue = make_scoped_ptr(new ResourceUpdateQu
eue); | 404 scoped_ptr<ResourceUpdateQueue> queue = make_scoped_ptr(new ResourceUpdateQu
eue); |
388 m_layerTreeHost->updateLayers(*(queue.get()), m_layerTreeHostImpl->memoryAll
ocationLimitBytes()); | 405 m_layerTreeHost->updateLayers(*(queue.get()), m_layerTreeHostImpl->memoryAll
ocationLimitBytes()); |
389 | 406 |
390 m_layerTreeHost->willCommit(); | 407 m_layerTreeHost->willCommit(); |
391 doCommit(queue.Pass()); | 408 doCommit(queue.Pass()); |
392 bool result = doComposite(); | 409 bool result = doComposite(offscreenContextProvider); |
393 m_layerTreeHost->didBeginFrame(); | 410 m_layerTreeHost->didBeginFrame(); |
394 return result; | 411 return result; |
395 } | 412 } |
396 | 413 |
397 bool SingleThreadProxy::doComposite() | 414 bool SingleThreadProxy::doComposite(scoped_refptr<ui::ContextProvider> offscreen
ContextProvider) |
398 { | 415 { |
399 DCHECK(!m_outputSurfaceLost); | 416 DCHECK(!m_outputSurfaceLost); |
400 { | 417 { |
401 DebugScopedSetImplThread impl(this); | 418 DebugScopedSetImplThread impl(this); |
402 base::AutoReset<bool> markInside(&m_insideDraw, true); | 419 base::AutoReset<bool> markInside(&m_insideDraw, true); |
403 | 420 |
| 421 m_layerTreeHostImpl->resourceProvider()->setOffscreenContextProvider(off
screenContextProvider); |
| 422 |
404 if (!m_layerTreeHostImpl->visible()) | 423 if (!m_layerTreeHostImpl->visible()) |
405 return false; | 424 return false; |
406 | 425 |
407 m_layerTreeHostImpl->animate(base::TimeTicks::Now(), base::Time::Now()); | 426 m_layerTreeHostImpl->animate(base::TimeTicks::Now(), base::Time::Now()); |
408 | 427 |
409 // We guard prepareToDraw() with canDraw() because it always returns a v
alid frame, so can only | 428 // 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 | 429 // be used when such a frame is possible. Since drawLayers() depends on
the result of |
411 // prepareToDraw(), it is guarded on canDraw() as well. | 430 // prepareToDraw(), it is guarded on canDraw() as well. |
412 if (!m_layerTreeHostImpl->canDraw()) | 431 if (!m_layerTreeHostImpl->canDraw()) |
413 return false; | 432 return false; |
414 | 433 |
415 LayerTreeHostImpl::FrameData frame; | 434 LayerTreeHostImpl::FrameData frame; |
416 m_layerTreeHostImpl->prepareToDraw(frame); | 435 m_layerTreeHostImpl->prepareToDraw(frame); |
417 m_layerTreeHostImpl->drawLayers(frame); | 436 m_layerTreeHostImpl->drawLayers(frame); |
418 m_layerTreeHostImpl->didDrawAllLayers(frame); | 437 m_layerTreeHostImpl->didDrawAllLayers(frame); |
419 m_outputSurfaceLost = m_layerTreeHostImpl->isContextLost(); | 438 m_outputSurfaceLost = m_layerTreeHostImpl->isContextLost(); |
420 | 439 |
421 m_layerTreeHostImpl->beginNextFrame(); | 440 m_layerTreeHostImpl->beginNextFrame(); |
422 } | 441 } |
423 | 442 |
424 if (m_outputSurfaceLost) { | 443 if (m_outputSurfaceLost) { |
| 444 if (ui::ContextProvider* offscreenContexts = m_layerTreeHostImpl->resour
ceProvider()->offscreenContextProvider()) |
| 445 offscreenContexts->VerifyContexts(); |
425 m_layerTreeHost->didLoseOutputSurface(); | 446 m_layerTreeHost->didLoseOutputSurface(); |
426 return false; | 447 return false; |
427 } | 448 } |
428 | 449 |
429 return true; | 450 return true; |
430 } | 451 } |
431 | 452 |
432 void SingleThreadProxy::didSwapFrame() | 453 void SingleThreadProxy::didSwapFrame() |
433 { | 454 { |
434 if (m_nextFrameIsNewlyCommittedFrame) { | 455 if (m_nextFrameIsNewlyCommittedFrame) { |
435 m_nextFrameIsNewlyCommittedFrame = false; | 456 m_nextFrameIsNewlyCommittedFrame = false; |
436 m_layerTreeHost->didCommitAndDrawFrame(); | 457 m_layerTreeHost->didCommitAndDrawFrame(); |
437 } | 458 } |
438 } | 459 } |
439 | 460 |
440 bool SingleThreadProxy::commitPendingForTesting() | 461 bool SingleThreadProxy::commitPendingForTesting() |
441 { | 462 { |
442 return false; | 463 return false; |
443 } | 464 } |
444 | 465 |
445 skia::RefPtr<SkPicture> SingleThreadProxy::capturePicture() | 466 skia::RefPtr<SkPicture> SingleThreadProxy::capturePicture() |
446 { | 467 { |
447 // Requires impl-side painting, which is only supported in threaded composit
ing. | 468 // Requires impl-side painting, which is only supported in threaded composit
ing. |
448 NOTREACHED(); | 469 NOTREACHED(); |
449 return skia::RefPtr<SkPicture>(); | 470 return skia::RefPtr<SkPicture>(); |
450 } | 471 } |
451 | 472 |
452 } // namespace cc | 473 } // namespace cc |
OLD | NEW |