Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/trees/thread_proxy.h" | 5 #include "cc/trees/thread_proxy.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 impl_task_runner, | 55 impl_task_runner, |
| 56 external_begin_frame_source.Pass())); | 56 external_begin_frame_source.Pass())); |
| 57 } | 57 } |
| 58 | 58 |
| 59 ThreadProxy::ThreadProxy( | 59 ThreadProxy::ThreadProxy( |
| 60 LayerTreeHost* layer_tree_host, | 60 LayerTreeHost* layer_tree_host, |
| 61 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 61 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 62 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, | 62 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 63 scoped_ptr<BeginFrameSource> external_begin_frame_source) | 63 scoped_ptr<BeginFrameSource> external_begin_frame_source) |
| 64 : Proxy(main_task_runner, impl_task_runner), | 64 : Proxy(main_task_runner, impl_task_runner), |
| 65 main_thread_only_vars_unsafe_(this, layer_tree_host->id()), | 65 main_thread_only_vars_unsafe_(this, layer_tree_host), |
| 66 main_thread_or_blocked_vars_unsafe_(layer_tree_host), | |
| 67 compositor_thread_vars_unsafe_( | 66 compositor_thread_vars_unsafe_( |
| 68 this, | 67 this, |
| 69 layer_tree_host->id(), | 68 layer_tree_host->id(), |
| 70 layer_tree_host->rendering_stats_instrumentation(), | 69 layer_tree_host->rendering_stats_instrumentation(), |
| 71 external_begin_frame_source.Pass()) { | 70 external_begin_frame_source.Pass()) { |
| 72 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); | 71 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); |
| 73 DCHECK(IsMainThread()); | 72 DCHECK(IsMainThread()); |
| 74 DCHECK(this->layer_tree_host()); | 73 DCHECK(this->layer_tree_host()); |
| 75 // TODO(khushalsagar): Move this to LayerTreeHost#InitializeThreaded once | 74 // TODO(khushalsagar): Move this to LayerTreeHost#InitializeThreaded once |
| 76 // ThreadProxy is split. LayerTreeHost creates the channel and passes it to | 75 // ThreadProxy is split. LayerTreeHost creates the channel and passes it to |
| 77 // ProxyMain#SetChannel. | 76 // ProxyMain#SetChannel. |
| 78 SetChannel(ThreadedChannel::Create(this, main_task_runner, impl_task_runner)); | 77 SetChannel(ThreadedChannel::Create(this, main_task_runner, impl_task_runner)); |
| 79 } | 78 } |
| 80 | 79 |
| 81 ThreadProxy::MainThreadOnly::MainThreadOnly(ThreadProxy* proxy, | 80 ThreadProxy::MainThreadOnly::MainThreadOnly(ThreadProxy* proxy, |
| 82 int layer_tree_host_id) | 81 LayerTreeHost* layer_tree_host) |
| 83 : layer_tree_host_id(layer_tree_host_id), | 82 : layer_tree_host_id(layer_tree_host->id()), |
| 83 layer_tree_host(layer_tree_host), | |
| 84 max_requested_pipeline_stage(NO_PIPELINE_STAGE), | 84 max_requested_pipeline_stage(NO_PIPELINE_STAGE), |
| 85 current_pipeline_stage(NO_PIPELINE_STAGE), | 85 current_pipeline_stage(NO_PIPELINE_STAGE), |
| 86 final_pipeline_stage(NO_PIPELINE_STAGE), | 86 final_pipeline_stage(NO_PIPELINE_STAGE), |
| 87 commit_waits_for_activation(false), | |
| 87 started(false), | 88 started(false), |
| 88 prepare_tiles_pending(false), | 89 prepare_tiles_pending(false), |
| 89 defer_commits(false), | 90 defer_commits(false), |
| 90 weak_factory(proxy) {} | 91 weak_factory(proxy) {} |
| 91 | 92 |
| 92 ThreadProxy::MainThreadOnly::~MainThreadOnly() {} | 93 ThreadProxy::MainThreadOnly::~MainThreadOnly() {} |
| 93 | 94 |
| 94 ThreadProxy::MainThreadOrBlockedMainThread::MainThreadOrBlockedMainThread( | 95 ThreadProxy::BlockedMainCommitOnly::BlockedMainCommitOnly() |
| 95 LayerTreeHost* host) | 96 : layer_tree_host(nullptr) {} |
| 96 : layer_tree_host(host), | |
| 97 commit_waits_for_activation(false), | |
| 98 main_thread_inside_commit(false) {} | |
| 99 | 97 |
| 100 ThreadProxy::MainThreadOrBlockedMainThread::~MainThreadOrBlockedMainThread() {} | 98 ThreadProxy::BlockedMainCommitOnly::~BlockedMainCommitOnly() {} |
| 101 | 99 |
| 102 ThreadProxy::CompositorThreadOnly::CompositorThreadOnly( | 100 ThreadProxy::CompositorThreadOnly::CompositorThreadOnly( |
| 103 ThreadProxy* proxy, | 101 ThreadProxy* proxy, |
| 104 int layer_tree_host_id, | 102 int layer_tree_host_id, |
| 105 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 103 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| 106 scoped_ptr<BeginFrameSource> external_begin_frame_source) | 104 scoped_ptr<BeginFrameSource> external_begin_frame_source) |
| 107 : layer_tree_host_id(layer_tree_host_id), | 105 : layer_tree_host_id(layer_tree_host_id), |
| 106 next_commit_waits_for_activation(false), | |
| 108 commit_completion_event(nullptr), | 107 commit_completion_event(nullptr), |
| 109 completion_event_for_commit_held_on_tree_activation(nullptr), | |
| 110 next_frame_is_newly_committed_frame(false), | 108 next_frame_is_newly_committed_frame(false), |
| 111 inside_draw(false), | 109 inside_draw(false), |
| 112 input_throttled_until_commit(false), | 110 input_throttled_until_commit(false), |
| 113 smoothness_priority_expiration_notifier( | 111 smoothness_priority_expiration_notifier( |
| 114 proxy->ImplThreadTaskRunner(), | 112 proxy->ImplThreadTaskRunner(), |
| 115 base::Bind(&ThreadProxy::RenewTreePriority, base::Unretained(proxy)), | 113 base::Bind(&ThreadProxy::RenewTreePriority, base::Unretained(proxy)), |
| 116 base::TimeDelta::FromMilliseconds( | 114 base::TimeDelta::FromMilliseconds( |
| 117 kSmoothnessTakesPriorityExpirationDelay * 1000)), | 115 kSmoothnessTakesPriorityExpirationDelay * 1000)), |
| 118 external_begin_frame_source(external_begin_frame_source.Pass()), | 116 external_begin_frame_source(external_begin_frame_source.Pass()), |
| 119 rendering_stats_instrumentation(rendering_stats_instrumentation), | 117 rendering_stats_instrumentation(rendering_stats_instrumentation), |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 main().channel_main->SetNeedsRedrawOnImpl(damage_rect); | 399 main().channel_main->SetNeedsRedrawOnImpl(damage_rect); |
| 402 } | 400 } |
| 403 | 401 |
| 404 void ThreadProxy::SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) { | 402 void ThreadProxy::SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) { |
| 405 DCHECK(IsImplThread()); | 403 DCHECK(IsImplThread()); |
| 406 SetNeedsRedrawRectOnImplThread(damage_rect); | 404 SetNeedsRedrawRectOnImplThread(damage_rect); |
| 407 } | 405 } |
| 408 | 406 |
| 409 void ThreadProxy::SetNextCommitWaitsForActivation() { | 407 void ThreadProxy::SetNextCommitWaitsForActivation() { |
| 410 DCHECK(IsMainThread()); | 408 DCHECK(IsMainThread()); |
| 411 DCHECK(!blocked_main().main_thread_inside_commit); | 409 main().commit_waits_for_activation = true; |
| 412 blocked_main().commit_waits_for_activation = true; | |
| 413 } | 410 } |
| 414 | 411 |
| 415 void ThreadProxy::SetDeferCommits(bool defer_commits) { | 412 void ThreadProxy::SetDeferCommits(bool defer_commits) { |
| 416 DCHECK(IsMainThread()); | 413 DCHECK(IsMainThread()); |
| 417 if (main().defer_commits == defer_commits) | 414 if (main().defer_commits == defer_commits) |
| 418 return; | 415 return; |
| 419 | 416 |
| 420 main().defer_commits = defer_commits; | 417 main().defer_commits = defer_commits; |
| 421 if (main().defer_commits) | 418 if (main().defer_commits) |
| 422 TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::SetDeferCommits", this); | 419 TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::SetDeferCommits", this); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 } | 480 } |
| 484 | 481 |
| 485 void ThreadProxy::SetInputThrottledUntilCommitOnImpl(bool is_throttled) { | 482 void ThreadProxy::SetInputThrottledUntilCommitOnImpl(bool is_throttled) { |
| 486 DCHECK(IsImplThread()); | 483 DCHECK(IsImplThread()); |
| 487 if (is_throttled == impl().input_throttled_until_commit) | 484 if (is_throttled == impl().input_throttled_until_commit) |
| 488 return; | 485 return; |
| 489 impl().input_throttled_until_commit = is_throttled; | 486 impl().input_throttled_until_commit = is_throttled; |
| 490 RenewTreePriority(); | 487 RenewTreePriority(); |
| 491 } | 488 } |
| 492 | 489 |
| 493 LayerTreeHost* ThreadProxy::layer_tree_host() { | 490 LayerTreeHost* ThreadProxy::layer_tree_host() { |
|
vmpstr
2015/10/29 21:36:33
I think we maybe should remove these functions and
Khushal
2015/10/29 22:52:19
Done.
| |
| 494 return blocked_main().layer_tree_host; | 491 return main().layer_tree_host; |
| 495 } | 492 } |
| 496 | 493 |
| 497 const LayerTreeHost* ThreadProxy::layer_tree_host() const { | 494 const LayerTreeHost* ThreadProxy::layer_tree_host() const { |
| 498 return blocked_main().layer_tree_host; | 495 return main().layer_tree_host; |
| 499 } | 496 } |
| 500 | 497 |
| 501 ThreadProxy::MainThreadOnly& ThreadProxy::main() { | 498 ThreadProxy::MainThreadOnly& ThreadProxy::main() { |
| 502 DCHECK(IsMainThread()); | 499 DCHECK(IsMainThread()); |
| 503 return main_thread_only_vars_unsafe_; | 500 return main_thread_only_vars_unsafe_; |
| 504 } | 501 } |
| 505 const ThreadProxy::MainThreadOnly& ThreadProxy::main() const { | 502 const ThreadProxy::MainThreadOnly& ThreadProxy::main() const { |
| 506 DCHECK(IsMainThread()); | 503 DCHECK(IsMainThread()); |
| 507 return main_thread_only_vars_unsafe_; | 504 return main_thread_only_vars_unsafe_; |
| 508 } | 505 } |
| 509 | 506 |
| 510 ThreadProxy::MainThreadOrBlockedMainThread& ThreadProxy::blocked_main() { | 507 ThreadProxy::BlockedMainCommitOnly& ThreadProxy::blocked_main_commit() { |
| 511 DCHECK(IsMainThread() || IsMainThreadBlocked()); | 508 DCHECK(IsMainThreadBlocked() && impl().commit_completion_event); |
|
vmpstr
2015/10/29 21:36:33
nit: Split into two dchecks, so we know which one
Khushal
2015/10/29 22:52:19
Done.
| |
| 512 return main_thread_or_blocked_vars_unsafe_; | 509 return main_thread_blocked_commit_vars_unsafe_; |
| 513 } | |
| 514 | |
| 515 const ThreadProxy::MainThreadOrBlockedMainThread& ThreadProxy::blocked_main() | |
| 516 const { | |
| 517 DCHECK(IsMainThread() || IsMainThreadBlocked()); | |
| 518 return main_thread_or_blocked_vars_unsafe_; | |
| 519 } | 510 } |
| 520 | 511 |
| 521 ThreadProxy::CompositorThreadOnly& ThreadProxy::impl() { | 512 ThreadProxy::CompositorThreadOnly& ThreadProxy::impl() { |
| 522 DCHECK(IsImplThread()); | 513 DCHECK(IsImplThread()); |
| 523 return compositor_thread_vars_unsafe_; | 514 return compositor_thread_vars_unsafe_; |
| 524 } | 515 } |
| 525 | 516 |
| 526 const ThreadProxy::CompositorThreadOnly& ThreadProxy::impl() const { | 517 const ThreadProxy::CompositorThreadOnly& ThreadProxy::impl() const { |
| 527 DCHECK(IsImplThread()); | 518 DCHECK(IsImplThread()); |
| 528 return compositor_thread_vars_unsafe_; | 519 return compositor_thread_vars_unsafe_; |
| 529 } | 520 } |
| 530 | 521 |
| 531 void ThreadProxy::Start() { | 522 void ThreadProxy::Start() { |
| 532 DCHECK(IsMainThread()); | 523 DCHECK(IsMainThread()); |
| 533 DCHECK(Proxy::HasImplThread()); | 524 DCHECK(Proxy::HasImplThread()); |
| 534 | 525 |
| 535 // Create LayerTreeHostImpl. | 526 // Create LayerTreeHostImpl. |
| 536 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 527 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 537 CompletionEvent completion; | 528 CompletionEvent completion; |
| 538 Proxy::ImplThreadTaskRunner()->PostTask( | 529 main().channel_main->InitializeImplOnImpl(&completion, layer_tree_host()); |
| 539 FROM_HERE, | |
| 540 base::Bind(&ThreadProxy::InitializeImplOnImplThread, | |
| 541 base::Unretained(this), | |
| 542 &completion)); | |
| 543 completion.Wait(); | 530 completion.Wait(); |
| 544 | 531 |
| 545 main_thread_weak_ptr_ = main().weak_factory.GetWeakPtr(); | 532 main_thread_weak_ptr_ = main().weak_factory.GetWeakPtr(); |
| 546 | 533 |
| 547 main().started = true; | 534 main().started = true; |
| 548 } | 535 } |
| 549 | 536 |
| 550 void ThreadProxy::Stop() { | 537 void ThreadProxy::Stop() { |
| 551 TRACE_EVENT0("cc", "ThreadProxy::Stop"); | 538 TRACE_EVENT0("cc", "ThreadProxy::Stop"); |
| 552 DCHECK(IsMainThread()); | 539 DCHECK(IsMainThread()); |
| 553 DCHECK(main().started); | 540 DCHECK(main().started); |
| 554 | 541 |
| 555 // Synchronously finishes pending GL operations and deletes the impl. | 542 // Synchronously finishes pending GL operations and deletes the impl. |
| 556 // The two steps are done as separate post tasks, so that tasks posted | 543 // The two steps are done as separate post tasks, so that tasks posted |
| 557 // by the GL implementation due to the Finish can be executed by the | 544 // by the GL implementation due to the Finish can be executed by the |
| 558 // renderer before shutting it down. | 545 // renderer before shutting it down. |
| 559 { | 546 { |
| 560 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 547 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 561 CompletionEvent completion; | 548 CompletionEvent completion; |
| 562 main().channel_main->FinishGLOnImpl(&completion); | 549 main().channel_main->FinishGLOnImpl(&completion); |
| 563 completion.Wait(); | 550 completion.Wait(); |
| 564 } | 551 } |
| 565 { | 552 { |
| 566 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 553 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 567 | 554 |
| 568 CompletionEvent completion; | 555 CompletionEvent completion; |
| 569 Proxy::ImplThreadTaskRunner()->PostTask( | 556 main().channel_main->LayerTreeHostClosedOnImpl(&completion); |
| 570 FROM_HERE, | |
| 571 base::Bind(&ThreadProxy::LayerTreeHostClosedOnImplThread, | |
| 572 impl_thread_weak_ptr_, | |
| 573 &completion)); | |
| 574 completion.Wait(); | 557 completion.Wait(); |
| 575 } | 558 } |
| 576 | 559 |
| 577 main().weak_factory.InvalidateWeakPtrs(); | 560 main().weak_factory.InvalidateWeakPtrs(); |
| 578 blocked_main().layer_tree_host = NULL; | 561 main().layer_tree_host = nullptr; |
| 579 main().started = false; | 562 main().started = false; |
| 580 } | 563 } |
| 581 | 564 |
| 582 bool ThreadProxy::SupportsImplScrolling() const { | 565 bool ThreadProxy::SupportsImplScrolling() const { |
| 583 return true; | 566 return true; |
| 584 } | 567 } |
| 585 | 568 |
| 586 void ThreadProxy::FinishAllRenderingOnImpl(CompletionEvent* completion) { | 569 void ThreadProxy::FinishAllRenderingOnImpl(CompletionEvent* completion) { |
| 587 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread"); | 570 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread"); |
| 588 DCHECK(IsImplThread()); | 571 DCHECK(IsImplThread()); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 714 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame::commit"); | 697 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame::commit"); |
| 715 | 698 |
| 716 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 699 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 717 | 700 |
| 718 // This CapturePostTasks should be destroyed before CommitComplete() is | 701 // This CapturePostTasks should be destroyed before CommitComplete() is |
| 719 // called since that goes out to the embedder, and we want the embedder | 702 // called since that goes out to the embedder, and we want the embedder |
| 720 // to receive its callbacks before that. | 703 // to receive its callbacks before that. |
| 721 BlockingTaskRunner::CapturePostTasks blocked( | 704 BlockingTaskRunner::CapturePostTasks blocked( |
| 722 blocking_main_thread_task_runner()); | 705 blocking_main_thread_task_runner()); |
| 723 | 706 |
| 707 bool hold_commit_for_activation = main().commit_waits_for_activation; | |
|
brianderson
2015/10/29 22:38:28
I think StartCommitOnImpl will not modify main().c
Khushal
2015/10/29 22:52:19
Done.
| |
| 708 main().commit_waits_for_activation = false; | |
| 724 CompletionEvent completion; | 709 CompletionEvent completion; |
| 725 main().channel_main->StartCommitOnImpl(&completion); | 710 main().channel_main->StartCommitOnImpl(&completion, layer_tree_host(), |
| 711 hold_commit_for_activation); | |
| 726 completion.Wait(); | 712 completion.Wait(); |
| 727 } | 713 } |
| 728 | 714 |
| 729 main().current_pipeline_stage = NO_PIPELINE_STAGE; | 715 main().current_pipeline_stage = NO_PIPELINE_STAGE; |
| 730 layer_tree_host()->CommitComplete(); | 716 layer_tree_host()->CommitComplete(); |
| 731 layer_tree_host()->DidBeginMainFrame(); | 717 layer_tree_host()->DidBeginMainFrame(); |
| 732 } | 718 } |
| 733 | 719 |
| 734 void ThreadProxy::BeginMainFrameNotExpectedSoon() { | 720 void ThreadProxy::BeginMainFrameNotExpectedSoon() { |
| 735 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrameNotExpectedSoon"); | 721 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrameNotExpectedSoon"); |
| 736 DCHECK(IsMainThread()); | 722 DCHECK(IsMainThread()); |
| 737 layer_tree_host()->BeginMainFrameNotExpectedSoon(); | 723 layer_tree_host()->BeginMainFrameNotExpectedSoon(); |
| 738 } | 724 } |
| 739 | 725 |
| 740 void ThreadProxy::StartCommitOnImpl(CompletionEvent* completion) { | 726 void ThreadProxy::StartCommitOnImpl(CompletionEvent* completion, |
| 727 LayerTreeHost* layer_tree_host, | |
| 728 bool hold_commit_for_activation) { | |
| 741 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread"); | 729 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread"); |
| 742 DCHECK(!impl().commit_completion_event); | 730 DCHECK(!impl().commit_completion_event); |
| 743 DCHECK(IsImplThread() && IsMainThreadBlocked()); | 731 DCHECK(IsImplThread() && IsMainThreadBlocked()); |
| 744 DCHECK(impl().scheduler); | 732 DCHECK(impl().scheduler); |
| 745 DCHECK(impl().scheduler->CommitPending()); | 733 DCHECK(impl().scheduler->CommitPending()); |
| 746 | 734 |
| 735 if (hold_commit_for_activation) { | |
|
vmpstr
2015/10/29 21:36:33
Can we get multiple StartCommitOnImpl calls while
Khushal
2015/10/29 22:52:19
Once the main side sends the hold_commit_for_activ
| |
| 736 // This commit may be aborted. Store the value for | |
| 737 // hold_commit_for_activation so that whenever the next commit is started, | |
| 738 // the main thread will be unblocked only after pending tree activation. | |
| 739 impl().next_commit_waits_for_activation = hold_commit_for_activation; | |
| 740 } | |
| 741 | |
| 747 if (!impl().layer_tree_host_impl) { | 742 if (!impl().layer_tree_host_impl) { |
| 748 TRACE_EVENT_INSTANT0( | 743 TRACE_EVENT_INSTANT0( |
| 749 "cc", "EarlyOut_NoLayerTree", TRACE_EVENT_SCOPE_THREAD); | 744 "cc", "EarlyOut_NoLayerTree", TRACE_EVENT_SCOPE_THREAD); |
| 750 completion->Signal(); | 745 completion->Signal(); |
| 751 return; | 746 return; |
| 752 } | 747 } |
| 753 | 748 |
| 754 // Ideally, we should inform to impl thread when BeginMainFrame is started. | 749 // Ideally, we should inform to impl thread when BeginMainFrame is started. |
| 755 // But, we can avoid a PostTask in here. | 750 // But, we can avoid a PostTask in here. |
| 756 impl().scheduler->NotifyBeginMainFrameStarted(); | 751 impl().scheduler->NotifyBeginMainFrameStarted(); |
| 757 impl().commit_completion_event = completion; | 752 impl().commit_completion_event = completion; |
|
vmpstr
2015/10/29 21:36:33
DCHECK that this is currently null? It should be r
Khushal
2015/10/29 22:52:19
Its already DCHECKed at the beginning of the funct
| |
| 753 DCHECK(!blocked_main_commit().layer_tree_host); | |
| 754 blocked_main_commit().layer_tree_host = layer_tree_host; | |
| 758 impl().scheduler->NotifyReadyToCommit(); | 755 impl().scheduler->NotifyReadyToCommit(); |
| 759 } | 756 } |
| 760 | 757 |
| 761 void ThreadProxy::BeginMainFrameAbortedOnImpl(CommitEarlyOutReason reason) { | 758 void ThreadProxy::BeginMainFrameAbortedOnImpl(CommitEarlyOutReason reason) { |
| 762 TRACE_EVENT1("cc", "ThreadProxy::BeginMainFrameAbortedOnImplThread", "reason", | 759 TRACE_EVENT1("cc", "ThreadProxy::BeginMainFrameAbortedOnImplThread", "reason", |
| 763 CommitEarlyOutReasonToString(reason)); | 760 CommitEarlyOutReasonToString(reason)); |
| 764 DCHECK(IsImplThread()); | 761 DCHECK(IsImplThread()); |
| 765 DCHECK(impl().scheduler); | 762 DCHECK(impl().scheduler); |
| 766 DCHECK(impl().scheduler->CommitPending()); | 763 DCHECK(impl().scheduler->CommitPending()); |
| 767 DCHECK(!impl().layer_tree_host_impl->pending_tree()); | 764 DCHECK(!impl().layer_tree_host_impl->pending_tree()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 780 DCHECK(IsImplThread()); | 777 DCHECK(IsImplThread()); |
| 781 | 778 |
| 782 impl().layer_tree_host_impl->Animate(); | 779 impl().layer_tree_host_impl->Animate(); |
| 783 } | 780 } |
| 784 | 781 |
| 785 void ThreadProxy::ScheduledActionCommit() { | 782 void ThreadProxy::ScheduledActionCommit() { |
| 786 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionCommit"); | 783 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionCommit"); |
| 787 DCHECK(IsImplThread()); | 784 DCHECK(IsImplThread()); |
| 788 DCHECK(IsMainThreadBlocked()); | 785 DCHECK(IsMainThreadBlocked()); |
| 789 DCHECK(impl().commit_completion_event); | 786 DCHECK(impl().commit_completion_event); |
| 787 DCHECK(blocked_main_commit().layer_tree_host); | |
| 790 | 788 |
| 791 blocked_main().main_thread_inside_commit = true; | |
| 792 impl().layer_tree_host_impl->BeginCommit(); | 789 impl().layer_tree_host_impl->BeginCommit(); |
| 793 layer_tree_host()->FinishCommitOnImplThread( | 790 blocked_main_commit().layer_tree_host->FinishCommitOnImplThread( |
| 794 impl().layer_tree_host_impl.get()); | 791 impl().layer_tree_host_impl.get()); |
| 795 blocked_main().main_thread_inside_commit = false; | |
| 796 | 792 |
| 797 bool hold_commit = blocked_main().commit_waits_for_activation; | 793 // Remove the LayerTreeHost reference before the completion event is signaled. |
|
vmpstr
2015/10/29 21:36:33
Why is this important? That is, I understand that
Khushal
2015/10/29 22:52:19
The moment we signal the event, it is cleared as w
| |
| 798 blocked_main().commit_waits_for_activation = false; | 794 blocked_main_commit().layer_tree_host = nullptr; |
| 799 | 795 |
| 800 if (hold_commit) { | 796 if (impl().next_commit_waits_for_activation) { |
| 801 // For some layer types in impl-side painting, the commit is held until | 797 // For some layer types in impl-side painting, the commit is held until |
| 802 // the sync tree is activated. It's also possible that the | 798 // the sync tree is activated. It's also possible that the |
| 803 // sync tree has already activated if there was no work to be done. | 799 // sync tree has already activated if there was no work to be done. |
| 804 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD); | 800 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD); |
| 805 impl().completion_event_for_commit_held_on_tree_activation = | |
|
vmpstr
2015/10/29 21:36:33
This is the part that ensured that we had both com
brianderson
2015/10/29 22:38:28
This looks okay to me. The main thread is blocked
| |
| 806 impl().commit_completion_event; | |
| 807 impl().commit_completion_event = nullptr; | |
| 808 } else { | 801 } else { |
| 809 impl().commit_completion_event->Signal(); | 802 impl().commit_completion_event->Signal(); |
| 810 impl().commit_completion_event = nullptr; | 803 impl().commit_completion_event = nullptr; |
| 811 } | 804 } |
| 812 | 805 |
| 813 impl().scheduler->DidCommit(); | 806 impl().scheduler->DidCommit(); |
| 814 | 807 |
| 815 // Delay this step until afer the main thread has been released as it's | 808 // Delay this step until afer the main thread has been released as it's |
| 816 // often a good bit of work to update the tree and prepare the new frame. | 809 // often a good bit of work to update the tree and prepare the new frame. |
| 817 impl().layer_tree_host_impl->CommitComplete(); | 810 impl().layer_tree_host_impl->CommitComplete(); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 944 DCHECK(IsMainThread()); | 937 DCHECK(IsMainThread()); |
| 945 layer_tree_host()->DidCompleteSwapBuffers(); | 938 layer_tree_host()->DidCompleteSwapBuffers(); |
| 946 } | 939 } |
| 947 | 940 |
| 948 void ThreadProxy::SetAnimationEvents(scoped_ptr<AnimationEventsVector> events) { | 941 void ThreadProxy::SetAnimationEvents(scoped_ptr<AnimationEventsVector> events) { |
| 949 TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents"); | 942 TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents"); |
| 950 DCHECK(IsMainThread()); | 943 DCHECK(IsMainThread()); |
| 951 layer_tree_host()->SetAnimationEvents(events.Pass()); | 944 layer_tree_host()->SetAnimationEvents(events.Pass()); |
| 952 } | 945 } |
| 953 | 946 |
| 954 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { | 947 void ThreadProxy::InitializeImplOnImpl(CompletionEvent* completion, |
| 948 LayerTreeHost* layer_tree_host) { | |
| 955 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); | 949 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); |
| 956 DCHECK(IsImplThread()); | 950 DCHECK(IsImplThread()); |
| 951 DCHECK(IsMainThreadBlocked()); | |
| 952 DCHECK(layer_tree_host); | |
| 957 | 953 |
| 958 // TODO(khushalsagar): ThreadedChannel will create ProxyImpl here and pass a | 954 // TODO(khushalsagar): ThreadedChannel will create ProxyImpl here and pass a |
| 959 // reference to itself. | 955 // reference to itself. |
| 960 impl().channel_impl = threaded_channel_.get(); | 956 impl().channel_impl = threaded_channel_.get(); |
| 961 | 957 |
| 962 impl().layer_tree_host_impl = | 958 impl().layer_tree_host_impl = layer_tree_host->CreateLayerTreeHostImpl(this); |
| 963 layer_tree_host()->CreateLayerTreeHostImpl(this); | |
| 964 | 959 |
| 965 SchedulerSettings scheduler_settings( | 960 SchedulerSettings scheduler_settings( |
| 966 layer_tree_host()->settings().ToSchedulerSettings()); | 961 layer_tree_host->settings().ToSchedulerSettings()); |
| 967 | 962 |
| 968 scoped_ptr<CompositorTimingHistory> compositor_timing_history( | 963 scoped_ptr<CompositorTimingHistory> compositor_timing_history( |
| 969 new CompositorTimingHistory(CompositorTimingHistory::RENDERER_UMA, | 964 new CompositorTimingHistory(CompositorTimingHistory::RENDERER_UMA, |
| 970 impl().rendering_stats_instrumentation)); | 965 impl().rendering_stats_instrumentation)); |
| 971 | 966 |
| 972 impl().scheduler = Scheduler::Create( | 967 impl().scheduler = Scheduler::Create( |
| 973 this, scheduler_settings, impl().layer_tree_host_id, | 968 this, scheduler_settings, impl().layer_tree_host_id, |
| 974 ImplThreadTaskRunner(), impl().external_begin_frame_source.get(), | 969 ImplThreadTaskRunner(), impl().external_begin_frame_source.get(), |
| 975 compositor_timing_history.Pass()); | 970 compositor_timing_history.Pass()); |
| 976 | 971 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1013 DCHECK(IsImplThread()); | 1008 DCHECK(IsImplThread()); |
| 1014 if (impl().layer_tree_host_impl->output_surface()) { | 1009 if (impl().layer_tree_host_impl->output_surface()) { |
| 1015 ContextProvider* context_provider = | 1010 ContextProvider* context_provider = |
| 1016 impl().layer_tree_host_impl->output_surface()->context_provider(); | 1011 impl().layer_tree_host_impl->output_surface()->context_provider(); |
| 1017 if (context_provider) | 1012 if (context_provider) |
| 1018 context_provider->ContextGL()->Finish(); | 1013 context_provider->ContextGL()->Finish(); |
| 1019 } | 1014 } |
| 1020 completion->Signal(); | 1015 completion->Signal(); |
| 1021 } | 1016 } |
| 1022 | 1017 |
| 1023 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) { | 1018 void ThreadProxy::LayerTreeHostClosedOnImpl(CompletionEvent* completion) { |
| 1024 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread"); | 1019 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread"); |
| 1025 DCHECK(IsImplThread()); | 1020 DCHECK(IsImplThread()); |
| 1026 DCHECK(IsMainThreadBlocked()); | 1021 DCHECK(IsMainThreadBlocked()); |
| 1027 impl().scheduler = nullptr; | 1022 impl().scheduler = nullptr; |
| 1028 impl().external_begin_frame_source = nullptr; | 1023 impl().external_begin_frame_source = nullptr; |
| 1029 impl().layer_tree_host_impl = nullptr; | 1024 impl().layer_tree_host_impl = nullptr; |
| 1030 impl().weak_factory.InvalidateWeakPtrs(); | 1025 impl().weak_factory.InvalidateWeakPtrs(); |
| 1031 // We need to explicitly shutdown the notifier to destroy any weakptrs it is | 1026 // We need to explicitly shutdown the notifier to destroy any weakptrs it is |
| 1032 // holding while still on the compositor thread. This also ensures any | 1027 // holding while still on the compositor thread. This also ensures any |
| 1033 // callbacks holding a ThreadProxy pointer are cancelled. | 1028 // callbacks holding a ThreadProxy pointer are cancelled. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1117 void ThreadProxy::PostDelayedAnimationTaskOnImplThread( | 1112 void ThreadProxy::PostDelayedAnimationTaskOnImplThread( |
| 1118 const base::Closure& task, | 1113 const base::Closure& task, |
| 1119 base::TimeDelta delay) { | 1114 base::TimeDelta delay) { |
| 1120 Proxy::ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE, task, delay); | 1115 Proxy::ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE, task, delay); |
| 1121 } | 1116 } |
| 1122 | 1117 |
| 1123 void ThreadProxy::DidActivateSyncTree() { | 1118 void ThreadProxy::DidActivateSyncTree() { |
| 1124 TRACE_EVENT0("cc", "ThreadProxy::DidActivateSyncTreeOnImplThread"); | 1119 TRACE_EVENT0("cc", "ThreadProxy::DidActivateSyncTreeOnImplThread"); |
| 1125 DCHECK(IsImplThread()); | 1120 DCHECK(IsImplThread()); |
| 1126 | 1121 |
| 1127 if (impl().completion_event_for_commit_held_on_tree_activation) { | 1122 if (impl().next_commit_waits_for_activation) { |
| 1128 TRACE_EVENT_INSTANT0( | 1123 TRACE_EVENT_INSTANT0( |
| 1129 "cc", "ReleaseCommitbyActivation", TRACE_EVENT_SCOPE_THREAD); | 1124 "cc", "ReleaseCommitbyActivation", TRACE_EVENT_SCOPE_THREAD); |
| 1130 impl().completion_event_for_commit_held_on_tree_activation->Signal(); | 1125 DCHECK(impl().commit_completion_event); |
| 1131 impl().completion_event_for_commit_held_on_tree_activation = nullptr; | 1126 impl().commit_completion_event->Signal(); |
| 1127 impl().commit_completion_event = nullptr; | |
| 1128 impl().next_commit_waits_for_activation = false; | |
| 1132 } | 1129 } |
| 1133 | 1130 |
| 1134 impl().last_processed_begin_main_frame_args = | 1131 impl().last_processed_begin_main_frame_args = |
| 1135 impl().last_begin_main_frame_args; | 1132 impl().last_begin_main_frame_args; |
| 1136 } | 1133 } |
| 1137 | 1134 |
| 1138 void ThreadProxy::WillPrepareTiles() { | 1135 void ThreadProxy::WillPrepareTiles() { |
| 1139 DCHECK(IsImplThread()); | 1136 DCHECK(IsImplThread()); |
| 1140 impl().scheduler->WillPrepareTiles(); | 1137 impl().scheduler->WillPrepareTiles(); |
| 1141 } | 1138 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1188 | 1185 |
| 1189 base::WeakPtr<ProxyMain> ThreadProxy::GetMainWeakPtr() { | 1186 base::WeakPtr<ProxyMain> ThreadProxy::GetMainWeakPtr() { |
| 1190 return main_thread_weak_ptr_; | 1187 return main_thread_weak_ptr_; |
| 1191 } | 1188 } |
| 1192 | 1189 |
| 1193 base::WeakPtr<ProxyImpl> ThreadProxy::GetImplWeakPtr() { | 1190 base::WeakPtr<ProxyImpl> ThreadProxy::GetImplWeakPtr() { |
| 1194 return impl_thread_weak_ptr_; | 1191 return impl_thread_weak_ptr_; |
| 1195 } | 1192 } |
| 1196 | 1193 |
| 1197 } // namespace cc | 1194 } // namespace cc |
| OLD | NEW |