Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 TestLayerDelegate delegate; | 517 TestLayerDelegate delegate; |
| 518 l1->set_delegate(&delegate); | 518 l1->set_delegate(&delegate); |
| 519 delegate.AddColor(SK_ColorWHITE); | 519 delegate.AddColor(SK_ColorWHITE); |
| 520 delegate.AddColor(SK_ColorYELLOW); | 520 delegate.AddColor(SK_ColorYELLOW); |
| 521 delegate.AddColor(SK_ColorGREEN); | 521 delegate.AddColor(SK_ColorGREEN); |
| 522 | 522 |
| 523 l1->SchedulePaint(gfx::Rect(0, 0, 400, 400)); | 523 l1->SchedulePaint(gfx::Rect(0, 0, 400, 400)); |
| 524 WaitForDraw(); | 524 WaitForDraw(); |
| 525 | 525 |
| 526 EXPECT_EQ(delegate.color_index(), 1); | 526 EXPECT_EQ(delegate.color_index(), 1); |
| 527 EXPECT_EQ(delegate.paint_size(), l1->bounds().size()); | |
| 528 | 527 |
| 529 l1->SchedulePaint(gfx::Rect(10, 10, 200, 200)); | 528 l1->SchedulePaint(gfx::Rect(10, 10, 200, 200)); |
| 530 WaitForDraw(); | 529 WaitForDraw(); |
| 531 EXPECT_EQ(delegate.color_index(), 2); | 530 EXPECT_EQ(delegate.color_index(), 2); |
| 532 EXPECT_EQ(delegate.paint_size(), gfx::Size(200, 200)); | |
|
danakj
2015/03/02 23:03:09
can you make the delegate bigger so that you can v
weiliangc
2015/03/03 16:35:44
Done.
| |
| 533 | 531 |
| 534 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50)); | 532 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50)); |
| 535 WaitForDraw(); | 533 WaitForDraw(); |
| 536 EXPECT_EQ(delegate.color_index(), 0); | 534 EXPECT_EQ(delegate.color_index(), 0); |
| 537 EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50)); | |
| 538 } | 535 } |
| 539 | 536 |
| 540 TEST_F(LayerWithRealCompositorTest, DrawTree) { | 537 TEST_F(LayerWithRealCompositorTest, DrawTree) { |
| 541 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 538 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, |
| 542 gfx::Rect(20, 20, 400, 400))); | 539 gfx::Rect(20, 20, 400, 400))); |
| 543 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 540 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, |
| 544 gfx::Rect(10, 10, 350, 350))); | 541 gfx::Rect(10, 10, 350, 350))); |
| 545 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, | 542 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, |
| 546 gfx::Rect(10, 10, 100, 100))); | 543 gfx::Rect(10, 10, 100, 100))); |
| 547 l1->Add(l2.get()); | 544 l1->Add(l2.get()); |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1301 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); | 1298 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
| 1302 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1299 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
| 1303 gfx::Size cc_bounds_size = root->cc_layer()->bounds(); | 1300 gfx::Size cc_bounds_size = root->cc_layer()->bounds(); |
| 1304 EXPECT_EQ("200x220", cc_bounds_size.ToString()); | 1301 EXPECT_EQ("200x220", cc_bounds_size.ToString()); |
| 1305 cc_bounds_size = l1->cc_layer()->bounds(); | 1302 cc_bounds_size = l1->cc_layer()->bounds(); |
| 1306 EXPECT_EQ("140x180", cc_bounds_size.ToString()); | 1303 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
| 1307 // No scale change, so no scale notification. | 1304 // No scale change, so no scale notification. |
| 1308 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); | 1305 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); |
| 1309 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); | 1306 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); |
| 1310 | 1307 |
| 1311 EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); | |
| 1312 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); | |
| 1313 | |
| 1314 // Scale up to 2.0. Changing scale doesn't change the bounds in DIP. | 1308 // Scale up to 2.0. Changing scale doesn't change the bounds in DIP. |
| 1315 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); | 1309 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); |
| 1316 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); | 1310 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
| 1317 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1311 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
| 1318 // CC layer should still match the UI layer bounds. | 1312 // CC layer should still match the UI layer bounds. |
| 1319 cc_bounds_size = root->cc_layer()->bounds(); | 1313 cc_bounds_size = root->cc_layer()->bounds(); |
| 1320 EXPECT_EQ("200x220", cc_bounds_size.ToString()); | 1314 EXPECT_EQ("200x220", cc_bounds_size.ToString()); |
| 1321 cc_bounds_size = l1->cc_layer()->bounds(); | 1315 cc_bounds_size = l1->cc_layer()->bounds(); |
| 1322 EXPECT_EQ("140x180", cc_bounds_size.ToString()); | 1316 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
| 1323 // New scale factor must have been notified. | 1317 // New scale factor must have been notified. |
| 1324 EXPECT_EQ(2.0f, root_delegate.device_scale_factor()); | 1318 EXPECT_EQ(2.0f, root_delegate.device_scale_factor()); |
| 1325 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); | 1319 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); |
| 1326 | 1320 |
| 1327 // Canvas size must have been scaled down up. | 1321 // Canvas size must have been scaled down up. |
|
danakj
2015/03/03 17:57:05
You can remove this WaitForDraw() block entirely i
| |
| 1328 WaitForDraw(); | 1322 WaitForDraw(); |
| 1329 EXPECT_EQ("400x440", root_delegate.paint_size().ToString()); | |
| 1330 EXPECT_EQ("2.0 2.0", root_delegate.ToScaleString()); | |
|
danakj
2015/03/02 23:03:09
Does the DSF no longer go to the delegate? This te
weiliangc
2015/03/03 16:35:44
The ScaleString is from the canvas passed to Layer
| |
| 1331 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); | |
| 1332 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); | |
| 1333 | 1323 |
| 1334 // Scale down back to 1.0f. | 1324 // Scale down back to 1.0f. |
| 1335 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); | 1325 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); |
| 1336 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); | 1326 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
| 1337 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1327 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
| 1338 // CC layer should still match the UI layer bounds. | 1328 // CC layer should still match the UI layer bounds. |
| 1339 cc_bounds_size = root->cc_layer()->bounds(); | 1329 cc_bounds_size = root->cc_layer()->bounds(); |
| 1340 EXPECT_EQ("200x220", cc_bounds_size.ToString()); | 1330 EXPECT_EQ("200x220", cc_bounds_size.ToString()); |
| 1341 cc_bounds_size = l1->cc_layer()->bounds(); | 1331 cc_bounds_size = l1->cc_layer()->bounds(); |
| 1342 EXPECT_EQ("140x180", cc_bounds_size.ToString()); | 1332 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
| 1343 // New scale factor must have been notified. | 1333 // New scale factor must have been notified. |
| 1344 EXPECT_EQ(1.0f, root_delegate.device_scale_factor()); | 1334 EXPECT_EQ(1.0f, root_delegate.device_scale_factor()); |
| 1345 EXPECT_EQ(1.0f, l1_delegate.device_scale_factor()); | 1335 EXPECT_EQ(1.0f, l1_delegate.device_scale_factor()); |
| 1346 | 1336 |
| 1347 // Canvas size must have been scaled down too. | 1337 // Canvas size must have been scaled down too. |
| 1348 WaitForDraw(); | 1338 WaitForDraw(); |
|
danakj
2015/03/03 17:57:05
same here
| |
| 1349 EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); | |
| 1350 EXPECT_EQ("1.0 1.0", root_delegate.ToScaleString()); | 1339 EXPECT_EQ("1.0 1.0", root_delegate.ToScaleString()); |
| 1351 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); | |
| 1352 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); | 1340 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); |
| 1353 | 1341 |
| 1354 root_delegate.reset(); | 1342 root_delegate.reset(); |
| 1355 l1_delegate.reset(); | 1343 l1_delegate.reset(); |
| 1356 // Just changing the size shouldn't notify the scale change nor | 1344 // Just changing the size shouldn't notify the scale change nor |
| 1357 // trigger repaint. | 1345 // trigger repaint. |
| 1358 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); | 1346 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); |
| 1359 // No scale change, so no scale notification. | 1347 // No scale change, so no scale notification. |
| 1360 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); | 1348 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); |
| 1361 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); | 1349 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); |
| 1362 WaitForDraw(); | 1350 WaitForDraw(); |
| 1363 EXPECT_EQ("0x0", root_delegate.paint_size().ToString()); | 1351 EXPECT_EQ("0x0", root_delegate.paint_size().ToString()); |
|
danakj
2015/03/03 17:57:05
can you test "paint_count()" or something instead,
weiliangc
2015/03/04 01:23:57
paint_size() can still be used for the later tests
| |
| 1364 EXPECT_EQ("0.0 0.0", root_delegate.ToScaleString()); | 1352 EXPECT_EQ("0.0 0.0", root_delegate.ToScaleString()); |
| 1365 EXPECT_EQ("0x0", l1_delegate.paint_size().ToString()); | 1353 EXPECT_EQ("0x0", l1_delegate.paint_size().ToString()); |
| 1366 EXPECT_EQ("0.0 0.0", l1_delegate.ToScaleString()); | 1354 EXPECT_EQ("0.0 0.0", l1_delegate.ToScaleString()); |
| 1367 } | 1355 } |
| 1368 | 1356 |
| 1369 TEST_F(LayerWithRealCompositorTest, ScaleReparent) { | 1357 TEST_F(LayerWithRealCompositorTest, ScaleReparent) { |
| 1370 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, | 1358 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, |
| 1371 gfx::Rect(10, 20, 200, 220))); | 1359 gfx::Rect(10, 20, 200, 220))); |
| 1372 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, | 1360 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, |
| 1373 gfx::Rect(10, 20, 140, 180))); | 1361 gfx::Rect(10, 20, 140, 180))); |
| 1374 TestLayerDelegate l1_delegate; | 1362 TestLayerDelegate l1_delegate; |
| 1375 l1_delegate.AddColor(SK_ColorWHITE); | 1363 l1_delegate.AddColor(SK_ColorWHITE); |
| 1376 l1->set_delegate(&l1_delegate); | 1364 l1->set_delegate(&l1_delegate); |
| 1377 | 1365 |
| 1378 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); | 1366 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); |
| 1379 GetCompositor()->SetRootLayer(root.get()); | 1367 GetCompositor()->SetRootLayer(root.get()); |
| 1380 WaitForDraw(); | 1368 WaitForDraw(); |
| 1381 | 1369 |
| 1382 root->Add(l1.get()); | 1370 root->Add(l1.get()); |
| 1383 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1371 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
| 1384 gfx::Size cc_bounds_size = l1->cc_layer()->bounds(); | 1372 gfx::Size cc_bounds_size = l1->cc_layer()->bounds(); |
| 1385 EXPECT_EQ("140x180", cc_bounds_size.ToString()); | 1373 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
| 1386 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); | 1374 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); |
| 1387 | 1375 |
| 1388 WaitForDraw(); | 1376 WaitForDraw(); |
| 1389 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); | |
|
danakj
2015/03/02 23:03:09
This test isn't testing anything now. We should lo
weiliangc
2015/03/03 16:35:44
The test was added when moving DIP translation to
danakj
2015/03/03 17:57:05
Thanks for digging. I think this test made sense t
| |
| 1390 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); | |
| 1391 | 1377 |
| 1392 // Remove l1 from root and change the scale. | 1378 // Remove l1 from root and change the scale. |
| 1393 root->Remove(l1.get()); | 1379 root->Remove(l1.get()); |
| 1394 EXPECT_EQ(NULL, l1->parent()); | 1380 EXPECT_EQ(NULL, l1->parent()); |
| 1395 EXPECT_EQ(NULL, l1->GetCompositor()); | 1381 EXPECT_EQ(NULL, l1->GetCompositor()); |
| 1396 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); | 1382 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); |
| 1397 // Sanity check on root and l1. | 1383 // Sanity check on root and l1. |
| 1398 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); | 1384 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
| 1399 cc_bounds_size = l1->cc_layer()->bounds(); | 1385 cc_bounds_size = l1->cc_layer()->bounds(); |
| 1400 EXPECT_EQ("140x180", cc_bounds_size.ToString()); | 1386 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
| 1401 | 1387 |
| 1402 root->Add(l1.get()); | 1388 root->Add(l1.get()); |
| 1403 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1389 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
| 1404 cc_bounds_size = l1->cc_layer()->bounds(); | 1390 cc_bounds_size = l1->cc_layer()->bounds(); |
| 1405 EXPECT_EQ("140x180", cc_bounds_size.ToString()); | 1391 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
| 1406 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); | 1392 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); |
| 1407 WaitForDraw(); | 1393 WaitForDraw(); |
| 1408 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); | |
| 1409 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); | |
| 1410 } | 1394 } |
| 1411 | 1395 |
| 1412 // Verifies that when changing bounds on a layer that is invisible, and then | 1396 // Verifies that when changing bounds on a layer that is invisible, and then |
| 1413 // made visible, the right thing happens: | 1397 // made visible, the right thing happens: |
| 1414 // - if just a move, then no painting should happen. | 1398 // - if just a move, then no painting should happen. |
| 1415 // - if a resize, the layer should be repainted. | 1399 // - if a resize, the layer should be repainted. |
| 1416 TEST_F(LayerWithDelegateTest, SetBoundsWhenInvisible) { | 1400 TEST_F(LayerWithDelegateTest, SetBoundsWhenInvisible) { |
| 1417 scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); | 1401 scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); |
| 1418 | 1402 |
| 1419 scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); | 1403 scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1766 MakeFrameData(gfx::Size(10, 10)))); | 1750 MakeFrameData(gfx::Size(10, 10)))); |
| 1767 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); | 1751 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); |
| 1768 | 1752 |
| 1769 EXPECT_FALSE(delegate.delegated_frame_damage_called()); | 1753 EXPECT_FALSE(delegate.delegated_frame_damage_called()); |
| 1770 layer->OnDelegatedFrameDamage(damage_rect); | 1754 layer->OnDelegatedFrameDamage(damage_rect); |
| 1771 EXPECT_TRUE(delegate.delegated_frame_damage_called()); | 1755 EXPECT_TRUE(delegate.delegated_frame_damage_called()); |
| 1772 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); | 1756 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); |
| 1773 } | 1757 } |
| 1774 | 1758 |
| 1775 } // namespace ui | 1759 } // namespace ui |
| OLD | NEW |