| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 paint_time_counter_(PaintTimeCounter::Create()), | 213 paint_time_counter_(PaintTimeCounter::Create()), |
| 214 memory_history_(MemoryHistory::Create()), | 214 memory_history_(MemoryHistory::Create()), |
| 215 debug_rect_history_(DebugRectHistory::Create()), | 215 debug_rect_history_(DebugRectHistory::Create()), |
| 216 texture_mailbox_deleter_(new TextureMailboxDeleter( | 216 texture_mailbox_deleter_(new TextureMailboxDeleter( |
| 217 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() | 217 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() |
| 218 : proxy_->MainThreadTaskRunner())), | 218 : proxy_->MainThreadTaskRunner())), |
| 219 max_memory_needed_bytes_(0), | 219 max_memory_needed_bytes_(0), |
| 220 device_scale_factor_(1.f), | 220 device_scale_factor_(1.f), |
| 221 resourceless_software_draw_(false), | 221 resourceless_software_draw_(false), |
| 222 begin_impl_frame_interval_(BeginFrameArgs::DefaultInterval()), | 222 begin_impl_frame_interval_(BeginFrameArgs::DefaultInterval()), |
| 223 animation_registrar_(AnimationRegistrar::Create()), | |
| 224 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 223 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
| 225 micro_benchmark_controller_(this), | 224 micro_benchmark_controller_(this), |
| 226 shared_bitmap_manager_(shared_bitmap_manager), | 225 shared_bitmap_manager_(shared_bitmap_manager), |
| 227 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 226 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
| 228 task_graph_runner_(task_graph_runner), | 227 task_graph_runner_(task_graph_runner), |
| 229 id_(id), | 228 id_(id), |
| 230 requires_high_res_to_draw_(false), | 229 requires_high_res_to_draw_(false), |
| 231 is_likely_to_require_a_draw_(false), | 230 is_likely_to_require_a_draw_(false), |
| 232 frame_timing_tracker_(FrameTimingTracker::Create()) { | 231 frame_timing_tracker_(FrameTimingTracker::Create()) { |
| 233 if (settings.use_compositor_animation_timelines) { | 232 if (settings.use_compositor_animation_timelines) { |
| 234 animation_host_ = AnimationHost::Create(true); | 233 animation_host_ = AnimationHost::Create(true); |
| 235 animation_host_->SetLayerTreeMutatorsClient(this); | 234 animation_host_->SetLayerTreeMutatorsClient(this); |
| 235 animation_host_->SetSupportsScrollAnimations( |
| 236 proxy_->SupportsImplScrolling()); |
| 237 } else { |
| 238 animation_registrar_ = AnimationRegistrar::Create(); |
| 239 animation_registrar_->set_supports_scroll_animations( |
| 240 proxy_->SupportsImplScrolling()); |
| 236 } | 241 } |
| 237 | 242 |
| 238 DCHECK(proxy_->IsImplThread()); | 243 DCHECK(proxy_->IsImplThread()); |
| 239 DidVisibilityChange(this, visible_); | 244 DidVisibilityChange(this, visible_); |
| 240 animation_registrar_->set_supports_scroll_animations( | |
| 241 proxy_->SupportsImplScrolling()); | |
| 242 | 245 |
| 243 SetDebugState(settings.initial_debug_state); | 246 SetDebugState(settings.initial_debug_state); |
| 244 | 247 |
| 245 // LTHI always has an active tree. | 248 // LTHI always has an active tree. |
| 246 active_tree_ = | 249 active_tree_ = |
| 247 LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(), | 250 LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(), |
| 248 new SyncedTopControls, new SyncedElasticOverscroll); | 251 new SyncedTopControls, new SyncedElasticOverscroll); |
| 249 | 252 |
| 250 viewport_ = Viewport::Create(this); | 253 viewport_ = Viewport::Create(this); |
| 251 | 254 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 275 // made a contract with our animation controllers that the registrar | 278 // made a contract with our animation controllers that the registrar |
| 276 // will outlive them, and we must make good. | 279 // will outlive them, and we must make good. |
| 277 if (recycle_tree_) | 280 if (recycle_tree_) |
| 278 recycle_tree_->Shutdown(); | 281 recycle_tree_->Shutdown(); |
| 279 if (pending_tree_) | 282 if (pending_tree_) |
| 280 pending_tree_->Shutdown(); | 283 pending_tree_->Shutdown(); |
| 281 active_tree_->Shutdown(); | 284 active_tree_->Shutdown(); |
| 282 recycle_tree_ = nullptr; | 285 recycle_tree_ = nullptr; |
| 283 pending_tree_ = nullptr; | 286 pending_tree_ = nullptr; |
| 284 active_tree_ = nullptr; | 287 active_tree_ = nullptr; |
| 288 |
| 289 if (animation_host_) { |
| 290 animation_host_->ClearTimelines(); |
| 291 animation_host_->SetLayerTreeMutatorsClient(nullptr); |
| 292 } |
| 293 |
| 285 DestroyTileManager(); | 294 DestroyTileManager(); |
| 286 } | 295 } |
| 287 | 296 |
| 288 void LayerTreeHostImpl::BeginMainFrameAborted(CommitEarlyOutReason reason) { | 297 void LayerTreeHostImpl::BeginMainFrameAborted(CommitEarlyOutReason reason) { |
| 289 // If the begin frame data was handled, then scroll and scale set was applied | 298 // If the begin frame data was handled, then scroll and scale set was applied |
| 290 // by the main thread, so the active tree needs to be updated as if these sent | 299 // by the main thread, so the active tree needs to be updated as if these sent |
| 291 // values were applied and committed. | 300 // values were applied and committed. |
| 292 if (CommitEarlyOutHandledCommit(reason)) { | 301 if (CommitEarlyOutHandledCommit(reason)) { |
| 293 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit(); | 302 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit(); |
| 294 active_tree_->ResetContentsTexturesPurged(); | 303 active_tree_->ResetContentsTexturesPurged(); |
| (...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 // contents of its texture are updated as the last thing before the frame is | 1541 // contents of its texture are updated as the last thing before the frame is |
| 1533 // drawn. | 1542 // drawn. |
| 1534 if (active_tree_->hud_layer()) { | 1543 if (active_tree_->hud_layer()) { |
| 1535 TRACE_EVENT0("cc", "DrawLayers.UpdateHudTexture"); | 1544 TRACE_EVENT0("cc", "DrawLayers.UpdateHudTexture"); |
| 1536 active_tree_->hud_layer()->UpdateHudTexture(draw_mode, | 1545 active_tree_->hud_layer()->UpdateHudTexture(draw_mode, |
| 1537 resource_provider_.get()); | 1546 resource_provider_.get()); |
| 1538 } | 1547 } |
| 1539 | 1548 |
| 1540 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) { | 1549 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) { |
| 1541 bool disable_picture_quad_image_filtering = | 1550 bool disable_picture_quad_image_filtering = |
| 1542 IsActivelyScrolling() || animation_registrar_->needs_animate_layers(); | 1551 IsActivelyScrolling() || |
| 1552 (animation_host_ ? animation_host_->NeedsAnimateLayers() |
| 1553 : animation_registrar_->needs_animate_layers()); |
| 1543 | 1554 |
| 1544 scoped_ptr<SoftwareRenderer> temp_software_renderer = | 1555 scoped_ptr<SoftwareRenderer> temp_software_renderer = |
| 1545 SoftwareRenderer::Create(this, &settings_.renderer_settings, | 1556 SoftwareRenderer::Create(this, &settings_.renderer_settings, |
| 1546 output_surface_.get(), NULL); | 1557 output_surface_.get(), NULL); |
| 1547 temp_software_renderer->DrawFrame(&frame->render_passes, | 1558 temp_software_renderer->DrawFrame(&frame->render_passes, |
| 1548 device_scale_factor_, | 1559 device_scale_factor_, |
| 1549 DeviceViewport(), | 1560 DeviceViewport(), |
| 1550 DeviceClip(), | 1561 DeviceClip(), |
| 1551 disable_picture_quad_image_filtering); | 1562 disable_picture_quad_image_filtering); |
| 1552 } else { | 1563 } else { |
| (...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3008 for (auto& it : controllers_copy) | 3019 for (auto& it : controllers_copy) |
| 3009 it->Animate(monotonic_time); | 3020 it->Animate(monotonic_time); |
| 3010 | 3021 |
| 3011 SetNeedsAnimate(); | 3022 SetNeedsAnimate(); |
| 3012 } | 3023 } |
| 3013 | 3024 |
| 3014 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) { | 3025 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) { |
| 3015 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) | 3026 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) |
| 3016 return; | 3027 return; |
| 3017 | 3028 |
| 3018 if (animation_registrar_->AnimateLayers(monotonic_time)) | 3029 if (animation_host_) { |
| 3019 SetNeedsAnimate(); | 3030 if (animation_host_->AnimateLayers(monotonic_time)) |
| 3031 SetNeedsAnimate(); |
| 3032 } else { |
| 3033 if (animation_registrar_->AnimateLayers(monotonic_time)) |
| 3034 SetNeedsAnimate(); |
| 3035 } |
| 3020 } | 3036 } |
| 3021 | 3037 |
| 3022 void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) { | 3038 void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) { |
| 3023 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) | 3039 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) |
| 3024 return; | 3040 return; |
| 3025 | 3041 |
| 3026 scoped_ptr<AnimationEventsVector> events = | 3042 bool has_active_animations = false; |
| 3027 animation_registrar_->CreateEvents(); | 3043 scoped_ptr<AnimationEventsVector> events; |
| 3028 const bool has_active_animations = animation_registrar_->UpdateAnimationState( | 3044 |
| 3029 start_ready_animations, events.get()); | 3045 if (animation_host_) { |
| 3046 events = animation_host_->CreateEvents(); |
| 3047 has_active_animations = animation_host_->UpdateAnimationState( |
| 3048 start_ready_animations, events.get()); |
| 3049 } else { |
| 3050 events = animation_registrar_->CreateEvents(); |
| 3051 has_active_animations = animation_registrar_->UpdateAnimationState( |
| 3052 start_ready_animations, events.get()); |
| 3053 } |
| 3030 | 3054 |
| 3031 if (!events->empty()) | 3055 if (!events->empty()) |
| 3032 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass()); | 3056 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass()); |
| 3033 | 3057 |
| 3034 if (has_active_animations) | 3058 if (has_active_animations) |
| 3035 SetNeedsAnimate(); | 3059 SetNeedsAnimate(); |
| 3036 } | 3060 } |
| 3037 | 3061 |
| 3038 void LayerTreeHostImpl::ActivateAnimations() { | 3062 void LayerTreeHostImpl::ActivateAnimations() { |
| 3039 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) | 3063 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) |
| 3040 return; | 3064 return; |
| 3041 | 3065 |
| 3042 if (animation_registrar_->ActivateAnimations()) | 3066 if (animation_host_) { |
| 3043 SetNeedsAnimate(); | 3067 if (animation_host_->ActivateAnimations()) |
| 3068 SetNeedsAnimate(); |
| 3069 } else { |
| 3070 if (animation_registrar_->ActivateAnimations()) |
| 3071 SetNeedsAnimate(); |
| 3072 } |
| 3044 } | 3073 } |
| 3045 | 3074 |
| 3046 std::string LayerTreeHostImpl::LayerTreeAsJson() const { | 3075 std::string LayerTreeHostImpl::LayerTreeAsJson() const { |
| 3047 std::string str; | 3076 std::string str; |
| 3048 if (active_tree_->root_layer()) { | 3077 if (active_tree_->root_layer()) { |
| 3049 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson()); | 3078 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson()); |
| 3050 base::JSONWriter::WriteWithOptions( | 3079 base::JSONWriter::WriteWithOptions( |
| 3051 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str); | 3080 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str); |
| 3052 } | 3081 } |
| 3053 return str; | 3082 return str; |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3483 const gfx::ScrollOffset& scroll_offset) { | 3512 const gfx::ScrollOffset& scroll_offset) { |
| 3484 if (affects_active_tree) { | 3513 if (affects_active_tree) { |
| 3485 SetTreeLayerScrollOffsetMutated(layer_id, active_tree(), scroll_offset); | 3514 SetTreeLayerScrollOffsetMutated(layer_id, active_tree(), scroll_offset); |
| 3486 } else { | 3515 } else { |
| 3487 SetTreeLayerScrollOffsetMutated(layer_id, pending_tree(), scroll_offset); | 3516 SetTreeLayerScrollOffsetMutated(layer_id, pending_tree(), scroll_offset); |
| 3488 SetTreeLayerScrollOffsetMutated(layer_id, recycle_tree(), scroll_offset); | 3517 SetTreeLayerScrollOffsetMutated(layer_id, recycle_tree(), scroll_offset); |
| 3489 } | 3518 } |
| 3490 } | 3519 } |
| 3491 | 3520 |
| 3492 } // namespace cc | 3521 } // namespace cc |
| OLD | NEW |