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

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

Issue 2150533004: cc: Send all begin frames using a PostTask. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scheduler_unittest_no_deadline
Patch Set: Created 4 years, 5 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/single_thread_proxy.h" 5 #include "cc/trees/single_thread_proxy.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/profiler/scoped_tracker.h" 9 #include "base/profiler/scoped_tracker.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 scheduler_settings.using_synchronous_renderer_compositor, 73 scheduler_settings.using_synchronous_renderer_compositor,
74 CompositorTimingHistory::BROWSER_UMA, 74 CompositorTimingHistory::BROWSER_UMA,
75 layer_tree_host_->rendering_stats_instrumentation())); 75 layer_tree_host_->rendering_stats_instrumentation()));
76 76
77 BeginFrameSource* frame_source = nullptr; 77 BeginFrameSource* frame_source = nullptr;
78 if (!layer_tree_host_->settings().use_output_surface_begin_frame_source) { 78 if (!layer_tree_host_->settings().use_output_surface_begin_frame_source) {
79 frame_source = external_begin_frame_source_.get(); 79 frame_source = external_begin_frame_source_.get();
80 if (!scheduler_settings.throttle_frame_production) { 80 if (!scheduler_settings.throttle_frame_production) {
81 // Unthrottled source takes precedence over external sources. 81 // Unthrottled source takes precedence over external sources.
82 unthrottled_begin_frame_source_.reset(new BackToBackBeginFrameSource( 82 unthrottled_begin_frame_source_.reset(new BackToBackBeginFrameSource(
83 base::MakeUnique<DelayBasedTimeSource>( 83 task_runner_provider_->MainThreadTaskRunner()));
84 task_runner_provider_->MainThreadTaskRunner())));
85 frame_source = unthrottled_begin_frame_source_.get(); 84 frame_source = unthrottled_begin_frame_source_.get();
86 } 85 }
87 if (!frame_source) { 86 if (!frame_source) {
88 synthetic_begin_frame_source_.reset(new DelayBasedBeginFrameSource( 87 synthetic_begin_frame_source_.reset(new DelayBasedBeginFrameSource(
89 base::MakeUnique<DelayBasedTimeSource>( 88 task_runner_provider_->MainThreadTaskRunner()));
90 task_runner_provider_->MainThreadTaskRunner())));
91 frame_source = synthetic_begin_frame_source_.get(); 89 frame_source = synthetic_begin_frame_source_.get();
92 } 90 }
93 } 91 }
94 92
95 scheduler_on_impl_thread_ = 93 scheduler_on_impl_thread_ =
96 Scheduler::Create(this, scheduler_settings, layer_tree_host_->id(), 94 Scheduler::Create(this, scheduler_settings, layer_tree_host_->id(),
97 task_runner_provider_->MainThreadTaskRunner(), 95 task_runner_provider_->MainThreadTaskRunner(),
98 frame_source, std::move(compositor_timing_history)); 96 frame_source, std::move(compositor_timing_history));
99 } 97 }
100 98
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 layer_tree_host_ = NULL; 368 layer_tree_host_ = NULL;
371 } 369 }
372 370
373 void SingleThreadProxy::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) { 371 void SingleThreadProxy::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) {
374 DCHECK(task_runner_provider_->IsMainThread()); 372 DCHECK(task_runner_provider_->IsMainThread());
375 DebugScopedSetImplThread impl(task_runner_provider_); 373 DebugScopedSetImplThread impl(task_runner_provider_);
376 layer_tree_host_impl_->SetLayerTreeMutator(std::move(mutator)); 374 layer_tree_host_impl_->SetLayerTreeMutator(std::move(mutator));
377 } 375 }
378 376
379 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { 377 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
380 TRACE_EVENT1( 378 TRACE_EVENT1("cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw",
381 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); 379 can_draw);
382 DCHECK(task_runner_provider_->IsImplThread()); 380 DCHECK(task_runner_provider_->IsImplThread());
383 if (scheduler_on_impl_thread_) 381 if (scheduler_on_impl_thread_)
384 scheduler_on_impl_thread_->SetCanDraw(can_draw); 382 scheduler_on_impl_thread_->SetCanDraw(can_draw);
385 } 383 }
386 384
387 void SingleThreadProxy::NotifyReadyToActivate() { 385 void SingleThreadProxy::NotifyReadyToActivate() {
388 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate"); 386 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate");
389 DebugScopedSetImplThread impl(task_runner_provider_); 387 DebugScopedSetImplThread impl(task_runner_provider_);
390 if (scheduler_on_impl_thread_) 388 if (scheduler_on_impl_thread_)
391 scheduler_on_impl_thread_->NotifyReadyToActivate(); 389 scheduler_on_impl_thread_->NotifyReadyToActivate();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 438
441 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( 439 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
442 std::unique_ptr<AnimationEvents> events) { 440 std::unique_ptr<AnimationEvents> events) {
443 TRACE_EVENT0( 441 TRACE_EVENT0(
444 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); 442 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
445 DCHECK(task_runner_provider_->IsImplThread()); 443 DCHECK(task_runner_provider_->IsImplThread());
446 DebugScopedSetMainThread main(task_runner_provider_); 444 DebugScopedSetMainThread main(task_runner_provider_);
447 layer_tree_host_->SetAnimationEvents(std::move(events)); 445 layer_tree_host_->SetAnimationEvents(std::move(events));
448 } 446 }
449 447
450 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } 448 bool SingleThreadProxy::IsInsideDraw() {
449 return inside_draw_;
450 }
451 451
452 void SingleThreadProxy::DidActivateSyncTree() { 452 void SingleThreadProxy::DidActivateSyncTree() {
453 // Synchronously call to CommitComplete. Resetting 453 // Synchronously call to CommitComplete. Resetting
454 // |commit_blocking_task_runner| would make sure all tasks posted during 454 // |commit_blocking_task_runner| would make sure all tasks posted during
455 // commit/activation before CommitComplete. 455 // commit/activation before CommitComplete.
456 CommitComplete(); 456 CommitComplete();
457 } 457 }
458 458
459 void SingleThreadProxy::WillPrepareTiles() { 459 void SingleThreadProxy::WillPrepareTiles() {
460 DCHECK(task_runner_provider_->IsImplThread()); 460 DCHECK(task_runner_provider_->IsImplThread());
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 DidFinishImplFrame(); 593 DidFinishImplFrame();
594 } 594 }
595 } 595 }
596 596
597 bool SingleThreadProxy::SupportsImplScrolling() const { 597 bool SingleThreadProxy::SupportsImplScrolling() const {
598 return false; 598 return false;
599 } 599 }
600 600
601 bool SingleThreadProxy::ShouldComposite() const { 601 bool SingleThreadProxy::ShouldComposite() const {
602 DCHECK(task_runner_provider_->IsImplThread()); 602 DCHECK(task_runner_provider_->IsImplThread());
603 return layer_tree_host_impl_->visible() && 603 return layer_tree_host_impl_->visible() && layer_tree_host_impl_->CanDraw();
604 layer_tree_host_impl_->CanDraw();
605 } 604 }
606 605
607 void SingleThreadProxy::ScheduleRequestNewOutputSurface() { 606 void SingleThreadProxy::ScheduleRequestNewOutputSurface() {
608 if (output_surface_creation_callback_.IsCancelled() && 607 if (output_surface_creation_callback_.IsCancelled() &&
609 !output_surface_creation_requested_) { 608 !output_surface_creation_requested_) {
610 output_surface_creation_callback_.Reset( 609 output_surface_creation_callback_.Reset(
611 base::Bind(&SingleThreadProxy::RequestNewOutputSurface, 610 base::Bind(&SingleThreadProxy::RequestNewOutputSurface,
612 weak_factory_.GetWeakPtr())); 611 weak_factory_.GetWeakPtr()));
613 task_runner_provider_->MainThreadTaskRunner()->PostTask( 612 task_runner_provider_->MainThreadTaskRunner()->PostTask(
614 FROM_HERE, output_surface_creation_callback_.callback()); 613 FROM_HERE, output_surface_creation_callback_.callback());
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 DCHECK(!inside_impl_frame_) 729 DCHECK(!inside_impl_frame_)
731 << "WillBeginImplFrame called while already inside an impl frame!"; 730 << "WillBeginImplFrame called while already inside an impl frame!";
732 inside_impl_frame_ = true; 731 inside_impl_frame_ = true;
733 #endif 732 #endif
734 layer_tree_host_impl_->WillBeginImplFrame(args); 733 layer_tree_host_impl_->WillBeginImplFrame(args);
735 } 734 }
736 735
737 void SingleThreadProxy::ScheduledActionSendBeginMainFrame( 736 void SingleThreadProxy::ScheduledActionSendBeginMainFrame(
738 const BeginFrameArgs& begin_frame_args) { 737 const BeginFrameArgs& begin_frame_args) {
739 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame"); 738 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame");
740 // Although this proxy is single-threaded, it's problematic to synchronously 739 // Although this proxy is single-threaded, it's problematic to synchronously
741 // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This 740 // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This
742 // could cause a commit to occur in between a series of SetNeedsCommit calls 741 // could cause a commit to occur in between a series of SetNeedsCommit calls
743 // (i.e. property modifications) causing some to fall on one frame and some to 742 // (i.e. property modifications) causing some to fall on one frame and some to
744 // fall on the next. Doing it asynchronously instead matches the semantics of 743 // fall on the next. Doing it asynchronously instead matches the semantics of
745 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a 744 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a
746 // synchronous commit. 745 // synchronous commit.
747 #if DCHECK_IS_ON() 746 #if DCHECK_IS_ON()
748 DCHECK(inside_impl_frame_) 747 DCHECK(inside_impl_frame_)
749 << "BeginMainFrame should only be sent inside a BeginImplFrame"; 748 << "BeginMainFrame should only be sent inside a BeginImplFrame";
750 #endif 749 #endif
751 750
752 task_runner_provider_->MainThreadTaskRunner()->PostTask( 751 task_runner_provider_->MainThreadTaskRunner()->PostTask(
753 FROM_HERE, base::Bind(&SingleThreadProxy::BeginMainFrame, 752 FROM_HERE, base::Bind(&SingleThreadProxy::BeginMainFrame,
754 weak_factory_.GetWeakPtr(), begin_frame_args)); 753 weak_factory_.GetWeakPtr(), begin_frame_args));
755 } 754 }
756 755
(...skipping 23 matching lines...) Expand all
780 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_); 779 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_);
781 780
782 if (!layer_tree_host_->visible()) { 781 if (!layer_tree_host_->visible()) {
783 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); 782 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD);
784 BeginMainFrameAbortedOnImplThread( 783 BeginMainFrameAbortedOnImplThread(
785 CommitEarlyOutReason::ABORTED_NOT_VISIBLE); 784 CommitEarlyOutReason::ABORTED_NOT_VISIBLE);
786 return; 785 return;
787 } 786 }
788 787
789 if (layer_tree_host_->output_surface_lost()) { 788 if (layer_tree_host_->output_surface_lost()) {
790 TRACE_EVENT_INSTANT0( 789 TRACE_EVENT_INSTANT0("cc", "EarlyOut_OutputSurfaceLost",
791 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); 790 TRACE_EVENT_SCOPE_THREAD);
792 BeginMainFrameAbortedOnImplThread( 791 BeginMainFrameAbortedOnImplThread(
793 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST); 792 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST);
794 return; 793 return;
795 } 794 }
796 795
797 // Prevent new commits from being requested inside DoBeginMainFrame. 796 // Prevent new commits from being requested inside DoBeginMainFrame.
798 // Note: We do not want to prevent SetNeedsAnimate from requesting 797 // Note: We do not want to prevent SetNeedsAnimate from requesting
799 // a commit here. 798 // a commit here.
800 commit_requested_ = true; 799 commit_requested_ = true;
801 800
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 void SingleThreadProxy::DidFinishImplFrame() { 884 void SingleThreadProxy::DidFinishImplFrame() {
886 layer_tree_host_impl_->DidFinishImplFrame(); 885 layer_tree_host_impl_->DidFinishImplFrame();
887 #if DCHECK_IS_ON() 886 #if DCHECK_IS_ON()
888 DCHECK(inside_impl_frame_) 887 DCHECK(inside_impl_frame_)
889 << "DidFinishImplFrame called while not inside an impl frame!"; 888 << "DidFinishImplFrame called while not inside an impl frame!";
890 inside_impl_frame_ = false; 889 inside_impl_frame_ = false;
891 #endif 890 #endif
892 } 891 }
893 892
894 } // namespace cc 893 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698