OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/trees/damage_tracker.h" | 5 #include "cc/trees/damage_tracker.h" |
6 | 6 |
7 #include "cc/base/math_util.h" | 7 #include "cc/base/math_util.h" |
8 #include "cc/layers/layer_impl.h" | 8 #include "cc/layers/layer_impl.h" |
9 #include "cc/output/filter_operation.h" | 9 #include "cc/output/filter_operation.h" |
10 #include "cc/output/filter_operations.h" | 10 #include "cc/output/filter_operations.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 child->SetUpdateRect(gfx::RectF(20.f, 25.f, 1.f, 2.f)); | 261 child->SetUpdateRect(gfx::RectF(20.f, 25.f, 1.f, 2.f)); |
262 EmulateDrawingOneFrame(root.get()); | 262 EmulateDrawingOneFrame(root.get()); |
263 | 263 |
264 // Damage position on the surface should be: position of update_rect (20, 25) | 264 // Damage position on the surface should be: position of update_rect (20, 25) |
265 // relative to the child (100, 100). | 265 // relative to the child (100, 100). |
266 root_damage_rect = | 266 root_damage_rect = |
267 root->render_surface()->damage_tracker()->current_damage_rect(); | 267 root->render_surface()->damage_tracker()->current_damage_rect(); |
268 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString()); | 268 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString()); |
269 } | 269 } |
270 | 270 |
| 271 TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) { |
| 272 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
| 273 LayerImpl* child = root->children()[0]; |
| 274 |
| 275 // CASE 1: Adding the layer damage rect should cause the corresponding damage |
| 276 // to the surface. |
| 277 ClearDamageForAllSurfaces(root.get()); |
| 278 child->AddDamageRect(gfx::RectF(10.f, 11.f, 12.f, 13.f)); |
| 279 EmulateDrawingOneFrame(root.get()); |
| 280 |
| 281 // Damage position on the surface should be: position of layer damage_rect |
| 282 // (10, 11) relative to the child (100, 100). |
| 283 gfx::Rect root_damage_rect = |
| 284 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 285 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13))); |
| 286 |
| 287 // CASE 2: The same layer damage rect twice in a row still produces the same |
| 288 // damage. |
| 289 ClearDamageForAllSurfaces(root.get()); |
| 290 child->AddDamageRect(gfx::RectF(10.f, 11.f, 12.f, 13.f)); |
| 291 EmulateDrawingOneFrame(root.get()); |
| 292 root_damage_rect = |
| 293 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 294 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13))); |
| 295 |
| 296 // CASE 3: Adding a different layer damage rect should cause damage on the |
| 297 // new damaged region, but no additional exposed old region. |
| 298 ClearDamageForAllSurfaces(root.get()); |
| 299 child->AddDamageRect(gfx::RectF(20.f, 25.f, 1.f, 2.f)); |
| 300 EmulateDrawingOneFrame(root.get()); |
| 301 |
| 302 // Damage position on the surface should be: position of layer damage_rect |
| 303 // (20, 25) relative to the child (100, 100). |
| 304 root_damage_rect = |
| 305 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 306 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); |
| 307 |
| 308 // CASE 4: Adding multiple layer damage rects should cause a unified |
| 309 // damage on root damage rect. |
| 310 ClearDamageForAllSurfaces(root.get()); |
| 311 child->AddDamageRect(gfx::RectF(20.f, 25.f, 1.f, 2.f)); |
| 312 child->AddDamageRect(gfx::RectF(10.f, 15.f, 3.f, 4.f)); |
| 313 EmulateDrawingOneFrame(root.get()); |
| 314 |
| 315 // Damage position on the surface should be: position of layer damage_rect |
| 316 // (20, 25) relative to the child (100, 100). |
| 317 root_damage_rect = |
| 318 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 319 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); |
| 320 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4))); |
| 321 } |
| 322 |
| 323 TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) { |
| 324 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
| 325 LayerImpl* child = root->children()[0]; |
| 326 |
| 327 // CASE 1: Adding the layer damage rect and update rect should cause the |
| 328 // corresponding damage to the surface. |
| 329 ClearDamageForAllSurfaces(root.get()); |
| 330 child->AddDamageRect(gfx::RectF(5.f, 6.f, 12.f, 13.f)); |
| 331 child->SetUpdateRect(gfx::RectF(15.f, 16.f, 14.f, 10.f)); |
| 332 EmulateDrawingOneFrame(root.get()); |
| 333 |
| 334 // Damage position on the surface should be: position of unified layer |
| 335 // damage_rect and update rect (5, 6) |
| 336 // relative to the child (100, 100). |
| 337 gfx::Rect root_damage_rect = |
| 338 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 339 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 106, 24, 20))); |
| 340 |
| 341 // CASE 2: The same layer damage rect and update rect twice in a row still |
| 342 // produces the same damage. |
| 343 ClearDamageForAllSurfaces(root.get()); |
| 344 child->AddDamageRect(gfx::RectF(10.f, 11.f, 12.f, 13.f)); |
| 345 child->SetUpdateRect(gfx::RectF(10.f, 11.f, 14.f, 15.f)); |
| 346 EmulateDrawingOneFrame(root.get()); |
| 347 root_damage_rect = |
| 348 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 349 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 14, 15))); |
| 350 |
| 351 // CASE 3: Adding a different layer damage rect and update rect should cause |
| 352 // damage on the new damaged region, but no additional exposed old region. |
| 353 ClearDamageForAllSurfaces(root.get()); |
| 354 child->AddDamageRect(gfx::RectF(20.f, 25.f, 2.f, 3.f)); |
| 355 child->SetUpdateRect(gfx::RectF(5.f, 10.f, 7.f, 8.f)); |
| 356 EmulateDrawingOneFrame(root.get()); |
| 357 |
| 358 // Damage position on the surface should be: position of unified layer damage |
| 359 // rect and update rect (5, 10) relative to the child (100, 100). |
| 360 root_damage_rect = |
| 361 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 362 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18))); |
| 363 } |
| 364 |
271 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) { | 365 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) { |
272 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 366 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
273 LayerImpl* child = root->children()[0]; | 367 LayerImpl* child = root->children()[0]; |
274 | 368 |
275 // CASE 1: The layer's property changed flag takes priority over update rect. | 369 // CASE 1: The layer's property changed flag takes priority over update rect. |
276 // | 370 // |
277 ClearDamageForAllSurfaces(root.get()); | 371 ClearDamageForAllSurfaces(root.get()); |
278 child->SetUpdateRect(gfx::RectF(10.f, 11.f, 12.f, 13.f)); | 372 child->SetUpdateRect(gfx::RectF(10.f, 11.f, 12.f, 13.f)); |
279 child->SetOpacity(0.5f); | 373 child->SetOpacity(0.5f); |
280 EmulateDrawingOneFrame(root.get()); | 374 EmulateDrawingOneFrame(root.get()); |
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 gfx::Rect root_damage_rect = | 1475 gfx::Rect root_damage_rect = |
1382 root->render_surface()->damage_tracker()->current_damage_rect(); | 1476 root->render_surface()->damage_tracker()->current_damage_rect(); |
1383 gfx::Rect damage_we_care_about = gfx::Rect(i, i); | 1477 gfx::Rect damage_we_care_about = gfx::Rect(i, i); |
1384 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); | 1478 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); |
1385 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); | 1479 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); |
1386 } | 1480 } |
1387 } | 1481 } |
1388 | 1482 |
1389 } // namespace | 1483 } // namespace |
1390 } // namespace cc | 1484 } // namespace cc |
OLD | NEW |