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

Side by Side Diff: cc/layer_tree_host_common_unittest.cc

Issue 11017044: Remove root layer specialness in calculateDrawTransforms (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added assertion that rounding does not affect exact coverage testing Created 8 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 | « cc/layer_tree_host_common.cc ('k') | cc/layer_tree_host_impl_unittest.cc » ('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 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 "config.h" 5 #include "config.h"
6 6
7 #include "cc/layer_tree_host_common.h" 7 #include "cc/layer_tree_host_common.h"
8 8
9 #include "cc/content_layer.h" 9 #include "cc/content_layer.h"
10 #include "cc/content_layer_client.h" 10 #include "cc/content_layer_client.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( )); 166 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( ));
167 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ; 167 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ;
168 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form()); 168 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form());
169 } 169 }
170 170
171 TEST(LayerTreeHostCommonTest, verifyTransformsForSingleLayer) 171 TEST(LayerTreeHostCommonTest, verifyTransformsForSingleLayer)
172 { 172 {
173 WebTransformationMatrix identityMatrix; 173 WebTransformationMatrix identityMatrix;
174 scoped_refptr<Layer> layer = Layer::create(); 174 scoped_refptr<Layer> layer = Layer::create();
175 175
176 scoped_refptr<Layer> root = Layer::create();
177 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(1, 2), false);
178 root->addChild(layer);
179
176 // Case 1: setting the sublayer transform should not affect this layer's dra w transform or screen-space transform. 180 // Case 1: setting the sublayer transform should not affect this layer's dra w transform or screen-space transform.
177 WebTransformationMatrix arbitraryTranslation; 181 WebTransformationMatrix arbitraryTranslation;
178 arbitraryTranslation.translate(10, 20); 182 arbitraryTranslation.translate(10, 20);
179 setLayerPropertiesForTesting(layer.get(), identityMatrix, arbitraryTranslati on, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 183 setLayerPropertiesForTesting(layer.get(), identityMatrix, arbitraryTranslati on, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
180 executeCalculateDrawTransformsAndVisibility(layer.get()); 184 executeCalculateDrawTransformsAndVisibility(root.get());
181 WebTransformationMatrix expectedDrawTransform = identityMatrix; 185 WebTransformationMatrix expectedDrawTransform = identityMatrix;
182 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedDrawTransform, layer->drawTransform( )); 186 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedDrawTransform, layer->drawTransform( ));
183 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( )); 187 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( ));
184 188
185 // Case 2: Setting the bounds of the layer should not affect either the draw transform or the screenspace transform. 189 // Case 2: Setting the bounds of the layer should not affect either the draw transform or the screenspace transform.
186 WebTransformationMatrix translationToCenter; 190 WebTransformationMatrix translationToCenter;
187 translationToCenter.translate(5, 6); 191 translationToCenter.translate(5, 6);
188 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 12), false); 192 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 12), false);
189 executeCalculateDrawTransformsAndVisibility(layer.get()); 193 executeCalculateDrawTransformsAndVisibility(root.get());
190 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform()); 194 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform());
191 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( )); 195 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( ));
192 196
193 // Case 3: The anchor point by itself (without a layer transform) should hav e no effect on the transforms. 197 // Case 3: The anchor point by itself (without a layer transform) should hav e no effect on the transforms.
194 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, Fl oatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 198 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, Fl oatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
195 executeCalculateDrawTransformsAndVisibility(layer.get()); 199 executeCalculateDrawTransformsAndVisibility(root.get());
196 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform()); 200 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform());
197 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( )); 201 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( ));
198 202
199 // Case 4: A change in actual position affects both the draw transform and s creen space transform. 203 // Case 4: A change in actual position affects both the draw transform and s creen space transform.
200 WebTransformationMatrix positionTransform; 204 WebTransformationMatrix positionTransform;
201 positionTransform.translate(0, 1.2); 205 positionTransform.translate(0, 1.2);
202 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, Fl oatPoint(0.25, 0.25), FloatPoint(0, 1.2f), IntSize(10, 12), false); 206 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, Fl oatPoint(0.25, 0.25), FloatPoint(0, 1.2f), IntSize(10, 12), false);
203 executeCalculateDrawTransformsAndVisibility(layer.get()); 207 executeCalculateDrawTransformsAndVisibility(root.get());
204 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->drawTransform()); 208 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->drawTransform());
205 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->screenSpaceTransfo rm()); 209 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->screenSpaceTransfo rm());
206 210
207 // Case 5: In the correct sequence of transforms, the layer transform should pre-multiply the translationToCenter. This is easily tested by 211 // Case 5: In the correct sequence of transforms, the layer transform should pre-multiply the translationToCenter. This is easily tested by
208 // using a scale transform, because scale and translation are not co mmutative. 212 // using a scale transform, because scale and translation are not co mmutative.
209 WebTransformationMatrix layerTransform; 213 WebTransformationMatrix layerTransform;
210 layerTransform.scale3d(2, 2, 1); 214 layerTransform.scale3d(2, 2, 1);
211 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 12), false); 215 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 12), false);
212 executeCalculateDrawTransformsAndVisibility(layer.get()); 216 executeCalculateDrawTransformsAndVisibility(root.get());
213 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->drawTransform()); 217 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->drawTransform());
214 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->screenSpaceTransform( )); 218 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->screenSpaceTransform( ));
215 219
216 // Case 6: The layer transform should occur with respect to the anchor point . 220 // Case 6: The layer transform should occur with respect to the anchor point .
217 WebTransformationMatrix translationToAnchor; 221 WebTransformationMatrix translationToAnchor;
218 translationToAnchor.translate(5, 0); 222 translationToAnchor.translate(5, 0);
219 WebTransformationMatrix expectedResult = translationToAnchor * layerTransfor m * translationToAnchor.inverse(); 223 WebTransformationMatrix expectedResult = translationToAnchor * layerTransfor m * translationToAnchor.inverse();
220 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, Fl oatPoint(0.5, 0), FloatPoint(0, 0), IntSize(10, 12), false); 224 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, Fl oatPoint(0.5, 0), FloatPoint(0, 0), IntSize(10, 12), false);
221 executeCalculateDrawTransformsAndVisibility(layer.get()); 225 executeCalculateDrawTransformsAndVisibility(root.get());
222 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform()); 226 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform());
223 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform( )); 227 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform( ));
224 228
225 // Case 7: Verify that position pre-multiplies the layer transform. 229 // Case 7: Verify that position pre-multiplies the layer transform.
226 // The current implementation of calculateDrawTransforms does this i mplicitly, but it is 230 // The current implementation of calculateDrawTransforms does this i mplicitly, but it is
227 // still worth testing to detect accidental regressions. 231 // still worth testing to detect accidental regressions.
228 expectedResult = positionTransform * translationToAnchor * layerTransform * translationToAnchor.inverse(); 232 expectedResult = positionTransform * translationToAnchor * layerTransform * translationToAnchor.inverse();
229 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, Fl oatPoint(0.5, 0), FloatPoint(0, 1.2f), IntSize(10, 12), false); 233 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, Fl oatPoint(0.5, 0), FloatPoint(0, 1.2f), IntSize(10, 12), false);
230 executeCalculateDrawTransformsAndVisibility(layer.get()); 234 executeCalculateDrawTransformsAndVisibility(root.get());
231 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform()); 235 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform());
232 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform( )); 236 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform( ));
233 } 237 }
234 238
235 TEST(LayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy) 239 TEST(LayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy)
236 { 240 {
237 WebTransformationMatrix identityMatrix; 241 WebTransformationMatrix identityMatrix;
242 scoped_refptr<Layer> root = Layer::create();
238 scoped_refptr<Layer> parent = Layer::create(); 243 scoped_refptr<Layer> parent = Layer::create();
239 scoped_refptr<Layer> child = Layer::create(); 244 scoped_refptr<Layer> child = Layer::create();
240 scoped_refptr<Layer> grandChild = Layer::create(); 245 scoped_refptr<Layer> grandChild = Layer::create();
246 root->addChild(parent);
241 parent->addChild(child); 247 parent->addChild(child);
242 child->addChild(grandChild); 248 child->addChild(grandChild);
243 249
250 // One-time setup of root layer
251 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(1, 2), false);
252
244 // Case 1: parent's anchorPoint should not affect child or grandChild. 253 // Case 1: parent's anchorPoint should not affect child or grandChild.
245 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 254 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
246 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 255 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
247 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false); 256 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
248 executeCalculateDrawTransformsAndVisibility(parent.get()); 257 executeCalculateDrawTransformsAndVisibility(root.get());
249 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); 258 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
250 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( )); 259 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( ));
251 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ; 260 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ;
252 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form()); 261 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form());
253 262
254 // Case 2: parent's position affects child and grandChild. 263 // Case 2: parent's position affects child and grandChild.
255 WebTransformationMatrix parentPositionTransform; 264 WebTransformationMatrix parentPositionTransform;
256 parentPositionTransform.translate(0, 1.2); 265 parentPositionTransform.translate(0, 1.2);
257 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0.25, 0.25), FloatPoint(0, 1.2f), IntSize(10, 12), false); 266 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0.25, 0.25), FloatPoint(0, 1.2f), IntSize(10, 12), false);
258 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 267 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
259 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false); 268 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
260 executeCalculateDrawTransformsAndVisibility(parent.get()); 269 executeCalculateDrawTransformsAndVisibility(root.get());
261 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->drawTransfor m()); 270 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->drawTransfor m());
262 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->screenSpaceT ransform()); 271 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->screenSpaceT ransform());
263 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->drawTra nsform()); 272 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->drawTra nsform());
264 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->screenS paceTransform()); 273 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->screenS paceTransform());
265 274
266 // Case 3: parent's local transform affects child and grandchild 275 // Case 3: parent's local transform affects child and grandchild
267 WebTransformationMatrix parentLayerTransform; 276 WebTransformationMatrix parentLayerTransform;
268 parentLayerTransform.scale3d(2, 2, 1); 277 parentLayerTransform.scale3d(2, 2, 1);
269 WebTransformationMatrix parentTranslationToAnchor; 278 WebTransformationMatrix parentTranslationToAnchor;
270 parentTranslationToAnchor.translate(2.5, 3); 279 parentTranslationToAnchor.translate(2.5, 3);
271 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse(); 280 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse();
272 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, identityMat rix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 281 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, identityMat rix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
273 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 282 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
274 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false); 283 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
275 executeCalculateDrawTransformsAndVisibility(parent.get()); 284 executeCalculateDrawTransformsAndVisibility(root.get());
276 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm()); 285 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm());
277 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 286 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
278 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr ansform()); 287 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr ansform());
279 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen SpaceTransform()); 288 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen SpaceTransform());
280 289
281 // Case 4: parent's sublayerMatrix affects child and grandchild 290 // Case 4: parent's sublayerMatrix affects child and grandchild
282 // scaling is used here again so that the correct sequence of transf orms is properly tested. 291 // scaling is used here again so that the correct sequence of transf orms is properly tested.
283 // Note that preserves3D is false, but the sublayer matrix should re tain its 3D properties when given to child. 292 // Note that preserves3D is false, but the sublayer matrix should re tain its 3D properties when given to child.
284 // But then, the child also does not preserve3D. When it gives its h ierarchy to the grandChild, it should be flattened to 2D. 293 // But then, the child also does not preserve3D. When it gives its h ierarchy to the grandChild, it should be flattened to 2D.
285 WebTransformationMatrix parentSublayerMatrix; 294 WebTransformationMatrix parentSublayerMatrix;
286 parentSublayerMatrix.scale3d(10, 10, 3.3); 295 parentSublayerMatrix.scale3d(10, 10, 3.3);
287 WebTransformationMatrix parentTranslationToCenter; 296 WebTransformationMatrix parentTranslationToCenter;
288 parentTranslationToCenter.translate(5, 6); 297 parentTranslationToCenter.translate(5, 6);
289 // Sublayer matrix is applied to the center of the parent layer. 298 // Sublayer matrix is applied to the center of the parent layer.
290 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse() 299 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
291 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse(); 300 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse();
292 WebTransformationMatrix flattenedCompositeTransform = remove3DComponentOfMat rix(parentCompositeTransform); 301 WebTransformationMatrix flattenedCompositeTransform = remove3DComponentOfMat rix(parentCompositeTransform);
293 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 302 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
294 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 303 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
295 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false); 304 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
296 executeCalculateDrawTransformsAndVisibility(parent.get()); 305 executeCalculateDrawTransformsAndVisibility(root.get());
297 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm()); 306 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm());
298 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 307 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
299 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->dra wTransform()); 308 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->dra wTransform());
300 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->scr eenSpaceTransform()); 309 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->scr eenSpaceTransform());
301 310
302 // Case 5: same as Case 4, except that child does preserve 3D, so the grandC hild should receive the non-flattened composite transform. 311 // Case 5: same as Case 4, except that child does preserve 3D, so the grandC hild should receive the non-flattened composite transform.
303 // 312 //
304 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 313 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
305 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), true); 314 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), true);
306 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false); 315 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
307 executeCalculateDrawTransformsAndVisibility(parent.get()); 316 executeCalculateDrawTransformsAndVisibility(root.get());
308 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm()); 317 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm());
309 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 318 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
310 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr ansform()); 319 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr ansform());
311 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen SpaceTransform()); 320 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen SpaceTransform());
312 } 321 }
313 322
314 TEST(LayerTreeHostCommonTest, verifyTransformsForSingleRenderSurface) 323 TEST(LayerTreeHostCommonTest, verifyTransformsForSingleRenderSurface)
315 { 324 {
325 scoped_refptr<Layer> root = Layer::create();
316 scoped_refptr<Layer> parent = Layer::create(); 326 scoped_refptr<Layer> parent = Layer::create();
317 scoped_refptr<Layer> child = Layer::create(); 327 scoped_refptr<Layer> child = Layer::create();
318 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent()); 328 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent());
329 root->addChild(parent);
319 parent->addChild(child); 330 parent->addChild(child);
320 child->addChild(grandChild); 331 child->addChild(grandChild);
321 332
333 // One-time setup of root layer
334 WebTransformationMatrix identityMatrix;
335 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(1, 2), false);
336
322 // Child is set up so that a new render surface should be created. 337 // Child is set up so that a new render surface should be created.
323 child->setOpacity(0.5); 338 child->setOpacity(0.5);
324 339
325 WebTransformationMatrix identityMatrix;
326 WebTransformationMatrix parentLayerTransform; 340 WebTransformationMatrix parentLayerTransform;
327 parentLayerTransform.scale3d(1, 0.9, 1); 341 parentLayerTransform.scale3d(1, 0.9, 1);
328 WebTransformationMatrix parentTranslationToAnchor; 342 WebTransformationMatrix parentTranslationToAnchor;
329 parentTranslationToAnchor.translate(25, 30); 343 parentTranslationToAnchor.translate(25, 30);
330 WebTransformationMatrix parentSublayerMatrix; 344 WebTransformationMatrix parentSublayerMatrix;
331 parentSublayerMatrix.scale3d(0.9, 1, 3.3); 345 parentSublayerMatrix.scale3d(0.9, 1, 3.3);
332 WebTransformationMatrix parentTranslationToCenter; 346 WebTransformationMatrix parentTranslationToCenter;
333 parentTranslationToCenter.translate(50, 60); 347 parentTranslationToCenter.translate(50, 60);
334 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse() 348 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
335 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse(); 349 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse();
336 FloatPoint parentCompositeScale = MathUtil::computeTransform2dScaleComponent s(parentCompositeTransform); 350 FloatPoint parentCompositeScale = MathUtil::computeTransform2dScaleComponent s(parentCompositeTransform);
337 WebTransformationMatrix surfaceSublayerTransform; 351 WebTransformationMatrix surfaceSublayerTransform;
338 surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCom positeScale.y()); 352 surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCom positeScale.y());
339 WebTransformationMatrix surfaceSublayerCompositeTransform = parentCompositeT ransform * surfaceSublayerTransform.inverse(); 353 WebTransformationMatrix surfaceSublayerCompositeTransform = parentCompositeT ransform * surfaceSublayerTransform.inverse();
340 354
341 // Child's render surface should not exist yet. 355 // Child's render surface should not exist yet.
342 ASSERT_FALSE(child->renderSurface()); 356 ASSERT_FALSE(child->renderSurface());
343 357
344 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(100, 120), false); 358 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(100, 120), false);
345 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 359 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
346 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(8, 10), false); 360 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(8, 10), false);
347 executeCalculateDrawTransformsAndVisibility(parent.get()); 361 executeCalculateDrawTransformsAndVisibility(root.get());
348 362
349 // Render surface should have been created now. 363 // Render surface should have been created now.
350 ASSERT_TRUE(child->renderSurface()); 364 ASSERT_TRUE(child->renderSurface());
351 ASSERT_EQ(child, child->renderTarget()); 365 ASSERT_EQ(child, child->renderTarget());
352 366
353 // The child layer's draw transform should refer to its new render surface. 367 // The child layer's draw transform should refer to its new render surface.
354 // The screen-space transform, however, should still refer to the root. 368 // The screen-space transform, however, should still refer to the root.
355 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerTransform, child->drawTransfo rm()); 369 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerTransform, child->drawTransfo rm());
356 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 370 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
357 371
358 // Because the grandChild is the only drawable content, the child's renderSu rface will tighten its bounds to the grandChild. 372 // Because the grandChild is the only drawable content, the child's renderSu rface will tighten its bounds to the grandChild.
359 // The scale at which the surface's subtree is drawn must be removed from th e composite transform. 373 // The scale at which the surface's subtree is drawn must be removed from th e composite transform.
360 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re nderTarget()->renderSurface()->drawTransform()); 374 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re nderTarget()->renderSurface()->drawTransform());
361 375
362 // The screen space is the same as the target since the child surface draws into the root. 376 // The screen space is the same as the target since the child surface draws into the root.
363 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re nderTarget()->renderSurface()->screenSpaceTransform()); 377 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->re nderTarget()->renderSurface()->screenSpaceTransform());
364 } 378 }
365 379
366 TEST(LayerTreeHostCommonTest, verifyTransformsForReplica) 380 TEST(LayerTreeHostCommonTest, verifyTransformsForReplica)
367 { 381 {
382 scoped_refptr<Layer> root = Layer::create();
368 scoped_refptr<Layer> parent = Layer::create(); 383 scoped_refptr<Layer> parent = Layer::create();
369 scoped_refptr<Layer> child = Layer::create(); 384 scoped_refptr<Layer> child = Layer::create();
370 scoped_refptr<Layer> childReplica = Layer::create(); 385 scoped_refptr<Layer> childReplica = Layer::create();
371 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent()); 386 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent());
387 root->addChild(parent);
372 parent->addChild(child); 388 parent->addChild(child);
373 child->addChild(grandChild); 389 child->addChild(grandChild);
374 child->setReplicaLayer(childReplica.get()); 390 child->setReplicaLayer(childReplica.get());
375 391
392 // One-time setup of root layer
393 WebTransformationMatrix identityMatrix;
394 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(1, 2), false);
395
376 // Child is set up so that a new render surface should be created. 396 // Child is set up so that a new render surface should be created.
377 child->setOpacity(0.5); 397 child->setOpacity(0.5);
378 398
379 WebTransformationMatrix identityMatrix;
380 WebTransformationMatrix parentLayerTransform; 399 WebTransformationMatrix parentLayerTransform;
381 parentLayerTransform.scale3d(2, 2, 1); 400 parentLayerTransform.scale3d(2, 2, 1);
382 WebTransformationMatrix parentTranslationToAnchor; 401 WebTransformationMatrix parentTranslationToAnchor;
383 parentTranslationToAnchor.translate(2.5, 3); 402 parentTranslationToAnchor.translate(2.5, 3);
384 WebTransformationMatrix parentSublayerMatrix; 403 WebTransformationMatrix parentSublayerMatrix;
385 parentSublayerMatrix.scale3d(10, 10, 3.3); 404 parentSublayerMatrix.scale3d(10, 10, 3.3);
386 WebTransformationMatrix parentTranslationToCenter; 405 WebTransformationMatrix parentTranslationToCenter;
387 parentTranslationToCenter.translate(5, 6); 406 parentTranslationToCenter.translate(5, 6);
388 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse() 407 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
389 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse(); 408 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse();
390 WebTransformationMatrix childTranslationToCenter; 409 WebTransformationMatrix childTranslationToCenter;
391 childTranslationToCenter.translate(8, 9); 410 childTranslationToCenter.translate(8, 9);
392 WebTransformationMatrix replicaLayerTransform; 411 WebTransformationMatrix replicaLayerTransform;
393 replicaLayerTransform.scale3d(3, 3, 1); 412 replicaLayerTransform.scale3d(3, 3, 1);
394 FloatPoint parentCompositeScale = MathUtil::computeTransform2dScaleComponent s(parentCompositeTransform); 413 FloatPoint parentCompositeScale = MathUtil::computeTransform2dScaleComponent s(parentCompositeTransform);
395 WebTransformationMatrix surfaceSublayerTransform; 414 WebTransformationMatrix surfaceSublayerTransform;
396 surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCom positeScale.y()); 415 surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCom positeScale.y());
397 WebTransformationMatrix replicaCompositeTransform = parentCompositeTransform * replicaLayerTransform * surfaceSublayerTransform.inverse(); 416 WebTransformationMatrix replicaCompositeTransform = parentCompositeTransform * replicaLayerTransform * surfaceSublayerTransform.inverse();
398 417
399 // Child's render surface should not exist yet. 418 // Child's render surface should not exist yet.
400 ASSERT_FALSE(child->renderSurface()); 419 ASSERT_FALSE(child->renderSurface());
401 420
402 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 421 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
403 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 422 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
404 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(-0.5, -0.5), IntSize(1, 1), false); 423 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(-0.5, -0.5), IntSize(1, 1), false);
405 setLayerPropertiesForTesting(childReplica.get(), replicaLayerTransform, iden tityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(0, 0), false); 424 setLayerPropertiesForTesting(childReplica.get(), replicaLayerTransform, iden tityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(0, 0), false);
406 executeCalculateDrawTransformsAndVisibility(parent.get()); 425 executeCalculateDrawTransformsAndVisibility(root.get());
407 426
408 // Render surface should have been created now. 427 // Render surface should have been created now.
409 ASSERT_TRUE(child->renderSurface()); 428 ASSERT_TRUE(child->renderSurface());
410 ASSERT_EQ(child, child->renderTarget()); 429 ASSERT_EQ(child, child->renderTarget());
411 430
412 EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarg et()->renderSurface()->replicaDrawTransform()); 431 EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarg et()->renderSurface()->replicaDrawTransform());
413 EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarg et()->renderSurface()->replicaScreenSpaceTransform()); 432 EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarg et()->renderSurface()->replicaScreenSpaceTransform());
414 } 433 }
415 434
416 TEST(LayerTreeHostCommonTest, verifyTransformsForRenderSurfaceHierarchy) 435 TEST(LayerTreeHostCommonTest, verifyTransformsForRenderSurfaceHierarchy)
417 { 436 {
418 // This test creates a more complex tree and verifies it all at once. This c overs the following cases: 437 // This test creates a more complex tree and verifies it all at once. This c overs the following cases:
419 // - layers that are described w.r.t. a render surface: should have draw t ransforms described w.r.t. that surface 438 // - layers that are described w.r.t. a render surface: should have draw t ransforms described w.r.t. that surface
420 // - A render surface described w.r.t. an ancestor render surface: should have a draw transform described w.r.t. that ancestor surface 439 // - A render surface described w.r.t. an ancestor render surface: should have a draw transform described w.r.t. that ancestor surface
421 // - Replicas of a render surface are described w.r.t. the replica's trans form around its anchor, along with the surface itself. 440 // - Replicas of a render surface are described w.r.t. the replica's trans form around its anchor, along with the surface itself.
422 // - Sanity check on recursion: verify transforms of layers described w.r. t. a render surface that is described w.r.t. an ancestor render surface. 441 // - Sanity check on recursion: verify transforms of layers described w.r. t. a render surface that is described w.r.t. an ancestor render surface.
423 // - verifying that each layer has a reference to the correct renderSurfac e and renderTarget values. 442 // - verifying that each layer has a reference to the correct renderSurfac e and renderTarget values.
424 443
444 scoped_refptr<Layer> root = Layer::create();
425 scoped_refptr<Layer> parent = Layer::create(); 445 scoped_refptr<Layer> parent = Layer::create();
426 scoped_refptr<Layer> renderSurface1 = Layer::create(); 446 scoped_refptr<Layer> renderSurface1 = Layer::create();
427 scoped_refptr<Layer> renderSurface2 = Layer::create(); 447 scoped_refptr<Layer> renderSurface2 = Layer::create();
428 scoped_refptr<Layer> childOfRoot = Layer::create(); 448 scoped_refptr<Layer> childOfRoot = Layer::create();
429 scoped_refptr<Layer> childOfRS1 = Layer::create(); 449 scoped_refptr<Layer> childOfRS1 = Layer::create();
430 scoped_refptr<Layer> childOfRS2 = Layer::create(); 450 scoped_refptr<Layer> childOfRS2 = Layer::create();
431 scoped_refptr<Layer> replicaOfRS1 = Layer::create(); 451 scoped_refptr<Layer> replicaOfRS1 = Layer::create();
432 scoped_refptr<Layer> replicaOfRS2 = Layer::create(); 452 scoped_refptr<Layer> replicaOfRS2 = Layer::create();
433 scoped_refptr<Layer> grandChildOfRoot = Layer::create(); 453 scoped_refptr<Layer> grandChildOfRoot = Layer::create();
434 scoped_refptr<LayerWithForcedDrawsContent> grandChildOfRS1 = make_scoped_ref ptr(new LayerWithForcedDrawsContent()); 454 scoped_refptr<LayerWithForcedDrawsContent> grandChildOfRS1 = make_scoped_ref ptr(new LayerWithForcedDrawsContent());
435 scoped_refptr<LayerWithForcedDrawsContent> grandChildOfRS2 = make_scoped_ref ptr(new LayerWithForcedDrawsContent()); 455 scoped_refptr<LayerWithForcedDrawsContent> grandChildOfRS2 = make_scoped_ref ptr(new LayerWithForcedDrawsContent());
456 root->addChild(parent);
436 parent->addChild(renderSurface1); 457 parent->addChild(renderSurface1);
437 parent->addChild(childOfRoot); 458 parent->addChild(childOfRoot);
438 renderSurface1->addChild(childOfRS1); 459 renderSurface1->addChild(childOfRS1);
439 renderSurface1->addChild(renderSurface2); 460 renderSurface1->addChild(renderSurface2);
440 renderSurface2->addChild(childOfRS2); 461 renderSurface2->addChild(childOfRS2);
441 childOfRoot->addChild(grandChildOfRoot); 462 childOfRoot->addChild(grandChildOfRoot);
442 childOfRS1->addChild(grandChildOfRS1); 463 childOfRS1->addChild(grandChildOfRS1);
443 childOfRS2->addChild(grandChildOfRS2); 464 childOfRS2->addChild(grandChildOfRS2);
444 renderSurface1->setReplicaLayer(replicaOfRS1.get()); 465 renderSurface1->setReplicaLayer(replicaOfRS1.get());
445 renderSurface2->setReplicaLayer(replicaOfRS2.get()); 466 renderSurface2->setReplicaLayer(replicaOfRS2.get());
446 467
447 // In combination with descendantDrawsContent, opacity != 1 forces the layer to have a new renderSurface. 468 // In combination with descendantDrawsContent, opacity != 1 forces the layer to have a new renderSurface.
448 renderSurface1->setOpacity(0.5); 469 renderSurface1->setOpacity(0.5);
449 renderSurface2->setOpacity(0.33f); 470 renderSurface2->setOpacity(0.33f);
450 471
472 // One-time setup of root layer
473 WebTransformationMatrix identityMatrix;
474 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(1, 2), false);
475
451 // All layers in the tree are initialized with an anchor at .25 and a size o f (10,10). 476 // All layers in the tree are initialized with an anchor at .25 and a size o f (10,10).
452 // matrix "A" is the composite layer transform used in all layers, centered about the anchor point 477 // matrix "A" is the composite layer transform used in all layers, centered about the anchor point
453 // matrix "B" is the sublayer transform used in all layers, centered about t he center position of the layer. 478 // matrix "B" is the sublayer transform used in all layers, centered about t he center position of the layer.
454 // matrix "R" is the composite replica transform used in all replica layers. 479 // matrix "R" is the composite replica transform used in all replica layers.
455 // 480 //
456 // x component tests that layerTransform and sublayerTransform are done in t he right order (translation and scale are noncommutative). 481 // x component tests that layerTransform and sublayerTransform are done in t he right order (translation and scale are noncommutative).
457 // y component has a translation by 1 for every ancestor, which indicates th e "depth" of the layer in the hierarchy. 482 // y component has a translation by 1 for every ancestor, which indicates th e "depth" of the layer in the hierarchy.
458 WebTransformationMatrix translationToAnchor; 483 WebTransformationMatrix translationToAnchor;
459 translationToAnchor.translate(2.5, 0); 484 translationToAnchor.translate(2.5, 0);
460 WebTransformationMatrix translationToCenter; 485 WebTransformationMatrix translationToCenter;
461 translationToCenter.translate(5, 5); 486 translationToCenter.translate(5, 5);
462 WebTransformationMatrix layerTransform; 487 WebTransformationMatrix layerTransform;
463 layerTransform.translate(1, 1); 488 layerTransform.translate(1, 1);
464 WebTransformationMatrix sublayerTransform; 489 WebTransformationMatrix sublayerTransform;
465 sublayerTransform.scale3d(10, 1, 1); 490 sublayerTransform.scale3d(10, 1, 1);
466 WebTransformationMatrix replicaLayerTransform; 491 WebTransformationMatrix replicaLayerTransform;
467 replicaLayerTransform.scale3d(-2, 5, 1); 492 replicaLayerTransform.scale3d(-2, 5, 1);
468 493
469 WebTransformationMatrix A = translationToAnchor * layerTransform * translati onToAnchor.inverse(); 494 WebTransformationMatrix A = translationToAnchor * layerTransform * translati onToAnchor.inverse();
470 WebTransformationMatrix B = translationToCenter * sublayerTransform * transl ationToCenter.inverse(); 495 WebTransformationMatrix B = translationToCenter * sublayerTransform * transl ationToCenter.inverse();
471 WebTransformationMatrix R = A * translationToAnchor * replicaLayerTransform * translationToAnchor.inverse(); 496 WebTransformationMatrix R = A * translationToAnchor * replicaLayerTransform * translationToAnchor.inverse();
472 WebTransformationMatrix identityMatrix;
473 497
474 FloatPoint surface1ParentTransformScale = MathUtil::computeTransform2dScaleC omponents(A * B); 498 FloatPoint surface1ParentTransformScale = MathUtil::computeTransform2dScaleC omponents(A * B);
475 WebTransformationMatrix surface1SublayerTransform; 499 WebTransformationMatrix surface1SublayerTransform;
476 surface1SublayerTransform.scaleNonUniform(surface1ParentTransformScale.x(), surface1ParentTransformScale.y()); 500 surface1SublayerTransform.scaleNonUniform(surface1ParentTransformScale.x(), surface1ParentTransformScale.y());
477 501
478 // SS1 = transform given to the subtree of renderSurface1 502 // SS1 = transform given to the subtree of renderSurface1
479 WebTransformationMatrix SS1 = surface1SublayerTransform; 503 WebTransformationMatrix SS1 = surface1SublayerTransform;
480 // S1 = transform to move from renderSurface1 pixels to the layer space of t he owning layer 504 // S1 = transform to move from renderSurface1 pixels to the layer space of t he owning layer
481 WebTransformationMatrix S1 = surface1SublayerTransform.inverse(); 505 WebTransformationMatrix S1 = surface1SublayerTransform.inverse();
482 506
(...skipping 11 matching lines...) Expand all
494 setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerT ransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 518 setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerT ransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
495 setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTran sform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 519 setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTran sform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
496 setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTrans form, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 520 setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTrans form, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
497 setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTrans form, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 521 setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTrans form, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
498 setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublaye rTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 522 setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublaye rTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
499 setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayer Transform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 523 setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayer Transform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
500 setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayer Transform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 524 setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayer Transform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
501 setLayerPropertiesForTesting(replicaOfRS1.get(), replicaLayerTransform, subl ayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(), false); 525 setLayerPropertiesForTesting(replicaOfRS1.get(), replicaLayerTransform, subl ayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(), false);
502 setLayerPropertiesForTesting(replicaOfRS2.get(), replicaLayerTransform, subl ayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(), false); 526 setLayerPropertiesForTesting(replicaOfRS2.get(), replicaLayerTransform, subl ayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(), false);
503 527
504 executeCalculateDrawTransformsAndVisibility(parent.get()); 528 executeCalculateDrawTransformsAndVisibility(root.get());
505 529
506 // Only layers that are associated with render surfaces should have an actua l renderSurface() value. 530 // Only layers that are associated with render surfaces should have an actua l renderSurface() value.
507 // 531 //
508 ASSERT_TRUE(parent->renderSurface()); 532 ASSERT_TRUE(root->renderSurface());
509 ASSERT_FALSE(childOfRoot->renderSurface()); 533 ASSERT_FALSE(childOfRoot->renderSurface());
510 ASSERT_FALSE(grandChildOfRoot->renderSurface()); 534 ASSERT_FALSE(grandChildOfRoot->renderSurface());
511 535
512 ASSERT_TRUE(renderSurface1->renderSurface()); 536 ASSERT_TRUE(renderSurface1->renderSurface());
513 ASSERT_FALSE(childOfRS1->renderSurface()); 537 ASSERT_FALSE(childOfRS1->renderSurface());
514 ASSERT_FALSE(grandChildOfRS1->renderSurface()); 538 ASSERT_FALSE(grandChildOfRS1->renderSurface());
515 539
516 ASSERT_TRUE(renderSurface2->renderSurface()); 540 ASSERT_TRUE(renderSurface2->renderSurface());
517 ASSERT_FALSE(childOfRS2->renderSurface()); 541 ASSERT_FALSE(childOfRS2->renderSurface());
518 ASSERT_FALSE(grandChildOfRS2->renderSurface()); 542 ASSERT_FALSE(grandChildOfRS2->renderSurface());
519 543
520 // Verify all renderTarget accessors 544 // Verify all renderTarget accessors
521 // 545 //
522 EXPECT_EQ(parent, parent->renderTarget()); 546 EXPECT_EQ(root, parent->renderTarget());
523 EXPECT_EQ(parent, childOfRoot->renderTarget()); 547 EXPECT_EQ(root, childOfRoot->renderTarget());
524 EXPECT_EQ(parent, grandChildOfRoot->renderTarget()); 548 EXPECT_EQ(root, grandChildOfRoot->renderTarget());
525 549
526 EXPECT_EQ(renderSurface1, renderSurface1->renderTarget()); 550 EXPECT_EQ(renderSurface1, renderSurface1->renderTarget());
527 EXPECT_EQ(renderSurface1, childOfRS1->renderTarget()); 551 EXPECT_EQ(renderSurface1, childOfRS1->renderTarget());
528 EXPECT_EQ(renderSurface1, grandChildOfRS1->renderTarget()); 552 EXPECT_EQ(renderSurface1, grandChildOfRS1->renderTarget());
529 553
530 EXPECT_EQ(renderSurface2, renderSurface2->renderTarget()); 554 EXPECT_EQ(renderSurface2, renderSurface2->renderTarget());
531 EXPECT_EQ(renderSurface2, childOfRS2->renderTarget()); 555 EXPECT_EQ(renderSurface2, childOfRS2->renderTarget());
532 EXPECT_EQ(renderSurface2, grandChildOfRS2->renderTarget()); 556 EXPECT_EQ(renderSurface2, grandChildOfRS2->renderTarget());
533 557
534 // Verify layer draw transforms 558 // Verify layer draw transforms
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 WebTransformationMatrix rotationByZ; 1314 WebTransformationMatrix rotationByZ;
1291 rotationByZ.rotate3d(0, 0, 90); 1315 rotationByZ.rotate3d(0, 0, 90);
1292 1316
1293 root->setTransform(rotationByZ); 1317 root->setTransform(rotationByZ);
1294 grandChild->setFixedToContainerLayer(true); 1318 grandChild->setFixedToContainerLayer(true);
1295 1319
1296 // Case 1: root scrollDelta of 0, 0 1320 // Case 1: root scrollDelta of 0, 0
1297 root->setScrollDelta(IntSize(0, 0)); 1321 root->setScrollDelta(IntSize(0, 0));
1298 executeCalculateDrawTransformsAndVisibility(root.get()); 1322 executeCalculateDrawTransformsAndVisibility(root.get());
1299 1323
1300 WebTransformationMatrix expectedChildTransform; 1324 WebTransformationMatrix identityMatrix;
1301 expectedChildTransform.multiply(rotationByZ);
1302 1325
1326 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
1327 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ;
1328
1329 // Case 2: root scrollDelta of 10, 10
1330 root->setScrollDelta(IntSize(10, 20));
1331 executeCalculateDrawTransformsAndVisibility(root.get());
1332
1333 // The child is affected by scrollDelta, but it is already implcitly account ed for by
1334 // the child's target surface (i.e. the root renderSurface). The grandChild is not
1335 // affected by the scrollDelta, so its drawTransform needs to explicitly
1336 // inverse-compensate for the scroll that's embedded in the target surface.
1303 WebTransformationMatrix expectedGrandChildTransform; 1337 WebTransformationMatrix expectedGrandChildTransform;
1338 expectedGrandChildTransform.multiply(rotationByZ.inverse());
1339 expectedGrandChildTransform.translate(10, 20); // explicit canceling out the scrollDelta that gets embedded in the fixed position layer's surface.
1304 expectedGrandChildTransform.multiply(rotationByZ); 1340 expectedGrandChildTransform.multiply(rotationByZ);
1305 1341
1306 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 1342 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
1307 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
1308
1309 // Case 2: root scrollDelta of 10, 10
1310 root->setScrollDelta(IntSize(10, 10));
1311 executeCalculateDrawTransformsAndVisibility(root.get());
1312
1313 // Here the child is affected by scrollDelta, but the fixed position grandCh ild should not be affected.
1314 expectedChildTransform.makeIdentity();
1315 expectedChildTransform.translate(-10, -10); // the scrollDelta
1316 expectedChildTransform.multiply(rotationByZ);
1317
1318 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
1319 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 1343 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
1320 } 1344 }
1321 1345
1322 TEST(LayerTreeHostCommonTest, verifyClipRectCullsRenderSurfaces) 1346 TEST(LayerTreeHostCommonTest, verifyClipRectCullsRenderSurfaces)
1323 { 1347 {
1324 // The entire subtree of layers that are outside the clipRect should be cull ed away, 1348 // The entire subtree of layers that are outside the clipRect should be cull ed away,
1325 // and should not affect the renderSurfaceLayerList. 1349 // and should not affect the renderSurfaceLayerList.
1326 // 1350 //
1327 // The test tree is set up as follows: 1351 // The test tree is set up as follows:
1328 // - all layers except the leafNodes are forced to be a new renderSurface t hat have something to draw. 1352 // - all layers except the leafNodes are forced to be a new renderSurface t hat have something to draw.
(...skipping 2535 matching lines...) Expand 10 before | Expand all | Expand 10 after
3864 int nonexistentId = -1; 3888 int nonexistentId = -1;
3865 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id ())); 3889 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id ()));
3866 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child-> id())); 3890 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child-> id()));
3867 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr andChild->id())); 3891 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr andChild->id()));
3868 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas kLayer->id())); 3892 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas kLayer->id()));
3869 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), replicaLayer->id())); 3893 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), replicaLayer->id()));
3870 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent Id)); 3894 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent Id));
3871 } 3895 }
3872 3896
3873 } // namespace 3897 } // namespace
OLDNEW
« no previous file with comments | « cc/layer_tree_host_common.cc ('k') | cc/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698