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

Side by Side Diff: cc/thread_proxy.cc

Issue 11348083: Revert 168095 - Merge 167537 - Use message passing for BeginFrameAndCommitState and clean up forced… (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1312/src/
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « cc/thread_proxy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "config.h" 5 #include "config.h"
6 6
7 #include "cc/thread_proxy.h" 7 #include "cc/thread_proxy.h"
8 8
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"
(...skipping 20 matching lines...) Expand all
31 31
32 scoped_ptr<Proxy> ThreadProxy::create(LayerTreeHost* layerTreeHost) 32 scoped_ptr<Proxy> ThreadProxy::create(LayerTreeHost* layerTreeHost)
33 { 33 {
34 return make_scoped_ptr(new ThreadProxy(layerTreeHost)).PassAs<Proxy>(); 34 return make_scoped_ptr(new ThreadProxy(layerTreeHost)).PassAs<Proxy>();
35 } 35 }
36 36
37 ThreadProxy::ThreadProxy(LayerTreeHost* layerTreeHost) 37 ThreadProxy::ThreadProxy(LayerTreeHost* layerTreeHost)
38 : m_animateRequested(false) 38 : m_animateRequested(false)
39 , m_commitRequested(false) 39 , m_commitRequested(false)
40 , m_commitRequestSentToImplThread(false) 40 , m_commitRequestSentToImplThread(false)
41 , m_forcedCommitRequested(false)
41 , m_layerTreeHost(layerTreeHost) 42 , m_layerTreeHost(layerTreeHost)
42 , m_rendererInitialized(false) 43 , m_rendererInitialized(false)
43 , m_started(false) 44 , m_started(false)
44 , m_texturesAcquired(true) 45 , m_texturesAcquired(true)
45 , m_inCompositeAndReadback(false) 46 , m_inCompositeAndReadback(false)
46 , m_mainThreadProxy(ScopedThreadProxy::create(Proxy::mainThread())) 47 , m_mainThreadProxy(ScopedThreadProxy::create(Proxy::mainThread()))
47 , m_beginFrameCompletionEventOnImplThread(0) 48 , m_beginFrameCompletionEventOnImplThread(0)
48 , m_readbackRequestOnImplThread(0) 49 , m_readbackRequestOnImplThread(0)
49 , m_commitCompletionEventOnImplThread(0) 50 , m_commitCompletionEventOnImplThread(0)
50 , m_textureAcquisitionCompletionEventOnImplThread(0) 51 , m_textureAcquisitionCompletionEventOnImplThread(0)
51 , m_nextFrameIsNewlyCommittedFrameOnImplThread(false) 52 , m_nextFrameIsNewlyCommittedFrameOnImplThread(false)
52 , m_renderVSyncEnabled(layerTreeHost->settings().renderVSyncEnabled) 53 , m_renderVSyncEnabled(layerTreeHost->settings().renderVSyncEnabled)
53 , m_totalCommitCount(0) 54 , m_totalCommitCount(0)
54 , m_deferCommits(false) 55 , m_deferCommits(false)
56 , m_deferredCommitPending(false)
55 { 57 {
56 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); 58 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy");
57 DCHECK(isMainThread()); 59 DCHECK(isMainThread());
58 } 60 }
59 61
60 ThreadProxy::~ThreadProxy() 62 ThreadProxy::~ThreadProxy()
61 { 63 {
62 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); 64 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy");
63 DCHECK(isMainThread()); 65 DCHECK(isMainThread());
64 DCHECK(!m_started); 66 DCHECK(!m_started);
65 } 67 }
66 68
67 bool ThreadProxy::compositeAndReadback(void *pixels, const IntRect& rect) 69 bool ThreadProxy::compositeAndReadback(void *pixels, const IntRect& rect)
68 { 70 {
69 TRACE_EVENT0("cc", "ThreadProxy::compositeAndReadback"); 71 TRACE_EVENT0("cc", "ThreadPRoxy::compositeAndReadback");
70 DCHECK(isMainThread()); 72 DCHECK(isMainThread());
71 DCHECK(m_layerTreeHost); 73 DCHECK(m_layerTreeHost);
72 DCHECK(!m_deferCommits); 74 DCHECK(!m_deferCommits);
73 75
74 if (!m_layerTreeHost->initializeRendererIfNeeded()) { 76 if (!m_layerTreeHost->initializeRendererIfNeeded()) {
75 TRACE_EVENT0("cc", "compositeAndReadback_EarlyOut_LR_Uninitialized"); 77 TRACE_EVENT0("cc", "compositeAndReadback_EarlyOut_LR_Uninitialized");
76 return false; 78 return false;
77 } 79 }
78 80
79 81
80 // Perform a synchronous commit. 82 // Perform a synchronous commit.
81 { 83 {
82 DebugScopedSetMainThreadBlocked mainThreadBlocked; 84 DebugScopedSetMainThreadBlocked mainThreadBlocked;
83 CompletionEvent beginFrameCompletion; 85 CompletionEvent beginFrameCompletion;
84 Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::force BeginFrameOnImplThread, &beginFrameCompletion)); 86 Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::force BeginFrameOnImplThread, &beginFrameCompletion));
85 beginFrameCompletion.wait(); 87 beginFrameCompletion.wait();
86 } 88 }
87 m_inCompositeAndReadback = true; 89 m_inCompositeAndReadback = true;
88 beginFrame(NULL); 90 beginFrame();
89 m_inCompositeAndReadback = false; 91 m_inCompositeAndReadback = false;
90 92
91 // Perform a synchronous readback. 93 // Perform a synchronous readback.
92 ReadbackRequest request; 94 ReadbackRequest request;
93 request.rect = rect; 95 request.rect = rect;
94 request.pixels = pixels; 96 request.pixels = pixels;
95 { 97 {
96 DebugScopedSetMainThreadBlocked mainThreadBlocked; 98 DebugScopedSetMainThreadBlocked mainThreadBlocked;
97 Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::reque stReadbackOnImplThread, &request)); 99 Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::reque stReadbackOnImplThread, &request));
98 request.completion.wait(); 100 request.completion.wait();
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 { 331 {
330 DCHECK(isImplThread()); 332 DCHECK(isImplThread());
331 TRACE_EVENT0("cc", "ThreadProxy::setNeedsCommitOnImplThread"); 333 TRACE_EVENT0("cc", "ThreadProxy::setNeedsCommitOnImplThread");
332 m_schedulerOnImplThread->setNeedsCommit(); 334 m_schedulerOnImplThread->setNeedsCommit();
333 } 335 }
334 336
335 void ThreadProxy::setNeedsForcedCommitOnImplThread() 337 void ThreadProxy::setNeedsForcedCommitOnImplThread()
336 { 338 {
337 DCHECK(isImplThread()); 339 DCHECK(isImplThread());
338 TRACE_EVENT0("cc", "ThreadProxy::setNeedsForcedCommitOnImplThread"); 340 TRACE_EVENT0("cc", "ThreadProxy::setNeedsForcedCommitOnImplThread");
341 m_schedulerOnImplThread->setNeedsCommit();
339 m_schedulerOnImplThread->setNeedsForcedCommit(); 342 m_schedulerOnImplThread->setNeedsForcedCommit();
340 } 343 }
341 344
342 void ThreadProxy::postAnimationEventsToMainThreadOnImplThread(scoped_ptr<Animati onEventsVector> events, base::Time wallClockTime) 345 void ThreadProxy::postAnimationEventsToMainThreadOnImplThread(scoped_ptr<Animati onEventsVector> events, base::Time wallClockTime)
343 { 346 {
344 DCHECK(isImplThread()); 347 DCHECK(isImplThread());
345 TRACE_EVENT0("cc", "ThreadProxy::postAnimationEventsToMainThreadOnImplThread "); 348 TRACE_EVENT0("cc", "ThreadProxy::postAnimationEventsToMainThreadOnImplThread ");
346 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadProxy::setAnimatio nEvents, events.release(), wallClockTime)); 349 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadProxy::setAnimatio nEvents, events.release(), wallClockTime));
347 } 350 }
348 351
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 { 397 {
395 DCHECK(isMainThread()); 398 DCHECK(isMainThread());
396 DCHECK_NE(m_deferCommits, deferCommits); 399 DCHECK_NE(m_deferCommits, deferCommits);
397 m_deferCommits = deferCommits; 400 m_deferCommits = deferCommits;
398 401
399 if (m_deferCommits) 402 if (m_deferCommits)
400 TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::setDeferCommits", this); 403 TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::setDeferCommits", this);
401 else 404 else
402 TRACE_EVENT_ASYNC_END0("cc", "ThreadProxy::setDeferCommits", this); 405 TRACE_EVENT_ASYNC_END0("cc", "ThreadProxy::setDeferCommits", this);
403 406
404 if (!m_deferCommits && m_pendingDeferredCommit) 407 if (!m_deferCommits && m_deferredCommitPending) {
405 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadProxy::beginFr ame, m_pendingDeferredCommit.release())); 408 m_deferredCommitPending = false;
409 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadProxy::beginFr ame));
410 }
406 } 411 }
407 412
408 bool ThreadProxy::commitRequested() const 413 bool ThreadProxy::commitRequested() const
409 { 414 {
410 DCHECK(isMainThread()); 415 DCHECK(isMainThread());
411 return m_commitRequested; 416 return m_commitRequested;
412 } 417 }
413 418
414 void ThreadProxy::setNeedsRedrawOnImplThread() 419 void ThreadProxy::setNeedsRedrawOnImplThread()
415 { 420 {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 DCHECK(isImplThread()); 481 DCHECK(isImplThread());
477 m_layerTreeHostImpl->finishAllRendering(); 482 m_layerTreeHostImpl->finishAllRendering();
478 completion->signal(); 483 completion->signal();
479 } 484 }
480 485
481 void ThreadProxy::forceBeginFrameOnImplThread(CompletionEvent* completion) 486 void ThreadProxy::forceBeginFrameOnImplThread(CompletionEvent* completion)
482 { 487 {
483 TRACE_EVENT0("cc", "ThreadProxy::forceBeginFrameOnImplThread"); 488 TRACE_EVENT0("cc", "ThreadProxy::forceBeginFrameOnImplThread");
484 DCHECK(!m_beginFrameCompletionEventOnImplThread); 489 DCHECK(!m_beginFrameCompletionEventOnImplThread);
485 490
486 setNeedsForcedCommitOnImplThread();
487 if (m_schedulerOnImplThread->commitPending()) { 491 if (m_schedulerOnImplThread->commitPending()) {
488 completion->signal(); 492 completion->signal();
489 return; 493 return;
490 } 494 }
491 495
492 m_beginFrameCompletionEventOnImplThread = completion; 496 m_beginFrameCompletionEventOnImplThread = completion;
497 setNeedsForcedCommitOnImplThread();
493 } 498 }
494 499
495 void ThreadProxy::scheduledActionBeginFrame() 500 void ThreadProxy::scheduledActionBeginFrame()
496 { 501 {
497 TRACE_EVENT0("cc", "ThreadProxy::scheduledActionBeginFrame"); 502 TRACE_EVENT0("cc", "ThreadProxy::scheduledActionBeginFrame");
498 scoped_ptr<BeginFrameAndCommitState> beginFrameState(new BeginFrameAndCommit State); 503 DCHECK(!m_pendingBeginFrameRequest);
499 beginFrameState->monotonicFrameBeginTime = base::TimeTicks::Now(); 504 m_pendingBeginFrameRequest = make_scoped_ptr(new BeginFrameAndCommitState()) ;
500 beginFrameState->scrollInfo = m_layerTreeHostImpl->processScrollDeltas(); 505 m_pendingBeginFrameRequest->monotonicFrameBeginTime = base::TimeTicks::Now() ;
501 beginFrameState->implTransform = m_layerTreeHostImpl->implTransform(); 506 m_pendingBeginFrameRequest->scrollInfo = m_layerTreeHostImpl->processScrollD eltas();
502 DCHECK_GT(m_layerTreeHostImpl->memoryAllocationLimitBytes(), 0u); 507 m_pendingBeginFrameRequest->implTransform = m_layerTreeHostImpl->implTransfo rm();
503 beginFrameState->memoryAllocationLimitBytes = m_layerTreeHostImpl->memoryAll ocationLimitBytes(); 508 m_pendingBeginFrameRequest->memoryAllocationLimitBytes = m_layerTreeHostImpl ->memoryAllocationLimitBytes();
504 if (m_layerTreeHost->contentsTextureManager()) 509 if (m_layerTreeHost->contentsTextureManager())
505 m_layerTreeHost->contentsTextureManager()->getEvictedBackings(beginFram eState->evictedContentsTexturesBackings); 510 m_layerTreeHost->contentsTextureManager()->getEvictedBackings(m_pending BeginFrameRequest->evictedContentsTexturesBackings);
506 511
507 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadProxy::beginFrame, beginFrameState.release())); 512 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadProxy::beginFrame) );
508 513
509 if (m_beginFrameCompletionEventOnImplThread) { 514 if (m_beginFrameCompletionEventOnImplThread) {
510 m_beginFrameCompletionEventOnImplThread->signal(); 515 m_beginFrameCompletionEventOnImplThread->signal();
511 m_beginFrameCompletionEventOnImplThread = 0; 516 m_beginFrameCompletionEventOnImplThread = 0;
512 } 517 }
513 } 518 }
514 519
515 void ThreadProxy::beginFrame(BeginFrameAndCommitState* rawBeginFrameState) 520 void ThreadProxy::beginFrame()
516 { 521 {
517 scoped_ptr<BeginFrameAndCommitState> beginFrameState(rawBeginFrameState);
518 TRACE_EVENT0("cc", "ThreadProxy::beginFrame"); 522 TRACE_EVENT0("cc", "ThreadProxy::beginFrame");
519 DCHECK(isMainThread()); 523 DCHECK(isMainThread());
520 if (!m_layerTreeHost) 524 if (!m_layerTreeHost)
521 return; 525 return;
522 526
523 if (m_deferCommits) { 527 if (m_deferCommits) {
524 m_pendingDeferredCommit = beginFrameState.Pass(); 528 m_deferredCommitPending = true;
525 m_layerTreeHost->didDeferCommit(); 529 m_layerTreeHost->didDeferCommit();
526 TRACE_EVENT0("cc", "EarlyOut_DeferCommits"); 530 TRACE_EVENT0("cc", "EarlyOut_DeferCommits");
527 return; 531 return;
528 } 532 }
529 533
534 if (!m_pendingBeginFrameRequest) {
535 TRACE_EVENT0("cc", "EarlyOut_StaleBeginFrameMessage");
536 return;
537 }
538
530 if (m_layerTreeHost->needsSharedContext() && !WebSharedGraphicsContext3D::ha veCompositorThreadContext()) 539 if (m_layerTreeHost->needsSharedContext() && !WebSharedGraphicsContext3D::ha veCompositorThreadContext())
531 WebSharedGraphicsContext3D::createCompositorThreadContext(); 540 WebSharedGraphicsContext3D::createCompositorThreadContext();
532 541
542 scoped_ptr<BeginFrameAndCommitState> request(m_pendingBeginFrameRequest.Pass ());
543
533 // Do not notify the impl thread of commit requests that occur during 544 // Do not notify the impl thread of commit requests that occur during
534 // the apply/animate/layout part of the beginFrameAndCommit process since 545 // the apply/animate/layout part of the beginFrameAndCommit process since
535 // those commit requests will get painted immediately. Once we have done 546 // those commit requests will get painted immediately. Once we have done
536 // the paint, m_commitRequested will be set to false to allow new commit 547 // the paint, m_commitRequested will be set to false to allow new commit
537 // requests to be scheduled. 548 // requests to be scheduled.
538 m_commitRequested = true; 549 m_commitRequested = true;
539 m_commitRequestSentToImplThread = true; 550 m_commitRequestSentToImplThread = true;
540 551
541 // On the other hand, the animationRequested flag needs to be cleared 552 // On the other hand, the animationRequested flag needs to be cleared
542 // here so that any animation requests generated by the apply or animate 553 // here so that any animation requests generated by the apply or animate
543 // callbacks will trigger another frame. 554 // callbacks will trigger another frame.
544 m_animateRequested = false; 555 m_animateRequested = false;
545 556
546 if (beginFrameState) { 557 // FIXME: technically, scroll deltas need to be applied for dropped commits as well.
547 m_layerTreeHost->applyScrollAndScale(*beginFrameState->scrollInfo); 558 // Re-do the commit flow so that we don't send the scrollInfo on the BFAC me ssage.
548 m_layerTreeHost->setImplTransform(beginFrameState->implTransform); 559 m_layerTreeHost->applyScrollAndScale(*request->scrollInfo);
549 } 560 m_layerTreeHost->setImplTransform(request->implTransform);
550 561
551 if (!m_inCompositeAndReadback && !m_layerTreeHost->visible()) { 562 if (!m_inCompositeAndReadback && !m_layerTreeHost->visible()) {
552 m_commitRequested = false; 563 m_commitRequested = false;
553 m_commitRequestSentToImplThread = false; 564 m_commitRequestSentToImplThread = false;
565 m_forcedCommitRequested = false;
554 566
555 TRACE_EVENT0("cc", "EarlyOut_NotVisible"); 567 TRACE_EVENT0("cc", "EarlyOut_NotVisible");
556 Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::begin FrameAbortedOnImplThread)); 568 Proxy::implThread()->postTask(createThreadTask(this, &ThreadProxy::begin FrameAbortedOnImplThread));
557 return; 569 return;
558 } 570 }
559 571
560 m_layerTreeHost->willBeginFrame(); 572 m_layerTreeHost->willBeginFrame();
561 573
562 if (beginFrameState) 574 m_layerTreeHost->updateAnimations(request->monotonicFrameBeginTime);
563 m_layerTreeHost->updateAnimations(beginFrameState->monotonicFrameBeginTi me);
564 m_layerTreeHost->layout(); 575 m_layerTreeHost->layout();
565 576
566 // Clear the commit flag after updating animations and layout here --- objec ts that only 577 // Clear the commit flag after updating animations and layout here --- objec ts that only
567 // layout when painted will trigger another setNeedsCommit inside 578 // layout when painted will trigger another setNeedsCommit inside
568 // updateLayers. 579 // updateLayers.
569 m_commitRequested = false; 580 m_commitRequested = false;
570 m_commitRequestSentToImplThread = false; 581 m_commitRequestSentToImplThread = false;
582 m_forcedCommitRequested = false;
571 583
572 if (!m_layerTreeHost->initializeRendererIfNeeded()) { 584 if (!m_layerTreeHost->initializeRendererIfNeeded()) {
573 TRACE_EVENT0("cc", "EarlyOut_InitializeFailed"); 585 TRACE_EVENT0("cc", "EarlyOut_InitializeFailed");
574 return; 586 return;
575 } 587 }
576 588
577 if (beginFrameState) 589 m_layerTreeHost->contentsTextureManager()->unlinkEvictedBackings(request->ev ictedContentsTexturesBackings);
578 m_layerTreeHost->contentsTextureManager()->unlinkEvictedBackings(beginFr ameState->evictedContentsTexturesBackings);
579 590
580 scoped_ptr<ResourceUpdateQueue> queue = make_scoped_ptr(new ResourceUpdateQu eue); 591 scoped_ptr<ResourceUpdateQueue> queue = make_scoped_ptr(new ResourceUpdateQu eue);
581 m_layerTreeHost->updateLayers(*(queue.get()), beginFrameState ? beginFrameSt ate->memoryAllocationLimitBytes : 0); 592 m_layerTreeHost->updateLayers(*(queue.get()), request->memoryAllocationLimit Bytes);
582 593
583 // Once single buffered layers are committed, they cannot be modified until 594 // Once single buffered layers are committed, they cannot be modified until
584 // they are drawn by the impl thread. 595 // they are drawn by the impl thread.
585 m_texturesAcquired = false; 596 m_texturesAcquired = false;
586 597
587 m_layerTreeHost->willCommit(); 598 m_layerTreeHost->willCommit();
588 // Before applying scrolls and calling animate, we set m_animateRequested to 599 // Before applying scrolls and calling animate, we set m_animateRequested to
589 // false. If it is true now, it means setNeedAnimate was called again, but 600 // false. If it is true now, it means setNeedAnimate was called again, but
590 // during a state when m_commitRequestSentToImplThread = true. We need to 601 // during a state when m_commitRequestSentToImplThread = true. We need to
591 // force that call to happen again now so that the commit request is sent to 602 // force that call to happen again now so that the commit request is sent to
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 } 995 }
985 996
986 void ThreadProxy::renderingStatsOnImplThread(CompletionEvent* completion, Render ingStats* stats) 997 void ThreadProxy::renderingStatsOnImplThread(CompletionEvent* completion, Render ingStats* stats)
987 { 998 {
988 DCHECK(isImplThread()); 999 DCHECK(isImplThread());
989 m_layerTreeHostImpl->renderingStats(stats); 1000 m_layerTreeHostImpl->renderingStats(stats);
990 completion->signal(); 1001 completion->signal();
991 } 1002 }
992 1003
993 ThreadProxy::BeginFrameAndCommitState::BeginFrameAndCommitState() 1004 ThreadProxy::BeginFrameAndCommitState::BeginFrameAndCommitState()
994 : memoryAllocationLimitBytes(0)
995 { 1005 {
996 } 1006 }
997 1007
998 ThreadProxy::BeginFrameAndCommitState::~BeginFrameAndCommitState() 1008 ThreadProxy::BeginFrameAndCommitState::~BeginFrameAndCommitState()
999 { 1009 {
1000 } 1010 }
1001 1011
1002 } // namespace cc 1012 } // namespace cc
OLDNEW
« no previous file with comments | « cc/thread_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698