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

Side by Side Diff: ui/gfx/compositor/layer_unittest.cc

Issue 8515006: A fix for LayerNoTextureSetFillsBoundsOpaquely. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable all the tests that don't apply to the webkit compositor. Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/compositor/layer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/canvas_skia.h" 9 #include "ui/gfx/canvas_skia.h"
10 #include "ui/gfx/compositor/compositor_observer.h" 10 #include "ui/gfx/compositor/compositor_observer.h"
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 layer->SetBounds(bounds); 458 layer->SetBounds(bounds);
459 return layer; 459 return layer;
460 } 460 }
461 461
462 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) OVERRIDE { 462 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) OVERRIDE {
463 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); 463 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE);
464 layer->SetBounds(bounds); 464 layer->SetBounds(bounds);
465 return layer; 465 return layer;
466 } 466 }
467 467
468 void RunPendingMessages() {
469 MessageLoopForUI::current()->RunAllPending();
470 }
471
468 private: 472 private:
469 scoped_ptr<NullLayerDelegate> default_layer_delegate_; 473 scoped_ptr<NullLayerDelegate> default_layer_delegate_;
470 474
471 DISALLOW_COPY_AND_ASSIGN(LayerWithNullDelegateTest); 475 DISALLOW_COPY_AND_ASSIGN(LayerWithNullDelegateTest);
472 }; 476 };
473 477
478 // With the webkit compositor, we don't explicitly textures for layers, making
479 // tests that check that we do fail.
480 #if defined(USE_WEBKIT_COMPOSITOR)
481 #define NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(X) DISABLED_ ## X
482 #else
483 #define NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(X) X
484 #endif
485
474 // Verifies that a layer which is set never to have a texture does not 486 // Verifies that a layer which is set never to have a texture does not
475 // get a texture when SetFillsBoundsOpaquely is called. 487 // get a texture when SetFillsBoundsOpaquely is called.
476 TEST_F(LayerWithNullDelegateTest, LayerNoTextureSetFillsBoundsOpaquely) { 488 TEST_F(LayerWithNullDelegateTest,
489 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(
490 LayerNoTextureSetFillsBoundsOpaquely)) {
477 scoped_ptr<Layer> parent(CreateNoTextureLayer(gfx::Rect(0, 0, 400, 400))); 491 scoped_ptr<Layer> parent(CreateNoTextureLayer(gfx::Rect(0, 0, 400, 400)));
478 scoped_ptr<Layer> child(CreateNoTextureLayer(gfx::Rect(50, 50, 100, 100))); 492 scoped_ptr<Layer> child(CreateNoTextureLayer(gfx::Rect(50, 50, 100, 100)));
479 parent->Add(child.get()); 493 parent->Add(child.get());
480 494
481 compositor()->SetRootLayer(parent.get()); 495 compositor()->SetRootLayer(parent.get());
496 parent->SetFillsBoundsOpaquely(true);
497 child->SetFillsBoundsOpaquely(true);
482 Draw(); 498 Draw();
499 RunPendingMessages();
500 EXPECT_TRUE(child->texture() == NULL);
501 EXPECT_TRUE(parent->texture() == NULL);
502
503 parent->SetFillsBoundsOpaquely(false);
504 child->SetFillsBoundsOpaquely(false);
505 Draw();
506 RunPendingMessages();
483 EXPECT_TRUE(child->texture() == NULL); 507 EXPECT_TRUE(child->texture() == NULL);
484 EXPECT_TRUE(parent->texture() == NULL); 508 EXPECT_TRUE(parent->texture() == NULL);
485 } 509 }
486 510
487 // With the webkit compositor, we don't explicitly textures for layers, making
488 // tests that check that we do fail.
489 #if defined(USE_WEBKIT_COMPOSITOR)
490 #define WEBKIT_COMPOSITOR_FAILS(X) FAILS_ ## X
491 #else
492 #define WEBKIT_COMPOSITOR_FAILS(X) X
493 #endif
494
495 // Verifies that a layer does not have a texture when the hole is the size 511 // Verifies that a layer does not have a texture when the hole is the size
496 // of the parent layer. 512 // of the parent layer.
497 TEST_F(LayerWithNullDelegateTest, 513 TEST_F(LayerWithNullDelegateTest,
498 WEBKIT_COMPOSITOR_FAILS(LayerNoTextureHoleSizeOfLayer)) { 514 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(LayerNoTextureHoleSizeOfLayer)) {
499 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400))); 515 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
500 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100))); 516 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
501 parent->Add(child.get()); 517 parent->Add(child.get());
502 518
503 Draw(); 519 Draw();
504 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), parent->hole_rect()); 520 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), parent->hole_rect());
505 EXPECT_TRUE(parent->texture() != NULL); 521 EXPECT_TRUE(parent->texture() != NULL);
506 522
507 child->SetBounds(gfx::Rect(0, 0, 400, 400)); 523 child->SetBounds(gfx::Rect(0, 0, 400, 400));
508 Draw(); 524 Draw();
509 EXPECT_TRUE(parent->texture() == NULL); 525 EXPECT_TRUE(parent->texture() == NULL);
510 } 526 }
511 527
512 // Verifies that a layer which has opacity == 0 does not have a texture. 528 // Verifies that a layer which has opacity == 0 does not have a texture.
513 TEST_F(LayerWithNullDelegateTest, 529 TEST_F(LayerWithNullDelegateTest,
514 WEBKIT_COMPOSITOR_FAILS(LayerNoTextureTransparent)) { 530 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(LayerNoTextureTransparent)) {
515 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400))); 531 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
516 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100))); 532 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
517 parent->Add(child.get()); 533 parent->Add(child.get());
518 534
519 parent->SetOpacity(0.0f); 535 parent->SetOpacity(0.0f);
520 child->SetOpacity(0.0f); 536 child->SetOpacity(0.0f);
521 Draw(); 537 Draw();
522 EXPECT_TRUE(parent->texture() == NULL); 538 EXPECT_TRUE(parent->texture() == NULL);
523 EXPECT_TRUE(child->texture() == NULL); 539 EXPECT_TRUE(child->texture() == NULL);
524 540
525 parent->SetOpacity(1.0f); 541 parent->SetOpacity(1.0f);
526 Draw(); 542 Draw();
527 EXPECT_TRUE(parent->texture() != NULL); 543 EXPECT_TRUE(parent->texture() != NULL);
528 EXPECT_TRUE(child->texture() == NULL); 544 EXPECT_TRUE(child->texture() == NULL);
529 545
530 child->SetOpacity(1.0f); 546 child->SetOpacity(1.0f);
531 Draw(); 547 Draw();
532 EXPECT_TRUE(parent->texture() != NULL); 548 EXPECT_TRUE(parent->texture() != NULL);
533 EXPECT_TRUE(child->texture() != NULL); 549 EXPECT_TRUE(child->texture() != NULL);
534 } 550 }
535 551
536 // Verifies that no texture is created for a layer with empty bounds. 552 // Verifies that no texture is created for a layer with empty bounds.
537 TEST_F(LayerWithNullDelegateTest, 553 TEST_F(LayerWithNullDelegateTest,
538 WEBKIT_COMPOSITOR_FAILS(LayerTextureNonEmptySchedulePaint)) { 554 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(LayerTextureNonEmptySchedulePaint)) {
539 scoped_ptr<Layer> layer(CreateTextureRootLayer(gfx::Rect(0, 0, 0, 0))); 555 scoped_ptr<Layer> layer(CreateTextureRootLayer(gfx::Rect(0, 0, 0, 0)));
540 Draw(); 556 Draw();
541 EXPECT_TRUE(layer->texture() == NULL); 557 EXPECT_TRUE(layer->texture() == NULL);
542 558
543 layer->SetBounds(gfx::Rect(0, 0, 400, 400)); 559 layer->SetBounds(gfx::Rect(0, 0, 400, 400));
544 Draw(); 560 Draw();
545 EXPECT_TRUE(layer->texture() != NULL); 561 EXPECT_TRUE(layer->texture() != NULL);
546 } 562 }
547 563
548 // Verifies that when there are many potential holes, the largest one is picked. 564 // Verifies that when there are many potential holes, the largest one is picked.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 EXPECT_EQ(target_rect, parent->hole_rect()); 629 EXPECT_EQ(target_rect, parent->hole_rect());
614 } 630 }
615 } 631 }
616 632
617 // Create this hierarchy: 633 // Create this hierarchy:
618 // L1 (no texture) 634 // L1 (no texture)
619 // +- L11 (texture) 635 // +- L11 (texture)
620 // +- L12 (no texture) (added after L1 is already set as root-layer) 636 // +- L12 (no texture) (added after L1 is already set as root-layer)
621 // +- L121 (texture) 637 // +- L121 (texture)
622 // +- L122 (texture) 638 // +- L122 (texture)
623 TEST_F(LayerWithNullDelegateTest, WEBKIT_COMPOSITOR_FAILS(NoCompositor)) { 639 TEST_F(LayerWithNullDelegateTest,
640 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(NoCompositor)) {
624 scoped_ptr<Layer> l1(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE)); 641 scoped_ptr<Layer> l1(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE));
625 scoped_ptr<Layer> l11(CreateLayer(Layer::LAYER_HAS_TEXTURE)); 642 scoped_ptr<Layer> l11(CreateLayer(Layer::LAYER_HAS_TEXTURE));
626 scoped_ptr<Layer> l12(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE)); 643 scoped_ptr<Layer> l12(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE));
627 scoped_ptr<Layer> l121(CreateLayer(Layer::LAYER_HAS_TEXTURE)); 644 scoped_ptr<Layer> l121(CreateLayer(Layer::LAYER_HAS_TEXTURE));
628 scoped_ptr<Layer> l122(CreateLayer(Layer::LAYER_HAS_TEXTURE)); 645 scoped_ptr<Layer> l122(CreateLayer(Layer::LAYER_HAS_TEXTURE));
629 646
630 EXPECT_EQ(NULL, l1->texture()); 647 EXPECT_EQ(NULL, l1->texture());
631 EXPECT_EQ(NULL, l11->texture()); 648 EXPECT_EQ(NULL, l11->texture());
632 EXPECT_EQ(NULL, l12->texture()); 649 EXPECT_EQ(NULL, l12->texture());
633 EXPECT_EQ(NULL, l121->texture()); 650 EXPECT_EQ(NULL, l121->texture());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 EXPECT_TRUE(l2->IsDrawn()); 739 EXPECT_TRUE(l2->IsDrawn());
723 EXPECT_FALSE(l3->IsDrawn()); 740 EXPECT_FALSE(l3->IsDrawn());
724 #if defined(USE_WEBKIT_COMPOSITOR) 741 #if defined(USE_WEBKIT_COMPOSITOR)
725 EXPECT_EQ(1.f, l1->web_layer().opacity()); 742 EXPECT_EQ(1.f, l1->web_layer().opacity());
726 #endif 743 #endif
727 } 744 }
728 745
729 // Checks that the invalid rect assumes correct values when setting bounds. 746 // Checks that the invalid rect assumes correct values when setting bounds.
730 // TODO(vollick): for USE_WEBKIT_COMPOSITOR, use WebKit's dirty rect. 747 // TODO(vollick): for USE_WEBKIT_COMPOSITOR, use WebKit's dirty rect.
731 TEST_F(LayerWithNullDelegateTest, 748 TEST_F(LayerWithNullDelegateTest,
732 WEBKIT_COMPOSITOR_FAILS(SetBoundsInvalidRect)) { 749 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(SetBoundsInvalidRect)) {
733 scoped_ptr<Layer> l1(CreateTextureLayer(gfx::Rect(0, 0, 200, 200))); 750 scoped_ptr<Layer> l1(CreateTextureLayer(gfx::Rect(0, 0, 200, 200)));
734 compositor()->SetRootLayer(l1.get()); 751 compositor()->SetRootLayer(l1.get());
735 752
736 // After a draw the invalid rect should be empty. 753 // After a draw the invalid rect should be empty.
737 Draw(); 754 Draw();
738 EXPECT_TRUE(l1->invalid_rect().IsEmpty()); 755 EXPECT_TRUE(l1->invalid_rect().IsEmpty());
739 756
740 // After a move the invalid rect should be empty. 757 // After a move the invalid rect should be empty.
741 l1->SetBounds(gfx::Rect(5, 5, 200, 200)); 758 l1->SetBounds(gfx::Rect(5, 5, 200, 200));
742 EXPECT_TRUE(l1->invalid_rect().IsEmpty()); 759 EXPECT_TRUE(l1->invalid_rect().IsEmpty());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 SkAutoLockPixels lock(bitmap); 798 SkAutoLockPixels lock(bitmap);
782 bool is_all_red = true; 799 bool is_all_red = true;
783 for (int x = 0; is_all_red && x < 500; x++) 800 for (int x = 0; is_all_red && x < 500; x++)
784 for (int y = 0; is_all_red && y < 500; y++) 801 for (int y = 0; is_all_red && y < 500; y++)
785 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED); 802 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED);
786 803
787 EXPECT_TRUE(is_all_red); 804 EXPECT_TRUE(is_all_red);
788 } 805 }
789 806
790 } // namespace ui 807 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/layer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698