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 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 false, false, true); | 406 false, false, true); |
407 } | 407 } |
408 | 408 |
409 void DrawFrame() { | 409 void DrawFrame() { |
410 LayerTreeHostImpl::FrameData frame; | 410 LayerTreeHostImpl::FrameData frame; |
411 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); | 411 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); |
412 host_impl_->DrawLayers(&frame); | 412 host_impl_->DrawLayers(&frame); |
413 host_impl_->DidDrawAllLayers(frame); | 413 host_impl_->DidDrawAllLayers(frame); |
414 } | 414 } |
415 | 415 |
| 416 void DrawFrameWithoutRebuildPropertyTrees() { |
| 417 LayerTreeHostImpl::FrameData frame; |
| 418 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
| 419 host_impl_->DrawLayers(&frame); |
| 420 host_impl_->DidDrawAllLayers(frame); |
| 421 } |
| 422 |
416 void RebuildPropertyTrees() { | 423 void RebuildPropertyTrees() { |
417 host_impl_->active_tree()->property_trees()->needs_rebuild = true; | 424 host_impl_->active_tree()->property_trees()->needs_rebuild = true; |
418 host_impl_->active_tree()->BuildPropertyTreesForTesting(); | 425 host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
419 } | 426 } |
420 | 427 |
421 DrawResult PrepareToDrawFrame(LayerTreeHostImpl::FrameData* frame) { | 428 DrawResult PrepareToDrawFrame(LayerTreeHostImpl::FrameData* frame) { |
422 // We need to build property trees here before drawing the frame as they are | 429 // We need to build property trees here before drawing the frame as they are |
423 // not built on the impl thread. | 430 // not built on the impl thread. |
424 RebuildPropertyTrees(); | 431 RebuildPropertyTrees(); |
425 return host_impl_->PrepareToDraw(frame); | 432 return host_impl_->PrepareToDraw(frame); |
(...skipping 2014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2440 EXPECT_FALSE(did_complete_page_scale_animation_); | 2447 EXPECT_FALSE(did_complete_page_scale_animation_); |
2441 host_impl_->DidFinishImplFrame(); | 2448 host_impl_->DidFinishImplFrame(); |
2442 | 2449 |
2443 begin_frame_args.frame_time = end_time; | 2450 begin_frame_args.frame_time = end_time; |
2444 host_impl_->WillBeginImplFrame(begin_frame_args); | 2451 host_impl_->WillBeginImplFrame(begin_frame_args); |
2445 host_impl_->Animate(); | 2452 host_impl_->Animate(); |
2446 EXPECT_TRUE(did_complete_page_scale_animation_); | 2453 EXPECT_TRUE(did_complete_page_scale_animation_); |
2447 host_impl_->DidFinishImplFrame(); | 2454 host_impl_->DidFinishImplFrame(); |
2448 } | 2455 } |
2449 | 2456 |
| 2457 TEST_F(LayerTreeHostImplTest, MaxScrollOffsetAffectedByBoundsDelta) { |
| 2458 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 2459 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 2460 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
| 2461 DrawFrame(); |
| 2462 |
| 2463 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 2464 LayerImpl* inner_container = inner_scroll->scroll_clip_layer(); |
| 2465 DCHECK(inner_scroll); |
| 2466 DCHECK(inner_container); |
| 2467 EXPECT_EQ(gfx::ScrollOffset(50, 50), inner_scroll->MaxScrollOffset()); |
| 2468 |
| 2469 inner_container->SetBoundsDelta(gfx::Vector2dF(15.f, 15.f)); |
| 2470 inner_scroll->SetBoundsDelta(gfx::Vector2dF(7.f, 7.f)); |
| 2471 EXPECT_EQ(gfx::ScrollOffset(42, 42), inner_scroll->MaxScrollOffset()); |
| 2472 |
| 2473 inner_container->SetBoundsDelta(gfx::Vector2dF()); |
| 2474 inner_scroll->SetBoundsDelta(gfx::Vector2dF()); |
| 2475 inner_scroll->SetBounds(gfx::Size()); |
| 2476 DrawFrame(); |
| 2477 |
| 2478 inner_scroll->SetBoundsDelta(gfx::Vector2dF(60.f, 60.f)); |
| 2479 EXPECT_EQ(gfx::ScrollOffset(10, 10), inner_scroll->MaxScrollOffset()); |
| 2480 } |
| 2481 |
2450 class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl { | 2482 class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl { |
2451 public: | 2483 public: |
2452 LayerTreeHostImplOverridePhysicalTime( | 2484 LayerTreeHostImplOverridePhysicalTime( |
2453 const LayerTreeSettings& settings, | 2485 const LayerTreeSettings& settings, |
2454 LayerTreeHostImplClient* client, | 2486 LayerTreeHostImplClient* client, |
2455 TaskRunnerProvider* task_runner_provider, | 2487 TaskRunnerProvider* task_runner_provider, |
2456 SharedBitmapManager* manager, | 2488 SharedBitmapManager* manager, |
2457 TaskGraphRunner* task_graph_runner, | 2489 TaskGraphRunner* task_graph_runner, |
2458 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 2490 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
2459 : LayerTreeHostImpl(settings, | 2491 : LayerTreeHostImpl(settings, |
(...skipping 2774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5234 wheel_scroll_delta)); | 5266 wheel_scroll_delta)); |
5235 } | 5267 } |
5236 | 5268 |
5237 TEST_F(LayerTreeHostImplTest, ScrollViewportRounding) { | 5269 TEST_F(LayerTreeHostImplTest, ScrollViewportRounding) { |
5238 int width = 332; | 5270 int width = 332; |
5239 int height = 20; | 5271 int height = 20; |
5240 int scale = 3; | 5272 int scale = 3; |
5241 SetupScrollAndContentsLayers(gfx::Size(width, height)); | 5273 SetupScrollAndContentsLayers(gfx::Size(width, height)); |
5242 host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds( | 5274 host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds( |
5243 gfx::Size(width * scale - 1, height * scale)); | 5275 gfx::Size(width * scale - 1, height * scale)); |
| 5276 RebuildPropertyTrees(); |
5244 host_impl_->active_tree()->SetDeviceScaleFactor(scale); | 5277 host_impl_->active_tree()->SetDeviceScaleFactor(scale); |
5245 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); | 5278 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
5246 | 5279 |
5247 LayerImpl* inner_viewport_scroll_layer = | 5280 LayerImpl* inner_viewport_scroll_layer = |
5248 host_impl_->active_tree()->InnerViewportScrollLayer(); | 5281 host_impl_->active_tree()->InnerViewportScrollLayer(); |
5249 EXPECT_EQ(gfx::ScrollOffset(0, 0), | 5282 EXPECT_EQ(gfx::ScrollOffset(0, 0), |
5250 inner_viewport_scroll_layer->MaxScrollOffset()); | 5283 inner_viewport_scroll_layer->MaxScrollOffset()); |
5251 } | 5284 } |
5252 | 5285 |
5253 class TestInputHandlerClient : public InputHandlerClient { | 5286 class TestInputHandlerClient : public InputHandlerClient { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5312 float min_page_scale_factor_; | 5345 float min_page_scale_factor_; |
5313 float max_page_scale_factor_; | 5346 float max_page_scale_factor_; |
5314 }; | 5347 }; |
5315 | 5348 |
5316 TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { | 5349 TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { |
5317 TestInputHandlerClient scroll_watcher; | 5350 TestInputHandlerClient scroll_watcher; |
5318 host_impl_->SetViewportSize(gfx::Size(10, 20)); | 5351 host_impl_->SetViewportSize(gfx::Size(10, 20)); |
5319 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 5352 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
5320 LayerImpl* clip_layer = scroll_layer->parent()->parent(); | 5353 LayerImpl* clip_layer = scroll_layer->parent()->parent(); |
5321 clip_layer->SetBounds(gfx::Size(10, 20)); | 5354 clip_layer->SetBounds(gfx::Size(10, 20)); |
| 5355 RebuildPropertyTrees(); |
5322 | 5356 |
5323 host_impl_->BindToClient(&scroll_watcher); | 5357 host_impl_->BindToClient(&scroll_watcher); |
5324 | 5358 |
5325 gfx::Vector2dF initial_scroll_delta(10.f, 10.f); | 5359 gfx::Vector2dF initial_scroll_delta(10.f, 10.f); |
5326 scroll_layer->PushScrollOffsetFromMainThread(gfx::ScrollOffset()); | 5360 scroll_layer->PushScrollOffsetFromMainThread(gfx::ScrollOffset()); |
5327 scroll_layer->SetScrollDelta(initial_scroll_delta); | 5361 scroll_layer->SetScrollDelta(initial_scroll_delta); |
5328 | 5362 |
5329 EXPECT_EQ(gfx::ScrollOffset(), scroll_watcher.last_set_scroll_offset()); | 5363 EXPECT_EQ(gfx::ScrollOffset(), scroll_watcher.last_set_scroll_offset()); |
5330 | 5364 |
5331 // Requesting an update results in the current scroll offset being set. | 5365 // Requesting an update results in the current scroll offset being set. |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5682 } | 5716 } |
5683 | 5717 |
5684 TEST_F(LayerTreeHostImplTest, OverscrollAlways) { | 5718 TEST_F(LayerTreeHostImplTest, OverscrollAlways) { |
5685 InputHandlerScrollResult scroll_result; | 5719 InputHandlerScrollResult scroll_result; |
5686 LayerTreeSettings settings = DefaultSettings(); | 5720 LayerTreeSettings settings = DefaultSettings(); |
5687 CreateHostImpl(settings, CreateOutputSurface()); | 5721 CreateHostImpl(settings, CreateOutputSurface()); |
5688 | 5722 |
5689 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(50, 50)); | 5723 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(50, 50)); |
5690 LayerImpl* clip_layer = scroll_layer->parent()->parent(); | 5724 LayerImpl* clip_layer = scroll_layer->parent()->parent(); |
5691 clip_layer->SetBounds(gfx::Size(50, 50)); | 5725 clip_layer->SetBounds(gfx::Size(50, 50)); |
| 5726 RebuildPropertyTrees(); |
5692 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 5727 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
5693 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); | 5728 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
5694 DrawFrame(); | 5729 DrawFrame(); |
5695 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 5730 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
5696 | 5731 |
5697 // Even though the layer can't scroll the overscroll still happens. | 5732 // Even though the layer can't scroll the overscroll still happens. |
5698 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, | 5733 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
5699 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), | 5734 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
5700 InputHandler::WHEEL) | 5735 InputHandler::WHEEL) |
5701 .thread); | 5736 .thread); |
(...skipping 1956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7658 scoped_ptr<LayerImpl> child_scroll_clip = | 7693 scoped_ptr<LayerImpl> child_scroll_clip = |
7659 LayerImpl::Create(host_impl_->active_tree(), child_scroll_clip_layer_id); | 7694 LayerImpl::Create(host_impl_->active_tree(), child_scroll_clip_layer_id); |
7660 | 7695 |
7661 int child_scroll_layer_id = 8; | 7696 int child_scroll_layer_id = 8; |
7662 scoped_ptr<LayerImpl> child_scroll = CreateScrollableLayer( | 7697 scoped_ptr<LayerImpl> child_scroll = CreateScrollableLayer( |
7663 child_scroll_layer_id, content_size, child_scroll_clip.get()); | 7698 child_scroll_layer_id, content_size, child_scroll_clip.get()); |
7664 | 7699 |
7665 child_scroll->SetPosition(gfx::PointF(10.f, 10.f)); | 7700 child_scroll->SetPosition(gfx::PointF(10.f, 10.f)); |
7666 | 7701 |
7667 child_scroll->AddChild(std::move(occluder_layer)); | 7702 child_scroll->AddChild(std::move(occluder_layer)); |
7668 scroll_layer->AddChild(std::move(child_scroll)); | 7703 child_scroll_clip->AddChild(std::move(child_scroll)); |
| 7704 scroll_layer->AddChild(std::move(child_scroll_clip)); |
7669 | 7705 |
7670 DrawFrame(); | 7706 DrawFrame(); |
7671 | 7707 |
7672 InputHandler::ScrollStatus status = host_impl_->ScrollBegin( | 7708 InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
7673 BeginState(gfx::Point()).get(), InputHandler::WHEEL); | 7709 BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
7674 EXPECT_EQ(InputHandler::SCROLL_UNKNOWN, status.thread); | 7710 EXPECT_EQ(InputHandler::SCROLL_UNKNOWN, status.thread); |
7675 EXPECT_EQ(MainThreadScrollingReason::kFailedHitTest, | 7711 EXPECT_EQ(MainThreadScrollingReason::kFailedHitTest, |
7676 status.main_thread_scrolling_reasons); | 7712 status.main_thread_scrolling_reasons); |
7677 } | 7713 } |
7678 | 7714 |
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8406 | 8442 |
8407 TEST_F(LayerTreeHostImplWithTopControlsTest, | 8443 TEST_F(LayerTreeHostImplWithTopControlsTest, |
8408 TopControlsScrollDeltaInOverScroll) { | 8444 TopControlsScrollDeltaInOverScroll) { |
8409 // Verifies that the overscroll delta should not have accumulated in | 8445 // Verifies that the overscroll delta should not have accumulated in |
8410 // the top controls if we do a hide and show without releasing finger. | 8446 // the top controls if we do a hide and show without releasing finger. |
8411 | 8447 |
8412 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); | 8448 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
8413 host_impl_->SetViewportSize(gfx::Size(100, 100)); | 8449 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
8414 host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, | 8450 host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, |
8415 false); | 8451 false); |
8416 DrawFrame(); | 8452 DrawFrameWithoutRebuildPropertyTrees(); |
8417 | 8453 |
8418 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, | 8454 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
8419 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), | 8455 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
8420 InputHandler::GESTURE) | 8456 InputHandler::GESTURE) |
8421 .thread); | 8457 .thread); |
8422 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | 8458 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
8423 | 8459 |
8424 float offset = 50; | 8460 float offset = 50; |
8425 EXPECT_TRUE( | 8461 EXPECT_TRUE( |
8426 host_impl_->ScrollBy( | 8462 host_impl_->ScrollBy( |
(...skipping 1468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9895 host_impl_->ActivateSyncTree(); | 9931 host_impl_->ActivateSyncTree(); |
9896 DrawFrame(); | 9932 DrawFrame(); |
9897 | 9933 |
9898 host_impl_->CreatePendingTree(); | 9934 host_impl_->CreatePendingTree(); |
9899 host_impl_->active_tree()->SetPageScaleOnActiveTree(2.f); | 9935 host_impl_->active_tree()->SetPageScaleOnActiveTree(2.f); |
9900 LayerImpl* page_scale_layer = host_impl_->active_tree()->PageScaleLayer(); | 9936 LayerImpl* page_scale_layer = host_impl_->active_tree()->PageScaleLayer(); |
9901 | 9937 |
9902 TransformNode* active_tree_node = | 9938 TransformNode* active_tree_node = |
9903 host_impl_->active_tree()->property_trees()->transform_tree.Node( | 9939 host_impl_->active_tree()->property_trees()->transform_tree.Node( |
9904 page_scale_layer->transform_tree_index()); | 9940 page_scale_layer->transform_tree_index()); |
9905 EXPECT_EQ(active_tree_node->data.post_local_scale_factor, 1.f); | 9941 // SetPageScaleOnActiveTree also updates the factors in property trees. |
| 9942 EXPECT_EQ(active_tree_node->data.post_local_scale_factor, 2.f); |
9906 EXPECT_EQ(host_impl_->active_tree()->current_page_scale_factor(), 2.f); | 9943 EXPECT_EQ(host_impl_->active_tree()->current_page_scale_factor(), 2.f); |
9907 | 9944 |
9908 TransformNode* pending_tree_node = | 9945 TransformNode* pending_tree_node = |
9909 host_impl_->pending_tree()->property_trees()->transform_tree.Node( | 9946 host_impl_->pending_tree()->property_trees()->transform_tree.Node( |
9910 page_scale_layer->transform_tree_index()); | 9947 page_scale_layer->transform_tree_index()); |
9911 EXPECT_EQ(pending_tree_node->data.post_local_scale_factor, 1.f); | 9948 EXPECT_EQ(pending_tree_node->data.post_local_scale_factor, 1.f); |
9912 EXPECT_EQ(host_impl_->pending_tree()->current_page_scale_factor(), 2.f); | 9949 EXPECT_EQ(host_impl_->pending_tree()->current_page_scale_factor(), 2.f); |
9913 | 9950 |
9914 host_impl_->pending_tree()->UpdateDrawProperties(false); | 9951 host_impl_->pending_tree()->UpdateDrawProperties(false); |
9915 pending_tree_node = | 9952 pending_tree_node = |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9997 // There should not be any jitter measured till we hit the fixed point hits | 10034 // There should not be any jitter measured till we hit the fixed point hits |
9998 // threshold. | 10035 // threshold. |
9999 float expected_jitter = | 10036 float expected_jitter = |
10000 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0; | 10037 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0; |
10001 EXPECT_EQ(jitter, expected_jitter); | 10038 EXPECT_EQ(jitter, expected_jitter); |
10002 } | 10039 } |
10003 } | 10040 } |
10004 | 10041 |
10005 } // namespace | 10042 } // namespace |
10006 } // namespace cc | 10043 } // namespace cc |
OLD | NEW |