| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 } | 42 } |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 cc::LayerTreeHost* layer_tree_host_; | 45 cc::LayerTreeHost* layer_tree_host_; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 namespace cc { | 50 namespace cc { |
| 51 | 51 |
| 52 struct ThreadProxy::ReadbackRequest { | |
| 53 CompletionEvent completion; | |
| 54 bool success; | |
| 55 void* pixels; | |
| 56 gfx::Rect rect; | |
| 57 }; | |
| 58 | |
| 59 struct ThreadProxy::CommitPendingRequest { | 52 struct ThreadProxy::CommitPendingRequest { |
| 60 CompletionEvent completion; | 53 CompletionEvent completion; |
| 61 bool commit_pending; | 54 bool commit_pending; |
| 62 }; | 55 }; |
| 63 | 56 |
| 64 struct ThreadProxy::SchedulerStateRequest { | 57 struct ThreadProxy::SchedulerStateRequest { |
| 65 CompletionEvent completion; | 58 CompletionEvent completion; |
| 66 scoped_ptr<base::Value> state; | 59 scoped_ptr<base::Value> state; |
| 67 }; | 60 }; |
| 68 | 61 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 85 DCHECK(this->layer_tree_host()); | 78 DCHECK(this->layer_tree_host()); |
| 86 } | 79 } |
| 87 | 80 |
| 88 ThreadProxy::MainThreadOnly::MainThreadOnly(ThreadProxy* proxy, | 81 ThreadProxy::MainThreadOnly::MainThreadOnly(ThreadProxy* proxy, |
| 89 int layer_tree_host_id) | 82 int layer_tree_host_id) |
| 90 : layer_tree_host_id(layer_tree_host_id), | 83 : layer_tree_host_id(layer_tree_host_id), |
| 91 animate_requested(false), | 84 animate_requested(false), |
| 92 commit_requested(false), | 85 commit_requested(false), |
| 93 commit_request_sent_to_impl_thread(false), | 86 commit_request_sent_to_impl_thread(false), |
| 94 started(false), | 87 started(false), |
| 95 in_composite_and_readback(false), | |
| 96 manage_tiles_pending(false), | 88 manage_tiles_pending(false), |
| 97 can_cancel_commit(true), | 89 can_cancel_commit(true), |
| 98 defer_commits(false), | 90 defer_commits(false), |
| 99 weak_factory(proxy) {} | 91 weak_factory(proxy) {} |
| 100 | 92 |
| 101 ThreadProxy::MainThreadOnly::~MainThreadOnly() {} | 93 ThreadProxy::MainThreadOnly::~MainThreadOnly() {} |
| 102 | 94 |
| 103 ThreadProxy::MainThreadOrBlockedMainThread::MainThreadOrBlockedMainThread( | 95 ThreadProxy::MainThreadOrBlockedMainThread::MainThreadOrBlockedMainThread( |
| 104 LayerTreeHost* host) | 96 LayerTreeHost* host) |
| 105 : layer_tree_host(host), | 97 : layer_tree_host(host), |
| 106 commit_waits_for_activation(false), | 98 commit_waits_for_activation(false), |
| 107 main_thread_inside_commit(false) {} | 99 main_thread_inside_commit(false) {} |
| 108 | 100 |
| 109 ThreadProxy::MainThreadOrBlockedMainThread::~MainThreadOrBlockedMainThread() {} | 101 ThreadProxy::MainThreadOrBlockedMainThread::~MainThreadOrBlockedMainThread() {} |
| 110 | 102 |
| 111 PrioritizedResourceManager* | 103 PrioritizedResourceManager* |
| 112 ThreadProxy::MainThreadOrBlockedMainThread::contents_texture_manager() { | 104 ThreadProxy::MainThreadOrBlockedMainThread::contents_texture_manager() { |
| 113 return layer_tree_host->contents_texture_manager(); | 105 return layer_tree_host->contents_texture_manager(); |
| 114 } | 106 } |
| 115 | 107 |
| 116 ThreadProxy::CompositorThreadOnly::CompositorThreadOnly(ThreadProxy* proxy, | 108 ThreadProxy::CompositorThreadOnly::CompositorThreadOnly(ThreadProxy* proxy, |
| 117 int layer_tree_host_id) | 109 int layer_tree_host_id) |
| 118 : layer_tree_host_id(layer_tree_host_id), | 110 : layer_tree_host_id(layer_tree_host_id), |
| 119 contents_texture_manager(NULL), | 111 contents_texture_manager(NULL), |
| 120 begin_main_frame_sent_completion_event(NULL), | |
| 121 readback_request(NULL), | |
| 122 commit_completion_event(NULL), | 112 commit_completion_event(NULL), |
| 123 completion_event_for_commit_held_on_tree_activation(NULL), | 113 completion_event_for_commit_held_on_tree_activation(NULL), |
| 124 next_frame_is_newly_committed_frame(false), | 114 next_frame_is_newly_committed_frame(false), |
| 125 inside_draw(false), | 115 inside_draw(false), |
| 126 input_throttled_until_commit(false), | 116 input_throttled_until_commit(false), |
| 127 animations_frozen_until_next_draw(false), | 117 animations_frozen_until_next_draw(false), |
| 128 did_commit_after_animating(false), | 118 did_commit_after_animating(false), |
| 129 renew_tree_priority_pending(false), | 119 renew_tree_priority_pending(false), |
| 130 weak_factory(proxy) { | 120 weak_factory(proxy) { |
| 131 } | 121 } |
| 132 | 122 |
| 133 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {} | 123 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {} |
| 134 | 124 |
| 135 ThreadProxy::~ThreadProxy() { | 125 ThreadProxy::~ThreadProxy() { |
| 136 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); | 126 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); |
| 137 DCHECK(IsMainThread()); | 127 DCHECK(IsMainThread()); |
| 138 DCHECK(!main().started); | 128 DCHECK(!main().started); |
| 139 } | 129 } |
| 140 | 130 |
| 141 bool ThreadProxy::CompositeAndReadback(void* pixels, const gfx::Rect& rect) { | |
| 142 TRACE_EVENT0("cc", "ThreadProxy::CompositeAndReadback"); | |
| 143 DCHECK(IsMainThread()); | |
| 144 DCHECK(layer_tree_host()); | |
| 145 | |
| 146 if (main().defer_commits) { | |
| 147 TRACE_EVENT0("cc", "CompositeAndReadback_DeferCommit"); | |
| 148 return false; | |
| 149 } | |
| 150 | |
| 151 if (!layer_tree_host()->InitializeOutputSurfaceIfNeeded()) { | |
| 152 TRACE_EVENT_INSTANT0("cc", | |
| 153 "CompositeAndReadback_EarlyOut_LR_Uninitialized", | |
| 154 TRACE_EVENT_SCOPE_THREAD); | |
| 155 return false; | |
| 156 } | |
| 157 | |
| 158 // Perform a synchronous commit with an associated readback. | |
| 159 ReadbackRequest request; | |
| 160 request.rect = rect; | |
| 161 request.pixels = pixels; | |
| 162 { | |
| 163 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | |
| 164 CompletionEvent begin_main_frame_sent_completion; | |
| 165 Proxy::ImplThreadTaskRunner()->PostTask( | |
| 166 FROM_HERE, | |
| 167 base::Bind(&ThreadProxy::ForceCommitForReadbackOnImplThread, | |
| 168 impl_thread_weak_ptr_, | |
| 169 &begin_main_frame_sent_completion, | |
| 170 &request)); | |
| 171 begin_main_frame_sent_completion.Wait(); | |
| 172 } | |
| 173 | |
| 174 main().in_composite_and_readback = true; | |
| 175 // This is the forced commit. | |
| 176 // Note: The Impl thread also queues a separate BeginMainFrame on the | |
| 177 // main thread, which will be called after this CompositeAndReadback | |
| 178 // completes, to replace the forced commit. | |
| 179 BeginMainFrame(scoped_ptr<BeginMainFrameAndCommitState>()); | |
| 180 main().in_composite_and_readback = false; | |
| 181 | |
| 182 // Composite and readback requires a second commit to undo any changes | |
| 183 // that it made. | |
| 184 main().can_cancel_commit = false; | |
| 185 | |
| 186 request.completion.Wait(); | |
| 187 return request.success; | |
| 188 } | |
| 189 | |
| 190 void ThreadProxy::ForceCommitForReadbackOnImplThread( | |
| 191 CompletionEvent* begin_main_frame_sent_completion, | |
| 192 ReadbackRequest* request) { | |
| 193 TRACE_EVENT0("cc", "ThreadProxy::ForceCommitForReadbackOnImplThread"); | |
| 194 DCHECK(IsImplThread()); | |
| 195 DCHECK(!impl().begin_main_frame_sent_completion_event); | |
| 196 DCHECK(!impl().readback_request); | |
| 197 | |
| 198 if (!impl().layer_tree_host_impl) { | |
| 199 begin_main_frame_sent_completion->Signal(); | |
| 200 request->success = false; | |
| 201 request->completion.Signal(); | |
| 202 return; | |
| 203 } | |
| 204 | |
| 205 impl().readback_request = request; | |
| 206 | |
| 207 impl().scheduler->SetNeedsForcedCommitForReadback(); | |
| 208 if (impl().scheduler->IsBeginMainFrameSent()) { | |
| 209 begin_main_frame_sent_completion->Signal(); | |
| 210 return; | |
| 211 } | |
| 212 | |
| 213 impl().begin_main_frame_sent_completion_event = | |
| 214 begin_main_frame_sent_completion; | |
| 215 } | |
| 216 | |
| 217 void ThreadProxy::FinishAllRendering() { | 131 void ThreadProxy::FinishAllRendering() { |
| 218 DCHECK(Proxy::IsMainThread()); | 132 DCHECK(Proxy::IsMainThread()); |
| 219 DCHECK(!main().defer_commits); | 133 DCHECK(!main().defer_commits); |
| 220 | 134 |
| 221 // Make sure all GL drawing is finished on the impl thread. | 135 // Make sure all GL drawing is finished on the impl thread. |
| 222 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 136 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 223 CompletionEvent completion; | 137 CompletionEvent completion; |
| 224 Proxy::ImplThreadTaskRunner()->PostTask( | 138 Proxy::ImplThreadTaskRunner()->PostTask( |
| 225 FROM_HERE, | 139 FROM_HERE, |
| 226 base::Bind(&ThreadProxy::FinishAllRenderingOnImplThread, | 140 base::Bind(&ThreadProxy::FinishAllRenderingOnImplThread, |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 impl().layer_tree_host_impl->memory_allocation_priority_cutoff(); | 694 impl().layer_tree_host_impl->memory_allocation_priority_cutoff(); |
| 781 begin_main_frame_state->evicted_ui_resources = | 695 begin_main_frame_state->evicted_ui_resources = |
| 782 impl().layer_tree_host_impl->EvictedUIResourcesExist(); | 696 impl().layer_tree_host_impl->EvictedUIResourcesExist(); |
| 783 Proxy::MainThreadTaskRunner()->PostTask( | 697 Proxy::MainThreadTaskRunner()->PostTask( |
| 784 FROM_HERE, | 698 FROM_HERE, |
| 785 base::Bind(&ThreadProxy::BeginMainFrame, | 699 base::Bind(&ThreadProxy::BeginMainFrame, |
| 786 main_thread_weak_ptr_, | 700 main_thread_weak_ptr_, |
| 787 base::Passed(&begin_main_frame_state))); | 701 base::Passed(&begin_main_frame_state))); |
| 788 devtools_instrumentation::DidRequestMainThreadFrame( | 702 devtools_instrumentation::DidRequestMainThreadFrame( |
| 789 impl().layer_tree_host_id); | 703 impl().layer_tree_host_id); |
| 790 if (impl().begin_main_frame_sent_completion_event) { | |
| 791 impl().begin_main_frame_sent_completion_event->Signal(); | |
| 792 impl().begin_main_frame_sent_completion_event = NULL; | |
| 793 } | |
| 794 impl().timing_history.DidBeginMainFrame(); | 704 impl().timing_history.DidBeginMainFrame(); |
| 795 } | 705 } |
| 796 | 706 |
| 797 void ThreadProxy::BeginMainFrame( | 707 void ThreadProxy::BeginMainFrame( |
| 798 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { | 708 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { |
| 799 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame"); | 709 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame"); |
| 800 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame"); | 710 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame"); |
| 801 DCHECK(IsMainThread()); | 711 DCHECK(IsMainThread()); |
| 802 | 712 |
| 803 if (!layer_tree_host()) | 713 if (!layer_tree_host()) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 822 // the paint, main().commit_requested will be set to false to allow new commit | 732 // the paint, main().commit_requested will be set to false to allow new commit |
| 823 // requests to be scheduled. | 733 // requests to be scheduled. |
| 824 main().commit_requested = true; | 734 main().commit_requested = true; |
| 825 main().commit_request_sent_to_impl_thread = true; | 735 main().commit_request_sent_to_impl_thread = true; |
| 826 | 736 |
| 827 // On the other hand, the AnimationRequested flag needs to be cleared | 737 // On the other hand, the AnimationRequested flag needs to be cleared |
| 828 // here so that any animation requests generated by the apply or animate | 738 // here so that any animation requests generated by the apply or animate |
| 829 // callbacks will trigger another frame. | 739 // callbacks will trigger another frame. |
| 830 main().animate_requested = false; | 740 main().animate_requested = false; |
| 831 | 741 |
| 832 if (!main().in_composite_and_readback && !layer_tree_host()->visible()) { | 742 if (!layer_tree_host()->visible()) { |
| 833 main().commit_requested = false; | 743 main().commit_requested = false; |
| 834 main().commit_request_sent_to_impl_thread = false; | 744 main().commit_request_sent_to_impl_thread = false; |
| 835 | 745 |
| 836 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); | 746 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); |
| 837 bool did_handle = false; | 747 bool did_handle = false; |
| 838 Proxy::ImplThreadTaskRunner()->PostTask( | 748 Proxy::ImplThreadTaskRunner()->PostTask( |
| 839 FROM_HERE, | 749 FROM_HERE, |
| 840 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, | 750 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, |
| 841 impl_thread_weak_ptr_, | 751 impl_thread_weak_ptr_, |
| 842 did_handle)); | 752 did_handle)); |
| 843 return; | 753 return; |
| 844 } | 754 } |
| 845 | 755 |
| 846 if (begin_main_frame_state) { | 756 layer_tree_host()->ApplyScrollAndScale(*begin_main_frame_state->scroll_info); |
| 847 layer_tree_host()->ApplyScrollAndScale( | |
| 848 *begin_main_frame_state->scroll_info); | |
| 849 } | |
| 850 | 757 |
| 851 layer_tree_host()->WillBeginMainFrame(); | 758 layer_tree_host()->WillBeginMainFrame(); |
| 852 | 759 |
| 853 if (begin_main_frame_state) { | 760 layer_tree_host()->UpdateClientAnimations( |
| 854 layer_tree_host()->UpdateClientAnimations( | 761 begin_main_frame_state->monotonic_frame_begin_time); |
| 855 begin_main_frame_state->monotonic_frame_begin_time); | 762 layer_tree_host()->AnimateLayers( |
| 856 layer_tree_host()->AnimateLayers( | 763 begin_main_frame_state->monotonic_frame_begin_time); |
| 857 begin_main_frame_state->monotonic_frame_begin_time); | 764 blocked_main().last_monotonic_frame_begin_time = |
| 858 blocked_main().last_monotonic_frame_begin_time = | 765 begin_main_frame_state->monotonic_frame_begin_time; |
| 859 begin_main_frame_state->monotonic_frame_begin_time; | |
| 860 } | |
| 861 | 766 |
| 862 // Unlink any backings that the impl thread has evicted, so that we know to | 767 // Unlink any backings that the impl thread has evicted, so that we know to |
| 863 // re-paint them in UpdateLayers. | 768 // re-paint them in UpdateLayers. |
| 864 if (blocked_main().contents_texture_manager()) { | 769 if (blocked_main().contents_texture_manager()) { |
| 865 blocked_main().contents_texture_manager()->UnlinkAndClearEvictedBackings(); | 770 blocked_main().contents_texture_manager()->UnlinkAndClearEvictedBackings(); |
| 866 | 771 |
| 867 if (begin_main_frame_state) { | 772 blocked_main().contents_texture_manager()->SetMaxMemoryLimitBytes( |
| 868 blocked_main().contents_texture_manager()->SetMaxMemoryLimitBytes( | 773 begin_main_frame_state->memory_allocation_limit_bytes); |
| 869 begin_main_frame_state->memory_allocation_limit_bytes); | 774 blocked_main().contents_texture_manager()->SetExternalPriorityCutoff( |
| 870 blocked_main().contents_texture_manager()->SetExternalPriorityCutoff( | 775 begin_main_frame_state->memory_allocation_priority_cutoff); |
| 871 begin_main_frame_state->memory_allocation_priority_cutoff); | |
| 872 } | |
| 873 } | 776 } |
| 874 | 777 |
| 875 // Recreate all UI resources if there were evicted UI resources when the impl | 778 // Recreate all UI resources if there were evicted UI resources when the impl |
| 876 // thread initiated the commit. | 779 // thread initiated the commit. |
| 877 bool evicted_ui_resources = begin_main_frame_state | 780 if (begin_main_frame_state->evicted_ui_resources) |
| 878 ? begin_main_frame_state->evicted_ui_resources | |
| 879 : false; | |
| 880 if (evicted_ui_resources) | |
| 881 layer_tree_host()->RecreateUIResources(); | 781 layer_tree_host()->RecreateUIResources(); |
| 882 | 782 |
| 883 layer_tree_host()->Layout(); | 783 layer_tree_host()->Layout(); |
| 884 TRACE_EVENT_SYNTHETIC_DELAY_END("cc.BeginMainFrame"); | 784 TRACE_EVENT_SYNTHETIC_DELAY_END("cc.BeginMainFrame"); |
| 885 | 785 |
| 886 // Clear the commit flag after updating animations and layout here --- objects | 786 // Clear the commit flag after updating animations and layout here --- objects |
| 887 // that only layout when painted will trigger another SetNeedsCommit inside | 787 // that only layout when painted will trigger another SetNeedsCommit inside |
| 888 // UpdateLayers. | 788 // UpdateLayers. |
| 889 main().commit_requested = false; | 789 main().commit_requested = false; |
| 890 main().commit_request_sent_to_impl_thread = false; | 790 main().commit_request_sent_to_impl_thread = false; |
| 891 bool can_cancel_this_commit = main().can_cancel_commit && | 791 bool can_cancel_this_commit = |
| 892 !main().in_composite_and_readback && | 792 main().can_cancel_commit && !begin_main_frame_state->evicted_ui_resources; |
| 893 !evicted_ui_resources; | |
| 894 main().can_cancel_commit = true; | 793 main().can_cancel_commit = true; |
| 895 | 794 |
| 896 scoped_ptr<ResourceUpdateQueue> queue = | 795 scoped_ptr<ResourceUpdateQueue> queue = |
| 897 make_scoped_ptr(new ResourceUpdateQueue); | 796 make_scoped_ptr(new ResourceUpdateQueue); |
| 898 | 797 |
| 899 bool updated = layer_tree_host()->UpdateLayers(queue.get()); | 798 bool updated = layer_tree_host()->UpdateLayers(queue.get()); |
| 900 | 799 |
| 901 layer_tree_host()->WillCommit(); | 800 layer_tree_host()->WillCommit(); |
| 902 | 801 |
| 903 // Before calling animate, we set main().animate_requested to false. If it is | 802 // Before calling animate, we set main().animate_requested to false. If it is |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 | 1007 |
| 1109 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { | 1008 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { |
| 1110 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionBeginOutputSurfaceCreation"); | 1009 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionBeginOutputSurfaceCreation"); |
| 1111 DCHECK(IsImplThread()); | 1010 DCHECK(IsImplThread()); |
| 1112 Proxy::MainThreadTaskRunner()->PostTask( | 1011 Proxy::MainThreadTaskRunner()->PostTask( |
| 1113 FROM_HERE, | 1012 FROM_HERE, |
| 1114 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, | 1013 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, |
| 1115 main_thread_weak_ptr_)); | 1014 main_thread_weak_ptr_)); |
| 1116 } | 1015 } |
| 1117 | 1016 |
| 1118 DrawSwapReadbackResult ThreadProxy::DrawSwapReadbackInternal( | 1017 DrawSwapReadbackResult ThreadProxy::DrawSwapInternal(bool forced_draw) { |
| 1119 bool forced_draw, | |
| 1120 bool swap_requested, | |
| 1121 bool readback_requested) { | |
| 1122 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap"); | 1018 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap"); |
| 1123 DrawSwapReadbackResult result; | 1019 DrawSwapReadbackResult result; |
| 1124 | 1020 |
| 1125 DCHECK(IsImplThread()); | 1021 DCHECK(IsImplThread()); |
| 1126 DCHECK(impl().layer_tree_host_impl.get()); | 1022 DCHECK(impl().layer_tree_host_impl.get()); |
| 1127 | 1023 |
| 1128 impl().timing_history.DidStartDrawing(); | 1024 impl().timing_history.DidStartDrawing(); |
| 1129 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); | 1025 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); |
| 1130 base::AutoReset<bool> mark_inside(&impl().inside_draw, true); | 1026 base::AutoReset<bool> mark_inside(&impl().inside_draw, true); |
| 1131 | 1027 |
| 1132 if (impl().did_commit_after_animating) { | 1028 if (impl().did_commit_after_animating) { |
| 1133 impl().layer_tree_host_impl->Animate(impl().animation_time); | 1029 impl().layer_tree_host_impl->Animate(impl().animation_time); |
| 1134 impl().did_commit_after_animating = false; | 1030 impl().did_commit_after_animating = false; |
| 1135 } | 1031 } |
| 1136 | 1032 |
| 1137 if (impl().layer_tree_host_impl->pending_tree()) | 1033 if (impl().layer_tree_host_impl->pending_tree()) |
| 1138 impl().layer_tree_host_impl->pending_tree()->UpdateDrawProperties(); | 1034 impl().layer_tree_host_impl->pending_tree()->UpdateDrawProperties(); |
| 1139 | 1035 |
| 1140 // This method is called on a forced draw, regardless of whether we are able | 1036 // This method is called on a forced draw, regardless of whether we are able |
| 1141 // to produce a frame, as the calling site on main thread is blocked until its | 1037 // to produce a frame, as the calling site on main thread is blocked until its |
| 1142 // request completes, and we signal completion here. If CanDraw() is false, we | 1038 // request completes, and we signal completion here. If CanDraw() is false, we |
| 1143 // will indicate success=false to the caller, but we must still signal | 1039 // will indicate success=false to the caller, but we must still signal |
| 1144 // completion to avoid deadlock. | 1040 // completion to avoid deadlock. |
| 1145 | 1041 |
| 1146 // We guard PrepareToDraw() with CanDraw() because it always returns a valid | 1042 // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
| 1147 // frame, so can only be used when such a frame is possible. Since | 1043 // frame, so can only be used when such a frame is possible. Since |
| 1148 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on | 1044 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
| 1149 // CanDraw() as well. | 1045 // CanDraw() as well. |
| 1150 | 1046 |
| 1151 bool drawing_for_readback = readback_requested && !!impl().readback_request; | |
| 1152 bool can_do_readback = | |
| 1153 impl().layer_tree_host_impl->renderer()->CanReadPixels(); | |
| 1154 | |
| 1155 LayerTreeHostImpl::FrameData frame; | 1047 LayerTreeHostImpl::FrameData frame; |
| 1156 bool draw_frame = false; | 1048 bool draw_frame = false; |
| 1157 | 1049 |
| 1158 if (impl().layer_tree_host_impl->CanDraw()) { | 1050 if (impl().layer_tree_host_impl->CanDraw()) { |
| 1159 if (!drawing_for_readback || can_do_readback) { | 1051 result.draw_result = impl().layer_tree_host_impl->PrepareToDraw(&frame); |
| 1160 // If it is for a readback, make sure we draw the portion being read back. | 1052 draw_frame = forced_draw || |
| 1161 gfx::Rect readback_rect; | 1053 result.draw_result == DrawSwapReadbackResult::DRAW_SUCCESS; |
| 1162 if (drawing_for_readback) | |
| 1163 readback_rect = impl().readback_request->rect; | |
| 1164 | |
| 1165 result.draw_result = | |
| 1166 impl().layer_tree_host_impl->PrepareToDraw(&frame, readback_rect); | |
| 1167 draw_frame = forced_draw || | |
| 1168 result.draw_result == DrawSwapReadbackResult::DRAW_SUCCESS; | |
| 1169 } else { | |
| 1170 result.draw_result = DrawSwapReadbackResult::DRAW_ABORTED_CANT_READBACK; | |
| 1171 } | |
| 1172 } else { | 1054 } else { |
| 1173 result.draw_result = DrawSwapReadbackResult::DRAW_ABORTED_CANT_DRAW; | 1055 result.draw_result = DrawSwapReadbackResult::DRAW_ABORTED_CANT_DRAW; |
| 1174 } | 1056 } |
| 1175 | 1057 |
| 1176 if (draw_frame) { | 1058 if (draw_frame) { |
| 1177 impl().layer_tree_host_impl->DrawLayers( | 1059 impl().layer_tree_host_impl->DrawLayers( |
| 1178 &frame, impl().scheduler->LastBeginImplFrameTime()); | 1060 &frame, impl().scheduler->LastBeginImplFrameTime()); |
| 1179 result.draw_result = DrawSwapReadbackResult::DRAW_SUCCESS; | 1061 result.draw_result = DrawSwapReadbackResult::DRAW_SUCCESS; |
| 1180 impl().animations_frozen_until_next_draw = false; | 1062 impl().animations_frozen_until_next_draw = false; |
| 1181 } else if (result.draw_result == | 1063 } else if (result.draw_result == |
| 1182 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS && | 1064 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS && |
| 1183 !impl().layer_tree_host_impl->settings().impl_side_painting) { | 1065 !impl().layer_tree_host_impl->settings().impl_side_painting) { |
| 1184 // Without impl-side painting, the animated layer that is checkerboarding | 1066 // Without impl-side painting, the animated layer that is checkerboarding |
| 1185 // will continue to checkerboard until the next commit. If this layer | 1067 // will continue to checkerboard until the next commit. If this layer |
| 1186 // continues to move during the commit, it may continue to checkerboard | 1068 // continues to move during the commit, it may continue to checkerboard |
| 1187 // after the commit since the region rasterized during the commit will not | 1069 // after the commit since the region rasterized during the commit will not |
| 1188 // match the region that is currently visible; eventually this | 1070 // match the region that is currently visible; eventually this |
| 1189 // checkerboarding will be displayed when we force a draw. To avoid this, | 1071 // checkerboarding will be displayed when we force a draw. To avoid this, |
| 1190 // we freeze animations until we successfully draw. | 1072 // we freeze animations until we successfully draw. |
| 1191 impl().animations_frozen_until_next_draw = true; | 1073 impl().animations_frozen_until_next_draw = true; |
| 1192 } else { | 1074 } else { |
| 1193 DCHECK_NE(DrawSwapReadbackResult::DRAW_SUCCESS, result.draw_result); | 1075 DCHECK_NE(DrawSwapReadbackResult::DRAW_SUCCESS, result.draw_result); |
| 1194 } | 1076 } |
| 1195 impl().layer_tree_host_impl->DidDrawAllLayers(frame); | 1077 impl().layer_tree_host_impl->DidDrawAllLayers(frame); |
| 1196 | 1078 |
| 1197 bool start_ready_animations = draw_frame; | 1079 bool start_ready_animations = draw_frame; |
| 1198 impl().layer_tree_host_impl->UpdateAnimationState(start_ready_animations); | 1080 impl().layer_tree_host_impl->UpdateAnimationState(start_ready_animations); |
| 1199 | 1081 |
| 1200 // Check for a pending CompositeAndReadback. | 1082 if (draw_frame) { |
| 1201 if (drawing_for_readback) { | |
| 1202 DCHECK(!swap_requested); | |
| 1203 result.did_readback = false; | |
| 1204 if (draw_frame) { | |
| 1205 if (!impl().layer_tree_host_impl->IsContextLost()) { | |
| 1206 impl().layer_tree_host_impl->Readback(impl().readback_request->pixels, | |
| 1207 impl().readback_request->rect); | |
| 1208 result.did_readback = true; | |
| 1209 } else { | |
| 1210 result.draw_result = DrawSwapReadbackResult::DRAW_ABORTED_CONTEXT_LOST; | |
| 1211 } | |
| 1212 } | |
| 1213 impl().readback_request->success = result.did_readback; | |
| 1214 impl().readback_request->completion.Signal(); | |
| 1215 impl().readback_request = NULL; | |
| 1216 } else if (draw_frame) { | |
| 1217 DCHECK(swap_requested); | |
| 1218 result.did_request_swap = impl().layer_tree_host_impl->SwapBuffers(frame); | 1083 result.did_request_swap = impl().layer_tree_host_impl->SwapBuffers(frame); |
| 1219 | 1084 |
| 1220 // We don't know if we have incomplete tiles if we didn't actually swap. | 1085 // We don't know if we have incomplete tiles if we didn't actually swap. |
| 1221 if (result.did_request_swap) { | 1086 if (result.did_request_swap) { |
| 1222 DCHECK(!frame.has_no_damage); | 1087 DCHECK(!frame.has_no_damage); |
| 1223 SetSwapUsedIncompleteTileOnImplThread(frame.contains_incomplete_tile); | 1088 SetSwapUsedIncompleteTileOnImplThread(frame.contains_incomplete_tile); |
| 1224 } | 1089 } |
| 1225 } | 1090 } |
| 1226 | 1091 |
| 1227 // Tell the main thread that the the newly-commited frame was drawn. | 1092 // Tell the main thread that the the newly-commited frame was drawn. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1273 | 1138 |
| 1274 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapIfPossible() { | 1139 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapIfPossible() { |
| 1275 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap"); | 1140 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap"); |
| 1276 | 1141 |
| 1277 // SchedulerStateMachine::DidDrawIfPossibleCompleted isn't set up to | 1142 // SchedulerStateMachine::DidDrawIfPossibleCompleted isn't set up to |
| 1278 // handle DRAW_ABORTED_CANT_DRAW. Moreover, the scheduler should | 1143 // handle DRAW_ABORTED_CANT_DRAW. Moreover, the scheduler should |
| 1279 // never generate this call when it can't draw. | 1144 // never generate this call when it can't draw. |
| 1280 DCHECK(impl().layer_tree_host_impl->CanDraw()); | 1145 DCHECK(impl().layer_tree_host_impl->CanDraw()); |
| 1281 | 1146 |
| 1282 bool forced_draw = false; | 1147 bool forced_draw = false; |
| 1283 bool swap_requested = true; | 1148 return DrawSwapInternal(forced_draw); |
| 1284 bool readback_requested = false; | |
| 1285 return DrawSwapReadbackInternal( | |
| 1286 forced_draw, swap_requested, readback_requested); | |
| 1287 } | 1149 } |
| 1288 | 1150 |
| 1289 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapForced() { | 1151 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapForced() { |
| 1290 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwapForced"); | 1152 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwapForced"); |
| 1291 bool forced_draw = true; | 1153 bool forced_draw = true; |
| 1292 bool swap_requested = true; | 1154 return DrawSwapInternal(forced_draw); |
| 1293 bool readback_requested = false; | |
| 1294 return DrawSwapReadbackInternal( | |
| 1295 forced_draw, swap_requested, readback_requested); | |
| 1296 } | 1155 } |
| 1297 | 1156 |
| 1298 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndReadback() { | 1157 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndReadback() { |
| 1299 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndReadback"); | 1158 NOTREACHED(); |
| 1300 bool forced_draw = true; | 1159 return DrawSwapReadbackResult(); |
| 1301 bool swap_requested = false; | |
| 1302 bool readback_requested = true; | |
| 1303 return DrawSwapReadbackInternal( | |
| 1304 forced_draw, swap_requested, readback_requested); | |
| 1305 } | 1160 } |
| 1306 | 1161 |
| 1307 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { | 1162 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { |
| 1308 if (impl().current_resource_update_controller) | 1163 if (impl().current_resource_update_controller) |
| 1309 impl().current_resource_update_controller->PerformMoreUpdates(time); | 1164 impl().current_resource_update_controller->PerformMoreUpdates(time); |
| 1310 } | 1165 } |
| 1311 | 1166 |
| 1312 base::TimeDelta ThreadProxy::DrawDurationEstimate() { | 1167 base::TimeDelta ThreadProxy::DrawDurationEstimate() { |
| 1313 return impl().timing_history.DrawDurationEstimate(); | 1168 return impl().timing_history.DrawDurationEstimate(); |
| 1314 } | 1169 } |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1653 | 1508 |
| 1654 impl().timing_history.DidActivatePendingTree(); | 1509 impl().timing_history.DidActivatePendingTree(); |
| 1655 } | 1510 } |
| 1656 | 1511 |
| 1657 void ThreadProxy::DidManageTiles() { | 1512 void ThreadProxy::DidManageTiles() { |
| 1658 DCHECK(IsImplThread()); | 1513 DCHECK(IsImplThread()); |
| 1659 impl().scheduler->DidManageTiles(); | 1514 impl().scheduler->DidManageTiles(); |
| 1660 } | 1515 } |
| 1661 | 1516 |
| 1662 } // namespace cc | 1517 } // namespace cc |
| OLD | NEW |