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

Side by Side Diff: cc/damage_tracker_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/damage_tracker.cc ('k') | cc/debug_rect_history.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/damage_tracker.h" 7 #include "cc/damage_tracker.h"
8 8
9 #include "cc/layer_impl.h" 9 #include "cc/layer_impl.h"
10 #include "cc/layer_sorter.h" 10 #include "cc/layer_sorter.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 65
66 root->resetAllChangeTrackingForSubtree(); 66 root->resetAllChangeTrackingForSubtree();
67 } 67 }
68 68
69 scoped_ptr<LayerImpl> createTestTreeWithOneSurface() 69 scoped_ptr<LayerImpl> createTestTreeWithOneSurface()
70 { 70 {
71 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 71 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
72 scoped_ptr<LayerImpl> child = LayerImpl::create(2); 72 scoped_ptr<LayerImpl> child = LayerImpl::create(2);
73 73
74 root->setPosition(FloatPoint::zero()); 74 root->setPosition(gfx::PointF());
75 root->setAnchorPoint(FloatPoint::zero()); 75 root->setAnchorPoint(gfx::PointF());
76 root->setBounds(IntSize(500, 500)); 76 root->setBounds(gfx::Size(500, 500));
77 root->setContentBounds(IntSize(500, 500)); 77 root->setContentBounds(gfx::Size(500, 500));
78 root->setDrawsContent(true); 78 root->setDrawsContent(true);
79 root->createRenderSurface(); 79 root->createRenderSurface();
80 root->renderSurface()->setContentRect(IntRect(IntPoint(), IntSize(500, 500)) ); 80 root->renderSurface()->setContentRect(gfx::Rect(gfx::Point(), gfx::Size(500, 500)));
81 81
82 child->setPosition(FloatPoint(100, 100)); 82 child->setPosition(gfx::PointF(100, 100));
83 child->setAnchorPoint(FloatPoint::zero()); 83 child->setAnchorPoint(gfx::PointF());
84 child->setBounds(IntSize(30, 30)); 84 child->setBounds(gfx::Size(30, 30));
85 child->setContentBounds(IntSize(30, 30)); 85 child->setContentBounds(gfx::Size(30, 30));
86 child->setDrawsContent(true); 86 child->setDrawsContent(true);
87 root->addChild(child.Pass()); 87 root->addChild(child.Pass());
88 88
89 return root.Pass(); 89 return root.Pass();
90 } 90 }
91 91
92 scoped_ptr<LayerImpl> createTestTreeWithTwoSurfaces() 92 scoped_ptr<LayerImpl> createTestTreeWithTwoSurfaces()
93 { 93 {
94 // This test tree has two render surfaces: one for the root, and one for 94 // This test tree has two render surfaces: one for the root, and one for
95 // child1. Additionally, the root has a second child layer, and child1 has t wo 95 // child1. Additionally, the root has a second child layer, and child1 has t wo
96 // children of its own. 96 // children of its own.
97 97
98 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 98 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
99 scoped_ptr<LayerImpl> child1 = LayerImpl::create(2); 99 scoped_ptr<LayerImpl> child1 = LayerImpl::create(2);
100 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); 100 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3);
101 scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(4); 101 scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(4);
102 scoped_ptr<LayerImpl> grandChild2 = LayerImpl::create(5); 102 scoped_ptr<LayerImpl> grandChild2 = LayerImpl::create(5);
103 103
104 root->setPosition(FloatPoint::zero()); 104 root->setPosition(gfx::PointF());
105 root->setAnchorPoint(FloatPoint::zero()); 105 root->setAnchorPoint(gfx::PointF());
106 root->setBounds(IntSize(500, 500)); 106 root->setBounds(gfx::Size(500, 500));
107 root->setContentBounds(IntSize(500, 500)); 107 root->setContentBounds(gfx::Size(500, 500));
108 root->setDrawsContent(true); 108 root->setDrawsContent(true);
109 root->createRenderSurface(); 109 root->createRenderSurface();
110 root->renderSurface()->setContentRect(IntRect(IntPoint(), IntSize(500, 500)) ); 110 root->renderSurface()->setContentRect(gfx::Rect(gfx::Point(), gfx::Size(500, 500)));
111 111
112 child1->setPosition(FloatPoint(100, 100)); 112 child1->setPosition(gfx::PointF(100, 100));
113 child1->setAnchorPoint(FloatPoint::zero()); 113 child1->setAnchorPoint(gfx::PointF());
114 child1->setBounds(IntSize(30, 30)); 114 child1->setBounds(gfx::Size(30, 30));
115 child1->setContentBounds(IntSize(30, 30)); 115 child1->setContentBounds(gfx::Size(30, 30));
116 child1->setOpacity(0.5); // with a child that drawsContent, this will cause the layer to create its own renderSurface. 116 child1->setOpacity(0.5); // with a child that drawsContent, this will cause the layer to create its own renderSurface.
117 child1->setDrawsContent(false); // this layer does not draw, but is intended to create its own renderSurface. 117 child1->setDrawsContent(false); // this layer does not draw, but is intended to create its own renderSurface.
118 118
119 child2->setPosition(FloatPoint(11, 11)); 119 child2->setPosition(gfx::PointF(11, 11));
120 child2->setAnchorPoint(FloatPoint::zero()); 120 child2->setAnchorPoint(gfx::PointF());
121 child2->setBounds(IntSize(18, 18)); 121 child2->setBounds(gfx::Size(18, 18));
122 child2->setContentBounds(IntSize(18, 18)); 122 child2->setContentBounds(gfx::Size(18, 18));
123 child2->setDrawsContent(true); 123 child2->setDrawsContent(true);
124 124
125 grandChild1->setPosition(FloatPoint(200, 200)); 125 grandChild1->setPosition(gfx::PointF(200, 200));
126 grandChild1->setAnchorPoint(FloatPoint::zero()); 126 grandChild1->setAnchorPoint(gfx::PointF());
127 grandChild1->setBounds(IntSize(6, 8)); 127 grandChild1->setBounds(gfx::Size(6, 8));
128 grandChild1->setContentBounds(IntSize(6, 8)); 128 grandChild1->setContentBounds(gfx::Size(6, 8));
129 grandChild1->setDrawsContent(true); 129 grandChild1->setDrawsContent(true);
130 130
131 grandChild2->setPosition(FloatPoint(190, 190)); 131 grandChild2->setPosition(gfx::PointF(190, 190));
132 grandChild2->setAnchorPoint(FloatPoint::zero()); 132 grandChild2->setAnchorPoint(gfx::PointF());
133 grandChild2->setBounds(IntSize(6, 8)); 133 grandChild2->setBounds(gfx::Size(6, 8));
134 grandChild2->setContentBounds(IntSize(6, 8)); 134 grandChild2->setContentBounds(gfx::Size(6, 8));
135 grandChild2->setDrawsContent(true); 135 grandChild2->setDrawsContent(true);
136 136
137 child1->addChild(grandChild1.Pass()); 137 child1->addChild(grandChild1.Pass());
138 child1->addChild(grandChild2.Pass()); 138 child1->addChild(grandChild2.Pass());
139 root->addChild(child1.Pass()); 139 root->addChild(child1.Pass());
140 root->addChild(child2.Pass()); 140 root->addChild(child2.Pass());
141 141
142 return root.Pass(); 142 return root.Pass();
143 } 143 }
144 144
(...skipping 29 matching lines...) Expand all
174 { 174 {
175 // Sanity check that the simple test tree will actually produce the expected render 175 // Sanity check that the simple test tree will actually produce the expected render
176 // surfaces and layer lists. 176 // surfaces and layer lists.
177 177
178 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); 178 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface();
179 179
180 EXPECT_EQ(2u, root->renderSurface()->layerList().size()); 180 EXPECT_EQ(2u, root->renderSurface()->layerList().size());
181 EXPECT_EQ(1, root->renderSurface()->layerList()[0]->id()); 181 EXPECT_EQ(1, root->renderSurface()->layerList()[0]->id());
182 EXPECT_EQ(2, root->renderSurface()->layerList()[1]->id()); 182 EXPECT_EQ(2, root->renderSurface()->layerList()[1]->id());
183 183
184 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa mageRect(); 184 gfx::RectF rootDamageRect = root->renderSurface()->damageTracker()->currentD amageRect();
185 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect); 185 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 500, 500), rootDamageRect);
186 } 186 }
187 187
188 TEST_F(DamageTrackerTest, sanityCheckTestTreeWithTwoSurfaces) 188 TEST_F(DamageTrackerTest, sanityCheckTestTreeWithTwoSurfaces)
189 { 189 {
190 // Sanity check that the complex test tree will actually produce the expecte d render 190 // Sanity check that the complex test tree will actually produce the expecte d render
191 // surfaces and layer lists. 191 // surfaces and layer lists.
192 192
193 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); 193 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
194 194
195 LayerImpl* child1 = root->children()[0]; 195 LayerImpl* child1 = root->children()[0];
196 LayerImpl* child2 = root->children()[1]; 196 LayerImpl* child2 = root->children()[1];
197 FloatRect childDamageRect = child1->renderSurface()->damageTracker()->curren tDamageRect(); 197 gfx::RectF childDamageRect = child1->renderSurface()->damageTracker()->curre ntDamageRect();
198 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa mageRect(); 198 gfx::RectF rootDamageRect = root->renderSurface()->damageTracker()->currentD amageRect();
199 199
200 ASSERT_TRUE(child1->renderSurface()); 200 ASSERT_TRUE(child1->renderSurface());
201 EXPECT_FALSE(child2->renderSurface()); 201 EXPECT_FALSE(child2->renderSurface());
202 EXPECT_EQ(3u, root->renderSurface()->layerList().size()); 202 EXPECT_EQ(3u, root->renderSurface()->layerList().size());
203 EXPECT_EQ(2u, child1->renderSurface()->layerList().size()); 203 EXPECT_EQ(2u, child1->renderSurface()->layerList().size());
204 204
205 // The render surface for child1 only has a contentRect that encloses grandC hild1 and grandChild2, because child1 does not draw content. 205 // The render surface for child1 only has a contentRect that encloses grandC hild1 and grandChild2, because child1 does not draw content.
206 EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 16, 18), childDamageRect); 206 EXPECT_FLOAT_RECT_EQ(gfx::RectF(190, 190, 16, 18), childDamageRect);
207 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect); 207 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 500, 500), rootDamageRect);
208 } 208 }
209 209
210 TEST_F(DamageTrackerTest, verifyDamageForUpdateRects) 210 TEST_F(DamageTrackerTest, verifyDamageForUpdateRects)
211 { 211 {
212 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); 212 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface();
213 LayerImpl* child = root->children()[0]; 213 LayerImpl* child = root->children()[0];
214 214
215 // CASE 1: Setting the update rect should cause the corresponding damage to the surface. 215 // CASE 1: Setting the update rect should cause the corresponding damage to the surface.
216 // 216 //
217 clearDamageForAllSurfaces(root.get()); 217 clearDamageForAllSurfaces(root.get());
218 child->setUpdateRect(FloatRect(10, 11, 12, 13)); 218 child->setUpdateRect(gfx::RectF(10, 11, 12, 13));
219 emulateDrawingOneFrame(root.get()); 219 emulateDrawingOneFrame(root.get());
220 220
221 // Damage position on the surface should be: position of updateRect (10, 11) relative to the child (100, 100). 221 // Damage position on the surface should be: position of updateRect (10, 11) relative to the child (100, 100).
222 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa mageRect(); 222 gfx::RectF rootDamageRect = root->renderSurface()->damageTracker()->currentD amageRect();
223 EXPECT_FLOAT_RECT_EQ(FloatRect(110, 111, 12, 13), rootDamageRect); 223 EXPECT_FLOAT_RECT_EQ(gfx::RectF(110, 111, 12, 13), rootDamageRect);
224 224
225 // CASE 2: The same update rect twice in a row still produces the same damag e. 225 // CASE 2: The same update rect twice in a row still produces the same damag e.
226 // 226 //
227 clearDamageForAllSurfaces(root.get()); 227 clearDamageForAllSurfaces(root.get());
228 child->setUpdateRect(FloatRect(10, 11, 12, 13)); 228 child->setUpdateRect(gfx::RectF(10, 11, 12, 13));
229 emulateDrawingOneFrame(root.get()); 229 emulateDrawingOneFrame(root.get());
230 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 230 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
231 EXPECT_FLOAT_RECT_EQ(FloatRect(110, 111, 12, 13), rootDamageRect); 231 EXPECT_FLOAT_RECT_EQ(gfx::RectF(110, 111, 12, 13), rootDamageRect);
232 232
233 // CASE 3: Setting a different update rect should cause damage on the new up date region, but no additional exposed old region. 233 // CASE 3: Setting a different update rect should cause damage on the new up date region, but no additional exposed old region.
234 // 234 //
235 clearDamageForAllSurfaces(root.get()); 235 clearDamageForAllSurfaces(root.get());
236 child->setUpdateRect(FloatRect(20, 25, 1, 2)); 236 child->setUpdateRect(gfx::RectF(20, 25, 1, 2));
237 emulateDrawingOneFrame(root.get()); 237 emulateDrawingOneFrame(root.get());
238 238
239 // Damage position on the surface should be: position of updateRect (20, 25) relative to the child (100, 100). 239 // Damage position on the surface should be: position of updateRect (20, 25) relative to the child (100, 100).
240 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 240 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
241 EXPECT_FLOAT_RECT_EQ(FloatRect(120, 125, 1, 2), rootDamageRect); 241 EXPECT_FLOAT_RECT_EQ(gfx::RectF(120, 125, 1, 2), rootDamageRect);
242 } 242 }
243 243
244 TEST_F(DamageTrackerTest, verifyDamageForPropertyChanges) 244 TEST_F(DamageTrackerTest, verifyDamageForPropertyChanges)
245 { 245 {
246 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); 246 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface();
247 LayerImpl* child = root->children()[0]; 247 LayerImpl* child = root->children()[0];
248 248
249 // CASE 1: The layer's property changed flag takes priority over update rect . 249 // CASE 1: The layer's property changed flag takes priority over update rect .
250 // 250 //
251 clearDamageForAllSurfaces(root.get()); 251 clearDamageForAllSurfaces(root.get());
252 child->setUpdateRect(FloatRect(10, 11, 12, 13)); 252 child->setUpdateRect(gfx::RectF(10, 11, 12, 13));
253 child->setOpacity(0.5); 253 child->setOpacity(0.5);
254 emulateDrawingOneFrame(root.get()); 254 emulateDrawingOneFrame(root.get());
255 255
256 // Sanity check - we should not have accidentally created a separate render surface for the translucent layer. 256 // Sanity check - we should not have accidentally created a separate render surface for the translucent layer.
257 ASSERT_FALSE(child->renderSurface()); 257 ASSERT_FALSE(child->renderSurface());
258 ASSERT_EQ(2u, root->renderSurface()->layerList().size()); 258 ASSERT_EQ(2u, root->renderSurface()->layerList().size());
259 259
260 // Damage should be the entire child layer in targetSurface space. 260 // Damage should be the entire child layer in targetSurface space.
261 FloatRect expectedRect = FloatRect(100, 100, 30, 30); 261 gfx::RectF expectedRect = gfx::RectF(100, 100, 30, 30);
262 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa mageRect(); 262 gfx::RectF rootDamageRect = root->renderSurface()->damageTracker()->currentD amageRect();
263 EXPECT_FLOAT_RECT_EQ(expectedRect, rootDamageRect); 263 EXPECT_FLOAT_RECT_EQ(expectedRect, rootDamageRect);
264 264
265 // CASE 2: If a layer moves due to property change, it damages both the new location 265 // CASE 2: If a layer moves due to property change, it damages both the new location
266 // and the old (exposed) location. The old location is the entire ol d layer, 266 // and the old (exposed) location. The old location is the entire ol d layer,
267 // not just the updateRect. 267 // not just the updateRect.
268 268
269 // Cycle one frame of no change, just to sanity check that the next rect is not because of the old damage state. 269 // Cycle one frame of no change, just to sanity check that the next rect is not because of the old damage state.
270 clearDamageForAllSurfaces(root.get()); 270 clearDamageForAllSurfaces(root.get());
271 emulateDrawingOneFrame(root.get()); 271 emulateDrawingOneFrame(root.get());
272 EXPECT_TRUE(root->renderSurface()->damageTracker()->currentDamageRect().isEm pty()); 272 EXPECT_TRUE(root->renderSurface()->damageTracker()->currentDamageRect().IsEm pty());
273 273
274 // Then, test the actual layer movement. 274 // Then, test the actual layer movement.
275 clearDamageForAllSurfaces(root.get()); 275 clearDamageForAllSurfaces(root.get());
276 child->setPosition(FloatPoint(200, 230)); 276 child->setPosition(gfx::PointF(200, 230));
277 emulateDrawingOneFrame(root.get()); 277 emulateDrawingOneFrame(root.get());
278 278
279 // Expect damage to be the combination of the previous one and the new one. 279 // Expect damage to be the combination of the previous one and the new one.
280 expectedRect.uniteIfNonZero(FloatRect(200, 230, 30, 30)); 280 expectedRect.Union(gfx::RectF(200, 230, 30, 30));
281 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 281 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
282 EXPECT_FLOAT_RECT_EQ(expectedRect, rootDamageRect); 282 EXPECT_FLOAT_RECT_EQ(expectedRect, rootDamageRect);
283 } 283 }
284 284
285 TEST_F(DamageTrackerTest, verifyDamageForTransformedLayer) 285 TEST_F(DamageTrackerTest, verifyDamageForTransformedLayer)
286 { 286 {
287 // If a layer is transformed, the damage rect should still enclose the entir e 287 // If a layer is transformed, the damage rect should still enclose the entir e
288 // transformed layer. 288 // transformed layer.
289 289
290 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); 290 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface();
291 LayerImpl* child = root->children()[0]; 291 LayerImpl* child = root->children()[0];
292 292
293 WebTransformationMatrix rotation; 293 WebTransformationMatrix rotation;
294 rotation.rotate(45); 294 rotation.rotate(45);
295 295
296 clearDamageForAllSurfaces(root.get()); 296 clearDamageForAllSurfaces(root.get());
297 child->setAnchorPoint(FloatPoint(0.5, 0.5)); 297 child->setAnchorPoint(gfx::PointF(0.5, 0.5));
298 child->setPosition(FloatPoint(85, 85)); 298 child->setPosition(gfx::PointF(85, 85));
299 emulateDrawingOneFrame(root.get()); 299 emulateDrawingOneFrame(root.get());
300 300
301 // Sanity check that the layer actually moved to (85, 85), damaging its old location and new location. 301 // Sanity check that the layer actually moved to (85, 85), damaging its old location and new location.
302 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa mageRect(); 302 gfx::RectF rootDamageRect = root->renderSurface()->damageTracker()->currentD amageRect();
303 EXPECT_FLOAT_RECT_EQ(FloatRect(85, 85, 45, 45), rootDamageRect); 303 EXPECT_FLOAT_RECT_EQ(gfx::RectF(85, 85, 45, 45), rootDamageRect);
304 304
305 // With the anchor on the layer's center, now we can test the rotation more 305 // With the anchor on the layer's center, now we can test the rotation more
306 // intuitively, since it applies about the layer's anchor. 306 // intuitively, since it applies about the layer's anchor.
307 clearDamageForAllSurfaces(root.get()); 307 clearDamageForAllSurfaces(root.get());
308 child->setTransform(rotation); 308 child->setTransform(rotation);
309 emulateDrawingOneFrame(root.get()); 309 emulateDrawingOneFrame(root.get());
310 310
311 // Since the child layer is square, rotation by 45 degrees about the center should 311 // Since the child layer is square, rotation by 45 degrees about the center should
312 // increase the size of the expected rect by sqrt(2), centered around (100, 100). The 312 // increase the size of the expected rect by sqrt(2), centered around (100, 100). The
313 // old exposed region should be fully contained in the new region. 313 // old exposed region should be fully contained in the new region.
314 double expectedWidth = 30 * sqrt(2.0); 314 double expectedWidth = 30 * sqrt(2.0);
315 double expectedPosition = 100 - 0.5 * expectedWidth; 315 double expectedPosition = 100 - 0.5 * expectedWidth;
316 FloatRect expectedRect(expectedPosition, expectedPosition, expectedWidth, ex pectedWidth); 316 gfx::RectF expectedRect(expectedPosition, expectedPosition, expectedWidth, e xpectedWidth);
317 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 317 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
318 EXPECT_FLOAT_RECT_EQ(expectedRect, rootDamageRect); 318 EXPECT_FLOAT_RECT_EQ(expectedRect, rootDamageRect);
319 } 319 }
320 320
321 TEST_F(DamageTrackerTest, verifyDamageForPerspectiveClippedLayer) 321 TEST_F(DamageTrackerTest, verifyDamageForPerspectiveClippedLayer)
322 { 322 {
323 // If a layer has a perspective transform that causes w < 0, then not clippi ng the 323 // If a layer has a perspective transform that causes w < 0, then not clippi ng the
324 // layer can cause an invalid damage rect. This test checks that the w < 0 c ase is 324 // layer can cause an invalid damage rect. This test checks that the w < 0 c ase is
325 // tracked properly. 325 // tracked properly.
326 // 326 //
327 // The transform is constructed so that if w < 0 clipping is not performed, the 327 // The transform is constructed so that if w < 0 clipping is not performed, the
328 // incorrect rect will be very small, specifically: position (500.972504, 49 8.544617) and size 0.056610 x 2.910767. 328 // incorrect rect will be very small, specifically: position (500.972504, 49 8.544617) and size 0.056610 x 2.910767.
329 // Instead, the correctly transformed rect should actually be very huge (i.e . in theory, -infinity on the left), 329 // Instead, the correctly transformed rect should actually be very huge (i.e . in theory, -infinity on the left),
330 // and positioned so that the right-most bound rect will be approximately 50 1 units in root surface space. 330 // and positioned so that the right-most bound rect will be approximately 50 1 units in root surface space.
331 // 331 //
332 332
333 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); 333 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface();
334 LayerImpl* child = root->children()[0]; 334 LayerImpl* child = root->children()[0];
335 335
336 WebTransformationMatrix transform; 336 WebTransformationMatrix transform;
337 transform.translate3d(500, 500, 0); 337 transform.translate3d(500, 500, 0);
338 transform.applyPerspective(1); 338 transform.applyPerspective(1);
339 transform.rotate3d(0, 45, 0); 339 transform.rotate3d(0, 45, 0);
340 transform.translate3d(-50, -50, 0); 340 transform.translate3d(-50, -50, 0);
341 341
342 // Set up the child 342 // Set up the child
343 child->setPosition(FloatPoint(0, 0)); 343 child->setPosition(gfx::PointF(0, 0));
344 child->setBounds(IntSize(100, 100)); 344 child->setBounds(gfx::Size(100, 100));
345 child->setContentBounds(IntSize(100, 100)); 345 child->setContentBounds(gfx::Size(100, 100));
346 child->setTransform(transform); 346 child->setTransform(transform);
347 emulateDrawingOneFrame(root.get()); 347 emulateDrawingOneFrame(root.get());
348 348
349 // Sanity check that the child layer's bounds would actually get clipped by w < 0, 349 // Sanity check that the child layer's bounds would actually get clipped by w < 0,
350 // otherwise this test is not actually testing the intended scenario. 350 // otherwise this test is not actually testing the intended scenario.
351 FloatQuad testQuad(FloatRect(FloatPoint::zero(), FloatSize(100, 100))); 351 FloatQuad testQuad(gfx::RectF(gfx::PointF(), gfx::SizeF(100, 100)));
352 bool clipped = false; 352 bool clipped = false;
353 MathUtil::mapQuad(transform, testQuad, clipped); 353 MathUtil::mapQuad(transform, testQuad, clipped);
354 EXPECT_TRUE(clipped); 354 EXPECT_TRUE(clipped);
355 355
356 // Damage the child without moving it. 356 // Damage the child without moving it.
357 clearDamageForAllSurfaces(root.get()); 357 clearDamageForAllSurfaces(root.get());
358 child->setOpacity(0.5); 358 child->setOpacity(0.5);
359 emulateDrawingOneFrame(root.get()); 359 emulateDrawingOneFrame(root.get());
360 360
361 // The expected damage should cover the entire root surface (500x500), but w e don't 361 // The expected damage should cover the entire root surface (500x500), but w e don't
362 // care whether the damage rect was clamped or is larger than the surface fo r this test. 362 // care whether the damage rect was clamped or is larger than the surface fo r this test.
363 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa mageRect(); 363 gfx::RectF rootDamageRect = root->renderSurface()->damageTracker()->currentD amageRect();
364 FloatRect damageWeCareAbout = FloatRect(FloatPoint::zero(), FloatSize(500, 5 00)); 364 gfx::RectF damageWeCareAbout = gfx::RectF(gfx::PointF(), gfx::SizeF(500, 500 ));
365 EXPECT_TRUE(rootDamageRect.contains(damageWeCareAbout)); 365 EXPECT_TRUE(rootDamageRect.Contains(damageWeCareAbout));
366 } 366 }
367 367
368 TEST_F(DamageTrackerTest, verifyDamageForBlurredSurface) 368 TEST_F(DamageTrackerTest, verifyDamageForBlurredSurface)
369 { 369 {
370 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); 370 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface();
371 LayerImpl* child = root->children()[0]; 371 LayerImpl* child = root->children()[0];
372 372
373 WebFilterOperations filters; 373 WebFilterOperations filters;
374 filters.append(WebFilterOperation::createBlurFilter(5)); 374 filters.append(WebFilterOperation::createBlurFilter(5));
375 int outsetTop, outsetRight, outsetBottom, outsetLeft; 375 int outsetTop, outsetRight, outsetBottom, outsetLeft;
376 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft); 376 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
377 377
378 // Setting the filter will damage the whole surface. 378 // Setting the filter will damage the whole surface.
379 clearDamageForAllSurfaces(root.get()); 379 clearDamageForAllSurfaces(root.get());
380 root->setFilters(filters); 380 root->setFilters(filters);
381 emulateDrawingOneFrame(root.get()); 381 emulateDrawingOneFrame(root.get());
382 382
383 // Setting the update rect should cause the corresponding damage to the surf ace, blurred based on the size of the blur filter. 383 // Setting the update rect should cause the corresponding damage to the surf ace, blurred based on the size of the blur filter.
384 clearDamageForAllSurfaces(root.get()); 384 clearDamageForAllSurfaces(root.get());
385 child->setUpdateRect(FloatRect(10, 11, 12, 13)); 385 child->setUpdateRect(gfx::RectF(10, 11, 12, 13));
386 emulateDrawingOneFrame(root.get()); 386 emulateDrawingOneFrame(root.get());
387 387
388 // Damage position on the surface should be: position of updateRect (10, 11) relative to the child (100, 100), but expanded by the blur outsets. 388 // Damage position on the surface should be: position of updateRect (10, 11) relative to the child (100, 100), but expanded by the blur outsets.
389 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa mageRect(); 389 gfx::RectF rootDamageRect = root->renderSurface()->damageTracker()->currentD amageRect();
390 FloatRect expectedDamageRect = FloatRect(110, 111, 12, 13); 390 gfx::RectF expectedDamageRect = gfx::RectF(110, 111, 12, 13);
391 expectedDamageRect.move(-outsetLeft, -outsetTop); 391 expectedDamageRect.Inset(-outsetLeft, -outsetTop, -outsetRight, -outsetBotto m);
392 expectedDamageRect.expand(outsetLeft + outsetRight, outsetTop + outsetBottom );
393 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect); 392 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect);
394 } 393 }
395 394
396 TEST_F(DamageTrackerTest, verifyDamageForImageFilter) 395 TEST_F(DamageTrackerTest, verifyDamageForImageFilter)
397 { 396 {
398 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); 397 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface();
399 LayerImpl* child = root->children()[0]; 398 LayerImpl* child = root->children()[0];
400 FloatRect rootDamageRect, childDamageRect; 399 gfx::RectF rootDamageRect, childDamageRect;
401 400
402 // Allow us to set damage on child too. 401 // Allow us to set damage on child too.
403 child->setDrawsContent(true); 402 child->setDrawsContent(true);
404 403
405 SkAutoTUnref<SkImageFilter> filter(new SkBlurImageFilter(SkIntToScalar(2), 404 SkAutoTUnref<SkImageFilter> filter(new SkBlurImageFilter(SkIntToScalar(2),
406 SkIntToScalar(2))); 405 SkIntToScalar(2)));
407 // Setting the filter will damage the whole surface. 406 // Setting the filter will damage the whole surface.
408 clearDamageForAllSurfaces(root.get()); 407 clearDamageForAllSurfaces(root.get());
409 child->setFilter(filter); 408 child->setFilter(filter);
410 emulateDrawingOneFrame(root.get()); 409 emulateDrawingOneFrame(root.get());
411 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 410 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
412 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect (); 411 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect ();
413 EXPECT_FLOAT_RECT_EQ(FloatRect(100, 100, 30, 30), rootDamageRect); 412 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 30, 30), rootDamageRect);
414 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 30), childDamageRect); 413 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 30, 30), childDamageRect);
415 414
416 // CASE 1: Setting the update rect should damage the whole surface (for now) 415 // CASE 1: Setting the update rect should damage the whole surface (for now)
417 clearDamageForAllSurfaces(root.get()); 416 clearDamageForAllSurfaces(root.get());
418 child->setUpdateRect(FloatRect(0, 0, 1, 1)); 417 child->setUpdateRect(gfx::RectF(0, 0, 1, 1));
419 emulateDrawingOneFrame(root.get()); 418 emulateDrawingOneFrame(root.get());
420 419
421 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 420 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
422 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect (); 421 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect ();
423 EXPECT_FLOAT_RECT_EQ(FloatRect(100, 100, 30, 30), rootDamageRect); 422 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 30, 30), rootDamageRect);
424 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 30), childDamageRect); 423 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 30, 30), childDamageRect);
425 } 424 }
426 425
427 TEST_F(DamageTrackerTest, verifyDamageForBackgroundBlurredChild) 426 TEST_F(DamageTrackerTest, verifyDamageForBackgroundBlurredChild)
428 { 427 {
429 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); 428 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
430 LayerImpl* child1 = root->children()[0]; 429 LayerImpl* child1 = root->children()[0];
431 LayerImpl* child2 = root->children()[1]; 430 LayerImpl* child2 = root->children()[1];
432 431
433 // Allow us to set damage on child1 too. 432 // Allow us to set damage on child1 too.
434 child1->setDrawsContent(true); 433 child1->setDrawsContent(true);
435 434
436 WebFilterOperations filters; 435 WebFilterOperations filters;
437 filters.append(WebFilterOperation::createBlurFilter(2)); 436 filters.append(WebFilterOperation::createBlurFilter(2));
438 int outsetTop, outsetRight, outsetBottom, outsetLeft; 437 int outsetTop, outsetRight, outsetBottom, outsetLeft;
439 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft); 438 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
440 439
441 // Setting the filter will damage the whole surface. 440 // Setting the filter will damage the whole surface.
442 clearDamageForAllSurfaces(root.get()); 441 clearDamageForAllSurfaces(root.get());
443 child1->setBackgroundFilters(filters); 442 child1->setBackgroundFilters(filters);
444 emulateDrawingOneFrame(root.get()); 443 emulateDrawingOneFrame(root.get());
445 444
446 // CASE 1: Setting the update rect should cause the corresponding damage to 445 // CASE 1: Setting the update rect should cause the corresponding damage to
447 // the surface, blurred based on the size of the child's background blur 446 // the surface, blurred based on the size of the child's background blur
448 // filter. 447 // filter.
449 clearDamageForAllSurfaces(root.get()); 448 clearDamageForAllSurfaces(root.get());
450 root->setUpdateRect(FloatRect(297, 297, 2, 2)); 449 root->setUpdateRect(gfx::RectF(297, 297, 2, 2));
451 emulateDrawingOneFrame(root.get()); 450 emulateDrawingOneFrame(root.get());
452 451
453 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa mageRect(); 452 gfx::RectF rootDamageRect = root->renderSurface()->damageTracker()->currentD amageRect();
454 // Damage position on the surface should be a composition of the damage on t he root and on child2. 453 // Damage position on the surface should be a composition of the damage on t he root and on child2.
455 // Damage on the root should be: position of updateRect (297, 297), but expa nded by the blur outsets. 454 // Damage on the root should be: position of updateRect (297, 297), but expa nded by the blur outsets.
456 FloatRect expectedDamageRect = FloatRect(297, 297, 2, 2); 455 gfx::RectF expectedDamageRect = gfx::RectF(297, 297, 2, 2);
457 expectedDamageRect.move(-outsetLeft, -outsetTop); 456 expectedDamageRect.Inset(-outsetLeft, -outsetTop, -outsetRight, -outsetBotto m);
458 expectedDamageRect.expand(outsetLeft + outsetRight, outsetTop + outsetBottom );
459 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect); 457 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect);
460 458
461 // CASE 2: Setting the update rect should cause the corresponding damage to 459 // CASE 2: Setting the update rect should cause the corresponding damage to
462 // the surface, blurred based on the size of the child's background blur 460 // the surface, blurred based on the size of the child's background blur
463 // filter. Since the damage extends to the right/bottom outside of the 461 // filter. Since the damage extends to the right/bottom outside of the
464 // blurred layer, only the left/top should end up expanded. 462 // blurred layer, only the left/top should end up expanded.
465 clearDamageForAllSurfaces(root.get()); 463 clearDamageForAllSurfaces(root.get());
466 root->setUpdateRect(FloatRect(297, 297, 30, 30)); 464 root->setUpdateRect(gfx::RectF(297, 297, 30, 30));
467 emulateDrawingOneFrame(root.get()); 465 emulateDrawingOneFrame(root.get());
468 466
469 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 467 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
470 // Damage position on the surface should be a composition of the damage on t he root and on child2. 468 // Damage position on the surface should be a composition of the damage on t he root and on child2.
471 // Damage on the root should be: position of updateRect (297, 297), but expa nded on the left/top 469 // Damage on the root should be: position of updateRect (297, 297), but expa nded on the left/top
472 // by the blur outsets. 470 // by the blur outsets.
473 expectedDamageRect = FloatRect(297, 297, 30, 30); 471 expectedDamageRect = gfx::RectF(297, 297, 30, 30);
474 expectedDamageRect.move(-outsetLeft, -outsetTop); 472 expectedDamageRect.Inset(-outsetLeft, -outsetTop, 0, 0);
475 expectedDamageRect.expand(outsetLeft, outsetTop);
476 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect); 473 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect);
477 474
478 // CASE 3: Setting this update rect outside the blurred contentBounds of the blurred 475 // CASE 3: Setting this update rect outside the blurred contentBounds of the blurred
479 // child1 will not cause it to be expanded. 476 // child1 will not cause it to be expanded.
480 clearDamageForAllSurfaces(root.get()); 477 clearDamageForAllSurfaces(root.get());
481 root->setUpdateRect(FloatRect(30, 30, 2, 2)); 478 root->setUpdateRect(gfx::RectF(30, 30, 2, 2));
482 emulateDrawingOneFrame(root.get()); 479 emulateDrawingOneFrame(root.get());
483 480
484 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 481 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
485 // Damage on the root should be: position of updateRect (30, 30), not 482 // Damage on the root should be: position of updateRect (30, 30), not
486 // expanded. 483 // expanded.
487 expectedDamageRect = FloatRect(30, 30, 2, 2); 484 expectedDamageRect = gfx::RectF(30, 30, 2, 2);
488 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect); 485 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect);
489 486
490 // CASE 4: Setting this update rect inside the blurred contentBounds but out side the 487 // CASE 4: Setting this update rect inside the blurred contentBounds but out side the
491 // original contentBounds of the blurred child1 will cause it to be expanded . 488 // original contentBounds of the blurred child1 will cause it to be expanded .
492 clearDamageForAllSurfaces(root.get()); 489 clearDamageForAllSurfaces(root.get());
493 root->setUpdateRect(FloatRect(99, 99, 1, 1)); 490 root->setUpdateRect(gfx::RectF(99, 99, 1, 1));
494 emulateDrawingOneFrame(root.get()); 491 emulateDrawingOneFrame(root.get());
495 492
496 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 493 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
497 // Damage on the root should be: position of updateRect (99, 99), expanded 494 // Damage on the root should be: position of updateRect (99, 99), expanded
498 // by the blurring on child1, but since it is 1 pixel outside the layer, the 495 // by the blurring on child1, but since it is 1 pixel outside the layer, the
499 // expanding should be reduced by 1. 496 // expanding should be reduced by 1.
500 expectedDamageRect = FloatRect(99, 99, 1, 1); 497 expectedDamageRect = gfx::RectF(99, 99, 1, 1);
501 expectedDamageRect.move(-outsetLeft + 1, -outsetTop + 1); 498 expectedDamageRect.Inset(-outsetLeft + 1, -outsetTop + 1, -outsetRight, -out setBottom);
502 expectedDamageRect.expand(outsetLeft + outsetRight - 1, outsetTop + outsetBo ttom - 1);
503 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect); 499 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect);
504 500
505 // CASE 5: Setting the update rect on child2, which is above child1, will 501 // CASE 5: Setting the update rect on child2, which is above child1, will
506 // not get blurred by child1, so it does not need to get expanded. 502 // not get blurred by child1, so it does not need to get expanded.
507 clearDamageForAllSurfaces(root.get()); 503 clearDamageForAllSurfaces(root.get());
508 child2->setUpdateRect(FloatRect(0, 0, 1, 1)); 504 child2->setUpdateRect(gfx::RectF(0, 0, 1, 1));
509 emulateDrawingOneFrame(root.get()); 505 emulateDrawingOneFrame(root.get());
510 506
511 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 507 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
512 // Damage on child2 should be: position of updateRect offset by the child's position (11, 11), and not expanded by anything. 508 // Damage on child2 should be: position of updateRect offset by the child's position (11, 11), and not expanded by anything.
513 expectedDamageRect = FloatRect(11, 11, 1, 1); 509 expectedDamageRect = gfx::RectF(11, 11, 1, 1);
514 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect); 510 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect);
515 511
516 // CASE 6: Setting the update rect on child1 will also blur the damage, so 512 // CASE 6: Setting the update rect on child1 will also blur the damage, so
517 // that any pixels needed for the blur are redrawn in the current frame. 513 // that any pixels needed for the blur are redrawn in the current frame.
518 clearDamageForAllSurfaces(root.get()); 514 clearDamageForAllSurfaces(root.get());
519 child1->setUpdateRect(FloatRect(0, 0, 1, 1)); 515 child1->setUpdateRect(gfx::RectF(0, 0, 1, 1));
520 emulateDrawingOneFrame(root.get()); 516 emulateDrawingOneFrame(root.get());
521 517
522 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 518 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
523 // Damage on child1 should be: position of updateRect offset by the child's position (100, 100), and expanded by the damage. 519 // Damage on child1 should be: position of updateRect offset by the child's position (100, 100), and expanded by the damage.
524 expectedDamageRect = FloatRect(100, 100, 1, 1); 520 expectedDamageRect = gfx::RectF(100, 100, 1, 1);
525 expectedDamageRect.move(-outsetLeft, -outsetTop); 521 expectedDamageRect.Inset(-outsetLeft, -outsetTop, -outsetRight, -outsetBotto m);
526 expectedDamageRect.expand(outsetLeft + outsetRight, outsetTop + outsetBottom );
527 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect); 522 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect);
528 } 523 }
529 524
530 TEST_F(DamageTrackerTest, verifyDamageForAddingAndRemovingLayer) 525 TEST_F(DamageTrackerTest, verifyDamageForAddingAndRemovingLayer)
531 { 526 {
532 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); 527 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface();
533 LayerImpl* child1 = root->children()[0]; 528 LayerImpl* child1 = root->children()[0];
534 529
535 // CASE 1: Adding a new layer should cause the appropriate damage. 530 // CASE 1: Adding a new layer should cause the appropriate damage.
536 // 531 //
537 clearDamageForAllSurfaces(root.get()); 532 clearDamageForAllSurfaces(root.get());
538 { 533 {
539 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); 534 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3);
540 child2->setPosition(FloatPoint(400, 380)); 535 child2->setPosition(gfx::PointF(400, 380));
541 child2->setAnchorPoint(FloatPoint::zero()); 536 child2->setAnchorPoint(gfx::PointF());
542 child2->setBounds(IntSize(6, 8)); 537 child2->setBounds(gfx::Size(6, 8));
543 child2->setContentBounds(IntSize(6, 8)); 538 child2->setContentBounds(gfx::Size(6, 8));
544 child2->setDrawsContent(true); 539 child2->setDrawsContent(true);
545 root->addChild(child2.Pass()); 540 root->addChild(child2.Pass());
546 } 541 }
547 emulateDrawingOneFrame(root.get()); 542 emulateDrawingOneFrame(root.get());
548 543
549 // Sanity check - all 3 layers should be on the same render surface; render surfaces are tested elsewhere. 544 // Sanity check - all 3 layers should be on the same render surface; render surfaces are tested elsewhere.
550 ASSERT_EQ(3u, root->renderSurface()->layerList().size()); 545 ASSERT_EQ(3u, root->renderSurface()->layerList().size());
551 546
552 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa mageRect(); 547 gfx::RectF rootDamageRect = root->renderSurface()->damageTracker()->currentD amageRect();
553 EXPECT_FLOAT_RECT_EQ(FloatRect(400, 380, 6, 8), rootDamageRect); 548 EXPECT_FLOAT_RECT_EQ(gfx::RectF(400, 380, 6, 8), rootDamageRect);
554 549
555 // CASE 2: If the layer is removed, its entire old layer becomes exposed, no t just the 550 // CASE 2: If the layer is removed, its entire old layer becomes exposed, no t just the
556 // last update rect. 551 // last update rect.
557 552
558 // Advance one frame without damage so that we know the damage rect is not l eftover from the previous case. 553 // Advance one frame without damage so that we know the damage rect is not l eftover from the previous case.
559 clearDamageForAllSurfaces(root.get()); 554 clearDamageForAllSurfaces(root.get());
560 emulateDrawingOneFrame(root.get()); 555 emulateDrawingOneFrame(root.get());
561 EXPECT_TRUE(root->renderSurface()->damageTracker()->currentDamageRect().isEm pty()); 556 EXPECT_TRUE(root->renderSurface()->damageTracker()->currentDamageRect().IsEm pty());
562 557
563 // Then, test removing child1. 558 // Then, test removing child1.
564 child1->removeFromParent(); 559 child1->removeFromParent();
565 emulateDrawingOneFrame(root.get()); 560 emulateDrawingOneFrame(root.get());
566 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 561 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
567 EXPECT_FLOAT_RECT_EQ(FloatRect(100, 100, 30, 30), rootDamageRect); 562 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 30, 30), rootDamageRect);
568 } 563 }
569 564
570 TEST_F(DamageTrackerTest, verifyDamageForNewUnchangedLayer) 565 TEST_F(DamageTrackerTest, verifyDamageForNewUnchangedLayer)
571 { 566 {
572 // If child2 is added to the layer tree, but it doesn't have any explicit da mage of 567 // If child2 is added to the layer tree, but it doesn't have any explicit da mage of
573 // its own, it should still indeed damage the target surface. 568 // its own, it should still indeed damage the target surface.
574 569
575 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); 570 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface();
576 571
577 clearDamageForAllSurfaces(root.get()); 572 clearDamageForAllSurfaces(root.get());
578 { 573 {
579 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); 574 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3);
580 child2->setPosition(FloatPoint(400, 380)); 575 child2->setPosition(gfx::PointF(400, 380));
581 child2->setAnchorPoint(FloatPoint::zero()); 576 child2->setAnchorPoint(gfx::PointF());
582 child2->setBounds(IntSize(6, 8)); 577 child2->setBounds(gfx::Size(6, 8));
583 child2->setContentBounds(IntSize(6, 8)); 578 child2->setContentBounds(gfx::Size(6, 8));
584 child2->setDrawsContent(true); 579 child2->setDrawsContent(true);
585 child2->resetAllChangeTrackingForSubtree(); 580 child2->resetAllChangeTrackingForSubtree();
586 // Sanity check the initial conditions of the test, if these asserts tri gger, it 581 // Sanity check the initial conditions of the test, if these asserts tri gger, it
587 // means the test no longer actually covers the intended scenario. 582 // means the test no longer actually covers the intended scenario.
588 ASSERT_FALSE(child2->layerPropertyChanged()); 583 ASSERT_FALSE(child2->layerPropertyChanged());
589 ASSERT_TRUE(child2->updateRect().isEmpty()); 584 ASSERT_TRUE(child2->updateRect().IsEmpty());
590 root->addChild(child2.Pass()); 585 root->addChild(child2.Pass());
591 } 586 }
592 emulateDrawingOneFrame(root.get()); 587 emulateDrawingOneFrame(root.get());
593 588
594 // Sanity check - all 3 layers should be on the same render surface; render surfaces are tested elsewhere. 589 // Sanity check - all 3 layers should be on the same render surface; render surfaces are tested elsewhere.
595 ASSERT_EQ(3u, root->renderSurface()->layerList().size()); 590 ASSERT_EQ(3u, root->renderSurface()->layerList().size());
596 591
597 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa mageRect(); 592 gfx::RectF rootDamageRect = root->renderSurface()->damageTracker()->currentD amageRect();
598 EXPECT_FLOAT_RECT_EQ(FloatRect(400, 380, 6, 8), rootDamageRect); 593 EXPECT_FLOAT_RECT_EQ(gfx::RectF(400, 380, 6, 8), rootDamageRect);
599 } 594 }
600 595
601 TEST_F(DamageTrackerTest, verifyDamageForMultipleLayers) 596 TEST_F(DamageTrackerTest, verifyDamageForMultipleLayers)
602 { 597 {
603 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); 598 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface();
604 LayerImpl* child1 = root->children()[0]; 599 LayerImpl* child1 = root->children()[0];
605 600
606 // In this test we don't want the above tree manipulation to be considered p art of the same frame. 601 // In this test we don't want the above tree manipulation to be considered p art of the same frame.
607 clearDamageForAllSurfaces(root.get()); 602 clearDamageForAllSurfaces(root.get());
608 { 603 {
609 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); 604 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3);
610 child2->setPosition(FloatPoint(400, 380)); 605 child2->setPosition(gfx::PointF(400, 380));
611 child2->setAnchorPoint(FloatPoint::zero()); 606 child2->setAnchorPoint(gfx::PointF());
612 child2->setBounds(IntSize(6, 8)); 607 child2->setBounds(gfx::Size(6, 8));
613 child2->setContentBounds(IntSize(6, 8)); 608 child2->setContentBounds(gfx::Size(6, 8));
614 child2->setDrawsContent(true); 609 child2->setDrawsContent(true);
615 root->addChild(child2.Pass()); 610 root->addChild(child2.Pass());
616 } 611 }
617 LayerImpl* child2 = root->children()[1]; 612 LayerImpl* child2 = root->children()[1];
618 emulateDrawingOneFrame(root.get()); 613 emulateDrawingOneFrame(root.get());
619 614
620 // Damaging two layers simultaneously should cause combined damage. 615 // Damaging two layers simultaneously should cause combined damage.
621 // - child1 update rect in surface space: FloatRect(100, 100, 1, 2); 616 // - child1 update rect in surface space: gfx::RectF(100, 100, 1, 2);
622 // - child2 update rect in surface space: FloatRect(400, 380, 3, 4); 617 // - child2 update rect in surface space: gfx::RectF(400, 380, 3, 4);
623 clearDamageForAllSurfaces(root.get()); 618 clearDamageForAllSurfaces(root.get());
624 child1->setUpdateRect(FloatRect(0, 0, 1, 2)); 619 child1->setUpdateRect(gfx::RectF(0, 0, 1, 2));
625 child2->setUpdateRect(FloatRect(0, 0, 3, 4)); 620 child2->setUpdateRect(gfx::RectF(0, 0, 3, 4));
626 emulateDrawingOneFrame(root.get()); 621 emulateDrawingOneFrame(root.get());
627 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa mageRect(); 622 gfx::RectF rootDamageRect = root->renderSurface()->damageTracker()->currentD amageRect();
628 EXPECT_FLOAT_RECT_EQ(FloatRect(100, 100, 303, 284), rootDamageRect); 623 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 303, 284), rootDamageRect);
629 } 624 }
630 625
631 TEST_F(DamageTrackerTest, verifyDamageForNestedSurfaces) 626 TEST_F(DamageTrackerTest, verifyDamageForNestedSurfaces)
632 { 627 {
633 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); 628 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
634 LayerImpl* child1 = root->children()[0]; 629 LayerImpl* child1 = root->children()[0];
635 LayerImpl* child2 = root->children()[1]; 630 LayerImpl* child2 = root->children()[1];
636 LayerImpl* grandChild1 = root->children()[0]->children()[0]; 631 LayerImpl* grandChild1 = root->children()[0]->children()[0];
637 FloatRect childDamageRect; 632 gfx::RectF childDamageRect;
638 FloatRect rootDamageRect; 633 gfx::RectF rootDamageRect;
639 634
640 // CASE 1: Damage to a descendant surface should propagate properly to ances tor surface. 635 // CASE 1: Damage to a descendant surface should propagate properly to ances tor surface.
641 // 636 //
642 clearDamageForAllSurfaces(root.get()); 637 clearDamageForAllSurfaces(root.get());
643 grandChild1->setOpacity(0.5); 638 grandChild1->setOpacity(0.5);
644 emulateDrawingOneFrame(root.get()); 639 emulateDrawingOneFrame(root.get());
645 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t(); 640 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t();
646 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 641 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
647 EXPECT_FLOAT_RECT_EQ(FloatRect(200, 200, 6, 8), childDamageRect); 642 EXPECT_FLOAT_RECT_EQ(gfx::RectF(200, 200, 6, 8), childDamageRect);
648 EXPECT_FLOAT_RECT_EQ(FloatRect(300, 300, 6, 8), rootDamageRect); 643 EXPECT_FLOAT_RECT_EQ(gfx::RectF(300, 300, 6, 8), rootDamageRect);
649 644
650 // CASE 2: Same as previous case, but with additional damage elsewhere that should be properly unioned. 645 // CASE 2: Same as previous case, but with additional damage elsewhere that should be properly unioned.
651 // - child1 surface damage in root surface space: FloatRect(300, 300, 6, 8); 646 // - child1 surface damage in root surface space: gfx::RectF(300, 300, 6, 8) ;
652 // - child2 damage in root surface space: FloatRect(11, 11, 18, 18); 647 // - child2 damage in root surface space: gfx::RectF(11, 11, 18, 18);
653 clearDamageForAllSurfaces(root.get()); 648 clearDamageForAllSurfaces(root.get());
654 grandChild1->setOpacity(0.7f); 649 grandChild1->setOpacity(0.7f);
655 child2->setOpacity(0.7f); 650 child2->setOpacity(0.7f);
656 emulateDrawingOneFrame(root.get()); 651 emulateDrawingOneFrame(root.get());
657 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t(); 652 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t();
658 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 653 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
659 EXPECT_FLOAT_RECT_EQ(FloatRect(200, 200, 6, 8), childDamageRect); 654 EXPECT_FLOAT_RECT_EQ(gfx::RectF(200, 200, 6, 8), childDamageRect);
660 EXPECT_FLOAT_RECT_EQ(FloatRect(11, 11, 295, 297), rootDamageRect); 655 EXPECT_FLOAT_RECT_EQ(gfx::RectF(11, 11, 295, 297), rootDamageRect);
661 } 656 }
662 657
663 TEST_F(DamageTrackerTest, verifyDamageForSurfaceChangeFromDescendantLayer) 658 TEST_F(DamageTrackerTest, verifyDamageForSurfaceChangeFromDescendantLayer)
664 { 659 {
665 // If descendant layer changes and affects the content bounds of the render surface, 660 // If descendant layer changes and affects the content bounds of the render surface,
666 // then the entire descendant surface should be damaged, and it should damag e its 661 // then the entire descendant surface should be damaged, and it should damag e its
667 // ancestor surface with the old and new surface regions. 662 // ancestor surface with the old and new surface regions.
668 663
669 // This is a tricky case, since only the first grandChild changes, but the e ntire 664 // This is a tricky case, since only the first grandChild changes, but the e ntire
670 // surface should be marked dirty. 665 // surface should be marked dirty.
671 666
672 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); 667 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
673 LayerImpl* child1 = root->children()[0]; 668 LayerImpl* child1 = root->children()[0];
674 LayerImpl* grandChild1 = root->children()[0]->children()[0]; 669 LayerImpl* grandChild1 = root->children()[0]->children()[0];
675 FloatRect childDamageRect; 670 gfx::RectF childDamageRect;
676 FloatRect rootDamageRect; 671 gfx::RectF rootDamageRect;
677 672
678 clearDamageForAllSurfaces(root.get()); 673 clearDamageForAllSurfaces(root.get());
679 grandChild1->setPosition(FloatPoint(195, 205)); 674 grandChild1->setPosition(gfx::PointF(195, 205));
680 emulateDrawingOneFrame(root.get()); 675 emulateDrawingOneFrame(root.get());
681 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t(); 676 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t();
682 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 677 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
683 678
684 // The new surface bounds should be damaged entirely, even though only one o f the layers changed. 679 // The new surface bounds should be damaged entirely, even though only one o f the layers changed.
685 EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 11, 23), childDamageRect); 680 EXPECT_FLOAT_RECT_EQ(gfx::RectF(190, 190, 11, 23), childDamageRect);
686 681
687 // Damage to the root surface should be the union of child1's *entire* rende r surface 682 // Damage to the root surface should be the union of child1's *entire* rende r surface
688 // (in target space), and its old exposed area (also in target space). 683 // (in target space), and its old exposed area (also in target space).
689 EXPECT_FLOAT_RECT_EQ(FloatRect(290, 290, 16, 23), rootDamageRect); 684 EXPECT_FLOAT_RECT_EQ(gfx::RectF(290, 290, 16, 23), rootDamageRect);
690 } 685 }
691 686
692 TEST_F(DamageTrackerTest, verifyDamageForSurfaceChangeFromAncestorLayer) 687 TEST_F(DamageTrackerTest, verifyDamageForSurfaceChangeFromAncestorLayer)
693 { 688 {
694 // An ancestor/owning layer changes that affects the position/transform of t he render 689 // An ancestor/owning layer changes that affects the position/transform of t he render
695 // surface. Note that in this case, the layerPropertyChanged flag already pr opagates 690 // surface. Note that in this case, the layerPropertyChanged flag already pr opagates
696 // to the subtree (tested in LayerImpltest), which damages the entire child1 691 // to the subtree (tested in LayerImpltest), which damages the entire child1
697 // surface, but the damage tracker still needs the correct logic to compute the 692 // surface, but the damage tracker still needs the correct logic to compute the
698 // exposed region on the root surface. 693 // exposed region on the root surface.
699 694
700 // FIXME: the expectations of this test case should change when we add suppo rt for a 695 // FIXME: the expectations of this test case should change when we add suppo rt for a
701 // unique scissorRect per renderSurface. In that case, the child1 sur face 696 // unique scissorRect per renderSurface. In that case, the child1 sur face
702 // should be completely unchanged, since we are only transforming it, while the 697 // should be completely unchanged, since we are only transforming it, while the
703 // root surface would be damaged appropriately. 698 // root surface would be damaged appropriately.
704 699
705 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); 700 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
706 LayerImpl* child1 = root->children()[0]; 701 LayerImpl* child1 = root->children()[0];
707 FloatRect childDamageRect; 702 gfx::RectF childDamageRect;
708 FloatRect rootDamageRect; 703 gfx::RectF rootDamageRect;
709 704
710 clearDamageForAllSurfaces(root.get()); 705 clearDamageForAllSurfaces(root.get());
711 child1->setPosition(FloatPoint(50, 50)); 706 child1->setPosition(gfx::PointF(50, 50));
712 emulateDrawingOneFrame(root.get()); 707 emulateDrawingOneFrame(root.get());
713 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t(); 708 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t();
714 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 709 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
715 710
716 // The new surface bounds should be damaged entirely. 711 // The new surface bounds should be damaged entirely.
717 EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 16, 18), childDamageRect); 712 EXPECT_FLOAT_RECT_EQ(gfx::RectF(190, 190, 16, 18), childDamageRect);
718 713
719 // The entire child1 surface and the old exposed child1 surface should damag e the root surface. 714 // The entire child1 surface and the old exposed child1 surface should damag e the root surface.
720 // - old child1 surface in target space: FloatRect(290, 290, 16, 18) 715 // - old child1 surface in target space: gfx::RectF(290, 290, 16, 18)
721 // - new child1 surface in target space: FloatRect(240, 240, 16, 18) 716 // - new child1 surface in target space: gfx::RectF(240, 240, 16, 18)
722 EXPECT_FLOAT_RECT_EQ(FloatRect(240, 240, 66, 68), rootDamageRect); 717 EXPECT_FLOAT_RECT_EQ(gfx::RectF(240, 240, 66, 68), rootDamageRect);
723 } 718 }
724 719
725 TEST_F(DamageTrackerTest, verifyDamageForAddingAndRemovingRenderSurfaces) 720 TEST_F(DamageTrackerTest, verifyDamageForAddingAndRemovingRenderSurfaces)
726 { 721 {
727 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); 722 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
728 LayerImpl* child1 = root->children()[0]; 723 LayerImpl* child1 = root->children()[0];
729 FloatRect childDamageRect; 724 gfx::RectF childDamageRect;
730 FloatRect rootDamageRect; 725 gfx::RectF rootDamageRect;
731 726
732 // CASE 1: If a descendant surface disappears, its entire old area becomes e xposed. 727 // CASE 1: If a descendant surface disappears, its entire old area becomes e xposed.
733 // 728 //
734 clearDamageForAllSurfaces(root.get()); 729 clearDamageForAllSurfaces(root.get());
735 child1->setOpacity(1); 730 child1->setOpacity(1);
736 emulateDrawingOneFrame(root.get()); 731 emulateDrawingOneFrame(root.get());
737 732
738 // Sanity check that there is only one surface now. 733 // Sanity check that there is only one surface now.
739 ASSERT_FALSE(child1->renderSurface()); 734 ASSERT_FALSE(child1->renderSurface());
740 ASSERT_EQ(4u, root->renderSurface()->layerList().size()); 735 ASSERT_EQ(4u, root->renderSurface()->layerList().size());
741 736
742 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 737 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
743 EXPECT_FLOAT_RECT_EQ(FloatRect(290, 290, 16, 18), rootDamageRect); 738 EXPECT_FLOAT_RECT_EQ(gfx::RectF(290, 290, 16, 18), rootDamageRect);
744 739
745 // CASE 2: If a descendant surface appears, its entire old area becomes expo sed. 740 // CASE 2: If a descendant surface appears, its entire old area becomes expo sed.
746 741
747 // Cycle one frame of no change, just to sanity check that the next rect is not because of the old damage state. 742 // Cycle one frame of no change, just to sanity check that the next rect is not because of the old damage state.
748 clearDamageForAllSurfaces(root.get()); 743 clearDamageForAllSurfaces(root.get());
749 emulateDrawingOneFrame(root.get()); 744 emulateDrawingOneFrame(root.get());
750 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 745 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
751 EXPECT_TRUE(rootDamageRect.isEmpty()); 746 EXPECT_TRUE(rootDamageRect.IsEmpty());
752 747
753 // Then change the tree so that the render surface is added back. 748 // Then change the tree so that the render surface is added back.
754 clearDamageForAllSurfaces(root.get()); 749 clearDamageForAllSurfaces(root.get());
755 child1->setOpacity(0.5); 750 child1->setOpacity(0.5);
756 emulateDrawingOneFrame(root.get()); 751 emulateDrawingOneFrame(root.get());
757 752
758 // Sanity check that there is a new surface now. 753 // Sanity check that there is a new surface now.
759 ASSERT_TRUE(child1->renderSurface()); 754 ASSERT_TRUE(child1->renderSurface());
760 EXPECT_EQ(3u, root->renderSurface()->layerList().size()); 755 EXPECT_EQ(3u, root->renderSurface()->layerList().size());
761 EXPECT_EQ(2u, child1->renderSurface()->layerList().size()); 756 EXPECT_EQ(2u, child1->renderSurface()->layerList().size());
762 757
763 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t(); 758 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t();
764 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 759 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
765 EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 16, 18), childDamageRect); 760 EXPECT_FLOAT_RECT_EQ(gfx::RectF(190, 190, 16, 18), childDamageRect);
766 EXPECT_FLOAT_RECT_EQ(FloatRect(290, 290, 16, 18), rootDamageRect); 761 EXPECT_FLOAT_RECT_EQ(gfx::RectF(290, 290, 16, 18), rootDamageRect);
767 } 762 }
768 763
769 TEST_F(DamageTrackerTest, verifyNoDamageWhenNothingChanged) 764 TEST_F(DamageTrackerTest, verifyNoDamageWhenNothingChanged)
770 { 765 {
771 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); 766 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
772 LayerImpl* child1 = root->children()[0]; 767 LayerImpl* child1 = root->children()[0];
773 FloatRect childDamageRect; 768 gfx::RectF childDamageRect;
774 FloatRect rootDamageRect; 769 gfx::RectF rootDamageRect;
775 770
776 // CASE 1: If nothing changes, the damage rect should be empty. 771 // CASE 1: If nothing changes, the damage rect should be empty.
777 // 772 //
778 clearDamageForAllSurfaces(root.get()); 773 clearDamageForAllSurfaces(root.get());
779 emulateDrawingOneFrame(root.get()); 774 emulateDrawingOneFrame(root.get());
780 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t(); 775 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t();
781 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 776 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
782 EXPECT_TRUE(childDamageRect.isEmpty()); 777 EXPECT_TRUE(childDamageRect.IsEmpty());
783 EXPECT_TRUE(rootDamageRect.isEmpty()); 778 EXPECT_TRUE(rootDamageRect.IsEmpty());
784 779
785 // CASE 2: If nothing changes twice in a row, the damage rect should still b e empty. 780 // CASE 2: If nothing changes twice in a row, the damage rect should still b e empty.
786 // 781 //
787 clearDamageForAllSurfaces(root.get()); 782 clearDamageForAllSurfaces(root.get());
788 emulateDrawingOneFrame(root.get()); 783 emulateDrawingOneFrame(root.get());
789 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t(); 784 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t();
790 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 785 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
791 EXPECT_TRUE(childDamageRect.isEmpty()); 786 EXPECT_TRUE(childDamageRect.IsEmpty());
792 EXPECT_TRUE(rootDamageRect.isEmpty()); 787 EXPECT_TRUE(rootDamageRect.IsEmpty());
793 } 788 }
794 789
795 TEST_F(DamageTrackerTest, verifyNoDamageForUpdateRectThatDoesNotDrawContent) 790 TEST_F(DamageTrackerTest, verifyNoDamageForUpdateRectThatDoesNotDrawContent)
796 { 791 {
797 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); 792 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
798 LayerImpl* child1 = root->children()[0]; 793 LayerImpl* child1 = root->children()[0];
799 FloatRect childDamageRect; 794 gfx::RectF childDamageRect;
800 FloatRect rootDamageRect; 795 gfx::RectF rootDamageRect;
801 796
802 // In our specific tree, the update rect of child1 should not cause any dama ge to any 797 // In our specific tree, the update rect of child1 should not cause any dama ge to any
803 // surface because it does not actually draw content. 798 // surface because it does not actually draw content.
804 clearDamageForAllSurfaces(root.get()); 799 clearDamageForAllSurfaces(root.get());
805 child1->setUpdateRect(FloatRect(0, 0, 1, 2)); 800 child1->setUpdateRect(gfx::RectF(0, 0, 1, 2));
806 emulateDrawingOneFrame(root.get()); 801 emulateDrawingOneFrame(root.get());
807 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t(); 802 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t();
808 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 803 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
809 EXPECT_TRUE(childDamageRect.isEmpty()); 804 EXPECT_TRUE(childDamageRect.IsEmpty());
810 EXPECT_TRUE(rootDamageRect.isEmpty()); 805 EXPECT_TRUE(rootDamageRect.IsEmpty());
811 } 806 }
812 807
813 TEST_F(DamageTrackerTest, verifyDamageForReplica) 808 TEST_F(DamageTrackerTest, verifyDamageForReplica)
814 { 809 {
815 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); 810 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
816 LayerImpl* child1 = root->children()[0]; 811 LayerImpl* child1 = root->children()[0];
817 LayerImpl* grandChild1 = child1->children()[0]; 812 LayerImpl* grandChild1 = child1->children()[0];
818 LayerImpl* grandChild2 = child1->children()[1]; 813 LayerImpl* grandChild2 = child1->children()[1];
819 814
820 // Damage on a surface that has a reflection should cause the target surface to 815 // Damage on a surface that has a reflection should cause the target surface to
821 // receive the surface's damage and the surface's reflected damage. 816 // receive the surface's damage and the surface's reflected damage.
822 817
823 // For this test case, we modify grandChild2, and add grandChild3 to extend the bounds 818 // For this test case, we modify grandChild2, and add grandChild3 to extend the bounds
824 // of child1's surface. This way, we can test reflection changes without cha nging 819 // of child1's surface. This way, we can test reflection changes without cha nging
825 // contentBounds of the surface. 820 // contentBounds of the surface.
826 grandChild2->setPosition(FloatPoint(180, 180)); 821 grandChild2->setPosition(gfx::PointF(180, 180));
827 { 822 {
828 scoped_ptr<LayerImpl> grandChild3 = LayerImpl::create(6); 823 scoped_ptr<LayerImpl> grandChild3 = LayerImpl::create(6);
829 grandChild3->setPosition(FloatPoint(240, 240)); 824 grandChild3->setPosition(gfx::PointF(240, 240));
830 grandChild3->setAnchorPoint(FloatPoint::zero()); 825 grandChild3->setAnchorPoint(gfx::PointF());
831 grandChild3->setBounds(IntSize(10, 10)); 826 grandChild3->setBounds(gfx::Size(10, 10));
832 grandChild3->setContentBounds(IntSize(10, 10)); 827 grandChild3->setContentBounds(gfx::Size(10, 10));
833 grandChild3->setDrawsContent(true); 828 grandChild3->setDrawsContent(true);
834 child1->addChild(grandChild3.Pass()); 829 child1->addChild(grandChild3.Pass());
835 } 830 }
836 child1->setOpacity(0.5); 831 child1->setOpacity(0.5);
837 emulateDrawingOneFrame(root.get()); 832 emulateDrawingOneFrame(root.get());
838 833
839 // CASE 1: adding a reflection about the left edge of grandChild1. 834 // CASE 1: adding a reflection about the left edge of grandChild1.
840 // 835 //
841 clearDamageForAllSurfaces(root.get()); 836 clearDamageForAllSurfaces(root.get());
842 { 837 {
843 scoped_ptr<LayerImpl> grandChild1Replica = LayerImpl::create(7); 838 scoped_ptr<LayerImpl> grandChild1Replica = LayerImpl::create(7);
844 grandChild1Replica->setPosition(FloatPoint::zero()); 839 grandChild1Replica->setPosition(gfx::PointF());
845 grandChild1Replica->setAnchorPoint(FloatPoint::zero()); 840 grandChild1Replica->setAnchorPoint(gfx::PointF());
846 WebTransformationMatrix reflection; 841 WebTransformationMatrix reflection;
847 reflection.scale3d(-1, 1, 1); 842 reflection.scale3d(-1, 1, 1);
848 grandChild1Replica->setTransform(reflection); 843 grandChild1Replica->setTransform(reflection);
849 grandChild1->setReplicaLayer(grandChild1Replica.Pass()); 844 grandChild1->setReplicaLayer(grandChild1Replica.Pass());
850 } 845 }
851 emulateDrawingOneFrame(root.get()); 846 emulateDrawingOneFrame(root.get());
852 847
853 FloatRect grandChildDamageRect = grandChild1->renderSurface()->damageTracker ()->currentDamageRect(); 848 gfx::RectF grandChildDamageRect = grandChild1->renderSurface()->damageTracke r()->currentDamageRect();
854 FloatRect childDamageRect = child1->renderSurface()->damageTracker()->curren tDamageRect(); 849 gfx::RectF childDamageRect = child1->renderSurface()->damageTracker()->curre ntDamageRect();
855 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa mageRect(); 850 gfx::RectF rootDamageRect = root->renderSurface()->damageTracker()->currentD amageRect();
856 851
857 // The grandChild surface damage should not include its own replica. The chi ld 852 // The grandChild surface damage should not include its own replica. The chi ld
858 // surface damage should include the normal and replica surfaces. 853 // surface damage should include the normal and replica surfaces.
859 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 6, 8), grandChildDamageRect); 854 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 6, 8), grandChildDamageRect);
860 EXPECT_FLOAT_RECT_EQ(FloatRect(194, 200, 12, 8), childDamageRect); 855 EXPECT_FLOAT_RECT_EQ(gfx::RectF(194, 200, 12, 8), childDamageRect);
861 EXPECT_FLOAT_RECT_EQ(FloatRect(294, 300, 12, 8), rootDamageRect); 856 EXPECT_FLOAT_RECT_EQ(gfx::RectF(294, 300, 12, 8), rootDamageRect);
862 857
863 // CASE 2: moving the descendant surface should cause both the original and reflected 858 // CASE 2: moving the descendant surface should cause both the original and reflected
864 // areas to be damaged on the target. 859 // areas to be damaged on the target.
865 clearDamageForAllSurfaces(root.get()); 860 clearDamageForAllSurfaces(root.get());
866 IntRect oldContentRect = child1->renderSurface()->contentRect(); 861 gfx::Rect oldContentRect = child1->renderSurface()->contentRect();
867 grandChild1->setPosition(FloatPoint(195, 205)); 862 grandChild1->setPosition(gfx::PointF(195, 205));
868 emulateDrawingOneFrame(root.get()); 863 emulateDrawingOneFrame(root.get());
869 ASSERT_EQ(oldContentRect.width(), child1->renderSurface()->contentRect().wid th()); 864 ASSERT_EQ(oldContentRect.width(), child1->renderSurface()->contentRect().wid th());
870 ASSERT_EQ(oldContentRect.height(), child1->renderSurface()->contentRect().he ight()); 865 ASSERT_EQ(oldContentRect.height(), child1->renderSurface()->contentRect().he ight());
871 866
872 grandChildDamageRect = grandChild1->renderSurface()->damageTracker()->curren tDamageRect(); 867 grandChildDamageRect = grandChild1->renderSurface()->damageTracker()->curren tDamageRect();
873 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t(); 868 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t();
874 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 869 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
875 870
876 // The child surface damage should include normal and replica surfaces for b oth old and new locations. 871 // The child surface damage should include normal and replica surfaces for b oth old and new locations.
877 // - old location in target space: FloatRect(194, 200, 12, 8) 872 // - old location in target space: gfx::RectF(194, 200, 12, 8)
878 // - new location in target space: FloatRect(189, 205, 12, 8) 873 // - new location in target space: gfx::RectF(189, 205, 12, 8)
879 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 6, 8), grandChildDamageRect); 874 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 6, 8), grandChildDamageRect);
880 EXPECT_FLOAT_RECT_EQ(FloatRect(189, 200, 17, 13), childDamageRect); 875 EXPECT_FLOAT_RECT_EQ(gfx::RectF(189, 200, 17, 13), childDamageRect);
881 EXPECT_FLOAT_RECT_EQ(FloatRect(289, 300, 17, 13), rootDamageRect); 876 EXPECT_FLOAT_RECT_EQ(gfx::RectF(289, 300, 17, 13), rootDamageRect);
882 877
883 // CASE 3: removing the reflection should cause the entire region including reflection 878 // CASE 3: removing the reflection should cause the entire region including reflection
884 // to damage the target surface. 879 // to damage the target surface.
885 clearDamageForAllSurfaces(root.get()); 880 clearDamageForAllSurfaces(root.get());
886 grandChild1->setReplicaLayer(scoped_ptr<LayerImpl>()); 881 grandChild1->setReplicaLayer(scoped_ptr<LayerImpl>());
887 emulateDrawingOneFrame(root.get()); 882 emulateDrawingOneFrame(root.get());
888 ASSERT_EQ(oldContentRect.width(), child1->renderSurface()->contentRect().wid th()); 883 ASSERT_EQ(oldContentRect.width(), child1->renderSurface()->contentRect().wid th());
889 ASSERT_EQ(oldContentRect.height(), child1->renderSurface()->contentRect().he ight()); 884 ASSERT_EQ(oldContentRect.height(), child1->renderSurface()->contentRect().he ight());
890 885
891 EXPECT_FALSE(grandChild1->renderSurface()); 886 EXPECT_FALSE(grandChild1->renderSurface());
892 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t(); 887 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t();
893 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 888 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
894 889
895 EXPECT_FLOAT_RECT_EQ(FloatRect(189, 205, 12, 8), childDamageRect); 890 EXPECT_FLOAT_RECT_EQ(gfx::RectF(189, 205, 12, 8), childDamageRect);
896 EXPECT_FLOAT_RECT_EQ(FloatRect(289, 305, 12, 8), rootDamageRect); 891 EXPECT_FLOAT_RECT_EQ(gfx::RectF(289, 305, 12, 8), rootDamageRect);
897 } 892 }
898 893
899 TEST_F(DamageTrackerTest, verifyDamageForMask) 894 TEST_F(DamageTrackerTest, verifyDamageForMask)
900 { 895 {
901 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); 896 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface();
902 LayerImpl* child = root->children()[0]; 897 LayerImpl* child = root->children()[0];
903 898
904 // In the current implementation of the damage tracker, changes to mask laye rs should 899 // In the current implementation of the damage tracker, changes to mask laye rs should
905 // damage the entire corresponding surface. 900 // damage the entire corresponding surface.
906 901
907 clearDamageForAllSurfaces(root.get()); 902 clearDamageForAllSurfaces(root.get());
908 903
909 // Set up the mask layer. 904 // Set up the mask layer.
910 { 905 {
911 scoped_ptr<LayerImpl> maskLayer = LayerImpl::create(3); 906 scoped_ptr<LayerImpl> maskLayer = LayerImpl::create(3);
912 maskLayer->setPosition(child->position()); 907 maskLayer->setPosition(child->position());
913 maskLayer->setAnchorPoint(FloatPoint::zero()); 908 maskLayer->setAnchorPoint(gfx::PointF());
914 maskLayer->setBounds(child->bounds()); 909 maskLayer->setBounds(child->bounds());
915 maskLayer->setContentBounds(child->bounds()); 910 maskLayer->setContentBounds(child->bounds());
916 child->setMaskLayer(maskLayer.Pass()); 911 child->setMaskLayer(maskLayer.Pass());
917 } 912 }
918 LayerImpl* maskLayer = child->maskLayer(); 913 LayerImpl* maskLayer = child->maskLayer();
919 914
920 // Add opacity and a grandChild so that the render surface persists even aft er we remove the mask. 915 // Add opacity and a grandChild so that the render surface persists even aft er we remove the mask.
921 child->setOpacity(0.5); 916 child->setOpacity(0.5);
922 { 917 {
923 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(4); 918 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(4);
924 grandChild->setPosition(FloatPoint(2, 2)); 919 grandChild->setPosition(gfx::PointF(2, 2));
925 grandChild->setAnchorPoint(FloatPoint::zero()); 920 grandChild->setAnchorPoint(gfx::PointF());
926 grandChild->setBounds(IntSize(2, 2)); 921 grandChild->setBounds(gfx::Size(2, 2));
927 grandChild->setContentBounds(IntSize(2, 2)); 922 grandChild->setContentBounds(gfx::Size(2, 2));
928 grandChild->setDrawsContent(true); 923 grandChild->setDrawsContent(true);
929 child->addChild(grandChild.Pass()); 924 child->addChild(grandChild.Pass());
930 } 925 }
931 emulateDrawingOneFrame(root.get()); 926 emulateDrawingOneFrame(root.get());
932 927
933 // Sanity check that a new surface was created for the child. 928 // Sanity check that a new surface was created for the child.
934 ASSERT_TRUE(child->renderSurface()); 929 ASSERT_TRUE(child->renderSurface());
935 930
936 // CASE 1: the updateRect on a mask layer should damage the entire target su rface. 931 // CASE 1: the updateRect on a mask layer should damage the entire target su rface.
937 // 932 //
938 clearDamageForAllSurfaces(root.get()); 933 clearDamageForAllSurfaces(root.get());
939 maskLayer->setUpdateRect(FloatRect(1, 2, 3, 4)); 934 maskLayer->setUpdateRect(gfx::RectF(1, 2, 3, 4));
940 emulateDrawingOneFrame(root.get()); 935 emulateDrawingOneFrame(root.get());
941 FloatRect childDamageRect = child->renderSurface()->damageTracker()->current DamageRect(); 936 gfx::RectF childDamageRect = child->renderSurface()->damageTracker()->curren tDamageRect();
942 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 30), childDamageRect); 937 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 30, 30), childDamageRect);
943 938
944 // CASE 2: a property change on the mask layer should damage the entire targ et surface. 939 // CASE 2: a property change on the mask layer should damage the entire targ et surface.
945 // 940 //
946 941
947 // Advance one frame without damage so that we know the damage rect is not l eftover from the previous case. 942 // Advance one frame without damage so that we know the damage rect is not l eftover from the previous case.
948 clearDamageForAllSurfaces(root.get()); 943 clearDamageForAllSurfaces(root.get());
949 emulateDrawingOneFrame(root.get()); 944 emulateDrawingOneFrame(root.get());
950 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect (); 945 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect ();
951 EXPECT_TRUE(childDamageRect.isEmpty()); 946 EXPECT_TRUE(childDamageRect.IsEmpty());
952 947
953 // Then test the property change. 948 // Then test the property change.
954 clearDamageForAllSurfaces(root.get()); 949 clearDamageForAllSurfaces(root.get());
955 maskLayer->setStackingOrderChanged(true); 950 maskLayer->setStackingOrderChanged(true);
956 951
957 emulateDrawingOneFrame(root.get()); 952 emulateDrawingOneFrame(root.get());
958 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect (); 953 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect ();
959 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 30), childDamageRect); 954 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 30, 30), childDamageRect);
960 955
961 // CASE 3: removing the mask also damages the entire target surface. 956 // CASE 3: removing the mask also damages the entire target surface.
962 // 957 //
963 958
964 // Advance one frame without damage so that we know the damage rect is not l eftover from the previous case. 959 // Advance one frame without damage so that we know the damage rect is not l eftover from the previous case.
965 clearDamageForAllSurfaces(root.get()); 960 clearDamageForAllSurfaces(root.get());
966 emulateDrawingOneFrame(root.get()); 961 emulateDrawingOneFrame(root.get());
967 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect (); 962 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect ();
968 EXPECT_TRUE(childDamageRect.isEmpty()); 963 EXPECT_TRUE(childDamageRect.IsEmpty());
969 964
970 // Then test mask removal. 965 // Then test mask removal.
971 clearDamageForAllSurfaces(root.get()); 966 clearDamageForAllSurfaces(root.get());
972 child->setMaskLayer(scoped_ptr<LayerImpl>()); 967 child->setMaskLayer(scoped_ptr<LayerImpl>());
973 ASSERT_TRUE(child->layerPropertyChanged()); 968 ASSERT_TRUE(child->layerPropertyChanged());
974 emulateDrawingOneFrame(root.get()); 969 emulateDrawingOneFrame(root.get());
975 970
976 // Sanity check that a render surface still exists. 971 // Sanity check that a render surface still exists.
977 ASSERT_TRUE(child->renderSurface()); 972 ASSERT_TRUE(child->renderSurface());
978 973
979 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect (); 974 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect ();
980 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 30), childDamageRect); 975 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 30, 30), childDamageRect);
981 } 976 }
982 977
983 TEST_F(DamageTrackerTest, verifyDamageForReplicaMask) 978 TEST_F(DamageTrackerTest, verifyDamageForReplicaMask)
984 { 979 {
985 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); 980 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
986 LayerImpl* child1 = root->children()[0]; 981 LayerImpl* child1 = root->children()[0];
987 LayerImpl* grandChild1 = child1->children()[0]; 982 LayerImpl* grandChild1 = child1->children()[0];
988 983
989 // Changes to a replica's mask should not damage the original surface, becau se it is 984 // Changes to a replica's mask should not damage the original surface, becau se it is
990 // not masked. But it does damage the ancestor target surface. 985 // not masked. But it does damage the ancestor target surface.
991 986
992 clearDamageForAllSurfaces(root.get()); 987 clearDamageForAllSurfaces(root.get());
993 988
994 // Create a reflection about the left edge of grandChild1. 989 // Create a reflection about the left edge of grandChild1.
995 { 990 {
996 scoped_ptr<LayerImpl> grandChild1Replica = LayerImpl::create(6); 991 scoped_ptr<LayerImpl> grandChild1Replica = LayerImpl::create(6);
997 grandChild1Replica->setPosition(FloatPoint::zero()); 992 grandChild1Replica->setPosition(gfx::PointF());
998 grandChild1Replica->setAnchorPoint(FloatPoint::zero()); 993 grandChild1Replica->setAnchorPoint(gfx::PointF());
999 WebTransformationMatrix reflection; 994 WebTransformationMatrix reflection;
1000 reflection.scale3d(-1, 1, 1); 995 reflection.scale3d(-1, 1, 1);
1001 grandChild1Replica->setTransform(reflection); 996 grandChild1Replica->setTransform(reflection);
1002 grandChild1->setReplicaLayer(grandChild1Replica.Pass()); 997 grandChild1->setReplicaLayer(grandChild1Replica.Pass());
1003 } 998 }
1004 LayerImpl* grandChild1Replica = grandChild1->replicaLayer(); 999 LayerImpl* grandChild1Replica = grandChild1->replicaLayer();
1005 1000
1006 // Set up the mask layer on the replica layer 1001 // Set up the mask layer on the replica layer
1007 { 1002 {
1008 scoped_ptr<LayerImpl> replicaMaskLayer = LayerImpl::create(7); 1003 scoped_ptr<LayerImpl> replicaMaskLayer = LayerImpl::create(7);
1009 replicaMaskLayer->setPosition(FloatPoint::zero()); 1004 replicaMaskLayer->setPosition(gfx::PointF());
1010 replicaMaskLayer->setAnchorPoint(FloatPoint::zero()); 1005 replicaMaskLayer->setAnchorPoint(gfx::PointF());
1011 replicaMaskLayer->setBounds(grandChild1->bounds()); 1006 replicaMaskLayer->setBounds(grandChild1->bounds());
1012 replicaMaskLayer->setContentBounds(grandChild1->bounds()); 1007 replicaMaskLayer->setContentBounds(grandChild1->bounds());
1013 grandChild1Replica->setMaskLayer(replicaMaskLayer.Pass()); 1008 grandChild1Replica->setMaskLayer(replicaMaskLayer.Pass());
1014 } 1009 }
1015 LayerImpl* replicaMaskLayer = grandChild1Replica->maskLayer(); 1010 LayerImpl* replicaMaskLayer = grandChild1Replica->maskLayer();
1016 1011
1017 emulateDrawingOneFrame(root.get()); 1012 emulateDrawingOneFrame(root.get());
1018 1013
1019 // Sanity check that the appropriate render surfaces were created 1014 // Sanity check that the appropriate render surfaces were created
1020 ASSERT_TRUE(grandChild1->renderSurface()); 1015 ASSERT_TRUE(grandChild1->renderSurface());
1021 1016
1022 // CASE 1: a property change on the mask should damage only the reflected re gion on the target surface. 1017 // CASE 1: a property change on the mask should damage only the reflected re gion on the target surface.
1023 clearDamageForAllSurfaces(root.get()); 1018 clearDamageForAllSurfaces(root.get());
1024 replicaMaskLayer->setStackingOrderChanged(true); 1019 replicaMaskLayer->setStackingOrderChanged(true);
1025 emulateDrawingOneFrame(root.get()); 1020 emulateDrawingOneFrame(root.get());
1026 1021
1027 FloatRect grandChildDamageRect = grandChild1->renderSurface()->damageTracker ()->currentDamageRect(); 1022 gfx::RectF grandChildDamageRect = grandChild1->renderSurface()->damageTracke r()->currentDamageRect();
1028 FloatRect childDamageRect = child1->renderSurface()->damageTracker()->curren tDamageRect(); 1023 gfx::RectF childDamageRect = child1->renderSurface()->damageTracker()->curre ntDamageRect();
1029 1024
1030 EXPECT_TRUE(grandChildDamageRect.isEmpty()); 1025 EXPECT_TRUE(grandChildDamageRect.IsEmpty());
1031 EXPECT_FLOAT_RECT_EQ(FloatRect(194, 200, 6, 8), childDamageRect); 1026 EXPECT_FLOAT_RECT_EQ(gfx::RectF(194, 200, 6, 8), childDamageRect);
1032 1027
1033 // CASE 2: removing the replica mask damages only the reflected region on th e target surface. 1028 // CASE 2: removing the replica mask damages only the reflected region on th e target surface.
1034 // 1029 //
1035 clearDamageForAllSurfaces(root.get()); 1030 clearDamageForAllSurfaces(root.get());
1036 grandChild1Replica->setMaskLayer(scoped_ptr<LayerImpl>()); 1031 grandChild1Replica->setMaskLayer(scoped_ptr<LayerImpl>());
1037 emulateDrawingOneFrame(root.get()); 1032 emulateDrawingOneFrame(root.get());
1038 1033
1039 grandChildDamageRect = grandChild1->renderSurface()->damageTracker()->curren tDamageRect(); 1034 grandChildDamageRect = grandChild1->renderSurface()->damageTracker()->curren tDamageRect();
1040 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t(); 1035 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec t();
1041 1036
1042 EXPECT_TRUE(grandChildDamageRect.isEmpty()); 1037 EXPECT_TRUE(grandChildDamageRect.IsEmpty());
1043 EXPECT_FLOAT_RECT_EQ(FloatRect(194, 200, 6, 8), childDamageRect); 1038 EXPECT_FLOAT_RECT_EQ(gfx::RectF(194, 200, 6, 8), childDamageRect);
1044 } 1039 }
1045 1040
1046 TEST_F(DamageTrackerTest, verifyDamageForReplicaMaskWithAnchor) 1041 TEST_F(DamageTrackerTest, verifyDamageForReplicaMaskWithAnchor)
1047 { 1042 {
1048 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); 1043 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
1049 LayerImpl* child1 = root->children()[0]; 1044 LayerImpl* child1 = root->children()[0];
1050 LayerImpl* grandChild1 = child1->children()[0]; 1045 LayerImpl* grandChild1 = child1->children()[0];
1051 1046
1052 // Verify that the correct replicaOriginTransform is used for the replicaMas k; 1047 // Verify that the correct replicaOriginTransform is used for the replicaMas k;
1053 clearDamageForAllSurfaces(root.get()); 1048 clearDamageForAllSurfaces(root.get());
1054 1049
1055 grandChild1->setAnchorPoint(FloatPoint(1, 0)); // This is not exactly the an chor being tested, but by convention its expected to be the same as the replica' s anchor point. 1050 grandChild1->setAnchorPoint(gfx::PointF(1, 0)); // This is not exactly the a nchor being tested, but by convention its expected to be the same as the replica 's anchor point.
1056 1051
1057 { 1052 {
1058 scoped_ptr<LayerImpl> grandChild1Replica = LayerImpl::create(6); 1053 scoped_ptr<LayerImpl> grandChild1Replica = LayerImpl::create(6);
1059 grandChild1Replica->setPosition(FloatPoint::zero()); 1054 grandChild1Replica->setPosition(gfx::PointF());
1060 grandChild1Replica->setAnchorPoint(FloatPoint(1, 0)); // This is the anc hor being tested. 1055 grandChild1Replica->setAnchorPoint(gfx::PointF(1, 0)); // This is the an chor being tested.
1061 WebTransformationMatrix reflection; 1056 WebTransformationMatrix reflection;
1062 reflection.scale3d(-1, 1, 1); 1057 reflection.scale3d(-1, 1, 1);
1063 grandChild1Replica->setTransform(reflection); 1058 grandChild1Replica->setTransform(reflection);
1064 grandChild1->setReplicaLayer(grandChild1Replica.Pass()); 1059 grandChild1->setReplicaLayer(grandChild1Replica.Pass());
1065 } 1060 }
1066 LayerImpl* grandChild1Replica = grandChild1->replicaLayer(); 1061 LayerImpl* grandChild1Replica = grandChild1->replicaLayer();
1067 1062
1068 // Set up the mask layer on the replica layer 1063 // Set up the mask layer on the replica layer
1069 { 1064 {
1070 scoped_ptr<LayerImpl> replicaMaskLayer = LayerImpl::create(7); 1065 scoped_ptr<LayerImpl> replicaMaskLayer = LayerImpl::create(7);
1071 replicaMaskLayer->setPosition(FloatPoint::zero()); 1066 replicaMaskLayer->setPosition(gfx::PointF());
1072 replicaMaskLayer->setAnchorPoint(FloatPoint::zero()); // note, this is n ot the anchor being tested. 1067 replicaMaskLayer->setAnchorPoint(gfx::PointF()); // note, this is not th e anchor being tested.
1073 replicaMaskLayer->setBounds(grandChild1->bounds()); 1068 replicaMaskLayer->setBounds(grandChild1->bounds());
1074 replicaMaskLayer->setContentBounds(grandChild1->bounds()); 1069 replicaMaskLayer->setContentBounds(grandChild1->bounds());
1075 grandChild1Replica->setMaskLayer(replicaMaskLayer.Pass()); 1070 grandChild1Replica->setMaskLayer(replicaMaskLayer.Pass());
1076 } 1071 }
1077 LayerImpl* replicaMaskLayer = grandChild1Replica->maskLayer(); 1072 LayerImpl* replicaMaskLayer = grandChild1Replica->maskLayer();
1078 1073
1079 emulateDrawingOneFrame(root.get()); 1074 emulateDrawingOneFrame(root.get());
1080 1075
1081 // Sanity check that the appropriate render surfaces were created 1076 // Sanity check that the appropriate render surfaces were created
1082 ASSERT_TRUE(grandChild1->renderSurface()); 1077 ASSERT_TRUE(grandChild1->renderSurface());
1083 1078
1084 // A property change on the replicaMask should damage the reflected region o n the target surface. 1079 // A property change on the replicaMask should damage the reflected region o n the target surface.
1085 clearDamageForAllSurfaces(root.get()); 1080 clearDamageForAllSurfaces(root.get());
1086 replicaMaskLayer->setStackingOrderChanged(true); 1081 replicaMaskLayer->setStackingOrderChanged(true);
1087 1082
1088 emulateDrawingOneFrame(root.get()); 1083 emulateDrawingOneFrame(root.get());
1089 1084
1090 FloatRect childDamageRect = child1->renderSurface()->damageTracker()->curren tDamageRect(); 1085 gfx::RectF childDamageRect = child1->renderSurface()->damageTracker()->curre ntDamageRect();
1091 EXPECT_FLOAT_RECT_EQ(FloatRect(206, 200, 6, 8), childDamageRect); 1086 EXPECT_FLOAT_RECT_EQ(gfx::RectF(206, 200, 6, 8), childDamageRect);
1092 } 1087 }
1093 1088
1094 TEST_F(DamageTrackerTest, verifyDamageWhenForcedFullDamage) 1089 TEST_F(DamageTrackerTest, verifyDamageWhenForcedFullDamage)
1095 { 1090 {
1096 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); 1091 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface();
1097 LayerImpl* child = root->children()[0]; 1092 LayerImpl* child = root->children()[0];
1098 1093
1099 // Case 1: This test ensures that when the tracker is forced to have full da mage, that 1094 // Case 1: This test ensures that when the tracker is forced to have full da mage, that
1100 // it takes priority over any other partial damage. 1095 // it takes priority over any other partial damage.
1101 // 1096 //
1102 clearDamageForAllSurfaces(root.get()); 1097 clearDamageForAllSurfaces(root.get());
1103 child->setUpdateRect(FloatRect(10, 11, 12, 13)); 1098 child->setUpdateRect(gfx::RectF(10, 11, 12, 13));
1104 root->renderSurface()->damageTracker()->forceFullDamageNextUpdate(); 1099 root->renderSurface()->damageTracker()->forceFullDamageNextUpdate();
1105 emulateDrawingOneFrame(root.get()); 1100 emulateDrawingOneFrame(root.get());
1106 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa mageRect(); 1101 gfx::RectF rootDamageRect = root->renderSurface()->damageTracker()->currentD amageRect();
1107 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect); 1102 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 500, 500), rootDamageRect);
1108 1103
1109 // Case 2: An additional sanity check that forcing full damage works even wh en nothing 1104 // Case 2: An additional sanity check that forcing full damage works even wh en nothing
1110 // on the layer tree changed. 1105 // on the layer tree changed.
1111 // 1106 //
1112 clearDamageForAllSurfaces(root.get()); 1107 clearDamageForAllSurfaces(root.get());
1113 root->renderSurface()->damageTracker()->forceFullDamageNextUpdate(); 1108 root->renderSurface()->damageTracker()->forceFullDamageNextUpdate();
1114 emulateDrawingOneFrame(root.get()); 1109 emulateDrawingOneFrame(root.get());
1115 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 1110 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
1116 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect); 1111 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 500, 500), rootDamageRect);
1117 } 1112 }
1118 1113
1119 TEST_F(DamageTrackerTest, verifyDamageForEmptyLayerList) 1114 TEST_F(DamageTrackerTest, verifyDamageForEmptyLayerList)
1120 { 1115 {
1121 // Though it should never happen, its a good idea to verify that the damage tracker 1116 // Though it should never happen, its a good idea to verify that the damage tracker
1122 // does not crash when it receives an empty layerList. 1117 // does not crash when it receives an empty layerList.
1123 1118
1124 scoped_ptr<LayerImpl> root = LayerImpl::create(1); 1119 scoped_ptr<LayerImpl> root = LayerImpl::create(1);
1125 root->createRenderSurface(); 1120 root->createRenderSurface();
1126 1121
1127 ASSERT_TRUE(root == root->renderTarget()); 1122 ASSERT_TRUE(root == root->renderTarget());
1128 RenderSurfaceImpl* targetSurface = root->renderSurface(); 1123 RenderSurfaceImpl* targetSurface = root->renderSurface();
1129 targetSurface->clearLayerLists(); 1124 targetSurface->clearLayerLists();
1130 targetSurface->damageTracker()->updateDamageTrackingState(targetSurface->lay erList(), targetSurface->owningLayerId(), false, IntRect(), 0, WebFilterOperatio ns(), 0); 1125 targetSurface->damageTracker()->updateDamageTrackingState(targetSurface->lay erList(), targetSurface->owningLayerId(), false, gfx::Rect(), 0, WebFilterOperat ions(), 0);
1131 1126
1132 FloatRect damageRect = targetSurface->damageTracker()->currentDamageRect(); 1127 gfx::RectF damageRect = targetSurface->damageTracker()->currentDamageRect();
1133 EXPECT_TRUE(damageRect.isEmpty()); 1128 EXPECT_TRUE(damageRect.IsEmpty());
1134 } 1129 }
1135 1130
1136 TEST_F(DamageTrackerTest, verifyDamageAccumulatesUntilReset) 1131 TEST_F(DamageTrackerTest, verifyDamageAccumulatesUntilReset)
1137 { 1132 {
1138 // If damage is not cleared, it should accumulate. 1133 // If damage is not cleared, it should accumulate.
1139 1134
1140 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); 1135 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface();
1141 LayerImpl* child = root->children()[0]; 1136 LayerImpl* child = root->children()[0];
1142 1137
1143 clearDamageForAllSurfaces(root.get()); 1138 clearDamageForAllSurfaces(root.get());
1144 child->setUpdateRect(FloatRect(10, 11, 1, 2)); 1139 child->setUpdateRect(gfx::RectF(10, 11, 1, 2));
1145 emulateDrawingOneFrame(root.get()); 1140 emulateDrawingOneFrame(root.get());
1146 1141
1147 // Sanity check damage after the first frame; this isnt the actual test yet. 1142 // Sanity check damage after the first frame; this isnt the actual test yet.
1148 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa mageRect(); 1143 gfx::RectF rootDamageRect = root->renderSurface()->damageTracker()->currentD amageRect();
1149 EXPECT_FLOAT_RECT_EQ(FloatRect(110, 111, 1, 2), rootDamageRect); 1144 EXPECT_FLOAT_RECT_EQ(gfx::RectF(110, 111, 1, 2), rootDamageRect);
1150 1145
1151 // New damage, without having cleared the previous damage, should be unioned to the previous one. 1146 // New damage, without having cleared the previous damage, should be unioned to the previous one.
1152 child->setUpdateRect(FloatRect(20, 25, 1, 2)); 1147 child->setUpdateRect(gfx::RectF(20, 25, 1, 2));
1153 emulateDrawingOneFrame(root.get()); 1148 emulateDrawingOneFrame(root.get());
1154 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 1149 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
1155 EXPECT_FLOAT_RECT_EQ(FloatRect(110, 111, 11, 16), rootDamageRect); 1150 EXPECT_FLOAT_RECT_EQ(gfx::RectF(110, 111, 11, 16), rootDamageRect);
1156 1151
1157 // If we notify the damage tracker that we drew the damaged area, then damag e should be emptied. 1152 // If we notify the damage tracker that we drew the damaged area, then damag e should be emptied.
1158 root->renderSurface()->damageTracker()->didDrawDamagedArea(); 1153 root->renderSurface()->damageTracker()->didDrawDamagedArea();
1159 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 1154 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
1160 EXPECT_TRUE(rootDamageRect.isEmpty()); 1155 EXPECT_TRUE(rootDamageRect.IsEmpty());
1161 1156
1162 // Damage should remain empty even after one frame, since there's yet no new damage 1157 // Damage should remain empty even after one frame, since there's yet no new damage
1163 emulateDrawingOneFrame(root.get()); 1158 emulateDrawingOneFrame(root.get());
1164 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; 1159 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ;
1165 EXPECT_TRUE(rootDamageRect.isEmpty()); 1160 EXPECT_TRUE(rootDamageRect.IsEmpty());
1166 } 1161 }
1167 1162
1168 } // namespace 1163 } // namespace
OLDNEW
« no previous file with comments | « cc/damage_tracker.cc ('k') | cc/debug_rect_history.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698