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

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: Restart with GrContext owned in cc 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
227 // Try to create the surface. 224 // Try to create the surface.
228 scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurfa ce(); 225 scoped_ptr<OutputSurface> outputSurface = m_layerTreeHost->createOutputSurfa ce();
229 if (!outputSurface.get()) 226 if (!outputSurface.get())
230 return false; 227 return false;
231 if (m_layerTreeHost->needsSharedContext()) 228 WebKit::WebGraphicsContext3D* offscreenContext3d = NULL;
232 if (!WebSharedGraphicsContext3D::createCompositorThreadContext()) 229 if (m_RendererCapabilitiesMainThreadCopy.usingOffscreenContext3d && m_layerT reeHost->needsOffscreenContext()) {
230 offscreenContext3d = m_layerTreeHost->client()->OffscreenContext3dForCom positorThread();
231 if (!offscreenContext3d)
233 return false; 232 return false;
233 }
234 234
235 // Make a blocking call to recreateOutputSurfaceOnImplThread. The results of that 235 // Make a blocking call to recreateOutputSurfaceOnImplThread. The results of that
236 // call are pushed into the recreateSucceeded and capabilities local 236 // call are pushed into the recreateSucceeded and capabilities local
237 // variables. 237 // variables.
238 CompletionEvent completion; 238 CompletionEvent completion;
239 bool recreateSucceeded = false; 239 bool recreateSucceeded = false;
240 RendererCapabilities capabilities; 240 RendererCapabilities capabilities;
241 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); 241 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
242 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::recreateOutputSurface OnImplThread, 242 Proxy::implThread()->postTask(base::Bind(&ThreadProxy::recreateOutputSurface OnImplThread,
243 m_implThreadWeakPtr, 243 m_implThreadWeakPtr,
244 &completion, 244 &completion,
245 base::Passed(&outputSurface), 245 base::Passed(&outputSurface),
246 offscreenContext3d,
246 &recreateSucceeded, 247 &recreateSucceeded,
247 &capabilities)); 248 &capabilities));
248 completion.wait(); 249 completion.wait();
249 250
250 if (recreateSucceeded) 251 if (recreateSucceeded)
251 m_RendererCapabilitiesMainThreadCopy = capabilities; 252 m_RendererCapabilitiesMainThreadCopy = capabilities;
252 return recreateSucceeded; 253 return recreateSucceeded;
253 } 254 }
254 255
255 void ThreadProxy::renderingStats(RenderingStats* stats) 256 void ThreadProxy::renderingStats(RenderingStats* stats)
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 if (!m_layerTreeHost) 593 if (!m_layerTreeHost)
593 return; 594 return;
594 595
595 if (m_deferCommits) { 596 if (m_deferCommits) {
596 m_pendingDeferredCommit = beginFrameState.Pass(); 597 m_pendingDeferredCommit = beginFrameState.Pass();
597 m_layerTreeHost->didDeferCommit(); 598 m_layerTreeHost->didDeferCommit();
598 TRACE_EVENT0("cc", "EarlyOut_DeferCommits"); 599 TRACE_EVENT0("cc", "EarlyOut_DeferCommits");
599 return; 600 return;
600 } 601 }
601 602
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 603 // Do not notify the impl thread of commit requests that occur during
606 // the apply/animate/layout part of the beginFrameAndCommit process since 604 // the apply/animate/layout part of the beginFrameAndCommit process since
607 // those commit requests will get painted immediately. Once we have done 605 // 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 606 // the paint, m_commitRequested will be set to false to allow new commit
609 // requests to be scheduled. 607 // requests to be scheduled.
610 m_commitRequested = true; 608 m_commitRequested = true;
611 m_commitRequestSentToImplThread = true; 609 m_commitRequestSentToImplThread = true;
612 610
613 // On the other hand, the animationRequested flag needs to be cleared 611 // On the other hand, the animationRequested flag needs to be cleared
614 // here so that any animation requests generated by the apply or animate 612 // 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 662 // false. If it is true now, it means setNeedAnimate was called again, but
665 // during a state when m_commitRequestSentToImplThread = true. We need to 663 // 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 664 // force that call to happen again now so that the commit request is sent to
667 // the impl thread. 665 // the impl thread.
668 if (m_animateRequested) { 666 if (m_animateRequested) {
669 // Forces setNeedsAnimate to consider posting a commit task. 667 // Forces setNeedsAnimate to consider posting a commit task.
670 m_animateRequested = false; 668 m_animateRequested = false;
671 setNeedsAnimate(); 669 setNeedsAnimate();
672 } 670 }
673 671
672 WebKit::WebGraphicsContext3D* offscreenContext3d = NULL;
673 if (m_RendererCapabilitiesMainThreadCopy.usingOffscreenContext3d && m_layerT reeHost->needsOffscreenContext()) {
674 offscreenContext3d = m_layerTreeHost->client()->OffscreenContext3dForCom positorThread();
675 }
676
674 // Notify the impl thread that the beginFrame has completed. This will 677 // Notify the impl thread that the beginFrame has completed. This will
675 // 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
676 // point of view, but asynchronously performed on the impl thread, 679 // point of view, but asynchronously performed on the impl thread,
677 // coordinated by the Scheduler. 680 // coordinated by the Scheduler.
678 { 681 {
679 TRACE_EVENT0("cc", "commit"); 682 TRACE_EVENT0("cc", "commit");
680 683
681 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); 684 DebugScopedSetMainThreadBlocked mainThreadBlocked(this);
682 685
683 base::TimeTicks startTime = base::TimeTicks::HighResNow(); 686 base::TimeTicks startTime = base::TimeTicks::HighResNow();
684 CompletionEvent completion; 687 CompletionEvent completion;
685 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));
686 completion.wait(); 689 completion.wait();
687 base::TimeTicks endTime = base::TimeTicks::HighResNow(); 690 base::TimeTicks endTime = base::TimeTicks::HighResNow();
688 691
689 m_totalCommitTime += endTime - startTime; 692 m_totalCommitTime += endTime - startTime;
690 m_totalCommitCount++; 693 m_totalCommitCount++;
691 } 694 }
692 695
693 m_layerTreeHost->commitComplete(); 696 m_layerTreeHost->commitComplete();
694 m_layerTreeHost->didBeginFrame(); 697 m_layerTreeHost->didBeginFrame();
695 } 698 }
696 699
697 void ThreadProxy::beginFrameCompleteOnImplThread(CompletionEvent* completion, Re sourceUpdateQueue* rawQueue) 700 void ThreadProxy::beginFrameCompleteOnImplThread(CompletionEvent* completion, Re sourceUpdateQueue* rawQueue, WebKit::WebGraphicsContext3D* offscreenContext3d)
698 { 701 {
699 scoped_ptr<ResourceUpdateQueue> queue(rawQueue); 702 scoped_ptr<ResourceUpdateQueue> queue(rawQueue);
700 703
701 TRACE_EVENT0("cc", "ThreadProxy::beginFrameCompleteOnImplThread"); 704 TRACE_EVENT0("cc", "ThreadProxy::beginFrameCompleteOnImplThread");
702 DCHECK(!m_commitCompletionEventOnImplThread); 705 DCHECK(!m_commitCompletionEventOnImplThread);
703 DCHECK(isImplThread() && isMainThreadBlocked()); 706 DCHECK(isImplThread() && isMainThreadBlocked());
704 DCHECK(m_schedulerOnImplThread); 707 DCHECK(m_schedulerOnImplThread);
705 DCHECK(m_schedulerOnImplThread->commitPending()); 708 DCHECK(m_schedulerOnImplThread->commitPending());
706 709
707 if (!m_layerTreeHostImpl.get()) { 710 if (!m_layerTreeHostImpl.get()) {
708 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree"); 711 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree");
709 completion->signal(); 712 completion->signal();
710 return; 713 return;
711 } 714 }
712 715
716 m_layerTreeHostImpl->resourceProvider()->setContext3dForGrContext(offscreenC ontext3d);
717
713 if (m_layerTreeHost->contentsTextureManager()->linkedEvictedBackingsExist()) { 718 if (m_layerTreeHost->contentsTextureManager()->linkedEvictedBackingsExist()) {
714 // Clear any uploads we were making to textures linked to evicted 719 // Clear any uploads we were making to textures linked to evicted
715 // resources 720 // resources
716 queue->clearUploadsToEvictedResources(); 721 queue->clearUploadsToEvictedResources();
717 // Some textures in the layer tree are invalid. Kick off another commit 722 // Some textures in the layer tree are invalid. Kick off another commit
718 // to fill them again. 723 // to fill them again.
719 setNeedsCommitOnImplThread(); 724 setNeedsCommitOnImplThread();
720 } 725 }
721 726
722 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings() ; 727 m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings() ;
723 728
724 m_currentResourceUpdateControllerOnImplThread = ResourceUpdateController::cr eate(this, Proxy::implThread(), queue.Pass(), m_layerTreeHostImpl->resourceProvi der(), hasImplThread()); 729 m_currentResourceUpdateControllerOnImplThread = ResourceUpdateController::cr eate(this, Proxy::implThread(), queue.Pass(), m_layerTreeHostImpl->resourceProvi der());
725 m_currentResourceUpdateControllerOnImplThread->performMoreUpdates( 730 m_currentResourceUpdateControllerOnImplThread->performMoreUpdates(
726 m_schedulerOnImplThread->anticipatedDrawTime()); 731 m_schedulerOnImplThread->anticipatedDrawTime());
727 732
728 m_commitCompletionEventOnImplThread = completion; 733 m_commitCompletionEventOnImplThread = completion;
729 } 734 }
730 735
731 void ThreadProxy::beginFrameAbortedOnImplThread() 736 void ThreadProxy::beginFrameAbortedOnImplThread()
732 { 737 {
733 TRACE_EVENT0("cc", "ThreadProxy::beginFrameAbortedOnImplThread"); 738 TRACE_EVENT0("cc", "ThreadProxy::beginFrameAbortedOnImplThread");
734 DCHECK(isImplThread()); 739 DCHECK(isImplThread());
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 { 1057 {
1053 DCHECK(isImplThread()); 1058 DCHECK(isImplThread());
1054 m_layerTreeHostImpl->setFullRootLayerDamage(); 1059 m_layerTreeHostImpl->setFullRootLayerDamage();
1055 } 1060 }
1056 1061
1057 size_t ThreadProxy::maxPartialTextureUpdates() const 1062 size_t ThreadProxy::maxPartialTextureUpdates() const
1058 { 1063 {
1059 return ResourceUpdateController::maxPartialTextureUpdates(); 1064 return ResourceUpdateController::maxPartialTextureUpdates();
1060 } 1065 }
1061 1066
1062 void ThreadProxy::recreateOutputSurfaceOnImplThread(CompletionEvent* completion, scoped_ptr<OutputSurface> outputSurface, bool* recreateSucceeded, RendererCapab ilities* capabilities) 1067 void ThreadProxy::recreateOutputSurfaceOnImplThread(CompletionEvent* completion, scoped_ptr<OutputSurface> outputSurface, WebKit::WebGraphicsContext3D* offscree nContext3d, bool* recreateSucceeded, RendererCapabilities* capabilities)
1063 { 1068 {
1064 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurfaceOnImplThread"); 1069 TRACE_EVENT0("cc", "ThreadProxy::recreateOutputSurfaceOnImplThread");
1065 DCHECK(isImplThread()); 1070 DCHECK(isImplThread());
1066 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->res ourceProvider()); 1071 m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->res ourceProvider());
1067 *recreateSucceeded = m_layerTreeHostImpl->initializeRenderer(outputSurface.P ass()); 1072 *recreateSucceeded = m_layerTreeHostImpl->initializeRenderer(outputSurface.P ass());
1068 if (*recreateSucceeded) { 1073 if (*recreateSucceeded) {
1069 *capabilities = m_layerTreeHostImpl->rendererCapabilities(); 1074 *capabilities = m_layerTreeHostImpl->rendererCapabilities();
1075 m_layerTreeHostImpl->resourceProvider()->setContext3dForGrContext(offscr eenContext3d);
1070 m_schedulerOnImplThread->didRecreateOutputSurface(); 1076 m_schedulerOnImplThread->didRecreateOutputSurface();
1071 } 1077 }
1072 completion->signal(); 1078 completion->signal();
1073 } 1079 }
1074 1080
1075 void ThreadProxy::renderingStatsOnImplThread(CompletionEvent* completion, Render ingStats* stats) 1081 void ThreadProxy::renderingStatsOnImplThread(CompletionEvent* completion, Render ingStats* stats)
1076 { 1082 {
1077 DCHECK(isImplThread()); 1083 DCHECK(isImplThread());
1078 m_layerTreeHostImpl->renderingStats(stats); 1084 m_layerTreeHostImpl->renderingStats(stats);
1079 completion->signal(); 1085 completion->signal();
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 1194
1189 void ThreadProxy::renewTreePriorityOnImplThread() 1195 void ThreadProxy::renewTreePriorityOnImplThread()
1190 { 1196 {
1191 DCHECK(m_renewTreePriorityOnImplThreadPending); 1197 DCHECK(m_renewTreePriorityOnImplThreadPending);
1192 m_renewTreePriorityOnImplThreadPending = false; 1198 m_renewTreePriorityOnImplThreadPending = false;
1193 1199
1194 renewTreePriority(); 1200 renewTreePriority();
1195 } 1201 }
1196 1202
1197 } // namespace cc 1203 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698