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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "cc/base/thread.h" | 10 #include "cc/base/thread.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "cc/trees/layer_tree_impl.h" | 21 #include "cc/trees/layer_tree_impl.h" |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 // Measured in seconds. | 25 // Measured in seconds. |
26 const double kContextRecreationTickRate = 0.03; | 26 const double kContextRecreationTickRate = 0.03; |
27 | 27 |
28 // Measured in seconds. | 28 // Measured in seconds. |
29 const double kSmoothnessTakesPriorityExpirationDelay = 0.25; | 29 const double kSmoothnessTakesPriorityExpirationDelay = 0.25; |
30 | 30 |
31 const size_t kDrawDurationHistorySize = 60; | |
ajuma
2013/06/06 18:00:35
We might actually want something smaller than this
| |
32 const double kDrawDurationEstimationPercentile = 100.0; | |
33 const int kDrawDurationEstimatePaddingInMicroseconds = 0; | |
ajuma
2013/06/06 18:00:35
The padding serves 2 purposes: First, by using app
| |
34 | |
31 } // namespace | 35 } // namespace |
32 | 36 |
33 namespace cc { | 37 namespace cc { |
34 | 38 |
35 scoped_ptr<Proxy> ThreadProxy::Create(LayerTreeHost* layer_tree_host, | 39 scoped_ptr<Proxy> ThreadProxy::Create(LayerTreeHost* layer_tree_host, |
36 scoped_ptr<Thread> impl_thread) { | 40 scoped_ptr<Thread> impl_thread) { |
37 return make_scoped_ptr( | 41 return make_scoped_ptr( |
38 new ThreadProxy(layer_tree_host, impl_thread.Pass())).PassAs<Proxy>(); | 42 new ThreadProxy(layer_tree_host, impl_thread.Pass())).PassAs<Proxy>(); |
39 } | 43 } |
40 | 44 |
(...skipping 19 matching lines...) Expand all Loading... | |
60 next_frame_is_newly_committed_frame_on_impl_thread_(false), | 64 next_frame_is_newly_committed_frame_on_impl_thread_(false), |
61 throttle_frame_production_( | 65 throttle_frame_production_( |
62 layer_tree_host->settings().throttle_frame_production), | 66 layer_tree_host->settings().throttle_frame_production), |
63 begin_frame_scheduling_enabled_( | 67 begin_frame_scheduling_enabled_( |
64 layer_tree_host->settings().begin_frame_scheduling_enabled), | 68 layer_tree_host->settings().begin_frame_scheduling_enabled), |
65 using_synchronous_renderer_compositor_( | 69 using_synchronous_renderer_compositor_( |
66 layer_tree_host->settings().using_synchronous_renderer_compositor), | 70 layer_tree_host->settings().using_synchronous_renderer_compositor), |
67 vsync_client_(NULL), | 71 vsync_client_(NULL), |
68 inside_draw_(false), | 72 inside_draw_(false), |
69 defer_commits_(false), | 73 defer_commits_(false), |
70 renew_tree_priority_on_impl_thread_pending_(false) { | 74 renew_tree_priority_on_impl_thread_pending_(false), |
75 draw_duration_history_(kDrawDurationHistorySize) { | |
71 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); | 76 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); |
72 DCHECK(IsMainThread()); | 77 DCHECK(IsMainThread()); |
73 DCHECK(layer_tree_host_); | 78 DCHECK(layer_tree_host_); |
74 } | 79 } |
75 | 80 |
76 ThreadProxy::~ThreadProxy() { | 81 ThreadProxy::~ThreadProxy() { |
77 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); | 82 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); |
78 DCHECK(IsMainThread()); | 83 DCHECK(IsMainThread()); |
79 DCHECK(!started_); | 84 DCHECK(!started_); |
80 } | 85 } |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
885 DCHECK(IsImplThread()); | 890 DCHECK(IsImplThread()); |
886 Proxy::MainThread()->PostTask( | 891 Proxy::MainThread()->PostTask( |
887 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, | 892 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, |
888 main_thread_weak_ptr_)); | 893 main_thread_weak_ptr_)); |
889 } | 894 } |
890 | 895 |
891 ScheduledActionDrawAndSwapResult | 896 ScheduledActionDrawAndSwapResult |
892 ThreadProxy::ScheduledActionDrawAndSwapInternal(bool forced_draw) { | 897 ThreadProxy::ScheduledActionDrawAndSwapInternal(bool forced_draw) { |
893 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap"); | 898 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap"); |
894 | 899 |
900 base::TimeTicks start_time = base::TimeTicks::Now(); | |
895 base::AutoReset<bool> mark_inside(&inside_draw_, true); | 901 base::AutoReset<bool> mark_inside(&inside_draw_, true); |
896 | 902 |
897 ScheduledActionDrawAndSwapResult result; | 903 ScheduledActionDrawAndSwapResult result; |
898 result.did_draw = false; | 904 result.did_draw = false; |
899 result.did_swap = false; | 905 result.did_swap = false; |
900 DCHECK(IsImplThread()); | 906 DCHECK(IsImplThread()); |
901 DCHECK(layer_tree_host_impl_.get()); | 907 DCHECK(layer_tree_host_impl_.get()); |
902 if (!layer_tree_host_impl_) | 908 if (!layer_tree_host_impl_) |
903 return result; | 909 return result; |
904 | 910 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
976 DidSwapUseIncompleteTileOnImplThread(); | 982 DidSwapUseIncompleteTileOnImplThread(); |
977 } | 983 } |
978 | 984 |
979 // Tell the main thread that the the newly-commited frame was drawn. | 985 // Tell the main thread that the the newly-commited frame was drawn. |
980 if (next_frame_is_newly_committed_frame_on_impl_thread_) { | 986 if (next_frame_is_newly_committed_frame_on_impl_thread_) { |
981 next_frame_is_newly_committed_frame_on_impl_thread_ = false; | 987 next_frame_is_newly_committed_frame_on_impl_thread_ = false; |
982 Proxy::MainThread()->PostTask( | 988 Proxy::MainThread()->PostTask( |
983 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); | 989 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); |
984 } | 990 } |
985 | 991 |
986 if (draw_frame) | 992 if (draw_frame) { |
987 CheckOutputSurfaceStatusOnImplThread(); | 993 CheckOutputSurfaceStatusOnImplThread(); |
994 base::TimeTicks end_time = base::TimeTicks::Now(); | |
995 draw_duration_history_.InsertSample(end_time - start_time); | |
996 } | |
988 | 997 |
989 return result; | 998 return result; |
990 } | 999 } |
991 | 1000 |
992 void ThreadProxy::AcquireLayerTextures() { | 1001 void ThreadProxy::AcquireLayerTextures() { |
993 // Called when the main thread needs to modify a layer texture that is used | 1002 // Called when the main thread needs to modify a layer texture that is used |
994 // directly by the compositor. | 1003 // directly by the compositor. |
995 // This method will block until the next compositor draw if there is a | 1004 // This method will block until the next compositor draw if there is a |
996 // previously committed frame that is still undrawn. This is necessary to | 1005 // previously committed frame that is still undrawn. This is necessary to |
997 // ensure that the main thread does not monopolize access to the textures. | 1006 // ensure that the main thread does not monopolize access to the textures. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1038 return ScheduledActionDrawAndSwapInternal(true); | 1047 return ScheduledActionDrawAndSwapInternal(true); |
1039 } | 1048 } |
1040 | 1049 |
1041 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { | 1050 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { |
1042 if (current_resource_update_controller_on_impl_thread_) | 1051 if (current_resource_update_controller_on_impl_thread_) |
1043 current_resource_update_controller_on_impl_thread_ | 1052 current_resource_update_controller_on_impl_thread_ |
1044 ->PerformMoreUpdates(time); | 1053 ->PerformMoreUpdates(time); |
1045 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | 1054 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
1046 } | 1055 } |
1047 | 1056 |
1057 base::TimeDelta ThreadProxy::DrawDurationEstimate() { | |
1058 base::TimeDelta historical_estimate = | |
1059 draw_duration_history_.Percentile(kDrawDurationEstimationPercentile); | |
1060 base::TimeDelta padding = base::TimeDelta::FromMicroseconds( | |
1061 kDrawDurationEstimatePaddingInMicroseconds); | |
1062 return historical_estimate + padding; | |
1063 } | |
1064 | |
1048 void ThreadProxy::ReadyToFinalizeTextureUpdates() { | 1065 void ThreadProxy::ReadyToFinalizeTextureUpdates() { |
1049 DCHECK(IsImplThread()); | 1066 DCHECK(IsImplThread()); |
1050 scheduler_on_impl_thread_->FinishCommit(); | 1067 scheduler_on_impl_thread_->FinishCommit(); |
1051 } | 1068 } |
1052 | 1069 |
1053 void ThreadProxy::DidCommitAndDrawFrame() { | 1070 void ThreadProxy::DidCommitAndDrawFrame() { |
1054 DCHECK(IsMainThread()); | 1071 DCHECK(IsMainThread()); |
1055 if (!layer_tree_host_) | 1072 if (!layer_tree_host_) |
1056 return; | 1073 return; |
1057 layer_tree_host_->DidCommitAndDrawFrame(); | 1074 layer_tree_host_->DidCommitAndDrawFrame(); |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1386 !layer_tree_host_impl_->pending_tree()) { | 1403 !layer_tree_host_impl_->pending_tree()) { |
1387 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation", | 1404 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation", |
1388 TRACE_EVENT_SCOPE_THREAD); | 1405 TRACE_EVENT_SCOPE_THREAD); |
1389 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); | 1406 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); |
1390 completion_event_for_commit_held_on_tree_activation_->Signal(); | 1407 completion_event_for_commit_held_on_tree_activation_->Signal(); |
1391 completion_event_for_commit_held_on_tree_activation_ = NULL; | 1408 completion_event_for_commit_held_on_tree_activation_ = NULL; |
1392 } | 1409 } |
1393 } | 1410 } |
1394 | 1411 |
1395 } // namespace cc | 1412 } // namespace cc |
OLD | NEW |