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

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

Issue 2383263002: Generalize layer mirroring for phantom windows (Closed)
Patch Set: Rebase 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
185 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerWithCompositor) { 88 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerWithCompositor) {
186 LayerOwner owner; 89 LayerOwner owner;
187 Layer* layer = new Layer; 90 owner.SetLayer(base::MakeUnique<Layer>());
188 owner.SetLayer(layer); 91 Layer* layer = owner.layer();
189
190 compositor()->SetRootLayer(layer); 92 compositor()->SetRootLayer(layer);
191 93
192 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer(); 94 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer();
193 95
194 EXPECT_EQ(compositor(), owner.layer()->GetCompositor()); 96 EXPECT_EQ(compositor(), owner.layer()->GetCompositor());
195 EXPECT_EQ(owner.layer(), compositor()->root_layer()); 97 EXPECT_EQ(owner.layer(), compositor()->root_layer());
196 EXPECT_EQ(nullptr, layer_copy->GetCompositor()); 98 EXPECT_EQ(nullptr, layer_copy->GetCompositor());
197 } 99 }
198 100
199 // Tests that recreating the root layer, while one of its children is animating, 101 // Tests that recreating the root layer, while one of its children is animating,
200 // properly updates the compositor. So that compositor is not null for observers 102 // properly updates the compositor. So that compositor is not null for observers
201 // of animations being cancelled. 103 // of animations being cancelled.
202 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerDuringAnimation) { 104 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerDuringAnimation) {
203 LayerOwner owner; 105 LayerOwner owner;
204 Layer* layer = new Layer; 106 owner.SetLayer(base::MakeUnique<Layer>());
205 owner.SetLayer(layer); 107 Layer* layer = owner.layer();
206 compositor()->SetRootLayer(layer); 108 compositor()->SetRootLayer(layer);
207 109
208 std::unique_ptr<Layer> child(new Layer); 110 std::unique_ptr<Layer> child(new Layer);
209 child->SetBounds(gfx::Rect(0, 0, 100, 100)); 111 child->SetBounds(gfx::Rect(0, 0, 100, 100));
210 layer->Add(child.get()); 112 layer->Add(child.get());
211 113
212 // This observer checks that the compositor of |child| is not null upon 114 // This observer checks that the compositor of |child| is not null upon
213 // animation completion. 115 // animation completion.
214 std::unique_ptr<TestLayerAnimationObserver> observer( 116 std::unique_ptr<TestLayerAnimationObserver> observer(
215 new TestLayerAnimationObserver(child.get())); 117 new TestLayerAnimationObserver(child.get()));
(...skipping 13 matching lines...) Expand all
229 } 131 }
230 132
231 // Tests that recreating a non-root layer, while one of its children is 133 // Tests that recreating a non-root layer, while one of its children is
232 // animating, properly updates the compositor. So that compositor is not null 134 // animating, properly updates the compositor. So that compositor is not null
233 // for observers of animations being cancelled. 135 // for observers of animations being cancelled.
234 TEST_F(LayerOwnerTestWithCompositor, RecreateNonRootLayerDuringAnimation) { 136 TEST_F(LayerOwnerTestWithCompositor, RecreateNonRootLayerDuringAnimation) {
235 std::unique_ptr<Layer> root_layer(new Layer); 137 std::unique_ptr<Layer> root_layer(new Layer);
236 compositor()->SetRootLayer(root_layer.get()); 138 compositor()->SetRootLayer(root_layer.get());
237 139
238 LayerOwner owner; 140 LayerOwner owner;
239 Layer* layer = new Layer; 141 owner.SetLayer(base::MakeUnique<Layer>());
240 owner.SetLayer(layer); 142 Layer* layer = owner.layer();
241 root_layer->Add(layer); 143 root_layer->Add(layer);
242 144
243 std::unique_ptr<Layer> child(new Layer); 145 std::unique_ptr<Layer> child(new Layer);
244 child->SetBounds(gfx::Rect(0, 0, 100, 100)); 146 child->SetBounds(gfx::Rect(0, 0, 100, 100));
245 layer->Add(child.get()); 147 layer->Add(child.get());
246 148
247 // This observer checks that the compositor of |child| is not null upon 149 // This observer checks that the compositor of |child| is not null upon
248 // animation completion. 150 // animation completion.
249 std::unique_ptr<TestLayerAnimationObserver> observer( 151 std::unique_ptr<TestLayerAnimationObserver> observer(
250 new TestLayerAnimationObserver(child.get())); 152 new TestLayerAnimationObserver(child.get()));
(...skipping 12 matching lines...) Expand all
263 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer(); 165 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer();
264 } 166 }
265 167
266 // Tests that if LayerOwner-derived class destroys layer, then 168 // Tests that if LayerOwner-derived class destroys layer, then
267 // LayerAnimator's player becomes detached from compositor timeline. 169 // LayerAnimator's player becomes detached from compositor timeline.
268 TEST_F(LayerOwnerTestWithCompositor, DetachTimelineOnAnimatorDeletion) { 170 TEST_F(LayerOwnerTestWithCompositor, DetachTimelineOnAnimatorDeletion) {
269 std::unique_ptr<Layer> root_layer(new Layer); 171 std::unique_ptr<Layer> root_layer(new Layer);
270 compositor()->SetRootLayer(root_layer.get()); 172 compositor()->SetRootLayer(root_layer.get());
271 173
272 LayerOwnerForTesting owner; 174 LayerOwnerForTesting owner;
273 Layer* layer = new Layer; 175 owner.SetLayer(base::MakeUnique<Layer>());
274 owner.SetLayer(layer); 176 Layer* layer = owner.layer();
275 layer->SetOpacity(0.5f); 177 layer->SetOpacity(0.5f);
276 root_layer->Add(layer); 178 root_layer->Add(layer);
277 179
278 scoped_refptr<cc::AnimationPlayer> player = 180 scoped_refptr<cc::AnimationPlayer> player =
279 layer->GetAnimator()->GetAnimationPlayerForTesting(); 181 layer->GetAnimator()->GetAnimationPlayerForTesting();
280 EXPECT_TRUE(player); 182 EXPECT_TRUE(player);
281 EXPECT_TRUE(player->animation_timeline()); 183 EXPECT_TRUE(player->animation_timeline());
282 184
283 // Destroying layer/animator must detach animator's player from timeline. 185 // Destroying layer/animator must detach animator's player from timeline.
284 owner.DestroyLayerForTesting(); 186 owner.DestroyLayerForTesting();
285 EXPECT_FALSE(player->animation_timeline()); 187 EXPECT_FALSE(player->animation_timeline());
286 } 188 }
287 189
288 // Tests that if we run threaded opacity animation on already added layer 190 // Tests that if we run threaded opacity animation on already added layer
289 // then LayerAnimator's player becomes attached to timeline. 191 // then LayerAnimator's player becomes attached to timeline.
290 TEST_F(LayerOwnerTestWithCompositor, 192 TEST_F(LayerOwnerTestWithCompositor,
291 AttachTimelineIfAnimatorCreatedAfterSetCompositor) { 193 AttachTimelineIfAnimatorCreatedAfterSetCompositor) {
292 std::unique_ptr<Layer> root_layer(new Layer); 194 std::unique_ptr<Layer> root_layer(new Layer);
293 compositor()->SetRootLayer(root_layer.get()); 195 compositor()->SetRootLayer(root_layer.get());
294 196
295 LayerOwner owner; 197 LayerOwner owner;
296 Layer* layer = new Layer; 198 owner.SetLayer(base::MakeUnique<Layer>());
297 owner.SetLayer(layer); 199 Layer* layer = owner.layer();
298 root_layer->Add(layer); 200 root_layer->Add(layer);
299 201
300 layer->SetOpacity(0.5f); 202 layer->SetOpacity(0.5f);
301 203
302 scoped_refptr<cc::AnimationPlayer> player = 204 scoped_refptr<cc::AnimationPlayer> player =
303 layer->GetAnimator()->GetAnimationPlayerForTesting(); 205 layer->GetAnimator()->GetAnimationPlayerForTesting();
304 EXPECT_TRUE(player); 206 EXPECT_TRUE(player);
305 EXPECT_TRUE(player->animation_timeline()); 207 EXPECT_TRUE(player->animation_timeline());
306 } 208 }
307 209
308 } // namespace ui 210 } // 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