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

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: Fix typo 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/context_provider.h"
10 #include "cc/delay_based_time_source.h" 11 #include "cc/delay_based_time_source.h"
11 #include "cc/draw_quad.h" 12 #include "cc/draw_quad.h"
12 #include "cc/frame_rate_controller.h" 13 #include "cc/frame_rate_controller.h"
13 #include "cc/input_handler.h" 14 #include "cc/input_handler.h"
14 #include "cc/layer_tree_host.h" 15 #include "cc/layer_tree_host.h"
15 #include "cc/layer_tree_impl.h" 16 #include "cc/layer_tree_impl.h"
16 #include "cc/output_surface.h" 17 #include "cc/output_surface.h"
17 #include "cc/prioritized_resource_manager.h" 18 #include "cc/prioritized_resource_manager.h"
18 #include "cc/scheduler.h" 19 #include "cc/scheduler.h"
19 #include "cc/thread.h" 20 #include "cc/thread.h"
20 #include "third_party/WebKit/Source/Platform/chromium/public/WebSharedGraphicsCo ntext3D.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
33 31
34 namespace cc { 32 namespace cc {
35 33
36 scoped_ptr<Proxy> ThreadProxy::create(LayerTreeHost* layerTreeHost, scoped_ptr<T hread> implThread) 34 scoped_ptr<Proxy> ThreadProxy::create(LayerTreeHost* layerTreeHost, scoped_ptr<T hread> implThread)
37 { 35 {
38 return make_scoped_ptr(new ThreadProxy(layerTreeHost, implThread.Pass())).Pa ssAs<Proxy>(); 36 return make_scoped_ptr(new ThreadProxy(layerTreeHost, implThread.Pass())).Pa ssAs<Proxy>();
39 } 37 }
40 38
41 ThreadProxy::ThreadProxy(LayerTreeHost* layerTreeHost, scoped_ptr<Thread> implTh read) 39 ThreadProxy::ThreadProxy(LayerTreeHost* layerTreeHost, scoped_ptr<Thread> implTh read)
42 : Proxy(implThread.Pass()) 40 : Proxy(implThread.Pass())
43 , m_animateRequested(false) 41 , m_animateRequested(false)
44 , m_commitRequested(false) 42 , m_commitRequested(false)
45 , m_commitRequestSentToImplThread(false) 43 , m_commitRequestSentToImplThread(false)
44 , m_createdOffscreenContextProvider(false)
46 , m_layerTreeHost(layerTreeHost) 45 , m_layerTreeHost(layerTreeHost)
47 , m_rendererInitialized(false) 46 , m_rendererInitialized(false)
48 , m_started(false) 47 , m_started(false)
49 , m_texturesAcquired(true) 48 , m_texturesAcquired(true)
50 , m_inCompositeAndReadback(false) 49 , m_inCompositeAndReadback(false)
51 , m_manageTilesPending(false) 50 , m_manageTilesPending(false)
52 , m_weakFactoryOnImplThread(ALLOW_THIS_IN_INITIALIZER_LIST(this)) 51 , m_weakFactoryOnImplThread(ALLOW_THIS_IN_INITIALIZER_LIST(this))
53 , m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) 52 , m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this))
54 , m_beginFrameCompletionEventOnImplThread(0) 53 , m_beginFrameCompletionEventOnImplThread(0)
55 , m_readbackRequestOnImplThread(0) 54 , m_readbackRequestOnImplThread(0)
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 220
222 bool ThreadProxy::recreateOutputSurface() 221 bool ThreadProxy::recreateOutputSurface()
223 { 222 {
224 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurface"); 223 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurface");
225 DCHECK(isMainThread()); 224 DCHECK(isMainThread());
226 225
227 // Try to create the surface. 226 // Try to create the surface.
228 scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurfa ce(); 227 scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurfa ce();
229 if (!outputSurface.get()) 228 if (!outputSurface.get())
230 return false; 229 return false;
231 if (m_layerTreeHost->needsSharedContext()) 230 scoped_refptr<cc::ContextProvider> offscreenContextProvider;
232 if (!WebSharedGraphicsContext3D::createCompositorThreadContext()) 231 if (m_createdOffscreenContextProvider) {
232 offscreenContextProvider = m_layerTreeHost->client()->OffscreenContextPr oviderForCompositorThread();
233 if (!offscreenContextProvider->InitializeOnMainThread())
233 return false; 234 return false;
235 }
234 236
235 // Make a blocking call to recreateOutputSurfaceOnImplThread. The results of that 237 // Make a blocking call to recreateOutputSurfaceOnImplThread. The results of that
236 // call are pushed into the recreateSucceeded and capabilities local 238 // call are pushed into the recreateSucceeded and capabilities local
237 // variables. 239 // variables.
238 CompletionEvent completion; 240 CompletionEvent completion;
239 bool recreateSucceeded = false; 241 bool recreateSucceeded = false;
240 RendererCapabilities capabilities; 242 RendererCapabilities capabilities;
241 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); 243 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
242 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::recreateOutputSurface OnImplThread, 244 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::recreateOutputSurface OnImplThread,
243 m_implThreadWeakPtr, 245 m_implThreadWeakPtr,
244 &completion, 246 &completion,
245 base::Passed(&outputSurface), 247 base::Passed(&outputSurface),
248 offscreenContextProvider,
246 &recreateSucceeded, 249 &recreateSucceeded,
247 &capabilities)); 250 &capabilities));
248 completion.wait(); 251 completion.wait();
249 252
250 if (recreateSucceeded) 253 if (recreateSucceeded)
251 m_RendererCapabilitiesMainThreadCopy = capabilities; 254 m_RendererCapabilitiesMainThreadCopy = capabilities;
252 return recreateSucceeded; 255 return recreateSucceeded;
253 } 256 }
254 257
255 void ThreadProxy::renderingStats(RenderingStats* stats) 258 void ThreadProxy::renderingStats(RenderingStats* stats)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 TRACE_EVENT0("cc", "ThreadProxy::didLoseOutputSurfaceOnImplThread"); 310 TRACE_EVENT0("cc", "ThreadProxy::didLoseOutputSurfaceOnImplThread");
308 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::checkOutputSurfaceSta tusOnImplThread, m_implThreadWeakPtr)); 311 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::checkOutputSurfaceSta tusOnImplThread, m_implThreadWeakPtr));
309 } 312 }
310 313
311 void ThreadProxy::checkOutputSurfaceStatusOnImplThread() 314 void ThreadProxy::checkOutputSurfaceStatusOnImplThread()
312 { 315 {
313 DCHECK(isImplThread()); 316 DCHECK(isImplThread());
314 TRACE_EVENT0("cc", "ThreadProxy::checkOutputSurfaceStatusOnImplThread"); 317 TRACE_EVENT0("cc", "ThreadProxy::checkOutputSurfaceStatusOnImplThread");
315 if (!m_layerTreeHostImpl->isContextLost()) 318 if (!m_layerTreeHostImpl->isContextLost())
316 return; 319 return;
320 if (cc::ContextProvider* offscreenContexts = m_layerTreeHostImpl->resourcePr ovider()->offscreenContextProvider())
321 offscreenContexts->VerifyContexts();
317 m_schedulerOnImplThread->didLoseOutputSurface(); 322 m_schedulerOnImplThread->didLoseOutputSurface();
318 } 323 }
319 324
320 void ThreadProxy::onSwapBuffersCompleteOnImplThread() 325 void ThreadProxy::onSwapBuffersCompleteOnImplThread()
321 { 326 {
322 DCHECK(isImplThread()); 327 DCHECK(isImplThread());
323 TRACE_EVENT0("cc", "ThreadProxy::onSwapBuffersCompleteOnImplThread"); 328 TRACE_EVENT0("cc", "ThreadProxy::onSwapBuffersCompleteOnImplThread");
324 m_schedulerOnImplThread->didSwapBuffersComplete(); 329 m_schedulerOnImplThread->didSwapBuffersComplete();
325 Proxy::mainThread()->postTask(base::Bind(&ThreadProxy::didCompleteSwapBuffer s, m_mainThreadWeakPtr)); 330 Proxy::mainThread()->postTask(base::Bind(&ThreadProxy::didCompleteSwapBuffer s, m_mainThreadWeakPtr));
326 } 331 }
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 scoped_refptr<cc::ContextProvider> offscreenContextProvider;
677 if (m_RendererCapabilitiesMainThreadCopy.usingOffscreenContext3d && m_layerT reeHost->needsOffscreenContext()) {
678 offscreenContextProvider = m_layerTreeHost->client()->OffscreenContextPr oviderForCompositorThread();
679 if (offscreenContextProvider->InitializeOnMainThread())
680 m_createdOffscreenContextProvider = true;
681 else
682 offscreenContextProvider = NULL;
683 }
684
674 // Notify the impl thread that the beginFrame has completed. This will 685 // Notify the impl thread that the beginFrame has completed. This will
675 // begin the commit process, which is blocking from the main thread's 686 // begin the commit process, which is blocking from the main thread's
676 // point of view, but asynchronously performed on the impl thread, 687 // point of view, but asynchronously performed on the impl thread,
677 // coordinated by the Scheduler. 688 // coordinated by the Scheduler.
678 { 689 {
679 TRACE_EVENT0("cc", "commit"); 690 TRACE_EVENT0("cc", "commit");
680 691
681 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); 692 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
682 693
683 base::TimeTicks startTime = base::TimeTicks::HighResNow(); 694 base::TimeTicks startTime = base::TimeTicks::HighResNow();
684 CompletionEvent completion; 695 CompletionEvent completion;
685 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::beginFrameComplet eOnImplThread, m_implThreadWeakPtr, &completion, queue.release())); 696 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::beginFrameComplet eOnImplThread, m_implThreadWeakPtr, &completion, queue.release(), offscreenConte xtProvider));
686 completion.wait(); 697 completion.wait();
687 base::TimeTicks endTime = base::TimeTicks::HighResNow(); 698 base::TimeTicks endTime = base::TimeTicks::HighResNow();
688 699
689 m_totalCommitTime += endTime - startTime; 700 m_totalCommitTime += endTime - startTime;
690 m_totalCommitCount++; 701 m_totalCommitCount++;
691 } 702 }
692 703
693 m_layerTreeHost->commitComplete(); 704 m_layerTreeHost->commitComplete();
694 m_layerTreeHost->didBeginFrame(); 705 m_layerTreeHost->didBeginFrame();
695 } 706 }
696 707
697 void ThreadProxy::beginFrameCompleteOnImplThread(CompletionEvent* completion, Re sourceUpdateQueue* rawQueue) 708 void ThreadProxy::beginFrameCompleteOnImplThread(CompletionEvent* completion, Re sourceUpdateQueue* rawQueue, scoped_refptr<cc::ContextProvider> offscreenContext Provider)
698 { 709 {
699 scoped_ptr<ResourceUpdateQueue> queue(rawQueue); 710 scoped_ptr<ResourceUpdateQueue> queue(rawQueue);
700 711
701 TRACE_EVENT0("cc", "ThreadProxy::beginFrameCompleteOnImplThread"); 712 TRACE_EVENT0("cc", "ThreadProxy::beginFrameCompleteOnImplThread");
702 DCHECK(!m_commitCompletionEventOnImplThread); 713 DCHECK(!m_commitCompletionEventOnImplThread);
703 DCHECK(isImplThread() && isMainThreadBlocked()); 714 DCHECK(isImplThread() && isMainThreadBlocked());
704 DCHECK(m_schedulerOnImplThread); 715 DCHECK(m_schedulerOnImplThread);
705 DCHECK(m_schedulerOnImplThread->commitPending()); 716 DCHECK(m_schedulerOnImplThread->commitPending());
706 717
707 if (!m_layerTreeHostImpl.get()) { 718 if (!m_layerTreeHostImpl.get()) {
708 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree"); 719 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree");
709 completion->signal(); 720 completion->signal();
710 return; 721 return;
711 } 722 }
712 723
724 m_layerTreeHostImpl->resourceProvider()->setOffscreenContextProvider(offscre enContextProvider);
725
713 if (m_layerTreeHost->contentsTextureManager()->linkedEvictedBackingsExist()) { 726 if (m_layerTreeHost->contentsTextureManager()->linkedEvictedBackingsExist()) {
714 // Clear any uploads we were making to textures linked to evicted 727 // Clear any uploads we were making to textures linked to evicted
715 // resources 728 // resources
716 queue->clearUploadsToEvictedResources(); 729 queue->clearUploadsToEvictedResources();
717 // Some textures in the layer tree are invalid. Kick off another commit 730 // Some textures in the layer tree are invalid. Kick off another commit
718 // to fill them again. 731 // to fill them again.
719 setNeedsCommitOnImplThread(); 732 setNeedsCommitOnImplThread();
720 } 733 }
721 734
722 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings() ; 735 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings() ;
723 736
724 m_currentResourceUpdateControllerOnImplThread = ResourceUpdateController::cr eate(this, Proxy::implThread(), queue.Pass(), m_layerTreeHostImpl->resourceProvi der(), hasImplThread()); 737 m_currentResourceUpdateControllerOnImplThread = ResourceUpdateController::cr eate(this, Proxy::implThread(), queue.Pass(), m_layerTreeHostImpl->resourceProvi der());
725 m_currentResourceUpdateControllerOnImplThread->performMoreUpdates( 738 m_currentResourceUpdateControllerOnImplThread->performMoreUpdates(
726 m_schedulerOnImplThread->anticipatedDrawTime()); 739 m_schedulerOnImplThread->anticipatedDrawTime());
727 740
728 m_commitCompletionEventOnImplThread = completion; 741 m_commitCompletionEventOnImplThread = completion;
729 } 742 }
730 743
731 void ThreadProxy::beginFrameAbortedOnImplThread() 744 void ThreadProxy::beginFrameAbortedOnImplThread()
732 { 745 {
733 TRACE_EVENT0("cc", "ThreadProxy::beginFrameAbortedOnImplThread"); 746 TRACE_EVENT0("cc", "ThreadProxy::beginFrameAbortedOnImplThread");
734 DCHECK(isImplThread()); 747 DCHECK(isImplThread());
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 { 1065 {
1053 DCHECK(isImplThread()); 1066 DCHECK(isImplThread());
1054 m_layerTreeHostImpl->setFullRootLayerDamage(); 1067 m_layerTreeHostImpl->setFullRootLayerDamage();
1055 } 1068 }
1056 1069
1057 size_t ThreadProxy::maxPartialTextureUpdates() const 1070 size_t ThreadProxy::maxPartialTextureUpdates() const
1058 { 1071 {
1059 return ResourceUpdateController::maxPartialTextureUpdates(); 1072 return ResourceUpdateController::maxPartialTextureUpdates();
1060 } 1073 }
1061 1074
1062 void ThreadProxy::recreateOutputSurfaceOnImplThread(CompletionEvent* completion, scoped_ptr<OutputSurface> outputSurface, bool* recreateSucceeded, RendererCapab ilities* capabilities) 1075 void ThreadProxy::recreateOutputSurfaceOnImplThread(CompletionEvent* completion, scoped_ptr<OutputSurface> outputSurface, scoped_refptr<cc::ContextProvider> off screenContextProvider, bool* recreateSucceeded, RendererCapabilities* capabiliti es)
1063 { 1076 {
1064 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurfaceOnImplThread"); 1077 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurfaceOnImplThread");
1065 DCHECK(isImplThread()); 1078 DCHECK(isImplThread());
1066 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->res ourceProvider()); 1079 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->res ourceProvider());
1067 *recreateSucceeded = m_layerTreeHostImpl->initializeRenderer(outputSurface.P ass()); 1080 *recreateSucceeded = m_layerTreeHostImpl->initializeRenderer(outputSurface.P ass());
1068 if (*recreateSucceeded) { 1081 if (*recreateSucceeded) {
1069 *capabilities = m_layerTreeHostImpl->rendererCapabilities(); 1082 *capabilities = m_layerTreeHostImpl->rendererCapabilities();
1083 m_layerTreeHostImpl->resourceProvider()->setOffscreenContextProvider(off screenContextProvider);
1070 m_schedulerOnImplThread->didRecreateOutputSurface(); 1084 m_schedulerOnImplThread->didRecreateOutputSurface();
1085 } else if (offscreenContextProvider) {
1086 offscreenContextProvider->VerifyContexts();
1071 } 1087 }
1072 completion->signal(); 1088 completion->signal();
1073 } 1089 }
1074 1090
1075 void ThreadProxy::renderingStatsOnImplThread(CompletionEvent* completion, Render ingStats* stats) 1091 void ThreadProxy::renderingStatsOnImplThread(CompletionEvent* completion, Render ingStats* stats)
1076 { 1092 {
1077 DCHECK(isImplThread()); 1093 DCHECK(isImplThread());
1078 m_layerTreeHostImpl->renderingStats(stats); 1094 m_layerTreeHostImpl->renderingStats(stats);
1079 completion->signal(); 1095 completion->signal();
1080 } 1096 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 1228
1213 void ThreadProxy::renewTreePriorityOnImplThread() 1229 void ThreadProxy::renewTreePriorityOnImplThread()
1214 { 1230 {
1215 DCHECK(m_renewTreePriorityOnImplThreadPending); 1231 DCHECK(m_renewTreePriorityOnImplThreadPending);
1216 m_renewTreePriorityOnImplThreadPending = false; 1232 m_renewTreePriorityOnImplThreadPending = false;
1217 1233
1218 renewTreePriority(); 1234 renewTreePriority();
1219 } 1235 }
1220 1236
1221 } // namespace cc 1237 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698