Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: cc/thread_proxy.cc

Issue 12212007: cc: Route offscreen context creation for compositor to the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove the GrContextProvider::ScopedContexts guard classes Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
21
22 using WebKit::WebSharedGraphicsContext3D;
23 20
24 namespace { 21 namespace {
25 22
26 // Measured in seconds. 23 // Measured in seconds.
27 const double contextRecreationTickRate = 0.03; 24 const double contextRecreationTickRate = 0.03;
28 25
29 // Measured in seconds. 26 // Measured in seconds.
30 const double smoothnessTakesPriorityExpirationDelay = 0.25; 27 const double smoothnessTakesPriorityExpirationDelay = 0.25;
31 28
32 } // namespace 29 } // namespace
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 m_RendererCapabilitiesMainThreadCopy = capabilities; 214 m_RendererCapabilitiesMainThreadCopy = capabilities;
218 } 215 }
219 return initializeSucceeded; 216 return initializeSucceeded;
220 } 217 }
221 218
222 bool ThreadProxy::recreateOutputSurface() 219 bool ThreadProxy::recreateOutputSurface()
223 { 220 {
224 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurface"); 221 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurface");
225 DCHECK(isMainThread()); 222 DCHECK(isMainThread());
226 223
224 bool needsOffscreenContext = m_RendererCapabilitiesMainThreadCopy.usingOffsc reenContext3d && m_layerTreeHost->needsOffscreenContext();
225 if (needsOffscreenContext)
226 m_layerTreeHost->client()->DestroyOffscreenContext3dForCompositorThread( );
227
227 // Try to create the surface. 228 // Try to create the surface.
228 scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurfa ce(); 229 scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurfa ce();
229 if (!outputSurface.get()) 230 if (!outputSurface.get())
230 return false; 231 return false;
231 if (m_layerTreeHost->needsSharedContext()) 232 WebKit::WebGraphicsContext3D* offscreenContext3d = NULL;
232 if (!WebSharedGraphicsContext3D::createCompositorThreadContext()) 233 GrContext* offscreenGrContext = NULL;
234 if (needsOffscreenContext) {
235 offscreenContext3d = m_layerTreeHost->client()->OffscreenContext3dForCom positorThread();
236 if (!offscreenContext3d)
233 return false; 237 return false;
238 offscreenGrContext = m_layerTreeHost->client()->OffscreenGrContextForCom positorThread();
239 }
234 240
235 // Make a blocking call to recreateOutputSurfaceOnImplThread. The results of that 241 // Make a blocking call to recreateOutputSurfaceOnImplThread. The results of that
236 // call are pushed into the recreateSucceeded and capabilities local 242 // call are pushed into the recreateSucceeded and capabilities local
237 // variables. 243 // variables.
238 CompletionEvent completion; 244 CompletionEvent completion;
239 bool recreateSucceeded = false; 245 bool recreateSucceeded = false;
240 RendererCapabilities capabilities; 246 RendererCapabilities capabilities;
241 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); 247 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
242 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::recreateOutputSurface OnImplThread, 248 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::recreateOutputSurface OnImplThread,
243 m_implThreadWeakPtr, 249 m_implThreadWeakPtr,
244 &completion, 250 &completion,
245 base::Passed(&outputSurface), 251 base::Passed(&outputSurface),
252 offscreenContext3d,
253 offscreenGrContext,
246 &recreateSucceeded, 254 &recreateSucceeded,
247 &capabilities)); 255 &capabilities));
248 completion.wait(); 256 completion.wait();
249 257
250 if (recreateSucceeded) 258 if (recreateSucceeded)
251 m_RendererCapabilitiesMainThreadCopy = capabilities; 259 m_RendererCapabilitiesMainThreadCopy = capabilities;
252 return recreateSucceeded; 260 return recreateSucceeded;
253 } 261 }
254 262
255 void ThreadProxy::renderingStats(RenderingStats* stats) 263 void ThreadProxy::renderingStats(RenderingStats* stats)
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 if (!m_layerTreeHost) 600 if (!m_layerTreeHost)
593 return; 601 return;
594 602
595 if (m_deferCommits) { 603 if (m_deferCommits) {
596 m_pendingDeferredCommit = beginFrameState.Pass(); 604 m_pendingDeferredCommit = beginFrameState.Pass();
597 m_layerTreeHost->didDeferCommit(); 605 m_layerTreeHost->didDeferCommit();
598 TRACE_EVENT0("cc", "EarlyOut_DeferCommits"); 606 TRACE_EVENT0("cc", "EarlyOut_DeferCommits");
599 return; 607 return;
600 } 608 }
601 609
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 610 // Do not notify the impl thread of commit requests that occur during
606 // the apply/animate/layout part of the beginFrameAndCommit process since 611 // the apply/animate/layout part of the beginFrameAndCommit process since
607 // those commit requests will get painted immediately. Once we have done 612 // 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 613 // the paint, m_commitRequested will be set to false to allow new commit
609 // requests to be scheduled. 614 // requests to be scheduled.
610 m_commitRequested = true; 615 m_commitRequested = true;
611 m_commitRequestSentToImplThread = true; 616 m_commitRequestSentToImplThread = true;
612 617
613 // On the other hand, the animationRequested flag needs to be cleared 618 // On the other hand, the animationRequested flag needs to be cleared
614 // here so that any animation requests generated by the apply or animate 619 // here so that any animation requests generated by the apply or animate
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 // false. If it is true now, it means setNeedAnimate was called again, but 669 // false. If it is true now, it means setNeedAnimate was called again, but
665 // during a state when m_commitRequestSentToImplThread = true. We need to 670 // 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 671 // force that call to happen again now so that the commit request is sent to
667 // the impl thread. 672 // the impl thread.
668 if (m_animateRequested) { 673 if (m_animateRequested) {
669 // Forces setNeedsAnimate to consider posting a commit task. 674 // Forces setNeedsAnimate to consider posting a commit task.
670 m_animateRequested = false; 675 m_animateRequested = false;
671 setNeedsAnimate(); 676 setNeedsAnimate();
672 } 677 }
673 678
679 WebKit::WebGraphicsContext3D* offscreenContext3d = NULL;
680 GrContext* offscreenGrContext = NULL;
681 if (m_RendererCapabilitiesMainThreadCopy.usingOffscreenContext3d && m_layerT reeHost->needsOffscreenContext()) {
682 offscreenContext3d = m_layerTreeHost->client()->OffscreenContext3dForCom positorThread();
683 offscreenGrContext = m_layerTreeHost->client()->OffscreenGrContextForCom positorThread();
684 }
685
674 // Notify the impl thread that the beginFrame has completed. This will 686 // Notify the impl thread that the beginFrame has completed. This will
675 // begin the commit process, which is blocking from the main thread's 687 // begin the commit process, which is blocking from the main thread's
676 // point of view, but asynchronously performed on the impl thread, 688 // point of view, but asynchronously performed on the impl thread,
677 // coordinated by the Scheduler. 689 // coordinated by the Scheduler.
678 { 690 {
679 TRACE_EVENT0("cc", "commit"); 691 TRACE_EVENT0("cc", "commit");
680 692
681 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); 693 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
682 694
683 base::TimeTicks startTime = base::TimeTicks::HighResNow(); 695 base::TimeTicks startTime = base::TimeTicks::HighResNow();
684 CompletionEvent completion; 696 CompletionEvent completion;
685 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::beginFrameComplet eOnImplThread, m_implThreadWeakPtr, &completion, queue.release())); 697 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::beginFrameComplet eOnImplThread, m_implThreadWeakPtr, &completion, queue.release(), offscreenConte xt3d, offscreenGrContext));
686 completion.wait(); 698 completion.wait();
687 base::TimeTicks endTime = base::TimeTicks::HighResNow(); 699 base::TimeTicks endTime = base::TimeTicks::HighResNow();
688 700
689 m_totalCommitTime += endTime - startTime; 701 m_totalCommitTime += endTime - startTime;
690 m_totalCommitCount++; 702 m_totalCommitCount++;
691 } 703 }
692 704
693 m_layerTreeHost->commitComplete(); 705 m_layerTreeHost->commitComplete();
694 m_layerTreeHost->didBeginFrame(); 706 m_layerTreeHost->didBeginFrame();
695 } 707 }
696 708
697 void ThreadProxy::beginFrameCompleteOnImplThread(CompletionEvent* completion, Re sourceUpdateQueue* rawQueue) 709 void ThreadProxy::beginFrameCompleteOnImplThread(CompletionEvent* completion, Re sourceUpdateQueue* rawQueue, WebKit::WebGraphicsContext3D* offscreenContext3d, G rContext* offscreenGrContext)
698 { 710 {
699 scoped_ptr<ResourceUpdateQueue> queue(rawQueue); 711 scoped_ptr<ResourceUpdateQueue> queue(rawQueue);
700 712
701 TRACE_EVENT0("cc", "ThreadProxy::beginFrameCompleteOnImplThread"); 713 TRACE_EVENT0("cc", "ThreadProxy::beginFrameCompleteOnImplThread");
702 DCHECK(!m_commitCompletionEventOnImplThread); 714 DCHECK(!m_commitCompletionEventOnImplThread);
703 DCHECK(isImplThread() && isMainThreadBlocked()); 715 DCHECK(isImplThread() && isMainThreadBlocked());
704 DCHECK(m_schedulerOnImplThread); 716 DCHECK(m_schedulerOnImplThread);
705 DCHECK(m_schedulerOnImplThread->commitPending()); 717 DCHECK(m_schedulerOnImplThread->commitPending());
706 718
707 if (!m_layerTreeHostImpl.get()) { 719 if (!m_layerTreeHostImpl.get()) {
708 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree"); 720 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree");
709 completion->signal(); 721 completion->signal();
710 return; 722 return;
711 } 723 }
712 724
725 m_layerTreeHostImpl->resourceProvider()->setOffscreenContexts(offscreenConte xt3d, offscreenGrContext);
726
713 if (m_layerTreeHost->contentsTextureManager()->linkedEvictedBackingsExist()) { 727 if (m_layerTreeHost->contentsTextureManager()->linkedEvictedBackingsExist()) {
714 // Clear any uploads we were making to textures linked to evicted 728 // Clear any uploads we were making to textures linked to evicted
715 // resources 729 // resources
716 queue->clearUploadsToEvictedResources(); 730 queue->clearUploadsToEvictedResources();
717 // Some textures in the layer tree are invalid. Kick off another commit 731 // Some textures in the layer tree are invalid. Kick off another commit
718 // to fill them again. 732 // to fill them again.
719 setNeedsCommitOnImplThread(); 733 setNeedsCommitOnImplThread();
720 } 734 }
721 735
722 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings() ; 736 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings() ;
723 737
724 m_currentResourceUpdateControllerOnImplThread = ResourceUpdateController::cr eate(this, Proxy::implThread(), queue.Pass(), m_layerTreeHostImpl->resourceProvi der(), hasImplThread()); 738 m_currentResourceUpdateControllerOnImplThread = ResourceUpdateController::cr eate(this, Proxy::implThread(), queue.Pass(), m_layerTreeHostImpl->resourceProvi der());
725 m_currentResourceUpdateControllerOnImplThread->performMoreUpdates( 739 m_currentResourceUpdateControllerOnImplThread->performMoreUpdates(
726 m_schedulerOnImplThread->anticipatedDrawTime()); 740 m_schedulerOnImplThread->anticipatedDrawTime());
727 741
728 m_commitCompletionEventOnImplThread = completion; 742 m_commitCompletionEventOnImplThread = completion;
729 } 743 }
730 744
731 void ThreadProxy::beginFrameAbortedOnImplThread() 745 void ThreadProxy::beginFrameAbortedOnImplThread()
732 { 746 {
733 TRACE_EVENT0("cc", "ThreadProxy::beginFrameAbortedOnImplThread"); 747 TRACE_EVENT0("cc", "ThreadProxy::beginFrameAbortedOnImplThread");
734 DCHECK(isImplThread()); 748 DCHECK(isImplThread());
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 { 1066 {
1053 DCHECK(isImplThread()); 1067 DCHECK(isImplThread());
1054 m_layerTreeHostImpl->setFullRootLayerDamage(); 1068 m_layerTreeHostImpl->setFullRootLayerDamage();
1055 } 1069 }
1056 1070
1057 size_t ThreadProxy::maxPartialTextureUpdates() const 1071 size_t ThreadProxy::maxPartialTextureUpdates() const
1058 { 1072 {
1059 return ResourceUpdateController::maxPartialTextureUpdates(); 1073 return ResourceUpdateController::maxPartialTextureUpdates();
1060 } 1074 }
1061 1075
1062 void ThreadProxy::recreateOutputSurfaceOnImplThread(CompletionEvent* completion, scoped_ptr<OutputSurface> outputSurface, bool* recreateSucceeded, RendererCapab ilities* capabilities) 1076 void ThreadProxy::recreateOutputSurfaceOnImplThread(CompletionEvent* completion, scoped_ptr<OutputSurface> outputSurface, WebKit::WebGraphicsContext3D* offscree nContext3d, GrContext* offscreenGrContext, bool* recreateSucceeded, RendererCapa bilities* capabilities)
1063 { 1077 {
1064 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurfaceOnImplThread"); 1078 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurfaceOnImplThread");
1065 DCHECK(isImplThread()); 1079 DCHECK(isImplThread());
1066 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->res ourceProvider()); 1080 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->res ourceProvider());
1067 *recreateSucceeded = m_layerTreeHostImpl->initializeRenderer(outputSurface.P ass()); 1081 *recreateSucceeded = m_layerTreeHostImpl->initializeRenderer(outputSurface.P ass());
1068 if (*recreateSucceeded) { 1082 if (*recreateSucceeded) {
1069 *capabilities = m_layerTreeHostImpl->rendererCapabilities(); 1083 *capabilities = m_layerTreeHostImpl->rendererCapabilities();
1084 m_layerTreeHostImpl->resourceProvider()->setOffscreenContexts(offscreenC ontext3d, offscreenGrContext);
1070 m_schedulerOnImplThread->didRecreateOutputSurface(); 1085 m_schedulerOnImplThread->didRecreateOutputSurface();
1071 } 1086 }
1072 completion->signal(); 1087 completion->signal();
1073 } 1088 }
1074 1089
1075 void ThreadProxy::renderingStatsOnImplThread(CompletionEvent* completion, Render ingStats* stats) 1090 void ThreadProxy::renderingStatsOnImplThread(CompletionEvent* completion, Render ingStats* stats)
1076 { 1091 {
1077 DCHECK(isImplThread()); 1092 DCHECK(isImplThread());
1078 m_layerTreeHostImpl->renderingStats(stats); 1093 m_layerTreeHostImpl->renderingStats(stats);
1079 completion->signal(); 1094 completion->signal();
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 1226
1212 void ThreadProxy::renewTreePriorityOnImplThread() 1227 void ThreadProxy::renewTreePriorityOnImplThread()
1213 { 1228 {
1214 DCHECK(m_renewTreePriorityOnImplThreadPending); 1229 DCHECK(m_renewTreePriorityOnImplThreadPending);
1215 m_renewTreePriorityOnImplThreadPending = false; 1230 m_renewTreePriorityOnImplThreadPending = false;
1216 1231
1217 renewTreePriority(); 1232 renewTreePriority();
1218 } 1233 }
1219 1234
1220 } // namespace cc 1235 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698