Chromium Code Reviews| 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, ScrollWithLatencyInfo) { | |
| 975 ui::LatencyInfo latency_info; | |
| 976 latency_info.AddLatencyNumber( | |
| 977 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, 0); | |
| 978 | |
| 979 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | |
| 980 EXPECT_EQ(InputHandler::ScrollStarted, | |
| 981 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | |
| 982 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | |
| 983 host_impl_->QueueScrollUpdateLatencyInfo(latency_info); | |
| 984 host_impl_->ScrollEnd(); | |
| 985 | |
| 986 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | |
| 987 ASSERT_EQ(scroll_info->latency_infos.size(), 1u); | |
| 988 ASSERT_TRUE(scroll_info->latency_infos[0].FindLatency( | |
|
danakj
2014/07/08 16:49:07
use EXPECT
Sami
2014/07/09 13:28:55
Done.
| |
| 989 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, 0)); | |
| 990 } | |
| 991 | |
| 974 TEST_F(LayerTreeHostImplTest, MasksToBoundsDoesntClobberInnerContainerSize) { | 992 TEST_F(LayerTreeHostImplTest, MasksToBoundsDoesntClobberInnerContainerSize) { |
| 975 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 993 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 976 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 994 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 977 DrawFrame(); | 995 DrawFrame(); |
| 978 | 996 |
| 979 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); | 997 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 980 LayerImpl* container_layer = scroll_layer->scroll_clip_layer(); | 998 LayerImpl* container_layer = scroll_layer->scroll_clip_layer(); |
| 981 DCHECK(scroll_layer); | 999 DCHECK(scroll_layer); |
| 982 | 1000 |
| 983 float min_page_scale = 1.f; | 1001 float min_page_scale = 1.f; |
| (...skipping 5358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6342 EXPECT_EQ(selection_rect, selection_anchor_after.viewport_rect); | 6360 EXPECT_EQ(selection_rect, selection_anchor_after.viewport_rect); |
| 6343 EXPECT_TRUE(selection_anchor_after.visible); | 6361 EXPECT_TRUE(selection_anchor_after.visible); |
| 6344 EXPECT_TRUE(selection_anchor_after.visible); | 6362 EXPECT_TRUE(selection_anchor_after.visible); |
| 6345 } | 6363 } |
| 6346 | 6364 |
| 6347 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { | 6365 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { |
| 6348 public: | 6366 public: |
| 6349 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, | 6367 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, |
| 6350 LayerTreeHostImpl* layer_tree_host_impl, | 6368 LayerTreeHostImpl* layer_tree_host_impl, |
| 6351 int* set_needs_commit_count, | 6369 int* set_needs_commit_count, |
| 6352 int* set_needs_redraw_count) | 6370 int* set_needs_redraw_count, |
| 6371 int* forward_to_main_count) | |
| 6353 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), | 6372 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), |
| 6354 set_needs_commit_count_(set_needs_commit_count), | 6373 set_needs_commit_count_(set_needs_commit_count), |
| 6355 set_needs_redraw_count_(set_needs_redraw_count) {} | 6374 set_needs_redraw_count_(set_needs_redraw_count), |
| 6375 forward_to_main_count_(forward_to_main_count) {} | |
| 6356 | 6376 |
| 6357 virtual ~SimpleSwapPromiseMonitor() {} | 6377 virtual ~SimpleSwapPromiseMonitor() {} |
| 6358 | 6378 |
| 6359 virtual void OnSetNeedsCommitOnMain() OVERRIDE { | 6379 virtual void OnSetNeedsCommitOnMain() OVERRIDE { |
| 6360 (*set_needs_commit_count_)++; | 6380 (*set_needs_commit_count_)++; |
| 6361 } | 6381 } |
| 6362 | 6382 |
| 6363 virtual void OnSetNeedsRedrawOnImpl() OVERRIDE { | 6383 virtual void OnSetNeedsRedrawOnImpl() OVERRIDE { |
| 6364 (*set_needs_redraw_count_)++; | 6384 (*set_needs_redraw_count_)++; |
| 6365 } | 6385 } |
| 6366 | 6386 |
| 6387 virtual void OnForwardScrollUpdateToMainThreadOnImpl() OVERRIDE { | |
| 6388 (*forward_to_main_count_)++; | |
| 6389 } | |
| 6390 | |
| 6367 private: | 6391 private: |
| 6368 int* set_needs_commit_count_; | 6392 int* set_needs_commit_count_; |
| 6369 int* set_needs_redraw_count_; | 6393 int* set_needs_redraw_count_; |
| 6394 int* forward_to_main_count_; | |
| 6370 }; | 6395 }; |
| 6371 | 6396 |
| 6372 TEST_F(LayerTreeHostImplTest, SimpleSwapPromiseMonitor) { | 6397 TEST_F(LayerTreeHostImplTest, SimpleSwapPromiseMonitor) { |
| 6373 int set_needs_commit_count = 0; | 6398 int set_needs_commit_count = 0; |
| 6374 int set_needs_redraw_count = 0; | 6399 int set_needs_redraw_count = 0; |
| 6400 int forward_to_main_count = 0; | |
| 6375 | 6401 |
| 6376 { | 6402 { |
| 6377 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( | 6403 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 6378 new SimpleSwapPromiseMonitor(NULL, | 6404 new SimpleSwapPromiseMonitor(NULL, |
| 6379 host_impl_.get(), | 6405 host_impl_.get(), |
| 6380 &set_needs_commit_count, | 6406 &set_needs_commit_count, |
| 6381 &set_needs_redraw_count)); | 6407 &set_needs_redraw_count, |
| 6408 &forward_to_main_count)); | |
| 6382 host_impl_->SetNeedsRedraw(); | 6409 host_impl_->SetNeedsRedraw(); |
| 6383 EXPECT_EQ(0, set_needs_commit_count); | 6410 EXPECT_EQ(0, set_needs_commit_count); |
| 6384 EXPECT_EQ(1, set_needs_redraw_count); | 6411 EXPECT_EQ(1, set_needs_redraw_count); |
| 6412 EXPECT_EQ(0, forward_to_main_count); | |
| 6385 } | 6413 } |
| 6386 | 6414 |
| 6387 // Now the monitor is destroyed, SetNeedsRedraw() is no longer being | 6415 // Now the monitor is destroyed, SetNeedsRedraw() is no longer being |
| 6388 // monitored. | 6416 // monitored. |
| 6389 host_impl_->SetNeedsRedraw(); | 6417 host_impl_->SetNeedsRedraw(); |
| 6390 EXPECT_EQ(0, set_needs_commit_count); | 6418 EXPECT_EQ(0, set_needs_commit_count); |
| 6391 EXPECT_EQ(1, set_needs_redraw_count); | 6419 EXPECT_EQ(1, set_needs_redraw_count); |
| 6420 EXPECT_EQ(0, forward_to_main_count); | |
| 6392 | 6421 |
| 6393 { | 6422 { |
| 6394 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( | 6423 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 6395 new SimpleSwapPromiseMonitor(NULL, | 6424 new SimpleSwapPromiseMonitor(NULL, |
| 6396 host_impl_.get(), | 6425 host_impl_.get(), |
| 6397 &set_needs_commit_count, | 6426 &set_needs_commit_count, |
| 6398 &set_needs_redraw_count)); | 6427 &set_needs_redraw_count, |
| 6428 &forward_to_main_count)); | |
| 6399 host_impl_->SetNeedsRedrawRect(gfx::Rect(10, 10)); | 6429 host_impl_->SetNeedsRedrawRect(gfx::Rect(10, 10)); |
| 6400 EXPECT_EQ(0, set_needs_commit_count); | 6430 EXPECT_EQ(0, set_needs_commit_count); |
| 6401 EXPECT_EQ(2, set_needs_redraw_count); | 6431 EXPECT_EQ(2, set_needs_redraw_count); |
| 6432 EXPECT_EQ(0, forward_to_main_count); | |
| 6402 } | 6433 } |
| 6403 | 6434 |
| 6404 { | 6435 { |
| 6405 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( | 6436 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 6406 new SimpleSwapPromiseMonitor(NULL, | 6437 new SimpleSwapPromiseMonitor(NULL, |
| 6407 host_impl_.get(), | 6438 host_impl_.get(), |
| 6408 &set_needs_commit_count, | 6439 &set_needs_commit_count, |
| 6409 &set_needs_redraw_count)); | 6440 &set_needs_redraw_count, |
| 6441 &forward_to_main_count)); | |
| 6410 // Empty damage rect won't signal the monitor. | 6442 // Empty damage rect won't signal the monitor. |
| 6411 host_impl_->SetNeedsRedrawRect(gfx::Rect()); | 6443 host_impl_->SetNeedsRedrawRect(gfx::Rect()); |
| 6412 EXPECT_EQ(0, set_needs_commit_count); | 6444 EXPECT_EQ(0, set_needs_commit_count); |
| 6413 EXPECT_EQ(2, set_needs_redraw_count); | 6445 EXPECT_EQ(2, set_needs_redraw_count); |
| 6446 EXPECT_EQ(0, forward_to_main_count); | |
| 6447 } | |
| 6448 | |
| 6449 { | |
| 6450 set_needs_commit_count = 0; | |
| 6451 set_needs_redraw_count = 0; | |
| 6452 forward_to_main_count = 0; | |
| 6453 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( | |
| 6454 new SimpleSwapPromiseMonitor(NULL, | |
| 6455 host_impl_.get(), | |
| 6456 &set_needs_commit_count, | |
| 6457 &set_needs_redraw_count, | |
| 6458 &forward_to_main_count)); | |
| 6459 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | |
| 6460 | |
| 6461 // Scrolling normally should not trigger any forwarding. | |
| 6462 EXPECT_EQ(InputHandler::ScrollStarted, | |
| 6463 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | |
| 6464 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10))); | |
| 6465 host_impl_->ScrollEnd(); | |
| 6466 | |
| 6467 EXPECT_EQ(0, set_needs_commit_count); | |
| 6468 EXPECT_EQ(1, set_needs_redraw_count); | |
| 6469 EXPECT_EQ(0, forward_to_main_count); | |
| 6470 | |
| 6471 // Scrolling with a scroll handler should defer the swap to the main | |
| 6472 // thread. | |
| 6473 scroll_layer->SetHaveScrollEventHandlers(true); | |
| 6474 EXPECT_EQ(InputHandler::ScrollStarted, | |
| 6475 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | |
| 6476 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10))); | |
| 6477 host_impl_->ScrollEnd(); | |
| 6478 | |
| 6479 EXPECT_EQ(0, set_needs_commit_count); | |
| 6480 EXPECT_EQ(2, set_needs_redraw_count); | |
| 6481 EXPECT_EQ(1, forward_to_main_count); | |
| 6414 } | 6482 } |
| 6415 } | 6483 } |
| 6416 | 6484 |
| 6417 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { | 6485 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { |
| 6418 public: | 6486 public: |
| 6419 virtual void SetUp() OVERRIDE { | 6487 virtual void SetUp() OVERRIDE { |
| 6420 LayerTreeSettings settings = DefaultSettings(); | 6488 LayerTreeSettings settings = DefaultSettings(); |
| 6421 settings.calculate_top_controls_position = true; | 6489 settings.calculate_top_controls_position = true; |
| 6422 settings.top_controls_height = top_controls_height_; | 6490 settings.top_controls_height = top_controls_height_; |
| 6423 CreateHostImpl(settings, CreateOutputSurface()); | 6491 CreateHostImpl(settings, CreateOutputSurface()); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6650 external_viewport, | 6718 external_viewport, |
| 6651 external_clip, | 6719 external_clip, |
| 6652 valid_for_tile_management); | 6720 valid_for_tile_management); |
| 6653 DrawFrame(); | 6721 DrawFrame(); |
| 6654 EXPECT_TRANSFORMATION_MATRIX_EQ( | 6722 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6655 external_transform, layer->draw_properties().target_space_transform); | 6723 external_transform, layer->draw_properties().target_space_transform); |
| 6656 } | 6724 } |
| 6657 | 6725 |
| 6658 } // namespace | 6726 } // namespace |
| 6659 } // namespace cc | 6727 } // namespace cc |
| OLD | NEW |