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

Side by Side Diff: cc/trees/damage_tracker_unittest.cc

Issue 2857343002: Delete LayerImpl::GetRenderSurface. (Closed)
Patch Set: none Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/test/layer_test_common.cc ('k') | cc/trees/layer_tree_host_common_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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/filter_operation.h" 9 #include "cc/base/filter_operation.h"
10 #include "cc/base/filter_operations.h" 10 #include "cc/base/filter_operations.h"
11 #include "cc/base/math_util.h" 11 #include "cc/base/math_util.h"
12 #include "cc/layers/layer_impl.h" 12 #include "cc/layers/layer_impl.h"
13 #include "cc/test/fake_impl_task_runner_provider.h" 13 #include "cc/test/fake_impl_task_runner_provider.h"
14 #include "cc/test/fake_layer_tree_host_impl.h" 14 #include "cc/test/fake_layer_tree_host_impl.h"
15 #include "cc/test/geometry_test_utils.h" 15 #include "cc/test/geometry_test_utils.h"
16 #include "cc/test/layer_test_common.h"
16 #include "cc/test/test_task_graph_runner.h" 17 #include "cc/test/test_task_graph_runner.h"
17 #include "cc/trees/layer_tree_host_common.h" 18 #include "cc/trees/layer_tree_host_common.h"
18 #include "cc/trees/layer_tree_impl.h" 19 #include "cc/trees/layer_tree_impl.h"
19 #include "cc/trees/single_thread_proxy.h" 20 #include "cc/trees/single_thread_proxy.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/skia/include/effects/SkBlurImageFilter.h" 22 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
22 #include "ui/gfx/geometry/quad_f.h" 23 #include "ui/gfx/geometry/quad_f.h"
23 #include "ui/gfx/geometry/rect_conversions.h" 24 #include "ui/gfx/geometry/rect_conversions.h"
24 25
25 namespace cc { 26 namespace cc {
26 namespace { 27 namespace {
27 28
28 void ExecuteCalculateDrawProperties(LayerImpl* root, 29 void ExecuteCalculateDrawProperties(LayerImpl* root,
29 float device_scale_factor, 30 float device_scale_factor,
30 RenderSurfaceList* render_surface_list) { 31 RenderSurfaceList* render_surface_list) {
31 // Sanity check: The test itself should create the root layer's render 32 // Sanity check: The test itself should create the root layer's render
32 // surface, so that the surface (and its damage tracker) can 33 // surface, so that the surface (and its damage tracker) can
33 // persist across multiple calls to this function. 34 // persist across multiple calls to this function.
34 ASSERT_FALSE(render_surface_list->size()); 35 ASSERT_FALSE(render_surface_list->size());
35 36
36 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 37 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
37 root, root->bounds(), device_scale_factor, render_surface_list); 38 root, root->bounds(), device_scale_factor, render_surface_list);
38 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); 39 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
39 ASSERT_TRUE(root->GetRenderSurface()); 40 ASSERT_TRUE(GetRenderSurface(root));
40 } 41 }
41 42
42 void ClearDamageForAllSurfaces(LayerImpl* root) { 43 void ClearDamageForAllSurfaces(LayerImpl* root) {
43 for (auto* layer : *root->layer_tree_impl()) { 44 for (auto* layer : *root->layer_tree_impl()) {
44 if (layer->GetRenderSurface()) 45 if (GetRenderSurface(layer))
45 layer->GetRenderSurface()->damage_tracker()->DidDrawDamagedArea(); 46 GetRenderSurface(layer)->damage_tracker()->DidDrawDamagedArea();
46 } 47 }
47 } 48 }
48 49
49 void EmulateDrawingOneFrame(LayerImpl* root, float device_scale_factor = 1.f) { 50 void EmulateDrawingOneFrame(LayerImpl* root, float device_scale_factor = 1.f) {
50 // This emulates only steps that are relevant to testing the damage tracker: 51 // This emulates only steps that are relevant to testing the damage tracker:
51 // 1. computing the render passes and layerlists 52 // 1. computing the render passes and layerlists
52 // 2. updating all damage trackers in the correct order 53 // 2. updating all damage trackers in the correct order
53 // 3. resetting all update_rects and property_changed flags for all layers 54 // 3. resetting all update_rects and property_changed flags for all layers
54 // and surfaces. 55 // and surfaces.
55 56
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 FakeLayerTreeHostImpl host_impl_; 173 FakeLayerTreeHostImpl host_impl_;
173 }; 174 };
174 175
175 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithOneSurface) { 176 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithOneSurface) {
176 // Sanity check that the simple test tree will actually produce the expected 177 // Sanity check that the simple test tree will actually produce the expected
177 // render surfaces. 178 // render surfaces.
178 179
179 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 180 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
180 LayerImpl* child = root->test_properties()->children[0]; 181 LayerImpl* child = root->test_properties()->children[0];
181 182
182 EXPECT_EQ(2, root->GetRenderSurface()->num_contributors()); 183 EXPECT_EQ(2, GetRenderSurface(root)->num_contributors());
183 EXPECT_TRUE(root->contributes_to_drawn_render_surface()); 184 EXPECT_TRUE(root->contributes_to_drawn_render_surface());
184 EXPECT_TRUE(child->contributes_to_drawn_render_surface()); 185 EXPECT_TRUE(child->contributes_to_drawn_render_surface());
185 186
186 gfx::Rect root_damage_rect; 187 gfx::Rect root_damage_rect;
187 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 188 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
188 &root_damage_rect)); 189 &root_damage_rect));
189 190
190 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); 191 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString());
191 } 192 }
192 193
193 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) { 194 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) {
194 // Sanity check that the complex test tree will actually produce the expected 195 // Sanity check that the complex test tree will actually produce the expected
195 // render surfaces. 196 // render surfaces.
196 197
197 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 198 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
198 199
199 LayerImpl* child1 = root->test_properties()->children[0]; 200 LayerImpl* child1 = root->test_properties()->children[0];
200 LayerImpl* child2 = root->test_properties()->children[1]; 201 LayerImpl* child2 = root->test_properties()->children[1];
201 202
202 gfx::Rect child_damage_rect; 203 gfx::Rect child_damage_rect;
203 EXPECT_TRUE( 204 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid(
204 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 205 &child_damage_rect));
205 &child_damage_rect));
206 gfx::Rect root_damage_rect; 206 gfx::Rect root_damage_rect;
207 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 207 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
208 &root_damage_rect)); 208 &root_damage_rect));
209 209
210 ASSERT_TRUE(child1->GetRenderSurface()); 210 ASSERT_TRUE(GetRenderSurface(child1));
211 EXPECT_FALSE(child2->GetRenderSurface()); 211 EXPECT_FALSE(GetRenderSurface(child2));
212 EXPECT_EQ(3, root->GetRenderSurface()->num_contributors()); 212 EXPECT_EQ(3, GetRenderSurface(root)->num_contributors());
213 EXPECT_EQ(2, child1->GetRenderSurface()->num_contributors()); 213 EXPECT_EQ(2, GetRenderSurface(child1)->num_contributors());
214 214
215 // The render surface for child1 only has a content_rect that encloses 215 // The render surface for child1 only has a content_rect that encloses
216 // grand_child1 and grand_child2, because child1 does not draw content. 216 // grand_child1 and grand_child2, because child1 does not draw content.
217 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), 217 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(),
218 child_damage_rect.ToString()); 218 child_damage_rect.ToString());
219 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); 219 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString());
220 } 220 }
221 221
222 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) { 222 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) {
223 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 223 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
224 LayerImpl* child = root->test_properties()->children[0]; 224 LayerImpl* child = root->test_properties()->children[0];
225 225
226 // CASE 1: Setting the update rect should cause the corresponding damage to 226 // CASE 1: Setting the update rect should cause the corresponding damage to
227 // the surface. 227 // the surface.
228 ClearDamageForAllSurfaces(root); 228 ClearDamageForAllSurfaces(root);
229 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); 229 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13));
230 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 230 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
231 EmulateDrawingOneFrame(root); 231 EmulateDrawingOneFrame(root);
232 232
233 // Damage position on the surface should be: position of update_rect (10, 11) 233 // Damage position on the surface should be: position of update_rect (10, 11)
234 // relative to the child (100, 100). 234 // relative to the child (100, 100).
235 gfx::Rect root_damage_rect; 235 gfx::Rect root_damage_rect;
236 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 236 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
237 &root_damage_rect)); 237 &root_damage_rect));
238 EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(), 238 EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(),
239 root_damage_rect.ToString()); 239 root_damage_rect.ToString());
240 240
241 // CASE 2: The same update rect twice in a row still produces the same 241 // CASE 2: The same update rect twice in a row still produces the same
242 // damage. 242 // damage.
243 ClearDamageForAllSurfaces(root); 243 ClearDamageForAllSurfaces(root);
244 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); 244 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13));
245 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 245 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
246 EmulateDrawingOneFrame(root); 246 EmulateDrawingOneFrame(root);
247 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 247 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
248 &root_damage_rect)); 248 &root_damage_rect));
249 EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(), 249 EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(),
250 root_damage_rect.ToString()); 250 root_damage_rect.ToString());
251 251
252 // CASE 3: Setting a different update rect should cause damage on the new 252 // CASE 3: Setting a different update rect should cause damage on the new
253 // update region, but no additional exposed old region. 253 // update region, but no additional exposed old region.
254 ClearDamageForAllSurfaces(root); 254 ClearDamageForAllSurfaces(root);
255 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); 255 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2));
256 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 256 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
257 EmulateDrawingOneFrame(root); 257 EmulateDrawingOneFrame(root);
258 258
259 // Damage position on the surface should be: position of update_rect (20, 25) 259 // Damage position on the surface should be: position of update_rect (20, 25)
260 // relative to the child (100, 100). 260 // relative to the child (100, 100).
261 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 261 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
262 &root_damage_rect)); 262 &root_damage_rect));
263 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString()); 263 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString());
264 } 264 }
265 265
266 TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) { 266 TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) {
267 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 267 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
268 LayerImpl* child = root->test_properties()->children[0]; 268 LayerImpl* child = root->test_properties()->children[0];
269 269
270 // CASE 1: Adding the layer damage rect should cause the corresponding damage 270 // CASE 1: Adding the layer damage rect should cause the corresponding damage
271 // to the surface. 271 // to the surface.
272 ClearDamageForAllSurfaces(root); 272 ClearDamageForAllSurfaces(root);
273 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); 273 child->AddDamageRect(gfx::Rect(10, 11, 12, 13));
274 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 274 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
275 EmulateDrawingOneFrame(root); 275 EmulateDrawingOneFrame(root);
276 276
277 // Damage position on the surface should be: position of layer damage_rect 277 // Damage position on the surface should be: position of layer damage_rect
278 // (10, 11) relative to the child (100, 100). 278 // (10, 11) relative to the child (100, 100).
279 gfx::Rect root_damage_rect; 279 gfx::Rect root_damage_rect;
280 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 280 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
281 &root_damage_rect)); 281 &root_damage_rect));
282 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13))); 282 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13)));
283 283
284 // CASE 2: The same layer damage rect twice in a row still produces the same 284 // CASE 2: The same layer damage rect twice in a row still produces the same
285 // damage. 285 // damage.
286 ClearDamageForAllSurfaces(root); 286 ClearDamageForAllSurfaces(root);
287 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); 287 child->AddDamageRect(gfx::Rect(10, 11, 12, 13));
288 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 288 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
289 EmulateDrawingOneFrame(root); 289 EmulateDrawingOneFrame(root);
290 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 290 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
291 &root_damage_rect)); 291 &root_damage_rect));
292 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13))); 292 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13)));
293 293
294 // CASE 3: Adding a different layer damage rect should cause damage on the 294 // CASE 3: Adding a different layer damage rect should cause damage on the
295 // new damaged region, but no additional exposed old region. 295 // new damaged region, but no additional exposed old region.
296 ClearDamageForAllSurfaces(root); 296 ClearDamageForAllSurfaces(root);
297 child->AddDamageRect(gfx::Rect(20, 25, 1, 2)); 297 child->AddDamageRect(gfx::Rect(20, 25, 1, 2));
298 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 298 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
299 EmulateDrawingOneFrame(root); 299 EmulateDrawingOneFrame(root);
300 300
301 // Damage position on the surface should be: position of layer damage_rect 301 // Damage position on the surface should be: position of layer damage_rect
302 // (20, 25) relative to the child (100, 100). 302 // (20, 25) relative to the child (100, 100).
303 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 303 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
304 &root_damage_rect)); 304 &root_damage_rect));
305 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); 305 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2)));
306 306
307 // CASE 4: Adding multiple layer damage rects should cause a unified 307 // CASE 4: Adding multiple layer damage rects should cause a unified
308 // damage on root damage rect. 308 // damage on root damage rect.
309 ClearDamageForAllSurfaces(root); 309 ClearDamageForAllSurfaces(root);
310 child->AddDamageRect(gfx::Rect(20, 25, 1, 2)); 310 child->AddDamageRect(gfx::Rect(20, 25, 1, 2));
311 child->AddDamageRect(gfx::Rect(10, 15, 3, 4)); 311 child->AddDamageRect(gfx::Rect(10, 15, 3, 4));
312 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 312 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
313 EmulateDrawingOneFrame(root); 313 EmulateDrawingOneFrame(root);
314 314
315 // Damage position on the surface should be: position of layer damage_rect 315 // Damage position on the surface should be: position of layer damage_rect
316 // (20, 25) relative to the child (100, 100). 316 // (20, 25) relative to the child (100, 100).
317 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 317 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
318 &root_damage_rect)); 318 &root_damage_rect));
319 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); 319 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2)));
320 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4))); 320 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4)));
321 } 321 }
322 322
323 TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) { 323 TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) {
324 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 324 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
325 LayerImpl* child = root->test_properties()->children[0]; 325 LayerImpl* child = root->test_properties()->children[0];
326 326
327 // CASE 1: Adding the layer damage rect and update rect should cause the 327 // CASE 1: Adding the layer damage rect and update rect should cause the
328 // corresponding damage to the surface. 328 // corresponding damage to the surface.
329 ClearDamageForAllSurfaces(root); 329 ClearDamageForAllSurfaces(root);
330 child->AddDamageRect(gfx::Rect(5, 6, 12, 13)); 330 child->AddDamageRect(gfx::Rect(5, 6, 12, 13));
331 child->SetUpdateRect(gfx::Rect(15, 16, 14, 10)); 331 child->SetUpdateRect(gfx::Rect(15, 16, 14, 10));
332 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 332 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
333 EmulateDrawingOneFrame(root); 333 EmulateDrawingOneFrame(root);
334 334
335 // Damage position on the surface should be: position of unified layer 335 // Damage position on the surface should be: position of unified layer
336 // damage_rect and update rect (5, 6) 336 // damage_rect and update rect (5, 6)
337 // relative to the child (100, 100). 337 // relative to the child (100, 100).
338 gfx::Rect root_damage_rect; 338 gfx::Rect root_damage_rect;
339 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 339 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
340 &root_damage_rect)); 340 &root_damage_rect));
341 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 106, 24, 20))); 341 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 106, 24, 20)));
342 342
343 // CASE 2: The same layer damage rect and update rect twice in a row still 343 // CASE 2: The same layer damage rect and update rect twice in a row still
344 // produces the same damage. 344 // produces the same damage.
345 ClearDamageForAllSurfaces(root); 345 ClearDamageForAllSurfaces(root);
346 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); 346 child->AddDamageRect(gfx::Rect(10, 11, 12, 13));
347 child->SetUpdateRect(gfx::Rect(10, 11, 14, 15)); 347 child->SetUpdateRect(gfx::Rect(10, 11, 14, 15));
348 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 348 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
349 EmulateDrawingOneFrame(root); 349 EmulateDrawingOneFrame(root);
350 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 350 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
351 &root_damage_rect)); 351 &root_damage_rect));
352 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 14, 15))); 352 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 14, 15)));
353 353
354 // CASE 3: Adding a different layer damage rect and update rect should cause 354 // CASE 3: Adding a different layer damage rect and update rect should cause
355 // damage on the new damaged region, but no additional exposed old region. 355 // damage on the new damaged region, but no additional exposed old region.
356 ClearDamageForAllSurfaces(root); 356 ClearDamageForAllSurfaces(root);
357 child->AddDamageRect(gfx::Rect(20, 25, 2, 3)); 357 child->AddDamageRect(gfx::Rect(20, 25, 2, 3));
358 child->SetUpdateRect(gfx::Rect(5, 10, 7, 8)); 358 child->SetUpdateRect(gfx::Rect(5, 10, 7, 8));
359 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 359 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
360 EmulateDrawingOneFrame(root); 360 EmulateDrawingOneFrame(root);
361 361
362 // Damage position on the surface should be: position of unified layer damage 362 // Damage position on the surface should be: position of unified layer damage
363 // rect and update rect (5, 10) relative to the child (100, 100). 363 // rect and update rect (5, 10) relative to the child (100, 100).
364 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 364 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
365 &root_damage_rect)); 365 &root_damage_rect));
366 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18))); 366 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18)));
367 } 367 }
368 368
369 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) { 369 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) {
370 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 370 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
371 LayerImpl* child = root->test_properties()->children[0]; 371 LayerImpl* child = root->test_properties()->children[0];
372 372
373 // CASE 1: The layer's property changed flag takes priority over update rect. 373 // CASE 1: The layer's property changed flag takes priority over update rect.
374 // 374 //
375 child->test_properties()->force_render_surface = true; 375 child->test_properties()->force_render_surface = true;
376 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 376 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
377 EmulateDrawingOneFrame(root); 377 EmulateDrawingOneFrame(root);
378 ClearDamageForAllSurfaces(root); 378 ClearDamageForAllSurfaces(root);
379 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); 379 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13));
380 root->layer_tree_impl()->SetOpacityMutated(child->element_id(), 0.5f); 380 root->layer_tree_impl()->SetOpacityMutated(child->element_id(), 0.5f);
381 EmulateDrawingOneFrame(root); 381 EmulateDrawingOneFrame(root);
382 382
383 ASSERT_EQ(2, root->GetRenderSurface()->num_contributors()); 383 ASSERT_EQ(2, GetRenderSurface(root)->num_contributors());
384 384
385 // Damage should be the entire child layer in target_surface space. 385 // Damage should be the entire child layer in target_surface space.
386 gfx::Rect expected_rect = gfx::Rect(100, 100, 30, 30); 386 gfx::Rect expected_rect = gfx::Rect(100, 100, 30, 30);
387 gfx::Rect root_damage_rect; 387 gfx::Rect root_damage_rect;
388 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 388 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
389 &root_damage_rect)); 389 &root_damage_rect));
390 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); 390 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString());
391 391
392 // CASE 2: If a layer moves due to property change, it damages both the new 392 // CASE 2: If a layer moves due to property change, it damages both the new
393 // location and the old (exposed) location. The old location is the 393 // location and the old (exposed) location. The old location is the
394 // entire old layer, not just the update_rect. 394 // entire old layer, not just the update_rect.
395 395
396 // Cycle one frame of no change, just to sanity check that the next rect is 396 // Cycle one frame of no change, just to sanity check that the next rect is
397 // not because of the old damage state. 397 // not because of the old damage state.
398 ClearDamageForAllSurfaces(root); 398 ClearDamageForAllSurfaces(root);
399 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 399 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
400 EmulateDrawingOneFrame(root); 400 EmulateDrawingOneFrame(root);
401 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 401 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
402 &root_damage_rect)); 402 &root_damage_rect));
403 EXPECT_TRUE(root_damage_rect.IsEmpty()); 403 EXPECT_TRUE(root_damage_rect.IsEmpty());
404 404
405 // Then, test the actual layer movement. 405 // Then, test the actual layer movement.
406 ClearDamageForAllSurfaces(root); 406 ClearDamageForAllSurfaces(root);
407 gfx::Transform translation; 407 gfx::Transform translation;
408 translation.Translate(100.f, 130.f); 408 translation.Translate(100.f, 130.f);
409 root->layer_tree_impl()->SetTransformMutated(child->element_id(), 409 root->layer_tree_impl()->SetTransformMutated(child->element_id(),
410 translation); 410 translation);
411 EmulateDrawingOneFrame(root); 411 EmulateDrawingOneFrame(root);
412 412
413 // Expect damage to be the combination of the previous one and the new one. 413 // Expect damage to be the combination of the previous one and the new one.
414 expected_rect.Union(gfx::Rect(200, 230, 30, 30)); 414 expected_rect.Union(gfx::Rect(200, 230, 30, 30));
415 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 415 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
416 &root_damage_rect)); 416 &root_damage_rect));
417 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect); 417 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect);
418 } 418 }
419 419
420 TEST_F(DamageTrackerTest, VerifyDamageWhenSurfaceRemoved) { 420 TEST_F(DamageTrackerTest, VerifyDamageWhenSurfaceRemoved) {
421 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 421 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
422 LayerImpl* surface = root->test_properties()->children[0]; 422 LayerImpl* surface = root->test_properties()->children[0];
423 LayerImpl* child = surface->test_properties()->children[0]; 423 LayerImpl* child = surface->test_properties()->children[0];
424 child->SetDrawsContent(true); 424 child->SetDrawsContent(true);
425 EmulateDrawingOneFrame(root); 425 EmulateDrawingOneFrame(root);
426 ClearDamageForAllSurfaces(root); 426 ClearDamageForAllSurfaces(root);
427 427
428 surface->test_properties()->force_render_surface = false; 428 surface->test_properties()->force_render_surface = false;
429 child->SetDrawsContent(false); 429 child->SetDrawsContent(false);
430 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 430 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
431 EmulateDrawingOneFrame(root); 431 EmulateDrawingOneFrame(root);
432 gfx::Rect root_damage_rect; 432 gfx::Rect root_damage_rect;
433 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 433 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
434 &root_damage_rect)); 434 &root_damage_rect));
435 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), 435 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(),
436 root_damage_rect.ToString()); 436 root_damage_rect.ToString());
437 } 437 }
438 438
439 TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) { 439 TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) {
440 // If a layer is transformed, the damage rect should still enclose the entire 440 // If a layer is transformed, the damage rect should still enclose the entire
441 // transformed layer. 441 // transformed layer.
442 442
443 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 443 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
444 LayerImpl* child = root->test_properties()->children[0]; 444 LayerImpl* child = root->test_properties()->children[0];
445 child->test_properties()->force_render_surface = true; 445 child->test_properties()->force_render_surface = true;
446 446
447 gfx::Transform rotation; 447 gfx::Transform rotation;
448 rotation.Rotate(45.0); 448 rotation.Rotate(45.0);
449 449
450 ClearDamageForAllSurfaces(root); 450 ClearDamageForAllSurfaces(root);
451 child->test_properties()->transform_origin = gfx::Point3F( 451 child->test_properties()->transform_origin = gfx::Point3F(
452 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f); 452 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f);
453 child->SetPosition(gfx::PointF(85.f, 85.f)); 453 child->SetPosition(gfx::PointF(85.f, 85.f));
454 child->NoteLayerPropertyChanged(); 454 child->NoteLayerPropertyChanged();
455 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 455 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
456 EmulateDrawingOneFrame(root); 456 EmulateDrawingOneFrame(root);
457 457
458 // Sanity check that the layer actually moved to (85, 85), damaging its old 458 // Sanity check that the layer actually moved to (85, 85), damaging its old
459 // location and new location. 459 // location and new location.
460 gfx::Rect root_damage_rect; 460 gfx::Rect root_damage_rect;
461 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 461 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
462 &root_damage_rect)); 462 &root_damage_rect));
463 EXPECT_EQ(gfx::Rect(85, 85, 45, 45).ToString(), root_damage_rect.ToString()); 463 EXPECT_EQ(gfx::Rect(85, 85, 45, 45).ToString(), root_damage_rect.ToString());
464 464
465 // With the anchor on the layer's center, now we can test the rotation more 465 // With the anchor on the layer's center, now we can test the rotation more
466 // intuitively, since it applies about the layer's anchor. 466 // intuitively, since it applies about the layer's anchor.
467 ClearDamageForAllSurfaces(root); 467 ClearDamageForAllSurfaces(root);
468 root->layer_tree_impl()->SetTransformMutated(child->element_id(), rotation); 468 root->layer_tree_impl()->SetTransformMutated(child->element_id(), rotation);
469 EmulateDrawingOneFrame(root); 469 EmulateDrawingOneFrame(root);
470 470
471 // Since the child layer is square, rotation by 45 degrees about the center 471 // Since the child layer is square, rotation by 45 degrees about the center
472 // should increase the size of the expected rect by sqrt(2), centered around 472 // should increase the size of the expected rect by sqrt(2), centered around
473 // (100, 100). The old exposed region should be fully contained in the new 473 // (100, 100). The old exposed region should be fully contained in the new
474 // region. 474 // region.
475 float expected_width = 30.f * sqrt(2.f); 475 float expected_width = 30.f * sqrt(2.f);
476 float expected_position = 100.f - 0.5f * expected_width; 476 float expected_position = 100.f - 0.5f * expected_width;
477 gfx::Rect expected_rect = gfx::ToEnclosingRect(gfx::RectF( 477 gfx::Rect expected_rect = gfx::ToEnclosingRect(gfx::RectF(
478 expected_position, expected_position, expected_width, expected_width)); 478 expected_position, expected_position, expected_width, expected_width));
479 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 479 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
480 &root_damage_rect)); 480 &root_damage_rect));
481 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); 481 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString());
482 } 482 }
483 483
484 TEST_F(DamageTrackerTest, VerifyDamageForPerspectiveClippedLayer) { 484 TEST_F(DamageTrackerTest, VerifyDamageForPerspectiveClippedLayer) {
485 // If a layer has a perspective transform that causes w < 0, then not 485 // If a layer has a perspective transform that causes w < 0, then not
486 // clipping the layer can cause an invalid damage rect. This test checks that 486 // clipping the layer can cause an invalid damage rect. This test checks that
487 // the w < 0 case is tracked properly. 487 // the w < 0 case is tracked properly.
488 // 488 //
489 // The transform is constructed so that if w < 0 clipping is not performed, 489 // The transform is constructed so that if w < 0 clipping is not performed,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 522 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
523 EmulateDrawingOneFrame(root); 523 EmulateDrawingOneFrame(root);
524 ClearDamageForAllSurfaces(root); 524 ClearDamageForAllSurfaces(root);
525 root->layer_tree_impl()->SetOpacityMutated(child->element_id(), 0.5f); 525 root->layer_tree_impl()->SetOpacityMutated(child->element_id(), 0.5f);
526 EmulateDrawingOneFrame(root); 526 EmulateDrawingOneFrame(root);
527 527
528 // The expected damage should cover the entire root surface (500x500), but we 528 // The expected damage should cover the entire root surface (500x500), but we
529 // don't care whether the damage rect was clamped or is larger than the 529 // don't care whether the damage rect was clamped or is larger than the
530 // surface for this test. 530 // surface for this test.
531 gfx::Rect root_damage_rect; 531 gfx::Rect root_damage_rect;
532 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 532 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
533 &root_damage_rect)); 533 &root_damage_rect));
534 gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500)); 534 gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500));
535 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about)); 535 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about));
536 } 536 }
537 537
538 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) { 538 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) {
539 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 539 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
540 LayerImpl* surface = root->test_properties()->children[0]; 540 LayerImpl* surface = root->test_properties()->children[0];
541 LayerImpl* child = surface->test_properties()->children[0]; 541 LayerImpl* child = surface->test_properties()->children[0];
542 542
(...skipping 10 matching lines...) Expand all
553 // surface, blurred based on the size of the blur filter. 553 // surface, blurred based on the size of the blur filter.
554 ClearDamageForAllSurfaces(root); 554 ClearDamageForAllSurfaces(root);
555 child->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); 555 child->SetUpdateRect(gfx::Rect(1, 2, 3, 4));
556 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 556 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
557 EmulateDrawingOneFrame(root); 557 EmulateDrawingOneFrame(root);
558 558
559 // Damage position on the surface should be: position of update_rect (1, 2) 559 // Damage position on the surface should be: position of update_rect (1, 2)
560 // relative to the child (300, 300), but expanded by the blur outsets 560 // relative to the child (300, 300), but expanded by the blur outsets
561 // (15, since the blur radius is 5). 561 // (15, since the blur radius is 5).
562 gfx::Rect root_damage_rect; 562 gfx::Rect root_damage_rect;
563 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 563 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
564 &root_damage_rect)); 564 &root_damage_rect));
565 EXPECT_EQ(gfx::Rect(286, 287, 33, 34), root_damage_rect); 565 EXPECT_EQ(gfx::Rect(286, 287, 33, 34), root_damage_rect);
566 } 566 }
567 567
568 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { 568 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) {
569 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 569 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
570 LayerImpl* child = root->test_properties()->children[0]; 570 LayerImpl* child = root->test_properties()->children[0];
571 gfx::Rect root_damage_rect, child_damage_rect; 571 gfx::Rect root_damage_rect, child_damage_rect;
572 572
573 // Allow us to set damage on child too. 573 // Allow us to set damage on child too.
574 child->SetDrawsContent(true); 574 child->SetDrawsContent(true);
575 575
576 FilterOperations filters; 576 FilterOperations filters;
577 filters.Append(FilterOperation::CreateReferenceFilter( 577 filters.Append(FilterOperation::CreateReferenceFilter(
578 SkBlurImageFilter::Make(2, 2, nullptr))); 578 SkBlurImageFilter::Make(2, 2, nullptr)));
579 579
580 // Setting the filter will damage the whole surface. 580 // Setting the filter will damage the whole surface.
581 ClearDamageForAllSurfaces(root); 581 ClearDamageForAllSurfaces(root);
582 child->test_properties()->force_render_surface = true; 582 child->test_properties()->force_render_surface = true;
583 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 583 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
584 EmulateDrawingOneFrame(root); 584 EmulateDrawingOneFrame(root);
585 child->layer_tree_impl()->SetFilterMutated(child->element_id(), filters); 585 child->layer_tree_impl()->SetFilterMutated(child->element_id(), filters);
586 EmulateDrawingOneFrame(root); 586 EmulateDrawingOneFrame(root);
587 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 587 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
588 &root_damage_rect)); 588 &root_damage_rect));
589 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 589 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
590 &child_damage_rect)); 590 &child_damage_rect));
591 591
592 // gfx::Rect(100, 100, 30, 30), expanded by 6px for the 2px blur filter. 592 // gfx::Rect(100, 100, 30, 30), expanded by 6px for the 2px blur filter.
593 EXPECT_EQ(gfx::Rect(94, 94, 42, 42), root_damage_rect); 593 EXPECT_EQ(gfx::Rect(94, 94, 42, 42), root_damage_rect);
594 594
595 // gfx::Rect(0, 0, 30, 30), expanded by 6px for the 2px blur filter. 595 // gfx::Rect(0, 0, 30, 30), expanded by 6px for the 2px blur filter.
596 EXPECT_EQ(gfx::Rect(-6, -6, 42, 42), child_damage_rect); 596 EXPECT_EQ(gfx::Rect(-6, -6, 42, 42), child_damage_rect);
597 597
598 // CASE 1: Setting the update rect should damage the whole surface (for now) 598 // CASE 1: Setting the update rect should damage the whole surface (for now)
599 ClearDamageForAllSurfaces(root); 599 ClearDamageForAllSurfaces(root);
600 child->SetUpdateRect(gfx::Rect(1, 1)); 600 child->SetUpdateRect(gfx::Rect(1, 1));
601 EmulateDrawingOneFrame(root); 601 EmulateDrawingOneFrame(root);
602 602
603 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 603 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
604 &root_damage_rect)); 604 &root_damage_rect));
605 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 605 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
606 &child_damage_rect)); 606 &child_damage_rect));
607 607
608 // gfx::Rect(100, 100, 1, 1), expanded by 6px for the 2px blur filter. 608 // gfx::Rect(100, 100, 1, 1), expanded by 6px for the 2px blur filter.
609 EXPECT_EQ(gfx::Rect(94, 94, 13, 13), root_damage_rect); 609 EXPECT_EQ(gfx::Rect(94, 94, 13, 13), root_damage_rect);
610 610
611 // gfx::Rect(0, 0, 1, 1), expanded by 6px for the 2px blur filter. 611 // gfx::Rect(0, 0, 1, 1), expanded by 6px for the 2px blur filter.
612 EXPECT_EQ(gfx::Rect(-6, -6, 13, 13), child_damage_rect); 612 EXPECT_EQ(gfx::Rect(-6, -6, 13, 13), child_damage_rect);
613 } 613 }
614 614
615 TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) { 615 TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) {
(...skipping 11 matching lines...) Expand all
627 // Setting the filter will damage the whole surface. 627 // Setting the filter will damage the whole surface.
628 gfx::Transform transform; 628 gfx::Transform transform;
629 transform.RotateAboutYAxis(60); 629 transform.RotateAboutYAxis(60);
630 ClearDamageForAllSurfaces(root); 630 ClearDamageForAllSurfaces(root);
631 child->test_properties()->force_render_surface = true; 631 child->test_properties()->force_render_surface = true;
632 child->test_properties()->transform = transform; 632 child->test_properties()->transform = transform;
633 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 633 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
634 EmulateDrawingOneFrame(root); 634 EmulateDrawingOneFrame(root);
635 child->layer_tree_impl()->SetFilterMutated(child->element_id(), filters); 635 child->layer_tree_impl()->SetFilterMutated(child->element_id(), filters);
636 EmulateDrawingOneFrame(root); 636 EmulateDrawingOneFrame(root);
637 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 637 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
638 &root_damage_rect)); 638 &root_damage_rect));
639 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 639 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
640 &child_damage_rect)); 640 &child_damage_rect));
641 641
642 // Blur outset is 6px for a 2px blur. 642 // Blur outset is 6px for a 2px blur.
643 int blur_outset = 6; 643 int blur_outset = 6;
644 int rotated_outset_left = blur_outset / 2; 644 int rotated_outset_left = blur_outset / 2;
645 int expected_rotated_width = (30 + 2 * blur_outset) / 2; 645 int expected_rotated_width = (30 + 2 * blur_outset) / 2;
646 gfx::Rect expected_root_damage(100 - rotated_outset_left, 100 - blur_outset, 646 gfx::Rect expected_root_damage(100 - rotated_outset_left, 100 - blur_outset,
647 expected_rotated_width, 30 + 2 * blur_outset); 647 expected_rotated_width, 30 + 2 * blur_outset);
648 expected_root_damage.Union(gfx::Rect(100, 100, 30, 30)); 648 expected_root_damage.Union(gfx::Rect(100, 100, 30, 30));
649 EXPECT_EQ(expected_root_damage, root_damage_rect); 649 EXPECT_EQ(expected_root_damage, root_damage_rect);
650 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, 30 + 2 * blur_outset, 650 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, 30 + 2 * blur_outset,
651 30 + 2 * blur_outset), 651 30 + 2 * blur_outset),
652 child_damage_rect); 652 child_damage_rect);
653 653
654 // Setting the update rect should damage the whole surface (for now) 654 // Setting the update rect should damage the whole surface (for now)
655 ClearDamageForAllSurfaces(root); 655 ClearDamageForAllSurfaces(root);
656 child->SetUpdateRect(gfx::Rect(30, 30)); 656 child->SetUpdateRect(gfx::Rect(30, 30));
657 EmulateDrawingOneFrame(root); 657 EmulateDrawingOneFrame(root);
658 658
659 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 659 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
660 &root_damage_rect)); 660 &root_damage_rect));
661 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 661 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
662 &child_damage_rect)); 662 &child_damage_rect));
663 663
664 int expect_width = 30 + 2 * blur_outset; 664 int expect_width = 30 + 2 * blur_outset;
665 int expect_height = 30 + 2 * blur_outset; 665 int expect_height = 30 + 2 * blur_outset;
666 EXPECT_EQ(gfx::Rect(100 - blur_outset / 2, 100 - blur_outset, 666 EXPECT_EQ(gfx::Rect(100 - blur_outset / 2, 100 - blur_outset,
667 expect_width / 2, expect_height), 667 expect_width / 2, expect_height),
668 root_damage_rect); 668 root_damage_rect);
669 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, expect_width, expect_height), 669 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, expect_width, expect_height),
670 child_damage_rect); 670 child_damage_rect);
671 } 671 }
(...skipping 10 matching lines...) Expand all
682 filters.Append(FilterOperation::CreateBlurFilter(3.f)); 682 filters.Append(FilterOperation::CreateBlurFilter(3.f));
683 683
684 // Setting the filter will damage the whole surface. 684 // Setting the filter will damage the whole surface.
685 ClearDamageForAllSurfaces(root); 685 ClearDamageForAllSurfaces(root);
686 child->test_properties()->force_render_surface = true; 686 child->test_properties()->force_render_surface = true;
687 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 687 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
688 int device_scale_factor = 2; 688 int device_scale_factor = 2;
689 EmulateDrawingOneFrame(root, device_scale_factor); 689 EmulateDrawingOneFrame(root, device_scale_factor);
690 child->layer_tree_impl()->SetFilterMutated(child->element_id(), filters); 690 child->layer_tree_impl()->SetFilterMutated(child->element_id(), filters);
691 EmulateDrawingOneFrame(root, device_scale_factor); 691 EmulateDrawingOneFrame(root, device_scale_factor);
692 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 692 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
693 &root_damage_rect)); 693 &root_damage_rect));
694 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 694 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
695 &child_damage_rect)); 695 &child_damage_rect));
696 696
697 // Blur outset is 9px for a 3px blur, scaled up by DSF. 697 // Blur outset is 9px for a 3px blur, scaled up by DSF.
698 int blur_outset = 9 * device_scale_factor; 698 int blur_outset = 9 * device_scale_factor;
699 gfx::Rect original_rect(100, 100, 100, 100); 699 gfx::Rect original_rect(100, 100, 100, 100);
700 gfx::Rect expected_child_damage_rect(60, 60); 700 gfx::Rect expected_child_damage_rect(60, 60);
701 expected_child_damage_rect.Inset(-blur_outset, -blur_outset); 701 expected_child_damage_rect.Inset(-blur_outset, -blur_outset);
702 gfx::Rect expected_root_damage_rect(child_damage_rect); 702 gfx::Rect expected_root_damage_rect(child_damage_rect);
703 expected_root_damage_rect.Offset(200, 200); 703 expected_root_damage_rect.Offset(200, 200);
704 gfx::Rect expected_total_damage_rect = expected_root_damage_rect; 704 gfx::Rect expected_total_damage_rect = expected_root_damage_rect;
705 expected_total_damage_rect.Union(original_rect); 705 expected_total_damage_rect.Union(original_rect);
706 EXPECT_EQ(expected_total_damage_rect, root_damage_rect); 706 EXPECT_EQ(expected_total_damage_rect, root_damage_rect);
707 EXPECT_EQ(expected_child_damage_rect, child_damage_rect); 707 EXPECT_EQ(expected_child_damage_rect, child_damage_rect);
708 708
709 // Setting the update rect should damage only the affected area (original, 709 // Setting the update rect should damage only the affected area (original,
710 // outset by 3 * blur sigma * DSF). 710 // outset by 3 * blur sigma * DSF).
711 ClearDamageForAllSurfaces(root); 711 ClearDamageForAllSurfaces(root);
712 child->SetUpdateRect(gfx::Rect(30, 30)); 712 child->SetUpdateRect(gfx::Rect(30, 30));
713 EmulateDrawingOneFrame(root, device_scale_factor); 713 EmulateDrawingOneFrame(root, device_scale_factor);
714 714
715 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 715 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
716 &root_damage_rect)); 716 &root_damage_rect));
717 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 717 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
718 &child_damage_rect)); 718 &child_damage_rect));
719 719
720 EXPECT_EQ(expected_root_damage_rect, root_damage_rect); 720 EXPECT_EQ(expected_root_damage_rect, root_damage_rect);
721 EXPECT_EQ(expected_child_damage_rect, child_damage_rect); 721 EXPECT_EQ(expected_child_damage_rect, child_damage_rect);
722 } 722 }
723 723
724 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) { 724 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) {
725 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 725 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
726 LayerImpl* child1 = root->test_properties()->children[0]; 726 LayerImpl* child1 = root->test_properties()->children[0];
727 LayerImpl* child2 = root->test_properties()->children[1]; 727 LayerImpl* child2 = root->test_properties()->children[1];
(...skipping 14 matching lines...) Expand all
742 // CASE 1: Setting the update rect should cause the corresponding damage to 742 // CASE 1: Setting the update rect should cause the corresponding damage to
743 // the surface, blurred based on the size of the child's background 743 // the surface, blurred based on the size of the child's background
744 // blur filter. Note that child1's render surface has a size of 744 // blur filter. Note that child1's render surface has a size of
745 // 206x208 due to contributions from grand_child1 and grand_child2. 745 // 206x208 due to contributions from grand_child1 and grand_child2.
746 ClearDamageForAllSurfaces(root); 746 ClearDamageForAllSurfaces(root);
747 root->SetUpdateRect(gfx::Rect(297, 297, 2, 2)); 747 root->SetUpdateRect(gfx::Rect(297, 297, 2, 2));
748 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 748 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
749 EmulateDrawingOneFrame(root); 749 EmulateDrawingOneFrame(root);
750 750
751 gfx::Rect root_damage_rect; 751 gfx::Rect root_damage_rect;
752 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 752 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
753 &root_damage_rect)); 753 &root_damage_rect));
754 // Damage position on the surface should be a composition of the damage on 754 // Damage position on the surface should be a composition of the damage on
755 // the root and on child2. Damage on the root should be: position of 755 // the root and on child2. Damage on the root should be: position of
756 // update_rect (297, 297), but expanded by the blur outsets. 756 // update_rect (297, 297), but expanded by the blur outsets.
757 gfx::Rect expected_damage_rect = gfx::Rect(297, 297, 2, 2); 757 gfx::Rect expected_damage_rect = gfx::Rect(297, 297, 2, 2);
758 758
759 // 6px spread for a 2px blur. 759 // 6px spread for a 2px blur.
760 expected_damage_rect.Inset(-6, -6, -6, -6); 760 expected_damage_rect.Inset(-6, -6, -6, -6);
761 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); 761 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
762 762
763 // CASE 2: Setting the update rect should cause the corresponding damage to 763 // CASE 2: Setting the update rect should cause the corresponding damage to
764 // the surface, blurred based on the size of the child's background 764 // the surface, blurred based on the size of the child's background
765 // blur filter. Since the damage extends to the right/bottom outside 765 // blur filter. Since the damage extends to the right/bottom outside
766 // of the blurred layer, only the left/top should end up expanded. 766 // of the blurred layer, only the left/top should end up expanded.
767 ClearDamageForAllSurfaces(root); 767 ClearDamageForAllSurfaces(root);
768 root->SetUpdateRect(gfx::Rect(297, 297, 30, 30)); 768 root->SetUpdateRect(gfx::Rect(297, 297, 30, 30));
769 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 769 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
770 EmulateDrawingOneFrame(root); 770 EmulateDrawingOneFrame(root);
771 771
772 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 772 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
773 &root_damage_rect)); 773 &root_damage_rect));
774 // Damage position on the surface should be a composition of the damage on 774 // Damage position on the surface should be a composition of the damage on
775 // the root and on child2. Damage on the root should be: position of 775 // the root and on child2. Damage on the root should be: position of
776 // update_rect (297, 297), but expanded on the left/top by the blur outsets. 776 // update_rect (297, 297), but expanded on the left/top by the blur outsets.
777 expected_damage_rect = gfx::Rect(297, 297, 30, 30); 777 expected_damage_rect = gfx::Rect(297, 297, 30, 30);
778 778
779 // 6px spread for a 2px blur. 779 // 6px spread for a 2px blur.
780 expected_damage_rect.Inset(-6, -6, 0, 0); 780 expected_damage_rect.Inset(-6, -6, 0, 0);
781 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); 781 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
782 782
783 // CASE 3: Setting this update rect outside the blurred content_bounds of the 783 // CASE 3: Setting this update rect outside the blurred content_bounds of the
784 // blurred child1 will not cause it to be expanded. 784 // blurred child1 will not cause it to be expanded.
785 ClearDamageForAllSurfaces(root); 785 ClearDamageForAllSurfaces(root);
786 root->SetUpdateRect(gfx::Rect(30, 30, 2, 2)); 786 root->SetUpdateRect(gfx::Rect(30, 30, 2, 2));
787 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 787 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
788 EmulateDrawingOneFrame(root); 788 EmulateDrawingOneFrame(root);
789 789
790 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 790 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
791 &root_damage_rect)); 791 &root_damage_rect));
792 // Damage on the root should be: position of update_rect (30, 30), not 792 // Damage on the root should be: position of update_rect (30, 30), not
793 // expanded. 793 // expanded.
794 expected_damage_rect = gfx::Rect(30, 30, 2, 2); 794 expected_damage_rect = gfx::Rect(30, 30, 2, 2);
795 795
796 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); 796 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
797 797
798 // CASE 4: Setting this update rect inside the blurred content_bounds but 798 // CASE 4: Setting this update rect inside the blurred content_bounds but
799 // outside the original content_bounds of the blurred child1 will 799 // outside the original content_bounds of the blurred child1 will
800 // cause it to be expanded. 800 // cause it to be expanded.
801 ClearDamageForAllSurfaces(root); 801 ClearDamageForAllSurfaces(root);
802 root->SetUpdateRect(gfx::Rect(99, 99, 1, 1)); 802 root->SetUpdateRect(gfx::Rect(99, 99, 1, 1));
803 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 803 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
804 EmulateDrawingOneFrame(root); 804 EmulateDrawingOneFrame(root);
805 805
806 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 806 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
807 &root_damage_rect)); 807 &root_damage_rect));
808 // Damage on the root should be: the originally damaged rect (99,99 1x1) 808 // Damage on the root should be: the originally damaged rect (99,99 1x1)
809 // plus the rect that can influence with a 2px blur (93,93 13x13) intersected 809 // plus the rect that can influence with a 2px blur (93,93 13x13) intersected
810 // with the surface rect (100,100 206x208). So no additional damage occurs 810 // with the surface rect (100,100 206x208). So no additional damage occurs
811 // above or to the left, but there is additional damage within the blurred 811 // above or to the left, but there is additional damage within the blurred
812 // area. 812 // area.
813 expected_damage_rect = gfx::Rect(99, 99, 7, 7); 813 expected_damage_rect = gfx::Rect(99, 99, 7, 7);
814 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); 814 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
815 815
816 // CASE 5: Setting the update rect on child2, which is above child1, will 816 // CASE 5: Setting the update rect on child2, which is above child1, will
817 // not get blurred by child1, so it does not need to get expanded. 817 // not get blurred by child1, so it does not need to get expanded.
818 ClearDamageForAllSurfaces(root); 818 ClearDamageForAllSurfaces(root);
819 child2->SetUpdateRect(gfx::Rect(1, 1)); 819 child2->SetUpdateRect(gfx::Rect(1, 1));
820 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 820 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
821 EmulateDrawingOneFrame(root); 821 EmulateDrawingOneFrame(root);
822 822
823 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 823 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
824 &root_damage_rect)); 824 &root_damage_rect));
825 // Damage on child2 should be: position of update_rect offset by the child's 825 // Damage on child2 should be: position of update_rect offset by the child's
826 // position (11, 11), and not expanded by anything. 826 // position (11, 11), and not expanded by anything.
827 expected_damage_rect = gfx::Rect(11, 11, 1, 1); 827 expected_damage_rect = gfx::Rect(11, 11, 1, 1);
828 828
829 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); 829 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
830 830
831 // CASE 6: Setting the update rect on child1 will also blur the damage, so 831 // CASE 6: Setting the update rect on child1 will also blur the damage, so
832 // that any pixels needed for the blur are redrawn in the current 832 // that any pixels needed for the blur are redrawn in the current
833 // frame. 833 // frame.
834 ClearDamageForAllSurfaces(root); 834 ClearDamageForAllSurfaces(root);
835 child1->SetUpdateRect(gfx::Rect(1, 1)); 835 child1->SetUpdateRect(gfx::Rect(1, 1));
836 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 836 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
837 EmulateDrawingOneFrame(root); 837 EmulateDrawingOneFrame(root);
838 838
839 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 839 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
840 &root_damage_rect)); 840 &root_damage_rect));
841 // Damage on child1 should be: position of update_rect offset by the child's 841 // Damage on child1 should be: position of update_rect offset by the child's
842 // position (100, 100), and expanded by the damage. 842 // position (100, 100), and expanded by the damage.
843 843
844 // Damage should be (0,0 1x1), offset by the 100,100 offset of child1 in 844 // Damage should be (0,0 1x1), offset by the 100,100 offset of child1 in
845 // root, and expanded 6px for the 2px blur (i.e., 94,94 13x13), but there 845 // root, and expanded 6px for the 2px blur (i.e., 94,94 13x13), but there
846 // should be no damage outside child1 (i.e. none above or to the left of 846 // should be no damage outside child1 (i.e. none above or to the left of
847 // 100,100. 847 // 100,100.
848 expected_damage_rect = gfx::Rect(100, 100, 7, 7); 848 expected_damage_rect = gfx::Rect(100, 100, 7, 7);
849 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); 849 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
(...skipping 12 matching lines...) Expand all
862 child2->SetPosition(gfx::PointF(400.f, 380.f)); 862 child2->SetPosition(gfx::PointF(400.f, 380.f));
863 child2->SetBounds(gfx::Size(6, 8)); 863 child2->SetBounds(gfx::Size(6, 8));
864 child2->SetDrawsContent(true); 864 child2->SetDrawsContent(true);
865 root->test_properties()->AddChild(std::move(child2)); 865 root->test_properties()->AddChild(std::move(child2));
866 } 866 }
867 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 867 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
868 EmulateDrawingOneFrame(root); 868 EmulateDrawingOneFrame(root);
869 869
870 // Sanity check - all 3 layers should be on the same render surface; render 870 // Sanity check - all 3 layers should be on the same render surface; render
871 // surfaces are tested elsewhere. 871 // surfaces are tested elsewhere.
872 ASSERT_EQ(3, root->GetRenderSurface()->num_contributors()); 872 ASSERT_EQ(3, GetRenderSurface(root)->num_contributors());
873 873
874 gfx::Rect root_damage_rect; 874 gfx::Rect root_damage_rect;
875 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 875 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
876 &root_damage_rect)); 876 &root_damage_rect));
877 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); 877 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString());
878 878
879 // CASE 2: If the layer is removed, its entire old layer becomes exposed, not 879 // CASE 2: If the layer is removed, its entire old layer becomes exposed, not
880 // just the last update rect. 880 // just the last update rect.
881 881
882 // Advance one frame without damage so that we know the damage rect is not 882 // Advance one frame without damage so that we know the damage rect is not
883 // leftover from the previous case. 883 // leftover from the previous case.
884 ClearDamageForAllSurfaces(root); 884 ClearDamageForAllSurfaces(root);
885 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 885 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
886 EmulateDrawingOneFrame(root); 886 EmulateDrawingOneFrame(root);
887 887
888 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 888 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
889 &root_damage_rect)); 889 &root_damage_rect));
890 EXPECT_TRUE(root_damage_rect.IsEmpty()); 890 EXPECT_TRUE(root_damage_rect.IsEmpty());
891 891
892 // Then, test removing child1. 892 // Then, test removing child1.
893 root->test_properties()->RemoveChild(child1); 893 root->test_properties()->RemoveChild(child1);
894 child1 = NULL; 894 child1 = NULL;
895 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 895 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
896 EmulateDrawingOneFrame(root); 896 EmulateDrawingOneFrame(root);
897 897
898 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 898 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
899 &root_damage_rect)); 899 &root_damage_rect));
900 EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(), 900 EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(),
901 root_damage_rect.ToString()); 901 root_damage_rect.ToString());
902 } 902 }
903 903
904 TEST_F(DamageTrackerTest, VerifyDamageForNewUnchangedLayer) { 904 TEST_F(DamageTrackerTest, VerifyDamageForNewUnchangedLayer) {
905 // If child2 is added to the layer tree, but it doesn't have any explicit 905 // If child2 is added to the layer tree, but it doesn't have any explicit
906 // damage of its own, it should still indeed damage the target surface. 906 // damage of its own, it should still indeed damage the target surface.
907 907
908 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 908 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
(...skipping 13 matching lines...) Expand all
922 // trigger, it means the test no longer actually covers the intended 922 // trigger, it means the test no longer actually covers the intended
923 // scenario. 923 // scenario.
924 ASSERT_FALSE(child2_ptr->LayerPropertyChanged()); 924 ASSERT_FALSE(child2_ptr->LayerPropertyChanged());
925 ASSERT_TRUE(child2_ptr->update_rect().IsEmpty()); 925 ASSERT_TRUE(child2_ptr->update_rect().IsEmpty());
926 } 926 }
927 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 927 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
928 EmulateDrawingOneFrame(root); 928 EmulateDrawingOneFrame(root);
929 929
930 // Sanity check - all 3 layers should be on the same render surface; render 930 // Sanity check - all 3 layers should be on the same render surface; render
931 // surfaces are tested elsewhere. 931 // surfaces are tested elsewhere.
932 ASSERT_EQ(3, root->GetRenderSurface()->num_contributors()); 932 ASSERT_EQ(3, GetRenderSurface(root)->num_contributors());
933 933
934 gfx::Rect root_damage_rect; 934 gfx::Rect root_damage_rect;
935 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 935 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
936 &root_damage_rect)); 936 &root_damage_rect));
937 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); 937 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString());
938 } 938 }
939 939
940 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { 940 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) {
941 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 941 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
942 LayerImpl* child1 = root->test_properties()->children[0]; 942 LayerImpl* child1 = root->test_properties()->children[0];
943 943
944 // In this test we don't want the above tree manipulation to be considered 944 // In this test we don't want the above tree manipulation to be considered
945 // part of the same frame. 945 // part of the same frame.
(...skipping 12 matching lines...) Expand all
958 958
959 // Damaging two layers simultaneously should cause combined damage. 959 // Damaging two layers simultaneously should cause combined damage.
960 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2); 960 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2);
961 // - child2 update rect in surface space: gfx::Rect(400, 380, 3, 4); 961 // - child2 update rect in surface space: gfx::Rect(400, 380, 3, 4);
962 ClearDamageForAllSurfaces(root); 962 ClearDamageForAllSurfaces(root);
963 child1->SetUpdateRect(gfx::Rect(1, 2)); 963 child1->SetUpdateRect(gfx::Rect(1, 2));
964 child2->SetUpdateRect(gfx::Rect(3, 4)); 964 child2->SetUpdateRect(gfx::Rect(3, 4));
965 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 965 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
966 EmulateDrawingOneFrame(root); 966 EmulateDrawingOneFrame(root);
967 gfx::Rect root_damage_rect; 967 gfx::Rect root_damage_rect;
968 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 968 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
969 &root_damage_rect)); 969 &root_damage_rect));
970 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(), 970 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(),
971 root_damage_rect.ToString()); 971 root_damage_rect.ToString());
972 } 972 }
973 973
974 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) { 974 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) {
975 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 975 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
976 LayerImpl* child1 = root->test_properties()->children[0]; 976 LayerImpl* child1 = root->test_properties()->children[0];
977 LayerImpl* child2 = root->test_properties()->children[1]; 977 LayerImpl* child2 = root->test_properties()->children[1];
978 LayerImpl* grand_child1 = 978 LayerImpl* grand_child1 =
979 root->test_properties()->children[0]->test_properties()->children[0]; 979 root->test_properties()->children[0]->test_properties()->children[0];
980 child2->test_properties()->force_render_surface = true; 980 child2->test_properties()->force_render_surface = true;
981 grand_child1->test_properties()->force_render_surface = true; 981 grand_child1->test_properties()->force_render_surface = true;
982 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 982 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
983 EmulateDrawingOneFrame(root); 983 EmulateDrawingOneFrame(root);
984 gfx::Rect child_damage_rect; 984 gfx::Rect child_damage_rect;
985 gfx::Rect root_damage_rect; 985 gfx::Rect root_damage_rect;
986 986
987 // CASE 1: Damage to a descendant surface should propagate properly to 987 // CASE 1: Damage to a descendant surface should propagate properly to
988 // ancestor surface. 988 // ancestor surface.
989 ClearDamageForAllSurfaces(root); 989 ClearDamageForAllSurfaces(root);
990 root->layer_tree_impl()->SetOpacityMutated(grand_child1->element_id(), 0.5f); 990 root->layer_tree_impl()->SetOpacityMutated(grand_child1->element_id(), 0.5f);
991 EmulateDrawingOneFrame(root); 991 EmulateDrawingOneFrame(root);
992 EXPECT_TRUE( 992 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid(
993 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 993 &child_damage_rect));
994 &child_damage_rect)); 994 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
995 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid(
996 &root_damage_rect)); 995 &root_damage_rect));
997 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); 996 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString());
998 EXPECT_EQ(gfx::Rect(300, 300, 6, 8).ToString(), root_damage_rect.ToString()); 997 EXPECT_EQ(gfx::Rect(300, 300, 6, 8).ToString(), root_damage_rect.ToString());
999 998
1000 // CASE 2: Same as previous case, but with additional damage elsewhere that 999 // CASE 2: Same as previous case, but with additional damage elsewhere that
1001 // should be properly unioned. 1000 // should be properly unioned.
1002 // - child1 surface damage in root surface space: 1001 // - child1 surface damage in root surface space:
1003 // gfx::Rect(300, 300, 6, 8); 1002 // gfx::Rect(300, 300, 6, 8);
1004 // - child2 damage in root surface space: 1003 // - child2 damage in root surface space:
1005 // gfx::Rect(11, 11, 18, 18); 1004 // gfx::Rect(11, 11, 18, 18);
1006 ClearDamageForAllSurfaces(root); 1005 ClearDamageForAllSurfaces(root);
1007 root->layer_tree_impl()->SetOpacityMutated(grand_child1->element_id(), 0.7f); 1006 root->layer_tree_impl()->SetOpacityMutated(grand_child1->element_id(), 0.7f);
1008 root->layer_tree_impl()->SetOpacityMutated(child2->element_id(), 0.7f); 1007 root->layer_tree_impl()->SetOpacityMutated(child2->element_id(), 0.7f);
1009 EmulateDrawingOneFrame(root); 1008 EmulateDrawingOneFrame(root);
1010 EXPECT_TRUE( 1009 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid(
1011 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1010 &child_damage_rect));
1012 &child_damage_rect)); 1011 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1013 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid(
1014 &root_damage_rect)); 1012 &root_damage_rect));
1015 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); 1013 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString());
1016 EXPECT_EQ(gfx::Rect(11, 11, 295, 297).ToString(), 1014 EXPECT_EQ(gfx::Rect(11, 11, 295, 297).ToString(),
1017 root_damage_rect.ToString()); 1015 root_damage_rect.ToString());
1018 } 1016 }
1019 1017
1020 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) { 1018 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) {
1021 // If descendant layer changes and affects the content bounds of the render 1019 // If descendant layer changes and affects the content bounds of the render
1022 // surface, then the entire descendant surface should be damaged, and it 1020 // surface, then the entire descendant surface should be damaged, and it
1023 // should damage its ancestor surface with the old and new surface regions. 1021 // should damage its ancestor surface with the old and new surface regions.
1024 1022
1025 // This is a tricky case, since only the first grand_child changes, but the 1023 // This is a tricky case, since only the first grand_child changes, but the
1026 // entire surface should be marked dirty. 1024 // entire surface should be marked dirty.
1027 1025
1028 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 1026 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
1029 LayerImpl* child1 = root->test_properties()->children[0]; 1027 LayerImpl* child1 = root->test_properties()->children[0];
1030 LayerImpl* grand_child1 = 1028 LayerImpl* grand_child1 =
1031 root->test_properties()->children[0]->test_properties()->children[0]; 1029 root->test_properties()->children[0]->test_properties()->children[0];
1032 gfx::Rect child_damage_rect; 1030 gfx::Rect child_damage_rect;
1033 gfx::Rect root_damage_rect; 1031 gfx::Rect root_damage_rect;
1034 1032
1035 ClearDamageForAllSurfaces(root); 1033 ClearDamageForAllSurfaces(root);
1036 grand_child1->SetPosition(gfx::PointF(195.f, 205.f)); 1034 grand_child1->SetPosition(gfx::PointF(195.f, 205.f));
1037 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1035 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1038 EmulateDrawingOneFrame(root); 1036 EmulateDrawingOneFrame(root);
1039 EXPECT_TRUE( 1037 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid(
1040 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1038 &child_damage_rect));
1041 &child_damage_rect)); 1039 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1042 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid(
1043 &root_damage_rect)); 1040 &root_damage_rect));
1044 1041
1045 // The new surface bounds should be damaged entirely, even though only one of 1042 // The new surface bounds should be damaged entirely, even though only one of
1046 // the layers changed. 1043 // the layers changed.
1047 EXPECT_EQ(gfx::Rect(190, 190, 11, 23).ToString(), 1044 EXPECT_EQ(gfx::Rect(190, 190, 11, 23).ToString(),
1048 child_damage_rect.ToString()); 1045 child_damage_rect.ToString());
1049 1046
1050 // Damage to the root surface should be the union of child1's *entire* render 1047 // Damage to the root surface should be the union of child1's *entire* render
1051 // surface (in target space), and its old exposed area (also in target 1048 // surface (in target space), and its old exposed area (also in target
1052 // space). 1049 // space).
(...skipping 17 matching lines...) Expand all
1070 LayerImpl* child1 = root->test_properties()->children[0]; 1067 LayerImpl* child1 = root->test_properties()->children[0];
1071 gfx::Rect child_damage_rect; 1068 gfx::Rect child_damage_rect;
1072 gfx::Rect root_damage_rect; 1069 gfx::Rect root_damage_rect;
1073 1070
1074 ClearDamageForAllSurfaces(root); 1071 ClearDamageForAllSurfaces(root);
1075 gfx::Transform translation; 1072 gfx::Transform translation;
1076 translation.Translate(-50.f, -50.f); 1073 translation.Translate(-50.f, -50.f);
1077 root->layer_tree_impl()->SetTransformMutated(child1->element_id(), 1074 root->layer_tree_impl()->SetTransformMutated(child1->element_id(),
1078 translation); 1075 translation);
1079 EmulateDrawingOneFrame(root); 1076 EmulateDrawingOneFrame(root);
1080 EXPECT_TRUE( 1077 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid(
1081 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1078 &child_damage_rect));
1082 &child_damage_rect)); 1079 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1083 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid(
1084 &root_damage_rect)); 1080 &root_damage_rect));
1085 1081
1086 // The new surface bounds should be damaged entirely. 1082 // The new surface bounds should be damaged entirely.
1087 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), 1083 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(),
1088 child_damage_rect.ToString()); 1084 child_damage_rect.ToString());
1089 1085
1090 // The entire child1 surface and the old exposed child1 surface should damage 1086 // The entire child1 surface and the old exposed child1 surface should damage
1091 // the root surface. 1087 // the root surface.
1092 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18) 1088 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18)
1093 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18) 1089 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18)
1094 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(), 1090 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(),
1095 root_damage_rect.ToString()); 1091 root_damage_rect.ToString());
1096 } 1092 }
1097 1093
1098 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) { 1094 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) {
1099 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 1095 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
1100 LayerImpl* child1 = root->test_properties()->children[0]; 1096 LayerImpl* child1 = root->test_properties()->children[0];
1101 gfx::Rect child_damage_rect; 1097 gfx::Rect child_damage_rect;
1102 gfx::Rect root_damage_rect; 1098 gfx::Rect root_damage_rect;
1103 1099
1104 // CASE 1: If a descendant surface disappears, its entire old area becomes 1100 // CASE 1: If a descendant surface disappears, its entire old area becomes
1105 // exposed. 1101 // exposed.
1106 ClearDamageForAllSurfaces(root); 1102 ClearDamageForAllSurfaces(root);
1107 child1->test_properties()->force_render_surface = false; 1103 child1->test_properties()->force_render_surface = false;
1108 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1104 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1109 EmulateDrawingOneFrame(root); 1105 EmulateDrawingOneFrame(root);
1110 1106
1111 // Sanity check that there is only one surface now. 1107 // Sanity check that there is only one surface now.
1112 ASSERT_FALSE(child1->GetRenderSurface()); 1108 ASSERT_FALSE(GetRenderSurface(child1));
1113 ASSERT_EQ(4, root->GetRenderSurface()->num_contributors()); 1109 ASSERT_EQ(4, GetRenderSurface(root)->num_contributors());
1114 1110
1115 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1111 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1116 &root_damage_rect)); 1112 &root_damage_rect));
1117 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), 1113 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(),
1118 root_damage_rect.ToString()); 1114 root_damage_rect.ToString());
1119 1115
1120 // CASE 2: If a descendant surface appears, its entire old area becomes 1116 // CASE 2: If a descendant surface appears, its entire old area becomes
1121 // exposed. 1117 // exposed.
1122 1118
1123 // Cycle one frame of no change, just to sanity check that the next rect is 1119 // Cycle one frame of no change, just to sanity check that the next rect is
1124 // not because of the old damage state. 1120 // not because of the old damage state.
1125 ClearDamageForAllSurfaces(root); 1121 ClearDamageForAllSurfaces(root);
1126 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1122 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1127 EmulateDrawingOneFrame(root); 1123 EmulateDrawingOneFrame(root);
1128 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1124 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1129 &root_damage_rect)); 1125 &root_damage_rect));
1130 EXPECT_TRUE(root_damage_rect.IsEmpty()); 1126 EXPECT_TRUE(root_damage_rect.IsEmpty());
1131 1127
1132 // Then change the tree so that the render surface is added back. 1128 // Then change the tree so that the render surface is added back.
1133 ClearDamageForAllSurfaces(root); 1129 ClearDamageForAllSurfaces(root);
1134 child1->test_properties()->force_render_surface = true; 1130 child1->test_properties()->force_render_surface = true;
1135 1131
1136 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1132 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1137 EmulateDrawingOneFrame(root); 1133 EmulateDrawingOneFrame(root);
1138 1134
1139 // Sanity check that there is a new surface now. 1135 // Sanity check that there is a new surface now.
1140 ASSERT_TRUE(child1->GetRenderSurface()); 1136 ASSERT_TRUE(GetRenderSurface(child1));
1141 EXPECT_EQ(3, root->GetRenderSurface()->num_contributors()); 1137 EXPECT_EQ(3, GetRenderSurface(root)->num_contributors());
1142 EXPECT_EQ(2, child1->GetRenderSurface()->num_contributors()); 1138 EXPECT_EQ(2, GetRenderSurface(child1)->num_contributors());
1143 1139
1144 EXPECT_TRUE( 1140 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid(
1145 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1141 &child_damage_rect));
1146 &child_damage_rect)); 1142 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1147 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid(
1148 &root_damage_rect)); 1143 &root_damage_rect));
1149 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), 1144 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(),
1150 child_damage_rect.ToString()); 1145 child_damage_rect.ToString());
1151 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), 1146 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(),
1152 root_damage_rect.ToString()); 1147 root_damage_rect.ToString());
1153 } 1148 }
1154 1149
1155 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) { 1150 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) {
1156 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 1151 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
1157 LayerImpl* child1 = root->test_properties()->children[0]; 1152 LayerImpl* child1 = root->test_properties()->children[0];
1158 gfx::Rect child_damage_rect; 1153 gfx::Rect child_damage_rect;
1159 gfx::Rect root_damage_rect; 1154 gfx::Rect root_damage_rect;
1160 1155
1161 // CASE 1: If nothing changes, the damage rect should be empty. 1156 // CASE 1: If nothing changes, the damage rect should be empty.
1162 // 1157 //
1163 ClearDamageForAllSurfaces(root); 1158 ClearDamageForAllSurfaces(root);
1164 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1159 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1165 EmulateDrawingOneFrame(root); 1160 EmulateDrawingOneFrame(root);
1166 EXPECT_TRUE( 1161 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid(
1167 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1162 &child_damage_rect));
1168 &child_damage_rect)); 1163 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1169 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid(
1170 &root_damage_rect)); 1164 &root_damage_rect));
1171 EXPECT_TRUE(child_damage_rect.IsEmpty()); 1165 EXPECT_TRUE(child_damage_rect.IsEmpty());
1172 EXPECT_TRUE(root_damage_rect.IsEmpty()); 1166 EXPECT_TRUE(root_damage_rect.IsEmpty());
1173 1167
1174 // CASE 2: If nothing changes twice in a row, the damage rect should still be 1168 // CASE 2: If nothing changes twice in a row, the damage rect should still be
1175 // empty. 1169 // empty.
1176 // 1170 //
1177 ClearDamageForAllSurfaces(root); 1171 ClearDamageForAllSurfaces(root);
1178 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1172 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1179 EmulateDrawingOneFrame(root); 1173 EmulateDrawingOneFrame(root);
1180 EXPECT_TRUE( 1174 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid(
1181 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1175 &child_damage_rect));
1182 &child_damage_rect)); 1176 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1183 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid(
1184 &root_damage_rect)); 1177 &root_damage_rect));
1185 EXPECT_TRUE(child_damage_rect.IsEmpty()); 1178 EXPECT_TRUE(child_damage_rect.IsEmpty());
1186 EXPECT_TRUE(root_damage_rect.IsEmpty()); 1179 EXPECT_TRUE(root_damage_rect.IsEmpty());
1187 } 1180 }
1188 1181
1189 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) { 1182 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) {
1190 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 1183 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
1191 LayerImpl* child1 = root->test_properties()->children[0]; 1184 LayerImpl* child1 = root->test_properties()->children[0];
1192 gfx::Rect child_damage_rect; 1185 gfx::Rect child_damage_rect;
1193 gfx::Rect root_damage_rect; 1186 gfx::Rect root_damage_rect;
1194 1187
1195 // In our specific tree, the update rect of child1 should not cause any 1188 // In our specific tree, the update rect of child1 should not cause any
1196 // damage to any surface because it does not actually draw content. 1189 // damage to any surface because it does not actually draw content.
1197 ClearDamageForAllSurfaces(root); 1190 ClearDamageForAllSurfaces(root);
1198 child1->SetUpdateRect(gfx::Rect(1, 2)); 1191 child1->SetUpdateRect(gfx::Rect(1, 2));
1199 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1192 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1200 EmulateDrawingOneFrame(root); 1193 EmulateDrawingOneFrame(root);
1201 EXPECT_TRUE( 1194 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid(
1202 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1195 &child_damage_rect));
1203 &child_damage_rect)); 1196 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1204 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid(
1205 &root_damage_rect)); 1197 &root_damage_rect));
1206 EXPECT_TRUE(child_damage_rect.IsEmpty()); 1198 EXPECT_TRUE(child_damage_rect.IsEmpty());
1207 EXPECT_TRUE(root_damage_rect.IsEmpty()); 1199 EXPECT_TRUE(root_damage_rect.IsEmpty());
1208 } 1200 }
1209 1201
1210 TEST_F(DamageTrackerTest, VerifyDamageForMask) { 1202 TEST_F(DamageTrackerTest, VerifyDamageForMask) {
1211 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 1203 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
1212 LayerImpl* child = root->test_properties()->children[0]; 1204 LayerImpl* child = root->test_properties()->children[0];
1213 1205
1214 // In the current implementation of the damage tracker, changes to mask 1206 // In the current implementation of the damage tracker, changes to mask
(...skipping 25 matching lines...) Expand all
1240 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1232 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1241 EmulateDrawingOneFrame(root); 1233 EmulateDrawingOneFrame(root);
1242 1234
1243 // CASE 1: the update_rect on a mask layer should damage the entire target 1235 // CASE 1: the update_rect on a mask layer should damage the entire target
1244 // surface. 1236 // surface.
1245 ClearDamageForAllSurfaces(root); 1237 ClearDamageForAllSurfaces(root);
1246 mask_layer->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); 1238 mask_layer->SetUpdateRect(gfx::Rect(1, 2, 3, 4));
1247 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1239 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1248 EmulateDrawingOneFrame(root); 1240 EmulateDrawingOneFrame(root);
1249 gfx::Rect child_damage_rect; 1241 gfx::Rect child_damage_rect;
1250 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1242 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
1251 &child_damage_rect)); 1243 &child_damage_rect));
1252 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); 1244 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString());
1253 1245
1254 // CASE 2: a property change on the mask layer should damage the entire 1246 // CASE 2: a property change on the mask layer should damage the entire
1255 // target surface. 1247 // target surface.
1256 1248
1257 // Advance one frame without damage so that we know the damage rect is not 1249 // Advance one frame without damage so that we know the damage rect is not
1258 // leftover from the previous case. 1250 // leftover from the previous case.
1259 ClearDamageForAllSurfaces(root); 1251 ClearDamageForAllSurfaces(root);
1260 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1252 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1261 EmulateDrawingOneFrame(root); 1253 EmulateDrawingOneFrame(root);
1262 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1254 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
1263 &child_damage_rect)); 1255 &child_damage_rect));
1264 EXPECT_TRUE(child_damage_rect.IsEmpty()); 1256 EXPECT_TRUE(child_damage_rect.IsEmpty());
1265 1257
1266 // Then test the property change. 1258 // Then test the property change.
1267 ClearDamageForAllSurfaces(root); 1259 ClearDamageForAllSurfaces(root);
1268 mask_layer->NoteLayerPropertyChanged(); 1260 mask_layer->NoteLayerPropertyChanged();
1269 1261
1270 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1262 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1271 EmulateDrawingOneFrame(root); 1263 EmulateDrawingOneFrame(root);
1272 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1264 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
1273 &child_damage_rect)); 1265 &child_damage_rect));
1274 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); 1266 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString());
1275 1267
1276 // CASE 3: removing the mask also damages the entire target surface. 1268 // CASE 3: removing the mask also damages the entire target surface.
1277 // 1269 //
1278 1270
1279 // Advance one frame without damage so that we know the damage rect is not 1271 // Advance one frame without damage so that we know the damage rect is not
1280 // leftover from the previous case. 1272 // leftover from the previous case.
1281 ClearDamageForAllSurfaces(root); 1273 ClearDamageForAllSurfaces(root);
1282 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1274 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1283 EmulateDrawingOneFrame(root); 1275 EmulateDrawingOneFrame(root);
1284 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1276 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
1285 &child_damage_rect)); 1277 &child_damage_rect));
1286 EXPECT_TRUE(child_damage_rect.IsEmpty()); 1278 EXPECT_TRUE(child_damage_rect.IsEmpty());
1287 1279
1288 // Then test mask removal. 1280 // Then test mask removal.
1289 ClearDamageForAllSurfaces(root); 1281 ClearDamageForAllSurfaces(root);
1290 child->test_properties()->SetMaskLayer(nullptr); 1282 child->test_properties()->SetMaskLayer(nullptr);
1291 child->NoteLayerPropertyChanged(); 1283 child->NoteLayerPropertyChanged();
1292 ASSERT_TRUE(child->LayerPropertyChanged()); 1284 ASSERT_TRUE(child->LayerPropertyChanged());
1293 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1285 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1294 EmulateDrawingOneFrame(root); 1286 EmulateDrawingOneFrame(root);
1295 1287
1296 // Sanity check that a render surface still exists. 1288 // Sanity check that a render surface still exists.
1297 ASSERT_TRUE(child->GetRenderSurface()); 1289 ASSERT_TRUE(GetRenderSurface(child));
1298 1290
1299 EXPECT_TRUE(child->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1291 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
1300 &child_damage_rect)); 1292 &child_damage_rect));
1301 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); 1293 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString());
1302 } 1294 }
1303 1295
1304 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) { 1296 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) {
1305 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 1297 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
1306 LayerImpl* child = root->test_properties()->children[0]; 1298 LayerImpl* child = root->test_properties()->children[0];
1307 1299
1308 // Case 1: This test ensures that when the tracker is given damage, that 1300 // Case 1: This test ensures that when the tracker is given damage, that
1309 // it is included with any other partial damage. 1301 // it is included with any other partial damage.
1310 // 1302 //
1311 ClearDamageForAllSurfaces(root); 1303 ClearDamageForAllSurfaces(root);
1312 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); 1304 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13));
1313 root->GetRenderSurface()->damage_tracker()->AddDamageNextUpdate( 1305 GetRenderSurface(root)->damage_tracker()->AddDamageNextUpdate(
1314 gfx::Rect(15, 16, 32, 33)); 1306 gfx::Rect(15, 16, 32, 33));
1315 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1307 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1316 EmulateDrawingOneFrame(root); 1308 EmulateDrawingOneFrame(root);
1317 gfx::Rect root_damage_rect; 1309 gfx::Rect root_damage_rect;
1318 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1310 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1319 &root_damage_rect)); 1311 &root_damage_rect));
1320 EXPECT_EQ(gfx::UnionRects(gfx::Rect(15, 16, 32, 33), 1312 EXPECT_EQ(gfx::UnionRects(gfx::Rect(15, 16, 32, 33),
1321 gfx::Rect(100 + 10, 100 + 11, 12, 13)).ToString(), 1313 gfx::Rect(100 + 10, 100 + 11, 12, 13)).ToString(),
1322 root_damage_rect.ToString()); 1314 root_damage_rect.ToString());
1323 1315
1324 // Case 2: An additional sanity check that adding damage works even when 1316 // Case 2: An additional sanity check that adding damage works even when
1325 // nothing on the layer tree changed. 1317 // nothing on the layer tree changed.
1326 // 1318 //
1327 ClearDamageForAllSurfaces(root); 1319 ClearDamageForAllSurfaces(root);
1328 root->GetRenderSurface()->damage_tracker()->AddDamageNextUpdate( 1320 GetRenderSurface(root)->damage_tracker()->AddDamageNextUpdate(
1329 gfx::Rect(30, 31, 14, 15)); 1321 gfx::Rect(30, 31, 14, 15));
1330 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1322 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1331 EmulateDrawingOneFrame(root); 1323 EmulateDrawingOneFrame(root);
1332 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1324 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1333 &root_damage_rect)); 1325 &root_damage_rect));
1334 EXPECT_EQ(gfx::Rect(30, 31, 14, 15).ToString(), root_damage_rect.ToString()); 1326 EXPECT_EQ(gfx::Rect(30, 31, 14, 15).ToString(), root_damage_rect.ToString());
1335 } 1327 }
1336 1328
1337 TEST_F(DamageTrackerTest, VerifyDamageWithNoContributingLayers) { 1329 TEST_F(DamageTrackerTest, VerifyDamageWithNoContributingLayers) {
1338 std::unique_ptr<LayerImpl> root = 1330 std::unique_ptr<LayerImpl> root =
1339 LayerImpl::Create(host_impl_.active_tree(), 1); 1331 LayerImpl::Create(host_impl_.active_tree(), 1);
1340 root->test_properties()->force_render_surface = true; 1332 root->test_properties()->force_render_surface = true;
1341 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root)); 1333 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root));
1342 LayerImpl* root_ptr = host_impl_.active_tree()->root_layer_for_testing(); 1334 LayerImpl* root_ptr = host_impl_.active_tree()->root_layer_for_testing();
1343 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; 1335 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
1344 EmulateDrawingOneFrame(root_ptr); 1336 EmulateDrawingOneFrame(root_ptr);
1345 1337
1346 DCHECK_EQ(root_ptr->GetRenderSurface(), root_ptr->render_target()); 1338 DCHECK_EQ(GetRenderSurface(root_ptr), root_ptr->render_target());
1347 RenderSurfaceImpl* target_surface = root_ptr->GetRenderSurface(); 1339 RenderSurfaceImpl* target_surface = GetRenderSurface(root_ptr);
1348 gfx::Rect damage_rect; 1340 gfx::Rect damage_rect;
1349 EXPECT_TRUE( 1341 EXPECT_TRUE(
1350 target_surface->damage_tracker()->GetDamageRectIfValid(&damage_rect)); 1342 target_surface->damage_tracker()->GetDamageRectIfValid(&damage_rect));
1351 EXPECT_TRUE(damage_rect.IsEmpty()); 1343 EXPECT_TRUE(damage_rect.IsEmpty());
1352 } 1344 }
1353 1345
1354 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) { 1346 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) {
1355 // If damage is not cleared, it should accumulate. 1347 // If damage is not cleared, it should accumulate.
1356 1348
1357 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 1349 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
1358 LayerImpl* child = root->test_properties()->children[0]; 1350 LayerImpl* child = root->test_properties()->children[0];
1359 1351
1360 ClearDamageForAllSurfaces(root); 1352 ClearDamageForAllSurfaces(root);
1361 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f)); 1353 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f));
1362 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1354 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1363 EmulateDrawingOneFrame(root); 1355 EmulateDrawingOneFrame(root);
1364 1356
1365 // Sanity check damage after the first frame; this isnt the actual test yet. 1357 // Sanity check damage after the first frame; this isnt the actual test yet.
1366 gfx::Rect root_damage_rect; 1358 gfx::Rect root_damage_rect;
1367 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1359 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1368 &root_damage_rect)); 1360 &root_damage_rect));
1369 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString()); 1361 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString());
1370 1362
1371 // New damage, without having cleared the previous damage, should be unioned 1363 // New damage, without having cleared the previous damage, should be unioned
1372 // to the previous one. 1364 // to the previous one.
1373 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); 1365 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2));
1374 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1366 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1375 EmulateDrawingOneFrame(root); 1367 EmulateDrawingOneFrame(root);
1376 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1368 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1377 &root_damage_rect)); 1369 &root_damage_rect));
1378 EXPECT_EQ(gfx::Rect(110, 111, 11, 16).ToString(), 1370 EXPECT_EQ(gfx::Rect(110, 111, 11, 16).ToString(),
1379 root_damage_rect.ToString()); 1371 root_damage_rect.ToString());
1380 1372
1381 // If we notify the damage tracker that we drew the damaged area, then damage 1373 // If we notify the damage tracker that we drew the damaged area, then damage
1382 // should be emptied. 1374 // should be emptied.
1383 root->GetRenderSurface()->damage_tracker()->DidDrawDamagedArea(); 1375 GetRenderSurface(root)->damage_tracker()->DidDrawDamagedArea();
1384 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1376 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1385 &root_damage_rect)); 1377 &root_damage_rect));
1386 EXPECT_TRUE(root_damage_rect.IsEmpty()); 1378 EXPECT_TRUE(root_damage_rect.IsEmpty());
1387 1379
1388 // Damage should remain empty even after one frame, since there's yet no new 1380 // Damage should remain empty even after one frame, since there's yet no new
1389 // damage. 1381 // damage.
1390 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1382 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1391 EmulateDrawingOneFrame(root); 1383 EmulateDrawingOneFrame(root);
1392 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1384 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1393 &root_damage_rect)); 1385 &root_damage_rect));
1394 EXPECT_TRUE(root_damage_rect.IsEmpty()); 1386 EXPECT_TRUE(root_damage_rect.IsEmpty());
1395 } 1387 }
1396 1388
1397 TEST_F(DamageTrackerTest, HugeDamageRect) { 1389 TEST_F(DamageTrackerTest, HugeDamageRect) {
1398 // This number is so large that we start losting floating point accuracy. 1390 // This number is so large that we start losting floating point accuracy.
1399 const int kBigNumber = 900000000; 1391 const int kBigNumber = 900000000;
1400 // Walk over a range to find floating point inaccuracy boundaries that move 1392 // Walk over a range to find floating point inaccuracy boundaries that move
1401 // toward the wrong direction. 1393 // toward the wrong direction.
1402 const int kRange = 5000; 1394 const int kRange = 5000;
(...skipping 13 matching lines...) Expand all
1416 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1408 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1417 float device_scale_factor = 1.f; 1409 float device_scale_factor = 1.f;
1418 // Visible rects computed from combining clips in target space and root 1410 // Visible rects computed from combining clips in target space and root
1419 // space don't match because of the loss in floating point accuracy. So, we 1411 // space don't match because of the loss in floating point accuracy. So, we
1420 // skip verify_clip_tree_calculations. 1412 // skip verify_clip_tree_calculations.
1421 EmulateDrawingOneFrame(root, device_scale_factor); 1413 EmulateDrawingOneFrame(root, device_scale_factor);
1422 1414
1423 // The expected damage should cover the visible part of the child layer, 1415 // The expected damage should cover the visible part of the child layer,
1424 // which is (0, 0, i, i) in the viewport. 1416 // which is (0, 0, i, i) in the viewport.
1425 gfx::Rect root_damage_rect; 1417 gfx::Rect root_damage_rect;
1426 EXPECT_TRUE( 1418 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1427 root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1419 &root_damage_rect));
1428 &root_damage_rect));
1429 gfx::Rect damage_we_care_about = gfx::Rect(i, i); 1420 gfx::Rect damage_we_care_about = gfx::Rect(i, i);
1430 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); 1421 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right());
1431 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); 1422 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom());
1432 } 1423 }
1433 } 1424 }
1434 1425
1435 TEST_F(DamageTrackerTest, DamageRectTooBig) { 1426 TEST_F(DamageTrackerTest, DamageRectTooBig) {
1436 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2); 1427 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2);
1437 LayerImpl* child1 = root->test_properties()->children[0]; 1428 LayerImpl* child1 = root->test_properties()->children[0];
1438 LayerImpl* child2 = root->test_properties()->children[1]; 1429 LayerImpl* child2 = root->test_properties()->children[1];
1439 1430
1440 // Really far left. 1431 // Really far left.
1441 child1->SetPosition(gfx::PointF(std::numeric_limits<int>::min() + 100, 0)); 1432 child1->SetPosition(gfx::PointF(std::numeric_limits<int>::min() + 100, 0));
1442 child1->SetBounds(gfx::Size(1, 1)); 1433 child1->SetBounds(gfx::Size(1, 1));
1443 1434
1444 // Really far right. 1435 // Really far right.
1445 child2->SetPosition(gfx::PointF(std::numeric_limits<int>::max() - 100, 0)); 1436 child2->SetPosition(gfx::PointF(std::numeric_limits<int>::max() - 100, 0));
1446 child2->SetBounds(gfx::Size(1, 1)); 1437 child2->SetBounds(gfx::Size(1, 1));
1447 1438
1448 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1439 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1449 float device_scale_factor = 1.f; 1440 float device_scale_factor = 1.f;
1450 EmulateDrawingOneFrame(root, device_scale_factor); 1441 EmulateDrawingOneFrame(root, device_scale_factor);
1451 1442
1452 // The expected damage would be too large to store in a gfx::Rect, so we 1443 // The expected damage would be too large to store in a gfx::Rect, so we
1453 // should damage everything (ie, we don't have a valid rect). 1444 // should damage everything (ie, we don't have a valid rect).
1454 gfx::Rect damage_rect; 1445 gfx::Rect damage_rect;
1455 EXPECT_FALSE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1446 EXPECT_FALSE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1456 &damage_rect)); 1447 &damage_rect));
1457 EXPECT_EQ(root->GetRenderSurface()->content_rect(), 1448 EXPECT_EQ(GetRenderSurface(root)->content_rect(),
1458 root->GetRenderSurface()->GetDamageRect()); 1449 GetRenderSurface(root)->GetDamageRect());
1459 } 1450 }
1460 1451
1461 TEST_F(DamageTrackerTest, DamageRectTooBigWithFilter) { 1452 TEST_F(DamageTrackerTest, DamageRectTooBigWithFilter) {
1462 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2); 1453 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2);
1463 LayerImpl* child1 = root->test_properties()->children[0]; 1454 LayerImpl* child1 = root->test_properties()->children[0];
1464 LayerImpl* child2 = root->test_properties()->children[1]; 1455 LayerImpl* child2 = root->test_properties()->children[1];
1465 1456
1466 FilterOperations filters; 1457 FilterOperations filters;
1467 filters.Append(FilterOperation::CreateBlurFilter(5.f)); 1458 filters.Append(FilterOperation::CreateBlurFilter(5.f));
1468 root->SetDrawsContent(true); 1459 root->SetDrawsContent(true);
1469 root->test_properties()->background_filters = filters; 1460 root->test_properties()->background_filters = filters;
1470 1461
1471 // Really far left. 1462 // Really far left.
1472 child1->SetPosition(gfx::PointF(std::numeric_limits<int>::min() + 100, 0)); 1463 child1->SetPosition(gfx::PointF(std::numeric_limits<int>::min() + 100, 0));
1473 child1->SetBounds(gfx::Size(1, 1)); 1464 child1->SetBounds(gfx::Size(1, 1));
1474 1465
1475 // Really far right. 1466 // Really far right.
1476 child2->SetPosition(gfx::PointF(std::numeric_limits<int>::max() - 100, 0)); 1467 child2->SetPosition(gfx::PointF(std::numeric_limits<int>::max() - 100, 0));
1477 child2->SetBounds(gfx::Size(1, 1)); 1468 child2->SetBounds(gfx::Size(1, 1));
1478 1469
1479 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1470 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1480 float device_scale_factor = 1.f; 1471 float device_scale_factor = 1.f;
1481 EmulateDrawingOneFrame(root, device_scale_factor); 1472 EmulateDrawingOneFrame(root, device_scale_factor);
1482 1473
1483 // The expected damage would be too large to store in a gfx::Rect, so we 1474 // The expected damage would be too large to store in a gfx::Rect, so we
1484 // should damage everything (ie, we don't have a valid rect). 1475 // should damage everything (ie, we don't have a valid rect).
1485 gfx::Rect damage_rect; 1476 gfx::Rect damage_rect;
1486 EXPECT_FALSE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1477 EXPECT_FALSE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1487 &damage_rect)); 1478 &damage_rect));
1488 EXPECT_EQ(root->GetRenderSurface()->content_rect(), 1479 EXPECT_EQ(GetRenderSurface(root)->content_rect(),
1489 root->GetRenderSurface()->GetDamageRect()); 1480 GetRenderSurface(root)->GetDamageRect());
1490 } 1481 }
1491 1482
1492 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurface) { 1483 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurface) {
1493 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 1484 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
1494 LayerImpl* child1 = root->test_properties()->children[0]; 1485 LayerImpl* child1 = root->test_properties()->children[0];
1495 LayerImpl* grandchild1 = child1->test_properties()->children[0]; 1486 LayerImpl* grandchild1 = child1->test_properties()->children[0];
1496 LayerImpl* grandchild2 = child1->test_properties()->children[1]; 1487 LayerImpl* grandchild2 = child1->test_properties()->children[1];
1497 1488
1498 // Really far left. 1489 // Really far left.
1499 grandchild1->SetPosition( 1490 grandchild1->SetPosition(
1500 gfx::PointF(std::numeric_limits<int>::min() + 500, 0)); 1491 gfx::PointF(std::numeric_limits<int>::min() + 500, 0));
1501 grandchild1->SetBounds(gfx::Size(1, 1)); 1492 grandchild1->SetBounds(gfx::Size(1, 1));
1502 grandchild1->SetDrawsContent(true); 1493 grandchild1->SetDrawsContent(true);
1503 1494
1504 // Really far right. 1495 // Really far right.
1505 grandchild2->SetPosition( 1496 grandchild2->SetPosition(
1506 gfx::PointF(std::numeric_limits<int>::max() - 500, 0)); 1497 gfx::PointF(std::numeric_limits<int>::max() - 500, 0));
1507 grandchild2->SetBounds(gfx::Size(1, 1)); 1498 grandchild2->SetBounds(gfx::Size(1, 1));
1508 grandchild2->SetDrawsContent(true); 1499 grandchild2->SetDrawsContent(true);
1509 1500
1510 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1501 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1511 float device_scale_factor = 1.f; 1502 float device_scale_factor = 1.f;
1512 RenderSurfaceList render_surface_list; 1503 RenderSurfaceList render_surface_list;
1513 ExecuteCalculateDrawProperties(root, device_scale_factor, 1504 ExecuteCalculateDrawProperties(root, device_scale_factor,
1514 &render_surface_list); 1505 &render_surface_list);
1515 // Avoid the descendant-only property change path that skips unioning damage 1506 // Avoid the descendant-only property change path that skips unioning damage
1516 // from descendant layers. 1507 // from descendant layers.
1517 child1->GetRenderSurface()->NoteAncestorPropertyChanged(); 1508 GetRenderSurface(child1)->NoteAncestorPropertyChanged();
1518 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), 1509 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(),
1519 render_surface_list); 1510 render_surface_list);
1520 1511
1521 // The expected damage would be too large to store in a gfx::Rect, so we 1512 // The expected damage would be too large to store in a gfx::Rect, so we
1522 // should damage everything on child1. 1513 // should damage everything on child1.
1523 gfx::Rect damage_rect; 1514 gfx::Rect damage_rect;
1524 EXPECT_FALSE( 1515 EXPECT_FALSE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid(
1525 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1516 &damage_rect));
1526 &damage_rect)); 1517 EXPECT_EQ(GetRenderSurface(child1)->content_rect(),
1527 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), 1518 GetRenderSurface(child1)->GetDamageRect());
1528 child1->GetRenderSurface()->GetDamageRect());
1529 1519
1530 // However, the root should just use the child1 render surface's content rect 1520 // However, the root should just use the child1 render surface's content rect
1531 // as damage. 1521 // as damage.
1532 ASSERT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1522 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1533 &damage_rect)); 1523 &damage_rect));
1534 EXPECT_TRUE(damage_rect.Contains(root->GetRenderSurface()->content_rect())); 1524 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect()));
1535 EXPECT_TRUE(damage_rect.Contains( 1525 EXPECT_TRUE(damage_rect.Contains(
1536 gfx::ToEnclosingRect(child1->GetRenderSurface()->DrawableContentRect()))); 1526 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect())));
1537 EXPECT_EQ(damage_rect, root->GetRenderSurface()->GetDamageRect()); 1527 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect());
1538 1528
1539 // Add new damage, without changing properties, which goes down a different 1529 // Add new damage, without changing properties, which goes down a different
1540 // path in the damage tracker. 1530 // path in the damage tracker.
1541 root->layer_tree_impl()->ResetAllChangeTracking(); 1531 root->layer_tree_impl()->ResetAllChangeTracking();
1542 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); 1532 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds()));
1543 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); 1533 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds()));
1544 1534
1545 // Recompute all damage / properties. 1535 // Recompute all damage / properties.
1546 render_surface_list.clear(); 1536 render_surface_list.clear();
1547 ExecuteCalculateDrawProperties(root, device_scale_factor, 1537 ExecuteCalculateDrawProperties(root, device_scale_factor,
1548 &render_surface_list); 1538 &render_surface_list);
1549 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), 1539 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(),
1550 render_surface_list); 1540 render_surface_list);
1551 1541
1552 // Child1 should still not have a valid rect, since the union of the damage of 1542 // Child1 should still not have a valid rect, since the union of the damage of
1553 // its children is not representable by a single rect. 1543 // its children is not representable by a single rect.
1554 EXPECT_FALSE( 1544 EXPECT_FALSE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid(
1555 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1545 &damage_rect));
1556 &damage_rect)); 1546 EXPECT_EQ(GetRenderSurface(child1)->content_rect(),
1557 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), 1547 GetRenderSurface(child1)->GetDamageRect());
1558 child1->GetRenderSurface()->GetDamageRect());
1559 1548
1560 // Root should have valid damage and contain both its content rect and the 1549 // Root should have valid damage and contain both its content rect and the
1561 // drawable content rect of child1. 1550 // drawable content rect of child1.
1562 ASSERT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1551 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1563 &damage_rect)); 1552 &damage_rect));
1564 EXPECT_TRUE(damage_rect.Contains(root->GetRenderSurface()->content_rect())); 1553 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect()));
1565 EXPECT_TRUE(damage_rect.Contains( 1554 EXPECT_TRUE(damage_rect.Contains(
1566 gfx::ToEnclosingRect(child1->GetRenderSurface()->DrawableContentRect()))); 1555 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect())));
1567 EXPECT_EQ(damage_rect, root->GetRenderSurface()->GetDamageRect()); 1556 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect());
1568 } 1557 }
1569 1558
1570 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurfaceWithFilter) { 1559 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurfaceWithFilter) {
1571 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 1560 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
1572 LayerImpl* child1 = root->test_properties()->children[0]; 1561 LayerImpl* child1 = root->test_properties()->children[0];
1573 LayerImpl* grandchild1 = child1->test_properties()->children[0]; 1562 LayerImpl* grandchild1 = child1->test_properties()->children[0];
1574 LayerImpl* grandchild2 = child1->test_properties()->children[1]; 1563 LayerImpl* grandchild2 = child1->test_properties()->children[1];
1575 1564
1576 // Set up a moving pixels filter on the child. 1565 // Set up a moving pixels filter on the child.
1577 FilterOperations filters; 1566 FilterOperations filters;
(...skipping 13 matching lines...) Expand all
1591 grandchild2->SetBounds(gfx::Size(1, 1)); 1580 grandchild2->SetBounds(gfx::Size(1, 1));
1592 grandchild2->SetDrawsContent(true); 1581 grandchild2->SetDrawsContent(true);
1593 1582
1594 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1583 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1595 float device_scale_factor = 1.f; 1584 float device_scale_factor = 1.f;
1596 RenderSurfaceList render_surface_list; 1585 RenderSurfaceList render_surface_list;
1597 ExecuteCalculateDrawProperties(root, device_scale_factor, 1586 ExecuteCalculateDrawProperties(root, device_scale_factor,
1598 &render_surface_list); 1587 &render_surface_list);
1599 // Avoid the descendant-only property change path that skips unioning damage 1588 // Avoid the descendant-only property change path that skips unioning damage
1600 // from descendant layers. 1589 // from descendant layers.
1601 child1->GetRenderSurface()->NoteAncestorPropertyChanged(); 1590 GetRenderSurface(child1)->NoteAncestorPropertyChanged();
1602 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), 1591 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(),
1603 render_surface_list); 1592 render_surface_list);
1604 1593
1605 // The expected damage would be too large to store in a gfx::Rect, so we 1594 // The expected damage would be too large to store in a gfx::Rect, so we
1606 // should damage everything on child1. 1595 // should damage everything on child1.
1607 gfx::Rect damage_rect; 1596 gfx::Rect damage_rect;
1608 EXPECT_FALSE( 1597 EXPECT_FALSE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid(
1609 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1598 &damage_rect));
1610 &damage_rect)); 1599 EXPECT_EQ(GetRenderSurface(child1)->content_rect(),
1611 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), 1600 GetRenderSurface(child1)->GetDamageRect());
1612 child1->GetRenderSurface()->GetDamageRect());
1613 1601
1614 // However, the root should just use the child1 render surface's content rect 1602 // However, the root should just use the child1 render surface's content rect
1615 // as damage. 1603 // as damage.
1616 ASSERT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1604 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1617 &damage_rect)); 1605 &damage_rect));
1618 EXPECT_TRUE(damage_rect.Contains(root->GetRenderSurface()->content_rect())); 1606 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect()));
1619 EXPECT_TRUE(damage_rect.Contains( 1607 EXPECT_TRUE(damage_rect.Contains(
1620 gfx::ToEnclosingRect(child1->GetRenderSurface()->DrawableContentRect()))); 1608 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect())));
1621 EXPECT_EQ(damage_rect, root->GetRenderSurface()->GetDamageRect()); 1609 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect());
1622 1610
1623 // Add new damage, without changing properties, which goes down a different 1611 // Add new damage, without changing properties, which goes down a different
1624 // path in the damage tracker. 1612 // path in the damage tracker.
1625 root->layer_tree_impl()->ResetAllChangeTracking(); 1613 root->layer_tree_impl()->ResetAllChangeTracking();
1626 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); 1614 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds()));
1627 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); 1615 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds()));
1628 1616
1629 // Recompute all damage / properties. 1617 // Recompute all damage / properties.
1630 render_surface_list.clear(); 1618 render_surface_list.clear();
1631 ExecuteCalculateDrawProperties(root, device_scale_factor, 1619 ExecuteCalculateDrawProperties(root, device_scale_factor,
1632 &render_surface_list); 1620 &render_surface_list);
1633 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), 1621 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(),
1634 render_surface_list); 1622 render_surface_list);
1635 1623
1636 // Child1 should still not have a valid rect, since the union of the damage of 1624 // Child1 should still not have a valid rect, since the union of the damage of
1637 // its children is not representable by a single rect. 1625 // its children is not representable by a single rect.
1638 EXPECT_FALSE( 1626 EXPECT_FALSE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid(
1639 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1627 &damage_rect));
1640 &damage_rect)); 1628 EXPECT_EQ(GetRenderSurface(child1)->content_rect(),
1641 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), 1629 GetRenderSurface(child1)->GetDamageRect());
1642 child1->GetRenderSurface()->GetDamageRect());
1643 1630
1644 // Root should have valid damage and contain both its content rect and the 1631 // Root should have valid damage and contain both its content rect and the
1645 // drawable content rect of child1. 1632 // drawable content rect of child1.
1646 ASSERT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( 1633 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
1647 &damage_rect)); 1634 &damage_rect));
1648 EXPECT_TRUE(damage_rect.Contains(root->GetRenderSurface()->content_rect())); 1635 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect()));
1649 EXPECT_TRUE(damage_rect.Contains( 1636 EXPECT_TRUE(damage_rect.Contains(
1650 gfx::ToEnclosingRect(child1->GetRenderSurface()->DrawableContentRect()))); 1637 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect())));
1651 EXPECT_EQ(damage_rect, root->GetRenderSurface()->GetDamageRect()); 1638 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect());
1652 } 1639 }
1653 1640
1654 } // namespace 1641 } // namespace
1655 } // namespace cc 1642 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/layer_test_common.cc ('k') | cc/trees/layer_tree_host_common_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698