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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 if (!m_layerTreeHost) | 597 if (!m_layerTreeHost) |
593 return; | 598 return; |
594 | 599 |
595 if (m_deferCommits) { | 600 if (m_deferCommits) { |
596 m_pendingDeferredCommit = beginFrameState.Pass(); | 601 m_pendingDeferredCommit = beginFrameState.Pass(); |
597 m_layerTreeHost->didDeferCommit(); | 602 m_layerTreeHost->didDeferCommit(); |
598 TRACE_EVENT0("cc", "EarlyOut_DeferCommits"); | 603 TRACE_EVENT0("cc", "EarlyOut_DeferCommits"); |
599 return; | 604 return; |
600 } | 605 } |
601 | 606 |
602 if (m_layerTreeHost->needsSharedContext() && !WebSharedGraphicsContext3D::ha
veCompositorThreadContext()) | |
603 WebSharedGraphicsContext3D::createCompositorThreadContext(); | |
604 | |
605 // Do not notify the impl thread of commit requests that occur during | 607 // Do not notify the impl thread of commit requests that occur during |
606 // the apply/animate/layout part of the beginFrameAndCommit process since | 608 // the apply/animate/layout part of the beginFrameAndCommit process since |
607 // those commit requests will get painted immediately. Once we have done | 609 // those commit requests will get painted immediately. Once we have done |
608 // the paint, m_commitRequested will be set to false to allow new commit | 610 // the paint, m_commitRequested will be set to false to allow new commit |
609 // requests to be scheduled. | 611 // requests to be scheduled. |
610 m_commitRequested = true; | 612 m_commitRequested = true; |
611 m_commitRequestSentToImplThread = true; | 613 m_commitRequestSentToImplThread = true; |
612 | 614 |
613 // On the other hand, the animationRequested flag needs to be cleared | 615 // On the other hand, the animationRequested flag needs to be cleared |
614 // here so that any animation requests generated by the apply or animate | 616 // 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... |
664 // false. If it is true now, it means setNeedAnimate was called again, but | 666 // false. If it is true now, it means setNeedAnimate was called again, but |
665 // during a state when m_commitRequestSentToImplThread = true. We need to | 667 // during a state when m_commitRequestSentToImplThread = true. We need to |
666 // force that call to happen again now so that the commit request is sent to | 668 // force that call to happen again now so that the commit request is sent to |
667 // the impl thread. | 669 // the impl thread. |
668 if (m_animateRequested) { | 670 if (m_animateRequested) { |
669 // Forces setNeedsAnimate to consider posting a commit task. | 671 // Forces setNeedsAnimate to consider posting a commit task. |
670 m_animateRequested = false; | 672 m_animateRequested = false; |
671 setNeedsAnimate(); | 673 setNeedsAnimate(); |
672 } | 674 } |
673 | 675 |
| 676 WebKit::WebGraphicsContext3D* offscreenContext3d = NULL; |
| 677 GrContext* offscreenGrContext = NULL; |
| 678 if (m_RendererCapabilitiesMainThreadCopy.usingOffscreenContext3d && m_layerT
reeHost->needsOffscreenContext()) { |
| 679 offscreenContext3d = m_layerTreeHost->client()->OffscreenContext3dForCom
positorThread(); |
| 680 offscreenGrContext = m_layerTreeHost->client()->OffscreenGrContextForCom
positorThread(); |
| 681 } |
| 682 |
674 // Notify the impl thread that the beginFrame has completed. This will | 683 // Notify the impl thread that the beginFrame has completed. This will |
675 // begin the commit process, which is blocking from the main thread's | 684 // begin the commit process, which is blocking from the main thread's |
676 // point of view, but asynchronously performed on the impl thread, | 685 // point of view, but asynchronously performed on the impl thread, |
677 // coordinated by the Scheduler. | 686 // coordinated by the Scheduler. |
678 { | 687 { |
679 TRACE_EVENT0("cc", "commit"); | 688 TRACE_EVENT0("cc", "commit"); |
680 | 689 |
681 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); | 690 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
682 | 691 |
683 base::TimeTicks startTime = base::TimeTicks::HighResNow(); | 692 base::TimeTicks startTime = base::TimeTicks::HighResNow(); |
684 CompletionEvent completion; | 693 CompletionEvent completion; |
685 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::beginFrameComplet
eOnImplThread, m_implThreadWeakPtr, &completion, queue.release())); | 694 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::beginFrameComplet
eOnImplThread, m_implThreadWeakPtr, &completion, queue.release(), offscreenConte
xt3d, offscreenGrContext)); |
686 completion.wait(); | 695 completion.wait(); |
687 base::TimeTicks endTime = base::TimeTicks::HighResNow(); | 696 base::TimeTicks endTime = base::TimeTicks::HighResNow(); |
688 | 697 |
689 m_totalCommitTime += endTime - startTime; | 698 m_totalCommitTime += endTime - startTime; |
690 m_totalCommitCount++; | 699 m_totalCommitCount++; |
691 } | 700 } |
692 | 701 |
693 m_layerTreeHost->commitComplete(); | 702 m_layerTreeHost->commitComplete(); |
694 m_layerTreeHost->didBeginFrame(); | 703 m_layerTreeHost->didBeginFrame(); |
695 } | 704 } |
696 | 705 |
697 void ThreadProxy::beginFrameCompleteOnImplThread(CompletionEvent* completion, Re
sourceUpdateQueue* rawQueue) | 706 void ThreadProxy::beginFrameCompleteOnImplThread(CompletionEvent* completion, Re
sourceUpdateQueue* rawQueue, WebKit::WebGraphicsContext3D* offscreenContext3d, G
rContext* offscreenGrContext) |
698 { | 707 { |
699 scoped_ptr<ResourceUpdateQueue> queue(rawQueue); | 708 scoped_ptr<ResourceUpdateQueue> queue(rawQueue); |
700 | 709 |
701 TRACE_EVENT0("cc", "ThreadProxy::beginFrameCompleteOnImplThread"); | 710 TRACE_EVENT0("cc", "ThreadProxy::beginFrameCompleteOnImplThread"); |
702 DCHECK(!m_commitCompletionEventOnImplThread); | 711 DCHECK(!m_commitCompletionEventOnImplThread); |
703 DCHECK(isImplThread() && isMainThreadBlocked()); | 712 DCHECK(isImplThread() && isMainThreadBlocked()); |
704 DCHECK(m_schedulerOnImplThread); | 713 DCHECK(m_schedulerOnImplThread); |
705 DCHECK(m_schedulerOnImplThread->commitPending()); | 714 DCHECK(m_schedulerOnImplThread->commitPending()); |
706 | 715 |
707 if (!m_layerTreeHostImpl.get()) { | 716 if (!m_layerTreeHostImpl.get()) { |
708 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree"); | 717 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree"); |
709 completion->signal(); | 718 completion->signal(); |
710 return; | 719 return; |
711 } | 720 } |
712 | 721 |
| 722 m_layerTreeHostImpl->resourceProvider()->setGaneshContexts(offscreenContext3
d, offscreenGrContext); |
| 723 |
713 if (m_layerTreeHost->contentsTextureManager()->linkedEvictedBackingsExist())
{ | 724 if (m_layerTreeHost->contentsTextureManager()->linkedEvictedBackingsExist())
{ |
714 // Clear any uploads we were making to textures linked to evicted | 725 // Clear any uploads we were making to textures linked to evicted |
715 // resources | 726 // resources |
716 queue->clearUploadsToEvictedResources(); | 727 queue->clearUploadsToEvictedResources(); |
717 // Some textures in the layer tree are invalid. Kick off another commit | 728 // Some textures in the layer tree are invalid. Kick off another commit |
718 // to fill them again. | 729 // to fill them again. |
719 setNeedsCommitOnImplThread(); | 730 setNeedsCommitOnImplThread(); |
720 } | 731 } |
721 | 732 |
722 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings()
; | 733 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings()
; |
723 | 734 |
724 m_currentResourceUpdateControllerOnImplThread = ResourceUpdateController::cr
eate(this, Proxy::implThread(), queue.Pass(), m_layerTreeHostImpl->resourceProvi
der(), hasImplThread()); | 735 m_currentResourceUpdateControllerOnImplThread = ResourceUpdateController::cr
eate(this, Proxy::implThread(), queue.Pass(), m_layerTreeHostImpl->resourceProvi
der()); |
725 m_currentResourceUpdateControllerOnImplThread->performMoreUpdates( | 736 m_currentResourceUpdateControllerOnImplThread->performMoreUpdates( |
726 m_schedulerOnImplThread->anticipatedDrawTime()); | 737 m_schedulerOnImplThread->anticipatedDrawTime()); |
727 | 738 |
728 m_commitCompletionEventOnImplThread = completion; | 739 m_commitCompletionEventOnImplThread = completion; |
729 } | 740 } |
730 | 741 |
731 void ThreadProxy::beginFrameAbortedOnImplThread() | 742 void ThreadProxy::beginFrameAbortedOnImplThread() |
732 { | 743 { |
733 TRACE_EVENT0("cc", "ThreadProxy::beginFrameAbortedOnImplThread"); | 744 TRACE_EVENT0("cc", "ThreadProxy::beginFrameAbortedOnImplThread"); |
734 DCHECK(isImplThread()); | 745 DCHECK(isImplThread()); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1052 { | 1063 { |
1053 DCHECK(isImplThread()); | 1064 DCHECK(isImplThread()); |
1054 m_layerTreeHostImpl->setFullRootLayerDamage(); | 1065 m_layerTreeHostImpl->setFullRootLayerDamage(); |
1055 } | 1066 } |
1056 | 1067 |
1057 size_t ThreadProxy::maxPartialTextureUpdates() const | 1068 size_t ThreadProxy::maxPartialTextureUpdates() const |
1058 { | 1069 { |
1059 return ResourceUpdateController::maxPartialTextureUpdates(); | 1070 return ResourceUpdateController::maxPartialTextureUpdates(); |
1060 } | 1071 } |
1061 | 1072 |
1062 void ThreadProxy::recreateOutputSurfaceOnImplThread(CompletionEvent* completion,
scoped_ptr<OutputSurface> outputSurface, bool* recreateSucceeded, RendererCapab
ilities* capabilities) | 1073 void ThreadProxy::recreateOutputSurfaceOnImplThread(CompletionEvent* completion,
scoped_ptr<OutputSurface> outputSurface, WebKit::WebGraphicsContext3D* offscree
nContext3d, GrContext* offscreenGrContext, bool* recreateSucceeded, RendererCapa
bilities* capabilities) |
1063 { | 1074 { |
1064 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurfaceOnImplThread"); | 1075 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurfaceOnImplThread"); |
1065 DCHECK(isImplThread()); | 1076 DCHECK(isImplThread()); |
1066 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->res
ourceProvider()); | 1077 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->res
ourceProvider()); |
1067 *recreateSucceeded = m_layerTreeHostImpl->initializeRenderer(outputSurface.P
ass()); | 1078 *recreateSucceeded = m_layerTreeHostImpl->initializeRenderer(outputSurface.P
ass()); |
1068 if (*recreateSucceeded) { | 1079 if (*recreateSucceeded) { |
1069 *capabilities = m_layerTreeHostImpl->rendererCapabilities(); | 1080 *capabilities = m_layerTreeHostImpl->rendererCapabilities(); |
| 1081 m_layerTreeHostImpl->resourceProvider()->setGaneshContexts(offscreenCont
ext3d, offscreenGrContext); |
1070 m_schedulerOnImplThread->didRecreateOutputSurface(); | 1082 m_schedulerOnImplThread->didRecreateOutputSurface(); |
1071 } | 1083 } |
1072 completion->signal(); | 1084 completion->signal(); |
1073 } | 1085 } |
1074 | 1086 |
1075 void ThreadProxy::renderingStatsOnImplThread(CompletionEvent* completion, Render
ingStats* stats) | 1087 void ThreadProxy::renderingStatsOnImplThread(CompletionEvent* completion, Render
ingStats* stats) |
1076 { | 1088 { |
1077 DCHECK(isImplThread()); | 1089 DCHECK(isImplThread()); |
1078 m_layerTreeHostImpl->renderingStats(stats); | 1090 m_layerTreeHostImpl->renderingStats(stats); |
1079 completion->signal(); | 1091 completion->signal(); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 | 1200 |
1189 void ThreadProxy::renewTreePriorityOnImplThread() | 1201 void ThreadProxy::renewTreePriorityOnImplThread() |
1190 { | 1202 { |
1191 DCHECK(m_renewTreePriorityOnImplThreadPending); | 1203 DCHECK(m_renewTreePriorityOnImplThreadPending); |
1192 m_renewTreePriorityOnImplThreadPending = false; | 1204 m_renewTreePriorityOnImplThreadPending = false; |
1193 | 1205 |
1194 renewTreePriority(); | 1206 renewTreePriority(); |
1195 } | 1207 } |
1196 | 1208 |
1197 } // namespace cc | 1209 } // namespace cc |
OLD | NEW |