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

Unified Diff: ui/compositor/layer_unittest.cc

Issue 1588093004: Compute if a layer is drawn without LayerTree hierarchy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
« cc/trees/property_tree_builder.cc ('K') | « ui/compositor/layer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/compositor/layer_unittest.cc
diff --git a/ui/compositor/layer_unittest.cc b/ui/compositor/layer_unittest.cc
index 70581b6d08ebf5a0e9991d429628aa62a3319b91..df81764b49ea7817e82cde79a1898f958ec61b96 100644
--- a/ui/compositor/layer_unittest.cc
+++ b/ui/compositor/layer_unittest.cc
@@ -727,7 +727,7 @@ TEST_F(LayerWithNullDelegateTest, SwitchLayerPreservesCCLayerState) {
EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent());
EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque());
EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface());
- EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree());
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f);
EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds());
cc::Layer* before_layer = l1->cc_layer_for_testing();
@@ -744,7 +744,7 @@ TEST_F(LayerWithNullDelegateTest, SwitchLayerPreservesCCLayerState) {
EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent());
EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque());
EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface());
- EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree());
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f);
EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds());
EXPECT_FALSE(callback1_run);
@@ -762,7 +762,7 @@ TEST_F(LayerWithNullDelegateTest, SwitchLayerPreservesCCLayerState) {
EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent());
EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque());
EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface());
- EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree());
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f);
EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds());
EXPECT_TRUE(callback2_run);
@@ -781,7 +781,7 @@ TEST_F(LayerWithNullDelegateTest, SwitchLayerPreservesCCLayerState) {
EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent());
EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque());
EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface());
- EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree());
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f);
EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds());
EXPECT_FALSE(callback3_run);
@@ -806,9 +806,9 @@ TEST_F(LayerWithNullDelegateTest, Visibility) {
EXPECT_TRUE(l1->IsDrawn());
EXPECT_TRUE(l2->IsDrawn());
EXPECT_TRUE(l3->IsDrawn());
- EXPECT_FALSE(l1->cc_layer_for_testing()->hide_layer_and_subtree());
- EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree());
- EXPECT_FALSE(l3->cc_layer_for_testing()->hide_layer_and_subtree());
+ EXPECT_NE(l1->cc_layer_for_testing()->opacity(), 0.f);
+ EXPECT_NE(l2->cc_layer_for_testing()->opacity(), 0.f);
+ EXPECT_NE(l3->cc_layer_for_testing()->opacity(), 0.f);
compositor()->SetRootLayer(l1.get());
@@ -818,25 +818,62 @@ TEST_F(LayerWithNullDelegateTest, Visibility) {
EXPECT_FALSE(l1->IsDrawn());
EXPECT_FALSE(l2->IsDrawn());
EXPECT_FALSE(l3->IsDrawn());
- EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree());
- EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree());
- EXPECT_FALSE(l3->cc_layer_for_testing()->hide_layer_and_subtree());
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f);
+ EXPECT_NE(l2->cc_layer_for_testing()->opacity(), 0.f);
+ EXPECT_NE(l3->cc_layer_for_testing()->opacity(), 0.f);
l3->SetVisible(false);
EXPECT_FALSE(l1->IsDrawn());
EXPECT_FALSE(l2->IsDrawn());
EXPECT_FALSE(l3->IsDrawn());
- EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree());
- EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree());
- EXPECT_TRUE(l3->cc_layer_for_testing()->hide_layer_and_subtree());
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f);
+ EXPECT_NE(l2->cc_layer_for_testing()->opacity(), 0.f);
+ EXPECT_EQ(l3->cc_layer_for_testing()->opacity(), 0.f);
l1->SetVisible(true);
EXPECT_TRUE(l1->IsDrawn());
EXPECT_TRUE(l2->IsDrawn());
EXPECT_FALSE(l3->IsDrawn());
- EXPECT_FALSE(l1->cc_layer_for_testing()->hide_layer_and_subtree());
- EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree());
- EXPECT_TRUE(l3->cc_layer_for_testing()->hide_layer_and_subtree());
+ EXPECT_NE(l1->cc_layer_for_testing()->opacity(), 0.f);
+ EXPECT_NE(l2->cc_layer_for_testing()->opacity(), 0.f);
+ EXPECT_EQ(l3->cc_layer_for_testing()->opacity(), 0.f);
+}
+
+TEST_F(LayerWithNullDelegateTest, Opacity) {
weiliangc 2016/01/15 19:30:24 Preferably with more descriptive test name.
jaydasika 2016/01/19 20:02:49 Done.
+ scoped_ptr<Layer> l1(new Layer(LAYER_TEXTURED));
+
+ NullLayerDelegate delegate;
+ l1->set_delegate(&delegate);
+
+ // Initially, the layer should be fully opaque.
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 1.f);
+
+ compositor()->SetRootLayer(l1.get());
+
+ Draw();
+
+ // When a layer is invisble, the corresponding cc_layer should be completely
+ // transparent, but the ui layer should store the original opacity of cc
+ // layer.
+ l1->SetVisible(false);
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f);
+ EXPECT_EQ(l1->opacity(), 1.f);
+
+ // Any changes to opacity when the layer is invisble is cached by the ui
+ // layer and set on the corresponding cc layer only when it becomes visible.
+ l1->SetOpacity(0.5f);
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f);
+ EXPECT_EQ(l1->opacity(), 0.5f);
+ l1->SetVisible(true);
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.5f);
+
+ // The original opacity should be restored when invisible layer becomes
+ // visible.
+ l1->SetOpacity(0.2f);
+ l1->SetVisible(false);
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f);
+ l1->SetVisible(true);
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.2f);
}
// Checks that stacking-related methods behave as advertised.
« cc/trees/property_tree_builder.cc ('K') | « ui/compositor/layer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698