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/thread_proxy.h" | 5 #include "cc/thread_proxy.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "cc/delay_based_time_source.h" | 10 #include "cc/delay_based_time_source.h" |
11 #include "cc/draw_quad.h" | 11 #include "cc/draw_quad.h" |
12 #include "cc/frame_rate_controller.h" | 12 #include "cc/frame_rate_controller.h" |
13 #include "cc/input_handler.h" | 13 #include "cc/input_handler.h" |
14 #include "cc/layer_tree_host.h" | 14 #include "cc/layer_tree_host.h" |
15 #include "cc/layer_tree_impl.h" | 15 #include "cc/layer_tree_impl.h" |
16 #include "cc/output_surface.h" | 16 #include "cc/output_surface.h" |
17 #include "cc/prioritized_resource_manager.h" | 17 #include "cc/prioritized_resource_manager.h" |
18 #include "cc/scheduler.h" | 18 #include "cc/scheduler.h" |
19 #include "cc/thread.h" | 19 #include "cc/thread.h" |
20 #include "third_party/WebKit/Source/Platform/chromium/public/WebSharedGraphicsCo
ntext3D.h" | 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
21 | |
22 using WebKit::WebSharedGraphicsContext3D; | |
23 | 21 |
24 namespace { | 22 namespace { |
25 | 23 |
26 // Measured in seconds. | 24 // Measured in seconds. |
27 const double contextRecreationTickRate = 0.03; | 25 const double contextRecreationTickRate = 0.03; |
28 | 26 |
29 // Measured in seconds. | 27 // Measured in seconds. |
30 const double smoothnessTakesPriorityExpirationDelay = 0.25; | 28 const double smoothnessTakesPriorityExpirationDelay = 0.25; |
31 | 29 |
32 } // namespace | 30 } // namespace |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 219 |
222 bool ThreadProxy::recreateOutputSurface() | 220 bool ThreadProxy::recreateOutputSurface() |
223 { | 221 { |
224 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurface"); | 222 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurface"); |
225 DCHECK(isMainThread()); | 223 DCHECK(isMainThread()); |
226 | 224 |
227 // Try to create the surface. | 225 // Try to create the surface. |
228 scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurfa
ce(); | 226 scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurfa
ce(); |
229 if (!outputSurface.get()) | 227 if (!outputSurface.get()) |
230 return false; | 228 return false; |
231 if (m_layerTreeHost->needsSharedContext()) | 229 WebKit::WebGraphicsContext3D* offscreenContext3d = NULL; |
232 if (!WebSharedGraphicsContext3D::createCompositorThreadContext()) | 230 GrContext* offscreenGrContext = NULL; |
| 231 if (m_RendererCapabilitiesMainThreadCopy.usingOffscreenContext3d && m_layerT
reeHost->needsOffscreenContext()) { |
| 232 offscreenContext3d = m_layerTreeHost->client()->offscreenContext3dForCom
positorThread(); |
| 233 if (!offscreenContext3d || !offscreenContext3d->makeContextCurrent()) |
233 return false; | 234 return false; |
| 235 offscreenGrContext = m_layerTreeHost->client()->offscreenGrContextForCom
positorThread(); |
| 236 } |
234 | 237 |
235 // Make a blocking call to recreateOutputSurfaceOnImplThread. The results of
that | 238 // Make a blocking call to recreateOutputSurfaceOnImplThread. The results of
that |
236 // call are pushed into the recreateSucceeded and capabilities local | 239 // call are pushed into the recreateSucceeded and capabilities local |
237 // variables. | 240 // variables. |
238 CompletionEvent completion; | 241 CompletionEvent completion; |
239 bool recreateSucceeded = false; | 242 bool recreateSucceeded = false; |
240 RendererCapabilities capabilities; | 243 RendererCapabilities capabilities; |
241 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); | 244 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
242 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::recreateOutputSurface
OnImplThread, | 245 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::recreateOutputSurface
OnImplThread, |
243 m_implThreadWeakPtr, | 246 m_implThreadWeakPtr, |
244 &completion, | 247 &completion, |
245 base::Passed(&outputSurface), | 248 base::Passed(&outputSurface), |
| 249 offscreenContext3d, |
| 250 offscreenGrContext, |
246 &recreateSucceeded, | 251 &recreateSucceeded, |
247 &capabilities)); | 252 &capabilities)); |
248 completion.wait(); | 253 completion.wait(); |
249 | 254 |
250 if (recreateSucceeded) | 255 if (recreateSucceeded) |
251 m_RendererCapabilitiesMainThreadCopy = capabilities; | 256 m_RendererCapabilitiesMainThreadCopy = capabilities; |
252 return recreateSucceeded; | 257 return recreateSucceeded; |
253 } | 258 } |
254 | 259 |
255 void ThreadProxy::renderingStats(RenderingStats* stats) | 260 void ThreadProxy::renderingStats(RenderingStats* stats) |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 if (!m_layerTreeHost) | 587 if (!m_layerTreeHost) |
583 return; | 588 return; |
584 | 589 |
585 if (m_deferCommits) { | 590 if (m_deferCommits) { |
586 m_pendingDeferredCommit = beginFrameState.Pass(); | 591 m_pendingDeferredCommit = beginFrameState.Pass(); |
587 m_layerTreeHost->didDeferCommit(); | 592 m_layerTreeHost->didDeferCommit(); |
588 TRACE_EVENT0("cc", "EarlyOut_DeferCommits"); | 593 TRACE_EVENT0("cc", "EarlyOut_DeferCommits"); |
589 return; | 594 return; |
590 } | 595 } |
591 | 596 |
592 if (m_layerTreeHost->needsSharedContext() && !WebSharedGraphicsContext3D::ha
veCompositorThreadContext()) | |
593 WebSharedGraphicsContext3D::createCompositorThreadContext(); | |
594 | |
595 // Do not notify the impl thread of commit requests that occur during | 597 // Do not notify the impl thread of commit requests that occur during |
596 // the apply/animate/layout part of the beginFrameAndCommit process since | 598 // the apply/animate/layout part of the beginFrameAndCommit process since |
597 // those commit requests will get painted immediately. Once we have done | 599 // those commit requests will get painted immediately. Once we have done |
598 // the paint, m_commitRequested will be set to false to allow new commit | 600 // the paint, m_commitRequested will be set to false to allow new commit |
599 // requests to be scheduled. | 601 // requests to be scheduled. |
600 m_commitRequested = true; | 602 m_commitRequested = true; |
601 m_commitRequestSentToImplThread = true; | 603 m_commitRequestSentToImplThread = true; |
602 | 604 |
603 // On the other hand, the animationRequested flag needs to be cleared | 605 // On the other hand, the animationRequested flag needs to be cleared |
604 // here so that any animation requests generated by the apply or animate | 606 // here so that any animation requests generated by the apply or animate |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 // false. If it is true now, it means setNeedAnimate was called again, but | 656 // false. If it is true now, it means setNeedAnimate was called again, but |
655 // during a state when m_commitRequestSentToImplThread = true. We need to | 657 // during a state when m_commitRequestSentToImplThread = true. We need to |
656 // force that call to happen again now so that the commit request is sent to | 658 // force that call to happen again now so that the commit request is sent to |
657 // the impl thread. | 659 // the impl thread. |
658 if (m_animateRequested) { | 660 if (m_animateRequested) { |
659 // Forces setNeedsAnimate to consider posting a commit task. | 661 // Forces setNeedsAnimate to consider posting a commit task. |
660 m_animateRequested = false; | 662 m_animateRequested = false; |
661 setNeedsAnimate(); | 663 setNeedsAnimate(); |
662 } | 664 } |
663 | 665 |
| 666 WebKit::WebGraphicsContext3D* offscreenContext3d = NULL; |
| 667 GrContext* offscreenGrContext = NULL; |
| 668 if (m_RendererCapabilitiesMainThreadCopy.usingOffscreenContext3d && m_layerT
reeHost->needsOffscreenContext()) { |
| 669 offscreenContext3d = m_layerTreeHost->client()->offscreenContext3dForCom
positorThread(); |
| 670 offscreenGrContext = m_layerTreeHost->client()->offscreenGrContextForCom
positorThread(); |
| 671 } |
| 672 |
664 // Notify the impl thread that the beginFrame has completed. This will | 673 // Notify the impl thread that the beginFrame has completed. This will |
665 // begin the commit process, which is blocking from the main thread's | 674 // begin the commit process, which is blocking from the main thread's |
666 // point of view, but asynchronously performed on the impl thread, | 675 // point of view, but asynchronously performed on the impl thread, |
667 // coordinated by the Scheduler. | 676 // coordinated by the Scheduler. |
668 { | 677 { |
669 TRACE_EVENT0("cc", "commit"); | 678 TRACE_EVENT0("cc", "commit"); |
670 | 679 |
671 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); | 680 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
672 | 681 |
673 base::TimeTicks startTime = base::TimeTicks::HighResNow(); | 682 base::TimeTicks startTime = base::TimeTicks::HighResNow(); |
674 CompletionEvent completion; | 683 CompletionEvent completion; |
675 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::beginFrameComplet
eOnImplThread, m_implThreadWeakPtr, &completion, queue.release())); | 684 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::beginFrameComplet
eOnImplThread, m_implThreadWeakPtr, &completion, queue.release(), offscreenConte
xt3d, offscreenGrContext)); |
676 completion.wait(); | 685 completion.wait(); |
677 base::TimeTicks endTime = base::TimeTicks::HighResNow(); | 686 base::TimeTicks endTime = base::TimeTicks::HighResNow(); |
678 | 687 |
679 m_totalCommitTime += endTime - startTime; | 688 m_totalCommitTime += endTime - startTime; |
680 m_totalCommitCount++; | 689 m_totalCommitCount++; |
681 } | 690 } |
682 | 691 |
683 m_layerTreeHost->commitComplete(); | 692 m_layerTreeHost->commitComplete(); |
684 m_layerTreeHost->didBeginFrame(); | 693 m_layerTreeHost->didBeginFrame(); |
685 } | 694 } |
686 | 695 |
687 void ThreadProxy::beginFrameCompleteOnImplThread(CompletionEvent* completion, Re
sourceUpdateQueue* rawQueue) | 696 void ThreadProxy::beginFrameCompleteOnImplThread(CompletionEvent* completion, Re
sourceUpdateQueue* rawQueue, WebKit::WebGraphicsContext3D* offscreenContext3d, G
rContext* offscreenGrContext) |
688 { | 697 { |
689 scoped_ptr<ResourceUpdateQueue> queue(rawQueue); | 698 scoped_ptr<ResourceUpdateQueue> queue(rawQueue); |
690 | 699 |
691 TRACE_EVENT0("cc", "ThreadProxy::beginFrameCompleteOnImplThread"); | 700 TRACE_EVENT0("cc", "ThreadProxy::beginFrameCompleteOnImplThread"); |
692 DCHECK(!m_commitCompletionEventOnImplThread); | 701 DCHECK(!m_commitCompletionEventOnImplThread); |
693 DCHECK(isImplThread() && isMainThreadBlocked()); | 702 DCHECK(isImplThread() && isMainThreadBlocked()); |
694 DCHECK(m_schedulerOnImplThread); | 703 DCHECK(m_schedulerOnImplThread); |
695 DCHECK(m_schedulerOnImplThread->commitPending()); | 704 DCHECK(m_schedulerOnImplThread->commitPending()); |
696 | 705 |
697 if (!m_layerTreeHostImpl.get()) { | 706 if (!m_layerTreeHostImpl.get()) { |
698 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree"); | 707 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree"); |
699 completion->signal(); | 708 completion->signal(); |
700 return; | 709 return; |
701 } | 710 } |
702 | 711 |
| 712 m_layerTreeHostImpl->resourceProvider()->setGaneshContexts(offscreenContext3
d, offscreenGrContext); |
| 713 |
703 if (m_layerTreeHost->contentsTextureManager()->linkedEvictedBackingsExist())
{ | 714 if (m_layerTreeHost->contentsTextureManager()->linkedEvictedBackingsExist())
{ |
704 // Clear any uploads we were making to textures linked to evicted | 715 // Clear any uploads we were making to textures linked to evicted |
705 // resources | 716 // resources |
706 queue->clearUploadsToEvictedResources(); | 717 queue->clearUploadsToEvictedResources(); |
707 // Some textures in the layer tree are invalid. Kick off another commit | 718 // Some textures in the layer tree are invalid. Kick off another commit |
708 // to fill them again. | 719 // to fill them again. |
709 setNeedsCommitOnImplThread(); | 720 setNeedsCommitOnImplThread(); |
710 } | 721 } |
711 | 722 |
712 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings()
; | 723 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings()
; |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 { | 1053 { |
1043 DCHECK(isImplThread()); | 1054 DCHECK(isImplThread()); |
1044 m_layerTreeHostImpl->setFullRootLayerDamage(); | 1055 m_layerTreeHostImpl->setFullRootLayerDamage(); |
1045 } | 1056 } |
1046 | 1057 |
1047 size_t ThreadProxy::maxPartialTextureUpdates() const | 1058 size_t ThreadProxy::maxPartialTextureUpdates() const |
1048 { | 1059 { |
1049 return ResourceUpdateController::maxPartialTextureUpdates(); | 1060 return ResourceUpdateController::maxPartialTextureUpdates(); |
1050 } | 1061 } |
1051 | 1062 |
1052 void ThreadProxy::recreateOutputSurfaceOnImplThread(CompletionEvent* completion,
scoped_ptr<OutputSurface> outputSurface, bool* recreateSucceeded, RendererCapab
ilities* capabilities) | 1063 void ThreadProxy::recreateOutputSurfaceOnImplThread(CompletionEvent* completion,
scoped_ptr<OutputSurface> outputSurface, WebKit::WebGraphicsContext3D* offscree
nContext3d, GrContext* offscreenGrContext, bool* recreateSucceeded, RendererCapa
bilities* capabilities) |
1053 { | 1064 { |
1054 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurfaceOnImplThread"); | 1065 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurfaceOnImplThread"); |
1055 DCHECK(isImplThread()); | 1066 DCHECK(isImplThread()); |
1056 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->res
ourceProvider()); | 1067 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->res
ourceProvider()); |
1057 *recreateSucceeded = m_layerTreeHostImpl->initializeRenderer(outputSurface.P
ass()); | 1068 *recreateSucceeded = m_layerTreeHostImpl->initializeRenderer(outputSurface.P
ass()); |
1058 if (*recreateSucceeded) { | 1069 if (*recreateSucceeded) { |
1059 *capabilities = m_layerTreeHostImpl->rendererCapabilities(); | 1070 *capabilities = m_layerTreeHostImpl->rendererCapabilities(); |
| 1071 m_layerTreeHostImpl->resourceProvider()->setGaneshContexts(offscreenCont
ext3d, offscreenGrContext); |
1060 m_schedulerOnImplThread->didRecreateOutputSurface(); | 1072 m_schedulerOnImplThread->didRecreateOutputSurface(); |
1061 } | 1073 } |
1062 completion->signal(); | 1074 completion->signal(); |
1063 } | 1075 } |
1064 | 1076 |
1065 void ThreadProxy::renderingStatsOnImplThread(CompletionEvent* completion, Render
ingStats* stats) | 1077 void ThreadProxy::renderingStatsOnImplThread(CompletionEvent* completion, Render
ingStats* stats) |
1066 { | 1078 { |
1067 DCHECK(isImplThread()); | 1079 DCHECK(isImplThread()); |
1068 m_layerTreeHostImpl->renderingStats(stats); | 1080 m_layerTreeHostImpl->renderingStats(stats); |
1069 completion->signal(); | 1081 completion->signal(); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 | 1190 |
1179 void ThreadProxy::renewTreePriorityOnImplThread() | 1191 void ThreadProxy::renewTreePriorityOnImplThread() |
1180 { | 1192 { |
1181 DCHECK(m_renewTreePriorityOnImplThreadPending); | 1193 DCHECK(m_renewTreePriorityOnImplThreadPending); |
1182 m_renewTreePriorityOnImplThreadPending = false; | 1194 m_renewTreePriorityOnImplThreadPending = false; |
1183 | 1195 |
1184 renewTreePriority(); | 1196 renewTreePriority(); |
1185 } | 1197 } |
1186 | 1198 |
1187 } // namespace cc | 1199 } // namespace cc |
OLD | NEW |