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

Side by Side Diff: cc/CCThreadProxy.cpp

Issue 10909020: Enable webkit_compositor_unittests (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 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
« no previous file with comments | « cc/CCThreadProxy.h ('k') | cc/cc_tests.gyp » ('j') | 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 "CCThreadProxy.h" 7 #include "CCThreadProxy.h"
8 8
9 #include "CCDelayBasedTimeSource.h" 9 #include "CCDelayBasedTimeSource.h"
10 #include "CCDrawQuad.h" 10 #include "CCDrawQuad.h"
11 #include "CCFrameRateController.h" 11 #include "CCFrameRateController.h"
12 #include "CCGraphicsContext.h" 12 #include "CCGraphicsContext.h"
13 #include "CCInputHandler.h" 13 #include "CCInputHandler.h"
14 #include "CCLayerTreeHost.h" 14 #include "CCLayerTreeHost.h"
15 #include "CCScheduler.h" 15 #include "CCScheduler.h"
16 #include "CCScopedThreadProxy.h" 16 #include "CCScopedThreadProxy.h"
17 #include "CCTextureUpdateController.h"
17 #include "CCThreadTask.h" 18 #include "CCThreadTask.h"
18 #include "TraceEvent.h" 19 #include "TraceEvent.h"
19 #include <public/WebSharedGraphicsContext3D.h> 20 #include <public/WebSharedGraphicsContext3D.h>
20 #include <wtf/CurrentTime.h> 21 #include <wtf/CurrentTime.h>
21 #include <wtf/MainThread.h> 22 #include <wtf/MainThread.h>
22 23
23 using namespace WTF; 24 using namespace WTF;
24 25
25 using WebKit::WebSharedGraphicsContext3D; 26 using WebKit::WebSharedGraphicsContext3D;
26 namespace { 27 namespace {
(...skipping 13 matching lines...) Expand all
40 } // anonymous namespace 41 } // anonymous namespace
41 42
42 PassOwnPtr<CCProxy> CCThreadProxy::create(CCLayerTreeHost* layerTreeHost) 43 PassOwnPtr<CCProxy> CCThreadProxy::create(CCLayerTreeHost* layerTreeHost)
43 { 44 {
44 return adoptPtr(new CCThreadProxy(layerTreeHost)); 45 return adoptPtr(new CCThreadProxy(layerTreeHost));
45 } 46 }
46 47
47 CCThreadProxy::CCThreadProxy(CCLayerTreeHost* layerTreeHost) 48 CCThreadProxy::CCThreadProxy(CCLayerTreeHost* layerTreeHost)
48 : m_animateRequested(false) 49 : m_animateRequested(false)
49 , m_commitRequested(false) 50 , m_commitRequested(false)
51 , m_commitRequestSentToImplThread(false)
50 , m_forcedCommitRequested(false) 52 , m_forcedCommitRequested(false)
51 , m_layerTreeHost(layerTreeHost) 53 , m_layerTreeHost(layerTreeHost)
52 , m_compositorIdentifier(-1) 54 , m_compositorIdentifier(-1)
53 , m_rendererInitialized(false) 55 , m_rendererInitialized(false)
54 , m_started(false) 56 , m_started(false)
55 , m_texturesAcquired(true) 57 , m_texturesAcquired(true)
56 , m_inCompositeAndReadback(false) 58 , m_inCompositeAndReadback(false)
57 , m_mainThreadProxy(CCScopedThreadProxy::create(CCProxy::mainThread())) 59 , m_mainThreadProxy(CCScopedThreadProxy::create(CCProxy::mainThread()))
58 , m_beginFrameCompletionEventOnImplThread(0) 60 , m_beginFrameCompletionEventOnImplThread(0)
59 , m_readbackRequestOnImplThread(0) 61 , m_readbackRequestOnImplThread(0)
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 270 }
269 271
270 void CCThreadProxy::setNeedsAnimate() 272 void CCThreadProxy::setNeedsAnimate()
271 { 273 {
272 ASSERT(isMainThread()); 274 ASSERT(isMainThread());
273 if (m_animateRequested) 275 if (m_animateRequested)
274 return; 276 return;
275 277
276 TRACE_EVENT0("cc", "CCThreadProxy::setNeedsAnimate"); 278 TRACE_EVENT0("cc", "CCThreadProxy::setNeedsAnimate");
277 m_animateRequested = true; 279 m_animateRequested = true;
278 setNeedsCommit(); 280
281 if (m_commitRequestSentToImplThread)
282 return;
283 m_commitRequestSentToImplThread = true;
284 CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::set NeedsCommitOnImplThread));
279 } 285 }
280 286
281 void CCThreadProxy::setNeedsCommit() 287 void CCThreadProxy::setNeedsCommit()
282 { 288 {
283 ASSERT(isMainThread()); 289 ASSERT(isMainThread());
284 if (m_commitRequested) 290 if (m_commitRequested)
285 return; 291 return;
286
287 TRACE_EVENT0("cc", "CCThreadProxy::setNeedsCommit"); 292 TRACE_EVENT0("cc", "CCThreadProxy::setNeedsCommit");
288 m_commitRequested = true; 293 m_commitRequested = true;
294
295 if (m_commitRequestSentToImplThread)
296 return;
297 m_commitRequestSentToImplThread = true;
289 CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::set NeedsCommitOnImplThread)); 298 CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::set NeedsCommitOnImplThread));
290 } 299 }
291 300
292 void CCThreadProxy::didLoseContextOnImplThread() 301 void CCThreadProxy::didLoseContextOnImplThread()
293 { 302 {
294 ASSERT(isImplThread()); 303 ASSERT(isImplThread());
295 TRACE_EVENT0("cc", "CCThreadProxy::didLoseContextOnImplThread"); 304 TRACE_EVENT0("cc", "CCThreadProxy::didLoseContextOnImplThread");
296 if (m_currentTextureUpdateControllerOnImplThread) 305 m_currentTextureUpdateControllerOnImplThread.clear();
297 m_currentTextureUpdateControllerOnImplThread->discardUploads();
298 m_schedulerOnImplThread->didLoseContext(); 306 m_schedulerOnImplThread->didLoseContext();
299 } 307 }
300 308
301 void CCThreadProxy::onSwapBuffersCompleteOnImplThread() 309 void CCThreadProxy::onSwapBuffersCompleteOnImplThread()
302 { 310 {
303 ASSERT(isImplThread()); 311 ASSERT(isImplThread());
304 TRACE_EVENT0("cc", "CCThreadProxy::onSwapBuffersCompleteOnImplThread"); 312 TRACE_EVENT0("cc", "CCThreadProxy::onSwapBuffersCompleteOnImplThread");
305 m_schedulerOnImplThread->didSwapBuffersComplete(); 313 m_schedulerOnImplThread->didSwapBuffersComplete();
306 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadProxy::didComp leteSwapBuffers)); 314 m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadProxy::didComp leteSwapBuffers));
307 } 315 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 WebSharedGraphicsContext3D::createCompositorThreadContext(); 469 WebSharedGraphicsContext3D::createCompositorThreadContext();
462 470
463 OwnPtr<BeginFrameAndCommitState> request(m_pendingBeginFrameRequest.release( )); 471 OwnPtr<BeginFrameAndCommitState> request(m_pendingBeginFrameRequest.release( ));
464 472
465 // Do not notify the impl thread of commit requests that occur during 473 // Do not notify the impl thread of commit requests that occur during
466 // the apply/animate/layout part of the beginFrameAndCommit process since 474 // the apply/animate/layout part of the beginFrameAndCommit process since
467 // those commit requests will get painted immediately. Once we have done 475 // those commit requests will get painted immediately. Once we have done
468 // the paint, m_commitRequested will be set to false to allow new commit 476 // the paint, m_commitRequested will be set to false to allow new commit
469 // requests to be scheduled. 477 // requests to be scheduled.
470 m_commitRequested = true; 478 m_commitRequested = true;
479 m_commitRequestSentToImplThread = true;
471 480
472 // On the other hand, the animationRequested flag needs to be cleared 481 // On the other hand, the animationRequested flag needs to be cleared
473 // here so that any animation requests generated by the apply or animate 482 // here so that any animation requests generated by the apply or animate
474 // callbacks will trigger another frame. 483 // callbacks will trigger another frame.
475 m_animateRequested = false; 484 m_animateRequested = false;
476 485
477 // FIXME: technically, scroll deltas need to be applied for dropped commits as well. 486 // FIXME: technically, scroll deltas need to be applied for dropped commits as well.
478 // Re-do the commit flow so that we don't send the scrollInfo on the BFAC me ssage. 487 // Re-do the commit flow so that we don't send the scrollInfo on the BFAC me ssage.
479 m_layerTreeHost->applyScrollAndScale(*request->scrollInfo); 488 m_layerTreeHost->applyScrollAndScale(*request->scrollInfo);
480 489
481 if (!m_inCompositeAndReadback && !m_layerTreeHost->visible()) { 490 if (!m_inCompositeAndReadback && !m_layerTreeHost->visible()) {
482 m_commitRequested = false; 491 m_commitRequested = false;
492 m_commitRequestSentToImplThread = false;
483 m_forcedCommitRequested = false; 493 m_forcedCommitRequested = false;
484 494
485 TRACE_EVENT0("cc", "EarlyOut_NotVisible"); 495 TRACE_EVENT0("cc", "EarlyOut_NotVisible");
486 CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy: :beginFrameAbortedOnImplThread)); 496 CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy: :beginFrameAbortedOnImplThread));
487 return; 497 return;
488 } 498 }
489 499
490 m_layerTreeHost->willBeginFrame(); 500 m_layerTreeHost->willBeginFrame();
491 501
492 m_layerTreeHost->updateAnimations(request->monotonicFrameBeginTime); 502 m_layerTreeHost->updateAnimations(request->monotonicFrameBeginTime);
493 m_layerTreeHost->layout(); 503 m_layerTreeHost->layout();
494 504
495 // Clear the commit flag after updating animations and layout here --- objec ts that only 505 // Clear the commit flag after updating animations and layout here --- objec ts that only
496 // layout when painted will trigger another setNeedsCommit inside 506 // layout when painted will trigger another setNeedsCommit inside
497 // updateLayers. 507 // updateLayers.
498 m_commitRequested = false; 508 m_commitRequested = false;
509 m_commitRequestSentToImplThread = false;
499 m_forcedCommitRequested = false; 510 m_forcedCommitRequested = false;
500 511
501 if (!m_layerTreeHost->initializeRendererIfNeeded()) 512 if (!m_layerTreeHost->initializeRendererIfNeeded())
502 return; 513 return;
503 514
504 if (request->contentsTexturesWereDeleted) 515 if (request->contentsTexturesWereDeleted)
505 m_layerTreeHost->evictAllContentTextures(); 516 m_layerTreeHost->evictAllContentTextures();
506 517
507 OwnPtr<CCTextureUpdateQueue> queue = adoptPtr(new CCTextureUpdateQueue); 518 OwnPtr<CCTextureUpdateQueue> queue = adoptPtr(new CCTextureUpdateQueue);
508 m_layerTreeHost->updateLayers(*(queue.get()), request->memoryAllocationLimit Bytes); 519 m_layerTreeHost->updateLayers(*(queue.get()), request->memoryAllocationLimit Bytes);
509 520
510 // Once single buffered layers are committed, they cannot be modified until 521 // Once single buffered layers are committed, they cannot be modified until
511 // they are drawn by the impl thread. 522 // they are drawn by the impl thread.
512 m_texturesAcquired = false; 523 m_texturesAcquired = false;
513 524
514 m_layerTreeHost->willCommit(); 525 m_layerTreeHost->willCommit();
515 // Before applying scrolls and calling animate, we set m_animateRequested to false. 526 // Before applying scrolls and calling animate, we set m_animateRequested to
516 // If it is true now, it means setNeedAnimate was called again. Call setNeed sCommit 527 // false. If it is true now, it means setNeedAnimate was called again, but
517 // now so that we get begin frame when this one is done. 528 // during a state when m_commitRequestSentToImplThread = true. We need to
518 if (m_animateRequested) 529 // force that call to happen again now so that the commit request is sent to
519 setNeedsCommit(); 530 // the impl thread.
531 if (m_animateRequested) {
532 // Forces setNeedsAnimate to consider posting a commit task.
533 m_animateRequested = false;
534 setNeedsAnimate();
535 }
520 536
521 // Notify the impl thread that the beginFrame has completed. This will 537 // Notify the impl thread that the beginFrame has completed. This will
522 // begin the commit process, which is blocking from the main thread's 538 // begin the commit process, which is blocking from the main thread's
523 // point of view, but asynchronously performed on the impl thread, 539 // point of view, but asynchronously performed on the impl thread,
524 // coordinated by the CCScheduler. 540 // coordinated by the CCScheduler.
525 { 541 {
526 TRACE_EVENT0("cc", "commit"); 542 TRACE_EVENT0("cc", "commit");
527 DebugScopedSetMainThreadBlocked mainThreadBlocked; 543 DebugScopedSetMainThreadBlocked mainThreadBlocked;
528 544
529 CCCompletionEvent completion; 545 CCCompletionEvent completion;
(...skipping 21 matching lines...) Expand all
551 if (!contentsTexturesWereDeleted && m_layerTreeHostImpl->contentsTexturesPur ged()) { 567 if (!contentsTexturesWereDeleted && m_layerTreeHostImpl->contentsTexturesPur ged()) {
552 // We purged the content textures on the impl thread between the time we 568 // We purged the content textures on the impl thread between the time we
553 // posted the beginFrame task and now, meaning we have a bunch of 569 // posted the beginFrame task and now, meaning we have a bunch of
554 // uploads that are now invalid. Clear the uploads (they all go to 570 // uploads that are now invalid. Clear the uploads (they all go to
555 // content textures), and kick another commit to fill them again. 571 // content textures), and kick another commit to fill them again.
556 queue->clearUploads(); 572 queue->clearUploads();
557 setNeedsCommitOnImplThread(); 573 setNeedsCommitOnImplThread();
558 } else 574 } else
559 m_resetContentsTexturesPurgedAfterCommitOnImplThread = true; 575 m_resetContentsTexturesPurgedAfterCommitOnImplThread = true;
560 576
561 bool hasResourceUpdates = queue->hasMoreUpdates(); 577 m_currentTextureUpdateControllerOnImplThread = CCTextureUpdateController::cr eate(CCProxy::implThread(), queue, m_layerTreeHostImpl->resourceProvider(), m_la yerTreeHostImpl->renderer()->textureCopier(), m_layerTreeHostImpl->renderer()->t extureUploader());
562 if (hasResourceUpdates)
563 m_currentTextureUpdateControllerOnImplThread = CCTextureUpdateController ::create(this, CCProxy::implThread(), queue, m_layerTreeHostImpl->resourceProvid er(), m_layerTreeHostImpl->renderer()->textureCopier(), m_layerTreeHostImpl->ren derer()->textureUploader());
564 m_commitCompletionEventOnImplThread = completion; 578 m_commitCompletionEventOnImplThread = completion;
565 579
566 m_schedulerOnImplThread->beginFrameComplete(hasResourceUpdates); 580 m_schedulerOnImplThread->beginFrameComplete();
567 } 581 }
568 582
569 void CCThreadProxy::beginFrameAbortedOnImplThread() 583 void CCThreadProxy::beginFrameAbortedOnImplThread()
570 { 584 {
571 TRACE_EVENT0("cc", "CCThreadProxy::beginFrameAbortedOnImplThread"); 585 TRACE_EVENT0("cc", "CCThreadProxy::beginFrameAbortedOnImplThread");
572 ASSERT(isImplThread()); 586 ASSERT(isImplThread());
573 ASSERT(m_schedulerOnImplThread); 587 ASSERT(m_schedulerOnImplThread);
574 ASSERT(m_schedulerOnImplThread->commitPending()); 588 ASSERT(m_schedulerOnImplThread->commitPending());
575 589
576 m_schedulerOnImplThread->beginFrameAborted(); 590 m_schedulerOnImplThread->beginFrameAborted();
577 } 591 }
578 592
593 bool CCThreadProxy::hasMoreResourceUpdates() const
594 {
595 if (!m_currentTextureUpdateControllerOnImplThread)
596 return false;
597 return m_currentTextureUpdateControllerOnImplThread->hasMoreUpdates();
598 }
599
579 bool CCThreadProxy::canDraw() 600 bool CCThreadProxy::canDraw()
580 { 601 {
581 ASSERT(isImplThread()); 602 ASSERT(isImplThread());
582 if (!m_layerTreeHostImpl) 603 if (!m_layerTreeHostImpl)
583 return false; 604 return false;
584 return m_layerTreeHostImpl->canDraw(); 605 return m_layerTreeHostImpl->canDraw();
585 } 606 }
586 607
587 void CCThreadProxy::scheduledActionUpdateMoreResources(double monotonicTimeLimit ) 608 void CCThreadProxy::scheduledActionUpdateMoreResources(double monotonicTimeLimit )
588 { 609 {
589 TRACE_EVENT0("cc", "CCThreadProxy::scheduledActionUpdateMoreResources"); 610 TRACE_EVENT0("cc", "CCThreadProxy::scheduledActionUpdateMoreResources");
590 ASSERT(m_currentTextureUpdateControllerOnImplThread); 611 ASSERT(m_currentTextureUpdateControllerOnImplThread);
591 m_currentTextureUpdateControllerOnImplThread->updateMoreTextures(monotonicTi meLimit); 612 m_currentTextureUpdateControllerOnImplThread->updateMoreTextures(monotonicTi meLimit);
592 } 613 }
593 614
594 void CCThreadProxy::scheduledActionCommit() 615 void CCThreadProxy::scheduledActionCommit()
595 { 616 {
596 TRACE_EVENT0("cc", "CCThreadProxy::scheduledActionCommit"); 617 TRACE_EVENT0("cc", "CCThreadProxy::scheduledActionCommit");
597 ASSERT(isImplThread()); 618 ASSERT(isImplThread());
619 ASSERT(!hasMoreResourceUpdates());
598 ASSERT(m_commitCompletionEventOnImplThread); 620 ASSERT(m_commitCompletionEventOnImplThread);
599 621
600 m_currentTextureUpdateControllerOnImplThread.clear(); 622 m_currentTextureUpdateControllerOnImplThread.clear();
601 623
602 m_layerTreeHostImpl->beginCommit(); 624 m_layerTreeHostImpl->beginCommit();
603 625
604 m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get()); 626 m_layerTreeHost->beginCommitOnImplThread(m_layerTreeHostImpl.get());
605 m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get()); 627 m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get());
606 628
607 if (m_resetContentsTexturesPurgedAfterCommitOnImplThread) { 629 if (m_resetContentsTexturesPurgedAfterCommitOnImplThread) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 CCScheduledActionDrawAndSwapResult CCThreadProxy::scheduledActionDrawAndSwapIfPo ssible() 747 CCScheduledActionDrawAndSwapResult CCThreadProxy::scheduledActionDrawAndSwapIfPo ssible()
726 { 748 {
727 return scheduledActionDrawAndSwapInternal(false); 749 return scheduledActionDrawAndSwapInternal(false);
728 } 750 }
729 751
730 CCScheduledActionDrawAndSwapResult CCThreadProxy::scheduledActionDrawAndSwapForc ed() 752 CCScheduledActionDrawAndSwapResult CCThreadProxy::scheduledActionDrawAndSwapForc ed()
731 { 753 {
732 return scheduledActionDrawAndSwapInternal(true); 754 return scheduledActionDrawAndSwapInternal(true);
733 } 755 }
734 756
735 void CCThreadProxy::updateTexturesCompleted()
736 {
737 ASSERT(isImplThread());
738 m_schedulerOnImplThread->updateResourcesComplete();
739 }
740
741 void CCThreadProxy::didCommitAndDrawFrame() 757 void CCThreadProxy::didCommitAndDrawFrame()
742 { 758 {
743 ASSERT(isMainThread()); 759 ASSERT(isMainThread());
744 if (!m_layerTreeHost) 760 if (!m_layerTreeHost)
745 return; 761 return;
746 m_layerTreeHost->didCommitAndDrawFrame(); 762 m_layerTreeHost->didCommitAndDrawFrame();
747 } 763 }
748 764
749 void CCThreadProxy::didCompleteSwapBuffers() 765 void CCThreadProxy::didCompleteSwapBuffers()
750 { 766 {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 } 899 }
884 900
885 void CCThreadProxy::implSideRenderingStatsOnImplThread(CCCompletionEvent* comple tion, CCRenderingStats* stats) 901 void CCThreadProxy::implSideRenderingStatsOnImplThread(CCCompletionEvent* comple tion, CCRenderingStats* stats)
886 { 902 {
887 ASSERT(isImplThread()); 903 ASSERT(isImplThread());
888 m_layerTreeHostImpl->renderingStats(*stats); 904 m_layerTreeHostImpl->renderingStats(*stats);
889 completion->signal(); 905 completion->signal();
890 } 906 }
891 907
892 } // namespace WebCore 908 } // namespace WebCore
OLDNEW
« no previous file with comments | « cc/CCThreadProxy.h ('k') | cc/cc_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698