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

Side by Side Diff: cc/layer_tree_host_common_unittest.cc

Issue 11308153: Migrate most of cc/ from WebKit::WebTransformationMatrix to gfx::Transform (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | Annotate | Revision Log
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/layer_tree_host_common.h" 5 #include "cc/layer_tree_host_common.h"
6 6
7 #include "cc/content_layer.h" 7 #include "cc/content_layer.h"
8 #include "cc/content_layer_client.h" 8 #include "cc/content_layer_client.h"
9 #include "cc/layer.h" 9 #include "cc/layer.h"
10 #include "cc/layer_animation_controller.h" 10 #include "cc/layer_animation_controller.h"
11 #include "cc/layer_impl.h" 11 #include "cc/layer_impl.h"
12 #include "cc/layer_sorter.h" 12 #include "cc/layer_sorter.h"
13 #include "cc/math_util.h" 13 #include "cc/math_util.h"
14 #include "cc/proxy.h" 14 #include "cc/proxy.h"
15 #include "cc/single_thread_proxy.h" 15 #include "cc/single_thread_proxy.h"
16 #include "cc/test/animation_test_common.h" 16 #include "cc/test/animation_test_common.h"
17 #include "cc/test/geometry_test_utils.h" 17 #include "cc/test/geometry_test_utils.h"
18 #include "cc/thread.h" 18 #include "cc/thread.h"
19 #include "ui/gfx/size_conversions.h" 19 #include "ui/gfx/size_conversions.h"
20 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include <public/WebTransformationMatrix.h> 22 #include "ui/gfx/transform.h"
23 23
24 using namespace WebKitTests; 24 using namespace WebKitTests;
25 using WebKit::WebTransformationMatrix; 25 using gfx::Transform;
26 26
27 namespace cc { 27 namespace cc {
28 namespace { 28 namespace {
29 29
30 template<typename LayerType> 30 template<typename LayerType>
31 void setLayerPropertiesForTestingInternal(LayerType* layer, const WebTransformat ionMatrix& transform, const WebTransformationMatrix& sublayerTransform, const gf x::PointF& anchor, const gfx::PointF& position, const gfx::Size& bounds, bool pr eserves3D) 31 void setLayerPropertiesForTestingInternal(LayerType* layer, const Transform& tra nsform, const Transform& sublayerTransform, const gfx::PointF& anchor, const gfx ::PointF& position, const gfx::Size& bounds, bool preserves3D)
32 { 32 {
33 layer->setTransform(transform); 33 layer->setTransform(transform);
34 layer->setSublayerTransform(sublayerTransform); 34 layer->setSublayerTransform(sublayerTransform);
35 layer->setAnchorPoint(anchor); 35 layer->setAnchorPoint(anchor);
36 layer->setPosition(position); 36 layer->setPosition(position);
37 layer->setBounds(bounds); 37 layer->setBounds(bounds);
38 layer->setPreserves3D(preserves3D); 38 layer->setPreserves3D(preserves3D);
39 } 39 }
40 40
41 void setLayerPropertiesForTesting(Layer* layer, const WebTransformationMatrix& t ransform, const WebTransformationMatrix& sublayerTransform, const gfx::PointF& a nchor, const gfx::PointF& position, const gfx::Size& bounds, bool preserves3D) 41 void setLayerPropertiesForTesting(Layer* layer, const Transform& transform, cons t Transform& sublayerTransform, const gfx::PointF& anchor, const gfx::PointF& po sition, const gfx::Size& bounds, bool preserves3D)
42 { 42 {
43 setLayerPropertiesForTestingInternal<Layer>(layer, transform, sublayerTransf orm, anchor, position, bounds, preserves3D); 43 setLayerPropertiesForTestingInternal<Layer>(layer, transform, sublayerTransf orm, anchor, position, bounds, preserves3D);
44 layer->setAutomaticallyComputeRasterScale(true); 44 layer->setAutomaticallyComputeRasterScale(true);
45 } 45 }
46 46
47 void setLayerPropertiesForTesting(LayerImpl* layer, const WebTransformationMatri x& transform, const WebTransformationMatrix& sublayerTransform, const gfx::Point F& anchor, const gfx::PointF& position, const gfx::Size& bounds, bool preserves3 D) 47 void setLayerPropertiesForTesting(LayerImpl* layer, const Transform& transform, const Transform& sublayerTransform, const gfx::PointF& anchor, const gfx::PointF & position, const gfx::Size& bounds, bool preserves3D)
48 { 48 {
49 setLayerPropertiesForTestingInternal<LayerImpl>(layer, transform, sublayerTr ansform, anchor, position, bounds, preserves3D); 49 setLayerPropertiesForTestingInternal<LayerImpl>(layer, transform, sublayerTr ansform, anchor, position, bounds, preserves3D);
50 layer->setContentBounds(bounds); 50 layer->setContentBounds(bounds);
51 } 51 }
52 52
53 void executeCalculateDrawTransformsAndVisibility(Layer* rootLayer, float deviceS caleFactor = 1, float pageScaleFactor = 1) 53 void executeCalculateDrawTransformsAndVisibility(Layer* rootLayer, float deviceS caleFactor = 1, float pageScaleFactor = 1)
54 { 54 {
55 WebTransformationMatrix identityMatrix; 55 Transform identityMatrix;
56 std::vector<scoped_refptr<Layer> > dummyRenderSurfaceLayerList; 56 std::vector<scoped_refptr<Layer> > dummyRenderSurfaceLayerList;
57 int dummyMaxTextureSize = 512; 57 int dummyMaxTextureSize = 512;
58 gfx::Size deviceViewportSize = gfx::Size(rootLayer->bounds().width() * devic eScaleFactor, rootLayer->bounds().height() * deviceScaleFactor); 58 gfx::Size deviceViewportSize = gfx::Size(rootLayer->bounds().width() * devic eScaleFactor, rootLayer->bounds().height() * deviceScaleFactor);
59 59
60 // We are probably not testing what is intended if the rootLayer bounds are empty. 60 // We are probably not testing what is intended if the rootLayer bounds are empty.
61 DCHECK(!rootLayer->bounds().IsEmpty()); 61 DCHECK(!rootLayer->bounds().IsEmpty());
62 LayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, dummyRenderSurfaceLayer List); 62 LayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, dummyRenderSurfaceLayer List);
63 } 63 }
64 64
65 void executeCalculateDrawTransformsAndVisibility(LayerImpl* rootLayer, float dev iceScaleFactor = 1, float pageScaleFactor = 1) 65 void executeCalculateDrawTransformsAndVisibility(LayerImpl* rootLayer, float dev iceScaleFactor = 1, float pageScaleFactor = 1)
66 { 66 {
67 // Note: this version skips layer sorting. 67 // Note: this version skips layer sorting.
68 68
69 WebTransformationMatrix identityMatrix; 69 Transform identityMatrix;
70 std::vector<LayerImpl*> dummyRenderSurfaceLayerList; 70 std::vector<LayerImpl*> dummyRenderSurfaceLayerList;
71 int dummyMaxTextureSize = 512; 71 int dummyMaxTextureSize = 512;
72 gfx::Size deviceViewportSize = gfx::Size(rootLayer->bounds().width() * devic eScaleFactor, rootLayer->bounds().height() * deviceScaleFactor); 72 gfx::Size deviceViewportSize = gfx::Size(rootLayer->bounds().width() * devic eScaleFactor, rootLayer->bounds().height() * deviceScaleFactor);
73 73
74 // We are probably not testing what is intended if the rootLayer bounds are empty. 74 // We are probably not testing what is intended if the rootLayer bounds are empty.
75 DCHECK(!rootLayer->bounds().IsEmpty()); 75 DCHECK(!rootLayer->bounds().IsEmpty());
76 LayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, pageScaleFactor, 0, dummyMaxTextureSize, dummyRenderSurfaceLa yerList); 76 LayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, pageScaleFactor, 0, dummyMaxTextureSize, dummyRenderSurfaceLa yerList);
77 } 77 }
78 78
79 WebTransformationMatrix remove3DComponentOfMatrix(const WebTransformationMatrix& mat) 79 Transform remove3DComponentOfMatrix(const Transform& mat)
80 { 80 {
81 WebTransformationMatrix ret = mat; 81 Transform ret = mat;
82 ret.setM13(0); 82 ret.matrix().setDouble(2, 0, 0);
83 ret.setM23(0); 83 ret.matrix().setDouble(2, 1, 0);
84 ret.setM31(0); 84 ret.matrix().setDouble(0, 2, 0);
85 ret.setM32(0); 85 ret.matrix().setDouble(1, 2, 0);
86 ret.setM33(1); 86 ret.matrix().setDouble(2, 2, 1);
87 ret.setM34(0); 87 ret.matrix().setDouble(3, 2, 0);
88 ret.setM43(0); 88 ret.matrix().setDouble(2, 3, 0);
89 return ret; 89 return ret;
90 } 90 }
91 91
92 scoped_ptr<LayerImpl> createTreeForFixedPositionTests() 92 scoped_ptr<LayerImpl> createTreeForFixedPositionTests()
93 { 93 {
94 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 94 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
95 scoped_ptr<LayerImpl> child = LayerImpl::create(2); 95 scoped_ptr<LayerImpl> child = LayerImpl::create(2);
96 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(3); 96 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(3);
97 scoped_ptr<LayerImpl> greatGrandChild = LayerImpl::create(4); 97 scoped_ptr<LayerImpl> greatGrandChild = LayerImpl::create(4);
98 98
99 WebTransformationMatrix IdentityMatrix; 99 Transform IdentityMatrix;
100 gfx::PointF anchor(0, 0); 100 gfx::PointF anchor(0, 0);
101 gfx::PointF position(0, 0); 101 gfx::PointF position(0, 0);
102 gfx::Size bounds(100, 100); 102 gfx::Size bounds(100, 100);
103 setLayerPropertiesForTesting(root.get(), IdentityMatrix, IdentityMatrix, anc hor, position, bounds, false); 103 setLayerPropertiesForTesting(root.get(), IdentityMatrix, IdentityMatrix, anc hor, position, bounds, false);
104 setLayerPropertiesForTesting(child.get(), IdentityMatrix, IdentityMatrix, an chor, position, bounds, false); 104 setLayerPropertiesForTesting(child.get(), IdentityMatrix, IdentityMatrix, an chor, position, bounds, false);
105 setLayerPropertiesForTesting(grandChild.get(), IdentityMatrix, IdentityMatri x, anchor, position, bounds, false); 105 setLayerPropertiesForTesting(grandChild.get(), IdentityMatrix, IdentityMatri x, anchor, position, bounds, false);
106 setLayerPropertiesForTesting(greatGrandChild.get(), IdentityMatrix, Identity Matrix, anchor, position, bounds, false); 106 setLayerPropertiesForTesting(greatGrandChild.get(), IdentityMatrix, Identity Matrix, anchor, position, bounds, false);
107 107
108 grandChild->addChild(greatGrandChild.Pass()); 108 grandChild->addChild(greatGrandChild.Pass());
109 child->addChild(grandChild.Pass()); 109 child->addChild(grandChild.Pass());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // and with identity transforms, then the drawTransform, 153 // and with identity transforms, then the drawTransform,
154 // screenSpaceTransform, and the hierarchy passed on to children 154 // screenSpaceTransform, and the hierarchy passed on to children
155 // layers should also be identity transforms. 155 // layers should also be identity transforms.
156 156
157 scoped_refptr<Layer> parent = Layer::create(); 157 scoped_refptr<Layer> parent = Layer::create();
158 scoped_refptr<Layer> child = Layer::create(); 158 scoped_refptr<Layer> child = Layer::create();
159 scoped_refptr<Layer> grandChild = Layer::create(); 159 scoped_refptr<Layer> grandChild = Layer::create();
160 parent->addChild(child); 160 parent->addChild(child);
161 child->addChild(grandChild); 161 child->addChild(grandChild);
162 162
163 WebTransformationMatrix identityMatrix; 163 Transform identityMatrix;
164 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 164 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
165 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(0, 0), false); 165 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(0, 0), false);
166 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(0, 0), false); 166 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(0, 0), false);
167 167
168 executeCalculateDrawTransformsAndVisibility(parent.get()); 168 executeCalculateDrawTransformsAndVisibility(parent.get());
169 169
170 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); 170 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
171 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( )); 171 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( ));
172 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ; 172 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ;
173 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form()); 173 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form());
174 } 174 }
175 175
176 TEST(LayerTreeHostCommonTest, verifyTransformsForSingleLayer) 176 TEST(LayerTreeHostCommonTest, verifyTransformsForSingleLayer)
177 { 177 {
178 WebTransformationMatrix identityMatrix; 178 Transform identityMatrix;
179 scoped_refptr<Layer> layer = Layer::create(); 179 scoped_refptr<Layer> layer = Layer::create();
180 180
181 scoped_refptr<Layer> root = Layer::create(); 181 scoped_refptr<Layer> root = Layer::create();
182 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false); 182 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false);
183 root->addChild(layer); 183 root->addChild(layer);
184 184
185 // Case 1: setting the sublayer transform should not affect this layer's dra w transform or screen-space transform. 185 // Case 1: setting the sublayer transform should not affect this layer's dra w transform or screen-space transform.
186 WebTransformationMatrix arbitraryTranslation; 186 Transform arbitraryTranslation;
187 arbitraryTranslation.translate(10, 20); 187 arbitraryTranslation.PreconcatTranslate(10, 20);
188 setLayerPropertiesForTesting(layer.get(), identityMatrix, arbitraryTranslati on, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 188 setLayerPropertiesForTesting(layer.get(), identityMatrix, arbitraryTranslati on, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
189 executeCalculateDrawTransformsAndVisibility(root.get()); 189 executeCalculateDrawTransformsAndVisibility(root.get());
190 WebTransformationMatrix expectedDrawTransform = identityMatrix; 190 Transform expectedDrawTransform = identityMatrix;
191 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedDrawTransform, layer->drawTransform( )); 191 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedDrawTransform, layer->drawTransform( ));
192 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( )); 192 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( ));
193 193
194 // Case 2: Setting the bounds of the layer should not affect either the draw transform or the screenspace transform. 194 // Case 2: Setting the bounds of the layer should not affect either the draw transform or the screenspace transform.
195 WebTransformationMatrix translationToCenter; 195 Transform translationToCenter;
196 translationToCenter.translate(5, 6); 196 translationToCenter.PreconcatTranslate(5, 6);
197 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 12), false); 197 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 12), false);
198 executeCalculateDrawTransformsAndVisibility(root.get()); 198 executeCalculateDrawTransformsAndVisibility(root.get());
199 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform()); 199 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform());
200 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( )); 200 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( ));
201 201
202 // Case 3: The anchor point by itself (without a layer transform) should hav e no effect on the transforms. 202 // Case 3: The anchor point by itself (without a layer transform) should hav e no effect on the transforms.
203 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, gf x::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false); 203 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, gf x::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false);
204 executeCalculateDrawTransformsAndVisibility(root.get()); 204 executeCalculateDrawTransformsAndVisibility(root.get());
205 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform()); 205 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform());
206 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( )); 206 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( ));
207 207
208 // Case 4: A change in actual position affects both the draw transform and s creen space transform. 208 // Case 4: A change in actual position affects both the draw transform and s creen space transform.
209 WebTransformationMatrix positionTransform; 209 Transform positionTransform;
210 positionTransform.translate(0, 1.2); 210 positionTransform.PreconcatTranslate(0, 1.2);
211 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, gf x::PointF(0.25, 0.25), gfx::PointF(0, 1.2f), gfx::Size(10, 12), false); 211 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, gf x::PointF(0.25, 0.25), gfx::PointF(0, 1.2f), gfx::Size(10, 12), false);
212 executeCalculateDrawTransformsAndVisibility(root.get()); 212 executeCalculateDrawTransformsAndVisibility(root.get());
213 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->drawTransform()); 213 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->drawTransform());
214 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->screenSpaceTransfo rm()); 214 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->screenSpaceTransfo rm());
215 215
216 // Case 5: In the correct sequence of transforms, the layer transform should pre-multiply the translationToCenter. This is easily tested by 216 // Case 5: In the correct sequence of transforms, the layer transform should pre-multiply the translationToCenter. This is easily tested by
217 // using a scale transform, because scale and translation are not co mmutative. 217 // using a scale transform, because scale and translation are not co mmutative.
218 WebTransformationMatrix layerTransform; 218 Transform layerTransform;
219 layerTransform.scale3d(2, 2, 1); 219 layerTransform.PreconcatScale3d(2, 2, 1);
220 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 12), false); 220 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 12), false);
221 executeCalculateDrawTransformsAndVisibility(root.get()); 221 executeCalculateDrawTransformsAndVisibility(root.get());
222 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->drawTransform()); 222 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->drawTransform());
223 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->screenSpaceTransform( )); 223 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->screenSpaceTransform( ));
224 224
225 // Case 6: The layer transform should occur with respect to the anchor point . 225 // Case 6: The layer transform should occur with respect to the anchor point .
226 WebTransformationMatrix translationToAnchor; 226 Transform translationToAnchor;
227 translationToAnchor.translate(5, 0); 227 translationToAnchor.PreconcatTranslate(5, 0);
228 WebTransformationMatrix expectedResult = translationToAnchor * layerTransfor m * translationToAnchor.inverse(); 228 Transform expectedResult = translationToAnchor * layerTransform * MathUtil:: inverse(translationToAnchor);
229 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, gf x::PointF(0.5, 0), gfx::PointF(0, 0), gfx::Size(10, 12), false); 229 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, gf x::PointF(0.5, 0), gfx::PointF(0, 0), gfx::Size(10, 12), false);
230 executeCalculateDrawTransformsAndVisibility(root.get()); 230 executeCalculateDrawTransformsAndVisibility(root.get());
231 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform()); 231 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform());
232 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform( )); 232 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform( ));
233 233
234 // Case 7: Verify that position pre-multiplies the layer transform. 234 // Case 7: Verify that position pre-multiplies the layer transform.
235 // The current implementation of calculateDrawTransforms does this i mplicitly, but it is 235 // The current implementation of calculateDrawTransforms does this i mplicitly, but it is
236 // still worth testing to detect accidental regressions. 236 // still worth testing to detect accidental regressions.
237 expectedResult = positionTransform * translationToAnchor * layerTransform * translationToAnchor.inverse(); 237 expectedResult = positionTransform * translationToAnchor * layerTransform * MathUtil::inverse(translationToAnchor);
238 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, gf x::PointF(0.5, 0), gfx::PointF(0, 1.2f), gfx::Size(10, 12), false); 238 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, gf x::PointF(0.5, 0), gfx::PointF(0, 1.2f), gfx::Size(10, 12), false);
239 executeCalculateDrawTransformsAndVisibility(root.get()); 239 executeCalculateDrawTransformsAndVisibility(root.get());
240 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform()); 240 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform());
241 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform( )); 241 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform( ));
242 } 242 }
243 243
244 TEST(LayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy) 244 TEST(LayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy)
245 { 245 {
246 WebTransformationMatrix identityMatrix; 246 Transform identityMatrix;
247 scoped_refptr<Layer> root = Layer::create(); 247 scoped_refptr<Layer> root = Layer::create();
248 scoped_refptr<Layer> parent = Layer::create(); 248 scoped_refptr<Layer> parent = Layer::create();
249 scoped_refptr<Layer> child = Layer::create(); 249 scoped_refptr<Layer> child = Layer::create();
250 scoped_refptr<Layer> grandChild = Layer::create(); 250 scoped_refptr<Layer> grandChild = Layer::create();
251 root->addChild(parent); 251 root->addChild(parent);
252 parent->addChild(child); 252 parent->addChild(child);
253 child->addChild(grandChild); 253 child->addChild(grandChild);
254 254
255 // One-time setup of root layer 255 // One-time setup of root layer
256 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false); 256 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false);
257 257
258 // Case 1: parent's anchorPoint should not affect child or grandChild. 258 // Case 1: parent's anchorPoint should not affect child or grandChild.
259 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false); 259 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false);
260 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); 260 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
261 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false); 261 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false);
262 executeCalculateDrawTransformsAndVisibility(root.get()); 262 executeCalculateDrawTransformsAndVisibility(root.get());
263 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); 263 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
264 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( )); 264 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( ));
265 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ; 265 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ;
266 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form()); 266 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form());
267 267
268 // Case 2: parent's position affects child and grandChild. 268 // Case 2: parent's position affects child and grandChild.
269 WebTransformationMatrix parentPositionTransform; 269 Transform parentPositionTransform;
270 parentPositionTransform.translate(0, 1.2); 270 parentPositionTransform.PreconcatTranslate(0, 1.2);
271 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0.25, 0.25), gfx::PointF(0, 1.2f), gfx::Size(10, 12), false); 271 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0.25, 0.25), gfx::PointF(0, 1.2f), gfx::Size(10, 12), false);
272 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); 272 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
273 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false); 273 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false);
274 executeCalculateDrawTransformsAndVisibility(root.get()); 274 executeCalculateDrawTransformsAndVisibility(root.get());
275 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->drawTransfor m()); 275 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->drawTransfor m());
276 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->screenSpaceT ransform()); 276 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->screenSpaceT ransform());
277 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->drawTra nsform()); 277 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->drawTra nsform());
278 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->screenS paceTransform()); 278 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->screenS paceTransform());
279 279
280 // Case 3: parent's local transform affects child and grandchild 280 // Case 3: parent's local transform affects child and grandchild
281 WebTransformationMatrix parentLayerTransform; 281 Transform parentLayerTransform;
282 parentLayerTransform.scale3d(2, 2, 1); 282 parentLayerTransform.PreconcatScale3d(2, 2, 1);
283 WebTransformationMatrix parentTranslationToAnchor; 283 Transform parentTranslationToAnchor;
284 parentTranslationToAnchor.translate(2.5, 3); 284 parentTranslationToAnchor.PreconcatTranslate(2.5, 3);
285 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse(); 285 Transform parentCompositeTransform = parentTranslationToAnchor * parentLayer Transform * MathUtil::inverse(parentTranslationToAnchor);
286 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, identityMat rix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false); 286 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, identityMat rix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false);
287 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); 287 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
288 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false); 288 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false);
289 executeCalculateDrawTransformsAndVisibility(root.get()); 289 executeCalculateDrawTransformsAndVisibility(root.get());
290 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm()); 290 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm());
291 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 291 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
292 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr ansform()); 292 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr ansform());
293 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen SpaceTransform()); 293 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen SpaceTransform());
294 294
295 // Case 4: parent's sublayerMatrix affects child and grandchild 295 // Case 4: parent's sublayerMatrix affects child and grandchild
296 // scaling is used here again so that the correct sequence of transf orms is properly tested. 296 // scaling is used here again so that the correct sequence of transf orms is properly tested.
297 // Note that preserves3D is false, but the sublayer matrix should re tain its 3D properties when given to child. 297 // Note that preserves3D is false, but the sublayer matrix should re tain its 3D properties when given to child.
298 // But then, the child also does not preserve3D. When it gives its h ierarchy to the grandChild, it should be flattened to 2D. 298 // But then, the child also does not preserve3D. When it gives its h ierarchy to the grandChild, it should be flattened to 2D.
299 WebTransformationMatrix parentSublayerMatrix; 299 Transform parentSublayerMatrix;
300 parentSublayerMatrix.scale3d(10, 10, 3.3); 300 parentSublayerMatrix.PreconcatScale3d(10, 10, 3.3);
301 WebTransformationMatrix parentTranslationToCenter; 301 Transform parentTranslationToCenter;
302 parentTranslationToCenter.translate(5, 6); 302 parentTranslationToCenter.PreconcatTranslate(5, 6);
303 // Sublayer matrix is applied to the center of the parent layer. 303 // Sublayer matrix is applied to the center of the parent layer.
304 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse() 304 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * MathUtil::inverse(parentTranslationToAnchor)
305 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse(); 305 * parentTranslationToCenter * parentSublayerMatrix * MathUtil::inver se(parentTranslationToCenter);
306 WebTransformationMatrix flattenedCompositeTransform = remove3DComponentOfMat rix(parentCompositeTransform); 306 Transform flattenedCompositeTransform = remove3DComponentOfMatrix(parentComp ositeTransform);
307 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false) ; 307 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false) ;
308 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); 308 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
309 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false); 309 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false);
310 executeCalculateDrawTransformsAndVisibility(root.get()); 310 executeCalculateDrawTransformsAndVisibility(root.get());
311 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm()); 311 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm());
312 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 312 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
313 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->dra wTransform()); 313 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->dra wTransform());
314 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->scr eenSpaceTransform()); 314 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->scr eenSpaceTransform());
315 315
316 // Case 5: same as Case 4, except that child does preserve 3D, so the grandC hild should receive the non-flattened composite transform. 316 // Case 5: same as Case 4, except that child does preserve 3D, so the grandC hild should receive the non-flattened composite transform.
(...skipping 12 matching lines...) Expand all
329 { 329 {
330 scoped_refptr<Layer> root = Layer::create(); 330 scoped_refptr<Layer> root = Layer::create();
331 scoped_refptr<Layer> parent = Layer::create(); 331 scoped_refptr<Layer> parent = Layer::create();
332 scoped_refptr<Layer> child = Layer::create(); 332 scoped_refptr<Layer> child = Layer::create();
333 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent()); 333 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent());
334 root->addChild(parent); 334 root->addChild(parent);
335 parent->addChild(child); 335 parent->addChild(child);
336 child->addChild(grandChild); 336 child->addChild(grandChild);
337 337
338 // One-time setup of root layer 338 // One-time setup of root layer
339 WebTransformationMatrix identityMatrix; 339 Transform identityMatrix;
340 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false); 340 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false);
341 341
342 // Child is set up so that a new render surface should be created. 342 // Child is set up so that a new render surface should be created.
343 child->setOpacity(0.5); 343 child->setOpacity(0.5);
344 344
345 WebTransformationMatrix parentLayerTransform; 345 Transform parentLayerTransform;
346 parentLayerTransform.scale3d(1, 0.9, 1); 346 parentLayerTransform.PreconcatScale3d(1, 0.9, 1);
347 WebTransformationMatrix parentTranslationToAnchor; 347 Transform parentTranslationToAnchor;
348 parentTranslationToAnchor.translate(25, 30); 348 parentTranslationToAnchor.PreconcatTranslate(25, 30);
349 WebTransformationMatrix parentSublayerMatrix; 349 Transform parentSublayerMatrix;
350 parentSublayerMatrix.scale3d(0.9, 1, 3.3); 350 parentSublayerMatrix.PreconcatScale3d(0.9, 1, 3.3);
351 WebTransformationMatrix parentTranslationToCenter; 351 Transform parentTranslationToCenter;
352 parentTranslationToCenter.translate(50, 60); 352 parentTranslationToCenter.PreconcatTranslate(50, 60);
353 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse() 353 Transform parentCompositeTransform = parentTranslationToAnchor * parentLayer Transform * MathUtil::inverse(parentTranslationToAnchor)
354 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse(); 354 * parentTranslationToCenter * parentSublayerMatrix * MathUtil::inver se(parentTranslationToCenter);
355 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo nents(parentCompositeTransform); 355 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo nents(parentCompositeTransform);
356 WebTransformationMatrix surfaceSublayerTransform; 356 Transform surfaceSublayerTransform;
357 surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCom positeScale.y()); 357 surfaceSublayerTransform.PreconcatScale(parentCompositeScale.x(), parentComp ositeScale.y());
358 WebTransformationMatrix surfaceSublayerCompositeTransform = parentCompositeT ransform * surfaceSublayerTransform.inverse(); 358 Transform surfaceSublayerCompositeTransform = parentCompositeTransform * Mat hUtil::inverse(surfaceSublayerTransform);
359 359
360 // Child's render surface should not exist yet. 360 // Child's render surface should not exist yet.
361 ASSERT_FALSE(child->renderSurface()); 361 ASSERT_FALSE(child->renderSurface());
362 362
363 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), fals e); 363 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), fals e);
364 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); 364 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
365 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(8, 10), false); 365 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(8, 10), false);
366 executeCalculateDrawTransformsAndVisibility(root.get()); 366 executeCalculateDrawTransformsAndVisibility(root.get());
367 367
368 // Render surface should have been created now. 368 // Render surface should have been created now.
(...skipping 19 matching lines...) Expand all
388 scoped_refptr<Layer> parent = Layer::create(); 388 scoped_refptr<Layer> parent = Layer::create();
389 scoped_refptr<Layer> child = Layer::create(); 389 scoped_refptr<Layer> child = Layer::create();
390 scoped_refptr<Layer> childReplica = Layer::create(); 390 scoped_refptr<Layer> childReplica = Layer::create();
391 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent()); 391 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent());
392 root->addChild(parent); 392 root->addChild(parent);
393 parent->addChild(child); 393 parent->addChild(child);
394 child->addChild(grandChild); 394 child->addChild(grandChild);
395 child->setReplicaLayer(childReplica.get()); 395 child->setReplicaLayer(childReplica.get());
396 396
397 // One-time setup of root layer 397 // One-time setup of root layer
398 WebTransformationMatrix identityMatrix; 398 Transform identityMatrix;
399 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false); 399 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false);
400 400
401 // Child is set up so that a new render surface should be created. 401 // Child is set up so that a new render surface should be created.
402 child->setOpacity(0.5); 402 child->setOpacity(0.5);
403 403
404 WebTransformationMatrix parentLayerTransform; 404 Transform parentLayerTransform;
405 parentLayerTransform.scale3d(2, 2, 1); 405 parentLayerTransform.PreconcatScale3d(2, 2, 1);
406 WebTransformationMatrix parentTranslationToAnchor; 406 Transform parentTranslationToAnchor;
407 parentTranslationToAnchor.translate(2.5, 3); 407 parentTranslationToAnchor.PreconcatTranslate(2.5, 3);
408 WebTransformationMatrix parentSublayerMatrix; 408 Transform parentSublayerMatrix;
409 parentSublayerMatrix.scale3d(10, 10, 3.3); 409 parentSublayerMatrix.PreconcatScale3d(10, 10, 3.3);
410 WebTransformationMatrix parentTranslationToCenter; 410 Transform parentTranslationToCenter;
411 parentTranslationToCenter.translate(5, 6); 411 parentTranslationToCenter.PreconcatTranslate(5, 6);
412 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse() 412 Transform parentCompositeTransform = parentTranslationToAnchor * parentLayer Transform * MathUtil::inverse(parentTranslationToAnchor)
413 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse(); 413 * parentTranslationToCenter * parentSublayerMatrix * MathUtil::inver se(parentTranslationToCenter);
414 WebTransformationMatrix childTranslationToCenter; 414 Transform childTranslationToCenter;
415 childTranslationToCenter.translate(8, 9); 415 childTranslationToCenter.PreconcatTranslate(8, 9);
416 WebTransformationMatrix replicaLayerTransform; 416 Transform replicaLayerTransform;
417 replicaLayerTransform.scale3d(3, 3, 1); 417 replicaLayerTransform.PreconcatScale3d(3, 3, 1);
418 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo nents(parentCompositeTransform); 418 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo nents(parentCompositeTransform);
419 WebTransformationMatrix surfaceSublayerTransform; 419 Transform surfaceSublayerTransform;
420 surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCom positeScale.y()); 420 surfaceSublayerTransform.PreconcatScale(parentCompositeScale.x(), parentComp ositeScale.y());
421 WebTransformationMatrix replicaCompositeTransform = parentCompositeTransform * replicaLayerTransform * surfaceSublayerTransform.inverse(); 421 Transform replicaCompositeTransform = parentCompositeTransform * replicaLaye rTransform * MathUtil::inverse(surfaceSublayerTransform);
422 422
423 // Child's render surface should not exist yet. 423 // Child's render surface should not exist yet.
424 ASSERT_FALSE(child->renderSurface()); 424 ASSERT_FALSE(child->renderSurface());
425 425
426 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false) ; 426 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false) ;
427 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false); 427 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
428 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(-0.5, -0.5), gfx::Size(1, 1), false); 428 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(-0.5, -0.5), gfx::Size(1, 1), false);
429 setLayerPropertiesForTesting(childReplica.get(), replicaLayerTransform, iden tityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(0, 0), false); 429 setLayerPropertiesForTesting(childReplica.get(), replicaLayerTransform, iden tityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(0, 0), false);
430 executeCalculateDrawTransformsAndVisibility(root.get()); 430 executeCalculateDrawTransformsAndVisibility(root.get());
431 431
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 childOfRS1->addChild(grandChildOfRS1); 468 childOfRS1->addChild(grandChildOfRS1);
469 childOfRS2->addChild(grandChildOfRS2); 469 childOfRS2->addChild(grandChildOfRS2);
470 renderSurface1->setReplicaLayer(replicaOfRS1.get()); 470 renderSurface1->setReplicaLayer(replicaOfRS1.get());
471 renderSurface2->setReplicaLayer(replicaOfRS2.get()); 471 renderSurface2->setReplicaLayer(replicaOfRS2.get());
472 472
473 // In combination with descendantDrawsContent, opacity != 1 forces the layer to have a new renderSurface. 473 // In combination with descendantDrawsContent, opacity != 1 forces the layer to have a new renderSurface.
474 renderSurface1->setOpacity(0.5); 474 renderSurface1->setOpacity(0.5);
475 renderSurface2->setOpacity(0.33f); 475 renderSurface2->setOpacity(0.33f);
476 476
477 // One-time setup of root layer 477 // One-time setup of root layer
478 WebTransformationMatrix identityMatrix; 478 Transform identityMatrix;
479 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false); 479 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false);
480 480
481 // All layers in the tree are initialized with an anchor at .25 and a size o f (10,10). 481 // All layers in the tree are initialized with an anchor at .25 and a size o f (10,10).
482 // matrix "A" is the composite layer transform used in all layers, centered about the anchor point 482 // matrix "A" is the composite layer transform used in all layers, centered about the anchor point
483 // matrix "B" is the sublayer transform used in all layers, centered about t he center position of the layer. 483 // matrix "B" is the sublayer transform used in all layers, centered about t he center position of the layer.
484 // matrix "R" is the composite replica transform used in all replica layers. 484 // matrix "R" is the composite replica transform used in all replica layers.
485 // 485 //
486 // x component tests that layerTransform and sublayerTransform are done in t he right order (translation and scale are noncommutative). 486 // x component tests that layerTransform and sublayerTransform are done in t he right order (translation and scale are noncommutative).
487 // y component has a translation by 1 for every ancestor, which indicates th e "depth" of the layer in the hierarchy. 487 // y component has a translation by 1 for every ancestor, which indicates th e "depth" of the layer in the hierarchy.
488 WebTransformationMatrix translationToAnchor; 488 Transform translationToAnchor;
489 translationToAnchor.translate(2.5, 0); 489 translationToAnchor.PreconcatTranslate(2.5, 0);
490 WebTransformationMatrix translationToCenter; 490 Transform translationToCenter;
491 translationToCenter.translate(5, 5); 491 translationToCenter.PreconcatTranslate(5, 5);
492 WebTransformationMatrix layerTransform; 492 Transform layerTransform;
493 layerTransform.translate(1, 1); 493 layerTransform.PreconcatTranslate(1, 1);
494 WebTransformationMatrix sublayerTransform; 494 Transform sublayerTransform;
495 sublayerTransform.scale3d(10, 1, 1); 495 sublayerTransform.PreconcatScale3d(10, 1, 1);
496 WebTransformationMatrix replicaLayerTransform; 496 Transform replicaLayerTransform;
497 replicaLayerTransform.scale3d(-2, 5, 1); 497 replicaLayerTransform.PreconcatScale3d(-2, 5, 1);
498 498
499 WebTransformationMatrix A = translationToAnchor * layerTransform * translati onToAnchor.inverse(); 499 Transform A = translationToAnchor * layerTransform * MathUtil::inverse(trans lationToAnchor);
500 WebTransformationMatrix B = translationToCenter * sublayerTransform * transl ationToCenter.inverse(); 500 Transform B = translationToCenter * sublayerTransform * MathUtil::inverse(tr anslationToCenter);
501 WebTransformationMatrix R = A * translationToAnchor * replicaLayerTransform * translationToAnchor.inverse(); 501 Transform R = A * translationToAnchor * replicaLayerTransform * MathUtil::in verse(translationToAnchor);
502 502
503 gfx::Vector2dF surface1ParentTransformScale = MathUtil::computeTransform2dSc aleComponents(A * B); 503 gfx::Vector2dF surface1ParentTransformScale = MathUtil::computeTransform2dSc aleComponents(A * B);
504 WebTransformationMatrix surface1SublayerTransform; 504 Transform surface1SublayerTransform;
505 surface1SublayerTransform.scaleNonUniform(surface1ParentTransformScale.x(), surface1ParentTransformScale.y()); 505 surface1SublayerTransform.PreconcatScale(surface1ParentTransformScale.x(), s urface1ParentTransformScale.y());
506 506
507 // SS1 = transform given to the subtree of renderSurface1 507 // SS1 = transform given to the subtree of renderSurface1
508 WebTransformationMatrix SS1 = surface1SublayerTransform; 508 Transform SS1 = surface1SublayerTransform;
509 // S1 = transform to move from renderSurface1 pixels to the layer space of t he owning layer 509 // S1 = transform to move from renderSurface1 pixels to the layer space of t he owning layer
510 WebTransformationMatrix S1 = surface1SublayerTransform.inverse(); 510 Transform S1 = MathUtil::inverse(surface1SublayerTransform);
511 511
512 gfx::Vector2dF surface2ParentTransformScale = MathUtil::computeTransform2dSc aleComponents(SS1 * A * B); 512 gfx::Vector2dF surface2ParentTransformScale = MathUtil::computeTransform2dSc aleComponents(SS1 * A * B);
513 WebTransformationMatrix surface2SublayerTransform; 513 Transform surface2SublayerTransform;
514 surface2SublayerTransform.scaleNonUniform(surface2ParentTransformScale.x(), surface2ParentTransformScale.y()); 514 surface2SublayerTransform.PreconcatScale(surface2ParentTransformScale.x(), s urface2ParentTransformScale.y());
515 515
516 // SS2 = transform given to the subtree of renderSurface2 516 // SS2 = transform given to the subtree of renderSurface2
517 WebTransformationMatrix SS2 = surface2SublayerTransform; 517 Transform SS2 = surface2SublayerTransform;
518 // S2 = transform to move from renderSurface2 pixels to the layer space of t he owning layer 518 // S2 = transform to move from renderSurface2 pixels to the layer space of t he owning layer
519 WebTransformationMatrix S2 = surface2SublayerTransform.inverse(); 519 Transform S2 = MathUtil::inverse(surface2SublayerTransform);
520 520
521 setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform , gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false); 521 setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform , gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
522 setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerT ransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false); 522 setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerT ransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
523 setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerT ransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false); 523 setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerT ransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
524 setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTran sform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false); 524 setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTran sform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
525 setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTrans form, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false); 525 setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTrans form, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
526 setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTrans form, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false); 526 setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTrans form, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
527 setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublaye rTransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false); 527 setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublaye rTransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
528 setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayer Transform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false); 528 setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayer Transform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
529 setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayer Transform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false); 529 setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayer Transform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * R * S1, renderSurface1->renderSurfac e()->replicaScreenSpaceTransform()); 599 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * R * S1, renderSurface1->renderSurfac e()->replicaScreenSpaceTransform());
600 // Draw transform of render surface 2 is described with respect to render su rface 1. 600 // Draw transform of render surface 2 is described with respect to render su rface 1.
601 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * A * S2, renderSurface2->renderSurf ace()->drawTransform()); 601 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * A * S2, renderSurface2->renderSurf ace()->drawTransform());
602 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * R * S2, renderSurface2->renderSurf ace()->replicaDrawTransform()); 602 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * R * S2, renderSurface2->renderSurf ace()->replicaDrawTransform());
603 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * S2, renderSurface2->rend erSurface()->screenSpaceTransform()); 603 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * S2, renderSurface2->rend erSurface()->screenSpaceTransform());
604 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * R * S2, renderSurface2->rend erSurface()->replicaScreenSpaceTransform()); 604 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * R * S2, renderSurface2->rend erSurface()->replicaScreenSpaceTransform());
605 605
606 // Sanity check. If these fail there is probably a bug in the test itself. 606 // Sanity check. If these fail there is probably a bug in the test itself.
607 // It is expected that we correctly set up transforms so that the y-componen t of the screen-space transform 607 // It is expected that we correctly set up transforms so that the y-componen t of the screen-space transform
608 // encodes the "depth" of the layer in the tree. 608 // encodes the "depth" of the layer in the tree.
609 EXPECT_FLOAT_EQ(1, parent->screenSpaceTransform().m42()); 609 EXPECT_FLOAT_EQ(1, parent->screenSpaceTransform().matrix().getDouble(1, 3));
610 EXPECT_FLOAT_EQ(2, childOfRoot->screenSpaceTransform().m42()); 610 EXPECT_FLOAT_EQ(2, childOfRoot->screenSpaceTransform().matrix().getDouble(1, 3));
611 EXPECT_FLOAT_EQ(3, grandChildOfRoot->screenSpaceTransform().m42()); 611 EXPECT_FLOAT_EQ(3, grandChildOfRoot->screenSpaceTransform().matrix().getDoub le(1, 3));
612 612
613 EXPECT_FLOAT_EQ(2, renderSurface1->screenSpaceTransform().m42()); 613 EXPECT_FLOAT_EQ(2, renderSurface1->screenSpaceTransform().matrix().getDouble (1, 3));
614 EXPECT_FLOAT_EQ(3, childOfRS1->screenSpaceTransform().m42()); 614 EXPECT_FLOAT_EQ(3, childOfRS1->screenSpaceTransform().matrix().getDouble(1, 3));
615 EXPECT_FLOAT_EQ(4, grandChildOfRS1->screenSpaceTransform().m42()); 615 EXPECT_FLOAT_EQ(4, grandChildOfRS1->screenSpaceTransform().matrix().getDoubl e(1, 3));
616 616
617 EXPECT_FLOAT_EQ(3, renderSurface2->screenSpaceTransform().m42()); 617 EXPECT_FLOAT_EQ(3, renderSurface2->screenSpaceTransform().matrix().getDouble (1, 3));
618 EXPECT_FLOAT_EQ(4, childOfRS2->screenSpaceTransform().m42()); 618 EXPECT_FLOAT_EQ(4, childOfRS2->screenSpaceTransform().matrix().getDouble(1, 3));
619 EXPECT_FLOAT_EQ(5, grandChildOfRS2->screenSpaceTransform().m42()); 619 EXPECT_FLOAT_EQ(5, grandChildOfRS2->screenSpaceTransform().matrix().getDoubl e(1, 3));
620 } 620 }
621 621
622 TEST(LayerTreeHostCommonTest, verifyTransformsForFlatteningLayer) 622 TEST(LayerTreeHostCommonTest, verifyTransformsForFlatteningLayer)
623 { 623 {
624 // For layers that flatten their subtree, there should be an orthographic pr ojection 624 // For layers that flatten their subtree, there should be an orthographic pr ojection
625 // (for x and y values) in the middle of the transform sequence. Note that t he way the 625 // (for x and y values) in the middle of the transform sequence. Note that t he way the
626 // code is currently implemented, it is not expected to use a canonical orth ographic 626 // code is currently implemented, it is not expected to use a canonical orth ographic
627 // projection. 627 // projection.
628 628
629 scoped_refptr<Layer> root = Layer::create(); 629 scoped_refptr<Layer> root = Layer::create();
630 scoped_refptr<Layer> child = Layer::create(); 630 scoped_refptr<Layer> child = Layer::create();
631 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent()); 631 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent());
632 632
633 WebTransformationMatrix rotationAboutYAxis; 633 Transform rotationAboutYAxis;
634 rotationAboutYAxis.rotate3d(0, 30, 0); 634 MathUtil::rotateEulerAngles(&rotationAboutYAxis, 0, 30, 0);
Ian Vollick 2012/11/21 22:07:09 Why not rotationAboutYAxis.PreconcatRotateAbout(Po
shawnsingh 2012/11/23 08:10:45 I started doing this and realized that I feel unco
635 635
636 const WebTransformationMatrix identityMatrix; 636 const Transform identityMatrix;
637 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(), gfx::PointF(), gfx::Size(100, 100), false); 637 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(), gfx::PointF(), gfx::Size(100, 100), false);
638 setLayerPropertiesForTesting(child.get(), rotationAboutYAxis, identityMatrix , gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); 638 setLayerPropertiesForTesting(child.get(), rotationAboutYAxis, identityMatrix , gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
639 setLayerPropertiesForTesting(grandChild.get(), rotationAboutYAxis, identityM atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); 639 setLayerPropertiesForTesting(grandChild.get(), rotationAboutYAxis, identityM atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
640 640
641 root->addChild(child); 641 root->addChild(child);
642 child->addChild(grandChild); 642 child->addChild(grandChild);
643 child->setForceRenderSurface(true); 643 child->setForceRenderSurface(true);
644 644
645 // No layers in this test should preserve 3d. 645 // No layers in this test should preserve 3d.
646 ASSERT_FALSE(root->preserves3D()); 646 ASSERT_FALSE(root->preserves3D());
647 ASSERT_FALSE(child->preserves3D()); 647 ASSERT_FALSE(child->preserves3D());
648 ASSERT_FALSE(grandChild->preserves3D()); 648 ASSERT_FALSE(grandChild->preserves3D());
649 649
650 WebTransformationMatrix expectedChildDrawTransform = rotationAboutYAxis; 650 Transform expectedChildDrawTransform = rotationAboutYAxis;
651 WebTransformationMatrix expectedChildScreenSpaceTransform = rotationAboutYAx is; 651 Transform expectedChildScreenSpaceTransform = rotationAboutYAxis;
652 WebTransformationMatrix expectedGrandChildDrawTransform = rotationAboutYAxis ; // draws onto child's renderSurface 652 Transform expectedGrandChildDrawTransform = rotationAboutYAxis; // draws ont o child's renderSurface
653 WebTransformationMatrix expectedGrandChildScreenSpaceTransform = rotationAbo utYAxis.to2dTransform() * rotationAboutYAxis; 653 Transform expectedGrandChildScreenSpaceTransform = MathUtil::to2dTransform(r otationAboutYAxis) * rotationAboutYAxis;
654 654
655 executeCalculateDrawTransformsAndVisibility(root.get()); 655 executeCalculateDrawTransformsAndVisibility(root.get());
656 656
657 // The child's drawTransform should have been taken by its surface. 657 // The child's drawTransform should have been taken by its surface.
658 ASSERT_TRUE(child->renderSurface()); 658 ASSERT_TRUE(child->renderSurface());
659 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildDrawTransform, child->renderSur face()->drawTransform()); 659 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildDrawTransform, child->renderSur face()->drawTransform());
660 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->re nderSurface()->screenSpaceTransform()); 660 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->re nderSurface()->screenSpaceTransform());
661 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); 661 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
662 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->sc reenSpaceTransform()); 662 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->sc reenSpaceTransform());
663 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildDrawTransform, grandChild- >drawTransform()); 663 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildDrawTransform, grandChild- >drawTransform());
664 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildScreenSpaceTransform, gran dChild->screenSpaceTransform()); 664 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildScreenSpaceTransform, gran dChild->screenSpaceTransform());
665 } 665 }
666 666
667 TEST(LayerTreeHostCommonTest, verifyTransformsForDegenerateIntermediateLayer) 667 TEST(LayerTreeHostCommonTest, verifyTransformsForDegenerateIntermediateLayer)
668 { 668 {
669 // A layer that is empty in one axis, but not the other, was accidentally sk ipping a necessary translation. 669 // A layer that is empty in one axis, but not the other, was accidentally sk ipping a necessary translation.
670 // Without that translation, the coordinate space of the layer's drawTransfo rm is incorrect. 670 // Without that translation, the coordinate space of the layer's drawTransfo rm is incorrect.
671 // 671 //
672 // Normally this isn't a problem, because the layer wouldn't be drawn anyway , but if that layer becomes a renderSurface, then 672 // Normally this isn't a problem, because the layer wouldn't be drawn anyway , but if that layer becomes a renderSurface, then
673 // its drawTransform is implicitly inherited by the rest of the subtree, whi ch then is positioned incorrectly as a result. 673 // its drawTransform is implicitly inherited by the rest of the subtree, whi ch then is positioned incorrectly as a result.
674 674
675 scoped_refptr<Layer> root = Layer::create(); 675 scoped_refptr<Layer> root = Layer::create();
676 scoped_refptr<Layer> child = Layer::create(); 676 scoped_refptr<Layer> child = Layer::create();
677 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent()); 677 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent());
678 678
679 // The child height is zero, but has non-zero width that should be accounted for while computing drawTransforms. 679 // The child height is zero, but has non-zero width that should be accounted for while computing drawTransforms.
680 const WebTransformationMatrix identityMatrix; 680 const Transform identityMatrix;
681 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(), gfx::PointF(), gfx::Size(100, 100), false); 681 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(), gfx::PointF(), gfx::Size(100, 100), false);
682 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(), gfx::PointF(), gfx::Size(10, 0), false); 682 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(), gfx::PointF(), gfx::Size(10, 0), false);
683 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); 683 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
684 684
685 root->addChild(child); 685 root->addChild(child);
686 child->addChild(grandChild); 686 child->addChild(grandChild);
687 child->setForceRenderSurface(true); 687 child->setForceRenderSurface(true);
688 688
689 executeCalculateDrawTransformsAndVisibility(root.get()); 689 executeCalculateDrawTransformsAndVisibility(root.get());
690 690
691 ASSERT_TRUE(child->renderSurface()); 691 ASSERT_TRUE(child->renderSurface());
692 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->renderSurface()->draw Transform()); // This is the real test, the rest are sanity checks. 692 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->renderSurface()->draw Transform()); // This is the real test, the rest are sanity checks.
693 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); 693 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
694 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ; 694 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ;
695 } 695 }
696 696
697 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceListForRenderSurfaceWithClipped Layer) 697 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceListForRenderSurfaceWithClipped Layer)
698 { 698 {
699 scoped_refptr<Layer> parent = Layer::create(); 699 scoped_refptr<Layer> parent = Layer::create();
700 scoped_refptr<Layer> renderSurface1 = Layer::create(); 700 scoped_refptr<Layer> renderSurface1 = Layer::create();
701 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent()); 701 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent());
702 702
703 const WebTransformationMatrix identityMatrix; 703 const Transform identityMatrix;
704 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); 704 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
705 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); 705 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
706 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(), gfx::PointF(30, 30), gfx::Size(10, 10), false); 706 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(), gfx::PointF(30, 30), gfx::Size(10, 10), false);
707 707
708 parent->addChild(renderSurface1); 708 parent->addChild(renderSurface1);
709 parent->setMasksToBounds(true); 709 parent->setMasksToBounds(true);
710 renderSurface1->addChild(child); 710 renderSurface1->addChild(child);
711 renderSurface1->setForceRenderSurface(true); 711 renderSurface1->setForceRenderSurface(true);
712 712
713 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 713 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
714 int dummyMaxTextureSize = 512; 714 int dummyMaxTextureSize = 512;
715 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 715 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
716 716
717 // The child layer's content is entirely outside the parent's clip rect, so the intermediate 717 // The child layer's content is entirely outside the parent's clip rect, so the intermediate
718 // render surface should not be listed here, even if it was forced to be cre ated. Render surfaces without children or visible 718 // render surface should not be listed here, even if it was forced to be cre ated. Render surfaces without children or visible
719 // content are unexpected at draw time (e.g. we might try to create a conten t texture of size 0). 719 // content are unexpected at draw time (e.g. we might try to create a conten t texture of size 0).
720 ASSERT_TRUE(parent->renderSurface()); 720 ASSERT_TRUE(parent->renderSurface());
721 ASSERT_FALSE(renderSurface1->renderSurface()); 721 ASSERT_FALSE(renderSurface1->renderSurface());
722 EXPECT_EQ(1U, renderSurfaceLayerList.size()); 722 EXPECT_EQ(1U, renderSurfaceLayerList.size());
723 } 723 }
724 724
725 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceListForTransparentChild) 725 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceListForTransparentChild)
726 { 726 {
727 scoped_refptr<Layer> parent = Layer::create(); 727 scoped_refptr<Layer> parent = Layer::create();
728 scoped_refptr<Layer> renderSurface1 = Layer::create(); 728 scoped_refptr<Layer> renderSurface1 = Layer::create();
729 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent()); 729 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent());
730 730
731 const WebTransformationMatrix identityMatrix; 731 const Transform identityMatrix;
732 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); 732 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
733 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(), gfx::PointF(), gfx::Size(10, 10), false); 733 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
734 734
735 parent->addChild(renderSurface1); 735 parent->addChild(renderSurface1);
736 renderSurface1->addChild(child); 736 renderSurface1->addChild(child);
737 renderSurface1->setForceRenderSurface(true); 737 renderSurface1->setForceRenderSurface(true);
738 renderSurface1->setOpacity(0); 738 renderSurface1->setOpacity(0);
739 739
740 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 740 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
741 int dummyMaxTextureSize = 512; 741 int dummyMaxTextureSize = 512;
742 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 742 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
743 743
744 // Since the layer is transparent, renderSurface1->renderSurface() should no t have gotten added anywhere. 744 // Since the layer is transparent, renderSurface1->renderSurface() should no t have gotten added anywhere.
745 // Also, the drawable content rect should not have been extended by the chil dren. 745 // Also, the drawable content rect should not have been extended by the chil dren.
746 ASSERT_TRUE(parent->renderSurface()); 746 ASSERT_TRUE(parent->renderSurface());
747 EXPECT_EQ(0U, parent->renderSurface()->layerList().size()); 747 EXPECT_EQ(0U, parent->renderSurface()->layerList().size());
748 EXPECT_EQ(1U, renderSurfaceLayerList.size()); 748 EXPECT_EQ(1U, renderSurfaceLayerList.size());
749 EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id()); 749 EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
750 EXPECT_EQ(gfx::Rect(), parent->drawableContentRect()); 750 EXPECT_EQ(gfx::Rect(), parent->drawableContentRect());
751 } 751 }
752 752
753 TEST(LayerTreeHostCommonTest, verifyForceRenderSurface) 753 TEST(LayerTreeHostCommonTest, verifyForceRenderSurface)
754 { 754 {
755 scoped_refptr<Layer> parent = Layer::create(); 755 scoped_refptr<Layer> parent = Layer::create();
756 scoped_refptr<Layer> renderSurface1 = Layer::create(); 756 scoped_refptr<Layer> renderSurface1 = Layer::create();
757 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent()); 757 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent());
758 renderSurface1->setForceRenderSurface(true); 758 renderSurface1->setForceRenderSurface(true);
759 759
760 const WebTransformationMatrix identityMatrix; 760 const Transform identityMatrix;
761 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); 761 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
762 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false); 762 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
763 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(), gfx::PointF(), gfx::Size(10, 10), false); 763 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
764 764
765 parent->addChild(renderSurface1); 765 parent->addChild(renderSurface1);
766 renderSurface1->addChild(child); 766 renderSurface1->addChild(child);
767 767
768 // Sanity check before the actual test 768 // Sanity check before the actual test
769 EXPECT_FALSE(parent->renderSurface()); 769 EXPECT_FALSE(parent->renderSurface());
770 EXPECT_FALSE(renderSurface1->renderSurface()); 770 EXPECT_FALSE(renderSurface1->renderSurface());
(...skipping 23 matching lines...) Expand all
794 LayerImpl* child = root->children()[0]; 794 LayerImpl* child = root->children()[0];
795 LayerImpl* grandChild = child->children()[0]; 795 LayerImpl* grandChild = child->children()[0];
796 796
797 child->setIsContainerForFixedPositionLayers(true); 797 child->setIsContainerForFixedPositionLayers(true);
798 grandChild->setFixedToContainerLayer(true); 798 grandChild->setFixedToContainerLayer(true);
799 799
800 // Case 1: scrollDelta of 0, 0 800 // Case 1: scrollDelta of 0, 0
801 child->setScrollDelta(gfx::Vector2d(0, 0)); 801 child->setScrollDelta(gfx::Vector2d(0, 0));
802 executeCalculateDrawTransformsAndVisibility(root.get()); 802 executeCalculateDrawTransformsAndVisibility(root.get());
803 803
804 WebTransformationMatrix expectedChildTransform; 804 Transform expectedChildTransform;
805 WebTransformationMatrix expectedGrandChildTransform = expectedChildTransform ; 805 Transform expectedGrandChildTransform = expectedChildTransform;
806 806
807 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 807 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
808 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 808 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
809 809
810 // Case 2: scrollDelta of 10, 10 810 // Case 2: scrollDelta of 10, 10
811 child->setScrollDelta(gfx::Vector2d(10, 10)); 811 child->setScrollDelta(gfx::Vector2d(10, 10));
812 executeCalculateDrawTransformsAndVisibility(root.get()); 812 executeCalculateDrawTransformsAndVisibility(root.get());
813 813
814 // Here the child is affected by scrollDelta, but the fixed position grandCh ild should not be affected. 814 // Here the child is affected by scrollDelta, but the fixed position grandCh ild should not be affected.
815 expectedChildTransform.makeIdentity(); 815 expectedChildTransform.matrix().setIdentity();
816 expectedChildTransform.translate(-10, -10); 816 expectedChildTransform.PreconcatTranslate(-10, -10);
817 817
818 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 818 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
819 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 819 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
820 } 820 }
821 821
822 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithT ransformedDirectContainer) 822 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithT ransformedDirectContainer)
823 { 823 {
824 // This test checks for correct scroll compensation when the fixed-position container 824 // This test checks for correct scroll compensation when the fixed-position container
825 // is the direct parent of the fixed-position layer, but that container is t ransformed. 825 // is the direct parent of the fixed-position layer, but that container is t ransformed.
826 // In this case, the fixed position element inherits the container's transfo rm, 826 // In this case, the fixed position element inherits the container's transfo rm,
827 // but the scrollDelta that has to be undone should not be affected by that transform. 827 // but the scrollDelta that has to be undone should not be affected by that transform.
828 // 828 //
829 // Transforms are in general non-commutative; using something like a non-uni form scale 829 // Transforms are in general non-commutative; using something like a non-uni form scale
830 // helps to verify that translations and non-uniform scales are applied in t he correct 830 // helps to verify that translations and non-uniform scales are applied in t he correct
831 // order. 831 // order.
832 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 832 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
833 LayerImpl* child = root->children()[0]; 833 LayerImpl* child = root->children()[0];
834 LayerImpl* grandChild = child->children()[0]; 834 LayerImpl* grandChild = child->children()[0];
835 835
836 // This scale will cause child and grandChild to be effectively 200 x 800 wi th respect to the renderTarget. 836 // This scale will cause child and grandChild to be effectively 200 x 800 wi th respect to the renderTarget.
837 WebTransformationMatrix nonUniformScale; 837 Transform nonUniformScale;
838 nonUniformScale.scaleNonUniform(2, 8); 838 nonUniformScale.PreconcatScale(2, 8);
839 child->setTransform(nonUniformScale); 839 child->setTransform(nonUniformScale);
840 840
841 child->setIsContainerForFixedPositionLayers(true); 841 child->setIsContainerForFixedPositionLayers(true);
842 grandChild->setFixedToContainerLayer(true); 842 grandChild->setFixedToContainerLayer(true);
843 843
844 // Case 1: scrollDelta of 0, 0 844 // Case 1: scrollDelta of 0, 0
845 child->setScrollDelta(gfx::Vector2d(0, 0)); 845 child->setScrollDelta(gfx::Vector2d(0, 0));
846 executeCalculateDrawTransformsAndVisibility(root.get()); 846 executeCalculateDrawTransformsAndVisibility(root.get());
847 847
848 WebTransformationMatrix expectedChildTransform; 848 Transform expectedChildTransform;
849 expectedChildTransform.multiply(nonUniformScale); 849 expectedChildTransform.PreconcatTransform(nonUniformScale);
850 850
851 WebTransformationMatrix expectedGrandChildTransform = expectedChildTransform ; 851 Transform expectedGrandChildTransform = expectedChildTransform;
852 852
853 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 853 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
854 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 854 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
855 855
856 // Case 2: scrollDelta of 10, 20 856 // Case 2: scrollDelta of 10, 20
857 child->setScrollDelta(gfx::Vector2d(10, 20)); 857 child->setScrollDelta(gfx::Vector2d(10, 20));
858 executeCalculateDrawTransformsAndVisibility(root.get()); 858 executeCalculateDrawTransformsAndVisibility(root.get());
859 859
860 // The child should be affected by scrollDelta, but the fixed position grand Child should not be affected. 860 // The child should be affected by scrollDelta, but the fixed position grand Child should not be affected.
861 expectedChildTransform.makeIdentity(); 861 expectedChildTransform.matrix().setIdentity();
862 expectedChildTransform.translate(-10, -20); // scrollDelta 862 expectedChildTransform.PreconcatTranslate(-10, -20); // scrollDelta
863 expectedChildTransform.multiply(nonUniformScale); 863 expectedChildTransform.PreconcatTransform(nonUniformScale);
864 864
865 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 865 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
866 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 866 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
867 } 867 }
868 868
869 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithD istantContainer) 869 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithD istantContainer)
870 { 870 {
871 // This test checks for correct scroll compensation when the fixed-position container 871 // This test checks for correct scroll compensation when the fixed-position container
872 // is NOT the direct parent of the fixed-position layer. 872 // is NOT the direct parent of the fixed-position layer.
873 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 873 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
874 LayerImpl* child = root->children()[0]; 874 LayerImpl* child = root->children()[0];
875 LayerImpl* grandChild = child->children()[0]; 875 LayerImpl* grandChild = child->children()[0];
876 LayerImpl* greatGrandChild = grandChild->children()[0]; 876 LayerImpl* greatGrandChild = grandChild->children()[0];
877 877
878 child->setIsContainerForFixedPositionLayers(true); 878 child->setIsContainerForFixedPositionLayers(true);
879 grandChild->setPosition(gfx::PointF(8, 6)); 879 grandChild->setPosition(gfx::PointF(8, 6));
880 greatGrandChild->setFixedToContainerLayer(true); 880 greatGrandChild->setFixedToContainerLayer(true);
881 881
882 // Case 1: scrollDelta of 0, 0 882 // Case 1: scrollDelta of 0, 0
883 child->setScrollDelta(gfx::Vector2d(0, 0)); 883 child->setScrollDelta(gfx::Vector2d(0, 0));
884 executeCalculateDrawTransformsAndVisibility(root.get()); 884 executeCalculateDrawTransformsAndVisibility(root.get());
885 885
886 WebTransformationMatrix expectedChildTransform; 886 Transform expectedChildTransform;
887 WebTransformationMatrix expectedGrandChildTransform; 887 Transform expectedGrandChildTransform;
888 expectedGrandChildTransform.translate(8, 6); 888 expectedGrandChildTransform.PreconcatTranslate(8, 6);
889 889
890 WebTransformationMatrix expectedGreatGrandChildTransform = expectedGrandChil dTransform; 890 Transform expectedGreatGrandChildTransform = expectedGrandChildTransform;
891 891
892 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 892 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
893 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 893 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
894 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform()); 894 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform());
895 895
896 // Case 2: scrollDelta of 10, 10 896 // Case 2: scrollDelta of 10, 10
897 child->setScrollDelta(gfx::Vector2d(10, 10)); 897 child->setScrollDelta(gfx::Vector2d(10, 10));
898 executeCalculateDrawTransformsAndVisibility(root.get()); 898 executeCalculateDrawTransformsAndVisibility(root.get());
899 899
900 // Here the child and grandChild are affected by scrollDelta, but the fixed position greatGrandChild should not be affected. 900 // Here the child and grandChild are affected by scrollDelta, but the fixed position greatGrandChild should not be affected.
901 expectedChildTransform.makeIdentity(); 901 expectedChildTransform.matrix().setIdentity();
902 expectedChildTransform.translate(-10, -10); 902 expectedChildTransform.PreconcatTranslate(-10, -10);
903 expectedGrandChildTransform.makeIdentity(); 903 expectedGrandChildTransform.matrix().setIdentity();
904 expectedGrandChildTransform.translate(-2, -4); 904 expectedGrandChildTransform.PreconcatTranslate(-2, -4);
905 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 905 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
906 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 906 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
907 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform()); 907 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform());
908 } 908 }
909 909
910 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithD istantContainerAndTransforms) 910 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithD istantContainerAndTransforms)
911 { 911 {
912 // This test checks for correct scroll compensation when the fixed-position container 912 // This test checks for correct scroll compensation when the fixed-position container
913 // is NOT the direct parent of the fixed-position layer, and the hierarchy h as various 913 // is NOT the direct parent of the fixed-position layer, and the hierarchy h as various
914 // transforms that have to be processed in the correct order. 914 // transforms that have to be processed in the correct order.
915 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 915 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
916 LayerImpl* child = root->children()[0]; 916 LayerImpl* child = root->children()[0];
917 LayerImpl* grandChild = child->children()[0]; 917 LayerImpl* grandChild = child->children()[0];
918 LayerImpl* greatGrandChild = grandChild->children()[0]; 918 LayerImpl* greatGrandChild = grandChild->children()[0];
919 919
920 WebTransformationMatrix rotationAboutZ; 920 Transform rotationAboutZ;
921 rotationAboutZ.rotate3d(0, 0, 90); 921 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90);
922 922
923 child->setIsContainerForFixedPositionLayers(true); 923 child->setIsContainerForFixedPositionLayers(true);
924 child->setTransform(rotationAboutZ); 924 child->setTransform(rotationAboutZ);
925 grandChild->setPosition(gfx::PointF(8, 6)); 925 grandChild->setPosition(gfx::PointF(8, 6));
926 grandChild->setTransform(rotationAboutZ); 926 grandChild->setTransform(rotationAboutZ);
927 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget. 927 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget.
928 928
929 // Case 1: scrollDelta of 0, 0 929 // Case 1: scrollDelta of 0, 0
930 child->setScrollDelta(gfx::Vector2d(0, 0)); 930 child->setScrollDelta(gfx::Vector2d(0, 0));
931 executeCalculateDrawTransformsAndVisibility(root.get()); 931 executeCalculateDrawTransformsAndVisibility(root.get());
932 932
933 WebTransformationMatrix expectedChildTransform; 933 Transform expectedChildTransform;
934 expectedChildTransform.multiply(rotationAboutZ); 934 expectedChildTransform.PreconcatTransform(rotationAboutZ);
935 935
936 WebTransformationMatrix expectedGrandChildTransform; 936 Transform expectedGrandChildTransform;
937 expectedGrandChildTransform.multiply(rotationAboutZ); // child's local trans form is inherited 937 expectedGrandChildTransform.PreconcatTransform(rotationAboutZ); // child's l ocal transform is inherited
938 expectedGrandChildTransform.translate(8, 6); // translation because of posit ion occurs before layer's local transform. 938 expectedGrandChildTransform.PreconcatTranslate(8, 6); // translation because of position occurs before layer's local transform.
939 expectedGrandChildTransform.multiply(rotationAboutZ); // grandChild's local transform 939 expectedGrandChildTransform.PreconcatTransform(rotationAboutZ); // grandChil d's local transform
940 940
941 WebTransformationMatrix expectedGreatGrandChildTransform = expectedGrandChil dTransform; 941 Transform expectedGreatGrandChildTransform = expectedGrandChildTransform;
942 942
943 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 943 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
944 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 944 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
945 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform()); 945 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform());
946 946
947 // Case 2: scrollDelta of 10, 20 947 // Case 2: scrollDelta of 10, 20
948 child->setScrollDelta(gfx::Vector2d(10, 20)); 948 child->setScrollDelta(gfx::Vector2d(10, 20));
949 executeCalculateDrawTransformsAndVisibility(root.get()); 949 executeCalculateDrawTransformsAndVisibility(root.get());
950 950
951 // Here the child and grandChild are affected by scrollDelta, but the fixed position greatGrandChild should not be affected. 951 // Here the child and grandChild are affected by scrollDelta, but the fixed position greatGrandChild should not be affected.
952 expectedChildTransform.makeIdentity(); 952 expectedChildTransform.matrix().setIdentity();
953 expectedChildTransform.translate(-10, -20); // scrollDelta 953 expectedChildTransform.PreconcatTranslate(-10, -20); // scrollDelta
954 expectedChildTransform.multiply(rotationAboutZ); 954 expectedChildTransform.PreconcatTransform(rotationAboutZ);
955 955
956 expectedGrandChildTransform.makeIdentity(); 956 expectedGrandChildTransform.matrix().setIdentity();
957 expectedGrandChildTransform.translate(-10, -20); // child's scrollDelta is i nherited 957 expectedGrandChildTransform.PreconcatTranslate(-10, -20); // child's scrollD elta is inherited
958 expectedGrandChildTransform.multiply(rotationAboutZ); // child's local trans form is inherited 958 expectedGrandChildTransform.PreconcatTransform(rotationAboutZ); // child's l ocal transform is inherited
959 expectedGrandChildTransform.translate(8, 6); // translation because of posit ion occurs before layer's local transform. 959 expectedGrandChildTransform.PreconcatTranslate(8, 6); // translation because of position occurs before layer's local transform.
960 expectedGrandChildTransform.multiply(rotationAboutZ); // grandChild's local transform 960 expectedGrandChildTransform.PreconcatTransform(rotationAboutZ); // grandChil d's local transform
961 961
962 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 962 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
963 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 963 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
964 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform()); 964 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform());
965 } 965 }
966 966
967 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithM ultipleScrollDeltas) 967 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithM ultipleScrollDeltas)
968 { 968 {
969 // This test checks for correct scroll compensation when the fixed-position container 969 // This test checks for correct scroll compensation when the fixed-position container
970 // has multiple ancestors that have nonzero scrollDelta before reaching the space where the layer is fixed. 970 // has multiple ancestors that have nonzero scrollDelta before reaching the space where the layer is fixed.
971 // In this test, each scrollDelta occurs in a different space because of eac h layer's local transform. 971 // In this test, each scrollDelta occurs in a different space because of eac h layer's local transform.
972 // This test checks for correct scroll compensation when the fixed-position container 972 // This test checks for correct scroll compensation when the fixed-position container
973 // is NOT the direct parent of the fixed-position layer, and the hierarchy h as various 973 // is NOT the direct parent of the fixed-position layer, and the hierarchy h as various
974 // transforms that have to be processed in the correct order. 974 // transforms that have to be processed in the correct order.
975 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 975 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
976 LayerImpl* child = root->children()[0]; 976 LayerImpl* child = root->children()[0];
977 LayerImpl* grandChild = child->children()[0]; 977 LayerImpl* grandChild = child->children()[0];
978 LayerImpl* greatGrandChild = grandChild->children()[0]; 978 LayerImpl* greatGrandChild = grandChild->children()[0];
979 979
980 WebTransformationMatrix rotationAboutZ; 980 Transform rotationAboutZ;
981 rotationAboutZ.rotate3d(0, 0, 90); 981 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90);
Ian Vollick 2012/11/21 22:07:09 same comment here. We can pass the canonical vecto
982 982
983 child->setIsContainerForFixedPositionLayers(true); 983 child->setIsContainerForFixedPositionLayers(true);
984 child->setTransform(rotationAboutZ); 984 child->setTransform(rotationAboutZ);
985 grandChild->setPosition(gfx::PointF(8, 6)); 985 grandChild->setPosition(gfx::PointF(8, 6));
986 grandChild->setTransform(rotationAboutZ); 986 grandChild->setTransform(rotationAboutZ);
987 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget. 987 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget.
988 988
989 // Case 1: scrollDelta of 0, 0 989 // Case 1: scrollDelta of 0, 0
990 child->setScrollDelta(gfx::Vector2d(0, 0)); 990 child->setScrollDelta(gfx::Vector2d(0, 0));
991 executeCalculateDrawTransformsAndVisibility(root.get()); 991 executeCalculateDrawTransformsAndVisibility(root.get());
992 992
993 WebTransformationMatrix expectedChildTransform; 993 Transform expectedChildTransform;
994 expectedChildTransform.multiply(rotationAboutZ); 994 expectedChildTransform.PreconcatTransform(rotationAboutZ);
995 995
996 WebTransformationMatrix expectedGrandChildTransform; 996 Transform expectedGrandChildTransform;
997 expectedGrandChildTransform.multiply(rotationAboutZ); // child's local trans form is inherited 997 expectedGrandChildTransform.PreconcatTransform(rotationAboutZ); // child's l ocal transform is inherited
998 expectedGrandChildTransform.translate(8, 6); // translation because of posit ion occurs before layer's local transform. 998 expectedGrandChildTransform.PreconcatTranslate(8, 6); // translation because of position occurs before layer's local transform.
999 expectedGrandChildTransform.multiply(rotationAboutZ); // grandChild's local transform 999 expectedGrandChildTransform.PreconcatTransform(rotationAboutZ); // grandChil d's local transform
1000 1000
1001 WebTransformationMatrix expectedGreatGrandChildTransform = expectedGrandChil dTransform; 1001 Transform expectedGreatGrandChildTransform = expectedGrandChildTransform;
1002 1002
1003 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 1003 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
1004 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 1004 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
1005 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform()); 1005 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform());
1006 1006
1007 // Case 2: scrollDelta of 10, 20 1007 // Case 2: scrollDelta of 10, 20
1008 child->setScrollDelta(gfx::Vector2d(10, 0)); 1008 child->setScrollDelta(gfx::Vector2d(10, 0));
1009 grandChild->setScrollDelta(gfx::Vector2d(5, 0)); 1009 grandChild->setScrollDelta(gfx::Vector2d(5, 0));
1010 executeCalculateDrawTransformsAndVisibility(root.get()); 1010 executeCalculateDrawTransformsAndVisibility(root.get());
1011 1011
1012 // Here the child and grandChild are affected by scrollDelta, but the fixed position greatGrandChild should not be affected. 1012 // Here the child and grandChild are affected by scrollDelta, but the fixed position greatGrandChild should not be affected.
1013 expectedChildTransform.makeIdentity(); 1013 expectedChildTransform.matrix().setIdentity();
1014 expectedChildTransform.translate(-10, 0); // scrollDelta 1014 expectedChildTransform.PreconcatTranslate(-10, 0); // scrollDelta
1015 expectedChildTransform.multiply(rotationAboutZ); 1015 expectedChildTransform.PreconcatTransform(rotationAboutZ);
1016 1016
1017 expectedGrandChildTransform.makeIdentity(); 1017 expectedGrandChildTransform.matrix().setIdentity();
1018 expectedGrandChildTransform.translate(-10, 0); // child's scrollDelta is inh erited 1018 expectedGrandChildTransform.PreconcatTranslate(-10, 0); // child's scrollDel ta is inherited
1019 expectedGrandChildTransform.multiply(rotationAboutZ); // child's local trans form is inherited 1019 expectedGrandChildTransform.PreconcatTransform(rotationAboutZ); // child's l ocal transform is inherited
1020 expectedGrandChildTransform.translate(-5, 0); // grandChild's scrollDelta 1020 expectedGrandChildTransform.PreconcatTranslate(-5, 0); // grandChild's scrol lDelta
1021 expectedGrandChildTransform.translate(8, 6); // translation because of posit ion occurs before layer's local transform. 1021 expectedGrandChildTransform.PreconcatTranslate(8, 6); // translation because of position occurs before layer's local transform.
1022 expectedGrandChildTransform.multiply(rotationAboutZ); // grandChild's local transform 1022 expectedGrandChildTransform.PreconcatTransform(rotationAboutZ); // grandChil d's local transform
1023 1023
1024 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 1024 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
1025 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 1025 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
1026 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform()); 1026 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform());
1027 } 1027 }
1028 1028
1029 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithI ntermediateSurfaceAndTransforms) 1029 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithI ntermediateSurfaceAndTransforms)
1030 { 1030 {
1031 // This test checks for correct scroll compensation when the fixed-position container 1031 // This test checks for correct scroll compensation when the fixed-position container
1032 // contributes to a different renderSurface than the fixed-position layer. I n this 1032 // contributes to a different renderSurface than the fixed-position layer. I n this
1033 // case, the surface drawTransforms also have to be accounted for when check ing the 1033 // case, the surface drawTransforms also have to be accounted for when check ing the
1034 // scrollDelta. 1034 // scrollDelta.
1035 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 1035 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
1036 LayerImpl* child = root->children()[0]; 1036 LayerImpl* child = root->children()[0];
1037 LayerImpl* grandChild = child->children()[0]; 1037 LayerImpl* grandChild = child->children()[0];
1038 LayerImpl* greatGrandChild = grandChild->children()[0]; 1038 LayerImpl* greatGrandChild = grandChild->children()[0];
1039 1039
1040 child->setIsContainerForFixedPositionLayers(true); 1040 child->setIsContainerForFixedPositionLayers(true);
1041 grandChild->setPosition(gfx::PointF(8, 6)); 1041 grandChild->setPosition(gfx::PointF(8, 6));
1042 grandChild->setForceRenderSurface(true); 1042 grandChild->setForceRenderSurface(true);
1043 greatGrandChild->setFixedToContainerLayer(true); 1043 greatGrandChild->setFixedToContainerLayer(true);
1044 greatGrandChild->setDrawsContent(true); 1044 greatGrandChild->setDrawsContent(true);
1045 1045
1046 WebTransformationMatrix rotationAboutZ; 1046 Transform rotationAboutZ;
1047 rotationAboutZ.rotate3d(0, 0, 90); 1047 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90);
1048 grandChild->setTransform(rotationAboutZ); 1048 grandChild->setTransform(rotationAboutZ);
1049 1049
1050 // Case 1: scrollDelta of 0, 0 1050 // Case 1: scrollDelta of 0, 0
1051 child->setScrollDelta(gfx::Vector2d(0, 0)); 1051 child->setScrollDelta(gfx::Vector2d(0, 0));
1052 executeCalculateDrawTransformsAndVisibility(root.get()); 1052 executeCalculateDrawTransformsAndVisibility(root.get());
1053 1053
1054 WebTransformationMatrix expectedChildTransform; 1054 Transform expectedChildTransform;
1055 WebTransformationMatrix expectedSurfaceDrawTransform; 1055 Transform expectedSurfaceDrawTransform;
1056 expectedSurfaceDrawTransform.translate(8, 6); 1056 expectedSurfaceDrawTransform.PreconcatTranslate(8, 6);
1057 expectedSurfaceDrawTransform.multiply(rotationAboutZ); 1057 expectedSurfaceDrawTransform.PreconcatTransform(rotationAboutZ);
1058 WebTransformationMatrix expectedGrandChildTransform; 1058 Transform expectedGrandChildTransform;
1059 WebTransformationMatrix expectedGreatGrandChildTransform; 1059 Transform expectedGreatGrandChildTransform;
1060 ASSERT_TRUE(grandChild->renderSurface()); 1060 ASSERT_TRUE(grandChild->renderSurface());
1061 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 1061 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
1062 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceDrawTransform, grandChild->re nderSurface()->drawTransform()); 1062 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceDrawTransform, grandChild->re nderSurface()->drawTransform());
1063 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 1063 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
1064 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform()); 1064 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform());
1065 1065
1066 // Case 2: scrollDelta of 10, 30 1066 // Case 2: scrollDelta of 10, 30
1067 child->setScrollDelta(gfx::Vector2d(10, 30)); 1067 child->setScrollDelta(gfx::Vector2d(10, 30));
1068 executeCalculateDrawTransformsAndVisibility(root.get()); 1068 executeCalculateDrawTransformsAndVisibility(root.get());
1069 1069
1070 // Here the grandChild remains unchanged, because it scrolls along with the 1070 // Here the grandChild remains unchanged, because it scrolls along with the
1071 // renderSurface, and the translation is actually in the renderSurface. But, the fixed 1071 // renderSurface, and the translation is actually in the renderSurface. But, the fixed
1072 // position greatGrandChild is more awkward: its actually being drawn with r espect to 1072 // position greatGrandChild is more awkward: its actually being drawn with r espect to
1073 // the renderSurface, but it needs to remain fixed with resepct to a contain er beyond 1073 // the renderSurface, but it needs to remain fixed with resepct to a contain er beyond
1074 // that surface. So, the net result is that, unlike previous tests where the fixed 1074 // that surface. So, the net result is that, unlike previous tests where the fixed
1075 // position layer's transform remains unchanged, here the fixed position lay er's 1075 // position layer's transform remains unchanged, here the fixed position lay er's
1076 // transform explicitly contains the translation that cancels out the scroll . 1076 // transform explicitly contains the translation that cancels out the scroll .
1077 expectedChildTransform.makeIdentity(); 1077 expectedChildTransform.matrix().setIdentity();
1078 expectedChildTransform.translate(-10, -30); // scrollDelta 1078 expectedChildTransform.PreconcatTranslate(-10, -30); // scrollDelta
1079 1079
1080 expectedSurfaceDrawTransform.makeIdentity(); 1080 expectedSurfaceDrawTransform.matrix().setIdentity();
1081 expectedSurfaceDrawTransform.translate(-10, -30); // scrollDelta 1081 expectedSurfaceDrawTransform.PreconcatTranslate(-10, -30); // scrollDelta
1082 expectedSurfaceDrawTransform.translate(8, 6); 1082 expectedSurfaceDrawTransform.PreconcatTranslate(8, 6);
1083 expectedSurfaceDrawTransform.multiply(rotationAboutZ); 1083 expectedSurfaceDrawTransform.PreconcatTransform(rotationAboutZ);
1084 1084
1085 // The rotation and its inverse are needed to place the scrollDelta compensa tion in 1085 // The rotation and its inverse are needed to place the scrollDelta compensa tion in
1086 // the correct space. This test will fail if the rotation/inverse are backwa rds, too, 1086 // the correct space. This test will fail if the rotation/inverse are backwa rds, too,
1087 // so it requires perfect order of operations. 1087 // so it requires perfect order of operations.
1088 expectedGreatGrandChildTransform.makeIdentity(); 1088 expectedGreatGrandChildTransform.matrix().setIdentity();
1089 expectedGreatGrandChildTransform.multiply(rotationAboutZ.inverse()); 1089 expectedGreatGrandChildTransform.PreconcatTransform(MathUtil::inverse(rotati onAboutZ));
1090 expectedGreatGrandChildTransform.translate(10, 30); // explicit canceling ou t the scrollDelta that gets embedded in the fixed position layer's surface. 1090 expectedGreatGrandChildTransform.PreconcatTranslate(10, 30); // explicit can celing out the scrollDelta that gets embedded in the fixed position layer's surf ace.
1091 expectedGreatGrandChildTransform.multiply(rotationAboutZ); 1091 expectedGreatGrandChildTransform.PreconcatTransform(rotationAboutZ);
1092 1092
1093 ASSERT_TRUE(grandChild->renderSurface()); 1093 ASSERT_TRUE(grandChild->renderSurface());
1094 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 1094 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
1095 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceDrawTransform, grandChild->re nderSurface()->drawTransform()); 1095 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceDrawTransform, grandChild->re nderSurface()->drawTransform());
1096 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 1096 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
1097 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform()); 1097 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform());
1098 } 1098 }
1099 1099
1100 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithM ultipleIntermediateSurfaces) 1100 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithM ultipleIntermediateSurfaces)
1101 { 1101 {
1102 // This test checks for correct scroll compensation when the fixed-position container 1102 // This test checks for correct scroll compensation when the fixed-position container
1103 // contributes to a different renderSurface than the fixed-position layer, w ith 1103 // contributes to a different renderSurface than the fixed-position layer, w ith
1104 // additional renderSurfaces in-between. This checks that the conversion to ancestor 1104 // additional renderSurfaces in-between. This checks that the conversion to ancestor
1105 // surfaces is accumulated properly in the final matrix transform. 1105 // surfaces is accumulated properly in the final matrix transform.
1106 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 1106 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
1107 LayerImpl* child = root->children()[0]; 1107 LayerImpl* child = root->children()[0];
1108 LayerImpl* grandChild = child->children()[0]; 1108 LayerImpl* grandChild = child->children()[0];
1109 LayerImpl* greatGrandChild = grandChild->children()[0]; 1109 LayerImpl* greatGrandChild = grandChild->children()[0];
1110 1110
1111 // Add one more layer to the test tree for this scenario. 1111 // Add one more layer to the test tree for this scenario.
1112 { 1112 {
1113 WebTransformationMatrix identity; 1113 Transform identity;
1114 scoped_ptr<LayerImpl> fixedPositionChild = LayerImpl::create(5); 1114 scoped_ptr<LayerImpl> fixedPositionChild = LayerImpl::create(5);
1115 setLayerPropertiesForTesting(fixedPositionChild.get(), identity, identit y, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 1115 setLayerPropertiesForTesting(fixedPositionChild.get(), identity, identit y, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
1116 greatGrandChild->addChild(fixedPositionChild.Pass()); 1116 greatGrandChild->addChild(fixedPositionChild.Pass());
1117 } 1117 }
1118 LayerImpl* fixedPositionChild = greatGrandChild->children()[0]; 1118 LayerImpl* fixedPositionChild = greatGrandChild->children()[0];
1119 1119
1120 // Actually set up the scenario here. 1120 // Actually set up the scenario here.
1121 child->setIsContainerForFixedPositionLayers(true); 1121 child->setIsContainerForFixedPositionLayers(true);
1122 grandChild->setPosition(gfx::PointF(8, 6)); 1122 grandChild->setPosition(gfx::PointF(8, 6));
1123 grandChild->setForceRenderSurface(true); 1123 grandChild->setForceRenderSurface(true);
1124 greatGrandChild->setPosition(gfx::PointF(40, 60)); 1124 greatGrandChild->setPosition(gfx::PointF(40, 60));
1125 greatGrandChild->setForceRenderSurface(true); 1125 greatGrandChild->setForceRenderSurface(true);
1126 fixedPositionChild->setFixedToContainerLayer(true); 1126 fixedPositionChild->setFixedToContainerLayer(true);
1127 fixedPositionChild->setDrawsContent(true); 1127 fixedPositionChild->setDrawsContent(true);
1128 1128
1129 // The additional rotations, which are non-commutative with translations, he lp to 1129 // The additional rotations, which are non-commutative with translations, he lp to
1130 // verify that we have correct order-of-operations in the final scroll compe nsation. 1130 // verify that we have correct order-of-operations in the final scroll compe nsation.
1131 // Note that rotating about the center of the layer ensures we do not accide ntally 1131 // Note that rotating about the center of the layer ensures we do not accide ntally
1132 // clip away layers that we want to test. 1132 // clip away layers that we want to test.
1133 WebTransformationMatrix rotationAboutZ; 1133 Transform rotationAboutZ;
1134 rotationAboutZ.translate(50, 50); 1134 rotationAboutZ.PreconcatTranslate(50, 50);
1135 rotationAboutZ.rotate3d(0, 0, 90); 1135 MathUtil::rotateEulerAngles(&rotationAboutZ, 0, 0, 90);
1136 rotationAboutZ.translate(-50, -50); 1136 rotationAboutZ.PreconcatTranslate(-50, -50);
1137 grandChild->setTransform(rotationAboutZ); 1137 grandChild->setTransform(rotationAboutZ);
1138 greatGrandChild->setTransform(rotationAboutZ); 1138 greatGrandChild->setTransform(rotationAboutZ);
1139 1139
1140 // Case 1: scrollDelta of 0, 0 1140 // Case 1: scrollDelta of 0, 0
1141 child->setScrollDelta(gfx::Vector2d(0, 0)); 1141 child->setScrollDelta(gfx::Vector2d(0, 0));
1142 executeCalculateDrawTransformsAndVisibility(root.get()); 1142 executeCalculateDrawTransformsAndVisibility(root.get());
1143 1143
1144 WebTransformationMatrix expectedChildTransform; 1144 Transform expectedChildTransform;
1145 1145
1146 WebTransformationMatrix expectedGrandChildSurfaceDrawTransform; 1146 Transform expectedGrandChildSurfaceDrawTransform;
1147 expectedGrandChildSurfaceDrawTransform.translate(8, 6); 1147 expectedGrandChildSurfaceDrawTransform.PreconcatTranslate(8, 6);
1148 expectedGrandChildSurfaceDrawTransform.multiply(rotationAboutZ); 1148 expectedGrandChildSurfaceDrawTransform.PreconcatTransform(rotationAboutZ);
1149 1149
1150 WebTransformationMatrix expectedGrandChildTransform; 1150 Transform expectedGrandChildTransform;
1151 1151
1152 WebTransformationMatrix expectedGreatGrandChildSurfaceDrawTransform; 1152 Transform expectedGreatGrandChildSurfaceDrawTransform;
1153 expectedGreatGrandChildSurfaceDrawTransform.translate(40, 60); 1153 expectedGreatGrandChildSurfaceDrawTransform.PreconcatTranslate(40, 60);
1154 expectedGreatGrandChildSurfaceDrawTransform.multiply(rotationAboutZ); 1154 expectedGreatGrandChildSurfaceDrawTransform.PreconcatTransform(rotationAbout Z);
1155 1155
1156 WebTransformationMatrix expectedGreatGrandChildTransform; 1156 Transform expectedGreatGrandChildTransform;
1157 1157
1158 WebTransformationMatrix expectedFixedPositionChildTransform; 1158 Transform expectedFixedPositionChildTransform;
1159 1159
1160 ASSERT_TRUE(grandChild->renderSurface()); 1160 ASSERT_TRUE(grandChild->renderSurface());
1161 ASSERT_TRUE(greatGrandChild->renderSurface()); 1161 ASSERT_TRUE(greatGrandChild->renderSurface());
1162 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 1162 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
1163 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildSurfaceDrawTransform, gran dChild->renderSurface()->drawTransform()); 1163 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildSurfaceDrawTransform, gran dChild->renderSurface()->drawTransform());
1164 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 1164 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
1165 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildSurfaceDrawTransform, greatGrandChild->renderSurface()->drawTransform()); 1165 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildSurfaceDrawTransform, greatGrandChild->renderSurface()->drawTransform());
1166 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform()); 1166 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform());
1167 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedFixedPositionChildTransform, fixedPo sitionChild->drawTransform()); 1167 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedFixedPositionChildTransform, fixedPo sitionChild->drawTransform());
1168 1168
1169 // Case 2: scrollDelta of 10, 30 1169 // Case 2: scrollDelta of 10, 30
1170 child->setScrollDelta(gfx::Vector2d(10, 30)); 1170 child->setScrollDelta(gfx::Vector2d(10, 30));
1171 executeCalculateDrawTransformsAndVisibility(root.get()); 1171 executeCalculateDrawTransformsAndVisibility(root.get());
1172 1172
1173 expectedChildTransform.makeIdentity(); 1173 expectedChildTransform.matrix().setIdentity();
1174 expectedChildTransform.translate(-10, -30); // scrollDelta 1174 expectedChildTransform.PreconcatTranslate(-10, -30); // scrollDelta
1175 1175
1176 expectedGrandChildSurfaceDrawTransform.makeIdentity(); 1176 expectedGrandChildSurfaceDrawTransform.matrix().setIdentity();
1177 expectedGrandChildSurfaceDrawTransform.translate(-10, -30); // scrollDelta 1177 expectedGrandChildSurfaceDrawTransform.PreconcatTranslate(-10, -30); // scro llDelta
1178 expectedGrandChildSurfaceDrawTransform.translate(8, 6); 1178 expectedGrandChildSurfaceDrawTransform.PreconcatTranslate(8, 6);
1179 expectedGrandChildSurfaceDrawTransform.multiply(rotationAboutZ); 1179 expectedGrandChildSurfaceDrawTransform.PreconcatTransform(rotationAboutZ);
1180 1180
1181 // grandChild, greatGrandChild, and greatGrandChild's surface are not expect ed to 1181 // grandChild, greatGrandChild, and greatGrandChild's surface are not expect ed to
1182 // change, since they are all not fixed, and they are all drawn with respect to 1182 // change, since they are all not fixed, and they are all drawn with respect to
1183 // grandChild's surface that already has the scrollDelta accounted for. 1183 // grandChild's surface that already has the scrollDelta accounted for.
1184 1184
1185 // But the great-great grandchild, "fixedPositionChild", should have a trans form that explicitly cancels out the scrollDelta. 1185 // But the great-great grandchild, "fixedPositionChild", should have a trans form that explicitly cancels out the scrollDelta.
1186 // The expected transform is: 1186 // The expected transform is:
1187 // compoundDrawTransform.inverse() * translate(positive scrollDelta) * com poundOriginTransform 1187 // compoundDrawTransform.inverse() * translate(positive scrollDelta) * com poundOriginTransform
1188 WebTransformationMatrix compoundDrawTransform; // transform from greatGrandC hildSurface's origin to the root surface. 1188 Transform compoundDrawTransform; // transform from greatGrandChildSurface's origin to the root surface.
1189 compoundDrawTransform.translate(8, 6); // origin translation of grandChild 1189 compoundDrawTransform.PreconcatTranslate(8, 6); // origin translation of gra ndChild
1190 compoundDrawTransform.multiply(rotationAboutZ); // rotation of grandChild 1190 compoundDrawTransform.PreconcatTransform(rotationAboutZ); // rotation of gra ndChild
1191 compoundDrawTransform.translate(40, 60); // origin translation of greatGrand Child 1191 compoundDrawTransform.PreconcatTranslate(40, 60); // origin translation of g reatGrandChild
1192 compoundDrawTransform.multiply(rotationAboutZ); // rotation of greatGrandChi ld 1192 compoundDrawTransform.PreconcatTransform(rotationAboutZ); // rotation of gre atGrandChild
1193 1193
1194 expectedFixedPositionChildTransform.makeIdentity(); 1194 expectedFixedPositionChildTransform.matrix().setIdentity();
1195 expectedFixedPositionChildTransform.multiply(compoundDrawTransform.inverse() ); 1195 expectedFixedPositionChildTransform.PreconcatTransform(MathUtil::inverse(com poundDrawTransform));
1196 expectedFixedPositionChildTransform.translate(10, 30); // explicit canceling out the scrollDelta that gets embedded in the fixed position layer's surface. 1196 expectedFixedPositionChildTransform.PreconcatTranslate(10, 30); // explicit canceling out the scrollDelta that gets embedded in the fixed position layer's s urface.
1197 expectedFixedPositionChildTransform.multiply(compoundDrawTransform); 1197 expectedFixedPositionChildTransform.PreconcatTransform(compoundDrawTransform );
1198 1198
1199 ASSERT_TRUE(grandChild->renderSurface()); 1199 ASSERT_TRUE(grandChild->renderSurface());
1200 ASSERT_TRUE(greatGrandChild->renderSurface()); 1200 ASSERT_TRUE(greatGrandChild->renderSurface());
1201 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 1201 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
1202 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildSurfaceDrawTransform, gran dChild->renderSurface()->drawTransform()); 1202 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildSurfaceDrawTransform, gran dChild->renderSurface()->drawTransform());
1203 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 1203 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
1204 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildSurfaceDrawTransform, greatGrandChild->renderSurface()->drawTransform()); 1204 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildSurfaceDrawTransform, greatGrandChild->renderSurface()->drawTransform());
1205 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform()); 1205 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrand Child->drawTransform());
1206 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedFixedPositionChildTransform, fixedPo sitionChild->drawTransform()); 1206 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedFixedPositionChildTransform, fixedPo sitionChild->drawTransform());
1207 } 1207 }
(...skipping 10 matching lines...) Expand all
1218 1218
1219 child->setIsContainerForFixedPositionLayers(true); 1219 child->setIsContainerForFixedPositionLayers(true);
1220 child->setForceRenderSurface(true); 1220 child->setForceRenderSurface(true);
1221 grandChild->setFixedToContainerLayer(true); 1221 grandChild->setFixedToContainerLayer(true);
1222 grandChild->setDrawsContent(true); 1222 grandChild->setDrawsContent(true);
1223 1223
1224 // Case 1: scrollDelta of 0, 0 1224 // Case 1: scrollDelta of 0, 0
1225 child->setScrollDelta(gfx::Vector2d(0, 0)); 1225 child->setScrollDelta(gfx::Vector2d(0, 0));
1226 executeCalculateDrawTransformsAndVisibility(root.get()); 1226 executeCalculateDrawTransformsAndVisibility(root.get());
1227 1227
1228 WebTransformationMatrix expectedSurfaceDrawTransform; 1228 Transform expectedSurfaceDrawTransform;
1229 expectedSurfaceDrawTransform.translate(0, 0); 1229 expectedSurfaceDrawTransform.PreconcatTranslate(0, 0);
1230 WebTransformationMatrix expectedChildTransform; 1230 Transform expectedChildTransform;
1231 WebTransformationMatrix expectedGrandChildTransform; 1231 Transform expectedGrandChildTransform;
1232 ASSERT_TRUE(child->renderSurface()); 1232 ASSERT_TRUE(child->renderSurface());
1233 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceDrawTransform, child->renderS urface()->drawTransform()); 1233 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceDrawTransform, child->renderS urface()->drawTransform());
1234 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 1234 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
1235 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 1235 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
1236 1236
1237 // Case 2: scrollDelta of 10, 10 1237 // Case 2: scrollDelta of 10, 10
1238 child->setScrollDelta(gfx::Vector2d(10, 10)); 1238 child->setScrollDelta(gfx::Vector2d(10, 10));
1239 executeCalculateDrawTransformsAndVisibility(root.get()); 1239 executeCalculateDrawTransformsAndVisibility(root.get());
1240 1240
1241 // The surface is translated by scrollDelta, the child transform doesn't cha nge 1241 // The surface is translated by scrollDelta, the child transform doesn't cha nge
1242 // because it scrolls along with the surface, but the fixed position grandCh ild 1242 // because it scrolls along with the surface, but the fixed position grandCh ild
1243 // needs to compensate for the scroll translation. 1243 // needs to compensate for the scroll translation.
1244 expectedSurfaceDrawTransform.makeIdentity(); 1244 expectedSurfaceDrawTransform.matrix().setIdentity();
1245 expectedSurfaceDrawTransform.translate(-10, -10); 1245 expectedSurfaceDrawTransform.PreconcatTranslate(-10, -10);
1246 expectedGrandChildTransform.makeIdentity(); 1246 expectedGrandChildTransform.matrix().setIdentity();
1247 expectedGrandChildTransform.translate(10, 10); 1247 expectedGrandChildTransform.PreconcatTranslate(10, 10);
1248 1248
1249 ASSERT_TRUE(child->renderSurface()); 1249 ASSERT_TRUE(child->renderSurface());
1250 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceDrawTransform, child->renderS urface()->drawTransform()); 1250 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceDrawTransform, child->renderS urface()->drawTransform());
1251 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 1251 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
1252 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 1252 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
1253 } 1253 }
1254 1254
1255 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerThatI sAlsoFixedPositionContainer) 1255 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerThatI sAlsoFixedPositionContainer)
1256 { 1256 {
1257 // This test checks the scenario where a fixed-position layer also happens t o be a 1257 // This test checks the scenario where a fixed-position layer also happens t o be a
1258 // container itself for a descendant fixed position layer. In particular, th e layer 1258 // container itself for a descendant fixed position layer. In particular, th e layer
1259 // should not accidentally be fixed to itself. 1259 // should not accidentally be fixed to itself.
1260 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 1260 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
1261 LayerImpl* child = root->children()[0]; 1261 LayerImpl* child = root->children()[0];
1262 LayerImpl* grandChild = child->children()[0]; 1262 LayerImpl* grandChild = child->children()[0];
1263 1263
1264 child->setIsContainerForFixedPositionLayers(true); 1264 child->setIsContainerForFixedPositionLayers(true);
1265 grandChild->setFixedToContainerLayer(true); 1265 grandChild->setFixedToContainerLayer(true);
1266 1266
1267 // This should not confuse the grandChild. If correct, the grandChild would still be considered fixed to its container (i.e. "child"). 1267 // This should not confuse the grandChild. If correct, the grandChild would still be considered fixed to its container (i.e. "child").
1268 grandChild->setIsContainerForFixedPositionLayers(true); 1268 grandChild->setIsContainerForFixedPositionLayers(true);
1269 1269
1270 // Case 1: scrollDelta of 0, 0 1270 // Case 1: scrollDelta of 0, 0
1271 child->setScrollDelta(gfx::Vector2d(0, 0)); 1271 child->setScrollDelta(gfx::Vector2d(0, 0));
1272 executeCalculateDrawTransformsAndVisibility(root.get()); 1272 executeCalculateDrawTransformsAndVisibility(root.get());
1273 1273
1274 WebTransformationMatrix expectedChildTransform; 1274 Transform expectedChildTransform;
1275 WebTransformationMatrix expectedGrandChildTransform; 1275 Transform expectedGrandChildTransform;
1276 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 1276 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
1277 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 1277 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
1278 1278
1279 // Case 2: scrollDelta of 10, 10 1279 // Case 2: scrollDelta of 10, 10
1280 child->setScrollDelta(gfx::Vector2d(10, 10)); 1280 child->setScrollDelta(gfx::Vector2d(10, 10));
1281 executeCalculateDrawTransformsAndVisibility(root.get()); 1281 executeCalculateDrawTransformsAndVisibility(root.get());
1282 1282
1283 // Here the child is affected by scrollDelta, but the fixed position grandCh ild should not be affected. 1283 // Here the child is affected by scrollDelta, but the fixed position grandCh ild should not be affected.
1284 expectedChildTransform.makeIdentity(); 1284 expectedChildTransform.matrix().setIdentity();
1285 expectedChildTransform.translate(-10, -10); 1285 expectedChildTransform.PreconcatTranslate(-10, -10);
1286 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 1286 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
1287 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 1287 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
1288 } 1288 }
1289 1289
1290 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerThatH asNoContainer) 1290 TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerThatH asNoContainer)
1291 { 1291 {
1292 // This test checks scroll compensation when a fixed-position layer does not find any 1292 // This test checks scroll compensation when a fixed-position layer does not find any
1293 // ancestor that is a "containerForFixedPositionLayers". In this situation, the layer should 1293 // ancestor that is a "containerForFixedPositionLayers". In this situation, the layer should
1294 // be fixed to the viewport -- not the rootLayer, which may have transforms of its own. 1294 // be fixed to the viewport -- not the rootLayer, which may have transforms of its own.
1295 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 1295 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
1296 LayerImpl* child = root->children()[0]; 1296 LayerImpl* child = root->children()[0];
1297 LayerImpl* grandChild = child->children()[0]; 1297 LayerImpl* grandChild = child->children()[0];
1298 1298
1299 WebTransformationMatrix rotationByZ; 1299 Transform rotationByZ;
1300 rotationByZ.rotate3d(0, 0, 90); 1300 MathUtil::rotateEulerAngles(&rotationByZ, 0, 0, 90);
1301 1301
1302 root->setTransform(rotationByZ); 1302 root->setTransform(rotationByZ);
1303 grandChild->setFixedToContainerLayer(true); 1303 grandChild->setFixedToContainerLayer(true);
1304 1304
1305 // Case 1: root scrollDelta of 0, 0 1305 // Case 1: root scrollDelta of 0, 0
1306 root->setScrollDelta(gfx::Vector2d(0, 0)); 1306 root->setScrollDelta(gfx::Vector2d(0, 0));
1307 executeCalculateDrawTransformsAndVisibility(root.get()); 1307 executeCalculateDrawTransformsAndVisibility(root.get());
1308 1308
1309 WebTransformationMatrix identityMatrix; 1309 Transform identityMatrix;
1310 1310
1311 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); 1311 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
1312 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ; 1312 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ;
1313 1313
1314 // Case 2: root scrollDelta of 10, 10 1314 // Case 2: root scrollDelta of 10, 10
1315 root->setScrollDelta(gfx::Vector2d(10, 20)); 1315 root->setScrollDelta(gfx::Vector2d(10, 20));
1316 executeCalculateDrawTransformsAndVisibility(root.get()); 1316 executeCalculateDrawTransformsAndVisibility(root.get());
1317 1317
1318 // The child is affected by scrollDelta, but it is already implcitly account ed for by 1318 // The child is affected by scrollDelta, but it is already implcitly account ed for by
1319 // the child's target surface (i.e. the root renderSurface). The grandChild is not 1319 // the child's target surface (i.e. the root renderSurface). The grandChild is not
1320 // affected by the scrollDelta, so its drawTransform needs to explicitly 1320 // affected by the scrollDelta, so its drawTransform needs to explicitly
1321 // inverse-compensate for the scroll that's embedded in the target surface. 1321 // inverse-compensate for the scroll that's embedded in the target surface.
1322 WebTransformationMatrix expectedGrandChildTransform; 1322 Transform expectedGrandChildTransform;
1323 expectedGrandChildTransform.multiply(rotationByZ.inverse()); 1323 expectedGrandChildTransform.PreconcatTransform(MathUtil::inverse(rotationByZ ));
1324 expectedGrandChildTransform.translate(10, 20); // explicit canceling out the scrollDelta that gets embedded in the fixed position layer's surface. 1324 expectedGrandChildTransform.PreconcatTranslate(10, 20); // explicit cancelin g out the scrollDelta that gets embedded in the fixed position layer's surface.
1325 expectedGrandChildTransform.multiply(rotationByZ); 1325 expectedGrandChildTransform.PreconcatTransform(rotationByZ);
1326 1326
1327 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); 1327 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
1328 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform()); 1328 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->dra wTransform());
1329 } 1329 }
1330 1330
1331 TEST(LayerTreeHostCommonTest, verifyClipRectCullsRenderSurfaces) 1331 TEST(LayerTreeHostCommonTest, verifyClipRectCullsRenderSurfaces)
1332 { 1332 {
1333 // The entire subtree of layers that are outside the clipRect should be cull ed away, 1333 // The entire subtree of layers that are outside the clipRect should be cull ed away,
1334 // and should not affect the renderSurfaceLayerList. 1334 // and should not affect the renderSurfaceLayerList.
1335 // 1335 //
1336 // The test tree is set up as follows: 1336 // The test tree is set up as follows:
1337 // - all layers except the leafNodes are forced to be a new renderSurface t hat have something to draw. 1337 // - all layers except the leafNodes are forced to be a new renderSurface t hat have something to draw.
1338 // - parent is a large container layer. 1338 // - parent is a large container layer.
1339 // - child has masksToBounds=true to cause clipping. 1339 // - child has masksToBounds=true to cause clipping.
1340 // - grandChild is positioned outside of the child's bounds 1340 // - grandChild is positioned outside of the child's bounds
1341 // - greatGrandChild is also kept outside child's bounds. 1341 // - greatGrandChild is also kept outside child's bounds.
1342 // 1342 //
1343 // In this configuration, grandChild and greatGrandChild are completely outs ide the 1343 // In this configuration, grandChild and greatGrandChild are completely outs ide the
1344 // clipRect, and they should never get scheduled on the list of renderSurfac es. 1344 // clipRect, and they should never get scheduled on the list of renderSurfac es.
1345 // 1345 //
1346 1346
1347 const WebTransformationMatrix identityMatrix; 1347 const Transform identityMatrix;
1348 scoped_refptr<Layer> parent = Layer::create(); 1348 scoped_refptr<Layer> parent = Layer::create();
1349 scoped_refptr<Layer> child = Layer::create(); 1349 scoped_refptr<Layer> child = Layer::create();
1350 scoped_refptr<Layer> grandChild = Layer::create(); 1350 scoped_refptr<Layer> grandChild = Layer::create();
1351 scoped_refptr<Layer> greatGrandChild = Layer::create(); 1351 scoped_refptr<Layer> greatGrandChild = Layer::create();
1352 scoped_refptr<LayerWithForcedDrawsContent> leafNode1 = make_scoped_refptr(ne w LayerWithForcedDrawsContent()); 1352 scoped_refptr<LayerWithForcedDrawsContent> leafNode1 = make_scoped_refptr(ne w LayerWithForcedDrawsContent());
1353 scoped_refptr<LayerWithForcedDrawsContent> leafNode2 = make_scoped_refptr(ne w LayerWithForcedDrawsContent()); 1353 scoped_refptr<LayerWithForcedDrawsContent> leafNode2 = make_scoped_refptr(ne w LayerWithForcedDrawsContent());
1354 parent->addChild(child); 1354 parent->addChild(child);
1355 child->addChild(grandChild); 1355 child->addChild(grandChild);
1356 grandChild->addChild(greatGrandChild); 1356 grandChild->addChild(greatGrandChild);
1357 1357
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 // - parent is a container layer that masksToBounds=true to cause clipping. 1392 // - parent is a container layer that masksToBounds=true to cause clipping.
1393 // - child is a renderSurface, which has a clipRect set to the bounds of th e parent. 1393 // - child is a renderSurface, which has a clipRect set to the bounds of th e parent.
1394 // - grandChild is a renderSurface, and the only visible content in child. It is positioned outside of the clipRect from parent. 1394 // - grandChild is a renderSurface, and the only visible content in child. It is positioned outside of the clipRect from parent.
1395 1395
1396 // In this configuration, grandChild should be outside the clipped 1396 // In this configuration, grandChild should be outside the clipped
1397 // contentRect of the child, making grandChild not appear in the 1397 // contentRect of the child, making grandChild not appear in the
1398 // renderSurfaceLayerList. However, when we place an animation on the child, 1398 // renderSurfaceLayerList. However, when we place an animation on the child,
1399 // this clipping should be avoided and we should keep the grandChild 1399 // this clipping should be avoided and we should keep the grandChild
1400 // in the renderSurfaceLayerList. 1400 // in the renderSurfaceLayerList.
1401 1401
1402 const WebTransformationMatrix identityMatrix; 1402 const Transform identityMatrix;
1403 scoped_refptr<Layer> parent = Layer::create(); 1403 scoped_refptr<Layer> parent = Layer::create();
1404 scoped_refptr<Layer> child = Layer::create(); 1404 scoped_refptr<Layer> child = Layer::create();
1405 scoped_refptr<Layer> grandChild = Layer::create(); 1405 scoped_refptr<Layer> grandChild = Layer::create();
1406 scoped_refptr<LayerWithForcedDrawsContent> leafNode = make_scoped_refptr(new LayerWithForcedDrawsContent()); 1406 scoped_refptr<LayerWithForcedDrawsContent> leafNode = make_scoped_refptr(new LayerWithForcedDrawsContent());
1407 parent->addChild(child); 1407 parent->addChild(child);
1408 child->addChild(grandChild); 1408 child->addChild(grandChild);
1409 grandChild->addChild(leafNode); 1409 grandChild->addChild(leafNode);
1410 1410
1411 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 1411 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
1412 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(20, 20), false); 1412 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(20, 20), false);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 TEST(LayerTreeHostCommonTest, verifyDrawableContentRectForLayers) 1445 TEST(LayerTreeHostCommonTest, verifyDrawableContentRectForLayers)
1446 { 1446 {
1447 // Verify that layers get the appropriate drawableContentRect when their par ent masksToBounds is true. 1447 // Verify that layers get the appropriate drawableContentRect when their par ent masksToBounds is true.
1448 // 1448 //
1449 // grandChild1 - completely inside the region; drawableContentRect should be the layer rect expressed in target space. 1449 // grandChild1 - completely inside the region; drawableContentRect should be the layer rect expressed in target space.
1450 // grandChild2 - partially clipped but NOT masksToBounds; the clipRect wil l be the intersection of layerBounds and the mask region. 1450 // grandChild2 - partially clipped but NOT masksToBounds; the clipRect wil l be the intersection of layerBounds and the mask region.
1451 // grandChild3 - partially clipped and masksToBounds; the drawableContentR ect will still be the intersection of layerBounds and the mask region. 1451 // grandChild3 - partially clipped and masksToBounds; the drawableContentR ect will still be the intersection of layerBounds and the mask region.
1452 // grandChild4 - outside parent's clipRect; the drawableContentRect should be empty. 1452 // grandChild4 - outside parent's clipRect; the drawableContentRect should be empty.
1453 // 1453 //
1454 1454
1455 const WebTransformationMatrix identityMatrix; 1455 const Transform identityMatrix;
1456 scoped_refptr<Layer> parent = Layer::create(); 1456 scoped_refptr<Layer> parent = Layer::create();
1457 scoped_refptr<Layer> child = Layer::create(); 1457 scoped_refptr<Layer> child = Layer::create();
1458 scoped_refptr<Layer> grandChild1 = Layer::create(); 1458 scoped_refptr<Layer> grandChild1 = Layer::create();
1459 scoped_refptr<Layer> grandChild2 = Layer::create(); 1459 scoped_refptr<Layer> grandChild2 = Layer::create();
1460 scoped_refptr<Layer> grandChild3 = Layer::create(); 1460 scoped_refptr<Layer> grandChild3 = Layer::create();
1461 scoped_refptr<Layer> grandChild4 = Layer::create(); 1461 scoped_refptr<Layer> grandChild4 = Layer::create();
1462 1462
1463 parent->addChild(child); 1463 parent->addChild(child);
1464 child->addChild(grandChild1); 1464 child->addChild(grandChild1);
1465 child->addChild(grandChild2); 1465 child->addChild(grandChild2);
(...skipping 29 matching lines...) Expand all
1495 1495
1496 TEST(LayerTreeHostCommonTest, verifyClipRectIsPropagatedCorrectlyToSurfaces) 1496 TEST(LayerTreeHostCommonTest, verifyClipRectIsPropagatedCorrectlyToSurfaces)
1497 { 1497 {
1498 // Verify that renderSurfaces (and their layers) get the appropriate clipRec ts when their parent masksToBounds is true. 1498 // Verify that renderSurfaces (and their layers) get the appropriate clipRec ts when their parent masksToBounds is true.
1499 // 1499 //
1500 // Layers that own renderSurfaces (at least for now) do not inherit any clip ping; 1500 // Layers that own renderSurfaces (at least for now) do not inherit any clip ping;
1501 // instead the surface will enforce the clip for the entire subtree. They ma y still 1501 // instead the surface will enforce the clip for the entire subtree. They ma y still
1502 // have a clipRect of their own layer bounds, however, if masksToBounds was true. 1502 // have a clipRect of their own layer bounds, however, if masksToBounds was true.
1503 // 1503 //
1504 1504
1505 const WebTransformationMatrix identityMatrix; 1505 const Transform identityMatrix;
1506 scoped_refptr<Layer> parent = Layer::create(); 1506 scoped_refptr<Layer> parent = Layer::create();
1507 scoped_refptr<Layer> child = Layer::create(); 1507 scoped_refptr<Layer> child = Layer::create();
1508 scoped_refptr<Layer> grandChild1 = Layer::create(); 1508 scoped_refptr<Layer> grandChild1 = Layer::create();
1509 scoped_refptr<Layer> grandChild2 = Layer::create(); 1509 scoped_refptr<Layer> grandChild2 = Layer::create();
1510 scoped_refptr<Layer> grandChild3 = Layer::create(); 1510 scoped_refptr<Layer> grandChild3 = Layer::create();
1511 scoped_refptr<Layer> grandChild4 = Layer::create(); 1511 scoped_refptr<Layer> grandChild4 = Layer::create();
1512 scoped_refptr<LayerWithForcedDrawsContent> leafNode1 = make_scoped_refptr(ne w LayerWithForcedDrawsContent()); 1512 scoped_refptr<LayerWithForcedDrawsContent> leafNode1 = make_scoped_refptr(ne w LayerWithForcedDrawsContent());
1513 scoped_refptr<LayerWithForcedDrawsContent> leafNode2 = make_scoped_refptr(ne w LayerWithForcedDrawsContent()); 1513 scoped_refptr<LayerWithForcedDrawsContent> leafNode2 = make_scoped_refptr(ne w LayerWithForcedDrawsContent());
1514 scoped_refptr<LayerWithForcedDrawsContent> leafNode3 = make_scoped_refptr(ne w LayerWithForcedDrawsContent()); 1514 scoped_refptr<LayerWithForcedDrawsContent> leafNode3 = make_scoped_refptr(ne w LayerWithForcedDrawsContent());
1515 scoped_refptr<LayerWithForcedDrawsContent> leafNode4 = make_scoped_refptr(ne w LayerWithForcedDrawsContent()); 1515 scoped_refptr<LayerWithForcedDrawsContent> leafNode4 = make_scoped_refptr(ne w LayerWithForcedDrawsContent());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 // Make our render surfaces. 1586 // Make our render surfaces.
1587 renderSurface1->setForceRenderSurface(true); 1587 renderSurface1->setForceRenderSurface(true);
1588 renderSurface2->setForceRenderSurface(true); 1588 renderSurface2->setForceRenderSurface(true);
1589 1589
1590 // Put an animated opacity on the render surface. 1590 // Put an animated opacity on the render surface.
1591 addOpacityTransitionToController(*renderSurface1->layerAnimationController() , 10, 1, 0, false); 1591 addOpacityTransitionToController(*renderSurface1->layerAnimationController() , 10, 1, 0, false);
1592 1592
1593 // Also put an animated opacity on a layer without descendants. 1593 // Also put an animated opacity on a layer without descendants.
1594 addOpacityTransitionToController(*grandChildOfRoot->layerAnimationController (), 10, 1, 0, false); 1594 addOpacityTransitionToController(*grandChildOfRoot->layerAnimationController (), 10, 1, 0, false);
1595 1595
1596 WebTransformationMatrix layerTransform; 1596 Transform layerTransform;
1597 layerTransform.translate(1, 1); 1597 layerTransform.PreconcatTranslate(1, 1);
1598 WebTransformationMatrix sublayerTransform; 1598 Transform sublayerTransform;
1599 sublayerTransform.scale3d(10, 1, 1); 1599 sublayerTransform.PreconcatScale3d(10, 1, 1);
1600 1600
1601 // Put a transform animation on the render surface. 1601 // Put a transform animation on the render surface.
1602 addAnimatedTransformToController(*renderSurface2->layerAnimationController() , 10, 30, 0); 1602 addAnimatedTransformToController(*renderSurface2->layerAnimationController() , 10, 30, 0);
1603 1603
1604 // Also put transform animations on grandChildOfRoot, and grandChildOfRS2 1604 // Also put transform animations on grandChildOfRoot, and grandChildOfRS2
1605 addAnimatedTransformToController(*grandChildOfRoot->layerAnimationController (), 10, 30, 0); 1605 addAnimatedTransformToController(*grandChildOfRoot->layerAnimationController (), 10, 30, 0);
1606 addAnimatedTransformToController(*grandChildOfRS2->layerAnimationController( ), 10, 30, 0); 1606 addAnimatedTransformToController(*grandChildOfRS2->layerAnimationController( ), 10, 30, 0);
1607 1607
1608 setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform , gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false); 1608 setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform , gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1609 setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerT ransform, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false); 1609 setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerT ransform, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 EXPECT_FALSE(grandChildOfRS1->screenSpaceTransformIsAnimating()); 1684 EXPECT_FALSE(grandChildOfRS1->screenSpaceTransformIsAnimating());
1685 EXPECT_TRUE(renderSurface2->screenSpaceTransformIsAnimating()); 1685 EXPECT_TRUE(renderSurface2->screenSpaceTransformIsAnimating());
1686 EXPECT_TRUE(renderSurface2->renderSurface()->screenSpaceTransformsAreAnimati ng()); 1686 EXPECT_TRUE(renderSurface2->renderSurface()->screenSpaceTransformsAreAnimati ng());
1687 EXPECT_TRUE(childOfRS2->screenSpaceTransformIsAnimating()); 1687 EXPECT_TRUE(childOfRS2->screenSpaceTransformIsAnimating());
1688 EXPECT_TRUE(grandChildOfRS2->screenSpaceTransformIsAnimating()); 1688 EXPECT_TRUE(grandChildOfRS2->screenSpaceTransformIsAnimating());
1689 1689
1690 1690
1691 // Sanity check. If these fail there is probably a bug in the test itself. 1691 // Sanity check. If these fail there is probably a bug in the test itself.
1692 // It is expected that we correctly set up transforms so that the y-componen t of the screen-space transform 1692 // It is expected that we correctly set up transforms so that the y-componen t of the screen-space transform
1693 // encodes the "depth" of the layer in the tree. 1693 // encodes the "depth" of the layer in the tree.
1694 EXPECT_FLOAT_EQ(1, parent->screenSpaceTransform().m42()); 1694 EXPECT_FLOAT_EQ(1, parent->screenSpaceTransform().matrix().getDouble(1, 3));
1695 EXPECT_FLOAT_EQ(2, childOfRoot->screenSpaceTransform().m42()); 1695 EXPECT_FLOAT_EQ(2, childOfRoot->screenSpaceTransform().matrix().getDouble(1, 3));
1696 EXPECT_FLOAT_EQ(3, grandChildOfRoot->screenSpaceTransform().m42()); 1696 EXPECT_FLOAT_EQ(3, grandChildOfRoot->screenSpaceTransform().matrix().getDoub le(1, 3));
1697 1697
1698 EXPECT_FLOAT_EQ(2, renderSurface1->screenSpaceTransform().m42()); 1698 EXPECT_FLOAT_EQ(2, renderSurface1->screenSpaceTransform().matrix().getDouble (1, 3));
1699 EXPECT_FLOAT_EQ(3, childOfRS1->screenSpaceTransform().m42()); 1699 EXPECT_FLOAT_EQ(3, childOfRS1->screenSpaceTransform().matrix().getDouble(1, 3));
1700 EXPECT_FLOAT_EQ(4, grandChildOfRS1->screenSpaceTransform().m42()); 1700 EXPECT_FLOAT_EQ(4, grandChildOfRS1->screenSpaceTransform().matrix().getDoubl e(1, 3));
1701 1701
1702 EXPECT_FLOAT_EQ(3, renderSurface2->screenSpaceTransform().m42()); 1702 EXPECT_FLOAT_EQ(3, renderSurface2->screenSpaceTransform().matrix().getDouble (1, 3));
1703 EXPECT_FLOAT_EQ(4, childOfRS2->screenSpaceTransform().m42()); 1703 EXPECT_FLOAT_EQ(4, childOfRS2->screenSpaceTransform().matrix().getDouble(1, 3));
1704 EXPECT_FLOAT_EQ(5, grandChildOfRS2->screenSpaceTransform().m42()); 1704 EXPECT_FLOAT_EQ(5, grandChildOfRS2->screenSpaceTransform().matrix().getDoubl e(1, 3));
1705 } 1705 }
1706 1706
1707 TEST(LayerTreeHostCommonTest, verifyVisibleRectForIdentityTransform) 1707 TEST(LayerTreeHostCommonTest, verifyVisibleRectForIdentityTransform)
1708 { 1708 {
1709 // Test the calculateVisibleRect() function works correctly for identity tra nsforms. 1709 // Test the calculateVisibleRect() function works correctly for identity tra nsforms.
1710 1710
1711 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 )); 1711 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1712 WebTransformationMatrix layerToSurfaceTransform; 1712 Transform layerToSurfaceTransform;
1713 1713
1714 // Case 1: Layer is contained within the surface. 1714 // Case 1: Layer is contained within the surface.
1715 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(10, 10), gfx::Size(30, 30) ); 1715 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(10, 10), gfx::Size(30, 30) );
1716 gfx::Rect expected = gfx::Rect(gfx::Point(10, 10), gfx::Size(30, 30)); 1716 gfx::Rect expected = gfx::Rect(gfx::Point(10, 10), gfx::Size(30, 30));
1717 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform); 1717 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1718 EXPECT_RECT_EQ(expected, actual); 1718 EXPECT_RECT_EQ(expected, actual);
1719 1719
1720 // Case 2: Layer is outside the surface rect. 1720 // Case 2: Layer is outside the surface rect.
1721 layerContentRect = gfx::Rect(gfx::Point(120, 120), gfx::Size(30, 30)); 1721 layerContentRect = gfx::Rect(gfx::Point(120, 120), gfx::Size(30, 30));
1722 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1722 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1723 EXPECT_TRUE(actual.IsEmpty()); 1723 EXPECT_TRUE(actual.IsEmpty());
1724 1724
1725 // Case 3: Layer is partially overlapping the surface rect. 1725 // Case 3: Layer is partially overlapping the surface rect.
1726 layerContentRect = gfx::Rect(gfx::Point(80, 80), gfx::Size(30, 30)); 1726 layerContentRect = gfx::Rect(gfx::Point(80, 80), gfx::Size(30, 30));
1727 expected = gfx::Rect(gfx::Point(80, 80), gfx::Size(20, 20)); 1727 expected = gfx::Rect(gfx::Point(80, 80), gfx::Size(20, 20));
1728 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1728 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1729 EXPECT_RECT_EQ(expected, actual); 1729 EXPECT_RECT_EQ(expected, actual);
1730 } 1730 }
1731 1731
1732 TEST(LayerTreeHostCommonTest, verifyVisibleRectForTranslations) 1732 TEST(LayerTreeHostCommonTest, verifyVisibleRectForTranslations)
1733 { 1733 {
1734 // Test the calculateVisibleRect() function works correctly for scaling tran sforms. 1734 // Test the calculateVisibleRect() function works correctly for scaling tran sforms.
1735 1735
1736 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 )); 1736 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1737 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30)); 1737 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30));
1738 WebTransformationMatrix layerToSurfaceTransform; 1738 Transform layerToSurfaceTransform;
1739 1739
1740 // Case 1: Layer is contained within the surface. 1740 // Case 1: Layer is contained within the surface.
1741 layerToSurfaceTransform.makeIdentity(); 1741 layerToSurfaceTransform.matrix().setIdentity();
1742 layerToSurfaceTransform.translate(10, 10); 1742 layerToSurfaceTransform.PreconcatTranslate(10, 10);
1743 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30)); 1743 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30));
1744 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform); 1744 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1745 EXPECT_RECT_EQ(expected, actual); 1745 EXPECT_RECT_EQ(expected, actual);
1746 1746
1747 // Case 2: Layer is outside the surface rect. 1747 // Case 2: Layer is outside the surface rect.
1748 layerToSurfaceTransform.makeIdentity(); 1748 layerToSurfaceTransform.matrix().setIdentity();
1749 layerToSurfaceTransform.translate(120, 120); 1749 layerToSurfaceTransform.PreconcatTranslate(120, 120);
1750 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1750 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1751 EXPECT_TRUE(actual.IsEmpty()); 1751 EXPECT_TRUE(actual.IsEmpty());
1752 1752
1753 // Case 3: Layer is partially overlapping the surface rect. 1753 // Case 3: Layer is partially overlapping the surface rect.
1754 layerToSurfaceTransform.makeIdentity(); 1754 layerToSurfaceTransform.matrix().setIdentity();
1755 layerToSurfaceTransform.translate(80, 80); 1755 layerToSurfaceTransform.PreconcatTranslate(80, 80);
1756 expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(20, 20)); 1756 expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(20, 20));
1757 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1757 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1758 EXPECT_RECT_EQ(expected, actual); 1758 EXPECT_RECT_EQ(expected, actual);
1759 } 1759 }
1760 1760
1761 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor2DRotations) 1761 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor2DRotations)
1762 { 1762 {
1763 // Test the calculateVisibleRect() function works correctly for rotations ab out z-axis (i.e. 2D rotations). 1763 // Test the calculateVisibleRect() function works correctly for rotations ab out z-axis (i.e. 2D rotations).
1764 // Remember that calculateVisibleRect() should return the visible rect in th e layer's space. 1764 // Remember that calculateVisibleRect() should return the visible rect in th e layer's space.
1765 1765
1766 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 )); 1766 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1767 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30)); 1767 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30));
1768 WebTransformationMatrix layerToSurfaceTransform; 1768 Transform layerToSurfaceTransform;
1769 1769
1770 // Case 1: Layer is contained within the surface. 1770 // Case 1: Layer is contained within the surface.
1771 layerToSurfaceTransform.makeIdentity(); 1771 layerToSurfaceTransform.matrix().setIdentity();
1772 layerToSurfaceTransform.translate(50, 50); 1772 layerToSurfaceTransform.PreconcatTranslate(50, 50);
1773 layerToSurfaceTransform.rotate(45); 1773 layerToSurfaceTransform.PreconcatRotate(45);
1774 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30)); 1774 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30));
1775 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform); 1775 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1776 EXPECT_RECT_EQ(expected, actual); 1776 EXPECT_RECT_EQ(expected, actual);
1777 1777
1778 // Case 2: Layer is outside the surface rect. 1778 // Case 2: Layer is outside the surface rect.
1779 layerToSurfaceTransform.makeIdentity(); 1779 layerToSurfaceTransform.matrix().setIdentity();
1780 layerToSurfaceTransform.translate(-50, 0); 1780 layerToSurfaceTransform.PreconcatTranslate(-50, 0);
1781 layerToSurfaceTransform.rotate(45); 1781 layerToSurfaceTransform.PreconcatRotate(45);
1782 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1782 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1783 EXPECT_TRUE(actual.IsEmpty()); 1783 EXPECT_TRUE(actual.IsEmpty());
1784 1784
1785 // Case 3: The layer is rotated about its top-left corner. In surface space, the layer 1785 // Case 3: The layer is rotated about its top-left corner. In surface space, the layer
1786 // is oriented diagonally, with the left half outside of the renderS urface. In 1786 // is oriented diagonally, with the left half outside of the renderS urface. In
1787 // this case, the visible rect should still be the entire layer (rem ember the 1787 // this case, the visible rect should still be the entire layer (rem ember the
1788 // visible rect is computed in layer space); both the top-left and 1788 // visible rect is computed in layer space); both the top-left and
1789 // bottom-right corners of the layer are still visible. 1789 // bottom-right corners of the layer are still visible.
1790 layerToSurfaceTransform.makeIdentity(); 1790 layerToSurfaceTransform.matrix().setIdentity();
1791 layerToSurfaceTransform.rotate(45); 1791 layerToSurfaceTransform.PreconcatRotate(45);
1792 expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30)); 1792 expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30));
1793 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1793 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1794 EXPECT_RECT_EQ(expected, actual); 1794 EXPECT_RECT_EQ(expected, actual);
1795 1795
1796 // Case 4: The layer is rotated about its top-left corner, and translated up wards. In 1796 // Case 4: The layer is rotated about its top-left corner, and translated up wards. In
1797 // surface space, the layer is oriented diagonally, with only the to p corner 1797 // surface space, the layer is oriented diagonally, with only the to p corner
1798 // of the surface overlapping the layer. In layer space, the render surface 1798 // of the surface overlapping the layer. In layer space, the render surface
1799 // overlaps the right side of the layer. The visible rect should be the 1799 // overlaps the right side of the layer. The visible rect should be the
1800 // layer's right half. 1800 // layer's right half.
1801 layerToSurfaceTransform.makeIdentity(); 1801 layerToSurfaceTransform.matrix().setIdentity();
1802 layerToSurfaceTransform.translate(0, -sqrt(2.0) * 15); 1802 layerToSurfaceTransform.PreconcatTranslate(0, -sqrt(2.0) * 15);
1803 layerToSurfaceTransform.rotate(45); 1803 layerToSurfaceTransform.PreconcatRotate(45);
1804 expected = gfx::Rect(gfx::Point(15, 0), gfx::Size(15, 30)); // right half of layer bounds. 1804 expected = gfx::Rect(gfx::Point(15, 0), gfx::Size(15, 30)); // right half of layer bounds.
1805 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1805 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1806 EXPECT_RECT_EQ(expected, actual); 1806 EXPECT_RECT_EQ(expected, actual);
1807 } 1807 }
1808 1808
1809 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform) 1809 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform)
1810 { 1810 {
1811 // Test that the calculateVisibleRect() function works correctly for 3d tran sforms. 1811 // Test that the calculateVisibleRect() function works correctly for 3d tran sforms.
1812 1812
1813 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 )); 1813 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1814 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100) ); 1814 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100) );
1815 WebTransformationMatrix layerToSurfaceTransform; 1815 Transform layerToSurfaceTransform;
1816 1816
1817 // Case 1: Orthographic projection of a layer rotated about y-axis by 45 deg rees, should be fully contained in the renderSurface. 1817 // Case 1: Orthographic projection of a layer rotated about y-axis by 45 deg rees, should be fully contained in the renderSurface.
1818 layerToSurfaceTransform.makeIdentity(); 1818 layerToSurfaceTransform.matrix().setIdentity();
1819 layerToSurfaceTransform.rotate3d(0, 45, 0); 1819 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0);
1820 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)); 1820 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100));
1821 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform); 1821 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1822 EXPECT_RECT_EQ(expected, actual); 1822 EXPECT_RECT_EQ(expected, actual);
1823 1823
1824 // Case 2: Orthographic projection of a layer rotated about y-axis by 45 deg rees, but 1824 // Case 2: Orthographic projection of a layer rotated about y-axis by 45 deg rees, but
1825 // shifted to the side so only the right-half the layer would be vis ible on 1825 // shifted to the side so only the right-half the layer would be vis ible on
1826 // the surface. 1826 // the surface.
1827 double halfWidthOfRotatedLayer = (100 / sqrt(2.0)) * 0.5; // 100 is the un-r otated layer width; divided by sqrt(2) is the rotated width. 1827 double halfWidthOfRotatedLayer = (100 / sqrt(2.0)) * 0.5; // 100 is the un-r otated layer width; divided by sqrt(2) is the rotated width.
1828 layerToSurfaceTransform.makeIdentity(); 1828 layerToSurfaceTransform.matrix().setIdentity();
1829 layerToSurfaceTransform.translate(-halfWidthOfRotatedLayer, 0); 1829 layerToSurfaceTransform.PreconcatTranslate(-halfWidthOfRotatedLayer, 0);
1830 layerToSurfaceTransform.rotate3d(0, 45, 0); // rotates about the left edge o f the layer 1830 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0); // rotates about the left edge of the layer
1831 expected = gfx::Rect(gfx::Point(50, 0), gfx::Size(50, 100)); // right half o f the layer. 1831 expected = gfx::Rect(gfx::Point(50, 0), gfx::Size(50, 100)); // right half o f the layer.
1832 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1832 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1833 EXPECT_RECT_EQ(expected, actual); 1833 EXPECT_RECT_EQ(expected, actual);
1834 } 1834 }
1835 1835
1836 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform) 1836 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform)
1837 { 1837 {
1838 // Test the calculateVisibleRect() function works correctly when the layer h as a 1838 // Test the calculateVisibleRect() function works correctly when the layer h as a
1839 // perspective projection onto the target surface. 1839 // perspective projection onto the target surface.
1840 1840
1841 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 )); 1841 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1842 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(200, 200)); 1842 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(200, 200));
1843 WebTransformationMatrix layerToSurfaceTransform; 1843 Transform layerToSurfaceTransform;
1844 1844
1845 // Case 1: Even though the layer is twice as large as the surface, due to pe rspective 1845 // Case 1: Even though the layer is twice as large as the surface, due to pe rspective
1846 // foreshortening, the layer will fit fully in the surface when its translated 1846 // foreshortening, the layer will fit fully in the surface when its translated
1847 // more than the perspective amount. 1847 // more than the perspective amount.
1848 layerToSurfaceTransform.makeIdentity(); 1848 layerToSurfaceTransform.matrix().setIdentity();
1849 1849
1850 // The following sequence of transforms applies the perspective about the ce nter of the surface. 1850 // The following sequence of transforms applies the perspective about the ce nter of the surface.
1851 layerToSurfaceTransform.translate(50, 50); 1851 layerToSurfaceTransform.PreconcatTranslate(50, 50);
1852 layerToSurfaceTransform.applyPerspective(9); 1852 layerToSurfaceTransform.PreconcatPerspectiveDepth(9);
1853 layerToSurfaceTransform.translate(-50, -50); 1853 layerToSurfaceTransform.PreconcatTranslate(-50, -50);
1854 1854
1855 // This translate places the layer in front of the surface's projection plan e. 1855 // This translate places the layer in front of the surface's projection plan e.
1856 layerToSurfaceTransform.translate3d(0, 0, -27); 1856 layerToSurfaceTransform.PreconcatTranslate3d(0, 0, -27);
1857 1857
1858 gfx::Rect expected = gfx::Rect(gfx::Point(-50, -50), gfx::Size(200, 200)); 1858 gfx::Rect expected = gfx::Rect(gfx::Point(-50, -50), gfx::Size(200, 200));
1859 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform); 1859 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1860 EXPECT_RECT_EQ(expected, actual); 1860 EXPECT_RECT_EQ(expected, actual);
1861 1861
1862 // Case 2: same projection as before, except that the layer is also translat ed to the 1862 // Case 2: same projection as before, except that the layer is also translat ed to the
1863 // side, so that only the right half of the layer should be visible. 1863 // side, so that only the right half of the layer should be visible.
1864 // 1864 //
1865 // Explanation of expected result: 1865 // Explanation of expected result:
1866 // The perspective ratio is (z distance between layer and camera origin) / ( z distance between projection plane and camera origin) == ((-27 - 9) / 9) 1866 // The perspective ratio is (z distance between layer and camera origin) / ( z distance between projection plane and camera origin) == ((-27 - 9) / 9)
1867 // Then, by similar triangles, if we want to move a layer by translating -50 units in projected surface units (so that only half of it is 1867 // Then, by similar triangles, if we want to move a layer by translating -50 units in projected surface units (so that only half of it is
1868 // visible), then we would need to translate by (-36 / 9) * -50 == -200 in t he layer's units. 1868 // visible), then we would need to translate by (-36 / 9) * -50 == -200 in t he layer's units.
1869 // 1869 //
1870 layerToSurfaceTransform.translate3d(-200, 0, 0); 1870 layerToSurfaceTransform.PreconcatTranslate3d(-200, 0, 0);
1871 expected = gfx::Rect(gfx::Point(50, -50), gfx::Size(100, 200)); // The right half of the layer's bounding rect. 1871 expected = gfx::Rect(gfx::Point(50, -50), gfx::Size(100, 200)); // The right half of the layer's bounding rect.
1872 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1872 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1873 EXPECT_RECT_EQ(expected, actual); 1873 EXPECT_RECT_EQ(expected, actual);
1874 } 1874 }
1875 1875
1876 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicIsNotClippedBehi ndSurface) 1876 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicIsNotClippedBehi ndSurface)
1877 { 1877 {
1878 // There is currently no explicit concept of an orthographic projection plan e in our 1878 // There is currently no explicit concept of an orthographic projection plan e in our
1879 // code (nor in the CSS spec to my knowledge). Therefore, layers that are te chnically 1879 // code (nor in the CSS spec to my knowledge). Therefore, layers that are te chnically
1880 // behind the surface in an orthographic world should not be clipped when th ey are 1880 // behind the surface in an orthographic world should not be clipped when th ey are
1881 // flattened to the surface. 1881 // flattened to the surface.
1882 1882
1883 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 )); 1883 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1884 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100) ); 1884 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100) );
1885 WebTransformationMatrix layerToSurfaceTransform; 1885 Transform layerToSurfaceTransform;
1886 1886
1887 // This sequence of transforms effectively rotates the layer about the y-axi s at the 1887 // This sequence of transforms effectively rotates the layer about the y-axi s at the
1888 // center of the layer. 1888 // center of the layer.
1889 layerToSurfaceTransform.makeIdentity(); 1889 layerToSurfaceTransform.matrix().setIdentity();
1890 layerToSurfaceTransform.translate(50, 0); 1890 layerToSurfaceTransform.PreconcatTranslate(50, 0);
1891 layerToSurfaceTransform.rotate3d(0, 45, 0); 1891 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0);
1892 layerToSurfaceTransform.translate(-50, 0); 1892 layerToSurfaceTransform.PreconcatTranslate(-50, 0);
1893 1893
1894 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100)); 1894 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100));
1895 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform); 1895 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1896 EXPECT_RECT_EQ(expected, actual); 1896 EXPECT_RECT_EQ(expected, actual);
1897 } 1897 }
1898 1898
1899 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW) 1899 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW)
1900 { 1900 {
1901 // Test the calculateVisibleRect() function works correctly when projecting a surface 1901 // Test the calculateVisibleRect() function works correctly when projecting a surface
1902 // onto a layer, but the layer is partially behind the camera (not just behi nd the 1902 // onto a layer, but the layer is partially behind the camera (not just behi nd the
1903 // projection plane). In this case, the cartesian coordinates may seem to be valid, 1903 // projection plane). In this case, the cartesian coordinates may seem to be valid,
1904 // but actually they are not. The visibleRect needs to be properly clipped b y the 1904 // but actually they are not. The visibleRect needs to be properly clipped b y the
1905 // w = 0 plane in homogeneous coordinates before converting to cartesian coo rdinates. 1905 // w = 0 plane in homogeneous coordinates before converting to cartesian coo rdinates.
1906 1906
1907 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100, 100)); 1907 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100, 100));
1908 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -1), gfx::Size(20, 2) ); 1908 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -1), gfx::Size(20, 2) );
1909 WebTransformationMatrix layerToSurfaceTransform; 1909 Transform layerToSurfaceTransform;
1910 1910
1911 // The layer is positioned so that the right half of the layer should be in front of 1911 // The layer is positioned so that the right half of the layer should be in front of
1912 // the camera, while the other half is behind the surface's projection plane . The 1912 // the camera, while the other half is behind the surface's projection plane . The
1913 // following sequence of transforms applies the perspective and rotation abo ut the 1913 // following sequence of transforms applies the perspective and rotation abo ut the
1914 // center of the layer. 1914 // center of the layer.
1915 layerToSurfaceTransform.makeIdentity(); 1915 layerToSurfaceTransform.matrix().setIdentity();
1916 layerToSurfaceTransform.applyPerspective(1); 1916 layerToSurfaceTransform.PreconcatPerspectiveDepth(1);
1917 layerToSurfaceTransform.translate3d(-2, 0, 1); 1917 layerToSurfaceTransform.PreconcatTranslate3d(-2, 0, 1);
1918 layerToSurfaceTransform.rotate3d(0, 45, 0); 1918 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0);
1919 1919
1920 // Sanity check that this transform does indeed cause w < 0 when applying th e 1920 // Sanity check that this transform does indeed cause w < 0 when applying th e
1921 // transform, otherwise this code is not testing the intended scenario. 1921 // transform, otherwise this code is not testing the intended scenario.
1922 bool clipped = false; 1922 bool clipped = false;
1923 MathUtil::mapQuad(layerToSurfaceTransform, gfx::QuadF(gfx::RectF(layerConten tRect)), clipped); 1923 MathUtil::mapQuad(layerToSurfaceTransform, gfx::QuadF(gfx::RectF(layerConten tRect)), clipped);
1924 ASSERT_TRUE(clipped); 1924 ASSERT_TRUE(clipped);
1925 1925
1926 int expectedXPosition = 0; 1926 int expectedXPosition = 0;
1927 int expectedWidth = 10; 1927 int expectedWidth = 10;
1928 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform); 1928 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1929 EXPECT_EQ(expectedXPosition, actual.x()); 1929 EXPECT_EQ(expectedXPosition, actual.x());
1930 EXPECT_EQ(expectedWidth, actual.width()); 1930 EXPECT_EQ(expectedWidth, actual.width());
1931 } 1931 }
1932 1932
1933 TEST(LayerTreeHostCommonTest, verifyVisibleRectForPerspectiveUnprojection) 1933 TEST(LayerTreeHostCommonTest, verifyVisibleRectForPerspectiveUnprojection)
1934 { 1934 {
1935 // To determine visibleRect in layer space, there needs to be an un-projecti on from 1935 // To determine visibleRect in layer space, there needs to be an un-projecti on from
1936 // surface space to layer space. When the original transform was a perspecti ve 1936 // surface space to layer space. When the original transform was a perspecti ve
1937 // projection that was clipped, it returns a rect that encloses the clipped bounds. 1937 // projection that was clipped, it returns a rect that encloses the clipped bounds.
1938 // Un-projecting this new rect may require clipping again. 1938 // Un-projecting this new rect may require clipping again.
1939 1939
1940 // This sequence of transforms causes one corner of the layer to protrude ac ross the w = 0 plane, and should be clipped. 1940 // This sequence of transforms causes one corner of the layer to protrude ac ross the w = 0 plane, and should be clipped.
1941 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100, 100)); 1941 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100, 100));
1942 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -10), gfx::Size(20, 2 0)); 1942 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -10), gfx::Size(20, 2 0));
1943 WebTransformationMatrix layerToSurfaceTransform; 1943 Transform layerToSurfaceTransform;
1944 layerToSurfaceTransform.makeIdentity(); 1944 layerToSurfaceTransform.matrix().setIdentity();
1945 layerToSurfaceTransform.applyPerspective(1); 1945 layerToSurfaceTransform.PreconcatPerspectiveDepth(1);
1946 layerToSurfaceTransform.translate3d(0, 0, -5); 1946 layerToSurfaceTransform.PreconcatTranslate3d(0, 0, -5);
1947 layerToSurfaceTransform.rotate3d(0, 45, 0); 1947 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 0, 45, 0);
1948 layerToSurfaceTransform.rotate3d(80, 0, 0); 1948 MathUtil::rotateEulerAngles(&layerToSurfaceTransform, 80, 0, 0);
1949 1949
1950 // Sanity check that un-projection does indeed cause w < 0, otherwise this c ode is not 1950 // Sanity check that un-projection does indeed cause w < 0, otherwise this c ode is not
1951 // testing the intended scenario. 1951 // testing the intended scenario.
1952 bool clipped = false; 1952 bool clipped = false;
1953 gfx::RectF clippedRect = MathUtil::mapClippedRect(layerToSurfaceTransform, l ayerContentRect); 1953 gfx::RectF clippedRect = MathUtil::mapClippedRect(layerToSurfaceTransform, l ayerContentRect);
1954 MathUtil::projectQuad(layerToSurfaceTransform.inverse(), gfx::QuadF(clippedR ect), clipped); 1954 MathUtil::projectQuad(MathUtil::inverse(layerToSurfaceTransform), gfx::QuadF (clippedRect), clipped);
1955 ASSERT_TRUE(clipped); 1955 ASSERT_TRUE(clipped);
1956 1956
1957 // Only the corner of the layer is not visible on the surface because of bei ng 1957 // Only the corner of the layer is not visible on the surface because of bei ng
1958 // clipped. But, the net result of rounding visible region to an axis-aligne d rect is 1958 // clipped. But, the net result of rounding visible region to an axis-aligne d rect is
1959 // that the entire layer should still be considered visible. 1959 // that the entire layer should still be considered visible.
1960 gfx::Rect expected = gfx::Rect(gfx::Point(-10, -10), gfx::Size(20, 20)); 1960 gfx::Rect expected = gfx::Rect(gfx::Point(-10, -10), gfx::Size(20, 20));
1961 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform); 1961 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1962 EXPECT_RECT_EQ(expected, actual); 1962 EXPECT_RECT_EQ(expected, actual);
1963 } 1963 }
1964 1964
1965 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForSimpleLayer s) 1965 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForSimpleLayer s)
1966 { 1966 {
1967 scoped_refptr<Layer> root = Layer::create(); 1967 scoped_refptr<Layer> root = Layer::create();
1968 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 1968 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
1969 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 1969 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
1970 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 1970 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
1971 root->addChild(child1); 1971 root->addChild(child1);
1972 root->addChild(child2); 1972 root->addChild(child2);
1973 root->addChild(child3); 1973 root->addChild(child3);
1974 1974
1975 WebTransformationMatrix identityMatrix; 1975 Transform identityMatrix;
1976 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 1976 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
1977 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(50, 50), false); 1977 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(50, 50), false);
1978 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false); 1978 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
1979 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false); 1979 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
1980 1980
1981 executeCalculateDrawTransformsAndVisibility(root.get()); 1981 executeCalculateDrawTransformsAndVisibility(root.get());
1982 1982
1983 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect()); 1983 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect());
1984 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawableContentRect()); 1984 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawableContentRect());
1985 1985
(...skipping 16 matching lines...) Expand all
2002 scoped_refptr<Layer> root = Layer::create(); 2002 scoped_refptr<Layer> root = Layer::create();
2003 scoped_refptr<Layer> child = Layer::create(); 2003 scoped_refptr<Layer> child = Layer::create();
2004 scoped_refptr<LayerWithForcedDrawsContent> grandChild1 = make_scoped_refptr( new LayerWithForcedDrawsContent()); 2004 scoped_refptr<LayerWithForcedDrawsContent> grandChild1 = make_scoped_refptr( new LayerWithForcedDrawsContent());
2005 scoped_refptr<LayerWithForcedDrawsContent> grandChild2 = make_scoped_refptr( new LayerWithForcedDrawsContent()); 2005 scoped_refptr<LayerWithForcedDrawsContent> grandChild2 = make_scoped_refptr( new LayerWithForcedDrawsContent());
2006 scoped_refptr<LayerWithForcedDrawsContent> grandChild3 = make_scoped_refptr( new LayerWithForcedDrawsContent()); 2006 scoped_refptr<LayerWithForcedDrawsContent> grandChild3 = make_scoped_refptr( new LayerWithForcedDrawsContent());
2007 root->addChild(child); 2007 root->addChild(child);
2008 child->addChild(grandChild1); 2008 child->addChild(grandChild1);
2009 child->addChild(grandChild2); 2009 child->addChild(grandChild2);
2010 child->addChild(grandChild3); 2010 child->addChild(grandChild3);
2011 2011
2012 WebTransformationMatrix identityMatrix; 2012 Transform identityMatrix;
2013 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 2013 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2014 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 2014 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2015 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false); 2015 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2016 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false); 2016 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2017 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false); 2017 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2018 2018
2019 child->setMasksToBounds(true); 2019 child->setMasksToBounds(true);
2020 executeCalculateDrawTransformsAndVisibility(root.get()); 2020 executeCalculateDrawTransformsAndVisibility(root.get());
2021 2021
2022 ASSERT_FALSE(child->renderSurface()); 2022 ASSERT_FALSE(child->renderSurface());
(...skipping 21 matching lines...) Expand all
2044 scoped_refptr<Layer> root = Layer::create(); 2044 scoped_refptr<Layer> root = Layer::create();
2045 scoped_refptr<Layer> renderSurface1 = Layer::create(); 2045 scoped_refptr<Layer> renderSurface1 = Layer::create();
2046 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2046 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2047 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2047 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2048 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2048 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2049 root->addChild(renderSurface1); 2049 root->addChild(renderSurface1);
2050 renderSurface1->addChild(child1); 2050 renderSurface1->addChild(child1);
2051 renderSurface1->addChild(child2); 2051 renderSurface1->addChild(child2);
2052 renderSurface1->addChild(child3); 2052 renderSurface1->addChild(child3);
2053 2053
2054 WebTransformationMatrix identityMatrix; 2054 Transform identityMatrix;
2055 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 2055 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2056 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false); 2056 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false);
2057 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false); 2057 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2058 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false); 2058 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2059 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false); 2059 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2060 2060
2061 renderSurface1->setForceRenderSurface(true); 2061 renderSurface1->setForceRenderSurface(true);
2062 executeCalculateDrawTransformsAndVisibility(root.get()); 2062 executeCalculateDrawTransformsAndVisibility(root.get());
2063 2063
2064 ASSERT_TRUE(renderSurface1->renderSurface()); 2064 ASSERT_TRUE(renderSurface1->renderSurface());
(...skipping 23 matching lines...) Expand all
2088 scoped_refptr<Layer> root = Layer::create(); 2088 scoped_refptr<Layer> root = Layer::create();
2089 scoped_refptr<Layer> renderSurface1 = Layer::create(); 2089 scoped_refptr<Layer> renderSurface1 = Layer::create();
2090 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2090 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2091 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2091 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2092 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2092 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2093 root->addChild(renderSurface1); 2093 root->addChild(renderSurface1);
2094 renderSurface1->addChild(child1); 2094 renderSurface1->addChild(child1);
2095 renderSurface1->addChild(child2); 2095 renderSurface1->addChild(child2);
2096 renderSurface1->addChild(child3); 2096 renderSurface1->addChild(child3);
2097 2097
2098 WebTransformationMatrix identityMatrix; 2098 Transform identityMatrix;
2099 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 2099 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2100 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false); 2100 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false);
2101 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false); 2101 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2102 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false); 2102 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2103 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false); 2103 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2104 2104
2105 root->setMasksToBounds(true); 2105 root->setMasksToBounds(true);
2106 renderSurface1->setForceRenderSurface(true); 2106 renderSurface1->setForceRenderSurface(true);
2107 executeCalculateDrawTransformsAndVisibility(root.get()); 2107 executeCalculateDrawTransformsAndVisibility(root.get());
2108 2108
(...skipping 29 matching lines...) Expand all
2138 scoped_refptr<Layer> renderSurface2 = Layer::create(); 2138 scoped_refptr<Layer> renderSurface2 = Layer::create();
2139 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2139 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2140 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2140 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2141 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2141 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2142 root->addChild(renderSurface1); 2142 root->addChild(renderSurface1);
2143 renderSurface1->addChild(renderSurface2); 2143 renderSurface1->addChild(renderSurface2);
2144 renderSurface2->addChild(child1); 2144 renderSurface2->addChild(child1);
2145 renderSurface2->addChild(child2); 2145 renderSurface2->addChild(child2);
2146 renderSurface2->addChild(child3); 2146 renderSurface2->addChild(child3);
2147 2147
2148 WebTransformationMatrix identityMatrix; 2148 Transform identityMatrix;
2149 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 2149 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2150 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false); 2150 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false);
2151 setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(7, 13), false); 2151 setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(7, 13), false);
2152 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false); 2152 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2153 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false); 2153 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2154 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false); 2154 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2155 2155
2156 root->setMasksToBounds(true); 2156 root->setMasksToBounds(true);
2157 renderSurface1->setForceRenderSurface(true); 2157 renderSurface1->setForceRenderSurface(true);
2158 renderSurface2->setForceRenderSurface(true); 2158 renderSurface2->setForceRenderSurface(true);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2193 { 2193 {
2194 // Layers that have non-axis aligned bounds (due to transforms) have an expa nded, 2194 // Layers that have non-axis aligned bounds (due to transforms) have an expa nded,
2195 // axis-aligned drawableContentRect and visibleContentRect. 2195 // axis-aligned drawableContentRect and visibleContentRect.
2196 2196
2197 scoped_refptr<Layer> root = Layer::create(); 2197 scoped_refptr<Layer> root = Layer::create();
2198 scoped_refptr<Layer> renderSurface1 = Layer::create(); 2198 scoped_refptr<Layer> renderSurface1 = Layer::create();
2199 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2199 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2200 root->addChild(renderSurface1); 2200 root->addChild(renderSurface1);
2201 renderSurface1->addChild(child1); 2201 renderSurface1->addChild(child1);
2202 2202
2203 WebTransformationMatrix identityMatrix; 2203 Transform identityMatrix;
2204 WebTransformationMatrix childRotation; 2204 Transform childRotation;
2205 childRotation.rotate(45); 2205 childRotation.PreconcatRotate(45);
2206 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 2206 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2207 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false); 2207 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false);
2208 setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, gf x::PointF(0.5, 0.5), gfx::PointF(25, 25), gfx::Size(50, 50), false); 2208 setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, gf x::PointF(0.5, 0.5), gfx::PointF(25, 25), gfx::Size(50, 50), false);
2209 2209
2210 renderSurface1->setForceRenderSurface(true); 2210 renderSurface1->setForceRenderSurface(true);
2211 executeCalculateDrawTransformsAndVisibility(root.get()); 2211 executeCalculateDrawTransformsAndVisibility(root.get());
2212 2212
2213 ASSERT_TRUE(renderSurface1->renderSurface()); 2213 ASSERT_TRUE(renderSurface1->renderSurface());
2214 2214
2215 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect()); 2215 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect());
(...skipping 17 matching lines...) Expand all
2233 { 2233 {
2234 // Layers that have non-axis aligned bounds (due to transforms) have an expa nded, 2234 // Layers that have non-axis aligned bounds (due to transforms) have an expa nded,
2235 // axis-aligned drawableContentRect and visibleContentRect. 2235 // axis-aligned drawableContentRect and visibleContentRect.
2236 2236
2237 scoped_refptr<Layer> root = Layer::create(); 2237 scoped_refptr<Layer> root = Layer::create();
2238 scoped_refptr<Layer> renderSurface1 = Layer::create(); 2238 scoped_refptr<Layer> renderSurface1 = Layer::create();
2239 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2239 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2240 root->addChild(renderSurface1); 2240 root->addChild(renderSurface1);
2241 renderSurface1->addChild(child1); 2241 renderSurface1->addChild(child1);
2242 2242
2243 WebTransformationMatrix identityMatrix; 2243 Transform identityMatrix;
2244 WebTransformationMatrix childRotation; 2244 Transform childRotation;
2245 childRotation.rotate(45); 2245 childRotation.PreconcatRotate(45);
2246 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(50, 50), false); 2246 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(50, 50), false);
2247 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false); 2247 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false);
2248 setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, gf x::PointF(0.5, 0.5), gfx::PointF(25, 25), gfx::Size(50, 50), false); 2248 setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, gf x::PointF(0.5, 0.5), gfx::PointF(25, 25), gfx::Size(50, 50), false);
2249 2249
2250 root->setMasksToBounds(true); 2250 root->setMasksToBounds(true);
2251 renderSurface1->setForceRenderSurface(true); 2251 renderSurface1->setForceRenderSurface(true);
2252 executeCalculateDrawTransformsAndVisibility(root.get()); 2252 executeCalculateDrawTransformsAndVisibility(root.get());
2253 2253
2254 ASSERT_TRUE(renderSurface1->renderSurface()); 2254 ASSERT_TRUE(renderSurface1->renderSurface());
2255 2255
(...skipping 21 matching lines...) Expand all
2277 scoped_refptr<ContentLayer> renderSurface2 = createDrawableContentLayer(&cli ent); 2277 scoped_refptr<ContentLayer> renderSurface2 = createDrawableContentLayer(&cli ent);
2278 scoped_refptr<ContentLayer> child1 = createDrawableContentLayer(&client); 2278 scoped_refptr<ContentLayer> child1 = createDrawableContentLayer(&client);
2279 scoped_refptr<ContentLayer> child2 = createDrawableContentLayer(&client); 2279 scoped_refptr<ContentLayer> child2 = createDrawableContentLayer(&client);
2280 scoped_refptr<ContentLayer> child3 = createDrawableContentLayer(&client); 2280 scoped_refptr<ContentLayer> child3 = createDrawableContentLayer(&client);
2281 root->addChild(renderSurface1); 2281 root->addChild(renderSurface1);
2282 renderSurface1->addChild(renderSurface2); 2282 renderSurface1->addChild(renderSurface2);
2283 renderSurface2->addChild(child1); 2283 renderSurface2->addChild(child1);
2284 renderSurface2->addChild(child2); 2284 renderSurface2->addChild(child2);
2285 renderSurface2->addChild(child3); 2285 renderSurface2->addChild(child3);
2286 2286
2287 WebTransformationMatrix identityMatrix; 2287 Transform identityMatrix;
2288 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 2288 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2289 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(3, 4), false); 2289 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(3, 4), false);
2290 setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(7, 13), false); 2290 setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(7, 13), false);
2291 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false); 2291 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2292 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false); 2292 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2293 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false); 2293 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2294 2294
2295 const double deviceScaleFactor = 2; 2295 const double deviceScaleFactor = 2;
2296 root->setContentsScale(deviceScaleFactor); 2296 root->setContentsScale(deviceScaleFactor);
2297 renderSurface1->setContentsScale(deviceScaleFactor); 2297 renderSurface1->setContentsScale(deviceScaleFactor);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visibleContentRect()); 2332 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visibleContentRect());
2333 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visibleContentRect()); 2333 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visibleContentRect());
2334 } 2334 }
2335 2335
2336 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithoutPreserves3d) 2336 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithoutPreserves3d)
2337 { 2337 {
2338 // Verify the behavior of back-face culling when there are no preserve-3d la yers. Note 2338 // Verify the behavior of back-face culling when there are no preserve-3d la yers. Note
2339 // that 3d transforms still apply in this case, but they are "flattened" to each 2339 // that 3d transforms still apply in this case, but they are "flattened" to each
2340 // parent layer according to current W3C spec. 2340 // parent layer according to current W3C spec.
2341 2341
2342 const WebTransformationMatrix identityMatrix; 2342 const Transform identityMatrix;
2343 scoped_refptr<Layer> parent = Layer::create(); 2343 scoped_refptr<Layer> parent = Layer::create();
2344 scoped_refptr<LayerWithForcedDrawsContent> frontFacingChild = make_scoped_re fptr(new LayerWithForcedDrawsContent()); 2344 scoped_refptr<LayerWithForcedDrawsContent> frontFacingChild = make_scoped_re fptr(new LayerWithForcedDrawsContent());
2345 scoped_refptr<LayerWithForcedDrawsContent> backFacingChild = make_scoped_ref ptr(new LayerWithForcedDrawsContent()); 2345 scoped_refptr<LayerWithForcedDrawsContent> backFacingChild = make_scoped_ref ptr(new LayerWithForcedDrawsContent());
2346 scoped_refptr<LayerWithForcedDrawsContent> frontFacingSurface = make_scoped_ refptr(new LayerWithForcedDrawsContent()); 2346 scoped_refptr<LayerWithForcedDrawsContent> frontFacingSurface = make_scoped_ refptr(new LayerWithForcedDrawsContent());
2347 scoped_refptr<LayerWithForcedDrawsContent> backFacingSurface = make_scoped_r efptr(new LayerWithForcedDrawsContent()); 2347 scoped_refptr<LayerWithForcedDrawsContent> backFacingSurface = make_scoped_r efptr(new LayerWithForcedDrawsContent());
2348 scoped_refptr<LayerWithForcedDrawsContent> frontFacingChildOfFrontFacingSurf ace = make_scoped_refptr(new LayerWithForcedDrawsContent()); 2348 scoped_refptr<LayerWithForcedDrawsContent> frontFacingChildOfFrontFacingSurf ace = make_scoped_refptr(new LayerWithForcedDrawsContent());
2349 scoped_refptr<LayerWithForcedDrawsContent> backFacingChildOfFrontFacingSurfa ce = make_scoped_refptr(new LayerWithForcedDrawsContent()); 2349 scoped_refptr<LayerWithForcedDrawsContent> backFacingChildOfFrontFacingSurfa ce = make_scoped_refptr(new LayerWithForcedDrawsContent());
2350 scoped_refptr<LayerWithForcedDrawsContent> frontFacingChildOfBackFacingSurfa ce = make_scoped_refptr(new LayerWithForcedDrawsContent()); 2350 scoped_refptr<LayerWithForcedDrawsContent> frontFacingChildOfBackFacingSurfa ce = make_scoped_refptr(new LayerWithForcedDrawsContent());
2351 scoped_refptr<LayerWithForcedDrawsContent> backFacingChildOfBackFacingSurfac e = make_scoped_refptr(new LayerWithForcedDrawsContent()); 2351 scoped_refptr<LayerWithForcedDrawsContent> backFacingChildOfBackFacingSurfac e = make_scoped_refptr(new LayerWithForcedDrawsContent());
2352 2352
2353 parent->addChild(frontFacingChild); 2353 parent->addChild(frontFacingChild);
2354 parent->addChild(backFacingChild); 2354 parent->addChild(backFacingChild);
2355 parent->addChild(frontFacingSurface); 2355 parent->addChild(frontFacingSurface);
2356 parent->addChild(backFacingSurface); 2356 parent->addChild(backFacingSurface);
2357 frontFacingSurface->addChild(frontFacingChildOfFrontFacingSurface); 2357 frontFacingSurface->addChild(frontFacingChildOfFrontFacingSurface);
2358 frontFacingSurface->addChild(backFacingChildOfFrontFacingSurface); 2358 frontFacingSurface->addChild(backFacingChildOfFrontFacingSurface);
2359 backFacingSurface->addChild(frontFacingChildOfBackFacingSurface); 2359 backFacingSurface->addChild(frontFacingChildOfBackFacingSurface);
2360 backFacingSurface->addChild(backFacingChildOfBackFacingSurface); 2360 backFacingSurface->addChild(backFacingChildOfBackFacingSurface);
2361 2361
2362 // Nothing is double-sided 2362 // Nothing is double-sided
2363 frontFacingChild->setDoubleSided(false); 2363 frontFacingChild->setDoubleSided(false);
2364 backFacingChild->setDoubleSided(false); 2364 backFacingChild->setDoubleSided(false);
2365 frontFacingSurface->setDoubleSided(false); 2365 frontFacingSurface->setDoubleSided(false);
2366 backFacingSurface->setDoubleSided(false); 2366 backFacingSurface->setDoubleSided(false);
2367 frontFacingChildOfFrontFacingSurface->setDoubleSided(false); 2367 frontFacingChildOfFrontFacingSurface->setDoubleSided(false);
2368 backFacingChildOfFrontFacingSurface->setDoubleSided(false); 2368 backFacingChildOfFrontFacingSurface->setDoubleSided(false);
2369 frontFacingChildOfBackFacingSurface->setDoubleSided(false); 2369 frontFacingChildOfBackFacingSurface->setDoubleSided(false);
2370 backFacingChildOfBackFacingSurface->setDoubleSided(false); 2370 backFacingChildOfBackFacingSurface->setDoubleSided(false);
2371 2371
2372 WebTransformationMatrix backfaceMatrix; 2372 Transform backfaceMatrix;
2373 backfaceMatrix.translate(50, 50); 2373 backfaceMatrix.PreconcatTranslate(50, 50);
2374 backfaceMatrix.rotate3d(0, 1, 0, 180); 2374 MathUtil::rotateAxisAngle(&backfaceMatrix, 0, 1, 0, 180);
2375 backfaceMatrix.translate(-50, -50); 2375 backfaceMatrix.PreconcatTranslate(-50, -50);
2376 2376
2377 // Having a descendant and opacity will force these to have render surfaces. 2377 // Having a descendant and opacity will force these to have render surfaces.
2378 frontFacingSurface->setOpacity(0.5); 2378 frontFacingSurface->setOpacity(0.5);
2379 backFacingSurface->setOpacity(0.5); 2379 backFacingSurface->setOpacity(0.5);
2380 2380
2381 // Nothing preserves 3d. According to current W3C CSS Transforms spec, these layers 2381 // Nothing preserves 3d. According to current W3C CSS Transforms spec, these layers
2382 // should blindly use their own local transforms to determine back-face cull ing. 2382 // should blindly use their own local transforms to determine back-face cull ing.
2383 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 2383 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2384 setLayerPropertiesForTesting(frontFacingChild.get(), identityMatrix, identit yMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 2384 setLayerPropertiesForTesting(frontFacingChild.get(), identityMatrix, identit yMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2385 setLayerPropertiesForTesting(backFacingChild.get(), backfaceMatrix, identity Matrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 2385 setLayerPropertiesForTesting(backFacingChild.get(), backfaceMatrix, identity Matrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2424 2424
2425 // Verify backFacingSurface's layerList; its own layer should be culled from the surface list. 2425 // Verify backFacingSurface's layerList; its own layer should be culled from the surface list.
2426 ASSERT_EQ(1u, renderSurfaceLayerList[2]->renderSurface()->layerList().size() ); 2426 ASSERT_EQ(1u, renderSurfaceLayerList[2]->renderSurface()->layerList().size() );
2427 EXPECT_EQ(frontFacingChildOfBackFacingSurface->id(), renderSurfaceLayerList[ 2]->renderSurface()->layerList()[0]->id()); 2427 EXPECT_EQ(frontFacingChildOfBackFacingSurface->id(), renderSurfaceLayerList[ 2]->renderSurface()->layerList()[0]->id());
2428 } 2428 }
2429 2429
2430 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3d) 2430 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3d)
2431 { 2431 {
2432 // Verify the behavior of back-face culling when preserves-3d transform styl e is used. 2432 // Verify the behavior of back-face culling when preserves-3d transform styl e is used.
2433 2433
2434 const WebTransformationMatrix identityMatrix; 2434 const Transform identityMatrix;
2435 scoped_refptr<Layer> parent = Layer::create(); 2435 scoped_refptr<Layer> parent = Layer::create();
2436 scoped_refptr<LayerWithForcedDrawsContent> frontFacingChild = make_scoped_re fptr(new LayerWithForcedDrawsContent()); 2436 scoped_refptr<LayerWithForcedDrawsContent> frontFacingChild = make_scoped_re fptr(new LayerWithForcedDrawsContent());
2437 scoped_refptr<LayerWithForcedDrawsContent> backFacingChild = make_scoped_ref ptr(new LayerWithForcedDrawsContent()); 2437 scoped_refptr<LayerWithForcedDrawsContent> backFacingChild = make_scoped_ref ptr(new LayerWithForcedDrawsContent());
2438 scoped_refptr<LayerWithForcedDrawsContent> frontFacingSurface = make_scoped_ refptr(new LayerWithForcedDrawsContent()); 2438 scoped_refptr<LayerWithForcedDrawsContent> frontFacingSurface = make_scoped_ refptr(new LayerWithForcedDrawsContent());
2439 scoped_refptr<LayerWithForcedDrawsContent> backFacingSurface = make_scoped_r efptr(new LayerWithForcedDrawsContent()); 2439 scoped_refptr<LayerWithForcedDrawsContent> backFacingSurface = make_scoped_r efptr(new LayerWithForcedDrawsContent());
2440 scoped_refptr<LayerWithForcedDrawsContent> frontFacingChildOfFrontFacingSurf ace = make_scoped_refptr(new LayerWithForcedDrawsContent()); 2440 scoped_refptr<LayerWithForcedDrawsContent> frontFacingChildOfFrontFacingSurf ace = make_scoped_refptr(new LayerWithForcedDrawsContent());
2441 scoped_refptr<LayerWithForcedDrawsContent> backFacingChildOfFrontFacingSurfa ce = make_scoped_refptr(new LayerWithForcedDrawsContent()); 2441 scoped_refptr<LayerWithForcedDrawsContent> backFacingChildOfFrontFacingSurfa ce = make_scoped_refptr(new LayerWithForcedDrawsContent());
2442 scoped_refptr<LayerWithForcedDrawsContent> frontFacingChildOfBackFacingSurfa ce = make_scoped_refptr(new LayerWithForcedDrawsContent()); 2442 scoped_refptr<LayerWithForcedDrawsContent> frontFacingChildOfBackFacingSurfa ce = make_scoped_refptr(new LayerWithForcedDrawsContent());
2443 scoped_refptr<LayerWithForcedDrawsContent> backFacingChildOfBackFacingSurfac e = make_scoped_refptr(new LayerWithForcedDrawsContent()); 2443 scoped_refptr<LayerWithForcedDrawsContent> backFacingChildOfBackFacingSurfac e = make_scoped_refptr(new LayerWithForcedDrawsContent());
2444 scoped_refptr<LayerWithForcedDrawsContent> dummyReplicaLayer1 = make_scoped_ refptr(new LayerWithForcedDrawsContent()); 2444 scoped_refptr<LayerWithForcedDrawsContent> dummyReplicaLayer1 = make_scoped_ refptr(new LayerWithForcedDrawsContent());
(...skipping 11 matching lines...) Expand all
2456 // Nothing is double-sided 2456 // Nothing is double-sided
2457 frontFacingChild->setDoubleSided(false); 2457 frontFacingChild->setDoubleSided(false);
2458 backFacingChild->setDoubleSided(false); 2458 backFacingChild->setDoubleSided(false);
2459 frontFacingSurface->setDoubleSided(false); 2459 frontFacingSurface->setDoubleSided(false);
2460 backFacingSurface->setDoubleSided(false); 2460 backFacingSurface->setDoubleSided(false);
2461 frontFacingChildOfFrontFacingSurface->setDoubleSided(false); 2461 frontFacingChildOfFrontFacingSurface->setDoubleSided(false);
2462 backFacingChildOfFrontFacingSurface->setDoubleSided(false); 2462 backFacingChildOfFrontFacingSurface->setDoubleSided(false);
2463 frontFacingChildOfBackFacingSurface->setDoubleSided(false); 2463 frontFacingChildOfBackFacingSurface->setDoubleSided(false);
2464 backFacingChildOfBackFacingSurface->setDoubleSided(false); 2464 backFacingChildOfBackFacingSurface->setDoubleSided(false);
2465 2465
2466 WebTransformationMatrix backfaceMatrix; 2466 Transform backfaceMatrix;
2467 backfaceMatrix.translate(50, 50); 2467 backfaceMatrix.PreconcatTranslate(50, 50);
2468 backfaceMatrix.rotate3d(0, 1, 0, 180); 2468 MathUtil::rotateAxisAngle(&backfaceMatrix, 0, 1, 0, 180);
2469 backfaceMatrix.translate(-50, -50); 2469 backfaceMatrix.PreconcatTranslate(-50, -50);
2470 2470
2471 // Opacity will not force creation of renderSurfaces in this case because of the 2471 // Opacity will not force creation of renderSurfaces in this case because of the
2472 // preserve-3d transform style. Instead, an example of when a surface would be 2472 // preserve-3d transform style. Instead, an example of when a surface would be
2473 // created with preserve-3d is when there is a replica layer. 2473 // created with preserve-3d is when there is a replica layer.
2474 frontFacingSurface->setReplicaLayer(dummyReplicaLayer1.get()); 2474 frontFacingSurface->setReplicaLayer(dummyReplicaLayer1.get());
2475 backFacingSurface->setReplicaLayer(dummyReplicaLayer2.get()); 2475 backFacingSurface->setReplicaLayer(dummyReplicaLayer2.get());
2476 2476
2477 // Each surface creates its own new 3d rendering context (as defined by W3C spec). 2477 // Each surface creates its own new 3d rendering context (as defined by W3C spec).
2478 // According to current W3C CSS Transforms spec, layers in a 3d rendering co ntext 2478 // According to current W3C CSS Transforms spec, layers in a 3d rendering co ntext
2479 // should use the transform with respect to that context. This 3d rendering context 2479 // should use the transform with respect to that context. This 3d rendering context
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2521 2521
2522 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithAnimatingTransforms) 2522 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithAnimatingTransforms)
2523 { 2523 {
2524 // Verify that layers are appropriately culled when their back face is showi ng and 2524 // Verify that layers are appropriately culled when their back face is showi ng and
2525 // they are not double sided, while animations are going on. 2525 // they are not double sided, while animations are going on.
2526 // 2526 //
2527 // Layers that are animating do not get culled on the main thread, as their transforms should be 2527 // Layers that are animating do not get culled on the main thread, as their transforms should be
2528 // treated as "unknown" so we can not be sure that their back face is really showing. 2528 // treated as "unknown" so we can not be sure that their back face is really showing.
2529 // 2529 //
2530 2530
2531 const WebTransformationMatrix identityMatrix; 2531 const Transform identityMatrix;
2532 scoped_refptr<Layer> parent = Layer::create(); 2532 scoped_refptr<Layer> parent = Layer::create();
2533 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent()); 2533 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent());
2534 scoped_refptr<LayerWithForcedDrawsContent> animatingSurface = make_scoped_re fptr(new LayerWithForcedDrawsContent()); 2534 scoped_refptr<LayerWithForcedDrawsContent> animatingSurface = make_scoped_re fptr(new LayerWithForcedDrawsContent());
2535 scoped_refptr<LayerWithForcedDrawsContent> childOfAnimatingSurface = make_sc oped_refptr(new LayerWithForcedDrawsContent()); 2535 scoped_refptr<LayerWithForcedDrawsContent> childOfAnimatingSurface = make_sc oped_refptr(new LayerWithForcedDrawsContent());
2536 scoped_refptr<LayerWithForcedDrawsContent> animatingChild = make_scoped_refp tr(new LayerWithForcedDrawsContent()); 2536 scoped_refptr<LayerWithForcedDrawsContent> animatingChild = make_scoped_refp tr(new LayerWithForcedDrawsContent());
2537 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2537 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2538 2538
2539 parent->addChild(child); 2539 parent->addChild(child);
2540 parent->addChild(animatingSurface); 2540 parent->addChild(animatingSurface);
2541 animatingSurface->addChild(childOfAnimatingSurface); 2541 animatingSurface->addChild(childOfAnimatingSurface);
2542 parent->addChild(animatingChild); 2542 parent->addChild(animatingChild);
2543 parent->addChild(child2); 2543 parent->addChild(child2);
2544 2544
2545 // Nothing is double-sided 2545 // Nothing is double-sided
2546 child->setDoubleSided(false); 2546 child->setDoubleSided(false);
2547 child2->setDoubleSided(false); 2547 child2->setDoubleSided(false);
2548 animatingSurface->setDoubleSided(false); 2548 animatingSurface->setDoubleSided(false);
2549 childOfAnimatingSurface->setDoubleSided(false); 2549 childOfAnimatingSurface->setDoubleSided(false);
2550 animatingChild->setDoubleSided(false); 2550 animatingChild->setDoubleSided(false);
2551 2551
2552 WebTransformationMatrix backfaceMatrix; 2552 Transform backfaceMatrix;
2553 backfaceMatrix.translate(50, 50); 2553 backfaceMatrix.PreconcatTranslate(50, 50);
2554 backfaceMatrix.rotate3d(0, 1, 0, 180); 2554 MathUtil::rotateAxisAngle(&backfaceMatrix, 0, 1, 0, 180);
2555 backfaceMatrix.translate(-50, -50); 2555 backfaceMatrix.PreconcatTranslate(-50, -50);
2556 2556
2557 // Make our render surface. 2557 // Make our render surface.
2558 animatingSurface->setForceRenderSurface(true); 2558 animatingSurface->setForceRenderSurface(true);
2559 2559
2560 // Animate the transform on the render surface. 2560 // Animate the transform on the render surface.
2561 addAnimatedTransformToController(*animatingSurface->layerAnimationController (), 10, 30, 0); 2561 addAnimatedTransformToController(*animatingSurface->layerAnimationController (), 10, 30, 0);
2562 // This is just an animating layer, not a surface. 2562 // This is just an animating layer, not a surface.
2563 addAnimatedTransformToController(*animatingChild->layerAnimationController() , 10, 30, 0); 2563 addAnimatedTransformToController(*animatingChild->layerAnimationController() , 10, 30, 0);
2564 2564
2565 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 2565 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2601 EXPECT_EQ(animatingSurface->visibleContentRect(), gfx::Rect(gfx::Point(), an imatingSurface->contentBounds())); 2601 EXPECT_EQ(animatingSurface->visibleContentRect(), gfx::Rect(gfx::Point(), an imatingSurface->contentBounds()));
2602 // And layers in the subtree of the animating layer should have valid visibl eContentRects also. 2602 // And layers in the subtree of the animating layer should have valid visibl eContentRects also.
2603 EXPECT_EQ(childOfAnimatingSurface->visibleContentRect(), gfx::Rect(gfx::Poin t(), childOfAnimatingSurface->contentBounds())); 2603 EXPECT_EQ(childOfAnimatingSurface->visibleContentRect(), gfx::Rect(gfx::Poin t(), childOfAnimatingSurface->contentBounds()));
2604 } 2604 }
2605 2605
2606 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3dForFlatteningS urface) 2606 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3dForFlatteningS urface)
2607 { 2607 {
2608 // Verify the behavior of back-face culling for a renderSurface that is crea ted 2608 // Verify the behavior of back-face culling for a renderSurface that is crea ted
2609 // when it flattens its subtree, and its parent has preserves-3d. 2609 // when it flattens its subtree, and its parent has preserves-3d.
2610 2610
2611 const WebTransformationMatrix identityMatrix; 2611 const Transform identityMatrix;
2612 scoped_refptr<Layer> parent = Layer::create(); 2612 scoped_refptr<Layer> parent = Layer::create();
2613 scoped_refptr<LayerWithForcedDrawsContent> frontFacingSurface = make_scoped_ refptr(new LayerWithForcedDrawsContent()); 2613 scoped_refptr<LayerWithForcedDrawsContent> frontFacingSurface = make_scoped_ refptr(new LayerWithForcedDrawsContent());
2614 scoped_refptr<LayerWithForcedDrawsContent> backFacingSurface = make_scoped_r efptr(new LayerWithForcedDrawsContent()); 2614 scoped_refptr<LayerWithForcedDrawsContent> backFacingSurface = make_scoped_r efptr(new LayerWithForcedDrawsContent());
2615 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2615 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2616 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2616 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2617 2617
2618 parent->addChild(frontFacingSurface); 2618 parent->addChild(frontFacingSurface);
2619 parent->addChild(backFacingSurface); 2619 parent->addChild(backFacingSurface);
2620 frontFacingSurface->addChild(child1); 2620 frontFacingSurface->addChild(child1);
2621 backFacingSurface->addChild(child2); 2621 backFacingSurface->addChild(child2);
2622 2622
2623 // RenderSurfaces are not double-sided 2623 // RenderSurfaces are not double-sided
2624 frontFacingSurface->setDoubleSided(false); 2624 frontFacingSurface->setDoubleSided(false);
2625 backFacingSurface->setDoubleSided(false); 2625 backFacingSurface->setDoubleSided(false);
2626 2626
2627 WebTransformationMatrix backfaceMatrix; 2627 Transform backfaceMatrix;
2628 backfaceMatrix.translate(50, 50); 2628 backfaceMatrix.PreconcatTranslate(50, 50);
2629 backfaceMatrix.rotate3d(0, 1, 0, 180); 2629 MathUtil::rotateAxisAngle(&backfaceMatrix, 0, 1, 0, 180);
2630 backfaceMatrix.translate(-50, -50); 2630 backfaceMatrix.PreconcatTranslate(-50, -50);
2631 2631
2632 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true); // parent trans form style is preserve3d. 2632 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true); // parent trans form style is preserve3d.
2633 setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, ident ityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); // surface transform style is flat. 2633 setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, ident ityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); // surface transform style is flat.
2634 setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, ident ityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); // surface transform style is flat. 2634 setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, ident ityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); // surface transform style is flat.
2635 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 2635 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2636 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 2636 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2637 2637
2638 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 2638 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
2639 int dummyMaxTextureSize = 512; 2639 int dummyMaxTextureSize = 512;
2640 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 2640 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
(...skipping 30 matching lines...) Expand all
2671 2671
2672 testPoint = gfx::Point(10, 20); 2672 testPoint = gfx::Point(10, 20);
2673 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2673 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2674 EXPECT_FALSE(resultLayer); 2674 EXPECT_FALSE(resultLayer);
2675 } 2675 }
2676 2676
2677 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayer) 2677 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayer)
2678 { 2678 {
2679 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 2679 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
2680 2680
2681 WebTransformationMatrix identityMatrix; 2681 Transform identityMatrix;
2682 gfx::PointF anchor(0, 0); 2682 gfx::PointF anchor(0, 0);
2683 gfx::PointF position(0, 0); 2683 gfx::PointF position(0, 0);
2684 gfx::Size bounds(100, 100); 2684 gfx::Size bounds(100, 100);
2685 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 2685 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
2686 root->setDrawsContent(true); 2686 root->setDrawsContent(true);
2687 2687
2688 std::vector<LayerImpl*> renderSurfaceLayerList; 2688 std::vector<LayerImpl*> renderSurfaceLayerList;
2689 int dummyMaxTextureSize = 512; 2689 int dummyMaxTextureSize = 512;
2690 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2690 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2691 2691
(...skipping 19 matching lines...) Expand all
2711 testPoint = gfx::Point(99, 99); 2711 testPoint = gfx::Point(99, 99);
2712 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2712 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2713 ASSERT_TRUE(resultLayer); 2713 ASSERT_TRUE(resultLayer);
2714 EXPECT_EQ(12345, resultLayer->id()); 2714 EXPECT_EQ(12345, resultLayer->id());
2715 } 2715 }
2716 2716
2717 TEST(LayerTreeHostCommonTest, verifyHitTestingForUninvertibleTransform) 2717 TEST(LayerTreeHostCommonTest, verifyHitTestingForUninvertibleTransform)
2718 { 2718 {
2719 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 2719 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
2720 2720
2721 WebTransformationMatrix uninvertibleTransform; 2721 Transform uninvertibleTransform;
2722 uninvertibleTransform.setM11(0); 2722 uninvertibleTransform.matrix().setDouble(0, 0, 0);
2723 uninvertibleTransform.setM22(0); 2723 uninvertibleTransform.matrix().setDouble(1, 1, 0);
2724 uninvertibleTransform.setM33(0); 2724 uninvertibleTransform.matrix().setDouble(2, 2, 0);
2725 uninvertibleTransform.setM44(0); 2725 uninvertibleTransform.matrix().setDouble(3, 3, 0);
2726 ASSERT_FALSE(uninvertibleTransform.isInvertible()); 2726 ASSERT_FALSE(uninvertibleTransform.IsInvertible());
2727 2727
2728 WebTransformationMatrix identityMatrix; 2728 Transform identityMatrix;
2729 gfx::PointF anchor(0, 0); 2729 gfx::PointF anchor(0, 0);
2730 gfx::PointF position(0, 0); 2730 gfx::PointF position(0, 0);
2731 gfx::Size bounds(100, 100); 2731 gfx::Size bounds(100, 100);
2732 setLayerPropertiesForTesting(root.get(), uninvertibleTransform, identityMatr ix, anchor, position, bounds, false); 2732 setLayerPropertiesForTesting(root.get(), uninvertibleTransform, identityMatr ix, anchor, position, bounds, false);
2733 root->setDrawsContent(true); 2733 root->setDrawsContent(true);
2734 2734
2735 std::vector<LayerImpl*> renderSurfaceLayerList; 2735 std::vector<LayerImpl*> renderSurfaceLayerList;
2736 int dummyMaxTextureSize = 512; 2736 int dummyMaxTextureSize = 512;
2737 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2737 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2738 2738
2739 // Sanity check the scenario we just created. 2739 // Sanity check the scenario we just created.
2740 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 2740 ASSERT_EQ(1u, renderSurfaceLayerList.size());
2741 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 2741 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
2742 ASSERT_FALSE(root->screenSpaceTransform().isInvertible()); 2742 ASSERT_FALSE(root->screenSpaceTransform().IsInvertible());
2743 2743
2744 // Hit testing any point should not hit the layer. If the invertible matrix is 2744 // Hit testing any point should not hit the layer. If the invertible matrix is
2745 // accidentally ignored and treated like an identity, then the hit testing w ill 2745 // accidentally ignored and treated like an identity, then the hit testing w ill
2746 // incorrectly hit the layer when it shouldn't. 2746 // incorrectly hit the layer when it shouldn't.
2747 gfx::Point testPoint(1, 1); 2747 gfx::Point testPoint(1, 1);
2748 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 2748 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
2749 EXPECT_FALSE(resultLayer); 2749 EXPECT_FALSE(resultLayer);
2750 2750
2751 testPoint = gfx::Point(10, 10); 2751 testPoint = gfx::Point(10, 10);
2752 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2752 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
(...skipping 17 matching lines...) Expand all
2770 2770
2771 testPoint = gfx::Point(-1, -1); 2771 testPoint = gfx::Point(-1, -1);
2772 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2772 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2773 EXPECT_FALSE(resultLayer); 2773 EXPECT_FALSE(resultLayer);
2774 } 2774 }
2775 2775
2776 TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePositionedLayer) 2776 TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePositionedLayer)
2777 { 2777 {
2778 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 2778 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
2779 2779
2780 WebTransformationMatrix identityMatrix; 2780 Transform identityMatrix;
2781 gfx::PointF anchor(0, 0); 2781 gfx::PointF anchor(0, 0);
2782 gfx::PointF position(50, 50); // this layer is positioned, and hit testing s hould correctly know where the layer is located. 2782 gfx::PointF position(50, 50); // this layer is positioned, and hit testing s hould correctly know where the layer is located.
2783 gfx::Size bounds(100, 100); 2783 gfx::Size bounds(100, 100);
2784 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 2784 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
2785 root->setDrawsContent(true); 2785 root->setDrawsContent(true);
2786 2786
2787 std::vector<LayerImpl*> renderSurfaceLayerList; 2787 std::vector<LayerImpl*> renderSurfaceLayerList;
2788 int dummyMaxTextureSize = 512; 2788 int dummyMaxTextureSize = 512;
2789 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2789 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2790 2790
(...skipping 20 matching lines...) Expand all
2811 testPoint = gfx::Point(99, 99); 2811 testPoint = gfx::Point(99, 99);
2812 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2812 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2813 ASSERT_TRUE(resultLayer); 2813 ASSERT_TRUE(resultLayer);
2814 EXPECT_EQ(12345, resultLayer->id()); 2814 EXPECT_EQ(12345, resultLayer->id());
2815 } 2815 }
2816 2816
2817 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer) 2817 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer)
2818 { 2818 {
2819 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 2819 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
2820 2820
2821 WebTransformationMatrix identityMatrix; 2821 Transform identityMatrix;
2822 WebTransformationMatrix rotation45DegreesAboutCenter; 2822 Transform rotation45DegreesAboutCenter;
2823 rotation45DegreesAboutCenter.translate(50, 50); 2823 rotation45DegreesAboutCenter.PreconcatTranslate(50, 50);
2824 rotation45DegreesAboutCenter.rotate3d(0, 0, 45); 2824 MathUtil::rotateEulerAngles(&rotation45DegreesAboutCenter, 0, 0, 45);
2825 rotation45DegreesAboutCenter.translate(-50, -50); 2825 rotation45DegreesAboutCenter.PreconcatTranslate(-50, -50);
2826 gfx::PointF anchor(0, 0); 2826 gfx::PointF anchor(0, 0);
2827 gfx::PointF position(0, 0); 2827 gfx::PointF position(0, 0);
2828 gfx::Size bounds(100, 100); 2828 gfx::Size bounds(100, 100);
2829 setLayerPropertiesForTesting(root.get(), rotation45DegreesAboutCenter, ident ityMatrix, anchor, position, bounds, false); 2829 setLayerPropertiesForTesting(root.get(), rotation45DegreesAboutCenter, ident ityMatrix, anchor, position, bounds, false);
2830 root->setDrawsContent(true); 2830 root->setDrawsContent(true);
2831 2831
2832 std::vector<LayerImpl*> renderSurfaceLayerList; 2832 std::vector<LayerImpl*> renderSurfaceLayerList;
2833 int dummyMaxTextureSize = 512; 2833 int dummyMaxTextureSize = 512;
2834 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2834 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2835 2835
(...skipping 24 matching lines...) Expand all
2860 2860
2861 testPoint = gfx::Point(-1, 50); 2861 testPoint = gfx::Point(-1, 50);
2862 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2862 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2863 ASSERT_FALSE(resultLayer); 2863 ASSERT_FALSE(resultLayer);
2864 } 2864 }
2865 2865
2866 TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePerspectiveLayer) 2866 TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePerspectiveLayer)
2867 { 2867 {
2868 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 2868 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
2869 2869
2870 WebTransformationMatrix identityMatrix; 2870 Transform identityMatrix;
2871 2871
2872 // perspectiveProjectionAboutCenter * translationByZ is designed so that the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50). 2872 // perspectiveProjectionAboutCenter * translationByZ is designed so that the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50).
2873 WebTransformationMatrix perspectiveProjectionAboutCenter; 2873 Transform perspectiveProjectionAboutCenter;
2874 perspectiveProjectionAboutCenter.translate(50, 50); 2874 perspectiveProjectionAboutCenter.PreconcatTranslate(50, 50);
2875 perspectiveProjectionAboutCenter.applyPerspective(1); 2875 perspectiveProjectionAboutCenter.PreconcatPerspectiveDepth(1);
2876 perspectiveProjectionAboutCenter.translate(-50, -50); 2876 perspectiveProjectionAboutCenter.PreconcatTranslate(-50, -50);
2877 WebTransformationMatrix translationByZ; 2877 Transform translationByZ;
2878 translationByZ.translate3d(0, 0, -1); 2878 translationByZ.PreconcatTranslate3d(0, 0, -1);
2879 2879
2880 gfx::PointF anchor(0, 0); 2880 gfx::PointF anchor(0, 0);
2881 gfx::PointF position(0, 0); 2881 gfx::PointF position(0, 0);
2882 gfx::Size bounds(100, 100); 2882 gfx::Size bounds(100, 100);
2883 setLayerPropertiesForTesting(root.get(), perspectiveProjectionAboutCenter * translationByZ, identityMatrix, anchor, position, bounds, false); 2883 setLayerPropertiesForTesting(root.get(), perspectiveProjectionAboutCenter * translationByZ, identityMatrix, anchor, position, bounds, false);
2884 root->setDrawsContent(true); 2884 root->setDrawsContent(true);
2885 2885
2886 std::vector<LayerImpl*> renderSurfaceLayerList; 2886 std::vector<LayerImpl*> renderSurfaceLayerList;
2887 int dummyMaxTextureSize = 512; 2887 int dummyMaxTextureSize = 512;
2888 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2888 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2920 // test makes sure that hit testing works correctly accounts for the content s scale. 2920 // test makes sure that hit testing works correctly accounts for the content s scale.
2921 // A contentsScale that is not 1 effectively forces a non-identity transform between 2921 // A contentsScale that is not 1 effectively forces a non-identity transform between
2922 // layer's content space and layer's origin space. The hit testing code must take this into account. 2922 // layer's content space and layer's origin space. The hit testing code must take this into account.
2923 // 2923 //
2924 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If 2924 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
2925 // contentsScale is ignored, then hit testing will mis-interpret the visible ContentRect 2925 // contentsScale is ignored, then hit testing will mis-interpret the visible ContentRect
2926 // as being larger than the actual bounds of the layer. 2926 // as being larger than the actual bounds of the layer.
2927 // 2927 //
2928 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 2928 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
2929 2929
2930 WebTransformationMatrix identityMatrix; 2930 Transform identityMatrix;
2931 gfx::PointF anchor(0, 0); 2931 gfx::PointF anchor(0, 0);
2932 2932
2933 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false); 2933 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
2934 2934
2935 { 2935 {
2936 gfx::PointF position(25, 25); 2936 gfx::PointF position(25, 25);
2937 gfx::Size bounds(50, 50); 2937 gfx::Size bounds(50, 50);
2938 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345); 2938 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345);
2939 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false); 2939 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false);
2940 2940
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2979 testPoint = gfx::Point(74, 74); 2979 testPoint = gfx::Point(74, 74);
2980 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2980 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2981 ASSERT_TRUE(resultLayer); 2981 ASSERT_TRUE(resultLayer);
2982 EXPECT_EQ(12345, resultLayer->id()); 2982 EXPECT_EQ(12345, resultLayer->id());
2983 } 2983 }
2984 2984
2985 TEST(LayerTreeHostCommonTest, verifyHitTestingForSimpleClippedLayer) 2985 TEST(LayerTreeHostCommonTest, verifyHitTestingForSimpleClippedLayer)
2986 { 2986 {
2987 // Test that hit-testing will only work for the visible portion of a layer, and not 2987 // Test that hit-testing will only work for the visible portion of a layer, and not
2988 // the entire layer bounds. Here we just test the simple axis-aligned case. 2988 // the entire layer bounds. Here we just test the simple axis-aligned case.
2989 WebTransformationMatrix identityMatrix; 2989 Transform identityMatrix;
2990 gfx::PointF anchor(0, 0); 2990 gfx::PointF anchor(0, 0);
2991 2991
2992 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 2992 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
2993 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false); 2993 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
2994 2994
2995 { 2995 {
2996 scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(123); 2996 scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(123);
2997 gfx::PointF position(25, 25); // this layer is positioned, and hit testi ng should correctly know where the layer is located. 2997 gfx::PointF position(25, 25); // this layer is positioned, and hit testi ng should correctly know where the layer is located.
2998 gfx::Size bounds(50, 50); 2998 gfx::Size bounds(50, 50);
2999 setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identi tyMatrix, anchor, position, bounds, false); 2999 setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identi tyMatrix, anchor, position, bounds, false);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3047 // algorithm needs to recognize that multiple parent layers may clip the lay er, and 3047 // algorithm needs to recognize that multiple parent layers may clip the lay er, and
3048 // should not actually hit those clipped areas. 3048 // should not actually hit those clipped areas.
3049 // 3049 //
3050 // The child and grandChild layers are both initialized to clip the rotatedL eaf. The 3050 // The child and grandChild layers are both initialized to clip the rotatedL eaf. The
3051 // child layer is rotated about the top-left corner, so that the root + chil d clips 3051 // child layer is rotated about the top-left corner, so that the root + chil d clips
3052 // combined create a triangle. The rotatedLeaf will only be visible where it overlaps 3052 // combined create a triangle. The rotatedLeaf will only be visible where it overlaps
3053 // this triangle. 3053 // this triangle.
3054 // 3054 //
3055 scoped_ptr<LayerImpl> root = LayerImpl::create(123); 3055 scoped_ptr<LayerImpl> root = LayerImpl::create(123);
3056 3056
3057 WebTransformationMatrix identityMatrix; 3057 Transform identityMatrix;
3058 gfx::PointF anchor(0, 0); 3058 gfx::PointF anchor(0, 0);
3059 gfx::PointF position(0, 0); 3059 gfx::PointF position(0, 0);
3060 gfx::Size bounds(100, 100); 3060 gfx::Size bounds(100, 100);
3061 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 3061 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
3062 root->setMasksToBounds(true); 3062 root->setMasksToBounds(true);
3063 3063
3064 { 3064 {
3065 scoped_ptr<LayerImpl> child = LayerImpl::create(456); 3065 scoped_ptr<LayerImpl> child = LayerImpl::create(456);
3066 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(789); 3066 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(789);
3067 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(2468); 3067 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(2468);
3068 3068
3069 position = gfx::PointF(10, 10); 3069 position = gfx::PointF(10, 10);
3070 bounds = gfx::Size(80, 80); 3070 bounds = gfx::Size(80, 80);
3071 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false); 3071 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false);
3072 child->setMasksToBounds(true); 3072 child->setMasksToBounds(true);
3073 3073
3074 WebTransformationMatrix rotation45DegreesAboutCorner; 3074 Transform rotation45DegreesAboutCorner;
3075 rotation45DegreesAboutCorner.rotate3d(0, 0, 45); 3075 MathUtil::rotateEulerAngles(&rotation45DegreesAboutCorner, 0, 0, 45);
3076 3076
3077 position = gfx::PointF(0, 0); // remember, positioned with respect to it s parent which is already at 10, 10 3077 position = gfx::PointF(0, 0); // remember, positioned with respect to it s parent which is already at 10, 10
3078 bounds = gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100. 3078 bounds = gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100.
3079 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor ner, identityMatrix, anchor, position, bounds, false); 3079 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor ner, identityMatrix, anchor, position, bounds, false);
3080 grandChild->setMasksToBounds(true); 3080 grandChild->setMasksToBounds(true);
3081 3081
3082 // Rotates about the center of the layer 3082 // Rotates about the center of the layer
3083 WebTransformationMatrix rotatedLeafTransform; 3083 Transform rotatedLeafTransform;
3084 rotatedLeafTransform.translate(-10, -10); // cancel out the grandParent' s position 3084 rotatedLeafTransform.PreconcatTranslate(-10, -10); // cancel out the gra ndParent's position
3085 rotatedLeafTransform.rotate3d(0, 0, -45); // cancel out the corner 45-de gree rotation of the parent. 3085 MathUtil::rotateEulerAngles(&rotatedLeafTransform, 0, 0, -45); // cancel out the corner 45-degree rotation of the parent.
3086 rotatedLeafTransform.translate(50, 50); 3086 rotatedLeafTransform.PreconcatTranslate(50, 50);
3087 rotatedLeafTransform.rotate3d(0, 0, 45); 3087 MathUtil::rotateEulerAngles(&rotatedLeafTransform, 0, 0, 45);
3088 rotatedLeafTransform.translate(-50, -50); 3088 rotatedLeafTransform.PreconcatTranslate(-50, -50);
3089 position = gfx::PointF(0, 0); 3089 position = gfx::PointF(0, 0);
3090 bounds = gfx::Size(100, 100); 3090 bounds = gfx::Size(100, 100);
3091 setLayerPropertiesForTesting(rotatedLeaf.get(), rotatedLeafTransform, id entityMatrix, anchor, position, bounds, false); 3091 setLayerPropertiesForTesting(rotatedLeaf.get(), rotatedLeafTransform, id entityMatrix, anchor, position, bounds, false);
3092 rotatedLeaf->setDrawsContent(true); 3092 rotatedLeaf->setDrawsContent(true);
3093 3093
3094 grandChild->addChild(rotatedLeaf.Pass()); 3094 grandChild->addChild(rotatedLeaf.Pass());
3095 child->addChild(grandChild.Pass()); 3095 child->addChild(grandChild.Pass());
3096 root->addChild(child.Pass()); 3096 root->addChild(child.Pass());
3097 } 3097 }
3098 3098
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
3143 testPoint = gfx::Point(49, 51); 3143 testPoint = gfx::Point(49, 51);
3144 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3144 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3145 ASSERT_TRUE(resultLayer); 3145 ASSERT_TRUE(resultLayer);
3146 EXPECT_EQ(2468, resultLayer->id()); 3146 EXPECT_EQ(2468, resultLayer->id());
3147 } 3147 }
3148 3148
3149 TEST(LayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer) 3149 TEST(LayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer)
3150 { 3150 {
3151 // This test checks that hit testing code does not accidentally clip to laye r 3151 // This test checks that hit testing code does not accidentally clip to laye r
3152 // bounds for a layer that actually does not clip. 3152 // bounds for a layer that actually does not clip.
3153 WebTransformationMatrix identityMatrix; 3153 Transform identityMatrix;
3154 gfx::PointF anchor(0, 0); 3154 gfx::PointF anchor(0, 0);
3155 3155
3156 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 3156 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3157 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false); 3157 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
3158 3158
3159 { 3159 {
3160 scoped_ptr<LayerImpl> intermediateLayer = LayerImpl::create(123); 3160 scoped_ptr<LayerImpl> intermediateLayer = LayerImpl::create(123);
3161 gfx::PointF position(10, 10); // this layer is positioned, and hit testi ng should correctly know where the layer is located. 3161 gfx::PointF position(10, 10); // this layer is positioned, and hit testi ng should correctly know where the layer is located.
3162 gfx::Size bounds(50, 50); 3162 gfx::Size bounds(50, 50);
3163 setLayerPropertiesForTesting(intermediateLayer.get(), identityMatrix, id entityMatrix, anchor, position, bounds, false); 3163 setLayerPropertiesForTesting(intermediateLayer.get(), identityMatrix, id entityMatrix, anchor, position, bounds, false);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3204 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3204 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3205 ASSERT_TRUE(resultLayer); 3205 ASSERT_TRUE(resultLayer);
3206 EXPECT_EQ(456, resultLayer->id()); 3206 EXPECT_EQ(456, resultLayer->id());
3207 } 3207 }
3208 3208
3209 3209
3210 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayers) 3210 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayers)
3211 { 3211 {
3212 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 3212 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3213 3213
3214 WebTransformationMatrix identityMatrix; 3214 Transform identityMatrix;
3215 gfx::PointF anchor(0, 0); 3215 gfx::PointF anchor(0, 0);
3216 gfx::PointF position(0, 0); 3216 gfx::PointF position(0, 0);
3217 gfx::Size bounds(100, 100); 3217 gfx::Size bounds(100, 100);
3218 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 3218 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
3219 root->setDrawsContent(true); 3219 root->setDrawsContent(true);
3220 3220
3221 { 3221 {
3222 // child 1 and child2 are initialized to overlap between x=50 and x=60. 3222 // child 1 and child2 are initialized to overlap between x=50 and x=60.
3223 // grandChild is set to overlap both child1 and child2 between y=50 and y=60. 3223 // grandChild is set to overlap both child1 and child2 between y=50 and y=60.
3224 // The expected stacking order is: 3224 // The expected stacking order is:
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
3307 } 3307 }
3308 3308
3309 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists) 3309 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists)
3310 { 3310 {
3311 // 3311 //
3312 // The geometry is set up similarly to the previous case, but 3312 // The geometry is set up similarly to the previous case, but
3313 // all layers are forced to be renderSurfaces now. 3313 // all layers are forced to be renderSurfaces now.
3314 // 3314 //
3315 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 3315 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3316 3316
3317 WebTransformationMatrix identityMatrix; 3317 Transform identityMatrix;
3318 gfx::PointF anchor(0, 0); 3318 gfx::PointF anchor(0, 0);
3319 gfx::PointF position(0, 0); 3319 gfx::PointF position(0, 0);
3320 gfx::Size bounds(100, 100); 3320 gfx::Size bounds(100, 100);
3321 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 3321 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
3322 root->setDrawsContent(true); 3322 root->setDrawsContent(true);
3323 3323
3324 { 3324 {
3325 // child 1 and child2 are initialized to overlap between x=50 and x=60. 3325 // child 1 and child2 are initialized to overlap between x=50 and x=60.
3326 // grandChild is set to overlap both child1 and child2 between y=50 and y=60. 3326 // grandChild is set to overlap both child1 and child2 between y=50 and y=60.
3327 // The expected stacking order is: 3327 // The expected stacking order is:
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
3429 3429
3430 testPoint = gfx::Point(10, 20); 3430 testPoint = gfx::Point(10, 20);
3431 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); 3431 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3432 EXPECT_FALSE(resultLayer); 3432 EXPECT_FALSE(resultLayer);
3433 } 3433 }
3434 3434
3435 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer ) 3435 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer )
3436 { 3436 {
3437 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 3437 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
3438 3438
3439 WebTransformationMatrix identityMatrix; 3439 Transform identityMatrix;
3440 Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50)); 3440 Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50));
3441 gfx::PointF anchor(0, 0); 3441 gfx::PointF anchor(0, 0);
3442 gfx::PointF position(0, 0); 3442 gfx::PointF position(0, 0);
3443 gfx::Size bounds(100, 100); 3443 gfx::Size bounds(100, 100);
3444 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 3444 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
3445 root->setDrawsContent(true); 3445 root->setDrawsContent(true);
3446 3446
3447 std::vector<LayerImpl*> renderSurfaceLayerList; 3447 std::vector<LayerImpl*> renderSurfaceLayerList;
3448 int dummyMaxTextureSize = 512; 3448 int dummyMaxTextureSize = 512;
3449 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 3449 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3485 testPoint = gfx::Point(59, 59); 3485 testPoint = gfx::Point(59, 59);
3486 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); 3486 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3487 ASSERT_TRUE(resultLayer); 3487 ASSERT_TRUE(resultLayer);
3488 EXPECT_EQ(12345, resultLayer->id()); 3488 EXPECT_EQ(12345, resultLayer->id());
3489 } 3489 }
3490 3490
3491 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForUninvertibl eTransform) 3491 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForUninvertibl eTransform)
3492 { 3492 {
3493 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 3493 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
3494 3494
3495 WebTransformationMatrix uninvertibleTransform; 3495 Transform uninvertibleTransform;
3496 uninvertibleTransform.setM11(0); 3496 uninvertibleTransform.matrix().setDouble(0, 0, 0);
3497 uninvertibleTransform.setM22(0); 3497 uninvertibleTransform.matrix().setDouble(1, 1, 0);
3498 uninvertibleTransform.setM33(0); 3498 uninvertibleTransform.matrix().setDouble(2, 2, 0);
3499 uninvertibleTransform.setM44(0); 3499 uninvertibleTransform.matrix().setDouble(3, 3, 0);
3500 ASSERT_FALSE(uninvertibleTransform.isInvertible()); 3500 ASSERT_FALSE(uninvertibleTransform.IsInvertible());
3501 3501
3502 WebTransformationMatrix identityMatrix; 3502 Transform identityMatrix;
3503 Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50)); 3503 Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50));
3504 gfx::PointF anchor(0, 0); 3504 gfx::PointF anchor(0, 0);
3505 gfx::PointF position(0, 0); 3505 gfx::PointF position(0, 0);
3506 gfx::Size bounds(100, 100); 3506 gfx::Size bounds(100, 100);
3507 setLayerPropertiesForTesting(root.get(), uninvertibleTransform, identityMatr ix, anchor, position, bounds, false); 3507 setLayerPropertiesForTesting(root.get(), uninvertibleTransform, identityMatr ix, anchor, position, bounds, false);
3508 root->setDrawsContent(true); 3508 root->setDrawsContent(true);
3509 root->setTouchEventHandlerRegion(touchHandlerRegion); 3509 root->setTouchEventHandlerRegion(touchHandlerRegion);
3510 3510
3511 std::vector<LayerImpl*> renderSurfaceLayerList; 3511 std::vector<LayerImpl*> renderSurfaceLayerList;
3512 int dummyMaxTextureSize = 512; 3512 int dummyMaxTextureSize = 512;
3513 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 3513 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3514 3514
3515 // Sanity check the scenario we just created. 3515 // Sanity check the scenario we just created.
3516 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 3516 ASSERT_EQ(1u, renderSurfaceLayerList.size());
3517 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 3517 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
3518 ASSERT_FALSE(root->screenSpaceTransform().isInvertible()); 3518 ASSERT_FALSE(root->screenSpaceTransform().IsInvertible());
3519 3519
3520 // Hit checking any point should not hit the touch handler region on the lay er. If the invertible matrix is 3520 // Hit checking any point should not hit the touch handler region on the lay er. If the invertible matrix is
3521 // accidentally ignored and treated like an identity, then the hit testing w ill 3521 // accidentally ignored and treated like an identity, then the hit testing w ill
3522 // incorrectly hit the layer when it shouldn't. 3522 // incorrectly hit the layer when it shouldn't.
3523 gfx::Point testPoint(1, 1); 3523 gfx::Point testPoint(1, 1);
3524 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList); 3524 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou chHandlerRegion(testPoint, renderSurfaceLayerList);
3525 EXPECT_FALSE(resultLayer); 3525 EXPECT_FALSE(resultLayer);
3526 3526
3527 testPoint = gfx::Point(10, 10); 3527 testPoint = gfx::Point(10, 10);
3528 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); 3528 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
(...skipping 17 matching lines...) Expand all
3546 3546
3547 testPoint = gfx::Point(-1, -1); 3547 testPoint = gfx::Point(-1, -1);
3548 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); 3548 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3549 EXPECT_FALSE(resultLayer); 3549 EXPECT_FALSE(resultLayer);
3550 } 3550 }
3551 3551
3552 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSinglePosit ionedLayer) 3552 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSinglePosit ionedLayer)
3553 { 3553 {
3554 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 3554 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
3555 3555
3556 WebTransformationMatrix identityMatrix; 3556 Transform identityMatrix;
3557 Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50)); 3557 Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50));
3558 gfx::PointF anchor(0, 0); 3558 gfx::PointF anchor(0, 0);
3559 gfx::PointF position(50, 50); // this layer is positioned, and hit testing s hould correctly know where the layer is located. 3559 gfx::PointF position(50, 50); // this layer is positioned, and hit testing s hould correctly know where the layer is located.
3560 gfx::Size bounds(100, 100); 3560 gfx::Size bounds(100, 100);
3561 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 3561 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
3562 root->setDrawsContent(true); 3562 root->setDrawsContent(true);
3563 root->setTouchEventHandlerRegion(touchHandlerRegion); 3563 root->setTouchEventHandlerRegion(touchHandlerRegion);
3564 3564
3565 std::vector<LayerImpl*> renderSurfaceLayerList; 3565 std::vector<LayerImpl*> renderSurfaceLayerList;
3566 int dummyMaxTextureSize = 512; 3566 int dummyMaxTextureSize = 512;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3604 // test makes sure that hit testing works correctly accounts for the content s scale. 3604 // test makes sure that hit testing works correctly accounts for the content s scale.
3605 // A contentsScale that is not 1 effectively forces a non-identity transform between 3605 // A contentsScale that is not 1 effectively forces a non-identity transform between
3606 // layer's content space and layer's origin space. The hit testing code must take this into account. 3606 // layer's content space and layer's origin space. The hit testing code must take this into account.
3607 // 3607 //
3608 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If 3608 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
3609 // contentsScale is ignored, then hit checking will mis-interpret the visibl eContentRect 3609 // contentsScale is ignored, then hit checking will mis-interpret the visibl eContentRect
3610 // as being larger than the actual bounds of the layer. 3610 // as being larger than the actual bounds of the layer.
3611 // 3611 //
3612 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 3612 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3613 3613
3614 WebTransformationMatrix identityMatrix; 3614 Transform identityMatrix;
3615 gfx::PointF anchor(0, 0); 3615 gfx::PointF anchor(0, 0);
3616 3616
3617 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false); 3617 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
3618 3618
3619 { 3619 {
3620 Region touchHandlerRegion(gfx::Rect(10, 10, 30, 30)); 3620 Region touchHandlerRegion(gfx::Rect(10, 10, 30, 30));
3621 gfx::PointF position(25, 25); 3621 gfx::PointF position(25, 25);
3622 gfx::Size bounds(50, 50); 3622 gfx::Size bounds(50, 50);
3623 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345); 3623 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345);
3624 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false); 3624 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3676 ASSERT_TRUE(resultLayer); 3676 ASSERT_TRUE(resultLayer);
3677 EXPECT_EQ(12345, resultLayer->id()); 3677 EXPECT_EQ(12345, resultLayer->id());
3678 } 3678 }
3679 3679
3680 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer WithDeviceScale) 3680 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer WithDeviceScale)
3681 { 3681 {
3682 // The layer's deviceScalefactor and pageScaleFactor should scale the conten tRect and we should 3682 // The layer's deviceScalefactor and pageScaleFactor should scale the conten tRect and we should
3683 // be able to hit the touch handler region by scaling the points accordingly . 3683 // be able to hit the touch handler region by scaling the points accordingly .
3684 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 3684 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3685 3685
3686 WebTransformationMatrix identityMatrix; 3686 Transform identityMatrix;
3687 gfx::PointF anchor(0, 0); 3687 gfx::PointF anchor(0, 0);
3688 // Set the bounds of the root layer big enough to fit the child when scaled. 3688 // Set the bounds of the root layer big enough to fit the child when scaled.
3689 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false); 3689 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
3690 3690
3691 { 3691 {
3692 Region touchHandlerRegion(gfx::Rect(10, 10, 30, 30)); 3692 Region touchHandlerRegion(gfx::Rect(10, 10, 30, 30));
3693 gfx::PointF position(25, 25); 3693 gfx::PointF position(25, 25);
3694 gfx::Size bounds(50, 50); 3694 gfx::Size bounds(50, 50);
3695 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345); 3695 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345);
3696 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false); 3696 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false);
3697 3697
3698 testLayer->setDrawsContent(true); 3698 testLayer->setDrawsContent(true);
3699 testLayer->setTouchEventHandlerRegion(touchHandlerRegion); 3699 testLayer->setTouchEventHandlerRegion(touchHandlerRegion);
3700 root->addChild(testLayer.Pass()); 3700 root->addChild(testLayer.Pass());
3701 } 3701 }
3702 3702
3703 std::vector<LayerImpl*> renderSurfaceLayerList; 3703 std::vector<LayerImpl*> renderSurfaceLayerList;
3704 int dummyMaxTextureSize = 512; 3704 int dummyMaxTextureSize = 512;
3705 float deviceScaleFactor = 3.0f; 3705 float deviceScaleFactor = 3.0f;
3706 float pageScaleFactor = 5.0f; 3706 float pageScaleFactor = 5.0f;
3707 WebTransformationMatrix pageScaleTransform; 3707 Transform pageScaleTransform;
3708 pageScaleTransform.scale(pageScaleFactor); 3708 pageScaleTransform.PreconcatScale(pageScaleFactor, pageScaleFactor);
3709 root->setImplTransform(pageScaleTransform); // Applying the pageScaleFactor through implTransform. 3709 root->setImplTransform(pageScaleTransform); // Applying the pageScaleFactor through implTransform.
3710 gfx::Size scaledBoundsForRoot = gfx::ToCeiledSize(gfx::ScaleSize(root->bound s(), deviceScaleFactor * pageScaleFactor)); 3710 gfx::Size scaledBoundsForRoot = gfx::ToCeiledSize(gfx::ScaleSize(root->bound s(), deviceScaleFactor * pageScaleFactor));
3711 LayerTreeHostCommon::calculateDrawTransforms(root.get(), scaledBoundsForRoot , deviceScaleFactor, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 3711 LayerTreeHostCommon::calculateDrawTransforms(root.get(), scaledBoundsForRoot , deviceScaleFactor, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3712 3712
3713 // Sanity check the scenario we just created. 3713 // Sanity check the scenario we just created.
3714 // The visibleContentRect for testLayer is actually 100x100, even though its layout size is 50x50, positioned at 25x25. 3714 // The visibleContentRect for testLayer is actually 100x100, even though its layout size is 50x50, positioned at 25x25.
3715 LayerImpl* testLayer = root->children()[0]; 3715 LayerImpl* testLayer = root->children()[0];
3716 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 3716 ASSERT_EQ(1u, renderSurfaceLayerList.size());
3717 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 3717 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
3718 3718
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3757 testPoint = gfx::ScalePoint(testPoint, deviceScaleFactor * pageScaleFactor); 3757 testPoint = gfx::ScalePoint(testPoint, deviceScaleFactor * pageScaleFactor);
3758 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); 3758 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3759 ASSERT_TRUE(resultLayer); 3759 ASSERT_TRUE(resultLayer);
3760 EXPECT_EQ(12345, resultLayer->id()); 3760 EXPECT_EQ(12345, resultLayer->id());
3761 } 3761 }
3762 3762
3763 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSimpleClipp edLayer) 3763 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSimpleClipp edLayer)
3764 { 3764 {
3765 // Test that hit-checking will only work for the visible portion of a layer, and not 3765 // Test that hit-checking will only work for the visible portion of a layer, and not
3766 // the entire layer bounds. Here we just test the simple axis-aligned case. 3766 // the entire layer bounds. Here we just test the simple axis-aligned case.
3767 WebTransformationMatrix identityMatrix; 3767 Transform identityMatrix;
3768 gfx::PointF anchor(0, 0); 3768 gfx::PointF anchor(0, 0);
3769 3769
3770 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 3770 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3771 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false); 3771 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
3772 3772
3773 { 3773 {
3774 scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(123); 3774 scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(123);
3775 gfx::PointF position(25, 25); // this layer is positioned, and hit testi ng should correctly know where the layer is located. 3775 gfx::PointF position(25, 25); // this layer is positioned, and hit testi ng should correctly know where the layer is located.
3776 gfx::Size bounds(50, 50); 3776 gfx::Size bounds(50, 50);
3777 setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identi tyMatrix, anchor, position, bounds, false); 3777 setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identi tyMatrix, anchor, position, bounds, false);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
3842 { 3842 {
3843 scoped_refptr<NoScaleContentLayer> toReturn = NoScaleContentLayer::create(de legate); 3843 scoped_refptr<NoScaleContentLayer> toReturn = NoScaleContentLayer::create(de legate);
3844 toReturn->setIsDrawable(true); 3844 toReturn->setIsDrawable(true);
3845 return toReturn; 3845 return toReturn;
3846 } 3846 }
3847 3847
3848 TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPI) 3848 TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPI)
3849 { 3849 {
3850 // Verify draw and screen space transforms of layers not in a surface. 3850 // Verify draw and screen space transforms of layers not in a surface.
3851 MockContentLayerClient delegate; 3851 MockContentLayerClient delegate;
3852 WebTransformationMatrix identityMatrix; 3852 Transform identityMatrix;
3853 3853
3854 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 3854 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
3855 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true); 3855 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true);
3856 3856
3857 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate); 3857 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate);
3858 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true); 3858 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
3859 3859
3860 scoped_refptr<ContentLayer> childEmpty = createDrawableContentLayer(&delegat e); 3860 scoped_refptr<ContentLayer> childEmpty = createDrawableContentLayer(&delegat e);
3861 setLayerPropertiesForTesting(childEmpty.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(0, 0), true); 3861 setLayerPropertiesForTesting(childEmpty.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(0, 0), true);
3862 3862
(...skipping 13 matching lines...) Expand all
3876 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 3876 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
3877 3877
3878 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, parent); 3878 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, parent);
3879 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, child); 3879 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, child);
3880 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, childEmpty); 3880 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, childEmpty);
3881 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); 3881 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale);
3882 3882
3883 EXPECT_EQ(1u, renderSurfaceLayerList.size()); 3883 EXPECT_EQ(1u, renderSurfaceLayerList.size());
3884 3884
3885 // Verify parent transforms 3885 // Verify parent transforms
3886 WebTransformationMatrix expectedParentTransform; 3886 Transform expectedParentTransform;
3887 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform()); 3887 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform());
3888 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm()); 3888 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm());
3889 3889
3890 // Verify results of transformed parent rects 3890 // Verify results of transformed parent rects
3891 gfx::RectF parentContentBounds(gfx::PointF(), gfx::SizeF(parent->contentBoun ds())); 3891 gfx::RectF parentContentBounds(gfx::PointF(), gfx::SizeF(parent->contentBoun ds()));
3892 3892
3893 gfx::RectF parentDrawRect = MathUtil::mapClippedRect(parent->drawTransform() , parentContentBounds); 3893 gfx::RectF parentDrawRect = MathUtil::mapClippedRect(parent->drawTransform() , parentContentBounds);
3894 gfx::RectF parentScreenSpaceRect = MathUtil::mapClippedRect(parent->screenSp aceTransform(), parentContentBounds); 3894 gfx::RectF parentScreenSpaceRect = MathUtil::mapClippedRect(parent->screenSp aceTransform(), parentContentBounds);
3895 3895
3896 gfx::RectF expectedParentDrawRect(gfx::PointF(), parent->bounds()); 3896 gfx::RectF expectedParentDrawRect(gfx::PointF(), parent->bounds());
3897 expectedParentDrawRect.Scale(deviceScaleFactor); 3897 expectedParentDrawRect.Scale(deviceScaleFactor);
3898 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentDrawRect); 3898 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentDrawRect);
3899 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentScreenSpaceRect); 3899 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentScreenSpaceRect);
3900 3900
3901 // Verify child and childEmpty transforms. They should match. 3901 // Verify child and childEmpty transforms. They should match.
3902 WebTransformationMatrix expectedChildTransform; 3902 Transform expectedChildTransform;
3903 expectedChildTransform.translate(deviceScaleFactor * child->position().x(), deviceScaleFactor * child->position().y()); 3903 expectedChildTransform.PreconcatTranslate(deviceScaleFactor * child->positio n().x(), deviceScaleFactor * child->position().y());
3904 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 3904 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
3905 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->screenSpaceTr ansform()); 3905 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->screenSpaceTr ansform());
3906 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, childEmpty->drawTran sform()); 3906 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, childEmpty->drawTran sform());
3907 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, childEmpty->screenSp aceTransform()); 3907 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, childEmpty->screenSp aceTransform());
3908 3908
3909 // Verify results of transformed child and childEmpty rects. They should mat ch. 3909 // Verify results of transformed child and childEmpty rects. They should mat ch.
3910 gfx::RectF childContentBounds(gfx::PointF(), gfx::SizeF(child->contentBounds ())); 3910 gfx::RectF childContentBounds(gfx::PointF(), gfx::SizeF(child->contentBounds ()));
3911 3911
3912 gfx::RectF childDrawRect = MathUtil::mapClippedRect(child->drawTransform(), childContentBounds); 3912 gfx::RectF childDrawRect = MathUtil::mapClippedRect(child->drawTransform(), childContentBounds);
3913 gfx::RectF childScreenSpaceRect = MathUtil::mapClippedRect(child->screenSpac eTransform(), childContentBounds); 3913 gfx::RectF childScreenSpaceRect = MathUtil::mapClippedRect(child->screenSpac eTransform(), childContentBounds);
3914 3914
3915 gfx::RectF childEmptyDrawRect = MathUtil::mapClippedRect(childEmpty->drawTra nsform(), childContentBounds); 3915 gfx::RectF childEmptyDrawRect = MathUtil::mapClippedRect(childEmpty->drawTra nsform(), childContentBounds);
3916 gfx::RectF childEmptyScreenSpaceRect = MathUtil::mapClippedRect(childEmpty-> screenSpaceTransform(), childContentBounds); 3916 gfx::RectF childEmptyScreenSpaceRect = MathUtil::mapClippedRect(childEmpty-> screenSpaceTransform(), childContentBounds);
3917 3917
3918 gfx::RectF expectedChildDrawRect(child->position(), child->bounds()); 3918 gfx::RectF expectedChildDrawRect(child->position(), child->bounds());
3919 expectedChildDrawRect.Scale(deviceScaleFactor); 3919 expectedChildDrawRect.Scale(deviceScaleFactor);
3920 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childDrawRect); 3920 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childDrawRect);
3921 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childScreenSpaceRect); 3921 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childScreenSpaceRect);
3922 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childEmptyDrawRect); 3922 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childEmptyDrawRect);
3923 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childEmptyScreenSpaceRect); 3923 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childEmptyScreenSpaceRect);
3924 3924
3925 // Verify childNoScale transforms 3925 // Verify childNoScale transforms
3926 WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform (); 3926 Transform expectedChildNoScaleTransform = child->drawTransform();
3927 // All transforms operate on content rects. The child's content rect 3927 // All transforms operate on content rects. The child's content rect
3928 // incorporates device scale, but the childNoScale does not; add it here. 3928 // incorporates device scale, but the childNoScale does not; add it here.
3929 expectedChildNoScaleTransform.scale(deviceScaleFactor); 3929 expectedChildNoScaleTransform.PreconcatScale(deviceScaleFactor, deviceScaleF actor);
3930 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >drawTransform()); 3930 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >drawTransform());
3931 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >screenSpaceTransform()); 3931 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >screenSpaceTransform());
3932 } 3932 }
3933 3933
3934 TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPIAccurateScaleZeroChi ldPosition) 3934 TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPIAccurateScaleZeroChi ldPosition)
3935 { 3935 {
3936 // Verify draw and screen space transforms of layers not in a surface. 3936 // Verify draw and screen space transforms of layers not in a surface.
3937 MockContentLayerClient delegate; 3937 MockContentLayerClient delegate;
3938 WebTransformationMatrix identityMatrix; 3938 Transform identityMatrix;
3939 3939
3940 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 3940 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
3941 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(133, 133), true); 3941 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(133, 133), true);
3942 3942
3943 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate); 3943 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate);
3944 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 13), true); 3944 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 13), true);
3945 3945
3946 scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableConte ntLayer(&delegate); 3946 scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableConte ntLayer(&delegate);
3947 setLayerPropertiesForTesting(childNoScale.get(), identityMatrix, identityMat rix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 13), true); 3947 setLayerPropertiesForTesting(childNoScale.get(), identityMatrix, identityMat rix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 13), true);
3948 3948
3949 parent->addChild(child); 3949 parent->addChild(child);
3950 parent->addChild(childNoScale); 3950 parent->addChild(childNoScale);
3951 3951
3952 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 3952 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
3953 int dummyMaxTextureSize = 512; 3953 int dummyMaxTextureSize = 512;
3954 3954
3955 const float deviceScaleFactor = 1.7f; 3955 const float deviceScaleFactor = 1.7f;
3956 const float pageScaleFactor = 1; 3956 const float pageScaleFactor = 1;
3957 3957
3958 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 3958 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
3959 3959
3960 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, parent); 3960 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, parent);
3961 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, child); 3961 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, child);
3962 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); 3962 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale);
3963 3963
3964 EXPECT_EQ(1u, renderSurfaceLayerList.size()); 3964 EXPECT_EQ(1u, renderSurfaceLayerList.size());
3965 3965
3966 // Verify parent transforms 3966 // Verify parent transforms
3967 WebTransformationMatrix expectedParentTransform; 3967 Transform expectedParentTransform;
3968 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform()); 3968 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform());
3969 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm()); 3969 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm());
3970 3970
3971 // Verify results of transformed parent rects 3971 // Verify results of transformed parent rects
3972 gfx::RectF parentContentBounds(gfx::PointF(), gfx::SizeF(parent->contentBoun ds())); 3972 gfx::RectF parentContentBounds(gfx::PointF(), gfx::SizeF(parent->contentBoun ds()));
3973 3973
3974 gfx::RectF parentDrawRect = MathUtil::mapClippedRect(parent->drawTransform() , parentContentBounds); 3974 gfx::RectF parentDrawRect = MathUtil::mapClippedRect(parent->drawTransform() , parentContentBounds);
3975 gfx::RectF parentScreenSpaceRect = MathUtil::mapClippedRect(parent->screenSp aceTransform(), parentContentBounds); 3975 gfx::RectF parentScreenSpaceRect = MathUtil::mapClippedRect(parent->screenSp aceTransform(), parentContentBounds);
3976 3976
3977 gfx::RectF expectedParentDrawRect(gfx::PointF(), parent->bounds()); 3977 gfx::RectF expectedParentDrawRect(gfx::PointF(), parent->bounds());
3978 expectedParentDrawRect.Scale(deviceScaleFactor); 3978 expectedParentDrawRect.Scale(deviceScaleFactor);
3979 expectedParentDrawRect.set_width(ceil(expectedParentDrawRect.width())); 3979 expectedParentDrawRect.set_width(ceil(expectedParentDrawRect.width()));
3980 expectedParentDrawRect.set_height(ceil(expectedParentDrawRect.height())); 3980 expectedParentDrawRect.set_height(ceil(expectedParentDrawRect.height()));
3981 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentDrawRect); 3981 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentDrawRect);
3982 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentScreenSpaceRect); 3982 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentScreenSpaceRect);
3983 3983
3984 // Verify child transforms 3984 // Verify child transforms
3985 WebTransformationMatrix expectedChildTransform; 3985 Transform expectedChildTransform;
3986 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 3986 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
3987 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->screenSpaceTr ansform()); 3987 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->screenSpaceTr ansform());
3988 3988
3989 // Verify results of transformed child rects 3989 // Verify results of transformed child rects
3990 gfx::RectF childContentBounds(gfx::PointF(), gfx::SizeF(child->contentBounds ())); 3990 gfx::RectF childContentBounds(gfx::PointF(), gfx::SizeF(child->contentBounds ()));
3991 3991
3992 gfx::RectF childDrawRect = MathUtil::mapClippedRect(child->drawTransform(), childContentBounds); 3992 gfx::RectF childDrawRect = MathUtil::mapClippedRect(child->drawTransform(), childContentBounds);
3993 gfx::RectF childScreenSpaceRect = MathUtil::mapClippedRect(child->screenSpac eTransform(), childContentBounds); 3993 gfx::RectF childScreenSpaceRect = MathUtil::mapClippedRect(child->screenSpac eTransform(), childContentBounds);
3994 3994
3995 gfx::RectF expectedChildDrawRect(gfx::PointF(), child->bounds()); 3995 gfx::RectF expectedChildDrawRect(gfx::PointF(), child->bounds());
3996 expectedChildDrawRect.Scale(deviceScaleFactor); 3996 expectedChildDrawRect.Scale(deviceScaleFactor);
3997 expectedChildDrawRect.set_width(ceil(expectedChildDrawRect.width())); 3997 expectedChildDrawRect.set_width(ceil(expectedChildDrawRect.width()));
3998 expectedChildDrawRect.set_height(ceil(expectedChildDrawRect.height())); 3998 expectedChildDrawRect.set_height(ceil(expectedChildDrawRect.height()));
3999 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childDrawRect); 3999 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childDrawRect);
4000 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childScreenSpaceRect); 4000 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childScreenSpaceRect);
4001 4001
4002 // Verify childNoScale transforms 4002 // Verify childNoScale transforms
4003 WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform (); 4003 Transform expectedChildNoScaleTransform = child->drawTransform();
4004 // All transforms operate on content rects. The child's content rect 4004 // All transforms operate on content rects. The child's content rect
4005 // incorporates device scale, but the childNoScale does not; add it here. 4005 // incorporates device scale, but the childNoScale does not; add it here.
4006 expectedChildNoScaleTransform.scale(deviceScaleFactor); 4006 expectedChildNoScaleTransform.PreconcatScale(deviceScaleFactor, deviceScaleF actor);
4007 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >drawTransform()); 4007 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >drawTransform());
4008 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >screenSpaceTransform()); 4008 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >screenSpaceTransform());
4009 } 4009 }
4010 4010
4011 TEST(LayerTreeHostCommonTest, verifyContentsScale) 4011 TEST(LayerTreeHostCommonTest, verifyContentsScale)
4012 { 4012 {
4013 MockContentLayerClient delegate; 4013 MockContentLayerClient delegate;
4014 WebTransformationMatrix identityMatrix; 4014 Transform identityMatrix;
4015 4015
4016 WebTransformationMatrix parentScaleMatrix; 4016 Transform parentScaleMatrix;
4017 const double initialParentScale = 1.75; 4017 const double initialParentScale = 1.75;
4018 parentScaleMatrix.scale(initialParentScale); 4018 parentScaleMatrix.PreconcatScale(initialParentScale, initialParentScale);
4019 4019
4020 WebTransformationMatrix childScaleMatrix; 4020 Transform childScaleMatrix;
4021 const double initialChildScale = 1.25; 4021 const double initialChildScale = 1.25;
4022 childScaleMatrix.scale(initialChildScale); 4022 childScaleMatrix.PreconcatScale(initialChildScale, initialChildScale);
4023 4023
4024 float fixedRasterScale = 2.5; 4024 float fixedRasterScale = 2.5;
4025 4025
4026 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 4026 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
4027 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true); 4027 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true);
4028 4028
4029 scoped_refptr<ContentLayer> childScale = createDrawableContentLayer(&delegat e); 4029 scoped_refptr<ContentLayer> childScale = createDrawableContentLayer(&delegat e);
4030 setLayerPropertiesForTesting(childScale.get(), childScaleMatrix, identityMat rix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true); 4030 setLayerPropertiesForTesting(childScale.get(), childScaleMatrix, identityMat rix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
4031 4031
4032 scoped_refptr<ContentLayer> childEmpty = createDrawableContentLayer(&delegat e); 4032 scoped_refptr<ContentLayer> childEmpty = createDrawableContentLayer(&delegat e);
(...skipping 16 matching lines...) Expand all
4049 parent->addChild(childNoScale); 4049 parent->addChild(childNoScale);
4050 parent->addChild(childNoAutoScale); 4050 parent->addChild(childNoAutoScale);
4051 4051
4052 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 4052 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
4053 int dummyMaxTextureSize = 512; 4053 int dummyMaxTextureSize = 512;
4054 4054
4055 double deviceScaleFactor = 2.5; 4055 double deviceScaleFactor = 2.5;
4056 double pageScaleFactor = 1.5; 4056 double pageScaleFactor = 1.5;
4057 4057
4058 // FIXME: Remove this when pageScaleFactor is applied in the compositor. 4058 // FIXME: Remove this when pageScaleFactor is applied in the compositor.
4059 WebTransformationMatrix pageScaleMatrix; 4059 Transform pageScaleMatrix;
4060 pageScaleMatrix.scale(pageScaleFactor); 4060 pageScaleMatrix.PreconcatScale(pageScaleFactor, pageScaleFactor);
4061 parent->setSublayerTransform(pageScaleMatrix); 4061 parent->setSublayerTransform(pageScaleMatrix);
4062 4062
4063 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 4063 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
4064 4064
4065 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent); 4065 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent);
4066 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, childScale); 4066 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, childScale);
4067 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, childEmpty); 4067 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, childEmpty);
4068 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); 4068 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale);
4069 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterSc ale, childNoAutoScale); 4069 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterSc ale, childNoAutoScale);
4070 4070
4071 // The parent is scaled up and shouldn't need to scale during draw. The chil d that can scale its contents should 4071 // The parent is scaled up and shouldn't need to scale during draw. The chil d that can scale its contents should
4072 // also not need to scale during draw. This shouldn't change if the child ha s empty bounds. The other children should. 4072 // also not need to scale during draw. This shouldn't change if the child ha s empty bounds. The other children should.
4073 EXPECT_FLOAT_EQ(1, parent->drawTransform().m11()); 4073 EXPECT_FLOAT_EQ(1, parent->drawTransform().matrix().getDouble(0, 0));
4074 EXPECT_FLOAT_EQ(1, parent->drawTransform().m22()); 4074 EXPECT_FLOAT_EQ(1, parent->drawTransform().matrix().getDouble(1, 1));
4075 EXPECT_FLOAT_EQ(1, childScale->drawTransform().m11()); 4075 EXPECT_FLOAT_EQ(1, childScale->drawTransform().matrix().getDouble(0, 0));
4076 EXPECT_FLOAT_EQ(1, childScale->drawTransform().m22()); 4076 EXPECT_FLOAT_EQ(1, childScale->drawTransform().matrix().getDouble(1, 1));
4077 EXPECT_FLOAT_EQ(1, childEmpty->drawTransform().m11()); 4077 EXPECT_FLOAT_EQ(1, childEmpty->drawTransform().matrix().getDouble(0, 0));
4078 EXPECT_FLOAT_EQ(1, childEmpty->drawTransform().m22()); 4078 EXPECT_FLOAT_EQ(1, childEmpty->drawTransform().matrix().getDouble(1, 1));
4079 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale, childNoScale->drawTransform().m11()); 4079 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale, childNoScale->drawTransform().matrix().getDouble(0, 0));
4080 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale, childNoScale->drawTransform().m22()); 4080 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale, childNoScale->drawTransform().matrix().getDouble(1, 1));
4081 EXPECT_FLOAT_EQ(initialParentScale * initialChildScale / fixedRasterScale, c hildNoAutoScale->drawTransform().m11()); 4081 EXPECT_FLOAT_EQ(initialParentScale * initialChildScale / fixedRasterScale, c hildNoAutoScale->drawTransform().matrix().getDouble(0, 0));
4082 EXPECT_FLOAT_EQ(initialParentScale * initialChildScale / fixedRasterScale, c hildNoAutoScale->drawTransform().m22()); 4082 EXPECT_FLOAT_EQ(initialParentScale * initialChildScale / fixedRasterScale, c hildNoAutoScale->drawTransform().matrix().getDouble(1, 1));
4083 4083
4084 // If the transform changes, we expect the contentsScale to remain unchanged . 4084 // If the transform changes, we expect the contentsScale to remain unchanged .
4085 childScale->setTransform(identityMatrix); 4085 childScale->setTransform(identityMatrix);
4086 childEmpty->setTransform(identityMatrix); 4086 childEmpty->setTransform(identityMatrix);
4087 4087
4088 renderSurfaceLayerList.clear(); 4088 renderSurfaceLayerList.clear();
4089 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 4089 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
4090 4090
4091 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent); 4091 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent);
4092 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, childScale); 4092 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, childScale);
4093 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, childEmpty); 4093 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, childEmpty);
4094 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); 4094 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale);
4095 4095
4096 // But if the deviceScaleFactor or pageScaleFactor changes, then it should b e updated, but using the initial transform. 4096 // But if the deviceScaleFactor or pageScaleFactor changes, then it should b e updated, but using the initial transform.
4097 deviceScaleFactor = 2.25; 4097 deviceScaleFactor = 2.25;
4098 pageScaleFactor = 1.25; 4098 pageScaleFactor = 1.25;
4099 4099
4100 // FIXME: Remove this when pageScaleFactor is applied in the compositor. 4100 // FIXME: Remove this when pageScaleFactor is applied in the compositor.
4101 pageScaleMatrix = identityMatrix; 4101 pageScaleMatrix = identityMatrix;
4102 pageScaleMatrix.scale(pageScaleFactor); 4102 pageScaleMatrix.PreconcatScale(pageScaleFactor, pageScaleFactor);
4103 parent->setSublayerTransform(pageScaleMatrix); 4103 parent->setSublayerTransform(pageScaleMatrix);
4104 4104
4105 renderSurfaceLayerList.clear(); 4105 renderSurfaceLayerList.clear();
4106 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 4106 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
4107 4107
4108 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent); 4108 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent);
4109 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, childScale); 4109 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, childScale);
4110 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, childEmpty); 4110 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, childEmpty);
4111 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); 4111 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale);
4112 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterSc ale, childNoAutoScale); 4112 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterSc ale, childNoAutoScale);
4113 } 4113 }
4114 4114
4115 TEST(LayerTreeHostCommonTest, verifySmallContentsScale) 4115 TEST(LayerTreeHostCommonTest, verifySmallContentsScale)
4116 { 4116 {
4117 MockContentLayerClient delegate; 4117 MockContentLayerClient delegate;
4118 WebTransformationMatrix identityMatrix; 4118 Transform identityMatrix;
4119 4119
4120 WebTransformationMatrix parentScaleMatrix; 4120 Transform parentScaleMatrix;
4121 const double initialParentScale = 1.75; 4121 const double initialParentScale = 1.75;
4122 parentScaleMatrix.scale(initialParentScale); 4122 parentScaleMatrix.PreconcatScale(initialParentScale, initialParentScale);
4123 4123
4124 WebTransformationMatrix childScaleMatrix; 4124 Transform childScaleMatrix;
4125 const double initialChildScale = 0.25; 4125 const double initialChildScale = 0.25;
4126 childScaleMatrix.scale(initialChildScale); 4126 childScaleMatrix.PreconcatScale(initialChildScale, initialChildScale);
4127 4127
4128 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 4128 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
4129 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true); 4129 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true);
4130 4130
4131 scoped_refptr<ContentLayer> childScale = createDrawableContentLayer(&delegat e); 4131 scoped_refptr<ContentLayer> childScale = createDrawableContentLayer(&delegat e);
4132 setLayerPropertiesForTesting(childScale.get(), childScaleMatrix, identityMat rix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true); 4132 setLayerPropertiesForTesting(childScale.get(), childScaleMatrix, identityMat rix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
4133 4133
4134 // FIXME: Remove this when pageScaleFactor is applied in the compositor. 4134 // FIXME: Remove this when pageScaleFactor is applied in the compositor.
4135 // Page scale should not apply to the parent. 4135 // Page scale should not apply to the parent.
4136 parent->setBoundsContainPageScale(true); 4136 parent->setBoundsContainPageScale(true);
4137 4137
4138 parent->addChild(childScale); 4138 parent->addChild(childScale);
4139 4139
4140 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 4140 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
4141 int dummyMaxTextureSize = 512; 4141 int dummyMaxTextureSize = 512;
4142 4142
4143 double deviceScaleFactor = 2.5; 4143 double deviceScaleFactor = 2.5;
4144 double pageScaleFactor = 0.01; 4144 double pageScaleFactor = 0.01;
4145 4145
4146 // FIXME: Remove this when pageScaleFactor is applied in the compositor. 4146 // FIXME: Remove this when pageScaleFactor is applied in the compositor.
4147 WebTransformationMatrix pageScaleMatrix; 4147 Transform pageScaleMatrix;
4148 pageScaleMatrix.scale(pageScaleFactor); 4148 pageScaleMatrix.PreconcatScale(pageScaleFactor, pageScaleFactor);
4149 parent->setSublayerTransform(pageScaleMatrix); 4149 parent->setSublayerTransform(pageScaleMatrix);
4150 4150
4151 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 4151 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
4152 4152
4153 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent); 4153 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent);
4154 // The child's scale is < 1, so we should not save and use that scale factor . 4154 // The child's scale is < 1, so we should not save and use that scale factor .
4155 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * 1, childScale ); 4155 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * 1, childScale );
4156 4156
4157 // When chilld's total scale becomes >= 1, we should save and use that scale factor. 4157 // When chilld's total scale becomes >= 1, we should save and use that scale factor.
4158 childScaleMatrix.makeIdentity(); 4158 childScaleMatrix.matrix().setIdentity();
4159 const double finalChildScale = 0.75; 4159 const double finalChildScale = 0.75;
4160 childScaleMatrix.scale(finalChildScale); 4160 childScaleMatrix.PreconcatScale(finalChildScale, finalChildScale);
4161 childScale->setTransform(childScaleMatrix); 4161 childScale->setTransform(childScaleMatrix);
4162 4162
4163 renderSurfaceLayerList.clear(); 4163 renderSurfaceLayerList.clear();
4164 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 4164 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
4165 4165
4166 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent); 4166 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent);
4167 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * finalChildScale, childScale); 4167 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * finalChildScale, childScale);
4168 } 4168 }
4169 4169
4170 TEST(LayerTreeHostCommonTest, verifyContentsScaleForSurfaces) 4170 TEST(LayerTreeHostCommonTest, verifyContentsScaleForSurfaces)
4171 { 4171 {
4172 MockContentLayerClient delegate; 4172 MockContentLayerClient delegate;
4173 WebTransformationMatrix identityMatrix; 4173 Transform identityMatrix;
4174 4174
4175 WebTransformationMatrix parentScaleMatrix; 4175 Transform parentScaleMatrix;
4176 const double initialParentScale = 2; 4176 const double initialParentScale = 2;
4177 parentScaleMatrix.scale(initialParentScale); 4177 parentScaleMatrix.PreconcatScale(initialParentScale, initialParentScale);
4178 4178
4179 WebTransformationMatrix childScaleMatrix; 4179 Transform childScaleMatrix;
4180 const double initialChildScale = 3; 4180 const double initialChildScale = 3;
4181 childScaleMatrix.scale(initialChildScale); 4181 childScaleMatrix.PreconcatScale(initialChildScale, initialChildScale);
4182 4182
4183 float fixedRasterScale = 4; 4183 float fixedRasterScale = 4;
4184 4184
4185 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 4185 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
4186 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true); 4186 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true);
4187 4187
4188 scoped_refptr<ContentLayer> surfaceScale = createDrawableContentLayer(&deleg ate); 4188 scoped_refptr<ContentLayer> surfaceScale = createDrawableContentLayer(&deleg ate);
4189 setLayerPropertiesForTesting(surfaceScale.get(), childScaleMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true); 4189 setLayerPropertiesForTesting(surfaceScale.get(), childScaleMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
4190 4190
4191 scoped_refptr<ContentLayer> surfaceScaleChildScale = createDrawableContentLa yer(&delegate); 4191 scoped_refptr<ContentLayer> surfaceScaleChildScale = createDrawableContentLa yer(&delegate);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
4234 surfaceNoAutoScale->addChild(surfaceNoAutoScaleChildScale); 4234 surfaceNoAutoScale->addChild(surfaceNoAutoScaleChildScale);
4235 surfaceNoAutoScale->addChild(surfaceNoAutoScaleChildNoScale); 4235 surfaceNoAutoScale->addChild(surfaceNoAutoScaleChildNoScale);
4236 4236
4237 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 4237 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
4238 int dummyMaxTextureSize = 512; 4238 int dummyMaxTextureSize = 512;
4239 4239
4240 double deviceScaleFactor = 5; 4240 double deviceScaleFactor = 5;
4241 double pageScaleFactor = 7; 4241 double pageScaleFactor = 7;
4242 4242
4243 // FIXME: Remove this when pageScaleFactor is applied in the compositor. 4243 // FIXME: Remove this when pageScaleFactor is applied in the compositor.
4244 WebTransformationMatrix pageScaleMatrix; 4244 Transform pageScaleMatrix;
4245 pageScaleMatrix.scale(pageScaleFactor); 4245 pageScaleMatrix.PreconcatScale(pageScaleFactor, pageScaleFactor);
4246 parent->setSublayerTransform(pageScaleMatrix); 4246 parent->setSublayerTransform(pageScaleMatrix);
4247 4247
4248 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 4248 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
4249 4249
4250 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent); 4250 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent);
4251 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, surfaceScale); 4251 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, surfaceScale);
4252 EXPECT_CONTENTS_SCALE_EQ(1, surfaceNoScale); 4252 EXPECT_CONTENTS_SCALE_EQ(1, surfaceNoScale);
4253 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterSc ale, surfaceNoAutoScale); 4253 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterSc ale, surfaceNoAutoScale);
4254 4254
4255 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale * initialChildScale, surfaceScaleChildScale); 4255 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale * initialChildScale, surfaceScaleChildScale);
4256 EXPECT_CONTENTS_SCALE_EQ(1, surfaceScaleChildNoScale); 4256 EXPECT_CONTENTS_SCALE_EQ(1, surfaceScaleChildNoScale);
4257 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale * initialChildScale, surfaceNoScaleChildScale); 4257 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale * initialChildScale, surfaceNoScaleChildScale);
4258 EXPECT_CONTENTS_SCALE_EQ(1, surfaceNoScaleChildNoScale); 4258 EXPECT_CONTENTS_SCALE_EQ(1, surfaceNoScaleChildNoScale);
4259 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale * initialChildScale, surfaceNoAutoScaleChildScale); 4259 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale * initialChildScale, surfaceNoAutoScaleChildScale);
4260 EXPECT_CONTENTS_SCALE_EQ(1, surfaceNoAutoScaleChildNoScale); 4260 EXPECT_CONTENTS_SCALE_EQ(1, surfaceNoAutoScaleChildNoScale);
4261 4261
4262 // The parent is scaled up and shouldn't need to scale during draw. 4262 // The parent is scaled up and shouldn't need to scale during draw.
4263 EXPECT_FLOAT_EQ(1, parent->drawTransform().m11()); 4263 EXPECT_FLOAT_EQ(1, parent->drawTransform().matrix().getDouble(0, 0));
4264 EXPECT_FLOAT_EQ(1, parent->drawTransform().m22()); 4264 EXPECT_FLOAT_EQ(1, parent->drawTransform().matrix().getDouble(1, 1));
4265 4265
4266 // RenderSurfaces should always be 1:1 with their target. 4266 // RenderSurfaces should always be 1:1 with their target.
4267 EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().m11()); 4267 EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().matrix().g etDouble(0, 0));
4268 EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().m22()); 4268 EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().matrix().g etDouble(1, 1));
4269 4269
4270 // The surfaceScale can apply contents scale so the layer shouldn't need to scale during draw. 4270 // The surfaceScale can apply contents scale so the layer shouldn't need to scale during draw.
4271 EXPECT_FLOAT_EQ(1, surfaceScale->drawTransform().m11()); 4271 EXPECT_FLOAT_EQ(1, surfaceScale->drawTransform().matrix().getDouble(0, 0));
4272 EXPECT_FLOAT_EQ(1, surfaceScale->drawTransform().m22()); 4272 EXPECT_FLOAT_EQ(1, surfaceScale->drawTransform().matrix().getDouble(1, 1));
4273 4273
4274 // The surfaceScaleChildScale can apply contents scale so it shouldn't need to scale during draw. 4274 // The surfaceScaleChildScale can apply contents scale so it shouldn't need to scale during draw.
4275 EXPECT_FLOAT_EQ(1, surfaceScaleChildScale->drawTransform().m11()); 4275 EXPECT_FLOAT_EQ(1, surfaceScaleChildScale->drawTransform().matrix().getDoubl e(0, 0));
4276 EXPECT_FLOAT_EQ(1, surfaceScaleChildScale->drawTransform().m22()); 4276 EXPECT_FLOAT_EQ(1, surfaceScaleChildScale->drawTransform().matrix().getDoubl e(1, 1));
4277 4277
4278 // The surfaceScaleChildNoScale can not apply contents scale, so it needs to be scaled during draw. 4278 // The surfaceScaleChildNoScale can not apply contents scale, so it needs to be scaled during draw.
4279 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceScaleChildNoScale->drawTransform(). m11()); 4279 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceScaleChildNoScale->drawTransform(). matrix().getDouble(0, 0));
4280 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceScaleChildNoScale->drawTransform(). m22()); 4280 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceScaleChildNoScale->drawTransform(). matrix().getDouble(1, 1));
4281 4281
4282 // RenderSurfaces should always be 1:1 with their target. 4282 // RenderSurfaces should always be 1:1 with their target.
4283 EXPECT_FLOAT_EQ(1, surfaceNoScale->renderSurface()->drawTransform().m11()); 4283 EXPECT_FLOAT_EQ(1, surfaceNoScale->renderSurface()->drawTransform().matrix() .getDouble(0, 0));
4284 EXPECT_FLOAT_EQ(1, surfaceNoScale->renderSurface()->drawTransform().m22()); 4284 EXPECT_FLOAT_EQ(1, surfaceNoScale->renderSurface()->drawTransform().matrix() .getDouble(1, 1));
4285 4285
4286 // The surfaceNoScale layer can not apply contents scale, so it needs to be scaled during draw. 4286 // The surfaceNoScale layer can not apply contents scale, so it needs to be scaled during draw.
4287 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale, surfaceNoScale->drawTransform().m11()); 4287 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale, surfaceNoScale->drawTransform().matrix().getDouble(0, 0));
4288 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale, surfaceNoScale->drawTransform().m22()); 4288 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale, surfaceNoScale->drawTransform().matrix().getDouble(1, 1));
4289 4289
4290 // The surfaceScaleChildScale can apply contents scale so it shouldn't need to scale during draw. 4290 // The surfaceScaleChildScale can apply contents scale so it shouldn't need to scale during draw.
4291 EXPECT_FLOAT_EQ(1, surfaceNoScaleChildScale->drawTransform().m11()); 4291 EXPECT_FLOAT_EQ(1, surfaceNoScaleChildScale->drawTransform().matrix().getDou ble(0, 0));
4292 EXPECT_FLOAT_EQ(1, surfaceNoScaleChildScale->drawTransform().m22()); 4292 EXPECT_FLOAT_EQ(1, surfaceNoScaleChildScale->drawTransform().matrix().getDou ble(1, 1));
4293 4293
4294 // The surfaceScaleChildNoScale can not apply contents scale, so it needs to be scaled during draw. 4294 // The surfaceScaleChildNoScale can not apply contents scale, so it needs to be scaled during draw.
4295 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoScaleChildNoScale->drawTransform( ).m11()); 4295 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoScaleChildNoScale->drawTransform( ).matrix().getDouble(0, 0));
4296 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoScaleChildNoScale->drawTransform( ).m22()); 4296 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoScaleChildNoScale->drawTransform( ).matrix().getDouble(1, 1));
4297 4297
4298 // RenderSurfaces should always be 1:1 with their target. 4298 // RenderSurfaces should always be 1:1 with their target.
4299 EXPECT_FLOAT_EQ(1, surfaceNoAutoScale->renderSurface()->drawTransform().m11( )); 4299 EXPECT_FLOAT_EQ(1, surfaceNoAutoScale->renderSurface()->drawTransform().matr ix().getDouble(0, 0));
4300 EXPECT_FLOAT_EQ(1, surfaceNoAutoScale->renderSurface()->drawTransform().m22( )); 4300 EXPECT_FLOAT_EQ(1, surfaceNoAutoScale->renderSurface()->drawTransform().matr ix().getDouble(1, 1));
4301 4301
4302 // The surfaceNoAutoScale layer has a fixed contents scale, so it needs to b e scaled during draw. 4302 // The surfaceNoAutoScale layer has a fixed contents scale, so it needs to b e scaled during draw.
4303 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale / (deviceScaleFactor * pageScaleFactor * fixedRasterScale), sur faceNoAutoScale->drawTransform().m11()); 4303 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale / (deviceScaleFactor * pageScaleFactor * fixedRasterScale), sur faceNoAutoScale->drawTransform().matrix().getDouble(0, 0));
4304 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale / (deviceScaleFactor * pageScaleFactor * fixedRasterScale), sur faceNoAutoScale->drawTransform().m22()); 4304 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale / (deviceScaleFactor * pageScaleFactor * fixedRasterScale), sur faceNoAutoScale->drawTransform().matrix().getDouble(1, 1));
4305 4305
4306 // The surfaceScaleChildScale can apply contents scale so it shouldn't need to scale during draw. 4306 // The surfaceScaleChildScale can apply contents scale so it shouldn't need to scale during draw.
4307 EXPECT_FLOAT_EQ(1, surfaceNoAutoScaleChildScale->drawTransform().m11()); 4307 EXPECT_FLOAT_EQ(1, surfaceNoAutoScaleChildScale->drawTransform().matrix().ge tDouble(0, 0));
4308 EXPECT_FLOAT_EQ(1, surfaceNoAutoScaleChildScale->drawTransform().m22()); 4308 EXPECT_FLOAT_EQ(1, surfaceNoAutoScaleChildScale->drawTransform().matrix().ge tDouble(1, 1));
4309 4309
4310 // The surfaceScaleChildNoScale can not apply contents scale, so it needs to be scaled during draw. 4310 // The surfaceScaleChildNoScale can not apply contents scale, so it needs to be scaled during draw.
4311 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoAutoScaleChildNoScale->drawTransf orm().m11()); 4311 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoAutoScaleChildNoScale->drawTransf orm().matrix().getDouble(0, 0));
4312 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoAutoScaleChildNoScale->drawTransf orm().m22()); 4312 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoAutoScaleChildNoScale->drawTransf orm().matrix().getDouble(1, 1));
4313 } 4313 }
4314 4314
4315 TEST(LayerTreeHostCommonTest, verifyContentsScaleForAnimatingLayer) 4315 TEST(LayerTreeHostCommonTest, verifyContentsScaleForAnimatingLayer)
4316 { 4316 {
4317 MockContentLayerClient delegate; 4317 MockContentLayerClient delegate;
4318 WebTransformationMatrix identityMatrix; 4318 Transform identityMatrix;
4319 4319
4320 WebTransformationMatrix parentScaleMatrix; 4320 Transform parentScaleMatrix;
4321 const double initialParentScale = 1.75; 4321 const double initialParentScale = 1.75;
4322 parentScaleMatrix.scale(initialParentScale); 4322 parentScaleMatrix.PreconcatScale(initialParentScale, initialParentScale);
4323 4323
4324 WebTransformationMatrix childScaleMatrix; 4324 Transform childScaleMatrix;
4325 const double initialChildScale = 1.25; 4325 const double initialChildScale = 1.25;
4326 childScaleMatrix.scale(initialChildScale); 4326 childScaleMatrix.PreconcatScale(initialChildScale, initialChildScale);
4327 4327
4328 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 4328 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
4329 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true); 4329 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true);
4330 4330
4331 scoped_refptr<ContentLayer> childScale = createDrawableContentLayer(&delegat e); 4331 scoped_refptr<ContentLayer> childScale = createDrawableContentLayer(&delegat e);
4332 setLayerPropertiesForTesting(childScale.get(), childScaleMatrix, identityMat rix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true); 4332 setLayerPropertiesForTesting(childScale.get(), childScaleMatrix, identityMat rix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
4333 4333
4334 parent->addChild(childScale); 4334 parent->addChild(childScale);
4335 4335
4336 // Now put an animating transform on child. 4336 // Now put an animating transform on child.
(...skipping 15 matching lines...) Expand all
4352 4352
4353 EXPECT_CONTENTS_SCALE_EQ(initialParentScale, parent); 4353 EXPECT_CONTENTS_SCALE_EQ(initialParentScale, parent);
4354 // The layers with animating transforms should not compute a contentsScale o ther than 1 until they finish animating. 4354 // The layers with animating transforms should not compute a contentsScale o ther than 1 until they finish animating.
4355 EXPECT_CONTENTS_SCALE_EQ(initialParentScale * initialChildScale, childScale) ; 4355 EXPECT_CONTENTS_SCALE_EQ(initialParentScale * initialChildScale, childScale) ;
4356 } 4356 }
4357 4357
4358 4358
4359 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPI) 4359 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPI)
4360 { 4360 {
4361 MockContentLayerClient delegate; 4361 MockContentLayerClient delegate;
4362 WebTransformationMatrix identityMatrix; 4362 Transform identityMatrix;
4363 4363
4364 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 4364 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
4365 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(30, 30), true); 4365 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(30, 30), true);
4366 4366
4367 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate); 4367 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate);
4368 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true); 4368 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
4369 4369
4370 WebTransformationMatrix replicaTransform; 4370 Transform replicaTransform;
4371 replicaTransform.scaleNonUniform(1, -1); 4371 replicaTransform.PreconcatScale(1, -1);
4372 scoped_refptr<ContentLayer> replica = createDrawableContentLayer(&delegate); 4372 scoped_refptr<ContentLayer> replica = createDrawableContentLayer(&delegate);
4373 setLayerPropertiesForTesting(replica.get(), replicaTransform, identityMatrix , gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true); 4373 setLayerPropertiesForTesting(replica.get(), replicaTransform, identityMatrix , gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
4374 4374
4375 // This layer should end up in the same surface as child, with the same draw 4375 // This layer should end up in the same surface as child, with the same draw
4376 // and screen space transforms. 4376 // and screen space transforms.
4377 scoped_refptr<ContentLayer> duplicateChildNonOwner = createDrawableContentLa yer(&delegate); 4377 scoped_refptr<ContentLayer> duplicateChildNonOwner = createDrawableContentLa yer(&delegate);
4378 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i dentityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), true); 4378 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i dentityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), true);
4379 4379
4380 parent->addChild(child); 4380 parent->addChild(child);
4381 child->addChild(duplicateChildNonOwner); 4381 child->addChild(duplicateChildNonOwner);
4382 child->setReplicaLayer(replica.get()); 4382 child->setReplicaLayer(replica.get());
4383 4383
4384 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 4384 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
4385 int dummyMaxTextureSize = 512; 4385 int dummyMaxTextureSize = 512;
4386 4386
4387 const double deviceScaleFactor = 1.5; 4387 const double deviceScaleFactor = 1.5;
4388 parent->setContentsScale(deviceScaleFactor); 4388 parent->setContentsScale(deviceScaleFactor);
4389 child->setContentsScale(deviceScaleFactor); 4389 child->setContentsScale(deviceScaleFactor);
4390 duplicateChildNonOwner->setContentsScale(deviceScaleFactor); 4390 duplicateChildNonOwner->setContentsScale(deviceScaleFactor);
4391 replica->setContentsScale(deviceScaleFactor); 4391 replica->setContentsScale(deviceScaleFactor);
4392 4392
4393 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, 1, dummyMaxTextureSize, renderSurfaceLayerList); 4393 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, 1, dummyMaxTextureSize, renderSurfaceLayerList);
4394 4394
4395 // We should have two render surfaces. The root's render surface and child's 4395 // We should have two render surfaces. The root's render surface and child's
4396 // render surface (it needs one because it has a replica layer). 4396 // render surface (it needs one because it has a replica layer).
4397 EXPECT_EQ(2u, renderSurfaceLayerList.size()); 4397 EXPECT_EQ(2u, renderSurfaceLayerList.size());
4398 4398
4399 WebTransformationMatrix expectedParentTransform; 4399 Transform expectedParentTransform;
4400 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform()); 4400 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform());
4401 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm()); 4401 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm());
4402 4402
4403 WebTransformationMatrix expectedDrawTransform; 4403 Transform expectedDrawTransform;
4404 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedDrawTransform, child->drawTransform( )); 4404 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedDrawTransform, child->drawTransform( ));
4405 4405
4406 WebTransformationMatrix expectedScreenSpaceTransform; 4406 Transform expectedScreenSpaceTransform;
4407 expectedScreenSpaceTransform.translate(deviceScaleFactor * child->position() .x(), deviceScaleFactor * child->position().y()); 4407 expectedScreenSpaceTransform.PreconcatTranslate(deviceScaleFactor * child->p osition().x(), deviceScaleFactor * child->position().y());
4408 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedScreenSpaceTransform, child->screenS paceTransform()); 4408 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedScreenSpaceTransform, child->screenS paceTransform());
4409 4409
4410 WebTransformationMatrix expectedDuplicateChildDrawTransform = child->drawTra nsform(); 4410 Transform expectedDuplicateChildDrawTransform = child->drawTransform();
4411 EXPECT_TRANSFORMATION_MATRIX_EQ(child->drawTransform(), duplicateChildNonOwn er->drawTransform()); 4411 EXPECT_TRANSFORMATION_MATRIX_EQ(child->drawTransform(), duplicateChildNonOwn er->drawTransform());
4412 EXPECT_TRANSFORMATION_MATRIX_EQ(child->screenSpaceTransform(), duplicateChil dNonOwner->screenSpaceTransform()); 4412 EXPECT_TRANSFORMATION_MATRIX_EQ(child->screenSpaceTransform(), duplicateChil dNonOwner->screenSpaceTransform());
4413 EXPECT_RECT_EQ(child->drawableContentRect(), duplicateChildNonOwner->drawabl eContentRect()); 4413 EXPECT_RECT_EQ(child->drawableContentRect(), duplicateChildNonOwner->drawabl eContentRect());
4414 EXPECT_EQ(child->contentBounds(), duplicateChildNonOwner->contentBounds()); 4414 EXPECT_EQ(child->contentBounds(), duplicateChildNonOwner->contentBounds());
4415 4415
4416 WebTransformationMatrix expectedRenderSurfaceDrawTransform; 4416 Transform expectedRenderSurfaceDrawTransform;
4417 expectedRenderSurfaceDrawTransform.translate(deviceScaleFactor * child->posi tion().x(), deviceScaleFactor * child->position().y()); 4417 expectedRenderSurfaceDrawTransform.PreconcatTranslate(deviceScaleFactor * ch ild->position().x(), deviceScaleFactor * child->position().y());
4418 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedRenderSurfaceDrawTransform, child->r enderSurface()->drawTransform()); 4418 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedRenderSurfaceDrawTransform, child->r enderSurface()->drawTransform());
4419 4419
4420 WebTransformationMatrix expectedSurfaceDrawTransform; 4420 Transform expectedSurfaceDrawTransform;
4421 expectedSurfaceDrawTransform.translate(deviceScaleFactor * 2, deviceScaleFac tor * 2); 4421 expectedSurfaceDrawTransform.PreconcatTranslate(deviceScaleFactor * 2, devic eScaleFactor * 2);
4422 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceDrawTransform, child->renderS urface()->drawTransform()); 4422 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceDrawTransform, child->renderS urface()->drawTransform());
4423 4423
4424 WebTransformationMatrix expectedSurfaceScreenSpaceTransform; 4424 Transform expectedSurfaceScreenSpaceTransform;
4425 expectedSurfaceScreenSpaceTransform.translate(deviceScaleFactor * 2, deviceS caleFactor * 2); 4425 expectedSurfaceScreenSpaceTransform.PreconcatTranslate(deviceScaleFactor * 2 , deviceScaleFactor * 2);
4426 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceScreenSpaceTransform, child-> renderSurface()->screenSpaceTransform()); 4426 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceScreenSpaceTransform, child-> renderSurface()->screenSpaceTransform());
4427 4427
4428 WebTransformationMatrix expectedReplicaDrawTransform; 4428 Transform expectedReplicaDrawTransform;
4429 expectedReplicaDrawTransform.setM22(-1); 4429 expectedReplicaDrawTransform.matrix().setDouble(1, 1, -1);
4430 expectedReplicaDrawTransform.setM41(6); 4430 expectedReplicaDrawTransform.matrix().setDouble(0, 3, 6);
4431 expectedReplicaDrawTransform.setM42(6); 4431 expectedReplicaDrawTransform.matrix().setDouble(1, 3, 6);
4432 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaDrawTransform, child->renderS urface()->replicaDrawTransform()); 4432 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaDrawTransform, child->renderS urface()->replicaDrawTransform());
4433 4433
4434 WebTransformationMatrix expectedReplicaScreenSpaceTransform; 4434 Transform expectedReplicaScreenSpaceTransform;
4435 expectedReplicaScreenSpaceTransform.setM22(-1); 4435 expectedReplicaScreenSpaceTransform.matrix().setDouble(1, 1, -1);
4436 expectedReplicaScreenSpaceTransform.setM41(6); 4436 expectedReplicaScreenSpaceTransform.matrix().setDouble(0, 3, 6);
4437 expectedReplicaScreenSpaceTransform.setM42(6); 4437 expectedReplicaScreenSpaceTransform.matrix().setDouble(1, 3, 6);
4438 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child-> renderSurface()->replicaScreenSpaceTransform()); 4438 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child-> renderSurface()->replicaScreenSpaceTransform());
4439 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child-> renderSurface()->replicaScreenSpaceTransform()); 4439 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child-> renderSurface()->replicaScreenSpaceTransform());
4440 } 4440 }
4441 4441
4442 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPIAccurateScal eZeroPosition) 4442 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPIAccurateScal eZeroPosition)
4443 { 4443 {
4444 MockContentLayerClient delegate; 4444 MockContentLayerClient delegate;
4445 WebTransformationMatrix identityMatrix; 4445 Transform identityMatrix;
4446 4446
4447 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 4447 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
4448 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(33, 31), true); 4448 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(33, 31), true);
4449 4449
4450 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate); 4450 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate);
4451 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 11), true); 4451 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 11), true);
4452 4452
4453 WebTransformationMatrix replicaTransform; 4453 Transform replicaTransform;
4454 replicaTransform.scaleNonUniform(1, -1); 4454 replicaTransform.PreconcatScale(1, -1);
4455 scoped_refptr<ContentLayer> replica = createDrawableContentLayer(&delegate); 4455 scoped_refptr<ContentLayer> replica = createDrawableContentLayer(&delegate);
4456 setLayerPropertiesForTesting(replica.get(), replicaTransform, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 11), true); 4456 setLayerPropertiesForTesting(replica.get(), replicaTransform, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 11), true);
4457 4457
4458 // This layer should end up in the same surface as child, with the same draw 4458 // This layer should end up in the same surface as child, with the same draw
4459 // and screen space transforms. 4459 // and screen space transforms.
4460 scoped_refptr<ContentLayer> duplicateChildNonOwner = createDrawableContentLa yer(&delegate); 4460 scoped_refptr<ContentLayer> duplicateChildNonOwner = createDrawableContentLa yer(&delegate);
4461 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i dentityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 11), true); 4461 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i dentityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 11), true);
4462 4462
4463 parent->addChild(child); 4463 parent->addChild(child);
4464 child->addChild(duplicateChildNonOwner); 4464 child->addChild(duplicateChildNonOwner);
4465 child->setReplicaLayer(replica.get()); 4465 child->setReplicaLayer(replica.get());
4466 4466
4467 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 4467 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
4468 int dummyMaxTextureSize = 512; 4468 int dummyMaxTextureSize = 512;
4469 4469
4470 const float deviceScaleFactor = 1.7f; 4470 const float deviceScaleFactor = 1.7f;
4471 parent->setContentsScale(deviceScaleFactor); 4471 parent->setContentsScale(deviceScaleFactor);
4472 child->setContentsScale(deviceScaleFactor); 4472 child->setContentsScale(deviceScaleFactor);
4473 duplicateChildNonOwner->setContentsScale(deviceScaleFactor); 4473 duplicateChildNonOwner->setContentsScale(deviceScaleFactor);
4474 replica->setContentsScale(deviceScaleFactor); 4474 replica->setContentsScale(deviceScaleFactor);
4475 4475
4476 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, 1, dummyMaxTextureSize, renderSurfaceLayerList); 4476 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, 1, dummyMaxTextureSize, renderSurfaceLayerList);
4477 4477
4478 // We should have two render surfaces. The root's render surface and child's 4478 // We should have two render surfaces. The root's render surface and child's
4479 // render surface (it needs one because it has a replica layer). 4479 // render surface (it needs one because it has a replica layer).
4480 EXPECT_EQ(2u, renderSurfaceLayerList.size()); 4480 EXPECT_EQ(2u, renderSurfaceLayerList.size());
4481 4481
4482 WebTransformationMatrix identityTransform; 4482 Transform identityTransform;
4483 4483
4484 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, parent->screenSpaceTransf orm()); 4484 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, parent->screenSpaceTransf orm());
4485 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, parent->drawTransform()); 4485 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, parent->drawTransform());
4486 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->drawTransform()); 4486 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->drawTransform());
4487 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->screenSpaceTransfo rm()); 4487 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->screenSpaceTransfo rm());
4488 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, duplicateChildNonOwner->d rawTransform()); 4488 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, duplicateChildNonOwner->d rawTransform());
4489 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, duplicateChildNonOwner->s creenSpaceTransform()); 4489 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, duplicateChildNonOwner->s creenSpaceTransform());
4490 EXPECT_RECT_EQ(child->drawableContentRect(), duplicateChildNonOwner->drawabl eContentRect()); 4490 EXPECT_RECT_EQ(child->drawableContentRect(), duplicateChildNonOwner->drawabl eContentRect());
4491 EXPECT_EQ(child->contentBounds(), duplicateChildNonOwner->contentBounds()); 4491 EXPECT_EQ(child->contentBounds(), duplicateChildNonOwner->contentBounds());
4492 4492
4493 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->renderSurface()->d rawTransform()); 4493 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->renderSurface()->d rawTransform());
4494 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->renderSurface()->d rawTransform()); 4494 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->renderSurface()->d rawTransform());
4495 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->renderSurface()->s creenSpaceTransform()); 4495 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->renderSurface()->s creenSpaceTransform());
4496 4496
4497 WebTransformationMatrix expectedReplicaDrawTransform; 4497 Transform expectedReplicaDrawTransform;
4498 expectedReplicaDrawTransform.setM22(-1); 4498 expectedReplicaDrawTransform.matrix().setDouble(1, 1, -1);
4499 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaDrawTransform, child->renderS urface()->replicaDrawTransform()); 4499 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaDrawTransform, child->renderS urface()->replicaDrawTransform());
4500 4500
4501 WebTransformationMatrix expectedReplicaScreenSpaceTransform; 4501 Transform expectedReplicaScreenSpaceTransform;
4502 expectedReplicaScreenSpaceTransform.setM22(-1); 4502 expectedReplicaScreenSpaceTransform.matrix().setDouble(1, 1, -1);
4503 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child-> renderSurface()->replicaScreenSpaceTransform()); 4503 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child-> renderSurface()->replicaScreenSpaceTransform());
4504 } 4504 }
4505 4505
4506 TEST(LayerTreeHostCommonTest, verifySubtreeSearch) 4506 TEST(LayerTreeHostCommonTest, verifySubtreeSearch)
4507 { 4507 {
4508 scoped_refptr<Layer> root = Layer::create(); 4508 scoped_refptr<Layer> root = Layer::create();
4509 scoped_refptr<Layer> child = Layer::create(); 4509 scoped_refptr<Layer> child = Layer::create();
4510 scoped_refptr<Layer> grandChild = Layer::create(); 4510 scoped_refptr<Layer> grandChild = Layer::create();
4511 scoped_refptr<Layer> maskLayer = Layer::create(); 4511 scoped_refptr<Layer> maskLayer = Layer::create();
4512 scoped_refptr<Layer> replicaLayer = Layer::create(); 4512 scoped_refptr<Layer> replicaLayer = Layer::create();
4513 4513
4514 grandChild->setReplicaLayer(replicaLayer.get()); 4514 grandChild->setReplicaLayer(replicaLayer.get());
4515 child->addChild(grandChild.get()); 4515 child->addChild(grandChild.get());
4516 child->setMaskLayer(maskLayer.get()); 4516 child->setMaskLayer(maskLayer.get());
4517 root->addChild(child.get()); 4517 root->addChild(child.get());
4518 4518
4519 int nonexistentId = -1; 4519 int nonexistentId = -1;
4520 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id ())); 4520 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id ()));
4521 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child-> id())); 4521 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child-> id()));
4522 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr andChild->id())); 4522 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr andChild->id()));
4523 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas kLayer->id())); 4523 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas kLayer->id()));
4524 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), replicaLayer->id())); 4524 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), replicaLayer->id()));
4525 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent Id)); 4525 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent Id));
4526 } 4526 }
4527 4527
4528 } // namespace 4528 } // namespace
4529 } // namespace cc 4529 } // namespace cc
OLDNEW
« cc/gl_renderer.cc ('K') | « cc/layer_tree_host_common.cc ('k') | cc/layer_tree_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698