Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: cc/trees/layer_tree_host_unittest_damage.cc

Issue 1905713002: cc: Remove LayerImpl::children() calls from descendants of LayerTreeTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDamageTestForcedFullDamage); 331 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDamageTestForcedFullDamage);
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 content_layer_ = FakePictureLayer::Create(&client_);
342 content_layer->SetScrollClipLayerId(scroll_clip_layer->id()); 342 content_layer_->SetScrollClipLayerId(scroll_clip_layer->id());
343 content_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); 343 content_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20));
344 content_layer->SetBounds(gfx::Size(100, 200)); 344 content_layer_->SetBounds(gfx::Size(100, 200));
345 content_layer->SetIsDrawable(true); 345 content_layer_->SetIsDrawable(true);
346 scroll_clip_layer->SetBounds( 346 scroll_clip_layer->SetBounds(
347 gfx::Size(content_layer->bounds().width() - 30, 347 gfx::Size(content_layer_->bounds().width() - 30,
348 content_layer->bounds().height() - 50)); 348 content_layer_->bounds().height() - 50));
349 scroll_clip_layer->AddChild(content_layer); 349 scroll_clip_layer->AddChild(content_layer_);
350 root_layer->AddChild(scroll_clip_layer); 350 root_layer->AddChild(scroll_clip_layer);
351 351
352 scoped_refptr<Layer> scrollbar_layer = 352 scoped_refptr<Layer> scrollbar_layer =
353 FakePaintedScrollbarLayer::Create(false, true, content_layer->id()); 353 FakePaintedScrollbarLayer::Create(false, true, content_layer_->id());
354 scrollbar_layer->SetPosition(gfx::PointF(300.f, 300.f)); 354 scrollbar_layer->SetPosition(gfx::PointF(300.f, 300.f));
355 scrollbar_layer->SetBounds(gfx::Size(10, 100)); 355 scrollbar_layer->SetBounds(gfx::Size(10, 100));
356 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(content_layer->id()); 356 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(content_layer_->id());
357 root_layer->AddChild(scrollbar_layer); 357 root_layer->AddChild(scrollbar_layer);
358 358
359 gfx::RectF content_rect(content_layer->position(), 359 gfx::RectF content_rect(content_layer_->position(),
360 gfx::SizeF(content_layer->bounds())); 360 gfx::SizeF(content_layer_->bounds()));
361 gfx::RectF scrollbar_rect(scrollbar_layer->position(), 361 gfx::RectF scrollbar_rect(scrollbar_layer->position(),
362 gfx::SizeF(scrollbar_layer->bounds())); 362 gfx::SizeF(scrollbar_layer->bounds()));
363 EXPECT_FALSE(content_rect.Intersects(scrollbar_rect)); 363 EXPECT_FALSE(content_rect.Intersects(scrollbar_rect));
364 364
365 LayerTreeHostDamageTest::SetupTree(); 365 LayerTreeHostDamageTest::SetupTree();
366 client_.set_bounds(root_layer->bounds()); 366 client_.set_bounds(root_layer->bounds());
367 } 367 }
368 368
369 private: 369 private:
370 FakeContentLayerClient client_; 370 FakeContentLayerClient client_;
371
372 protected:
373 scoped_refptr<Layer> content_layer_;
371 }; 374 };
372 375
373 class LayerTreeHostDamageTestScrollbarDoesDamage 376 class LayerTreeHostDamageTestScrollbarDoesDamage
374 : public LayerTreeHostScrollbarDamageTest { 377 : public LayerTreeHostScrollbarDamageTest {
375 void BeginTest() override { 378 void BeginTest() override {
376 did_swaps_ = 0; 379 did_swaps_ = 0;
377 PostSetNeedsCommitToMainThread(); 380 PostSetNeedsCommitToMainThread();
378 } 381 }
379 382
380 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, 383 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
(...skipping 22 matching lines...) Expand all
403 EXPECT_TRUE(root_damage.Contains(gfx::Rect(300, 300, 10, 100))); 406 EXPECT_TRUE(root_damage.Contains(gfx::Rect(300, 300, 10, 100)));
404 EndTest(); 407 EndTest();
405 break; 408 break;
406 } 409 }
407 return draw_result; 410 return draw_result;
408 } 411 }
409 412
410 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { 413 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override {
411 ++did_swaps_; 414 ++did_swaps_;
412 EXPECT_TRUE(result); 415 EXPECT_TRUE(result);
413 LayerImpl* root = host_impl->active_tree()->root_layer(); 416 LayerImpl* scroll_layer =
414 LayerImpl* scroll_clip_layer = root->children()[0]; 417 host_impl->active_tree()->LayerById(content_layer_->id());
415 LayerImpl* scroll_layer = scroll_clip_layer->children()[0];
416 switch (did_swaps_) { 418 switch (did_swaps_) {
417 case 1: 419 case 1:
418 // Test that modifying the position of the content layer (not 420 // Test that modifying the position of the content layer (not
419 // scrolling) won't damage the scrollbar. 421 // scrolling) won't damage the scrollbar.
420 MainThreadTaskRunner()->PostTask( 422 MainThreadTaskRunner()->PostTask(
421 FROM_HERE, base::Bind(&LayerTreeHostDamageTestScrollbarDoesDamage:: 423 FROM_HERE, base::Bind(&LayerTreeHostDamageTestScrollbarDoesDamage::
422 ModifyContentLayerPosition, 424 ModifyContentLayerPosition,
423 base::Unretained(this))); 425 base::Unretained(this)));
424 break; 426 break;
425 case 2: 427 case 2:
426 scroll_layer->ScrollBy(gfx::Vector2dF(10.f, 10.f)); 428 scroll_layer->ScrollBy(gfx::Vector2dF(10.f, 10.f));
427 host_impl->SetNeedsRedraw(); 429 host_impl->SetNeedsRedraw();
428 break; 430 break;
429 case 3: 431 case 3:
430 // We will resize the content layer, on the main thread. 432 // We will resize the content layer, on the main thread.
431 MainThreadTaskRunner()->PostTask( 433 MainThreadTaskRunner()->PostTask(
432 FROM_HERE, 434 FROM_HERE,
433 base::Bind( 435 base::Bind(
434 &LayerTreeHostDamageTestScrollbarDoesDamage::ResizeScrollLayer, 436 &LayerTreeHostDamageTestScrollbarDoesDamage::ResizeScrollLayer,
435 base::Unretained(this))); 437 base::Unretained(this)));
436 break; 438 break;
437 } 439 }
438 } 440 }
439 441
440 void ModifyContentLayerPosition() { 442 void ModifyContentLayerPosition() {
441 EXPECT_EQ(1, did_swaps_); 443 EXPECT_EQ(1, did_swaps_);
442 Layer* root = layer_tree_host()->root_layer(); 444 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 } 445 }
447 446
448 void ResizeScrollLayer() { 447 void ResizeScrollLayer() {
449 EXPECT_EQ(3, did_swaps_); 448 EXPECT_EQ(3, did_swaps_);
450 Layer* root = layer_tree_host()->root_layer(); 449 Layer* root = layer_tree_host()->root_layer();
451 Layer* scroll_clip_layer = root->child_at(0); 450 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)); 451 gfx::Size(root->bounds().width() + 60, root->bounds().height() + 100));
455 } 452 }
456 453
457 void AfterTest() override { EXPECT_EQ(4, did_swaps_); } 454 void AfterTest() override { EXPECT_EQ(4, did_swaps_); }
458 455
459 int did_swaps_; 456 int did_swaps_;
460 }; 457 };
461 458
462 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarDoesDamage); 459 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarDoesDamage);
463 460
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 default: 493 default:
497 NOTREACHED(); 494 NOTREACHED();
498 break; 495 break;
499 } 496 }
500 return draw_result; 497 return draw_result;
501 } 498 }
502 499
503 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { 500 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override {
504 ++did_swaps_; 501 ++did_swaps_;
505 EXPECT_TRUE(result); 502 EXPECT_TRUE(result);
506 LayerImpl* root = host_impl->active_tree()->root_layer(); 503 LayerImpl* scroll_layer =
507 LayerImpl* scroll_clip_layer = root->children()[0]; 504 host_impl->active_tree()->LayerById(content_layer_->id());
508 LayerImpl* scroll_layer = scroll_clip_layer->children()[0];
509 switch (did_swaps_) { 505 switch (did_swaps_) {
510 case 1: 506 case 1:
511 // Scroll on the thread. This should damage the scrollbar for the 507 // Scroll on the thread. This should damage the scrollbar for the
512 // next draw on the thread. 508 // next draw on the thread.
513 scroll_layer->ScrollBy(gfx::Vector2dF(10.f, 10.f)); 509 scroll_layer->ScrollBy(gfx::Vector2dF(10.f, 10.f));
514 host_impl->SetNeedsRedraw(); 510 host_impl->SetNeedsRedraw();
515 break; 511 break;
516 case 2: 512 case 2:
517 // Forcibly send the scroll to the main thread. 513 // Forcibly send the scroll to the main thread.
518 PostSetNeedsCommitToMainThread(); 514 PostSetNeedsCommitToMainThread();
(...skipping 10 matching lines...) Expand all
529 525
530 void AfterTest() override { EXPECT_EQ(3, did_swaps_); } 526 void AfterTest() override { EXPECT_EQ(3, did_swaps_); }
531 527
532 int did_swaps_; 528 int did_swaps_;
533 }; 529 };
534 530
535 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarCommitDoesNoDamage); 531 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarCommitDoesNoDamage);
536 532
537 } // namespace 533 } // namespace
538 } // namespace cc 534 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest_copyrequest.cc ('k') | cc/trees/layer_tree_host_unittest_occlusion.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698