| 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/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 return GL_TEXTURE_2D; | 166 return GL_TEXTURE_2D; |
| 167 } | 167 } |
| 168 | 168 |
| 169 size_t GetMaxStagingResourceCount() { | 169 size_t GetMaxStagingResourceCount() { |
| 170 // Upper bound for number of staging resource to allow. | 170 // Upper bound for number of staging resource to allow. |
| 171 return 32; | 171 return 32; |
| 172 } | 172 } |
| 173 | 173 |
| 174 } // namespace | 174 } // namespace |
| 175 | 175 |
| 176 class LayerTreeHostImplTimeSourceAdapter : public TimeSourceClient { | |
| 177 public: | |
| 178 static scoped_ptr<LayerTreeHostImplTimeSourceAdapter> Create( | |
| 179 LayerTreeHostImpl* layer_tree_host_impl, | |
| 180 scoped_refptr<DelayBasedTimeSource> time_source) { | |
| 181 return make_scoped_ptr( | |
| 182 new LayerTreeHostImplTimeSourceAdapter(layer_tree_host_impl, | |
| 183 time_source)); | |
| 184 } | |
| 185 ~LayerTreeHostImplTimeSourceAdapter() override { | |
| 186 time_source_->SetClient(NULL); | |
| 187 time_source_->SetActive(false); | |
| 188 } | |
| 189 | |
| 190 void OnTimerTick() override { | |
| 191 // In single threaded mode we attempt to simulate changing the current | |
| 192 // thread by maintaining a fake thread id. When we switch from one | |
| 193 // thread to another, we construct DebugScopedSetXXXThread objects that | |
| 194 // update the thread id. This lets DCHECKS that ensure we're on the | |
| 195 // right thread to work correctly in single threaded mode. The problem | |
| 196 // here is that the timer tasks are run via the message loop, and when | |
| 197 // they run, we've had no chance to construct a DebugScopedSetXXXThread | |
| 198 // object. The result is that we report that we're running on the main | |
| 199 // thread. In multi-threaded mode, this timer is run on the compositor | |
| 200 // thread, so to keep this consistent in single-threaded mode, we'll | |
| 201 // construct a DebugScopedSetImplThread object. There is no need to do | |
| 202 // this in multi-threaded mode since the real thread id's will be | |
| 203 // correct. In fact, setting fake thread id's interferes with the real | |
| 204 // thread id's and causes breakage. | |
| 205 scoped_ptr<DebugScopedSetImplThread> set_impl_thread; | |
| 206 if (!layer_tree_host_impl_->proxy()->HasImplThread()) { | |
| 207 set_impl_thread.reset( | |
| 208 new DebugScopedSetImplThread(layer_tree_host_impl_->proxy())); | |
| 209 } | |
| 210 | |
| 211 layer_tree_host_impl_->Animate( | |
| 212 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time); | |
| 213 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true); | |
| 214 bool start_ready_animations = true; | |
| 215 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | |
| 216 | |
| 217 if (layer_tree_host_impl_->pending_tree()) { | |
| 218 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties(); | |
| 219 layer_tree_host_impl_->ManageTiles(); | |
| 220 } | |
| 221 | |
| 222 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); | |
| 223 } | |
| 224 | |
| 225 void SetActive(bool active) { | |
| 226 if (active != time_source_->Active()) | |
| 227 time_source_->SetActive(active); | |
| 228 } | |
| 229 | |
| 230 bool Active() const { return time_source_->Active(); } | |
| 231 | |
| 232 private: | |
| 233 LayerTreeHostImplTimeSourceAdapter( | |
| 234 LayerTreeHostImpl* layer_tree_host_impl, | |
| 235 scoped_refptr<DelayBasedTimeSource> time_source) | |
| 236 : layer_tree_host_impl_(layer_tree_host_impl), | |
| 237 time_source_(time_source) { | |
| 238 time_source_->SetClient(this); | |
| 239 } | |
| 240 | |
| 241 LayerTreeHostImpl* layer_tree_host_impl_; | |
| 242 scoped_refptr<DelayBasedTimeSource> time_source_; | |
| 243 | |
| 244 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImplTimeSourceAdapter); | |
| 245 }; | |
| 246 | |
| 247 LayerTreeHostImpl::FrameData::FrameData() | 176 LayerTreeHostImpl::FrameData::FrameData() |
| 248 : contains_incomplete_tile(false), has_no_damage(false) {} | 177 : contains_incomplete_tile(false), has_no_damage(false) {} |
| 249 | 178 |
| 250 LayerTreeHostImpl::FrameData::~FrameData() {} | 179 LayerTreeHostImpl::FrameData::~FrameData() {} |
| 251 | 180 |
| 252 scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create( | 181 scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create( |
| 253 const LayerTreeSettings& settings, | 182 const LayerTreeSettings& settings, |
| 254 LayerTreeHostImplClient* client, | 183 LayerTreeHostImplClient* client, |
| 255 Proxy* proxy, | 184 Proxy* proxy, |
| 256 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 185 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 << frame->render_passes.size(); | 896 << frame->render_passes.size(); |
| 968 | 897 |
| 969 return draw_result; | 898 return draw_result; |
| 970 } | 899 } |
| 971 | 900 |
| 972 void LayerTreeHostImpl::MainThreadHasStoppedFlinging() { | 901 void LayerTreeHostImpl::MainThreadHasStoppedFlinging() { |
| 973 if (input_handler_client_) | 902 if (input_handler_client_) |
| 974 input_handler_client_->MainThreadHasStoppedFlinging(); | 903 input_handler_client_->MainThreadHasStoppedFlinging(); |
| 975 } | 904 } |
| 976 | 905 |
| 977 void LayerTreeHostImpl::UpdateBackgroundAnimateTicking( | |
| 978 bool should_background_tick) { | |
| 979 DCHECK(proxy_->IsImplThread()); | |
| 980 if (should_background_tick) | |
| 981 DCHECK(active_tree_->root_layer()); | |
| 982 | |
| 983 bool enabled = should_background_tick && needs_animate_layers(); | |
| 984 | |
| 985 // Lazily create the time_source adapter so that we can vary the interval for | |
| 986 // testing. | |
| 987 if (!time_source_client_adapter_) { | |
| 988 time_source_client_adapter_ = LayerTreeHostImplTimeSourceAdapter::Create( | |
| 989 this, | |
| 990 DelayBasedTimeSource::Create( | |
| 991 LowFrequencyAnimationInterval(), | |
| 992 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() | |
| 993 : proxy_->MainThreadTaskRunner())); | |
| 994 } | |
| 995 | |
| 996 time_source_client_adapter_->SetActive(enabled); | |
| 997 } | |
| 998 | |
| 999 void LayerTreeHostImpl::DidAnimateScrollOffset() { | 906 void LayerTreeHostImpl::DidAnimateScrollOffset() { |
| 1000 client_->SetNeedsCommitOnImplThread(); | 907 client_->SetNeedsCommitOnImplThread(); |
| 1001 client_->RenewTreePriority(); | 908 client_->RenewTreePriority(); |
| 1002 } | 909 } |
| 1003 | 910 |
| 1004 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) { | 911 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) { |
| 1005 viewport_damage_rect_.Union(damage_rect); | 912 viewport_damage_rect_.Union(damage_rect); |
| 1006 } | 913 } |
| 1007 | 914 |
| 1008 static inline RenderPass* FindRenderPassById( | 915 static inline RenderPass* FindRenderPassById( |
| (...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 if (debug_state_.continuous_painting) { | 1788 if (debug_state_.continuous_painting) { |
| 1882 const RenderingStats& stats = | 1789 const RenderingStats& stats = |
| 1883 rendering_stats_instrumentation_->GetRenderingStats(); | 1790 rendering_stats_instrumentation_->GetRenderingStats(); |
| 1884 // TODO(hendrikw): This requires a different metric when we commit directly | 1791 // TODO(hendrikw): This requires a different metric when we commit directly |
| 1885 // to the active tree. See crbug.com/429311. | 1792 // to the active tree. See crbug.com/429311. |
| 1886 paint_time_counter_->SavePaintTime( | 1793 paint_time_counter_->SavePaintTime( |
| 1887 stats.commit_to_activate_duration.GetLastTimeDelta() + | 1794 stats.commit_to_activate_duration.GetLastTimeDelta() + |
| 1888 stats.draw_duration.GetLastTimeDelta()); | 1795 stats.draw_duration.GetLastTimeDelta()); |
| 1889 } | 1796 } |
| 1890 | 1797 |
| 1891 if (time_source_client_adapter_ && time_source_client_adapter_->Active()) | |
| 1892 DCHECK(active_tree_->root_layer()); | |
| 1893 | |
| 1894 scoped_ptr<PageScaleAnimation> page_scale_animation = | 1798 scoped_ptr<PageScaleAnimation> page_scale_animation = |
| 1895 active_tree_->TakePageScaleAnimation(); | 1799 active_tree_->TakePageScaleAnimation(); |
| 1896 if (page_scale_animation) { | 1800 if (page_scale_animation) { |
| 1897 page_scale_animation_ = page_scale_animation.Pass(); | 1801 page_scale_animation_ = page_scale_animation.Pass(); |
| 1898 SetNeedsAnimate(); | 1802 SetNeedsAnimate(); |
| 1899 client_->SetNeedsCommitOnImplThread(); | 1803 client_->SetNeedsCommitOnImplThread(); |
| 1900 client_->RenewTreePriority(); | 1804 client_->RenewTreePriority(); |
| 1901 } | 1805 } |
| 1902 } | 1806 } |
| 1903 | 1807 |
| (...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3188 !active_tree_->root_layer()) | 3092 !active_tree_->root_layer()) |
| 3189 return; | 3093 return; |
| 3190 | 3094 |
| 3191 TRACE_EVENT0("cc", "LayerTreeHostImpl::ActivateAnimations"); | 3095 TRACE_EVENT0("cc", "LayerTreeHostImpl::ActivateAnimations"); |
| 3192 AnimationRegistrar::AnimationControllerMap copy = | 3096 AnimationRegistrar::AnimationControllerMap copy = |
| 3193 animation_registrar_->active_animation_controllers(); | 3097 animation_registrar_->active_animation_controllers(); |
| 3194 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); | 3098 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); |
| 3195 iter != copy.end(); | 3099 iter != copy.end(); |
| 3196 ++iter) | 3100 ++iter) |
| 3197 (*iter).second->ActivateAnimations(); | 3101 (*iter).second->ActivateAnimations(); |
| 3198 } | |
| 3199 | 3102 |
| 3200 base::TimeDelta LayerTreeHostImpl::LowFrequencyAnimationInterval() const { | 3103 SetNeedsAnimate(); |
| 3201 return base::TimeDelta::FromSeconds(1); | |
| 3202 } | 3104 } |
| 3203 | 3105 |
| 3204 std::string LayerTreeHostImpl::LayerTreeAsJson() const { | 3106 std::string LayerTreeHostImpl::LayerTreeAsJson() const { |
| 3205 std::string str; | 3107 std::string str; |
| 3206 if (active_tree_->root_layer()) { | 3108 if (active_tree_->root_layer()) { |
| 3207 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson()); | 3109 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson()); |
| 3208 base::JSONWriter::WriteWithOptions( | 3110 base::JSONWriter::WriteWithOptions( |
| 3209 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str); | 3111 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str); |
| 3210 } | 3112 } |
| 3211 return str; | 3113 return str; |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3520 } | 3422 } |
| 3521 | 3423 |
| 3522 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3424 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
| 3523 std::vector<PictureLayerImpl*>::iterator it = | 3425 std::vector<PictureLayerImpl*>::iterator it = |
| 3524 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3426 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
| 3525 DCHECK(it != picture_layers_.end()); | 3427 DCHECK(it != picture_layers_.end()); |
| 3526 picture_layers_.erase(it); | 3428 picture_layers_.erase(it); |
| 3527 } | 3429 } |
| 3528 | 3430 |
| 3529 } // namespace cc | 3431 } // namespace cc |
| OLD | NEW |