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 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 pinch_gesture_active_(false), | 223 pinch_gesture_active_(false), |
224 pinch_gesture_end_should_clear_scrolling_layer_(false), | 224 pinch_gesture_end_should_clear_scrolling_layer_(false), |
225 fps_counter_(FrameRateCounter::Create(proxy_->HasImplThread())), | 225 fps_counter_(FrameRateCounter::Create(proxy_->HasImplThread())), |
226 paint_time_counter_(PaintTimeCounter::Create()), | 226 paint_time_counter_(PaintTimeCounter::Create()), |
227 memory_history_(MemoryHistory::Create()), | 227 memory_history_(MemoryHistory::Create()), |
228 debug_rect_history_(DebugRectHistory::Create()), | 228 debug_rect_history_(DebugRectHistory::Create()), |
229 texture_mailbox_deleter_(new TextureMailboxDeleter(GetTaskRunner())), | 229 texture_mailbox_deleter_(new TextureMailboxDeleter(GetTaskRunner())), |
230 max_memory_needed_bytes_(0), | 230 max_memory_needed_bytes_(0), |
231 device_scale_factor_(1.f), | 231 device_scale_factor_(1.f), |
232 resourceless_software_draw_(false), | 232 resourceless_software_draw_(false), |
233 animation_registrar_(AnimationRegistrar::Create()), | 233 animation_registrar_(), |
234 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 234 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
235 micro_benchmark_controller_(this), | 235 micro_benchmark_controller_(this), |
236 shared_bitmap_manager_(shared_bitmap_manager), | 236 shared_bitmap_manager_(shared_bitmap_manager), |
237 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 237 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
238 task_graph_runner_(task_graph_runner), | 238 task_graph_runner_(task_graph_runner), |
239 id_(id), | 239 id_(id), |
240 requires_high_res_to_draw_(false), | 240 requires_high_res_to_draw_(false), |
241 is_likely_to_require_a_draw_(false), | 241 is_likely_to_require_a_draw_(false), |
242 frame_timing_tracker_(FrameTimingTracker::Create(this)) { | 242 frame_timing_tracker_(FrameTimingTracker::Create(this)) { |
243 if (settings.use_compositor_animation_timelines) { | 243 if (settings.use_compositor_animation_timelines) { |
244 animation_host_ = AnimationHost::Create(ThreadInstance::IMPL); | 244 if (settings.accelerated_animation_enabled) { |
245 animation_host_->SetMutatorHostClient(this); | 245 animation_host_ = AnimationHost::Create(ThreadInstance::IMPL); |
| 246 animation_host_->SetMutatorHostClient(this); |
| 247 animation_host_->SetSupportsScrollAnimations( |
| 248 proxy_->SupportsImplScrolling()); |
| 249 } |
| 250 } else { |
| 251 animation_registrar_ = AnimationRegistrar::Create(); |
| 252 animation_registrar_->set_supports_scroll_animations( |
| 253 proxy_->SupportsImplScrolling()); |
246 } | 254 } |
247 | 255 |
248 DCHECK(proxy_->IsImplThread()); | 256 DCHECK(proxy_->IsImplThread()); |
249 DCHECK_IMPLIES(settings.use_one_copy, !settings.use_zero_copy); | 257 DCHECK_IMPLIES(settings.use_one_copy, !settings.use_zero_copy); |
250 DCHECK_IMPLIES(settings.use_zero_copy, !settings.use_one_copy); | 258 DCHECK_IMPLIES(settings.use_zero_copy, !settings.use_one_copy); |
251 DidVisibilityChange(this, visible_); | 259 DidVisibilityChange(this, visible_); |
252 animation_registrar_->set_supports_scroll_animations( | |
253 proxy_->SupportsImplScrolling()); | |
254 | 260 |
255 SetDebugState(settings.initial_debug_state); | 261 SetDebugState(settings.initial_debug_state); |
256 | 262 |
257 // LTHI always has an active tree. | 263 // LTHI always has an active tree. |
258 active_tree_ = | 264 active_tree_ = |
259 LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(), | 265 LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(), |
260 new SyncedTopControls, new SyncedElasticOverscroll); | 266 new SyncedTopControls, new SyncedElasticOverscroll); |
261 | 267 |
262 viewport_ = Viewport::Create(this); | 268 viewport_ = Viewport::Create(this); |
263 | 269 |
(...skipping 23 matching lines...) Expand all Loading... |
287 // made a contract with our animation controllers that the registrar | 293 // made a contract with our animation controllers that the registrar |
288 // will outlive them, and we must make good. | 294 // will outlive them, and we must make good. |
289 if (recycle_tree_) | 295 if (recycle_tree_) |
290 recycle_tree_->Shutdown(); | 296 recycle_tree_->Shutdown(); |
291 if (pending_tree_) | 297 if (pending_tree_) |
292 pending_tree_->Shutdown(); | 298 pending_tree_->Shutdown(); |
293 active_tree_->Shutdown(); | 299 active_tree_->Shutdown(); |
294 recycle_tree_ = nullptr; | 300 recycle_tree_ = nullptr; |
295 pending_tree_ = nullptr; | 301 pending_tree_ = nullptr; |
296 active_tree_ = nullptr; | 302 active_tree_ = nullptr; |
| 303 |
| 304 if (animation_host_) { |
| 305 animation_host_->ClearTimelines(); |
| 306 animation_host_->SetMutatorHostClient(nullptr); |
| 307 } |
| 308 |
297 DestroyTileManager(); | 309 DestroyTileManager(); |
298 } | 310 } |
299 | 311 |
300 void LayerTreeHostImpl::BeginMainFrameAborted(CommitEarlyOutReason reason) { | 312 void LayerTreeHostImpl::BeginMainFrameAborted(CommitEarlyOutReason reason) { |
301 // If the begin frame data was handled, then scroll and scale set was applied | 313 // If the begin frame data was handled, then scroll and scale set was applied |
302 // by the main thread, so the active tree needs to be updated as if these sent | 314 // by the main thread, so the active tree needs to be updated as if these sent |
303 // values were applied and committed. | 315 // values were applied and committed. |
304 if (CommitEarlyOutHandledCommit(reason)) | 316 if (CommitEarlyOutHandledCommit(reason)) |
305 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit(); | 317 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit(); |
306 } | 318 } |
(...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 // contents of its texture are updated as the last thing before the frame is | 1568 // contents of its texture are updated as the last thing before the frame is |
1557 // drawn. | 1569 // drawn. |
1558 if (active_tree_->hud_layer()) { | 1570 if (active_tree_->hud_layer()) { |
1559 TRACE_EVENT0("cc", "DrawLayers.UpdateHudTexture"); | 1571 TRACE_EVENT0("cc", "DrawLayers.UpdateHudTexture"); |
1560 active_tree_->hud_layer()->UpdateHudTexture(draw_mode, | 1572 active_tree_->hud_layer()->UpdateHudTexture(draw_mode, |
1561 resource_provider_.get()); | 1573 resource_provider_.get()); |
1562 } | 1574 } |
1563 | 1575 |
1564 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) { | 1576 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) { |
1565 bool disable_picture_quad_image_filtering = | 1577 bool disable_picture_quad_image_filtering = |
1566 IsActivelyScrolling() || animation_registrar_->needs_animate_layers(); | 1578 IsActivelyScrolling() || |
| 1579 (animation_host_ ? animation_host_->NeedsAnimateLayers() |
| 1580 : animation_registrar_->needs_animate_layers()); |
1567 | 1581 |
1568 scoped_ptr<SoftwareRenderer> temp_software_renderer = | 1582 scoped_ptr<SoftwareRenderer> temp_software_renderer = |
1569 SoftwareRenderer::Create(this, &settings_.renderer_settings, | 1583 SoftwareRenderer::Create(this, &settings_.renderer_settings, |
1570 output_surface_.get(), NULL); | 1584 output_surface_.get(), NULL); |
1571 temp_software_renderer->DrawFrame(&frame->render_passes, | 1585 temp_software_renderer->DrawFrame(&frame->render_passes, |
1572 device_scale_factor_, | 1586 device_scale_factor_, |
1573 DeviceViewport(), | 1587 DeviceViewport(), |
1574 DeviceClip(), | 1588 DeviceClip(), |
1575 disable_picture_quad_image_filtering); | 1589 disable_picture_quad_image_filtering); |
1576 } else { | 1590 } else { |
(...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3096 for (auto& it : controllers_copy) | 3110 for (auto& it : controllers_copy) |
3097 it->Animate(monotonic_time); | 3111 it->Animate(monotonic_time); |
3098 | 3112 |
3099 SetNeedsAnimate(); | 3113 SetNeedsAnimate(); |
3100 } | 3114 } |
3101 | 3115 |
3102 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) { | 3116 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) { |
3103 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) | 3117 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) |
3104 return; | 3118 return; |
3105 | 3119 |
3106 if (animation_registrar_->AnimateLayers(monotonic_time)) | 3120 if (animation_host_) { |
3107 SetNeedsAnimate(); | 3121 if (animation_host_->AnimateLayers(monotonic_time)) |
| 3122 SetNeedsAnimate(); |
| 3123 } else { |
| 3124 if (animation_registrar_->AnimateLayers(monotonic_time)) |
| 3125 SetNeedsAnimate(); |
| 3126 } |
3108 } | 3127 } |
3109 | 3128 |
3110 void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) { | 3129 void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) { |
3111 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) | 3130 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) |
3112 return; | 3131 return; |
3113 | 3132 |
3114 scoped_ptr<AnimationEventsVector> events = | 3133 bool has_active_animations = false; |
3115 animation_registrar_->CreateEvents(); | 3134 scoped_ptr<AnimationEventsVector> events; |
3116 const bool has_active_animations = animation_registrar_->UpdateAnimationState( | 3135 |
3117 start_ready_animations, events.get()); | 3136 if (animation_host_) { |
| 3137 events = animation_host_->CreateEvents(); |
| 3138 has_active_animations = animation_host_->UpdateAnimationState( |
| 3139 start_ready_animations, events.get()); |
| 3140 } else { |
| 3141 events = animation_registrar_->CreateEvents(); |
| 3142 has_active_animations = animation_registrar_->UpdateAnimationState( |
| 3143 start_ready_animations, events.get()); |
| 3144 } |
3118 | 3145 |
3119 if (!events->empty()) | 3146 if (!events->empty()) |
3120 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass()); | 3147 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass()); |
3121 | 3148 |
3122 if (has_active_animations) | 3149 if (has_active_animations) |
3123 SetNeedsAnimate(); | 3150 SetNeedsAnimate(); |
3124 } | 3151 } |
3125 | 3152 |
3126 void LayerTreeHostImpl::ActivateAnimations() { | 3153 void LayerTreeHostImpl::ActivateAnimations() { |
3127 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) | 3154 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) |
3128 return; | 3155 return; |
3129 | 3156 |
3130 if (animation_registrar_->ActivateAnimations()) | 3157 if (animation_host_) { |
3131 SetNeedsAnimate(); | 3158 if (animation_host_->ActivateAnimations()) |
| 3159 SetNeedsAnimate(); |
| 3160 } else { |
| 3161 if (animation_registrar_->ActivateAnimations()) |
| 3162 SetNeedsAnimate(); |
| 3163 } |
3132 } | 3164 } |
3133 | 3165 |
3134 std::string LayerTreeHostImpl::LayerTreeAsJson() const { | 3166 std::string LayerTreeHostImpl::LayerTreeAsJson() const { |
3135 std::string str; | 3167 std::string str; |
3136 if (active_tree_->root_layer()) { | 3168 if (active_tree_->root_layer()) { |
3137 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson()); | 3169 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson()); |
3138 base::JSONWriter::WriteWithOptions( | 3170 base::JSONWriter::WriteWithOptions( |
3139 *json, base::JSONWriter::OPTIONS_PRETTY_PRINT, &str); | 3171 *json, base::JSONWriter::OPTIONS_PRETTY_PRINT, &str); |
3140 } | 3172 } |
3141 return str; | 3173 return str; |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3554 const gfx::ScrollOffset& scroll_offset) { | 3586 const gfx::ScrollOffset& scroll_offset) { |
3555 if (tree_type == LayerTreeType::ACTIVE) { | 3587 if (tree_type == LayerTreeType::ACTIVE) { |
3556 SetTreeLayerScrollOffsetMutated(layer_id, active_tree(), scroll_offset); | 3588 SetTreeLayerScrollOffsetMutated(layer_id, active_tree(), scroll_offset); |
3557 } else { | 3589 } else { |
3558 SetTreeLayerScrollOffsetMutated(layer_id, pending_tree(), scroll_offset); | 3590 SetTreeLayerScrollOffsetMutated(layer_id, pending_tree(), scroll_offset); |
3559 SetTreeLayerScrollOffsetMutated(layer_id, recycle_tree(), scroll_offset); | 3591 SetTreeLayerScrollOffsetMutated(layer_id, recycle_tree(), scroll_offset); |
3560 } | 3592 } |
3561 } | 3593 } |
3562 | 3594 |
3563 } // namespace cc | 3595 } // namespace cc |
OLD | NEW |