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

Side by Side Diff: cc/trees/layer_tree_host_common_unittest.cc

Issue 1859733002: cc: Remove usage of Layer draw_transform (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve comments Created 4 years, 8 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
« no previous file with comments | « cc/trees/draw_property_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 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 "cc/trees/layer_tree_host_common.h" 5 #include "cc/trees/layer_tree_host_common.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 LayerTreeHostCommonScalingTest() 101 LayerTreeHostCommonScalingTest()
102 : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {} 102 : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {}
103 }; 103 };
104 104
105 TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { 105 TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
106 // Sanity check: For layers positioned at zero, with zero size, 106 // Sanity check: For layers positioned at zero, with zero size,
107 // and with identity transforms, then the draw transform, 107 // and with identity transforms, then the draw transform,
108 // screen space transform, and the hierarchy passed on to children 108 // screen space transform, and the hierarchy passed on to children
109 // layers should also be identity transforms. 109 // layers should also be identity transforms.
110 110
111 scoped_refptr<Layer> parent = Layer::Create(); 111 LayerImpl* parent = root_layer();
112 scoped_refptr<Layer> child = Layer::Create(); 112 LayerImpl* child = AddChild<LayerImpl>(parent);
113 scoped_refptr<Layer> grand_child = Layer::Create(); 113 LayerImpl* grand_child = AddChild<LayerImpl>(child);
114 parent->AddChild(child);
115 child->AddChild(grand_child);
116
117 host()->SetRootLayer(parent);
118 114
119 gfx::Transform identity_matrix; 115 gfx::Transform identity_matrix;
120 SetLayerPropertiesForTesting(parent.get(), 116 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
121 identity_matrix, 117 gfx::PointF(), gfx::Size(100, 100), true, false);
122 gfx::Point3F(), 118 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
123 gfx::PointF(), 119 gfx::PointF(), gfx::Size(), true, false);
124 gfx::Size(100, 100), 120 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
125 true, 121 gfx::PointF(), gfx::Size(), true, false);
126 false);
127 SetLayerPropertiesForTesting(child.get(),
128 identity_matrix,
129 gfx::Point3F(),
130 gfx::PointF(),
131 gfx::Size(),
132 true,
133 false);
134 SetLayerPropertiesForTesting(grand_child.get(),
135 identity_matrix,
136 gfx::Point3F(),
137 gfx::PointF(),
138 gfx::Size(),
139 true,
140 false);
141 122
142 ExecuteCalculateDrawProperties(parent.get()); 123 ExecuteCalculateDrawProperties(parent);
143 124
144 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); 125 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
145 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, 126 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
146 child->screen_space_transform()); 127 child->ScreenSpaceTransform());
147 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, 128 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
148 grand_child->draw_transform()); 129 grand_child->DrawTransform());
149 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, 130 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
150 grand_child->screen_space_transform()); 131 grand_child->ScreenSpaceTransform());
151 } 132 }
152 133
153 TEST_F(LayerTreeHostCommonTest, 134 TEST_F(LayerTreeHostCommonTest,
154 ScreenSpaceTransformOfSkippedLayersWithHandlers) { 135 ScreenSpaceTransformOfSkippedLayersWithHandlers) {
155 // Even for layers that are skipped, we need to compute the correct screen 136 // Even for layers that are skipped, we need to compute the correct screen
156 // space transform because it is used during hit testing. 137 // space transform because it is used during hit testing.
157 LayerImpl* parent = root_layer(); 138 LayerImpl* parent = root_layer();
158 LayerImpl* child = AddChild<LayerImpl>(parent); 139 LayerImpl* child = AddChild<LayerImpl>(parent);
159 LayerImpl* grand_child = AddChild<LayerImpl>(child); 140 LayerImpl* grand_child = AddChild<LayerImpl>(child);
160 child->SetDrawsContent(true); 141 child->SetDrawsContent(true);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 parent->layer_tree_impl()->property_trees()->effect_tree; 183 parent->layer_tree_impl()->property_trees()->effect_tree;
203 EffectNode* node = effect_tree.Node(child->effect_tree_index()); 184 EffectNode* node = effect_tree.Node(child->effect_tree_index());
204 const int transform_tree_size = parent->layer_tree_impl() 185 const int transform_tree_size = parent->layer_tree_impl()
205 ->property_trees() 186 ->property_trees()
206 ->transform_tree.next_available_id(); 187 ->transform_tree.next_available_id();
207 EXPECT_LT(node->data.transform_id, transform_tree_size); 188 EXPECT_LT(node->data.transform_id, transform_tree_size);
208 } 189 }
209 190
210 TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { 191 TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
211 gfx::Transform identity_matrix; 192 gfx::Transform identity_matrix;
212 scoped_refptr<Layer> layer = Layer::Create(); 193 LayerImpl* root = root_layer();
194 LayerImpl* layer = AddChild<LayerImpl>(root);
213 195
214 scoped_refptr<Layer> root = Layer::Create(); 196 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
215 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
216 gfx::PointF(), gfx::Size(1, 2), true, false); 197 gfx::PointF(), gfx::Size(1, 2), true, false);
217 root->AddChild(layer);
218 198
219 host()->SetRootLayer(root); 199 TransformTree& tree =
220 200 host_impl()->active_tree()->property_trees()->transform_tree;
221 TransformTree& tree = host()->property_trees()->transform_tree;
222 201
223 // Case 2: Setting the bounds of the layer should not affect either the draw 202 // Case 2: Setting the bounds of the layer should not affect either the draw
224 // transform or the screenspace transform. 203 // transform or the screenspace transform.
225 gfx::Transform translation_to_center; 204 gfx::Transform translation_to_center;
226 translation_to_center.Translate(5.0, 6.0); 205 translation_to_center.Translate(5.0, 6.0);
227 SetLayerPropertiesForTesting(layer.get(), identity_matrix, gfx::Point3F(), 206 SetLayerPropertiesForTesting(layer, identity_matrix, gfx::Point3F(),
228 gfx::PointF(), gfx::Size(10, 12), true, false); 207 gfx::PointF(), gfx::Size(10, 12), true, false);
229 ExecuteCalculateDrawProperties(root.get()); 208 ExecuteCalculateDrawProperties(root);
230 EXPECT_TRANSFORMATION_MATRIX_EQ( 209 EXPECT_TRANSFORMATION_MATRIX_EQ(
231 identity_matrix, draw_property_utils::DrawTransform(layer.get(), tree)); 210 identity_matrix, draw_property_utils::DrawTransform(layer, tree));
232 EXPECT_TRANSFORMATION_MATRIX_EQ( 211 EXPECT_TRANSFORMATION_MATRIX_EQ(
233 identity_matrix, 212 identity_matrix, draw_property_utils::ScreenSpaceTransform(layer, tree));
234 draw_property_utils::ScreenSpaceTransform(layer.get(), tree));
235 213
236 // Case 3: The anchor point by itself (without a layer transform) should have 214 // Case 3: The anchor point by itself (without a layer transform) should have
237 // no effect on the transforms. 215 // no effect on the transforms.
238 SetLayerPropertiesForTesting(layer.get(), identity_matrix, 216 SetLayerPropertiesForTesting(layer, identity_matrix,
239 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), 217 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
240 gfx::Size(10, 12), true, false); 218 gfx::Size(10, 12), true, false);
241 ExecuteCalculateDrawProperties(root.get()); 219 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
220 ExecuteCalculateDrawProperties(root);
242 EXPECT_TRANSFORMATION_MATRIX_EQ( 221 EXPECT_TRANSFORMATION_MATRIX_EQ(
243 identity_matrix, draw_property_utils::DrawTransform(layer.get(), tree)); 222 identity_matrix, draw_property_utils::DrawTransform(layer, tree));
244 EXPECT_TRANSFORMATION_MATRIX_EQ( 223 EXPECT_TRANSFORMATION_MATRIX_EQ(
245 identity_matrix, 224 identity_matrix, draw_property_utils::ScreenSpaceTransform(layer, tree));
246 draw_property_utils::ScreenSpaceTransform(layer.get(), tree));
247 225
248 // Case 4: A change in actual position affects both the draw transform and 226 // Case 4: A change in actual position affects both the draw transform and
249 // screen space transform. 227 // screen space transform.
250 gfx::Transform position_transform; 228 gfx::Transform position_transform;
251 position_transform.Translate(0.f, 1.2f); 229 position_transform.Translate(0.f, 1.2f);
252 SetLayerPropertiesForTesting( 230 SetLayerPropertiesForTesting(
253 layer.get(), identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f), 231 layer, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
254 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false); 232 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
255 ExecuteCalculateDrawProperties(root.get()); 233 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
234 ExecuteCalculateDrawProperties(root);
235 EXPECT_TRANSFORMATION_MATRIX_EQ(
236 position_transform, draw_property_utils::DrawTransform(layer, tree));
256 EXPECT_TRANSFORMATION_MATRIX_EQ( 237 EXPECT_TRANSFORMATION_MATRIX_EQ(
257 position_transform, 238 position_transform,
258 draw_property_utils::DrawTransform(layer.get(), tree)); 239 draw_property_utils::ScreenSpaceTransform(layer, tree));
259 EXPECT_TRANSFORMATION_MATRIX_EQ(
260 position_transform,
261 draw_property_utils::ScreenSpaceTransform(layer.get(), tree));
262 240
263 // Case 5: In the correct sequence of transforms, the layer transform should 241 // Case 5: In the correct sequence of transforms, the layer transform should
264 // pre-multiply the translation_to_center. This is easily tested by using a 242 // pre-multiply the translation_to_center. This is easily tested by using a
265 // scale transform, because scale and translation are not commutative. 243 // scale transform, because scale and translation are not commutative.
266 gfx::Transform layer_transform; 244 gfx::Transform layer_transform;
267 layer_transform.Scale3d(2.0, 2.0, 1.0); 245 layer_transform.Scale3d(2.0, 2.0, 1.0);
268 SetLayerPropertiesForTesting(layer.get(), layer_transform, gfx::Point3F(), 246 SetLayerPropertiesForTesting(layer, layer_transform, gfx::Point3F(),
269 gfx::PointF(), gfx::Size(10, 12), true, false); 247 gfx::PointF(), gfx::Size(10, 12), true, false);
270 ExecuteCalculateDrawProperties(root.get()); 248 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
249 ExecuteCalculateDrawProperties(root);
271 EXPECT_TRANSFORMATION_MATRIX_EQ( 250 EXPECT_TRANSFORMATION_MATRIX_EQ(
272 layer_transform, draw_property_utils::DrawTransform(layer.get(), tree)); 251 layer_transform, draw_property_utils::DrawTransform(layer, tree));
273 EXPECT_TRANSFORMATION_MATRIX_EQ( 252 EXPECT_TRANSFORMATION_MATRIX_EQ(
274 layer_transform, 253 layer_transform, draw_property_utils::ScreenSpaceTransform(layer, tree));
275 draw_property_utils::ScreenSpaceTransform(layer.get(), tree));
276 254
277 // Case 6: The layer transform should occur with respect to the anchor point. 255 // Case 6: The layer transform should occur with respect to the anchor point.
278 gfx::Transform translation_to_anchor; 256 gfx::Transform translation_to_anchor;
279 translation_to_anchor.Translate(5.0, 0.0); 257 translation_to_anchor.Translate(5.0, 0.0);
280 gfx::Transform expected_result = 258 gfx::Transform expected_result =
281 translation_to_anchor * layer_transform * Inverse(translation_to_anchor); 259 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
282 SetLayerPropertiesForTesting(layer.get(), layer_transform, 260 SetLayerPropertiesForTesting(layer, layer_transform,
283 gfx::Point3F(5.0f, 0.f, 0.f), gfx::PointF(), 261 gfx::Point3F(5.0f, 0.f, 0.f), gfx::PointF(),
284 gfx::Size(10, 12), true, false); 262 gfx::Size(10, 12), true, false);
285 ExecuteCalculateDrawProperties(root.get()); 263 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
264 ExecuteCalculateDrawProperties(root);
286 EXPECT_TRANSFORMATION_MATRIX_EQ( 265 EXPECT_TRANSFORMATION_MATRIX_EQ(
287 expected_result, draw_property_utils::DrawTransform(layer.get(), tree)); 266 expected_result, draw_property_utils::DrawTransform(layer, tree));
288 EXPECT_TRANSFORMATION_MATRIX_EQ( 267 EXPECT_TRANSFORMATION_MATRIX_EQ(
289 expected_result, 268 expected_result, draw_property_utils::ScreenSpaceTransform(layer, tree));
290 draw_property_utils::ScreenSpaceTransform(layer.get(), tree));
291 269
292 // Case 7: Verify that position pre-multiplies the layer transform. The 270 // Case 7: Verify that position pre-multiplies the layer transform. The
293 // current implementation of CalculateDrawProperties does this implicitly, but 271 // current implementation of CalculateDrawProperties does this implicitly, but
294 // it is still worth testing to detect accidental regressions. 272 // it is still worth testing to detect accidental regressions.
295 expected_result = position_transform * translation_to_anchor * 273 expected_result = position_transform * translation_to_anchor *
296 layer_transform * Inverse(translation_to_anchor); 274 layer_transform * Inverse(translation_to_anchor);
297 SetLayerPropertiesForTesting( 275 SetLayerPropertiesForTesting(
298 layer.get(), layer_transform, gfx::Point3F(5.0f, 0.f, 0.f), 276 layer, layer_transform, gfx::Point3F(5.0f, 0.f, 0.f),
299 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false); 277 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
300 ExecuteCalculateDrawProperties(root.get()); 278 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
279 ExecuteCalculateDrawProperties(root);
301 EXPECT_TRANSFORMATION_MATRIX_EQ( 280 EXPECT_TRANSFORMATION_MATRIX_EQ(
302 expected_result, draw_property_utils::DrawTransform(layer.get(), tree)); 281 expected_result, draw_property_utils::DrawTransform(layer, tree));
303 EXPECT_TRANSFORMATION_MATRIX_EQ( 282 EXPECT_TRANSFORMATION_MATRIX_EQ(
304 expected_result, 283 expected_result, draw_property_utils::ScreenSpaceTransform(layer, tree));
305 draw_property_utils::ScreenSpaceTransform(layer.get(), tree));
306 } 284 }
307 285
308 TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { 286 TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
309 const gfx::ScrollOffset kScrollOffset(50, 100); 287 const gfx::ScrollOffset kScrollOffset(50, 100);
310 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); 288 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
311 const gfx::Vector2d kMaxScrollOffset(200, 200); 289 const gfx::Vector2d kMaxScrollOffset(200, 200);
312 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), 290 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
313 -kScrollOffset.y()); 291 -kScrollOffset.y());
314 float page_scale = 0.888f; 292 float page_scale = 0.888f;
315 const float kDeviceScale = 1.666f; 293 const float kDeviceScale = 1.666f;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 sub_layer_screen_position.y() * page_scale * 398 sub_layer_screen_position.y() * page_scale *
421 kDeviceScale)); 399 kDeviceScale));
422 expected_transform.Scale(page_scale * kDeviceScale, 400 expected_transform.Scale(page_scale * kDeviceScale,
423 page_scale * kDeviceScale); 401 page_scale * kDeviceScale);
424 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, 402 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
425 sublayer->DrawTransform()); 403 sublayer->DrawTransform());
426 } 404 }
427 405
428 TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { 406 TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
429 gfx::Transform identity_matrix; 407 gfx::Transform identity_matrix;
430 scoped_refptr<Layer> root = Layer::Create(); 408 LayerImpl* root = root_layer();
431 scoped_refptr<Layer> parent = Layer::Create(); 409 LayerImpl* parent = AddChild<LayerImpl>(root);
432 scoped_refptr<Layer> child = Layer::Create(); 410 LayerImpl* child = AddChild<LayerImpl>(parent);
433 scoped_refptr<Layer> grand_child = Layer::Create(); 411 LayerImpl* grand_child = AddChild<LayerImpl>(child);
434 root->AddChild(parent);
435 parent->AddChild(child);
436 child->AddChild(grand_child);
437
438 host()->SetRootLayer(root);
439 412
440 // One-time setup of root layer 413 // One-time setup of root layer
441 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), 414 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
442 gfx::PointF(), gfx::Size(1, 2), true, false); 415 gfx::PointF(), gfx::Size(1, 2), true, false);
443 416
444 TransformTree& tree = host()->property_trees()->transform_tree; 417 TransformTree& tree =
418 host_impl()->active_tree()->property_trees()->transform_tree;
445 419
446 // Case 1: parent's anchor point should not affect child or grand_child. 420 // Case 1: parent's anchor point should not affect child or grand_child.
447 SetLayerPropertiesForTesting(parent.get(), identity_matrix, 421 SetLayerPropertiesForTesting(parent, identity_matrix,
448 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), 422 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
449 gfx::Size(10, 12), true, false); 423 gfx::Size(10, 12), true, false);
450 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), 424 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
451 gfx::PointF(), gfx::Size(16, 18), true, false); 425 gfx::PointF(), gfx::Size(16, 18), true, false);
452 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, 426 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
453 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78), 427 gfx::PointF(), gfx::Size(76, 78), true, false);
454 true, false); 428 ExecuteCalculateDrawProperties(root);
455 ExecuteCalculateDrawProperties(root.get());
456 429
457 EXPECT_TRANSFORMATION_MATRIX_EQ( 430 EXPECT_TRANSFORMATION_MATRIX_EQ(
458 identity_matrix, draw_property_utils::DrawTransform(child.get(), tree)); 431 identity_matrix, draw_property_utils::DrawTransform(child, tree));
432 EXPECT_TRANSFORMATION_MATRIX_EQ(
433 identity_matrix, draw_property_utils::ScreenSpaceTransform(child, tree));
434 EXPECT_TRANSFORMATION_MATRIX_EQ(
435 identity_matrix, draw_property_utils::DrawTransform(grand_child, tree));
459 EXPECT_TRANSFORMATION_MATRIX_EQ( 436 EXPECT_TRANSFORMATION_MATRIX_EQ(
460 identity_matrix, 437 identity_matrix,
461 draw_property_utils::ScreenSpaceTransform(child.get(), tree)); 438 draw_property_utils::ScreenSpaceTransform(grand_child, tree));
462 EXPECT_TRANSFORMATION_MATRIX_EQ(
463 identity_matrix,
464 draw_property_utils::DrawTransform(grand_child.get(), tree));
465 EXPECT_TRANSFORMATION_MATRIX_EQ(
466 identity_matrix,
467 draw_property_utils::ScreenSpaceTransform(grand_child.get(), tree));
468 439
469 // Case 2: parent's position affects child and grand_child. 440 // Case 2: parent's position affects child and grand_child.
470 gfx::Transform parent_position_transform; 441 gfx::Transform parent_position_transform;
471 parent_position_transform.Translate(0.f, 1.2f); 442 parent_position_transform.Translate(0.f, 1.2f);
472 SetLayerPropertiesForTesting( 443 SetLayerPropertiesForTesting(
473 parent.get(), identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f), 444 parent, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
474 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false); 445 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
475 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), 446 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
476 gfx::PointF(), gfx::Size(16, 18), true, false); 447 gfx::PointF(), gfx::Size(16, 18), true, false);
477 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, 448 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
478 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78), 449 gfx::PointF(), gfx::Size(76, 78), true, false);
479 true, false); 450 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
480 ExecuteCalculateDrawProperties(root.get()); 451 ExecuteCalculateDrawProperties(root);
481 EXPECT_TRANSFORMATION_MATRIX_EQ( 452 EXPECT_TRANSFORMATION_MATRIX_EQ(
482 parent_position_transform, 453 parent_position_transform,
483 draw_property_utils::DrawTransform(child.get(), tree)); 454 draw_property_utils::DrawTransform(child, tree));
484 EXPECT_TRANSFORMATION_MATRIX_EQ( 455 EXPECT_TRANSFORMATION_MATRIX_EQ(
485 parent_position_transform, 456 parent_position_transform,
486 draw_property_utils::ScreenSpaceTransform(child.get(), tree)); 457 draw_property_utils::ScreenSpaceTransform(child, tree));
487 EXPECT_TRANSFORMATION_MATRIX_EQ( 458 EXPECT_TRANSFORMATION_MATRIX_EQ(
488 parent_position_transform, 459 parent_position_transform,
489 draw_property_utils::DrawTransform(grand_child.get(), tree)); 460 draw_property_utils::DrawTransform(grand_child, tree));
490 EXPECT_TRANSFORMATION_MATRIX_EQ( 461 EXPECT_TRANSFORMATION_MATRIX_EQ(
491 parent_position_transform, 462 parent_position_transform,
492 draw_property_utils::ScreenSpaceTransform(grand_child.get(), tree)); 463 draw_property_utils::ScreenSpaceTransform(grand_child, tree));
493 464
494 // Case 3: parent's local transform affects child and grandchild 465 // Case 3: parent's local transform affects child and grandchild
495 gfx::Transform parent_layer_transform; 466 gfx::Transform parent_layer_transform;
496 parent_layer_transform.Scale3d(2.0, 2.0, 1.0); 467 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
497 gfx::Transform parent_translation_to_anchor; 468 gfx::Transform parent_translation_to_anchor;
498 parent_translation_to_anchor.Translate(2.5, 3.0); 469 parent_translation_to_anchor.Translate(2.5, 3.0);
499 gfx::Transform parent_composite_transform = 470 gfx::Transform parent_composite_transform =
500 parent_translation_to_anchor * parent_layer_transform * 471 parent_translation_to_anchor * parent_layer_transform *
501 Inverse(parent_translation_to_anchor); 472 Inverse(parent_translation_to_anchor);
502 SetLayerPropertiesForTesting(parent.get(), parent_layer_transform, 473 SetLayerPropertiesForTesting(parent, parent_layer_transform,
503 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), 474 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
504 gfx::Size(10, 12), true, false); 475 gfx::Size(10, 12), true, false);
505 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), 476 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
506 gfx::PointF(), gfx::Size(16, 18), true, false); 477 gfx::PointF(), gfx::Size(16, 18), true, false);
507 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, 478 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
508 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78), 479 gfx::PointF(), gfx::Size(76, 78), true, false);
509 true, false); 480 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
510 ExecuteCalculateDrawProperties(root.get()); 481 ExecuteCalculateDrawProperties(root);
511 EXPECT_TRANSFORMATION_MATRIX_EQ( 482 EXPECT_TRANSFORMATION_MATRIX_EQ(
512 parent_composite_transform, 483 parent_composite_transform,
513 draw_property_utils::DrawTransform(child.get(), tree)); 484 draw_property_utils::DrawTransform(child, tree));
514 EXPECT_TRANSFORMATION_MATRIX_EQ( 485 EXPECT_TRANSFORMATION_MATRIX_EQ(
515 parent_composite_transform, 486 parent_composite_transform,
516 draw_property_utils::ScreenSpaceTransform(child.get(), tree)); 487 draw_property_utils::ScreenSpaceTransform(child, tree));
517 EXPECT_TRANSFORMATION_MATRIX_EQ( 488 EXPECT_TRANSFORMATION_MATRIX_EQ(
518 parent_composite_transform, 489 parent_composite_transform,
519 draw_property_utils::DrawTransform(grand_child.get(), tree)); 490 draw_property_utils::DrawTransform(grand_child, tree));
520 EXPECT_TRANSFORMATION_MATRIX_EQ( 491 EXPECT_TRANSFORMATION_MATRIX_EQ(
521 parent_composite_transform, 492 parent_composite_transform,
522 draw_property_utils::ScreenSpaceTransform(grand_child.get(), tree)); 493 draw_property_utils::ScreenSpaceTransform(grand_child, tree));
523 } 494 }
524 495
525 TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { 496 TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
526 LayerImpl* root = root_layer(); 497 LayerImpl* root = root_layer();
527 LayerImpl* parent = AddChildToRoot<LayerImpl>(); 498 LayerImpl* parent = AddChildToRoot<LayerImpl>();
528 LayerImpl* child = AddChild<LayerImpl>(parent); 499 LayerImpl* child = AddChild<LayerImpl>(parent);
529 LayerImpl* grand_child = AddChild<LayerImpl>(child); 500 LayerImpl* grand_child = AddChild<LayerImpl>(child);
530 grand_child->SetDrawsContent(true); 501 grand_child->SetDrawsContent(true);
531 502
532 gfx::Transform identity_matrix; 503 gfx::Transform identity_matrix;
(...skipping 6443 matching lines...) Expand 10 before | Expand all | Expand 10 after
6976 // Ensures that when we have a render surface between a fixed position layer 6947 // Ensures that when we have a render surface between a fixed position layer
6977 // and its container, we compute the fixed position layer's draw transform 6948 // and its container, we compute the fixed position layer's draw transform
6978 // with respect to that intervening render surface, not with respect to its 6949 // with respect to that intervening render surface, not with respect to its
6979 // container's render target. 6950 // container's render target.
6980 // 6951 //
6981 // + root 6952 // + root
6982 // + render_surface 6953 // + render_surface
6983 // + fixed 6954 // + fixed
6984 // + child 6955 // + child
6985 // 6956 //
6986 scoped_refptr<Layer> root = Layer::Create(); 6957 LayerImpl* root = root_layer();
6987 scoped_refptr<LayerWithForcedDrawsContent> render_surface = 6958 LayerImpl* render_surface = AddChild<LayerImpl>(root);
6988 make_scoped_refptr(new LayerWithForcedDrawsContent()); 6959 LayerImpl* fixed = AddChild<LayerImpl>(render_surface);
6989 scoped_refptr<LayerWithForcedDrawsContent> fixed = 6960 LayerImpl* child = AddChild<LayerImpl>(fixed);
6990 make_scoped_refptr(new LayerWithForcedDrawsContent());
6991 scoped_refptr<LayerWithForcedDrawsContent> child =
6992 make_scoped_refptr(new LayerWithForcedDrawsContent());
6993 6961
6994 root->AddChild(render_surface); 6962 render_surface->SetDrawsContent(true);
6995 render_surface->AddChild(fixed); 6963 fixed->SetDrawsContent(true);
6996 fixed->AddChild(child); 6964 child->SetDrawsContent(true);
6997 6965
6998 root->SetIsContainerForFixedPositionLayers(true); 6966 root->SetIsContainerForFixedPositionLayers(true);
6999 render_surface->SetForceRenderSurface(true); 6967 render_surface->SetForceRenderSurface(true);
7000 6968
7001 LayerPositionConstraint constraint; 6969 LayerPositionConstraint constraint;
7002 constraint.set_is_fixed_position(true); 6970 constraint.set_is_fixed_position(true);
7003 fixed->SetPositionConstraint(constraint); 6971 fixed->SetPositionConstraint(constraint);
7004 6972
7005 SetLayerPropertiesForTesting(root.get(), gfx::Transform(), gfx::Point3F(), 6973 SetLayerPropertiesForTesting(root, gfx::Transform(), gfx::Point3F(),
7006 gfx::PointF(), gfx::Size(50, 50), true, false); 6974 gfx::PointF(), gfx::Size(50, 50), true, false);
7007 SetLayerPropertiesForTesting(render_surface.get(), gfx::Transform(), 6975 SetLayerPropertiesForTesting(render_surface, gfx::Transform(), gfx::Point3F(),
7008 gfx::Point3F(), gfx::PointF(7.f, 9.f), 6976 gfx::PointF(7.f, 9.f), gfx::Size(50, 50), true,
7009 gfx::Size(50, 50), true, false); 6977 false);
7010 SetLayerPropertiesForTesting(fixed.get(), gfx::Transform(), gfx::Point3F(), 6978 SetLayerPropertiesForTesting(fixed, gfx::Transform(), gfx::Point3F(),
7011 gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true, 6979 gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true,
7012 false); 6980 false);
7013 SetLayerPropertiesForTesting(child.get(), gfx::Transform(), gfx::Point3F(), 6981 SetLayerPropertiesForTesting(child, gfx::Transform(), gfx::Point3F(),
7014 gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true, 6982 gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true,
7015 false); 6983 false);
7016 6984
7017 host()->SetRootLayer(root); 6985 ExecuteCalculateDrawProperties(root);
7018 6986
7019 ExecuteCalculateDrawProperties(root.get()); 6987 TransformTree& tree =
7020 6988 host_impl()->active_tree()->property_trees()->transform_tree;
7021 TransformTree& tree = host()->property_trees()->transform_tree;
7022 6989
7023 gfx::Transform expected_fixed_draw_transform; 6990 gfx::Transform expected_fixed_draw_transform;
7024 expected_fixed_draw_transform.Translate(10.f, 15.f); 6991 expected_fixed_draw_transform.Translate(10.f, 15.f);
7025 EXPECT_EQ(expected_fixed_draw_transform, 6992 EXPECT_EQ(expected_fixed_draw_transform,
7026 draw_property_utils::DrawTransform(fixed.get(), tree)); 6993 draw_property_utils::DrawTransform(fixed, tree));
7027 6994
7028 gfx::Transform expected_fixed_screen_space_transform; 6995 gfx::Transform expected_fixed_screen_space_transform;
7029 expected_fixed_screen_space_transform.Translate(17.f, 24.f); 6996 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
7030 EXPECT_EQ(expected_fixed_screen_space_transform, 6997 EXPECT_EQ(expected_fixed_screen_space_transform,
7031 draw_property_utils::ScreenSpaceTransform(fixed.get(), tree)); 6998 draw_property_utils::ScreenSpaceTransform(fixed, tree));
7032 6999
7033 gfx::Transform expected_child_draw_transform; 7000 gfx::Transform expected_child_draw_transform;
7034 expected_child_draw_transform.Translate(11.f, 17.f); 7001 expected_child_draw_transform.Translate(11.f, 17.f);
7035 EXPECT_EQ(expected_child_draw_transform, 7002 EXPECT_EQ(expected_child_draw_transform,
7036 draw_property_utils::DrawTransform(child.get(), tree)); 7003 draw_property_utils::DrawTransform(child, tree));
7037 7004
7038 gfx::Transform expected_child_screen_space_transform; 7005 gfx::Transform expected_child_screen_space_transform;
7039 expected_child_screen_space_transform.Translate(18.f, 26.f); 7006 expected_child_screen_space_transform.Translate(18.f, 26.f);
7040 EXPECT_EQ(expected_child_screen_space_transform, 7007 EXPECT_EQ(expected_child_screen_space_transform,
7041 draw_property_utils::ScreenSpaceTransform(child.get(), tree)); 7008 draw_property_utils::ScreenSpaceTransform(child, tree));
7042 } 7009 }
7043 7010
7044 TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { 7011 TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
7045 // This test verifies that a scrolling layer that gets snapped to 7012 // This test verifies that a scrolling layer that gets snapped to
7046 // integer coordinates doesn't move a fixed position child. 7013 // integer coordinates doesn't move a fixed position child.
7047 // 7014 //
7048 // + root 7015 // + root
7049 // + container 7016 // + container
7050 // + scroller 7017 // + scroller
7051 // + fixed 7018 // + fixed
(...skipping 2993 matching lines...) Expand 10 before | Expand all | Expand 10 after
10045 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); 10012 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10046 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); 10013 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10047 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); 10014 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10048 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); 10015 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10049 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); 10016 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10050 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); 10017 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10051 } 10018 }
10052 10019
10053 } // namespace 10020 } // namespace
10054 } // namespace cc 10021 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/draw_property_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698