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/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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 return GL_TEXTURE_2D; | 160 return GL_TEXTURE_2D; |
| 161 } | 161 } |
| 162 | 162 |
| 163 size_t GetMaxStagingResourceCount() { | 163 size_t GetMaxStagingResourceCount() { |
| 164 // Upper bound for number of staging resource to allow. | 164 // Upper bound for number of staging resource to allow. |
| 165 return 32; | 165 return 32; |
| 166 } | 166 } |
| 167 | 167 |
| 168 } // namespace | 168 } // namespace |
| 169 | 169 |
| 170 class LayerTreeHostImplTimeSourceAdapter : public TimeSourceClient { | |
| 171 public: | |
| 172 static scoped_ptr<LayerTreeHostImplTimeSourceAdapter> Create( | |
| 173 LayerTreeHostImpl* layer_tree_host_impl, | |
| 174 scoped_refptr<DelayBasedTimeSource> time_source) { | |
| 175 return make_scoped_ptr( | |
| 176 new LayerTreeHostImplTimeSourceAdapter(layer_tree_host_impl, | |
| 177 time_source)); | |
| 178 } | |
| 179 ~LayerTreeHostImplTimeSourceAdapter() override { | |
| 180 time_source_->SetClient(NULL); | |
| 181 time_source_->SetActive(false); | |
| 182 } | |
| 183 | |
| 184 void OnTimerTick() override { | |
| 185 // In single threaded mode we attempt to simulate changing the current | |
| 186 // thread by maintaining a fake thread id. When we switch from one | |
| 187 // thread to another, we construct DebugScopedSetXXXThread objects that | |
| 188 // update the thread id. This lets DCHECKS that ensure we're on the | |
| 189 // right thread to work correctly in single threaded mode. The problem | |
| 190 // here is that the timer tasks are run via the message loop, and when | |
| 191 // they run, we've had no chance to construct a DebugScopedSetXXXThread | |
| 192 // object. The result is that we report that we're running on the main | |
| 193 // thread. In multi-threaded mode, this timer is run on the compositor | |
| 194 // thread, so to keep this consistent in single-threaded mode, we'll | |
| 195 // construct a DebugScopedSetImplThread object. There is no need to do | |
| 196 // this in multi-threaded mode since the real thread id's will be | |
| 197 // correct. In fact, setting fake thread id's interferes with the real | |
| 198 // thread id's and causes breakage. | |
| 199 scoped_ptr<DebugScopedSetImplThread> set_impl_thread; | |
| 200 if (!layer_tree_host_impl_->proxy()->HasImplThread()) { | |
| 201 set_impl_thread.reset( | |
| 202 new DebugScopedSetImplThread(layer_tree_host_impl_->proxy())); | |
| 203 } | |
| 204 | |
| 205 layer_tree_host_impl_->Animate( | |
| 206 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time); | |
| 207 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true); | |
| 208 bool start_ready_animations = true; | |
| 209 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | |
| 210 | |
| 211 if (layer_tree_host_impl_->pending_tree()) { | |
| 212 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties(); | |
| 213 layer_tree_host_impl_->ManageTiles(); | |
| 214 } | |
| 215 | |
| 216 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); | |
| 217 } | |
| 218 | |
| 219 void SetActive(bool active) { | |
| 220 if (active != time_source_->Active()) | |
| 221 time_source_->SetActive(active); | |
| 222 } | |
| 223 | |
| 224 bool Active() const { return time_source_->Active(); } | |
| 225 | |
| 226 private: | |
| 227 LayerTreeHostImplTimeSourceAdapter( | |
| 228 LayerTreeHostImpl* layer_tree_host_impl, | |
| 229 scoped_refptr<DelayBasedTimeSource> time_source) | |
| 230 : layer_tree_host_impl_(layer_tree_host_impl), | |
| 231 time_source_(time_source) { | |
| 232 time_source_->SetClient(this); | |
| 233 } | |
| 234 | |
| 235 LayerTreeHostImpl* layer_tree_host_impl_; | |
| 236 scoped_refptr<DelayBasedTimeSource> time_source_; | |
| 237 | |
| 238 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImplTimeSourceAdapter); | |
| 239 }; | |
| 240 | |
| 241 LayerTreeHostImpl::FrameData::FrameData() | 170 LayerTreeHostImpl::FrameData::FrameData() |
| 242 : contains_incomplete_tile(false), has_no_damage(false) {} | 171 : contains_incomplete_tile(false), has_no_damage(false) {} |
| 243 | 172 |
| 244 LayerTreeHostImpl::FrameData::~FrameData() {} | 173 LayerTreeHostImpl::FrameData::~FrameData() {} |
| 245 | 174 |
| 246 scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create( | 175 scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create( |
| 247 const LayerTreeSettings& settings, | 176 const LayerTreeSettings& settings, |
| 248 LayerTreeHostImplClient* client, | 177 LayerTreeHostImplClient* client, |
| 249 Proxy* proxy, | 178 Proxy* proxy, |
| 250 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 179 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 961 << frame->render_passes.size(); | 890 << frame->render_passes.size(); |
| 962 | 891 |
| 963 return draw_result; | 892 return draw_result; |
| 964 } | 893 } |
| 965 | 894 |
| 966 void LayerTreeHostImpl::MainThreadHasStoppedFlinging() { | 895 void LayerTreeHostImpl::MainThreadHasStoppedFlinging() { |
| 967 if (input_handler_client_) | 896 if (input_handler_client_) |
| 968 input_handler_client_->MainThreadHasStoppedFlinging(); | 897 input_handler_client_->MainThreadHasStoppedFlinging(); |
| 969 } | 898 } |
| 970 | 899 |
| 971 void LayerTreeHostImpl::UpdateBackgroundAnimateTicking( | |
| 972 bool should_background_tick) { | |
| 973 DCHECK(proxy_->IsImplThread()); | |
| 974 if (should_background_tick) | |
| 975 DCHECK(active_tree_->root_layer()); | |
| 976 | |
| 977 bool enabled = should_background_tick && needs_animate_layers(); | |
| 978 | |
| 979 // Lazily create the time_source adapter so that we can vary the interval for | |
| 980 // testing. | |
| 981 if (!time_source_client_adapter_) { | |
| 982 time_source_client_adapter_ = LayerTreeHostImplTimeSourceAdapter::Create( | |
| 983 this, | |
| 984 DelayBasedTimeSource::Create( | |
| 985 LowFrequencyAnimationInterval(), | |
| 986 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() | |
| 987 : proxy_->MainThreadTaskRunner())); | |
| 988 } | |
| 989 | |
| 990 time_source_client_adapter_->SetActive(enabled); | |
| 991 } | |
| 992 | |
| 993 void LayerTreeHostImpl::DidAnimateScrollOffset() { | 900 void LayerTreeHostImpl::DidAnimateScrollOffset() { |
| 994 client_->SetNeedsCommitOnImplThread(); | 901 client_->SetNeedsCommitOnImplThread(); |
| 995 client_->RenewTreePriority(); | 902 client_->RenewTreePriority(); |
| 996 } | 903 } |
| 997 | 904 |
| 998 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) { | 905 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) { |
| 999 viewport_damage_rect_.Union(damage_rect); | 906 viewport_damage_rect_.Union(damage_rect); |
| 1000 } | 907 } |
| 1001 | 908 |
| 1002 static inline RenderPass* FindRenderPassById( | 909 static inline RenderPass* FindRenderPassById( |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1872 tree_activation_callback_.Run(); | 1779 tree_activation_callback_.Run(); |
| 1873 | 1780 |
| 1874 if (debug_state_.continuous_painting) { | 1781 if (debug_state_.continuous_painting) { |
| 1875 const RenderingStats& stats = | 1782 const RenderingStats& stats = |
| 1876 rendering_stats_instrumentation_->GetRenderingStats(); | 1783 rendering_stats_instrumentation_->GetRenderingStats(); |
| 1877 paint_time_counter_->SavePaintTime(stats.main_stats.paint_time + | 1784 paint_time_counter_->SavePaintTime(stats.main_stats.paint_time + |
| 1878 stats.main_stats.record_time + | 1785 stats.main_stats.record_time + |
| 1879 stats.impl_stats.rasterize_time); | 1786 stats.impl_stats.rasterize_time); |
| 1880 } | 1787 } |
| 1881 | 1788 |
| 1882 if (time_source_client_adapter_ && time_source_client_adapter_->Active()) | |
| 1883 DCHECK(active_tree_->root_layer()); | |
| 1884 | |
| 1885 scoped_ptr<PageScaleAnimation> page_scale_animation = | 1789 scoped_ptr<PageScaleAnimation> page_scale_animation = |
| 1886 active_tree_->TakePageScaleAnimation(); | 1790 active_tree_->TakePageScaleAnimation(); |
| 1887 if (page_scale_animation) { | 1791 if (page_scale_animation) { |
| 1888 page_scale_animation_ = page_scale_animation.Pass(); | 1792 page_scale_animation_ = page_scale_animation.Pass(); |
| 1889 SetNeedsAnimate(); | 1793 SetNeedsAnimate(); |
| 1890 client_->SetNeedsCommitOnImplThread(); | 1794 client_->SetNeedsCommitOnImplThread(); |
| 1891 client_->RenewTreePriority(); | 1795 client_->RenewTreePriority(); |
| 1892 } | 1796 } |
| 1893 } | 1797 } |
| 1894 | 1798 |
| (...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3182 !active_tree_->root_layer()) | 3086 !active_tree_->root_layer()) |
| 3183 return; | 3087 return; |
| 3184 | 3088 |
| 3185 TRACE_EVENT0("cc", "LayerTreeHostImpl::ActivateAnimations"); | 3089 TRACE_EVENT0("cc", "LayerTreeHostImpl::ActivateAnimations"); |
| 3186 AnimationRegistrar::AnimationControllerMap copy = | 3090 AnimationRegistrar::AnimationControllerMap copy = |
| 3187 animation_registrar_->active_animation_controllers(); | 3091 animation_registrar_->active_animation_controllers(); |
| 3188 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); | 3092 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); |
| 3189 iter != copy.end(); | 3093 iter != copy.end(); |
| 3190 ++iter) | 3094 ++iter) |
| 3191 (*iter).second->ActivateAnimations(); | 3095 (*iter).second->ActivateAnimations(); |
| 3192 } | |
| 3193 | 3096 |
| 3194 base::TimeDelta LayerTreeHostImpl::LowFrequencyAnimationInterval() const { | 3097 SetNeedsAnimate(); |
|
brianderson
2014/11/04 18:54:38
How is this SetNeedsAnimate related to background
mithro-old
2014/11/04 22:16:50
This is needed otherwise SetNeedsAnimate is not al
| |
| 3195 return base::TimeDelta::FromSeconds(1); | |
| 3196 } | 3098 } |
| 3197 | 3099 |
| 3198 std::string LayerTreeHostImpl::LayerTreeAsJson() const { | 3100 std::string LayerTreeHostImpl::LayerTreeAsJson() const { |
| 3199 std::string str; | 3101 std::string str; |
| 3200 if (active_tree_->root_layer()) { | 3102 if (active_tree_->root_layer()) { |
| 3201 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson()); | 3103 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson()); |
| 3202 base::JSONWriter::WriteWithOptions( | 3104 base::JSONWriter::WriteWithOptions( |
| 3203 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str); | 3105 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str); |
| 3204 } | 3106 } |
| 3205 return str; | 3107 return str; |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3514 } | 3416 } |
| 3515 | 3417 |
| 3516 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3418 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
| 3517 std::vector<PictureLayerImpl*>::iterator it = | 3419 std::vector<PictureLayerImpl*>::iterator it = |
| 3518 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3420 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
| 3519 DCHECK(it != picture_layers_.end()); | 3421 DCHECK(it != picture_layers_.end()); |
| 3520 picture_layers_.erase(it); | 3422 picture_layers_.erase(it); |
| 3521 } | 3423 } |
| 3522 | 3424 |
| 3523 } // namespace cc | 3425 } // namespace cc |
| OLD | NEW |