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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 debug_rect_history_(DebugRectHistory::Create()), | 218 debug_rect_history_(DebugRectHistory::Create()), |
219 texture_mailbox_deleter_(new TextureMailboxDeleter(GetTaskRunner())), | 219 texture_mailbox_deleter_(new TextureMailboxDeleter(GetTaskRunner())), |
220 max_memory_needed_bytes_(0), | 220 max_memory_needed_bytes_(0), |
221 resourceless_software_draw_(false), | 221 resourceless_software_draw_(false), |
222 animation_registrar_(), | 222 animation_registrar_(), |
223 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 223 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
224 micro_benchmark_controller_(this), | 224 micro_benchmark_controller_(this), |
225 shared_bitmap_manager_(shared_bitmap_manager), | 225 shared_bitmap_manager_(shared_bitmap_manager), |
226 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 226 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
227 task_graph_runner_(task_graph_runner), | 227 task_graph_runner_(task_graph_runner), |
| 228 mutator_(nullptr), |
228 id_(id), | 229 id_(id), |
| 230 is_scrolling_(false), |
229 requires_high_res_to_draw_(false), | 231 requires_high_res_to_draw_(false), |
230 is_likely_to_require_a_draw_(false), | 232 is_likely_to_require_a_draw_(false), |
231 frame_timing_tracker_(FrameTimingTracker::Create(this)) { | 233 frame_timing_tracker_(FrameTimingTracker::Create(this)) { |
232 if (settings.use_compositor_animation_timelines) { | 234 if (settings.use_compositor_animation_timelines) { |
233 if (settings.accelerated_animation_enabled) { | 235 if (settings.accelerated_animation_enabled) { |
234 animation_host_ = AnimationHost::Create(ThreadInstance::IMPL); | 236 animation_host_ = AnimationHost::Create(ThreadInstance::IMPL); |
235 animation_host_->SetMutatorHostClient(this); | 237 animation_host_->SetMutatorHostClient(this); |
236 animation_host_->SetSupportsScrollAnimations(SupportsImplScrolling()); | 238 animation_host_->SetSupportsScrollAnimations(SupportsImplScrolling()); |
237 } | 239 } |
238 } else { | 240 } else { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 // Display::Draw currently relies on resource being reclaimed to block drawing | 322 // Display::Draw currently relies on resource being reclaimed to block drawing |
321 // between BeginCommit / Swap. See crbug.com/489515. | 323 // between BeginCommit / Swap. See crbug.com/489515. |
322 if (output_surface_) | 324 if (output_surface_) |
323 output_surface_->ForceReclaimResources(); | 325 output_surface_->ForceReclaimResources(); |
324 | 326 |
325 if (!CommitToActiveTree()) | 327 if (!CommitToActiveTree()) |
326 CreatePendingTree(); | 328 CreatePendingTree(); |
327 } | 329 } |
328 | 330 |
329 void LayerTreeHostImpl::CommitComplete() { | 331 void LayerTreeHostImpl::CommitComplete() { |
330 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete"); | 332 TRACE_EVENT0("cc,compositor-worker", "LayerTreeHostImpl::CommitComplete"); |
331 | 333 |
332 if (CommitToActiveTree()) { | 334 if (CommitToActiveTree()) { |
333 // We have to activate animations here or "IsActive()" is true on the layers | 335 // We have to activate animations here or "IsActive()" is true on the layers |
334 // but the animations aren't activated yet so they get ignored by | 336 // but the animations aren't activated yet so they get ignored by |
335 // UpdateDrawProperties. | 337 // UpdateDrawProperties. |
336 ActivateAnimations(); | 338 ActivateAnimations(); |
337 } | 339 } |
338 | 340 |
339 // Start animations before UpdateDrawProperties and PrepareTiles, as they can | 341 // Start animations before UpdateDrawProperties and PrepareTiles, as they can |
340 // change the results. When doing commit to the active tree, this must happen | 342 // change the results. When doing commit to the active tree, this must happen |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 input_handler_client_->Animate(monotonic_time); | 453 input_handler_client_->Animate(monotonic_time); |
452 } | 454 } |
453 } | 455 } |
454 | 456 |
455 did_animate |= AnimatePageScale(monotonic_time); | 457 did_animate |= AnimatePageScale(monotonic_time); |
456 did_animate |= AnimateLayers(monotonic_time); | 458 did_animate |= AnimateLayers(monotonic_time); |
457 did_animate |= AnimateScrollbars(monotonic_time); | 459 did_animate |= AnimateScrollbars(monotonic_time); |
458 did_animate |= AnimateTopControls(monotonic_time); | 460 did_animate |= AnimateTopControls(monotonic_time); |
459 | 461 |
460 if (active_tree) { | 462 if (active_tree) { |
| 463 did_animate |= Mutate(monotonic_time); |
| 464 |
461 // Animating stuff can change the root scroll offset, so inform the | 465 // Animating stuff can change the root scroll offset, so inform the |
462 // synchronous input handler. | 466 // synchronous input handler. |
463 UpdateRootLayerStateForSynchronousInputHandler(); | 467 UpdateRootLayerStateForSynchronousInputHandler(); |
464 if (did_animate) { | 468 if (did_animate) { |
465 // If the tree changed, then we want to draw at the end of the current | 469 // If the tree changed, then we want to draw at the end of the current |
466 // frame. | 470 // frame. |
467 SetNeedsRedraw(); | 471 SetNeedsRedraw(); |
468 } | 472 } |
469 } | 473 } |
470 } | 474 } |
471 | 475 |
| 476 bool LayerTreeHostImpl::Mutate(base::TimeTicks monotonic_time) { |
| 477 if (!mutator_) |
| 478 return false; |
| 479 TRACE_EVENT0("compositor-worker", "LayerTreeHostImpl::Mutate"); |
| 480 if (mutator_->Mutate(monotonic_time, active_tree_.get())) |
| 481 client_->SetNeedsOneBeginImplFrameOnImplThread(); |
| 482 return true; |
| 483 } |
| 484 |
| 485 void LayerTreeHostImpl::SetNeedsMutate() { |
| 486 TRACE_EVENT0("compositor-worker", "LayerTreeHostImpl::SetNeedsMutate"); |
| 487 client_->SetNeedsOneBeginImplFrameOnImplThread(); |
| 488 } |
| 489 |
472 bool LayerTreeHostImpl::PrepareTiles() { | 490 bool LayerTreeHostImpl::PrepareTiles() { |
473 if (!tile_priorities_dirty_) | 491 if (!tile_priorities_dirty_) |
474 return false; | 492 return false; |
475 | 493 |
476 client_->WillPrepareTiles(); | 494 client_->WillPrepareTiles(); |
477 bool did_prepare_tiles = tile_manager_->PrepareTiles(global_tile_state_); | 495 bool did_prepare_tiles = tile_manager_->PrepareTiles(global_tile_state_); |
478 if (did_prepare_tiles) | 496 if (did_prepare_tiles) |
479 tile_priorities_dirty_ = false; | 497 tile_priorities_dirty_ = false; |
480 client_->DidPrepareTiles(); | 498 client_->DidPrepareTiles(); |
481 return did_prepare_tiles; | 499 return did_prepare_tiles; |
(...skipping 1568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2050 // tree, rename the pending tree the recycle tree so we can reuse it on the | 2068 // tree, rename the pending tree the recycle tree so we can reuse it on the |
2051 // next sync. | 2069 // next sync. |
2052 DCHECK(!recycle_tree_); | 2070 DCHECK(!recycle_tree_); |
2053 pending_tree_.swap(recycle_tree_); | 2071 pending_tree_.swap(recycle_tree_); |
2054 | 2072 |
2055 UpdateViewportContainerSizes(); | 2073 UpdateViewportContainerSizes(); |
2056 | 2074 |
2057 // If we commit to the active tree directly, this is already done during | 2075 // If we commit to the active tree directly, this is already done during |
2058 // commit. | 2076 // commit. |
2059 ActivateAnimations(); | 2077 ActivateAnimations(); |
| 2078 Mutate(CurrentBeginFrameArgs().frame_time); |
2060 } else { | 2079 } else { |
2061 active_tree_->ProcessUIResourceRequestQueue(); | 2080 active_tree_->ProcessUIResourceRequestQueue(); |
2062 } | 2081 } |
2063 | 2082 |
2064 // bounds_delta isn't a pushed property, so the newly-pushed property tree | 2083 // bounds_delta isn't a pushed property, so the newly-pushed property tree |
2065 // won't already account for current bounds_delta values. | 2084 // won't already account for current bounds_delta values. |
2066 active_tree_->UpdatePropertyTreesForBoundsDelta(); | 2085 active_tree_->UpdatePropertyTreesForBoundsDelta(); |
2067 active_tree_->DidBecomeActive(); | 2086 active_tree_->DidBecomeActive(); |
2068 client_->RenewTreePriority(); | 2087 client_->RenewTreePriority(); |
2069 // If we have any picture layers, then by activating we also modified tile | 2088 // If we have any picture layers, then by activating we also modified tile |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2300 request_ids, start_time, end_time, active_tree_->source_frame_number()); | 2319 request_ids, start_time, end_time, active_tree_->source_frame_number()); |
2301 } | 2320 } |
2302 | 2321 |
2303 void LayerTreeHostImpl::PostFrameTimingEvents( | 2322 void LayerTreeHostImpl::PostFrameTimingEvents( |
2304 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | 2323 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
2305 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { | 2324 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
2306 client_->PostFrameTimingEventsOnImplThread(std::move(composite_events), | 2325 client_->PostFrameTimingEventsOnImplThread(std::move(composite_events), |
2307 std::move(main_frame_events)); | 2326 std::move(main_frame_events)); |
2308 } | 2327 } |
2309 | 2328 |
| 2329 void LayerTreeHostImpl::SetLayerTreeMutator(LayerTreeMutator* mutator) { |
| 2330 if (mutator == mutator_) |
| 2331 return; |
| 2332 TRACE_EVENT0("compositor-worker", "LayerTreeHostImpl::SetLayerTreeMutator"); |
| 2333 mutator_ = mutator; |
| 2334 mutator_->SetClient(this); |
| 2335 } |
| 2336 |
2310 void LayerTreeHostImpl::CleanUpTileManagerAndUIResources() { | 2337 void LayerTreeHostImpl::CleanUpTileManagerAndUIResources() { |
2311 ClearUIResources(); | 2338 ClearUIResources(); |
2312 tile_manager_->FinishTasksAndCleanUp(); | 2339 tile_manager_->FinishTasksAndCleanUp(); |
2313 resource_pool_ = nullptr; | 2340 resource_pool_ = nullptr; |
2314 tile_task_worker_pool_ = nullptr; | 2341 tile_task_worker_pool_ = nullptr; |
2315 single_thread_synchronous_task_graph_runner_ = nullptr; | 2342 single_thread_synchronous_task_graph_runner_ = nullptr; |
2316 } | 2343 } |
2317 | 2344 |
2318 void LayerTreeHostImpl::ReleaseOutputSurface() { | 2345 void LayerTreeHostImpl::ReleaseOutputSurface() { |
2319 TRACE_EVENT0("cc", "LayerTreeHostImpl::ReleaseOutputSurface"); | 2346 TRACE_EVENT0("cc", "LayerTreeHostImpl::ReleaseOutputSurface"); |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2771 const gfx::Vector2dF& delta, | 2798 const gfx::Vector2dF& delta, |
2772 const gfx::Point& viewport_point, | 2799 const gfx::Point& viewport_point, |
2773 bool is_direct_manipulation) { | 2800 bool is_direct_manipulation) { |
2774 // Events representing direct manipulation of the screen (such as gesture | 2801 // Events representing direct manipulation of the screen (such as gesture |
2775 // events) need to be transformed from viewport coordinates to local layer | 2802 // events) need to be transformed from viewport coordinates to local layer |
2776 // coordinates so that the scrolling contents exactly follow the user's | 2803 // coordinates so that the scrolling contents exactly follow the user's |
2777 // finger. In contrast, events not representing direct manipulation of the | 2804 // finger. In contrast, events not representing direct manipulation of the |
2778 // screen (such as wheel events) represent a fixed amount of scrolling so we | 2805 // screen (such as wheel events) represent a fixed amount of scrolling so we |
2779 // can just apply them directly, but the page scale factor is applied to the | 2806 // can just apply them directly, but the page scale factor is applied to the |
2780 // scroll delta. | 2807 // scroll delta. |
| 2808 base::AutoReset<bool> reset(&is_scrolling_, true); |
2781 if (is_direct_manipulation) { | 2809 if (is_direct_manipulation) { |
2782 return ScrollLayerWithViewportSpaceDelta( | 2810 return ScrollLayerWithViewportSpaceDelta( |
2783 layer_impl, gfx::PointF(viewport_point), delta); | 2811 layer_impl, gfx::PointF(viewport_point), delta); |
2784 } | 2812 } |
2785 float scale_factor = active_tree()->current_page_scale_factor(); | 2813 float scale_factor = active_tree()->current_page_scale_factor(); |
2786 return ScrollLayerWithLocalDelta(layer_impl, delta, scale_factor); | 2814 return ScrollLayerWithLocalDelta(layer_impl, delta, scale_factor); |
2787 } | 2815 } |
2788 | 2816 |
2789 void LayerTreeHostImpl::ApplyScroll(LayerImpl* layer, | 2817 void LayerTreeHostImpl::ApplyScroll(LayerImpl* layer, |
2790 ScrollState* scroll_state) { | 2818 ScrollState* scroll_state) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2857 } | 2885 } |
2858 scroll_state->set_scroll_chain(current_scroll_chain); | 2886 scroll_state->set_scroll_chain(current_scroll_chain); |
2859 scroll_state->DistributeToScrollChainDescendant(); | 2887 scroll_state->DistributeToScrollChainDescendant(); |
2860 } | 2888 } |
2861 | 2889 |
2862 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy( | 2890 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy( |
2863 ScrollState* scroll_state) { | 2891 ScrollState* scroll_state) { |
2864 DCHECK(scroll_state); | 2892 DCHECK(scroll_state); |
2865 | 2893 |
2866 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); | 2894 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); |
| 2895 base::AutoReset<bool> reset(&is_scrolling_, true); |
2867 if (!CurrentlyScrollingLayer()) | 2896 if (!CurrentlyScrollingLayer()) |
2868 return InputHandlerScrollResult(); | 2897 return InputHandlerScrollResult(); |
2869 | 2898 |
2870 float initial_top_controls_offset = | 2899 float initial_top_controls_offset = |
2871 top_controls_manager_->ControlsTopOffset(); | 2900 top_controls_manager_->ControlsTopOffset(); |
2872 | 2901 |
2873 scroll_state->set_delta_consumed_for_scroll_sequence( | 2902 scroll_state->set_delta_consumed_for_scroll_sequence( |
2874 did_lock_scrolling_layer_); | 2903 did_lock_scrolling_layer_); |
2875 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); | 2904 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); |
2876 scroll_state->set_current_native_scrolling_layer(CurrentlyScrollingLayer()); | 2905 scroll_state->set_current_native_scrolling_layer(CurrentlyScrollingLayer()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2922 scroll_result.did_overscroll_root = !unused_root_delta.IsZero(); | 2951 scroll_result.did_overscroll_root = !unused_root_delta.IsZero(); |
2923 scroll_result.accumulated_root_overscroll = accumulated_root_overscroll_; | 2952 scroll_result.accumulated_root_overscroll = accumulated_root_overscroll_; |
2924 scroll_result.unused_scroll_delta = unused_root_delta; | 2953 scroll_result.unused_scroll_delta = unused_root_delta; |
2925 | 2954 |
2926 if (scroll_result.did_scroll) { | 2955 if (scroll_result.did_scroll) { |
2927 // Scrolling can change the root scroll offset, so inform the synchronous | 2956 // Scrolling can change the root scroll offset, so inform the synchronous |
2928 // input handler. | 2957 // input handler. |
2929 UpdateRootLayerStateForSynchronousInputHandler(); | 2958 UpdateRootLayerStateForSynchronousInputHandler(); |
2930 } | 2959 } |
2931 | 2960 |
| 2961 // Update compositor worker mutations which may respond to scrolling. |
| 2962 Mutate(CurrentBeginFrameArgs().frame_time); |
| 2963 |
2932 return scroll_result; | 2964 return scroll_result; |
2933 } | 2965 } |
2934 | 2966 |
2935 // This implements scrolling by page as described here: | 2967 // This implements scrolling by page as described here: |
2936 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).asp
x#_win32_The_Mouse_Wheel | 2968 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).asp
x#_win32_The_Mouse_Wheel |
2937 // for events with WHEEL_PAGESCROLL set. | 2969 // for events with WHEEL_PAGESCROLL set. |
2938 bool LayerTreeHostImpl::ScrollVerticallyByPage(const gfx::Point& viewport_point, | 2970 bool LayerTreeHostImpl::ScrollVerticallyByPage(const gfx::Point& viewport_point, |
2939 ScrollDirection direction) { | 2971 ScrollDirection direction) { |
2940 DCHECK(wheel_scrolling_); | 2972 DCHECK(wheel_scrolling_); |
2941 | 2973 |
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3841 return task_runner_provider_->HasImplThread(); | 3873 return task_runner_provider_->HasImplThread(); |
3842 } | 3874 } |
3843 | 3875 |
3844 bool LayerTreeHostImpl::CommitToActiveTree() const { | 3876 bool LayerTreeHostImpl::CommitToActiveTree() const { |
3845 // In single threaded mode we skip the pending tree and commit directly to the | 3877 // In single threaded mode we skip the pending tree and commit directly to the |
3846 // active tree. | 3878 // active tree. |
3847 return !task_runner_provider_->HasImplThread(); | 3879 return !task_runner_provider_->HasImplThread(); |
3848 } | 3880 } |
3849 | 3881 |
3850 } // namespace cc | 3882 } // namespace cc |
OLD | NEW |