| 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 <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 host_impl_->ScrollEnd(); | 964 host_impl_->ScrollEnd(); |
| 965 | 965 |
| 966 scoped_ptr<ScrollAndScaleSet> scroll_info = | 966 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 967 host_impl_->ProcessScrollDeltas(); | 967 host_impl_->ProcessScrollDeltas(); |
| 968 ExpectContains(*scroll_info.get(), | 968 ExpectContains(*scroll_info.get(), |
| 969 scroll_layer->id(), | 969 scroll_layer->id(), |
| 970 scroll_delta); | 970 scroll_delta); |
| 971 } | 971 } |
| 972 } | 972 } |
| 973 | 973 |
| 974 TEST_F(LayerTreeHostImplTest, ScrollWithSwapPromises) { | |
| 975 ui::LatencyInfo latency_info; | |
| 976 latency_info.trace_id = 1234; | |
| 977 scoped_ptr<SwapPromise> swap_promise( | |
| 978 new LatencyInfoSwapPromise(latency_info)); | |
| 979 | |
| 980 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | |
| 981 EXPECT_EQ(InputHandler::ScrollStarted, | |
| 982 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | |
| 983 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | |
| 984 host_impl_->QueueSwapPromiseForMainThreadScrollUpdate(swap_promise.Pass()); | |
| 985 host_impl_->ScrollEnd(); | |
| 986 | |
| 987 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | |
| 988 EXPECT_EQ(1u, scroll_info->swap_promises.size()); | |
| 989 EXPECT_EQ(latency_info.trace_id, scroll_info->swap_promises[0]->TraceId()); | |
| 990 } | |
| 991 | |
| 992 TEST_F(LayerTreeHostImplTest, MasksToBoundsDoesntClobberInnerContainerSize) { | 974 TEST_F(LayerTreeHostImplTest, MasksToBoundsDoesntClobberInnerContainerSize) { |
| 993 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 975 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 994 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 976 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 995 DrawFrame(); | 977 DrawFrame(); |
| 996 | 978 |
| 997 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); | 979 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 998 LayerImpl* container_layer = scroll_layer->scroll_clip_layer(); | 980 LayerImpl* container_layer = scroll_layer->scroll_clip_layer(); |
| 999 DCHECK(scroll_layer); | 981 DCHECK(scroll_layer); |
| 1000 | 982 |
| 1001 float min_page_scale = 1.f; | 983 float min_page_scale = 1.f; |
| (...skipping 5371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6373 EXPECT_EQ(selection_rect, selection_start_after.viewport_rect); | 6355 EXPECT_EQ(selection_rect, selection_start_after.viewport_rect); |
| 6374 EXPECT_TRUE(selection_start_after.visible); | 6356 EXPECT_TRUE(selection_start_after.visible); |
| 6375 EXPECT_TRUE(selection_start_after.visible); | 6357 EXPECT_TRUE(selection_start_after.visible); |
| 6376 } | 6358 } |
| 6377 | 6359 |
| 6378 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { | 6360 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { |
| 6379 public: | 6361 public: |
| 6380 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, | 6362 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, |
| 6381 LayerTreeHostImpl* layer_tree_host_impl, | 6363 LayerTreeHostImpl* layer_tree_host_impl, |
| 6382 int* set_needs_commit_count, | 6364 int* set_needs_commit_count, |
| 6383 int* set_needs_redraw_count, | 6365 int* set_needs_redraw_count) |
| 6384 int* forward_to_main_count) | |
| 6385 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), | 6366 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), |
| 6386 set_needs_commit_count_(set_needs_commit_count), | 6367 set_needs_commit_count_(set_needs_commit_count), |
| 6387 set_needs_redraw_count_(set_needs_redraw_count), | 6368 set_needs_redraw_count_(set_needs_redraw_count) {} |
| 6388 forward_to_main_count_(forward_to_main_count) {} | |
| 6389 | 6369 |
| 6390 virtual ~SimpleSwapPromiseMonitor() {} | 6370 virtual ~SimpleSwapPromiseMonitor() {} |
| 6391 | 6371 |
| 6392 virtual void OnSetNeedsCommitOnMain() OVERRIDE { | 6372 virtual void OnSetNeedsCommitOnMain() OVERRIDE { |
| 6393 (*set_needs_commit_count_)++; | 6373 (*set_needs_commit_count_)++; |
| 6394 } | 6374 } |
| 6395 | 6375 |
| 6396 virtual void OnSetNeedsRedrawOnImpl() OVERRIDE { | 6376 virtual void OnSetNeedsRedrawOnImpl() OVERRIDE { |
| 6397 (*set_needs_redraw_count_)++; | 6377 (*set_needs_redraw_count_)++; |
| 6398 } | 6378 } |
| 6399 | 6379 |
| 6400 virtual void OnForwardScrollUpdateToMainThreadOnImpl() OVERRIDE { | |
| 6401 (*forward_to_main_count_)++; | |
| 6402 } | |
| 6403 | |
| 6404 private: | 6380 private: |
| 6405 int* set_needs_commit_count_; | 6381 int* set_needs_commit_count_; |
| 6406 int* set_needs_redraw_count_; | 6382 int* set_needs_redraw_count_; |
| 6407 int* forward_to_main_count_; | |
| 6408 }; | 6383 }; |
| 6409 | 6384 |
| 6410 TEST_F(LayerTreeHostImplTest, SimpleSwapPromiseMonitor) { | 6385 TEST_F(LayerTreeHostImplTest, SimpleSwapPromiseMonitor) { |
| 6411 int set_needs_commit_count = 0; | 6386 int set_needs_commit_count = 0; |
| 6412 int set_needs_redraw_count = 0; | 6387 int set_needs_redraw_count = 0; |
| 6413 int forward_to_main_count = 0; | |
| 6414 | 6388 |
| 6415 { | 6389 { |
| 6416 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( | 6390 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 6417 new SimpleSwapPromiseMonitor(NULL, | 6391 new SimpleSwapPromiseMonitor(NULL, |
| 6418 host_impl_.get(), | 6392 host_impl_.get(), |
| 6419 &set_needs_commit_count, | 6393 &set_needs_commit_count, |
| 6420 &set_needs_redraw_count, | 6394 &set_needs_redraw_count)); |
| 6421 &forward_to_main_count)); | |
| 6422 host_impl_->SetNeedsRedraw(); | 6395 host_impl_->SetNeedsRedraw(); |
| 6423 EXPECT_EQ(0, set_needs_commit_count); | 6396 EXPECT_EQ(0, set_needs_commit_count); |
| 6424 EXPECT_EQ(1, set_needs_redraw_count); | 6397 EXPECT_EQ(1, set_needs_redraw_count); |
| 6425 EXPECT_EQ(0, forward_to_main_count); | |
| 6426 } | 6398 } |
| 6427 | 6399 |
| 6428 // Now the monitor is destroyed, SetNeedsRedraw() is no longer being | 6400 // Now the monitor is destroyed, SetNeedsRedraw() is no longer being |
| 6429 // monitored. | 6401 // monitored. |
| 6430 host_impl_->SetNeedsRedraw(); | 6402 host_impl_->SetNeedsRedraw(); |
| 6431 EXPECT_EQ(0, set_needs_commit_count); | 6403 EXPECT_EQ(0, set_needs_commit_count); |
| 6432 EXPECT_EQ(1, set_needs_redraw_count); | 6404 EXPECT_EQ(1, set_needs_redraw_count); |
| 6433 EXPECT_EQ(0, forward_to_main_count); | |
| 6434 | 6405 |
| 6435 { | 6406 { |
| 6436 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( | 6407 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 6437 new SimpleSwapPromiseMonitor(NULL, | 6408 new SimpleSwapPromiseMonitor(NULL, |
| 6438 host_impl_.get(), | 6409 host_impl_.get(), |
| 6439 &set_needs_commit_count, | 6410 &set_needs_commit_count, |
| 6440 &set_needs_redraw_count, | 6411 &set_needs_redraw_count)); |
| 6441 &forward_to_main_count)); | |
| 6442 host_impl_->SetNeedsRedrawRect(gfx::Rect(10, 10)); | 6412 host_impl_->SetNeedsRedrawRect(gfx::Rect(10, 10)); |
| 6443 EXPECT_EQ(0, set_needs_commit_count); | 6413 EXPECT_EQ(0, set_needs_commit_count); |
| 6444 EXPECT_EQ(2, set_needs_redraw_count); | 6414 EXPECT_EQ(2, set_needs_redraw_count); |
| 6445 EXPECT_EQ(0, forward_to_main_count); | |
| 6446 } | 6415 } |
| 6447 | 6416 |
| 6448 { | 6417 { |
| 6449 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( | 6418 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 6450 new SimpleSwapPromiseMonitor(NULL, | 6419 new SimpleSwapPromiseMonitor(NULL, |
| 6451 host_impl_.get(), | 6420 host_impl_.get(), |
| 6452 &set_needs_commit_count, | 6421 &set_needs_commit_count, |
| 6453 &set_needs_redraw_count, | 6422 &set_needs_redraw_count)); |
| 6454 &forward_to_main_count)); | |
| 6455 // Empty damage rect won't signal the monitor. | 6423 // Empty damage rect won't signal the monitor. |
| 6456 host_impl_->SetNeedsRedrawRect(gfx::Rect()); | 6424 host_impl_->SetNeedsRedrawRect(gfx::Rect()); |
| 6457 EXPECT_EQ(0, set_needs_commit_count); | 6425 EXPECT_EQ(0, set_needs_commit_count); |
| 6458 EXPECT_EQ(2, set_needs_redraw_count); | 6426 EXPECT_EQ(2, set_needs_redraw_count); |
| 6459 EXPECT_EQ(0, forward_to_main_count); | |
| 6460 } | |
| 6461 | |
| 6462 { | |
| 6463 set_needs_commit_count = 0; | |
| 6464 set_needs_redraw_count = 0; | |
| 6465 forward_to_main_count = 0; | |
| 6466 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( | |
| 6467 new SimpleSwapPromiseMonitor(NULL, | |
| 6468 host_impl_.get(), | |
| 6469 &set_needs_commit_count, | |
| 6470 &set_needs_redraw_count, | |
| 6471 &forward_to_main_count)); | |
| 6472 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | |
| 6473 | |
| 6474 // Scrolling normally should not trigger any forwarding. | |
| 6475 EXPECT_EQ(InputHandler::ScrollStarted, | |
| 6476 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | |
| 6477 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10))); | |
| 6478 host_impl_->ScrollEnd(); | |
| 6479 | |
| 6480 EXPECT_EQ(0, set_needs_commit_count); | |
| 6481 EXPECT_EQ(1, set_needs_redraw_count); | |
| 6482 EXPECT_EQ(0, forward_to_main_count); | |
| 6483 | |
| 6484 // Scrolling with a scroll handler should defer the swap to the main | |
| 6485 // thread. | |
| 6486 scroll_layer->SetHaveScrollEventHandlers(true); | |
| 6487 EXPECT_EQ(InputHandler::ScrollStarted, | |
| 6488 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | |
| 6489 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10))); | |
| 6490 host_impl_->ScrollEnd(); | |
| 6491 | |
| 6492 EXPECT_EQ(0, set_needs_commit_count); | |
| 6493 EXPECT_EQ(2, set_needs_redraw_count); | |
| 6494 EXPECT_EQ(1, forward_to_main_count); | |
| 6495 } | 6427 } |
| 6496 } | 6428 } |
| 6497 | 6429 |
| 6498 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { | 6430 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { |
| 6499 public: | 6431 public: |
| 6500 virtual void SetUp() OVERRIDE { | 6432 virtual void SetUp() OVERRIDE { |
| 6501 LayerTreeSettings settings = DefaultSettings(); | 6433 LayerTreeSettings settings = DefaultSettings(); |
| 6502 settings.calculate_top_controls_position = true; | 6434 settings.calculate_top_controls_position = true; |
| 6503 settings.top_controls_height = top_controls_height_; | 6435 settings.top_controls_height = top_controls_height_; |
| 6504 CreateHostImpl(settings, CreateOutputSurface()); | 6436 CreateHostImpl(settings, CreateOutputSurface()); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6762 | 6694 |
| 6763 host_impl_->Animate(start_time + base::TimeDelta::FromMilliseconds(200)); | 6695 host_impl_->Animate(start_time + base::TimeDelta::FromMilliseconds(200)); |
| 6764 host_impl_->UpdateAnimationState(true); | 6696 host_impl_->UpdateAnimationState(true); |
| 6765 | 6697 |
| 6766 EXPECT_EQ(gfx::Vector2dF(0, 50), scrolling_layer->TotalScrollOffset()); | 6698 EXPECT_EQ(gfx::Vector2dF(0, 50), scrolling_layer->TotalScrollOffset()); |
| 6767 EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); | 6699 EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); |
| 6768 } | 6700 } |
| 6769 | 6701 |
| 6770 } // namespace | 6702 } // namespace |
| 6771 } // namespace cc | 6703 } // namespace cc |
| OLD | NEW |