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

Side by Side Diff: cc/thread_proxy.cc

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