| 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 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 host_impl_->ScrollEnd(); | 965 host_impl_->ScrollEnd(); |
| 966 | 966 |
| 967 scoped_ptr<ScrollAndScaleSet> scroll_info = | 967 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 968 host_impl_->ProcessScrollDeltas(); | 968 host_impl_->ProcessScrollDeltas(); |
| 969 ExpectContains(*scroll_info.get(), | 969 ExpectContains(*scroll_info.get(), |
| 970 scroll_layer->id(), | 970 scroll_layer->id(), |
| 971 scroll_delta); | 971 scroll_delta); |
| 972 } | 972 } |
| 973 } | 973 } |
| 974 | 974 |
| 975 TEST_F(LayerTreeHostImplTest, ScrollWithSwapPromises) { |
| 976 ui::LatencyInfo latency_info; |
| 977 latency_info.trace_id = 1234; |
| 978 scoped_ptr<SwapPromise> swap_promise( |
| 979 new LatencyInfoSwapPromise(latency_info)); |
| 980 |
| 981 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 982 EXPECT_EQ(InputHandler::ScrollStarted, |
| 983 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 984 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
| 985 host_impl_->QueueSwapPromiseForMainThreadScrollUpdate(swap_promise.Pass()); |
| 986 host_impl_->ScrollEnd(); |
| 987 |
| 988 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
| 989 EXPECT_EQ(1u, scroll_info->swap_promises.size()); |
| 990 EXPECT_EQ(latency_info.trace_id, scroll_info->swap_promises[0]->TraceId()); |
| 991 } |
| 992 |
| 975 TEST_F(LayerTreeHostImplTest, MasksToBoundsDoesntClobberInnerContainerSize) { | 993 TEST_F(LayerTreeHostImplTest, MasksToBoundsDoesntClobberInnerContainerSize) { |
| 976 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 994 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 977 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 995 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 978 DrawFrame(); | 996 DrawFrame(); |
| 979 | 997 |
| 980 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); | 998 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 981 LayerImpl* container_layer = scroll_layer->scroll_clip_layer(); | 999 LayerImpl* container_layer = scroll_layer->scroll_clip_layer(); |
| 982 DCHECK(scroll_layer); | 1000 DCHECK(scroll_layer); |
| 983 | 1001 |
| 984 float min_page_scale = 1.f; | 1002 float min_page_scale = 1.f; |
| (...skipping 5370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6355 EXPECT_EQ(selection_rect, selection_start_after.viewport_rect); | 6373 EXPECT_EQ(selection_rect, selection_start_after.viewport_rect); |
| 6356 EXPECT_TRUE(selection_start_after.visible); | 6374 EXPECT_TRUE(selection_start_after.visible); |
| 6357 EXPECT_TRUE(selection_start_after.visible); | 6375 EXPECT_TRUE(selection_start_after.visible); |
| 6358 } | 6376 } |
| 6359 | 6377 |
| 6360 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { | 6378 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { |
| 6361 public: | 6379 public: |
| 6362 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, | 6380 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, |
| 6363 LayerTreeHostImpl* layer_tree_host_impl, | 6381 LayerTreeHostImpl* layer_tree_host_impl, |
| 6364 int* set_needs_commit_count, | 6382 int* set_needs_commit_count, |
| 6365 int* set_needs_redraw_count) | 6383 int* set_needs_redraw_count, |
| 6384 int* forward_to_main_count) |
| 6366 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), | 6385 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), |
| 6367 set_needs_commit_count_(set_needs_commit_count), | 6386 set_needs_commit_count_(set_needs_commit_count), |
| 6368 set_needs_redraw_count_(set_needs_redraw_count) {} | 6387 set_needs_redraw_count_(set_needs_redraw_count), |
| 6388 forward_to_main_count_(forward_to_main_count) {} |
| 6369 | 6389 |
| 6370 virtual ~SimpleSwapPromiseMonitor() {} | 6390 virtual ~SimpleSwapPromiseMonitor() {} |
| 6371 | 6391 |
| 6372 virtual void OnSetNeedsCommitOnMain() OVERRIDE { | 6392 virtual void OnSetNeedsCommitOnMain() OVERRIDE { |
| 6373 (*set_needs_commit_count_)++; | 6393 (*set_needs_commit_count_)++; |
| 6374 } | 6394 } |
| 6375 | 6395 |
| 6376 virtual void OnSetNeedsRedrawOnImpl() OVERRIDE { | 6396 virtual void OnSetNeedsRedrawOnImpl() OVERRIDE { |
| 6377 (*set_needs_redraw_count_)++; | 6397 (*set_needs_redraw_count_)++; |
| 6378 } | 6398 } |
| 6379 | 6399 |
| 6400 virtual void OnForwardScrollUpdateToMainThreadOnImpl() OVERRIDE { |
| 6401 (*forward_to_main_count_)++; |
| 6402 } |
| 6403 |
| 6380 private: | 6404 private: |
| 6381 int* set_needs_commit_count_; | 6405 int* set_needs_commit_count_; |
| 6382 int* set_needs_redraw_count_; | 6406 int* set_needs_redraw_count_; |
| 6407 int* forward_to_main_count_; |
| 6383 }; | 6408 }; |
| 6384 | 6409 |
| 6385 TEST_F(LayerTreeHostImplTest, SimpleSwapPromiseMonitor) { | 6410 TEST_F(LayerTreeHostImplTest, SimpleSwapPromiseMonitor) { |
| 6386 int set_needs_commit_count = 0; | 6411 int set_needs_commit_count = 0; |
| 6387 int set_needs_redraw_count = 0; | 6412 int set_needs_redraw_count = 0; |
| 6413 int forward_to_main_count = 0; |
| 6388 | 6414 |
| 6389 { | 6415 { |
| 6390 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( | 6416 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 6391 new SimpleSwapPromiseMonitor(NULL, | 6417 new SimpleSwapPromiseMonitor(NULL, |
| 6392 host_impl_.get(), | 6418 host_impl_.get(), |
| 6393 &set_needs_commit_count, | 6419 &set_needs_commit_count, |
| 6394 &set_needs_redraw_count)); | 6420 &set_needs_redraw_count, |
| 6421 &forward_to_main_count)); |
| 6395 host_impl_->SetNeedsRedraw(); | 6422 host_impl_->SetNeedsRedraw(); |
| 6396 EXPECT_EQ(0, set_needs_commit_count); | 6423 EXPECT_EQ(0, set_needs_commit_count); |
| 6397 EXPECT_EQ(1, set_needs_redraw_count); | 6424 EXPECT_EQ(1, set_needs_redraw_count); |
| 6425 EXPECT_EQ(0, forward_to_main_count); |
| 6398 } | 6426 } |
| 6399 | 6427 |
| 6400 // Now the monitor is destroyed, SetNeedsRedraw() is no longer being | 6428 // Now the monitor is destroyed, SetNeedsRedraw() is no longer being |
| 6401 // monitored. | 6429 // monitored. |
| 6402 host_impl_->SetNeedsRedraw(); | 6430 host_impl_->SetNeedsRedraw(); |
| 6403 EXPECT_EQ(0, set_needs_commit_count); | 6431 EXPECT_EQ(0, set_needs_commit_count); |
| 6404 EXPECT_EQ(1, set_needs_redraw_count); | 6432 EXPECT_EQ(1, set_needs_redraw_count); |
| 6433 EXPECT_EQ(0, forward_to_main_count); |
| 6405 | 6434 |
| 6406 { | 6435 { |
| 6407 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( | 6436 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 6408 new SimpleSwapPromiseMonitor(NULL, | 6437 new SimpleSwapPromiseMonitor(NULL, |
| 6409 host_impl_.get(), | 6438 host_impl_.get(), |
| 6410 &set_needs_commit_count, | 6439 &set_needs_commit_count, |
| 6411 &set_needs_redraw_count)); | 6440 &set_needs_redraw_count, |
| 6441 &forward_to_main_count)); |
| 6412 host_impl_->SetNeedsRedrawRect(gfx::Rect(10, 10)); | 6442 host_impl_->SetNeedsRedrawRect(gfx::Rect(10, 10)); |
| 6413 EXPECT_EQ(0, set_needs_commit_count); | 6443 EXPECT_EQ(0, set_needs_commit_count); |
| 6414 EXPECT_EQ(2, set_needs_redraw_count); | 6444 EXPECT_EQ(2, set_needs_redraw_count); |
| 6445 EXPECT_EQ(0, forward_to_main_count); |
| 6415 } | 6446 } |
| 6416 | 6447 |
| 6417 { | 6448 { |
| 6418 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( | 6449 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 6419 new SimpleSwapPromiseMonitor(NULL, | 6450 new SimpleSwapPromiseMonitor(NULL, |
| 6420 host_impl_.get(), | 6451 host_impl_.get(), |
| 6421 &set_needs_commit_count, | 6452 &set_needs_commit_count, |
| 6422 &set_needs_redraw_count)); | 6453 &set_needs_redraw_count, |
| 6454 &forward_to_main_count)); |
| 6423 // Empty damage rect won't signal the monitor. | 6455 // Empty damage rect won't signal the monitor. |
| 6424 host_impl_->SetNeedsRedrawRect(gfx::Rect()); | 6456 host_impl_->SetNeedsRedrawRect(gfx::Rect()); |
| 6425 EXPECT_EQ(0, set_needs_commit_count); | 6457 EXPECT_EQ(0, set_needs_commit_count); |
| 6426 EXPECT_EQ(2, set_needs_redraw_count); | 6458 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); |
| 6427 } | 6495 } |
| 6428 } | 6496 } |
| 6429 | 6497 |
| 6430 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { | 6498 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { |
| 6431 public: | 6499 public: |
| 6432 virtual void SetUp() OVERRIDE { | 6500 virtual void SetUp() OVERRIDE { |
| 6433 LayerTreeSettings settings = DefaultSettings(); | 6501 LayerTreeSettings settings = DefaultSettings(); |
| 6434 settings.calculate_top_controls_position = true; | 6502 settings.calculate_top_controls_position = true; |
| 6435 settings.top_controls_height = top_controls_height_; | 6503 settings.top_controls_height = top_controls_height_; |
| 6436 CreateHostImpl(settings, CreateOutputSurface()); | 6504 CreateHostImpl(settings, CreateOutputSurface()); |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6836 host_impl_->DidLoseOutputSurface(); | 6904 host_impl_->DidLoseOutputSurface(); |
| 6837 EXPECT_TRUE(host_impl_->IsContextLost()); | 6905 EXPECT_TRUE(host_impl_->IsContextLost()); |
| 6838 EXPECT_EQ(1, num_lost_surfaces_); | 6906 EXPECT_EQ(1, num_lost_surfaces_); |
| 6839 host_impl_->DidLoseOutputSurface(); | 6907 host_impl_->DidLoseOutputSurface(); |
| 6840 EXPECT_TRUE(host_impl_->IsContextLost()); | 6908 EXPECT_TRUE(host_impl_->IsContextLost()); |
| 6841 EXPECT_EQ(1, num_lost_surfaces_); | 6909 EXPECT_EQ(1, num_lost_surfaces_); |
| 6842 } | 6910 } |
| 6843 | 6911 |
| 6844 } // namespace | 6912 } // namespace |
| 6845 } // namespace cc | 6913 } // namespace cc |
| OLD | NEW |