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

Side by Side Diff: cc/trees/thread_proxy.cc

Issue 1418953002: cc: Send shared variables between main and impl side using the channel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/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
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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 main().channel_main->SetNeedsRedrawOnImpl(damage_rect); 393 main().channel_main->SetNeedsRedrawOnImpl(damage_rect);
396 } 394 }
397 395
398 void ThreadProxy::SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) { 396 void ThreadProxy::SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) {
399 DCHECK(IsImplThread()); 397 DCHECK(IsImplThread());
400 SetNeedsRedrawRectOnImplThread(damage_rect); 398 SetNeedsRedrawRectOnImplThread(damage_rect);
401 } 399 }
402 400
403 void ThreadProxy::SetNextCommitWaitsForActivation() { 401 void ThreadProxy::SetNextCommitWaitsForActivation() {
404 DCHECK(IsMainThread()); 402 DCHECK(IsMainThread());
405 DCHECK(!blocked_main().main_thread_inside_commit); 403 main().commit_waits_for_activation = true;
406 blocked_main().commit_waits_for_activation = true;
407 } 404 }
408 405
409 void ThreadProxy::SetDeferCommits(bool defer_commits) { 406 void ThreadProxy::SetDeferCommits(bool defer_commits) {
410 DCHECK(IsMainThread()); 407 DCHECK(IsMainThread());
411 if (main().defer_commits == defer_commits) 408 if (main().defer_commits == defer_commits)
412 return; 409 return;
413 410
414 main().defer_commits = defer_commits; 411 main().defer_commits = defer_commits;
415 if (main().defer_commits) 412 if (main().defer_commits)
416 TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::SetDeferCommits", this); 413 TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::SetDeferCommits", this);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 475
479 void ThreadProxy::SetInputThrottledUntilCommitOnImpl(bool is_throttled) { 476 void ThreadProxy::SetInputThrottledUntilCommitOnImpl(bool is_throttled) {
480 DCHECK(IsImplThread()); 477 DCHECK(IsImplThread());
481 if (is_throttled == impl().input_throttled_until_commit) 478 if (is_throttled == impl().input_throttled_until_commit)
482 return; 479 return;
483 impl().input_throttled_until_commit = is_throttled; 480 impl().input_throttled_until_commit = is_throttled;
484 RenewTreePriority(); 481 RenewTreePriority();
485 } 482 }
486 483
487 LayerTreeHost* ThreadProxy::layer_tree_host() { 484 LayerTreeHost* ThreadProxy::layer_tree_host() {
488 return blocked_main().layer_tree_host; 485 return main().layer_tree_host;
489 } 486 }
490 487
491 const LayerTreeHost* ThreadProxy::layer_tree_host() const { 488 const LayerTreeHost* ThreadProxy::layer_tree_host() const {
492 return blocked_main().layer_tree_host; 489 return main().layer_tree_host;
493 } 490 }
494 491
495 ThreadProxy::MainThreadOnly& ThreadProxy::main() { 492 ThreadProxy::MainThreadOnly& ThreadProxy::main() {
496 DCHECK(IsMainThread()); 493 DCHECK(IsMainThread());
497 return main_thread_only_vars_unsafe_; 494 return main_thread_only_vars_unsafe_;
498 } 495 }
499 const ThreadProxy::MainThreadOnly& ThreadProxy::main() const { 496 const ThreadProxy::MainThreadOnly& ThreadProxy::main() const {
500 DCHECK(IsMainThread()); 497 DCHECK(IsMainThread());
501 return main_thread_only_vars_unsafe_; 498 return main_thread_only_vars_unsafe_;
502 } 499 }
503 500
504 ThreadProxy::MainThreadOrBlockedMainThread& ThreadProxy::blocked_main() { 501 ThreadProxy::BlockedMainCommitOnly& ThreadProxy::blocked_main_commit() {
505 DCHECK(IsMainThread() || IsMainThreadBlocked()); 502 DCHECK(IsMainThreadBlocked() && impl().commit_completion_event);
506 return main_thread_or_blocked_vars_unsafe_; 503 return main_thread_blocked_commit_vars_unsafe_;
507 }
508
509 const ThreadProxy::MainThreadOrBlockedMainThread& ThreadProxy::blocked_main()
510 const {
511 DCHECK(IsMainThread() || IsMainThreadBlocked());
512 return main_thread_or_blocked_vars_unsafe_;
513 } 504 }
514 505
515 ThreadProxy::CompositorThreadOnly& ThreadProxy::impl() { 506 ThreadProxy::CompositorThreadOnly& ThreadProxy::impl() {
516 DCHECK(IsImplThread()); 507 DCHECK(IsImplThread());
517 return compositor_thread_vars_unsafe_; 508 return compositor_thread_vars_unsafe_;
518 } 509 }
519 510
520 const ThreadProxy::CompositorThreadOnly& ThreadProxy::impl() const { 511 const ThreadProxy::CompositorThreadOnly& ThreadProxy::impl() const {
521 DCHECK(IsImplThread()); 512 DCHECK(IsImplThread());
522 return compositor_thread_vars_unsafe_; 513 return compositor_thread_vars_unsafe_;
523 } 514 }
524 515
525 void ThreadProxy::Start() { 516 void ThreadProxy::Start() {
526 DCHECK(IsMainThread()); 517 DCHECK(IsMainThread());
527 DCHECK(Proxy::HasImplThread()); 518 DCHECK(Proxy::HasImplThread());
528 519
529 // Create LayerTreeHostImpl. 520 // Create LayerTreeHostImpl.
530 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 521 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
531 CompletionEvent completion; 522 CompletionEvent completion;
532 Proxy::ImplThreadTaskRunner()->PostTask( 523 main().channel_main->InitializeImplOnImpl(&completion, layer_tree_host());
533 FROM_HERE,
534 base::Bind(&ThreadProxy::InitializeImplOnImplThread,
535 base::Unretained(this),
536 &completion));
537 completion.Wait(); 524 completion.Wait();
538 525
539 main_thread_weak_ptr_ = main().weak_factory.GetWeakPtr(); 526 main_thread_weak_ptr_ = main().weak_factory.GetWeakPtr();
540 527
541 main().started = true; 528 main().started = true;
542 } 529 }
543 530
544 void ThreadProxy::Stop() { 531 void ThreadProxy::Stop() {
545 TRACE_EVENT0("cc", "ThreadProxy::Stop"); 532 TRACE_EVENT0("cc", "ThreadProxy::Stop");
546 DCHECK(IsMainThread()); 533 DCHECK(IsMainThread());
547 DCHECK(main().started); 534 DCHECK(main().started);
548 535
549 // Synchronously finishes pending GL operations and deletes the impl. 536 // Synchronously finishes pending GL operations and deletes the impl.
550 // The two steps are done as separate post tasks, so that tasks posted 537 // The two steps are done as separate post tasks, so that tasks posted
551 // by the GL implementation due to the Finish can be executed by the 538 // by the GL implementation due to the Finish can be executed by the
552 // renderer before shutting it down. 539 // renderer before shutting it down.
553 { 540 {
554 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 541 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
555 CompletionEvent completion; 542 CompletionEvent completion;
556 main().channel_main->FinishGLOnImpl(&completion); 543 main().channel_main->FinishGLOnImpl(&completion);
557 completion.Wait(); 544 completion.Wait();
558 } 545 }
559 { 546 {
560 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 547 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
561 548
562 CompletionEvent completion; 549 CompletionEvent completion;
563 Proxy::ImplThreadTaskRunner()->PostTask( 550 main().channel_main->LayerTreeHostClosedOnImpl(&completion);
564 FROM_HERE,
565 base::Bind(&ThreadProxy::LayerTreeHostClosedOnImplThread,
566 impl_thread_weak_ptr_,
567 &completion));
568 completion.Wait(); 551 completion.Wait();
569 } 552 }
570 553
571 main().weak_factory.InvalidateWeakPtrs(); 554 main().weak_factory.InvalidateWeakPtrs();
572 blocked_main().layer_tree_host = NULL; 555 main().layer_tree_host = nullptr;
573 main().started = false; 556 main().started = false;
574 } 557 }
575 558
576 bool ThreadProxy::SupportsImplScrolling() const { 559 bool ThreadProxy::SupportsImplScrolling() const {
577 return true; 560 return true;
578 } 561 }
579 562
580 void ThreadProxy::FinishAllRenderingOnImpl(CompletionEvent* completion) { 563 void ThreadProxy::FinishAllRenderingOnImpl(CompletionEvent* completion) {
581 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread"); 564 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread");
582 DCHECK(IsImplThread()); 565 DCHECK(IsImplThread());
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame::commit"); 691 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame::commit");
709 692
710 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 693 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
711 694
712 // This CapturePostTasks should be destroyed before CommitComplete() is 695 // This CapturePostTasks should be destroyed before CommitComplete() is
713 // called since that goes out to the embedder, and we want the embedder 696 // called since that goes out to the embedder, and we want the embedder
714 // to receive its callbacks before that. 697 // to receive its callbacks before that.
715 BlockingTaskRunner::CapturePostTasks blocked( 698 BlockingTaskRunner::CapturePostTasks blocked(
716 blocking_main_thread_task_runner()); 699 blocking_main_thread_task_runner());
717 700
701 bool hold_commit_for_activation = main().commit_waits_for_activation;
702 main().commit_waits_for_activation = false;
718 CompletionEvent completion; 703 CompletionEvent completion;
719 main().channel_main->StartCommitOnImpl(&completion); 704 main().channel_main->StartCommitOnImpl(&completion, layer_tree_host(),
705 hold_commit_for_activation);
720 completion.Wait(); 706 completion.Wait();
721 } 707 }
722 708
723 main().current_pipeline_stage = NO_PIPELINE_STAGE; 709 main().current_pipeline_stage = NO_PIPELINE_STAGE;
724 layer_tree_host()->CommitComplete(); 710 layer_tree_host()->CommitComplete();
725 layer_tree_host()->DidBeginMainFrame(); 711 layer_tree_host()->DidBeginMainFrame();
726 } 712 }
727 713
728 void ThreadProxy::BeginMainFrameNotExpectedSoon() { 714 void ThreadProxy::BeginMainFrameNotExpectedSoon() {
729 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrameNotExpectedSoon"); 715 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrameNotExpectedSoon");
730 DCHECK(IsMainThread()); 716 DCHECK(IsMainThread());
731 layer_tree_host()->BeginMainFrameNotExpectedSoon(); 717 layer_tree_host()->BeginMainFrameNotExpectedSoon();
732 } 718 }
733 719
734 void ThreadProxy::StartCommitOnImpl(CompletionEvent* completion) { 720 void ThreadProxy::StartCommitOnImpl(CompletionEvent* completion,
721 LayerTreeHost* layer_tree_host,
722 bool hold_commit_for_activation) {
735 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread"); 723 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread");
736 DCHECK(!impl().commit_completion_event); 724 DCHECK(!impl().commit_completion_event);
737 DCHECK(IsImplThread() && IsMainThreadBlocked()); 725 DCHECK(IsImplThread() && IsMainThreadBlocked());
738 DCHECK(impl().scheduler); 726 DCHECK(impl().scheduler);
739 DCHECK(impl().scheduler->CommitPending()); 727 DCHECK(impl().scheduler->CommitPending());
740 728
729 if (hold_commit_for_activation) {
730 // This commit may be aborted. Store the value for
731 // hold_commit_for_activation so that whenever the next commit is started,
732 // the main thread will be unblocked only after pending tree activation.
733 impl().next_commit_waits_for_activation = hold_commit_for_activation;
734 }
735
741 if (!impl().layer_tree_host_impl) { 736 if (!impl().layer_tree_host_impl) {
742 TRACE_EVENT_INSTANT0( 737 TRACE_EVENT_INSTANT0(
743 "cc", "EarlyOut_NoLayerTree", TRACE_EVENT_SCOPE_THREAD); 738 "cc", "EarlyOut_NoLayerTree", TRACE_EVENT_SCOPE_THREAD);
744 completion->Signal(); 739 completion->Signal();
745 return; 740 return;
746 } 741 }
747 742
748 // Ideally, we should inform to impl thread when BeginMainFrame is started. 743 // Ideally, we should inform to impl thread when BeginMainFrame is started.
749 // But, we can avoid a PostTask in here. 744 // But, we can avoid a PostTask in here.
750 impl().scheduler->NotifyBeginMainFrameStarted(); 745 impl().scheduler->NotifyBeginMainFrameStarted();
751 impl().commit_completion_event = completion; 746 impl().commit_completion_event = completion;
747 DCHECK(!blocked_main_commit().layer_tree_host);
748 blocked_main_commit().layer_tree_host = layer_tree_host;
752 impl().scheduler->NotifyReadyToCommit(); 749 impl().scheduler->NotifyReadyToCommit();
753 } 750 }
754 751
755 void ThreadProxy::BeginMainFrameAbortedOnImpl(CommitEarlyOutReason reason) { 752 void ThreadProxy::BeginMainFrameAbortedOnImpl(CommitEarlyOutReason reason) {
756 TRACE_EVENT1("cc", "ThreadProxy::BeginMainFrameAbortedOnImplThread", "reason", 753 TRACE_EVENT1("cc", "ThreadProxy::BeginMainFrameAbortedOnImplThread", "reason",
757 CommitEarlyOutReasonToString(reason)); 754 CommitEarlyOutReasonToString(reason));
758 DCHECK(IsImplThread()); 755 DCHECK(IsImplThread());
759 DCHECK(impl().scheduler); 756 DCHECK(impl().scheduler);
760 DCHECK(impl().scheduler->CommitPending()); 757 DCHECK(impl().scheduler->CommitPending());
761 DCHECK(!impl().layer_tree_host_impl->pending_tree()); 758 DCHECK(!impl().layer_tree_host_impl->pending_tree());
(...skipping 12 matching lines...) Expand all
774 DCHECK(IsImplThread()); 771 DCHECK(IsImplThread());
775 772
776 impl().layer_tree_host_impl->Animate(); 773 impl().layer_tree_host_impl->Animate();
777 } 774 }
778 775
779 void ThreadProxy::ScheduledActionCommit() { 776 void ThreadProxy::ScheduledActionCommit() {
780 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionCommit"); 777 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionCommit");
781 DCHECK(IsImplThread()); 778 DCHECK(IsImplThread());
782 DCHECK(IsMainThreadBlocked()); 779 DCHECK(IsMainThreadBlocked());
783 DCHECK(impl().commit_completion_event); 780 DCHECK(impl().commit_completion_event);
781 DCHECK(blocked_main_commit().layer_tree_host);
784 782
785 blocked_main().main_thread_inside_commit = true;
786 impl().layer_tree_host_impl->BeginCommit(); 783 impl().layer_tree_host_impl->BeginCommit();
787 layer_tree_host()->FinishCommitOnImplThread( 784 blocked_main_commit().layer_tree_host->FinishCommitOnImplThread(
788 impl().layer_tree_host_impl.get()); 785 impl().layer_tree_host_impl.get());
789 blocked_main().main_thread_inside_commit = false;
790 786
791 bool hold_commit = blocked_main().commit_waits_for_activation; 787 // Remove the LayerTreeHost reference before the completion event is signaled.
792 blocked_main().commit_waits_for_activation = false; 788 blocked_main_commit().layer_tree_host = nullptr;
793 789
794 if (hold_commit) { 790 if (impl().next_commit_waits_for_activation) {
795 // For some layer types in impl-side painting, the commit is held until 791 // For some layer types in impl-side painting, the commit is held until
796 // the sync tree is activated. It's also possible that the 792 // the sync tree is activated. It's also possible that the
797 // sync tree has already activated if there was no work to be done. 793 // sync tree has already activated if there was no work to be done.
798 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD); 794 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD);
799 impl().completion_event_for_commit_held_on_tree_activation =
800 impl().commit_completion_event;
801 impl().commit_completion_event = nullptr;
802 } else { 795 } else {
803 impl().commit_completion_event->Signal(); 796 impl().commit_completion_event->Signal();
804 impl().commit_completion_event = nullptr; 797 impl().commit_completion_event = nullptr;
805 } 798 }
806 799
807 impl().scheduler->DidCommit(); 800 impl().scheduler->DidCommit();
808 801
809 // Delay this step until afer the main thread has been released as it's 802 // Delay this step until afer the main thread has been released as it's
810 // often a good bit of work to update the tree and prepare the new frame. 803 // often a good bit of work to update the tree and prepare the new frame.
811 impl().layer_tree_host_impl->CommitComplete(); 804 impl().layer_tree_host_impl->CommitComplete();
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 DCHECK(IsMainThread()); 931 DCHECK(IsMainThread());
939 layer_tree_host()->DidCompleteSwapBuffers(); 932 layer_tree_host()->DidCompleteSwapBuffers();
940 } 933 }
941 934
942 void ThreadProxy::SetAnimationEvents(scoped_ptr<AnimationEventsVector> events) { 935 void ThreadProxy::SetAnimationEvents(scoped_ptr<AnimationEventsVector> events) {
943 TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents"); 936 TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents");
944 DCHECK(IsMainThread()); 937 DCHECK(IsMainThread());
945 layer_tree_host()->SetAnimationEvents(events.Pass()); 938 layer_tree_host()->SetAnimationEvents(events.Pass());
946 } 939 }
947 940
948 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { 941 void ThreadProxy::InitializeImplOnImpl(CompletionEvent* completion,
942 LayerTreeHost* layer_tree_host) {
949 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); 943 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread");
950 DCHECK(IsImplThread()); 944 DCHECK(IsImplThread());
945 DCHECK(IsMainThreadBlocked());
946 DCHECK(layer_tree_host);
951 947
952 // TODO(khushalsagar): ThreadedChannel will create ProxyImpl here and pass a 948 // TODO(khushalsagar): ThreadedChannel will create ProxyImpl here and pass a
953 // reference to itself. 949 // reference to itself.
954 impl().channel_impl = threaded_channel_.get(); 950 impl().channel_impl = threaded_channel_.get();
955 951
956 impl().layer_tree_host_impl = 952 impl().layer_tree_host_impl = layer_tree_host->CreateLayerTreeHostImpl(this);
957 layer_tree_host()->CreateLayerTreeHostImpl(this);
958 953
959 SchedulerSettings scheduler_settings( 954 SchedulerSettings scheduler_settings(
960 layer_tree_host()->settings().ToSchedulerSettings()); 955 layer_tree_host->settings().ToSchedulerSettings());
961 956
962 scoped_ptr<CompositorTimingHistory> compositor_timing_history( 957 scoped_ptr<CompositorTimingHistory> compositor_timing_history(
963 new CompositorTimingHistory(CompositorTimingHistory::RENDERER_UMA, 958 new CompositorTimingHistory(CompositorTimingHistory::RENDERER_UMA,
964 impl().rendering_stats_instrumentation)); 959 impl().rendering_stats_instrumentation));
965 960
966 impl().scheduler = Scheduler::Create( 961 impl().scheduler = Scheduler::Create(
967 this, scheduler_settings, impl().layer_tree_host_id, 962 this, scheduler_settings, impl().layer_tree_host_id,
968 ImplThreadTaskRunner(), impl().external_begin_frame_source.get(), 963 ImplThreadTaskRunner(), impl().external_begin_frame_source.get(),
969 compositor_timing_history.Pass()); 964 compositor_timing_history.Pass());
970 965
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 DCHECK(IsImplThread()); 1002 DCHECK(IsImplThread());
1008 if (impl().layer_tree_host_impl->output_surface()) { 1003 if (impl().layer_tree_host_impl->output_surface()) {
1009 ContextProvider* context_provider = 1004 ContextProvider* context_provider =
1010 impl().layer_tree_host_impl->output_surface()->context_provider(); 1005 impl().layer_tree_host_impl->output_surface()->context_provider();
1011 if (context_provider) 1006 if (context_provider)
1012 context_provider->ContextGL()->Finish(); 1007 context_provider->ContextGL()->Finish();
1013 } 1008 }
1014 completion->Signal(); 1009 completion->Signal();
1015 } 1010 }
1016 1011
1017 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) { 1012 void ThreadProxy::LayerTreeHostClosedOnImpl(CompletionEvent* completion) {
1018 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread"); 1013 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread");
1019 DCHECK(IsImplThread()); 1014 DCHECK(IsImplThread());
1020 DCHECK(IsMainThreadBlocked()); 1015 DCHECK(IsMainThreadBlocked());
1021 impl().scheduler = nullptr; 1016 impl().scheduler = nullptr;
1022 impl().external_begin_frame_source = nullptr; 1017 impl().external_begin_frame_source = nullptr;
1023 impl().layer_tree_host_impl = nullptr; 1018 impl().layer_tree_host_impl = nullptr;
1024 impl().weak_factory.InvalidateWeakPtrs(); 1019 impl().weak_factory.InvalidateWeakPtrs();
1025 // We need to explicitly shutdown the notifier to destroy any weakptrs it is 1020 // We need to explicitly shutdown the notifier to destroy any weakptrs it is
1026 // holding while still on the compositor thread. This also ensures any 1021 // holding while still on the compositor thread. This also ensures any
1027 // callbacks holding a ThreadProxy pointer are cancelled. 1022 // callbacks holding a ThreadProxy pointer are cancelled.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 void ThreadProxy::PostDelayedAnimationTaskOnImplThread( 1106 void ThreadProxy::PostDelayedAnimationTaskOnImplThread(
1112 const base::Closure& task, 1107 const base::Closure& task,
1113 base::TimeDelta delay) { 1108 base::TimeDelta delay) {
1114 Proxy::ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE, task, delay); 1109 Proxy::ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE, task, delay);
1115 } 1110 }
1116 1111
1117 void ThreadProxy::DidActivateSyncTree() { 1112 void ThreadProxy::DidActivateSyncTree() {
1118 TRACE_EVENT0("cc", "ThreadProxy::DidActivateSyncTreeOnImplThread"); 1113 TRACE_EVENT0("cc", "ThreadProxy::DidActivateSyncTreeOnImplThread");
1119 DCHECK(IsImplThread()); 1114 DCHECK(IsImplThread());
1120 1115
1121 if (impl().completion_event_for_commit_held_on_tree_activation) { 1116 if (impl().next_commit_waits_for_activation) {
1122 TRACE_EVENT_INSTANT0( 1117 TRACE_EVENT_INSTANT0(
1123 "cc", "ReleaseCommitbyActivation", TRACE_EVENT_SCOPE_THREAD); 1118 "cc", "ReleaseCommitbyActivation", TRACE_EVENT_SCOPE_THREAD);
1124 impl().completion_event_for_commit_held_on_tree_activation->Signal(); 1119 DCHECK(impl().commit_completion_event);
1125 impl().completion_event_for_commit_held_on_tree_activation = nullptr; 1120 impl().commit_completion_event->Signal();
1121 impl().commit_completion_event = nullptr;
1122 impl().next_commit_waits_for_activation = false;
1126 } 1123 }
1127 1124
1128 impl().last_processed_begin_main_frame_args = 1125 impl().last_processed_begin_main_frame_args =
1129 impl().last_begin_main_frame_args; 1126 impl().last_begin_main_frame_args;
1130 } 1127 }
1131 1128
1132 void ThreadProxy::WillPrepareTiles() { 1129 void ThreadProxy::WillPrepareTiles() {
1133 DCHECK(IsImplThread()); 1130 DCHECK(IsImplThread());
1134 impl().scheduler->WillPrepareTiles(); 1131 impl().scheduler->WillPrepareTiles();
1135 } 1132 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 1179
1183 base::WeakPtr<ProxyMain> ThreadProxy::GetMainWeakPtr() { 1180 base::WeakPtr<ProxyMain> ThreadProxy::GetMainWeakPtr() {
1184 return main_thread_weak_ptr_; 1181 return main_thread_weak_ptr_;
1185 } 1182 }
1186 1183
1187 base::WeakPtr<ProxyImpl> ThreadProxy::GetImplWeakPtr() { 1184 base::WeakPtr<ProxyImpl> ThreadProxy::GetImplWeakPtr() {
1188 return impl_thread_weak_ptr_; 1185 return impl_thread_weak_ptr_;
1189 } 1186 }
1190 1187
1191 } // namespace cc 1188 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698