| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/layers/layer_impl.h" | 10 #include "cc/layers/layer_impl.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // surface, so that the surface (and its damage tracker) can | 33 // surface, so that the surface (and its damage tracker) can |
| 34 // persist across multiple calls to this function. | 34 // persist across multiple calls to this function. |
| 35 ASSERT_FALSE(render_surface_layer_list->size()); | 35 ASSERT_FALSE(render_surface_layer_list->size()); |
| 36 | 36 |
| 37 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root); | 37 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root); |
| 38 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | 38 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 39 root, root->bounds(), device_scale_factor, render_surface_layer_list); | 39 root, root->bounds(), device_scale_factor, render_surface_layer_list); |
| 40 if (skip_verify_visible_rect_calculations) | 40 if (skip_verify_visible_rect_calculations) |
| 41 inputs.verify_visible_rect_calculations = false; | 41 inputs.verify_visible_rect_calculations = false; |
| 42 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | 42 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 43 ASSERT_TRUE(root->render_surface()); | 43 ASSERT_TRUE(root->GetRenderSurface()); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void ClearDamageForAllSurfaces(LayerImpl* root) { | 46 void ClearDamageForAllSurfaces(LayerImpl* root) { |
| 47 for (auto* layer : *root->layer_tree_impl()) { | 47 for (auto* layer : *root->layer_tree_impl()) { |
| 48 if (layer->render_surface()) | 48 if (layer->GetRenderSurface()) |
| 49 layer->render_surface()->damage_tracker()->DidDrawDamagedArea(); | 49 layer->GetRenderSurface()->damage_tracker()->DidDrawDamagedArea(); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 void EmulateDrawingOneFrame( | 53 void EmulateDrawingOneFrame( |
| 54 LayerImpl* root, | 54 LayerImpl* root, |
| 55 float device_scale_factor = 1.f, | 55 float device_scale_factor = 1.f, |
| 56 bool skip_verify_visible_rect_calculations = false) { | 56 bool skip_verify_visible_rect_calculations = false) { |
| 57 // This emulates only steps that are relevant to testing the damage tracker: | 57 // This emulates only steps that are relevant to testing the damage tracker: |
| 58 // 1. computing the render passes and layerlists | 58 // 1. computing the render passes and layerlists |
| 59 // 2. updating all damage trackers in the correct order | 59 // 2. updating all damage trackers in the correct order |
| 60 // 3. resetting all update_rects and property_changed flags for all layers | 60 // 3. resetting all update_rects and property_changed flags for all layers |
| 61 // and surfaces. | 61 // and surfaces. |
| 62 | 62 |
| 63 LayerImplList render_surface_layer_list; | 63 LayerImplList render_surface_layer_list; |
| 64 ExecuteCalculateDrawProperties(root, device_scale_factor, | 64 ExecuteCalculateDrawProperties(root, device_scale_factor, |
| 65 skip_verify_visible_rect_calculations, | 65 skip_verify_visible_rect_calculations, |
| 66 &render_surface_layer_list); | 66 &render_surface_layer_list); |
| 67 | 67 |
| 68 // Iterate back-to-front, so that damage correctly propagates from descendant | 68 // Iterate back-to-front, so that damage correctly propagates from descendant |
| 69 // surfaces to ancestors. | 69 // surfaces to ancestors. |
| 70 size_t render_surface_layer_list_size = render_surface_layer_list.size(); | 70 size_t render_surface_layer_list_size = render_surface_layer_list.size(); |
| 71 for (size_t i = 0; i < render_surface_layer_list_size; ++i) { | 71 for (size_t i = 0; i < render_surface_layer_list_size; ++i) { |
| 72 size_t index = render_surface_layer_list_size - 1 - i; | 72 size_t index = render_surface_layer_list_size - 1 - i; |
| 73 RenderSurfaceImpl* target_surface = | 73 RenderSurfaceImpl* target_surface = |
| 74 render_surface_layer_list[index]->render_surface(); | 74 render_surface_layer_list[index]->GetRenderSurface(); |
| 75 target_surface->damage_tracker()->UpdateDamageTrackingState( | 75 target_surface->damage_tracker()->UpdateDamageTrackingState( |
| 76 target_surface->layer_list(), target_surface, | 76 target_surface->layer_list(), target_surface, |
| 77 target_surface->SurfacePropertyChangedOnlyFromDescendant(), | 77 target_surface->SurfacePropertyChangedOnlyFromDescendant(), |
| 78 target_surface->content_rect(), target_surface->MaskLayer(), | 78 target_surface->content_rect(), target_surface->MaskLayer(), |
| 79 target_surface->Filters()); | 79 target_surface->Filters()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 root->layer_tree_impl()->ResetAllChangeTracking(); | 82 root->layer_tree_impl()->ResetAllChangeTracking(); |
| 83 } | 83 } |
| 84 | 84 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 TestTaskGraphRunner task_graph_runner_; | 188 TestTaskGraphRunner task_graph_runner_; |
| 189 FakeLayerTreeHostImpl host_impl_; | 189 FakeLayerTreeHostImpl host_impl_; |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithOneSurface) { | 192 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithOneSurface) { |
| 193 // Sanity check that the simple test tree will actually produce the expected | 193 // Sanity check that the simple test tree will actually produce the expected |
| 194 // render surfaces and layer lists. | 194 // render surfaces and layer lists. |
| 195 | 195 |
| 196 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 196 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 197 | 197 |
| 198 EXPECT_EQ(2u, root->render_surface()->layer_list().size()); | 198 EXPECT_EQ(2u, root->GetRenderSurface()->layer_list().size()); |
| 199 EXPECT_EQ(1, root->render_surface()->layer_list()[0]->id()); | 199 EXPECT_EQ(1, root->GetRenderSurface()->layer_list()[0]->id()); |
| 200 EXPECT_EQ(2, root->render_surface()->layer_list()[1]->id()); | 200 EXPECT_EQ(2, root->GetRenderSurface()->layer_list()[1]->id()); |
| 201 | 201 |
| 202 gfx::Rect root_damage_rect; | 202 gfx::Rect root_damage_rect; |
| 203 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 203 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 204 &root_damage_rect)); | 204 &root_damage_rect)); |
| 205 | 205 |
| 206 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); | 206 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); |
| 207 } | 207 } |
| 208 | 208 |
| 209 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) { | 209 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) { |
| 210 // Sanity check that the complex test tree will actually produce the expected | 210 // Sanity check that the complex test tree will actually produce the expected |
| 211 // render surfaces and layer lists. | 211 // render surfaces and layer lists. |
| 212 | 212 |
| 213 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 213 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 214 | 214 |
| 215 LayerImpl* child1 = root->test_properties()->children[0]; | 215 LayerImpl* child1 = root->test_properties()->children[0]; |
| 216 LayerImpl* child2 = root->test_properties()->children[1]; | 216 LayerImpl* child2 = root->test_properties()->children[1]; |
| 217 | 217 |
| 218 gfx::Rect child_damage_rect; | 218 gfx::Rect child_damage_rect; |
| 219 EXPECT_TRUE(child1->render_surface()->damage_tracker()->GetDamageRectIfValid( | 219 EXPECT_TRUE( |
| 220 &child_damage_rect)); | 220 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 221 &child_damage_rect)); |
| 221 gfx::Rect root_damage_rect; | 222 gfx::Rect root_damage_rect; |
| 222 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 223 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 223 &root_damage_rect)); | 224 &root_damage_rect)); |
| 224 | 225 |
| 225 ASSERT_TRUE(child1->render_surface()); | 226 ASSERT_TRUE(child1->GetRenderSurface()); |
| 226 EXPECT_FALSE(child2->render_surface()); | 227 EXPECT_FALSE(child2->GetRenderSurface()); |
| 227 EXPECT_EQ(3u, root->render_surface()->layer_list().size()); | 228 EXPECT_EQ(3u, root->GetRenderSurface()->layer_list().size()); |
| 228 EXPECT_EQ(2u, child1->render_surface()->layer_list().size()); | 229 EXPECT_EQ(2u, child1->GetRenderSurface()->layer_list().size()); |
| 229 | 230 |
| 230 // The render surface for child1 only has a content_rect that encloses | 231 // The render surface for child1 only has a content_rect that encloses |
| 231 // grand_child1 and grand_child2, because child1 does not draw content. | 232 // grand_child1 and grand_child2, because child1 does not draw content. |
| 232 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 233 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 233 child_damage_rect.ToString()); | 234 child_damage_rect.ToString()); |
| 234 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); | 235 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); |
| 235 } | 236 } |
| 236 | 237 |
| 237 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) { | 238 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) { |
| 238 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 239 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 239 LayerImpl* child = root->test_properties()->children[0]; | 240 LayerImpl* child = root->test_properties()->children[0]; |
| 240 | 241 |
| 241 // CASE 1: Setting the update rect should cause the corresponding damage to | 242 // CASE 1: Setting the update rect should cause the corresponding damage to |
| 242 // the surface. | 243 // the surface. |
| 243 ClearDamageForAllSurfaces(root); | 244 ClearDamageForAllSurfaces(root); |
| 244 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 245 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
| 245 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 246 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 246 EmulateDrawingOneFrame(root); | 247 EmulateDrawingOneFrame(root); |
| 247 | 248 |
| 248 // Damage position on the surface should be: position of update_rect (10, 11) | 249 // Damage position on the surface should be: position of update_rect (10, 11) |
| 249 // relative to the child (100, 100). | 250 // relative to the child (100, 100). |
| 250 gfx::Rect root_damage_rect; | 251 gfx::Rect root_damage_rect; |
| 251 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 252 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 252 &root_damage_rect)); | 253 &root_damage_rect)); |
| 253 EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(), | 254 EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(), |
| 254 root_damage_rect.ToString()); | 255 root_damage_rect.ToString()); |
| 255 | 256 |
| 256 // CASE 2: The same update rect twice in a row still produces the same | 257 // CASE 2: The same update rect twice in a row still produces the same |
| 257 // damage. | 258 // damage. |
| 258 ClearDamageForAllSurfaces(root); | 259 ClearDamageForAllSurfaces(root); |
| 259 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 260 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
| 260 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 261 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 261 EmulateDrawingOneFrame(root); | 262 EmulateDrawingOneFrame(root); |
| 262 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 263 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 263 &root_damage_rect)); | 264 &root_damage_rect)); |
| 264 EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(), | 265 EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(), |
| 265 root_damage_rect.ToString()); | 266 root_damage_rect.ToString()); |
| 266 | 267 |
| 267 // CASE 3: Setting a different update rect should cause damage on the new | 268 // CASE 3: Setting a different update rect should cause damage on the new |
| 268 // update region, but no additional exposed old region. | 269 // update region, but no additional exposed old region. |
| 269 ClearDamageForAllSurfaces(root); | 270 ClearDamageForAllSurfaces(root); |
| 270 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); | 271 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); |
| 271 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 272 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 272 EmulateDrawingOneFrame(root); | 273 EmulateDrawingOneFrame(root); |
| 273 | 274 |
| 274 // Damage position on the surface should be: position of update_rect (20, 25) | 275 // Damage position on the surface should be: position of update_rect (20, 25) |
| 275 // relative to the child (100, 100). | 276 // relative to the child (100, 100). |
| 276 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 277 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 277 &root_damage_rect)); | 278 &root_damage_rect)); |
| 278 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString()); | 279 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString()); |
| 279 } | 280 } |
| 280 | 281 |
| 281 TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) { | 282 TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) { |
| 282 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 283 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 283 LayerImpl* child = root->test_properties()->children[0]; | 284 LayerImpl* child = root->test_properties()->children[0]; |
| 284 | 285 |
| 285 // CASE 1: Adding the layer damage rect should cause the corresponding damage | 286 // CASE 1: Adding the layer damage rect should cause the corresponding damage |
| 286 // to the surface. | 287 // to the surface. |
| 287 ClearDamageForAllSurfaces(root); | 288 ClearDamageForAllSurfaces(root); |
| 288 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); | 289 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); |
| 289 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 290 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 290 EmulateDrawingOneFrame(root); | 291 EmulateDrawingOneFrame(root); |
| 291 | 292 |
| 292 // Damage position on the surface should be: position of layer damage_rect | 293 // Damage position on the surface should be: position of layer damage_rect |
| 293 // (10, 11) relative to the child (100, 100). | 294 // (10, 11) relative to the child (100, 100). |
| 294 gfx::Rect root_damage_rect; | 295 gfx::Rect root_damage_rect; |
| 295 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 296 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 296 &root_damage_rect)); | 297 &root_damage_rect)); |
| 297 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13))); | 298 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13))); |
| 298 | 299 |
| 299 // CASE 2: The same layer damage rect twice in a row still produces the same | 300 // CASE 2: The same layer damage rect twice in a row still produces the same |
| 300 // damage. | 301 // damage. |
| 301 ClearDamageForAllSurfaces(root); | 302 ClearDamageForAllSurfaces(root); |
| 302 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); | 303 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); |
| 303 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 304 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 304 EmulateDrawingOneFrame(root); | 305 EmulateDrawingOneFrame(root); |
| 305 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 306 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 306 &root_damage_rect)); | 307 &root_damage_rect)); |
| 307 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13))); | 308 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13))); |
| 308 | 309 |
| 309 // CASE 3: Adding a different layer damage rect should cause damage on the | 310 // CASE 3: Adding a different layer damage rect should cause damage on the |
| 310 // new damaged region, but no additional exposed old region. | 311 // new damaged region, but no additional exposed old region. |
| 311 ClearDamageForAllSurfaces(root); | 312 ClearDamageForAllSurfaces(root); |
| 312 child->AddDamageRect(gfx::Rect(20, 25, 1, 2)); | 313 child->AddDamageRect(gfx::Rect(20, 25, 1, 2)); |
| 313 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 314 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 314 EmulateDrawingOneFrame(root); | 315 EmulateDrawingOneFrame(root); |
| 315 | 316 |
| 316 // Damage position on the surface should be: position of layer damage_rect | 317 // Damage position on the surface should be: position of layer damage_rect |
| 317 // (20, 25) relative to the child (100, 100). | 318 // (20, 25) relative to the child (100, 100). |
| 318 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 319 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 319 &root_damage_rect)); | 320 &root_damage_rect)); |
| 320 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); | 321 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); |
| 321 | 322 |
| 322 // CASE 4: Adding multiple layer damage rects should cause a unified | 323 // CASE 4: Adding multiple layer damage rects should cause a unified |
| 323 // damage on root damage rect. | 324 // damage on root damage rect. |
| 324 ClearDamageForAllSurfaces(root); | 325 ClearDamageForAllSurfaces(root); |
| 325 child->AddDamageRect(gfx::Rect(20, 25, 1, 2)); | 326 child->AddDamageRect(gfx::Rect(20, 25, 1, 2)); |
| 326 child->AddDamageRect(gfx::Rect(10, 15, 3, 4)); | 327 child->AddDamageRect(gfx::Rect(10, 15, 3, 4)); |
| 327 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 328 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 328 EmulateDrawingOneFrame(root); | 329 EmulateDrawingOneFrame(root); |
| 329 | 330 |
| 330 // Damage position on the surface should be: position of layer damage_rect | 331 // Damage position on the surface should be: position of layer damage_rect |
| 331 // (20, 25) relative to the child (100, 100). | 332 // (20, 25) relative to the child (100, 100). |
| 332 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 333 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 333 &root_damage_rect)); | 334 &root_damage_rect)); |
| 334 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); | 335 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); |
| 335 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4))); | 336 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4))); |
| 336 } | 337 } |
| 337 | 338 |
| 338 TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) { | 339 TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) { |
| 339 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 340 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 340 LayerImpl* child = root->test_properties()->children[0]; | 341 LayerImpl* child = root->test_properties()->children[0]; |
| 341 | 342 |
| 342 // CASE 1: Adding the layer damage rect and update rect should cause the | 343 // CASE 1: Adding the layer damage rect and update rect should cause the |
| 343 // corresponding damage to the surface. | 344 // corresponding damage to the surface. |
| 344 ClearDamageForAllSurfaces(root); | 345 ClearDamageForAllSurfaces(root); |
| 345 child->AddDamageRect(gfx::Rect(5, 6, 12, 13)); | 346 child->AddDamageRect(gfx::Rect(5, 6, 12, 13)); |
| 346 child->SetUpdateRect(gfx::Rect(15, 16, 14, 10)); | 347 child->SetUpdateRect(gfx::Rect(15, 16, 14, 10)); |
| 347 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 348 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 348 EmulateDrawingOneFrame(root); | 349 EmulateDrawingOneFrame(root); |
| 349 | 350 |
| 350 // Damage position on the surface should be: position of unified layer | 351 // Damage position on the surface should be: position of unified layer |
| 351 // damage_rect and update rect (5, 6) | 352 // damage_rect and update rect (5, 6) |
| 352 // relative to the child (100, 100). | 353 // relative to the child (100, 100). |
| 353 gfx::Rect root_damage_rect; | 354 gfx::Rect root_damage_rect; |
| 354 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 355 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 355 &root_damage_rect)); | 356 &root_damage_rect)); |
| 356 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 106, 24, 20))); | 357 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 106, 24, 20))); |
| 357 | 358 |
| 358 // CASE 2: The same layer damage rect and update rect twice in a row still | 359 // CASE 2: The same layer damage rect and update rect twice in a row still |
| 359 // produces the same damage. | 360 // produces the same damage. |
| 360 ClearDamageForAllSurfaces(root); | 361 ClearDamageForAllSurfaces(root); |
| 361 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); | 362 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); |
| 362 child->SetUpdateRect(gfx::Rect(10, 11, 14, 15)); | 363 child->SetUpdateRect(gfx::Rect(10, 11, 14, 15)); |
| 363 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 364 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 364 EmulateDrawingOneFrame(root); | 365 EmulateDrawingOneFrame(root); |
| 365 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 366 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 366 &root_damage_rect)); | 367 &root_damage_rect)); |
| 367 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 14, 15))); | 368 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 14, 15))); |
| 368 | 369 |
| 369 // CASE 3: Adding a different layer damage rect and update rect should cause | 370 // CASE 3: Adding a different layer damage rect and update rect should cause |
| 370 // damage on the new damaged region, but no additional exposed old region. | 371 // damage on the new damaged region, but no additional exposed old region. |
| 371 ClearDamageForAllSurfaces(root); | 372 ClearDamageForAllSurfaces(root); |
| 372 child->AddDamageRect(gfx::Rect(20, 25, 2, 3)); | 373 child->AddDamageRect(gfx::Rect(20, 25, 2, 3)); |
| 373 child->SetUpdateRect(gfx::Rect(5, 10, 7, 8)); | 374 child->SetUpdateRect(gfx::Rect(5, 10, 7, 8)); |
| 374 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 375 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 375 EmulateDrawingOneFrame(root); | 376 EmulateDrawingOneFrame(root); |
| 376 | 377 |
| 377 // Damage position on the surface should be: position of unified layer damage | 378 // Damage position on the surface should be: position of unified layer damage |
| 378 // rect and update rect (5, 10) relative to the child (100, 100). | 379 // rect and update rect (5, 10) relative to the child (100, 100). |
| 379 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 380 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 380 &root_damage_rect)); | 381 &root_damage_rect)); |
| 381 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18))); | 382 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18))); |
| 382 } | 383 } |
| 383 | 384 |
| 384 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) { | 385 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) { |
| 385 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 386 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 386 LayerImpl* child = root->test_properties()->children[0]; | 387 LayerImpl* child = root->test_properties()->children[0]; |
| 387 | 388 |
| 388 // CASE 1: The layer's property changed flag takes priority over update rect. | 389 // CASE 1: The layer's property changed flag takes priority over update rect. |
| 389 // | 390 // |
| 390 child->test_properties()->force_render_surface = true; | 391 child->test_properties()->force_render_surface = true; |
| 391 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 392 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 392 EmulateDrawingOneFrame(root); | 393 EmulateDrawingOneFrame(root); |
| 393 ClearDamageForAllSurfaces(root); | 394 ClearDamageForAllSurfaces(root); |
| 394 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 395 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
| 395 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( | 396 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( |
| 396 0.5f, child->effect_tree_index(), root->layer_tree_impl()); | 397 0.5f, child->effect_tree_index(), root->layer_tree_impl()); |
| 397 EmulateDrawingOneFrame(root); | 398 EmulateDrawingOneFrame(root); |
| 398 | 399 |
| 399 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); | 400 ASSERT_EQ(2u, root->GetRenderSurface()->layer_list().size()); |
| 400 | 401 |
| 401 // Damage should be the entire child layer in target_surface space. | 402 // Damage should be the entire child layer in target_surface space. |
| 402 gfx::Rect expected_rect = gfx::Rect(100, 100, 30, 30); | 403 gfx::Rect expected_rect = gfx::Rect(100, 100, 30, 30); |
| 403 gfx::Rect root_damage_rect; | 404 gfx::Rect root_damage_rect; |
| 404 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 405 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 405 &root_damage_rect)); | 406 &root_damage_rect)); |
| 406 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); | 407 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); |
| 407 | 408 |
| 408 // CASE 2: If a layer moves due to property change, it damages both the new | 409 // CASE 2: If a layer moves due to property change, it damages both the new |
| 409 // location and the old (exposed) location. The old location is the | 410 // location and the old (exposed) location. The old location is the |
| 410 // entire old layer, not just the update_rect. | 411 // entire old layer, not just the update_rect. |
| 411 | 412 |
| 412 // Cycle one frame of no change, just to sanity check that the next rect is | 413 // Cycle one frame of no change, just to sanity check that the next rect is |
| 413 // not because of the old damage state. | 414 // not because of the old damage state. |
| 414 ClearDamageForAllSurfaces(root); | 415 ClearDamageForAllSurfaces(root); |
| 415 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 416 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 416 EmulateDrawingOneFrame(root); | 417 EmulateDrawingOneFrame(root); |
| 417 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 418 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 418 &root_damage_rect)); | 419 &root_damage_rect)); |
| 419 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 420 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 420 | 421 |
| 421 // Then, test the actual layer movement. | 422 // Then, test the actual layer movement. |
| 422 ClearDamageForAllSurfaces(root); | 423 ClearDamageForAllSurfaces(root); |
| 423 gfx::Transform translation; | 424 gfx::Transform translation; |
| 424 translation.Translate(100.f, 130.f); | 425 translation.Translate(100.f, 130.f); |
| 425 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( | 426 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 426 translation, child->transform_tree_index(), root->layer_tree_impl()); | 427 translation, child->transform_tree_index(), root->layer_tree_impl()); |
| 427 EmulateDrawingOneFrame(root); | 428 EmulateDrawingOneFrame(root); |
| 428 | 429 |
| 429 // Expect damage to be the combination of the previous one and the new one. | 430 // Expect damage to be the combination of the previous one and the new one. |
| 430 expected_rect.Union(gfx::Rect(200, 230, 30, 30)); | 431 expected_rect.Union(gfx::Rect(200, 230, 30, 30)); |
| 431 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 432 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 432 &root_damage_rect)); | 433 &root_damage_rect)); |
| 433 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect); | 434 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect); |
| 434 } | 435 } |
| 435 | 436 |
| 436 TEST_F(DamageTrackerTest, VerifyDamageWhenSurfaceRemoved) { | 437 TEST_F(DamageTrackerTest, VerifyDamageWhenSurfaceRemoved) { |
| 437 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 438 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 438 LayerImpl* surface = root->test_properties()->children[0]; | 439 LayerImpl* surface = root->test_properties()->children[0]; |
| 439 LayerImpl* child = surface->test_properties()->children[0]; | 440 LayerImpl* child = surface->test_properties()->children[0]; |
| 440 child->SetDrawsContent(true); | 441 child->SetDrawsContent(true); |
| 441 EmulateDrawingOneFrame(root); | 442 EmulateDrawingOneFrame(root); |
| 442 ClearDamageForAllSurfaces(root); | 443 ClearDamageForAllSurfaces(root); |
| 443 | 444 |
| 444 surface->test_properties()->force_render_surface = false; | 445 surface->test_properties()->force_render_surface = false; |
| 445 child->SetDrawsContent(false); | 446 child->SetDrawsContent(false); |
| 446 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 447 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 447 EmulateDrawingOneFrame(root); | 448 EmulateDrawingOneFrame(root); |
| 448 gfx::Rect root_damage_rect; | 449 gfx::Rect root_damage_rect; |
| 449 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 450 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 450 &root_damage_rect)); | 451 &root_damage_rect)); |
| 451 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 452 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
| 452 root_damage_rect.ToString()); | 453 root_damage_rect.ToString()); |
| 453 } | 454 } |
| 454 | 455 |
| 455 TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) { | 456 TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) { |
| 456 // If a layer is transformed, the damage rect should still enclose the entire | 457 // If a layer is transformed, the damage rect should still enclose the entire |
| 457 // transformed layer. | 458 // transformed layer. |
| 458 | 459 |
| 459 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 460 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 460 LayerImpl* child = root->test_properties()->children[0]; | 461 LayerImpl* child = root->test_properties()->children[0]; |
| 461 child->test_properties()->force_render_surface = true; | 462 child->test_properties()->force_render_surface = true; |
| 462 | 463 |
| 463 gfx::Transform rotation; | 464 gfx::Transform rotation; |
| 464 rotation.Rotate(45.0); | 465 rotation.Rotate(45.0); |
| 465 | 466 |
| 466 ClearDamageForAllSurfaces(root); | 467 ClearDamageForAllSurfaces(root); |
| 467 child->test_properties()->transform_origin = gfx::Point3F( | 468 child->test_properties()->transform_origin = gfx::Point3F( |
| 468 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f); | 469 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f); |
| 469 child->SetPosition(gfx::PointF(85.f, 85.f)); | 470 child->SetPosition(gfx::PointF(85.f, 85.f)); |
| 470 child->NoteLayerPropertyChanged(); | 471 child->NoteLayerPropertyChanged(); |
| 471 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 472 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 472 EmulateDrawingOneFrame(root); | 473 EmulateDrawingOneFrame(root); |
| 473 | 474 |
| 474 // Sanity check that the layer actually moved to (85, 85), damaging its old | 475 // Sanity check that the layer actually moved to (85, 85), damaging its old |
| 475 // location and new location. | 476 // location and new location. |
| 476 gfx::Rect root_damage_rect; | 477 gfx::Rect root_damage_rect; |
| 477 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 478 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 478 &root_damage_rect)); | 479 &root_damage_rect)); |
| 479 EXPECT_EQ(gfx::Rect(85, 85, 45, 45).ToString(), root_damage_rect.ToString()); | 480 EXPECT_EQ(gfx::Rect(85, 85, 45, 45).ToString(), root_damage_rect.ToString()); |
| 480 | 481 |
| 481 // With the anchor on the layer's center, now we can test the rotation more | 482 // With the anchor on the layer's center, now we can test the rotation more |
| 482 // intuitively, since it applies about the layer's anchor. | 483 // intuitively, since it applies about the layer's anchor. |
| 483 ClearDamageForAllSurfaces(root); | 484 ClearDamageForAllSurfaces(root); |
| 484 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( | 485 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 485 rotation, child->transform_tree_index(), root->layer_tree_impl()); | 486 rotation, child->transform_tree_index(), root->layer_tree_impl()); |
| 486 EmulateDrawingOneFrame(root); | 487 EmulateDrawingOneFrame(root); |
| 487 | 488 |
| 488 // Since the child layer is square, rotation by 45 degrees about the center | 489 // Since the child layer is square, rotation by 45 degrees about the center |
| 489 // should increase the size of the expected rect by sqrt(2), centered around | 490 // should increase the size of the expected rect by sqrt(2), centered around |
| 490 // (100, 100). The old exposed region should be fully contained in the new | 491 // (100, 100). The old exposed region should be fully contained in the new |
| 491 // region. | 492 // region. |
| 492 float expected_width = 30.f * sqrt(2.f); | 493 float expected_width = 30.f * sqrt(2.f); |
| 493 float expected_position = 100.f - 0.5f * expected_width; | 494 float expected_position = 100.f - 0.5f * expected_width; |
| 494 gfx::Rect expected_rect = gfx::ToEnclosingRect(gfx::RectF( | 495 gfx::Rect expected_rect = gfx::ToEnclosingRect(gfx::RectF( |
| 495 expected_position, expected_position, expected_width, expected_width)); | 496 expected_position, expected_position, expected_width, expected_width)); |
| 496 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 497 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 497 &root_damage_rect)); | 498 &root_damage_rect)); |
| 498 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); | 499 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); |
| 499 } | 500 } |
| 500 | 501 |
| 501 TEST_F(DamageTrackerTest, VerifyDamageForPerspectiveClippedLayer) { | 502 TEST_F(DamageTrackerTest, VerifyDamageForPerspectiveClippedLayer) { |
| 502 // If a layer has a perspective transform that causes w < 0, then not | 503 // If a layer has a perspective transform that causes w < 0, then not |
| 503 // clipping the layer can cause an invalid damage rect. This test checks that | 504 // clipping the layer can cause an invalid damage rect. This test checks that |
| 504 // the w < 0 case is tracked properly. | 505 // the w < 0 case is tracked properly. |
| 505 // | 506 // |
| 506 // The transform is constructed so that if w < 0 clipping is not performed, | 507 // The transform is constructed so that if w < 0 clipping is not performed, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 EmulateDrawingOneFrame(root); | 541 EmulateDrawingOneFrame(root); |
| 541 ClearDamageForAllSurfaces(root); | 542 ClearDamageForAllSurfaces(root); |
| 542 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( | 543 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( |
| 543 0.5f, child->effect_tree_index(), root->layer_tree_impl()); | 544 0.5f, child->effect_tree_index(), root->layer_tree_impl()); |
| 544 EmulateDrawingOneFrame(root); | 545 EmulateDrawingOneFrame(root); |
| 545 | 546 |
| 546 // The expected damage should cover the entire root surface (500x500), but we | 547 // The expected damage should cover the entire root surface (500x500), but we |
| 547 // don't care whether the damage rect was clamped or is larger than the | 548 // don't care whether the damage rect was clamped or is larger than the |
| 548 // surface for this test. | 549 // surface for this test. |
| 549 gfx::Rect root_damage_rect; | 550 gfx::Rect root_damage_rect; |
| 550 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 551 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 551 &root_damage_rect)); | 552 &root_damage_rect)); |
| 552 gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500)); | 553 gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500)); |
| 553 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about)); | 554 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about)); |
| 554 } | 555 } |
| 555 | 556 |
| 556 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) { | 557 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) { |
| 557 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 558 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 558 LayerImpl* surface = root->test_properties()->children[0]; | 559 LayerImpl* surface = root->test_properties()->children[0]; |
| 559 LayerImpl* child = surface->test_properties()->children[0]; | 560 LayerImpl* child = surface->test_properties()->children[0]; |
| 560 | 561 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 571 // surface, blurred based on the size of the blur filter. | 572 // surface, blurred based on the size of the blur filter. |
| 572 ClearDamageForAllSurfaces(root); | 573 ClearDamageForAllSurfaces(root); |
| 573 child->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); | 574 child->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); |
| 574 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 575 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 575 EmulateDrawingOneFrame(root); | 576 EmulateDrawingOneFrame(root); |
| 576 | 577 |
| 577 // Damage position on the surface should be: position of update_rect (1, 2) | 578 // Damage position on the surface should be: position of update_rect (1, 2) |
| 578 // relative to the child (300, 300), but expanded by the blur outsets | 579 // relative to the child (300, 300), but expanded by the blur outsets |
| 579 // (15, since the blur radius is 5). | 580 // (15, since the blur radius is 5). |
| 580 gfx::Rect root_damage_rect; | 581 gfx::Rect root_damage_rect; |
| 581 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 582 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 582 &root_damage_rect)); | 583 &root_damage_rect)); |
| 583 EXPECT_EQ(gfx::Rect(286, 287, 33, 34), root_damage_rect); | 584 EXPECT_EQ(gfx::Rect(286, 287, 33, 34), root_damage_rect); |
| 584 } | 585 } |
| 585 | 586 |
| 586 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { | 587 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { |
| 587 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 588 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 588 LayerImpl* child = root->test_properties()->children[0]; | 589 LayerImpl* child = root->test_properties()->children[0]; |
| 589 gfx::Rect root_damage_rect, child_damage_rect; | 590 gfx::Rect root_damage_rect, child_damage_rect; |
| 590 | 591 |
| 591 // Allow us to set damage on child too. | 592 // Allow us to set damage on child too. |
| 592 child->SetDrawsContent(true); | 593 child->SetDrawsContent(true); |
| 593 | 594 |
| 594 FilterOperations filters; | 595 FilterOperations filters; |
| 595 filters.Append(FilterOperation::CreateReferenceFilter( | 596 filters.Append(FilterOperation::CreateReferenceFilter( |
| 596 SkBlurImageFilter::Make(2, 2, nullptr))); | 597 SkBlurImageFilter::Make(2, 2, nullptr))); |
| 597 | 598 |
| 598 // Setting the filter will damage the whole surface. | 599 // Setting the filter will damage the whole surface. |
| 599 ClearDamageForAllSurfaces(root); | 600 ClearDamageForAllSurfaces(root); |
| 600 child->test_properties()->force_render_surface = true; | 601 child->test_properties()->force_render_surface = true; |
| 601 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 602 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 602 EmulateDrawingOneFrame(root); | 603 EmulateDrawingOneFrame(root); |
| 603 child->layer_tree_impl()->property_trees()->effect_tree.OnFilterAnimated( | 604 child->layer_tree_impl()->property_trees()->effect_tree.OnFilterAnimated( |
| 604 filters, child->effect_tree_index(), child->layer_tree_impl()); | 605 filters, child->effect_tree_index(), child->layer_tree_impl()); |
| 605 EmulateDrawingOneFrame(root); | 606 EmulateDrawingOneFrame(root); |
| 606 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 607 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 607 &root_damage_rect)); | 608 &root_damage_rect)); |
| 608 EXPECT_TRUE(child->render_surface()->damage_tracker()->GetDamageRectIfValid( | 609 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 609 &child_damage_rect)); | 610 &child_damage_rect)); |
| 610 | 611 |
| 611 // gfx::Rect(100, 100, 30, 30), expanded by 6px for the 2px blur filter. | 612 // gfx::Rect(100, 100, 30, 30), expanded by 6px for the 2px blur filter. |
| 612 EXPECT_EQ(gfx::Rect(94, 94, 42, 42), root_damage_rect); | 613 EXPECT_EQ(gfx::Rect(94, 94, 42, 42), root_damage_rect); |
| 613 | 614 |
| 614 // gfx::Rect(0, 0, 30, 30), expanded by 6px for the 2px blur filter. | 615 // gfx::Rect(0, 0, 30, 30), expanded by 6px for the 2px blur filter. |
| 615 EXPECT_EQ(gfx::Rect(-6, -6, 42, 42), child_damage_rect); | 616 EXPECT_EQ(gfx::Rect(-6, -6, 42, 42), child_damage_rect); |
| 616 | 617 |
| 617 // CASE 1: Setting the update rect should damage the whole surface (for now) | 618 // CASE 1: Setting the update rect should damage the whole surface (for now) |
| 618 ClearDamageForAllSurfaces(root); | 619 ClearDamageForAllSurfaces(root); |
| 619 child->SetUpdateRect(gfx::Rect(1, 1)); | 620 child->SetUpdateRect(gfx::Rect(1, 1)); |
| 620 EmulateDrawingOneFrame(root); | 621 EmulateDrawingOneFrame(root); |
| 621 | 622 |
| 622 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 623 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 623 &root_damage_rect)); | 624 &root_damage_rect)); |
| 624 EXPECT_TRUE(child->render_surface()->damage_tracker()->GetDamageRectIfValid( | 625 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 625 &child_damage_rect)); | 626 &child_damage_rect)); |
| 626 | 627 |
| 627 // gfx::Rect(100, 100, 1, 1), expanded by 6px for the 2px blur filter. | 628 // gfx::Rect(100, 100, 1, 1), expanded by 6px for the 2px blur filter. |
| 628 EXPECT_EQ(gfx::Rect(94, 94, 13, 13), root_damage_rect); | 629 EXPECT_EQ(gfx::Rect(94, 94, 13, 13), root_damage_rect); |
| 629 | 630 |
| 630 // gfx::Rect(0, 0, 1, 1), expanded by 6px for the 2px blur filter. | 631 // gfx::Rect(0, 0, 1, 1), expanded by 6px for the 2px blur filter. |
| 631 EXPECT_EQ(gfx::Rect(-6, -6, 13, 13), child_damage_rect); | 632 EXPECT_EQ(gfx::Rect(-6, -6, 13, 13), child_damage_rect); |
| 632 } | 633 } |
| 633 | 634 |
| 634 TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) { | 635 TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 647 gfx::Transform transform; | 648 gfx::Transform transform; |
| 648 transform.RotateAboutYAxis(60); | 649 transform.RotateAboutYAxis(60); |
| 649 ClearDamageForAllSurfaces(root); | 650 ClearDamageForAllSurfaces(root); |
| 650 child->test_properties()->force_render_surface = true; | 651 child->test_properties()->force_render_surface = true; |
| 651 child->test_properties()->transform = transform; | 652 child->test_properties()->transform = transform; |
| 652 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 653 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 653 EmulateDrawingOneFrame(root); | 654 EmulateDrawingOneFrame(root); |
| 654 child->layer_tree_impl()->property_trees()->effect_tree.OnFilterAnimated( | 655 child->layer_tree_impl()->property_trees()->effect_tree.OnFilterAnimated( |
| 655 filters, child->effect_tree_index(), child->layer_tree_impl()); | 656 filters, child->effect_tree_index(), child->layer_tree_impl()); |
| 656 EmulateDrawingOneFrame(root); | 657 EmulateDrawingOneFrame(root); |
| 657 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 658 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 658 &root_damage_rect)); | 659 &root_damage_rect)); |
| 659 EXPECT_TRUE(child->render_surface()->damage_tracker()->GetDamageRectIfValid( | 660 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 660 &child_damage_rect)); | 661 &child_damage_rect)); |
| 661 | 662 |
| 662 // Blur outset is 6px for a 2px blur. | 663 // Blur outset is 6px for a 2px blur. |
| 663 int blur_outset = 6; | 664 int blur_outset = 6; |
| 664 int rotated_outset_left = blur_outset / 2; | 665 int rotated_outset_left = blur_outset / 2; |
| 665 int expected_rotated_width = (30 + 2 * blur_outset) / 2; | 666 int expected_rotated_width = (30 + 2 * blur_outset) / 2; |
| 666 gfx::Rect expected_root_damage(100 - rotated_outset_left, 100 - blur_outset, | 667 gfx::Rect expected_root_damage(100 - rotated_outset_left, 100 - blur_outset, |
| 667 expected_rotated_width, 30 + 2 * blur_outset); | 668 expected_rotated_width, 30 + 2 * blur_outset); |
| 668 expected_root_damage.Union(gfx::Rect(100, 100, 30, 30)); | 669 expected_root_damage.Union(gfx::Rect(100, 100, 30, 30)); |
| 669 EXPECT_EQ(expected_root_damage, root_damage_rect); | 670 EXPECT_EQ(expected_root_damage, root_damage_rect); |
| 670 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, 30 + 2 * blur_outset, | 671 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, 30 + 2 * blur_outset, |
| 671 30 + 2 * blur_outset), | 672 30 + 2 * blur_outset), |
| 672 child_damage_rect); | 673 child_damage_rect); |
| 673 | 674 |
| 674 // Setting the update rect should damage the whole surface (for now) | 675 // Setting the update rect should damage the whole surface (for now) |
| 675 ClearDamageForAllSurfaces(root); | 676 ClearDamageForAllSurfaces(root); |
| 676 child->SetUpdateRect(gfx::Rect(30, 30)); | 677 child->SetUpdateRect(gfx::Rect(30, 30)); |
| 677 EmulateDrawingOneFrame(root); | 678 EmulateDrawingOneFrame(root); |
| 678 | 679 |
| 679 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 680 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 680 &root_damage_rect)); | 681 &root_damage_rect)); |
| 681 EXPECT_TRUE(child->render_surface()->damage_tracker()->GetDamageRectIfValid( | 682 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 682 &child_damage_rect)); | 683 &child_damage_rect)); |
| 683 | 684 |
| 684 int expect_width = 30 + 2 * blur_outset; | 685 int expect_width = 30 + 2 * blur_outset; |
| 685 int expect_height = 30 + 2 * blur_outset; | 686 int expect_height = 30 + 2 * blur_outset; |
| 686 EXPECT_EQ(gfx::Rect(100 - blur_outset / 2, 100 - blur_outset, | 687 EXPECT_EQ(gfx::Rect(100 - blur_outset / 2, 100 - blur_outset, |
| 687 expect_width / 2, expect_height), | 688 expect_width / 2, expect_height), |
| 688 root_damage_rect); | 689 root_damage_rect); |
| 689 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, expect_width, expect_height), | 690 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, expect_width, expect_height), |
| 690 child_damage_rect); | 691 child_damage_rect); |
| 691 } | 692 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 703 | 704 |
| 704 // Setting the filter will damage the whole surface. | 705 // Setting the filter will damage the whole surface. |
| 705 ClearDamageForAllSurfaces(root); | 706 ClearDamageForAllSurfaces(root); |
| 706 child->test_properties()->force_render_surface = true; | 707 child->test_properties()->force_render_surface = true; |
| 707 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 708 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 708 int device_scale_factor = 2; | 709 int device_scale_factor = 2; |
| 709 EmulateDrawingOneFrame(root, device_scale_factor); | 710 EmulateDrawingOneFrame(root, device_scale_factor); |
| 710 child->layer_tree_impl()->property_trees()->effect_tree.OnFilterAnimated( | 711 child->layer_tree_impl()->property_trees()->effect_tree.OnFilterAnimated( |
| 711 filters, child->effect_tree_index(), child->layer_tree_impl()); | 712 filters, child->effect_tree_index(), child->layer_tree_impl()); |
| 712 EmulateDrawingOneFrame(root, device_scale_factor); | 713 EmulateDrawingOneFrame(root, device_scale_factor); |
| 713 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 714 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 714 &root_damage_rect)); | 715 &root_damage_rect)); |
| 715 EXPECT_TRUE(child->render_surface()->damage_tracker()->GetDamageRectIfValid( | 716 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 716 &child_damage_rect)); | 717 &child_damage_rect)); |
| 717 | 718 |
| 718 // Blur outset is 9px for a 3px blur, scaled up by DSF. | 719 // Blur outset is 9px for a 3px blur, scaled up by DSF. |
| 719 int blur_outset = 9 * device_scale_factor; | 720 int blur_outset = 9 * device_scale_factor; |
| 720 gfx::Rect original_rect(100, 100, 100, 100); | 721 gfx::Rect original_rect(100, 100, 100, 100); |
| 721 gfx::Rect expected_child_damage_rect(60, 60); | 722 gfx::Rect expected_child_damage_rect(60, 60); |
| 722 expected_child_damage_rect.Inset(-blur_outset, -blur_outset); | 723 expected_child_damage_rect.Inset(-blur_outset, -blur_outset); |
| 723 gfx::Rect expected_root_damage_rect(child_damage_rect); | 724 gfx::Rect expected_root_damage_rect(child_damage_rect); |
| 724 expected_root_damage_rect.Offset(200, 200); | 725 expected_root_damage_rect.Offset(200, 200); |
| 725 gfx::Rect expected_total_damage_rect = expected_root_damage_rect; | 726 gfx::Rect expected_total_damage_rect = expected_root_damage_rect; |
| 726 expected_total_damage_rect.Union(original_rect); | 727 expected_total_damage_rect.Union(original_rect); |
| 727 EXPECT_EQ(expected_total_damage_rect, root_damage_rect); | 728 EXPECT_EQ(expected_total_damage_rect, root_damage_rect); |
| 728 EXPECT_EQ(expected_child_damage_rect, child_damage_rect); | 729 EXPECT_EQ(expected_child_damage_rect, child_damage_rect); |
| 729 | 730 |
| 730 // Setting the update rect should damage only the affected area (original, | 731 // Setting the update rect should damage only the affected area (original, |
| 731 // outset by 3 * blur sigma * DSF). | 732 // outset by 3 * blur sigma * DSF). |
| 732 ClearDamageForAllSurfaces(root); | 733 ClearDamageForAllSurfaces(root); |
| 733 child->SetUpdateRect(gfx::Rect(30, 30)); | 734 child->SetUpdateRect(gfx::Rect(30, 30)); |
| 734 EmulateDrawingOneFrame(root, device_scale_factor); | 735 EmulateDrawingOneFrame(root, device_scale_factor); |
| 735 | 736 |
| 736 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 737 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 737 &root_damage_rect)); | 738 &root_damage_rect)); |
| 738 EXPECT_TRUE(child->render_surface()->damage_tracker()->GetDamageRectIfValid( | 739 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 739 &child_damage_rect)); | 740 &child_damage_rect)); |
| 740 | 741 |
| 741 EXPECT_EQ(expected_root_damage_rect, root_damage_rect); | 742 EXPECT_EQ(expected_root_damage_rect, root_damage_rect); |
| 742 EXPECT_EQ(expected_child_damage_rect, child_damage_rect); | 743 EXPECT_EQ(expected_child_damage_rect, child_damage_rect); |
| 743 } | 744 } |
| 744 | 745 |
| 745 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) { | 746 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) { |
| 746 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 747 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 747 LayerImpl* child1 = root->test_properties()->children[0]; | 748 LayerImpl* child1 = root->test_properties()->children[0]; |
| 748 LayerImpl* child2 = root->test_properties()->children[1]; | 749 LayerImpl* child2 = root->test_properties()->children[1]; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 763 // CASE 1: Setting the update rect should cause the corresponding damage to | 764 // CASE 1: Setting the update rect should cause the corresponding damage to |
| 764 // the surface, blurred based on the size of the child's background | 765 // the surface, blurred based on the size of the child's background |
| 765 // blur filter. Note that child1's render surface has a size of | 766 // blur filter. Note that child1's render surface has a size of |
| 766 // 206x208 due to contributions from grand_child1 and grand_child2. | 767 // 206x208 due to contributions from grand_child1 and grand_child2. |
| 767 ClearDamageForAllSurfaces(root); | 768 ClearDamageForAllSurfaces(root); |
| 768 root->SetUpdateRect(gfx::Rect(297, 297, 2, 2)); | 769 root->SetUpdateRect(gfx::Rect(297, 297, 2, 2)); |
| 769 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 770 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 770 EmulateDrawingOneFrame(root); | 771 EmulateDrawingOneFrame(root); |
| 771 | 772 |
| 772 gfx::Rect root_damage_rect; | 773 gfx::Rect root_damage_rect; |
| 773 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 774 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 774 &root_damage_rect)); | 775 &root_damage_rect)); |
| 775 // Damage position on the surface should be a composition of the damage on | 776 // Damage position on the surface should be a composition of the damage on |
| 776 // the root and on child2. Damage on the root should be: position of | 777 // the root and on child2. Damage on the root should be: position of |
| 777 // update_rect (297, 297), but expanded by the blur outsets. | 778 // update_rect (297, 297), but expanded by the blur outsets. |
| 778 gfx::Rect expected_damage_rect = gfx::Rect(297, 297, 2, 2); | 779 gfx::Rect expected_damage_rect = gfx::Rect(297, 297, 2, 2); |
| 779 | 780 |
| 780 // 6px spread for a 2px blur. | 781 // 6px spread for a 2px blur. |
| 781 expected_damage_rect.Inset(-6, -6, -6, -6); | 782 expected_damage_rect.Inset(-6, -6, -6, -6); |
| 782 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 783 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| 783 | 784 |
| 784 // CASE 2: Setting the update rect should cause the corresponding damage to | 785 // CASE 2: Setting the update rect should cause the corresponding damage to |
| 785 // the surface, blurred based on the size of the child's background | 786 // the surface, blurred based on the size of the child's background |
| 786 // blur filter. Since the damage extends to the right/bottom outside | 787 // blur filter. Since the damage extends to the right/bottom outside |
| 787 // of the blurred layer, only the left/top should end up expanded. | 788 // of the blurred layer, only the left/top should end up expanded. |
| 788 ClearDamageForAllSurfaces(root); | 789 ClearDamageForAllSurfaces(root); |
| 789 root->SetUpdateRect(gfx::Rect(297, 297, 30, 30)); | 790 root->SetUpdateRect(gfx::Rect(297, 297, 30, 30)); |
| 790 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 791 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 791 EmulateDrawingOneFrame(root); | 792 EmulateDrawingOneFrame(root); |
| 792 | 793 |
| 793 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 794 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 794 &root_damage_rect)); | 795 &root_damage_rect)); |
| 795 // Damage position on the surface should be a composition of the damage on | 796 // Damage position on the surface should be a composition of the damage on |
| 796 // the root and on child2. Damage on the root should be: position of | 797 // the root and on child2. Damage on the root should be: position of |
| 797 // update_rect (297, 297), but expanded on the left/top by the blur outsets. | 798 // update_rect (297, 297), but expanded on the left/top by the blur outsets. |
| 798 expected_damage_rect = gfx::Rect(297, 297, 30, 30); | 799 expected_damage_rect = gfx::Rect(297, 297, 30, 30); |
| 799 | 800 |
| 800 // 6px spread for a 2px blur. | 801 // 6px spread for a 2px blur. |
| 801 expected_damage_rect.Inset(-6, -6, 0, 0); | 802 expected_damage_rect.Inset(-6, -6, 0, 0); |
| 802 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 803 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| 803 | 804 |
| 804 // CASE 3: Setting this update rect outside the blurred content_bounds of the | 805 // CASE 3: Setting this update rect outside the blurred content_bounds of the |
| 805 // blurred child1 will not cause it to be expanded. | 806 // blurred child1 will not cause it to be expanded. |
| 806 ClearDamageForAllSurfaces(root); | 807 ClearDamageForAllSurfaces(root); |
| 807 root->SetUpdateRect(gfx::Rect(30, 30, 2, 2)); | 808 root->SetUpdateRect(gfx::Rect(30, 30, 2, 2)); |
| 808 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 809 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 809 EmulateDrawingOneFrame(root); | 810 EmulateDrawingOneFrame(root); |
| 810 | 811 |
| 811 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 812 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 812 &root_damage_rect)); | 813 &root_damage_rect)); |
| 813 // Damage on the root should be: position of update_rect (30, 30), not | 814 // Damage on the root should be: position of update_rect (30, 30), not |
| 814 // expanded. | 815 // expanded. |
| 815 expected_damage_rect = gfx::Rect(30, 30, 2, 2); | 816 expected_damage_rect = gfx::Rect(30, 30, 2, 2); |
| 816 | 817 |
| 817 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 818 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| 818 | 819 |
| 819 // CASE 4: Setting this update rect inside the blurred content_bounds but | 820 // CASE 4: Setting this update rect inside the blurred content_bounds but |
| 820 // outside the original content_bounds of the blurred child1 will | 821 // outside the original content_bounds of the blurred child1 will |
| 821 // cause it to be expanded. | 822 // cause it to be expanded. |
| 822 ClearDamageForAllSurfaces(root); | 823 ClearDamageForAllSurfaces(root); |
| 823 root->SetUpdateRect(gfx::Rect(99, 99, 1, 1)); | 824 root->SetUpdateRect(gfx::Rect(99, 99, 1, 1)); |
| 824 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 825 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 825 EmulateDrawingOneFrame(root); | 826 EmulateDrawingOneFrame(root); |
| 826 | 827 |
| 827 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 828 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 828 &root_damage_rect)); | 829 &root_damage_rect)); |
| 829 // Damage on the root should be: the originally damaged rect (99,99 1x1) | 830 // Damage on the root should be: the originally damaged rect (99,99 1x1) |
| 830 // plus the rect that can influence with a 2px blur (93,93 13x13) intersected | 831 // plus the rect that can influence with a 2px blur (93,93 13x13) intersected |
| 831 // with the surface rect (100,100 206x208). So no additional damage occurs | 832 // with the surface rect (100,100 206x208). So no additional damage occurs |
| 832 // above or to the left, but there is additional damage within the blurred | 833 // above or to the left, but there is additional damage within the blurred |
| 833 // area. | 834 // area. |
| 834 expected_damage_rect = gfx::Rect(99, 99, 7, 7); | 835 expected_damage_rect = gfx::Rect(99, 99, 7, 7); |
| 835 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 836 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| 836 | 837 |
| 837 // CASE 5: Setting the update rect on child2, which is above child1, will | 838 // CASE 5: Setting the update rect on child2, which is above child1, will |
| 838 // not get blurred by child1, so it does not need to get expanded. | 839 // not get blurred by child1, so it does not need to get expanded. |
| 839 ClearDamageForAllSurfaces(root); | 840 ClearDamageForAllSurfaces(root); |
| 840 child2->SetUpdateRect(gfx::Rect(1, 1)); | 841 child2->SetUpdateRect(gfx::Rect(1, 1)); |
| 841 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 842 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 842 EmulateDrawingOneFrame(root); | 843 EmulateDrawingOneFrame(root); |
| 843 | 844 |
| 844 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 845 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 845 &root_damage_rect)); | 846 &root_damage_rect)); |
| 846 // Damage on child2 should be: position of update_rect offset by the child's | 847 // Damage on child2 should be: position of update_rect offset by the child's |
| 847 // position (11, 11), and not expanded by anything. | 848 // position (11, 11), and not expanded by anything. |
| 848 expected_damage_rect = gfx::Rect(11, 11, 1, 1); | 849 expected_damage_rect = gfx::Rect(11, 11, 1, 1); |
| 849 | 850 |
| 850 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 851 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| 851 | 852 |
| 852 // CASE 6: Setting the update rect on child1 will also blur the damage, so | 853 // CASE 6: Setting the update rect on child1 will also blur the damage, so |
| 853 // that any pixels needed for the blur are redrawn in the current | 854 // that any pixels needed for the blur are redrawn in the current |
| 854 // frame. | 855 // frame. |
| 855 ClearDamageForAllSurfaces(root); | 856 ClearDamageForAllSurfaces(root); |
| 856 child1->SetUpdateRect(gfx::Rect(1, 1)); | 857 child1->SetUpdateRect(gfx::Rect(1, 1)); |
| 857 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 858 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 858 EmulateDrawingOneFrame(root); | 859 EmulateDrawingOneFrame(root); |
| 859 | 860 |
| 860 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 861 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 861 &root_damage_rect)); | 862 &root_damage_rect)); |
| 862 // Damage on child1 should be: position of update_rect offset by the child's | 863 // Damage on child1 should be: position of update_rect offset by the child's |
| 863 // position (100, 100), and expanded by the damage. | 864 // position (100, 100), and expanded by the damage. |
| 864 | 865 |
| 865 // Damage should be (0,0 1x1), offset by the 100,100 offset of child1 in | 866 // Damage should be (0,0 1x1), offset by the 100,100 offset of child1 in |
| 866 // root, and expanded 6px for the 2px blur (i.e., 94,94 13x13), but there | 867 // root, and expanded 6px for the 2px blur (i.e., 94,94 13x13), but there |
| 867 // should be no damage outside child1 (i.e. none above or to the left of | 868 // should be no damage outside child1 (i.e. none above or to the left of |
| 868 // 100,100. | 869 // 100,100. |
| 869 expected_damage_rect = gfx::Rect(100, 100, 7, 7); | 870 expected_damage_rect = gfx::Rect(100, 100, 7, 7); |
| 870 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 871 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 883 child2->SetPosition(gfx::PointF(400.f, 380.f)); | 884 child2->SetPosition(gfx::PointF(400.f, 380.f)); |
| 884 child2->SetBounds(gfx::Size(6, 8)); | 885 child2->SetBounds(gfx::Size(6, 8)); |
| 885 child2->SetDrawsContent(true); | 886 child2->SetDrawsContent(true); |
| 886 root->test_properties()->AddChild(std::move(child2)); | 887 root->test_properties()->AddChild(std::move(child2)); |
| 887 } | 888 } |
| 888 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 889 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 889 EmulateDrawingOneFrame(root); | 890 EmulateDrawingOneFrame(root); |
| 890 | 891 |
| 891 // Sanity check - all 3 layers should be on the same render surface; render | 892 // Sanity check - all 3 layers should be on the same render surface; render |
| 892 // surfaces are tested elsewhere. | 893 // surfaces are tested elsewhere. |
| 893 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); | 894 ASSERT_EQ(3u, root->GetRenderSurface()->layer_list().size()); |
| 894 | 895 |
| 895 gfx::Rect root_damage_rect; | 896 gfx::Rect root_damage_rect; |
| 896 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 897 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 897 &root_damage_rect)); | 898 &root_damage_rect)); |
| 898 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); | 899 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); |
| 899 | 900 |
| 900 // CASE 2: If the layer is removed, its entire old layer becomes exposed, not | 901 // CASE 2: If the layer is removed, its entire old layer becomes exposed, not |
| 901 // just the last update rect. | 902 // just the last update rect. |
| 902 | 903 |
| 903 // Advance one frame without damage so that we know the damage rect is not | 904 // Advance one frame without damage so that we know the damage rect is not |
| 904 // leftover from the previous case. | 905 // leftover from the previous case. |
| 905 ClearDamageForAllSurfaces(root); | 906 ClearDamageForAllSurfaces(root); |
| 906 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 907 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 907 EmulateDrawingOneFrame(root); | 908 EmulateDrawingOneFrame(root); |
| 908 | 909 |
| 909 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 910 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 910 &root_damage_rect)); | 911 &root_damage_rect)); |
| 911 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 912 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 912 | 913 |
| 913 // Then, test removing child1. | 914 // Then, test removing child1. |
| 914 root->test_properties()->RemoveChild(child1); | 915 root->test_properties()->RemoveChild(child1); |
| 915 child1 = NULL; | 916 child1 = NULL; |
| 916 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 917 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 917 EmulateDrawingOneFrame(root); | 918 EmulateDrawingOneFrame(root); |
| 918 | 919 |
| 919 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 920 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 920 &root_damage_rect)); | 921 &root_damage_rect)); |
| 921 EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(), | 922 EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(), |
| 922 root_damage_rect.ToString()); | 923 root_damage_rect.ToString()); |
| 923 } | 924 } |
| 924 | 925 |
| 925 TEST_F(DamageTrackerTest, VerifyDamageForNewUnchangedLayer) { | 926 TEST_F(DamageTrackerTest, VerifyDamageForNewUnchangedLayer) { |
| 926 // If child2 is added to the layer tree, but it doesn't have any explicit | 927 // If child2 is added to the layer tree, but it doesn't have any explicit |
| 927 // damage of its own, it should still indeed damage the target surface. | 928 // damage of its own, it should still indeed damage the target surface. |
| 928 | 929 |
| 929 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 930 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 943 // trigger, it means the test no longer actually covers the intended | 944 // trigger, it means the test no longer actually covers the intended |
| 944 // scenario. | 945 // scenario. |
| 945 ASSERT_FALSE(child2_ptr->LayerPropertyChanged()); | 946 ASSERT_FALSE(child2_ptr->LayerPropertyChanged()); |
| 946 ASSERT_TRUE(child2_ptr->update_rect().IsEmpty()); | 947 ASSERT_TRUE(child2_ptr->update_rect().IsEmpty()); |
| 947 } | 948 } |
| 948 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 949 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 949 EmulateDrawingOneFrame(root); | 950 EmulateDrawingOneFrame(root); |
| 950 | 951 |
| 951 // Sanity check - all 3 layers should be on the same render surface; render | 952 // Sanity check - all 3 layers should be on the same render surface; render |
| 952 // surfaces are tested elsewhere. | 953 // surfaces are tested elsewhere. |
| 953 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); | 954 ASSERT_EQ(3u, root->GetRenderSurface()->layer_list().size()); |
| 954 | 955 |
| 955 gfx::Rect root_damage_rect; | 956 gfx::Rect root_damage_rect; |
| 956 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 957 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 957 &root_damage_rect)); | 958 &root_damage_rect)); |
| 958 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); | 959 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); |
| 959 } | 960 } |
| 960 | 961 |
| 961 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { | 962 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { |
| 962 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 963 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 963 LayerImpl* child1 = root->test_properties()->children[0]; | 964 LayerImpl* child1 = root->test_properties()->children[0]; |
| 964 | 965 |
| 965 // In this test we don't want the above tree manipulation to be considered | 966 // In this test we don't want the above tree manipulation to be considered |
| 966 // part of the same frame. | 967 // part of the same frame. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 979 | 980 |
| 980 // Damaging two layers simultaneously should cause combined damage. | 981 // Damaging two layers simultaneously should cause combined damage. |
| 981 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2); | 982 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2); |
| 982 // - child2 update rect in surface space: gfx::Rect(400, 380, 3, 4); | 983 // - child2 update rect in surface space: gfx::Rect(400, 380, 3, 4); |
| 983 ClearDamageForAllSurfaces(root); | 984 ClearDamageForAllSurfaces(root); |
| 984 child1->SetUpdateRect(gfx::Rect(1, 2)); | 985 child1->SetUpdateRect(gfx::Rect(1, 2)); |
| 985 child2->SetUpdateRect(gfx::Rect(3, 4)); | 986 child2->SetUpdateRect(gfx::Rect(3, 4)); |
| 986 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 987 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 987 EmulateDrawingOneFrame(root); | 988 EmulateDrawingOneFrame(root); |
| 988 gfx::Rect root_damage_rect; | 989 gfx::Rect root_damage_rect; |
| 989 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 990 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 990 &root_damage_rect)); | 991 &root_damage_rect)); |
| 991 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(), | 992 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(), |
| 992 root_damage_rect.ToString()); | 993 root_damage_rect.ToString()); |
| 993 } | 994 } |
| 994 | 995 |
| 995 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) { | 996 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) { |
| 996 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 997 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 997 LayerImpl* child1 = root->test_properties()->children[0]; | 998 LayerImpl* child1 = root->test_properties()->children[0]; |
| 998 LayerImpl* child2 = root->test_properties()->children[1]; | 999 LayerImpl* child2 = root->test_properties()->children[1]; |
| 999 LayerImpl* grand_child1 = | 1000 LayerImpl* grand_child1 = |
| 1000 root->test_properties()->children[0]->test_properties()->children[0]; | 1001 root->test_properties()->children[0]->test_properties()->children[0]; |
| 1001 child2->test_properties()->force_render_surface = true; | 1002 child2->test_properties()->force_render_surface = true; |
| 1002 grand_child1->test_properties()->force_render_surface = true; | 1003 grand_child1->test_properties()->force_render_surface = true; |
| 1003 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1004 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1004 EmulateDrawingOneFrame(root); | 1005 EmulateDrawingOneFrame(root); |
| 1005 gfx::Rect child_damage_rect; | 1006 gfx::Rect child_damage_rect; |
| 1006 gfx::Rect root_damage_rect; | 1007 gfx::Rect root_damage_rect; |
| 1007 | 1008 |
| 1008 // CASE 1: Damage to a descendant surface should propagate properly to | 1009 // CASE 1: Damage to a descendant surface should propagate properly to |
| 1009 // ancestor surface. | 1010 // ancestor surface. |
| 1010 ClearDamageForAllSurfaces(root); | 1011 ClearDamageForAllSurfaces(root); |
| 1011 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( | 1012 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( |
| 1012 0.5f, grand_child1->effect_tree_index(), root->layer_tree_impl()); | 1013 0.5f, grand_child1->effect_tree_index(), root->layer_tree_impl()); |
| 1013 EmulateDrawingOneFrame(root); | 1014 EmulateDrawingOneFrame(root); |
| 1014 EXPECT_TRUE(child1->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1015 EXPECT_TRUE( |
| 1015 &child_damage_rect)); | 1016 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1016 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1017 &child_damage_rect)); |
| 1018 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1017 &root_damage_rect)); | 1019 &root_damage_rect)); |
| 1018 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); | 1020 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); |
| 1019 EXPECT_EQ(gfx::Rect(300, 300, 6, 8).ToString(), root_damage_rect.ToString()); | 1021 EXPECT_EQ(gfx::Rect(300, 300, 6, 8).ToString(), root_damage_rect.ToString()); |
| 1020 | 1022 |
| 1021 // CASE 2: Same as previous case, but with additional damage elsewhere that | 1023 // CASE 2: Same as previous case, but with additional damage elsewhere that |
| 1022 // should be properly unioned. | 1024 // should be properly unioned. |
| 1023 // - child1 surface damage in root surface space: | 1025 // - child1 surface damage in root surface space: |
| 1024 // gfx::Rect(300, 300, 6, 8); | 1026 // gfx::Rect(300, 300, 6, 8); |
| 1025 // - child2 damage in root surface space: | 1027 // - child2 damage in root surface space: |
| 1026 // gfx::Rect(11, 11, 18, 18); | 1028 // gfx::Rect(11, 11, 18, 18); |
| 1027 ClearDamageForAllSurfaces(root); | 1029 ClearDamageForAllSurfaces(root); |
| 1028 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( | 1030 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( |
| 1029 0.7f, grand_child1->effect_tree_index(), root->layer_tree_impl()); | 1031 0.7f, grand_child1->effect_tree_index(), root->layer_tree_impl()); |
| 1030 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( | 1032 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( |
| 1031 0.7f, child2->effect_tree_index(), root->layer_tree_impl()); | 1033 0.7f, child2->effect_tree_index(), root->layer_tree_impl()); |
| 1032 EmulateDrawingOneFrame(root); | 1034 EmulateDrawingOneFrame(root); |
| 1033 EXPECT_TRUE(child1->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1035 EXPECT_TRUE( |
| 1034 &child_damage_rect)); | 1036 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1035 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1037 &child_damage_rect)); |
| 1038 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1036 &root_damage_rect)); | 1039 &root_damage_rect)); |
| 1037 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); | 1040 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); |
| 1038 EXPECT_EQ(gfx::Rect(11, 11, 295, 297).ToString(), | 1041 EXPECT_EQ(gfx::Rect(11, 11, 295, 297).ToString(), |
| 1039 root_damage_rect.ToString()); | 1042 root_damage_rect.ToString()); |
| 1040 } | 1043 } |
| 1041 | 1044 |
| 1042 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) { | 1045 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) { |
| 1043 // If descendant layer changes and affects the content bounds of the render | 1046 // If descendant layer changes and affects the content bounds of the render |
| 1044 // surface, then the entire descendant surface should be damaged, and it | 1047 // surface, then the entire descendant surface should be damaged, and it |
| 1045 // should damage its ancestor surface with the old and new surface regions. | 1048 // should damage its ancestor surface with the old and new surface regions. |
| 1046 | 1049 |
| 1047 // This is a tricky case, since only the first grand_child changes, but the | 1050 // This is a tricky case, since only the first grand_child changes, but the |
| 1048 // entire surface should be marked dirty. | 1051 // entire surface should be marked dirty. |
| 1049 | 1052 |
| 1050 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1053 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1051 LayerImpl* child1 = root->test_properties()->children[0]; | 1054 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1052 LayerImpl* grand_child1 = | 1055 LayerImpl* grand_child1 = |
| 1053 root->test_properties()->children[0]->test_properties()->children[0]; | 1056 root->test_properties()->children[0]->test_properties()->children[0]; |
| 1054 gfx::Rect child_damage_rect; | 1057 gfx::Rect child_damage_rect; |
| 1055 gfx::Rect root_damage_rect; | 1058 gfx::Rect root_damage_rect; |
| 1056 | 1059 |
| 1057 ClearDamageForAllSurfaces(root); | 1060 ClearDamageForAllSurfaces(root); |
| 1058 grand_child1->SetPosition(gfx::PointF(195.f, 205.f)); | 1061 grand_child1->SetPosition(gfx::PointF(195.f, 205.f)); |
| 1059 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1062 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1060 EmulateDrawingOneFrame(root); | 1063 EmulateDrawingOneFrame(root); |
| 1061 EXPECT_TRUE(child1->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1064 EXPECT_TRUE( |
| 1062 &child_damage_rect)); | 1065 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1063 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1066 &child_damage_rect)); |
| 1067 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1064 &root_damage_rect)); | 1068 &root_damage_rect)); |
| 1065 | 1069 |
| 1066 // The new surface bounds should be damaged entirely, even though only one of | 1070 // The new surface bounds should be damaged entirely, even though only one of |
| 1067 // the layers changed. | 1071 // the layers changed. |
| 1068 EXPECT_EQ(gfx::Rect(190, 190, 11, 23).ToString(), | 1072 EXPECT_EQ(gfx::Rect(190, 190, 11, 23).ToString(), |
| 1069 child_damage_rect.ToString()); | 1073 child_damage_rect.ToString()); |
| 1070 | 1074 |
| 1071 // Damage to the root surface should be the union of child1's *entire* render | 1075 // Damage to the root surface should be the union of child1's *entire* render |
| 1072 // surface (in target space), and its old exposed area (also in target | 1076 // surface (in target space), and its old exposed area (also in target |
| 1073 // space). | 1077 // space). |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1091 LayerImpl* child1 = root->test_properties()->children[0]; | 1095 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1092 gfx::Rect child_damage_rect; | 1096 gfx::Rect child_damage_rect; |
| 1093 gfx::Rect root_damage_rect; | 1097 gfx::Rect root_damage_rect; |
| 1094 | 1098 |
| 1095 ClearDamageForAllSurfaces(root); | 1099 ClearDamageForAllSurfaces(root); |
| 1096 gfx::Transform translation; | 1100 gfx::Transform translation; |
| 1097 translation.Translate(-50.f, -50.f); | 1101 translation.Translate(-50.f, -50.f); |
| 1098 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( | 1102 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 1099 translation, child1->transform_tree_index(), root->layer_tree_impl()); | 1103 translation, child1->transform_tree_index(), root->layer_tree_impl()); |
| 1100 EmulateDrawingOneFrame(root); | 1104 EmulateDrawingOneFrame(root); |
| 1101 EXPECT_TRUE(child1->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1105 EXPECT_TRUE( |
| 1102 &child_damage_rect)); | 1106 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1103 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1107 &child_damage_rect)); |
| 1108 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1104 &root_damage_rect)); | 1109 &root_damage_rect)); |
| 1105 | 1110 |
| 1106 // The new surface bounds should be damaged entirely. | 1111 // The new surface bounds should be damaged entirely. |
| 1107 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 1112 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 1108 child_damage_rect.ToString()); | 1113 child_damage_rect.ToString()); |
| 1109 | 1114 |
| 1110 // The entire child1 surface and the old exposed child1 surface should damage | 1115 // The entire child1 surface and the old exposed child1 surface should damage |
| 1111 // the root surface. | 1116 // the root surface. |
| 1112 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18) | 1117 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18) |
| 1113 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18) | 1118 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18) |
| 1114 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(), | 1119 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(), |
| 1115 root_damage_rect.ToString()); | 1120 root_damage_rect.ToString()); |
| 1116 } | 1121 } |
| 1117 | 1122 |
| 1118 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) { | 1123 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) { |
| 1119 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1124 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1120 LayerImpl* child1 = root->test_properties()->children[0]; | 1125 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1121 gfx::Rect child_damage_rect; | 1126 gfx::Rect child_damage_rect; |
| 1122 gfx::Rect root_damage_rect; | 1127 gfx::Rect root_damage_rect; |
| 1123 | 1128 |
| 1124 // CASE 1: If a descendant surface disappears, its entire old area becomes | 1129 // CASE 1: If a descendant surface disappears, its entire old area becomes |
| 1125 // exposed. | 1130 // exposed. |
| 1126 ClearDamageForAllSurfaces(root); | 1131 ClearDamageForAllSurfaces(root); |
| 1127 child1->test_properties()->force_render_surface = false; | 1132 child1->test_properties()->force_render_surface = false; |
| 1128 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1133 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1129 EmulateDrawingOneFrame(root); | 1134 EmulateDrawingOneFrame(root); |
| 1130 | 1135 |
| 1131 // Sanity check that there is only one surface now. | 1136 // Sanity check that there is only one surface now. |
| 1132 ASSERT_FALSE(child1->render_surface()); | 1137 ASSERT_FALSE(child1->GetRenderSurface()); |
| 1133 ASSERT_EQ(4u, root->render_surface()->layer_list().size()); | 1138 ASSERT_EQ(4u, root->GetRenderSurface()->layer_list().size()); |
| 1134 | 1139 |
| 1135 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1140 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1136 &root_damage_rect)); | 1141 &root_damage_rect)); |
| 1137 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 1142 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
| 1138 root_damage_rect.ToString()); | 1143 root_damage_rect.ToString()); |
| 1139 | 1144 |
| 1140 // CASE 2: If a descendant surface appears, its entire old area becomes | 1145 // CASE 2: If a descendant surface appears, its entire old area becomes |
| 1141 // exposed. | 1146 // exposed. |
| 1142 | 1147 |
| 1143 // Cycle one frame of no change, just to sanity check that the next rect is | 1148 // Cycle one frame of no change, just to sanity check that the next rect is |
| 1144 // not because of the old damage state. | 1149 // not because of the old damage state. |
| 1145 ClearDamageForAllSurfaces(root); | 1150 ClearDamageForAllSurfaces(root); |
| 1146 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1151 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1147 EmulateDrawingOneFrame(root); | 1152 EmulateDrawingOneFrame(root); |
| 1148 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1153 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1149 &root_damage_rect)); | 1154 &root_damage_rect)); |
| 1150 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1155 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1151 | 1156 |
| 1152 // Then change the tree so that the render surface is added back. | 1157 // Then change the tree so that the render surface is added back. |
| 1153 ClearDamageForAllSurfaces(root); | 1158 ClearDamageForAllSurfaces(root); |
| 1154 child1->test_properties()->force_render_surface = true; | 1159 child1->test_properties()->force_render_surface = true; |
| 1155 | 1160 |
| 1156 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1161 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1157 EmulateDrawingOneFrame(root); | 1162 EmulateDrawingOneFrame(root); |
| 1158 | 1163 |
| 1159 // Sanity check that there is a new surface now. | 1164 // Sanity check that there is a new surface now. |
| 1160 ASSERT_TRUE(child1->render_surface()); | 1165 ASSERT_TRUE(child1->GetRenderSurface()); |
| 1161 EXPECT_EQ(3u, root->render_surface()->layer_list().size()); | 1166 EXPECT_EQ(3u, root->GetRenderSurface()->layer_list().size()); |
| 1162 EXPECT_EQ(2u, child1->render_surface()->layer_list().size()); | 1167 EXPECT_EQ(2u, child1->GetRenderSurface()->layer_list().size()); |
| 1163 | 1168 |
| 1164 EXPECT_TRUE(child1->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1169 EXPECT_TRUE( |
| 1165 &child_damage_rect)); | 1170 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1166 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1171 &child_damage_rect)); |
| 1172 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1167 &root_damage_rect)); | 1173 &root_damage_rect)); |
| 1168 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 1174 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 1169 child_damage_rect.ToString()); | 1175 child_damage_rect.ToString()); |
| 1170 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 1176 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
| 1171 root_damage_rect.ToString()); | 1177 root_damage_rect.ToString()); |
| 1172 } | 1178 } |
| 1173 | 1179 |
| 1174 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) { | 1180 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) { |
| 1175 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1181 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1176 LayerImpl* child1 = root->test_properties()->children[0]; | 1182 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1177 gfx::Rect child_damage_rect; | 1183 gfx::Rect child_damage_rect; |
| 1178 gfx::Rect root_damage_rect; | 1184 gfx::Rect root_damage_rect; |
| 1179 | 1185 |
| 1180 // CASE 1: If nothing changes, the damage rect should be empty. | 1186 // CASE 1: If nothing changes, the damage rect should be empty. |
| 1181 // | 1187 // |
| 1182 ClearDamageForAllSurfaces(root); | 1188 ClearDamageForAllSurfaces(root); |
| 1183 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1189 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1184 EmulateDrawingOneFrame(root); | 1190 EmulateDrawingOneFrame(root); |
| 1185 EXPECT_TRUE(child1->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1191 EXPECT_TRUE( |
| 1186 &child_damage_rect)); | 1192 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1187 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1193 &child_damage_rect)); |
| 1194 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1188 &root_damage_rect)); | 1195 &root_damage_rect)); |
| 1189 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1196 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
| 1190 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1197 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1191 | 1198 |
| 1192 // CASE 2: If nothing changes twice in a row, the damage rect should still be | 1199 // CASE 2: If nothing changes twice in a row, the damage rect should still be |
| 1193 // empty. | 1200 // empty. |
| 1194 // | 1201 // |
| 1195 ClearDamageForAllSurfaces(root); | 1202 ClearDamageForAllSurfaces(root); |
| 1196 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1203 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1197 EmulateDrawingOneFrame(root); | 1204 EmulateDrawingOneFrame(root); |
| 1198 EXPECT_TRUE(child1->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1205 EXPECT_TRUE( |
| 1199 &child_damage_rect)); | 1206 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1200 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1207 &child_damage_rect)); |
| 1208 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1201 &root_damage_rect)); | 1209 &root_damage_rect)); |
| 1202 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1210 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
| 1203 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1211 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1204 } | 1212 } |
| 1205 | 1213 |
| 1206 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) { | 1214 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) { |
| 1207 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1215 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1208 LayerImpl* child1 = root->test_properties()->children[0]; | 1216 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1209 gfx::Rect child_damage_rect; | 1217 gfx::Rect child_damage_rect; |
| 1210 gfx::Rect root_damage_rect; | 1218 gfx::Rect root_damage_rect; |
| 1211 | 1219 |
| 1212 // In our specific tree, the update rect of child1 should not cause any | 1220 // In our specific tree, the update rect of child1 should not cause any |
| 1213 // damage to any surface because it does not actually draw content. | 1221 // damage to any surface because it does not actually draw content. |
| 1214 ClearDamageForAllSurfaces(root); | 1222 ClearDamageForAllSurfaces(root); |
| 1215 child1->SetUpdateRect(gfx::Rect(1, 2)); | 1223 child1->SetUpdateRect(gfx::Rect(1, 2)); |
| 1216 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1224 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1217 EmulateDrawingOneFrame(root); | 1225 EmulateDrawingOneFrame(root); |
| 1218 EXPECT_TRUE(child1->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1226 EXPECT_TRUE( |
| 1219 &child_damage_rect)); | 1227 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1220 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1228 &child_damage_rect)); |
| 1229 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1221 &root_damage_rect)); | 1230 &root_damage_rect)); |
| 1222 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1231 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
| 1223 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1232 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1224 } | 1233 } |
| 1225 | 1234 |
| 1226 TEST_F(DamageTrackerTest, VerifyDamageForMask) { | 1235 TEST_F(DamageTrackerTest, VerifyDamageForMask) { |
| 1227 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1236 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 1228 LayerImpl* child = root->test_properties()->children[0]; | 1237 LayerImpl* child = root->test_properties()->children[0]; |
| 1229 | 1238 |
| 1230 // In the current implementation of the damage tracker, changes to mask | 1239 // In the current implementation of the damage tracker, changes to mask |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1256 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1265 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1257 EmulateDrawingOneFrame(root); | 1266 EmulateDrawingOneFrame(root); |
| 1258 | 1267 |
| 1259 // CASE 1: the update_rect on a mask layer should damage the entire target | 1268 // CASE 1: the update_rect on a mask layer should damage the entire target |
| 1260 // surface. | 1269 // surface. |
| 1261 ClearDamageForAllSurfaces(root); | 1270 ClearDamageForAllSurfaces(root); |
| 1262 mask_layer->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); | 1271 mask_layer->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); |
| 1263 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1272 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1264 EmulateDrawingOneFrame(root); | 1273 EmulateDrawingOneFrame(root); |
| 1265 gfx::Rect child_damage_rect; | 1274 gfx::Rect child_damage_rect; |
| 1266 EXPECT_TRUE(child->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1275 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1267 &child_damage_rect)); | 1276 &child_damage_rect)); |
| 1268 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 1277 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
| 1269 | 1278 |
| 1270 // CASE 2: a property change on the mask layer should damage the entire | 1279 // CASE 2: a property change on the mask layer should damage the entire |
| 1271 // target surface. | 1280 // target surface. |
| 1272 | 1281 |
| 1273 // Advance one frame without damage so that we know the damage rect is not | 1282 // Advance one frame without damage so that we know the damage rect is not |
| 1274 // leftover from the previous case. | 1283 // leftover from the previous case. |
| 1275 ClearDamageForAllSurfaces(root); | 1284 ClearDamageForAllSurfaces(root); |
| 1276 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1285 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1277 EmulateDrawingOneFrame(root); | 1286 EmulateDrawingOneFrame(root); |
| 1278 EXPECT_TRUE(child->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1287 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1279 &child_damage_rect)); | 1288 &child_damage_rect)); |
| 1280 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1289 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
| 1281 | 1290 |
| 1282 // Then test the property change. | 1291 // Then test the property change. |
| 1283 ClearDamageForAllSurfaces(root); | 1292 ClearDamageForAllSurfaces(root); |
| 1284 mask_layer->NoteLayerPropertyChanged(); | 1293 mask_layer->NoteLayerPropertyChanged(); |
| 1285 | 1294 |
| 1286 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1295 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1287 EmulateDrawingOneFrame(root); | 1296 EmulateDrawingOneFrame(root); |
| 1288 EXPECT_TRUE(child->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1297 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1289 &child_damage_rect)); | 1298 &child_damage_rect)); |
| 1290 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 1299 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
| 1291 | 1300 |
| 1292 // CASE 3: removing the mask also damages the entire target surface. | 1301 // CASE 3: removing the mask also damages the entire target surface. |
| 1293 // | 1302 // |
| 1294 | 1303 |
| 1295 // Advance one frame without damage so that we know the damage rect is not | 1304 // Advance one frame without damage so that we know the damage rect is not |
| 1296 // leftover from the previous case. | 1305 // leftover from the previous case. |
| 1297 ClearDamageForAllSurfaces(root); | 1306 ClearDamageForAllSurfaces(root); |
| 1298 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1307 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1299 EmulateDrawingOneFrame(root); | 1308 EmulateDrawingOneFrame(root); |
| 1300 EXPECT_TRUE(child->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1309 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1301 &child_damage_rect)); | 1310 &child_damage_rect)); |
| 1302 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1311 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
| 1303 | 1312 |
| 1304 // Then test mask removal. | 1313 // Then test mask removal. |
| 1305 ClearDamageForAllSurfaces(root); | 1314 ClearDamageForAllSurfaces(root); |
| 1306 child->test_properties()->SetMaskLayer(nullptr); | 1315 child->test_properties()->SetMaskLayer(nullptr); |
| 1307 child->NoteLayerPropertyChanged(); | 1316 child->NoteLayerPropertyChanged(); |
| 1308 ASSERT_TRUE(child->LayerPropertyChanged()); | 1317 ASSERT_TRUE(child->LayerPropertyChanged()); |
| 1309 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1318 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1310 EmulateDrawingOneFrame(root); | 1319 EmulateDrawingOneFrame(root); |
| 1311 | 1320 |
| 1312 // Sanity check that a render surface still exists. | 1321 // Sanity check that a render surface still exists. |
| 1313 ASSERT_TRUE(child->render_surface()); | 1322 ASSERT_TRUE(child->GetRenderSurface()); |
| 1314 | 1323 |
| 1315 EXPECT_TRUE(child->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1324 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1316 &child_damage_rect)); | 1325 &child_damage_rect)); |
| 1317 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 1326 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
| 1318 } | 1327 } |
| 1319 | 1328 |
| 1320 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) { | 1329 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) { |
| 1321 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1330 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 1322 LayerImpl* child = root->test_properties()->children[0]; | 1331 LayerImpl* child = root->test_properties()->children[0]; |
| 1323 | 1332 |
| 1324 // Case 1: This test ensures that when the tracker is given damage, that | 1333 // Case 1: This test ensures that when the tracker is given damage, that |
| 1325 // it is included with any other partial damage. | 1334 // it is included with any other partial damage. |
| 1326 // | 1335 // |
| 1327 ClearDamageForAllSurfaces(root); | 1336 ClearDamageForAllSurfaces(root); |
| 1328 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 1337 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
| 1329 root->render_surface()->damage_tracker()->AddDamageNextUpdate( | 1338 root->GetRenderSurface()->damage_tracker()->AddDamageNextUpdate( |
| 1330 gfx::Rect(15, 16, 32, 33)); | 1339 gfx::Rect(15, 16, 32, 33)); |
| 1331 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1340 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1332 EmulateDrawingOneFrame(root); | 1341 EmulateDrawingOneFrame(root); |
| 1333 gfx::Rect root_damage_rect; | 1342 gfx::Rect root_damage_rect; |
| 1334 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1343 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1335 &root_damage_rect)); | 1344 &root_damage_rect)); |
| 1336 EXPECT_EQ(gfx::UnionRects(gfx::Rect(15, 16, 32, 33), | 1345 EXPECT_EQ(gfx::UnionRects(gfx::Rect(15, 16, 32, 33), |
| 1337 gfx::Rect(100 + 10, 100 + 11, 12, 13)).ToString(), | 1346 gfx::Rect(100 + 10, 100 + 11, 12, 13)).ToString(), |
| 1338 root_damage_rect.ToString()); | 1347 root_damage_rect.ToString()); |
| 1339 | 1348 |
| 1340 // Case 2: An additional sanity check that adding damage works even when | 1349 // Case 2: An additional sanity check that adding damage works even when |
| 1341 // nothing on the layer tree changed. | 1350 // nothing on the layer tree changed. |
| 1342 // | 1351 // |
| 1343 ClearDamageForAllSurfaces(root); | 1352 ClearDamageForAllSurfaces(root); |
| 1344 root->render_surface()->damage_tracker()->AddDamageNextUpdate( | 1353 root->GetRenderSurface()->damage_tracker()->AddDamageNextUpdate( |
| 1345 gfx::Rect(30, 31, 14, 15)); | 1354 gfx::Rect(30, 31, 14, 15)); |
| 1346 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1355 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1347 EmulateDrawingOneFrame(root); | 1356 EmulateDrawingOneFrame(root); |
| 1348 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1357 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1349 &root_damage_rect)); | 1358 &root_damage_rect)); |
| 1350 EXPECT_EQ(gfx::Rect(30, 31, 14, 15).ToString(), root_damage_rect.ToString()); | 1359 EXPECT_EQ(gfx::Rect(30, 31, 14, 15).ToString(), root_damage_rect.ToString()); |
| 1351 } | 1360 } |
| 1352 | 1361 |
| 1353 TEST_F(DamageTrackerTest, VerifyDamageForEmptyLayerList) { | 1362 TEST_F(DamageTrackerTest, VerifyDamageForEmptyLayerList) { |
| 1354 // Though it should never happen, its a good idea to verify that the damage | 1363 // Though it should never happen, its a good idea to verify that the damage |
| 1355 // tracker does not crash when it receives an empty layer_list. | 1364 // tracker does not crash when it receives an empty layer_list. |
| 1356 | 1365 |
| 1357 std::unique_ptr<LayerImpl> root = | 1366 std::unique_ptr<LayerImpl> root = |
| 1358 LayerImpl::Create(host_impl_.active_tree(), 1); | 1367 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 1359 root->test_properties()->force_render_surface = true; | 1368 root->test_properties()->force_render_surface = true; |
| 1360 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root)); | 1369 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 1361 LayerImpl* root_ptr = host_impl_.active_tree()->root_layer_for_testing(); | 1370 LayerImpl* root_ptr = host_impl_.active_tree()->root_layer_for_testing(); |
| 1362 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1371 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1363 EmulateDrawingOneFrame(root_ptr); | 1372 EmulateDrawingOneFrame(root_ptr); |
| 1364 | 1373 |
| 1365 DCHECK_EQ(root_ptr->render_surface(), root_ptr->render_target()); | 1374 DCHECK_EQ(root_ptr->GetRenderSurface(), root_ptr->render_target()); |
| 1366 RenderSurfaceImpl* target_surface = root_ptr->render_surface(); | 1375 RenderSurfaceImpl* target_surface = root_ptr->GetRenderSurface(); |
| 1367 | 1376 |
| 1368 LayerImplList empty_list; | 1377 LayerImplList empty_list; |
| 1369 target_surface->damage_tracker()->UpdateDamageTrackingState( | 1378 target_surface->damage_tracker()->UpdateDamageTrackingState( |
| 1370 empty_list, target_surface, false, gfx::Rect(), NULL, FilterOperations()); | 1379 empty_list, target_surface, false, gfx::Rect(), NULL, FilterOperations()); |
| 1371 | 1380 |
| 1372 gfx::Rect damage_rect; | 1381 gfx::Rect damage_rect; |
| 1373 EXPECT_TRUE( | 1382 EXPECT_TRUE( |
| 1374 target_surface->damage_tracker()->GetDamageRectIfValid(&damage_rect)); | 1383 target_surface->damage_tracker()->GetDamageRectIfValid(&damage_rect)); |
| 1375 EXPECT_TRUE(damage_rect.IsEmpty()); | 1384 EXPECT_TRUE(damage_rect.IsEmpty()); |
| 1376 } | 1385 } |
| 1377 | 1386 |
| 1378 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) { | 1387 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) { |
| 1379 // If damage is not cleared, it should accumulate. | 1388 // If damage is not cleared, it should accumulate. |
| 1380 | 1389 |
| 1381 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1390 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 1382 LayerImpl* child = root->test_properties()->children[0]; | 1391 LayerImpl* child = root->test_properties()->children[0]; |
| 1383 | 1392 |
| 1384 ClearDamageForAllSurfaces(root); | 1393 ClearDamageForAllSurfaces(root); |
| 1385 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f)); | 1394 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f)); |
| 1386 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1395 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1387 EmulateDrawingOneFrame(root); | 1396 EmulateDrawingOneFrame(root); |
| 1388 | 1397 |
| 1389 // Sanity check damage after the first frame; this isnt the actual test yet. | 1398 // Sanity check damage after the first frame; this isnt the actual test yet. |
| 1390 gfx::Rect root_damage_rect; | 1399 gfx::Rect root_damage_rect; |
| 1391 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1400 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1392 &root_damage_rect)); | 1401 &root_damage_rect)); |
| 1393 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString()); | 1402 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString()); |
| 1394 | 1403 |
| 1395 // New damage, without having cleared the previous damage, should be unioned | 1404 // New damage, without having cleared the previous damage, should be unioned |
| 1396 // to the previous one. | 1405 // to the previous one. |
| 1397 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); | 1406 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); |
| 1398 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1407 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1399 EmulateDrawingOneFrame(root); | 1408 EmulateDrawingOneFrame(root); |
| 1400 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1409 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1401 &root_damage_rect)); | 1410 &root_damage_rect)); |
| 1402 EXPECT_EQ(gfx::Rect(110, 111, 11, 16).ToString(), | 1411 EXPECT_EQ(gfx::Rect(110, 111, 11, 16).ToString(), |
| 1403 root_damage_rect.ToString()); | 1412 root_damage_rect.ToString()); |
| 1404 | 1413 |
| 1405 // If we notify the damage tracker that we drew the damaged area, then damage | 1414 // If we notify the damage tracker that we drew the damaged area, then damage |
| 1406 // should be emptied. | 1415 // should be emptied. |
| 1407 root->render_surface()->damage_tracker()->DidDrawDamagedArea(); | 1416 root->GetRenderSurface()->damage_tracker()->DidDrawDamagedArea(); |
| 1408 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1417 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1409 &root_damage_rect)); | 1418 &root_damage_rect)); |
| 1410 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1419 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1411 | 1420 |
| 1412 // Damage should remain empty even after one frame, since there's yet no new | 1421 // Damage should remain empty even after one frame, since there's yet no new |
| 1413 // damage. | 1422 // damage. |
| 1414 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1423 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1415 EmulateDrawingOneFrame(root); | 1424 EmulateDrawingOneFrame(root); |
| 1416 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1425 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1417 &root_damage_rect)); | 1426 &root_damage_rect)); |
| 1418 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1427 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1419 } | 1428 } |
| 1420 | 1429 |
| 1421 TEST_F(DamageTrackerTest, HugeDamageRect) { | 1430 TEST_F(DamageTrackerTest, HugeDamageRect) { |
| 1422 // This number is so large that we start losting floating point accuracy. | 1431 // This number is so large that we start losting floating point accuracy. |
| 1423 const int kBigNumber = 900000000; | 1432 const int kBigNumber = 900000000; |
| 1424 // Walk over a range to find floating point inaccuracy boundaries that move | 1433 // Walk over a range to find floating point inaccuracy boundaries that move |
| 1425 // toward the wrong direction. | 1434 // toward the wrong direction. |
| 1426 const int kRange = 5000; | 1435 const int kRange = 5000; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1442 // Visible rects computed from combining clips in target space and root | 1451 // Visible rects computed from combining clips in target space and root |
| 1443 // space don't match because of the loss in floating point accuracy. So, we | 1452 // space don't match because of the loss in floating point accuracy. So, we |
| 1444 // skip verify_clip_tree_calculations. | 1453 // skip verify_clip_tree_calculations. |
| 1445 bool skip_verify_visible_rect_calculations = true; | 1454 bool skip_verify_visible_rect_calculations = true; |
| 1446 EmulateDrawingOneFrame(root, device_scale_factor, | 1455 EmulateDrawingOneFrame(root, device_scale_factor, |
| 1447 skip_verify_visible_rect_calculations); | 1456 skip_verify_visible_rect_calculations); |
| 1448 | 1457 |
| 1449 // The expected damage should cover the visible part of the child layer, | 1458 // The expected damage should cover the visible part of the child layer, |
| 1450 // which is (0, 0, i, i) in the viewport. | 1459 // which is (0, 0, i, i) in the viewport. |
| 1451 gfx::Rect root_damage_rect; | 1460 gfx::Rect root_damage_rect; |
| 1452 EXPECT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1461 EXPECT_TRUE( |
| 1453 &root_damage_rect)); | 1462 root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1463 &root_damage_rect)); |
| 1454 gfx::Rect damage_we_care_about = gfx::Rect(i, i); | 1464 gfx::Rect damage_we_care_about = gfx::Rect(i, i); |
| 1455 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); | 1465 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); |
| 1456 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); | 1466 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); |
| 1457 } | 1467 } |
| 1458 } | 1468 } |
| 1459 | 1469 |
| 1460 TEST_F(DamageTrackerTest, DamageRectTooBig) { | 1470 TEST_F(DamageTrackerTest, DamageRectTooBig) { |
| 1461 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2); | 1471 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2); |
| 1462 LayerImpl* child1 = root->test_properties()->children[0]; | 1472 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1463 LayerImpl* child2 = root->test_properties()->children[1]; | 1473 LayerImpl* child2 = root->test_properties()->children[1]; |
| 1464 | 1474 |
| 1465 // Really far left. | 1475 // Really far left. |
| 1466 child1->SetPosition(gfx::PointF(std::numeric_limits<int>::min() + 100, 0)); | 1476 child1->SetPosition(gfx::PointF(std::numeric_limits<int>::min() + 100, 0)); |
| 1467 child1->SetBounds(gfx::Size(1, 1)); | 1477 child1->SetBounds(gfx::Size(1, 1)); |
| 1468 | 1478 |
| 1469 // Really far right. | 1479 // Really far right. |
| 1470 child2->SetPosition(gfx::PointF(std::numeric_limits<int>::max() - 100, 0)); | 1480 child2->SetPosition(gfx::PointF(std::numeric_limits<int>::max() - 100, 0)); |
| 1471 child2->SetBounds(gfx::Size(1, 1)); | 1481 child2->SetBounds(gfx::Size(1, 1)); |
| 1472 | 1482 |
| 1473 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1483 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1474 float device_scale_factor = 1.f; | 1484 float device_scale_factor = 1.f; |
| 1475 bool skip_verify_visible_rect_calculations = true; | 1485 bool skip_verify_visible_rect_calculations = true; |
| 1476 EmulateDrawingOneFrame(root, device_scale_factor, | 1486 EmulateDrawingOneFrame(root, device_scale_factor, |
| 1477 skip_verify_visible_rect_calculations); | 1487 skip_verify_visible_rect_calculations); |
| 1478 | 1488 |
| 1479 // The expected damage would be too large to store in a gfx::Rect, so we | 1489 // The expected damage would be too large to store in a gfx::Rect, so we |
| 1480 // should damage everything (ie, we don't have a valid rect). | 1490 // should damage everything (ie, we don't have a valid rect). |
| 1481 gfx::Rect damage_rect; | 1491 gfx::Rect damage_rect; |
| 1482 EXPECT_FALSE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1492 EXPECT_FALSE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1483 &damage_rect)); | 1493 &damage_rect)); |
| 1484 EXPECT_EQ(root->render_surface()->content_rect(), | 1494 EXPECT_EQ(root->GetRenderSurface()->content_rect(), |
| 1485 root->render_surface()->GetDamageRect()); | 1495 root->GetRenderSurface()->GetDamageRect()); |
| 1486 } | 1496 } |
| 1487 | 1497 |
| 1488 TEST_F(DamageTrackerTest, DamageRectTooBigWithFilter) { | 1498 TEST_F(DamageTrackerTest, DamageRectTooBigWithFilter) { |
| 1489 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2); | 1499 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2); |
| 1490 LayerImpl* child1 = root->test_properties()->children[0]; | 1500 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1491 LayerImpl* child2 = root->test_properties()->children[1]; | 1501 LayerImpl* child2 = root->test_properties()->children[1]; |
| 1492 | 1502 |
| 1493 FilterOperations filters; | 1503 FilterOperations filters; |
| 1494 filters.Append(FilterOperation::CreateBlurFilter(5.f)); | 1504 filters.Append(FilterOperation::CreateBlurFilter(5.f)); |
| 1495 root->SetDrawsContent(true); | 1505 root->SetDrawsContent(true); |
| 1496 root->test_properties()->background_filters = filters; | 1506 root->test_properties()->background_filters = filters; |
| 1497 | 1507 |
| 1498 // Really far left. | 1508 // Really far left. |
| 1499 child1->SetPosition(gfx::PointF(std::numeric_limits<int>::min() + 100, 0)); | 1509 child1->SetPosition(gfx::PointF(std::numeric_limits<int>::min() + 100, 0)); |
| 1500 child1->SetBounds(gfx::Size(1, 1)); | 1510 child1->SetBounds(gfx::Size(1, 1)); |
| 1501 | 1511 |
| 1502 // Really far right. | 1512 // Really far right. |
| 1503 child2->SetPosition(gfx::PointF(std::numeric_limits<int>::max() - 100, 0)); | 1513 child2->SetPosition(gfx::PointF(std::numeric_limits<int>::max() - 100, 0)); |
| 1504 child2->SetBounds(gfx::Size(1, 1)); | 1514 child2->SetBounds(gfx::Size(1, 1)); |
| 1505 | 1515 |
| 1506 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1516 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1507 float device_scale_factor = 1.f; | 1517 float device_scale_factor = 1.f; |
| 1508 bool skip_verify_visible_rect_calculations = true; | 1518 bool skip_verify_visible_rect_calculations = true; |
| 1509 EmulateDrawingOneFrame(root, device_scale_factor, | 1519 EmulateDrawingOneFrame(root, device_scale_factor, |
| 1510 skip_verify_visible_rect_calculations); | 1520 skip_verify_visible_rect_calculations); |
| 1511 | 1521 |
| 1512 // The expected damage would be too large to store in a gfx::Rect, so we | 1522 // The expected damage would be too large to store in a gfx::Rect, so we |
| 1513 // should damage everything (ie, we don't have a valid rect). | 1523 // should damage everything (ie, we don't have a valid rect). |
| 1514 gfx::Rect damage_rect; | 1524 gfx::Rect damage_rect; |
| 1515 EXPECT_FALSE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1525 EXPECT_FALSE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1516 &damage_rect)); | 1526 &damage_rect)); |
| 1517 EXPECT_EQ(root->render_surface()->content_rect(), | 1527 EXPECT_EQ(root->GetRenderSurface()->content_rect(), |
| 1518 root->render_surface()->GetDamageRect()); | 1528 root->GetRenderSurface()->GetDamageRect()); |
| 1519 } | 1529 } |
| 1520 | 1530 |
| 1521 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurface) { | 1531 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurface) { |
| 1522 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1532 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1523 LayerImpl* child1 = root->test_properties()->children[0]; | 1533 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1524 LayerImpl* grandchild1 = child1->test_properties()->children[0]; | 1534 LayerImpl* grandchild1 = child1->test_properties()->children[0]; |
| 1525 LayerImpl* grandchild2 = child1->test_properties()->children[1]; | 1535 LayerImpl* grandchild2 = child1->test_properties()->children[1]; |
| 1526 | 1536 |
| 1527 // Really far left. | 1537 // Really far left. |
| 1528 grandchild1->SetPosition( | 1538 grandchild1->SetPosition( |
| 1529 gfx::PointF(std::numeric_limits<int>::min() + 500, 0)); | 1539 gfx::PointF(std::numeric_limits<int>::min() + 500, 0)); |
| 1530 grandchild1->SetBounds(gfx::Size(1, 1)); | 1540 grandchild1->SetBounds(gfx::Size(1, 1)); |
| 1531 grandchild1->SetDrawsContent(true); | 1541 grandchild1->SetDrawsContent(true); |
| 1532 | 1542 |
| 1533 // Really far right. | 1543 // Really far right. |
| 1534 grandchild2->SetPosition( | 1544 grandchild2->SetPosition( |
| 1535 gfx::PointF(std::numeric_limits<int>::max() - 500, 0)); | 1545 gfx::PointF(std::numeric_limits<int>::max() - 500, 0)); |
| 1536 grandchild2->SetBounds(gfx::Size(1, 1)); | 1546 grandchild2->SetBounds(gfx::Size(1, 1)); |
| 1537 grandchild2->SetDrawsContent(true); | 1547 grandchild2->SetDrawsContent(true); |
| 1538 | 1548 |
| 1539 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1549 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1540 float device_scale_factor = 1.f; | 1550 float device_scale_factor = 1.f; |
| 1541 bool skip_verify_visible_rect_calculations = true; | 1551 bool skip_verify_visible_rect_calculations = true; |
| 1542 LayerImplList render_surface_layer_list; | 1552 LayerImplList render_surface_layer_list; |
| 1543 ExecuteCalculateDrawProperties(root, device_scale_factor, | 1553 ExecuteCalculateDrawProperties(root, device_scale_factor, |
| 1544 skip_verify_visible_rect_calculations, | 1554 skip_verify_visible_rect_calculations, |
| 1545 &render_surface_layer_list); | 1555 &render_surface_layer_list); |
| 1546 | 1556 |
| 1547 auto* surface = child1->render_surface(); | 1557 auto* surface = child1->GetRenderSurface(); |
| 1548 surface->damage_tracker()->UpdateDamageTrackingState( | 1558 surface->damage_tracker()->UpdateDamageTrackingState( |
| 1549 surface->layer_list(), surface, false, surface->content_rect(), | 1559 surface->layer_list(), surface, false, surface->content_rect(), |
| 1550 surface->MaskLayer(), surface->Filters()); | 1560 surface->MaskLayer(), surface->Filters()); |
| 1551 surface = root->render_surface(); | 1561 surface = root->GetRenderSurface(); |
| 1552 surface->damage_tracker()->UpdateDamageTrackingState( | 1562 surface->damage_tracker()->UpdateDamageTrackingState( |
| 1553 surface->layer_list(), surface, false, surface->content_rect(), | 1563 surface->layer_list(), surface, false, surface->content_rect(), |
| 1554 surface->MaskLayer(), surface->Filters()); | 1564 surface->MaskLayer(), surface->Filters()); |
| 1555 | 1565 |
| 1556 // The expected damage would be too large to store in a gfx::Rect, so we | 1566 // The expected damage would be too large to store in a gfx::Rect, so we |
| 1557 // should damage everything on child1. | 1567 // should damage everything on child1. |
| 1558 gfx::Rect damage_rect; | 1568 gfx::Rect damage_rect; |
| 1559 EXPECT_FALSE(child1->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1569 EXPECT_FALSE( |
| 1560 &damage_rect)); | 1570 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1561 EXPECT_EQ(child1->render_surface()->content_rect(), | 1571 &damage_rect)); |
| 1562 child1->render_surface()->GetDamageRect()); | 1572 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), |
| 1573 child1->GetRenderSurface()->GetDamageRect()); |
| 1563 | 1574 |
| 1564 // However, the root should just use the child1 render surface's content rect | 1575 // However, the root should just use the child1 render surface's content rect |
| 1565 // as damage. | 1576 // as damage. |
| 1566 ASSERT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1577 ASSERT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1567 &damage_rect)); | 1578 &damage_rect)); |
| 1568 EXPECT_TRUE(damage_rect.Contains(root->render_surface()->content_rect())); | 1579 EXPECT_TRUE(damage_rect.Contains(root->GetRenderSurface()->content_rect())); |
| 1569 EXPECT_TRUE(damage_rect.Contains( | 1580 EXPECT_TRUE(damage_rect.Contains( |
| 1570 gfx::ToEnclosingRect(child1->render_surface()->DrawableContentRect()))); | 1581 gfx::ToEnclosingRect(child1->GetRenderSurface()->DrawableContentRect()))); |
| 1571 EXPECT_EQ(damage_rect, root->render_surface()->GetDamageRect()); | 1582 EXPECT_EQ(damage_rect, root->GetRenderSurface()->GetDamageRect()); |
| 1572 | 1583 |
| 1573 // Add new damage, without changing properties, which goes down a different | 1584 // Add new damage, without changing properties, which goes down a different |
| 1574 // path in the damage tracker. | 1585 // path in the damage tracker. |
| 1575 root->layer_tree_impl()->ResetAllChangeTracking(); | 1586 root->layer_tree_impl()->ResetAllChangeTracking(); |
| 1576 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1587 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
| 1577 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1588 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
| 1578 | 1589 |
| 1579 // Recompute all damage / properties. | 1590 // Recompute all damage / properties. |
| 1580 render_surface_layer_list.clear(); | 1591 render_surface_layer_list.clear(); |
| 1581 ExecuteCalculateDrawProperties(root, device_scale_factor, | 1592 ExecuteCalculateDrawProperties(root, device_scale_factor, |
| 1582 skip_verify_visible_rect_calculations, | 1593 skip_verify_visible_rect_calculations, |
| 1583 &render_surface_layer_list); | 1594 &render_surface_layer_list); |
| 1584 surface = child1->render_surface(); | 1595 surface = child1->GetRenderSurface(); |
| 1585 surface->damage_tracker()->UpdateDamageTrackingState( | 1596 surface->damage_tracker()->UpdateDamageTrackingState( |
| 1586 surface->layer_list(), surface, false, surface->content_rect(), | 1597 surface->layer_list(), surface, false, surface->content_rect(), |
| 1587 surface->MaskLayer(), surface->Filters()); | 1598 surface->MaskLayer(), surface->Filters()); |
| 1588 surface = root->render_surface(); | 1599 surface = root->GetRenderSurface(); |
| 1589 surface->damage_tracker()->UpdateDamageTrackingState( | 1600 surface->damage_tracker()->UpdateDamageTrackingState( |
| 1590 surface->layer_list(), surface, false, surface->content_rect(), | 1601 surface->layer_list(), surface, false, surface->content_rect(), |
| 1591 surface->MaskLayer(), surface->Filters()); | 1602 surface->MaskLayer(), surface->Filters()); |
| 1592 | 1603 |
| 1593 // Child1 should still not have a valid rect, since the union of the damage of | 1604 // Child1 should still not have a valid rect, since the union of the damage of |
| 1594 // its children is not representable by a single rect. | 1605 // its children is not representable by a single rect. |
| 1595 EXPECT_FALSE(child1->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1606 EXPECT_FALSE( |
| 1596 &damage_rect)); | 1607 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1597 EXPECT_EQ(child1->render_surface()->content_rect(), | 1608 &damage_rect)); |
| 1598 child1->render_surface()->GetDamageRect()); | 1609 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), |
| 1610 child1->GetRenderSurface()->GetDamageRect()); |
| 1599 | 1611 |
| 1600 // Root should have valid damage and contain both its content rect and the | 1612 // Root should have valid damage and contain both its content rect and the |
| 1601 // drawable content rect of child1. | 1613 // drawable content rect of child1. |
| 1602 ASSERT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1614 ASSERT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1603 &damage_rect)); | 1615 &damage_rect)); |
| 1604 EXPECT_TRUE(damage_rect.Contains(root->render_surface()->content_rect())); | 1616 EXPECT_TRUE(damage_rect.Contains(root->GetRenderSurface()->content_rect())); |
| 1605 EXPECT_TRUE(damage_rect.Contains( | 1617 EXPECT_TRUE(damage_rect.Contains( |
| 1606 gfx::ToEnclosingRect(child1->render_surface()->DrawableContentRect()))); | 1618 gfx::ToEnclosingRect(child1->GetRenderSurface()->DrawableContentRect()))); |
| 1607 EXPECT_EQ(damage_rect, root->render_surface()->GetDamageRect()); | 1619 EXPECT_EQ(damage_rect, root->GetRenderSurface()->GetDamageRect()); |
| 1608 } | 1620 } |
| 1609 | 1621 |
| 1610 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurfaceWithFilter) { | 1622 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurfaceWithFilter) { |
| 1611 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1623 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1612 LayerImpl* child1 = root->test_properties()->children[0]; | 1624 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1613 LayerImpl* grandchild1 = child1->test_properties()->children[0]; | 1625 LayerImpl* grandchild1 = child1->test_properties()->children[0]; |
| 1614 LayerImpl* grandchild2 = child1->test_properties()->children[1]; | 1626 LayerImpl* grandchild2 = child1->test_properties()->children[1]; |
| 1615 | 1627 |
| 1616 // Set up a moving pixels filter on the child. | 1628 // Set up a moving pixels filter on the child. |
| 1617 FilterOperations filters; | 1629 FilterOperations filters; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1632 grandchild2->SetDrawsContent(true); | 1644 grandchild2->SetDrawsContent(true); |
| 1633 | 1645 |
| 1634 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1646 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1635 float device_scale_factor = 1.f; | 1647 float device_scale_factor = 1.f; |
| 1636 bool skip_verify_visible_rect_calculations = true; | 1648 bool skip_verify_visible_rect_calculations = true; |
| 1637 LayerImplList render_surface_layer_list; | 1649 LayerImplList render_surface_layer_list; |
| 1638 ExecuteCalculateDrawProperties(root, device_scale_factor, | 1650 ExecuteCalculateDrawProperties(root, device_scale_factor, |
| 1639 skip_verify_visible_rect_calculations, | 1651 skip_verify_visible_rect_calculations, |
| 1640 &render_surface_layer_list); | 1652 &render_surface_layer_list); |
| 1641 | 1653 |
| 1642 auto* surface = child1->render_surface(); | 1654 auto* surface = child1->GetRenderSurface(); |
| 1643 surface->damage_tracker()->UpdateDamageTrackingState( | 1655 surface->damage_tracker()->UpdateDamageTrackingState( |
| 1644 surface->layer_list(), surface, false, surface->content_rect(), | 1656 surface->layer_list(), surface, false, surface->content_rect(), |
| 1645 surface->MaskLayer(), surface->Filters()); | 1657 surface->MaskLayer(), surface->Filters()); |
| 1646 surface = root->render_surface(); | 1658 surface = root->GetRenderSurface(); |
| 1647 surface->damage_tracker()->UpdateDamageTrackingState( | 1659 surface->damage_tracker()->UpdateDamageTrackingState( |
| 1648 surface->layer_list(), surface, false, surface->content_rect(), | 1660 surface->layer_list(), surface, false, surface->content_rect(), |
| 1649 surface->MaskLayer(), surface->Filters()); | 1661 surface->MaskLayer(), surface->Filters()); |
| 1650 | 1662 |
| 1651 // The expected damage would be too large to store in a gfx::Rect, so we | 1663 // The expected damage would be too large to store in a gfx::Rect, so we |
| 1652 // should damage everything on child1. | 1664 // should damage everything on child1. |
| 1653 gfx::Rect damage_rect; | 1665 gfx::Rect damage_rect; |
| 1654 EXPECT_FALSE(child1->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1666 EXPECT_FALSE( |
| 1655 &damage_rect)); | 1667 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1656 EXPECT_EQ(child1->render_surface()->content_rect(), | 1668 &damage_rect)); |
| 1657 child1->render_surface()->GetDamageRect()); | 1669 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), |
| 1670 child1->GetRenderSurface()->GetDamageRect()); |
| 1658 | 1671 |
| 1659 // However, the root should just use the child1 render surface's content rect | 1672 // However, the root should just use the child1 render surface's content rect |
| 1660 // as damage. | 1673 // as damage. |
| 1661 ASSERT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1674 ASSERT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1662 &damage_rect)); | 1675 &damage_rect)); |
| 1663 EXPECT_TRUE(damage_rect.Contains(root->render_surface()->content_rect())); | 1676 EXPECT_TRUE(damage_rect.Contains(root->GetRenderSurface()->content_rect())); |
| 1664 EXPECT_TRUE(damage_rect.Contains( | 1677 EXPECT_TRUE(damage_rect.Contains( |
| 1665 gfx::ToEnclosingRect(child1->render_surface()->DrawableContentRect()))); | 1678 gfx::ToEnclosingRect(child1->GetRenderSurface()->DrawableContentRect()))); |
| 1666 EXPECT_EQ(damage_rect, root->render_surface()->GetDamageRect()); | 1679 EXPECT_EQ(damage_rect, root->GetRenderSurface()->GetDamageRect()); |
| 1667 | 1680 |
| 1668 // Add new damage, without changing properties, which goes down a different | 1681 // Add new damage, without changing properties, which goes down a different |
| 1669 // path in the damage tracker. | 1682 // path in the damage tracker. |
| 1670 root->layer_tree_impl()->ResetAllChangeTracking(); | 1683 root->layer_tree_impl()->ResetAllChangeTracking(); |
| 1671 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1684 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
| 1672 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1685 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
| 1673 | 1686 |
| 1674 // Recompute all damage / properties. | 1687 // Recompute all damage / properties. |
| 1675 render_surface_layer_list.clear(); | 1688 render_surface_layer_list.clear(); |
| 1676 ExecuteCalculateDrawProperties(root, device_scale_factor, | 1689 ExecuteCalculateDrawProperties(root, device_scale_factor, |
| 1677 skip_verify_visible_rect_calculations, | 1690 skip_verify_visible_rect_calculations, |
| 1678 &render_surface_layer_list); | 1691 &render_surface_layer_list); |
| 1679 surface = child1->render_surface(); | 1692 surface = child1->GetRenderSurface(); |
| 1680 surface->damage_tracker()->UpdateDamageTrackingState( | 1693 surface->damage_tracker()->UpdateDamageTrackingState( |
| 1681 surface->layer_list(), surface, false, surface->content_rect(), | 1694 surface->layer_list(), surface, false, surface->content_rect(), |
| 1682 surface->MaskLayer(), surface->Filters()); | 1695 surface->MaskLayer(), surface->Filters()); |
| 1683 surface = root->render_surface(); | 1696 surface = root->GetRenderSurface(); |
| 1684 surface->damage_tracker()->UpdateDamageTrackingState( | 1697 surface->damage_tracker()->UpdateDamageTrackingState( |
| 1685 surface->layer_list(), surface, false, surface->content_rect(), | 1698 surface->layer_list(), surface, false, surface->content_rect(), |
| 1686 surface->MaskLayer(), surface->Filters()); | 1699 surface->MaskLayer(), surface->Filters()); |
| 1687 | 1700 |
| 1688 // Child1 should still not have a valid rect, since the union of the damage of | 1701 // Child1 should still not have a valid rect, since the union of the damage of |
| 1689 // its children is not representable by a single rect. | 1702 // its children is not representable by a single rect. |
| 1690 EXPECT_FALSE(child1->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1703 EXPECT_FALSE( |
| 1691 &damage_rect)); | 1704 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1692 EXPECT_EQ(child1->render_surface()->content_rect(), | 1705 &damage_rect)); |
| 1693 child1->render_surface()->GetDamageRect()); | 1706 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), |
| 1707 child1->GetRenderSurface()->GetDamageRect()); |
| 1694 | 1708 |
| 1695 // Root should have valid damage and contain both its content rect and the | 1709 // Root should have valid damage and contain both its content rect and the |
| 1696 // drawable content rect of child1. | 1710 // drawable content rect of child1. |
| 1697 ASSERT_TRUE(root->render_surface()->damage_tracker()->GetDamageRectIfValid( | 1711 ASSERT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1698 &damage_rect)); | 1712 &damage_rect)); |
| 1699 EXPECT_TRUE(damage_rect.Contains(root->render_surface()->content_rect())); | 1713 EXPECT_TRUE(damage_rect.Contains(root->GetRenderSurface()->content_rect())); |
| 1700 EXPECT_TRUE(damage_rect.Contains( | 1714 EXPECT_TRUE(damage_rect.Contains( |
| 1701 gfx::ToEnclosingRect(child1->render_surface()->DrawableContentRect()))); | 1715 gfx::ToEnclosingRect(child1->GetRenderSurface()->DrawableContentRect()))); |
| 1702 EXPECT_EQ(damage_rect, root->render_surface()->GetDamageRect()); | 1716 EXPECT_EQ(damage_rect, root->GetRenderSurface()->GetDamageRect()); |
| 1703 } | 1717 } |
| 1704 | 1718 |
| 1705 } // namespace | 1719 } // namespace |
| 1706 } // namespace cc | 1720 } // namespace cc |
| OLD | NEW |