Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 | 332 |
| 333 class LayerTreeHostScrollbarDamageTest : public LayerTreeHostDamageTest { | 333 class LayerTreeHostScrollbarDamageTest : public LayerTreeHostDamageTest { |
| 334 void SetupTree() override { | 334 void SetupTree() override { |
| 335 scoped_refptr<Layer> root_layer = Layer::Create(); | 335 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 336 root_layer->SetBounds(gfx::Size(400, 400)); | 336 root_layer->SetBounds(gfx::Size(400, 400)); |
| 337 root_layer->SetMasksToBounds(true); | 337 root_layer->SetMasksToBounds(true); |
| 338 layer_tree_host()->SetRootLayer(root_layer); | 338 layer_tree_host()->SetRootLayer(root_layer); |
| 339 | 339 |
| 340 scoped_refptr<Layer> scroll_clip_layer = Layer::Create(); | 340 scoped_refptr<Layer> scroll_clip_layer = Layer::Create(); |
| 341 scoped_refptr<Layer> content_layer = FakePictureLayer::Create(&client_); | 341 scoped_refptr<Layer> content_layer = FakePictureLayer::Create(&client_); |
| 342 content_layer_ = content_layer.get(); | |
| 342 content_layer->SetScrollClipLayerId(scroll_clip_layer->id()); | 343 content_layer->SetScrollClipLayerId(scroll_clip_layer->id()); |
| 343 content_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); | 344 content_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
| 344 content_layer->SetBounds(gfx::Size(100, 200)); | 345 content_layer->SetBounds(gfx::Size(100, 200)); |
| 345 content_layer->SetIsDrawable(true); | 346 content_layer->SetIsDrawable(true); |
| 346 scroll_clip_layer->SetBounds( | 347 scroll_clip_layer->SetBounds( |
| 347 gfx::Size(content_layer->bounds().width() - 30, | 348 gfx::Size(content_layer->bounds().width() - 30, |
| 348 content_layer->bounds().height() - 50)); | 349 content_layer->bounds().height() - 50)); |
| 349 scroll_clip_layer->AddChild(content_layer); | 350 scroll_clip_layer->AddChild(content_layer); |
| 350 root_layer->AddChild(scroll_clip_layer); | 351 root_layer->AddChild(scroll_clip_layer); |
| 351 | 352 |
| 352 scoped_refptr<Layer> scrollbar_layer = | 353 scoped_refptr<Layer> scrollbar_layer = |
| 353 FakePaintedScrollbarLayer::Create(false, true, content_layer->id()); | 354 FakePaintedScrollbarLayer::Create(false, true, content_layer->id()); |
| 354 scrollbar_layer->SetPosition(gfx::PointF(300.f, 300.f)); | 355 scrollbar_layer->SetPosition(gfx::PointF(300.f, 300.f)); |
| 355 scrollbar_layer->SetBounds(gfx::Size(10, 100)); | 356 scrollbar_layer->SetBounds(gfx::Size(10, 100)); |
| 356 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(content_layer->id()); | 357 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(content_layer->id()); |
| 357 root_layer->AddChild(scrollbar_layer); | 358 root_layer->AddChild(scrollbar_layer); |
| 358 | 359 |
| 359 gfx::RectF content_rect(content_layer->position(), | 360 gfx::RectF content_rect(content_layer->position(), |
| 360 gfx::SizeF(content_layer->bounds())); | 361 gfx::SizeF(content_layer->bounds())); |
| 361 gfx::RectF scrollbar_rect(scrollbar_layer->position(), | 362 gfx::RectF scrollbar_rect(scrollbar_layer->position(), |
| 362 gfx::SizeF(scrollbar_layer->bounds())); | 363 gfx::SizeF(scrollbar_layer->bounds())); |
| 363 EXPECT_FALSE(content_rect.Intersects(scrollbar_rect)); | 364 EXPECT_FALSE(content_rect.Intersects(scrollbar_rect)); |
| 364 | 365 |
| 365 LayerTreeHostDamageTest::SetupTree(); | 366 LayerTreeHostDamageTest::SetupTree(); |
| 366 client_.set_bounds(root_layer->bounds()); | 367 client_.set_bounds(root_layer->bounds()); |
| 367 } | 368 } |
| 368 | 369 |
| 369 private: | 370 private: |
| 370 FakeContentLayerClient client_; | 371 FakeContentLayerClient client_; |
| 372 | |
| 373 protected: | |
| 374 Layer* content_layer_; | |
|
ajuma
2016/04/20 21:40:52
This should be a scoped_refptr.
sunxd
2016/04/21 17:31:15
Done.
| |
| 371 }; | 375 }; |
| 372 | 376 |
| 373 class LayerTreeHostDamageTestScrollbarDoesDamage | 377 class LayerTreeHostDamageTestScrollbarDoesDamage |
| 374 : public LayerTreeHostScrollbarDamageTest { | 378 : public LayerTreeHostScrollbarDamageTest { |
| 375 void BeginTest() override { | 379 void BeginTest() override { |
| 376 did_swaps_ = 0; | 380 did_swaps_ = 0; |
| 377 PostSetNeedsCommitToMainThread(); | 381 PostSetNeedsCommitToMainThread(); |
| 378 } | 382 } |
| 379 | 383 |
| 380 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 384 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 403 EXPECT_TRUE(root_damage.Contains(gfx::Rect(300, 300, 10, 100))); | 407 EXPECT_TRUE(root_damage.Contains(gfx::Rect(300, 300, 10, 100))); |
| 404 EndTest(); | 408 EndTest(); |
| 405 break; | 409 break; |
| 406 } | 410 } |
| 407 return draw_result; | 411 return draw_result; |
| 408 } | 412 } |
| 409 | 413 |
| 410 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { | 414 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { |
| 411 ++did_swaps_; | 415 ++did_swaps_; |
| 412 EXPECT_TRUE(result); | 416 EXPECT_TRUE(result); |
| 413 LayerImpl* root = host_impl->active_tree()->root_layer(); | 417 LayerImpl* scroll_layer = |
| 414 LayerImpl* scroll_clip_layer = root->children()[0]; | 418 host_impl->active_tree()->LayerById(content_layer_->id()); |
| 415 LayerImpl* scroll_layer = scroll_clip_layer->children()[0]; | |
| 416 switch (did_swaps_) { | 419 switch (did_swaps_) { |
| 417 case 1: | 420 case 1: |
| 418 // Test that modifying the position of the content layer (not | 421 // Test that modifying the position of the content layer (not |
| 419 // scrolling) won't damage the scrollbar. | 422 // scrolling) won't damage the scrollbar. |
| 420 MainThreadTaskRunner()->PostTask( | 423 MainThreadTaskRunner()->PostTask( |
| 421 FROM_HERE, base::Bind(&LayerTreeHostDamageTestScrollbarDoesDamage:: | 424 FROM_HERE, base::Bind(&LayerTreeHostDamageTestScrollbarDoesDamage:: |
| 422 ModifyContentLayerPosition, | 425 ModifyContentLayerPosition, |
| 423 base::Unretained(this))); | 426 base::Unretained(this))); |
| 424 break; | 427 break; |
| 425 case 2: | 428 case 2: |
| 426 scroll_layer->ScrollBy(gfx::Vector2dF(10.f, 10.f)); | 429 scroll_layer->ScrollBy(gfx::Vector2dF(10.f, 10.f)); |
| 427 host_impl->SetNeedsRedraw(); | 430 host_impl->SetNeedsRedraw(); |
| 428 break; | 431 break; |
| 429 case 3: | 432 case 3: |
| 430 // We will resize the content layer, on the main thread. | 433 // We will resize the content layer, on the main thread. |
| 431 MainThreadTaskRunner()->PostTask( | 434 MainThreadTaskRunner()->PostTask( |
| 432 FROM_HERE, | 435 FROM_HERE, |
| 433 base::Bind( | 436 base::Bind( |
| 434 &LayerTreeHostDamageTestScrollbarDoesDamage::ResizeScrollLayer, | 437 &LayerTreeHostDamageTestScrollbarDoesDamage::ResizeScrollLayer, |
| 435 base::Unretained(this))); | 438 base::Unretained(this))); |
| 436 break; | 439 break; |
| 437 } | 440 } |
| 438 } | 441 } |
| 439 | 442 |
| 440 void ModifyContentLayerPosition() { | 443 void ModifyContentLayerPosition() { |
| 441 EXPECT_EQ(1, did_swaps_); | 444 EXPECT_EQ(1, did_swaps_); |
| 442 Layer* root = layer_tree_host()->root_layer(); | 445 content_layer_->SetPosition(gfx::PointF(10.f, 10.f)); |
| 443 Layer* scroll_clip_layer = root->child_at(0); | |
| 444 Layer* scroll_layer = scroll_clip_layer->child_at(0); | |
| 445 scroll_layer->SetPosition(gfx::PointF(10.f, 10.f)); | |
| 446 } | 446 } |
| 447 | 447 |
| 448 void ResizeScrollLayer() { | 448 void ResizeScrollLayer() { |
| 449 EXPECT_EQ(3, did_swaps_); | 449 EXPECT_EQ(3, did_swaps_); |
| 450 Layer* root = layer_tree_host()->root_layer(); | 450 Layer* root = layer_tree_host()->root_layer(); |
| 451 Layer* scroll_clip_layer = root->child_at(0); | 451 content_layer_->SetBounds( |
| 452 Layer* scroll_layer = scroll_clip_layer->child_at(0); | |
| 453 scroll_layer->SetBounds( | |
| 454 gfx::Size(root->bounds().width() + 60, root->bounds().height() + 100)); | 452 gfx::Size(root->bounds().width() + 60, root->bounds().height() + 100)); |
| 455 } | 453 } |
| 456 | 454 |
| 457 void AfterTest() override { EXPECT_EQ(4, did_swaps_); } | 455 void AfterTest() override { EXPECT_EQ(4, did_swaps_); } |
| 458 | 456 |
| 459 int did_swaps_; | 457 int did_swaps_; |
| 460 }; | 458 }; |
| 461 | 459 |
| 462 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarDoesDamage); | 460 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarDoesDamage); |
| 463 | 461 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 default: | 494 default: |
| 497 NOTREACHED(); | 495 NOTREACHED(); |
| 498 break; | 496 break; |
| 499 } | 497 } |
| 500 return draw_result; | 498 return draw_result; |
| 501 } | 499 } |
| 502 | 500 |
| 503 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { | 501 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { |
| 504 ++did_swaps_; | 502 ++did_swaps_; |
| 505 EXPECT_TRUE(result); | 503 EXPECT_TRUE(result); |
| 506 LayerImpl* root = host_impl->active_tree()->root_layer(); | 504 LayerImpl* scroll_layer = |
| 507 LayerImpl* scroll_clip_layer = root->children()[0]; | 505 host_impl->active_tree()->LayerById(content_layer_->id()); |
| 508 LayerImpl* scroll_layer = scroll_clip_layer->children()[0]; | |
| 509 switch (did_swaps_) { | 506 switch (did_swaps_) { |
| 510 case 1: | 507 case 1: |
| 511 // Scroll on the thread. This should damage the scrollbar for the | 508 // Scroll on the thread. This should damage the scrollbar for the |
| 512 // next draw on the thread. | 509 // next draw on the thread. |
| 513 scroll_layer->ScrollBy(gfx::Vector2dF(10.f, 10.f)); | 510 scroll_layer->ScrollBy(gfx::Vector2dF(10.f, 10.f)); |
| 514 host_impl->SetNeedsRedraw(); | 511 host_impl->SetNeedsRedraw(); |
| 515 break; | 512 break; |
| 516 case 2: | 513 case 2: |
| 517 // Forcibly send the scroll to the main thread. | 514 // Forcibly send the scroll to the main thread. |
| 518 PostSetNeedsCommitToMainThread(); | 515 PostSetNeedsCommitToMainThread(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 529 | 526 |
| 530 void AfterTest() override { EXPECT_EQ(3, did_swaps_); } | 527 void AfterTest() override { EXPECT_EQ(3, did_swaps_); } |
| 531 | 528 |
| 532 int did_swaps_; | 529 int did_swaps_; |
| 533 }; | 530 }; |
| 534 | 531 |
| 535 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarCommitDoesNoDamage); | 532 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarCommitDoesNoDamage); |
| 536 | 533 |
| 537 } // namespace | 534 } // namespace |
| 538 } // namespace cc | 535 } // namespace cc |
| OLD | NEW |