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

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: ScaleAsVector 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
« no previous file with comments | « cc/layer_tree_host_common.cc ('k') | cc/layer_tree_host_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // screenSpaceTransform, and the hierarchy passed on to children 155 // screenSpaceTransform, and the hierarchy passed on to children
156 // layers should also be identity transforms. 156 // layers should also be identity transforms.
157 157
158 scoped_refptr<Layer> parent = Layer::create(); 158 scoped_refptr<Layer> parent = Layer::create();
159 scoped_refptr<Layer> child = Layer::create(); 159 scoped_refptr<Layer> child = Layer::create();
160 scoped_refptr<Layer> grandChild = Layer::create(); 160 scoped_refptr<Layer> grandChild = Layer::create();
161 parent->addChild(child); 161 parent->addChild(child);
162 child->addChild(grandChild); 162 child->addChild(grandChild);
163 163
164 WebTransformationMatrix identityMatrix; 164 WebTransformationMatrix identityMatrix;
165 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 165 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
166 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(0, 0), false); 166 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(0, 0), false);
167 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(0, 0), false); 167 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(0, 0), false);
168 168
169 executeCalculateDrawTransformsAndVisibility(parent.get()); 169 executeCalculateDrawTransformsAndVisibility(parent.get());
170 170
171 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); 171 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
172 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( )); 172 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( ));
173 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ; 173 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ;
174 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form()); 174 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form());
175 } 175 }
176 176
177 TEST(LayerTreeHostCommonTest, verifyTransformsForSingleLayer) 177 TEST(LayerTreeHostCommonTest, verifyTransformsForSingleLayer)
178 { 178 {
179 WebTransformationMatrix identityMatrix; 179 WebTransformationMatrix identityMatrix;
180 scoped_refptr<Layer> layer = Layer::create(); 180 scoped_refptr<Layer> layer = Layer::create();
181 181
182 scoped_refptr<Layer> root = Layer::create(); 182 scoped_refptr<Layer> root = Layer::create();
183 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(1, 2), false); 183 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false);
184 root->addChild(layer); 184 root->addChild(layer);
185 185
186 // Case 1: setting the sublayer transform should not affect this layer's dra w transform or screen-space transform. 186 // Case 1: setting the sublayer transform should not affect this layer's dra w transform or screen-space transform.
187 WebTransformationMatrix arbitraryTranslation; 187 WebTransformationMatrix arbitraryTranslation;
188 arbitraryTranslation.translate(10, 20); 188 arbitraryTranslation.translate(10, 20);
189 setLayerPropertiesForTesting(layer.get(), identityMatrix, arbitraryTranslati on, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 189 setLayerPropertiesForTesting(layer.get(), identityMatrix, arbitraryTranslati on, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
190 executeCalculateDrawTransformsAndVisibility(root.get()); 190 executeCalculateDrawTransformsAndVisibility(root.get());
191 WebTransformationMatrix expectedDrawTransform = identityMatrix; 191 WebTransformationMatrix expectedDrawTransform = identityMatrix;
192 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedDrawTransform, layer->drawTransform( )); 192 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedDrawTransform, layer->drawTransform( ));
193 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( )); 193 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( ));
194 194
195 // Case 2: Setting the bounds of the layer should not affect either the draw transform or the screenspace transform. 195 // Case 2: Setting the bounds of the layer should not affect either the draw transform or the screenspace transform.
196 WebTransformationMatrix translationToCenter; 196 WebTransformationMatrix translationToCenter;
197 translationToCenter.translate(5, 6); 197 translationToCenter.translate(5, 6);
198 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 12), false); 198 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 12), false);
199 executeCalculateDrawTransformsAndVisibility(root.get()); 199 executeCalculateDrawTransformsAndVisibility(root.get());
200 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform()); 200 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform());
201 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( )); 201 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( ));
202 202
203 // Case 3: The anchor point by itself (without a layer transform) should hav e no effect on the transforms. 203 // Case 3: The anchor point by itself (without a layer transform) should hav e no effect on the transforms.
204 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, Fl oatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 204 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, gf x::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false);
205 executeCalculateDrawTransformsAndVisibility(root.get()); 205 executeCalculateDrawTransformsAndVisibility(root.get());
206 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform()); 206 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform());
207 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( )); 207 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform( ));
208 208
209 // Case 4: A change in actual position affects both the draw transform and s creen space transform. 209 // Case 4: A change in actual position affects both the draw transform and s creen space transform.
210 WebTransformationMatrix positionTransform; 210 WebTransformationMatrix positionTransform;
211 positionTransform.translate(0, 1.2); 211 positionTransform.translate(0, 1.2);
212 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, Fl oatPoint(0.25, 0.25), FloatPoint(0, 1.2f), IntSize(10, 12), false); 212 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, gf x::PointF(0.25, 0.25), gfx::PointF(0, 1.2f), gfx::Size(10, 12), false);
213 executeCalculateDrawTransformsAndVisibility(root.get()); 213 executeCalculateDrawTransformsAndVisibility(root.get());
214 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->drawTransform()); 214 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->drawTransform());
215 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->screenSpaceTransfo rm()); 215 EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->screenSpaceTransfo rm());
216 216
217 // Case 5: In the correct sequence of transforms, the layer transform should pre-multiply the translationToCenter. This is easily tested by 217 // Case 5: In the correct sequence of transforms, the layer transform should pre-multiply the translationToCenter. This is easily tested by
218 // using a scale transform, because scale and translation are not co mmutative. 218 // using a scale transform, because scale and translation are not co mmutative.
219 WebTransformationMatrix layerTransform; 219 WebTransformationMatrix layerTransform;
220 layerTransform.scale3d(2, 2, 1); 220 layerTransform.scale3d(2, 2, 1);
221 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 12), false); 221 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 12), false);
222 executeCalculateDrawTransformsAndVisibility(root.get()); 222 executeCalculateDrawTransformsAndVisibility(root.get());
223 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->drawTransform()); 223 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->drawTransform());
224 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->screenSpaceTransform( )); 224 EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->screenSpaceTransform( ));
225 225
226 // Case 6: The layer transform should occur with respect to the anchor point . 226 // Case 6: The layer transform should occur with respect to the anchor point .
227 WebTransformationMatrix translationToAnchor; 227 WebTransformationMatrix translationToAnchor;
228 translationToAnchor.translate(5, 0); 228 translationToAnchor.translate(5, 0);
229 WebTransformationMatrix expectedResult = translationToAnchor * layerTransfor m * translationToAnchor.inverse(); 229 WebTransformationMatrix expectedResult = translationToAnchor * layerTransfor m * translationToAnchor.inverse();
230 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, Fl oatPoint(0.5, 0), FloatPoint(0, 0), IntSize(10, 12), false); 230 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, gf x::PointF(0.5, 0), gfx::PointF(0, 0), gfx::Size(10, 12), false);
231 executeCalculateDrawTransformsAndVisibility(root.get()); 231 executeCalculateDrawTransformsAndVisibility(root.get());
232 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform()); 232 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform());
233 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform( )); 233 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform( ));
234 234
235 // Case 7: Verify that position pre-multiplies the layer transform. 235 // Case 7: Verify that position pre-multiplies the layer transform.
236 // The current implementation of calculateDrawTransforms does this i mplicitly, but it is 236 // The current implementation of calculateDrawTransforms does this i mplicitly, but it is
237 // still worth testing to detect accidental regressions. 237 // still worth testing to detect accidental regressions.
238 expectedResult = positionTransform * translationToAnchor * layerTransform * translationToAnchor.inverse(); 238 expectedResult = positionTransform * translationToAnchor * layerTransform * translationToAnchor.inverse();
239 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, Fl oatPoint(0.5, 0), FloatPoint(0, 1.2f), IntSize(10, 12), false); 239 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, gf x::PointF(0.5, 0), gfx::PointF(0, 1.2f), gfx::Size(10, 12), false);
240 executeCalculateDrawTransformsAndVisibility(root.get()); 240 executeCalculateDrawTransformsAndVisibility(root.get());
241 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform()); 241 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform());
242 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform( )); 242 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform( ));
243 } 243 }
244 244
245 TEST(LayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy) 245 TEST(LayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy)
246 { 246 {
247 WebTransformationMatrix identityMatrix; 247 WebTransformationMatrix identityMatrix;
248 scoped_refptr<Layer> root = Layer::create(); 248 scoped_refptr<Layer> root = Layer::create();
249 scoped_refptr<Layer> parent = Layer::create(); 249 scoped_refptr<Layer> parent = Layer::create();
250 scoped_refptr<Layer> child = Layer::create(); 250 scoped_refptr<Layer> child = Layer::create();
251 scoped_refptr<Layer> grandChild = Layer::create(); 251 scoped_refptr<Layer> grandChild = Layer::create();
252 root->addChild(parent); 252 root->addChild(parent);
253 parent->addChild(child); 253 parent->addChild(child);
254 child->addChild(grandChild); 254 child->addChild(grandChild);
255 255
256 // One-time setup of root layer 256 // One-time setup of root layer
257 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(1, 2), false); 257 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false);
258 258
259 // Case 1: parent's anchorPoint should not affect child or grandChild. 259 // Case 1: parent's anchorPoint should not affect child or grandChild.
260 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 260 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false);
261 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 261 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
262 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false); 262 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false);
263 executeCalculateDrawTransformsAndVisibility(root.get()); 263 executeCalculateDrawTransformsAndVisibility(root.get());
264 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); 264 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
265 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( )); 265 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform( ));
266 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ; 266 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ;
267 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form()); 267 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTrans form());
268 268
269 // Case 2: parent's position affects child and grandChild. 269 // Case 2: parent's position affects child and grandChild.
270 WebTransformationMatrix parentPositionTransform; 270 WebTransformationMatrix parentPositionTransform;
271 parentPositionTransform.translate(0, 1.2); 271 parentPositionTransform.translate(0, 1.2);
272 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0.25, 0.25), FloatPoint(0, 1.2f), IntSize(10, 12), false); 272 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0.25, 0.25), gfx::PointF(0, 1.2f), 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(root.get()); 275 executeCalculateDrawTransformsAndVisibility(root.get());
276 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->drawTransfor m()); 276 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->drawTransfor m());
277 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->screenSpaceT ransform()); 277 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->screenSpaceT ransform());
278 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->drawTra nsform()); 278 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->drawTra nsform());
279 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->screenS paceTransform()); 279 EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->screenS paceTransform());
280 280
281 // Case 3: parent's local transform affects child and grandchild 281 // Case 3: parent's local transform affects child and grandchild
282 WebTransformationMatrix parentLayerTransform; 282 WebTransformationMatrix parentLayerTransform;
283 parentLayerTransform.scale3d(2, 2, 1); 283 parentLayerTransform.scale3d(2, 2, 1);
284 WebTransformationMatrix parentTranslationToAnchor; 284 WebTransformationMatrix parentTranslationToAnchor;
285 parentTranslationToAnchor.translate(2.5, 3); 285 parentTranslationToAnchor.translate(2.5, 3);
286 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse(); 286 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse();
287 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, identityMat rix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 287 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, identityMat rix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false);
288 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 288 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
289 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false); 289 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false);
290 executeCalculateDrawTransformsAndVisibility(root.get()); 290 executeCalculateDrawTransformsAndVisibility(root.get());
291 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm()); 291 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm());
292 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 292 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
293 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr ansform()); 293 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr ansform());
294 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen SpaceTransform()); 294 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen SpaceTransform());
295 295
296 // Case 4: parent's sublayerMatrix affects child and grandchild 296 // Case 4: parent's sublayerMatrix affects child and grandchild
297 // scaling is used here again so that the correct sequence of transf orms is properly tested. 297 // scaling is used here again so that the correct sequence of transf orms is properly tested.
298 // Note that preserves3D is false, but the sublayer matrix should re tain its 3D properties when given to child. 298 // Note that preserves3D is false, but the sublayer matrix should re tain its 3D properties when given to child.
299 // But then, the child also does not preserve3D. When it gives its h ierarchy to the grandChild, it should be flattened to 2D. 299 // But then, the child also does not preserve3D. When it gives its h ierarchy to the grandChild, it should be flattened to 2D.
300 WebTransformationMatrix parentSublayerMatrix; 300 WebTransformationMatrix parentSublayerMatrix;
301 parentSublayerMatrix.scale3d(10, 10, 3.3); 301 parentSublayerMatrix.scale3d(10, 10, 3.3);
302 WebTransformationMatrix parentTranslationToCenter; 302 WebTransformationMatrix parentTranslationToCenter;
303 parentTranslationToCenter.translate(5, 6); 303 parentTranslationToCenter.translate(5, 6);
304 // Sublayer matrix is applied to the center of the parent layer. 304 // Sublayer matrix is applied to the center of the parent layer.
305 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse() 305 parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
306 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse(); 306 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse();
307 WebTransformationMatrix flattenedCompositeTransform = remove3DComponentOfMat rix(parentCompositeTransform); 307 WebTransformationMatrix flattenedCompositeTransform = remove3DComponentOfMat rix(parentCompositeTransform);
308 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 308 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false) ;
309 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 309 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
310 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false); 310 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false);
311 executeCalculateDrawTransformsAndVisibility(root.get()); 311 executeCalculateDrawTransformsAndVisibility(root.get());
312 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm()); 312 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm());
313 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 313 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
314 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->dra wTransform()); 314 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->dra wTransform());
315 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->scr eenSpaceTransform()); 315 EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->scr eenSpaceTransform());
316 316
317 // Case 5: same as Case 4, except that child does preserve 3D, so the grandC hild should receive the non-flattened composite transform. 317 // Case 5: same as Case 4, except that child does preserve 3D, so the grandC hild should receive the non-flattened composite transform.
318 // 318 //
319 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 319 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false) ;
320 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), true); 320 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), true);
321 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false); 321 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(76, 78), false);
322 executeCalculateDrawTransformsAndVisibility(root.get()); 322 executeCalculateDrawTransformsAndVisibility(root.get());
323 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm()); 323 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransfo rm());
324 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 324 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
325 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr ansform()); 325 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTr ansform());
326 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen SpaceTransform()); 326 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screen SpaceTransform());
327 } 327 }
328 328
329 TEST(LayerTreeHostCommonTest, verifyTransformsForSingleRenderSurface) 329 TEST(LayerTreeHostCommonTest, verifyTransformsForSingleRenderSurface)
330 { 330 {
331 scoped_refptr<Layer> root = Layer::create(); 331 scoped_refptr<Layer> root = Layer::create();
332 scoped_refptr<Layer> parent = Layer::create(); 332 scoped_refptr<Layer> parent = Layer::create();
333 scoped_refptr<Layer> child = Layer::create(); 333 scoped_refptr<Layer> child = Layer::create();
334 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent()); 334 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent());
335 root->addChild(parent); 335 root->addChild(parent);
336 parent->addChild(child); 336 parent->addChild(child);
337 child->addChild(grandChild); 337 child->addChild(grandChild);
338 338
339 // One-time setup of root layer 339 // One-time setup of root layer
340 WebTransformationMatrix identityMatrix; 340 WebTransformationMatrix identityMatrix;
341 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(1, 2), false); 341 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false);
342 342
343 // Child is set up so that a new render surface should be created. 343 // Child is set up so that a new render surface should be created.
344 child->setOpacity(0.5); 344 child->setOpacity(0.5);
345 345
346 WebTransformationMatrix parentLayerTransform; 346 WebTransformationMatrix parentLayerTransform;
347 parentLayerTransform.scale3d(1, 0.9, 1); 347 parentLayerTransform.scale3d(1, 0.9, 1);
348 WebTransformationMatrix parentTranslationToAnchor; 348 WebTransformationMatrix parentTranslationToAnchor;
349 parentTranslationToAnchor.translate(25, 30); 349 parentTranslationToAnchor.translate(25, 30);
350 WebTransformationMatrix parentSublayerMatrix; 350 WebTransformationMatrix parentSublayerMatrix;
351 parentSublayerMatrix.scale3d(0.9, 1, 3.3); 351 parentSublayerMatrix.scale3d(0.9, 1, 3.3);
352 WebTransformationMatrix parentTranslationToCenter; 352 WebTransformationMatrix parentTranslationToCenter;
353 parentTranslationToCenter.translate(50, 60); 353 parentTranslationToCenter.translate(50, 60);
354 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse() 354 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
355 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse(); 355 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse();
356 FloatPoint parentCompositeScale = MathUtil::computeTransform2dScaleComponent s(parentCompositeTransform); 356 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo nents(parentCompositeTransform);
357 WebTransformationMatrix surfaceSublayerTransform; 357 WebTransformationMatrix surfaceSublayerTransform;
358 surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCom positeScale.y()); 358 surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCom positeScale.y());
359 WebTransformationMatrix surfaceSublayerCompositeTransform = parentCompositeT ransform * surfaceSublayerTransform.inverse(); 359 WebTransformationMatrix surfaceSublayerCompositeTransform = parentCompositeT ransform * surfaceSublayerTransform.inverse();
360 360
361 // Child's render surface should not exist yet. 361 // Child's render surface should not exist yet.
362 ASSERT_FALSE(child->renderSurface()); 362 ASSERT_FALSE(child->renderSurface());
363 363
364 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(100, 120), false); 364 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), fals e);
365 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 365 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
366 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(8, 10), false); 366 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(8, 10), false);
367 executeCalculateDrawTransformsAndVisibility(root.get()); 367 executeCalculateDrawTransformsAndVisibility(root.get());
368 368
369 // Render surface should have been created now. 369 // Render surface should have been created now.
370 ASSERT_TRUE(child->renderSurface()); 370 ASSERT_TRUE(child->renderSurface());
371 ASSERT_EQ(child, child->renderTarget()); 371 ASSERT_EQ(child, child->renderTarget());
372 372
373 // The child layer's draw transform should refer to its new render surface. 373 // The child layer's draw transform should refer to its new render surface.
374 // The screen-space transform, however, should still refer to the root. 374 // The screen-space transform, however, should still refer to the root.
375 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerTransform, child->drawTransfo rm()); 375 EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerTransform, child->drawTransfo rm());
376 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform()); 376 EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpace Transform());
(...skipping 13 matching lines...) Expand all
390 scoped_refptr<Layer> child = Layer::create(); 390 scoped_refptr<Layer> child = Layer::create();
391 scoped_refptr<Layer> childReplica = Layer::create(); 391 scoped_refptr<Layer> childReplica = Layer::create();
392 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent()); 392 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent());
393 root->addChild(parent); 393 root->addChild(parent);
394 parent->addChild(child); 394 parent->addChild(child);
395 child->addChild(grandChild); 395 child->addChild(grandChild);
396 child->setReplicaLayer(childReplica.get()); 396 child->setReplicaLayer(childReplica.get());
397 397
398 // One-time setup of root layer 398 // One-time setup of root layer
399 WebTransformationMatrix identityMatrix; 399 WebTransformationMatrix identityMatrix;
400 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(1, 2), false); 400 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false);
401 401
402 // Child is set up so that a new render surface should be created. 402 // Child is set up so that a new render surface should be created.
403 child->setOpacity(0.5); 403 child->setOpacity(0.5);
404 404
405 WebTransformationMatrix parentLayerTransform; 405 WebTransformationMatrix parentLayerTransform;
406 parentLayerTransform.scale3d(2, 2, 1); 406 parentLayerTransform.scale3d(2, 2, 1);
407 WebTransformationMatrix parentTranslationToAnchor; 407 WebTransformationMatrix parentTranslationToAnchor;
408 parentTranslationToAnchor.translate(2.5, 3); 408 parentTranslationToAnchor.translate(2.5, 3);
409 WebTransformationMatrix parentSublayerMatrix; 409 WebTransformationMatrix parentSublayerMatrix;
410 parentSublayerMatrix.scale3d(10, 10, 3.3); 410 parentSublayerMatrix.scale3d(10, 10, 3.3);
411 WebTransformationMatrix parentTranslationToCenter; 411 WebTransformationMatrix parentTranslationToCenter;
412 parentTranslationToCenter.translate(5, 6); 412 parentTranslationToCenter.translate(5, 6);
413 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse() 413 WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
414 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse(); 414 * parentTranslationToCenter * parentSublayerMatrix * parentTranslati onToCenter.inverse();
415 WebTransformationMatrix childTranslationToCenter; 415 WebTransformationMatrix childTranslationToCenter;
416 childTranslationToCenter.translate(8, 9); 416 childTranslationToCenter.translate(8, 9);
417 WebTransformationMatrix replicaLayerTransform; 417 WebTransformationMatrix replicaLayerTransform;
418 replicaLayerTransform.scale3d(3, 3, 1); 418 replicaLayerTransform.scale3d(3, 3, 1);
419 FloatPoint parentCompositeScale = MathUtil::computeTransform2dScaleComponent s(parentCompositeTransform); 419 gfx::Vector2dF parentCompositeScale = MathUtil::computeTransform2dScaleCompo nents(parentCompositeTransform);
420 WebTransformationMatrix surfaceSublayerTransform; 420 WebTransformationMatrix surfaceSublayerTransform;
421 surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCom positeScale.y()); 421 surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCom positeScale.y());
422 WebTransformationMatrix replicaCompositeTransform = parentCompositeTransform * replicaLayerTransform * surfaceSublayerTransform.inverse(); 422 WebTransformationMatrix replicaCompositeTransform = parentCompositeTransform * replicaLayerTransform * surfaceSublayerTransform.inverse();
423 423
424 // Child's render surface should not exist yet. 424 // Child's render surface should not exist yet.
425 ASSERT_FALSE(child->renderSurface()); 425 ASSERT_FALSE(child->renderSurface());
426 426
427 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false); 427 setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSubla yerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(10, 12), false) ;
428 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false); 428 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(16, 18), false);
429 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(-0.5, -0.5), IntSize(1, 1), false); 429 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(-0.5, -0.5), gfx::Size(1, 1), false);
430 setLayerPropertiesForTesting(childReplica.get(), replicaLayerTransform, iden tityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(0, 0), false); 430 setLayerPropertiesForTesting(childReplica.get(), replicaLayerTransform, iden tityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(0, 0), false);
431 executeCalculateDrawTransformsAndVisibility(root.get()); 431 executeCalculateDrawTransformsAndVisibility(root.get());
432 432
433 // Render surface should have been created now. 433 // Render surface should have been created now.
434 ASSERT_TRUE(child->renderSurface()); 434 ASSERT_TRUE(child->renderSurface());
435 ASSERT_EQ(child, child->renderTarget()); 435 ASSERT_EQ(child, child->renderTarget());
436 436
437 EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarg et()->renderSurface()->replicaDrawTransform()); 437 EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarg et()->renderSurface()->replicaDrawTransform());
438 EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarg et()->renderSurface()->replicaScreenSpaceTransform()); 438 EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarg et()->renderSurface()->replicaScreenSpaceTransform());
439 } 439 }
440 440
(...skipping 29 matching lines...) Expand all
470 childOfRS2->addChild(grandChildOfRS2); 470 childOfRS2->addChild(grandChildOfRS2);
471 renderSurface1->setReplicaLayer(replicaOfRS1.get()); 471 renderSurface1->setReplicaLayer(replicaOfRS1.get());
472 renderSurface2->setReplicaLayer(replicaOfRS2.get()); 472 renderSurface2->setReplicaLayer(replicaOfRS2.get());
473 473
474 // In combination with descendantDrawsContent, opacity != 1 forces the layer to have a new renderSurface. 474 // In combination with descendantDrawsContent, opacity != 1 forces the layer to have a new renderSurface.
475 renderSurface1->setOpacity(0.5); 475 renderSurface1->setOpacity(0.5);
476 renderSurface2->setOpacity(0.33f); 476 renderSurface2->setOpacity(0.33f);
477 477
478 // One-time setup of root layer 478 // One-time setup of root layer
479 WebTransformationMatrix identityMatrix; 479 WebTransformationMatrix identityMatrix;
480 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(1, 2), false); 480 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(1, 2), false);
481 481
482 // All layers in the tree are initialized with an anchor at .25 and a size o f (10,10). 482 // All layers in the tree are initialized with an anchor at .25 and a size o f (10,10).
483 // matrix "A" is the composite layer transform used in all layers, centered about the anchor point 483 // matrix "A" is the composite layer transform used in all layers, centered about the anchor point
484 // matrix "B" is the sublayer transform used in all layers, centered about t he center position of the layer. 484 // matrix "B" is the sublayer transform used in all layers, centered about t he center position of the layer.
485 // matrix "R" is the composite replica transform used in all replica layers. 485 // matrix "R" is the composite replica transform used in all replica layers.
486 // 486 //
487 // x component tests that layerTransform and sublayerTransform are done in t he right order (translation and scale are noncommutative). 487 // x component tests that layerTransform and sublayerTransform are done in t he right order (translation and scale are noncommutative).
488 // y component has a translation by 1 for every ancestor, which indicates th e "depth" of the layer in the hierarchy. 488 // y component has a translation by 1 for every ancestor, which indicates th e "depth" of the layer in the hierarchy.
489 WebTransformationMatrix translationToAnchor; 489 WebTransformationMatrix translationToAnchor;
490 translationToAnchor.translate(2.5, 0); 490 translationToAnchor.translate(2.5, 0);
491 WebTransformationMatrix translationToCenter; 491 WebTransformationMatrix translationToCenter;
492 translationToCenter.translate(5, 5); 492 translationToCenter.translate(5, 5);
493 WebTransformationMatrix layerTransform; 493 WebTransformationMatrix layerTransform;
494 layerTransform.translate(1, 1); 494 layerTransform.translate(1, 1);
495 WebTransformationMatrix sublayerTransform; 495 WebTransformationMatrix sublayerTransform;
496 sublayerTransform.scale3d(10, 1, 1); 496 sublayerTransform.scale3d(10, 1, 1);
497 WebTransformationMatrix replicaLayerTransform; 497 WebTransformationMatrix replicaLayerTransform;
498 replicaLayerTransform.scale3d(-2, 5, 1); 498 replicaLayerTransform.scale3d(-2, 5, 1);
499 499
500 WebTransformationMatrix A = translationToAnchor * layerTransform * translati onToAnchor.inverse(); 500 WebTransformationMatrix A = translationToAnchor * layerTransform * translati onToAnchor.inverse();
501 WebTransformationMatrix B = translationToCenter * sublayerTransform * transl ationToCenter.inverse(); 501 WebTransformationMatrix B = translationToCenter * sublayerTransform * transl ationToCenter.inverse();
502 WebTransformationMatrix R = A * translationToAnchor * replicaLayerTransform * translationToAnchor.inverse(); 502 WebTransformationMatrix R = A * translationToAnchor * replicaLayerTransform * translationToAnchor.inverse();
503 503
504 FloatPoint surface1ParentTransformScale = MathUtil::computeTransform2dScaleC omponents(A * B); 504 gfx::Vector2dF surface1ParentTransformScale = MathUtil::computeTransform2dSc aleComponents(A * B);
505 WebTransformationMatrix surface1SublayerTransform; 505 WebTransformationMatrix surface1SublayerTransform;
506 surface1SublayerTransform.scaleNonUniform(surface1ParentTransformScale.x(), surface1ParentTransformScale.y()); 506 surface1SublayerTransform.scaleNonUniform(surface1ParentTransformScale.x(), surface1ParentTransformScale.y());
507 507
508 // SS1 = transform given to the subtree of renderSurface1 508 // SS1 = transform given to the subtree of renderSurface1
509 WebTransformationMatrix SS1 = surface1SublayerTransform; 509 WebTransformationMatrix SS1 = surface1SublayerTransform;
510 // S1 = transform to move from renderSurface1 pixels to the layer space of t he owning layer 510 // S1 = transform to move from renderSurface1 pixels to the layer space of t he owning layer
511 WebTransformationMatrix S1 = surface1SublayerTransform.inverse(); 511 WebTransformationMatrix S1 = surface1SublayerTransform.inverse();
512 512
513 FloatPoint surface2ParentTransformScale = MathUtil::computeTransform2dScaleC omponents(SS1 * A * B); 513 gfx::Vector2dF surface2ParentTransformScale = MathUtil::computeTransform2dSc aleComponents(SS1 * A * B);
514 WebTransformationMatrix surface2SublayerTransform; 514 WebTransformationMatrix surface2SublayerTransform;
515 surface2SublayerTransform.scaleNonUniform(surface2ParentTransformScale.x(), surface2ParentTransformScale.y()); 515 surface2SublayerTransform.scaleNonUniform(surface2ParentTransformScale.x(), surface2ParentTransformScale.y());
516 516
517 // SS2 = transform given to the subtree of renderSurface2 517 // SS2 = transform given to the subtree of renderSurface2
518 WebTransformationMatrix SS2 = surface2SublayerTransform; 518 WebTransformationMatrix SS2 = surface2SublayerTransform;
519 // S2 = transform to move from renderSurface2 pixels to the layer space of t he owning layer 519 // S2 = transform to move from renderSurface2 pixels to the layer space of t he owning layer
520 WebTransformationMatrix S2 = surface2SublayerTransform.inverse(); 520 WebTransformationMatrix S2 = surface2SublayerTransform.inverse();
521 521
522 setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform , FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 522 setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform , gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
523 setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerT ransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 523 setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerT ransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
524 setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerT ransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 524 setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerT ransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
525 setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTran sform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 525 setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTran sform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
526 setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTrans form, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 526 setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTrans form, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
527 setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTrans form, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 527 setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTrans form, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
528 setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublaye rTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 528 setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublaye rTransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
529 setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayer Transform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 529 setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayer Transform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
530 setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayer Transform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false); 530 setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayer Transform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
531 setLayerPropertiesForTesting(replicaOfRS1.get(), replicaLayerTransform, subl ayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(), false); 531 setLayerPropertiesForTesting(replicaOfRS1.get(), replicaLayerTransform, subl ayerTransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(), false);
532 setLayerPropertiesForTesting(replicaOfRS2.get(), replicaLayerTransform, subl ayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(), false); 532 setLayerPropertiesForTesting(replicaOfRS2.get(), replicaLayerTransform, subl ayerTransform, gfx::PointF(0.25, 0), gfx::PointF(0, 0), gfx::Size(), false);
533 533
534 executeCalculateDrawTransformsAndVisibility(root.get()); 534 executeCalculateDrawTransformsAndVisibility(root.get());
535 535
536 // Only layers that are associated with render surfaces should have an actua l renderSurface() value. 536 // Only layers that are associated with render surfaces should have an actua l renderSurface() value.
537 // 537 //
538 ASSERT_TRUE(root->renderSurface()); 538 ASSERT_TRUE(root->renderSurface());
539 ASSERT_FALSE(childOfRoot->renderSurface()); 539 ASSERT_FALSE(childOfRoot->renderSurface());
540 ASSERT_FALSE(grandChildOfRoot->renderSurface()); 540 ASSERT_FALSE(grandChildOfRoot->renderSurface());
541 541
542 ASSERT_TRUE(renderSurface1->renderSurface()); 542 ASSERT_TRUE(renderSurface1->renderSurface());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 // projection. 628 // projection.
629 629
630 scoped_refptr<Layer> root = Layer::create(); 630 scoped_refptr<Layer> root = Layer::create();
631 scoped_refptr<Layer> child = Layer::create(); 631 scoped_refptr<Layer> child = Layer::create();
632 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent()); 632 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent());
633 633
634 WebTransformationMatrix rotationAboutYAxis; 634 WebTransformationMatrix rotationAboutYAxis;
635 rotationAboutYAxis.rotate3d(0, 30, 0); 635 rotationAboutYAxis.rotate3d(0, 30, 0);
636 636
637 const WebTransformationMatrix identityMatrix; 637 const WebTransformationMatrix identityMatrix;
638 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint::zero(), FloatPoint::zero(), IntSize(100, 100), false); 638 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(), gfx::PointF(), gfx::Size(100, 100), false);
639 setLayerPropertiesForTesting(child.get(), rotationAboutYAxis, identityMatrix , FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 639 setLayerPropertiesForTesting(child.get(), rotationAboutYAxis, identityMatrix , gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
640 setLayerPropertiesForTesting(grandChild.get(), rotationAboutYAxis, identityM atrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 640 setLayerPropertiesForTesting(grandChild.get(), rotationAboutYAxis, identityM atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
641 641
642 root->addChild(child); 642 root->addChild(child);
643 child->addChild(grandChild); 643 child->addChild(grandChild);
644 child->setForceRenderSurface(true); 644 child->setForceRenderSurface(true);
645 645
646 // No layers in this test should preserve 3d. 646 // No layers in this test should preserve 3d.
647 ASSERT_FALSE(root->preserves3D()); 647 ASSERT_FALSE(root->preserves3D());
648 ASSERT_FALSE(child->preserves3D()); 648 ASSERT_FALSE(child->preserves3D());
649 ASSERT_FALSE(grandChild->preserves3D()); 649 ASSERT_FALSE(grandChild->preserves3D());
650 650
(...skipping 21 matching lines...) Expand all
672 // 672 //
673 // Normally this isn't a problem, because the layer wouldn't be drawn anyway , but if that layer becomes a renderSurface, then 673 // Normally this isn't a problem, because the layer wouldn't be drawn anyway , but if that layer becomes a renderSurface, then
674 // its drawTransform is implicitly inherited by the rest of the subtree, whi ch then is positioned incorrectly as a result. 674 // its drawTransform is implicitly inherited by the rest of the subtree, whi ch then is positioned incorrectly as a result.
675 675
676 scoped_refptr<Layer> root = Layer::create(); 676 scoped_refptr<Layer> root = Layer::create();
677 scoped_refptr<Layer> child = Layer::create(); 677 scoped_refptr<Layer> child = Layer::create();
678 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent()); 678 scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(n ew LayerWithForcedDrawsContent());
679 679
680 // The child height is zero, but has non-zero width that should be accounted for while computing drawTransforms. 680 // The child height is zero, but has non-zero width that should be accounted for while computing drawTransforms.
681 const WebTransformationMatrix identityMatrix; 681 const WebTransformationMatrix identityMatrix;
682 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint::zero(), FloatPoint::zero(), IntSize(100, 100), false); 682 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(), gfx::PointF(), gfx::Size(100, 100), false);
683 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint::zero(), FloatPoint::zero(), IntSize(10, 0), false); 683 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(), gfx::PointF(), gfx::Size(10, 0), false);
684 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 684 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
685 685
686 root->addChild(child); 686 root->addChild(child);
687 child->addChild(grandChild); 687 child->addChild(grandChild);
688 child->setForceRenderSurface(true); 688 child->setForceRenderSurface(true);
689 689
690 executeCalculateDrawTransformsAndVisibility(root.get()); 690 executeCalculateDrawTransformsAndVisibility(root.get());
691 691
692 ASSERT_TRUE(child->renderSurface()); 692 ASSERT_TRUE(child->renderSurface());
693 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->renderSurface()->draw Transform()); // This is the real test, the rest are sanity checks. 693 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->renderSurface()->draw Transform()); // This is the real test, the rest are sanity checks.
694 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform()); 694 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
695 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ; 695 EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform()) ;
696 } 696 }
697 697
698 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceListForRenderSurfaceWithClipped Layer) 698 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceListForRenderSurfaceWithClipped Layer)
699 { 699 {
700 scoped_refptr<Layer> parent = Layer::create(); 700 scoped_refptr<Layer> parent = Layer::create();
701 scoped_refptr<Layer> renderSurface1 = Layer::create(); 701 scoped_refptr<Layer> renderSurface1 = Layer::create();
702 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent()); 702 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent());
703 703
704 const WebTransformationMatrix identityMatrix; 704 const WebTransformationMatrix identityMatrix;
705 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 705 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
706 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 706 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
707 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint::zero(), FloatPoint(30, 30), IntSize(10, 10), false); 707 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(), gfx::PointF(30, 30), gfx::Size(10, 10), false);
708 708
709 parent->addChild(renderSurface1); 709 parent->addChild(renderSurface1);
710 parent->setMasksToBounds(true); 710 parent->setMasksToBounds(true);
711 renderSurface1->addChild(child); 711 renderSurface1->addChild(child);
712 renderSurface1->setForceRenderSurface(true); 712 renderSurface1->setForceRenderSurface(true);
713 713
714 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 714 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
715 int dummyMaxTextureSize = 512; 715 int dummyMaxTextureSize = 512;
716 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 716 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
717 717
718 // The child layer's content is entirely outside the parent's clip rect, so the intermediate 718 // The child layer's content is entirely outside the parent's clip rect, so the intermediate
719 // render surface should not be listed here, even if it was forced to be cre ated. Render surfaces without children or visible 719 // render surface should not be listed here, even if it was forced to be cre ated. Render surfaces without children or visible
720 // content are unexpected at draw time (e.g. we might try to create a conten t texture of size 0). 720 // content are unexpected at draw time (e.g. we might try to create a conten t texture of size 0).
721 ASSERT_TRUE(parent->renderSurface()); 721 ASSERT_TRUE(parent->renderSurface());
722 ASSERT_FALSE(renderSurface1->renderSurface()); 722 ASSERT_FALSE(renderSurface1->renderSurface());
723 EXPECT_EQ(1U, renderSurfaceLayerList.size()); 723 EXPECT_EQ(1U, renderSurfaceLayerList.size());
724 } 724 }
725 725
726 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceListForTransparentChild) 726 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceListForTransparentChild)
727 { 727 {
728 scoped_refptr<Layer> parent = Layer::create(); 728 scoped_refptr<Layer> parent = Layer::create();
729 scoped_refptr<Layer> renderSurface1 = Layer::create(); 729 scoped_refptr<Layer> renderSurface1 = Layer::create();
730 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent()); 730 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent());
731 731
732 const WebTransformationMatrix identityMatrix; 732 const WebTransformationMatrix identityMatrix;
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 renderSurface1->setForceRenderSurface(true); 738 renderSurface1->setForceRenderSurface(true);
739 renderSurface1->setOpacity(0); 739 renderSurface1->setOpacity(0);
740 740
741 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 741 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
742 int dummyMaxTextureSize = 512; 742 int dummyMaxTextureSize = 512;
743 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 743 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
744 744
745 // Since the layer is transparent, renderSurface1->renderSurface() should no t have gotten added anywhere. 745 // Since the layer is transparent, renderSurface1->renderSurface() should no t have gotten added anywhere.
746 // Also, the drawable content rect should not have been extended by the chil dren. 746 // Also, the drawable content rect should not have been extended by the chil dren.
747 ASSERT_TRUE(parent->renderSurface()); 747 ASSERT_TRUE(parent->renderSurface());
748 EXPECT_EQ(0U, parent->renderSurface()->layerList().size()); 748 EXPECT_EQ(0U, parent->renderSurface()->layerList().size());
749 EXPECT_EQ(1U, renderSurfaceLayerList.size()); 749 EXPECT_EQ(1U, renderSurfaceLayerList.size());
750 EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id()); 750 EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
751 EXPECT_EQ(IntRect(), parent->drawableContentRect()); 751 EXPECT_EQ(gfx::Rect(), parent->drawableContentRect());
752 } 752 }
753 753
754 TEST(LayerTreeHostCommonTest, verifyForceRenderSurface) 754 TEST(LayerTreeHostCommonTest, verifyForceRenderSurface)
755 { 755 {
756 scoped_refptr<Layer> parent = Layer::create(); 756 scoped_refptr<Layer> parent = Layer::create();
757 scoped_refptr<Layer> renderSurface1 = Layer::create(); 757 scoped_refptr<Layer> renderSurface1 = Layer::create();
758 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent()); 758 scoped_refptr<LayerWithForcedDrawsContent> child = make_scoped_refptr(new La yerWithForcedDrawsContent());
759 renderSurface1->setForceRenderSurface(true); 759 renderSurface1->setForceRenderSurface(true);
760 760
761 const WebTransformationMatrix identityMatrix; 761 const WebTransformationMatrix identityMatrix;
762 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 762 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
763 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 763 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
764 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false); 764 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(), gfx::PointF(), gfx::Size(10, 10), false);
765 765
766 parent->addChild(renderSurface1); 766 parent->addChild(renderSurface1);
767 renderSurface1->addChild(child); 767 renderSurface1->addChild(child);
768 768
769 // Sanity check before the actual test 769 // Sanity check before the actual test
770 EXPECT_FALSE(parent->renderSurface()); 770 EXPECT_FALSE(parent->renderSurface());
771 EXPECT_FALSE(renderSurface1->renderSurface()); 771 EXPECT_FALSE(renderSurface1->renderSurface());
772 772
773 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 773 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
774 int dummyMaxTextureSize = 512; 774 int dummyMaxTextureSize = 512;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 // This test checks for correct scroll compensation when the fixed-position container 876 // This test checks for correct scroll compensation when the fixed-position container
877 // is NOT the direct parent of the fixed-position layer. 877 // is NOT the direct parent of the fixed-position layer.
878 DebugScopedSetImplThread scopedImplThread; 878 DebugScopedSetImplThread scopedImplThread;
879 879
880 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 880 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
881 LayerImpl* child = root->children()[0]; 881 LayerImpl* child = root->children()[0];
882 LayerImpl* grandChild = child->children()[0]; 882 LayerImpl* grandChild = child->children()[0];
883 LayerImpl* greatGrandChild = grandChild->children()[0]; 883 LayerImpl* greatGrandChild = grandChild->children()[0];
884 884
885 child->setIsContainerForFixedPositionLayers(true); 885 child->setIsContainerForFixedPositionLayers(true);
886 grandChild->setPosition(FloatPoint(8, 6)); 886 grandChild->setPosition(gfx::PointF(8, 6));
887 greatGrandChild->setFixedToContainerLayer(true); 887 greatGrandChild->setFixedToContainerLayer(true);
888 888
889 // Case 1: scrollDelta of 0, 0 889 // Case 1: scrollDelta of 0, 0
890 child->setScrollDelta(IntSize(0, 0)); 890 child->setScrollDelta(IntSize(0, 0));
891 executeCalculateDrawTransformsAndVisibility(root.get()); 891 executeCalculateDrawTransformsAndVisibility(root.get());
892 892
893 WebTransformationMatrix expectedChildTransform; 893 WebTransformationMatrix expectedChildTransform;
894 WebTransformationMatrix expectedGrandChildTransform; 894 WebTransformationMatrix expectedGrandChildTransform;
895 expectedGrandChildTransform.translate(8, 6); 895 expectedGrandChildTransform.translate(8, 6);
896 896
(...skipping 27 matching lines...) Expand all
924 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 924 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
925 LayerImpl* child = root->children()[0]; 925 LayerImpl* child = root->children()[0];
926 LayerImpl* grandChild = child->children()[0]; 926 LayerImpl* grandChild = child->children()[0];
927 LayerImpl* greatGrandChild = grandChild->children()[0]; 927 LayerImpl* greatGrandChild = grandChild->children()[0];
928 928
929 WebTransformationMatrix rotationAboutZ; 929 WebTransformationMatrix rotationAboutZ;
930 rotationAboutZ.rotate3d(0, 0, 90); 930 rotationAboutZ.rotate3d(0, 0, 90);
931 931
932 child->setIsContainerForFixedPositionLayers(true); 932 child->setIsContainerForFixedPositionLayers(true);
933 child->setTransform(rotationAboutZ); 933 child->setTransform(rotationAboutZ);
934 grandChild->setPosition(FloatPoint(8, 6)); 934 grandChild->setPosition(gfx::PointF(8, 6));
935 grandChild->setTransform(rotationAboutZ); 935 grandChild->setTransform(rotationAboutZ);
936 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget. 936 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget.
937 937
938 // Case 1: scrollDelta of 0, 0 938 // Case 1: scrollDelta of 0, 0
939 child->setScrollDelta(IntSize(0, 0)); 939 child->setScrollDelta(IntSize(0, 0));
940 executeCalculateDrawTransformsAndVisibility(root.get()); 940 executeCalculateDrawTransformsAndVisibility(root.get());
941 941
942 WebTransformationMatrix expectedChildTransform; 942 WebTransformationMatrix expectedChildTransform;
943 expectedChildTransform.multiply(rotationAboutZ); 943 expectedChildTransform.multiply(rotationAboutZ);
944 944
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 986 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
987 LayerImpl* child = root->children()[0]; 987 LayerImpl* child = root->children()[0];
988 LayerImpl* grandChild = child->children()[0]; 988 LayerImpl* grandChild = child->children()[0];
989 LayerImpl* greatGrandChild = grandChild->children()[0]; 989 LayerImpl* greatGrandChild = grandChild->children()[0];
990 990
991 WebTransformationMatrix rotationAboutZ; 991 WebTransformationMatrix rotationAboutZ;
992 rotationAboutZ.rotate3d(0, 0, 90); 992 rotationAboutZ.rotate3d(0, 0, 90);
993 993
994 child->setIsContainerForFixedPositionLayers(true); 994 child->setIsContainerForFixedPositionLayers(true);
995 child->setTransform(rotationAboutZ); 995 child->setTransform(rotationAboutZ);
996 grandChild->setPosition(FloatPoint(8, 6)); 996 grandChild->setPosition(gfx::PointF(8, 6));
997 grandChild->setTransform(rotationAboutZ); 997 grandChild->setTransform(rotationAboutZ);
998 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget. 998 greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is posit ioned upside-down with respect to the renderTarget.
999 999
1000 // Case 1: scrollDelta of 0, 0 1000 // Case 1: scrollDelta of 0, 0
1001 child->setScrollDelta(IntSize(0, 0)); 1001 child->setScrollDelta(IntSize(0, 0));
1002 executeCalculateDrawTransformsAndVisibility(root.get()); 1002 executeCalculateDrawTransformsAndVisibility(root.get());
1003 1003
1004 WebTransformationMatrix expectedChildTransform; 1004 WebTransformationMatrix expectedChildTransform;
1005 expectedChildTransform.multiply(rotationAboutZ); 1005 expectedChildTransform.multiply(rotationAboutZ);
1006 1006
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 // case, the surface drawTransforms also have to be accounted for when check ing the 1044 // case, the surface drawTransforms also have to be accounted for when check ing the
1045 // scrollDelta. 1045 // scrollDelta.
1046 DebugScopedSetImplThread scopedImplThread; 1046 DebugScopedSetImplThread scopedImplThread;
1047 1047
1048 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 1048 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
1049 LayerImpl* child = root->children()[0]; 1049 LayerImpl* child = root->children()[0];
1050 LayerImpl* grandChild = child->children()[0]; 1050 LayerImpl* grandChild = child->children()[0];
1051 LayerImpl* greatGrandChild = grandChild->children()[0]; 1051 LayerImpl* greatGrandChild = grandChild->children()[0];
1052 1052
1053 child->setIsContainerForFixedPositionLayers(true); 1053 child->setIsContainerForFixedPositionLayers(true);
1054 grandChild->setPosition(FloatPoint(8, 6)); 1054 grandChild->setPosition(gfx::PointF(8, 6));
1055 grandChild->setForceRenderSurface(true); 1055 grandChild->setForceRenderSurface(true);
1056 greatGrandChild->setFixedToContainerLayer(true); 1056 greatGrandChild->setFixedToContainerLayer(true);
1057 greatGrandChild->setDrawsContent(true); 1057 greatGrandChild->setDrawsContent(true);
1058 1058
1059 WebTransformationMatrix rotationAboutZ; 1059 WebTransformationMatrix rotationAboutZ;
1060 rotationAboutZ.rotate3d(0, 0, 90); 1060 rotationAboutZ.rotate3d(0, 0, 90);
1061 grandChild->setTransform(rotationAboutZ); 1061 grandChild->setTransform(rotationAboutZ);
1062 1062
1063 // Case 1: scrollDelta of 0, 0 1063 // Case 1: scrollDelta of 0, 0
1064 child->setScrollDelta(IntSize(0, 0)); 1064 child->setScrollDelta(IntSize(0, 0));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 1120
1121 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); 1121 scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests();
1122 LayerImpl* child = root->children()[0]; 1122 LayerImpl* child = root->children()[0];
1123 LayerImpl* grandChild = child->children()[0]; 1123 LayerImpl* grandChild = child->children()[0];
1124 LayerImpl* greatGrandChild = grandChild->children()[0]; 1124 LayerImpl* greatGrandChild = grandChild->children()[0];
1125 1125
1126 // Add one more layer to the test tree for this scenario. 1126 // Add one more layer to the test tree for this scenario.
1127 { 1127 {
1128 WebTransformationMatrix identity; 1128 WebTransformationMatrix identity;
1129 scoped_ptr<LayerImpl> fixedPositionChild = LayerImpl::create(5); 1129 scoped_ptr<LayerImpl> fixedPositionChild = LayerImpl::create(5);
1130 setLayerPropertiesForTesting(fixedPositionChild.get(), identity, identit y, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 1130 setLayerPropertiesForTesting(fixedPositionChild.get(), identity, identit y, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
1131 greatGrandChild->addChild(fixedPositionChild.Pass()); 1131 greatGrandChild->addChild(fixedPositionChild.Pass());
1132 } 1132 }
1133 LayerImpl* fixedPositionChild = greatGrandChild->children()[0]; 1133 LayerImpl* fixedPositionChild = greatGrandChild->children()[0];
1134 1134
1135 // Actually set up the scenario here. 1135 // Actually set up the scenario here.
1136 child->setIsContainerForFixedPositionLayers(true); 1136 child->setIsContainerForFixedPositionLayers(true);
1137 grandChild->setPosition(FloatPoint(8, 6)); 1137 grandChild->setPosition(gfx::PointF(8, 6));
1138 grandChild->setForceRenderSurface(true); 1138 grandChild->setForceRenderSurface(true);
1139 greatGrandChild->setPosition(FloatPoint(40, 60)); 1139 greatGrandChild->setPosition(gfx::PointF(40, 60));
1140 greatGrandChild->setForceRenderSurface(true); 1140 greatGrandChild->setForceRenderSurface(true);
1141 fixedPositionChild->setFixedToContainerLayer(true); 1141 fixedPositionChild->setFixedToContainerLayer(true);
1142 fixedPositionChild->setDrawsContent(true); 1142 fixedPositionChild->setDrawsContent(true);
1143 1143
1144 // The additional rotations, which are non-commutative with translations, he lp to 1144 // The additional rotations, which are non-commutative with translations, he lp to
1145 // verify that we have correct order-of-operations in the final scroll compe nsation. 1145 // verify that we have correct order-of-operations in the final scroll compe nsation.
1146 // Note that rotating about the center of the layer ensures we do not accide ntally 1146 // Note that rotating about the center of the layer ensures we do not accide ntally
1147 // clip away layers that we want to test. 1147 // clip away layers that we want to test.
1148 WebTransformationMatrix rotationAboutZ; 1148 WebTransformationMatrix rotationAboutZ;
1149 rotationAboutZ.translate(50, 50); 1149 rotationAboutZ.translate(50, 50);
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 scoped_refptr<LayerWithForcedDrawsContent> leafNode2 = make_scoped_refptr(ne w LayerWithForcedDrawsContent()); 1374 scoped_refptr<LayerWithForcedDrawsContent> leafNode2 = make_scoped_refptr(ne w LayerWithForcedDrawsContent());
1375 parent->addChild(child); 1375 parent->addChild(child);
1376 child->addChild(grandChild); 1376 child->addChild(grandChild);
1377 grandChild->addChild(greatGrandChild); 1377 grandChild->addChild(greatGrandChild);
1378 1378
1379 // leafNode1 ensures that parent and child are kept on the renderSurfaceLaye rList, 1379 // leafNode1 ensures that parent and child are kept on the renderSurfaceLaye rList,
1380 // even though grandChild and greatGrandChild should be clipped. 1380 // even though grandChild and greatGrandChild should be clipped.
1381 child->addChild(leafNode1); 1381 child->addChild(leafNode1);
1382 greatGrandChild->addChild(leafNode2); 1382 greatGrandChild->addChild(leafNode2);
1383 1383
1384 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false); 1384 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(500, 500), false);
1385 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false); 1385 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(20, 20), false);
1386 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(45, 45), IntSize(10, 10), false); 1386 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(45, 45), gfx::Size(10, 10), false);
1387 setLayerPropertiesForTesting(greatGrandChild.get(), identityMatrix, identity Matrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false); 1387 setLayerPropertiesForTesting(greatGrandChild.get(), identityMatrix, identity Matrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
1388 setLayerPropertiesForTesting(leafNode1.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false); 1388 setLayerPropertiesForTesting(leafNode1.get(), identityMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(500, 500), false);
1389 setLayerPropertiesForTesting(leafNode2.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false); 1389 setLayerPropertiesForTesting(leafNode2.get(), identityMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(20, 20), false);
1390 1390
1391 child->setMasksToBounds(true); 1391 child->setMasksToBounds(true);
1392 child->setOpacity(0.4f); 1392 child->setOpacity(0.4f);
1393 grandChild->setOpacity(0.5); 1393 grandChild->setOpacity(0.5);
1394 greatGrandChild->setOpacity(0.4f); 1394 greatGrandChild->setOpacity(0.4f);
1395 1395
1396 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 1396 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
1397 int dummyMaxTextureSize = 512; 1397 int dummyMaxTextureSize = 512;
1398 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 1398 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
1399 1399
(...skipping 22 matching lines...) Expand all
1422 1422
1423 const WebTransformationMatrix identityMatrix; 1423 const WebTransformationMatrix identityMatrix;
1424 scoped_refptr<Layer> parent = Layer::create(); 1424 scoped_refptr<Layer> parent = Layer::create();
1425 scoped_refptr<Layer> child = Layer::create(); 1425 scoped_refptr<Layer> child = Layer::create();
1426 scoped_refptr<Layer> grandChild = Layer::create(); 1426 scoped_refptr<Layer> grandChild = Layer::create();
1427 scoped_refptr<LayerWithForcedDrawsContent> leafNode = make_scoped_refptr(new LayerWithForcedDrawsContent()); 1427 scoped_refptr<LayerWithForcedDrawsContent> leafNode = make_scoped_refptr(new LayerWithForcedDrawsContent());
1428 parent->addChild(child); 1428 parent->addChild(child);
1429 child->addChild(grandChild); 1429 child->addChild(grandChild);
1430 grandChild->addChild(leafNode); 1430 grandChild->addChild(leafNode);
1431 1431
1432 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 1432 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
1433 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false); 1433 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(20, 20), false);
1434 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(200, 200), IntSize(10, 10), false); 1434 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, gfx::PointF(0, 0), gfx::PointF(200, 200), gfx::Size(10, 10), false);
1435 setLayerPropertiesForTesting(leafNode.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false); 1435 setLayerPropertiesForTesting(leafNode.get(), identityMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
1436 1436
1437 parent->setMasksToBounds(true); 1437 parent->setMasksToBounds(true);
1438 child->setOpacity(0.4f); 1438 child->setOpacity(0.4f);
1439 grandChild->setOpacity(0.4f); 1439 grandChild->setOpacity(0.4f);
1440 1440
1441 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 1441 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
1442 int dummyMaxTextureSize = 512; 1442 int dummyMaxTextureSize = 512;
1443 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 1443 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
1444 1444
1445 // Without an animation, we should cull child and grandChild from the render SurfaceLayerList. 1445 // 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
1480 scoped_refptr<Layer> grandChild2 = Layer::create(); 1480 scoped_refptr<Layer> grandChild2 = Layer::create();
1481 scoped_refptr<Layer> grandChild3 = Layer::create(); 1481 scoped_refptr<Layer> grandChild3 = Layer::create();
1482 scoped_refptr<Layer> grandChild4 = Layer::create(); 1482 scoped_refptr<Layer> grandChild4 = Layer::create();
1483 1483
1484 parent->addChild(child); 1484 parent->addChild(child);
1485 child->addChild(grandChild1); 1485 child->addChild(grandChild1);
1486 child->addChild(grandChild2); 1486 child->addChild(grandChild2);
1487 child->addChild(grandChild3); 1487 child->addChild(grandChild3);
1488 child->addChild(grandChild4); 1488 child->addChild(grandChild4);
1489 1489
1490 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false); 1490 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(500, 500), false);
1491 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false); 1491 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(20, 20), false);
1492 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(10, 10), false); 1492 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(10, 10), false);
1493 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false); 1493 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(15, 15), gfx::Size(10, 10), false);
1494 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false); 1494 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(15, 15), gfx::Size(10, 10), false);
1495 setLayerPropertiesForTesting(grandChild4.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(45, 45), IntSize(10, 10), false); 1495 setLayerPropertiesForTesting(grandChild4.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(45, 45), gfx::Size(10, 10), false);
1496 1496
1497 child->setMasksToBounds(true); 1497 child->setMasksToBounds(true);
1498 grandChild3->setMasksToBounds(true); 1498 grandChild3->setMasksToBounds(true);
1499 1499
1500 // Force everyone to be a render surface. 1500 // Force everyone to be a render surface.
1501 child->setOpacity(0.4f); 1501 child->setOpacity(0.4f);
1502 grandChild1->setOpacity(0.5); 1502 grandChild1->setOpacity(0.5);
1503 grandChild2->setOpacity(0.5); 1503 grandChild2->setOpacity(0.5);
1504 grandChild3->setOpacity(0.5); 1504 grandChild3->setOpacity(0.5);
1505 grandChild4->setOpacity(0.5); 1505 grandChild4->setOpacity(0.5);
1506 1506
1507 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 1507 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
1508 int dummyMaxTextureSize = 512; 1508 int dummyMaxTextureSize = 512;
1509 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 1509 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
1510 1510
1511 EXPECT_RECT_EQ(IntRect(IntPoint(5, 5), IntSize(10, 10)), grandChild1->drawab leContentRect()); 1511 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(5, 5), gfx::Size(10, 10)), grandChild1-> drawableContentRect());
1512 EXPECT_RECT_EQ(IntRect(IntPoint(15, 15), IntSize(5, 5)), grandChild3->drawab leContentRect()); 1512 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(15, 15), gfx::Size(5, 5)), grandChild3-> drawableContentRect());
1513 EXPECT_RECT_EQ(IntRect(IntPoint(15, 15), IntSize(5, 5)), grandChild3->drawab leContentRect()); 1513 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(15, 15), gfx::Size(5, 5)), grandChild3-> drawableContentRect());
1514 EXPECT_TRUE(grandChild4->drawableContentRect().isEmpty()); 1514 EXPECT_TRUE(grandChild4->drawableContentRect().IsEmpty());
1515 } 1515 }
1516 1516
1517 TEST(LayerTreeHostCommonTest, verifyClipRectIsPropagatedCorrectlyToSurfaces) 1517 TEST(LayerTreeHostCommonTest, verifyClipRectIsPropagatedCorrectlyToSurfaces)
1518 { 1518 {
1519 // Verify that renderSurfaces (and their layers) get the appropriate clipRec ts when their parent masksToBounds is true. 1519 // Verify that renderSurfaces (and their layers) get the appropriate clipRec ts when their parent masksToBounds is true.
1520 // 1520 //
1521 // Layers that own renderSurfaces (at least for now) do not inherit any clip ping; 1521 // Layers that own renderSurfaces (at least for now) do not inherit any clip ping;
1522 // instead the surface will enforce the clip for the entire subtree. They ma y still 1522 // instead the surface will enforce the clip for the entire subtree. They ma y still
1523 // have a clipRect of their own layer bounds, however, if masksToBounds was true. 1523 // have a clipRect of their own layer bounds, however, if masksToBounds was true.
1524 // 1524 //
(...skipping 15 matching lines...) Expand all
1540 child->addChild(grandChild2); 1540 child->addChild(grandChild2);
1541 child->addChild(grandChild3); 1541 child->addChild(grandChild3);
1542 child->addChild(grandChild4); 1542 child->addChild(grandChild4);
1543 1543
1544 // the leaf nodes ensure that these grandChildren become renderSurfaces for this test. 1544 // the leaf nodes ensure that these grandChildren become renderSurfaces for this test.
1545 grandChild1->addChild(leafNode1); 1545 grandChild1->addChild(leafNode1);
1546 grandChild2->addChild(leafNode2); 1546 grandChild2->addChild(leafNode2);
1547 grandChild3->addChild(leafNode3); 1547 grandChild3->addChild(leafNode3);
1548 grandChild4->addChild(leafNode4); 1548 grandChild4->addChild(leafNode4);
1549 1549
1550 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false); 1550 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(500, 500), false);
1551 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false); 1551 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(20, 20), false);
1552 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(10, 10), false); 1552 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(10, 10), false);
1553 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false); 1553 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(15, 15), gfx::Size(10, 10), false);
1554 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false); 1554 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(15, 15), gfx::Size(10, 10), false);
1555 setLayerPropertiesForTesting(grandChild4.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(45, 45), IntSize(10, 10), false); 1555 setLayerPropertiesForTesting(grandChild4.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(45, 45), gfx::Size(10, 10), false);
1556 setLayerPropertiesForTesting(leafNode1.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false); 1556 setLayerPropertiesForTesting(leafNode1.get(), identityMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
1557 setLayerPropertiesForTesting(leafNode2.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false); 1557 setLayerPropertiesForTesting(leafNode2.get(), identityMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
1558 setLayerPropertiesForTesting(leafNode3.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false); 1558 setLayerPropertiesForTesting(leafNode3.get(), identityMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
1559 setLayerPropertiesForTesting(leafNode4.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false); 1559 setLayerPropertiesForTesting(leafNode4.get(), identityMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), false);
1560 1560
1561 child->setMasksToBounds(true); 1561 child->setMasksToBounds(true);
1562 grandChild3->setMasksToBounds(true); 1562 grandChild3->setMasksToBounds(true);
1563 grandChild4->setMasksToBounds(true); 1563 grandChild4->setMasksToBounds(true);
1564 1564
1565 // Force everyone to be a render surface. 1565 // Force everyone to be a render surface.
1566 child->setOpacity(0.4f); 1566 child->setOpacity(0.4f);
1567 grandChild1->setOpacity(0.5); 1567 grandChild1->setOpacity(0.5);
1568 grandChild2->setOpacity(0.5); 1568 grandChild2->setOpacity(0.5);
1569 grandChild3->setOpacity(0.5); 1569 grandChild3->setOpacity(0.5);
1570 grandChild4->setOpacity(0.5); 1570 grandChild4->setOpacity(0.5);
1571 1571
1572 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 1572 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
1573 int dummyMaxTextureSize = 512; 1573 int dummyMaxTextureSize = 512;
1574 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 1574 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
1575 1575
1576 ASSERT_TRUE(grandChild1->renderSurface()); 1576 ASSERT_TRUE(grandChild1->renderSurface());
1577 ASSERT_TRUE(grandChild2->renderSurface()); 1577 ASSERT_TRUE(grandChild2->renderSurface());
1578 ASSERT_TRUE(grandChild3->renderSurface()); 1578 ASSERT_TRUE(grandChild3->renderSurface());
1579 EXPECT_FALSE(grandChild4->renderSurface()); // Because grandChild4 is entire ly clipped, it is expected to not have a renderSurface. 1579 EXPECT_FALSE(grandChild4->renderSurface()); // Because grandChild4 is entire ly clipped, it is expected to not have a renderSurface.
1580 1580
1581 // Surfaces are clipped by their parent, but un-affected by the owning layer 's masksToBounds. 1581 // Surfaces are clipped by their parent, but un-affected by the owning layer 's masksToBounds.
1582 EXPECT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild1->render Surface()->clipRect()); 1582 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(0, 0), gfx::Size(20, 20)), grandChild1-> renderSurface()->clipRect());
1583 EXPECT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild2->render Surface()->clipRect()); 1583 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(0, 0), gfx::Size(20, 20)), grandChild2-> renderSurface()->clipRect());
1584 EXPECT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild3->render Surface()->clipRect()); 1584 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(0, 0), gfx::Size(20, 20)), grandChild3-> renderSurface()->clipRect());
1585 } 1585 }
1586 1586
1587 TEST(LayerTreeHostCommonTest, verifyAnimationsForRenderSurfaceHierarchy) 1587 TEST(LayerTreeHostCommonTest, verifyAnimationsForRenderSurfaceHierarchy)
1588 { 1588 {
1589 scoped_refptr<Layer> parent = Layer::create(); 1589 scoped_refptr<Layer> parent = Layer::create();
1590 scoped_refptr<Layer> renderSurface1 = Layer::create(); 1590 scoped_refptr<Layer> renderSurface1 = Layer::create();
1591 scoped_refptr<Layer> renderSurface2 = Layer::create(); 1591 scoped_refptr<Layer> renderSurface2 = Layer::create();
1592 scoped_refptr<Layer> childOfRoot = Layer::create(); 1592 scoped_refptr<Layer> childOfRoot = Layer::create();
1593 scoped_refptr<Layer> childOfRS1 = Layer::create(); 1593 scoped_refptr<Layer> childOfRS1 = Layer::create();
1594 scoped_refptr<Layer> childOfRS2 = Layer::create(); 1594 scoped_refptr<Layer> childOfRS2 = Layer::create();
(...skipping 24 matching lines...) Expand all
1619 WebTransformationMatrix sublayerTransform; 1619 WebTransformationMatrix sublayerTransform;
1620 sublayerTransform.scale3d(10, 1, 1); 1620 sublayerTransform.scale3d(10, 1, 1);
1621 1621
1622 // Put a transform animation on the render surface. 1622 // Put a transform animation on the render surface.
1623 addAnimatedTransformToController(*renderSurface2->layerAnimationController() , 10, 30, 0); 1623 addAnimatedTransformToController(*renderSurface2->layerAnimationController() , 10, 30, 0);
1624 1624
1625 // Also put transform animations on grandChildOfRoot, and grandChildOfRS2 1625 // Also put transform animations on grandChildOfRoot, and grandChildOfRS2
1626 addAnimatedTransformToController(*grandChildOfRoot->layerAnimationController (), 10, 30, 0); 1626 addAnimatedTransformToController(*grandChildOfRoot->layerAnimationController (), 10, 30, 0);
1627 addAnimatedTransformToController(*grandChildOfRS2->layerAnimationController( ), 10, 30, 0); 1627 addAnimatedTransformToController(*grandChildOfRS2->layerAnimationController( ), 10, 30, 0);
1628 1628
1629 setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform , FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1629 setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform , gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1630 setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerT ransform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1630 setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerT ransform, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1631 setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerT ransform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1631 setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerT ransform, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1632 setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTran sform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1632 setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTran sform, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1633 setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTrans form, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1633 setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTrans form, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1634 setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTrans form, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1634 setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTrans form, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1635 setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublaye rTransform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1635 setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublaye rTransform, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false) ;
1636 setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayer Transform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1636 setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayer Transform, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1637 setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayer Transform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false); 1637 setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayer Transform, gfx::PointF(0.25, 0), gfx::PointF(2.5, 0), gfx::Size(10, 10), false);
1638 1638
1639 executeCalculateDrawTransformsAndVisibility(parent.get()); 1639 executeCalculateDrawTransformsAndVisibility(parent.get());
1640 1640
1641 // Only layers that are associated with render surfaces should have an actua l renderSurface() value. 1641 // Only layers that are associated with render surfaces should have an actua l renderSurface() value.
1642 // 1642 //
1643 ASSERT_TRUE(parent->renderSurface()); 1643 ASSERT_TRUE(parent->renderSurface());
1644 ASSERT_FALSE(childOfRoot->renderSurface()); 1644 ASSERT_FALSE(childOfRoot->renderSurface());
1645 ASSERT_FALSE(grandChildOfRoot->renderSurface()); 1645 ASSERT_FALSE(grandChildOfRoot->renderSurface());
1646 1646
1647 ASSERT_TRUE(renderSurface1->renderSurface()); 1647 ASSERT_TRUE(renderSurface1->renderSurface());
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 1722
1723 EXPECT_FLOAT_EQ(3, renderSurface2->screenSpaceTransform().m42()); 1723 EXPECT_FLOAT_EQ(3, renderSurface2->screenSpaceTransform().m42());
1724 EXPECT_FLOAT_EQ(4, childOfRS2->screenSpaceTransform().m42()); 1724 EXPECT_FLOAT_EQ(4, childOfRS2->screenSpaceTransform().m42());
1725 EXPECT_FLOAT_EQ(5, grandChildOfRS2->screenSpaceTransform().m42()); 1725 EXPECT_FLOAT_EQ(5, grandChildOfRS2->screenSpaceTransform().m42());
1726 } 1726 }
1727 1727
1728 TEST(LayerTreeHostCommonTest, verifyVisibleRectForIdentityTransform) 1728 TEST(LayerTreeHostCommonTest, verifyVisibleRectForIdentityTransform)
1729 { 1729 {
1730 // Test the calculateVisibleRect() function works correctly for identity tra nsforms. 1730 // Test the calculateVisibleRect() function works correctly for identity tra nsforms.
1731 1731
1732 IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1732 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1733 WebTransformationMatrix layerToSurfaceTransform; 1733 WebTransformationMatrix layerToSurfaceTransform;
1734 1734
1735 // Case 1: Layer is contained within the surface. 1735 // Case 1: Layer is contained within the surface.
1736 IntRect layerContentRect = IntRect(IntPoint(10, 10), IntSize(30, 30)); 1736 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(10, 10), gfx::Size(30, 30) );
1737 IntRect expected = IntRect(IntPoint(10, 10), IntSize(30, 30)); 1737 gfx::Rect expected = gfx::Rect(gfx::Point(10, 10), gfx::Size(30, 30));
1738 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1738 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1739 EXPECT_RECT_EQ(expected, actual); 1739 EXPECT_RECT_EQ(expected, actual);
1740 1740
1741 // Case 2: Layer is outside the surface rect. 1741 // Case 2: Layer is outside the surface rect.
1742 layerContentRect = IntRect(IntPoint(120, 120), IntSize(30, 30)); 1742 layerContentRect = gfx::Rect(gfx::Point(120, 120), gfx::Size(30, 30));
1743 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1743 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1744 EXPECT_TRUE(actual.isEmpty()); 1744 EXPECT_TRUE(actual.IsEmpty());
1745 1745
1746 // Case 3: Layer is partially overlapping the surface rect. 1746 // Case 3: Layer is partially overlapping the surface rect.
1747 layerContentRect = IntRect(IntPoint(80, 80), IntSize(30, 30)); 1747 layerContentRect = gfx::Rect(gfx::Point(80, 80), gfx::Size(30, 30));
1748 expected = IntRect(IntPoint(80, 80), IntSize(20, 20)); 1748 expected = gfx::Rect(gfx::Point(80, 80), gfx::Size(20, 20));
1749 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1749 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1750 EXPECT_RECT_EQ(expected, actual); 1750 EXPECT_RECT_EQ(expected, actual);
1751 } 1751 }
1752 1752
1753 TEST(LayerTreeHostCommonTest, verifyVisibleRectForTranslations) 1753 TEST(LayerTreeHostCommonTest, verifyVisibleRectForTranslations)
1754 { 1754 {
1755 // Test the calculateVisibleRect() function works correctly for scaling tran sforms. 1755 // Test the calculateVisibleRect() function works correctly for scaling tran sforms.
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(10, 10); 1763 layerToSurfaceTransform.translate(10, 10);
1764 IntRect expected = IntRect(IntPoint(0, 0), IntSize(30, 30)); 1764 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30));
1765 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1765 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1766 EXPECT_RECT_EQ(expected, actual); 1766 EXPECT_RECT_EQ(expected, actual);
1767 1767
1768 // Case 2: Layer is outside the surface rect. 1768 // Case 2: Layer is outside the surface rect.
1769 layerToSurfaceTransform.makeIdentity(); 1769 layerToSurfaceTransform.makeIdentity();
1770 layerToSurfaceTransform.translate(120, 120); 1770 layerToSurfaceTransform.translate(120, 120);
1771 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1771 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1772 EXPECT_TRUE(actual.isEmpty()); 1772 EXPECT_TRUE(actual.IsEmpty());
1773 1773
1774 // Case 3: Layer is partially overlapping the surface rect. 1774 // Case 3: Layer is partially overlapping the surface rect.
1775 layerToSurfaceTransform.makeIdentity(); 1775 layerToSurfaceTransform.makeIdentity();
1776 layerToSurfaceTransform.translate(80, 80); 1776 layerToSurfaceTransform.translate(80, 80);
1777 expected = IntRect(IntPoint(0, 0), IntSize(20, 20)); 1777 expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(20, 20));
1778 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1778 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1779 EXPECT_RECT_EQ(expected, actual); 1779 EXPECT_RECT_EQ(expected, actual);
1780 } 1780 }
1781 1781
1782 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor2DRotations) 1782 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor2DRotations)
1783 { 1783 {
1784 // Test the calculateVisibleRect() function works correctly for rotations ab out z-axis (i.e. 2D rotations). 1784 // Test the calculateVisibleRect() function works correctly for rotations ab out z-axis (i.e. 2D rotations).
1785 // Remember that calculateVisibleRect() should return the visible rect in th e layer's space. 1785 // Remember that calculateVisibleRect() should return the visible rect in th e layer's space.
1786 1786
1787 IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1787 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1788 IntRect layerContentRect = IntRect(IntPoint(0, 0), IntSize(30, 30)); 1788 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30));
1789 WebTransformationMatrix layerToSurfaceTransform; 1789 WebTransformationMatrix layerToSurfaceTransform;
1790 1790
1791 // Case 1: Layer is contained within the surface. 1791 // Case 1: Layer is contained within the surface.
1792 layerToSurfaceTransform.makeIdentity(); 1792 layerToSurfaceTransform.makeIdentity();
1793 layerToSurfaceTransform.translate(50, 50); 1793 layerToSurfaceTransform.translate(50, 50);
1794 layerToSurfaceTransform.rotate(45); 1794 layerToSurfaceTransform.rotate(45);
1795 IntRect expected = IntRect(IntPoint(0, 0), IntSize(30, 30)); 1795 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30));
1796 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1796 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1797 EXPECT_RECT_EQ(expected, actual); 1797 EXPECT_RECT_EQ(expected, actual);
1798 1798
1799 // Case 2: Layer is outside the surface rect. 1799 // Case 2: Layer is outside the surface rect.
1800 layerToSurfaceTransform.makeIdentity(); 1800 layerToSurfaceTransform.makeIdentity();
1801 layerToSurfaceTransform.translate(-50, 0); 1801 layerToSurfaceTransform.translate(-50, 0);
1802 layerToSurfaceTransform.rotate(45); 1802 layerToSurfaceTransform.rotate(45);
1803 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1803 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1804 EXPECT_TRUE(actual.isEmpty()); 1804 EXPECT_TRUE(actual.IsEmpty());
1805 1805
1806 // Case 3: The layer is rotated about its top-left corner. In surface space, the layer 1806 // Case 3: The layer is rotated about its top-left corner. In surface space, the layer
1807 // is oriented diagonally, with the left half outside of the renderS urface. In 1807 // is oriented diagonally, with the left half outside of the renderS urface. In
1808 // this case, the visible rect should still be the entire layer (rem ember the 1808 // this case, the visible rect should still be the entire layer (rem ember the
1809 // visible rect is computed in layer space); both the top-left and 1809 // visible rect is computed in layer space); both the top-left and
1810 // bottom-right corners of the layer are still visible. 1810 // bottom-right corners of the layer are still visible.
1811 layerToSurfaceTransform.makeIdentity(); 1811 layerToSurfaceTransform.makeIdentity();
1812 layerToSurfaceTransform.rotate(45); 1812 layerToSurfaceTransform.rotate(45);
1813 expected = IntRect(IntPoint(0, 0), IntSize(30, 30)); 1813 expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(30, 30));
1814 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1814 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1815 EXPECT_RECT_EQ(expected, actual); 1815 EXPECT_RECT_EQ(expected, actual);
1816 1816
1817 // Case 4: The layer is rotated about its top-left corner, and translated up wards. In 1817 // Case 4: The layer is rotated about its top-left corner, and translated up wards. In
1818 // surface space, the layer is oriented diagonally, with only the to p corner 1818 // surface space, the layer is oriented diagonally, with only the to p corner
1819 // of the surface overlapping the layer. In layer space, the render surface 1819 // of the surface overlapping the layer. In layer space, the render surface
1820 // overlaps the right side of the layer. The visible rect should be the 1820 // overlaps the right side of the layer. The visible rect should be the
1821 // layer's right half. 1821 // layer's right half.
1822 layerToSurfaceTransform.makeIdentity(); 1822 layerToSurfaceTransform.makeIdentity();
1823 layerToSurfaceTransform.translate(0, -sqrt(2.0) * 15); 1823 layerToSurfaceTransform.translate(0, -sqrt(2.0) * 15);
1824 layerToSurfaceTransform.rotate(45); 1824 layerToSurfaceTransform.rotate(45);
1825 expected = IntRect(IntPoint(15, 0), IntSize(15, 30)); // right half of layer bounds. 1825 expected = gfx::Rect(gfx::Point(15, 0), gfx::Size(15, 30)); // right half of layer bounds.
1826 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1826 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1827 EXPECT_RECT_EQ(expected, actual); 1827 EXPECT_RECT_EQ(expected, actual);
1828 } 1828 }
1829 1829
1830 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform) 1830 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform)
1831 { 1831 {
1832 // Test that the calculateVisibleRect() function works correctly for 3d tran sforms. 1832 // Test that the calculateVisibleRect() function works correctly for 3d tran sforms.
1833 1833
1834 IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1834 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1835 IntRect layerContentRect = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1835 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100) );
1836 WebTransformationMatrix layerToSurfaceTransform; 1836 WebTransformationMatrix layerToSurfaceTransform;
1837 1837
1838 // Case 1: Orthographic projection of a layer rotated about y-axis by 45 deg rees, should be fully contained in the renderSurface. 1838 // Case 1: Orthographic projection of a layer rotated about y-axis by 45 deg rees, should be fully contained in the renderSurface.
1839 layerToSurfaceTransform.makeIdentity(); 1839 layerToSurfaceTransform.makeIdentity();
1840 layerToSurfaceTransform.rotate3d(0, 45, 0); 1840 layerToSurfaceTransform.rotate3d(0, 45, 0);
1841 IntRect expected = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1841 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100));
1842 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1842 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1843 EXPECT_RECT_EQ(expected, actual); 1843 EXPECT_RECT_EQ(expected, actual);
1844 1844
1845 // Case 2: Orthographic projection of a layer rotated about y-axis by 45 deg rees, but 1845 // Case 2: Orthographic projection of a layer rotated about y-axis by 45 deg rees, but
1846 // shifted to the side so only the right-half the layer would be vis ible on 1846 // shifted to the side so only the right-half the layer would be vis ible on
1847 // the surface. 1847 // the surface.
1848 double halfWidthOfRotatedLayer = (100 / sqrt(2.0)) * 0.5; // 100 is the un-r otated layer width; divided by sqrt(2) is the rotated width. 1848 double halfWidthOfRotatedLayer = (100 / sqrt(2.0)) * 0.5; // 100 is the un-r otated layer width; divided by sqrt(2) is the rotated width.
1849 layerToSurfaceTransform.makeIdentity(); 1849 layerToSurfaceTransform.makeIdentity();
1850 layerToSurfaceTransform.translate(-halfWidthOfRotatedLayer, 0); 1850 layerToSurfaceTransform.translate(-halfWidthOfRotatedLayer, 0);
1851 layerToSurfaceTransform.rotate3d(0, 45, 0); // rotates about the left edge o f the layer 1851 layerToSurfaceTransform.rotate3d(0, 45, 0); // rotates about the left edge o f the layer
1852 expected = IntRect(IntPoint(50, 0), IntSize(50, 100)); // right half of the layer. 1852 expected = gfx::Rect(gfx::Point(50, 0), gfx::Size(50, 100)); // right half o f the layer.
1853 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1853 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1854 EXPECT_RECT_EQ(expected, actual); 1854 EXPECT_RECT_EQ(expected, actual);
1855 } 1855 }
1856 1856
1857 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform) 1857 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform)
1858 { 1858 {
1859 // Test the calculateVisibleRect() function works correctly when the layer h as a 1859 // Test the calculateVisibleRect() function works correctly when the layer h as a
1860 // perspective projection onto the target surface. 1860 // perspective projection onto the target surface.
1861 1861
1862 IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1862 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1863 IntRect layerContentRect = IntRect(IntPoint(-50, -50), IntSize(200, 200)); 1863 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(200, 200));
1864 WebTransformationMatrix layerToSurfaceTransform; 1864 WebTransformationMatrix layerToSurfaceTransform;
1865 1865
1866 // Case 1: Even though the layer is twice as large as the surface, due to pe rspective 1866 // Case 1: Even though the layer is twice as large as the surface, due to pe rspective
1867 // foreshortening, the layer will fit fully in the surface when its translated 1867 // foreshortening, the layer will fit fully in the surface when its translated
1868 // more than the perspective amount. 1868 // more than the perspective amount.
1869 layerToSurfaceTransform.makeIdentity(); 1869 layerToSurfaceTransform.makeIdentity();
1870 1870
1871 // The following sequence of transforms applies the perspective about the ce nter of the surface. 1871 // The following sequence of transforms applies the perspective about the ce nter of the surface.
1872 layerToSurfaceTransform.translate(50, 50); 1872 layerToSurfaceTransform.translate(50, 50);
1873 layerToSurfaceTransform.applyPerspective(9); 1873 layerToSurfaceTransform.applyPerspective(9);
1874 layerToSurfaceTransform.translate(-50, -50); 1874 layerToSurfaceTransform.translate(-50, -50);
1875 1875
1876 // This translate places the layer in front of the surface's projection plan e. 1876 // This translate places the layer in front of the surface's projection plan e.
1877 layerToSurfaceTransform.translate3d(0, 0, -27); 1877 layerToSurfaceTransform.translate3d(0, 0, -27);
1878 1878
1879 IntRect expected = IntRect(IntPoint(-50, -50), IntSize(200, 200)); 1879 gfx::Rect expected = gfx::Rect(gfx::Point(-50, -50), gfx::Size(200, 200));
1880 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1880 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1881 EXPECT_RECT_EQ(expected, actual); 1881 EXPECT_RECT_EQ(expected, actual);
1882 1882
1883 // Case 2: same projection as before, except that the layer is also translat ed to the 1883 // Case 2: same projection as before, except that the layer is also translat ed to the
1884 // side, so that only the right half of the layer should be visible. 1884 // side, so that only the right half of the layer should be visible.
1885 // 1885 //
1886 // Explanation of expected result: 1886 // Explanation of expected result:
1887 // The perspective ratio is (z distance between layer and camera origin) / ( z distance between projection plane and camera origin) == ((-27 - 9) / 9) 1887 // The perspective ratio is (z distance between layer and camera origin) / ( z distance between projection plane and camera origin) == ((-27 - 9) / 9)
1888 // 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 1888 // 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
1889 // visible), then we would need to translate by (-36 / 9) * -50 == -200 in t he layer's units. 1889 // visible), then we would need to translate by (-36 / 9) * -50 == -200 in t he layer's units.
1890 // 1890 //
1891 layerToSurfaceTransform.translate3d(-200, 0, 0); 1891 layerToSurfaceTransform.translate3d(-200, 0, 0);
1892 expected = IntRect(IntPoint(50, -50), IntSize(100, 200)); // The right half of the layer's bounding rect. 1892 expected = gfx::Rect(gfx::Point(50, -50), gfx::Size(100, 200)); // The right half of the layer's bounding rect.
1893 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform); 1893 actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerC ontentRect, layerToSurfaceTransform);
1894 EXPECT_RECT_EQ(expected, actual); 1894 EXPECT_RECT_EQ(expected, actual);
1895 } 1895 }
1896 1896
1897 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicIsNotClippedBehi ndSurface) 1897 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicIsNotClippedBehi ndSurface)
1898 { 1898 {
1899 // There is currently no explicit concept of an orthographic projection plan e in our 1899 // There is currently no explicit concept of an orthographic projection plan e in our
1900 // code (nor in the CSS spec to my knowledge). Therefore, layers that are te chnically 1900 // code (nor in the CSS spec to my knowledge). Therefore, layers that are te chnically
1901 // behind the surface in an orthographic world should not be clipped when th ey are 1901 // behind the surface in an orthographic world should not be clipped when th ey are
1902 // flattened to the surface. 1902 // flattened to the surface.
1903 1903
1904 IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1904 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100 ));
1905 IntRect layerContentRect = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1905 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100) );
1906 WebTransformationMatrix layerToSurfaceTransform; 1906 WebTransformationMatrix layerToSurfaceTransform;
1907 1907
1908 // This sequence of transforms effectively rotates the layer about the y-axi s at the 1908 // This sequence of transforms effectively rotates the layer about the y-axi s at the
1909 // center of the layer. 1909 // center of the layer.
1910 layerToSurfaceTransform.makeIdentity(); 1910 layerToSurfaceTransform.makeIdentity();
1911 layerToSurfaceTransform.translate(50, 0); 1911 layerToSurfaceTransform.translate(50, 0);
1912 layerToSurfaceTransform.rotate3d(0, 45, 0); 1912 layerToSurfaceTransform.rotate3d(0, 45, 0);
1913 layerToSurfaceTransform.translate(-50, 0); 1913 layerToSurfaceTransform.translate(-50, 0);
1914 1914
1915 IntRect expected = IntRect(IntPoint(0, 0), IntSize(100, 100)); 1915 gfx::Rect expected = gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 100));
1916 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1916 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1917 EXPECT_RECT_EQ(expected, actual); 1917 EXPECT_RECT_EQ(expected, actual);
1918 } 1918 }
1919 1919
1920 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW) 1920 TEST(LayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW)
1921 { 1921 {
1922 // Test the calculateVisibleRect() function works correctly when projecting a surface 1922 // Test the calculateVisibleRect() function works correctly when projecting a surface
1923 // onto a layer, but the layer is partially behind the camera (not just behi nd the 1923 // onto a layer, but the layer is partially behind the camera (not just behi nd the
1924 // projection plane). In this case, the cartesian coordinates may seem to be valid, 1924 // projection plane). In this case, the cartesian coordinates may seem to be valid,
1925 // but actually they are not. The visibleRect needs to be properly clipped b y the 1925 // but actually they are not. The visibleRect needs to be properly clipped b y the
1926 // w = 0 plane in homogeneous coordinates before converting to cartesian coo rdinates. 1926 // w = 0 plane in homogeneous coordinates before converting to cartesian coo rdinates.
1927 1927
1928 IntRect targetSurfaceRect = IntRect(IntPoint(-50, -50), IntSize(100, 100)); 1928 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100, 100));
1929 IntRect layerContentRect = IntRect(IntPoint(-10, -1), IntSize(20, 2)); 1929 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -1), gfx::Size(20, 2) );
1930 WebTransformationMatrix layerToSurfaceTransform; 1930 WebTransformationMatrix layerToSurfaceTransform;
1931 1931
1932 // The layer is positioned so that the right half of the layer should be in front of 1932 // The layer is positioned so that the right half of the layer should be in front of
1933 // the camera, while the other half is behind the surface's projection plane . The 1933 // the camera, while the other half is behind the surface's projection plane . The
1934 // following sequence of transforms applies the perspective and rotation abo ut the 1934 // following sequence of transforms applies the perspective and rotation abo ut the
1935 // center of the layer. 1935 // center of the layer.
1936 layerToSurfaceTransform.makeIdentity(); 1936 layerToSurfaceTransform.makeIdentity();
1937 layerToSurfaceTransform.applyPerspective(1); 1937 layerToSurfaceTransform.applyPerspective(1);
1938 layerToSurfaceTransform.translate3d(-2, 0, 1); 1938 layerToSurfaceTransform.translate3d(-2, 0, 1);
1939 layerToSurfaceTransform.rotate3d(0, 45, 0); 1939 layerToSurfaceTransform.rotate3d(0, 45, 0);
1940 1940
1941 // Sanity check that this transform does indeed cause w < 0 when applying th e 1941 // Sanity check that this transform does indeed cause w < 0 when applying th e
1942 // transform, otherwise this code is not testing the intended scenario. 1942 // transform, otherwise this code is not testing the intended scenario.
1943 bool clipped = false; 1943 bool clipped = false;
1944 MathUtil::mapQuad(layerToSurfaceTransform, FloatQuad(FloatRect(layerContentR ect)), clipped); 1944 MathUtil::mapQuad(layerToSurfaceTransform, FloatQuad(gfx::RectF(layerContent Rect)), clipped);
1945 ASSERT_TRUE(clipped); 1945 ASSERT_TRUE(clipped);
1946 1946
1947 int expectedXPosition = 0; 1947 int expectedXPosition = 0;
1948 int expectedWidth = 10; 1948 int expectedWidth = 10;
1949 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1949 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1950 EXPECT_EQ(expectedXPosition, actual.x()); 1950 EXPECT_EQ(expectedXPosition, actual.x());
1951 EXPECT_EQ(expectedWidth, actual.width()); 1951 EXPECT_EQ(expectedWidth, actual.width());
1952 } 1952 }
1953 1953
1954 TEST(LayerTreeHostCommonTest, verifyVisibleRectForPerspectiveUnprojection) 1954 TEST(LayerTreeHostCommonTest, verifyVisibleRectForPerspectiveUnprojection)
1955 { 1955 {
1956 // To determine visibleRect in layer space, there needs to be an un-projecti on from 1956 // To determine visibleRect in layer space, there needs to be an un-projecti on from
1957 // surface space to layer space. When the original transform was a perspecti ve 1957 // surface space to layer space. When the original transform was a perspecti ve
1958 // projection that was clipped, it returns a rect that encloses the clipped bounds. 1958 // projection that was clipped, it returns a rect that encloses the clipped bounds.
1959 // Un-projecting this new rect may require clipping again. 1959 // Un-projecting this new rect may require clipping again.
1960 1960
1961 // This sequence of transforms causes one corner of the layer to protrude ac ross the w = 0 plane, and should be clipped. 1961 // This sequence of transforms causes one corner of the layer to protrude ac ross the w = 0 plane, and should be clipped.
1962 IntRect targetSurfaceRect = IntRect(IntPoint(-50, -50), IntSize(100, 100)); 1962 gfx::Rect targetSurfaceRect = gfx::Rect(gfx::Point(-50, -50), gfx::Size(100, 100));
1963 IntRect layerContentRect = IntRect(IntPoint(-10, -10), IntSize(20, 20)); 1963 gfx::Rect layerContentRect = gfx::Rect(gfx::Point(-10, -10), gfx::Size(20, 2 0));
1964 WebTransformationMatrix layerToSurfaceTransform; 1964 WebTransformationMatrix layerToSurfaceTransform;
1965 layerToSurfaceTransform.makeIdentity(); 1965 layerToSurfaceTransform.makeIdentity();
1966 layerToSurfaceTransform.applyPerspective(1); 1966 layerToSurfaceTransform.applyPerspective(1);
1967 layerToSurfaceTransform.translate3d(0, 0, -5); 1967 layerToSurfaceTransform.translate3d(0, 0, -5);
1968 layerToSurfaceTransform.rotate3d(0, 45, 0); 1968 layerToSurfaceTransform.rotate3d(0, 45, 0);
1969 layerToSurfaceTransform.rotate3d(80, 0, 0); 1969 layerToSurfaceTransform.rotate3d(80, 0, 0);
1970 1970
1971 // Sanity check that un-projection does indeed cause w < 0, otherwise this c ode is not 1971 // Sanity check that un-projection does indeed cause w < 0, otherwise this c ode is not
1972 // testing the intended scenario. 1972 // testing the intended scenario.
1973 bool clipped = false; 1973 bool clipped = false;
1974 FloatRect clippedRect = MathUtil::mapClippedRect(layerToSurfaceTransform, la yerContentRect); 1974 gfx::RectF clippedRect = MathUtil::mapClippedRect(layerToSurfaceTransform, l ayerContentRect);
1975 MathUtil::projectQuad(layerToSurfaceTransform.inverse(), FloatQuad(clippedRe ct), clipped); 1975 MathUtil::projectQuad(layerToSurfaceTransform.inverse(), FloatQuad(clippedRe ct), clipped);
1976 ASSERT_TRUE(clipped); 1976 ASSERT_TRUE(clipped);
1977 1977
1978 // Only the corner of the layer is not visible on the surface because of bei ng 1978 // Only the corner of the layer is not visible on the surface because of bei ng
1979 // clipped. But, the net result of rounding visible region to an axis-aligne d rect is 1979 // clipped. But, the net result of rounding visible region to an axis-aligne d rect is
1980 // that the entire layer should still be considered visible. 1980 // that the entire layer should still be considered visible.
1981 IntRect expected = IntRect(IntPoint(-10, -10), IntSize(20, 20)); 1981 gfx::Rect expected = gfx::Rect(gfx::Point(-10, -10), gfx::Size(20, 20));
1982 IntRect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect , layerContentRect, layerToSurfaceTransform); 1982 gfx::Rect actual = LayerTreeHostCommon::calculateVisibleRect(targetSurfaceRe ct, layerContentRect, layerToSurfaceTransform);
1983 EXPECT_RECT_EQ(expected, actual); 1983 EXPECT_RECT_EQ(expected, actual);
1984 } 1984 }
1985 1985
1986 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForSimpleLayer s) 1986 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForSimpleLayer s)
1987 { 1987 {
1988 scoped_refptr<Layer> root = Layer::create(); 1988 scoped_refptr<Layer> root = Layer::create();
1989 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 1989 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
1990 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 1990 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
1991 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 1991 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
1992 root->addChild(child1); 1992 root->addChild(child1);
1993 root->addChild(child2); 1993 root->addChild(child2);
1994 root->addChild(child3); 1994 root->addChild(child3);
1995 1995
1996 WebTransformationMatrix identityMatrix; 1996 WebTransformationMatrix identityMatrix;
1997 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 1997 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
1998 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(50, 50), false); 1998 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(50, 50), false);
1999 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false); 1999 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2000 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false); 2000 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2001 2001
2002 executeCalculateDrawTransformsAndVisibility(root.get()); 2002 executeCalculateDrawTransformsAndVisibility(root.get());
2003 2003
2004 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableConte ntRect()); 2004 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect());
2005 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect()); 2005 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawableContentRect());
2006 2006
2007 // Layers that do not draw content should have empty visibleContentRects. 2007 // Layers that do not draw content should have empty visibleContentRects.
2008 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect()); 2008 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visibleContentRect());
2009 2009
2010 // layer visibleContentRects are clipped by their targetSurface 2010 // layer visibleContentRects are clipped by their targetSurface
2011 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect()); 2011 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visibleContentRect());
2012 EXPECT_RECT_EQ(IntRect(0, 0, 25, 25), child2->visibleContentRect()); 2012 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visibleContentRect());
2013 EXPECT_TRUE(child3->visibleContentRect().isEmpty()); 2013 EXPECT_TRUE(child3->visibleContentRect().IsEmpty());
2014 2014
2015 // layer drawableContentRects are not clipped. 2015 // layer drawableContentRects are not clipped.
2016 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->drawableContentRect()); 2016 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawableContentRect());
2017 EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect()); 2017 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawableContentRect());
2018 EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect()); 2018 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawableContentRect());
2019 } 2019 }
2020 2020
2021 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersClipp edByLayer) 2021 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersClipp edByLayer)
2022 { 2022 {
2023 scoped_refptr<Layer> root = Layer::create(); 2023 scoped_refptr<Layer> root = Layer::create();
2024 scoped_refptr<Layer> child = Layer::create(); 2024 scoped_refptr<Layer> child = Layer::create();
2025 scoped_refptr<LayerWithForcedDrawsContent> grandChild1 = make_scoped_refptr( new LayerWithForcedDrawsContent()); 2025 scoped_refptr<LayerWithForcedDrawsContent> grandChild1 = make_scoped_refptr( new LayerWithForcedDrawsContent());
2026 scoped_refptr<LayerWithForcedDrawsContent> grandChild2 = make_scoped_refptr( new LayerWithForcedDrawsContent()); 2026 scoped_refptr<LayerWithForcedDrawsContent> grandChild2 = make_scoped_refptr( new LayerWithForcedDrawsContent());
2027 scoped_refptr<LayerWithForcedDrawsContent> grandChild3 = make_scoped_refptr( new LayerWithForcedDrawsContent()); 2027 scoped_refptr<LayerWithForcedDrawsContent> grandChild3 = make_scoped_refptr( new LayerWithForcedDrawsContent());
2028 root->addChild(child); 2028 root->addChild(child);
2029 child->addChild(grandChild1); 2029 child->addChild(grandChild1);
2030 child->addChild(grandChild2); 2030 child->addChild(grandChild2);
2031 child->addChild(grandChild3); 2031 child->addChild(grandChild3);
2032 2032
2033 WebTransformationMatrix identityMatrix; 2033 WebTransformationMatrix identityMatrix;
2034 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2034 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2035 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2035 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2036 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false); 2036 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2037 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false); 2037 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2038 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false); 2038 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, gfx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2039 2039
2040 child->setMasksToBounds(true); 2040 child->setMasksToBounds(true);
2041 executeCalculateDrawTransformsAndVisibility(root.get()); 2041 executeCalculateDrawTransformsAndVisibility(root.get());
2042 2042
2043 ASSERT_FALSE(child->renderSurface()); 2043 ASSERT_FALSE(child->renderSurface());
2044 2044
2045 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableConte ntRect()); 2045 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect());
2046 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect()); 2046 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawableContentRect());
2047 2047
2048 // Layers that do not draw content should have empty visibleContentRects. 2048 // Layers that do not draw content should have empty visibleContentRects.
2049 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect()); 2049 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visibleContentRect());
2050 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), child->visibleContentRect()); 2050 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visibleContentRect());
2051 2051
2052 // All grandchild visibleContentRects should be clipped by child. 2052 // All grandchild visibleContentRects should be clipped by child.
2053 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), grandChild1->visibleContentRect()); 2053 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grandChild1->visibleContentRect());
2054 EXPECT_RECT_EQ(IntRect(0, 0, 25, 25), grandChild2->visibleContentRect()); 2054 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grandChild2->visibleContentRect());
2055 EXPECT_TRUE(grandChild3->visibleContentRect().isEmpty()); 2055 EXPECT_TRUE(grandChild3->visibleContentRect().IsEmpty());
2056 2056
2057 // All grandchild drawableContentRects should also be clipped by child. 2057 // All grandchild drawableContentRects should also be clipped by child.
2058 EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), grandChild1->drawableContentRect()); 2058 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), grandChild1->drawableContentRect());
2059 EXPECT_RECT_EQ(IntRect(75, 75, 25, 25), grandChild2->drawableContentRect()); 2059 EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25), grandChild2->drawableContentRect() );
2060 EXPECT_TRUE(grandChild3->drawableContentRect().isEmpty()); 2060 EXPECT_TRUE(grandChild3->drawableContentRect().IsEmpty());
2061 } 2061 }
2062 2062
2063 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersInUnc lippedRenderSurface) 2063 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersInUnc lippedRenderSurface)
2064 { 2064 {
2065 scoped_refptr<Layer> root = Layer::create(); 2065 scoped_refptr<Layer> root = Layer::create();
2066 scoped_refptr<Layer> renderSurface1 = Layer::create(); 2066 scoped_refptr<Layer> renderSurface1 = Layer::create();
2067 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2067 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2068 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2068 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2069 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2069 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2070 root->addChild(renderSurface1); 2070 root->addChild(renderSurface1);
2071 renderSurface1->addChild(child1); 2071 renderSurface1->addChild(child1);
2072 renderSurface1->addChild(child2); 2072 renderSurface1->addChild(child2);
2073 renderSurface1->addChild(child3); 2073 renderSurface1->addChild(child3);
2074 2074
2075 WebTransformationMatrix identityMatrix; 2075 WebTransformationMatrix identityMatrix;
2076 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2076 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2077 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false); 2077 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false);
2078 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false); 2078 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2079 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false); 2079 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2080 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false); 2080 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2081 2081
2082 renderSurface1->setForceRenderSurface(true); 2082 renderSurface1->setForceRenderSurface(true);
2083 executeCalculateDrawTransformsAndVisibility(root.get()); 2083 executeCalculateDrawTransformsAndVisibility(root.get());
2084 2084
2085 ASSERT_TRUE(renderSurface1->renderSurface()); 2085 ASSERT_TRUE(renderSurface1->renderSurface());
2086 2086
2087 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableConte ntRect()); 2087 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect());
2088 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect()); 2088 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawableContentRect());
2089 2089
2090 // Layers that do not draw content should have empty visibleContentRects. 2090 // Layers that do not draw content should have empty visibleContentRects.
2091 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect()); 2091 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visibleContentRect());
2092 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect()); 2092 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), renderSurface1->visibleContentRect());
2093 2093
2094 // An unclipped surface grows its drawableContentRect to include all drawabl e regions of the subtree. 2094 // An unclipped surface grows its drawableContentRect to include all drawabl e regions of the subtree.
2095 EXPECT_RECT_EQ(IntRect(5, 5, 170, 170), renderSurface1->renderSurface()->dra wableContentRect()); 2095 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170), renderSurface1->renderSurface()->d rawableContentRect());
2096 2096
2097 // All layers that draw content into the unclipped surface are also unclippe d. 2097 // All layers that draw content into the unclipped surface are also unclippe d.
2098 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect()); 2098 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visibleContentRect());
2099 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child2->visibleContentRect()); 2099 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visibleContentRect());
2100 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child3->visibleContentRect()); 2100 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visibleContentRect());
2101 2101
2102 EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), child1->drawableContentRect()); 2102 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawableContentRect());
2103 EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect()); 2103 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawableContentRect());
2104 EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect()); 2104 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawableContentRect());
2105 } 2105 }
2106 2106
2107 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersInCli ppedRenderSurface) 2107 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersInCli ppedRenderSurface)
2108 { 2108 {
2109 scoped_refptr<Layer> root = Layer::create(); 2109 scoped_refptr<Layer> root = Layer::create();
2110 scoped_refptr<Layer> renderSurface1 = Layer::create(); 2110 scoped_refptr<Layer> renderSurface1 = Layer::create();
2111 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2111 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2112 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2112 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2113 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2113 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2114 root->addChild(renderSurface1); 2114 root->addChild(renderSurface1);
2115 renderSurface1->addChild(child1); 2115 renderSurface1->addChild(child1);
2116 renderSurface1->addChild(child2); 2116 renderSurface1->addChild(child2);
2117 renderSurface1->addChild(child3); 2117 renderSurface1->addChild(child3);
2118 2118
2119 WebTransformationMatrix identityMatrix; 2119 WebTransformationMatrix identityMatrix;
2120 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2120 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2121 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false); 2121 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false);
2122 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false); 2122 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2123 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false); 2123 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2124 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false); 2124 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2125 2125
2126 root->setMasksToBounds(true); 2126 root->setMasksToBounds(true);
2127 renderSurface1->setForceRenderSurface(true); 2127 renderSurface1->setForceRenderSurface(true);
2128 executeCalculateDrawTransformsAndVisibility(root.get()); 2128 executeCalculateDrawTransformsAndVisibility(root.get());
2129 2129
2130 ASSERT_TRUE(renderSurface1->renderSurface()); 2130 ASSERT_TRUE(renderSurface1->renderSurface());
2131 2131
2132 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableConte ntRect()); 2132 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect());
2133 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect()); 2133 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawableContentRect());
2134 2134
2135 // Layers that do not draw content should have empty visibleContentRects. 2135 // Layers that do not draw content should have empty visibleContentRects.
2136 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect()); 2136 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visibleContentRect());
2137 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect()); 2137 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), renderSurface1->visibleContentRect());
2138 2138
2139 // A clipped surface grows its drawableContentRect to include all drawable r egions of the subtree, 2139 // A clipped surface grows its drawableContentRect to include all drawable r egions of the subtree,
2140 // but also gets clamped by the ancestor's clip. 2140 // but also gets clamped by the ancestor's clip.
2141 EXPECT_RECT_EQ(IntRect(5, 5, 95, 95), renderSurface1->renderSurface()->drawa bleContentRect()); 2141 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95), renderSurface1->renderSurface()->dra wableContentRect());
2142 2142
2143 // All layers that draw content into the surface have their visibleContentRe ct clipped by the surface clipRect. 2143 // All layers that draw content into the surface have their visibleContentRe ct clipped by the surface clipRect.
2144 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect()); 2144 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visibleContentRect());
2145 EXPECT_RECT_EQ(IntRect(0, 0, 25, 25), child2->visibleContentRect()); 2145 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visibleContentRect());
2146 EXPECT_TRUE(child3->visibleContentRect().isEmpty()); 2146 EXPECT_TRUE(child3->visibleContentRect().IsEmpty());
2147 2147
2148 // But the drawableContentRects are unclipped. 2148 // But the drawableContentRects are unclipped.
2149 EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), child1->drawableContentRect()); 2149 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawableContentRect());
2150 EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect()); 2150 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawableContentRect());
2151 EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect()); 2151 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawableContentRect());
2152 } 2152 }
2153 2153
2154 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForSurfaceHier archy) 2154 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForSurfaceHier archy)
2155 { 2155 {
2156 // Check that clipping does not propagate down surfaces. 2156 // Check that clipping does not propagate down surfaces.
2157 scoped_refptr<Layer> root = Layer::create(); 2157 scoped_refptr<Layer> root = Layer::create();
2158 scoped_refptr<Layer> renderSurface1 = Layer::create(); 2158 scoped_refptr<Layer> renderSurface1 = Layer::create();
2159 scoped_refptr<Layer> renderSurface2 = Layer::create(); 2159 scoped_refptr<Layer> renderSurface2 = Layer::create();
2160 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2160 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2161 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2161 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2162 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2162 scoped_refptr<LayerWithForcedDrawsContent> child3 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2163 root->addChild(renderSurface1); 2163 root->addChild(renderSurface1);
2164 renderSurface1->addChild(renderSurface2); 2164 renderSurface1->addChild(renderSurface2);
2165 renderSurface2->addChild(child1); 2165 renderSurface2->addChild(child1);
2166 renderSurface2->addChild(child2); 2166 renderSurface2->addChild(child2);
2167 renderSurface2->addChild(child3); 2167 renderSurface2->addChild(child3);
2168 2168
2169 WebTransformationMatrix identityMatrix; 2169 WebTransformationMatrix identityMatrix;
2170 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2170 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2171 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false); 2171 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false);
2172 setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(7, 13), false); 2172 setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(7, 13), false);
2173 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false); 2173 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2174 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false); 2174 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2175 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false); 2175 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2176 2176
2177 root->setMasksToBounds(true); 2177 root->setMasksToBounds(true);
2178 renderSurface1->setForceRenderSurface(true); 2178 renderSurface1->setForceRenderSurface(true);
2179 renderSurface2->setForceRenderSurface(true); 2179 renderSurface2->setForceRenderSurface(true);
2180 executeCalculateDrawTransformsAndVisibility(root.get()); 2180 executeCalculateDrawTransformsAndVisibility(root.get());
2181 2181
2182 ASSERT_TRUE(renderSurface1->renderSurface()); 2182 ASSERT_TRUE(renderSurface1->renderSurface());
2183 ASSERT_TRUE(renderSurface2->renderSurface()); 2183 ASSERT_TRUE(renderSurface2->renderSurface());
2184 2184
2185 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableConte ntRect()); 2185 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect());
2186 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect()); 2186 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawableContentRect());
2187 2187
2188 // Layers that do not draw content should have empty visibleContentRects. 2188 // Layers that do not draw content should have empty visibleContentRects.
2189 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect()); 2189 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visibleContentRect());
2190 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect()); 2190 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), renderSurface1->visibleContentRect());
2191 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface2->visibleContentRect()); 2191 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), renderSurface2->visibleContentRect());
2192 2192
2193 // A clipped surface grows its drawableContentRect to include all drawable r egions of the subtree, 2193 // A clipped surface grows its drawableContentRect to include all drawable r egions of the subtree,
2194 // but also gets clamped by the ancestor's clip. 2194 // but also gets clamped by the ancestor's clip.
2195 EXPECT_RECT_EQ(IntRect(5, 5, 95, 95), renderSurface1->renderSurface()->drawa bleContentRect()); 2195 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95), renderSurface1->renderSurface()->dra wableContentRect());
2196 2196
2197 // renderSurface1 lives in the "unclipped universe" of renderSurface1, and i s only 2197 // renderSurface1 lives in the "unclipped universe" of renderSurface1, and i s only
2198 // implicitly clipped by renderSurface1's contentRect. So, renderSurface2 gr ows to 2198 // implicitly clipped by renderSurface1's contentRect. So, renderSurface2 gr ows to
2199 // enclose all drawable content of its subtree. 2199 // enclose all drawable content of its subtree.
2200 EXPECT_RECT_EQ(IntRect(5, 5, 170, 170), renderSurface2->renderSurface()->dra wableContentRect()); 2200 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170), renderSurface2->renderSurface()->d rawableContentRect());
2201 2201
2202 // All layers that draw content into renderSurface2 think they are unclipped . 2202 // All layers that draw content into renderSurface2 think they are unclipped .
2203 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect()); 2203 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visibleContentRect());
2204 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child2->visibleContentRect()); 2204 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visibleContentRect());
2205 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child3->visibleContentRect()); 2205 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visibleContentRect());
2206 2206
2207 // drawableContentRects are also unclipped. 2207 // drawableContentRects are also unclipped.
2208 EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), child1->drawableContentRect()); 2208 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawableContentRect());
2209 EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect()); 2209 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawableContentRect());
2210 EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect()); 2210 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawableContentRect());
2211 } 2211 }
2212 2212
2213 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsWithTransformO nUnclippedSurface) 2213 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsWithTransformO nUnclippedSurface)
2214 { 2214 {
2215 // Layers that have non-axis aligned bounds (due to transforms) have an expa nded, 2215 // Layers that have non-axis aligned bounds (due to transforms) have an expa nded,
2216 // axis-aligned drawableContentRect and visibleContentRect. 2216 // axis-aligned drawableContentRect and visibleContentRect.
2217 2217
2218 scoped_refptr<Layer> root = Layer::create(); 2218 scoped_refptr<Layer> root = Layer::create();
2219 scoped_refptr<Layer> renderSurface1 = Layer::create(); 2219 scoped_refptr<Layer> renderSurface1 = Layer::create();
2220 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2220 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2221 root->addChild(renderSurface1); 2221 root->addChild(renderSurface1);
2222 renderSurface1->addChild(child1); 2222 renderSurface1->addChild(child1);
2223 2223
2224 WebTransformationMatrix identityMatrix; 2224 WebTransformationMatrix identityMatrix;
2225 WebTransformationMatrix childRotation; 2225 WebTransformationMatrix childRotation;
2226 childRotation.rotate(45); 2226 childRotation.rotate(45);
2227 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2227 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2228 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false); 2228 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false);
2229 setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, Fl oatPoint(0.5, 0.5), FloatPoint(25, 25), IntSize(50, 50), false); 2229 setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, gf x::PointF(0.5, 0.5), gfx::PointF(25, 25), gfx::Size(50, 50), false);
2230 2230
2231 renderSurface1->setForceRenderSurface(true); 2231 renderSurface1->setForceRenderSurface(true);
2232 executeCalculateDrawTransformsAndVisibility(root.get()); 2232 executeCalculateDrawTransformsAndVisibility(root.get());
2233 2233
2234 ASSERT_TRUE(renderSurface1->renderSurface()); 2234 ASSERT_TRUE(renderSurface1->renderSurface());
2235 2235
2236 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableConte ntRect()); 2236 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->renderSurface()->drawableCon tentRect());
2237 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect()); 2237 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawableContentRect());
2238 2238
2239 // Layers that do not draw content should have empty visibleContentRects. 2239 // Layers that do not draw content should have empty visibleContentRects.
2240 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect()); 2240 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visibleContentRect());
2241 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect()); 2241 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), renderSurface1->visibleContentRect());
2242 2242
2243 // The unclipped surface grows its drawableContentRect to include all drawab le regions of the subtree. 2243 // The unclipped surface grows its drawableContentRect to include all drawab le regions of the subtree.
2244 int diagonalRadius = ceil(sqrt(2.0) * 25); 2244 int diagonalRadius = ceil(sqrt(2.0) * 25);
2245 IntRect expectedSurfaceDrawableContent = IntRect(50 - diagonalRadius, 50 - d iagonalRadius, diagonalRadius * 2, diagonalRadius * 2); 2245 gfx::Rect expectedSurfaceDrawableContent = gfx::Rect(50 - diagonalRadius, 50 - diagonalRadius, diagonalRadius * 2, diagonalRadius * 2);
2246 EXPECT_RECT_EQ(expectedSurfaceDrawableContent, renderSurface1->renderSurface ()->drawableContentRect()); 2246 EXPECT_RECT_EQ(expectedSurfaceDrawableContent, renderSurface1->renderSurface ()->drawableContentRect());
2247 2247
2248 // All layers that draw content into the unclipped surface are also unclippe d. 2248 // All layers that draw content into the unclipped surface are also unclippe d.
2249 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect()); 2249 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visibleContentRect());
2250 EXPECT_RECT_EQ(expectedSurfaceDrawableContent, child1->drawableContentRect() ); 2250 EXPECT_RECT_EQ(expectedSurfaceDrawableContent, child1->drawableContentRect() );
2251 } 2251 }
2252 2252
2253 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsWithTransformO nClippedSurface) 2253 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsWithTransformO nClippedSurface)
2254 { 2254 {
2255 // Layers that have non-axis aligned bounds (due to transforms) have an expa nded, 2255 // Layers that have non-axis aligned bounds (due to transforms) have an expa nded,
2256 // axis-aligned drawableContentRect and visibleContentRect. 2256 // axis-aligned drawableContentRect and visibleContentRect.
2257 2257
2258 scoped_refptr<Layer> root = Layer::create(); 2258 scoped_refptr<Layer> root = Layer::create();
2259 scoped_refptr<Layer> renderSurface1 = Layer::create(); 2259 scoped_refptr<Layer> renderSurface1 = Layer::create();
2260 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2260 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2261 root->addChild(renderSurface1); 2261 root->addChild(renderSurface1);
2262 renderSurface1->addChild(child1); 2262 renderSurface1->addChild(child1);
2263 2263
2264 WebTransformationMatrix identityMatrix; 2264 WebTransformationMatrix identityMatrix;
2265 WebTransformationMatrix childRotation; 2265 WebTransformationMatrix childRotation;
2266 childRotation.rotate(45); 2266 childRotation.rotate(45);
2267 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(50, 50), false); 2267 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(50, 50), false);
2268 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false); 2268 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(3, 4), false);
2269 setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, Fl oatPoint(0.5, 0.5), FloatPoint(25, 25), IntSize(50, 50), false); 2269 setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, gf x::PointF(0.5, 0.5), gfx::PointF(25, 25), gfx::Size(50, 50), false);
2270 2270
2271 root->setMasksToBounds(true); 2271 root->setMasksToBounds(true);
2272 renderSurface1->setForceRenderSurface(true); 2272 renderSurface1->setForceRenderSurface(true);
2273 executeCalculateDrawTransformsAndVisibility(root.get()); 2273 executeCalculateDrawTransformsAndVisibility(root.get());
2274 2274
2275 ASSERT_TRUE(renderSurface1->renderSurface()); 2275 ASSERT_TRUE(renderSurface1->renderSurface());
2276 2276
2277 // The clipped surface clamps the drawableContentRect that encloses the rota ted layer. 2277 // The clipped surface clamps the drawableContentRect that encloses the rota ted layer.
2278 int diagonalRadius = ceil(sqrt(2.0) * 25); 2278 int diagonalRadius = ceil(sqrt(2.0) * 25);
2279 IntRect unclippedSurfaceContent = IntRect(50 - diagonalRadius, 50 - diagonal Radius, diagonalRadius * 2, diagonalRadius * 2); 2279 gfx::Rect unclippedSurfaceContent = gfx::Rect(50 - diagonalRadius, 50 - diag onalRadius, diagonalRadius * 2, diagonalRadius * 2);
2280 IntRect expectedSurfaceDrawableContent = intersection(unclippedSurfaceConten t, IntRect(0, 0, 50, 50)); 2280 gfx::Rect expectedSurfaceDrawableContent = gfx::IntersectRects(unclippedSurf aceContent, gfx::Rect(0, 0, 50, 50));
2281 EXPECT_RECT_EQ(expectedSurfaceDrawableContent, renderSurface1->renderSurface ()->drawableContentRect()); 2281 EXPECT_RECT_EQ(expectedSurfaceDrawableContent, renderSurface1->renderSurface ()->drawableContentRect());
2282 2282
2283 // On the clipped surface, only a quarter of the child1 is visible, but whe n rotating 2283 // On the clipped surface, only a quarter of the child1 is visible, but whe n rotating
2284 // it back to child1's content space, the actual enclosing rect ends up cov ering the 2284 // it back to child1's content space, the actual enclosing rect ends up cov ering the
2285 // full left half of child1. 2285 // full left half of child1.
2286 EXPECT_RECT_EQ(IntRect(0, 0, 26, 50), child1->visibleContentRect()); 2286 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visibleContentRect());
2287 2287
2288 // The child's drawableContentRect is unclipped. 2288 // The child's drawableContentRect is unclipped.
2289 EXPECT_RECT_EQ(unclippedSurfaceContent, child1->drawableContentRect()); 2289 EXPECT_RECT_EQ(unclippedSurfaceContent, child1->drawableContentRect());
2290 } 2290 }
2291 2291
2292 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsInHighDPI) 2292 TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsInHighDPI)
2293 { 2293 {
2294 MockContentLayerClient client; 2294 MockContentLayerClient client;
2295 2295
2296 scoped_refptr<Layer> root = Layer::create(); 2296 scoped_refptr<Layer> root = Layer::create();
2297 scoped_refptr<ContentLayer> renderSurface1 = createDrawableContentLayer(&cli ent); 2297 scoped_refptr<ContentLayer> renderSurface1 = createDrawableContentLayer(&cli ent);
2298 scoped_refptr<ContentLayer> renderSurface2 = createDrawableContentLayer(&cli ent); 2298 scoped_refptr<ContentLayer> renderSurface2 = createDrawableContentLayer(&cli ent);
2299 scoped_refptr<ContentLayer> child1 = createDrawableContentLayer(&client); 2299 scoped_refptr<ContentLayer> child1 = createDrawableContentLayer(&client);
2300 scoped_refptr<ContentLayer> child2 = createDrawableContentLayer(&client); 2300 scoped_refptr<ContentLayer> child2 = createDrawableContentLayer(&client);
2301 scoped_refptr<ContentLayer> child3 = createDrawableContentLayer(&client); 2301 scoped_refptr<ContentLayer> child3 = createDrawableContentLayer(&client);
2302 root->addChild(renderSurface1); 2302 root->addChild(renderSurface1);
2303 renderSurface1->addChild(renderSurface2); 2303 renderSurface1->addChild(renderSurface2);
2304 renderSurface2->addChild(child1); 2304 renderSurface2->addChild(child1);
2305 renderSurface2->addChild(child2); 2305 renderSurface2->addChild(child2);
2306 renderSurface2->addChild(child3); 2306 renderSurface2->addChild(child3);
2307 2307
2308 WebTransformationMatrix identityMatrix; 2308 WebTransformationMatrix identityMatrix;
2309 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2309 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2310 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(3, 4), false); 2310 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(3, 4), false);
2311 setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(7, 13), false); 2311 setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(7, 13), false);
2312 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false); 2312 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2313 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false); 2313 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2314 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false); 2314 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2315 2315
2316 const double deviceScaleFactor = 2; 2316 const double deviceScaleFactor = 2;
2317 root->setContentsScale(deviceScaleFactor); 2317 root->setContentsScale(deviceScaleFactor);
2318 renderSurface1->setContentsScale(deviceScaleFactor); 2318 renderSurface1->setContentsScale(deviceScaleFactor);
2319 renderSurface2->setContentsScale(deviceScaleFactor); 2319 renderSurface2->setContentsScale(deviceScaleFactor);
2320 child1->setContentsScale(deviceScaleFactor); 2320 child1->setContentsScale(deviceScaleFactor);
2321 child2->setContentsScale(deviceScaleFactor); 2321 child2->setContentsScale(deviceScaleFactor);
2322 child3->setContentsScale(deviceScaleFactor); 2322 child3->setContentsScale(deviceScaleFactor);
2323 2323
2324 root->setMasksToBounds(true); 2324 root->setMasksToBounds(true);
2325 renderSurface1->setForceRenderSurface(true); 2325 renderSurface1->setForceRenderSurface(true);
2326 renderSurface2->setForceRenderSurface(true); 2326 renderSurface2->setForceRenderSurface(true);
2327 executeCalculateDrawTransformsAndVisibility(root.get(), deviceScaleFactor); 2327 executeCalculateDrawTransformsAndVisibility(root.get(), deviceScaleFactor);
2328 2328
2329 ASSERT_TRUE(renderSurface1->renderSurface()); 2329 ASSERT_TRUE(renderSurface1->renderSurface());
2330 ASSERT_TRUE(renderSurface2->renderSurface()); 2330 ASSERT_TRUE(renderSurface2->renderSurface());
2331 2331
2332 // DrawableContentRects for all layers and surfaces are scaled by deviceScal eFactor. 2332 // DrawableContentRects for all layers and surfaces are scaled by deviceScal eFactor.
2333 EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), root->renderSurface()->drawableConte ntRect()); 2333 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->renderSurface()->drawableCon tentRect());
2334 EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), root->drawableContentRect()); 2334 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawableContentRect());
2335 EXPECT_RECT_EQ(IntRect(10, 10, 190, 190), renderSurface1->renderSurface()->d rawableContentRect()); 2335 EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190), renderSurface1->renderSurface()- >drawableContentRect());
2336 2336
2337 // renderSurface2 lives in the "unclipped universe" of renderSurface1, and 2337 // renderSurface2 lives in the "unclipped universe" of renderSurface1, and
2338 // is only implicitly clipped by renderSurface1. 2338 // is only implicitly clipped by renderSurface1.
2339 EXPECT_RECT_EQ(IntRect(10, 10, 350, 350), renderSurface2->renderSurface()->d rawableContentRect()); 2339 EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350), renderSurface2->renderSurface()- >drawableContentRect());
2340 2340
2341 EXPECT_RECT_EQ(IntRect(10, 10, 100, 100), child1->drawableContentRect()); 2341 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawableContentRect());
2342 EXPECT_RECT_EQ(IntRect(150, 150, 100, 100), child2->drawableContentRect()); 2342 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawableContentRect()) ;
2343 EXPECT_RECT_EQ(IntRect(250, 250, 100, 100), child3->drawableContentRect()); 2343 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawableContentRect()) ;
2344 2344
2345 // The root layer does not actually draw content of its own. 2345 // The root layer does not actually draw content of its own.
2346 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect()); 2346 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visibleContentRect());
2347 2347
2348 // All layer visibleContentRects are expressed in content space of each 2348 // All layer visibleContentRects are expressed in content space of each
2349 // layer, so they are also scaled by the deviceScaleFactor. 2349 // layer, so they are also scaled by the deviceScaleFactor.
2350 EXPECT_RECT_EQ(IntRect(0, 0, 6, 8), renderSurface1->visibleContentRect()); 2350 EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8), renderSurface1->visibleContentRect());
2351 EXPECT_RECT_EQ(IntRect(0, 0, 14, 26), renderSurface2->visibleContentRect()); 2351 EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26), renderSurface2->visibleContentRect() );
2352 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), child1->visibleContentRect()); 2352 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visibleContentRect());
2353 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), child2->visibleContentRect()); 2353 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visibleContentRect());
2354 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), child3->visibleContentRect()); 2354 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visibleContentRect());
2355 } 2355 }
2356 2356
2357 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithoutPreserves3d) 2357 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithoutPreserves3d)
2358 { 2358 {
2359 // Verify the behavior of back-face culling when there are no preserve-3d la yers. Note 2359 // Verify the behavior of back-face culling when there are no preserve-3d la yers. Note
2360 // that 3d transforms still apply in this case, but they are "flattened" to each 2360 // that 3d transforms still apply in this case, but they are "flattened" to each
2361 // parent layer according to current W3C spec. 2361 // parent layer according to current W3C spec.
2362 2362
2363 const WebTransformationMatrix identityMatrix; 2363 const WebTransformationMatrix identityMatrix;
2364 scoped_refptr<Layer> parent = Layer::create(); 2364 scoped_refptr<Layer> parent = Layer::create();
(...skipping 29 matching lines...) Expand all
2394 backfaceMatrix.translate(50, 50); 2394 backfaceMatrix.translate(50, 50);
2395 backfaceMatrix.rotate3d(0, 1, 0, 180); 2395 backfaceMatrix.rotate3d(0, 1, 0, 180);
2396 backfaceMatrix.translate(-50, -50); 2396 backfaceMatrix.translate(-50, -50);
2397 2397
2398 // Having a descendant and opacity will force these to have render surfaces. 2398 // Having a descendant and opacity will force these to have render surfaces.
2399 frontFacingSurface->setOpacity(0.5); 2399 frontFacingSurface->setOpacity(0.5);
2400 backFacingSurface->setOpacity(0.5); 2400 backFacingSurface->setOpacity(0.5);
2401 2401
2402 // Nothing preserves 3d. According to current W3C CSS Transforms spec, these layers 2402 // Nothing preserves 3d. According to current W3C CSS Transforms spec, these layers
2403 // should blindly use their own local transforms to determine back-face cull ing. 2403 // should blindly use their own local transforms to determine back-face cull ing.
2404 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2404 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2405 setLayerPropertiesForTesting(frontFacingChild.get(), identityMatrix, identit yMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2405 setLayerPropertiesForTesting(frontFacingChild.get(), identityMatrix, identit yMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2406 setLayerPropertiesForTesting(backFacingChild.get(), backfaceMatrix, identity Matrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2406 setLayerPropertiesForTesting(backFacingChild.get(), backfaceMatrix, identity Matrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2407 setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, ident ityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2407 setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, ident ityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2408 setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, identi tyMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2408 setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, identi tyMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2409 setLayerPropertiesForTesting(frontFacingChildOfFrontFacingSurface.get(), ide ntityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 10 0), false); 2409 setLayerPropertiesForTesting(frontFacingChildOfFrontFacingSurface.get(), ide ntityMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100 , 100), false);
2410 setLayerPropertiesForTesting(backFacingChildOfFrontFacingSurface.get(), back faceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100 ), false); 2410 setLayerPropertiesForTesting(backFacingChildOfFrontFacingSurface.get(), back faceMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2411 setLayerPropertiesForTesting(frontFacingChildOfBackFacingSurface.get(), iden tityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100 ), false); 2411 setLayerPropertiesForTesting(frontFacingChildOfBackFacingSurface.get(), iden tityMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2412 setLayerPropertiesForTesting(backFacingChildOfBackFacingSurface.get(), backf aceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100) , false); 2412 setLayerPropertiesForTesting(backFacingChildOfBackFacingSurface.get(), backf aceMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2413 2413
2414 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 2414 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
2415 int dummyMaxTextureSize = 512; 2415 int dummyMaxTextureSize = 512;
2416 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 2416 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
2417 2417
2418 // Verify which renderSurfaces were created. 2418 // Verify which renderSurfaces were created.
2419 EXPECT_FALSE(frontFacingChild->renderSurface()); 2419 EXPECT_FALSE(frontFacingChild->renderSurface());
2420 EXPECT_FALSE(backFacingChild->renderSurface()); 2420 EXPECT_FALSE(backFacingChild->renderSurface());
2421 EXPECT_TRUE(frontFacingSurface->renderSurface()); 2421 EXPECT_TRUE(frontFacingSurface->renderSurface());
2422 EXPECT_TRUE(backFacingSurface->renderSurface()); 2422 EXPECT_TRUE(backFacingSurface->renderSurface());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2493 // preserve-3d transform style. Instead, an example of when a surface would be 2493 // preserve-3d transform style. Instead, an example of when a surface would be
2494 // created with preserve-3d is when there is a replica layer. 2494 // created with preserve-3d is when there is a replica layer.
2495 frontFacingSurface->setReplicaLayer(dummyReplicaLayer1.get()); 2495 frontFacingSurface->setReplicaLayer(dummyReplicaLayer1.get());
2496 backFacingSurface->setReplicaLayer(dummyReplicaLayer2.get()); 2496 backFacingSurface->setReplicaLayer(dummyReplicaLayer2.get());
2497 2497
2498 // Each surface creates its own new 3d rendering context (as defined by W3C spec). 2498 // Each surface creates its own new 3d rendering context (as defined by W3C spec).
2499 // According to current W3C CSS Transforms spec, layers in a 3d rendering co ntext 2499 // According to current W3C CSS Transforms spec, layers in a 3d rendering co ntext
2500 // should use the transform with respect to that context. This 3d rendering context 2500 // should use the transform with respect to that context. This 3d rendering context
2501 // occurs when (a) parent's transform style is flat and (b) the layer's tran sform 2501 // occurs when (a) parent's transform style is flat and (b) the layer's tran sform
2502 // style is preserve-3d. 2502 // style is preserve-3d.
2503 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); // parent transfor m style is flat. 2503 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.
2504 setLayerPropertiesForTesting(frontFacingChild.get(), identityMatrix, identit yMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2504 setLayerPropertiesForTesting(frontFacingChild.get(), identityMatrix, identit yMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2505 setLayerPropertiesForTesting(backFacingChild.get(), backfaceMatrix, identity Matrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2505 setLayerPropertiesForTesting(backFacingChild.get(), backfaceMatrix, identity Matrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2506 setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, ident ityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); // surf ace transform style is preserve-3d. 2506 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.
2507 setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, identi tyMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); // surfa ce transform style is preserve-3d. 2507 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.
2508 setLayerPropertiesForTesting(frontFacingChildOfFrontFacingSurface.get(), ide ntityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 10 0), false); 2508 setLayerPropertiesForTesting(frontFacingChildOfFrontFacingSurface.get(), ide ntityMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100 , 100), false);
2509 setLayerPropertiesForTesting(backFacingChildOfFrontFacingSurface.get(), back faceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100 ), false); 2509 setLayerPropertiesForTesting(backFacingChildOfFrontFacingSurface.get(), back faceMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2510 setLayerPropertiesForTesting(frontFacingChildOfBackFacingSurface.get(), iden tityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100 ), false); 2510 setLayerPropertiesForTesting(frontFacingChildOfBackFacingSurface.get(), iden tityMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2511 setLayerPropertiesForTesting(backFacingChildOfBackFacingSurface.get(), backf aceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100) , false); 2511 setLayerPropertiesForTesting(backFacingChildOfBackFacingSurface.get(), backf aceMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2512 2512
2513 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 2513 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
2514 int dummyMaxTextureSize = 512; 2514 int dummyMaxTextureSize = 512;
2515 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 2515 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
2516 2516
2517 // Verify which renderSurfaces were created. 2517 // Verify which renderSurfaces were created.
2518 EXPECT_FALSE(frontFacingChild->renderSurface()); 2518 EXPECT_FALSE(frontFacingChild->renderSurface());
2519 EXPECT_FALSE(backFacingChild->renderSurface()); 2519 EXPECT_FALSE(backFacingChild->renderSurface());
2520 EXPECT_TRUE(frontFacingSurface->renderSurface()); 2520 EXPECT_TRUE(frontFacingSurface->renderSurface());
2521 EXPECT_FALSE(backFacingSurface->renderSurface()); 2521 EXPECT_FALSE(backFacingSurface->renderSurface());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2576 backfaceMatrix.translate(-50, -50); 2576 backfaceMatrix.translate(-50, -50);
2577 2577
2578 // Make our render surface. 2578 // Make our render surface.
2579 animatingSurface->setForceRenderSurface(true); 2579 animatingSurface->setForceRenderSurface(true);
2580 2580
2581 // Animate the transform on the render surface. 2581 // Animate the transform on the render surface.
2582 addAnimatedTransformToController(*animatingSurface->layerAnimationController (), 10, 30, 0); 2582 addAnimatedTransformToController(*animatingSurface->layerAnimationController (), 10, 30, 0);
2583 // This is just an animating layer, not a surface. 2583 // This is just an animating layer, not a surface.
2584 addAnimatedTransformToController(*animatingChild->layerAnimationController() , 10, 30, 0); 2584 addAnimatedTransformToController(*animatingChild->layerAnimationController() , 10, 30, 0);
2585 2585
2586 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2586 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2587 setLayerPropertiesForTesting(child.get(), backfaceMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2587 setLayerPropertiesForTesting(child.get(), backfaceMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2588 setLayerPropertiesForTesting(animatingSurface.get(), backfaceMatrix, identit yMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2588 setLayerPropertiesForTesting(animatingSurface.get(), backfaceMatrix, identit yMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2589 setLayerPropertiesForTesting(childOfAnimatingSurface.get(), backfaceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2589 setLayerPropertiesForTesting(childOfAnimatingSurface.get(), backfaceMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false );
2590 setLayerPropertiesForTesting(animatingChild.get(), backfaceMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2590 setLayerPropertiesForTesting(animatingChild.get(), backfaceMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2591 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2591 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2592 2592
2593 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 2593 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
2594 int dummyMaxTextureSize = 512; 2594 int dummyMaxTextureSize = 512;
2595 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 2595 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
2596 2596
2597 EXPECT_FALSE(child->renderSurface()); 2597 EXPECT_FALSE(child->renderSurface());
2598 EXPECT_TRUE(animatingSurface->renderSurface()); 2598 EXPECT_TRUE(animatingSurface->renderSurface());
2599 EXPECT_FALSE(childOfAnimatingSurface->renderSurface()); 2599 EXPECT_FALSE(childOfAnimatingSurface->renderSurface());
2600 EXPECT_FALSE(animatingChild->renderSurface()); 2600 EXPECT_FALSE(animatingChild->renderSurface());
2601 EXPECT_FALSE(child2->renderSurface()); 2601 EXPECT_FALSE(child2->renderSurface());
2602 2602
2603 // Verify that the animatingChild and childOfAnimatingSurface were not culle d, but that child was. 2603 // Verify that the animatingChild and childOfAnimatingSurface were not culle d, but that child was.
2604 ASSERT_EQ(2u, renderSurfaceLayerList.size()); 2604 ASSERT_EQ(2u, renderSurfaceLayerList.size());
2605 EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id()); 2605 EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
2606 EXPECT_EQ(animatingSurface->id(), renderSurfaceLayerList[1]->id()); 2606 EXPECT_EQ(animatingSurface->id(), renderSurfaceLayerList[1]->id());
2607 2607
2608 // The non-animating child be culled from the layer list for the parent rend er surface. 2608 // The non-animating child be culled from the layer list for the parent rend er surface.
2609 ASSERT_EQ(3u, renderSurfaceLayerList[0]->renderSurface()->layerList().size() ); 2609 ASSERT_EQ(3u, renderSurfaceLayerList[0]->renderSurface()->layerList().size() );
2610 EXPECT_EQ(animatingSurface->id(), renderSurfaceLayerList[0]->renderSurface() ->layerList()[0]->id()); 2610 EXPECT_EQ(animatingSurface->id(), renderSurfaceLayerList[0]->renderSurface() ->layerList()[0]->id());
2611 EXPECT_EQ(animatingChild->id(), renderSurfaceLayerList[0]->renderSurface()-> layerList()[1]->id()); 2611 EXPECT_EQ(animatingChild->id(), renderSurfaceLayerList[0]->renderSurface()-> layerList()[1]->id());
2612 EXPECT_EQ(child2->id(), renderSurfaceLayerList[0]->renderSurface()->layerLis t()[2]->id()); 2612 EXPECT_EQ(child2->id(), renderSurfaceLayerList[0]->renderSurface()->layerLis t()[2]->id());
2613 2613
2614 ASSERT_EQ(2u, renderSurfaceLayerList[1]->renderSurface()->layerList().size() ); 2614 ASSERT_EQ(2u, renderSurfaceLayerList[1]->renderSurface()->layerList().size() );
2615 EXPECT_EQ(animatingSurface->id(), renderSurfaceLayerList[1]->renderSurface() ->layerList()[0]->id()); 2615 EXPECT_EQ(animatingSurface->id(), renderSurfaceLayerList[1]->renderSurface() ->layerList()[0]->id());
2616 EXPECT_EQ(childOfAnimatingSurface->id(), renderSurfaceLayerList[1]->renderSu rface()->layerList()[1]->id()); 2616 EXPECT_EQ(childOfAnimatingSurface->id(), renderSurfaceLayerList[1]->renderSu rface()->layerList()[1]->id());
2617 2617
2618 EXPECT_FALSE(child2->visibleContentRect().isEmpty()); 2618 EXPECT_FALSE(child2->visibleContentRect().IsEmpty());
2619 2619
2620 // The animating layers should have a visibleContentRect that represents the area of the front face that is within the viewport. 2620 // The animating layers should have a visibleContentRect that represents the area of the front face that is within the viewport.
2621 EXPECT_EQ(animatingChild->visibleContentRect(), IntRect(IntPoint(), animatin gChild->contentBounds())); 2621 EXPECT_EQ(animatingChild->visibleContentRect(), gfx::Rect(gfx::Point(), anim atingChild->contentBounds()));
2622 EXPECT_EQ(animatingSurface->visibleContentRect(), IntRect(IntPoint(), animat ingSurface->contentBounds())); 2622 EXPECT_EQ(animatingSurface->visibleContentRect(), gfx::Rect(gfx::Point(), an imatingSurface->contentBounds()));
2623 // And layers in the subtree of the animating layer should have valid visibl eContentRects also. 2623 // And layers in the subtree of the animating layer should have valid visibl eContentRects also.
2624 EXPECT_EQ(childOfAnimatingSurface->visibleContentRect(), IntRect(IntPoint(), childOfAnimatingSurface->contentBounds())); 2624 EXPECT_EQ(childOfAnimatingSurface->visibleContentRect(), gfx::Rect(gfx::Poin t(), childOfAnimatingSurface->contentBounds()));
2625 } 2625 }
2626 2626
2627 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3dForFlatteningS urface) 2627 TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3dForFlatteningS urface)
2628 { 2628 {
2629 // Verify the behavior of back-face culling for a renderSurface that is crea ted 2629 // Verify the behavior of back-face culling for a renderSurface that is crea ted
2630 // when it flattens its subtree, and its parent has preserves-3d. 2630 // when it flattens its subtree, and its parent has preserves-3d.
2631 2631
2632 const WebTransformationMatrix identityMatrix; 2632 const WebTransformationMatrix identityMatrix;
2633 scoped_refptr<Layer> parent = Layer::create(); 2633 scoped_refptr<Layer> parent = Layer::create();
2634 scoped_refptr<LayerWithForcedDrawsContent> frontFacingSurface = make_scoped_ refptr(new LayerWithForcedDrawsContent()); 2634 scoped_refptr<LayerWithForcedDrawsContent> frontFacingSurface = make_scoped_ refptr(new LayerWithForcedDrawsContent());
2635 scoped_refptr<LayerWithForcedDrawsContent> backFacingSurface = make_scoped_r efptr(new LayerWithForcedDrawsContent()); 2635 scoped_refptr<LayerWithForcedDrawsContent> backFacingSurface = make_scoped_r efptr(new LayerWithForcedDrawsContent());
2636 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2636 scoped_refptr<LayerWithForcedDrawsContent> child1 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2637 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent()); 2637 scoped_refptr<LayerWithForcedDrawsContent> child2 = make_scoped_refptr(new L ayerWithForcedDrawsContent());
2638 2638
2639 parent->addChild(frontFacingSurface); 2639 parent->addChild(frontFacingSurface);
2640 parent->addChild(backFacingSurface); 2640 parent->addChild(backFacingSurface);
2641 frontFacingSurface->addChild(child1); 2641 frontFacingSurface->addChild(child1);
2642 backFacingSurface->addChild(child2); 2642 backFacingSurface->addChild(child2);
2643 2643
2644 // RenderSurfaces are not double-sided 2644 // RenderSurfaces are not double-sided
2645 frontFacingSurface->setDoubleSided(false); 2645 frontFacingSurface->setDoubleSided(false);
2646 backFacingSurface->setDoubleSided(false); 2646 backFacingSurface->setDoubleSided(false);
2647 2647
2648 WebTransformationMatrix backfaceMatrix; 2648 WebTransformationMatrix backfaceMatrix;
2649 backfaceMatrix.translate(50, 50); 2649 backfaceMatrix.translate(50, 50);
2650 backfaceMatrix.rotate3d(0, 1, 0, 180); 2650 backfaceMatrix.rotate3d(0, 1, 0, 180);
2651 backfaceMatrix.translate(-50, -50); 2651 backfaceMatrix.translate(-50, -50);
2652 2652
2653 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); // parent transform style is preserve3d. 2653 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.
2654 setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, ident ityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); // sur face transform style is flat. 2654 setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, ident ityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); // surface transform style is flat.
2655 setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, ident ityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); // sur face transform style is flat. 2655 setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, ident ityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); // surface transform style is flat.
2656 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2656 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2657 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 2657 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2658 2658
2659 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 2659 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
2660 int dummyMaxTextureSize = 512; 2660 int dummyMaxTextureSize = 512;
2661 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList); 2661 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
2662 2662
2663 // Verify which renderSurfaces were created. 2663 // Verify which renderSurfaces were created.
2664 EXPECT_TRUE(frontFacingSurface->renderSurface()); 2664 EXPECT_TRUE(frontFacingSurface->renderSurface());
2665 EXPECT_FALSE(backFacingSurface->renderSurface()); // because it should be cu lled 2665 EXPECT_FALSE(backFacingSurface->renderSurface()); // because it should be cu lled
2666 EXPECT_FALSE(child1->renderSurface()); 2666 EXPECT_FALSE(child1->renderSurface());
2667 EXPECT_FALSE(child2->renderSurface()); 2667 EXPECT_FALSE(child2->renderSurface());
(...skipping 13 matching lines...) Expand all
2681 EXPECT_EQ(child1->id(), renderSurfaceLayerList[1]->renderSurface()->layerLis t()[1]->id()); 2681 EXPECT_EQ(child1->id(), renderSurfaceLayerList[1]->renderSurface()->layerLis t()[1]->id());
2682 } 2682 }
2683 2683
2684 TEST(LayerTreeHostCommonTest, verifyHitTestingForEmptyLayerList) 2684 TEST(LayerTreeHostCommonTest, verifyHitTestingForEmptyLayerList)
2685 { 2685 {
2686 // Hit testing on an empty renderSurfaceLayerList should return a null point er. 2686 // Hit testing on an empty renderSurfaceLayerList should return a null point er.
2687 DebugScopedSetImplThread thisScopeIsOnImplThread; 2687 DebugScopedSetImplThread thisScopeIsOnImplThread;
2688 2688
2689 std::vector<LayerImpl*> renderSurfaceLayerList; 2689 std::vector<LayerImpl*> renderSurfaceLayerList;
2690 2690
2691 IntPoint testPoint(0, 0); 2691 gfx::Point testPoint(0, 0);
2692 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 2692 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
2693 EXPECT_FALSE(resultLayer); 2693 EXPECT_FALSE(resultLayer);
2694 2694
2695 testPoint = IntPoint(10, 20); 2695 testPoint = gfx::Point(10, 20);
2696 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2696 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2697 EXPECT_FALSE(resultLayer); 2697 EXPECT_FALSE(resultLayer);
2698 } 2698 }
2699 2699
2700 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayer) 2700 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayer)
2701 { 2701 {
2702 DebugScopedSetImplThread thisScopeIsOnImplThread; 2702 DebugScopedSetImplThread thisScopeIsOnImplThread;
2703 2703
2704 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 2704 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
2705 2705
2706 WebTransformationMatrix identityMatrix; 2706 WebTransformationMatrix identityMatrix;
2707 FloatPoint anchor(0, 0); 2707 gfx::PointF anchor(0, 0);
2708 FloatPoint position(0, 0); 2708 gfx::PointF position(0, 0);
2709 IntSize bounds(100, 100); 2709 gfx::Size bounds(100, 100);
2710 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 2710 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
2711 root->setDrawsContent(true); 2711 root->setDrawsContent(true);
2712 2712
2713 std::vector<LayerImpl*> renderSurfaceLayerList; 2713 std::vector<LayerImpl*> renderSurfaceLayerList;
2714 int dummyMaxTextureSize = 512; 2714 int dummyMaxTextureSize = 512;
2715 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2715 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2716 2716
2717 // Sanity check the scenario we just created. 2717 // Sanity check the scenario we just created.
2718 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 2718 ASSERT_EQ(1u, renderSurfaceLayerList.size());
2719 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 2719 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
2720 2720
2721 // Hit testing for a point outside the layer should return a null pointer. 2721 // Hit testing for a point outside the layer should return a null pointer.
2722 IntPoint testPoint(101, 101); 2722 gfx::Point testPoint(101, 101);
2723 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 2723 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
2724 EXPECT_FALSE(resultLayer); 2724 EXPECT_FALSE(resultLayer);
2725 2725
2726 testPoint = IntPoint(-1, -1); 2726 testPoint = gfx::Point(-1, -1);
2727 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2727 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2728 EXPECT_FALSE(resultLayer); 2728 EXPECT_FALSE(resultLayer);
2729 2729
2730 // Hit testing for a point inside should return the root layer. 2730 // Hit testing for a point inside should return the root layer.
2731 testPoint = IntPoint(1, 1); 2731 testPoint = gfx::Point(1, 1);
2732 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2732 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2733 ASSERT_TRUE(resultLayer); 2733 ASSERT_TRUE(resultLayer);
2734 EXPECT_EQ(12345, resultLayer->id()); 2734 EXPECT_EQ(12345, resultLayer->id());
2735 2735
2736 testPoint = IntPoint(99, 99); 2736 testPoint = gfx::Point(99, 99);
2737 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2737 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2738 ASSERT_TRUE(resultLayer); 2738 ASSERT_TRUE(resultLayer);
2739 EXPECT_EQ(12345, resultLayer->id()); 2739 EXPECT_EQ(12345, resultLayer->id());
2740 } 2740 }
2741 2741
2742 TEST(LayerTreeHostCommonTest, verifyHitTestingForUninvertibleTransform) 2742 TEST(LayerTreeHostCommonTest, verifyHitTestingForUninvertibleTransform)
2743 { 2743 {
2744 DebugScopedSetImplThread thisScopeIsOnImplThread; 2744 DebugScopedSetImplThread thisScopeIsOnImplThread;
2745 2745
2746 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 2746 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
2747 2747
2748 WebTransformationMatrix uninvertibleTransform; 2748 WebTransformationMatrix uninvertibleTransform;
2749 uninvertibleTransform.setM11(0); 2749 uninvertibleTransform.setM11(0);
2750 uninvertibleTransform.setM22(0); 2750 uninvertibleTransform.setM22(0);
2751 uninvertibleTransform.setM33(0); 2751 uninvertibleTransform.setM33(0);
2752 uninvertibleTransform.setM44(0); 2752 uninvertibleTransform.setM44(0);
2753 ASSERT_FALSE(uninvertibleTransform.isInvertible()); 2753 ASSERT_FALSE(uninvertibleTransform.isInvertible());
2754 2754
2755 WebTransformationMatrix identityMatrix; 2755 WebTransformationMatrix identityMatrix;
2756 FloatPoint anchor(0, 0); 2756 gfx::PointF anchor(0, 0);
2757 FloatPoint position(0, 0); 2757 gfx::PointF position(0, 0);
2758 IntSize bounds(100, 100); 2758 gfx::Size bounds(100, 100);
2759 setLayerPropertiesForTesting(root.get(), uninvertibleTransform, identityMatr ix, anchor, position, bounds, false); 2759 setLayerPropertiesForTesting(root.get(), uninvertibleTransform, identityMatr ix, anchor, position, bounds, false);
2760 root->setDrawsContent(true); 2760 root->setDrawsContent(true);
2761 2761
2762 std::vector<LayerImpl*> renderSurfaceLayerList; 2762 std::vector<LayerImpl*> renderSurfaceLayerList;
2763 int dummyMaxTextureSize = 512; 2763 int dummyMaxTextureSize = 512;
2764 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2764 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2765 2765
2766 // Sanity check the scenario we just created. 2766 // Sanity check the scenario we just created.
2767 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 2767 ASSERT_EQ(1u, renderSurfaceLayerList.size());
2768 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 2768 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
2769 ASSERT_FALSE(root->screenSpaceTransform().isInvertible()); 2769 ASSERT_FALSE(root->screenSpaceTransform().isInvertible());
2770 2770
2771 // Hit testing any point should not hit the layer. If the invertible matrix is 2771 // Hit testing any point should not hit the layer. If the invertible matrix is
2772 // accidentally ignored and treated like an identity, then the hit testing w ill 2772 // accidentally ignored and treated like an identity, then the hit testing w ill
2773 // incorrectly hit the layer when it shouldn't. 2773 // incorrectly hit the layer when it shouldn't.
2774 IntPoint testPoint(1, 1); 2774 gfx::Point testPoint(1, 1);
2775 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 2775 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
2776 EXPECT_FALSE(resultLayer); 2776 EXPECT_FALSE(resultLayer);
2777 2777
2778 testPoint = IntPoint(10, 10); 2778 testPoint = gfx::Point(10, 10);
2779 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2779 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2780 EXPECT_FALSE(resultLayer); 2780 EXPECT_FALSE(resultLayer);
2781 2781
2782 testPoint = IntPoint(10, 30); 2782 testPoint = gfx::Point(10, 30);
2783 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2783 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2784 EXPECT_FALSE(resultLayer); 2784 EXPECT_FALSE(resultLayer);
2785 2785
2786 testPoint = IntPoint(50, 50); 2786 testPoint = gfx::Point(50, 50);
2787 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2787 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2788 EXPECT_FALSE(resultLayer); 2788 EXPECT_FALSE(resultLayer);
2789 2789
2790 testPoint = IntPoint(67, 48); 2790 testPoint = gfx::Point(67, 48);
2791 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2791 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2792 EXPECT_FALSE(resultLayer); 2792 EXPECT_FALSE(resultLayer);
2793 2793
2794 testPoint = IntPoint(99, 99); 2794 testPoint = gfx::Point(99, 99);
2795 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2795 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2796 EXPECT_FALSE(resultLayer); 2796 EXPECT_FALSE(resultLayer);
2797 2797
2798 testPoint = IntPoint(-1, -1); 2798 testPoint = gfx::Point(-1, -1);
2799 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2799 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2800 EXPECT_FALSE(resultLayer); 2800 EXPECT_FALSE(resultLayer);
2801 } 2801 }
2802 2802
2803 TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePositionedLayer) 2803 TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePositionedLayer)
2804 { 2804 {
2805 DebugScopedSetImplThread thisScopeIsOnImplThread; 2805 DebugScopedSetImplThread thisScopeIsOnImplThread;
2806 2806
2807 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 2807 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
2808 2808
2809 WebTransformationMatrix identityMatrix; 2809 WebTransformationMatrix identityMatrix;
2810 FloatPoint anchor(0, 0); 2810 gfx::PointF anchor(0, 0);
2811 FloatPoint position(50, 50); // this layer is positioned, and hit testing sh ould correctly know where the layer is located. 2811 gfx::PointF position(50, 50); // this layer is positioned, and hit testing s hould correctly know where the layer is located.
2812 IntSize bounds(100, 100); 2812 gfx::Size bounds(100, 100);
2813 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 2813 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
2814 root->setDrawsContent(true); 2814 root->setDrawsContent(true);
2815 2815
2816 std::vector<LayerImpl*> renderSurfaceLayerList; 2816 std::vector<LayerImpl*> renderSurfaceLayerList;
2817 int dummyMaxTextureSize = 512; 2817 int dummyMaxTextureSize = 512;
2818 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2818 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2819 2819
2820 // Sanity check the scenario we just created. 2820 // Sanity check the scenario we just created.
2821 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 2821 ASSERT_EQ(1u, renderSurfaceLayerList.size());
2822 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 2822 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
2823 2823
2824 // Hit testing for a point outside the layer should return a null pointer. 2824 // Hit testing for a point outside the layer should return a null pointer.
2825 IntPoint testPoint(49, 49); 2825 gfx::Point testPoint(49, 49);
2826 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 2826 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
2827 EXPECT_FALSE(resultLayer); 2827 EXPECT_FALSE(resultLayer);
2828 2828
2829 // Even though the layer exists at (101, 101), it should not be visible ther e since the root renderSurface would clamp it. 2829 // Even though the layer exists at (101, 101), it should not be visible ther e since the root renderSurface would clamp it.
2830 testPoint = IntPoint(101, 101); 2830 testPoint = gfx::Point(101, 101);
2831 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2831 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2832 EXPECT_FALSE(resultLayer); 2832 EXPECT_FALSE(resultLayer);
2833 2833
2834 // Hit testing for a point inside should return the root layer. 2834 // Hit testing for a point inside should return the root layer.
2835 testPoint = IntPoint(51, 51); 2835 testPoint = gfx::Point(51, 51);
2836 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2836 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2837 ASSERT_TRUE(resultLayer); 2837 ASSERT_TRUE(resultLayer);
2838 EXPECT_EQ(12345, resultLayer->id()); 2838 EXPECT_EQ(12345, resultLayer->id());
2839 2839
2840 testPoint = IntPoint(99, 99); 2840 testPoint = gfx::Point(99, 99);
2841 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2841 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2842 ASSERT_TRUE(resultLayer); 2842 ASSERT_TRUE(resultLayer);
2843 EXPECT_EQ(12345, resultLayer->id()); 2843 EXPECT_EQ(12345, resultLayer->id());
2844 } 2844 }
2845 2845
2846 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer) 2846 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer)
2847 { 2847 {
2848 DebugScopedSetImplThread thisScopeIsOnImplThread; 2848 DebugScopedSetImplThread thisScopeIsOnImplThread;
2849 2849
2850 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 2850 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
2851 2851
2852 WebTransformationMatrix identityMatrix; 2852 WebTransformationMatrix identityMatrix;
2853 WebTransformationMatrix rotation45DegreesAboutCenter; 2853 WebTransformationMatrix rotation45DegreesAboutCenter;
2854 rotation45DegreesAboutCenter.translate(50, 50); 2854 rotation45DegreesAboutCenter.translate(50, 50);
2855 rotation45DegreesAboutCenter.rotate3d(0, 0, 45); 2855 rotation45DegreesAboutCenter.rotate3d(0, 0, 45);
2856 rotation45DegreesAboutCenter.translate(-50, -50); 2856 rotation45DegreesAboutCenter.translate(-50, -50);
2857 FloatPoint anchor(0, 0); 2857 gfx::PointF anchor(0, 0);
2858 FloatPoint position(0, 0); 2858 gfx::PointF position(0, 0);
2859 IntSize bounds(100, 100); 2859 gfx::Size bounds(100, 100);
2860 setLayerPropertiesForTesting(root.get(), rotation45DegreesAboutCenter, ident ityMatrix, anchor, position, bounds, false); 2860 setLayerPropertiesForTesting(root.get(), rotation45DegreesAboutCenter, ident ityMatrix, anchor, position, bounds, false);
2861 root->setDrawsContent(true); 2861 root->setDrawsContent(true);
2862 2862
2863 std::vector<LayerImpl*> renderSurfaceLayerList; 2863 std::vector<LayerImpl*> renderSurfaceLayerList;
2864 int dummyMaxTextureSize = 512; 2864 int dummyMaxTextureSize = 512;
2865 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2865 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2866 2866
2867 // Sanity check the scenario we just created. 2867 // Sanity check the scenario we just created.
2868 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 2868 ASSERT_EQ(1u, renderSurfaceLayerList.size());
2869 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 2869 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
2870 2870
2871 // Hit testing for points outside the layer. 2871 // Hit testing for points outside the layer.
2872 // These corners would have been inside the un-transformed layer, but they s hould not hit the correctly transformed layer. 2872 // These corners would have been inside the un-transformed layer, but they s hould not hit the correctly transformed layer.
2873 IntPoint testPoint(99, 99); 2873 gfx::Point testPoint(99, 99);
2874 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 2874 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
2875 EXPECT_FALSE(resultLayer); 2875 EXPECT_FALSE(resultLayer);
2876 2876
2877 testPoint = IntPoint(1, 1); 2877 testPoint = gfx::Point(1, 1);
2878 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2878 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2879 EXPECT_FALSE(resultLayer); 2879 EXPECT_FALSE(resultLayer);
2880 2880
2881 // Hit testing for a point inside should return the root layer. 2881 // Hit testing for a point inside should return the root layer.
2882 testPoint = IntPoint(1, 50); 2882 testPoint = gfx::Point(1, 50);
2883 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2883 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2884 ASSERT_TRUE(resultLayer); 2884 ASSERT_TRUE(resultLayer);
2885 EXPECT_EQ(12345, resultLayer->id()); 2885 EXPECT_EQ(12345, resultLayer->id());
2886 2886
2887 // Hit testing the corners that would overlap the unclipped layer, but are o utside the clipped region. 2887 // Hit testing the corners that would overlap the unclipped layer, but are o utside the clipped region.
2888 testPoint = IntPoint(50, -1); 2888 testPoint = gfx::Point(50, -1);
2889 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2889 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2890 ASSERT_FALSE(resultLayer); 2890 ASSERT_FALSE(resultLayer);
2891 2891
2892 testPoint = IntPoint(-1, 50); 2892 testPoint = gfx::Point(-1, 50);
2893 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2893 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2894 ASSERT_FALSE(resultLayer); 2894 ASSERT_FALSE(resultLayer);
2895 } 2895 }
2896 2896
2897 TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePerspectiveLayer) 2897 TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePerspectiveLayer)
2898 { 2898 {
2899 DebugScopedSetImplThread thisScopeIsOnImplThread; 2899 DebugScopedSetImplThread thisScopeIsOnImplThread;
2900 2900
2901 scoped_ptr<LayerImpl> root = LayerImpl::create(12345); 2901 scoped_ptr<LayerImpl> root = LayerImpl::create(12345);
2902 2902
2903 WebTransformationMatrix identityMatrix; 2903 WebTransformationMatrix identityMatrix;
2904 2904
2905 // perspectiveProjectionAboutCenter * translationByZ is designed so that the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50). 2905 // perspectiveProjectionAboutCenter * translationByZ is designed so that the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50).
2906 WebTransformationMatrix perspectiveProjectionAboutCenter; 2906 WebTransformationMatrix perspectiveProjectionAboutCenter;
2907 perspectiveProjectionAboutCenter.translate(50, 50); 2907 perspectiveProjectionAboutCenter.translate(50, 50);
2908 perspectiveProjectionAboutCenter.applyPerspective(1); 2908 perspectiveProjectionAboutCenter.applyPerspective(1);
2909 perspectiveProjectionAboutCenter.translate(-50, -50); 2909 perspectiveProjectionAboutCenter.translate(-50, -50);
2910 WebTransformationMatrix translationByZ; 2910 WebTransformationMatrix translationByZ;
2911 translationByZ.translate3d(0, 0, -1); 2911 translationByZ.translate3d(0, 0, -1);
2912 2912
2913 FloatPoint anchor(0, 0); 2913 gfx::PointF anchor(0, 0);
2914 FloatPoint position(0, 0); 2914 gfx::PointF position(0, 0);
2915 IntSize bounds(100, 100); 2915 gfx::Size bounds(100, 100);
2916 setLayerPropertiesForTesting(root.get(), perspectiveProjectionAboutCenter * translationByZ, identityMatrix, anchor, position, bounds, false); 2916 setLayerPropertiesForTesting(root.get(), perspectiveProjectionAboutCenter * translationByZ, identityMatrix, anchor, position, bounds, false);
2917 root->setDrawsContent(true); 2917 root->setDrawsContent(true);
2918 2918
2919 std::vector<LayerImpl*> renderSurfaceLayerList; 2919 std::vector<LayerImpl*> renderSurfaceLayerList;
2920 int dummyMaxTextureSize = 512; 2920 int dummyMaxTextureSize = 512;
2921 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2921 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2922 2922
2923 // Sanity check the scenario we just created. 2923 // Sanity check the scenario we just created.
2924 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 2924 ASSERT_EQ(1u, renderSurfaceLayerList.size());
2925 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 2925 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
2926 2926
2927 // Hit testing for points outside the layer. 2927 // Hit testing for points outside the layer.
2928 // These corners would have been inside the un-transformed layer, but they s hould not hit the correctly transformed layer. 2928 // These corners would have been inside the un-transformed layer, but they s hould not hit the correctly transformed layer.
2929 IntPoint testPoint(24, 24); 2929 gfx::Point testPoint(24, 24);
2930 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 2930 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
2931 EXPECT_FALSE(resultLayer); 2931 EXPECT_FALSE(resultLayer);
2932 2932
2933 testPoint = IntPoint(76, 76); 2933 testPoint = gfx::Point(76, 76);
2934 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2934 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2935 EXPECT_FALSE(resultLayer); 2935 EXPECT_FALSE(resultLayer);
2936 2936
2937 // Hit testing for a point inside should return the root layer. 2937 // Hit testing for a point inside should return the root layer.
2938 testPoint = IntPoint(26, 26); 2938 testPoint = gfx::Point(26, 26);
2939 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2939 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2940 ASSERT_TRUE(resultLayer); 2940 ASSERT_TRUE(resultLayer);
2941 EXPECT_EQ(12345, resultLayer->id()); 2941 EXPECT_EQ(12345, resultLayer->id());
2942 2942
2943 testPoint = IntPoint(74, 74); 2943 testPoint = gfx::Point(74, 74);
2944 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 2944 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
2945 ASSERT_TRUE(resultLayer); 2945 ASSERT_TRUE(resultLayer);
2946 EXPECT_EQ(12345, resultLayer->id()); 2946 EXPECT_EQ(12345, resultLayer->id());
2947 } 2947 }
2948 2948
2949 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayerWithScaledContents) 2949 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayerWithScaledContents)
2950 { 2950 {
2951 // A layer's visibleContentRect is actually in the layer's content space. Th e 2951 // A layer's visibleContentRect is actually in the layer's content space. Th e
2952 // screenSpaceTransform converts from the layer's origin space to screen spa ce. This 2952 // screenSpaceTransform converts from the layer's origin space to screen spa ce. This
2953 // test makes sure that hit testing works correctly accounts for the content s scale. 2953 // test makes sure that hit testing works correctly accounts for the content s scale.
2954 // A contentsScale that is not 1 effectively forces a non-identity transform between 2954 // A contentsScale that is not 1 effectively forces a non-identity transform between
2955 // layer's content space and layer's origin space. The hit testing code must take this into account. 2955 // layer's content space and layer's origin space. The hit testing code must take this into account.
2956 // 2956 //
2957 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If 2957 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
2958 // contentsScale is ignored, then hit testing will mis-interpret the visible ContentRect 2958 // contentsScale is ignored, then hit testing will mis-interpret the visible ContentRect
2959 // as being larger than the actual bounds of the layer. 2959 // as being larger than the actual bounds of the layer.
2960 // 2960 //
2961 DebugScopedSetImplThread thisScopeIsOnImplThread; 2961 DebugScopedSetImplThread thisScopeIsOnImplThread;
2962 2962
2963 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 2963 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
2964 2964
2965 WebTransformationMatrix identityMatrix; 2965 WebTransformationMatrix identityMatrix;
2966 FloatPoint anchor(0, 0); 2966 gfx::PointF anchor(0, 0);
2967 2967
2968 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, FloatPoint(0, 0), IntSize(100, 100), false); 2968 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
2969 2969
2970 { 2970 {
2971 FloatPoint position(25, 25); 2971 gfx::PointF position(25, 25);
2972 IntSize bounds(50, 50); 2972 gfx::Size bounds(50, 50);
2973 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345); 2973 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345);
2974 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false); 2974 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false);
2975 2975
2976 // override contentBounds and contentsScale 2976 // override contentBounds and contentsScale
2977 testLayer->setContentBounds(IntSize(100, 100)); 2977 testLayer->setContentBounds(gfx::Size(100, 100));
2978 testLayer->setContentsScale(2, 2); 2978 testLayer->setContentsScale(2, 2);
2979 2979
2980 testLayer->setDrawsContent(true); 2980 testLayer->setDrawsContent(true);
2981 root->addChild(testLayer.Pass()); 2981 root->addChild(testLayer.Pass());
2982 } 2982 }
2983 2983
2984 std::vector<LayerImpl*> renderSurfaceLayerList; 2984 std::vector<LayerImpl*> renderSurfaceLayerList;
2985 int dummyMaxTextureSize = 512; 2985 int dummyMaxTextureSize = 512;
2986 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2986 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2987 2987
2988 // Sanity check the scenario we just created. 2988 // Sanity check the scenario we just created.
2989 // The visibleContentRect for testLayer is actually 100x100, even though its layout size is 50x50, positioned at 25x25. 2989 // The visibleContentRect for testLayer is actually 100x100, even though its layout size is 50x50, positioned at 25x25.
2990 LayerImpl* testLayer = root->children()[0]; 2990 LayerImpl* testLayer = root->children()[0];
2991 EXPECT_RECT_EQ(IntRect(IntPoint::zero(), IntSize(100, 100)), testLayer->visi bleContentRect()); 2991 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(), gfx::Size(100, 100)), testLayer->visi bleContentRect());
2992 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 2992 ASSERT_EQ(1u, renderSurfaceLayerList.size());
2993 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 2993 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
2994 2994
2995 // 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). 2995 // 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).
2996 IntPoint testPoint(101, 101); 2996 gfx::Point testPoint(101, 101);
2997 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 2997 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
2998 EXPECT_FALSE(resultLayer); 2998 EXPECT_FALSE(resultLayer);
2999 2999
3000 testPoint = IntPoint(24, 24); 3000 testPoint = gfx::Point(24, 24);
3001 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3001 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3002 EXPECT_FALSE(resultLayer); 3002 EXPECT_FALSE(resultLayer);
3003 3003
3004 testPoint = IntPoint(76, 76); 3004 testPoint = gfx::Point(76, 76);
3005 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3005 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3006 EXPECT_FALSE(resultLayer); 3006 EXPECT_FALSE(resultLayer);
3007 3007
3008 // Hit testing for a point inside should return the test layer. 3008 // Hit testing for a point inside should return the test layer.
3009 testPoint = IntPoint(26, 26); 3009 testPoint = gfx::Point(26, 26);
3010 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3010 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3011 ASSERT_TRUE(resultLayer); 3011 ASSERT_TRUE(resultLayer);
3012 EXPECT_EQ(12345, resultLayer->id()); 3012 EXPECT_EQ(12345, resultLayer->id());
3013 3013
3014 testPoint = IntPoint(74, 74); 3014 testPoint = gfx::Point(74, 74);
3015 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3015 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3016 ASSERT_TRUE(resultLayer); 3016 ASSERT_TRUE(resultLayer);
3017 EXPECT_EQ(12345, resultLayer->id()); 3017 EXPECT_EQ(12345, resultLayer->id());
3018 } 3018 }
3019 3019
3020 TEST(LayerTreeHostCommonTest, verifyHitTestingForSimpleClippedLayer) 3020 TEST(LayerTreeHostCommonTest, verifyHitTestingForSimpleClippedLayer)
3021 { 3021 {
3022 // Test that hit-testing will only work for the visible portion of a layer, and not 3022 // Test that hit-testing will only work for the visible portion of a layer, and not
3023 // the entire layer bounds. Here we just test the simple axis-aligned case. 3023 // the entire layer bounds. Here we just test the simple axis-aligned case.
3024 DebugScopedSetImplThread thisScopeIsOnImplThread; 3024 DebugScopedSetImplThread thisScopeIsOnImplThread;
3025 3025
3026 WebTransformationMatrix identityMatrix; 3026 WebTransformationMatrix identityMatrix;
3027 FloatPoint anchor(0, 0); 3027 gfx::PointF anchor(0, 0);
3028 3028
3029 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 3029 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3030 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, FloatPoint(0, 0), IntSize(100, 100), false); 3030 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
3031 3031
3032 { 3032 {
3033 scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(123); 3033 scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(123);
3034 FloatPoint position(25, 25); // this layer is positioned, and hit testin g should correctly know where the layer is located. 3034 gfx::PointF position(25, 25); // this layer is positioned, and hit testi ng should correctly know where the layer is located.
3035 IntSize bounds(50, 50); 3035 gfx::Size bounds(50, 50);
3036 setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identi tyMatrix, anchor, position, bounds, false); 3036 setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identi tyMatrix, anchor, position, bounds, false);
3037 clippingLayer->setMasksToBounds(true); 3037 clippingLayer->setMasksToBounds(true);
3038 3038
3039 scoped_ptr<LayerImpl> child = LayerImpl::create(456); 3039 scoped_ptr<LayerImpl> child = LayerImpl::create(456);
3040 position = FloatPoint(-50, -50); 3040 position = gfx::PointF(-50, -50);
3041 bounds = IntSize(300, 300); 3041 bounds = gfx::Size(300, 300);
3042 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false); 3042 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false);
3043 child->setDrawsContent(true); 3043 child->setDrawsContent(true);
3044 clippingLayer->addChild(child.Pass()); 3044 clippingLayer->addChild(child.Pass());
3045 root->addChild(clippingLayer.Pass()); 3045 root->addChild(clippingLayer.Pass());
3046 } 3046 }
3047 3047
3048 std::vector<LayerImpl*> renderSurfaceLayerList; 3048 std::vector<LayerImpl*> renderSurfaceLayerList;
3049 int dummyMaxTextureSize = 512; 3049 int dummyMaxTextureSize = 512;
3050 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 3050 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3051 3051
3052 // Sanity check the scenario we just created. 3052 // Sanity check the scenario we just created.
3053 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 3053 ASSERT_EQ(1u, renderSurfaceLayerList.size());
3054 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 3054 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
3055 ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id()); 3055 ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id());
3056 3056
3057 // Hit testing for a point outside the layer should return a null pointer. 3057 // Hit testing for a point outside the layer should return a null pointer.
3058 // Despite the child layer being very large, it should be clipped to the roo t layer's bounds. 3058 // Despite the child layer being very large, it should be clipped to the roo t layer's bounds.
3059 IntPoint testPoint(24, 24); 3059 gfx::Point testPoint(24, 24);
3060 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 3060 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
3061 EXPECT_FALSE(resultLayer); 3061 EXPECT_FALSE(resultLayer);
3062 3062
3063 // Even though the layer exists at (101, 101), it should not be visible ther e since the clippingLayer would clamp it. 3063 // Even though the layer exists at (101, 101), it should not be visible ther e since the clippingLayer would clamp it.
3064 testPoint = IntPoint(76, 76); 3064 testPoint = gfx::Point(76, 76);
3065 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3065 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3066 EXPECT_FALSE(resultLayer); 3066 EXPECT_FALSE(resultLayer);
3067 3067
3068 // Hit testing for a point inside should return the child layer. 3068 // Hit testing for a point inside should return the child layer.
3069 testPoint = IntPoint(26, 26); 3069 testPoint = gfx::Point(26, 26);
3070 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3070 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3071 ASSERT_TRUE(resultLayer); 3071 ASSERT_TRUE(resultLayer);
3072 EXPECT_EQ(456, resultLayer->id()); 3072 EXPECT_EQ(456, resultLayer->id());
3073 3073
3074 testPoint = IntPoint(74, 74); 3074 testPoint = gfx::Point(74, 74);
3075 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3075 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3076 ASSERT_TRUE(resultLayer); 3076 ASSERT_TRUE(resultLayer);
3077 EXPECT_EQ(456, resultLayer->id()); 3077 EXPECT_EQ(456, resultLayer->id());
3078 } 3078 }
3079 3079
3080 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultiClippedRotatedLayer) 3080 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultiClippedRotatedLayer)
3081 { 3081 {
3082 // This test checks whether hit testing correctly avoids hit testing with mu ltiple 3082 // This test checks whether hit testing correctly avoids hit testing with mu ltiple
3083 // ancestors that clip in non axis-aligned ways. To pass this test, the hit testing 3083 // ancestors that clip in non axis-aligned ways. To pass this test, the hit testing
3084 // algorithm needs to recognize that multiple parent layers may clip the lay er, and 3084 // algorithm needs to recognize that multiple parent layers may clip the lay er, and
3085 // should not actually hit those clipped areas. 3085 // should not actually hit those clipped areas.
3086 // 3086 //
3087 // The child and grandChild layers are both initialized to clip the rotatedL eaf. The 3087 // The child and grandChild layers are both initialized to clip the rotatedL eaf. The
3088 // child layer is rotated about the top-left corner, so that the root + chil d clips 3088 // child layer is rotated about the top-left corner, so that the root + chil d clips
3089 // combined create a triangle. The rotatedLeaf will only be visible where it overlaps 3089 // combined create a triangle. The rotatedLeaf will only be visible where it overlaps
3090 // this triangle. 3090 // this triangle.
3091 // 3091 //
3092 DebugScopedSetImplThread thisScopeIsOnImplThread; 3092 DebugScopedSetImplThread thisScopeIsOnImplThread;
3093 3093
3094 scoped_ptr<LayerImpl> root = LayerImpl::create(123); 3094 scoped_ptr<LayerImpl> root = LayerImpl::create(123);
3095 3095
3096 WebTransformationMatrix identityMatrix; 3096 WebTransformationMatrix identityMatrix;
3097 FloatPoint anchor(0, 0); 3097 gfx::PointF anchor(0, 0);
3098 FloatPoint position(0, 0); 3098 gfx::PointF position(0, 0);
3099 IntSize bounds(100, 100); 3099 gfx::Size bounds(100, 100);
3100 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 3100 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
3101 root->setMasksToBounds(true); 3101 root->setMasksToBounds(true);
3102 3102
3103 { 3103 {
3104 scoped_ptr<LayerImpl> child = LayerImpl::create(456); 3104 scoped_ptr<LayerImpl> child = LayerImpl::create(456);
3105 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(789); 3105 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(789);
3106 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(2468); 3106 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(2468);
3107 3107
3108 position = FloatPoint(10, 10); 3108 position = gfx::PointF(10, 10);
3109 bounds = IntSize(80, 80); 3109 bounds = gfx::Size(80, 80);
3110 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false); 3110 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false);
3111 child->setMasksToBounds(true); 3111 child->setMasksToBounds(true);
3112 3112
3113 WebTransformationMatrix rotation45DegreesAboutCorner; 3113 WebTransformationMatrix rotation45DegreesAboutCorner;
3114 rotation45DegreesAboutCorner.rotate3d(0, 0, 45); 3114 rotation45DegreesAboutCorner.rotate3d(0, 0, 45);
3115 3115
3116 position = FloatPoint(0, 0); // remember, positioned with respect to its parent which is already at 10, 10 3116 position = gfx::PointF(0, 0); // remember, positioned with respect to it s parent which is already at 10, 10
3117 bounds = IntSize(200, 200); // to ensure it covers at least sqrt(2) * 10 0. 3117 bounds = gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100.
3118 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor ner, identityMatrix, anchor, position, bounds, false); 3118 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor ner, identityMatrix, anchor, position, bounds, false);
3119 grandChild->setMasksToBounds(true); 3119 grandChild->setMasksToBounds(true);
3120 3120
3121 // Rotates about the center of the layer 3121 // Rotates about the center of the layer
3122 WebTransformationMatrix rotatedLeafTransform; 3122 WebTransformationMatrix rotatedLeafTransform;
3123 rotatedLeafTransform.translate(-10, -10); // cancel out the grandParent' s position 3123 rotatedLeafTransform.translate(-10, -10); // cancel out the grandParent' s position
3124 rotatedLeafTransform.rotate3d(0, 0, -45); // cancel out the corner 45-de gree rotation of the parent. 3124 rotatedLeafTransform.rotate3d(0, 0, -45); // cancel out the corner 45-de gree rotation of the parent.
3125 rotatedLeafTransform.translate(50, 50); 3125 rotatedLeafTransform.translate(50, 50);
3126 rotatedLeafTransform.rotate3d(0, 0, 45); 3126 rotatedLeafTransform.rotate3d(0, 0, 45);
3127 rotatedLeafTransform.translate(-50, -50); 3127 rotatedLeafTransform.translate(-50, -50);
3128 position = FloatPoint(0, 0); 3128 position = gfx::PointF(0, 0);
3129 bounds = IntSize(100, 100); 3129 bounds = gfx::Size(100, 100);
3130 setLayerPropertiesForTesting(rotatedLeaf.get(), rotatedLeafTransform, id entityMatrix, anchor, position, bounds, false); 3130 setLayerPropertiesForTesting(rotatedLeaf.get(), rotatedLeafTransform, id entityMatrix, anchor, position, bounds, false);
3131 rotatedLeaf->setDrawsContent(true); 3131 rotatedLeaf->setDrawsContent(true);
3132 3132
3133 grandChild->addChild(rotatedLeaf.Pass()); 3133 grandChild->addChild(rotatedLeaf.Pass());
3134 child->addChild(grandChild.Pass()); 3134 child->addChild(grandChild.Pass());
3135 root->addChild(child.Pass()); 3135 root->addChild(child.Pass());
3136 } 3136 }
3137 3137
3138 std::vector<LayerImpl*> renderSurfaceLayerList; 3138 std::vector<LayerImpl*> renderSurfaceLayerList;
3139 int dummyMaxTextureSize = 512; 3139 int dummyMaxTextureSize = 512;
3140 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 3140 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3141 3141
3142 // Sanity check the scenario we just created. 3142 // Sanity check the scenario we just created.
3143 // The grandChild is expected to create a renderSurface because it masksToBo unds and is not axis aligned. 3143 // The grandChild is expected to create a renderSurface because it masksToBo unds and is not axis aligned.
3144 ASSERT_EQ(2u, renderSurfaceLayerList.size()); 3144 ASSERT_EQ(2u, renderSurfaceLayerList.size());
3145 ASSERT_EQ(1u, renderSurfaceLayerList[0]->renderSurface()->layerList().size() ); 3145 ASSERT_EQ(1u, renderSurfaceLayerList[0]->renderSurface()->layerList().size() );
3146 ASSERT_EQ(789, renderSurfaceLayerList[0]->renderSurface()->layerList()[0]->i d()); // grandChild's surface. 3146 ASSERT_EQ(789, renderSurfaceLayerList[0]->renderSurface()->layerList()[0]->i d()); // grandChild's surface.
3147 ASSERT_EQ(1u, renderSurfaceLayerList[1]->renderSurface()->layerList().size() ); 3147 ASSERT_EQ(1u, renderSurfaceLayerList[1]->renderSurface()->layerList().size() );
3148 ASSERT_EQ(2468, renderSurfaceLayerList[1]->renderSurface()->layerList()[0]-> id()); 3148 ASSERT_EQ(2468, renderSurfaceLayerList[1]->renderSurface()->layerList()[0]-> id());
3149 3149
3150 // (11, 89) is close to the the bottom left corner within the clip, but it i s not inside the layer. 3150 // (11, 89) is close to the the bottom left corner within the clip, but it i s not inside the layer.
3151 IntPoint testPoint(11, 89); 3151 gfx::Point testPoint(11, 89);
3152 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 3152 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
3153 EXPECT_FALSE(resultLayer); 3153 EXPECT_FALSE(resultLayer);
3154 3154
3155 // Closer inwards from the bottom left will overlap the layer. 3155 // Closer inwards from the bottom left will overlap the layer.
3156 testPoint = IntPoint(25, 75); 3156 testPoint = gfx::Point(25, 75);
3157 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3157 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3158 ASSERT_TRUE(resultLayer); 3158 ASSERT_TRUE(resultLayer);
3159 EXPECT_EQ(2468, resultLayer->id()); 3159 EXPECT_EQ(2468, resultLayer->id());
3160 3160
3161 // (4, 50) is inside the unclipped layer, but that corner of the layer shoul d be 3161 // (4, 50) is inside the unclipped layer, but that corner of the layer shoul d be
3162 // clipped away by the grandParent and should not get hit. If hit testing bl indly uses 3162 // clipped away by the grandParent and should not get hit. If hit testing bl indly uses
3163 // visibleContentRect without considering how parent may clip the layer, the n hit 3163 // visibleContentRect without considering how parent may clip the layer, the n hit
3164 // testing would accidentally think that the point successfully hits the lay er. 3164 // testing would accidentally think that the point successfully hits the lay er.
3165 testPoint = IntPoint(4, 50); 3165 testPoint = gfx::Point(4, 50);
3166 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3166 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3167 EXPECT_FALSE(resultLayer); 3167 EXPECT_FALSE(resultLayer);
3168 3168
3169 // (11, 50) is inside the layer and within the clipped area. 3169 // (11, 50) is inside the layer and within the clipped area.
3170 testPoint = IntPoint(11, 50); 3170 testPoint = gfx::Point(11, 50);
3171 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3171 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3172 ASSERT_TRUE(resultLayer); 3172 ASSERT_TRUE(resultLayer);
3173 EXPECT_EQ(2468, resultLayer->id()); 3173 EXPECT_EQ(2468, resultLayer->id());
3174 3174
3175 // Around the middle, just to the right and up, would have hit the layer exc ept that 3175 // Around the middle, just to the right and up, would have hit the layer exc ept that
3176 // that area should be clipped away by the parent. 3176 // that area should be clipped away by the parent.
3177 testPoint = IntPoint(51, 51); 3177 testPoint = gfx::Point(51, 51);
3178 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3178 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3179 EXPECT_FALSE(resultLayer); 3179 EXPECT_FALSE(resultLayer);
3180 3180
3181 // Around the middle, just to the left and down, should successfully hit the layer. 3181 // Around the middle, just to the left and down, should successfully hit the layer.
3182 testPoint = IntPoint(49, 51); 3182 testPoint = gfx::Point(49, 51);
3183 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3183 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3184 ASSERT_TRUE(resultLayer); 3184 ASSERT_TRUE(resultLayer);
3185 EXPECT_EQ(2468, resultLayer->id()); 3185 EXPECT_EQ(2468, resultLayer->id());
3186 } 3186 }
3187 3187
3188 TEST(LayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer) 3188 TEST(LayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer)
3189 { 3189 {
3190 // This test checks that hit testing code does not accidentally clip to laye r 3190 // This test checks that hit testing code does not accidentally clip to laye r
3191 // bounds for a layer that actually does not clip. 3191 // bounds for a layer that actually does not clip.
3192 DebugScopedSetImplThread thisScopeIsOnImplThread; 3192 DebugScopedSetImplThread thisScopeIsOnImplThread;
3193 3193
3194 WebTransformationMatrix identityMatrix; 3194 WebTransformationMatrix identityMatrix;
3195 FloatPoint anchor(0, 0); 3195 gfx::PointF anchor(0, 0);
3196 3196
3197 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 3197 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3198 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, FloatPoint(0, 0), IntSize(100, 100), false); 3198 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
3199 3199
3200 { 3200 {
3201 scoped_ptr<LayerImpl> intermediateLayer = LayerImpl::create(123); 3201 scoped_ptr<LayerImpl> intermediateLayer = LayerImpl::create(123);
3202 FloatPoint position(10, 10); // this layer is positioned, and hit testin g should correctly know where the layer is located. 3202 gfx::PointF position(10, 10); // this layer is positioned, and hit testi ng should correctly know where the layer is located.
3203 IntSize bounds(50, 50); 3203 gfx::Size bounds(50, 50);
3204 setLayerPropertiesForTesting(intermediateLayer.get(), identityMatrix, id entityMatrix, anchor, position, bounds, false); 3204 setLayerPropertiesForTesting(intermediateLayer.get(), identityMatrix, id entityMatrix, anchor, position, bounds, false);
3205 // Sanity check the intermediate layer should not clip. 3205 // Sanity check the intermediate layer should not clip.
3206 ASSERT_FALSE(intermediateLayer->masksToBounds()); 3206 ASSERT_FALSE(intermediateLayer->masksToBounds());
3207 ASSERT_FALSE(intermediateLayer->maskLayer()); 3207 ASSERT_FALSE(intermediateLayer->maskLayer());
3208 3208
3209 // The child of the intermediateLayer is translated so that it does not overlap intermediateLayer at all. 3209 // The child of the intermediateLayer is translated so that it does not overlap intermediateLayer at all.
3210 // If child is incorrectly clipped, we would not be able to hit it succe ssfully. 3210 // If child is incorrectly clipped, we would not be able to hit it succe ssfully.
3211 scoped_ptr<LayerImpl> child = LayerImpl::create(456); 3211 scoped_ptr<LayerImpl> child = LayerImpl::create(456);
3212 position = FloatPoint(60, 60); // 70, 70 in screen space 3212 position = gfx::PointF(60, 60); // 70, 70 in screen space
3213 bounds = IntSize(20, 20); 3213 bounds = gfx::Size(20, 20);
3214 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false); 3214 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix , anchor, position, bounds, false);
3215 child->setDrawsContent(true); 3215 child->setDrawsContent(true);
3216 intermediateLayer->addChild(child.Pass()); 3216 intermediateLayer->addChild(child.Pass());
3217 root->addChild(intermediateLayer.Pass()); 3217 root->addChild(intermediateLayer.Pass());
3218 } 3218 }
3219 3219
3220 std::vector<LayerImpl*> renderSurfaceLayerList; 3220 std::vector<LayerImpl*> renderSurfaceLayerList;
3221 int dummyMaxTextureSize = 512; 3221 int dummyMaxTextureSize = 512;
3222 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 3222 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3223 3223
3224 // Sanity check the scenario we just created. 3224 // Sanity check the scenario we just created.
3225 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 3225 ASSERT_EQ(1u, renderSurfaceLayerList.size());
3226 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); 3226 ASSERT_EQ(1u, root->renderSurface()->layerList().size());
3227 ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id()); 3227 ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id());
3228 3228
3229 // Hit testing for a point outside the layer should return a null pointer. 3229 // Hit testing for a point outside the layer should return a null pointer.
3230 IntPoint testPoint(69, 69); 3230 gfx::Point testPoint(69, 69);
3231 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 3231 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
3232 EXPECT_FALSE(resultLayer); 3232 EXPECT_FALSE(resultLayer);
3233 3233
3234 testPoint = IntPoint(91, 91); 3234 testPoint = gfx::Point(91, 91);
3235 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3235 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3236 EXPECT_FALSE(resultLayer); 3236 EXPECT_FALSE(resultLayer);
3237 3237
3238 // Hit testing for a point inside should return the child layer. 3238 // Hit testing for a point inside should return the child layer.
3239 testPoint = IntPoint(71, 71); 3239 testPoint = gfx::Point(71, 71);
3240 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3240 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3241 ASSERT_TRUE(resultLayer); 3241 ASSERT_TRUE(resultLayer);
3242 EXPECT_EQ(456, resultLayer->id()); 3242 EXPECT_EQ(456, resultLayer->id());
3243 3243
3244 testPoint = IntPoint(89, 89); 3244 testPoint = gfx::Point(89, 89);
3245 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3245 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3246 ASSERT_TRUE(resultLayer); 3246 ASSERT_TRUE(resultLayer);
3247 EXPECT_EQ(456, resultLayer->id()); 3247 EXPECT_EQ(456, resultLayer->id());
3248 } 3248 }
3249 3249
3250 3250
3251 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayers) 3251 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayers)
3252 { 3252 {
3253 DebugScopedSetImplThread thisScopeIsOnImplThread; 3253 DebugScopedSetImplThread thisScopeIsOnImplThread;
3254 3254
3255 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 3255 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3256 3256
3257 WebTransformationMatrix identityMatrix; 3257 WebTransformationMatrix identityMatrix;
3258 FloatPoint anchor(0, 0); 3258 gfx::PointF anchor(0, 0);
3259 FloatPoint position(0, 0); 3259 gfx::PointF position(0, 0);
3260 IntSize bounds(100, 100); 3260 gfx::Size bounds(100, 100);
3261 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 3261 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
3262 root->setDrawsContent(true); 3262 root->setDrawsContent(true);
3263 3263
3264 { 3264 {
3265 // child 1 and child2 are initialized to overlap between x=50 and x=60. 3265 // child 1 and child2 are initialized to overlap between x=50 and x=60.
3266 // grandChild is set to overlap both child1 and child2 between y=50 and y=60. 3266 // grandChild is set to overlap both child1 and child2 between y=50 and y=60.
3267 // The expected stacking order is: 3267 // The expected stacking order is:
3268 // (front) child2, (second) grandChild, (third) child1, and (back) the root layer behind all other layers. 3268 // (front) child2, (second) grandChild, (third) child1, and (back) the root layer behind all other layers.
3269 3269
3270 scoped_ptr<LayerImpl> child1 = LayerImpl::create(2); 3270 scoped_ptr<LayerImpl> child1 = LayerImpl::create(2);
3271 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); 3271 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3);
3272 scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(4); 3272 scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(4);
3273 3273
3274 position = FloatPoint(10, 10); 3274 position = gfx::PointF(10, 10);
3275 bounds = IntSize(50, 50); 3275 bounds = gfx::Size(50, 50);
3276 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatri x, anchor, position, bounds, false); 3276 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatri x, anchor, position, bounds, false);
3277 child1->setDrawsContent(true); 3277 child1->setDrawsContent(true);
3278 3278
3279 position = FloatPoint(50, 10); 3279 position = gfx::PointF(50, 10);
3280 bounds = IntSize(50, 50); 3280 bounds = gfx::Size(50, 50);
3281 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatri x, anchor, position, bounds, false); 3281 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatri x, anchor, position, bounds, false);
3282 child2->setDrawsContent(true); 3282 child2->setDrawsContent(true);
3283 3283
3284 // Remember that grandChild is positioned with respect to its parent (i. e. child1). 3284 // Remember that grandChild is positioned with respect to its parent (i. e. child1).
3285 // In screen space, the intended position is (10, 50), with size 100 x 5 0. 3285 // In screen space, the intended position is (10, 50), with size 100 x 5 0.
3286 position = FloatPoint(0, 40); 3286 position = gfx::PointF(0, 40);
3287 bounds = IntSize(100, 50); 3287 bounds = gfx::Size(100, 50);
3288 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identity Matrix, anchor, position, bounds, false); 3288 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identity Matrix, anchor, position, bounds, false);
3289 grandChild1->setDrawsContent(true); 3289 grandChild1->setDrawsContent(true);
3290 3290
3291 child1->addChild(grandChild1.Pass()); 3291 child1->addChild(grandChild1.Pass());
3292 root->addChild(child1.Pass()); 3292 root->addChild(child1.Pass());
3293 root->addChild(child2.Pass()); 3293 root->addChild(child2.Pass());
3294 } 3294 }
3295 3295
3296 LayerImpl* child1 = root->children()[0]; 3296 LayerImpl* child1 = root->children()[0];
3297 LayerImpl* child2 = root->children()[1]; 3297 LayerImpl* child2 = root->children()[1];
3298 LayerImpl* grandChild1 = child1->children()[0]; 3298 LayerImpl* grandChild1 = child1->children()[0];
3299 3299
3300 std::vector<LayerImpl*> renderSurfaceLayerList; 3300 std::vector<LayerImpl*> renderSurfaceLayerList;
3301 int dummyMaxTextureSize = 512; 3301 int dummyMaxTextureSize = 512;
3302 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 3302 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
3303 3303
3304 // Sanity check the scenario we just created. 3304 // Sanity check the scenario we just created.
3305 ASSERT_TRUE(child1); 3305 ASSERT_TRUE(child1);
3306 ASSERT_TRUE(child2); 3306 ASSERT_TRUE(child2);
3307 ASSERT_TRUE(grandChild1); 3307 ASSERT_TRUE(grandChild1);
3308 ASSERT_EQ(1u, renderSurfaceLayerList.size()); 3308 ASSERT_EQ(1u, renderSurfaceLayerList.size());
3309 ASSERT_EQ(4u, root->renderSurface()->layerList().size()); 3309 ASSERT_EQ(4u, root->renderSurface()->layerList().size());
3310 ASSERT_EQ(1, root->renderSurface()->layerList()[0]->id()); // root layer 3310 ASSERT_EQ(1, root->renderSurface()->layerList()[0]->id()); // root layer
3311 ASSERT_EQ(2, root->renderSurface()->layerList()[1]->id()); // child1 3311 ASSERT_EQ(2, root->renderSurface()->layerList()[1]->id()); // child1
3312 ASSERT_EQ(4, root->renderSurface()->layerList()[2]->id()); // grandChild1 3312 ASSERT_EQ(4, root->renderSurface()->layerList()[2]->id()); // grandChild1
3313 ASSERT_EQ(3, root->renderSurface()->layerList()[3]->id()); // child2 3313 ASSERT_EQ(3, root->renderSurface()->layerList()[3]->id()); // child2
3314 3314
3315 // Nothing overlaps the rootLayer at (1, 1), so hit testing there should fin d the root layer. 3315 // Nothing overlaps the rootLayer at (1, 1), so hit testing there should fin d the root layer.
3316 IntPoint testPoint = IntPoint(1, 1); 3316 gfx::Point testPoint = gfx::Point(1, 1);
3317 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 3317 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
3318 ASSERT_TRUE(resultLayer); 3318 ASSERT_TRUE(resultLayer);
3319 EXPECT_EQ(1, resultLayer->id()); 3319 EXPECT_EQ(1, resultLayer->id());
3320 3320
3321 // At (15, 15), child1 and root are the only layers. child1 is expected to b e on top. 3321 // At (15, 15), child1 and root are the only layers. child1 is expected to b e on top.
3322 testPoint = IntPoint(15, 15); 3322 testPoint = gfx::Point(15, 15);
3323 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3323 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3324 ASSERT_TRUE(resultLayer); 3324 ASSERT_TRUE(resultLayer);
3325 EXPECT_EQ(2, resultLayer->id()); 3325 EXPECT_EQ(2, resultLayer->id());
3326 3326
3327 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top. 3327 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
3328 testPoint = IntPoint(51, 20); 3328 testPoint = gfx::Point(51, 20);
3329 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3329 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3330 ASSERT_TRUE(resultLayer); 3330 ASSERT_TRUE(resultLayer);
3331 EXPECT_EQ(3, resultLayer->id()); 3331 EXPECT_EQ(3, resultLayer->id());
3332 3332
3333 // At (80, 51), child2 and grandChild1 overlap. child2 is expected to be on top. 3333 // At (80, 51), child2 and grandChild1 overlap. child2 is expected to be on top.
3334 testPoint = IntPoint(80, 51); 3334 testPoint = gfx::Point(80, 51);
3335 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3335 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3336 ASSERT_TRUE(resultLayer); 3336 ASSERT_TRUE(resultLayer);
3337 EXPECT_EQ(3, resultLayer->id()); 3337 EXPECT_EQ(3, resultLayer->id());
3338 3338
3339 // At (51, 51), all layers overlap each other. child2 is expected to be on t op of all other layers. 3339 // At (51, 51), all layers overlap each other. child2 is expected to be on t op of all other layers.
3340 testPoint = IntPoint(51, 51); 3340 testPoint = gfx::Point(51, 51);
3341 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3341 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3342 ASSERT_TRUE(resultLayer); 3342 ASSERT_TRUE(resultLayer);
3343 EXPECT_EQ(3, resultLayer->id()); 3343 EXPECT_EQ(3, resultLayer->id());
3344 3344
3345 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b e on top. 3345 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b e on top.
3346 testPoint = IntPoint(20, 51); 3346 testPoint = gfx::Point(20, 51);
3347 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3347 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3348 ASSERT_TRUE(resultLayer); 3348 ASSERT_TRUE(resultLayer);
3349 EXPECT_EQ(4, resultLayer->id()); 3349 EXPECT_EQ(4, resultLayer->id());
3350 } 3350 }
3351 3351
3352 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists) 3352 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists)
3353 { 3353 {
3354 // 3354 //
3355 // The geometry is set up similarly to the previous case, but 3355 // The geometry is set up similarly to the previous case, but
3356 // all layers are forced to be renderSurfaces now. 3356 // all layers are forced to be renderSurfaces now.
3357 // 3357 //
3358 DebugScopedSetImplThread thisScopeIsOnImplThread; 3358 DebugScopedSetImplThread thisScopeIsOnImplThread;
3359 3359
3360 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 3360 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
3361 3361
3362 WebTransformationMatrix identityMatrix; 3362 WebTransformationMatrix identityMatrix;
3363 FloatPoint anchor(0, 0); 3363 gfx::PointF anchor(0, 0);
3364 FloatPoint position(0, 0); 3364 gfx::PointF position(0, 0);
3365 IntSize bounds(100, 100); 3365 gfx::Size bounds(100, 100);
3366 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false); 3366 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, position, bounds, false);
3367 root->setDrawsContent(true); 3367 root->setDrawsContent(true);
3368 3368
3369 { 3369 {
3370 // child 1 and child2 are initialized to overlap between x=50 and x=60. 3370 // child 1 and child2 are initialized to overlap between x=50 and x=60.
3371 // grandChild is set to overlap both child1 and child2 between y=50 and y=60. 3371 // grandChild is set to overlap both child1 and child2 between y=50 and y=60.
3372 // The expected stacking order is: 3372 // The expected stacking order is:
3373 // (front) child2, (second) grandChild, (third) child1, and (back) the root layer behind all other layers. 3373 // (front) child2, (second) grandChild, (third) child1, and (back) the root layer behind all other layers.
3374 3374
3375 scoped_ptr<LayerImpl> child1 = LayerImpl::create(2); 3375 scoped_ptr<LayerImpl> child1 = LayerImpl::create(2);
3376 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); 3376 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3);
3377 scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(4); 3377 scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(4);
3378 3378
3379 position = FloatPoint(10, 10); 3379 position = gfx::PointF(10, 10);
3380 bounds = IntSize(50, 50); 3380 bounds = gfx::Size(50, 50);
3381 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatri x, anchor, position, bounds, false); 3381 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatri x, anchor, position, bounds, false);
3382 child1->setDrawsContent(true); 3382 child1->setDrawsContent(true);
3383 child1->setForceRenderSurface(true); 3383 child1->setForceRenderSurface(true);
3384 3384
3385 position = FloatPoint(50, 10); 3385 position = gfx::PointF(50, 10);
3386 bounds = IntSize(50, 50); 3386 bounds = gfx::Size(50, 50);
3387 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatri x, anchor, position, bounds, false); 3387 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatri x, anchor, position, bounds, false);
3388 child2->setDrawsContent(true); 3388 child2->setDrawsContent(true);
3389 child2->setForceRenderSurface(true); 3389 child2->setForceRenderSurface(true);
3390 3390
3391 // Remember that grandChild is positioned with respect to its parent (i. e. child1). 3391 // Remember that grandChild is positioned with respect to its parent (i. e. child1).
3392 // In screen space, the intended position is (10, 50), with size 100 x 5 0. 3392 // In screen space, the intended position is (10, 50), with size 100 x 5 0.
3393 position = FloatPoint(0, 40); 3393 position = gfx::PointF(0, 40);
3394 bounds = IntSize(100, 50); 3394 bounds = gfx::Size(100, 50);
3395 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identity Matrix, anchor, position, bounds, false); 3395 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identity Matrix, anchor, position, bounds, false);
3396 grandChild1->setDrawsContent(true); 3396 grandChild1->setDrawsContent(true);
3397 grandChild1->setForceRenderSurface(true); 3397 grandChild1->setForceRenderSurface(true);
3398 3398
3399 child1->addChild(grandChild1.Pass()); 3399 child1->addChild(grandChild1.Pass());
3400 root->addChild(child1.Pass()); 3400 root->addChild(child1.Pass());
3401 root->addChild(child2.Pass()); 3401 root->addChild(child2.Pass());
3402 } 3402 }
3403 3403
3404 LayerImpl* child1 = root->children()[0]; 3404 LayerImpl* child1 = root->children()[0];
(...skipping 15 matching lines...) Expand all
3420 ASSERT_EQ(3u, root->renderSurface()->layerList().size()); // The root surfac e has the root layer, and child1's and child2's renderSurfaces. 3420 ASSERT_EQ(3u, root->renderSurface()->layerList().size()); // The root surfac e has the root layer, and child1's and child2's renderSurfaces.
3421 ASSERT_EQ(2u, child1->renderSurface()->layerList().size()); // The child1 su rface has the child1 layer and grandChild1's renderSurface. 3421 ASSERT_EQ(2u, child1->renderSurface()->layerList().size()); // The child1 su rface has the child1 layer and grandChild1's renderSurface.
3422 ASSERT_EQ(1u, child2->renderSurface()->layerList().size()); 3422 ASSERT_EQ(1u, child2->renderSurface()->layerList().size());
3423 ASSERT_EQ(1u, grandChild1->renderSurface()->layerList().size()); 3423 ASSERT_EQ(1u, grandChild1->renderSurface()->layerList().size());
3424 ASSERT_EQ(1, renderSurfaceLayerList[0]->id()); // root layer 3424 ASSERT_EQ(1, renderSurfaceLayerList[0]->id()); // root layer
3425 ASSERT_EQ(2, renderSurfaceLayerList[1]->id()); // child1 3425 ASSERT_EQ(2, renderSurfaceLayerList[1]->id()); // child1
3426 ASSERT_EQ(4, renderSurfaceLayerList[2]->id()); // grandChild1 3426 ASSERT_EQ(4, renderSurfaceLayerList[2]->id()); // grandChild1
3427 ASSERT_EQ(3, renderSurfaceLayerList[3]->id()); // child2 3427 ASSERT_EQ(3, renderSurfaceLayerList[3]->id()); // child2
3428 3428
3429 // Nothing overlaps the rootLayer at (1, 1), so hit testing there should fin d the root layer. 3429 // Nothing overlaps the rootLayer at (1, 1), so hit testing there should fin d the root layer.
3430 IntPoint testPoint = IntPoint(1, 1); 3430 gfx::Point testPoint = gfx::Point(1, 1);
3431 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList); 3431 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test Point, renderSurfaceLayerList);
3432 ASSERT_TRUE(resultLayer); 3432 ASSERT_TRUE(resultLayer);
3433 EXPECT_EQ(1, resultLayer->id()); 3433 EXPECT_EQ(1, resultLayer->id());
3434 3434
3435 // At (15, 15), child1 and root are the only layers. child1 is expected to b e on top. 3435 // At (15, 15), child1 and root are the only layers. child1 is expected to b e on top.
3436 testPoint = IntPoint(15, 15); 3436 testPoint = gfx::Point(15, 15);
3437 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3437 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3438 ASSERT_TRUE(resultLayer); 3438 ASSERT_TRUE(resultLayer);
3439 EXPECT_EQ(2, resultLayer->id()); 3439 EXPECT_EQ(2, resultLayer->id());
3440 3440
3441 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top. 3441 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
3442 testPoint = IntPoint(51, 20); 3442 testPoint = gfx::Point(51, 20);
3443 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3443 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3444 ASSERT_TRUE(resultLayer); 3444 ASSERT_TRUE(resultLayer);
3445 EXPECT_EQ(3, resultLayer->id()); 3445 EXPECT_EQ(3, resultLayer->id());
3446 3446
3447 // At (80, 51), child2 and grandChild1 overlap. child2 is expected to be on top. 3447 // At (80, 51), child2 and grandChild1 overlap. child2 is expected to be on top.
3448 testPoint = IntPoint(80, 51); 3448 testPoint = gfx::Point(80, 51);
3449 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3449 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3450 ASSERT_TRUE(resultLayer); 3450 ASSERT_TRUE(resultLayer);
3451 EXPECT_EQ(3, resultLayer->id()); 3451 EXPECT_EQ(3, resultLayer->id());
3452 3452
3453 // At (51, 51), all layers overlap each other. child2 is expected to be on t op of all other layers. 3453 // At (51, 51), all layers overlap each other. child2 is expected to be on t op of all other layers.
3454 testPoint = IntPoint(51, 51); 3454 testPoint = gfx::Point(51, 51);
3455 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3455 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3456 ASSERT_TRUE(resultLayer); 3456 ASSERT_TRUE(resultLayer);
3457 EXPECT_EQ(3, resultLayer->id()); 3457 EXPECT_EQ(3, resultLayer->id());
3458 3458
3459 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b e on top. 3459 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b e on top.
3460 testPoint = IntPoint(20, 51); 3460 testPoint = gfx::Point(20, 51);
3461 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3461 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3462 ASSERT_TRUE(resultLayer); 3462 ASSERT_TRUE(resultLayer);
3463 EXPECT_EQ(4, resultLayer->id()); 3463 EXPECT_EQ(4, resultLayer->id());
3464 } 3464 }
3465 3465
3466 class NoScaleContentLayer : public ContentLayer 3466 class NoScaleContentLayer : public ContentLayer
3467 { 3467 {
3468 public: 3468 public:
3469 static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client) { return make_scoped_refptr(new NoScaleContentLayer(client)); } 3469 static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client) { return make_scoped_refptr(new NoScaleContentLayer(client)); }
3470 3470
3471 virtual IntSize contentBounds() const OVERRIDE { return bounds(); } 3471 virtual gfx::Size contentBounds() const OVERRIDE { return bounds(); }
3472 virtual float contentsScaleX() const OVERRIDE { return 1.0; } 3472 virtual float contentsScaleX() const OVERRIDE { return 1.0; }
3473 virtual float contentsScaleY() const OVERRIDE { return 1.0; } 3473 virtual float contentsScaleY() const OVERRIDE { return 1.0; }
3474 3474
3475 protected: 3475 protected:
3476 explicit NoScaleContentLayer(ContentLayerClient* client) : ContentLayer(clie nt) { } 3476 explicit NoScaleContentLayer(ContentLayerClient* client) : ContentLayer(clie nt) { }
3477 virtual ~NoScaleContentLayer() { } 3477 virtual ~NoScaleContentLayer() { }
3478 }; 3478 };
3479 3479
3480 scoped_refptr<NoScaleContentLayer> createNoScaleDrawableContentLayer(ContentLaye rClient* delegate) 3480 scoped_refptr<NoScaleContentLayer> createNoScaleDrawableContentLayer(ContentLaye rClient* delegate)
3481 { 3481 {
3482 scoped_refptr<NoScaleContentLayer> toReturn = NoScaleContentLayer::create(de legate); 3482 scoped_refptr<NoScaleContentLayer> toReturn = NoScaleContentLayer::create(de legate);
3483 toReturn->setIsDrawable(true); 3483 toReturn->setIsDrawable(true);
3484 return toReturn; 3484 return toReturn;
3485 } 3485 }
3486 3486
3487 TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPI) 3487 TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPI)
3488 { 3488 {
3489 // Verify draw and screen space transforms of layers not in a surface. 3489 // Verify draw and screen space transforms of layers not in a surface.
3490 MockContentLayerClient delegate; 3490 MockContentLayerClient delegate;
3491 WebTransformationMatrix identityMatrix; 3491 WebTransformationMatrix identityMatrix;
3492 3492
3493 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 3493 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
3494 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); 3494 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true);
3495 3495
3496 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate); 3496 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate);
3497 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true); 3497 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
3498 3498
3499 scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableConte ntLayer(&delegate); 3499 scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableConte ntLayer(&delegate);
3500 setLayerPropertiesForTesting(childNoScale.get(), identityMatrix, identityMat rix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true); 3500 setLayerPropertiesForTesting(childNoScale.get(), identityMatrix, identityMat rix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
3501 3501
3502 parent->addChild(child); 3502 parent->addChild(child);
3503 parent->addChild(childNoScale); 3503 parent->addChild(childNoScale);
3504 3504
3505 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 3505 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
3506 int dummyMaxTextureSize = 512; 3506 int dummyMaxTextureSize = 512;
3507 3507
3508 const double deviceScaleFactor = 2.5; 3508 const double deviceScaleFactor = 2.5;
3509 const double pageScaleFactor = 1; 3509 const double pageScaleFactor = 1;
3510 3510
3511 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 3511 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
3512 3512
3513 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, parent); 3513 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, parent);
3514 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, child); 3514 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, child);
3515 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); 3515 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale);
3516 3516
3517 EXPECT_EQ(1u, renderSurfaceLayerList.size()); 3517 EXPECT_EQ(1u, renderSurfaceLayerList.size());
3518 3518
3519 // Verify parent transforms 3519 // Verify parent transforms
3520 WebTransformationMatrix expectedParentTransform; 3520 WebTransformationMatrix expectedParentTransform;
3521 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform()); 3521 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform());
3522 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm()); 3522 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm());
3523 3523
3524 // Verify results of transformed parent rects 3524 // Verify results of transformed parent rects
3525 FloatRect parentContentBounds(FloatPoint(), FloatSize(parent->contentBounds( ))); 3525 gfx::RectF parentContentBounds(gfx::PointF(), gfx::SizeF(parent->contentBoun ds()));
3526 3526
3527 FloatRect parentDrawRect = MathUtil::mapClippedRect(parent->drawTransform(), parentContentBounds); 3527 gfx::RectF parentDrawRect = MathUtil::mapClippedRect(parent->drawTransform() , parentContentBounds);
3528 FloatRect parentScreenSpaceRect = MathUtil::mapClippedRect(parent->screenSpa ceTransform(), parentContentBounds); 3528 gfx::RectF parentScreenSpaceRect = MathUtil::mapClippedRect(parent->screenSp aceTransform(), parentContentBounds);
3529 3529
3530 FloatRect expectedParentDrawRect(FloatPoint(), parent->bounds()); 3530 gfx::RectF expectedParentDrawRect(gfx::PointF(), parent->bounds());
3531 expectedParentDrawRect.scale(deviceScaleFactor); 3531 expectedParentDrawRect.Scale(deviceScaleFactor);
3532 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentDrawRect); 3532 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentDrawRect);
3533 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentScreenSpaceRect); 3533 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentScreenSpaceRect);
3534 3534
3535 // Verify child transforms 3535 // Verify child transforms
3536 WebTransformationMatrix expectedChildTransform; 3536 WebTransformationMatrix expectedChildTransform;
3537 expectedChildTransform.translate(deviceScaleFactor * child->position().x(), deviceScaleFactor * child->position().y()); 3537 expectedChildTransform.translate(deviceScaleFactor * child->position().x(), deviceScaleFactor * child->position().y());
3538 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 3538 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
3539 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->screenSpaceTr ansform()); 3539 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->screenSpaceTr ansform());
3540 3540
3541 // Verify results of transformed child rects 3541 // Verify results of transformed child rects
3542 FloatRect childContentBounds(FloatPoint(), FloatSize(child->contentBounds()) ); 3542 gfx::RectF childContentBounds(gfx::PointF(), gfx::SizeF(child->contentBounds ()));
3543 3543
3544 FloatRect childDrawRect = MathUtil::mapClippedRect(child->drawTransform(), c hildContentBounds); 3544 gfx::RectF childDrawRect = MathUtil::mapClippedRect(child->drawTransform(), childContentBounds);
3545 FloatRect childScreenSpaceRect = MathUtil::mapClippedRect(child->screenSpace Transform(), childContentBounds); 3545 gfx::RectF childScreenSpaceRect = MathUtil::mapClippedRect(child->screenSpac eTransform(), childContentBounds);
3546 3546
3547 FloatRect expectedChildDrawRect(FloatPoint(), child->bounds()); 3547 gfx::RectF expectedChildDrawRect(gfx::PointF(), child->bounds());
3548 expectedChildDrawRect.move(child->position().x(), child->position().y()); 3548 expectedChildDrawRect.Offset(child->position().x(), child->position().y());
3549 expectedChildDrawRect.scale(deviceScaleFactor); 3549 expectedChildDrawRect.Scale(deviceScaleFactor);
3550 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childDrawRect); 3550 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childDrawRect);
3551 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childScreenSpaceRect); 3551 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childScreenSpaceRect);
3552 3552
3553 // Verify childNoScale transforms 3553 // Verify childNoScale transforms
3554 WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform (); 3554 WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform ();
3555 // All transforms operate on content rects. The child's content rect 3555 // All transforms operate on content rects. The child's content rect
3556 // incorporates device scale, but the childNoScale does not; add it here. 3556 // incorporates device scale, but the childNoScale does not; add it here.
3557 expectedChildNoScaleTransform.scale(deviceScaleFactor); 3557 expectedChildNoScaleTransform.scale(deviceScaleFactor);
3558 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >drawTransform()); 3558 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >drawTransform());
3559 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >screenSpaceTransform()); 3559 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >screenSpaceTransform());
3560 } 3560 }
3561 3561
3562 TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPIAccurateScaleZeroChi ldPosition) 3562 TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPIAccurateScaleZeroChi ldPosition)
3563 { 3563 {
3564 // Verify draw and screen space transforms of layers not in a surface. 3564 // Verify draw and screen space transforms of layers not in a surface.
3565 MockContentLayerClient delegate; 3565 MockContentLayerClient delegate;
3566 WebTransformationMatrix identityMatrix; 3566 WebTransformationMatrix identityMatrix;
3567 3567
3568 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 3568 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
3569 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(133, 133), true); 3569 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(133, 133), true);
3570 3570
3571 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate); 3571 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate);
3572 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(13, 13), true); 3572 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 13), true);
3573 3573
3574 scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableConte ntLayer(&delegate); 3574 scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableConte ntLayer(&delegate);
3575 setLayerPropertiesForTesting(childNoScale.get(), identityMatrix, identityMat rix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(13, 13), true); 3575 setLayerPropertiesForTesting(childNoScale.get(), identityMatrix, identityMat rix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 13), true);
3576 3576
3577 parent->addChild(child); 3577 parent->addChild(child);
3578 parent->addChild(childNoScale); 3578 parent->addChild(childNoScale);
3579 3579
3580 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 3580 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
3581 int dummyMaxTextureSize = 512; 3581 int dummyMaxTextureSize = 512;
3582 3582
3583 const float deviceScaleFactor = 1.7f; 3583 const float deviceScaleFactor = 1.7f;
3584 const float pageScaleFactor = 1; 3584 const float pageScaleFactor = 1;
3585 3585
3586 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 3586 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
3587 3587
3588 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, parent); 3588 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, parent);
3589 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, child); 3589 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, child);
3590 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); 3590 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale);
3591 3591
3592 EXPECT_EQ(1u, renderSurfaceLayerList.size()); 3592 EXPECT_EQ(1u, renderSurfaceLayerList.size());
3593 3593
3594 // Verify parent transforms 3594 // Verify parent transforms
3595 WebTransformationMatrix expectedParentTransform; 3595 WebTransformationMatrix expectedParentTransform;
3596 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform()); 3596 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform());
3597 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm()); 3597 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm());
3598 3598
3599 // Verify results of transformed parent rects 3599 // Verify results of transformed parent rects
3600 FloatRect parentContentBounds(FloatPoint(), FloatSize(parent->contentBounds( ))); 3600 gfx::RectF parentContentBounds(gfx::PointF(), gfx::SizeF(parent->contentBoun ds()));
3601 3601
3602 FloatRect parentDrawRect = MathUtil::mapClippedRect(parent->drawTransform(), parentContentBounds); 3602 gfx::RectF parentDrawRect = MathUtil::mapClippedRect(parent->drawTransform() , parentContentBounds);
3603 FloatRect parentScreenSpaceRect = MathUtil::mapClippedRect(parent->screenSpa ceTransform(), parentContentBounds); 3603 gfx::RectF parentScreenSpaceRect = MathUtil::mapClippedRect(parent->screenSp aceTransform(), parentContentBounds);
3604 3604
3605 FloatRect expectedParentDrawRect(FloatPoint(), parent->bounds()); 3605 gfx::RectF expectedParentDrawRect(gfx::PointF(), parent->bounds());
3606 expectedParentDrawRect.scale(deviceScaleFactor); 3606 expectedParentDrawRect.Scale(deviceScaleFactor);
3607 expectedParentDrawRect.setWidth(ceil(expectedParentDrawRect.width())); 3607 expectedParentDrawRect.set_width(ceil(expectedParentDrawRect.width()));
3608 expectedParentDrawRect.setHeight(ceil(expectedParentDrawRect.height())); 3608 expectedParentDrawRect.set_height(ceil(expectedParentDrawRect.height()));
3609 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentDrawRect); 3609 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentDrawRect);
3610 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentScreenSpaceRect); 3610 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentScreenSpaceRect);
3611 3611
3612 // Verify child transforms 3612 // Verify child transforms
3613 WebTransformationMatrix expectedChildTransform; 3613 WebTransformationMatrix expectedChildTransform;
3614 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ()); 3614 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
3615 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->screenSpaceTr ansform()); 3615 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->screenSpaceTr ansform());
3616 3616
3617 // Verify results of transformed child rects 3617 // Verify results of transformed child rects
3618 FloatRect childContentBounds(FloatPoint(), FloatSize(child->contentBounds()) ); 3618 gfx::RectF childContentBounds(gfx::PointF(), gfx::SizeF(child->contentBounds ()));
3619 3619
3620 FloatRect childDrawRect = MathUtil::mapClippedRect(child->drawTransform(), c hildContentBounds); 3620 gfx::RectF childDrawRect = MathUtil::mapClippedRect(child->drawTransform(), childContentBounds);
3621 FloatRect childScreenSpaceRect = MathUtil::mapClippedRect(child->screenSpace Transform(), childContentBounds); 3621 gfx::RectF childScreenSpaceRect = MathUtil::mapClippedRect(child->screenSpac eTransform(), childContentBounds);
3622 3622
3623 FloatRect expectedChildDrawRect(FloatPoint(), child->bounds()); 3623 gfx::RectF expectedChildDrawRect(gfx::PointF(), child->bounds());
3624 expectedChildDrawRect.scale(deviceScaleFactor); 3624 expectedChildDrawRect.Scale(deviceScaleFactor);
3625 expectedChildDrawRect.setWidth(ceil(expectedChildDrawRect.width())); 3625 expectedChildDrawRect.set_width(ceil(expectedChildDrawRect.width()));
3626 expectedChildDrawRect.setHeight(ceil(expectedChildDrawRect.height())); 3626 expectedChildDrawRect.set_height(ceil(expectedChildDrawRect.height()));
3627 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childDrawRect); 3627 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childDrawRect);
3628 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childScreenSpaceRect); 3628 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childScreenSpaceRect);
3629 3629
3630 // Verify childNoScale transforms 3630 // Verify childNoScale transforms
3631 WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform (); 3631 WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform ();
3632 // All transforms operate on content rects. The child's content rect 3632 // All transforms operate on content rects. The child's content rect
3633 // incorporates device scale, but the childNoScale does not; add it here. 3633 // incorporates device scale, but the childNoScale does not; add it here.
3634 expectedChildNoScaleTransform.scale(deviceScaleFactor); 3634 expectedChildNoScaleTransform.scale(deviceScaleFactor);
3635 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >drawTransform()); 3635 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >drawTransform());
3636 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >screenSpaceTransform()); 3636 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >screenSpaceTransform());
3637 } 3637 }
3638 3638
3639 TEST(LayerTreeHostCommonTest, verifyContentsScale) 3639 TEST(LayerTreeHostCommonTest, verifyContentsScale)
3640 { 3640 {
3641 MockContentLayerClient delegate; 3641 MockContentLayerClient delegate;
3642 WebTransformationMatrix identityMatrix; 3642 WebTransformationMatrix identityMatrix;
3643 3643
3644 WebTransformationMatrix parentScaleMatrix; 3644 WebTransformationMatrix parentScaleMatrix;
3645 const double initialParentScale = 1.75; 3645 const double initialParentScale = 1.75;
3646 parentScaleMatrix.scale(initialParentScale); 3646 parentScaleMatrix.scale(initialParentScale);
3647 3647
3648 WebTransformationMatrix childScaleMatrix; 3648 WebTransformationMatrix childScaleMatrix;
3649 const double initialChildScale = 1.25; 3649 const double initialChildScale = 1.25;
3650 childScaleMatrix.scale(initialChildScale); 3650 childScaleMatrix.scale(initialChildScale);
3651 3651
3652 float fixedRasterScale = 2.5; 3652 float fixedRasterScale = 2.5;
3653 3653
3654 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 3654 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
3655 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); 3655 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true);
3656 3656
3657 scoped_refptr<ContentLayer> childScale = createDrawableContentLayer(&delegat e); 3657 scoped_refptr<ContentLayer> childScale = createDrawableContentLayer(&delegat e);
3658 setLayerPropertiesForTesting(childScale.get(), childScaleMatrix, identityMat rix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true); 3658 setLayerPropertiesForTesting(childScale.get(), childScaleMatrix, identityMat rix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
3659 3659
3660 scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableConte ntLayer(&delegate); 3660 scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableConte ntLayer(&delegate);
3661 setLayerPropertiesForTesting(childNoScale.get(), childScaleMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(12, 12), IntSize(10, 10), true); 3661 setLayerPropertiesForTesting(childNoScale.get(), childScaleMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(12, 12), gfx::Size(10, 10), true);
3662 3662
3663 scoped_refptr<ContentLayer> childNoAutoScale = createDrawableContentLayer(&d elegate); 3663 scoped_refptr<ContentLayer> childNoAutoScale = createDrawableContentLayer(&d elegate);
3664 setLayerPropertiesForTesting(childNoAutoScale.get(), childScaleMatrix, ident ityMatrix, FloatPoint(0, 0), FloatPoint(22, 22), IntSize(10, 10), true); 3664 setLayerPropertiesForTesting(childNoAutoScale.get(), childScaleMatrix, ident ityMatrix, gfx::PointF(0, 0), gfx::PointF(22, 22), gfx::Size(10, 10), true);
3665 childNoAutoScale->setAutomaticallyComputeRasterScale(false); 3665 childNoAutoScale->setAutomaticallyComputeRasterScale(false);
3666 childNoAutoScale->setRasterScale(fixedRasterScale); 3666 childNoAutoScale->setRasterScale(fixedRasterScale);
3667 3667
3668 // FIXME: Remove this when pageScaleFactor is applied in the compositor. 3668 // FIXME: Remove this when pageScaleFactor is applied in the compositor.
3669 // Page scale should not apply to the parent. 3669 // Page scale should not apply to the parent.
3670 parent->setBoundsContainPageScale(true); 3670 parent->setBoundsContainPageScale(true);
3671 3671
3672 parent->addChild(childScale); 3672 parent->addChild(childScale);
3673 parent->addChild(childNoScale); 3673 parent->addChild(childNoScale);
3674 parent->addChild(childNoAutoScale); 3674 parent->addChild(childNoAutoScale);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3740 const double initialParentScale = 2; 3740 const double initialParentScale = 2;
3741 parentScaleMatrix.scale(initialParentScale); 3741 parentScaleMatrix.scale(initialParentScale);
3742 3742
3743 WebTransformationMatrix childScaleMatrix; 3743 WebTransformationMatrix childScaleMatrix;
3744 const double initialChildScale = 3; 3744 const double initialChildScale = 3;
3745 childScaleMatrix.scale(initialChildScale); 3745 childScaleMatrix.scale(initialChildScale);
3746 3746
3747 float fixedRasterScale = 4; 3747 float fixedRasterScale = 4;
3748 3748
3749 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 3749 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
3750 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); 3750 setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), true);
3751 3751
3752 scoped_refptr<ContentLayer> surfaceScale = createDrawableContentLayer(&deleg ate); 3752 scoped_refptr<ContentLayer> surfaceScale = createDrawableContentLayer(&deleg ate);
3753 setLayerPropertiesForTesting(surfaceScale.get(), childScaleMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true); 3753 setLayerPropertiesForTesting(surfaceScale.get(), childScaleMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
3754 3754
3755 scoped_refptr<ContentLayer> surfaceScaleChildScale = createDrawableContentLa yer(&delegate); 3755 scoped_refptr<ContentLayer> surfaceScaleChildScale = createDrawableContentLa yer(&delegate);
3756 setLayerPropertiesForTesting(surfaceScaleChildScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true); 3756 setLayerPropertiesForTesting(surfaceScaleChildScale.get(), childScaleMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), true);
3757 3757
3758 scoped_refptr<NoScaleContentLayer> surfaceScaleChildNoScale = createNoScaleD rawableContentLayer(&delegate); 3758 scoped_refptr<NoScaleContentLayer> surfaceScaleChildNoScale = createNoScaleD rawableContentLayer(&delegate);
3759 setLayerPropertiesForTesting(surfaceScaleChildNoScale.get(), childScaleMatri x, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true); 3759 setLayerPropertiesForTesting(surfaceScaleChildNoScale.get(), childScaleMatri x, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), true );
3760 3760
3761 scoped_refptr<NoScaleContentLayer> surfaceNoScale = createNoScaleDrawableCon tentLayer(&delegate); 3761 scoped_refptr<NoScaleContentLayer> surfaceNoScale = createNoScaleDrawableCon tentLayer(&delegate);
3762 setLayerPropertiesForTesting(surfaceNoScale.get(), childScaleMatrix, identit yMatrix, FloatPoint(0, 0), FloatPoint(12, 12), IntSize(10, 10), true); 3762 setLayerPropertiesForTesting(surfaceNoScale.get(), childScaleMatrix, identit yMatrix, gfx::PointF(0, 0), gfx::PointF(12, 12), gfx::Size(10, 10), true);
3763 3763
3764 scoped_refptr<ContentLayer> surfaceNoScaleChildScale = createDrawableContent Layer(&delegate); 3764 scoped_refptr<ContentLayer> surfaceNoScaleChildScale = createDrawableContent Layer(&delegate);
3765 setLayerPropertiesForTesting(surfaceNoScaleChildScale.get(), childScaleMatri x, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true); 3765 setLayerPropertiesForTesting(surfaceNoScaleChildScale.get(), childScaleMatri x, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), true );
3766 3766
3767 scoped_refptr<NoScaleContentLayer> surfaceNoScaleChildNoScale = createNoScal eDrawableContentLayer(&delegate); 3767 scoped_refptr<NoScaleContentLayer> surfaceNoScaleChildNoScale = createNoScal eDrawableContentLayer(&delegate);
3768 setLayerPropertiesForTesting(surfaceNoScaleChildNoScale.get(), childScaleMat rix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true); 3768 setLayerPropertiesForTesting(surfaceNoScaleChildNoScale.get(), childScaleMat rix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), tr ue);
3769 3769
3770 scoped_refptr<ContentLayer> surfaceNoAutoScale = createDrawableContentLayer( &delegate); 3770 scoped_refptr<ContentLayer> surfaceNoAutoScale = createDrawableContentLayer( &delegate);
3771 setLayerPropertiesForTesting(surfaceNoAutoScale.get(), childScaleMatrix, ide ntityMatrix, FloatPoint(0, 0), FloatPoint(22, 22), IntSize(10, 10), true); 3771 setLayerPropertiesForTesting(surfaceNoAutoScale.get(), childScaleMatrix, ide ntityMatrix, gfx::PointF(0, 0), gfx::PointF(22, 22), gfx::Size(10, 10), true);
3772 surfaceNoAutoScale->setAutomaticallyComputeRasterScale(false); 3772 surfaceNoAutoScale->setAutomaticallyComputeRasterScale(false);
3773 surfaceNoAutoScale->setRasterScale(fixedRasterScale); 3773 surfaceNoAutoScale->setRasterScale(fixedRasterScale);
3774 3774
3775 scoped_refptr<ContentLayer> surfaceNoAutoScaleChildScale = createDrawableCon tentLayer(&delegate); 3775 scoped_refptr<ContentLayer> surfaceNoAutoScaleChildScale = createDrawableCon tentLayer(&delegate);
3776 setLayerPropertiesForTesting(surfaceNoAutoScaleChildScale.get(), childScaleM atrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true ); 3776 setLayerPropertiesForTesting(surfaceNoAutoScaleChildScale.get(), childScaleM atrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), true);
3777 3777
3778 scoped_refptr<NoScaleContentLayer> surfaceNoAutoScaleChildNoScale = createNo ScaleDrawableContentLayer(&delegate); 3778 scoped_refptr<NoScaleContentLayer> surfaceNoAutoScaleChildNoScale = createNo ScaleDrawableContentLayer(&delegate);
3779 setLayerPropertiesForTesting(surfaceNoAutoScaleChildNoScale.get(), childScal eMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), tr ue); 3779 setLayerPropertiesForTesting(surfaceNoAutoScaleChildNoScale.get(), childScal eMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10) , true);
3780 3780
3781 // FIXME: Remove this when pageScaleFactor is applied in the compositor. 3781 // FIXME: Remove this when pageScaleFactor is applied in the compositor.
3782 // Page scale should not apply to the parent. 3782 // Page scale should not apply to the parent.
3783 parent->setBoundsContainPageScale(true); 3783 parent->setBoundsContainPageScale(true);
3784 3784
3785 parent->addChild(surfaceScale); 3785 parent->addChild(surfaceScale);
3786 parent->addChild(surfaceNoScale); 3786 parent->addChild(surfaceNoScale);
3787 parent->addChild(surfaceNoAutoScale); 3787 parent->addChild(surfaceNoAutoScale);
3788 3788
3789 surfaceScale->setForceRenderSurface(true); 3789 surfaceScale->setForceRenderSurface(true);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
3875 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoAutoScaleChildNoScale->drawTransf orm().m11()); 3875 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoAutoScaleChildNoScale->drawTransf orm().m11());
3876 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoAutoScaleChildNoScale->drawTransf orm().m22()); 3876 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale * initialChildScale, surfaceNoAutoScaleChildNoScale->drawTransf orm().m22());
3877 } 3877 }
3878 3878
3879 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPI) 3879 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPI)
3880 { 3880 {
3881 MockContentLayerClient delegate; 3881 MockContentLayerClient delegate;
3882 WebTransformationMatrix identityMatrix; 3882 WebTransformationMatrix identityMatrix;
3883 3883
3884 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 3884 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
3885 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(30, 30), true); 3885 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(30, 30), true);
3886 3886
3887 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate); 3887 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate);
3888 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true); 3888 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
3889 3889
3890 WebTransformationMatrix replicaTransform; 3890 WebTransformationMatrix replicaTransform;
3891 replicaTransform.scaleNonUniform(1, -1); 3891 replicaTransform.scaleNonUniform(1, -1);
3892 scoped_refptr<ContentLayer> replica = createDrawableContentLayer(&delegate); 3892 scoped_refptr<ContentLayer> replica = createDrawableContentLayer(&delegate);
3893 setLayerPropertiesForTesting(replica.get(), replicaTransform, identityMatrix , FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true); 3893 setLayerPropertiesForTesting(replica.get(), replicaTransform, identityMatrix , gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true);
3894 3894
3895 // This layer should end up in the same surface as child, with the same draw 3895 // This layer should end up in the same surface as child, with the same draw
3896 // and screen space transforms. 3896 // and screen space transforms.
3897 scoped_refptr<ContentLayer> duplicateChildNonOwner = createDrawableContentLa yer(&delegate); 3897 scoped_refptr<ContentLayer> duplicateChildNonOwner = createDrawableContentLa yer(&delegate);
3898 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i dentityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true); 3898 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i dentityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), true);
3899 3899
3900 parent->addChild(child); 3900 parent->addChild(child);
3901 child->addChild(duplicateChildNonOwner); 3901 child->addChild(duplicateChildNonOwner);
3902 child->setReplicaLayer(replica.get()); 3902 child->setReplicaLayer(replica.get());
3903 3903
3904 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 3904 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
3905 int dummyMaxTextureSize = 512; 3905 int dummyMaxTextureSize = 512;
3906 3906
3907 const double deviceScaleFactor = 1.5; 3907 const double deviceScaleFactor = 1.5;
3908 parent->setContentsScale(deviceScaleFactor); 3908 parent->setContentsScale(deviceScaleFactor);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3958 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child-> renderSurface()->replicaScreenSpaceTransform()); 3958 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child-> renderSurface()->replicaScreenSpaceTransform());
3959 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child-> renderSurface()->replicaScreenSpaceTransform()); 3959 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child-> renderSurface()->replicaScreenSpaceTransform());
3960 } 3960 }
3961 3961
3962 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPIAccurateScal eZeroPosition) 3962 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPIAccurateScal eZeroPosition)
3963 { 3963 {
3964 MockContentLayerClient delegate; 3964 MockContentLayerClient delegate;
3965 WebTransformationMatrix identityMatrix; 3965 WebTransformationMatrix identityMatrix;
3966 3966
3967 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); 3967 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
3968 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(33, 31), true); 3968 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(33, 31), true);
3969 3969
3970 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate); 3970 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate);
3971 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(13, 11), true); 3971 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gf x::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 11), true);
3972 3972
3973 WebTransformationMatrix replicaTransform; 3973 WebTransformationMatrix replicaTransform;
3974 replicaTransform.scaleNonUniform(1, -1); 3974 replicaTransform.scaleNonUniform(1, -1);
3975 scoped_refptr<ContentLayer> replica = createDrawableContentLayer(&delegate); 3975 scoped_refptr<ContentLayer> replica = createDrawableContentLayer(&delegate);
3976 setLayerPropertiesForTesting(replica.get(), replicaTransform, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(13, 11), true); 3976 setLayerPropertiesForTesting(replica.get(), replicaTransform, identityMatrix , gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 11), true);
3977 3977
3978 // This layer should end up in the same surface as child, with the same draw 3978 // This layer should end up in the same surface as child, with the same draw
3979 // and screen space transforms. 3979 // and screen space transforms.
3980 scoped_refptr<ContentLayer> duplicateChildNonOwner = createDrawableContentLa yer(&delegate); 3980 scoped_refptr<ContentLayer> duplicateChildNonOwner = createDrawableContentLa yer(&delegate);
3981 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i dentityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(13, 11), true); 3981 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i dentityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 11), true);
3982 3982
3983 parent->addChild(child); 3983 parent->addChild(child);
3984 child->addChild(duplicateChildNonOwner); 3984 child->addChild(duplicateChildNonOwner);
3985 child->setReplicaLayer(replica.get()); 3985 child->setReplicaLayer(replica.get());
3986 3986
3987 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 3987 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
3988 int dummyMaxTextureSize = 512; 3988 int dummyMaxTextureSize = 512;
3989 3989
3990 const float deviceScaleFactor = 1.7f; 3990 const float deviceScaleFactor = 1.7f;
3991 parent->setContentsScale(deviceScaleFactor); 3991 parent->setContentsScale(deviceScaleFactor);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
4039 int nonexistentId = -1; 4039 int nonexistentId = -1;
4040 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id ())); 4040 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id ()));
4041 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child-> id())); 4041 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child-> id()));
4042 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr andChild->id())); 4042 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr andChild->id()));
4043 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas kLayer->id())); 4043 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas kLayer->id()));
4044 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), replicaLayer->id())); 4044 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), replicaLayer->id()));
4045 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent Id)); 4045 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent Id));
4046 } 4046 }
4047 4047
4048 } // namespace 4048 } // namespace
OLDNEW
« no previous file with comments | « cc/layer_tree_host_common.cc ('k') | cc/layer_tree_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698