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

Side by Side Diff: ui/compositor/layer_owner_unittest.cc

Issue 2458833003: Revert of [M55] Generalize layer mirroring for phantom windows (Closed)
Patch Set: Created 4 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
« no previous file with comments | « ui/compositor/layer_owner_delegate.h ('k') | ui/compositor/layer_tree_owner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/compositor/layer_owner.h" 5 #include "ui/compositor/layer_owner.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/test/null_task_runner.h" 8 #include "base/test/null_task_runner.h"
9 #include "cc/animation/animation_player.h" 9 #include "cc/animation/animation_player.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); 78 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
79 } 79 }
80 80
81 void LayerOwnerTestWithCompositor::TearDown() { 81 void LayerOwnerTestWithCompositor::TearDown() {
82 compositor_.reset(); 82 compositor_.reset();
83 ui::TerminateContextFactoryForTests(); 83 ui::TerminateContextFactoryForTests();
84 } 84 }
85 85
86 } // namespace 86 } // namespace
87 87
88 TEST(LayerOwnerTest, RecreateLayerHonorsAnimationTargets) {
89 LayerOwner owner;
90 Layer* layer = new Layer(LAYER_SOLID_COLOR);
91 layer->SetVisible(true);
92 layer->SetOpacity(1.0f);
93 layer->SetColor(SK_ColorRED);
94
95 owner.SetLayer(layer);
96
97 ScopedLayerAnimationSettings settings(layer->GetAnimator());
98 layer->SetVisible(false);
99 layer->SetOpacity(0.0f);
100 layer->SetColor(SK_ColorGREEN);
101 EXPECT_TRUE(layer->visible());
102 EXPECT_EQ(1.0f, layer->opacity());
103 EXPECT_EQ(SK_ColorRED, layer->background_color());
104
105 std::unique_ptr<Layer> old_layer(owner.RecreateLayer());
106 EXPECT_FALSE(owner.layer()->visible());
107 EXPECT_EQ(0.0f, owner.layer()->opacity());
108 EXPECT_EQ(SK_ColorGREEN, owner.layer()->background_color());
109 }
110
111 // Tests that when a LAYER_SOLID_COLOR which is not backed by a SolidColorLayer
112 // that opaqueness and color targets are maintained when the
113 // LayerOwner::RecreateLayers is called.
114 TEST(LayerOwnerTest, RecreateLayerSolidColorWithChangedCCLayerHonorsTargets) {
115 SkColor transparent = SK_ColorTRANSPARENT;
116 LayerOwner owner;
117 Layer* layer = new Layer(LAYER_SOLID_COLOR);
118 owner.SetLayer(layer);
119 layer->SetFillsBoundsOpaquely(false);
120 layer->SetColor(transparent);
121 // Changing the backing layer takes LAYER_SOLID_COLOR off of the normal layer
122 // flow, need to ensure that set values are maintained.
123 layer->SwitchCCLayerForTest();
124
125 EXPECT_FALSE(layer->fills_bounds_opaquely());
126 EXPECT_EQ(transparent, layer->background_color());
127 EXPECT_EQ(transparent, layer->GetTargetColor());
128
129 std::unique_ptr<Layer> old_layer(owner.RecreateLayer());
130 EXPECT_FALSE(owner.layer()->fills_bounds_opaquely());
131 EXPECT_EQ(transparent, owner.layer()->background_color());
132 EXPECT_EQ(transparent, owner.layer()->GetTargetColor());
133 }
134
135 TEST(LayerOwnerTest, RecreateRootLayerWithNullCompositor) {
136 LayerOwner owner;
137 Layer* layer = new Layer;
138 owner.SetLayer(layer);
139
140 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer();
141
142 EXPECT_EQ(nullptr, owner.layer()->GetCompositor());
143 EXPECT_EQ(nullptr, layer_copy->GetCompositor());
144 }
145
146 TEST(LayerOwnerTest, InvertPropertyRemainSameWithRecreateLayer) {
147 LayerOwner owner;
148 Layer* layer = new Layer;
149 owner.SetLayer(layer);
150
151 layer->SetLayerInverted(true);
152 std::unique_ptr<Layer> old_layer1 = owner.RecreateLayer();
153 EXPECT_EQ(old_layer1->layer_inverted(), owner.layer()->layer_inverted());
154
155 old_layer1->SetLayerInverted(false);
156 std::unique_ptr<Layer> old_layer2 = owner.RecreateLayer();
157 EXPECT_EQ(old_layer2->layer_inverted(), owner.layer()->layer_inverted());
158 }
159
160 TEST(LayerOwnerTest, RecreateLayerWithTransform) {
161 LayerOwner owner;
162 Layer* layer = new Layer;
163 owner.SetLayer(layer);
164
165 gfx::Transform transform;
166 transform.Scale(2, 1);
167 transform.Translate(10, 5);
168
169 layer->SetTransform(transform);
170
171 std::unique_ptr<Layer> old_layer1 = owner.RecreateLayer();
172 // Both new layer and original layer have the same transform.
173 EXPECT_EQ(transform, old_layer1->GetTargetTransform());
174 EXPECT_EQ(transform, owner.layer()->GetTargetTransform());
175
176 // But they're now separated, so changing the old layer's transform
177 // should not affect the owner's.
178 owner.layer()->SetTransform(gfx::Transform());
179 EXPECT_EQ(transform, old_layer1->GetTargetTransform());
180 std::unique_ptr<Layer> old_layer2 = owner.RecreateLayer();
181 EXPECT_TRUE(old_layer2->GetTargetTransform().IsIdentity());
182 EXPECT_TRUE(owner.layer()->GetTargetTransform().IsIdentity());
183 }
184
88 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerWithCompositor) { 185 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerWithCompositor) {
89 LayerOwner owner; 186 LayerOwner owner;
90 owner.SetLayer(base::MakeUnique<Layer>()); 187 Layer* layer = new Layer;
91 Layer* layer = owner.layer(); 188 owner.SetLayer(layer);
189
92 compositor()->SetRootLayer(layer); 190 compositor()->SetRootLayer(layer);
93 191
94 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer(); 192 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer();
95 193
96 EXPECT_EQ(compositor(), owner.layer()->GetCompositor()); 194 EXPECT_EQ(compositor(), owner.layer()->GetCompositor());
97 EXPECT_EQ(owner.layer(), compositor()->root_layer()); 195 EXPECT_EQ(owner.layer(), compositor()->root_layer());
98 EXPECT_EQ(nullptr, layer_copy->GetCompositor()); 196 EXPECT_EQ(nullptr, layer_copy->GetCompositor());
99 } 197 }
100 198
101 // Tests that recreating the root layer, while one of its children is animating, 199 // Tests that recreating the root layer, while one of its children is animating,
102 // properly updates the compositor. So that compositor is not null for observers 200 // properly updates the compositor. So that compositor is not null for observers
103 // of animations being cancelled. 201 // of animations being cancelled.
104 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerDuringAnimation) { 202 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerDuringAnimation) {
105 LayerOwner owner; 203 LayerOwner owner;
106 owner.SetLayer(base::MakeUnique<Layer>()); 204 Layer* layer = new Layer;
107 Layer* layer = owner.layer(); 205 owner.SetLayer(layer);
108 compositor()->SetRootLayer(layer); 206 compositor()->SetRootLayer(layer);
109 207
110 std::unique_ptr<Layer> child(new Layer); 208 std::unique_ptr<Layer> child(new Layer);
111 child->SetBounds(gfx::Rect(0, 0, 100, 100)); 209 child->SetBounds(gfx::Rect(0, 0, 100, 100));
112 layer->Add(child.get()); 210 layer->Add(child.get());
113 211
114 // This observer checks that the compositor of |child| is not null upon 212 // This observer checks that the compositor of |child| is not null upon
115 // animation completion. 213 // animation completion.
116 std::unique_ptr<TestLayerAnimationObserver> observer( 214 std::unique_ptr<TestLayerAnimationObserver> observer(
117 new TestLayerAnimationObserver(child.get())); 215 new TestLayerAnimationObserver(child.get()));
(...skipping 13 matching lines...) Expand all
131 } 229 }
132 230
133 // Tests that recreating a non-root layer, while one of its children is 231 // Tests that recreating a non-root layer, while one of its children is
134 // animating, properly updates the compositor. So that compositor is not null 232 // animating, properly updates the compositor. So that compositor is not null
135 // for observers of animations being cancelled. 233 // for observers of animations being cancelled.
136 TEST_F(LayerOwnerTestWithCompositor, RecreateNonRootLayerDuringAnimation) { 234 TEST_F(LayerOwnerTestWithCompositor, RecreateNonRootLayerDuringAnimation) {
137 std::unique_ptr<Layer> root_layer(new Layer); 235 std::unique_ptr<Layer> root_layer(new Layer);
138 compositor()->SetRootLayer(root_layer.get()); 236 compositor()->SetRootLayer(root_layer.get());
139 237
140 LayerOwner owner; 238 LayerOwner owner;
141 owner.SetLayer(base::MakeUnique<Layer>()); 239 Layer* layer = new Layer;
142 Layer* layer = owner.layer(); 240 owner.SetLayer(layer);
143 root_layer->Add(layer); 241 root_layer->Add(layer);
144 242
145 std::unique_ptr<Layer> child(new Layer); 243 std::unique_ptr<Layer> child(new Layer);
146 child->SetBounds(gfx::Rect(0, 0, 100, 100)); 244 child->SetBounds(gfx::Rect(0, 0, 100, 100));
147 layer->Add(child.get()); 245 layer->Add(child.get());
148 246
149 // This observer checks that the compositor of |child| is not null upon 247 // This observer checks that the compositor of |child| is not null upon
150 // animation completion. 248 // animation completion.
151 std::unique_ptr<TestLayerAnimationObserver> observer( 249 std::unique_ptr<TestLayerAnimationObserver> observer(
152 new TestLayerAnimationObserver(child.get())); 250 new TestLayerAnimationObserver(child.get()));
(...skipping 12 matching lines...) Expand all
165 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer(); 263 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer();
166 } 264 }
167 265
168 // Tests that if LayerOwner-derived class destroys layer, then 266 // Tests that if LayerOwner-derived class destroys layer, then
169 // LayerAnimator's player becomes detached from compositor timeline. 267 // LayerAnimator's player becomes detached from compositor timeline.
170 TEST_F(LayerOwnerTestWithCompositor, DetachTimelineOnAnimatorDeletion) { 268 TEST_F(LayerOwnerTestWithCompositor, DetachTimelineOnAnimatorDeletion) {
171 std::unique_ptr<Layer> root_layer(new Layer); 269 std::unique_ptr<Layer> root_layer(new Layer);
172 compositor()->SetRootLayer(root_layer.get()); 270 compositor()->SetRootLayer(root_layer.get());
173 271
174 LayerOwnerForTesting owner; 272 LayerOwnerForTesting owner;
175 owner.SetLayer(base::MakeUnique<Layer>()); 273 Layer* layer = new Layer;
176 Layer* layer = owner.layer(); 274 owner.SetLayer(layer);
177 layer->SetOpacity(0.5f); 275 layer->SetOpacity(0.5f);
178 root_layer->Add(layer); 276 root_layer->Add(layer);
179 277
180 scoped_refptr<cc::AnimationPlayer> player = 278 scoped_refptr<cc::AnimationPlayer> player =
181 layer->GetAnimator()->GetAnimationPlayerForTesting(); 279 layer->GetAnimator()->GetAnimationPlayerForTesting();
182 EXPECT_TRUE(player); 280 EXPECT_TRUE(player);
183 EXPECT_TRUE(player->animation_timeline()); 281 EXPECT_TRUE(player->animation_timeline());
184 282
185 // Destroying layer/animator must detach animator's player from timeline. 283 // Destroying layer/animator must detach animator's player from timeline.
186 owner.DestroyLayerForTesting(); 284 owner.DestroyLayerForTesting();
187 EXPECT_FALSE(player->animation_timeline()); 285 EXPECT_FALSE(player->animation_timeline());
188 } 286 }
189 287
190 // Tests that if we run threaded opacity animation on already added layer 288 // Tests that if we run threaded opacity animation on already added layer
191 // then LayerAnimator's player becomes attached to timeline. 289 // then LayerAnimator's player becomes attached to timeline.
192 TEST_F(LayerOwnerTestWithCompositor, 290 TEST_F(LayerOwnerTestWithCompositor,
193 AttachTimelineIfAnimatorCreatedAfterSetCompositor) { 291 AttachTimelineIfAnimatorCreatedAfterSetCompositor) {
194 std::unique_ptr<Layer> root_layer(new Layer); 292 std::unique_ptr<Layer> root_layer(new Layer);
195 compositor()->SetRootLayer(root_layer.get()); 293 compositor()->SetRootLayer(root_layer.get());
196 294
197 LayerOwner owner; 295 LayerOwner owner;
198 owner.SetLayer(base::MakeUnique<Layer>()); 296 Layer* layer = new Layer;
199 Layer* layer = owner.layer(); 297 owner.SetLayer(layer);
200 root_layer->Add(layer); 298 root_layer->Add(layer);
201 299
202 layer->SetOpacity(0.5f); 300 layer->SetOpacity(0.5f);
203 301
204 scoped_refptr<cc::AnimationPlayer> player = 302 scoped_refptr<cc::AnimationPlayer> player =
205 layer->GetAnimator()->GetAnimationPlayerForTesting(); 303 layer->GetAnimator()->GetAnimationPlayerForTesting();
206 EXPECT_TRUE(player); 304 EXPECT_TRUE(player);
207 EXPECT_TRUE(player->animation_timeline()); 305 EXPECT_TRUE(player->animation_timeline());
208 } 306 }
209 307
210 } // namespace ui 308 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer_owner_delegate.h ('k') | ui/compositor/layer_tree_owner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698