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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 commit_requested_(false), | 69 commit_requested_(false), |
| 70 commit_request_sent_to_impl_thread_(false), | 70 commit_request_sent_to_impl_thread_(false), |
| 71 created_offscreen_context_provider_(false), | 71 created_offscreen_context_provider_(false), |
| 72 layer_tree_host_(layer_tree_host), | 72 layer_tree_host_(layer_tree_host), |
| 73 started_(false), | 73 started_(false), |
| 74 textures_acquired_(true), | 74 textures_acquired_(true), |
| 75 in_composite_and_readback_(false), | 75 in_composite_and_readback_(false), |
| 76 manage_tiles_pending_(false), | 76 manage_tiles_pending_(false), |
| 77 weak_factory_on_impl_thread_(this), | 77 weak_factory_on_impl_thread_(this), |
| 78 weak_factory_(this), | 78 weak_factory_(this), |
| 79 frame_did_draw_(false), | |
| 79 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_(NULL), | 80 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_(NULL), |
| 80 readback_request_on_impl_thread_(NULL), | 81 readback_request_on_impl_thread_(NULL), |
| 81 commit_completion_event_on_impl_thread_(NULL), | 82 commit_completion_event_on_impl_thread_(NULL), |
| 82 completion_event_for_commit_held_on_tree_activation_(NULL), | 83 completion_event_for_commit_held_on_tree_activation_(NULL), |
| 83 texture_acquisition_completion_event_on_impl_thread_(NULL), | 84 texture_acquisition_completion_event_on_impl_thread_(NULL), |
| 84 next_frame_is_newly_committed_frame_on_impl_thread_(false), | 85 next_frame_is_newly_committed_frame_on_impl_thread_(false), |
| 85 throttle_frame_production_( | 86 throttle_frame_production_( |
| 86 layer_tree_host->settings().throttle_frame_production), | 87 layer_tree_host->settings().throttle_frame_production), |
| 87 begin_frame_scheduling_enabled_( | 88 begin_frame_scheduling_enabled_( |
| 88 layer_tree_host->settings().begin_frame_scheduling_enabled), | 89 layer_tree_host->settings().begin_frame_scheduling_enabled), |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 Proxy::MainThreadTaskRunner()->PostTask( | 364 Proxy::MainThreadTaskRunner()->PostTask( |
| 364 FROM_HERE, | 365 FROM_HERE, |
| 365 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); | 366 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); |
| 366 } | 367 } |
| 367 | 368 |
| 368 void ThreadProxy::SetNeedsBeginFrameOnImplThread(bool enable) { | 369 void ThreadProxy::SetNeedsBeginFrameOnImplThread(bool enable) { |
| 369 DCHECK(IsImplThread()); | 370 DCHECK(IsImplThread()); |
| 370 TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginFrameOnImplThread", | 371 TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginFrameOnImplThread", |
| 371 "enable", enable); | 372 "enable", enable); |
| 372 layer_tree_host_impl_->SetNeedsBeginFrame(enable); | 373 layer_tree_host_impl_->SetNeedsBeginFrame(enable); |
| 374 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(!enable); | |
| 373 } | 375 } |
| 374 | 376 |
| 375 void ThreadProxy::BeginFrameOnImplThread(const BeginFrameArgs& args) { | 377 void ThreadProxy::BeginFrameOnImplThread(const BeginFrameArgs& args) { |
| 376 DCHECK(IsImplThread()); | 378 DCHECK(IsImplThread()); |
| 377 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnImplThread"); | 379 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnImplThread"); |
| 380 | |
| 381 base::TimeTicks monotonic_time = | |
| 382 layer_tree_host_impl_->CurrentFrameTimeTicks(); | |
| 383 base::Time wall_clock_time = layer_tree_host_impl_->CurrentFrameTime(); | |
| 384 layer_tree_host_impl_->Animate(monotonic_time, wall_clock_time); | |
| 385 | |
| 386 // Reinitialize for the current frame. | |
| 387 frame_did_draw_ = false; | |
| 388 | |
| 378 scheduler_on_impl_thread_->BeginFrame(args); | 389 scheduler_on_impl_thread_->BeginFrame(args); |
| 379 } | 390 } |
| 380 | 391 |
| 392 void ThreadProxy::DidBeginFrameDeadlineOnImplThread() { | |
| 393 layer_tree_host_impl_->UpdateAnimationState( | |
| 394 frame_did_draw_ || !layer_tree_host_impl_->CanDraw()); | |
|
brianderson
2013/07/10 21:58:04
This makes sure to update animation state when we
| |
| 395 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | |
| 396 } | |
| 397 | |
| 381 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) { | 398 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
| 382 DCHECK(IsImplThread()); | 399 DCHECK(IsImplThread()); |
| 383 TRACE_EVENT1( | 400 TRACE_EVENT1( |
| 384 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); | 401 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); |
| 385 scheduler_on_impl_thread_->SetCanDraw(can_draw); | 402 scheduler_on_impl_thread_->SetCanDraw(can_draw); |
| 386 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( | 403 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( |
| 387 !scheduler_on_impl_thread_->WillDrawIfNeeded()); | 404 !scheduler_on_impl_thread_->WillDrawIfNeeded()); |
| 388 } | 405 } |
| 389 | 406 |
| 390 void ThreadProxy::OnHasPendingTreeStateChanged(bool has_pending_tree) { | 407 void ThreadProxy::OnHasPendingTreeStateChanged(bool has_pending_tree) { |
| 391 DCHECK(IsImplThread()); | 408 DCHECK(IsImplThread()); |
| 392 TRACE_EVENT1("cc", "ThreadProxy::OnHasPendingTreeStateChanged", | 409 TRACE_EVENT1("cc", "ThreadProxy::OnHasPendingTreeStateChanged", |
| 393 "has_pending_tree", has_pending_tree); | 410 "has_pending_tree", has_pending_tree); |
| 394 scheduler_on_impl_thread_->SetHasPendingTree(has_pending_tree); | 411 scheduler_on_impl_thread_->SetHasTrees( |
| 412 has_pending_tree, | |
| 413 layer_tree_host_impl_->active_tree() ? | |
| 414 !layer_tree_host_impl_->active_tree()->root_layer() : true); | |
| 415 | |
| 416 if (!has_pending_tree && !deferred_start_commit_on_impl_thread_.is_null()) { | |
| 417 Proxy::ImplThreadTaskRunner()->PostTask( | |
| 418 FROM_HERE, | |
| 419 deferred_start_commit_on_impl_thread_); | |
| 420 deferred_start_commit_on_impl_thread_.Reset(); | |
| 421 } | |
| 395 } | 422 } |
| 396 | 423 |
| 397 void ThreadProxy::SetNeedsCommitOnImplThread() { | 424 void ThreadProxy::SetNeedsCommitOnImplThread() { |
| 398 DCHECK(IsImplThread()); | 425 DCHECK(IsImplThread()); |
| 399 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread"); | 426 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread"); |
| 400 scheduler_on_impl_thread_->SetNeedsCommit(); | 427 scheduler_on_impl_thread_->SetNeedsCommit(); |
| 401 } | 428 } |
| 402 | 429 |
| 403 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread( | 430 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
| 404 scoped_ptr<AnimationEventsVector> events, | 431 scoped_ptr<AnimationEventsVector> events, |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread"); | 647 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread"); |
| 621 DCHECK(IsImplThread()); | 648 DCHECK(IsImplThread()); |
| 622 layer_tree_host_impl_->FinishAllRendering(); | 649 layer_tree_host_impl_->FinishAllRendering(); |
| 623 completion->Signal(); | 650 completion->Signal(); |
| 624 } | 651 } |
| 625 | 652 |
| 626 void ThreadProxy::ScheduledActionSendBeginFrameToMainThread() { | 653 void ThreadProxy::ScheduledActionSendBeginFrameToMainThread() { |
| 627 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionSendBeginFrameToMainThread"); | 654 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionSendBeginFrameToMainThread"); |
| 628 scoped_ptr<BeginFrameAndCommitState> begin_frame_state( | 655 scoped_ptr<BeginFrameAndCommitState> begin_frame_state( |
| 629 new BeginFrameAndCommitState); | 656 new BeginFrameAndCommitState); |
| 657 | |
| 630 begin_frame_state->monotonic_frame_begin_time = | 658 begin_frame_state->monotonic_frame_begin_time = |
| 631 layer_tree_host_impl_->CurrentPhysicalTimeTicks(); | 659 layer_tree_host_impl_->CurrentPhysicalTimeTicks(); |
| 632 begin_frame_state->scroll_info = | 660 begin_frame_state->scroll_info = |
| 633 layer_tree_host_impl_->ProcessScrollDeltas(); | 661 layer_tree_host_impl_->ProcessScrollDeltas(); |
| 634 | 662 |
| 635 if (!layer_tree_host_impl_->settings().impl_side_painting) { | 663 if (!layer_tree_host_impl_->settings().impl_side_painting) { |
| 636 DCHECK_GT(layer_tree_host_impl_->memory_allocation_limit_bytes(), 0u); | 664 DCHECK_GT(layer_tree_host_impl_->memory_allocation_limit_bytes(), 0u); |
| 637 } | 665 } |
| 666 | |
| 667 | |
| 638 begin_frame_state->memory_allocation_limit_bytes = | 668 begin_frame_state->memory_allocation_limit_bytes = |
| 639 layer_tree_host_impl_->memory_allocation_limit_bytes(); | 669 layer_tree_host_impl_->memory_allocation_limit_bytes(); |
| 640 Proxy::MainThreadTaskRunner()->PostTask( | 670 Proxy::MainThreadTaskRunner()->PostTask( |
| 641 FROM_HERE, | 671 FROM_HERE, |
| 642 base::Bind(&ThreadProxy::BeginFrameOnMainThread, | 672 base::Bind(&ThreadProxy::BeginFrameOnMainThread, |
| 643 main_thread_weak_ptr_, | 673 main_thread_weak_ptr_, |
| 644 base::Passed(&begin_frame_state))); | 674 base::Passed(&begin_frame_state))); |
| 645 | 675 |
| 646 if (begin_frame_sent_to_main_thread_completion_event_on_impl_thread_) { | 676 if (begin_frame_sent_to_main_thread_completion_event_on_impl_thread_) { |
| 647 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_->Signal(); | 677 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_->Signal(); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 775 } | 805 } |
| 776 | 806 |
| 777 layer_tree_host_->CommitComplete(); | 807 layer_tree_host_->CommitComplete(); |
| 778 layer_tree_host_->DidBeginFrame(); | 808 layer_tree_host_->DidBeginFrame(); |
| 779 } | 809 } |
| 780 | 810 |
| 781 void ThreadProxy::StartCommitOnImplThread( | 811 void ThreadProxy::StartCommitOnImplThread( |
| 782 CompletionEvent* completion, | 812 CompletionEvent* completion, |
| 783 ResourceUpdateQueue* raw_queue, | 813 ResourceUpdateQueue* raw_queue, |
| 784 scoped_refptr<cc::ContextProvider> offscreen_context_provider) { | 814 scoped_refptr<cc::ContextProvider> offscreen_context_provider) { |
| 785 scoped_ptr<ResourceUpdateQueue> queue(raw_queue); | |
| 786 | |
| 787 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread"); | 815 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread"); |
| 788 DCHECK(!commit_completion_event_on_impl_thread_); | 816 DCHECK(!commit_completion_event_on_impl_thread_); |
| 789 DCHECK(IsImplThread() && IsMainThreadBlocked()); | 817 DCHECK(IsImplThread() && IsMainThreadBlocked()); |
| 790 DCHECK(scheduler_on_impl_thread_); | 818 DCHECK(scheduler_on_impl_thread_); |
| 791 DCHECK(scheduler_on_impl_thread_->CommitPending()); | 819 DCHECK(scheduler_on_impl_thread_->CommitPending()); |
| 792 | 820 |
| 793 if (!layer_tree_host_impl_) { | 821 if (!layer_tree_host_impl_) { |
| 794 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree"); | 822 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree"); |
| 795 completion->Signal(); | 823 completion->Signal(); |
| 824 | |
| 796 return; | 825 return; |
| 797 } | 826 } |
| 798 | 827 |
| 828 // We defer forced commits while there is a pending tree here. | |
| 829 if (layer_tree_host_impl_->pending_tree()) { | |
| 830 DCHECK(deferred_start_commit_on_impl_thread_.is_null()); | |
| 831 deferred_start_commit_on_impl_thread_ = | |
| 832 base::Bind(&ThreadProxy::StartCommitOnImplThread, | |
| 833 impl_thread_weak_ptr_, | |
| 834 completion, | |
| 835 raw_queue, | |
| 836 offscreen_context_provider); | |
| 837 return; | |
| 838 } | |
| 839 | |
| 840 scoped_ptr<ResourceUpdateQueue> queue(raw_queue); | |
| 841 | |
| 799 if (offscreen_context_provider.get()) | 842 if (offscreen_context_provider.get()) |
| 800 offscreen_context_provider->BindToCurrentThread(); | 843 offscreen_context_provider->BindToCurrentThread(); |
| 801 layer_tree_host_impl_->resource_provider()-> | 844 layer_tree_host_impl_->resource_provider()-> |
| 802 set_offscreen_context_provider(offscreen_context_provider); | 845 set_offscreen_context_provider(offscreen_context_provider); |
| 803 | 846 |
| 804 if (layer_tree_host_->contents_texture_manager()) { | 847 if (layer_tree_host_->contents_texture_manager()) { |
| 805 if (layer_tree_host_->contents_texture_manager()-> | 848 if (layer_tree_host_->contents_texture_manager()-> |
| 806 LinkedEvictedBackingsExist()) { | 849 LinkedEvictedBackingsExist()) { |
| 807 // Clear any uploads we were making to textures linked to evicted | 850 // Clear any uploads we were making to textures linked to evicted |
| 808 // resources | 851 // resources |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 844 | 887 |
| 845 // Complete all remaining texture updates. | 888 // Complete all remaining texture updates. |
| 846 current_resource_update_controller_on_impl_thread_->Finalize(); | 889 current_resource_update_controller_on_impl_thread_->Finalize(); |
| 847 current_resource_update_controller_on_impl_thread_.reset(); | 890 current_resource_update_controller_on_impl_thread_.reset(); |
| 848 | 891 |
| 849 layer_tree_host_impl_->BeginCommit(); | 892 layer_tree_host_impl_->BeginCommit(); |
| 850 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get()); | 893 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get()); |
| 851 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); | 894 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); |
| 852 layer_tree_host_impl_->CommitComplete(); | 895 layer_tree_host_impl_->CommitComplete(); |
| 853 | 896 |
| 854 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( | |
| 855 !scheduler_on_impl_thread_->WillDrawIfNeeded()); | |
| 856 | |
| 857 next_frame_is_newly_committed_frame_on_impl_thread_ = true; | 897 next_frame_is_newly_committed_frame_on_impl_thread_ = true; |
| 858 | 898 |
| 859 if (layer_tree_host_->settings().impl_side_painting && | 899 if (layer_tree_host_->settings().impl_side_painting && |
| 860 layer_tree_host_->BlocksPendingCommit() && | 900 layer_tree_host_->BlocksPendingCommit() && |
| 861 layer_tree_host_impl_->pending_tree()) { | 901 layer_tree_host_impl_->pending_tree()) { |
| 862 // For some layer types in impl-side painting, the commit is held until | 902 // For some layer types in impl-side painting, the commit is held until |
| 863 // the pending tree is activated. It's also possible that the | 903 // the pending tree is activated. It's also possible that the |
| 864 // pending tree has already activated if there was no work to be done. | 904 // pending tree has already activated if there was no work to be done. |
| 865 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD); | 905 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD); |
| 866 completion_event_for_commit_held_on_tree_activation_ = | 906 completion_event_for_commit_held_on_tree_activation_ = |
| 867 commit_completion_event_on_impl_thread_; | 907 commit_completion_event_on_impl_thread_; |
| 868 commit_completion_event_on_impl_thread_ = NULL; | 908 commit_completion_event_on_impl_thread_ = NULL; |
| 869 } else { | 909 } else { |
| 870 commit_completion_event_on_impl_thread_->Signal(); | 910 commit_completion_event_on_impl_thread_->Signal(); |
| 871 commit_completion_event_on_impl_thread_ = NULL; | 911 commit_completion_event_on_impl_thread_ = NULL; |
| 872 } | 912 } |
| 873 | 913 |
| 914 // The commit may have added animations, requiring us to start | |
| 915 // background ticking. | |
| 916 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( | |
| 917 !scheduler_on_impl_thread_->WillDrawIfNeeded()); | |
| 874 // SetVisible kicks off the next scheduler action, so this must be last. | 918 // SetVisible kicks off the next scheduler action, so this must be last. |
| 875 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); | 919 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); |
| 876 } | 920 } |
| 877 | 921 |
| 878 void ThreadProxy::ScheduledActionCheckForCompletedTileUploads() { | 922 void ThreadProxy::ScheduledActionCheckForCompletedTileUploads() { |
| 879 DCHECK(IsImplThread()); | 923 DCHECK(IsImplThread()); |
| 880 TRACE_EVENT0("cc", | 924 TRACE_EVENT0("cc", |
| 881 "ThreadProxy::ScheduledActionCheckForCompletedTileUploads"); | 925 "ThreadProxy::ScheduledActionCheckForCompletedTileUploads"); |
| 882 layer_tree_host_impl_->CheckForCompletedTileUploads(); | 926 layer_tree_host_impl_->CheckForCompletedTileUploads(); |
| 883 } | 927 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 905 result.did_swap = false; | 949 result.did_swap = false; |
| 906 DCHECK(IsImplThread()); | 950 DCHECK(IsImplThread()); |
| 907 DCHECK(layer_tree_host_impl_.get()); | 951 DCHECK(layer_tree_host_impl_.get()); |
| 908 if (!layer_tree_host_impl_) | 952 if (!layer_tree_host_impl_) |
| 909 return result; | 953 return result; |
| 910 | 954 |
| 911 DCHECK(layer_tree_host_impl_->renderer()); | 955 DCHECK(layer_tree_host_impl_->renderer()); |
| 912 if (!layer_tree_host_impl_->renderer()) | 956 if (!layer_tree_host_impl_->renderer()) |
| 913 return result; | 957 return result; |
| 914 | 958 |
| 915 base::TimeTicks monotonic_time = | |
| 916 layer_tree_host_impl_->CurrentFrameTimeTicks(); | |
| 917 base::Time wall_clock_time = layer_tree_host_impl_->CurrentFrameTime(); | |
| 918 | |
| 919 // TODO(enne): This should probably happen post-animate. | |
| 920 if (layer_tree_host_impl_->pending_tree()) { | |
| 921 layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); | |
| 922 if (layer_tree_host_impl_->pending_tree()) | |
| 923 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties(); | |
| 924 } | |
| 925 layer_tree_host_impl_->Animate(monotonic_time, wall_clock_time); | |
| 926 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(false); | |
| 927 | |
| 928 base::TimeTicks start_time = base::TimeTicks::HighResNow(); | 959 base::TimeTicks start_time = base::TimeTicks::HighResNow(); |
| 929 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); | 960 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); |
| 930 base::AutoReset<bool> mark_inside(&inside_draw_, true); | 961 base::AutoReset<bool> mark_inside(&inside_draw_, true); |
| 931 | 962 |
| 932 // This method is called on a forced draw, regardless of whether we are able | 963 // This method is called on a forced draw, regardless of whether we are able |
| 933 // to produce a frame, as the calling site on main thread is blocked until its | 964 // to produce a frame, as the calling site on main thread is blocked until its |
| 934 // request completes, and we signal completion here. If CanDraw() is false, we | 965 // request completes, and we signal completion here. If CanDraw() is false, we |
| 935 // will indicate success=false to the caller, but we must still signal | 966 // will indicate success=false to the caller, but we must still signal |
| 936 // completion to avoid deadlock. | 967 // completion to avoid deadlock. |
| 937 | 968 |
| 938 // We guard PrepareToDraw() with CanDraw() because it always returns a valid | 969 // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
| 939 // frame, so can only be used when such a frame is possible. Since | 970 // frame, so can only be used when such a frame is possible. Since |
| 940 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on | 971 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
| 941 // CanDraw() as well. | 972 // CanDraw() as well. |
| 942 | 973 |
| 943 bool drawing_for_readback = !!readback_request_on_impl_thread_; | 974 bool drawing_for_readback = !!readback_request_on_impl_thread_; |
| 944 bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels(); | 975 bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels(); |
| 945 | 976 |
| 946 LayerTreeHostImpl::FrameData frame; | 977 LayerTreeHostImpl::FrameData frame; |
| 947 bool draw_frame = false; | 978 bool draw_frame = false; |
| 948 bool start_ready_animations = true; | |
| 949 | 979 |
| 950 if (layer_tree_host_impl_->CanDraw() && | 980 if (layer_tree_host_impl_->CanDraw() && |
| 951 (!drawing_for_readback || can_do_readback)) { | 981 (!drawing_for_readback || can_do_readback)) { |
| 952 // If it is for a readback, make sure we draw the portion being read back. | 982 // If it is for a readback, make sure we draw the portion being read back. |
| 953 gfx::Rect readback_rect; | 983 gfx::Rect readback_rect; |
| 954 if (drawing_for_readback) | 984 if (drawing_for_readback) |
| 955 readback_rect = readback_request_on_impl_thread_->rect; | 985 readback_rect = readback_request_on_impl_thread_->rect; |
| 956 | 986 |
| 957 // Do not start animations if we skip drawing the frame to avoid | 987 // Do not start animations if we skip drawing the frame to avoid |
| 958 // checkerboarding. | 988 // checkerboarding. |
| 959 if (layer_tree_host_impl_->PrepareToDraw(&frame, readback_rect) || | 989 if (layer_tree_host_impl_->PrepareToDraw(&frame, readback_rect) || |
| 960 forced_draw) | 990 forced_draw) |
| 961 draw_frame = true; | 991 draw_frame = true; |
| 962 else | |
| 963 start_ready_animations = false; | |
| 964 } | 992 } |
| 965 | 993 |
| 994 frame_did_draw_ = draw_frame; | |
| 995 | |
| 966 if (draw_frame) { | 996 if (draw_frame) { |
| 967 layer_tree_host_impl_->DrawLayers( | 997 layer_tree_host_impl_->DrawLayers( |
| 968 &frame, | 998 &frame, |
| 969 scheduler_on_impl_thread_->LastBeginFrameOnImplThreadTime()); | 999 scheduler_on_impl_thread_->LastBeginFrameOnImplThreadTime()); |
| 970 result.did_draw = true; | 1000 result.did_draw = true; |
| 971 } | 1001 } |
| 972 layer_tree_host_impl_->DidDrawAllLayers(frame); | 1002 layer_tree_host_impl_->DidDrawAllLayers(frame); |
| 973 | 1003 |
| 974 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | |
| 975 | |
| 976 // Check for a pending CompositeAndReadback. | 1004 // Check for a pending CompositeAndReadback. |
| 977 if (readback_request_on_impl_thread_) { | 1005 if (readback_request_on_impl_thread_) { |
| 978 readback_request_on_impl_thread_->success = false; | 1006 readback_request_on_impl_thread_->success = false; |
| 979 if (draw_frame) { | 1007 if (draw_frame) { |
| 980 layer_tree_host_impl_->Readback(readback_request_on_impl_thread_->pixels, | 1008 layer_tree_host_impl_->Readback(readback_request_on_impl_thread_->pixels, |
| 981 readback_request_on_impl_thread_->rect); | 1009 readback_request_on_impl_thread_->rect); |
| 982 readback_request_on_impl_thread_->success = | 1010 readback_request_on_impl_thread_->success = |
| 983 !layer_tree_host_impl_->IsContextLost(); | 1011 !layer_tree_host_impl_->IsContextLost(); |
| 984 } | 1012 } |
| 985 readback_request_on_impl_thread_->completion.Signal(); | 1013 readback_request_on_impl_thread_->completion.Signal(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1083 | 1111 |
| 1084 ScheduledActionDrawAndSwapResult | 1112 ScheduledActionDrawAndSwapResult |
| 1085 ThreadProxy::ScheduledActionDrawAndSwapForced() { | 1113 ThreadProxy::ScheduledActionDrawAndSwapForced() { |
| 1086 return ScheduledActionDrawAndSwapInternal(true); | 1114 return ScheduledActionDrawAndSwapInternal(true); |
| 1087 } | 1115 } |
| 1088 | 1116 |
| 1089 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { | 1117 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { |
| 1090 if (current_resource_update_controller_on_impl_thread_) | 1118 if (current_resource_update_controller_on_impl_thread_) |
| 1091 current_resource_update_controller_on_impl_thread_ | 1119 current_resource_update_controller_on_impl_thread_ |
| 1092 ->PerformMoreUpdates(time); | 1120 ->PerformMoreUpdates(time); |
| 1093 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | |
| 1094 } | 1121 } |
| 1095 | 1122 |
| 1096 base::TimeDelta ThreadProxy::DrawDurationEstimate() { | 1123 base::TimeDelta ThreadProxy::DrawDurationEstimate() { |
| 1097 base::TimeDelta historical_estimate = | 1124 base::TimeDelta historical_estimate = |
| 1098 draw_duration_history_.Percentile(kDrawDurationEstimationPercentile); | 1125 draw_duration_history_.Percentile(kDrawDurationEstimationPercentile); |
| 1099 base::TimeDelta padding = base::TimeDelta::FromMicroseconds( | 1126 base::TimeDelta padding = base::TimeDelta::FromMicroseconds( |
| 1100 kDrawDurationEstimatePaddingInMicroseconds); | 1127 kDrawDurationEstimatePaddingInMicroseconds); |
| 1101 return historical_estimate + padding; | 1128 return historical_estimate + padding; |
| 1102 } | 1129 } |
| 1103 | 1130 |
| 1131 void ThreadProxy::PostBeginFrameDeadline(const base::Closure &closure, | |
| 1132 base::TimeTicks deadline) { | |
| 1133 base::TimeDelta delta = deadline - base::TimeTicks::Now(); | |
| 1134 if (delta <= base::TimeDelta()) | |
| 1135 delta = base::TimeDelta(); | |
| 1136 Proxy::ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE, closure, delta); | |
| 1137 } | |
| 1138 | |
| 1104 void ThreadProxy::ReadyToFinalizeTextureUpdates() { | 1139 void ThreadProxy::ReadyToFinalizeTextureUpdates() { |
| 1105 DCHECK(IsImplThread()); | 1140 DCHECK(IsImplThread()); |
| 1106 scheduler_on_impl_thread_->FinishCommit(); | 1141 scheduler_on_impl_thread_->FinishCommit(); |
| 1107 } | 1142 } |
| 1108 | 1143 |
| 1109 void ThreadProxy::DidCommitAndDrawFrame() { | 1144 void ThreadProxy::DidCommitAndDrawFrame() { |
| 1110 DCHECK(IsMainThread()); | 1145 DCHECK(IsMainThread()); |
| 1111 if (!layer_tree_host_) | 1146 if (!layer_tree_host_) |
| 1112 return; | 1147 return; |
| 1113 layer_tree_host_->DidCommitAndDrawFrame(); | 1148 layer_tree_host_->DidCommitAndDrawFrame(); |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1439 !layer_tree_host_impl_->pending_tree()) { | 1474 !layer_tree_host_impl_->pending_tree()) { |
| 1440 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation", | 1475 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation", |
| 1441 TRACE_EVENT_SCOPE_THREAD); | 1476 TRACE_EVENT_SCOPE_THREAD); |
| 1442 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); | 1477 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); |
| 1443 completion_event_for_commit_held_on_tree_activation_->Signal(); | 1478 completion_event_for_commit_held_on_tree_activation_->Signal(); |
| 1444 completion_event_for_commit_held_on_tree_activation_ = NULL; | 1479 completion_event_for_commit_held_on_tree_activation_ = NULL; |
| 1445 } | 1480 } |
| 1446 } | 1481 } |
| 1447 | 1482 |
| 1448 } // namespace cc | 1483 } // namespace cc |
| OLD | NEW |