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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/compositor/layer_unittest.cc
diff --git a/ui/gfx/compositor/layer_unittest.cc b/ui/gfx/compositor/layer_unittest.cc
index 69999a3431b11497e219d207c73156caa336ceda..b1abea70fd047b127dbc54bc2a5b0a19418b6a78 100644
--- a/ui/gfx/compositor/layer_unittest.cc
+++ b/ui/gfx/compositor/layer_unittest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <string>
Ian Vollick 2011/10/22 01:06:03 Is this used?
+
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
@@ -535,6 +537,111 @@ TEST_F(LayerWithNullDelegateTest, LargestHole) {
EXPECT_EQ(gfx::Rect(75, 75, 200, 200), parent->hole_rect());
}
+// Verifies that the largest hole in the draw order is picked
+TEST_F(LayerWithNullDelegateTest, HoleGeneratedFromLeaf) {
+ // Layer tree looks like:
+ // node 1
+ // |_ node 11
+ // |_ node 111
+ // |_ node 12
+ // |_ node 121
+
+ scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
+
+ scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
+ node1->Add(node11.get());
+
+ scoped_ptr<Layer> node12(CreateTextureLayer(gfx::Rect(75, 75, 200, 200)));
+ node1->Add(node12.get());
+
+ scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
+ node11->Add(node111.get());
+
+ scoped_ptr<Layer> node121(CreateTextureLayer(gfx::Rect(10, 10, 190, 190)));
+ node12->Add(node121.get());
+
+ EXPECT_EQ(gfx::Rect(75, 75, 200, 200), node1->hole_rect());
+ EXPECT_EQ(gfx::Rect(35, 35, 65, 65), node11->hole_rect());
+ EXPECT_EQ(gfx::Rect(10, 10, 190, 190), node12->hole_rect());
+}
+
+// Verifies that a layer can only punch a hole if the opacity of the layer
+// punching the hole and the layer being punched is the same.
+TEST_F(LayerWithNullDelegateTest, HoleWithRelativeOpacity) {
+ // Layer tree looks like:
+ // node 1
+ // |_ node 11
+ // |_ node 111
+
+ scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
+
+ scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
+ node1->Add(node11.get());
+
+ scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
+ node11->Add(node111.get());
+
+ EXPECT_EQ(gfx::Rect(50, 50, 100, 100), node1->hole_rect());
+ EXPECT_EQ(gfx::Rect(10, 10, 20, 20), node11->hole_rect());
+
+ // Combined opacity node11 = combined opacity node111
+ node11->SetOpacity(0.5f);
+ EXPECT_TRUE(node1->hole_rect().IsEmpty());
+ EXPECT_EQ(gfx::Rect(10, 10, 20, 20), node11->hole_rect());
+
+ // Combined opacity of node11 != combind opacity node111.
+ node111->SetOpacity(0.5f);
+ EXPECT_TRUE(node1->hole_rect().IsEmpty());
+ EXPECT_TRUE(node11->hole_rect().IsEmpty());
+}
+
+// Verifies that a non visible layer or any of its children is not a hole.
+TEST_F(LayerWithNullDelegateTest, NonVisibleLayerCannotBeHole) {
+ // Layer tree looks like:
+ // node 1
+ // |_ node 11
+ // |_ node 111
+
+ scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
+
+ scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
+ node1->Add(node11.get());
+
+ scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
+ node11->Add(node111.get());
+
+ EXPECT_EQ(gfx::Rect(50, 50, 100, 100), node1->hole_rect());
+ EXPECT_EQ(gfx::Rect(10, 10, 20, 20), node11->hole_rect());
+
+ node11->SetVisible(false);
+ EXPECT_TRUE(node1->hole_rect().IsEmpty());
+ EXPECT_TRUE(node11->hole_rect().IsEmpty());
+}
+
+// Verifies that a layer which doesn't fill its bounds opaquely cannot punch a
+// hole. However its children should still be able to punch a hole.
+TEST_F(LayerWithNullDelegateTest, LayerNotFillingBoundsOpaquelyCannotBeHole) {
+ // Layer tree looks like:
+ // node 1
+ // |_ node 11
+ // |_ node 111
+
+ scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
+
+ scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
+ node1->Add(node11.get());
+
+ scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
+ node11->Add(node111.get());
+
+ EXPECT_EQ(gfx::Rect(50, 50, 100, 100), node1->hole_rect());
+ EXPECT_EQ(gfx::Rect(10, 10, 20, 20), node11->hole_rect());
+
+ node11->SetFillsBoundsOpaquely(false);
+ EXPECT_EQ(gfx::Rect(60, 60, 20, 20), node1->hole_rect());
+ EXPECT_TRUE(node11->hole_rect().IsEmpty());
+}
+
// Verifies that the hole is with respect to the local bounds of its parent.
TEST_F(LayerWithNullDelegateTest, HoleLocalBounds) {
scoped_ptr<Layer> parent(CreateTextureRootLayer(
@@ -589,6 +696,55 @@ TEST_F(LayerWithNullDelegateTest, HoleWithNinetyDegreeTransforms) {
}
}
+// Verifies that a layer which doesn't have a texture cannot punch a
+// hole. However its children should still be able to punch a hole.
+TEST_F(LayerWithNullDelegateTest, HoleWithRelativeNinetyDegreeTransforms) {
+ // Layer tree looks like:
+ // node 1
+ // |_ node 11
+ // |_ node 12
+
+ scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
+
+ scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 50, 50)));
+ node1->Add(node11.get());
+
+ scoped_ptr<Layer> node12(CreateTextureLayer(gfx::Rect(50, 50, 50, 50)));
+ node1->Add(node12.get());
+
+ EXPECT_EQ(gfx::Rect(0, 0, 50, 50), node11->hole_rect());
+ EXPECT_TRUE(node12->hole_rect().IsEmpty());
+
+ ui::Transform t1;
+ // Need to rotate in local coordinates.
+ t1.SetTranslate(-25, -25);
+ t1.ConcatRotate(45.0f);
+ t1.ConcatTranslate(25, 25);
+ node11->SetTransform(t1);
+
+ EXPECT_TRUE(node12->hole_rect().IsEmpty());
+ EXPECT_TRUE(node11->hole_rect().IsEmpty());
+
+ ui::Transform t2;
+ // Need to rotate in local coordinates.
+ t2.SetTranslate(-25, -25);
+ t2.ConcatRotate(-135.0f);
+ t2.ConcatTranslate(25, 25);
+ node12->SetTransform(t2);
+
+ // Do translation of target rect in order to account for inprecision of
+ // using floating point matrices vs integer rects.
+ ui::Transform t3;
+ gfx::Rect target_rect = gfx::Rect(node11->bounds().size());
+ t3.ConcatTransform(t2);
+ t1.Invert();
+ t3.ConcatTransform(t1);
+ t3.TransformRect(&target_rect);
+
+ EXPECT_TRUE(node12->hole_rect().IsEmpty());
+ EXPECT_EQ(target_rect, node11->hole_rect());
+}
+
// Create this hierarchy:
// L1 (no texture)
// +- L11 (texture)
« 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