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

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

Issue 895853003: Update from https://crrev.com/314320 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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_host_impl_unittest.cc » ('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 <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
12 #include "base/debug/trace_event_argument.h"
13 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
14 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
15 #include "base/stl_util.h" 14 #include "base/stl_util.h"
16 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/trace_event/trace_event_argument.h"
17 #include "cc/animation/animation_id_provider.h" 17 #include "cc/animation/animation_id_provider.h"
18 #include "cc/animation/scroll_offset_animation_curve.h" 18 #include "cc/animation/scroll_offset_animation_curve.h"
19 #include "cc/animation/scrollbar_animation_controller.h" 19 #include "cc/animation/scrollbar_animation_controller.h"
20 #include "cc/animation/timing_function.h" 20 #include "cc/animation/timing_function.h"
21 #include "cc/base/latency_info_swap_promise_monitor.h" 21 #include "cc/base/latency_info_swap_promise_monitor.h"
22 #include "cc/base/math_util.h" 22 #include "cc/base/math_util.h"
23 #include "cc/base/util.h" 23 #include "cc/base/util.h"
24 #include "cc/debug/benchmark_instrumentation.h" 24 #include "cc/debug/benchmark_instrumentation.h"
25 #include "cc/debug/debug_rect_history.h" 25 #include "cc/debug/debug_rect_history.h"
26 #include "cc/debug/devtools_instrumentation.h" 26 #include "cc/debug/devtools_instrumentation.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 namespace cc { 81 namespace cc {
82 namespace { 82 namespace {
83 83
84 // Small helper class that saves the current viewport location as the user sees 84 // Small helper class that saves the current viewport location as the user sees
85 // it and resets to the same location. 85 // it and resets to the same location.
86 class ViewportAnchor { 86 class ViewportAnchor {
87 public: 87 public:
88 ViewportAnchor(LayerImpl* inner_scroll, LayerImpl* outer_scroll) 88 ViewportAnchor(LayerImpl* inner_scroll, LayerImpl* outer_scroll)
89 : inner_(inner_scroll), 89 : inner_(inner_scroll),
90 outer_(outer_scroll) { 90 outer_(outer_scroll) {
91 viewport_in_content_coordinates_ = inner_->TotalScrollOffset(); 91 viewport_in_content_coordinates_ = inner_->CurrentScrollOffset();
92 92
93 if (outer_) 93 if (outer_)
94 viewport_in_content_coordinates_ += outer_->TotalScrollOffset(); 94 viewport_in_content_coordinates_ += outer_->CurrentScrollOffset();
95 } 95 }
96 96
97 void ResetViewportToAnchoredPosition() { 97 void ResetViewportToAnchoredPosition() {
98 DCHECK(outer_); 98 DCHECK(outer_);
99 99
100 inner_->ClampScrollToMaxScrollOffset(); 100 inner_->ClampScrollToMaxScrollOffset();
101 outer_->ClampScrollToMaxScrollOffset(); 101 outer_->ClampScrollToMaxScrollOffset();
102 102
103 gfx::ScrollOffset viewport_location = inner_->TotalScrollOffset() + 103 gfx::ScrollOffset viewport_location =
104 outer_->TotalScrollOffset(); 104 inner_->CurrentScrollOffset() + outer_->CurrentScrollOffset();
105 105
106 gfx::Vector2dF delta = 106 gfx::Vector2dF delta =
107 viewport_in_content_coordinates_.DeltaFrom(viewport_location); 107 viewport_in_content_coordinates_.DeltaFrom(viewport_location);
108 108
109 delta = outer_->ScrollBy(delta); 109 delta = outer_->ScrollBy(delta);
110 inner_->ScrollBy(delta); 110 inner_->ScrollBy(delta);
111 } 111 }
112 112
113 private: 113 private:
114 LayerImpl* inner_; 114 LayerImpl* inner_;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 device_scale_factor_(1.f), 222 device_scale_factor_(1.f),
223 resourceless_software_draw_(false), 223 resourceless_software_draw_(false),
224 begin_impl_frame_interval_(BeginFrameArgs::DefaultInterval()), 224 begin_impl_frame_interval_(BeginFrameArgs::DefaultInterval()),
225 animation_registrar_(AnimationRegistrar::Create()), 225 animation_registrar_(AnimationRegistrar::Create()),
226 rendering_stats_instrumentation_(rendering_stats_instrumentation), 226 rendering_stats_instrumentation_(rendering_stats_instrumentation),
227 micro_benchmark_controller_(this), 227 micro_benchmark_controller_(this),
228 shared_bitmap_manager_(shared_bitmap_manager), 228 shared_bitmap_manager_(shared_bitmap_manager),
229 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), 229 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
230 id_(id), 230 id_(id),
231 requires_high_res_to_draw_(false), 231 requires_high_res_to_draw_(false),
232 required_for_draw_tile_is_top_of_raster_queue_(false) { 232 is_likely_to_require_a_draw_(false) {
233 DCHECK(proxy_->IsImplThread()); 233 DCHECK(proxy_->IsImplThread());
234 DidVisibilityChange(this, visible_); 234 DidVisibilityChange(this, visible_);
235 animation_registrar_->set_supports_scroll_animations( 235 animation_registrar_->set_supports_scroll_animations(
236 proxy_->SupportsImplScrolling()); 236 proxy_->SupportsImplScrolling());
237 237
238 SetDebugState(settings.initial_debug_state); 238 SetDebugState(settings.initial_debug_state);
239 239
240 // LTHI always has an active tree. 240 // LTHI always has an active tree.
241 active_tree_ = LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(), 241 active_tree_ = LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(),
242 new SyncedElasticOverscroll); 242 new SyncedElasticOverscroll);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 if (!settings_.impl_side_painting && output_surface_) 298 if (!settings_.impl_side_painting && output_surface_)
299 output_surface_->ForceReclaimResources(); 299 output_surface_->ForceReclaimResources();
300 300
301 if (UsePendingTreeForSync()) 301 if (UsePendingTreeForSync())
302 CreatePendingTree(); 302 CreatePendingTree();
303 } 303 }
304 304
305 void LayerTreeHostImpl::CommitComplete() { 305 void LayerTreeHostImpl::CommitComplete() {
306 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete"); 306 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete");
307 307
308 if (pending_tree_)
309 pending_tree_->ApplyScrollDeltasSinceBeginMainFrame();
310 sync_tree()->set_needs_update_draw_properties(); 308 sync_tree()->set_needs_update_draw_properties();
311 309
312 if (settings_.impl_side_painting) { 310 if (settings_.impl_side_painting) {
313 // Impl-side painting needs an update immediately post-commit to have the 311 // Impl-side painting needs an update immediately post-commit to have the
314 // opportunity to create tilings. Other paths can call UpdateDrawProperties 312 // opportunity to create tilings. Other paths can call UpdateDrawProperties
315 // more lazily when needed prior to drawing. 313 // more lazily when needed prior to drawing.
316 sync_tree()->UpdateDrawProperties(); 314 sync_tree()->UpdateDrawProperties();
317 // Start working on newly created tiles immediately if needed. 315 // Start working on newly created tiles immediately if needed.
318 if (tile_manager_ && tile_priorities_dirty_) 316 if (tile_manager_ && tile_priorities_dirty_)
319 PrepareTiles(); 317 PrepareTiles();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 450
453 LayerImpl* layer_impl = 451 LayerImpl* layer_impl =
454 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); 452 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point);
455 453
456 bool scroll_on_main_thread = false; 454 bool scroll_on_main_thread = false;
457 LayerImpl* scrolling_layer_impl = FindScrollLayerForDeviceViewportPoint( 455 LayerImpl* scrolling_layer_impl = FindScrollLayerForDeviceViewportPoint(
458 device_viewport_point, type, layer_impl, &scroll_on_main_thread, NULL); 456 device_viewport_point, type, layer_impl, &scroll_on_main_thread, NULL);
459 return CurrentlyScrollingLayer() == scrolling_layer_impl; 457 return CurrentlyScrollingLayer() == scrolling_layer_impl;
460 } 458 }
461 459
460 bool LayerTreeHostImpl::HaveWheelEventHandlersAt(
461 const gfx::Point& viewport_point) {
462 gfx::PointF device_viewport_point =
463 gfx::ScalePoint(viewport_point, device_scale_factor_);
464
465 LayerImpl* layer_impl =
466 active_tree_->FindLayerWithWheelHandlerThatIsHitByPoint(
467 device_viewport_point);
468
469 return layer_impl != NULL;
470 }
471
462 bool LayerTreeHostImpl::HaveTouchEventHandlersAt( 472 bool LayerTreeHostImpl::HaveTouchEventHandlersAt(
463 const gfx::Point& viewport_point) { 473 const gfx::Point& viewport_point) {
464 474
465 gfx::PointF device_viewport_point = 475 gfx::PointF device_viewport_point =
466 gfx::ScalePoint(viewport_point, device_scale_factor_); 476 gfx::ScalePoint(viewport_point, device_scale_factor_);
467 477
468 LayerImpl* layer_impl = 478 LayerImpl* layer_impl =
469 active_tree_->FindLayerThatIsHitByPointInTouchHandlerRegion( 479 active_tree_->FindLayerThatIsHitByPointInTouchHandlerRegion(
470 device_viewport_point); 480 device_viewport_point);
471 481
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 LayerIteratorType::Begin(frame->render_surface_layer_list); 755 LayerIteratorType::Begin(frame->render_surface_layer_list);
746 it != end; 756 it != end;
747 ++it) { 757 ++it) {
748 RenderPassId target_render_pass_id = 758 RenderPassId target_render_pass_id =
749 it.target_render_surface_layer()->render_surface()->GetRenderPassId(); 759 it.target_render_surface_layer()->render_surface()->GetRenderPassId();
750 RenderPass* target_render_pass = 760 RenderPass* target_render_pass =
751 frame->render_passes_by_id[target_render_pass_id]; 761 frame->render_passes_by_id[target_render_pass_id];
752 762
753 occlusion_tracker.EnterLayer(it); 763 occlusion_tracker.EnterLayer(it);
754 764
755 AppendQuadsData append_quads_data(target_render_pass_id); 765 AppendQuadsData append_quads_data;
756 766
757 if (it.represents_target_render_surface()) { 767 if (it.represents_target_render_surface()) {
758 if (it->HasCopyRequest()) { 768 if (it->HasCopyRequest()) {
759 have_copy_request = true; 769 have_copy_request = true;
760 it->TakeCopyRequestsAndTransformToTarget( 770 it->TakeCopyRequestsAndTransformToTarget(
761 &target_render_pass->copy_requests); 771 &target_render_pass->copy_requests);
762 } 772 }
763 } else if (it.represents_contributing_render_surface() && 773 } else if (it.represents_contributing_render_surface() &&
764 it->render_surface()->contributes_to_drawn_surface()) { 774 it->render_surface()->contributes_to_drawn_surface()) {
765 RenderPassId contributing_render_pass_id = 775 RenderPassId contributing_render_pass_id =
(...skipping 16 matching lines...) Expand all
782 frame->will_draw_layers.push_back(*it); 792 frame->will_draw_layers.push_back(*it);
783 793
784 if (it->HasContributingDelegatedRenderPasses()) { 794 if (it->HasContributingDelegatedRenderPasses()) {
785 RenderPassId contributing_render_pass_id = 795 RenderPassId contributing_render_pass_id =
786 it->FirstContributingRenderPassId(); 796 it->FirstContributingRenderPassId();
787 while (frame->render_passes_by_id.find(contributing_render_pass_id) != 797 while (frame->render_passes_by_id.find(contributing_render_pass_id) !=
788 frame->render_passes_by_id.end()) { 798 frame->render_passes_by_id.end()) {
789 RenderPass* render_pass = 799 RenderPass* render_pass =
790 frame->render_passes_by_id[contributing_render_pass_id]; 800 frame->render_passes_by_id[contributing_render_pass_id];
791 801
792 AppendQuadsData append_quads_data(render_pass->id);
793 AppendQuadsForLayer(render_pass, 802 AppendQuadsForLayer(render_pass,
794 *it, 803 *it,
795 occlusion_tracker, 804 occlusion_tracker,
796 &append_quads_data); 805 &append_quads_data);
797 806
798 contributing_render_pass_id = 807 contributing_render_pass_id =
799 it->NextContributingRenderPassId(contributing_render_pass_id); 808 it->NextContributingRenderPassId(contributing_render_pass_id);
800 } 809 }
801 } 810 }
802 811
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 } 1202 }
1194 } 1203 }
1195 } 1204 }
1196 1205
1197 scoped_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue( 1206 scoped_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue(
1198 TreePriority tree_priority, 1207 TreePriority tree_priority,
1199 RasterTilePriorityQueue::Type type) { 1208 RasterTilePriorityQueue::Type type) {
1200 TRACE_EVENT0("cc", "LayerTreeHostImpl::BuildRasterQueue"); 1209 TRACE_EVENT0("cc", "LayerTreeHostImpl::BuildRasterQueue");
1201 picture_layer_pairs_.clear(); 1210 picture_layer_pairs_.clear();
1202 GetPictureLayerImplPairs(&picture_layer_pairs_, true); 1211 GetPictureLayerImplPairs(&picture_layer_pairs_, true);
1203 scoped_ptr<RasterTilePriorityQueue> queue(RasterTilePriorityQueue::Create( 1212 return RasterTilePriorityQueue::Create(picture_layer_pairs_, tree_priority,
1204 picture_layer_pairs_, tree_priority, type)); 1213 type);
1205
1206 if (!queue->IsEmpty()) {
1207 // Only checking the Top() tile here isn't a definite answer that there is
1208 // or isn't something required for draw in this raster queue. It's just a
1209 // heuristic to let us hit the common case and proactively tell the
1210 // scheduler that we expect to draw within each vsync until we get all the
1211 // tiles ready to draw. If we happen to miss a required for draw tile here,
1212 // then we will miss telling the scheduler each frame that we intend to draw
1213 // so it may make worse scheduling decisions.
1214 required_for_draw_tile_is_top_of_raster_queue_ =
1215 queue->Top()->required_for_draw();
1216 } else {
1217 required_for_draw_tile_is_top_of_raster_queue_ = false;
1218 }
1219 return queue;
1220 } 1214 }
1221 1215
1222 scoped_ptr<EvictionTilePriorityQueue> LayerTreeHostImpl::BuildEvictionQueue( 1216 scoped_ptr<EvictionTilePriorityQueue> LayerTreeHostImpl::BuildEvictionQueue(
1223 TreePriority tree_priority) { 1217 TreePriority tree_priority) {
1224 TRACE_EVENT0("cc", "LayerTreeHostImpl::BuildEvictionQueue"); 1218 TRACE_EVENT0("cc", "LayerTreeHostImpl::BuildEvictionQueue");
1225 scoped_ptr<EvictionTilePriorityQueue> queue(new EvictionTilePriorityQueue); 1219 scoped_ptr<EvictionTilePriorityQueue> queue(new EvictionTilePriorityQueue);
1226 picture_layer_pairs_.clear(); 1220 picture_layer_pairs_.clear();
1227 GetPictureLayerImplPairs(&picture_layer_pairs_, false); 1221 GetPictureLayerImplPairs(&picture_layer_pairs_, false);
1228 queue->Build(picture_layer_pairs_, tree_priority); 1222 queue->Build(picture_layer_pairs_, tree_priority);
1229 return queue; 1223 return queue;
1230 } 1224 }
1231 1225
1226 void LayerTreeHostImpl::SetIsLikelyToRequireADraw(
1227 bool is_likely_to_require_a_draw) {
1228 // Proactively tell the scheduler that we expect to draw within each vsync
1229 // until we get all the tiles ready to draw. If we happen to miss a required
1230 // for draw tile here, then we will miss telling the scheduler each frame that
1231 // we intend to draw so it may make worse scheduling decisions.
1232 is_likely_to_require_a_draw_ = is_likely_to_require_a_draw;
1233 }
1234
1232 const std::vector<PictureLayerImpl*>& LayerTreeHostImpl::GetPictureLayers() 1235 const std::vector<PictureLayerImpl*>& LayerTreeHostImpl::GetPictureLayers()
1233 const { 1236 const {
1234 return picture_layers_; 1237 return picture_layers_;
1235 } 1238 }
1236 1239
1237 void LayerTreeHostImpl::NotifyReadyToActivate() { 1240 void LayerTreeHostImpl::NotifyReadyToActivate() {
1238 client_->NotifyReadyToActivate(); 1241 client_->NotifyReadyToActivate();
1239 } 1242 }
1240 1243
1241 void LayerTreeHostImpl::NotifyReadyToDraw() { 1244 void LayerTreeHostImpl::NotifyReadyToDraw() {
1242 // Tiles that are ready will cause NotifyTileStateChanged() to be called so we 1245 // Tiles that are ready will cause NotifyTileStateChanged() to be called so we
1243 // don't need to schedule a draw here. Just stop WillBeginImplFrame() from 1246 // don't need to schedule a draw here. Just stop WillBeginImplFrame() from
1244 // causing optimistic requests to draw a frame. 1247 // causing optimistic requests to draw a frame.
1245 required_for_draw_tile_is_top_of_raster_queue_ = false; 1248 is_likely_to_require_a_draw_ = false;
1246 1249
1247 client_->NotifyReadyToDraw(); 1250 client_->NotifyReadyToDraw();
1248 } 1251 }
1249 1252
1250 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) { 1253 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) {
1251 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged"); 1254 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged");
1252 1255
1253 if (active_tree_) { 1256 if (active_tree_) {
1254 LayerImpl* layer_impl = 1257 LayerImpl* layer_impl =
1255 active_tree_->FindActiveTreeLayerById(tile->layer_id()); 1258 active_tree_->FindActiveTreeLayerById(tile->layer_id());
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 return true; 1608 return true;
1606 } 1609 }
1607 1610
1608 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { 1611 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) {
1609 // Sample the frame time now. This time will be used for updating animations 1612 // Sample the frame time now. This time will be used for updating animations
1610 // when we draw. 1613 // when we draw.
1611 UpdateCurrentBeginFrameArgs(args); 1614 UpdateCurrentBeginFrameArgs(args);
1612 // Cache the begin impl frame interval 1615 // Cache the begin impl frame interval
1613 begin_impl_frame_interval_ = args.interval; 1616 begin_impl_frame_interval_ = args.interval;
1614 1617
1615 if (required_for_draw_tile_is_top_of_raster_queue_) { 1618 if (is_likely_to_require_a_draw_) {
1616 // Optimistically schedule a draw, as a tile required for draw is at the top 1619 // Optimistically schedule a draw. This will let us expect the tile manager
1617 // of the current raster queue. This will let us expect the tile to complete 1620 // to complete its work so that we can draw new tiles within the impl frame
1618 // and draw it within the impl frame we are beginning now. 1621 // we are beginning now.
1619 SetNeedsRedraw(); 1622 SetNeedsRedraw();
1620 } 1623 }
1621 } 1624 }
1622 1625
1623 void LayerTreeHostImpl::UpdateViewportContainerSizes() { 1626 void LayerTreeHostImpl::UpdateViewportContainerSizes() {
1624 LayerImpl* inner_container = active_tree_->InnerViewportContainerLayer(); 1627 LayerImpl* inner_container = active_tree_->InnerViewportContainerLayer();
1625 LayerImpl* outer_container = active_tree_->OuterViewportContainerLayer(); 1628 LayerImpl* outer_container = active_tree_->OuterViewportContainerLayer();
1626 1629
1627 if (!inner_container || !top_controls_manager_) 1630 if (!inner_container || !top_controls_manager_)
1628 return; 1631 return;
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 tile_task_worker_pool_->AsTileTaskRunner(), 1952 tile_task_worker_pool_->AsTileTaskRunner(),
1950 rasterizer_.get(), scheduled_raster_task_limit); 1953 rasterizer_.get(), scheduled_raster_task_limit);
1951 1954
1952 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); 1955 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy());
1953 } 1956 }
1954 1957
1955 scoped_ptr<Rasterizer> LayerTreeHostImpl::CreateRasterizer() { 1958 scoped_ptr<Rasterizer> LayerTreeHostImpl::CreateRasterizer() {
1956 ContextProvider* context_provider = output_surface_->context_provider(); 1959 ContextProvider* context_provider = output_surface_->context_provider();
1957 if (use_gpu_rasterization_ && context_provider) { 1960 if (use_gpu_rasterization_ && context_provider) {
1958 return GpuRasterizer::Create(context_provider, resource_provider_.get(), 1961 return GpuRasterizer::Create(context_provider, resource_provider_.get(),
1959 settings_.use_distance_field_text, false); 1962 settings_.use_distance_field_text, false,
1963 settings_.gpu_rasterization_msaa_sample_count);
1960 } 1964 }
1961 return SoftwareRasterizer::Create(); 1965 return SoftwareRasterizer::Create();
1962 } 1966 }
1963 1967
1964 void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool( 1968 void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool(
1965 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool, 1969 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool,
1966 scoped_ptr<ResourcePool>* resource_pool, 1970 scoped_ptr<ResourcePool>* resource_pool,
1967 scoped_ptr<ResourcePool>* staging_resource_pool) { 1971 scoped_ptr<ResourcePool>* staging_resource_pool) {
1968 base::SingleThreadTaskRunner* task_runner = 1972 base::SingleThreadTaskRunner* task_runner =
1969 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() 1973 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner()
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
2394 // behavior as ScrollBy to determine which layer to animate, but we do not 2398 // behavior as ScrollBy to determine which layer to animate, but we do not
2395 // do the Android-specific things in ScrollBy like showing top controls. 2399 // do the Android-specific things in ScrollBy like showing top controls.
2396 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel); 2400 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel);
2397 if (scroll_status == ScrollStarted) { 2401 if (scroll_status == ScrollStarted) {
2398 gfx::Vector2dF pending_delta = scroll_delta; 2402 gfx::Vector2dF pending_delta = scroll_delta;
2399 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; 2403 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl;
2400 layer_impl = layer_impl->parent()) { 2404 layer_impl = layer_impl->parent()) {
2401 if (!layer_impl->scrollable()) 2405 if (!layer_impl->scrollable())
2402 continue; 2406 continue;
2403 2407
2404 gfx::ScrollOffset current_offset = layer_impl->TotalScrollOffset(); 2408 gfx::ScrollOffset current_offset = layer_impl->CurrentScrollOffset();
2405 gfx::ScrollOffset target_offset = 2409 gfx::ScrollOffset target_offset =
2406 ScrollOffsetWithDelta(current_offset, pending_delta); 2410 ScrollOffsetWithDelta(current_offset, pending_delta);
2407 target_offset.SetToMax(gfx::ScrollOffset()); 2411 target_offset.SetToMax(gfx::ScrollOffset());
2408 target_offset.SetToMin(layer_impl->MaxScrollOffset()); 2412 target_offset.SetToMin(layer_impl->MaxScrollOffset());
2409 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset); 2413 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset);
2410 2414
2411 const float kEpsilon = 0.1f; 2415 const float kEpsilon = 0.1f;
2412 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon || 2416 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon ||
2413 std::abs(actual_delta.y()) > kEpsilon); 2417 std::abs(actual_delta.y()) > kEpsilon);
2414 2418
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2484 return gfx::Vector2dF(); 2488 return gfx::Vector2dF();
2485 2489
2486 // local_start_point and local_end_point are in content space but we want to 2490 // local_start_point and local_end_point are in content space but we want to
2487 // move them to layer space for scrolling. 2491 // move them to layer space for scrolling.
2488 float width_scale = 1.f / layer_impl->contents_scale_x(); 2492 float width_scale = 1.f / layer_impl->contents_scale_x();
2489 float height_scale = 1.f / layer_impl->contents_scale_y(); 2493 float height_scale = 1.f / layer_impl->contents_scale_y();
2490 local_start_point.Scale(width_scale, height_scale); 2494 local_start_point.Scale(width_scale, height_scale);
2491 local_end_point.Scale(width_scale, height_scale); 2495 local_end_point.Scale(width_scale, height_scale);
2492 2496
2493 // Apply the scroll delta. 2497 // Apply the scroll delta.
2494 gfx::Vector2dF previous_delta = layer_impl->ScrollDelta(); 2498 gfx::ScrollOffset previous_offset = layer_impl->CurrentScrollOffset();
2495 layer_impl->ScrollBy(local_end_point - local_start_point); 2499 layer_impl->ScrollBy(local_end_point - local_start_point);
2500 gfx::ScrollOffset scrolled =
2501 layer_impl->CurrentScrollOffset() - previous_offset;
2496 2502
2497 // Get the end point in the layer's content space so we can apply its 2503 // Get the end point in the layer's content space so we can apply its
2498 // ScreenSpaceTransform. 2504 // ScreenSpaceTransform.
2499 gfx::PointF actual_local_end_point = local_start_point + 2505 gfx::PointF actual_local_end_point =
2500 layer_impl->ScrollDelta() - 2506 local_start_point + gfx::Vector2dF(scrolled.x(), scrolled.y());
2501 previous_delta;
2502 gfx::PointF actual_local_content_end_point = 2507 gfx::PointF actual_local_content_end_point =
2503 gfx::ScalePoint(actual_local_end_point, 2508 gfx::ScalePoint(actual_local_end_point,
2504 1.f / width_scale, 2509 1.f / width_scale,
2505 1.f / height_scale); 2510 1.f / height_scale);
2506 2511
2507 // Calculate the applied scroll delta in viewport space coordinates. 2512 // Calculate the applied scroll delta in viewport space coordinates.
2508 gfx::PointF actual_screen_space_end_point = 2513 gfx::PointF actual_screen_space_end_point =
2509 MathUtil::MapPoint(layer_impl->screen_space_transform(), 2514 MathUtil::MapPoint(layer_impl->screen_space_transform(),
2510 actual_local_content_end_point, 2515 actual_local_content_end_point,
2511 &end_clipped); 2516 &end_clipped);
2512 DCHECK(!end_clipped); 2517 DCHECK(!end_clipped);
2513 if (end_clipped) 2518 if (end_clipped)
2514 return gfx::Vector2dF(); 2519 return gfx::Vector2dF();
2515 gfx::PointF actual_viewport_end_point = 2520 gfx::PointF actual_viewport_end_point =
2516 gfx::ScalePoint(actual_screen_space_end_point, 2521 gfx::ScalePoint(actual_screen_space_end_point,
2517 1.f / scale_from_viewport_to_screen_space); 2522 1.f / scale_from_viewport_to_screen_space);
2518 return actual_viewport_end_point - viewport_point; 2523 return actual_viewport_end_point - viewport_point;
2519 } 2524 }
2520 2525
2521 static gfx::Vector2dF ScrollLayerWithLocalDelta( 2526 static gfx::Vector2dF ScrollLayerWithLocalDelta(
2522 LayerImpl* layer_impl, 2527 LayerImpl* layer_impl,
2523 const gfx::Vector2dF& local_delta, 2528 const gfx::Vector2dF& local_delta,
2524 float page_scale_factor) { 2529 float page_scale_factor) {
2525 gfx::Vector2dF previous_delta(layer_impl->ScrollDelta()); 2530 gfx::ScrollOffset previous_offset = layer_impl->CurrentScrollOffset();
2526 gfx::Vector2dF delta = local_delta; 2531 gfx::Vector2dF delta = local_delta;
2527 delta.Scale(1.f / page_scale_factor); 2532 delta.Scale(1.f / page_scale_factor);
2528 layer_impl->ScrollBy(delta); 2533 layer_impl->ScrollBy(delta);
2529 return layer_impl->ScrollDelta() - previous_delta; 2534 gfx::ScrollOffset scrolled =
2535 layer_impl->CurrentScrollOffset() - previous_offset;
2536 return gfx::Vector2dF(scrolled.x(), scrolled.y());
2530 } 2537 }
2531 2538
2532 bool LayerTreeHostImpl::ShouldTopControlsConsumeScroll( 2539 bool LayerTreeHostImpl::ShouldTopControlsConsumeScroll(
2533 const gfx::Vector2dF& scroll_delta) const { 2540 const gfx::Vector2dF& scroll_delta) const {
2534 DCHECK(CurrentlyScrollingLayer()); 2541 DCHECK(CurrentlyScrollingLayer());
2535 2542
2536 if (!top_controls_manager_) 2543 if (!top_controls_manager_)
2537 return false; 2544 return false;
2538 2545
2539 // Always consume if it's in the direction to show the top controls. 2546 // Always consume if it's in the direction to show the top controls.
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
2969 // scales that we want when we're not inside a pinch. 2976 // scales that we want when we're not inside a pinch.
2970 active_tree_->set_needs_update_draw_properties(); 2977 active_tree_->set_needs_update_draw_properties();
2971 SetNeedsRedraw(); 2978 SetNeedsRedraw();
2972 } 2979 }
2973 2980
2974 static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info, 2981 static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info,
2975 LayerImpl* layer_impl) { 2982 LayerImpl* layer_impl) {
2976 if (!layer_impl) 2983 if (!layer_impl)
2977 return; 2984 return;
2978 2985
2979 gfx::Vector2d scroll_delta = 2986 gfx::ScrollOffset scroll_delta = layer_impl->PullDeltaForMainThread();
2980 gfx::ToFlooredVector2d(layer_impl->ScrollDelta()); 2987
2981 if (!scroll_delta.IsZero()) { 2988 if (!scroll_delta.IsZero()) {
2982 LayerTreeHostCommon::ScrollUpdateInfo scroll; 2989 LayerTreeHostCommon::ScrollUpdateInfo scroll;
2983 scroll.layer_id = layer_impl->id(); 2990 scroll.layer_id = layer_impl->id();
2984 scroll.scroll_delta = scroll_delta; 2991 scroll.scroll_delta = gfx::Vector2d(scroll_delta.x(), scroll_delta.y());
2985 scroll_info->scrolls.push_back(scroll); 2992 scroll_info->scrolls.push_back(scroll);
2986 layer_impl->SetSentScrollDelta(scroll_delta);
2987 } 2993 }
2988 2994
2989 for (size_t i = 0; i < layer_impl->children().size(); ++i) 2995 for (size_t i = 0; i < layer_impl->children().size(); ++i)
2990 CollectScrollDeltas(scroll_info, layer_impl->children()[i]); 2996 CollectScrollDeltas(scroll_info, layer_impl->children()[i]);
2991 } 2997 }
2992 2998
2993 scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::ProcessScrollDeltas() { 2999 scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::ProcessScrollDeltas() {
2994 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); 3000 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet());
2995 3001
2996 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer()); 3002 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer());
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
3453 } 3459 }
3454 3460
3455 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { 3461 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) {
3456 std::vector<PictureLayerImpl*>::iterator it = 3462 std::vector<PictureLayerImpl*>::iterator it =
3457 std::find(picture_layers_.begin(), picture_layers_.end(), layer); 3463 std::find(picture_layers_.begin(), picture_layers_.end(), layer);
3458 DCHECK(it != picture_layers_.end()); 3464 DCHECK(it != picture_layers_.end());
3459 picture_layers_.erase(it); 3465 picture_layers_.erase(it);
3460 } 3466 }
3461 3467
3462 } // namespace cc 3468 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698