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

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: 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" 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
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_layerTreeHost->needsOffscreenContext()) {
232 offscreenContext3d = m_layerTreeHost->client()->createOrGetOffscreenContex t3dForCompositorThread();
233 if (!offscreenContext3d ||
234 !offscreenContext3d->makeContextCurrent() ||
235 offscreenContext3d->getGraphicsResetStatusARB())
236 {
233 return false; 237 return false;
238 }
239 offscreenGrContext = m_layerTreeHost->client()->createOrGetOffscreenGrCo ntextForCompositorThread();
240 }
234 241
235 // Make a blocking call to recreateOutputSurfaceOnImplThread. The results of that 242 // Make a blocking call to recreateOutputSurfaceOnImplThread. The results of that
236 // call are pushed into the recreateSucceeded and capabilities local 243 // call are pushed into the recreateSucceeded and capabilities local
237 // variables. 244 // variables.
238 CompletionEvent completion; 245 CompletionEvent completion;
239 bool recreateSucceeded = false; 246 bool recreateSucceeded = false;
240 RendererCapabilities capabilities; 247 RendererCapabilities capabilities;
241 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); 248 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
242 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::recreateOutputSurface OnImplThread, 249 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::recreateOutputSurface OnImplThread,
243 m_implThreadWeakPtr, 250 m_implThreadWeakPtr,
244 &completion, 251 &completion,
245 base::Passed(&outputSurface), 252 base::Passed(&outputSurface),
253 offscreenContext3d,
254 offscreenGrContext,
246 &recreateSucceeded, 255 &recreateSucceeded,
247 &capabilities)); 256 &capabilities));
248 completion.wait(); 257 completion.wait();
249 258
250 if (recreateSucceeded) 259 if (recreateSucceeded)
251 m_RendererCapabilitiesMainThreadCopy = capabilities; 260 m_RendererCapabilitiesMainThreadCopy = capabilities;
252 return recreateSucceeded; 261 return recreateSucceeded;
253 } 262 }
254 263
255 void ThreadProxy::renderingStats(RenderingStats* stats) 264 void ThreadProxy::renderingStats(RenderingStats* stats)
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 if (!m_layerTreeHost) 591 if (!m_layerTreeHost)
583 return; 592 return;
584 593
585 if (m_deferCommits) { 594 if (m_deferCommits) {
586 m_pendingDeferredCommit = beginFrameState.Pass(); 595 m_pendingDeferredCommit = beginFrameState.Pass();
587 m_layerTreeHost->didDeferCommit(); 596 m_layerTreeHost->didDeferCommit();
588 TRACE_EVENT0("cc", "EarlyOut_DeferCommits"); 597 TRACE_EVENT0("cc", "EarlyOut_DeferCommits");
589 return; 598 return;
590 } 599 }
591 600
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 601 // Do not notify the impl thread of commit requests that occur during
596 // the apply/animate/layout part of the beginFrameAndCommit process since 602 // the apply/animate/layout part of the beginFrameAndCommit process since
597 // those commit requests will get painted immediately. Once we have done 603 // 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 604 // the paint, m_commitRequested will be set to false to allow new commit
599 // requests to be scheduled. 605 // requests to be scheduled.
600 m_commitRequested = true; 606 m_commitRequested = true;
601 m_commitRequestSentToImplThread = true; 607 m_commitRequestSentToImplThread = true;
602 608
603 // On the other hand, the animationRequested flag needs to be cleared 609 // On the other hand, the animationRequested flag needs to be cleared
604 // here so that any animation requests generated by the apply or animate 610 // here so that any animation requests generated by the apply or animate
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 // false. If it is true now, it means setNeedAnimate was called again, but 660 // false. If it is true now, it means setNeedAnimate was called again, but
655 // during a state when m_commitRequestSentToImplThread = true. We need to 661 // 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 662 // force that call to happen again now so that the commit request is sent to
657 // the impl thread. 663 // the impl thread.
658 if (m_animateRequested) { 664 if (m_animateRequested) {
659 // Forces setNeedsAnimate to consider posting a commit task. 665 // Forces setNeedsAnimate to consider posting a commit task.
660 m_animateRequested = false; 666 m_animateRequested = false;
661 setNeedsAnimate(); 667 setNeedsAnimate();
662 } 668 }
663 669
670 WebKit::WebGraphicsContext3D* offscreenContext3d = NULL;
671 GrContext* offscreenGrContext = NULL;
672 if (m_layerTreeHost->needsOffscreenContext()) {
673 offscreenContext3d = m_layerTreeHost->client()->createOrGetOffscreenCont ext3dForCompositorThread();
674 offscreenGrContext = m_layerTreeHost->client()->createOrGetOffscreenGrCo ntextForCompositorThread();
675 }
676
664 // Notify the impl thread that the beginFrame has completed. This will 677 // Notify the impl thread that the beginFrame has completed. This will
665 // begin the commit process, which is blocking from the main thread's 678 // begin the commit process, which is blocking from the main thread's
666 // point of view, but asynchronously performed on the impl thread, 679 // point of view, but asynchronously performed on the impl thread,
667 // coordinated by the Scheduler. 680 // coordinated by the Scheduler.
668 { 681 {
669 TRACE_EVENT0("cc", "commit"); 682 TRACE_EVENT0("cc", "commit");
670 683
671 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); 684 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
672 685
673 base::TimeTicks startTime = base::TimeTicks::HighResNow(); 686 base::TimeTicks startTime = base::TimeTicks::HighResNow();
674 CompletionEvent completion; 687 CompletionEvent completion;
675 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::beginFrameComplet eOnImplThread, m_implThreadWeakPtr, &completion, queue.release())); 688 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::beginFrameComplet eOnImplThread, m_implThreadWeakPtr, &completion, queue.release(), offscreenConte xt3d, offscreenGrContext));
676 completion.wait(); 689 completion.wait();
677 base::TimeTicks endTime = base::TimeTicks::HighResNow(); 690 base::TimeTicks endTime = base::TimeTicks::HighResNow();
678 691
679 m_totalCommitTime += endTime - startTime; 692 m_totalCommitTime += endTime - startTime;
680 m_totalCommitCount++; 693 m_totalCommitCount++;
681 } 694 }
682 695
683 m_layerTreeHost->commitComplete(); 696 m_layerTreeHost->commitComplete();
684 m_layerTreeHost->didBeginFrame(); 697 m_layerTreeHost->didBeginFrame();
685 } 698 }
686 699
687 void ThreadProxy::beginFrameCompleteOnImplThread(CompletionEvent* completion, Re sourceUpdateQueue* rawQueue) 700 void ThreadProxy::beginFrameCompleteOnImplThread(CompletionEvent* completion, Re sourceUpdateQueue* rawQueue, WebKit::WebGraphicsContext3D* offscreenContext3d, G rContext* offscreenGrContext)
688 { 701 {
689 scoped_ptr<ResourceUpdateQueue> queue(rawQueue); 702 scoped_ptr<ResourceUpdateQueue> queue(rawQueue);
690 703
691 TRACE_EVENT0("cc", "ThreadProxy::beginFrameCompleteOnImplThread"); 704 TRACE_EVENT0("cc", "ThreadProxy::beginFrameCompleteOnImplThread");
692 DCHECK(!m_commitCompletionEventOnImplThread); 705 DCHECK(!m_commitCompletionEventOnImplThread);
693 DCHECK(isImplThread() && isMainThreadBlocked()); 706 DCHECK(isImplThread() && isMainThreadBlocked());
694 DCHECK(m_schedulerOnImplThread); 707 DCHECK(m_schedulerOnImplThread);
695 DCHECK(m_schedulerOnImplThread->commitPending()); 708 DCHECK(m_schedulerOnImplThread->commitPending());
696 709
697 if (!m_layerTreeHostImpl.get()) { 710 if (!m_layerTreeHostImpl.get()) {
698 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree"); 711 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree");
699 completion->signal(); 712 completion->signal();
700 return; 713 return;
701 } 714 }
702 715
716 m_layerTreeHostImpl->resourceProvider()->setOffscreenContexts(
717 offscreenContext3d,
718 offscreenGrContext);
719
703 if (m_layerTreeHost->contentsTextureManager()->linkedEvictedBackingsExist()) { 720 if (m_layerTreeHost->contentsTextureManager()->linkedEvictedBackingsExist()) {
704 // Clear any uploads we were making to textures linked to evicted 721 // Clear any uploads we were making to textures linked to evicted
705 // resources 722 // resources
706 queue->clearUploadsToEvictedResources(); 723 queue->clearUploadsToEvictedResources();
707 // Some textures in the layer tree are invalid. Kick off another commit 724 // Some textures in the layer tree are invalid. Kick off another commit
708 // to fill them again. 725 // to fill them again.
709 setNeedsCommitOnImplThread(); 726 setNeedsCommitOnImplThread();
710 } 727 }
711 728
712 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings() ; 729 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings() ;
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 { 1055 {
1039 DCHECK(isImplThread()); 1056 DCHECK(isImplThread());
1040 m_layerTreeHostImpl->setFullRootLayerDamage(); 1057 m_layerTreeHostImpl->setFullRootLayerDamage();
1041 } 1058 }
1042 1059
1043 size_t ThreadProxy::maxPartialTextureUpdates() const 1060 size_t ThreadProxy::maxPartialTextureUpdates() const
1044 { 1061 {
1045 return ResourceUpdateController::maxPartialTextureUpdates(); 1062 return ResourceUpdateController::maxPartialTextureUpdates();
1046 } 1063 }
1047 1064
1048 void ThreadProxy::recreateOutputSurfaceOnImplThread(CompletionEvent* completion, scoped_ptr<OutputSurface> outputSurface, bool* recreateSucceeded, RendererCapab ilities* capabilities) 1065 void ThreadProxy::recreateOutputSurfaceOnImplThread(CompletionEvent* completion, scoped_ptr<OutputSurface> outputSurface, WebKit::WebGraphicsContext3D* offscree nContext3d, GrContext* offscreenGrContext, bool* recreateSucceeded, RendererCapa bilities* capabilities)
1049 { 1066 {
1050 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurfaceOnImplThread"); 1067 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurfaceOnImplThread");
1051 DCHECK(isImplThread()); 1068 DCHECK(isImplThread());
1052 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->res ourceProvider()); 1069 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->res ourceProvider());
1053 *recreateSucceeded = m_layerTreeHostImpl->initializeRenderer(outputSurface.P ass()); 1070 *recreateSucceeded = m_layerTreeHostImpl->initializeRenderer(outputSurface.P ass());
1054 if (*recreateSucceeded) { 1071 if (*recreateSucceeded) {
1055 *capabilities = m_layerTreeHostImpl->rendererCapabilities(); 1072 *capabilities = m_layerTreeHostImpl->rendererCapabilities();
1056 m_schedulerOnImplThread->didRecreateOutputSurface(); 1073 m_schedulerOnImplThread->didRecreateOutputSurface();
1074 m_layerTreeHostImpl->resourceProvider()->setOffscreenContexts(
1075 offscreenContext3d,
1076 offscreenGrContext);
1057 } 1077 }
1058 completion->signal(); 1078 completion->signal();
1059 } 1079 }
1060 1080
1061 void ThreadProxy::renderingStatsOnImplThread(CompletionEvent* completion, Render ingStats* stats) 1081 void ThreadProxy::renderingStatsOnImplThread(CompletionEvent* completion, Render ingStats* stats)
1062 { 1082 {
1063 DCHECK(isImplThread()); 1083 DCHECK(isImplThread());
1064 m_layerTreeHostImpl->renderingStats(stats); 1084 m_layerTreeHostImpl->renderingStats(stats);
1065 completion->signal(); 1085 completion->signal();
1066 } 1086 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 1194
1175 void ThreadProxy::renewTreePriorityOnImplThread() 1195 void ThreadProxy::renewTreePriorityOnImplThread()
1176 { 1196 {
1177 DCHECK(m_renewTreePriorityOnImplThreadPending); 1197 DCHECK(m_renewTreePriorityOnImplThreadPending);
1178 m_renewTreePriorityOnImplThreadPending = false; 1198 m_renewTreePriorityOnImplThreadPending = false;
1179 1199
1180 renewTreePriority(); 1200 renewTreePriority();
1181 } 1201 }
1182 1202
1183 } // namespace cc 1203 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698