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

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

Issue 8368013: Improve Aura overdraw by changing hole calculation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nicer diff Created 9 years, 2 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 | Annotate | Revision Log
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 <string>
Ian Vollick 2011/10/22 01:06:03 Is this used?
6
5 #include "base/basictypes.h" 7 #include "base/basictypes.h"
6 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
7 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/canvas_skia.h" 11 #include "ui/gfx/canvas_skia.h"
10 #include "ui/gfx/compositor/compositor_observer.h" 12 #include "ui/gfx/compositor/compositor_observer.h"
11 #include "ui/gfx/compositor/layer.h" 13 #include "ui/gfx/compositor/layer.h"
12 #include "ui/gfx/compositor/test_compositor.h" 14 #include "ui/gfx/compositor/test_compositor.h"
13 #include "ui/gfx/compositor/test_compositor_host.h" 15 #include "ui/gfx/compositor/test_compositor_host.h"
14 16
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 530
529 scoped_ptr<Layer> child1(CreateTextureLayer(gfx::Rect(50, 50, 100, 100))); 531 scoped_ptr<Layer> child1(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
530 parent->Add(child1.get()); 532 parent->Add(child1.get());
531 533
532 scoped_ptr<Layer> child2(CreateTextureLayer(gfx::Rect(75, 75, 200, 200))); 534 scoped_ptr<Layer> child2(CreateTextureLayer(gfx::Rect(75, 75, 200, 200)));
533 parent->Add(child2.get()); 535 parent->Add(child2.get());
534 536
535 EXPECT_EQ(gfx::Rect(75, 75, 200, 200), parent->hole_rect()); 537 EXPECT_EQ(gfx::Rect(75, 75, 200, 200), parent->hole_rect());
536 } 538 }
537 539
540 // Verifies that the largest hole in the draw order is picked
541 TEST_F(LayerWithNullDelegateTest, HoleGeneratedFromLeaf) {
542 // Layer tree looks like:
543 // node 1
544 // |_ node 11
545 // |_ node 111
546 // |_ node 12
547 // |_ node 121
548
549 scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
550
551 scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
552 node1->Add(node11.get());
553
554 scoped_ptr<Layer> node12(CreateTextureLayer(gfx::Rect(75, 75, 200, 200)));
555 node1->Add(node12.get());
556
557 scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
558 node11->Add(node111.get());
559
560 scoped_ptr<Layer> node121(CreateTextureLayer(gfx::Rect(10, 10, 190, 190)));
561 node12->Add(node121.get());
562
563 EXPECT_EQ(gfx::Rect(75, 75, 200, 200), node1->hole_rect());
564 EXPECT_EQ(gfx::Rect(35, 35, 65, 65), node11->hole_rect());
565 EXPECT_EQ(gfx::Rect(10, 10, 190, 190), node12->hole_rect());
566 }
567
568 // Verifies that a layer can only punch a hole if the opacity of the layer
569 // punching the hole and the layer being punched is the same.
570 TEST_F(LayerWithNullDelegateTest, HoleWithRelativeOpacity) {
571 // Layer tree looks like:
572 // node 1
573 // |_ node 11
574 // |_ node 111
575
576 scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
577
578 scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
579 node1->Add(node11.get());
580
581 scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
582 node11->Add(node111.get());
583
584 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), node1->hole_rect());
585 EXPECT_EQ(gfx::Rect(10, 10, 20, 20), node11->hole_rect());
586
587 // Combined opacity node11 = combined opacity node111
588 node11->SetOpacity(0.5f);
589 EXPECT_TRUE(node1->hole_rect().IsEmpty());
590 EXPECT_EQ(gfx::Rect(10, 10, 20, 20), node11->hole_rect());
591
592 // Combined opacity of node11 != combind opacity node111.
593 node111->SetOpacity(0.5f);
594 EXPECT_TRUE(node1->hole_rect().IsEmpty());
595 EXPECT_TRUE(node11->hole_rect().IsEmpty());
596 }
597
598 // Verifies that a non visible layer or any of its children is not a hole.
599 TEST_F(LayerWithNullDelegateTest, NonVisibleLayerCannotBeHole) {
600 // Layer tree looks like:
601 // node 1
602 // |_ node 11
603 // |_ node 111
604
605 scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
606
607 scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
608 node1->Add(node11.get());
609
610 scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
611 node11->Add(node111.get());
612
613 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), node1->hole_rect());
614 EXPECT_EQ(gfx::Rect(10, 10, 20, 20), node11->hole_rect());
615
616 node11->SetVisible(false);
617 EXPECT_TRUE(node1->hole_rect().IsEmpty());
618 EXPECT_TRUE(node11->hole_rect().IsEmpty());
619 }
620
621 // Verifies that a layer which doesn't fill its bounds opaquely cannot punch a
622 // hole. However its children should still be able to punch a hole.
623 TEST_F(LayerWithNullDelegateTest, LayerNotFillingBoundsOpaquelyCannotBeHole) {
624 // Layer tree looks like:
625 // node 1
626 // |_ node 11
627 // |_ node 111
628
629 scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
630
631 scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
632 node1->Add(node11.get());
633
634 scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
635 node11->Add(node111.get());
636
637 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), node1->hole_rect());
638 EXPECT_EQ(gfx::Rect(10, 10, 20, 20), node11->hole_rect());
639
640 node11->SetFillsBoundsOpaquely(false);
641 EXPECT_EQ(gfx::Rect(60, 60, 20, 20), node1->hole_rect());
642 EXPECT_TRUE(node11->hole_rect().IsEmpty());
643 }
644
538 // Verifies that the hole is with respect to the local bounds of its parent. 645 // Verifies that the hole is with respect to the local bounds of its parent.
539 TEST_F(LayerWithNullDelegateTest, HoleLocalBounds) { 646 TEST_F(LayerWithNullDelegateTest, HoleLocalBounds) {
540 scoped_ptr<Layer> parent(CreateTextureRootLayer( 647 scoped_ptr<Layer> parent(CreateTextureRootLayer(
541 gfx::Rect(100, 100, 150, 150))); 648 gfx::Rect(100, 100, 150, 150)));
542 649
543 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100))); 650 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
544 parent->Add(child.get()); 651 parent->Add(child.get());
545 652
546 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), parent->hole_rect()); 653 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), parent->hole_rect());
547 } 654 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 child->SetTransform(t); 689 child->SetTransform(t);
583 690
584 gfx::Rect target_rect(child->bounds().size()); 691 gfx::Rect target_rect(child->bounds().size());
585 t.ConcatTranslate(child->bounds().x(), child->bounds().y()); 692 t.ConcatTranslate(child->bounds().x(), child->bounds().y());
586 t.TransformRect(&target_rect); 693 t.TransformRect(&target_rect);
587 694
588 EXPECT_EQ(target_rect, parent->hole_rect()); 695 EXPECT_EQ(target_rect, parent->hole_rect());
589 } 696 }
590 } 697 }
591 698
699 // Verifies that a layer which doesn't have a texture cannot punch a
700 // hole. However its children should still be able to punch a hole.
701 TEST_F(LayerWithNullDelegateTest, HoleWithRelativeNinetyDegreeTransforms) {
702 // Layer tree looks like:
703 // node 1
704 // |_ node 11
705 // |_ node 12
706
707 scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
708
709 scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 50, 50)));
710 node1->Add(node11.get());
711
712 scoped_ptr<Layer> node12(CreateTextureLayer(gfx::Rect(50, 50, 50, 50)));
713 node1->Add(node12.get());
714
715 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), node11->hole_rect());
716 EXPECT_TRUE(node12->hole_rect().IsEmpty());
717
718 ui::Transform t1;
719 // Need to rotate in local coordinates.
720 t1.SetTranslate(-25, -25);
721 t1.ConcatRotate(45.0f);
722 t1.ConcatTranslate(25, 25);
723 node11->SetTransform(t1);
724
725 EXPECT_TRUE(node12->hole_rect().IsEmpty());
726 EXPECT_TRUE(node11->hole_rect().IsEmpty());
727
728 ui::Transform t2;
729 // Need to rotate in local coordinates.
730 t2.SetTranslate(-25, -25);
731 t2.ConcatRotate(-135.0f);
732 t2.ConcatTranslate(25, 25);
733 node12->SetTransform(t2);
734
735 // Do translation of target rect in order to account for inprecision of
736 // using floating point matrices vs integer rects.
737 ui::Transform t3;
738 gfx::Rect target_rect = gfx::Rect(node11->bounds().size());
739 t3.ConcatTransform(t2);
740 t1.Invert();
741 t3.ConcatTransform(t1);
742 t3.TransformRect(&target_rect);
743
744 EXPECT_TRUE(node12->hole_rect().IsEmpty());
745 EXPECT_EQ(target_rect, node11->hole_rect());
746 }
747
592 // Create this hierarchy: 748 // Create this hierarchy:
593 // L1 (no texture) 749 // L1 (no texture)
594 // +- L11 (texture) 750 // +- L11 (texture)
595 // +- L12 (no texture) (added after L1 is already set as root-layer) 751 // +- L12 (no texture) (added after L1 is already set as root-layer)
596 // +- L121 (texture) 752 // +- L121 (texture)
597 // +- L122 (texture) 753 // +- L122 (texture)
598 TEST_F(LayerWithNullDelegateTest, NoCompositor) { 754 TEST_F(LayerWithNullDelegateTest, NoCompositor) {
599 scoped_ptr<Layer> l1(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE)); 755 scoped_ptr<Layer> l1(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE));
600 scoped_ptr<Layer> l11(CreateLayer(Layer::LAYER_HAS_TEXTURE)); 756 scoped_ptr<Layer> l11(CreateLayer(Layer::LAYER_HAS_TEXTURE));
601 scoped_ptr<Layer> l12(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE)); 757 scoped_ptr<Layer> l12(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE));
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 EXPECT_FALSE(l2->IsDrawn()); 837 EXPECT_FALSE(l2->IsDrawn());
682 EXPECT_FALSE(l3->IsDrawn()); 838 EXPECT_FALSE(l3->IsDrawn());
683 839
684 l1->SetVisible(true); 840 l1->SetVisible(true);
685 EXPECT_TRUE(l1->IsDrawn()); 841 EXPECT_TRUE(l1->IsDrawn());
686 EXPECT_TRUE(l2->IsDrawn()); 842 EXPECT_TRUE(l2->IsDrawn());
687 EXPECT_FALSE(l3->IsDrawn()); 843 EXPECT_FALSE(l3->IsDrawn());
688 } 844 }
689 845
690 } // namespace ui 846 } // namespace ui
OLDNEW
« ui/gfx/compositor/layer.cc ('K') | « ui/gfx/compositor/layer.cc ('k') | ui/gfx/transform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698