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

Side by Side Diff: cc/layer_tree_host_common_unittest.cc

Issue 11264056: cc: Use gfx:: Geometry types for positions, bounds, and related things. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: some missed intstuff 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 "config.h" 5 #include "config.h"
6 6
7 #include "cc/layer_tree_host_common.h" 7 #include "cc/layer_tree_host_common.h"
8 8
9 #include "cc/content_layer.h" 9 #include "cc/content_layer.h"
10 #include "cc/content_layer_client.h" 10 #include "cc/content_layer_client.h"
(...skipping 11 matching lines...) Expand all
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 #include <public/WebTransformationMatrix.h> 23 #include <public/WebTransformationMatrix.h>
24 24
25 using namespace cc; 25 using namespace cc;
26 using namespace WebKitTests; 26 using namespace WebKitTests;
27 using WebKit::WebTransformationMatrix; 27 using WebKit::WebTransformationMatrix;
28 28
29 namespace { 29 namespace {
30 30
31 template<typename LayerType> 31 template<typename LayerType>
32 void setLayerPropertiesForTestingInternal(LayerType* layer, const WebTransformat ionMatrix& transform, const WebTransformationMatrix& sublayerTransform, const Fl oatPoint& anchor, const FloatPoint& position, const IntSize& bounds, bool preser ves3D) 32 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)
33 { 33 {
34 layer->setTransform(transform); 34 layer->setTransform(transform);
35 layer->setSublayerTransform(sublayerTransform); 35 layer->setSublayerTransform(sublayerTransform);
36 layer->setAnchorPoint(anchor); 36 layer->setAnchorPoint(anchor);
37 layer->setPosition(position); 37 layer->setPosition(position);
38 layer->setBounds(bounds); 38 layer->setBounds(bounds);
39 layer->setPreserves3D(preserves3D); 39 layer->setPreserves3D(preserves3D);
40 } 40 }
41 41
42 void setLayerPropertiesForTesting(Layer* layer, const WebTransformationMatrix& t ransform, const WebTransformationMatrix& sublayerTransform, const FloatPoint& an chor, const FloatPoint& position, const IntSize& bounds, bool preserves3D) 42 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)
43 { 43 {
44 setLayerPropertiesForTestingInternal<Layer>(layer, transform, sublayerTransf orm, anchor, position, bounds, preserves3D); 44 setLayerPropertiesForTestingInternal<Layer>(layer, transform, sublayerTransf orm, anchor, position, bounds, preserves3D);
45 layer->setAutomaticallyComputeRasterScale(true); 45 layer->setAutomaticallyComputeRasterScale(true);
46 } 46 }
47 47
48 void setLayerPropertiesForTesting(LayerImpl* layer, const WebTransformationMatri x& transform, const WebTransformationMatrix& sublayerTransform, const FloatPoint & anchor, const FloatPoint& position, const IntSize& bounds, bool preserves3D) 48 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)
49 { 49 {
50 setLayerPropertiesForTestingInternal<LayerImpl>(layer, transform, sublayerTr ansform, anchor, position, bounds, preserves3D); 50 setLayerPropertiesForTestingInternal<LayerImpl>(layer, transform, sublayerTr ansform, anchor, position, bounds, preserves3D);
51 layer->setContentBounds(bounds); 51 layer->setContentBounds(bounds);
52 } 52 }
53 53
54 void executeCalculateDrawTransformsAndVisibility(Layer* rootLayer, float deviceS caleFactor = 1, float pageScaleFactor = 1) 54 void executeCalculateDrawTransformsAndVisibility(Layer* rootLayer, float deviceS caleFactor = 1, float pageScaleFactor = 1)
55 { 55 {
56 WebTransformationMatrix identityMatrix; 56 WebTransformationMatrix identityMatrix;
57 std::vector<scoped_refptr<Layer> > dummyRenderSurfaceLayerList; 57 std::vector<scoped_refptr<Layer> > dummyRenderSurfaceLayerList;
58 int dummyMaxTextureSize = 512; 58 int dummyMaxTextureSize = 512;
59 IntSize deviceViewportSize = IntSize(rootLayer->bounds().width() * deviceSca leFactor, rootLayer->bounds().height() * deviceScaleFactor); 59 gfx::Size deviceViewportSize = gfx::Size(rootLayer->bounds().width() * devic eScaleFactor, rootLayer->bounds().height() * deviceScaleFactor);
60 60
61 // We are probably not testing what is intended if the rootLayer bounds are empty. 61 // We are probably not testing what is intended if the rootLayer bounds are empty.
62 DCHECK(!rootLayer->bounds().isEmpty()); 62 DCHECK(!rootLayer->bounds().IsEmpty());
63 LayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, dummyRenderSurfaceLayer List); 63 LayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, dummyRenderSurfaceLayer List);
64 } 64 }
65 65
66 void executeCalculateDrawTransformsAndVisibility(LayerImpl* rootLayer, float dev iceScaleFactor = 1, float pageScaleFactor = 1) 66 void executeCalculateDrawTransformsAndVisibility(LayerImpl* rootLayer, float dev iceScaleFactor = 1, float pageScaleFactor = 1)
67 { 67 {
68 // Note: this version skips layer sorting. 68 // Note: this version skips layer sorting.
69 69
70 WebTransformationMatrix identityMatrix; 70 WebTransformationMatrix identityMatrix;
71 std::vector<LayerImpl*> dummyRenderSurfaceLayerList; 71 std::vector<LayerImpl*> dummyRenderSurfaceLayerList;
72 int dummyMaxTextureSize = 512; 72 int dummyMaxTextureSize = 512;
73 IntSize deviceViewportSize = IntSize(rootLayer->bounds().width() * deviceSca leFactor, rootLayer->bounds().height() * deviceScaleFactor); 73 gfx::Size deviceViewportSize = gfx::Size(rootLayer->bounds().width() * devic eScaleFactor, rootLayer->bounds().height() * deviceScaleFactor);
74 74
75 // We are probably not testing what is intended if the rootLayer bounds are empty. 75 // We are probably not testing what is intended if the rootLayer bounds are empty.
76 DCHECK(!rootLayer->bounds().isEmpty()); 76 DCHECK(!rootLayer->bounds().IsEmpty());
77 LayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, pageScaleFactor, 0, dummyMaxTextureSize, dummyRenderSurfaceLa yerList); 77 LayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, pageScaleFactor, 0, dummyMaxTextureSize, dummyRenderSurfaceLa yerList);
78 } 78 }
79 79
80 WebTransformationMatrix remove3DComponentOfMatrix(const WebTransformationMatrix& mat) 80 WebTransformationMatrix remove3DComponentOfMatrix(const WebTransformationMatrix& mat)
81 { 81 {
82 WebTransformationMatrix ret = mat; 82 WebTransformationMatrix ret = mat;
83 ret.setM13(0); 83 ret.setM13(0);
84 ret.setM23(0); 84 ret.setM23(0);
85 ret.setM31(0); 85 ret.setM31(0);
86 ret.setM32(0); 86 ret.setM32(0);
87 ret.setM33(1); 87 ret.setM33(1);
88 ret.setM34(0); 88 ret.setM34(0);
89 ret.setM43(0); 89 ret.setM43(0);
90 return ret; 90 return ret;
91 } 91 }
92 92
93 scoped_ptr<LayerImpl> createTreeForFixedPositionTests() 93 scoped_ptr<LayerImpl> createTreeForFixedPositionTests()
94 { 94 {
95 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 95 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
96 scoped_ptr<LayerImpl> child = LayerImpl::create(2); 96 scoped_ptr<LayerImpl> child = LayerImpl::create(2);
97 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(3); 97 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(3);
98 scoped_ptr<LayerImpl> greatGrandChild = LayerImpl::create(4); 98 scoped_ptr<LayerImpl> greatGrandChild = LayerImpl::create(4);
99 99
100 WebTransformationMatrix IdentityMatrix; 100 WebTransformationMatrix IdentityMatrix;
101 FloatPoint anchor(0, 0); 101 gfx::PointF anchor(0, 0);
102 FloatPoint position(0, 0); 102 gfx::PointF position(0, 0);
103 IntSize bounds(100, 100); 103 gfx::Size bounds(100, 100);
104 setLayerPropertiesForTesting(root.get(), IdentityMatrix, IdentityMatrix, anc hor, position, bounds, false); 104 setLayerPropertiesForTesting(root.get(), IdentityMatrix, IdentityMatrix, anc hor, position, bounds, false);
105 setLayerPropertiesForTesting(child.get(), IdentityMatrix, IdentityMatrix, an chor, position, bounds, false); 105 setLayerPropertiesForTesting(child.get(), IdentityMatrix, IdentityMatrix, an chor, position, bounds, false);
106 setLayerPropertiesForTesting(grandChild.get(), IdentityMatrix, IdentityMatri x, anchor, position, bounds, false); 106 setLayerPropertiesForTesting(grandChild.get(), IdentityMatrix, IdentityMatri x, anchor, position, bounds, false);
107 setLayerPropertiesForTesting(greatGrandChild.get(), IdentityMatrix, Identity Matrix, anchor, position, bounds, false); 107 setLayerPropertiesForTesting(greatGrandChild.get(), IdentityMatrix, Identity Matrix, anchor, position, bounds, false);
108 108
109 grandChild->addChild(greatGrandChild.Pass()); 109 grandChild->addChild(greatGrandChild.Pass());
110 child->addChild(grandChild.Pass()); 110 child->addChild(grandChild.Pass());
111 root->addChild(child.Pass()); 111 root->addChild(child.Pass());
112 112
113 return root.Pass(); 113 return root.Pass();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // screenSpaceTransform, and the hierarchy passed on to children 149 // screenSpaceTransform, and the hierarchy passed on to children
150 // layers should also be identity transforms. 150 // layers should also be identity transforms.
151 151
152 scoped_refptr<Layer> parent = Layer::create(); 152 scoped_refptr<Layer> parent = Layer::create();
153 scoped_refptr<Layer> child = Layer::create(); 153 scoped_refptr<Layer> child = Layer::create();
154 scoped_refptr<Layer> grandChild = Layer::create(); 154 scoped_refptr<Layer> grandChild = Layer::create();
155 parent->addChild(child); 155 parent->addChild(child);
156 child->addChild(grandChild); 156 child->addChild(grandChild);
157 157
158 WebTransformationMatrix identityMatrix; 158 WebTransformationMatrix identityMatrix;
159 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 159 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
160 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(0, 0), false); 160 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(0, 0), false);
161 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(0, 0), false); 161 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(0, 0), false);
162 162
163 executeCalculateDrawTransformsAndVisibility(parent.get()); 163 executeCalculateDrawTransformsAndVisibility(parent.get());
164 164
165 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); 165 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
166 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( )); 166 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( ));
167 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ; 167 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ;
168 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form()); 168 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form());
169 } 169 }
170 170
171 TEST(LayerTreeHostCommonTest, verifyTransformsForSingleLayer) 171 TEST(LayerTreeHostCommonTest, verifyTransformsForSingleLayer)
172 { 172 {
173 WebTransformationMatrix identityMatrix; 173 WebTransformationMatrix identityMatrix;
174 scoped_refptr<Layer> layer = Layer::create(); 174 scoped_refptr<Layer> layer = Layer::create();
175 175
176 // Case 1: setting the sublayer transform should not affect this layer's dra w transform or screen-space transform. 176 // Case 1: setting the sublayer transform should not affect this layer's dra w transform or screen-space transform.
177 WebTransformationMatrix arbitraryTranslation; 177 WebTransformationMatrix arbitraryTranslation;
178 arbitraryTranslation.translate(10, 20); 178 arbitraryTranslation.translate(10, 20);
179 setLayerPropertiesForTesting(layer.get(), identityMatrix, arbitraryTranslati on, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 179 setLayerPropertiesForTesting(layer.get(), identityMatrix, arbitraryTranslati on, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
180 executeCalculateDrawTransformsAndVisibility(layer.get()); 180 executeCalculateDrawTransformsAndVisibility(layer.get());
181 WebTransformationMatrix expectedDrawTransform = identityMatrix; 181 WebTransformationMatrix expectedDrawTransform = identityMatrix;
182 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedDrawTransform, layer->drawTransform( )); 182 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedDrawTransform, layer->drawTransform( ));
183 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( )); 183 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( ));
184 184
185 // Case 2: Setting the bounds of the layer should not affect either the draw transform or the screenspace transform. 185 // Case 2: Setting the bounds of the layer should not affect either the draw transform or the screenspace transform.
186 WebTransformationMatrix translationToCenter; 186 WebTransformationMatrix translationToCenter;
187 translationToCenter.translate(5, 6); 187 translationToCenter.translate(5, 6);
188 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 12), false); 188 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 12), false);
189 executeCalculateDrawTransformsAndVisibility(layer.get()); 189 executeCalculateDrawTransformsAndVisibility(layer.get());
190 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform()); 190 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform());
191 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( )); 191 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( ));
192 192
193 // Case 3: The anchor point by itself (without a layer transform) should hav e no effect on the transforms. 193 // Case 3: The anchor point by itself (without a layer transform) should hav e no effect on the transforms.
194 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, Fl oatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 194 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, gf x::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false);
195 executeCalculateDrawTransformsAndVisibility(layer.get()); 195 executeCalculateDrawTransformsAndVisibility(layer.get());
196 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform()); 196 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform());
197 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( )); 197 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( ));
198 198
199 // Case 4: A change in actual position affects both the draw transform and s creen space transform. 199 // Case 4: A change in actual position affects both the draw transform and s creen space transform.
200 WebTransformationMatrix positionTransform; 200 WebTransformationMatrix positionTransform;
201 positionTransform.translate(0, 1.2); 201 positionTransform.translate(0, 1.2);
202 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, Fl oatPoint(0.25, 0.25), FloatPoint(0, 1.2f), IntSize(10, 12), false); 202 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, gf x::PointF(0.25, 0.25), gfx::PointF(0, 1.2f), gfx::Size(10, 12), false);
203 executeCalculateDrawTransformsAndVisibility(layer.get()); 203 executeCalculateDrawTransformsAndVisibility(layer.get());
204 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->drawTransform()); 204 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->drawTransform());
205 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->screenSpaceTransfo rm()); 205 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->screenSpaceTransfo rm());
206 206
207 // Case 5: In the correct sequence of transforms, the layer transform should pre-multiply the translationToCenter. This is easily tested by 207 // Case 5: In the correct sequence of transforms, the layer transform should pre-multiply the translationToCenter. This is easily tested by
208 // using a scale transform, because scale and translation are not co mmutative. 208 // using a scale transform, because scale and translation are not co mmutative.
209 WebTransformationMatrix layerTransform; 209 WebTransformationMatrix layerTransform;
210 layerTransform.scale3d(2, 2, 1); 210 layerTransform.scale3d(2, 2, 1);
211 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 12), false); 211 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 12), false);
212 executeCalculateDrawTransformsAndVisibility(layer.get()); 212 executeCalculateDrawTransformsAndVisibility(layer.get());
213 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->drawTransform()); 213 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->drawTransform());
214 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->screenSpaceTransform( )); 214 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->screenSpaceTransform( ));
215 215
216 // Case 6: The layer transform should occur with respect to the anchor point . 216 // Case 6: The layer transform should occur with respect to the anchor point .
217 WebTransformationMatrix translationToAnchor; 217 WebTransformationMatrix translationToAnchor;
218 translationToAnchor.translate(5, 0); 218 translationToAnchor.translate(5, 0);
219 WebTransformationMatrix expectedResult = translationToAnchor * layerTransfor m * translationToAnchor.inverse(); 219 WebTransformationMatrix expectedResult = translationToAnchor * layerTransfor m * translationToAnchor.inverse();
220 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, Fl oatPoint(0.5, 0), FloatPoint(0, 0), IntSize(10, 12), false); 220 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, gf x::PointF(0.5, 0), gfx::PointF(0, 0), gfx::Size(10, 12), false);
221 executeCalculateDrawTransformsAndVisibility(layer.get()); 221 executeCalculateDrawTransformsAndVisibility(layer.get());
222 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform()); 222 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform());
223 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform( )); 223 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform( ));
224 224
225 // Case 7: Verify that position pre-multiplies the layer transform. 225 // Case 7: Verify that position pre-multiplies the layer transform.
226 // The current implementation of calculateDrawTransforms does this i mplicitly, but it is 226 // The current implementation of calculateDrawTransforms does this i mplicitly, but it is
227 // still worth testing to detect accidental regressions. 227 // still worth testing to detect accidental regressions.
228 expectedResult = positionTransform * translationToAnchor * layerTransform * translationToAnchor.inverse(); 228 expectedResult = positionTransform * translationToAnchor * layerTransform * translationToAnchor.inverse();
229 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, Fl oatPoint(0.5, 0), FloatPoint(0, 1.2f), IntSize(10, 12), false); 229 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, gf x::PointF(0.5, 0), gfx::PointF(0, 1.2f), gfx::Size(10, 12), false);
230 executeCalculateDrawTransformsAndVisibility(layer.get()); 230 executeCalculateDrawTransformsAndVisibility(layer.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 234
235 TEST(LayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy) 235 TEST(LayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy)
236 { 236 {
237 WebTransformationMatrix identityMatrix; 237 WebTransformationMatrix identityMatrix;
238 scoped_refptr<Layer> parent = Layer::create(); 238 scoped_refptr<Layer> parent = Layer::create();
239 scoped_refptr<Layer> child = Layer::create(); 239 scoped_refptr<Layer> child = Layer::create();
240 scoped_refptr<Layer> grandChild = Layer::create(); 240 scoped_refptr<Layer> grandChild = Layer::create();
241 parent->addChild(child); 241 parent->addChild(child);
242 child->addChild(grandChild); 242 child->addChild(grandChild);
243 243
244 // Case 1: parent's anchorPoint should not affect child or grandChild. 244 // Case 1: parent's anchorPoint should not affect child or grandChild.
245 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 245 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false);
246 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 246 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
247 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false); 247 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false);
248 executeCalculateDrawTransformsAndVisibility(parent.get()); 248 executeCalculateDrawTransformsAndVisibility(parent.get());
249 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); 249 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
250 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( )); 250 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( ));
251 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ; 251 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ;
252 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form()); 252 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form());
253 253
254 // Case 2: parent's position affects child and grandChild. 254 // Case 2: parent's position affects child and grandChild.
255 WebTransformationMatrix parentPositionTransform; 255 WebTransformationMatrix parentPositionTransform;
256 parentPositionTransform.translate(0, 1.2); 256 parentPositionTransform.translate(0, 1.2);
257 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0.25, 0.25), FloatPoint(0, 1.2f), IntSize(10, 12), false); 257 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0.25, 0.25), gfx::PointF(0, 1.2f), gfx::Size(10, 12), false);
258 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 258 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
259 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false); 259 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false);
260 executeCalculateDrawTransformsAndVisibility(parent.get()); 260 executeCalculateDrawTransformsAndVisibility(parent.get());
261 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->drawTransfor m()); 261 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->drawTransfor m());
262 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->screenSpaceT ransform()); 262 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->screenSpaceT ransform());
263 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->drawTra nsform()); 263 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->drawTra nsform());
264 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->screenS paceTransform()); 264 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->screenS paceTransform());
265 265
266 // Case 3: parent's local transform affects child and grandchild 266 // Case 3: parent's local transform affects child and grandchild
267 WebTransformationMatrix parentLayerTransform; 267 WebTransformationMatrix parentLayerTransform;
268 parentLayerTransform.scale3d(2, 2, 1); 268 parentLayerTransform.scale3d(2, 2, 1);
269 WebTransformationMatrix parentTranslationToAnchor; 269 WebTransformationMatrix parentTranslationToAnchor;
270 parentTranslationToAnchor.translate(2.5, 3); 270 parentTranslationToAnchor.translate(2.5, 3);
271 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse(); 271 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse();
272 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, identityMat rix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 272 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, identityMat rix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false);
273 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 273 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
274 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false); 274 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false);
275 executeCalculateDrawTransformsAndVisibility(parent.get()); 275 executeCalculateDrawTransformsAndVisibility(parent.get());
276 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm()); 276 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm());
277 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 277 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
278 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr ansform()); 278 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr ansform());
279 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen SpaceTransform()); 279 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen SpaceTransform());
280 280
281 // Case 4: parent's sublayerMatrix affects child and grandchild 281 // Case 4: parent's sublayerMatrix affects child and grandchild
282 // scaling is used here again so that the correct sequence of transf orms is properly tested. 282 // scaling is used here again so that the correct sequence of transf orms is properly tested.
283 // Note that preserves3D is false, but the sublayer matrix should re tain its 3D properties when given to child. 283 // Note that preserves3D is false, but the sublayer matrix should re tain its 3D properties when given to child.
284 // But then, the child also does not preserve3D. When it gives its h ierarchy to the grandChild, it should be flattened to 2D. 284 // But then, the child also does not preserve3D. When it gives its h ierarchy to the grandChild, it should be flattened to 2D.
285 WebTransformationMatrix parentSublayerMatrix; 285 WebTransformationMatrix parentSublayerMatrix;
286 parentSublayerMatrix.scale3d(10, 10, 3.3); 286 parentSublayerMatrix.scale3d(10, 10, 3.3);
287 WebTransformationMatrix parentTranslationToCenter; 287 WebTransformationMatrix parentTranslationToCenter;
288 parentTranslationToCenter.translate(5, 6); 288 parentTranslationToCenter.translate(5, 6);
289 // Sublayer matrix is applied to the center of the parent layer. 289 // Sublayer matrix is applied to the center of the parent layer.
290 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse() 290 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
291 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse(); 291 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse();
292 WebTransformationMatrix flattenedCompositeTransform = remove3DComponentOfMat rix(parentCompositeTransform); 292 WebTransformationMatrix flattenedCompositeTransform = remove3DComponentOfMat rix(parentCompositeTransform);
293 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 293 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false) ;
294 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 294 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
295 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false); 295 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false);
296 executeCalculateDrawTransformsAndVisibility(parent.get()); 296 executeCalculateDrawTransformsAndVisibility(parent.get());
297 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm()); 297 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm());
298 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 298 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
299 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->dra wTransform()); 299 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->dra wTransform());
300 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->scr eenSpaceTransform()); 300 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->scr eenSpaceTransform());
301 301
302 // Case 5: same as Case 4, except that child does preserve 3D, so the grandC hild should receive the non-flattened composite transform. 302 // Case 5: same as Case 4, except that child does preserve 3D, so the grandC hild should receive the non-flattened composite transform.
303 // 303 //
304 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 304 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false) ;
305 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), true); 305 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), true);
306 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false); 306 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false);
307 executeCalculateDrawTransformsAndVisibility(parent.get()); 307 executeCalculateDrawTransformsAndVisibility(parent.get());
308 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm()); 308 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm());
309 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 309 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
310 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr ansform()); 310 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr ansform());
311 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen SpaceTransform()); 311 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen SpaceTransform());
312 } 312 }
313 313
314 TEST(LayerTreeHostCommonTest, verifyTransformsForSingleRenderSurface) 314 TEST(LayerTreeHostCommonTest, verifyTransformsForSingleRenderSurface)
315 { 315 {
316 scoped_refptr<Layer> parent = Layer::create(); 316 scoped_refptr<Layer> parent = Layer::create();
317 scoped_refptr<Layer> child = Layer::create(); 317 scoped_refptr<Layer> child = Layer::create();
318 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent()); 318 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent());
319 parent->addChild(child); 319 parent->addChild(child);
320 child->addChild(grandChild); 320 child->addChild(grandChild);
321 321
322 // Child is set up so that a new render surface should be created. 322 // Child is set up so that a new render surface should be created.
323 child->setOpacity(0.5); 323 child->setOpacity(0.5);
324 324
325 WebTransformationMatrix identityMatrix; 325 WebTransformationMatrix identityMatrix;
326 WebTransformationMatrix parentLayerTransform; 326 WebTransformationMatrix parentLayerTransform;
327 parentLayerTransform.scale3d(1, 0.9, 1); 327 parentLayerTransform.scale3d(1, 0.9, 1);
328 WebTransformationMatrix parentTranslationToAnchor; 328 WebTransformationMatrix parentTranslationToAnchor;
329 parentTranslationToAnchor.translate(25, 30); 329 parentTranslationToAnchor.translate(25, 30);
330 WebTransformationMatrix parentSublayerMatrix; 330 WebTransformationMatrix parentSublayerMatrix;
331 parentSublayerMatrix.scale3d(0.9, 1, 3.3); 331 parentSublayerMatrix.scale3d(0.9, 1, 3.3);
332 WebTransformationMatrix parentTranslationToCenter; 332 WebTransformationMatrix parentTranslationToCenter;
333 parentTranslationToCenter.translate(50, 60); 333 parentTranslationToCenter.translate(50, 60);
334 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse() 334 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
335 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse(); 335 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse();
336 FloatPoint parentCompositeScale = MathUtil::computeTransform2dScaleComponent s(parentCompositeTransform); 336 gfx::PointF parentCompositeScale = MathUtil::computeTransform2dScaleComponen ts(parentCompositeTransform);
337 WebTransformationMatrix surfaceSublayerTransform; 337 WebTransformationMatrix surfaceSublayerTransform;
338 surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCom positeScale.y()); 338 surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCom positeScale.y());
339 WebTransformationMatrix surfaceSublayerCompositeTransform = parentCompositeT ransform * surfaceSublayerTransform.inverse(); 339 WebTransformationMatrix surfaceSublayerCompositeTransform = parentCompositeT ransform * surfaceSublayerTransform.inverse();
340 340
341 // Child's render surface should not exist yet. 341 // Child's render surface should not exist yet.
342 ASSERT_FALSE(child->renderSurface()); 342 ASSERT_FALSE(child->renderSurface());
343 343
344 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(100, 120), false); 344 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), fals e);
345 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 345 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
346 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(8, 10), false); 346 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(8, 10), false);
347 executeCalculateDrawTransformsAndVisibility(parent.get()); 347 executeCalculateDrawTransformsAndVisibility(parent.get());
348 348
349 // Render surface should have been created now. 349 // Render surface should have been created now.
350 ASSERT_TRUE(child->renderSurface()); 350 ASSERT_TRUE(child->renderSurface());
351 ASSERT_EQ(child, child->renderTarget()); 351 ASSERT_EQ(child, child->renderTarget());
352 352
353 // The child layer's draw transform should refer to its new render surface. 353 // The child layer's draw transform should refer to its new render surface.
354 // The screen-space transform, however, should still refer to the root. 354 // The screen-space transform, however, should still refer to the root.
355 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerTransform, child->drawTransfo rm()); 355 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerTransform, child->drawTransfo rm());
356 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 356 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
(...skipping 27 matching lines...) Expand all
384 WebTransformationMatrix parentSublayerMatrix; 384 WebTransformationMatrix parentSublayerMatrix;
385 parentSublayerMatrix.scale3d(10, 10, 3.3); 385 parentSublayerMatrix.scale3d(10, 10, 3.3);
386 WebTransformationMatrix parentTranslationToCenter; 386 WebTransformationMatrix parentTranslationToCenter;
387 parentTranslationToCenter.translate(5, 6); 387 parentTranslationToCenter.translate(5, 6);
388 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse() 388 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
389 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse(); 389 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse();
390 WebTransformationMatrix childTranslationToCenter; 390 WebTransformationMatrix childTranslationToCenter;
391 childTranslationToCenter.translate(8, 9); 391 childTranslationToCenter.translate(8, 9);
392 WebTransformationMatrix replicaLayerTransform; 392 WebTransformationMatrix replicaLayerTransform;
393 replicaLayerTransform.scale3d(3, 3, 1); 393 replicaLayerTransform.scale3d(3, 3, 1);
394 FloatPoint parentCompositeScale = MathUtil::computeTransform2dScaleComponent s(parentCompositeTransform); 394 gfx::PointF parentCompositeScale = MathUtil::computeTransform2dScaleComponen ts(parentCompositeTransform);
395 WebTransformationMatrix surfaceSublayerTransform; 395 WebTransformationMatrix surfaceSublayerTransform;
396 surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCom positeScale.y()); 396 surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCom positeScale.y());
397 WebTransformationMatrix replicaCompositeTransform = parentCompositeTransform * replicaLayerTransform * surfaceSublayerTransform.inverse(); 397 WebTransformationMatrix replicaCompositeTransform = parentCompositeTransform * replicaLayerTransform * surfaceSublayerTransform.inverse();
398 398
399 // Child's render surface should not exist yet. 399 // Child's render surface should not exist yet.
400 ASSERT_FALSE(child->renderSurface()); 400 ASSERT_FALSE(child->renderSurface());
401 401
402 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 402 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false) ;
403 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 403 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
404 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(-0.5, -0.5), IntSize(1, 1), false); 404 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(-0.5, -0.5), gfx::Size(1, 1), false);
405 setLayerPropertiesForTesting(childReplica.get(), replicaLayerTransform, iden tityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(0, 0), false); 405 setLayerPropertiesForTesting(childReplica.get(), replicaLayerTransform, iden tityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(0, 0), false);
406 executeCalculateDrawTransformsAndVisibility(parent.get()); 406 executeCalculateDrawTransformsAndVisibility(parent.get());
407 407
408 // Render surface should have been created now. 408 // Render surface should have been created now.
409 ASSERT_TRUE(child->renderSurface()); 409 ASSERT_TRUE(child->renderSurface());
410 ASSERT_EQ(child, child->renderTarget()); 410 ASSERT_EQ(child, child->renderTarget());
411 411
412 EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarg et()->renderSurface()->replicaDrawTransform()); 412 EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarg et()->renderSurface()->replicaDrawTransform());
413 EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarg et()->renderSurface()->replicaScreenSpaceTransform()); 413 EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarg et()->renderSurface()->replicaScreenSpaceTransform());
414 } 414 }
415 415
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 WebTransformationMatrix sublayerTransform; 464 WebTransformationMatrix sublayerTransform;
465 sublayerTransform.scale3d(10, 1, 1); 465 sublayerTransform.scale3d(10, 1, 1);
466 WebTransformationMatrix replicaLayerTransform; 466 WebTransformationMatrix replicaLayerTransform;
467 replicaLayerTransform.scale3d(-2, 5, 1); 467 replicaLayerTransform.scale3d(-2, 5, 1);
468 468
469 WebTransformationMatrix A = translationToAnchor * layerTransform * translati onToAnchor.inverse(); 469 WebTransformationMatrix A = translationToAnchor * layerTransform * translati onToAnchor.inverse();
470 WebTransformationMatrix B = translationToCenter * sublayerTransform * transl ationToCenter.inverse(); 470 WebTransformationMatrix B = translationToCenter * sublayerTransform * transl ationToCenter.inverse();
471 WebTransformationMatrix R = A * translationToAnchor * replicaLayerTransform * translationToAnchor.inverse(); 471 WebTransformationMatrix R = A * translationToAnchor * replicaLayerTransform * translationToAnchor.inverse();
472 WebTransformationMatrix identityMatrix; 472 WebTransformationMatrix identityMatrix;
473 473
474 FloatPoint surface1ParentTransformScale = MathUtil::computeTransform2dScaleC omponents(A * B); 474 gfx::PointF surface1ParentTransformScale = MathUtil::computeTransform2dScale Components(A * B);
475 WebTransformationMatrix surface1SublayerTransform; 475 WebTransformationMatrix surface1SublayerTransform;
476 surface1SublayerTransform.scaleNonUniform(surface1ParentTransformScale.x(), surface1ParentTransformScale.y()); 476 surface1SublayerTransform.scaleNonUniform(surface1ParentTransformScale.x(), surface1ParentTransformScale.y());
477 477
478 // SS1 = transform given to the subtree of renderSurface1 478 // SS1 = transform given to the subtree of renderSurface1
479 WebTransformationMatrix SS1 = surface1SublayerTransform; 479 WebTransformationMatrix SS1 = surface1SublayerTransform;
480 // S1 = transform to move from renderSurface1 pixels to the layer space of t he owning layer 480 // S1 = transform to move from renderSurface1 pixels to the layer space of t he owning layer
481 WebTransformationMatrix S1 = surface1SublayerTransform.inverse(); 481 WebTransformationMatrix S1 = surface1SublayerTransform.inverse();
482 482
483 FloatPoint surface2ParentTransformScale = MathUtil::computeTransform2dScaleC omponents(SS1 * A * B); 483 gfx::PointF surface2ParentTransformScale = MathUtil::computeTransform2dScale Components(SS1 * A * B);
484 WebTransformationMatrix surface2SublayerTransform; 484 WebTransformationMatrix surface2SublayerTransform;
485 surface2SublayerTransform.scaleNonUniform(surface2ParentTransformScale.x(), surface2ParentTransformScale.y()); 485 surface2SublayerTransform.scaleNonUniform(surface2ParentTransformScale.x(), surface2ParentTransformScale.y());
486 486
487 // SS2 = transform given to the subtree of renderSurface2 487 // SS2 = transform given to the subtree of renderSurface2
488 WebTransformationMatrix SS2 = surface2SublayerTransform; 488 WebTransformationMatrix SS2 = surface2SublayerTransform;
489 // S2 = transform to move from renderSurface2 pixels to the layer space of t he owning layer 489 // S2 = transform to move from renderSurface2 pixels to the layer space of t he owning layer
490 WebTransformationMatrix S2 = surface2SublayerTransform.inverse(); 490 WebTransformationMatrix S2 = surface2SublayerTransform.inverse();
491 491
492 setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform , FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 492 setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform , gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
493 setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerT ransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 493 setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerT ransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
494 setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerT ransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 494 setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerT ransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
495 setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTran sform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 495 setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTran sform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
496 setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTrans form, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 496 setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTrans form, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
497 setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTrans form, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 497 setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTrans form, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
498 setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublaye rTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 498 setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublaye rTransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
499 setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayer Transform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 499 setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayer Transform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
500 setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayer Transform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 500 setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayer Transform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
501 setLayerPropertiesForTesting(replicaOfRS1.get(), replicaLayerTransform, subl ayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(), false); 501 setLayerPropertiesForTesting(replicaOfRS1.get(), replicaLayerTransform, subl ayerTransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(), false);
502 setLayerPropertiesForTesting(replicaOfRS2.get(), replicaLayerTransform, subl ayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(), false); 502 setLayerPropertiesForTesting(replicaOfRS2.get(), replicaLayerTransform, subl ayerTransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(), false);
503 503
504 executeCalculateDrawTransformsAndVisibility(parent.get()); 504 executeCalculateDrawTransformsAndVisibility(parent.get());
505 505
506 // Only layers that are associated with render surfaces should have an actua l renderSurface() value. 506 // Only layers that are associated with render surfaces should have an actua l renderSurface() value.
507 // 507 //
508 ASSERT_TRUE(parent->renderSurface()); 508 ASSERT_TRUE(parent->renderSurface());
509 ASSERT_FALSE(childOfRoot->renderSurface()); 509 ASSERT_FALSE(childOfRoot->renderSurface());
510 ASSERT_FALSE(grandChildOfRoot->renderSurface()); 510 ASSERT_FALSE(grandChildOfRoot->renderSurface());
511 511
512 ASSERT_TRUE(renderSurface1->renderSurface()); 512 ASSERT_TRUE(renderSurface1->renderSurface());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 // projection. 598 // projection.
599 599
600 scoped_refptr<Layer> root = Layer::create(); 600 scoped_refptr<Layer> root = Layer::create();
601 scoped_refptr<Layer> child = Layer::create(); 601 scoped_refptr<Layer> child = Layer::create();
602 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent()); 602 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent());
603 603
604 WebTransformationMatrix rotationAboutYAxis; 604 WebTransformationMatrix rotationAboutYAxis;
605 rotationAboutYAxis.rotate3d(0, 30, 0); 605 rotationAboutYAxis.rotate3d(0, 30, 0);
606 606
607 const WebTransformationMatrix identityMatrix; 607 const WebTransformationMatrix identityMatrix;
608 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint::zero(), FloatPoint::zero(), IntSize(100, 100), false); 608 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(), gfx::PointF(), gfx::Size(100, 100), false);
609 setLayerPropertiesForTesting(child.get(), rotationAboutYAxis, identityMatrix , FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 609 setLayerPropertiesForTesting(child.get(), rotationAboutYAxis, identityMatrix , gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
610 setLayerPropertiesForTesting(grandChild.get(), rotationAboutYAxis, identityM atrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 610 setLayerPropertiesForTesting(grandChild.get(), rotationAboutYAxis, identityM atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
611 611
612 root->addChild(child); 612 root->addChild(child);
613 child->addChild(grandChild); 613 child->addChild(grandChild);
614 child->setForceRenderSurface(true); 614 child->setForceRenderSurface(true);
615 615
616 // No layers in this test should preserve 3d. 616 // No layers in this test should preserve 3d.
617 ASSERT_FALSE(root->preserves3D()); 617 ASSERT_FALSE(root->preserves3D());
618 ASSERT_FALSE(child->preserves3D()); 618 ASSERT_FALSE(child->preserves3D());
619 ASSERT_FALSE(grandChild->preserves3D()); 619 ASSERT_FALSE(grandChild->preserves3D());
620 620
(...skipping 21 matching lines...) Expand all
642 // 642 //
643 // Normally this isn't a problem, because the layer wouldn't be drawn anyway , but if that layer becomes a renderSurface, then 643 // Normally this isn't a problem, because the layer wouldn't be drawn anyway , but if that layer becomes a renderSurface, then
644 // its drawTransform is implicitly inherited by the rest of the subtree, whi ch then is positioned incorrectly as a result. 644 // its drawTransform is implicitly inherited by the rest of the subtree, whi ch then is positioned incorrectly as a result.
645 645
646 scoped_refptr<Layer> root = Layer::create(); 646 scoped_refptr<Layer> root = Layer::create();
647 scoped_refptr<Layer> child = Layer::create(); 647 scoped_refptr<Layer> child = Layer::create();
648 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent()); 648 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent());
649 649
650 // The child height is zero, but has non-zero width that should be accounted for while computing drawTransforms. 650 // The child height is zero, but has non-zero width that should be accounted for while computing drawTransforms.
651 const WebTransformationMatrix identityMatrix; 651 const WebTransformationMatrix identityMatrix;
652 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint::zero(), FloatPoint::zero(), IntSize(100, 100), false); 652 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(), gfx::PointF(), gfx::Size(100, 100), false);
653 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint::zero(), FloatPoint::zero(), IntSize(10, 0), false); 653 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(), gfx::PointF(), gfx::Size(10, 0), false);
654 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 654 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
655 655
656 root->addChild(child); 656 root->addChild(child);
657 child->addChild(grandChild); 657 child->addChild(grandChild);
658 child->setForceRenderSurface(true); 658 child->setForceRenderSurface(true);
659 659
660 executeCalculateDrawTransformsAndVisibility(root.get()); 660 executeCalculateDrawTransformsAndVisibility(root.get());
661 661
662 ASSERT_TRUE(child->renderSurface()); 662 ASSERT_TRUE(child->renderSurface());
663 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->renderSurface()->draw Transform()); // This is the real test, the rest are sanity checks. 663 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->renderSurface()->draw Transform()); // This is the real test, the rest are sanity checks.
664 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); 664 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
665 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ; 665 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ;
666 } 666 }
667 667
668 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceListForRenderSurfaceWithClipped Layer) 668 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceListForRenderSurfaceWithClipped Layer)
669 { 669 {
670 scoped_refptr<Layer> parent = Layer::create(); 670 scoped_refptr<Layer> parent = Layer::create();
671 scoped_refptr<Layer> renderSurface1 = Layer::create(); 671 scoped_refptr<Layer> renderSurface1 = Layer::create();
672 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent()); 672 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent());
673 673
674 const WebTransformationMatrix identityMatrix; 674 const WebTransformationMatrix identityMatrix;
675 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 675 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
676 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 676 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
677 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint::zero(), FloatPoint(30, 30), IntSize(10, 10), false); 677 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(), gfx::PointF(30, 30), gfx::Size(10, 10), false);
678 678
679 parent->addChild(renderSurface1); 679 parent->addChild(renderSurface1);
680 parent->setMasksToBounds(true); 680 parent->setMasksToBounds(true);
681 renderSurface1->addChild(child); 681 renderSurface1->addChild(child);
682 renderSurface1->setForceRenderSurface(true); 682 renderSurface1->setForceRenderSurface(true);
683 683
684 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 684 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
685 int dummyMaxTextureSize = 512; 685 int dummyMaxTextureSize = 512;
686 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 686 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
687 687
688 // The child layer's content is entirely outside the parent's clip rect, so the intermediate 688 // The child layer's content is entirely outside the parent's clip rect, so the intermediate
689 // render surface should not be listed here, even if it was forced to be cre ated. Render surfaces without children or visible 689 // render surface should not be listed here, even if it was forced to be cre ated. Render surfaces without children or visible
690 // content are unexpected at draw time (e.g. we might try to create a conten t texture of size 0). 690 // content are unexpected at draw time (e.g. we might try to create a conten t texture of size 0).
691 ASSERT_TRUE(parent->renderSurface()); 691 ASSERT_TRUE(parent->renderSurface());
692 ASSERT_FALSE(renderSurface1->renderSurface()); 692 ASSERT_FALSE(renderSurface1->renderSurface());
693 EXPECT_EQ(1U, renderSurfaceLayerList.size()); 693 EXPECT_EQ(1U, renderSurfaceLayerList.size());
694 } 694 }
695 695
696 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceListForTransparentChild) 696 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceListForTransparentChild)
697 { 697 {
698 scoped_refptr<Layer> parent = Layer::create(); 698 scoped_refptr<Layer> parent = Layer::create();
699 scoped_refptr<Layer> renderSurface1 = Layer::create(); 699 scoped_refptr<Layer> renderSurface1 = Layer::create();
700 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent()); 700 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent());
701 701
702 const WebTransformationMatrix identityMatrix; 702 const WebTransformationMatrix identityMatrix;
703 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 703 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
704 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 704 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
705 705
706 parent->addChild(renderSurface1); 706 parent->addChild(renderSurface1);
707 renderSurface1->addChild(child); 707 renderSurface1->addChild(child);
708 renderSurface1->setForceRenderSurface(true); 708 renderSurface1->setForceRenderSurface(true);
709 renderSurface1->setOpacity(0); 709 renderSurface1->setOpacity(0);
710 710
711 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 711 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
712 int dummyMaxTextureSize = 512; 712 int dummyMaxTextureSize = 512;
713 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 713 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
714 714
715 // Since the layer is transparent, renderSurface1->renderSurface() should no t have gotten added anywhere. 715 // Since the layer is transparent, renderSurface1->renderSurface() should no t have gotten added anywhere.
716 // Also, the drawable content rect should not have been extended by the chil dren. 716 // Also, the drawable content rect should not have been extended by the chil dren.
717 ASSERT_TRUE(parent->renderSurface()); 717 ASSERT_TRUE(parent->renderSurface());
718 EXPECT_EQ(0U, parent->renderSurface()->layerList().size()); 718 EXPECT_EQ(0U, parent->renderSurface()->layerList().size());
719 EXPECT_EQ(1U, renderSurfaceLayerList.size()); 719 EXPECT_EQ(1U, renderSurfaceLayerList.size());
720 EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id()); 720 EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
721 EXPECT_EQ(IntRect(), parent->drawableContentRect()); 721 EXPECT_EQ(gfx::Rect(), parent->drawableContentRect());
722 } 722 }
723 723
724 TEST(LayerTreeHostCommonTest, verifyForceRenderSurface) 724 TEST(LayerTreeHostCommonTest, verifyForceRenderSurface)
725 { 725 {
726 scoped_refptr<Layer> parent = Layer::create(); 726 scoped_refptr<Layer> parent = Layer::create();
727 scoped_refptr<Layer> renderSurface1 = Layer::create(); 727 scoped_refptr<Layer> renderSurface1 = Layer::create();
728 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent()); 728 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent());
729 renderSurface1->setForceRenderSurface(true); 729 renderSurface1->setForceRenderSurface(true);
730 730
731 const WebTransformationMatrix identityMatrix; 731 const WebTransformationMatrix identityMatrix;
732 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 732 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
733 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 733 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
734 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 734 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
735 735
736 parent->addChild(renderSurface1); 736 parent->addChild(renderSurface1);
737 renderSurface1->addChild(child); 737 renderSurface1->addChild(child);
738 738
739 // Sanity check before the actual test 739 // Sanity check before the actual test
740 EXPECT_FALSE(parent->renderSurface()); 740 EXPECT_FALSE(parent->renderSurface());
741 EXPECT_FALSE(renderSurface1->renderSurface()); 741 EXPECT_FALSE(renderSurface1->renderSurface());
742 742
743 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 743 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
744 int dummyMaxTextureSize = 512; 744 int dummyMaxTextureSize = 512;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 // This test checks for correct scroll compensation when the fixed-position container 846 // This test checks for correct scroll compensation when the fixed-position container
847 // is NOT the direct parent of the fixed-position layer. 847 // is NOT the direct parent of the fixed-position layer.
848 DebugScopedSetImplThread scopedImplThread; 848 DebugScopedSetImplThread scopedImplThread;
849 849
850 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 850 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
851 LayerImpl* child = root->children()[0]; 851 LayerImpl* child = root->children()[0];
852 LayerImpl* grandChild = child->children()[0]; 852 LayerImpl* grandChild = child->children()[0];
853 LayerImpl* greatGrandChild = grandChild->children()[0]; 853 LayerImpl* greatGrandChild = grandChild->children()[0];
854 854
855 child->setIsContainerForFixedPositionLayers(true); 855 child->setIsContainerForFixedPositionLayers(true);
856 grandChild->setPosition(FloatPoint(8, 6)); 856 grandChild->setPosition(gfx::PointF(8, 6));
857 greatGrandChild->setFixedToContainerLayer(true); 857 greatGrandChild->setFixedToContainerLayer(true);
858 858
859 // Case 1: scrollDelta of 0, 0 859 // Case 1: scrollDelta of 0, 0
860 child->setScrollDelta(IntSize(0, 0)); 860 child->setScrollDelta(IntSize(0, 0));
861 executeCalculateDrawTransformsAndVisibility(root.get()); 861 executeCalculateDrawTransformsAndVisibility(root.get());
862 862
863 WebTransformationMatrix expectedChildTransform; 863 WebTransformationMatrix expectedChildTransform;
864 WebTransformationMatrix expectedGrandChildTransform; 864 WebTransformationMatrix expectedGrandChildTransform;
865 expectedGrandChildTransform.translate(8, 6); 865 expectedGrandChildTransform.translate(8, 6);
866 866
(...skipping 27 matching lines...) Expand all
894 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 894 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
895 LayerImpl* child = root->children()[0]; 895 LayerImpl* child = root->children()[0];
896 LayerImpl* grandChild = child->children()[0]; 896 LayerImpl* grandChild = child->children()[0];
897 LayerImpl* greatGrandChild = grandChild->children()[0]; 897 LayerImpl* greatGrandChild = grandChild->children()[0];
898 898
899 WebTransformationMatrix rotationAboutZ; 899 WebTransformationMatrix rotationAboutZ;
900 rotationAboutZ.rotate3d(0, 0, 90); 900 rotationAboutZ.rotate3d(0, 0, 90);
901 901
902 child->setIsContainerForFixedPositionLayers(true); 902 child->setIsContainerForFixedPositionLayers(true);
903 child->setTransform(rotationAboutZ); 903 child->setTransform(rotationAboutZ);
904 grandChild->setPosition(FloatPoint(8, 6)); 904 grandChild->setPosition(gfx::PointF(8, 6));
905 grandChild->setTransform(rotationAboutZ); 905 grandChild->setTransform(rotationAboutZ);
906 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget. 906 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget.
907 907
908 // Case 1: scrollDelta of 0, 0 908 // Case 1: scrollDelta of 0, 0
909 child->setScrollDelta(IntSize(0, 0)); 909 child->setScrollDelta(IntSize(0, 0));
910 executeCalculateDrawTransformsAndVisibility(root.get()); 910 executeCalculateDrawTransformsAndVisibility(root.get());
911 911
912 WebTransformationMatrix expectedChildTransform; 912 WebTransformationMatrix expectedChildTransform;
913 expectedChildTransform.multiply(rotationAboutZ); 913 expectedChildTransform.multiply(rotationAboutZ);
914 914
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 956 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
957 LayerImpl* child = root->children()[0]; 957 LayerImpl* child = root->children()[0];
958 LayerImpl* grandChild = child->children()[0]; 958 LayerImpl* grandChild = child->children()[0];
959 LayerImpl* greatGrandChild = grandChild->children()[0]; 959 LayerImpl* greatGrandChild = grandChild->children()[0];
960 960
961 WebTransformationMatrix rotationAboutZ; 961 WebTransformationMatrix rotationAboutZ;
962 rotationAboutZ.rotate3d(0, 0, 90); 962 rotationAboutZ.rotate3d(0, 0, 90);
963 963
964 child->setIsContainerForFixedPositionLayers(true); 964 child->setIsContainerForFixedPositionLayers(true);
965 child->setTransform(rotationAboutZ); 965 child->setTransform(rotationAboutZ);
966 grandChild->setPosition(FloatPoint(8, 6)); 966 grandChild->setPosition(gfx::PointF(8, 6));
967 grandChild->setTransform(rotationAboutZ); 967 grandChild->setTransform(rotationAboutZ);
968 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget. 968 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget.
969 969
970 // Case 1: scrollDelta of 0, 0 970 // Case 1: scrollDelta of 0, 0
971 child->setScrollDelta(IntSize(0, 0)); 971 child->setScrollDelta(IntSize(0, 0));
972 executeCalculateDrawTransformsAndVisibility(root.get()); 972 executeCalculateDrawTransformsAndVisibility(root.get());
973 973
974 WebTransformationMatrix expectedChildTransform; 974 WebTransformationMatrix expectedChildTransform;
975 expectedChildTransform.multiply(rotationAboutZ); 975 expectedChildTransform.multiply(rotationAboutZ);
976 976
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 // case, the surface drawTransforms also have to be accounted for when check ing the 1014 // case, the surface drawTransforms also have to be accounted for when check ing the
1015 // scrollDelta. 1015 // scrollDelta.
1016 DebugScopedSetImplThread scopedImplThread; 1016 DebugScopedSetImplThread scopedImplThread;
1017 1017
1018 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 1018 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
1019 LayerImpl* child = root->children()[0]; 1019 LayerImpl* child = root->children()[0];
1020 LayerImpl* grandChild = child->children()[0]; 1020 LayerImpl* grandChild = child->children()[0];
1021 LayerImpl* greatGrandChild = grandChild->children()[0]; 1021 LayerImpl* greatGrandChild = grandChild->children()[0];
1022 1022
1023 child->setIsContainerForFixedPositionLayers(true); 1023 child->setIsContainerForFixedPositionLayers(true);
1024 grandChild->setPosition(FloatPoint(8, 6)); 1024 grandChild->setPosition(gfx::PointF(8, 6));
1025 grandChild->setForceRenderSurface(true); 1025 grandChild->setForceRenderSurface(true);
1026 greatGrandChild->setFixedToContainerLayer(true); 1026 greatGrandChild->setFixedToContainerLayer(true);
1027 greatGrandChild->setDrawsContent(true); 1027 greatGrandChild->setDrawsContent(true);
1028 1028
1029 WebTransformationMatrix rotationAboutZ; 1029 WebTransformationMatrix rotationAboutZ;
1030 rotationAboutZ.rotate3d(0, 0, 90); 1030 rotationAboutZ.rotate3d(0, 0, 90);
1031 grandChild->setTransform(rotationAboutZ); 1031 grandChild->setTransform(rotationAboutZ);
1032 1032
1033 // Case 1: scrollDelta of 0, 0 1033 // Case 1: scrollDelta of 0, 0
1034 child->setScrollDelta(IntSize(0, 0)); 1034 child->setScrollDelta(IntSize(0, 0));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 1090
1091 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 1091 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
1092 LayerImpl* child = root->children()[0]; 1092 LayerImpl* child = root->children()[0];
1093 LayerImpl* grandChild = child->children()[0]; 1093 LayerImpl* grandChild = child->children()[0];
1094 LayerImpl* greatGrandChild = grandChild->children()[0]; 1094 LayerImpl* greatGrandChild = grandChild->children()[0];
1095 1095
1096 // Add one more layer to the test tree for this scenario. 1096 // Add one more layer to the test tree for this scenario.
1097 { 1097 {
1098 WebTransformationMatrix identity; 1098 WebTransformationMatrix identity;
1099 scoped_ptr<LayerImpl> fixedPositionChild = LayerImpl::create(5); 1099 scoped_ptr<LayerImpl> fixedPositionChild = LayerImpl::create(5);
1100 setLayerPropertiesForTesting(fixedPositionChild.get(), identity, identit y, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 1100 setLayerPropertiesForTesting(fixedPositionChild.get(), identity, identit y, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
1101 greatGrandChild->addChild(fixedPositionChild.Pass()); 1101 greatGrandChild->addChild(fixedPositionChild.Pass());
1102 } 1102 }
1103 LayerImpl* fixedPositionChild = greatGrandChild->children()[0]; 1103 LayerImpl* fixedPositionChild = greatGrandChild->children()[0];
1104 1104
1105 // Actually set up the scenario here. 1105 // Actually set up the scenario here.
1106 child->setIsContainerForFixedPositionLayers(true); 1106 child->setIsContainerForFixedPositionLayers(true);
1107 grandChild->setPosition(FloatPoint(8, 6)); 1107 grandChild->setPosition(gfx::PointF(8, 6));
1108 grandChild->setForceRenderSurface(true); 1108 grandChild->setForceRenderSurface(true);
1109 greatGrandChild->setPosition(FloatPoint(40, 60)); 1109 greatGrandChild->setPosition(gfx::PointF(40, 60));
1110 greatGrandChild->setForceRenderSurface(true); 1110 greatGrandChild->setForceRenderSurface(true);
1111 fixedPositionChild->setFixedToContainerLayer(true); 1111 fixedPositionChild->setFixedToContainerLayer(true);
1112 fixedPositionChild->setDrawsContent(true); 1112 fixedPositionChild->setDrawsContent(true);
1113 1113
1114 // The additional rotations, which are non-commutative with translations, he lp to 1114 // The additional rotations, which are non-commutative with translations, he lp to
1115 // verify that we have correct order-of-operations in the final scroll compe nsation. 1115 // verify that we have correct order-of-operations in the final scroll compe nsation.
1116 // Note that rotating about the center of the layer ensures we do not accide ntally 1116 // Note that rotating about the center of the layer ensures we do not accide ntally
1117 // clip away layers that we want to test. 1117 // clip away layers that we want to test.
1118 WebTransformationMatrix rotationAboutZ; 1118 WebTransformationMatrix rotationAboutZ;
1119 rotationAboutZ.translate(50, 50); 1119 rotationAboutZ.translate(50, 50);
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 scoped_refptr<LayerWithForcedDrawsContent> leafNode2 = make_scoped_refptr(ne w LayerWithForcedDrawsContent()); 1344 scoped_refptr<LayerWithForcedDrawsContent> leafNode2 = make_scoped_refptr(ne w LayerWithForcedDrawsContent());
1345 parent->addChild(child); 1345 parent->addChild(child);
1346 child->addChild(grandChild); 1346 child->addChild(grandChild);
1347 grandChild->addChild(greatGrandChild); 1347 grandChild->addChild(greatGrandChild);
1348 1348
1349 // leafNode1 ensures that parent and child are kept on the renderSurfaceLaye rList, 1349 // leafNode1 ensures that parent and child are kept on the renderSurfaceLaye rList,
1350 // even though grandChild and greatGrandChild should be clipped. 1350 // even though grandChild and greatGrandChild should be clipped.
1351 child->addChild(leafNode1); 1351 child->addChild(leafNode1);
1352 greatGrandChild->addChild(leafNode2); 1352 greatGrandChild->addChild(leafNode2);
1353 1353
1354 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false); 1354 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(500, 500), false);
1355 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false); 1355 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(20, 20), false);
1356 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(45, 45), IntSize(10, 10), false); 1356 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(45, 45), gfx::Size(10, 10), false);
1357 setLayerPropertiesForTesting(greatGrandChild.get(), identityMatrix, identity Matrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false); 1357 setLayerPropertiesForTesting(greatGrandChild.get(), identityMatrix, identity Matrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
1358 setLayerPropertiesForTesting(leafNode1.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false); 1358 setLayerPropertiesForTesting(leafNode1.get(), identityMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(500, 500), false);
1359 setLayerPropertiesForTesting(leafNode2.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false); 1359 setLayerPropertiesForTesting(leafNode2.get(), identityMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(20, 20), false);
1360 1360
1361 child->setMasksToBounds(true); 1361 child->setMasksToBounds(true);
1362 child->setOpacity(0.4f); 1362 child->setOpacity(0.4f);
1363 grandChild->setOpacity(0.5); 1363 grandChild->setOpacity(0.5);
1364 greatGrandChild->setOpacity(0.4f); 1364 greatGrandChild->setOpacity(0.4f);
1365 1365
1366 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 1366 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
1367 int dummyMaxTextureSize = 512; 1367 int dummyMaxTextureSize = 512;
1368 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 1368 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
1369 1369
(...skipping 22 matching lines...) Expand all
1392 1392
1393 const WebTransformationMatrix identityMatrix; 1393 const WebTransformationMatrix identityMatrix;
1394 scoped_refptr<Layer> parent = Layer::create(); 1394 scoped_refptr<Layer> parent = Layer::create();
1395 scoped_refptr<Layer> child = Layer::create(); 1395 scoped_refptr<Layer> child = Layer::create();
1396 scoped_refptr<Layer> grandChild = Layer::create(); 1396 scoped_refptr<Layer> grandChild = Layer::create();
1397 scoped_refptr<LayerWithForcedDrawsContent> leafNode = make_scoped_refptr(new LayerWithForcedDrawsContent()); 1397 scoped_refptr<LayerWithForcedDrawsContent> leafNode = make_scoped_refptr(new LayerWithForcedDrawsContent());
1398 parent->addChild(child); 1398 parent->addChild(child);
1399 child->addChild(grandChild); 1399 child->addChild(grandChild);
1400 grandChild->addChild(leafNode); 1400 grandChild->addChild(leafNode);
1401 1401
1402 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 1402 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
1403 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false); 1403 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(20, 20), false);
1404 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(200, 200), IntSize(10, 10), false); 1404 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(200, 200), gfx::Size(10, 10), false);
1405 setLayerPropertiesForTesting(leafNode.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false); 1405 setLayerPropertiesForTesting(leafNode.get(), identityMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
1406 1406
1407 parent->setMasksToBounds(true); 1407 parent->setMasksToBounds(true);
1408 child->setOpacity(0.4f); 1408 child->setOpacity(0.4f);
1409 grandChild->setOpacity(0.4f); 1409 grandChild->setOpacity(0.4f);
1410 1410
1411 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 1411 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
1412 int dummyMaxTextureSize = 512; 1412 int dummyMaxTextureSize = 512;
1413 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 1413 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
1414 1414
1415 // Without an animation, we should cull child and grandChild from the render SurfaceLayerList. 1415 // Without an animation, we should cull child and grandChild from the render SurfaceLayerList.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 scoped_refptr<Layer> grandChild2 = Layer::create(); 1450 scoped_refptr<Layer> grandChild2 = Layer::create();
1451 scoped_refptr<Layer> grandChild3 = Layer::create(); 1451 scoped_refptr<Layer> grandChild3 = Layer::create();
1452 scoped_refptr<Layer> grandChild4 = Layer::create(); 1452 scoped_refptr<Layer> grandChild4 = Layer::create();
1453 1453
1454 parent->addChild(child); 1454 parent->addChild(child);
1455 child->addChild(grandChild1); 1455 child->addChild(grandChild1);
1456 child->addChild(grandChild2); 1456 child->addChild(grandChild2);
1457 child->addChild(grandChild3); 1457 child->addChild(grandChild3);
1458 child->addChild(grandChild4); 1458 child->addChild(grandChild4);
1459 1459
1460 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false); 1460 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(500, 500), false);
1461 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false); 1461 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(20, 20), false);
1462 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(10, 10), false); 1462 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(10, 10), false);
1463 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false); 1463 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(15, 15), gfx::Size(10, 10), false);
1464 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false); 1464 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(15, 15), gfx::Size(10, 10), false);
1465 setLayerPropertiesForTesting(grandChild4.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(45, 45), IntSize(10, 10), false); 1465 setLayerPropertiesForTesting(grandChild4.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(45, 45), gfx::Size(10, 10), false);
1466 1466
1467 child->setMasksToBounds(true); 1467 child->setMasksToBounds(true);
1468 grandChild3->setMasksToBounds(true); 1468 grandChild3->setMasksToBounds(true);
1469 1469
1470 // Force everyone to be a render surface. 1470 // Force everyone to be a render surface.
1471 child->setOpacity(0.4f); 1471 child->setOpacity(0.4f);
1472 grandChild1->setOpacity(0.5); 1472 grandChild1->setOpacity(0.5);
1473 grandChild2->setOpacity(0.5); 1473 grandChild2->setOpacity(0.5);
1474 grandChild3->setOpacity(0.5); 1474 grandChild3->setOpacity(0.5);
1475 grandChild4->setOpacity(0.5); 1475 grandChild4->setOpacity(0.5);
1476 1476
1477 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 1477 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
1478 int dummyMaxTextureSize = 512; 1478 int dummyMaxTextureSize = 512;
1479 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 1479 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
1480 1480
1481 EXPECT_RECT_EQ(IntRect(IntPoint(5, 5), IntSize(10, 10)), grandChild1->drawab leContentRect()); 1481 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(5, 5), gfx::Size(10, 10)), grandChild1-> drawableContentRect());
1482 EXPECT_RECT_EQ(IntRect(IntPoint(15, 15), IntSize(5, 5)), grandChild3->drawab leContentRect()); 1482 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(15, 15), gfx::Size(5, 5)), grandChild3-> drawableContentRect());
1483 EXPECT_RECT_EQ(IntRect(IntPoint(15, 15), IntSize(5, 5)), grandChild3->drawab leContentRect()); 1483 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(15, 15), gfx::Size(5, 5)), grandChild3-> drawableContentRect());
1484 EXPECT_TRUE(grandChild4->drawableContentRect().isEmpty()); 1484 EXPECT_TRUE(grandChild4->drawableContentRect().IsEmpty());
1485 } 1485 }
1486 1486
1487 TEST(LayerTreeHostCommonTest, verifyClipRectIsPropagatedCorrectlyToSurfaces) 1487 TEST(LayerTreeHostCommonTest, verifyClipRectIsPropagatedCorrectlyToSurfaces)
1488 { 1488 {
1489 // Verify that renderSurfaces (and their layers) get the appropriate clipRec ts when their parent masksToBounds is true. 1489 // Verify that renderSurfaces (and their layers) get the appropriate clipRec ts when their parent masksToBounds is true.
1490 // 1490 //
1491 // Layers that own renderSurfaces (at least for now) do not inherit any clip ping; 1491 // Layers that own renderSurfaces (at least for now) do not inherit any clip ping;
1492 // instead the surface will enforce the clip for the entire subtree. They ma y still 1492 // instead the surface will enforce the clip for the entire subtree. They ma y still
1493 // have a clipRect of their own layer bounds, however, if masksToBounds was true. 1493 // have a clipRect of their own layer bounds, however, if masksToBounds was true.
1494 // 1494 //
(...skipping 15 matching lines...) Expand all
1510 child->addChild(grandChild2); 1510 child->addChild(grandChild2);
1511 child->addChild(grandChild3); 1511 child->addChild(grandChild3);
1512 child->addChild(grandChild4); 1512 child->addChild(grandChild4);
1513 1513
1514 // the leaf nodes ensure that these grandChildren become renderSurfaces for this test. 1514 // the leaf nodes ensure that these grandChildren become renderSurfaces for this test.
1515 grandChild1->addChild(leafNode1); 1515 grandChild1->addChild(leafNode1);
1516 grandChild2->addChild(leafNode2); 1516 grandChild2->addChild(leafNode2);
1517 grandChild3->addChild(leafNode3); 1517 grandChild3->addChild(leafNode3);
1518 grandChild4->addChild(leafNode4); 1518 grandChild4->addChild(leafNode4);
1519 1519
1520 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false); 1520 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(500, 500), false);
1521 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false); 1521 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(20, 20), false);
1522 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(10, 10), false); 1522 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(10, 10), false);
1523 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false); 1523 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(15, 15), gfx::Size(10, 10), false);
1524 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false); 1524 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(15, 15), gfx::Size(10, 10), false);
1525 setLayerPropertiesForTesting(grandChild4.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(45, 45), IntSize(10, 10), false); 1525 setLayerPropertiesForTesting(grandChild4.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(45, 45), gfx::Size(10, 10), false);
1526 setLayerPropertiesForTesting(leafNode1.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false); 1526 setLayerPropertiesForTesting(leafNode1.get(), identityMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
1527 setLayerPropertiesForTesting(leafNode2.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false); 1527 setLayerPropertiesForTesting(leafNode2.get(), identityMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
1528 setLayerPropertiesForTesting(leafNode3.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false); 1528 setLayerPropertiesForTesting(leafNode3.get(), identityMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
1529 setLayerPropertiesForTesting(leafNode4.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false); 1529 setLayerPropertiesForTesting(leafNode4.get(), identityMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
1530 1530
1531 child->setMasksToBounds(true); 1531 child->setMasksToBounds(true);
1532 grandChild3->setMasksToBounds(true); 1532 grandChild3->setMasksToBounds(true);
1533 grandChild4->setMasksToBounds(true); 1533 grandChild4->setMasksToBounds(true);
1534 1534
1535 // Force everyone to be a render surface. 1535 // Force everyone to be a render surface.
1536 child->setOpacity(0.4f); 1536 child->setOpacity(0.4f);
1537 grandChild1->setOpacity(0.5); 1537 grandChild1->setOpacity(0.5);
1538 grandChild2->setOpacity(0.5); 1538 grandChild2->setOpacity(0.5);
1539 grandChild3->setOpacity(0.5); 1539 grandChild3->setOpacity(0.5);
1540 grandChild4->setOpacity(0.5); 1540 grandChild4->setOpacity(0.5);
1541 1541
1542 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 1542 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
1543 int dummyMaxTextureSize = 512; 1543 int dummyMaxTextureSize = 512;
1544 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 1544 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
1545 1545
1546 ASSERT_TRUE(grandChild1->renderSurface()); 1546 ASSERT_TRUE(grandChild1->renderSurface());
1547 ASSERT_TRUE(grandChild2->renderSurface()); 1547 ASSERT_TRUE(grandChild2->renderSurface());
1548 ASSERT_TRUE(grandChild3->renderSurface()); 1548 ASSERT_TRUE(grandChild3->renderSurface());
1549 EXPECT_FALSE(grandChild4->renderSurface()); // Because grandChild4 is entire ly clipped, it is expected to not have a renderSurface. 1549 EXPECT_FALSE(grandChild4->renderSurface()); // Because grandChild4 is entire ly clipped, it is expected to not have a renderSurface.
1550 1550
1551 // Surfaces are clipped by their parent, but un-affected by the owning layer 's masksToBounds. 1551 // Surfaces are clipped by their parent, but un-affected by the owning layer 's masksToBounds.
1552 EXPECT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild1->render Surface()->clipRect()); 1552 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(0, 0), gfx::Size(20, 20)), grandChild1-> renderSurface()->clipRect());
1553 EXPECT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild2->render Surface()->clipRect()); 1553 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(0, 0), gfx::Size(20, 20)), grandChild2-> renderSurface()->clipRect());
1554 EXPECT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild3->render Surface()->clipRect()); 1554 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(0, 0), gfx::Size(20, 20)), grandChild3-> renderSurface()->clipRect());
1555 } 1555 }
1556 1556
1557 TEST(LayerTreeHostCommonTest, verifyAnimationsForRenderSurfaceHierarchy) 1557 TEST(LayerTreeHostCommonTest, verifyAnimationsForRenderSurfaceHierarchy)
1558 { 1558 {
1559 scoped_refptr<Layer> parent = Layer::create(); 1559 scoped_refptr<Layer> parent = Layer::create();
1560 scoped_refptr<Layer> renderSurface1 = Layer::create(); 1560 scoped_refptr<Layer> renderSurface1 = Layer::create();
1561 scoped_refptr<Layer> renderSurface2 = Layer::create(); 1561 scoped_refptr<Layer> renderSurface2 = Layer::create();
1562 scoped_refptr<Layer> childOfRoot = Layer::create(); 1562 scoped_refptr<Layer> childOfRoot = Layer::create();
1563 scoped_refptr<Layer> childOfRS1 = Layer::create(); 1563 scoped_refptr<Layer> childOfRS1 = Layer::create();
1564 scoped_refptr<Layer> childOfRS2 = Layer::create(); 1564 scoped_refptr<Layer> childOfRS2 = Layer::create();
(...skipping 24 matching lines...) Expand all
1589 WebTransformationMatrix sublayerTransform; 1589 WebTransformationMatrix sublayerTransform;
1590 sublayerTransform.scale3d(10, 1, 1); 1590 sublayerTransform.scale3d(10, 1, 1);
1591 1591
1592 // Put a transform animation on the render surface. 1592 // Put a transform animation on the render surface.
1593 addAnimatedTransformToController(*renderSurface2->layerAnimationController() , 10, 30, 0); 1593 addAnimatedTransformToController(*renderSurface2->layerAnimationController() , 10, 30, 0);
1594 1594
1595 // Also put transform animations on grandChildOfRoot, and grandChildOfRS2 1595 // Also put transform animations on grandChildOfRoot, and grandChildOfRS2
1596 addAnimatedTransformToController(*grandChildOfRoot->layerAnimationController (), 10, 30, 0); 1596 addAnimatedTransformToController(*grandChildOfRoot->layerAnimationController (), 10, 30, 0);
1597 addAnimatedTransformToController(*grandChildOfRS2->layerAnimationController( ), 10, 30, 0); 1597 addAnimatedTransformToController(*grandChildOfRS2->layerAnimationController( ), 10, 30, 0);
1598 1598
1599 setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform , FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1599 setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform , gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1600 setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerT ransform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1600 setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerT ransform, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1601 setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerT ransform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1601 setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerT ransform, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1602 setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTran sform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1602 setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTran sform, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1603 setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTrans form, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1603 setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTrans form, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1604 setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTrans form, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1604 setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTrans form, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1605 setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublaye rTransform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1605 setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublaye rTransform, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false) ;
1606 setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayer Transform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1606 setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayer Transform, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1607 setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayer Transform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1607 setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayer Transform, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1608 1608
1609 executeCalculateDrawTransformsAndVisibility(parent.get()); 1609 executeCalculateDrawTransformsAndVisibility(parent.get());
1610 1610
1611 // Only layers that are associated with render surfaces should have an actua l renderSurface() value. 1611 // Only layers that are associated with render surfaces should have an actua l renderSurface() value.
1612 // 1612 //
1613 ASSERT_TRUE(parent->renderSurface()); 1613 ASSERT_TRUE(parent->renderSurface());
1614 ASSERT_FALSE(childOfRoot->renderSurface()); 1614 ASSERT_FALSE(childOfRoot->renderSurface());
1615 ASSERT_FALSE(grandChildOfRoot->renderSurface()); 1615 ASSERT_FALSE(grandChildOfRoot->renderSurface());
1616 1616
1617 ASSERT_TRUE(renderSurface1->renderSurface()); 1617 ASSERT_TRUE(renderSurface1->renderSurface());
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 1692
1693 EXPECT_FLOAT_EQ(3, renderSurface2->screenSpaceTransform().m42()); 1693 EXPECT_FLOAT_EQ(3, renderSurface2->screenSpaceTransform().m42());
1694 EXPECT_FLOAT_EQ(4, childOfRS2->screenSpaceTransform().m42()); 1694 EXPECT_FLOAT_EQ(4, childOfRS2->screenSpaceTransform().m42());
1695 EXPECT_FLOAT_EQ(5, grandChildOfRS2->screenSpaceTransform().m42()); 1695 EXPECT_FLOAT_EQ(5, grandChildOfRS2->screenSpaceTransform().m42());
1696 } 1696 }
1697 1697
1698 TEST(LayerTreeHostCommonTest, verifyVisibleRectForIdentityTransform) 1698 TEST(LayerTreeHostCommonTest, verifyVisibleRectForIdentityTransform)
1699 { 1699 {
1700 // Test the calculateVisibleRect() function works correctly for identity tra nsforms. 1700 // Test the calculateVisibleRect() function works correctly for identity tra nsforms.
1701 1701
1702 IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1702 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1703 WebTransformationMatrix layerToSurfaceTransform; 1703 WebTransformationMatrix layerToSurfaceTransform;
1704 1704
1705 // Case 1: Layer is contained within the surface. 1705 // Case 1: Layer is contained within the surface.
1706 IntRect layerContentRect = IntRect(IntPoint(10, 10), IntSize(30, 30)); 1706 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(10, 10), gfx::Size(30, 30) );
1707 IntRect expected = IntRect(IntPoint(10, 10), IntSize(30, 30)); 1707 gfx::Rect expected = gfx::Rect(gfx::Point(10, 10), gfx::Size(30, 30));
1708 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1708 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1709 EXPECT_RECT_EQ(expected, actual); 1709 EXPECT_RECT_EQ(expected, actual);
1710 1710
1711 // Case 2: Layer is outside the surface rect. 1711 // Case 2: Layer is outside the surface rect.
1712 layerContentRect = IntRect(IntPoint(120, 120), IntSize(30, 30)); 1712 layerContentRect = gfx::Rect(gfx::Point(120, 120), gfx::Size(30, 30));
1713 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1713 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1714 EXPECT_TRUE(actual.isEmpty()); 1714 EXPECT_TRUE(actual.IsEmpty());
1715 1715
1716 // Case 3: Layer is partially overlapping the surface rect. 1716 // Case 3: Layer is partially overlapping the surface rect.
1717 layerContentRect = IntRect(IntPoint(80, 80), IntSize(30, 30)); 1717 layerContentRect = gfx::Rect(gfx::Point(80, 80), gfx::Size(30, 30));
1718 expected = IntRect(IntPoint(80, 80), IntSize(20, 20)); 1718 expected = gfx::Rect(gfx::Point(80, 80), gfx::Size(20, 20));
1719 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1719 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1720 EXPECT_RECT_EQ(expected, actual); 1720 EXPECT_RECT_EQ(expected, actual);
1721 } 1721 }
1722 1722
1723 TEST(LayerTreeHostCommonTest, verifyVisibleRectForTranslations) 1723 TEST(LayerTreeHostCommonTest, verifyVisibleRectForTranslations)
1724 { 1724 {
1725 // Test the calculateVisibleRect() function works correctly for scaling tran sforms. 1725 // Test the calculateVisibleRect() function works correctly for scaling tran sforms.
1726 1726
1727 IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1727 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1728 IntRect layerContentRect = IntRect(IntPoint(0, 0), IntSize(30, 30)); 1728 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30));
1729 WebTransformationMatrix layerToSurfaceTransform; 1729 WebTransformationMatrix layerToSurfaceTransform;
1730 1730
1731 // Case 1: Layer is contained within the surface. 1731 // Case 1: Layer is contained within the surface.
1732 layerToSurfaceTransform.makeIdentity(); 1732 layerToSurfaceTransform.makeIdentity();
1733 layerToSurfaceTransform.translate(10, 10); 1733 layerToSurfaceTransform.translate(10, 10);
1734 IntRect expected = IntRect(IntPoint(0, 0), IntSize(30, 30)); 1734 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30));
1735 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1735 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1736 EXPECT_RECT_EQ(expected, actual); 1736 EXPECT_RECT_EQ(expected, actual);
1737 1737
1738 // Case 2: Layer is outside the surface rect. 1738 // Case 2: Layer is outside the surface rect.
1739 layerToSurfaceTransform.makeIdentity(); 1739 layerToSurfaceTransform.makeIdentity();
1740 layerToSurfaceTransform.translate(120, 120); 1740 layerToSurfaceTransform.translate(120, 120);
1741 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1741 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1742 EXPECT_TRUE(actual.isEmpty()); 1742 EXPECT_TRUE(actual.IsEmpty());
1743 1743
1744 // Case 3: Layer is partially overlapping the surface rect. 1744 // Case 3: Layer is partially overlapping the surface rect.
1745 layerToSurfaceTransform.makeIdentity(); 1745 layerToSurfaceTransform.makeIdentity();
1746 layerToSurfaceTransform.translate(80, 80); 1746 layerToSurfaceTransform.translate(80, 80);
1747 expected = IntRect(IntPoint(0, 0), IntSize(20, 20)); 1747 expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(20, 20));
1748 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1748 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1749 EXPECT_RECT_EQ(expected, actual); 1749 EXPECT_RECT_EQ(expected, actual);
1750 } 1750 }
1751 1751
1752 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor2DRotations) 1752 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor2DRotations)
1753 { 1753 {
1754 // Test the calculateVisibleRect() function works correctly for rotations ab out z-axis (i.e. 2D rotations). 1754 // Test the calculateVisibleRect() function works correctly for rotations ab out z-axis (i.e. 2D rotations).
1755 // Remember that calculateVisibleRect() should return the visible rect in th e layer's space. 1755 // Remember that calculateVisibleRect() should return the visible rect in th e layer's space.
1756 1756
1757 IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1757 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1758 IntRect layerContentRect = IntRect(IntPoint(0, 0), IntSize(30, 30)); 1758 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30));
1759 WebTransformationMatrix layerToSurfaceTransform; 1759 WebTransformationMatrix layerToSurfaceTransform;
1760 1760
1761 // Case 1: Layer is contained within the surface. 1761 // Case 1: Layer is contained within the surface.
1762 layerToSurfaceTransform.makeIdentity(); 1762 layerToSurfaceTransform.makeIdentity();
1763 layerToSurfaceTransform.translate(50, 50); 1763 layerToSurfaceTransform.translate(50, 50);
1764 layerToSurfaceTransform.rotate(45); 1764 layerToSurfaceTransform.rotate(45);
1765 IntRect expected = IntRect(IntPoint(0, 0), IntSize(30, 30)); 1765 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30));
1766 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1766 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1767 EXPECT_RECT_EQ(expected, actual); 1767 EXPECT_RECT_EQ(expected, actual);
1768 1768
1769 // Case 2: Layer is outside the surface rect. 1769 // Case 2: Layer is outside the surface rect.
1770 layerToSurfaceTransform.makeIdentity(); 1770 layerToSurfaceTransform.makeIdentity();
1771 layerToSurfaceTransform.translate(-50, 0); 1771 layerToSurfaceTransform.translate(-50, 0);
1772 layerToSurfaceTransform.rotate(45); 1772 layerToSurfaceTransform.rotate(45);
1773 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1773 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1774 EXPECT_TRUE(actual.isEmpty()); 1774 EXPECT_TRUE(actual.IsEmpty());
1775 1775
1776 // Case 3: The layer is rotated about its top-left corner. In surface space, the layer 1776 // Case 3: The layer is rotated about its top-left corner. In surface space, the layer
1777 // is oriented diagonally, with the left half outside of the renderS urface. In 1777 // is oriented diagonally, with the left half outside of the renderS urface. In
1778 // this case, the visible rect should still be the entire layer (rem ember the 1778 // this case, the visible rect should still be the entire layer (rem ember the
1779 // visible rect is computed in layer space); both the top-left and 1779 // visible rect is computed in layer space); both the top-left and
1780 // bottom-right corners of the layer are still visible. 1780 // bottom-right corners of the layer are still visible.
1781 layerToSurfaceTransform.makeIdentity(); 1781 layerToSurfaceTransform.makeIdentity();
1782 layerToSurfaceTransform.rotate(45); 1782 layerToSurfaceTransform.rotate(45);
1783 expected = IntRect(IntPoint(0, 0), IntSize(30, 30)); 1783 expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30));
1784 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1784 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1785 EXPECT_RECT_EQ(expected, actual); 1785 EXPECT_RECT_EQ(expected, actual);
1786 1786
1787 // Case 4: The layer is rotated about its top-left corner, and translated up wards. In 1787 // Case 4: The layer is rotated about its top-left corner, and translated up wards. In
1788 // surface space, the layer is oriented diagonally, with only the to p corner 1788 // surface space, the layer is oriented diagonally, with only the to p corner
1789 // of the surface overlapping the layer. In layer space, the render surface 1789 // of the surface overlapping the layer. In layer space, the render surface
1790 // overlaps the right side of the layer. The visible rect should be the 1790 // overlaps the right side of the layer. The visible rect should be the
1791 // layer's right half. 1791 // layer's right half.
1792 layerToSurfaceTransform.makeIdentity(); 1792 layerToSurfaceTransform.makeIdentity();
1793 layerToSurfaceTransform.translate(0, -sqrt(2.0) * 15); 1793 layerToSurfaceTransform.translate(0, -sqrt(2.0) * 15);
1794 layerToSurfaceTransform.rotate(45); 1794 layerToSurfaceTransform.rotate(45);
1795 expected = IntRect(IntPoint(15, 0), IntSize(15, 30)); // right half of layer bounds. 1795 expected = gfx::Rect(gfx::Point(15, 0), gfx::Size(15, 30)); // right half of layer bounds.
1796 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1796 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1797 EXPECT_RECT_EQ(expected, actual); 1797 EXPECT_RECT_EQ(expected, actual);
1798 } 1798 }
1799 1799
1800 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform) 1800 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform)
1801 { 1801 {
1802 // Test that the calculateVisibleRect() function works correctly for 3d tran sforms. 1802 // Test that the calculateVisibleRect() function works correctly for 3d tran sforms.
1803 1803
1804 IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1804 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1805 IntRect layerContentRect = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1805 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100) );
1806 WebTransformationMatrix layerToSurfaceTransform; 1806 WebTransformationMatrix layerToSurfaceTransform;
1807 1807
1808 // Case 1: Orthographic projection of a layer rotated about y-axis by 45 deg rees, should be fully contained in the renderSurface. 1808 // Case 1: Orthographic projection of a layer rotated about y-axis by 45 deg rees, should be fully contained in the renderSurface.
1809 layerToSurfaceTransform.makeIdentity(); 1809 layerToSurfaceTransform.makeIdentity();
1810 layerToSurfaceTransform.rotate3d(0, 45, 0); 1810 layerToSurfaceTransform.rotate3d(0, 45, 0);
1811 IntRect expected = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1811 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100));
1812 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1812 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1813 EXPECT_RECT_EQ(expected, actual); 1813 EXPECT_RECT_EQ(expected, actual);
1814 1814
1815 // Case 2: Orthographic projection of a layer rotated about y-axis by 45 deg rees, but 1815 // Case 2: Orthographic projection of a layer rotated about y-axis by 45 deg rees, but
1816 // shifted to the side so only the right-half the layer would be vis ible on 1816 // shifted to the side so only the right-half the layer would be vis ible on
1817 // the surface. 1817 // the surface.
1818 double halfWidthOfRotatedLayer = (100 / sqrt(2.0)) * 0.5; // 100 is the un-r otated layer width; divided by sqrt(2) is the rotated width. 1818 double halfWidthOfRotatedLayer = (100 / sqrt(2.0)) * 0.5; // 100 is the un-r otated layer width; divided by sqrt(2) is the rotated width.
1819 layerToSurfaceTransform.makeIdentity(); 1819 layerToSurfaceTransform.makeIdentity();
1820 layerToSurfaceTransform.translate(-halfWidthOfRotatedLayer, 0); 1820 layerToSurfaceTransform.translate(-halfWidthOfRotatedLayer, 0);
1821 layerToSurfaceTransform.rotate3d(0, 45, 0); // rotates about the left edge o f the layer 1821 layerToSurfaceTransform.rotate3d(0, 45, 0); // rotates about the left edge o f the layer
1822 expected = IntRect(IntPoint(50, 0), IntSize(50, 100)); // right half of the layer. 1822 expected = gfx::Rect(gfx::Point(50, 0), gfx::Size(50, 100)); // right half o f the layer.
1823 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1823 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1824 EXPECT_RECT_EQ(expected, actual); 1824 EXPECT_RECT_EQ(expected, actual);
1825 } 1825 }
1826 1826
1827 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform) 1827 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform)
1828 { 1828 {
1829 // Test the calculateVisibleRect() function works correctly when the layer h as a 1829 // Test the calculateVisibleRect() function works correctly when the layer h as a
1830 // perspective projection onto the target surface. 1830 // perspective projection onto the target surface.
1831 1831
1832 IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1832 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1833 IntRect layerContentRect = IntRect(IntPoint(-50, -50), IntSize(200, 200)); 1833 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(200, 200));
1834 WebTransformationMatrix layerToSurfaceTransform; 1834 WebTransformationMatrix layerToSurfaceTransform;
1835 1835
1836 // Case 1: Even though the layer is twice as large as the surface, due to pe rspective 1836 // Case 1: Even though the layer is twice as large as the surface, due to pe rspective
1837 // foreshortening, the layer will fit fully in the surface when its translated 1837 // foreshortening, the layer will fit fully in the surface when its translated
1838 // more than the perspective amount. 1838 // more than the perspective amount.
1839 layerToSurfaceTransform.makeIdentity(); 1839 layerToSurfaceTransform.makeIdentity();
1840 1840
1841 // The following sequence of transforms applies the perspective about the ce nter of the surface. 1841 // The following sequence of transforms applies the perspective about the ce nter of the surface.
1842 layerToSurfaceTransform.translate(50, 50); 1842 layerToSurfaceTransform.translate(50, 50);
1843 layerToSurfaceTransform.applyPerspective(9); 1843 layerToSurfaceTransform.applyPerspective(9);
1844 layerToSurfaceTransform.translate(-50, -50); 1844 layerToSurfaceTransform.translate(-50, -50);
1845 1845
1846 // This translate places the layer in front of the surface's projection plan e. 1846 // This translate places the layer in front of the surface's projection plan e.
1847 layerToSurfaceTransform.translate3d(0, 0, -27); 1847 layerToSurfaceTransform.translate3d(0, 0, -27);
1848 1848
1849 IntRect expected = IntRect(IntPoint(-50, -50), IntSize(200, 200)); 1849 gfx::Rect expected = gfx::Rect(gfx::Point(-50, -50), gfx::Size(200, 200));
1850 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1850 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1851 EXPECT_RECT_EQ(expected, actual); 1851 EXPECT_RECT_EQ(expected, actual);
1852 1852
1853 // Case 2: same projection as before, except that the layer is also translat ed to the 1853 // Case 2: same projection as before, except that the layer is also translat ed to the
1854 // side, so that only the right half of the layer should be visible. 1854 // side, so that only the right half of the layer should be visible.
1855 // 1855 //
1856 // Explanation of expected result: 1856 // Explanation of expected result:
1857 // The perspective ratio is (z distance between layer and camera origin) / ( z distance between projection plane and camera origin) == ((-27 - 9) / 9) 1857 // The perspective ratio is (z distance between layer and camera origin) / ( z distance between projection plane and camera origin) == ((-27 - 9) / 9)
1858 // 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 1858 // 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
1859 // visible), then we would need to translate by (-36 / 9) * -50 == -200 in t he layer's units. 1859 // visible), then we would need to translate by (-36 / 9) * -50 == -200 in t he layer's units.
1860 // 1860 //
1861 layerToSurfaceTransform.translate3d(-200, 0, 0); 1861 layerToSurfaceTransform.translate3d(-200, 0, 0);
1862 expected = IntRect(IntPoint(50, -50), IntSize(100, 200)); // The right half of the layer's bounding rect. 1862 expected = gfx::Rect(gfx::Point(50, -50), gfx::Size(100, 200)); // The right half of the layer's bounding rect.
1863 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1863 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1864 EXPECT_RECT_EQ(expected, actual); 1864 EXPECT_RECT_EQ(expected, actual);
1865 } 1865 }
1866 1866
1867 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicIsNotClippedBehi ndSurface) 1867 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicIsNotClippedBehi ndSurface)
1868 { 1868 {
1869 // There is currently no explicit concept of an orthographic projection plan e in our 1869 // There is currently no explicit concept of an orthographic projection plan e in our
1870 // code (nor in the CSS spec to my knowledge). Therefore, layers that are te chnically 1870 // code (nor in the CSS spec to my knowledge). Therefore, layers that are te chnically
1871 // behind the surface in an orthographic world should not be clipped when th ey are 1871 // behind the surface in an orthographic world should not be clipped when th ey are
1872 // flattened to the surface. 1872 // flattened to the surface.
1873 1873
1874 IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1874 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1875 IntRect layerContentRect = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1875 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100) );
1876 WebTransformationMatrix layerToSurfaceTransform; 1876 WebTransformationMatrix layerToSurfaceTransform;
1877 1877
1878 // This sequence of transforms effectively rotates the layer about the y-axi s at the 1878 // This sequence of transforms effectively rotates the layer about the y-axi s at the
1879 // center of the layer. 1879 // center of the layer.
1880 layerToSurfaceTransform.makeIdentity(); 1880 layerToSurfaceTransform.makeIdentity();
1881 layerToSurfaceTransform.translate(50, 0); 1881 layerToSurfaceTransform.translate(50, 0);
1882 layerToSurfaceTransform.rotate3d(0, 45, 0); 1882 layerToSurfaceTransform.rotate3d(0, 45, 0);
1883 layerToSurfaceTransform.translate(-50, 0); 1883 layerToSurfaceTransform.translate(-50, 0);
1884 1884
1885 IntRect expected = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1885 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100));
1886 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1886 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1887 EXPECT_RECT_EQ(expected, actual); 1887 EXPECT_RECT_EQ(expected, actual);
1888 } 1888 }
1889 1889
1890 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW) 1890 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW)
1891 { 1891 {
1892 // Test the calculateVisibleRect() function works correctly when projecting a surface 1892 // Test the calculateVisibleRect() function works correctly when projecting a surface
1893 // onto a layer, but the layer is partially behind the camera (not just behi nd the 1893 // onto a layer, but the layer is partially behind the camera (not just behi nd the
1894 // projection plane). In this case, the cartesian coordinates may seem to be valid, 1894 // projection plane). In this case, the cartesian coordinates may seem to be valid,
1895 // but actually they are not. The visibleRect needs to be properly clipped b y the 1895 // but actually they are not. The visibleRect needs to be properly clipped b y the
1896 // w = 0 plane in homogeneous coordinates before converting to cartesian coo rdinates. 1896 // w = 0 plane in homogeneous coordinates before converting to cartesian coo rdinates.
1897 1897
1898 IntRect targetSurfaceRect = IntRect(IntPoint(-50, -50), IntSize(100, 100)); 1898 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100, 100));
1899 IntRect layerContentRect = IntRect(IntPoint(-10, -1), IntSize(20, 2)); 1899 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -1), gfx::Size(20, 2) );
1900 WebTransformationMatrix layerToSurfaceTransform; 1900 WebTransformationMatrix layerToSurfaceTransform;
1901 1901
1902 // The layer is positioned so that the right half of the layer should be in front of 1902 // The layer is positioned so that the right half of the layer should be in front of
1903 // the camera, while the other half is behind the surface's projection plane . The 1903 // the camera, while the other half is behind the surface's projection plane . The
1904 // following sequence of transforms applies the perspective and rotation abo ut the 1904 // following sequence of transforms applies the perspective and rotation abo ut the
1905 // center of the layer. 1905 // center of the layer.
1906 layerToSurfaceTransform.makeIdentity(); 1906 layerToSurfaceTransform.makeIdentity();
1907 layerToSurfaceTransform.applyPerspective(1); 1907 layerToSurfaceTransform.applyPerspective(1);
1908 layerToSurfaceTransform.translate3d(-2, 0, 1); 1908 layerToSurfaceTransform.translate3d(-2, 0, 1);
1909 layerToSurfaceTransform.rotate3d(0, 45, 0); 1909 layerToSurfaceTransform.rotate3d(0, 45, 0);
1910 1910
1911 // Sanity check that this transform does indeed cause w < 0 when applying th e 1911 // Sanity check that this transform does indeed cause w < 0 when applying th e
1912 // transform, otherwise this code is not testing the intended scenario. 1912 // transform, otherwise this code is not testing the intended scenario.
1913 bool clipped = false; 1913 bool clipped = false;
1914 MathUtil::mapQuad(layerToSurfaceTransform, FloatQuad(FloatRect(layerContentR ect)), clipped); 1914 MathUtil::mapQuad(layerToSurfaceTransform, FloatQuad(gfx::RectF(layerContent Rect)), clipped);
1915 ASSERT_TRUE(clipped); 1915 ASSERT_TRUE(clipped);
1916 1916
1917 int expectedXPosition = 0; 1917 int expectedXPosition = 0;
1918 int expectedWidth = 10; 1918 int expectedWidth = 10;
1919 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1919 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1920 EXPECT_EQ(expectedXPosition, actual.x()); 1920 EXPECT_EQ(expectedXPosition, actual.x());
1921 EXPECT_EQ(expectedWidth, actual.width()); 1921 EXPECT_EQ(expectedWidth, actual.width());
1922 } 1922 }
1923 1923
1924 TEST(LayerTreeHostCommonTest, verifyVisibleRectForPerspectiveUnprojection) 1924 TEST(LayerTreeHostCommonTest, verifyVisibleRectForPerspectiveUnprojection)
1925 { 1925 {
1926 // To determine visibleRect in layer space, there needs to be an un-projecti on from 1926 // To determine visibleRect in layer space, there needs to be an un-projecti on from
1927 // surface space to layer space. When the original transform was a perspecti ve 1927 // surface space to layer space. When the original transform was a perspecti ve
1928 // projection that was clipped, it returns a rect that encloses the clipped bounds. 1928 // projection that was clipped, it returns a rect that encloses the clipped bounds.
1929 // Un-projecting this new rect may require clipping again. 1929 // Un-projecting this new rect may require clipping again.
1930 1930
1931 // This sequence of transforms causes one corner of the layer to protrude ac ross the w = 0 plane, and should be clipped. 1931 // This sequence of transforms causes one corner of the layer to protrude ac ross the w = 0 plane, and should be clipped.
1932 IntRect targetSurfaceRect = IntRect(IntPoint(-50, -50), IntSize(100, 100)); 1932 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100, 100));
1933 IntRect layerContentRect = IntRect(IntPoint(-10, -10), IntSize(20, 20)); 1933 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -10), gfx::Size(20, 2 0));
1934 WebTransformationMatrix layerToSurfaceTransform; 1934 WebTransformationMatrix layerToSurfaceTransform;
1935 layerToSurfaceTransform.makeIdentity(); 1935 layerToSurfaceTransform.makeIdentity();
1936 layerToSurfaceTransform.applyPerspective(1); 1936 layerToSurfaceTransform.applyPerspective(1);
1937 layerToSurfaceTransform.translate3d(0, 0, -5); 1937 layerToSurfaceTransform.translate3d(0, 0, -5);
1938 layerToSurfaceTransform.rotate3d(0, 45, 0); 1938 layerToSurfaceTransform.rotate3d(0, 45, 0);
1939 layerToSurfaceTransform.rotate3d(80, 0, 0); 1939 layerToSurfaceTransform.rotate3d(80, 0, 0);
1940 1940
1941 // Sanity check that un-projection does indeed cause w < 0, otherwise this c ode is not 1941 // Sanity check that un-projection does indeed cause w < 0, otherwise this c ode is not
1942 // testing the intended scenario. 1942 // testing the intended scenario.
1943 bool clipped = false; 1943 bool clipped = false;
1944 FloatRect clippedRect = MathUtil::mapClippedRect(layerToSurfaceTransform, la yerContentRect); 1944 gfx::RectF clippedRect = MathUtil::mapClippedRect(layerToSurfaceTransform, l ayerContentRect);
1945 MathUtil::projectQuad(layerToSurfaceTransform.inverse(), FloatQuad(clippedRe ct), clipped); 1945 MathUtil::projectQuad(layerToSurfaceTransform.inverse(), FloatQuad(clippedRe ct), clipped);
1946 ASSERT_TRUE(clipped); 1946 ASSERT_TRUE(clipped);
1947 1947
1948 // Only the corner of the layer is not visible on the surface because of bei ng 1948 // Only the corner of the layer is not visible on the surface because of bei ng
1949 // clipped. But, the net result of rounding visible region to an axis-aligne d rect is 1949 // clipped. But, the net result of rounding visible region to an axis-aligne d rect is
1950 // that the entire layer should still be considered visible. 1950 // that the entire layer should still be considered visible.
1951 IntRect expected = IntRect(IntPoint(-10, -10), IntSize(20, 20)); 1951 gfx::Rect expected = gfx::Rect(gfx::Point(-10, -10), gfx::Size(20, 20));
1952 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1952 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1953 EXPECT_RECT_EQ(expected, actual); 1953 EXPECT_RECT_EQ(expected, actual);
1954 } 1954 }
1955 1955
1956 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForSimpleLayer s) 1956 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForSimpleLayer s)
1957 { 1957 {
1958 scoped_refptr<Layer> root = Layer::create(); 1958 scoped_refptr<Layer> root = Layer::create();
1959 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 1959 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
1960 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 1960 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
1961 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 1961 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
1962 root->addChild(child1); 1962 root->addChild(child1);
1963 root->addChild(child2); 1963 root->addChild(child2);
1964 root->addChild(child3); 1964 root->addChild(child3);
1965 1965
1966 WebTransformationMatrix identityMatrix; 1966 WebTransformationMatrix identityMatrix;
1967 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 1967 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
1968 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(50, 50), false); 1968 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(50, 50), false);
1969 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false); 1969 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
1970 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false); 1970 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
1971 1971
1972 executeCalculateDrawTransformsAndVisibility(root.get()); 1972 executeCalculateDrawTransformsAndVisibility(root.get());
1973 1973
1974 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableConte ntRect()); 1974 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect());
1975 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect()); 1975 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawableContentRect());
1976 1976
1977 // Layers that do not draw content should have empty visibleContentRects. 1977 // Layers that do not draw content should have empty visibleContentRects.
1978 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect()); 1978 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visibleContentRect());
1979 1979
1980 // layer visibleContentRects are clipped by their targetSurface 1980 // layer visibleContentRects are clipped by their targetSurface
1981 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect()); 1981 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visibleContentRect());
1982 EXPECT_RECT_EQ(IntRect(0, 0, 25, 25), child2->visibleContentRect()); 1982 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visibleContentRect());
1983 EXPECT_TRUE(child3->visibleContentRect().isEmpty()); 1983 EXPECT_TRUE(child3->visibleContentRect().IsEmpty());
1984 1984
1985 // layer drawableContentRects are not clipped. 1985 // layer drawableContentRects are not clipped.
1986 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->drawableContentRect()); 1986 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawableContentRect());
1987 EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect()); 1987 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawableContentRect());
1988 EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect()); 1988 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawableContentRect());
1989 } 1989 }
1990 1990
1991 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersClipp edByLayer) 1991 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersClipp edByLayer)
1992 { 1992 {
1993 scoped_refptr<Layer> root = Layer::create(); 1993 scoped_refptr<Layer> root = Layer::create();
1994 scoped_refptr<Layer> child = Layer::create(); 1994 scoped_refptr<Layer> child = Layer::create();
1995 scoped_refptr<LayerWithForcedDrawsContent> grandChild1 = make_scoped_refptr( new LayerWithForcedDrawsContent()); 1995 scoped_refptr<LayerWithForcedDrawsContent> grandChild1 = make_scoped_refptr( new LayerWithForcedDrawsContent());
1996 scoped_refptr<LayerWithForcedDrawsContent> grandChild2 = make_scoped_refptr( new LayerWithForcedDrawsContent()); 1996 scoped_refptr<LayerWithForcedDrawsContent> grandChild2 = make_scoped_refptr( new LayerWithForcedDrawsContent());
1997 scoped_refptr<LayerWithForcedDrawsContent> grandChild3 = make_scoped_refptr( new LayerWithForcedDrawsContent()); 1997 scoped_refptr<LayerWithForcedDrawsContent> grandChild3 = make_scoped_refptr( new LayerWithForcedDrawsContent());
1998 root->addChild(child); 1998 root->addChild(child);
1999 child->addChild(grandChild1); 1999 child->addChild(grandChild1);
2000 child->addChild(grandChild2); 2000 child->addChild(grandChild2);
2001 child->addChild(grandChild3); 2001 child->addChild(grandChild3);
2002 2002
2003 WebTransformationMatrix identityMatrix; 2003 WebTransformationMatrix identityMatrix;
2004 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2004 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2005 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2005 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2006 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false); 2006 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2007 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false); 2007 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2008 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false); 2008 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2009 2009
2010 child->setMasksToBounds(true); 2010 child->setMasksToBounds(true);
2011 executeCalculateDrawTransformsAndVisibility(root.get()); 2011 executeCalculateDrawTransformsAndVisibility(root.get());
2012 2012
2013 ASSERT_FALSE(child->renderSurface()); 2013 ASSERT_FALSE(child->renderSurface());
2014 2014
2015 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableConte ntRect()); 2015 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect());
2016 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect()); 2016 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawableContentRect());
2017 2017
2018 // Layers that do not draw content should have empty visibleContentRects. 2018 // Layers that do not draw content should have empty visibleContentRects.
2019 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect()); 2019 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visibleContentRect());
2020 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), child->visibleContentRect()); 2020 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visibleContentRect());
2021 2021
2022 // All grandchild visibleContentRects should be clipped by child. 2022 // All grandchild visibleContentRects should be clipped by child.
2023 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), grandChild1->visibleContentRect()); 2023 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grandChild1->visibleContentRect());
2024 EXPECT_RECT_EQ(IntRect(0, 0, 25, 25), grandChild2->visibleContentRect()); 2024 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grandChild2->visibleContentRect());
2025 EXPECT_TRUE(grandChild3->visibleContentRect().isEmpty()); 2025 EXPECT_TRUE(grandChild3->visibleContentRect().IsEmpty());
2026 2026
2027 // All grandchild drawableContentRects should also be clipped by child. 2027 // All grandchild drawableContentRects should also be clipped by child.
2028 EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), grandChild1->drawableContentRect()); 2028 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), grandChild1->drawableContentRect());
2029 EXPECT_RECT_EQ(IntRect(75, 75, 25, 25), grandChild2->drawableContentRect()); 2029 EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25), grandChild2->drawableContentRect() );
2030 EXPECT_TRUE(grandChild3->drawableContentRect().isEmpty()); 2030 EXPECT_TRUE(grandChild3->drawableContentRect().IsEmpty());
2031 } 2031 }
2032 2032
2033 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersInUnc lippedRenderSurface) 2033 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersInUnc lippedRenderSurface)
2034 { 2034 {
2035 scoped_refptr<Layer> root = Layer::create(); 2035 scoped_refptr<Layer> root = Layer::create();
2036 scoped_refptr<Layer> renderSurface1 = Layer::create(); 2036 scoped_refptr<Layer> renderSurface1 = Layer::create();
2037 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2037 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2038 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2038 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2039 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2039 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2040 root->addChild(renderSurface1); 2040 root->addChild(renderSurface1);
2041 renderSurface1->addChild(child1); 2041 renderSurface1->addChild(child1);
2042 renderSurface1->addChild(child2); 2042 renderSurface1->addChild(child2);
2043 renderSurface1->addChild(child3); 2043 renderSurface1->addChild(child3);
2044 2044
2045 WebTransformationMatrix identityMatrix; 2045 WebTransformationMatrix identityMatrix;
2046 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2046 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2047 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false); 2047 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false);
2048 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false); 2048 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2049 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false); 2049 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2050 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false); 2050 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2051 2051
2052 renderSurface1->setForceRenderSurface(true); 2052 renderSurface1->setForceRenderSurface(true);
2053 executeCalculateDrawTransformsAndVisibility(root.get()); 2053 executeCalculateDrawTransformsAndVisibility(root.get());
2054 2054
2055 ASSERT_TRUE(renderSurface1->renderSurface()); 2055 ASSERT_TRUE(renderSurface1->renderSurface());
2056 2056
2057 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableConte ntRect()); 2057 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect());
2058 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect()); 2058 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawableContentRect());
2059 2059
2060 // Layers that do not draw content should have empty visibleContentRects. 2060 // Layers that do not draw content should have empty visibleContentRects.
2061 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect()); 2061 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visibleContentRect());
2062 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect()); 2062 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), renderSurface1->visibleContentRect());
2063 2063
2064 // An unclipped surface grows its drawableContentRect to include all drawabl e regions of the subtree. 2064 // An unclipped surface grows its drawableContentRect to include all drawabl e regions of the subtree.
2065 EXPECT_RECT_EQ(IntRect(5, 5, 170, 170), renderSurface1->renderSurface()->dra wableContentRect()); 2065 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170), renderSurface1->renderSurface()->d rawableContentRect());
2066 2066
2067 // All layers that draw content into the unclipped surface are also unclippe d. 2067 // All layers that draw content into the unclipped surface are also unclippe d.
2068 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect()); 2068 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visibleContentRect());
2069 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child2->visibleContentRect()); 2069 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visibleContentRect());
2070 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child3->visibleContentRect()); 2070 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visibleContentRect());
2071 2071
2072 EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), child1->drawableContentRect()); 2072 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawableContentRect());
2073 EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect()); 2073 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawableContentRect());
2074 EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect()); 2074 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawableContentRect());
2075 } 2075 }
2076 2076
2077 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersInCli ppedRenderSurface) 2077 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersInCli ppedRenderSurface)
2078 { 2078 {
2079 scoped_refptr<Layer> root = Layer::create(); 2079 scoped_refptr<Layer> root = Layer::create();
2080 scoped_refptr<Layer> renderSurface1 = Layer::create(); 2080 scoped_refptr<Layer> renderSurface1 = Layer::create();
2081 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2081 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2082 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2082 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2083 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2083 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2084 root->addChild(renderSurface1); 2084 root->addChild(renderSurface1);
2085 renderSurface1->addChild(child1); 2085 renderSurface1->addChild(child1);
2086 renderSurface1->addChild(child2); 2086 renderSurface1->addChild(child2);
2087 renderSurface1->addChild(child3); 2087 renderSurface1->addChild(child3);
2088 2088
2089 WebTransformationMatrix identityMatrix; 2089 WebTransformationMatrix identityMatrix;
2090 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2090 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2091 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false); 2091 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false);
2092 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false); 2092 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2093 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false); 2093 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2094 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false); 2094 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2095 2095
2096 root->setMasksToBounds(true); 2096 root->setMasksToBounds(true);
2097 renderSurface1->setForceRenderSurface(true); 2097 renderSurface1->setForceRenderSurface(true);
2098 executeCalculateDrawTransformsAndVisibility(root.get()); 2098 executeCalculateDrawTransformsAndVisibility(root.get());
2099 2099
2100 ASSERT_TRUE(renderSurface1->renderSurface()); 2100 ASSERT_TRUE(renderSurface1->renderSurface());
2101 2101
2102 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableConte ntRect()); 2102 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect());
2103 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect()); 2103 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawableContentRect());
2104 2104
2105 // Layers that do not draw content should have empty visibleContentRects. 2105 // Layers that do not draw content should have empty visibleContentRects.
2106 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect()); 2106 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visibleContentRect());
2107 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect()); 2107 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), renderSurface1->visibleContentRect());
2108 2108
2109 // A clipped surface grows its drawableContentRect to include all drawable r egions of the subtree, 2109 // A clipped surface grows its drawableContentRect to include all drawable r egions of the subtree,
2110 // but also gets clamped by the ancestor's clip. 2110 // but also gets clamped by the ancestor's clip.
2111 EXPECT_RECT_EQ(IntRect(5, 5, 95, 95), renderSurface1->renderSurface()->drawa bleContentRect()); 2111 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95), renderSurface1->renderSurface()->dra wableContentRect());
2112 2112
2113 // All layers that draw content into the surface have their visibleContentRe ct clipped by the surface clipRect. 2113 // All layers that draw content into the surface have their visibleContentRe ct clipped by the surface clipRect.
2114 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect()); 2114 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visibleContentRect());
2115 EXPECT_RECT_EQ(IntRect(0, 0, 25, 25), child2->visibleContentRect()); 2115 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visibleContentRect());
2116 EXPECT_TRUE(child3->visibleContentRect().isEmpty()); 2116 EXPECT_TRUE(child3->visibleContentRect().IsEmpty());
2117 2117
2118 // But the drawableContentRects are unclipped. 2118 // But the drawableContentRects are unclipped.
2119 EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), child1->drawableContentRect()); 2119 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawableContentRect());
2120 EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect()); 2120 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawableContentRect());
2121 EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect()); 2121 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawableContentRect());
2122 } 2122 }
2123 2123
2124 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForSurfaceHier archy) 2124 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForSurfaceHier archy)
2125 { 2125 {
2126 // Check that clipping does not propagate down surfaces. 2126 // Check that clipping does not propagate down surfaces.
2127 scoped_refptr<Layer> root = Layer::create(); 2127 scoped_refptr<Layer> root = Layer::create();
2128 scoped_refptr<Layer> renderSurface1 = Layer::create(); 2128 scoped_refptr<Layer> renderSurface1 = Layer::create();
2129 scoped_refptr<Layer> renderSurface2 = Layer::create(); 2129 scoped_refptr<Layer> renderSurface2 = Layer::create();
2130 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2130 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2131 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2131 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2132 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2132 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2133 root->addChild(renderSurface1); 2133 root->addChild(renderSurface1);
2134 renderSurface1->addChild(renderSurface2); 2134 renderSurface1->addChild(renderSurface2);
2135 renderSurface2->addChild(child1); 2135 renderSurface2->addChild(child1);
2136 renderSurface2->addChild(child2); 2136 renderSurface2->addChild(child2);
2137 renderSurface2->addChild(child3); 2137 renderSurface2->addChild(child3);
2138 2138
2139 WebTransformationMatrix identityMatrix; 2139 WebTransformationMatrix identityMatrix;
2140 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2140 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2141 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false); 2141 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false);
2142 setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(7, 13), false); 2142 setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(7, 13), false);
2143 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false); 2143 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2144 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false); 2144 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2145 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false); 2145 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2146 2146
2147 root->setMasksToBounds(true); 2147 root->setMasksToBounds(true);
2148 renderSurface1->setForceRenderSurface(true); 2148 renderSurface1->setForceRenderSurface(true);
2149 renderSurface2->setForceRenderSurface(true); 2149 renderSurface2->setForceRenderSurface(true);
2150 executeCalculateDrawTransformsAndVisibility(root.get()); 2150 executeCalculateDrawTransformsAndVisibility(root.get());
2151 2151
2152 ASSERT_TRUE(renderSurface1->renderSurface()); 2152 ASSERT_TRUE(renderSurface1->renderSurface());
2153 ASSERT_TRUE(renderSurface2->renderSurface()); 2153 ASSERT_TRUE(renderSurface2->renderSurface());
2154 2154
2155 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableConte ntRect()); 2155 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect());
2156 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect()); 2156 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawableContentRect());
2157 2157
2158 // Layers that do not draw content should have empty visibleContentRects. 2158 // Layers that do not draw content should have empty visibleContentRects.
2159 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect()); 2159 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visibleContentRect());
2160 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect()); 2160 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), renderSurface1->visibleContentRect());
2161 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface2->visibleContentRect()); 2161 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), renderSurface2->visibleContentRect());
2162 2162
2163 // A clipped surface grows its drawableContentRect to include all drawable r egions of the subtree, 2163 // A clipped surface grows its drawableContentRect to include all drawable r egions of the subtree,
2164 // but also gets clamped by the ancestor's clip. 2164 // but also gets clamped by the ancestor's clip.
2165 EXPECT_RECT_EQ(IntRect(5, 5, 95, 95), renderSurface1->renderSurface()->drawa bleContentRect()); 2165 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95), renderSurface1->renderSurface()->dra wableContentRect());
2166 2166
2167 // renderSurface1 lives in the "unclipped universe" of renderSurface1, and i s only 2167 // renderSurface1 lives in the "unclipped universe" of renderSurface1, and i s only
2168 // implicitly clipped by renderSurface1's contentRect. So, renderSurface2 gr ows to 2168 // implicitly clipped by renderSurface1's contentRect. So, renderSurface2 gr ows to
2169 // enclose all drawable content of its subtree. 2169 // enclose all drawable content of its subtree.
2170 EXPECT_RECT_EQ(IntRect(5, 5, 170, 170), renderSurface2->renderSurface()->dra wableContentRect()); 2170 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170), renderSurface2->renderSurface()->d rawableContentRect());
2171 2171
2172 // All layers that draw content into renderSurface2 think they are unclipped . 2172 // All layers that draw content into renderSurface2 think they are unclipped .
2173 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect()); 2173 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visibleContentRect());
2174 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child2->visibleContentRect()); 2174 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visibleContentRect());
2175 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child3->visibleContentRect()); 2175 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visibleContentRect());
2176 2176
2177 // drawableContentRects are also unclipped. 2177 // drawableContentRects are also unclipped.
2178 EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), child1->drawableContentRect()); 2178 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawableContentRect());
2179 EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect()); 2179 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawableContentRect());
2180 EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect()); 2180 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawableContentRect());
2181 } 2181 }
2182 2182
2183 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsWithTransformO nUnclippedSurface) 2183 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsWithTransformO nUnclippedSurface)
2184 { 2184 {
2185 // Layers that have non-axis aligned bounds (due to transforms) have an expa nded, 2185 // Layers that have non-axis aligned bounds (due to transforms) have an expa nded,
2186 // axis-aligned drawableContentRect and visibleContentRect. 2186 // axis-aligned drawableContentRect and visibleContentRect.
2187 2187
2188 scoped_refptr<Layer> root = Layer::create(); 2188 scoped_refptr<Layer> root = Layer::create();
2189 scoped_refptr<Layer> renderSurface1 = Layer::create(); 2189 scoped_refptr<Layer> renderSurface1 = Layer::create();
2190 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2190 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2191 root->addChild(renderSurface1); 2191 root->addChild(renderSurface1);
2192 renderSurface1->addChild(child1); 2192 renderSurface1->addChild(child1);
2193 2193
2194 WebTransformationMatrix identityMatrix; 2194 WebTransformationMatrix identityMatrix;
2195 WebTransformationMatrix childRotation; 2195 WebTransformationMatrix childRotation;
2196 childRotation.rotate(45); 2196 childRotation.rotate(45);
2197 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2197 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2198 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false); 2198 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false);
2199 setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, Fl oatPoint(0.5, 0.5), FloatPoint(25, 25), IntSize(50, 50), false); 2199 setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, gf x::PointF(0.5, 0.5), gfx::PointF(25, 25), gfx::Size(50, 50), false);
2200 2200
2201 renderSurface1->setForceRenderSurface(true); 2201 renderSurface1->setForceRenderSurface(true);
2202 executeCalculateDrawTransformsAndVisibility(root.get()); 2202 executeCalculateDrawTransformsAndVisibility(root.get());
2203 2203
2204 ASSERT_TRUE(renderSurface1->renderSurface()); 2204 ASSERT_TRUE(renderSurface1->renderSurface());
2205 2205
2206 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableConte ntRect()); 2206 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect());
2207 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect()); 2207 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawableContentRect());
2208 2208
2209 // Layers that do not draw content should have empty visibleContentRects. 2209 // Layers that do not draw content should have empty visibleContentRects.
2210 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect()); 2210 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visibleContentRect());
2211 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect()); 2211 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), renderSurface1->visibleContentRect());
2212 2212
2213 // The unclipped surface grows its drawableContentRect to include all drawab le regions of the subtree. 2213 // The unclipped surface grows its drawableContentRect to include all drawab le regions of the subtree.
2214 int diagonalRadius = ceil(sqrt(2.0) * 25); 2214 int diagonalRadius = ceil(sqrt(2.0) * 25);
2215 IntRect expectedSurfaceDrawableContent = IntRect(50 - diagonalRadius, 50 - d iagonalRadius, diagonalRadius * 2, diagonalRadius * 2); 2215 gfx::Rect expectedSurfaceDrawableContent = gfx::Rect(50 - diagonalRadius, 50 - diagonalRadius, diagonalRadius * 2, diagonalRadius * 2);
2216 EXPECT_RECT_EQ(expectedSurfaceDrawableContent, renderSurface1->renderSurface ()->drawableContentRect()); 2216 EXPECT_RECT_EQ(expectedSurfaceDrawableContent, renderSurface1->renderSurface ()->drawableContentRect());
2217 2217
2218 // All layers that draw content into the unclipped surface are also unclippe d. 2218 // All layers that draw content into the unclipped surface are also unclippe d.
2219 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect()); 2219 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visibleContentRect());
2220 EXPECT_RECT_EQ(expectedSurfaceDrawableContent, child1->drawableContentRect() ); 2220 EXPECT_RECT_EQ(expectedSurfaceDrawableContent, child1->drawableContentRect() );
2221 } 2221 }
2222 2222
2223 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsWithTransformO nClippedSurface) 2223 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsWithTransformO nClippedSurface)
2224 { 2224 {
2225 // Layers that have non-axis aligned bounds (due to transforms) have an expa nded, 2225 // Layers that have non-axis aligned bounds (due to transforms) have an expa nded,
2226 // axis-aligned drawableContentRect and visibleContentRect. 2226 // axis-aligned drawableContentRect and visibleContentRect.
2227 2227
2228 scoped_refptr<Layer> root = Layer::create(); 2228 scoped_refptr<Layer> root = Layer::create();
2229 scoped_refptr<Layer> renderSurface1 = Layer::create(); 2229 scoped_refptr<Layer> renderSurface1 = Layer::create();
2230 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2230 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2231 root->addChild(renderSurface1); 2231 root->addChild(renderSurface1);
2232 renderSurface1->addChild(child1); 2232 renderSurface1->addChild(child1);
2233 2233
2234 WebTransformationMatrix identityMatrix; 2234 WebTransformationMatrix identityMatrix;
2235 WebTransformationMatrix childRotation; 2235 WebTransformationMatrix childRotation;
2236 childRotation.rotate(45); 2236 childRotation.rotate(45);
2237 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(50, 50), false); 2237 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(50, 50), false);
2238 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false); 2238 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false);
2239 setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, Fl oatPoint(0.5, 0.5), FloatPoint(25, 25), IntSize(50, 50), false); 2239 setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, gf x::PointF(0.5, 0.5), gfx::PointF(25, 25), gfx::Size(50, 50), false);
2240 2240
2241 root->setMasksToBounds(true); 2241 root->setMasksToBounds(true);
2242 renderSurface1->setForceRenderSurface(true); 2242 renderSurface1->setForceRenderSurface(true);
2243 executeCalculateDrawTransformsAndVisibility(root.get()); 2243 executeCalculateDrawTransformsAndVisibility(root.get());
2244 2244
2245 ASSERT_TRUE(renderSurface1->renderSurface()); 2245 ASSERT_TRUE(renderSurface1->renderSurface());
2246 2246
2247 // The clipped surface clamps the drawableContentRect that encloses the rota ted layer. 2247 // The clipped surface clamps the drawableContentRect that encloses the rota ted layer.
2248 int diagonalRadius = ceil(sqrt(2.0) * 25); 2248 int diagonalRadius = ceil(sqrt(2.0) * 25);
2249 IntRect unclippedSurfaceContent = IntRect(50 - diagonalRadius, 50 - diagonal Radius, diagonalRadius * 2, diagonalRadius * 2); 2249 gfx::Rect unclippedSurfaceContent = gfx::Rect(50 - diagonalRadius, 50 - diag onalRadius, diagonalRadius * 2, diagonalRadius * 2);
2250 IntRect expectedSurfaceDrawableContent = intersection(unclippedSurfaceConten t, IntRect(0, 0, 50, 50)); 2250 gfx::Rect expectedSurfaceDrawableContent = gfx::IntersectRects(unclippedSurf aceContent, gfx::Rect(0, 0, 50, 50));
2251 EXPECT_RECT_EQ(expectedSurfaceDrawableContent, renderSurface1->renderSurface ()->drawableContentRect()); 2251 EXPECT_RECT_EQ(expectedSurfaceDrawableContent, renderSurface1->renderSurface ()->drawableContentRect());
2252 2252
2253 // On the clipped surface, only a quarter of the child1 is visible, but whe n rotating 2253 // On the clipped surface, only a quarter of the child1 is visible, but whe n rotating
2254 // it back to child1's content space, the actual enclosing rect ends up cov ering the 2254 // it back to child1's content space, the actual enclosing rect ends up cov ering the
2255 // full left half of child1. 2255 // full left half of child1.
2256 EXPECT_RECT_EQ(IntRect(0, 0, 26, 50), child1->visibleContentRect()); 2256 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visibleContentRect());
2257 2257
2258 // The child's drawableContentRect is unclipped. 2258 // The child's drawableContentRect is unclipped.
2259 EXPECT_RECT_EQ(unclippedSurfaceContent, child1->drawableContentRect()); 2259 EXPECT_RECT_EQ(unclippedSurfaceContent, child1->drawableContentRect());
2260 } 2260 }
2261 2261
2262 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsInHighDPI) 2262 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsInHighDPI)
2263 { 2263 {
2264 MockContentLayerClient client; 2264 MockContentLayerClient client;
2265 2265
2266 scoped_refptr<Layer> root = Layer::create(); 2266 scoped_refptr<Layer> root = Layer::create();
2267 scoped_refptr<ContentLayer> renderSurface1 = createDrawableContentLayer(&cli ent); 2267 scoped_refptr<ContentLayer> renderSurface1 = createDrawableContentLayer(&cli ent);
2268 scoped_refptr<ContentLayer> renderSurface2 = createDrawableContentLayer(&cli ent); 2268 scoped_refptr<ContentLayer> renderSurface2 = createDrawableContentLayer(&cli ent);
2269 scoped_refptr<ContentLayer> child1 = createDrawableContentLayer(&client); 2269 scoped_refptr<ContentLayer> child1 = createDrawableContentLayer(&client);
2270 scoped_refptr<ContentLayer> child2 = createDrawableContentLayer(&client); 2270 scoped_refptr<ContentLayer> child2 = createDrawableContentLayer(&client);
2271 scoped_refptr<ContentLayer> child3 = createDrawableContentLayer(&client); 2271 scoped_refptr<ContentLayer> child3 = createDrawableContentLayer(&client);
2272 root->addChild(renderSurface1); 2272 root->addChild(renderSurface1);
2273 renderSurface1->addChild(renderSurface2); 2273 renderSurface1->addChild(renderSurface2);
2274 renderSurface2->addChild(child1); 2274 renderSurface2->addChild(child1);
2275 renderSurface2->addChild(child2); 2275 renderSurface2->addChild(child2);
2276 renderSurface2->addChild(child3); 2276 renderSurface2->addChild(child3);
2277 2277
2278 WebTransformationMatrix identityMatrix; 2278 WebTransformationMatrix identityMatrix;
2279 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2279 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2280 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(3, 4), false); 2280 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(3, 4), false);
2281 setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(7, 13), false); 2281 setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(7, 13), false);
2282 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false); 2282 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2283 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false); 2283 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2284 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false); 2284 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2285 2285
2286 const double deviceScaleFactor = 2; 2286 const double deviceScaleFactor = 2;
2287 root->setContentsScale(deviceScaleFactor); 2287 root->setContentsScale(deviceScaleFactor);
2288 renderSurface1->setContentsScale(deviceScaleFactor); 2288 renderSurface1->setContentsScale(deviceScaleFactor);
2289 renderSurface2->setContentsScale(deviceScaleFactor); 2289 renderSurface2->setContentsScale(deviceScaleFactor);
2290 child1->setContentsScale(deviceScaleFactor); 2290 child1->setContentsScale(deviceScaleFactor);
2291 child2->setContentsScale(deviceScaleFactor); 2291 child2->setContentsScale(deviceScaleFactor);
2292 child3->setContentsScale(deviceScaleFactor); 2292 child3->setContentsScale(deviceScaleFactor);
2293 2293
2294 root->setMasksToBounds(true); 2294 root->setMasksToBounds(true);
2295 renderSurface1->setForceRenderSurface(true); 2295 renderSurface1->setForceRenderSurface(true);
2296 renderSurface2->setForceRenderSurface(true); 2296 renderSurface2->setForceRenderSurface(true);
2297 executeCalculateDrawTransformsAndVisibility(root.get(), deviceScaleFactor); 2297 executeCalculateDrawTransformsAndVisibility(root.get(), deviceScaleFactor);
2298 2298
2299 ASSERT_TRUE(renderSurface1->renderSurface()); 2299 ASSERT_TRUE(renderSurface1->renderSurface());
2300 ASSERT_TRUE(renderSurface2->renderSurface()); 2300 ASSERT_TRUE(renderSurface2->renderSurface());
2301 2301
2302 // DrawableContentRects for all layers and surfaces are scaled by deviceScal eFactor. 2302 // DrawableContentRects for all layers and surfaces are scaled by deviceScal eFactor.
2303 EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), root->renderSurface()->drawableConte ntRect()); 2303 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->renderSurface()->drawableCon tentRect());
2304 EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), root->drawableContentRect()); 2304 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawableContentRect());
2305 EXPECT_RECT_EQ(IntRect(10, 10, 190, 190), renderSurface1->renderSurface()->d rawableContentRect()); 2305 EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190), renderSurface1->renderSurface()- >drawableContentRect());
2306 2306
2307 // renderSurface2 lives in the "unclipped universe" of renderSurface1, and 2307 // renderSurface2 lives in the "unclipped universe" of renderSurface1, and
2308 // is only implicitly clipped by renderSurface1. 2308 // is only implicitly clipped by renderSurface1.
2309 EXPECT_RECT_EQ(IntRect(10, 10, 350, 350), renderSurface2->renderSurface()->d rawableContentRect()); 2309 EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350), renderSurface2->renderSurface()- >drawableContentRect());
2310 2310
2311 EXPECT_RECT_EQ(IntRect(10, 10, 100, 100), child1->drawableContentRect()); 2311 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawableContentRect());
2312 EXPECT_RECT_EQ(IntRect(150, 150, 100, 100), child2->drawableContentRect()); 2312 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawableContentRect()) ;
2313 EXPECT_RECT_EQ(IntRect(250, 250, 100, 100), child3->drawableContentRect()); 2313 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawableContentRect()) ;
2314 2314
2315 // The root layer does not actually draw content of its own. 2315 // The root layer does not actually draw content of its own.
2316 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect()); 2316 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visibleContentRect());
2317 2317
2318 // All layer visibleContentRects are expressed in content space of each 2318 // All layer visibleContentRects are expressed in content space of each
2319 // layer, so they are also scaled by the deviceScaleFactor. 2319 // layer, so they are also scaled by the deviceScaleFactor.
2320 EXPECT_RECT_EQ(IntRect(0, 0, 6, 8), renderSurface1->visibleContentRect()); 2320 EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8), renderSurface1->visibleContentRect());
2321 EXPECT_RECT_EQ(IntRect(0, 0, 14, 26), renderSurface2->visibleContentRect()); 2321 EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26), renderSurface2->visibleContentRect() );
2322 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), child1->visibleContentRect()); 2322 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visibleContentRect());
2323 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), child2->visibleContentRect()); 2323 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visibleContentRect());
2324 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), child3->visibleContentRect()); 2324 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visibleContentRect());
2325 } 2325 }
2326 2326
2327 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithoutPreserves3d) 2327 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithoutPreserves3d)
2328 { 2328 {
2329 // Verify the behavior of back-face culling when there are no preserve-3d la yers. Note 2329 // Verify the behavior of back-face culling when there are no preserve-3d la yers. Note
2330 // that 3d transforms still apply in this case, but they are "flattened" to each 2330 // that 3d transforms still apply in this case, but they are "flattened" to each
2331 // parent layer according to current W3C spec. 2331 // parent layer according to current W3C spec.
2332 2332
2333 const WebTransformationMatrix identityMatrix; 2333 const WebTransformationMatrix identityMatrix;
2334 scoped_refptr<Layer> parent = Layer::create(); 2334 scoped_refptr<Layer> parent = Layer::create();
(...skipping 29 matching lines...) Expand all
2364 backfaceMatrix.translate(50, 50); 2364 backfaceMatrix.translate(50, 50);
2365 backfaceMatrix.rotate3d(0, 1, 0, 180); 2365 backfaceMatrix.rotate3d(0, 1, 0, 180);
2366 backfaceMatrix.translate(-50, -50); 2366 backfaceMatrix.translate(-50, -50);
2367 2367
2368 // Having a descendant and opacity will force these to have render surfaces. 2368 // Having a descendant and opacity will force these to have render surfaces.
2369 frontFacingSurface->setOpacity(0.5); 2369 frontFacingSurface->setOpacity(0.5);
2370 backFacingSurface->setOpacity(0.5); 2370 backFacingSurface->setOpacity(0.5);
2371 2371
2372 // Nothing preserves 3d. According to current W3C CSS Transforms spec, these layers 2372 // Nothing preserves 3d. According to current W3C CSS Transforms spec, these layers
2373 // should blindly use their own local transforms to determine back-face cull ing. 2373 // should blindly use their own local transforms to determine back-face cull ing.
2374 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2374 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2375 setLayerPropertiesForTesting(frontFacingChild.get(), identityMatrix, identit yMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2375 setLayerPropertiesForTesting(frontFacingChild.get(), identityMatrix, identit yMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2376 setLayerPropertiesForTesting(backFacingChild.get(), backfaceMatrix, identity Matrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2376 setLayerPropertiesForTesting(backFacingChild.get(), backfaceMatrix, identity Matrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2377 setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, ident ityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2377 setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, ident ityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2378 setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, identi tyMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2378 setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, identi tyMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2379 setLayerPropertiesForTesting(frontFacingChildOfFrontFacingSurface.get(), ide ntityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 10 0), false); 2379 setLayerPropertiesForTesting(frontFacingChildOfFrontFacingSurface.get(), ide ntityMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100 , 100), false);
2380 setLayerPropertiesForTesting(backFacingChildOfFrontFacingSurface.get(), back faceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100 ), false); 2380 setLayerPropertiesForTesting(backFacingChildOfFrontFacingSurface.get(), back faceMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2381 setLayerPropertiesForTesting(frontFacingChildOfBackFacingSurface.get(), iden tityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100 ), false); 2381 setLayerPropertiesForTesting(frontFacingChildOfBackFacingSurface.get(), iden tityMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2382 setLayerPropertiesForTesting(backFacingChildOfBackFacingSurface.get(), backf aceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100) , false); 2382 setLayerPropertiesForTesting(backFacingChildOfBackFacingSurface.get(), backf aceMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2383 2383
2384 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 2384 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
2385 int dummyMaxTextureSize = 512; 2385 int dummyMaxTextureSize = 512;
2386 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 2386 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
2387 2387
2388 // Verify which renderSurfaces were created. 2388 // Verify which renderSurfaces were created.
2389 EXPECT_FALSE(frontFacingChild->renderSurface()); 2389 EXPECT_FALSE(frontFacingChild->renderSurface());
2390 EXPECT_FALSE(backFacingChild->renderSurface()); 2390 EXPECT_FALSE(backFacingChild->renderSurface());
2391 EXPECT_TRUE(frontFacingSurface->renderSurface()); 2391 EXPECT_TRUE(frontFacingSurface->renderSurface());
2392 EXPECT_TRUE(backFacingSurface->renderSurface()); 2392 EXPECT_TRUE(backFacingSurface->renderSurface());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2463 // preserve-3d transform style. Instead, an example of when a surface would be 2463 // preserve-3d transform style. Instead, an example of when a surface would be
2464 // created with preserve-3d is when there is a replica layer. 2464 // created with preserve-3d is when there is a replica layer.
2465 frontFacingSurface->setReplicaLayer(dummyReplicaLayer1.get()); 2465 frontFacingSurface->setReplicaLayer(dummyReplicaLayer1.get());
2466 backFacingSurface->setReplicaLayer(dummyReplicaLayer2.get()); 2466 backFacingSurface->setReplicaLayer(dummyReplicaLayer2.get());
2467 2467
2468 // Each surface creates its own new 3d rendering context (as defined by W3C spec). 2468 // Each surface creates its own new 3d rendering context (as defined by W3C spec).
2469 // According to current W3C CSS Transforms spec, layers in a 3d rendering co ntext 2469 // According to current W3C CSS Transforms spec, layers in a 3d rendering co ntext
2470 // should use the transform with respect to that context. This 3d rendering context 2470 // should use the transform with respect to that context. This 3d rendering context
2471 // occurs when (a) parent's transform style is flat and (b) the layer's tran sform 2471 // occurs when (a) parent's transform style is flat and (b) the layer's tran sform
2472 // style is preserve-3d. 2472 // style is preserve-3d.
2473 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); // parent transfor m style is flat. 2473 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); // parent tran sform style is flat.
2474 setLayerPropertiesForTesting(frontFacingChild.get(), identityMatrix, identit yMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2474 setLayerPropertiesForTesting(frontFacingChild.get(), identityMatrix, identit yMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2475 setLayerPropertiesForTesting(backFacingChild.get(), backfaceMatrix, identity Matrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2475 setLayerPropertiesForTesting(backFacingChild.get(), backfaceMatrix, identity Matrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2476 setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, ident ityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); // surf ace transform style is preserve-3d. 2476 setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, ident ityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true); // surface transform style is preserve-3d.
2477 setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, identi tyMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); // surfa ce transform style is preserve-3d. 2477 setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, identi tyMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true); // s urface transform style is preserve-3d.
2478 setLayerPropertiesForTesting(frontFacingChildOfFrontFacingSurface.get(), ide ntityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 10 0), false); 2478 setLayerPropertiesForTesting(frontFacingChildOfFrontFacingSurface.get(), ide ntityMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100 , 100), false);
2479 setLayerPropertiesForTesting(backFacingChildOfFrontFacingSurface.get(), back faceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100 ), false); 2479 setLayerPropertiesForTesting(backFacingChildOfFrontFacingSurface.get(), back faceMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2480 setLayerPropertiesForTesting(frontFacingChildOfBackFacingSurface.get(), iden tityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100 ), false); 2480 setLayerPropertiesForTesting(frontFacingChildOfBackFacingSurface.get(), iden tityMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2481 setLayerPropertiesForTesting(backFacingChildOfBackFacingSurface.get(), backf aceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100) , false); 2481 setLayerPropertiesForTesting(backFacingChildOfBackFacingSurface.get(), backf aceMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2482 2482
2483 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 2483 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
2484 int dummyMaxTextureSize = 512; 2484 int dummyMaxTextureSize = 512;
2485 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 2485 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
2486 2486
2487 // Verify which renderSurfaces were created. 2487 // Verify which renderSurfaces were created.
2488 EXPECT_FALSE(frontFacingChild->renderSurface()); 2488 EXPECT_FALSE(frontFacingChild->renderSurface());
2489 EXPECT_FALSE(backFacingChild->renderSurface()); 2489 EXPECT_FALSE(backFacingChild->renderSurface());
2490 EXPECT_TRUE(frontFacingSurface->renderSurface()); 2490 EXPECT_TRUE(frontFacingSurface->renderSurface());
2491 EXPECT_FALSE(backFacingSurface->renderSurface()); 2491 EXPECT_FALSE(backFacingSurface->renderSurface());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 backfaceMatrix.translate(-50, -50); 2546 backfaceMatrix.translate(-50, -50);
2547 2547
2548 // Make our render surface. 2548 // Make our render surface.
2549 animatingSurface->setForceRenderSurface(true); 2549 animatingSurface->setForceRenderSurface(true);
2550 2550
2551 // Animate the transform on the render surface. 2551 // Animate the transform on the render surface.
2552 addAnimatedTransformToController(*animatingSurface->layerAnimationController (), 10, 30, 0); 2552 addAnimatedTransformToController(*animatingSurface->layerAnimationController (), 10, 30, 0);
2553 // This is just an animating layer, not a surface. 2553 // This is just an animating layer, not a surface.
2554 addAnimatedTransformToController(*animatingChild->layerAnimationController() , 10, 30, 0); 2554 addAnimatedTransformToController(*animatingChild->layerAnimationController() , 10, 30, 0);
2555 2555
2556 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2556 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2557 setLayerPropertiesForTesting(child.get(), backfaceMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2557 setLayerPropertiesForTesting(child.get(), backfaceMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2558 setLayerPropertiesForTesting(animatingSurface.get(), backfaceMatrix, identit yMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2558 setLayerPropertiesForTesting(animatingSurface.get(), backfaceMatrix, identit yMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2559 setLayerPropertiesForTesting(childOfAnimatingSurface.get(), backfaceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2559 setLayerPropertiesForTesting(childOfAnimatingSurface.get(), backfaceMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false );
2560 setLayerPropertiesForTesting(animatingChild.get(), backfaceMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2560 setLayerPropertiesForTesting(animatingChild.get(), backfaceMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2561 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2561 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2562 2562
2563 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 2563 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
2564 int dummyMaxTextureSize = 512; 2564 int dummyMaxTextureSize = 512;
2565 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 2565 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
2566 2566
2567 EXPECT_FALSE(child->renderSurface()); 2567 EXPECT_FALSE(child->renderSurface());
2568 EXPECT_TRUE(animatingSurface->renderSurface()); 2568 EXPECT_TRUE(animatingSurface->renderSurface());
2569 EXPECT_FALSE(childOfAnimatingSurface->renderSurface()); 2569 EXPECT_FALSE(childOfAnimatingSurface->renderSurface());
2570 EXPECT_FALSE(animatingChild->renderSurface()); 2570 EXPECT_FALSE(animatingChild->renderSurface());
2571 EXPECT_FALSE(child2->renderSurface()); 2571 EXPECT_FALSE(child2->renderSurface());
2572 2572
2573 // Verify that the animatingChild and childOfAnimatingSurface were not culle d, but that child was. 2573 // Verify that the animatingChild and childOfAnimatingSurface were not culle d, but that child was.
2574 ASSERT_EQ(2u, renderSurfaceLayerList.size()); 2574 ASSERT_EQ(2u, renderSurfaceLayerList.size());
2575 EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id()); 2575 EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
2576 EXPECT_EQ(animatingSurface->id(), renderSurfaceLayerList[1]->id()); 2576 EXPECT_EQ(animatingSurface->id(), renderSurfaceLayerList[1]->id());
2577 2577
2578 // The non-animating child be culled from the layer list for the parent rend er surface. 2578 // The non-animating child be culled from the layer list for the parent rend er surface.
2579 ASSERT_EQ(3u, renderSurfaceLayerList[0]->renderSurface()->layerList().size() ); 2579 ASSERT_EQ(3u, renderSurfaceLayerList[0]->renderSurface()->layerList().size() );
2580 EXPECT_EQ(animatingSurface->id(), renderSurfaceLayerList[0]->renderSurface() ->layerList()[0]->id()); 2580 EXPECT_EQ(animatingSurface->id(), renderSurfaceLayerList[0]->renderSurface() ->layerList()[0]->id());
2581 EXPECT_EQ(animatingChild->id(), renderSurfaceLayerList[0]->renderSurface()-> layerList()[1]->id()); 2581 EXPECT_EQ(animatingChild->id(), renderSurfaceLayerList[0]->renderSurface()-> layerList()[1]->id());
2582 EXPECT_EQ(child2->id(), renderSurfaceLayerList[0]->renderSurface()->layerLis t()[2]->id()); 2582 EXPECT_EQ(child2->id(), renderSurfaceLayerList[0]->renderSurface()->layerLis t()[2]->id());
2583 2583
2584 ASSERT_EQ(2u, renderSurfaceLayerList[1]->renderSurface()->layerList().size() ); 2584 ASSERT_EQ(2u, renderSurfaceLayerList[1]->renderSurface()->layerList().size() );
2585 EXPECT_EQ(animatingSurface->id(), renderSurfaceLayerList[1]->renderSurface() ->layerList()[0]->id()); 2585 EXPECT_EQ(animatingSurface->id(), renderSurfaceLayerList[1]->renderSurface() ->layerList()[0]->id());
2586 EXPECT_EQ(childOfAnimatingSurface->id(), renderSurfaceLayerList[1]->renderSu rface()->layerList()[1]->id()); 2586 EXPECT_EQ(childOfAnimatingSurface->id(), renderSurfaceLayerList[1]->renderSu rface()->layerList()[1]->id());
2587 2587
2588 EXPECT_FALSE(child2->visibleContentRect().isEmpty()); 2588 EXPECT_FALSE(child2->visibleContentRect().IsEmpty());
2589 2589
2590 // The animating layers should have a visibleContentRect that represents the area of the front face that is within the viewport. 2590 // The animating layers should have a visibleContentRect that represents the area of the front face that is within the viewport.
2591 EXPECT_EQ(animatingChild->visibleContentRect(), IntRect(IntPoint(), animatin gChild->contentBounds())); 2591 EXPECT_EQ(animatingChild->visibleContentRect(), gfx::Rect(gfx::Point(), anim atingChild->contentBounds()));
2592 EXPECT_EQ(animatingSurface->visibleContentRect(), IntRect(IntPoint(), animat ingSurface->contentBounds())); 2592 EXPECT_EQ(animatingSurface->visibleContentRect(), gfx::Rect(gfx::Point(), an imatingSurface->contentBounds()));
2593 // And layers in the subtree of the animating layer should have valid visibl eContentRects also. 2593 // And layers in the subtree of the animating layer should have valid visibl eContentRects also.
2594 EXPECT_EQ(childOfAnimatingSurface->visibleContentRect(), IntRect(IntPoint(), childOfAnimatingSurface->contentBounds())); 2594 EXPECT_EQ(childOfAnimatingSurface->visibleContentRect(), gfx::Rect(gfx::Poin t(), childOfAnimatingSurface->contentBounds()));
2595 } 2595 }
2596 2596
2597 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3dForFlatteningS urface) 2597 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3dForFlatteningS urface)
2598 { 2598 {
2599 // Verify the behavior of back-face culling for a renderSurface that is crea ted 2599 // Verify the behavior of back-face culling for a renderSurface that is crea ted
2600 // when it flattens its subtree, and its parent has preserves-3d. 2600 // when it flattens its subtree, and its parent has preserves-3d.
2601 2601
2602 const WebTransformationMatrix identityMatrix; 2602 const WebTransformationMatrix identityMatrix;
2603 scoped_refptr<Layer> parent = Layer::create(); 2603 scoped_refptr<Layer> parent = Layer::create();
2604 scoped_refptr<LayerWithForcedDrawsContent> frontFacingSurface = make_scoped_ refptr(new LayerWithForcedDrawsContent()); 2604 scoped_refptr<LayerWithForcedDrawsContent> frontFacingSurface = make_scoped_ refptr(new LayerWithForcedDrawsContent());
2605 scoped_refptr<LayerWithForcedDrawsContent> backFacingSurface = make_scoped_r efptr(new LayerWithForcedDrawsContent()); 2605 scoped_refptr<LayerWithForcedDrawsContent> backFacingSurface = make_scoped_r efptr(new LayerWithForcedDrawsContent());
2606 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2606 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2607 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2607 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2608 2608
2609 parent->addChild(frontFacingSurface); 2609 parent->addChild(frontFacingSurface);
2610 parent->addChild(backFacingSurface); 2610 parent->addChild(backFacingSurface);
2611 frontFacingSurface->addChild(child1); 2611 frontFacingSurface->addChild(child1);
2612 backFacingSurface->addChild(child2); 2612 backFacingSurface->addChild(child2);
2613 2613
2614 // RenderSurfaces are not double-sided 2614 // RenderSurfaces are not double-sided
2615 frontFacingSurface->setDoubleSided(false); 2615 frontFacingSurface->setDoubleSided(false);
2616 backFacingSurface->setDoubleSided(false); 2616 backFacingSurface->setDoubleSided(false);
2617 2617
2618 WebTransformationMatrix backfaceMatrix; 2618 WebTransformationMatrix backfaceMatrix;
2619 backfaceMatrix.translate(50, 50); 2619 backfaceMatrix.translate(50, 50);
2620 backfaceMatrix.rotate3d(0, 1, 0, 180); 2620 backfaceMatrix.rotate3d(0, 1, 0, 180);
2621 backfaceMatrix.translate(-50, -50); 2621 backfaceMatrix.translate(-50, -50);
2622 2622
2623 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); // parent transform style is preserve3d. 2623 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.
2624 setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, ident ityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); // sur face transform style is flat. 2624 setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, ident ityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); // surface transform style is flat.
2625 setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, ident ityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); // sur face transform style is flat. 2625 setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, ident ityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); // surface transform style is flat.
2626 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2626 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2627 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2627 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2628 2628
2629 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 2629 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
2630 int dummyMaxTextureSize = 512; 2630 int dummyMaxTextureSize = 512;
2631 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 2631 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
2632 2632
2633 // Verify which renderSurfaces were created. 2633 // Verify which renderSurfaces were created.
2634 EXPECT_TRUE(frontFacingSurface->renderSurface()); 2634 EXPECT_TRUE(frontFacingSurface->renderSurface());
2635 EXPECT_FALSE(backFacingSurface->renderSurface()); // because it should be cu lled 2635 EXPECT_FALSE(backFacingSurface->renderSurface()); // because it should be cu lled
2636 EXPECT_FALSE(child1->renderSurface()); 2636 EXPECT_FALSE(child1->renderSurface());
2637 EXPECT_FALSE(child2->renderSurface()); 2637 EXPECT_FALSE(child2->renderSurface());
(...skipping 13 matching lines...) Expand all
2651 EXPECT_EQ(child1->id(), renderSurfaceLayerList[1]->renderSurface()->layerLis t()[1]->id()); 2651 EXPECT_EQ(child1->id(), renderSurfaceLayerList[1]->renderSurface()->layerLis t()[1]->id());
2652 } 2652 }
2653 2653
2654 TEST(LayerTreeHostCommonTest, verifyHitTestingForEmptyLayerList) 2654 TEST(LayerTreeHostCommonTest, verifyHitTestingForEmptyLayerList)
2655 { 2655 {
2656 // Hit testing on an empty renderSurfaceLayerList should return a null point er. 2656 // Hit testing on an empty renderSurfaceLayerList should return a null point er.
2657 DebugScopedSetImplThread thisScopeIsOnImplThread; 2657 DebugScopedSetImplThread thisScopeIsOnImplThread;
2658 2658
2659 std::vector<LayerImpl*> renderSurfaceLayerList; 2659 std::vector<LayerImpl*> renderSurfaceLayerList;
2660 2660
2661 IntPoint testPoint(0, 0); 2661 gfx::Point testPoint(0, 0);
2662 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 2662 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
2663 EXPECT_FALSE(resultLayer); 2663 EXPECT_FALSE(resultLayer);
2664 2664
2665 testPoint = IntPoint(10, 20); 2665 testPoint = gfx::Point(10, 20);
2666 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2666 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2667 EXPECT_FALSE(resultLayer); 2667 EXPECT_FALSE(resultLayer);
2668 } 2668 }
2669 2669
2670 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayer) 2670 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayer)
2671 { 2671 {
2672 DebugScopedSetImplThread thisScopeIsOnImplThread; 2672 DebugScopedSetImplThread thisScopeIsOnImplThread;
2673 2673
2674 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 2674 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
2675 2675
2676 WebTransformationMatrix identityMatrix; 2676 WebTransformationMatrix identityMatrix;
2677 FloatPoint anchor(0, 0); 2677 gfx::PointF anchor(0, 0);
2678 FloatPoint position(0, 0); 2678 gfx::PointF position(0, 0);
2679 IntSize bounds(100, 100); 2679 gfx::Size bounds(100, 100);
2680 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 2680 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
2681 root->setDrawsContent(true); 2681 root->setDrawsContent(true);
2682 2682
2683 std::vector<LayerImpl*> renderSurfaceLayerList; 2683 std::vector<LayerImpl*> renderSurfaceLayerList;
2684 int dummyMaxTextureSize = 512; 2684 int dummyMaxTextureSize = 512;
2685 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2685 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2686 2686
2687 // Sanity check the scenario we just created. 2687 // Sanity check the scenario we just created.
2688 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 2688 ASSERT_EQ(1u, renderSurfaceLayerList.size());
2689 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 2689 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
2690 2690
2691 // Hit testing for a point outside the layer should return a null pointer. 2691 // Hit testing for a point outside the layer should return a null pointer.
2692 IntPoint testPoint(101, 101); 2692 gfx::Point testPoint(101, 101);
2693 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 2693 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
2694 EXPECT_FALSE(resultLayer); 2694 EXPECT_FALSE(resultLayer);
2695 2695
2696 testPoint = IntPoint(-1, -1); 2696 testPoint = gfx::Point(-1, -1);
2697 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2697 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2698 EXPECT_FALSE(resultLayer); 2698 EXPECT_FALSE(resultLayer);
2699 2699
2700 // Hit testing for a point inside should return the root layer. 2700 // Hit testing for a point inside should return the root layer.
2701 testPoint = IntPoint(1, 1); 2701 testPoint = gfx::Point(1, 1);
2702 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2702 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2703 ASSERT_TRUE(resultLayer); 2703 ASSERT_TRUE(resultLayer);
2704 EXPECT_EQ(12345, resultLayer->id()); 2704 EXPECT_EQ(12345, resultLayer->id());
2705 2705
2706 testPoint = IntPoint(99, 99); 2706 testPoint = gfx::Point(99, 99);
2707 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2707 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2708 ASSERT_TRUE(resultLayer); 2708 ASSERT_TRUE(resultLayer);
2709 EXPECT_EQ(12345, resultLayer->id()); 2709 EXPECT_EQ(12345, resultLayer->id());
2710 } 2710 }
2711 2711
2712 TEST(LayerTreeHostCommonTest, verifyHitTestingForUninvertibleTransform) 2712 TEST(LayerTreeHostCommonTest, verifyHitTestingForUninvertibleTransform)
2713 { 2713 {
2714 DebugScopedSetImplThread thisScopeIsOnImplThread; 2714 DebugScopedSetImplThread thisScopeIsOnImplThread;
2715 2715
2716 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 2716 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
2717 2717
2718 WebTransformationMatrix uninvertibleTransform; 2718 WebTransformationMatrix uninvertibleTransform;
2719 uninvertibleTransform.setM11(0); 2719 uninvertibleTransform.setM11(0);
2720 uninvertibleTransform.setM22(0); 2720 uninvertibleTransform.setM22(0);
2721 uninvertibleTransform.setM33(0); 2721 uninvertibleTransform.setM33(0);
2722 uninvertibleTransform.setM44(0); 2722 uninvertibleTransform.setM44(0);
2723 ASSERT_FALSE(uninvertibleTransform.isInvertible()); 2723 ASSERT_FALSE(uninvertibleTransform.isInvertible());
2724 2724
2725 WebTransformationMatrix identityMatrix; 2725 WebTransformationMatrix identityMatrix;
2726 FloatPoint anchor(0, 0); 2726 gfx::PointF anchor(0, 0);
2727 FloatPoint position(0, 0); 2727 gfx::PointF position(0, 0);
2728 IntSize bounds(100, 100); 2728 gfx::Size bounds(100, 100);
2729 setLayerPropertiesForTesting(root.get(), uninvertibleTransform, identityMatr ix, anchor, position, bounds, false); 2729 setLayerPropertiesForTesting(root.get(), uninvertibleTransform, identityMatr ix, anchor, position, bounds, false);
2730 root->setDrawsContent(true); 2730 root->setDrawsContent(true);
2731 2731
2732 std::vector<LayerImpl*> renderSurfaceLayerList; 2732 std::vector<LayerImpl*> renderSurfaceLayerList;
2733 int dummyMaxTextureSize = 512; 2733 int dummyMaxTextureSize = 512;
2734 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2734 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2735 2735
2736 // Sanity check the scenario we just created. 2736 // Sanity check the scenario we just created.
2737 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 2737 ASSERT_EQ(1u, renderSurfaceLayerList.size());
2738 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 2738 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
2739 ASSERT_FALSE(root->screenSpaceTransform().isInvertible()); 2739 ASSERT_FALSE(root->screenSpaceTransform().isInvertible());
2740 2740
2741 // Hit testing any point should not hit the layer. If the invertible matrix is 2741 // Hit testing any point should not hit the layer. If the invertible matrix is
2742 // accidentally ignored and treated like an identity, then the hit testing w ill 2742 // accidentally ignored and treated like an identity, then the hit testing w ill
2743 // incorrectly hit the layer when it shouldn't. 2743 // incorrectly hit the layer when it shouldn't.
2744 IntPoint testPoint(1, 1); 2744 gfx::Point testPoint(1, 1);
2745 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 2745 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
2746 EXPECT_FALSE(resultLayer); 2746 EXPECT_FALSE(resultLayer);
2747 2747
2748 testPoint = IntPoint(10, 10); 2748 testPoint = gfx::Point(10, 10);
2749 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2749 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2750 EXPECT_FALSE(resultLayer); 2750 EXPECT_FALSE(resultLayer);
2751 2751
2752 testPoint = IntPoint(10, 30); 2752 testPoint = gfx::Point(10, 30);
2753 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2753 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2754 EXPECT_FALSE(resultLayer); 2754 EXPECT_FALSE(resultLayer);
2755 2755
2756 testPoint = IntPoint(50, 50); 2756 testPoint = gfx::Point(50, 50);
2757 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2757 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2758 EXPECT_FALSE(resultLayer); 2758 EXPECT_FALSE(resultLayer);
2759 2759
2760 testPoint = IntPoint(67, 48); 2760 testPoint = gfx::Point(67, 48);
2761 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2761 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2762 EXPECT_FALSE(resultLayer); 2762 EXPECT_FALSE(resultLayer);
2763 2763
2764 testPoint = IntPoint(99, 99); 2764 testPoint = gfx::Point(99, 99);
2765 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2765 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2766 EXPECT_FALSE(resultLayer); 2766 EXPECT_FALSE(resultLayer);
2767 2767
2768 testPoint = IntPoint(-1, -1); 2768 testPoint = gfx::Point(-1, -1);
2769 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2769 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2770 EXPECT_FALSE(resultLayer); 2770 EXPECT_FALSE(resultLayer);
2771 } 2771 }
2772 2772
2773 TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePositionedLayer) 2773 TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePositionedLayer)
2774 { 2774 {
2775 DebugScopedSetImplThread thisScopeIsOnImplThread; 2775 DebugScopedSetImplThread thisScopeIsOnImplThread;
2776 2776
2777 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 2777 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
2778 2778
2779 WebTransformationMatrix identityMatrix; 2779 WebTransformationMatrix identityMatrix;
2780 FloatPoint anchor(0, 0); 2780 gfx::PointF anchor(0, 0);
2781 FloatPoint position(50, 50); // this layer is positioned, and hit testing sh ould correctly know where the layer is located. 2781 gfx::PointF position(50, 50); // this layer is positioned, and hit testing s hould correctly know where the layer is located.
2782 IntSize bounds(100, 100); 2782 gfx::Size bounds(100, 100);
2783 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 2783 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
2784 root->setDrawsContent(true); 2784 root->setDrawsContent(true);
2785 2785
2786 std::vector<LayerImpl*> renderSurfaceLayerList; 2786 std::vector<LayerImpl*> renderSurfaceLayerList;
2787 int dummyMaxTextureSize = 512; 2787 int dummyMaxTextureSize = 512;
2788 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2788 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2789 2789
2790 // Sanity check the scenario we just created. 2790 // Sanity check the scenario we just created.
2791 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 2791 ASSERT_EQ(1u, renderSurfaceLayerList.size());
2792 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 2792 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
2793 2793
2794 // Hit testing for a point outside the layer should return a null pointer. 2794 // Hit testing for a point outside the layer should return a null pointer.
2795 IntPoint testPoint(49, 49); 2795 gfx::Point testPoint(49, 49);
2796 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 2796 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
2797 EXPECT_FALSE(resultLayer); 2797 EXPECT_FALSE(resultLayer);
2798 2798
2799 // Even though the layer exists at (101, 101), it should not be visible ther e since the root renderSurface would clamp it. 2799 // Even though the layer exists at (101, 101), it should not be visible ther e since the root renderSurface would clamp it.
2800 testPoint = IntPoint(101, 101); 2800 testPoint = gfx::Point(101, 101);
2801 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2801 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2802 EXPECT_FALSE(resultLayer); 2802 EXPECT_FALSE(resultLayer);
2803 2803
2804 // Hit testing for a point inside should return the root layer. 2804 // Hit testing for a point inside should return the root layer.
2805 testPoint = IntPoint(51, 51); 2805 testPoint = gfx::Point(51, 51);
2806 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2806 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2807 ASSERT_TRUE(resultLayer); 2807 ASSERT_TRUE(resultLayer);
2808 EXPECT_EQ(12345, resultLayer->id()); 2808 EXPECT_EQ(12345, resultLayer->id());
2809 2809
2810 testPoint = IntPoint(99, 99); 2810 testPoint = gfx::Point(99, 99);
2811 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2811 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2812 ASSERT_TRUE(resultLayer); 2812 ASSERT_TRUE(resultLayer);
2813 EXPECT_EQ(12345, resultLayer->id()); 2813 EXPECT_EQ(12345, resultLayer->id());
2814 } 2814 }
2815 2815
2816 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer) 2816 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer)
2817 { 2817 {
2818 DebugScopedSetImplThread thisScopeIsOnImplThread; 2818 DebugScopedSetImplThread thisScopeIsOnImplThread;
2819 2819
2820 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 2820 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
2821 2821
2822 WebTransformationMatrix identityMatrix; 2822 WebTransformationMatrix identityMatrix;
2823 WebTransformationMatrix rotation45DegreesAboutCenter; 2823 WebTransformationMatrix rotation45DegreesAboutCenter;
2824 rotation45DegreesAboutCenter.translate(50, 50); 2824 rotation45DegreesAboutCenter.translate(50, 50);
2825 rotation45DegreesAboutCenter.rotate3d(0, 0, 45); 2825 rotation45DegreesAboutCenter.rotate3d(0, 0, 45);
2826 rotation45DegreesAboutCenter.translate(-50, -50); 2826 rotation45DegreesAboutCenter.translate(-50, -50);
2827 FloatPoint anchor(0, 0); 2827 gfx::PointF anchor(0, 0);
2828 FloatPoint position(0, 0); 2828 gfx::PointF position(0, 0);
2829 IntSize bounds(100, 100); 2829 gfx::Size bounds(100, 100);
2830 setLayerPropertiesForTesting(root.get(), rotation45DegreesAboutCenter, ident ityMatrix, anchor, position, bounds, false); 2830 setLayerPropertiesForTesting(root.get(), rotation45DegreesAboutCenter, ident ityMatrix, anchor, position, bounds, false);
2831 root->setDrawsContent(true); 2831 root->setDrawsContent(true);
2832 2832
2833 std::vector<LayerImpl*> renderSurfaceLayerList; 2833 std::vector<LayerImpl*> renderSurfaceLayerList;
2834 int dummyMaxTextureSize = 512; 2834 int dummyMaxTextureSize = 512;
2835 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2835 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2836 2836
2837 // Sanity check the scenario we just created. 2837 // Sanity check the scenario we just created.
2838 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 2838 ASSERT_EQ(1u, renderSurfaceLayerList.size());
2839 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 2839 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
2840 2840
2841 // Hit testing for points outside the layer. 2841 // Hit testing for points outside the layer.
2842 // These corners would have been inside the un-transformed layer, but they s hould not hit the correctly transformed layer. 2842 // These corners would have been inside the un-transformed layer, but they s hould not hit the correctly transformed layer.
2843 IntPoint testPoint(99, 99); 2843 gfx::Point testPoint(99, 99);
2844 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 2844 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
2845 EXPECT_FALSE(resultLayer); 2845 EXPECT_FALSE(resultLayer);
2846 2846
2847 testPoint = IntPoint(1, 1); 2847 testPoint = gfx::Point(1, 1);
2848 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2848 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2849 EXPECT_FALSE(resultLayer); 2849 EXPECT_FALSE(resultLayer);
2850 2850
2851 // Hit testing for a point inside should return the root layer. 2851 // Hit testing for a point inside should return the root layer.
2852 testPoint = IntPoint(1, 50); 2852 testPoint = gfx::Point(1, 50);
2853 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2853 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2854 ASSERT_TRUE(resultLayer); 2854 ASSERT_TRUE(resultLayer);
2855 EXPECT_EQ(12345, resultLayer->id()); 2855 EXPECT_EQ(12345, resultLayer->id());
2856 2856
2857 // Hit testing the corners that would overlap the unclipped layer, but are o utside the clipped region. 2857 // Hit testing the corners that would overlap the unclipped layer, but are o utside the clipped region.
2858 testPoint = IntPoint(50, -1); 2858 testPoint = gfx::Point(50, -1);
2859 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2859 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2860 ASSERT_FALSE(resultLayer); 2860 ASSERT_FALSE(resultLayer);
2861 2861
2862 testPoint = IntPoint(-1, 50); 2862 testPoint = gfx::Point(-1, 50);
2863 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2863 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2864 ASSERT_FALSE(resultLayer); 2864 ASSERT_FALSE(resultLayer);
2865 } 2865 }
2866 2866
2867 TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePerspectiveLayer) 2867 TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePerspectiveLayer)
2868 { 2868 {
2869 DebugScopedSetImplThread thisScopeIsOnImplThread; 2869 DebugScopedSetImplThread thisScopeIsOnImplThread;
2870 2870
2871 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 2871 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
2872 2872
2873 WebTransformationMatrix identityMatrix; 2873 WebTransformationMatrix identityMatrix;
2874 2874
2875 // perspectiveProjectionAboutCenter * translationByZ is designed so that the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50). 2875 // perspectiveProjectionAboutCenter * translationByZ is designed so that the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50).
2876 WebTransformationMatrix perspectiveProjectionAboutCenter; 2876 WebTransformationMatrix perspectiveProjectionAboutCenter;
2877 perspectiveProjectionAboutCenter.translate(50, 50); 2877 perspectiveProjectionAboutCenter.translate(50, 50);
2878 perspectiveProjectionAboutCenter.applyPerspective(1); 2878 perspectiveProjectionAboutCenter.applyPerspective(1);
2879 perspectiveProjectionAboutCenter.translate(-50, -50); 2879 perspectiveProjectionAboutCenter.translate(-50, -50);
2880 WebTransformationMatrix translationByZ; 2880 WebTransformationMatrix translationByZ;
2881 translationByZ.translate3d(0, 0, -1); 2881 translationByZ.translate3d(0, 0, -1);
2882 2882
2883 FloatPoint anchor(0, 0); 2883 gfx::PointF anchor(0, 0);
2884 FloatPoint position(0, 0); 2884 gfx::PointF position(0, 0);
2885 IntSize bounds(100, 100); 2885 gfx::Size bounds(100, 100);
2886 setLayerPropertiesForTesting(root.get(), perspectiveProjectionAboutCenter * translationByZ, identityMatrix, anchor, position, bounds, false); 2886 setLayerPropertiesForTesting(root.get(), perspectiveProjectionAboutCenter * translationByZ, identityMatrix, anchor, position, bounds, false);
2887 root->setDrawsContent(true); 2887 root->setDrawsContent(true);
2888 2888
2889 std::vector<LayerImpl*> renderSurfaceLayerList; 2889 std::vector<LayerImpl*> renderSurfaceLayerList;
2890 int dummyMaxTextureSize = 512; 2890 int dummyMaxTextureSize = 512;
2891 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2891 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2892 2892
2893 // Sanity check the scenario we just created. 2893 // Sanity check the scenario we just created.
2894 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 2894 ASSERT_EQ(1u, renderSurfaceLayerList.size());
2895 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 2895 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
2896 2896
2897 // Hit testing for points outside the layer. 2897 // Hit testing for points outside the layer.
2898 // These corners would have been inside the un-transformed layer, but they s hould not hit the correctly transformed layer. 2898 // These corners would have been inside the un-transformed layer, but they s hould not hit the correctly transformed layer.
2899 IntPoint testPoint(24, 24); 2899 gfx::Point testPoint(24, 24);
2900 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 2900 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
2901 EXPECT_FALSE(resultLayer); 2901 EXPECT_FALSE(resultLayer);
2902 2902
2903 testPoint = IntPoint(76, 76); 2903 testPoint = gfx::Point(76, 76);
2904 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2904 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2905 EXPECT_FALSE(resultLayer); 2905 EXPECT_FALSE(resultLayer);
2906 2906
2907 // Hit testing for a point inside should return the root layer. 2907 // Hit testing for a point inside should return the root layer.
2908 testPoint = IntPoint(26, 26); 2908 testPoint = gfx::Point(26, 26);
2909 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2909 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2910 ASSERT_TRUE(resultLayer); 2910 ASSERT_TRUE(resultLayer);
2911 EXPECT_EQ(12345, resultLayer->id()); 2911 EXPECT_EQ(12345, resultLayer->id());
2912 2912
2913 testPoint = IntPoint(74, 74); 2913 testPoint = gfx::Point(74, 74);
2914 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2914 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2915 ASSERT_TRUE(resultLayer); 2915 ASSERT_TRUE(resultLayer);
2916 EXPECT_EQ(12345, resultLayer->id()); 2916 EXPECT_EQ(12345, resultLayer->id());
2917 } 2917 }
2918 2918
2919 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayerWithScaledContents) 2919 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayerWithScaledContents)
2920 { 2920 {
2921 // A layer's visibleContentRect is actually in the layer's content space. Th e 2921 // A layer's visibleContentRect is actually in the layer's content space. Th e
2922 // screenSpaceTransform converts from the layer's origin space to screen spa ce. This 2922 // screenSpaceTransform converts from the layer's origin space to screen spa ce. This
2923 // test makes sure that hit testing works correctly accounts for the content s scale. 2923 // test makes sure that hit testing works correctly accounts for the content s scale.
2924 // A contentsScale that is not 1 effectively forces a non-identity transform between 2924 // A contentsScale that is not 1 effectively forces a non-identity transform between
2925 // layer's content space and layer's origin space. The hit testing code must take this into account. 2925 // layer's content space and layer's origin space. The hit testing code must take this into account.
2926 // 2926 //
2927 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If 2927 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
2928 // contentsScale is ignored, then hit testing will mis-interpret the visible ContentRect 2928 // contentsScale is ignored, then hit testing will mis-interpret the visible ContentRect
2929 // as being larger than the actual bounds of the layer. 2929 // as being larger than the actual bounds of the layer.
2930 // 2930 //
2931 DebugScopedSetImplThread thisScopeIsOnImplThread; 2931 DebugScopedSetImplThread thisScopeIsOnImplThread;
2932 2932
2933 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 2933 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
2934 2934
2935 WebTransformationMatrix identityMatrix; 2935 WebTransformationMatrix identityMatrix;
2936 FloatPoint anchor(0, 0); 2936 gfx::PointF anchor(0, 0);
2937 2937
2938 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, FloatPoint(0, 0), IntSize(100, 100), false); 2938 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
2939 2939
2940 { 2940 {
2941 FloatPoint position(25, 25); 2941 gfx::PointF position(25, 25);
2942 IntSize bounds(50, 50); 2942 gfx::Size bounds(50, 50);
2943 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345); 2943 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345);
2944 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false); 2944 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false);
2945 2945
2946 // override contentBounds 2946 // override contentBounds
2947 testLayer->setContentBounds(IntSize(100, 100)); 2947 testLayer->setContentBounds(gfx::Size(100, 100));
2948 2948
2949 testLayer->setDrawsContent(true); 2949 testLayer->setDrawsContent(true);
2950 root->addChild(testLayer.Pass()); 2950 root->addChild(testLayer.Pass());
2951 } 2951 }
2952 2952
2953 std::vector<LayerImpl*> renderSurfaceLayerList; 2953 std::vector<LayerImpl*> renderSurfaceLayerList;
2954 int dummyMaxTextureSize = 512; 2954 int dummyMaxTextureSize = 512;
2955 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2955 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2956 2956
2957 // Sanity check the scenario we just created. 2957 // Sanity check the scenario we just created.
2958 // The visibleContentRect for testLayer is actually 100x100, even though its layout size is 50x50, positioned at 25x25. 2958 // The visibleContentRect for testLayer is actually 100x100, even though its layout size is 50x50, positioned at 25x25.
2959 LayerImpl* testLayer = root->children()[0]; 2959 LayerImpl* testLayer = root->children()[0];
2960 EXPECT_RECT_EQ(IntRect(IntPoint::zero(), IntSize(100, 100)), testLayer->visi bleContentRect()); 2960 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(), gfx::Size(100, 100)), testLayer->visi bleContentRect());
2961 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 2961 ASSERT_EQ(1u, renderSurfaceLayerList.size());
2962 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 2962 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
2963 2963
2964 // Hit testing for a point outside the layer should return a null pointer (t he root layer does not draw content, so it will not be hit tested either). 2964 // Hit testing for a point outside the layer should return a null pointer (t he root layer does not draw content, so it will not be hit tested either).
2965 IntPoint testPoint(101, 101); 2965 gfx::Point testPoint(101, 101);
2966 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 2966 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
2967 EXPECT_FALSE(resultLayer); 2967 EXPECT_FALSE(resultLayer);
2968 2968
2969 testPoint = IntPoint(24, 24); 2969 testPoint = gfx::Point(24, 24);
2970 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2970 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2971 EXPECT_FALSE(resultLayer); 2971 EXPECT_FALSE(resultLayer);
2972 2972
2973 testPoint = IntPoint(76, 76); 2973 testPoint = gfx::Point(76, 76);
2974 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2974 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2975 EXPECT_FALSE(resultLayer); 2975 EXPECT_FALSE(resultLayer);
2976 2976
2977 // Hit testing for a point inside should return the test layer. 2977 // Hit testing for a point inside should return the test layer.
2978 testPoint = IntPoint(26, 26); 2978 testPoint = gfx::Point(26, 26);
2979 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2979 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2980 ASSERT_TRUE(resultLayer); 2980 ASSERT_TRUE(resultLayer);
2981 EXPECT_EQ(12345, resultLayer->id()); 2981 EXPECT_EQ(12345, resultLayer->id());
2982 2982
2983 testPoint = IntPoint(74, 74); 2983 testPoint = gfx::Point(74, 74);
2984 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2984 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2985 ASSERT_TRUE(resultLayer); 2985 ASSERT_TRUE(resultLayer);
2986 EXPECT_EQ(12345, resultLayer->id()); 2986 EXPECT_EQ(12345, resultLayer->id());
2987 } 2987 }
2988 2988
2989 TEST(LayerTreeHostCommonTest, verifyHitTestingForSimpleClippedLayer) 2989 TEST(LayerTreeHostCommonTest, verifyHitTestingForSimpleClippedLayer)
2990 { 2990 {
2991 // Test that hit-testing will only work for the visible portion of a layer, and not 2991 // Test that hit-testing will only work for the visible portion of a layer, and not
2992 // the entire layer bounds. Here we just test the simple axis-aligned case. 2992 // the entire layer bounds. Here we just test the simple axis-aligned case.
2993 DebugScopedSetImplThread thisScopeIsOnImplThread; 2993 DebugScopedSetImplThread thisScopeIsOnImplThread;
2994 2994
2995 WebTransformationMatrix identityMatrix; 2995 WebTransformationMatrix identityMatrix;
2996 FloatPoint anchor(0, 0); 2996 gfx::PointF anchor(0, 0);
2997 2997
2998 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 2998 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
2999 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, FloatPoint(0, 0), IntSize(100, 100), false); 2999 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
3000 3000
3001 { 3001 {
3002 scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(123); 3002 scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(123);
3003 FloatPoint position(25, 25); // this layer is positioned, and hit testin g should correctly know where the layer is located. 3003 gfx::PointF position(25, 25); // this layer is positioned, and hit testi ng should correctly know where the layer is located.
3004 IntSize bounds(50, 50); 3004 gfx::Size bounds(50, 50);
3005 setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identi tyMatrix, anchor, position, bounds, false); 3005 setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identi tyMatrix, anchor, position, bounds, false);
3006 clippingLayer->setMasksToBounds(true); 3006 clippingLayer->setMasksToBounds(true);
3007 3007
3008 scoped_ptr<LayerImpl> child = LayerImpl::create(456); 3008 scoped_ptr<LayerImpl> child = LayerImpl::create(456);
3009 position = FloatPoint(-50, -50); 3009 position = gfx::PointF(-50, -50);
3010 bounds = IntSize(300, 300); 3010 bounds = gfx::Size(300, 300);
3011 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false); 3011 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false);
3012 child->setDrawsContent(true); 3012 child->setDrawsContent(true);
3013 clippingLayer->addChild(child.Pass()); 3013 clippingLayer->addChild(child.Pass());
3014 root->addChild(clippingLayer.Pass()); 3014 root->addChild(clippingLayer.Pass());
3015 } 3015 }
3016 3016
3017 std::vector<LayerImpl*> renderSurfaceLayerList; 3017 std::vector<LayerImpl*> renderSurfaceLayerList;
3018 int dummyMaxTextureSize = 512; 3018 int dummyMaxTextureSize = 512;
3019 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 3019 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3020 3020
3021 // Sanity check the scenario we just created. 3021 // Sanity check the scenario we just created.
3022 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 3022 ASSERT_EQ(1u, renderSurfaceLayerList.size());
3023 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 3023 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
3024 ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id()); 3024 ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id());
3025 3025
3026 // Hit testing for a point outside the layer should return a null pointer. 3026 // Hit testing for a point outside the layer should return a null pointer.
3027 // Despite the child layer being very large, it should be clipped to the roo t layer's bounds. 3027 // Despite the child layer being very large, it should be clipped to the roo t layer's bounds.
3028 IntPoint testPoint(24, 24); 3028 gfx::Point testPoint(24, 24);
3029 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 3029 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
3030 EXPECT_FALSE(resultLayer); 3030 EXPECT_FALSE(resultLayer);
3031 3031
3032 // Even though the layer exists at (101, 101), it should not be visible ther e since the clippingLayer would clamp it. 3032 // Even though the layer exists at (101, 101), it should not be visible ther e since the clippingLayer would clamp it.
3033 testPoint = IntPoint(76, 76); 3033 testPoint = gfx::Point(76, 76);
3034 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3034 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3035 EXPECT_FALSE(resultLayer); 3035 EXPECT_FALSE(resultLayer);
3036 3036
3037 // Hit testing for a point inside should return the child layer. 3037 // Hit testing for a point inside should return the child layer.
3038 testPoint = IntPoint(26, 26); 3038 testPoint = gfx::Point(26, 26);
3039 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3039 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3040 ASSERT_TRUE(resultLayer); 3040 ASSERT_TRUE(resultLayer);
3041 EXPECT_EQ(456, resultLayer->id()); 3041 EXPECT_EQ(456, resultLayer->id());
3042 3042
3043 testPoint = IntPoint(74, 74); 3043 testPoint = gfx::Point(74, 74);
3044 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3044 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3045 ASSERT_TRUE(resultLayer); 3045 ASSERT_TRUE(resultLayer);
3046 EXPECT_EQ(456, resultLayer->id()); 3046 EXPECT_EQ(456, resultLayer->id());
3047 } 3047 }
3048 3048
3049 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultiClippedRotatedLayer) 3049 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultiClippedRotatedLayer)
3050 { 3050 {
3051 // This test checks whether hit testing correctly avoids hit testing with mu ltiple 3051 // This test checks whether hit testing correctly avoids hit testing with mu ltiple
3052 // ancestors that clip in non axis-aligned ways. To pass this test, the hit testing 3052 // ancestors that clip in non axis-aligned ways. To pass this test, the hit testing
3053 // algorithm needs to recognize that multiple parent layers may clip the lay er, and 3053 // algorithm needs to recognize that multiple parent layers may clip the lay er, and
3054 // should not actually hit those clipped areas. 3054 // should not actually hit those clipped areas.
3055 // 3055 //
3056 // The child and grandChild layers are both initialized to clip the rotatedL eaf. The 3056 // The child and grandChild layers are both initialized to clip the rotatedL eaf. The
3057 // child layer is rotated about the top-left corner, so that the root + chil d clips 3057 // child layer is rotated about the top-left corner, so that the root + chil d clips
3058 // combined create a triangle. The rotatedLeaf will only be visible where it overlaps 3058 // combined create a triangle. The rotatedLeaf will only be visible where it overlaps
3059 // this triangle. 3059 // this triangle.
3060 // 3060 //
3061 DebugScopedSetImplThread thisScopeIsOnImplThread; 3061 DebugScopedSetImplThread thisScopeIsOnImplThread;
3062 3062
3063 scoped_ptr<LayerImpl> root = LayerImpl::create(123); 3063 scoped_ptr<LayerImpl> root = LayerImpl::create(123);
3064 3064
3065 WebTransformationMatrix identityMatrix; 3065 WebTransformationMatrix identityMatrix;
3066 FloatPoint anchor(0, 0); 3066 gfx::PointF anchor(0, 0);
3067 FloatPoint position(0, 0); 3067 gfx::PointF position(0, 0);
3068 IntSize bounds(100, 100); 3068 gfx::Size bounds(100, 100);
3069 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 3069 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
3070 root->setMasksToBounds(true); 3070 root->setMasksToBounds(true);
3071 3071
3072 { 3072 {
3073 scoped_ptr<LayerImpl> child = LayerImpl::create(456); 3073 scoped_ptr<LayerImpl> child = LayerImpl::create(456);
3074 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(789); 3074 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(789);
3075 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(2468); 3075 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(2468);
3076 3076
3077 position = FloatPoint(10, 10); 3077 position = gfx::PointF(10, 10);
3078 bounds = IntSize(80, 80); 3078 bounds = gfx::Size(80, 80);
3079 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false); 3079 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false);
3080 child->setMasksToBounds(true); 3080 child->setMasksToBounds(true);
3081 3081
3082 WebTransformationMatrix rotation45DegreesAboutCorner; 3082 WebTransformationMatrix rotation45DegreesAboutCorner;
3083 rotation45DegreesAboutCorner.rotate3d(0, 0, 45); 3083 rotation45DegreesAboutCorner.rotate3d(0, 0, 45);
3084 3084
3085 position = FloatPoint(0, 0); // remember, positioned with respect to its parent which is already at 10, 10 3085 position = gfx::PointF(0, 0); // remember, positioned with respect to it s parent which is already at 10, 10
3086 bounds = IntSize(200, 200); // to ensure it covers at least sqrt(2) * 10 0. 3086 bounds = gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100.
3087 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor ner, identityMatrix, anchor, position, bounds, false); 3087 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor ner, identityMatrix, anchor, position, bounds, false);
3088 grandChild->setMasksToBounds(true); 3088 grandChild->setMasksToBounds(true);
3089 3089
3090 // Rotates about the center of the layer 3090 // Rotates about the center of the layer
3091 WebTransformationMatrix rotatedLeafTransform; 3091 WebTransformationMatrix rotatedLeafTransform;
3092 rotatedLeafTransform.translate(-10, -10); // cancel out the grandParent' s position 3092 rotatedLeafTransform.translate(-10, -10); // cancel out the grandParent' s position
3093 rotatedLeafTransform.rotate3d(0, 0, -45); // cancel out the corner 45-de gree rotation of the parent. 3093 rotatedLeafTransform.rotate3d(0, 0, -45); // cancel out the corner 45-de gree rotation of the parent.
3094 rotatedLeafTransform.translate(50, 50); 3094 rotatedLeafTransform.translate(50, 50);
3095 rotatedLeafTransform.rotate3d(0, 0, 45); 3095 rotatedLeafTransform.rotate3d(0, 0, 45);
3096 rotatedLeafTransform.translate(-50, -50); 3096 rotatedLeafTransform.translate(-50, -50);
3097 position = FloatPoint(0, 0); 3097 position = gfx::PointF(0, 0);
3098 bounds = IntSize(100, 100); 3098 bounds = gfx::Size(100, 100);
3099 setLayerPropertiesForTesting(rotatedLeaf.get(), rotatedLeafTransform, id entityMatrix, anchor, position, bounds, false); 3099 setLayerPropertiesForTesting(rotatedLeaf.get(), rotatedLeafTransform, id entityMatrix, anchor, position, bounds, false);
3100 rotatedLeaf->setDrawsContent(true); 3100 rotatedLeaf->setDrawsContent(true);
3101 3101
3102 grandChild->addChild(rotatedLeaf.Pass()); 3102 grandChild->addChild(rotatedLeaf.Pass());
3103 child->addChild(grandChild.Pass()); 3103 child->addChild(grandChild.Pass());
3104 root->addChild(child.Pass()); 3104 root->addChild(child.Pass());
3105 } 3105 }
3106 3106
3107 std::vector<LayerImpl*> renderSurfaceLayerList; 3107 std::vector<LayerImpl*> renderSurfaceLayerList;
3108 int dummyMaxTextureSize = 512; 3108 int dummyMaxTextureSize = 512;
3109 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 3109 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3110 3110
3111 // Sanity check the scenario we just created. 3111 // Sanity check the scenario we just created.
3112 // The grandChild is expected to create a renderSurface because it masksToBo unds and is not axis aligned. 3112 // The grandChild is expected to create a renderSurface because it masksToBo unds and is not axis aligned.
3113 ASSERT_EQ(2u, renderSurfaceLayerList.size()); 3113 ASSERT_EQ(2u, renderSurfaceLayerList.size());
3114 ASSERT_EQ(1u, renderSurfaceLayerList[0]->renderSurface()->layerList().size() ); 3114 ASSERT_EQ(1u, renderSurfaceLayerList[0]->renderSurface()->layerList().size() );
3115 ASSERT_EQ(789, renderSurfaceLayerList[0]->renderSurface()->layerList()[0]->i d()); // grandChild's surface. 3115 ASSERT_EQ(789, renderSurfaceLayerList[0]->renderSurface()->layerList()[0]->i d()); // grandChild's surface.
3116 ASSERT_EQ(1u, renderSurfaceLayerList[1]->renderSurface()->layerList().size() ); 3116 ASSERT_EQ(1u, renderSurfaceLayerList[1]->renderSurface()->layerList().size() );
3117 ASSERT_EQ(2468, renderSurfaceLayerList[1]->renderSurface()->layerList()[0]-> id()); 3117 ASSERT_EQ(2468, renderSurfaceLayerList[1]->renderSurface()->layerList()[0]-> id());
3118 3118
3119 // (11, 89) is close to the the bottom left corner within the clip, but it i s not inside the layer. 3119 // (11, 89) is close to the the bottom left corner within the clip, but it i s not inside the layer.
3120 IntPoint testPoint(11, 89); 3120 gfx::Point testPoint(11, 89);
3121 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 3121 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
3122 EXPECT_FALSE(resultLayer); 3122 EXPECT_FALSE(resultLayer);
3123 3123
3124 // Closer inwards from the bottom left will overlap the layer. 3124 // Closer inwards from the bottom left will overlap the layer.
3125 testPoint = IntPoint(25, 75); 3125 testPoint = gfx::Point(25, 75);
3126 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3126 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3127 ASSERT_TRUE(resultLayer); 3127 ASSERT_TRUE(resultLayer);
3128 EXPECT_EQ(2468, resultLayer->id()); 3128 EXPECT_EQ(2468, resultLayer->id());
3129 3129
3130 // (4, 50) is inside the unclipped layer, but that corner of the layer shoul d be 3130 // (4, 50) is inside the unclipped layer, but that corner of the layer shoul d be
3131 // clipped away by the grandParent and should not get hit. If hit testing bl indly uses 3131 // clipped away by the grandParent and should not get hit. If hit testing bl indly uses
3132 // visibleContentRect without considering how parent may clip the layer, the n hit 3132 // visibleContentRect without considering how parent may clip the layer, the n hit
3133 // testing would accidentally think that the point successfully hits the lay er. 3133 // testing would accidentally think that the point successfully hits the lay er.
3134 testPoint = IntPoint(4, 50); 3134 testPoint = gfx::Point(4, 50);
3135 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3135 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3136 EXPECT_FALSE(resultLayer); 3136 EXPECT_FALSE(resultLayer);
3137 3137
3138 // (11, 50) is inside the layer and within the clipped area. 3138 // (11, 50) is inside the layer and within the clipped area.
3139 testPoint = IntPoint(11, 50); 3139 testPoint = gfx::Point(11, 50);
3140 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3140 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3141 ASSERT_TRUE(resultLayer); 3141 ASSERT_TRUE(resultLayer);
3142 EXPECT_EQ(2468, resultLayer->id()); 3142 EXPECT_EQ(2468, resultLayer->id());
3143 3143
3144 // Around the middle, just to the right and up, would have hit the layer exc ept that 3144 // Around the middle, just to the right and up, would have hit the layer exc ept that
3145 // that area should be clipped away by the parent. 3145 // that area should be clipped away by the parent.
3146 testPoint = IntPoint(51, 51); 3146 testPoint = gfx::Point(51, 51);
3147 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3147 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3148 EXPECT_FALSE(resultLayer); 3148 EXPECT_FALSE(resultLayer);
3149 3149
3150 // Around the middle, just to the left and down, should successfully hit the layer. 3150 // Around the middle, just to the left and down, should successfully hit the layer.
3151 testPoint = IntPoint(49, 51); 3151 testPoint = gfx::Point(49, 51);
3152 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3152 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3153 ASSERT_TRUE(resultLayer); 3153 ASSERT_TRUE(resultLayer);
3154 EXPECT_EQ(2468, resultLayer->id()); 3154 EXPECT_EQ(2468, resultLayer->id());
3155 } 3155 }
3156 3156
3157 TEST(LayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer) 3157 TEST(LayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer)
3158 { 3158 {
3159 // This test checks that hit testing code does not accidentally clip to laye r 3159 // This test checks that hit testing code does not accidentally clip to laye r
3160 // bounds for a layer that actually does not clip. 3160 // bounds for a layer that actually does not clip.
3161 DebugScopedSetImplThread thisScopeIsOnImplThread; 3161 DebugScopedSetImplThread thisScopeIsOnImplThread;
3162 3162
3163 WebTransformationMatrix identityMatrix; 3163 WebTransformationMatrix identityMatrix;
3164 FloatPoint anchor(0, 0); 3164 gfx::PointF anchor(0, 0);
3165 3165
3166 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 3166 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3167 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, FloatPoint(0, 0), IntSize(100, 100), false); 3167 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
3168 3168
3169 { 3169 {
3170 scoped_ptr<LayerImpl> intermediateLayer = LayerImpl::create(123); 3170 scoped_ptr<LayerImpl> intermediateLayer = LayerImpl::create(123);
3171 FloatPoint position(10, 10); // this layer is positioned, and hit testin g should correctly know where the layer is located. 3171 gfx::PointF position(10, 10); // this layer is positioned, and hit testi ng should correctly know where the layer is located.
3172 IntSize bounds(50, 50); 3172 gfx::Size bounds(50, 50);
3173 setLayerPropertiesForTesting(intermediateLayer.get(), identityMatrix, id entityMatrix, anchor, position, bounds, false); 3173 setLayerPropertiesForTesting(intermediateLayer.get(), identityMatrix, id entityMatrix, anchor, position, bounds, false);
3174 // Sanity check the intermediate layer should not clip. 3174 // Sanity check the intermediate layer should not clip.
3175 ASSERT_FALSE(intermediateLayer->masksToBounds()); 3175 ASSERT_FALSE(intermediateLayer->masksToBounds());
3176 ASSERT_FALSE(intermediateLayer->maskLayer()); 3176 ASSERT_FALSE(intermediateLayer->maskLayer());
3177 3177
3178 // The child of the intermediateLayer is translated so that it does not overlap intermediateLayer at all. 3178 // The child of the intermediateLayer is translated so that it does not overlap intermediateLayer at all.
3179 // If child is incorrectly clipped, we would not be able to hit it succe ssfully. 3179 // If child is incorrectly clipped, we would not be able to hit it succe ssfully.
3180 scoped_ptr<LayerImpl> child = LayerImpl::create(456); 3180 scoped_ptr<LayerImpl> child = LayerImpl::create(456);
3181 position = FloatPoint(60, 60); // 70, 70 in screen space 3181 position = gfx::PointF(60, 60); // 70, 70 in screen space
3182 bounds = IntSize(20, 20); 3182 bounds = gfx::Size(20, 20);
3183 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false); 3183 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false);
3184 child->setDrawsContent(true); 3184 child->setDrawsContent(true);
3185 intermediateLayer->addChild(child.Pass()); 3185 intermediateLayer->addChild(child.Pass());
3186 root->addChild(intermediateLayer.Pass()); 3186 root->addChild(intermediateLayer.Pass());
3187 } 3187 }
3188 3188
3189 std::vector<LayerImpl*> renderSurfaceLayerList; 3189 std::vector<LayerImpl*> renderSurfaceLayerList;
3190 int dummyMaxTextureSize = 512; 3190 int dummyMaxTextureSize = 512;
3191 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 3191 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3192 3192
3193 // Sanity check the scenario we just created. 3193 // Sanity check the scenario we just created.
3194 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 3194 ASSERT_EQ(1u, renderSurfaceLayerList.size());
3195 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 3195 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
3196 ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id()); 3196 ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id());
3197 3197
3198 // Hit testing for a point outside the layer should return a null pointer. 3198 // Hit testing for a point outside the layer should return a null pointer.
3199 IntPoint testPoint(69, 69); 3199 gfx::Point testPoint(69, 69);
3200 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 3200 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
3201 EXPECT_FALSE(resultLayer); 3201 EXPECT_FALSE(resultLayer);
3202 3202
3203 testPoint = IntPoint(91, 91); 3203 testPoint = gfx::Point(91, 91);
3204 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3204 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3205 EXPECT_FALSE(resultLayer); 3205 EXPECT_FALSE(resultLayer);
3206 3206
3207 // Hit testing for a point inside should return the child layer. 3207 // Hit testing for a point inside should return the child layer.
3208 testPoint = IntPoint(71, 71); 3208 testPoint = gfx::Point(71, 71);
3209 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3209 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3210 ASSERT_TRUE(resultLayer); 3210 ASSERT_TRUE(resultLayer);
3211 EXPECT_EQ(456, resultLayer->id()); 3211 EXPECT_EQ(456, resultLayer->id());
3212 3212
3213 testPoint = IntPoint(89, 89); 3213 testPoint = gfx::Point(89, 89);
3214 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3214 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3215 ASSERT_TRUE(resultLayer); 3215 ASSERT_TRUE(resultLayer);
3216 EXPECT_EQ(456, resultLayer->id()); 3216 EXPECT_EQ(456, resultLayer->id());
3217 } 3217 }
3218 3218
3219 3219
3220 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayers) 3220 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayers)
3221 { 3221 {
3222 DebugScopedSetImplThread thisScopeIsOnImplThread; 3222 DebugScopedSetImplThread thisScopeIsOnImplThread;
3223 3223
3224 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 3224 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3225 3225
3226 WebTransformationMatrix identityMatrix; 3226 WebTransformationMatrix identityMatrix;
3227 FloatPoint anchor(0, 0); 3227 gfx::PointF anchor(0, 0);
3228 FloatPoint position(0, 0); 3228 gfx::PointF position(0, 0);
3229 IntSize bounds(100, 100); 3229 gfx::Size bounds(100, 100);
3230 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 3230 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
3231 root->setDrawsContent(true); 3231 root->setDrawsContent(true);
3232 3232
3233 { 3233 {
3234 // child 1 and child2 are initialized to overlap between x=50 and x=60. 3234 // child 1 and child2 are initialized to overlap between x=50 and x=60.
3235 // grandChild is set to overlap both child1 and child2 between y=50 and y=60. 3235 // grandChild is set to overlap both child1 and child2 between y=50 and y=60.
3236 // The expected stacking order is: 3236 // The expected stacking order is:
3237 // (front) child2, (second) grandChild, (third) child1, and (back) the root layer behind all other layers. 3237 // (front) child2, (second) grandChild, (third) child1, and (back) the root layer behind all other layers.
3238 3238
3239 scoped_ptr<LayerImpl> child1 = LayerImpl::create(2); 3239 scoped_ptr<LayerImpl> child1 = LayerImpl::create(2);
3240 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); 3240 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3);
3241 scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(4); 3241 scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(4);
3242 3242
3243 position = FloatPoint(10, 10); 3243 position = gfx::PointF(10, 10);
3244 bounds = IntSize(50, 50); 3244 bounds = gfx::Size(50, 50);
3245 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatri x, anchor, position, bounds, false); 3245 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatri x, anchor, position, bounds, false);
3246 child1->setDrawsContent(true); 3246 child1->setDrawsContent(true);
3247 3247
3248 position = FloatPoint(50, 10); 3248 position = gfx::PointF(50, 10);
3249 bounds = IntSize(50, 50); 3249 bounds = gfx::Size(50, 50);
3250 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatri x, anchor, position, bounds, false); 3250 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatri x, anchor, position, bounds, false);
3251 child2->setDrawsContent(true); 3251 child2->setDrawsContent(true);
3252 3252
3253 // Remember that grandChild is positioned with respect to its parent (i. e. child1). 3253 // Remember that grandChild is positioned with respect to its parent (i. e. child1).
3254 // In screen space, the intended position is (10, 50), with size 100 x 5 0. 3254 // In screen space, the intended position is (10, 50), with size 100 x 5 0.
3255 position = FloatPoint(0, 40); 3255 position = gfx::PointF(0, 40);
3256 bounds = IntSize(100, 50); 3256 bounds = gfx::Size(100, 50);
3257 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identity Matrix, anchor, position, bounds, false); 3257 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identity Matrix, anchor, position, bounds, false);
3258 grandChild1->setDrawsContent(true); 3258 grandChild1->setDrawsContent(true);
3259 3259
3260 child1->addChild(grandChild1.Pass()); 3260 child1->addChild(grandChild1.Pass());
3261 root->addChild(child1.Pass()); 3261 root->addChild(child1.Pass());
3262 root->addChild(child2.Pass()); 3262 root->addChild(child2.Pass());
3263 } 3263 }
3264 3264
3265 LayerImpl* child1 = root->children()[0]; 3265 LayerImpl* child1 = root->children()[0];
3266 LayerImpl* child2 = root->children()[1]; 3266 LayerImpl* child2 = root->children()[1];
3267 LayerImpl* grandChild1 = child1->children()[0]; 3267 LayerImpl* grandChild1 = child1->children()[0];
3268 3268
3269 std::vector<LayerImpl*> renderSurfaceLayerList; 3269 std::vector<LayerImpl*> renderSurfaceLayerList;
3270 int dummyMaxTextureSize = 512; 3270 int dummyMaxTextureSize = 512;
3271 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 3271 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3272 3272
3273 // Sanity check the scenario we just created. 3273 // Sanity check the scenario we just created.
3274 ASSERT_TRUE(child1); 3274 ASSERT_TRUE(child1);
3275 ASSERT_TRUE(child2); 3275 ASSERT_TRUE(child2);
3276 ASSERT_TRUE(grandChild1); 3276 ASSERT_TRUE(grandChild1);
3277 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 3277 ASSERT_EQ(1u, renderSurfaceLayerList.size());
3278 ASSERT_EQ(4u, root->renderSurface()->layerList().size()); 3278 ASSERT_EQ(4u, root->renderSurface()->layerList().size());
3279 ASSERT_EQ(1, root->renderSurface()->layerList()[0]->id()); // root layer 3279 ASSERT_EQ(1, root->renderSurface()->layerList()[0]->id()); // root layer
3280 ASSERT_EQ(2, root->renderSurface()->layerList()[1]->id()); // child1 3280 ASSERT_EQ(2, root->renderSurface()->layerList()[1]->id()); // child1
3281 ASSERT_EQ(4, root->renderSurface()->layerList()[2]->id()); // grandChild1 3281 ASSERT_EQ(4, root->renderSurface()->layerList()[2]->id()); // grandChild1
3282 ASSERT_EQ(3, root->renderSurface()->layerList()[3]->id()); // child2 3282 ASSERT_EQ(3, root->renderSurface()->layerList()[3]->id()); // child2
3283 3283
3284 // Nothing overlaps the rootLayer at (1, 1), so hit testing there should fin d the root layer. 3284 // Nothing overlaps the rootLayer at (1, 1), so hit testing there should fin d the root layer.
3285 IntPoint testPoint = IntPoint(1, 1); 3285 gfx::Point testPoint = gfx::Point(1, 1);
3286 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 3286 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
3287 ASSERT_TRUE(resultLayer); 3287 ASSERT_TRUE(resultLayer);
3288 EXPECT_EQ(1, resultLayer->id()); 3288 EXPECT_EQ(1, resultLayer->id());
3289 3289
3290 // At (15, 15), child1 and root are the only layers. child1 is expected to b e on top. 3290 // At (15, 15), child1 and root are the only layers. child1 is expected to b e on top.
3291 testPoint = IntPoint(15, 15); 3291 testPoint = gfx::Point(15, 15);
3292 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3292 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3293 ASSERT_TRUE(resultLayer); 3293 ASSERT_TRUE(resultLayer);
3294 EXPECT_EQ(2, resultLayer->id()); 3294 EXPECT_EQ(2, resultLayer->id());
3295 3295
3296 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top. 3296 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
3297 testPoint = IntPoint(51, 20); 3297 testPoint = gfx::Point(51, 20);
3298 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3298 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3299 ASSERT_TRUE(resultLayer); 3299 ASSERT_TRUE(resultLayer);
3300 EXPECT_EQ(3, resultLayer->id()); 3300 EXPECT_EQ(3, resultLayer->id());
3301 3301
3302 // At (80, 51), child2 and grandChild1 overlap. child2 is expected to be on top. 3302 // At (80, 51), child2 and grandChild1 overlap. child2 is expected to be on top.
3303 testPoint = IntPoint(80, 51); 3303 testPoint = gfx::Point(80, 51);
3304 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3304 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3305 ASSERT_TRUE(resultLayer); 3305 ASSERT_TRUE(resultLayer);
3306 EXPECT_EQ(3, resultLayer->id()); 3306 EXPECT_EQ(3, resultLayer->id());
3307 3307
3308 // At (51, 51), all layers overlap each other. child2 is expected to be on t op of all other layers. 3308 // At (51, 51), all layers overlap each other. child2 is expected to be on t op of all other layers.
3309 testPoint = IntPoint(51, 51); 3309 testPoint = gfx::Point(51, 51);
3310 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3310 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3311 ASSERT_TRUE(resultLayer); 3311 ASSERT_TRUE(resultLayer);
3312 EXPECT_EQ(3, resultLayer->id()); 3312 EXPECT_EQ(3, resultLayer->id());
3313 3313
3314 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b e on top. 3314 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b e on top.
3315 testPoint = IntPoint(20, 51); 3315 testPoint = gfx::Point(20, 51);
3316 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3316 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3317 ASSERT_TRUE(resultLayer); 3317 ASSERT_TRUE(resultLayer);
3318 EXPECT_EQ(4, resultLayer->id()); 3318 EXPECT_EQ(4, resultLayer->id());
3319 } 3319 }
3320 3320
3321 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists) 3321 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists)
3322 { 3322 {
3323 // 3323 //
3324 // The geometry is set up similarly to the previous case, but 3324 // The geometry is set up similarly to the previous case, but
3325 // all layers are forced to be renderSurfaces now. 3325 // all layers are forced to be renderSurfaces now.
3326 // 3326 //
3327 DebugScopedSetImplThread thisScopeIsOnImplThread; 3327 DebugScopedSetImplThread thisScopeIsOnImplThread;
3328 3328
3329 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 3329 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3330 3330
3331 WebTransformationMatrix identityMatrix; 3331 WebTransformationMatrix identityMatrix;
3332 FloatPoint anchor(0, 0); 3332 gfx::PointF anchor(0, 0);
3333 FloatPoint position(0, 0); 3333 gfx::PointF position(0, 0);
3334 IntSize bounds(100, 100); 3334 gfx::Size bounds(100, 100);
3335 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 3335 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
3336 root->setDrawsContent(true); 3336 root->setDrawsContent(true);
3337 3337
3338 { 3338 {
3339 // child 1 and child2 are initialized to overlap between x=50 and x=60. 3339 // child 1 and child2 are initialized to overlap between x=50 and x=60.
3340 // grandChild is set to overlap both child1 and child2 between y=50 and y=60. 3340 // grandChild is set to overlap both child1 and child2 between y=50 and y=60.
3341 // The expected stacking order is: 3341 // The expected stacking order is:
3342 // (front) child2, (second) grandChild, (third) child1, and (back) the root layer behind all other layers. 3342 // (front) child2, (second) grandChild, (third) child1, and (back) the root layer behind all other layers.
3343 3343
3344 scoped_ptr<LayerImpl> child1 = LayerImpl::create(2); 3344 scoped_ptr<LayerImpl> child1 = LayerImpl::create(2);
3345 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); 3345 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3);
3346 scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(4); 3346 scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(4);
3347 3347
3348 position = FloatPoint(10, 10); 3348 position = gfx::PointF(10, 10);
3349 bounds = IntSize(50, 50); 3349 bounds = gfx::Size(50, 50);
3350 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatri x, anchor, position, bounds, false); 3350 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatri x, anchor, position, bounds, false);
3351 child1->setDrawsContent(true); 3351 child1->setDrawsContent(true);
3352 child1->setForceRenderSurface(true); 3352 child1->setForceRenderSurface(true);
3353 3353
3354 position = FloatPoint(50, 10); 3354 position = gfx::PointF(50, 10);
3355 bounds = IntSize(50, 50); 3355 bounds = gfx::Size(50, 50);
3356 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatri x, anchor, position, bounds, false); 3356 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatri x, anchor, position, bounds, false);
3357 child2->setDrawsContent(true); 3357 child2->setDrawsContent(true);
3358 child2->setForceRenderSurface(true); 3358 child2->setForceRenderSurface(true);
3359 3359
3360 // Remember that grandChild is positioned with respect to its parent (i. e. child1). 3360 // Remember that grandChild is positioned with respect to its parent (i. e. child1).
3361 // In screen space, the intended position is (10, 50), with size 100 x 5 0. 3361 // In screen space, the intended position is (10, 50), with size 100 x 5 0.
3362 position = FloatPoint(0, 40); 3362 position = gfx::PointF(0, 40);
3363 bounds = IntSize(100, 50); 3363 bounds = gfx::Size(100, 50);
3364 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identity Matrix, anchor, position, bounds, false); 3364 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identity Matrix, anchor, position, bounds, false);
3365 grandChild1->setDrawsContent(true); 3365 grandChild1->setDrawsContent(true);
3366 grandChild1->setForceRenderSurface(true); 3366 grandChild1->setForceRenderSurface(true);
3367 3367
3368 child1->addChild(grandChild1.Pass()); 3368 child1->addChild(grandChild1.Pass());
3369 root->addChild(child1.Pass()); 3369 root->addChild(child1.Pass());
3370 root->addChild(child2.Pass()); 3370 root->addChild(child2.Pass());
3371 } 3371 }
3372 3372
3373 LayerImpl* child1 = root->children()[0]; 3373 LayerImpl* child1 = root->children()[0];
(...skipping 15 matching lines...) Expand all
3389 ASSERT_EQ(3u, root->renderSurface()->layerList().size()); // The root surfac e has the root layer, and child1's and child2's renderSurfaces. 3389 ASSERT_EQ(3u, root->renderSurface()->layerList().size()); // The root surfac e has the root layer, and child1's and child2's renderSurfaces.
3390 ASSERT_EQ(2u, child1->renderSurface()->layerList().size()); // The child1 su rface has the child1 layer and grandChild1's renderSurface. 3390 ASSERT_EQ(2u, child1->renderSurface()->layerList().size()); // The child1 su rface has the child1 layer and grandChild1's renderSurface.
3391 ASSERT_EQ(1u, child2->renderSurface()->layerList().size()); 3391 ASSERT_EQ(1u, child2->renderSurface()->layerList().size());
3392 ASSERT_EQ(1u, grandChild1->renderSurface()->layerList().size()); 3392 ASSERT_EQ(1u, grandChild1->renderSurface()->layerList().size());
3393 ASSERT_EQ(1, renderSurfaceLayerList[0]->id()); // root layer 3393 ASSERT_EQ(1, renderSurfaceLayerList[0]->id()); // root layer
3394 ASSERT_EQ(2, renderSurfaceLayerList[1]->id()); // child1 3394 ASSERT_EQ(2, renderSurfaceLayerList[1]->id()); // child1
3395 ASSERT_EQ(4, renderSurfaceLayerList[2]->id()); // grandChild1 3395 ASSERT_EQ(4, renderSurfaceLayerList[2]->id()); // grandChild1
3396 ASSERT_EQ(3, renderSurfaceLayerList[3]->id()); // child2 3396 ASSERT_EQ(3, renderSurfaceLayerList[3]->id()); // child2
3397 3397
3398 // Nothing overlaps the rootLayer at (1, 1), so hit testing there should fin d the root layer. 3398 // Nothing overlaps the rootLayer at (1, 1), so hit testing there should fin d the root layer.
3399 IntPoint testPoint = IntPoint(1, 1); 3399 gfx::Point testPoint = gfx::Point(1, 1);
3400 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 3400 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
3401 ASSERT_TRUE(resultLayer); 3401 ASSERT_TRUE(resultLayer);
3402 EXPECT_EQ(1, resultLayer->id()); 3402 EXPECT_EQ(1, resultLayer->id());
3403 3403
3404 // At (15, 15), child1 and root are the only layers. child1 is expected to b e on top. 3404 // At (15, 15), child1 and root are the only layers. child1 is expected to b e on top.
3405 testPoint = IntPoint(15, 15); 3405 testPoint = gfx::Point(15, 15);
3406 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3406 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3407 ASSERT_TRUE(resultLayer); 3407 ASSERT_TRUE(resultLayer);
3408 EXPECT_EQ(2, resultLayer->id()); 3408 EXPECT_EQ(2, resultLayer->id());
3409 3409
3410 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top. 3410 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
3411 testPoint = IntPoint(51, 20); 3411 testPoint = gfx::Point(51, 20);
3412 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3412 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3413 ASSERT_TRUE(resultLayer); 3413 ASSERT_TRUE(resultLayer);
3414 EXPECT_EQ(3, resultLayer->id()); 3414 EXPECT_EQ(3, resultLayer->id());
3415 3415
3416 // At (80, 51), child2 and grandChild1 overlap. child2 is expected to be on top. 3416 // At (80, 51), child2 and grandChild1 overlap. child2 is expected to be on top.
3417 testPoint = IntPoint(80, 51); 3417 testPoint = gfx::Point(80, 51);
3418 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3418 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3419 ASSERT_TRUE(resultLayer); 3419 ASSERT_TRUE(resultLayer);
3420 EXPECT_EQ(3, resultLayer->id()); 3420 EXPECT_EQ(3, resultLayer->id());
3421 3421
3422 // At (51, 51), all layers overlap each other. child2 is expected to be on t op of all other layers. 3422 // At (51, 51), all layers overlap each other. child2 is expected to be on t op of all other layers.
3423 testPoint = IntPoint(51, 51); 3423 testPoint = gfx::Point(51, 51);
3424 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3424 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3425 ASSERT_TRUE(resultLayer); 3425 ASSERT_TRUE(resultLayer);
3426 EXPECT_EQ(3, resultLayer->id()); 3426 EXPECT_EQ(3, resultLayer->id());
3427 3427
3428 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b e on top. 3428 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b e on top.
3429 testPoint = IntPoint(20, 51); 3429 testPoint = gfx::Point(20, 51);
3430 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3430 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3431 ASSERT_TRUE(resultLayer); 3431 ASSERT_TRUE(resultLayer);
3432 EXPECT_EQ(4, resultLayer->id()); 3432 EXPECT_EQ(4, resultLayer->id());
3433 } 3433 }
3434 3434
3435 class NoScaleContentLayer : public ContentLayer 3435 class NoScaleContentLayer : public ContentLayer
3436 { 3436 {
3437 public: 3437 public:
3438 static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client) { return make_scoped_refptr(new NoScaleContentLayer(client)); } 3438 static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client) { return make_scoped_refptr(new NoScaleContentLayer(client)); }
3439 3439
(...skipping 11 matching lines...) Expand all
3451 return toReturn; 3451 return toReturn;
3452 } 3452 }
3453 3453
3454 TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPI) 3454 TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPI)
3455 { 3455 {
3456 // Verify draw and screen space transforms of layers not in a surface. 3456 // Verify draw and screen space transforms of layers not in a surface.
3457 MockContentLayerClient delegate; 3457 MockContentLayerClient delegate;
3458 WebTransformationMatrix identityMatrix; 3458 WebTransformationMatrix identityMatrix;
3459 3459
3460 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 3460 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
3461 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); 3461 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true);
3462 3462
3463 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate); 3463 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate);
3464 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true); 3464 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
3465 3465
3466 scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableConte ntLayer(&delegate); 3466 scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableConte ntLayer(&delegate);
3467 setLayerPropertiesForTesting(childNoScale.get(), identityMatrix, identityMat rix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true); 3467 setLayerPropertiesForTesting(childNoScale.get(), identityMatrix, identityMat rix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
3468 3468
3469 parent->addChild(child); 3469 parent->addChild(child);
3470 parent->addChild(childNoScale); 3470 parent->addChild(childNoScale);
3471 3471
3472 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 3472 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
3473 int dummyMaxTextureSize = 512; 3473 int dummyMaxTextureSize = 512;
3474 3474
3475 const double deviceScaleFactor = 2.5; 3475 const double deviceScaleFactor = 2.5;
3476 const double pageScaleFactor = 1; 3476 const double pageScaleFactor = 1;
3477 3477
3478 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 3478 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
3479 3479
3480 EXPECT_EQ(deviceScaleFactor * pageScaleFactor, parent->contentsScale()); 3480 EXPECT_EQ(deviceScaleFactor * pageScaleFactor, parent->contentsScale());
3481 EXPECT_EQ(deviceScaleFactor * pageScaleFactor, child->contentsScale()); 3481 EXPECT_EQ(deviceScaleFactor * pageScaleFactor, child->contentsScale());
3482 EXPECT_EQ(1, childNoScale->contentsScale()); 3482 EXPECT_EQ(1, childNoScale->contentsScale());
3483 3483
3484 EXPECT_EQ(1u, renderSurfaceLayerList.size()); 3484 EXPECT_EQ(1u, renderSurfaceLayerList.size());
3485 3485
3486 // Verify parent transforms 3486 // Verify parent transforms
3487 WebTransformationMatrix expectedParentTransform; 3487 WebTransformationMatrix expectedParentTransform;
3488 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform()); 3488 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform());
3489 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm()); 3489 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm());
3490 3490
3491 // Verify results of transformed parent rects 3491 // Verify results of transformed parent rects
3492 FloatRect parentContentBounds(FloatPoint(), FloatSize(parent->contentBounds( ))); 3492 gfx::RectF parentContentBounds(gfx::PointF(), gfx::SizeF(parent->contentBoun ds()));
3493 3493
3494 FloatRect parentDrawRect = MathUtil::mapClippedRect(parent->drawTransform(), parentContentBounds); 3494 gfx::RectF parentDrawRect = MathUtil::mapClippedRect(parent->drawTransform() , parentContentBounds);
3495 FloatRect parentScreenSpaceRect = MathUtil::mapClippedRect(parent->screenSpa ceTransform(), parentContentBounds); 3495 gfx::RectF parentScreenSpaceRect = MathUtil::mapClippedRect(parent->screenSp aceTransform(), parentContentBounds);
3496 3496
3497 FloatRect expectedParentDrawRect(FloatPoint(), parent->bounds()); 3497 gfx::RectF expectedParentDrawRect(gfx::PointF(), parent->bounds());
3498 expectedParentDrawRect.scale(deviceScaleFactor); 3498 expectedParentDrawRect.Scale(deviceScaleFactor);
3499 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentDrawRect); 3499 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentDrawRect);
3500 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentScreenSpaceRect); 3500 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentScreenSpaceRect);
3501 3501
3502 // Verify child transforms 3502 // Verify child transforms
3503 WebTransformationMatrix expectedChildTransform; 3503 WebTransformationMatrix expectedChildTransform;
3504 expectedChildTransform.translate(deviceScaleFactor * child->position().x(), deviceScaleFactor * child->position().y()); 3504 expectedChildTransform.translate(deviceScaleFactor * child->position().x(), deviceScaleFactor * child->position().y());
3505 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 3505 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
3506 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->screenSpaceTr ansform()); 3506 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->screenSpaceTr ansform());
3507 3507
3508 // Verify results of transformed child rects 3508 // Verify results of transformed child rects
3509 FloatRect childContentBounds(FloatPoint(), FloatSize(child->contentBounds()) ); 3509 gfx::RectF childContentBounds(gfx::PointF(), gfx::SizeF(child->contentBounds ()));
3510 3510
3511 FloatRect childDrawRect = MathUtil::mapClippedRect(child->drawTransform(), c hildContentBounds); 3511 gfx::RectF childDrawRect = MathUtil::mapClippedRect(child->drawTransform(), childContentBounds);
3512 FloatRect childScreenSpaceRect = MathUtil::mapClippedRect(child->screenSpace Transform(), childContentBounds); 3512 gfx::RectF childScreenSpaceRect = MathUtil::mapClippedRect(child->screenSpac eTransform(), childContentBounds);
3513 3513
3514 FloatRect expectedChildDrawRect(FloatPoint(), child->bounds()); 3514 gfx::RectF expectedChildDrawRect(gfx::PointF(), child->bounds());
3515 expectedChildDrawRect.move(child->position().x(), child->position().y()); 3515 expectedChildDrawRect.Offset(child->position().x(), child->position().y());
3516 expectedChildDrawRect.scale(deviceScaleFactor); 3516 expectedChildDrawRect.Scale(deviceScaleFactor);
3517 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childDrawRect); 3517 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childDrawRect);
3518 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childScreenSpaceRect); 3518 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childScreenSpaceRect);
3519 3519
3520 // Verify childNoScale transforms 3520 // Verify childNoScale transforms
3521 WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform (); 3521 WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform ();
3522 // All transforms operate on content rects. The child's content rect 3522 // All transforms operate on content rects. The child's content rect
3523 // incorporates device scale, but the childNoScale does not; add it here. 3523 // incorporates device scale, but the childNoScale does not; add it here.
3524 expectedChildNoScaleTransform.scale(deviceScaleFactor); 3524 expectedChildNoScaleTransform.scale(deviceScaleFactor);
3525 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >drawTransform()); 3525 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >drawTransform());
3526 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >screenSpaceTransform()); 3526 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >screenSpaceTransform());
3527 } 3527 }
3528 3528
3529 TEST(LayerTreeHostCommonTest, verifyContentsScale) 3529 TEST(LayerTreeHostCommonTest, verifyContentsScale)
3530 { 3530 {
3531 MockContentLayerClient delegate; 3531 MockContentLayerClient delegate;
3532 WebTransformationMatrix identityMatrix; 3532 WebTransformationMatrix identityMatrix;
3533 3533
3534 WebTransformationMatrix parentScaleMatrix; 3534 WebTransformationMatrix parentScaleMatrix;
3535 const double initialParentScale = 1.75; 3535 const double initialParentScale = 1.75;
3536 parentScaleMatrix.scale(initialParentScale); 3536 parentScaleMatrix.scale(initialParentScale);
3537 3537
3538 WebTransformationMatrix childScaleMatrix; 3538 WebTransformationMatrix childScaleMatrix;
3539 const double initialChildScale = 1.25; 3539 const double initialChildScale = 1.25;
3540 childScaleMatrix.scale(initialChildScale); 3540 childScaleMatrix.scale(initialChildScale);
3541 3541
3542 float fixedRasterScale = 2.5; 3542 float fixedRasterScale = 2.5;
3543 3543
3544 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 3544 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
3545 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); 3545 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true);
3546 3546
3547 scoped_refptr<ContentLayer> childScale = createDrawableContentLayer(&delegat e); 3547 scoped_refptr<ContentLayer> childScale = createDrawableContentLayer(&delegat e);
3548 setLayerPropertiesForTesting(childScale.get(), childScaleMatrix, identityMat rix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true); 3548 setLayerPropertiesForTesting(childScale.get(), childScaleMatrix, identityMat rix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
3549 3549
3550 scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableConte ntLayer(&delegate); 3550 scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableConte ntLayer(&delegate);
3551 setLayerPropertiesForTesting(childNoScale.get(), childScaleMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(12, 12), IntSize(10, 10), true); 3551 setLayerPropertiesForTesting(childNoScale.get(), childScaleMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(12, 12), gfx::Size(10, 10), true);
3552 3552
3553 scoped_refptr<ContentLayer> childNoAutoScale = createDrawableContentLayer(&d elegate); 3553 scoped_refptr<ContentLayer> childNoAutoScale = createDrawableContentLayer(&d elegate);
3554 setLayerPropertiesForTesting(childNoAutoScale.get(), childScaleMatrix, ident ityMatrix, FloatPoint(0, 0), FloatPoint(22, 22), IntSize(10, 10), true); 3554 setLayerPropertiesForTesting(childNoAutoScale.get(), childScaleMatrix, ident ityMatrix, gfx::PointF(0, 0), gfx::PointF(22, 22), gfx::Size(10, 10), true);
3555 childNoAutoScale->setAutomaticallyComputeRasterScale(false); 3555 childNoAutoScale->setAutomaticallyComputeRasterScale(false);
3556 childNoAutoScale->setRasterScale(fixedRasterScale); 3556 childNoAutoScale->setRasterScale(fixedRasterScale);
3557 3557
3558 // FIXME: Remove this when pageScaleFactor is applied in the compositor. 3558 // FIXME: Remove this when pageScaleFactor is applied in the compositor.
3559 // Page scale should not apply to the parent. 3559 // Page scale should not apply to the parent.
3560 parent->setBoundsContainPageScale(true); 3560 parent->setBoundsContainPageScale(true);
3561 3561
3562 parent->addChild(childScale); 3562 parent->addChild(childScale);
3563 parent->addChild(childNoScale); 3563 parent->addChild(childNoScale);
3564 parent->addChild(childNoAutoScale); 3564 parent->addChild(childNoAutoScale);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3630 const double initialParentScale = 2; 3630 const double initialParentScale = 2;
3631 parentScaleMatrix.scale(initialParentScale); 3631 parentScaleMatrix.scale(initialParentScale);
3632 3632
3633 WebTransformationMatrix childScaleMatrix; 3633 WebTransformationMatrix childScaleMatrix;
3634 const double initialChildScale = 3; 3634 const double initialChildScale = 3;
3635 childScaleMatrix.scale(initialChildScale); 3635 childScaleMatrix.scale(initialChildScale);
3636 3636
3637 float fixedRasterScale = 4; 3637 float fixedRasterScale = 4;
3638 3638
3639 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 3639 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
3640 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); 3640 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true);
3641 3641
3642 scoped_refptr<ContentLayer> surfaceScale = createDrawableContentLayer(&deleg ate); 3642 scoped_refptr<ContentLayer> surfaceScale = createDrawableContentLayer(&deleg ate);
3643 setLayerPropertiesForTesting(surfaceScale.get(), childScaleMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true); 3643 setLayerPropertiesForTesting(surfaceScale.get(), childScaleMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
3644 3644
3645 scoped_refptr<ContentLayer> surfaceScaleChildScale = createDrawableContentLa yer(&delegate); 3645 scoped_refptr<ContentLayer> surfaceScaleChildScale = createDrawableContentLa yer(&delegate);
3646 setLayerPropertiesForTesting(surfaceScaleChildScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true); 3646 setLayerPropertiesForTesting(surfaceScaleChildScale.get(), childScaleMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), true);
3647 3647
3648 scoped_refptr<NoScaleContentLayer> surfaceScaleChildNoScale = createNoScaleD rawableContentLayer(&delegate); 3648 scoped_refptr<NoScaleContentLayer> surfaceScaleChildNoScale = createNoScaleD rawableContentLayer(&delegate);
3649 setLayerPropertiesForTesting(surfaceScaleChildNoScale.get(), childScaleMatri x, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true); 3649 setLayerPropertiesForTesting(surfaceScaleChildNoScale.get(), childScaleMatri x, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), true );
3650 3650
3651 scoped_refptr<NoScaleContentLayer> surfaceNoScale = createNoScaleDrawableCon tentLayer(&delegate); 3651 scoped_refptr<NoScaleContentLayer> surfaceNoScale = createNoScaleDrawableCon tentLayer(&delegate);
3652 setLayerPropertiesForTesting(surfaceNoScale.get(), childScaleMatrix, identit yMatrix, FloatPoint(0, 0), FloatPoint(12, 12), IntSize(10, 10), true); 3652 setLayerPropertiesForTesting(surfaceNoScale.get(), childScaleMatrix, identit yMatrix, gfx::PointF(0, 0), gfx::PointF(12, 12), gfx::Size(10, 10), true);
3653 3653
3654 scoped_refptr<ContentLayer> surfaceNoScaleChildScale = createDrawableContent Layer(&delegate); 3654 scoped_refptr<ContentLayer> surfaceNoScaleChildScale = createDrawableContent Layer(&delegate);
3655 setLayerPropertiesForTesting(surfaceNoScaleChildScale.get(), childScaleMatri x, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true); 3655 setLayerPropertiesForTesting(surfaceNoScaleChildScale.get(), childScaleMatri x, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), true );
3656 3656
3657 scoped_refptr<NoScaleContentLayer> surfaceNoScaleChildNoScale = createNoScal eDrawableContentLayer(&delegate); 3657 scoped_refptr<NoScaleContentLayer> surfaceNoScaleChildNoScale = createNoScal eDrawableContentLayer(&delegate);
3658 setLayerPropertiesForTesting(surfaceNoScaleChildNoScale.get(), childScaleMat rix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true); 3658 setLayerPropertiesForTesting(surfaceNoScaleChildNoScale.get(), childScaleMat rix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), tr ue);
3659 3659
3660 scoped_refptr<ContentLayer> surfaceNoAutoScale = createDrawableContentLayer( &delegate); 3660 scoped_refptr<ContentLayer> surfaceNoAutoScale = createDrawableContentLayer( &delegate);
3661 setLayerPropertiesForTesting(surfaceNoAutoScale.get(), childScaleMatrix, ide ntityMatrix, FloatPoint(0, 0), FloatPoint(22, 22), IntSize(10, 10), true); 3661 setLayerPropertiesForTesting(surfaceNoAutoScale.get(), childScaleMatrix, ide ntityMatrix, gfx::PointF(0, 0), gfx::PointF(22, 22), gfx::Size(10, 10), true);
3662 surfaceNoAutoScale->setAutomaticallyComputeRasterScale(false); 3662 surfaceNoAutoScale->setAutomaticallyComputeRasterScale(false);
3663 surfaceNoAutoScale->setRasterScale(fixedRasterScale); 3663 surfaceNoAutoScale->setRasterScale(fixedRasterScale);
3664 3664
3665 scoped_refptr<ContentLayer> surfaceNoAutoScaleChildScale = createDrawableCon tentLayer(&delegate); 3665 scoped_refptr<ContentLayer> surfaceNoAutoScaleChildScale = createDrawableCon tentLayer(&delegate);
3666 setLayerPropertiesForTesting(surfaceNoAutoScaleChildScale.get(), childScaleM atrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true ); 3666 setLayerPropertiesForTesting(surfaceNoAutoScaleChildScale.get(), childScaleM atrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), true);
3667 3667
3668 scoped_refptr<NoScaleContentLayer> surfaceNoAutoScaleChildNoScale = createNo ScaleDrawableContentLayer(&delegate); 3668 scoped_refptr<NoScaleContentLayer> surfaceNoAutoScaleChildNoScale = createNo ScaleDrawableContentLayer(&delegate);
3669 setLayerPropertiesForTesting(surfaceNoAutoScaleChildNoScale.get(), childScal eMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), tr ue); 3669 setLayerPropertiesForTesting(surfaceNoAutoScaleChildNoScale.get(), childScal eMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10) , true);
3670 3670
3671 // FIXME: Remove this when pageScaleFactor is applied in the compositor. 3671 // FIXME: Remove this when pageScaleFactor is applied in the compositor.
3672 // Page scale should not apply to the parent. 3672 // Page scale should not apply to the parent.
3673 parent->setBoundsContainPageScale(true); 3673 parent->setBoundsContainPageScale(true);
3674 3674
3675 parent->addChild(surfaceScale); 3675 parent->addChild(surfaceScale);
3676 parent->addChild(surfaceNoScale); 3676 parent->addChild(surfaceNoScale);
3677 parent->addChild(surfaceNoAutoScale); 3677 parent->addChild(surfaceNoAutoScale);
3678 3678
3679 surfaceScale->setForceRenderSurface(true); 3679 surfaceScale->setForceRenderSurface(true);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
3765 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoAutoScaleChildNoScale->drawTransf orm().m11()); 3765 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoAutoScaleChildNoScale->drawTransf orm().m11());
3766 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoAutoScaleChildNoScale->drawTransf orm().m22()); 3766 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoAutoScaleChildNoScale->drawTransf orm().m22());
3767 } 3767 }
3768 3768
3769 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPI) 3769 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPI)
3770 { 3770 {
3771 MockContentLayerClient delegate; 3771 MockContentLayerClient delegate;
3772 WebTransformationMatrix identityMatrix; 3772 WebTransformationMatrix identityMatrix;
3773 3773
3774 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 3774 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
3775 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(30, 30), true); 3775 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(30, 30), true);
3776 3776
3777 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate); 3777 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate);
3778 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true); 3778 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
3779 3779
3780 WebTransformationMatrix replicaTransform; 3780 WebTransformationMatrix replicaTransform;
3781 replicaTransform.scaleNonUniform(1, -1); 3781 replicaTransform.scaleNonUniform(1, -1);
3782 scoped_refptr<ContentLayer> replica = createDrawableContentLayer(&delegate); 3782 scoped_refptr<ContentLayer> replica = createDrawableContentLayer(&delegate);
3783 setLayerPropertiesForTesting(replica.get(), replicaTransform, identityMatrix , FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true); 3783 setLayerPropertiesForTesting(replica.get(), replicaTransform, identityMatrix , gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
3784 3784
3785 // This layer should end up in the same surface as child, with the same draw 3785 // This layer should end up in the same surface as child, with the same draw
3786 // and screen space transforms. 3786 // and screen space transforms.
3787 scoped_refptr<ContentLayer> duplicateChildNonOwner = createDrawableContentLa yer(&delegate); 3787 scoped_refptr<ContentLayer> duplicateChildNonOwner = createDrawableContentLa yer(&delegate);
3788 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i dentityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true); 3788 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i dentityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), true);
3789 3789
3790 parent->addChild(child); 3790 parent->addChild(child);
3791 child->addChild(duplicateChildNonOwner); 3791 child->addChild(duplicateChildNonOwner);
3792 child->setReplicaLayer(replica.get()); 3792 child->setReplicaLayer(replica.get());
3793 3793
3794 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 3794 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
3795 int dummyMaxTextureSize = 512; 3795 int dummyMaxTextureSize = 512;
3796 3796
3797 const double deviceScaleFactor = 1.5; 3797 const double deviceScaleFactor = 1.5;
3798 parent->setContentsScale(deviceScaleFactor); 3798 parent->setContentsScale(deviceScaleFactor);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3864 int nonexistentId = -1; 3864 int nonexistentId = -1;
3865 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id ())); 3865 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id ()));
3866 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child-> id())); 3866 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child-> id()));
3867 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr andChild->id())); 3867 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr andChild->id()));
3868 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas kLayer->id())); 3868 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas kLayer->id()));
3869 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), replicaLayer->id())); 3869 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), replicaLayer->id()));
3870 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent Id)); 3870 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent Id));
3871 } 3871 }
3872 3872
3873 } // namespace 3873 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698