Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: cc/trees/layer_tree_host_impl.cc

Issue 1547893003: WIP - compositor worker mega patch. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 debug_rect_history_(DebugRectHistory::Create()), 217 debug_rect_history_(DebugRectHistory::Create()),
218 texture_mailbox_deleter_(new TextureMailboxDeleter(GetTaskRunner())), 218 texture_mailbox_deleter_(new TextureMailboxDeleter(GetTaskRunner())),
219 max_memory_needed_bytes_(0), 219 max_memory_needed_bytes_(0),
220 resourceless_software_draw_(false), 220 resourceless_software_draw_(false),
221 animation_registrar_(), 221 animation_registrar_(),
222 rendering_stats_instrumentation_(rendering_stats_instrumentation), 222 rendering_stats_instrumentation_(rendering_stats_instrumentation),
223 micro_benchmark_controller_(this), 223 micro_benchmark_controller_(this),
224 shared_bitmap_manager_(shared_bitmap_manager), 224 shared_bitmap_manager_(shared_bitmap_manager),
225 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), 225 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
226 task_graph_runner_(task_graph_runner), 226 task_graph_runner_(task_graph_runner),
227 mutator_(nullptr),
227 id_(id), 228 id_(id),
229 is_scrolling_(false),
228 requires_high_res_to_draw_(false), 230 requires_high_res_to_draw_(false),
229 is_likely_to_require_a_draw_(false), 231 is_likely_to_require_a_draw_(false),
230 frame_timing_tracker_(FrameTimingTracker::Create(this)) { 232 frame_timing_tracker_(FrameTimingTracker::Create(this)) {
231 if (settings.use_compositor_animation_timelines) { 233 if (settings.use_compositor_animation_timelines) {
232 if (settings.accelerated_animation_enabled) { 234 if (settings.accelerated_animation_enabled) {
233 animation_host_ = AnimationHost::Create(ThreadInstance::IMPL); 235 animation_host_ = AnimationHost::Create(ThreadInstance::IMPL);
234 animation_host_->SetMutatorHostClient(this); 236 animation_host_->SetMutatorHostClient(this);
235 animation_host_->SetSupportsScrollAnimations(SupportsImplScrolling()); 237 animation_host_->SetSupportsScrollAnimations(SupportsImplScrolling());
236 } 238 }
237 } else { 239 } else {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 // Display::Draw currently relies on resource being reclaimed to block drawing 321 // Display::Draw currently relies on resource being reclaimed to block drawing
320 // between BeginCommit / Swap. See crbug.com/489515. 322 // between BeginCommit / Swap. See crbug.com/489515.
321 if (output_surface_) 323 if (output_surface_)
322 output_surface_->ForceReclaimResources(); 324 output_surface_->ForceReclaimResources();
323 325
324 if (!CommitToActiveTree()) 326 if (!CommitToActiveTree())
325 CreatePendingTree(); 327 CreatePendingTree();
326 } 328 }
327 329
328 void LayerTreeHostImpl::CommitComplete() { 330 void LayerTreeHostImpl::CommitComplete() {
329 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete"); 331 TRACE_EVENT0("cc,compositor-worker", "LayerTreeHostImpl::CommitComplete");
330 332
331 if (CommitToActiveTree()) { 333 if (CommitToActiveTree()) {
332 // We have to activate animations here or "IsActive()" is true on the layers 334 // We have to activate animations here or "IsActive()" is true on the layers
333 // but the animations aren't activated yet so they get ignored by 335 // but the animations aren't activated yet so they get ignored by
334 // UpdateDrawProperties. 336 // UpdateDrawProperties.
335 ActivateAnimations(); 337 ActivateAnimations();
336 } 338 }
337 339
338 // Start animations before UpdateDrawProperties and PrepareTiles, as they can 340 // Start animations before UpdateDrawProperties and PrepareTiles, as they can
339 // change the results. When doing commit to the active tree, this must happen 341 // 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
450 input_handler_client_->Animate(monotonic_time); 452 input_handler_client_->Animate(monotonic_time);
451 } 453 }
452 } 454 }
453 455
454 did_animate |= AnimatePageScale(monotonic_time); 456 did_animate |= AnimatePageScale(monotonic_time);
455 did_animate |= AnimateLayers(monotonic_time); 457 did_animate |= AnimateLayers(monotonic_time);
456 did_animate |= AnimateScrollbars(monotonic_time); 458 did_animate |= AnimateScrollbars(monotonic_time);
457 did_animate |= AnimateTopControls(monotonic_time); 459 did_animate |= AnimateTopControls(monotonic_time);
458 460
459 if (active_tree) { 461 if (active_tree) {
462 did_animate |= Mutate(monotonic_time);
463
460 // Animating stuff can change the root scroll offset, so inform the 464 // Animating stuff can change the root scroll offset, so inform the
461 // synchronous input handler. 465 // synchronous input handler.
462 UpdateRootLayerStateForSynchronousInputHandler(); 466 UpdateRootLayerStateForSynchronousInputHandler();
463 if (did_animate) { 467 if (did_animate) {
464 // If the tree changed, then we want to draw at the end of the current 468 // If the tree changed, then we want to draw at the end of the current
465 // frame. 469 // frame.
466 SetNeedsRedraw(); 470 SetNeedsRedraw();
467 } 471 }
468 } 472 }
469 } 473 }
470 474
475 bool LayerTreeHostImpl::Mutate(base::TimeTicks monotonic_time) {
476 if (!mutator_)
477 return false;
478 TRACE_EVENT0("compositor-worker", "LayerTreeHostImpl::Mutate");
479 if (mutator_->Mutate(monotonic_time, active_tree_.get()))
480 client_->SetNeedsOneBeginImplFrameOnImplThread();
481 return true;
482 }
483
484 void LayerTreeHostImpl::SetNeedsMutate() {
485 TRACE_EVENT0("compositor-worker", "LayerTreeHostImpl::SetNeedsMutate");
486 client_->SetNeedsOneBeginImplFrameOnImplThread();
487 }
488
471 bool LayerTreeHostImpl::PrepareTiles() { 489 bool LayerTreeHostImpl::PrepareTiles() {
472 if (!tile_priorities_dirty_) 490 if (!tile_priorities_dirty_)
473 return false; 491 return false;
474 492
475 client_->WillPrepareTiles(); 493 client_->WillPrepareTiles();
476 bool did_prepare_tiles = tile_manager_->PrepareTiles(global_tile_state_); 494 bool did_prepare_tiles = tile_manager_->PrepareTiles(global_tile_state_);
477 if (did_prepare_tiles) 495 if (did_prepare_tiles)
478 tile_priorities_dirty_ = false; 496 tile_priorities_dirty_ = false;
479 client_->DidPrepareTiles(); 497 client_->DidPrepareTiles();
480 return did_prepare_tiles; 498 return did_prepare_tiles;
(...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after
2031 // tree, rename the pending tree the recycle tree so we can reuse it on the 2049 // tree, rename the pending tree the recycle tree so we can reuse it on the
2032 // next sync. 2050 // next sync.
2033 DCHECK(!recycle_tree_); 2051 DCHECK(!recycle_tree_);
2034 pending_tree_.swap(recycle_tree_); 2052 pending_tree_.swap(recycle_tree_);
2035 2053
2036 UpdateViewportContainerSizes(); 2054 UpdateViewportContainerSizes();
2037 2055
2038 // If we commit to the active tree directly, this is already done during 2056 // If we commit to the active tree directly, this is already done during
2039 // commit. 2057 // commit.
2040 ActivateAnimations(); 2058 ActivateAnimations();
2059 Mutate(CurrentBeginFrameArgs().frame_time);
2041 } else { 2060 } else {
2042 active_tree_->ProcessUIResourceRequestQueue(); 2061 active_tree_->ProcessUIResourceRequestQueue();
2043 } 2062 }
2044 2063
2045 // bounds_delta isn't a pushed property, so the newly-pushed property tree 2064 // bounds_delta isn't a pushed property, so the newly-pushed property tree
2046 // won't already account for current bounds_delta values. 2065 // won't already account for current bounds_delta values.
2047 active_tree_->UpdatePropertyTreesForBoundsDelta(); 2066 active_tree_->UpdatePropertyTreesForBoundsDelta();
2048 active_tree_->DidBecomeActive(); 2067 active_tree_->DidBecomeActive();
2049 client_->RenewTreePriority(); 2068 client_->RenewTreePriority();
2050 // If we have any picture layers, then by activating we also modified tile 2069 // If we have any picture layers, then by activating we also modified tile
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2280 request_ids, start_time, end_time, active_tree_->source_frame_number()); 2299 request_ids, start_time, end_time, active_tree_->source_frame_number());
2281 } 2300 }
2282 2301
2283 void LayerTreeHostImpl::PostFrameTimingEvents( 2302 void LayerTreeHostImpl::PostFrameTimingEvents(
2284 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, 2303 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
2285 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { 2304 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) {
2286 client_->PostFrameTimingEventsOnImplThread(std::move(composite_events), 2305 client_->PostFrameTimingEventsOnImplThread(std::move(composite_events),
2287 std::move(main_frame_events)); 2306 std::move(main_frame_events));
2288 } 2307 }
2289 2308
2309 void LayerTreeHostImpl::SetLayerTreeMutator(LayerTreeMutator* mutator) {
2310 if (mutator == mutator_)
2311 return;
2312 TRACE_EVENT0("compositor-worker", "LayerTreeHostImpl::SetLayerTreeMutator");
2313 mutator_ = mutator;
2314 mutator_->SetClient(this);
2315 }
2316
2290 void LayerTreeHostImpl::CleanUpTileManagerAndUIResources() { 2317 void LayerTreeHostImpl::CleanUpTileManagerAndUIResources() {
2291 ClearUIResources(); 2318 ClearUIResources();
2292 tile_manager_->FinishTasksAndCleanUp(); 2319 tile_manager_->FinishTasksAndCleanUp();
2293 resource_pool_ = nullptr; 2320 resource_pool_ = nullptr;
2294 tile_task_worker_pool_ = nullptr; 2321 tile_task_worker_pool_ = nullptr;
2295 single_thread_synchronous_task_graph_runner_ = nullptr; 2322 single_thread_synchronous_task_graph_runner_ = nullptr;
2296 } 2323 }
2297 2324
2298 void LayerTreeHostImpl::ReleaseOutputSurface() { 2325 void LayerTreeHostImpl::ReleaseOutputSurface() {
2299 TRACE_EVENT0("cc", "LayerTreeHostImpl::ReleaseOutputSurface"); 2326 TRACE_EVENT0("cc", "LayerTreeHostImpl::ReleaseOutputSurface");
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
2730 const gfx::Vector2dF& delta, 2757 const gfx::Vector2dF& delta,
2731 const gfx::Point& viewport_point, 2758 const gfx::Point& viewport_point,
2732 bool is_direct_manipulation) { 2759 bool is_direct_manipulation) {
2733 // Events representing direct manipulation of the screen (such as gesture 2760 // Events representing direct manipulation of the screen (such as gesture
2734 // events) need to be transformed from viewport coordinates to local layer 2761 // events) need to be transformed from viewport coordinates to local layer
2735 // coordinates so that the scrolling contents exactly follow the user's 2762 // coordinates so that the scrolling contents exactly follow the user's
2736 // finger. In contrast, events not representing direct manipulation of the 2763 // finger. In contrast, events not representing direct manipulation of the
2737 // screen (such as wheel events) represent a fixed amount of scrolling so we 2764 // screen (such as wheel events) represent a fixed amount of scrolling so we
2738 // can just apply them directly, but the page scale factor is applied to the 2765 // can just apply them directly, but the page scale factor is applied to the
2739 // scroll delta. 2766 // scroll delta.
2767 base::AutoReset<bool> reset(&is_scrolling_, true);
2740 if (is_direct_manipulation) { 2768 if (is_direct_manipulation) {
2741 return ScrollLayerWithViewportSpaceDelta( 2769 return ScrollLayerWithViewportSpaceDelta(
2742 layer_impl, gfx::PointF(viewport_point), delta); 2770 layer_impl, gfx::PointF(viewport_point), delta);
2743 } 2771 }
2744 float scale_factor = active_tree()->current_page_scale_factor(); 2772 float scale_factor = active_tree()->current_page_scale_factor();
2745 return ScrollLayerWithLocalDelta(layer_impl, delta, scale_factor); 2773 return ScrollLayerWithLocalDelta(layer_impl, delta, scale_factor);
2746 } 2774 }
2747 2775
2748 void LayerTreeHostImpl::ApplyScroll(LayerImpl* layer, 2776 void LayerTreeHostImpl::ApplyScroll(LayerImpl* layer,
2749 ScrollState* scroll_state) { 2777 ScrollState* scroll_state) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2796 if (!scrolled) 2824 if (!scrolled)
2797 return; 2825 return;
2798 2826
2799 scroll_state->set_current_native_scrolling_layer(layer); 2827 scroll_state->set_current_native_scrolling_layer(layer);
2800 } 2828 }
2801 2829
2802 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy( 2830 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy(
2803 const gfx::Point& viewport_point, 2831 const gfx::Point& viewport_point,
2804 const gfx::Vector2dF& scroll_delta) { 2832 const gfx::Vector2dF& scroll_delta) {
2805 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); 2833 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy");
2834 base::AutoReset<bool> reset(&is_scrolling_, true);
2806 if (!CurrentlyScrollingLayer()) 2835 if (!CurrentlyScrollingLayer())
2807 return InputHandlerScrollResult(); 2836 return InputHandlerScrollResult();
2808 2837
2809 float initial_top_controls_offset = 2838 float initial_top_controls_offset =
2810 top_controls_manager_->ControlsTopOffset(); 2839 top_controls_manager_->ControlsTopOffset();
2811 ScrollState scroll_state( 2840 ScrollState scroll_state(
2812 scroll_delta.x(), scroll_delta.y(), viewport_point.x(), 2841 scroll_delta.x(), scroll_delta.y(), viewport_point.x(),
2813 viewport_point.y(), false /* should_propagate */, 2842 viewport_point.y(), false /* should_propagate */,
2814 did_lock_scrolling_layer_ /* delta_consumed_for_scroll_sequence */, 2843 did_lock_scrolling_layer_ /* delta_consumed_for_scroll_sequence */,
2815 !wheel_scrolling_ /* is_direct_manipulation */); 2844 !wheel_scrolling_ /* is_direct_manipulation */);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2870 InputHandlerScrollResult scroll_result; 2899 InputHandlerScrollResult scroll_result;
2871 scroll_result.did_scroll = did_scroll_content || did_scroll_top_controls; 2900 scroll_result.did_scroll = did_scroll_content || did_scroll_top_controls;
2872 scroll_result.did_overscroll_root = !unused_root_delta.IsZero(); 2901 scroll_result.did_overscroll_root = !unused_root_delta.IsZero();
2873 scroll_result.accumulated_root_overscroll = accumulated_root_overscroll_; 2902 scroll_result.accumulated_root_overscroll = accumulated_root_overscroll_;
2874 scroll_result.unused_scroll_delta = unused_root_delta; 2903 scroll_result.unused_scroll_delta = unused_root_delta;
2875 2904
2876 // Scrolling can change the root scroll offset, so inform the synchronous 2905 // Scrolling can change the root scroll offset, so inform the synchronous
2877 // input handler. 2906 // input handler.
2878 UpdateRootLayerStateForSynchronousInputHandler(); 2907 UpdateRootLayerStateForSynchronousInputHandler();
2879 2908
2909 // Update compositor worker mutations which may respond to scrolling.
2910 Mutate(CurrentBeginFrameArgs().frame_time);
2911
2880 return scroll_result; 2912 return scroll_result;
2881 } 2913 }
2882 2914
2883 // This implements scrolling by page as described here: 2915 // This implements scrolling by page as described here:
2884 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).asp x#_win32_The_Mouse_Wheel 2916 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).asp x#_win32_The_Mouse_Wheel
2885 // for events with WHEEL_PAGESCROLL set. 2917 // for events with WHEEL_PAGESCROLL set.
2886 bool LayerTreeHostImpl::ScrollVerticallyByPage(const gfx::Point& viewport_point, 2918 bool LayerTreeHostImpl::ScrollVerticallyByPage(const gfx::Point& viewport_point,
2887 ScrollDirection direction) { 2919 ScrollDirection direction) {
2888 DCHECK(wheel_scrolling_); 2920 DCHECK(wheel_scrolling_);
2889 2921
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
3777 return task_runner_provider_->HasImplThread(); 3809 return task_runner_provider_->HasImplThread();
3778 } 3810 }
3779 3811
3780 bool LayerTreeHostImpl::CommitToActiveTree() const { 3812 bool LayerTreeHostImpl::CommitToActiveTree() const {
3781 // In single threaded mode we skip the pending tree and commit directly to the 3813 // In single threaded mode we skip the pending tree and commit directly to the
3782 // active tree. 3814 // active tree.
3783 return !task_runner_provider_->HasImplThread(); 3815 return !task_runner_provider_->HasImplThread();
3784 } 3816 }
3785 3817
3786 } // namespace cc 3818 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698