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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 EXPECT_EQ(point1_in_l1_coords, point1_in_l3_coords); | 503 EXPECT_EQ(point1_in_l1_coords, point1_in_l3_coords); |
| 504 | 504 |
| 505 gfx::Point point2_in_l1_coords(5, 5); | 505 gfx::Point point2_in_l1_coords(5, 5); |
| 506 Layer::ConvertPointToLayer(l1.get(), l3.get(), &point2_in_l1_coords); | 506 Layer::ConvertPointToLayer(l1.get(), l3.get(), &point2_in_l1_coords); |
| 507 gfx::Point point2_in_l3_coords(-15, -15); | 507 gfx::Point point2_in_l3_coords(-15, -15); |
| 508 EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords); | 508 EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords); |
| 509 } | 509 } |
| 510 | 510 |
| 511 TEST_F(LayerWithRealCompositorTest, Delegate) { | 511 TEST_F(LayerWithRealCompositorTest, Delegate) { |
| 512 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorBLACK, | 512 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorBLACK, |
| 513 gfx::Rect(20, 20, 400, 400))); | 513 gfx::Rect(20, 20, 1000, 1000))); |
| 514 GetCompositor()->SetRootLayer(l1.get()); | 514 GetCompositor()->SetRootLayer(l1.get()); |
| 515 WaitForDraw(); | 515 WaitForDraw(); |
| 516 | 516 |
| 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, 1000, 1000)); |
| 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()); | 527 EXPECT_EQ(delegate.paint_size(), gfx::Size(1030, 1030)); |
|
danakj
2015/03/03 17:57:05
This bakes in cc internal knowledge into these num
weiliangc
2015/03/04 01:23:57
paint_size() still used here.
(also time to test
weiliangc
2015/03/06 20:42:46
paint_size still needed here, since canvas rect wo
| |
| 528 | 528 |
| 529 l1->SchedulePaint(gfx::Rect(10, 10, 200, 200)); | 529 l1->SchedulePaint(gfx::Rect(10, 10, 600, 600)); |
| 530 WaitForDraw(); | 530 WaitForDraw(); |
| 531 EXPECT_EQ(delegate.color_index(), 2); | 531 EXPECT_EQ(delegate.color_index(), 2); |
| 532 EXPECT_EQ(delegate.paint_size(), gfx::Size(200, 200)); | 532 EXPECT_EQ(delegate.paint_size(), gfx::Size(1009, 1009)); |
| 533 | 533 |
| 534 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50)); | 534 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50)); |
| 535 WaitForDraw(); | 535 WaitForDraw(); |
| 536 EXPECT_EQ(delegate.color_index(), 0); | 536 EXPECT_EQ(delegate.color_index(), 0); |
| 537 EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50)); | 537 EXPECT_EQ(delegate.paint_size(), gfx::Size(527, 527)); |
| 538 } | 538 } |
| 539 | 539 |
| 540 TEST_F(LayerWithRealCompositorTest, DrawTree) { | 540 TEST_F(LayerWithRealCompositorTest, DrawTree) { |
| 541 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 541 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, |
| 542 gfx::Rect(20, 20, 400, 400))); | 542 gfx::Rect(20, 20, 400, 400))); |
| 543 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 543 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, |
| 544 gfx::Rect(10, 10, 350, 350))); | 544 gfx::Rect(10, 10, 350, 350))); |
| 545 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, | 545 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, |
| 546 gfx::Rect(10, 10, 100, 100))); | 546 gfx::Rect(10, 10, 100, 100))); |
| 547 l1->Add(l2.get()); | 547 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()); | 1301 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
| 1302 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1302 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
| 1303 gfx::Size cc_bounds_size = root->cc_layer()->bounds(); | 1303 gfx::Size cc_bounds_size = root->cc_layer()->bounds(); |
| 1304 EXPECT_EQ("200x220", cc_bounds_size.ToString()); | 1304 EXPECT_EQ("200x220", cc_bounds_size.ToString()); |
| 1305 cc_bounds_size = l1->cc_layer()->bounds(); | 1305 cc_bounds_size = l1->cc_layer()->bounds(); |
| 1306 EXPECT_EQ("140x180", cc_bounds_size.ToString()); | 1306 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
| 1307 // No scale change, so no scale notification. | 1307 // No scale change, so no scale notification. |
| 1308 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); | 1308 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); |
| 1309 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); | 1309 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); |
| 1310 | 1310 |
| 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. | 1311 // Scale up to 2.0. Changing scale doesn't change the bounds in DIP. |
| 1315 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); | 1312 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); |
| 1316 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); | 1313 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
| 1317 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1314 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
| 1318 // CC layer should still match the UI layer bounds. | 1315 // CC layer should still match the UI layer bounds. |
| 1319 cc_bounds_size = root->cc_layer()->bounds(); | 1316 cc_bounds_size = root->cc_layer()->bounds(); |
| 1320 EXPECT_EQ("200x220", cc_bounds_size.ToString()); | 1317 EXPECT_EQ("200x220", cc_bounds_size.ToString()); |
| 1321 cc_bounds_size = l1->cc_layer()->bounds(); | 1318 cc_bounds_size = l1->cc_layer()->bounds(); |
| 1322 EXPECT_EQ("140x180", cc_bounds_size.ToString()); | 1319 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
| 1323 // New scale factor must have been notified. | 1320 // New scale factor must have been notified. |
| 1324 EXPECT_EQ(2.0f, root_delegate.device_scale_factor()); | 1321 EXPECT_EQ(2.0f, root_delegate.device_scale_factor()); |
| 1325 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); | 1322 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); |
| 1326 | 1323 |
| 1327 // Canvas size must have been scaled down up. | 1324 // Canvas size must have been scaled down up. |
| 1328 WaitForDraw(); | 1325 WaitForDraw(); |
| 1329 EXPECT_EQ("400x440", root_delegate.paint_size().ToString()); | |
| 1330 EXPECT_EQ("2.0 2.0", root_delegate.ToScaleString()); | |
| 1331 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); | |
| 1332 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); | |
| 1333 | 1326 |
| 1334 // Scale down back to 1.0f. | 1327 // Scale down back to 1.0f. |
| 1335 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); | 1328 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); |
| 1336 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); | 1329 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
| 1337 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1330 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
| 1338 // CC layer should still match the UI layer bounds. | 1331 // CC layer should still match the UI layer bounds. |
| 1339 cc_bounds_size = root->cc_layer()->bounds(); | 1332 cc_bounds_size = root->cc_layer()->bounds(); |
| 1340 EXPECT_EQ("200x220", cc_bounds_size.ToString()); | 1333 EXPECT_EQ("200x220", cc_bounds_size.ToString()); |
| 1341 cc_bounds_size = l1->cc_layer()->bounds(); | 1334 cc_bounds_size = l1->cc_layer()->bounds(); |
| 1342 EXPECT_EQ("140x180", cc_bounds_size.ToString()); | 1335 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
| 1343 // New scale factor must have been notified. | 1336 // New scale factor must have been notified. |
| 1344 EXPECT_EQ(1.0f, root_delegate.device_scale_factor()); | 1337 EXPECT_EQ(1.0f, root_delegate.device_scale_factor()); |
| 1345 EXPECT_EQ(1.0f, l1_delegate.device_scale_factor()); | 1338 EXPECT_EQ(1.0f, l1_delegate.device_scale_factor()); |
| 1346 | 1339 |
| 1347 // Canvas size must have been scaled down too. | 1340 // Canvas size must have been scaled down too. |
| 1348 WaitForDraw(); | 1341 WaitForDraw(); |
| 1349 EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); | |
| 1350 EXPECT_EQ("1.0 1.0", root_delegate.ToScaleString()); | 1342 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()); | 1343 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); |
| 1353 | 1344 |
| 1354 root_delegate.reset(); | 1345 root_delegate.reset(); |
| 1355 l1_delegate.reset(); | 1346 l1_delegate.reset(); |
| 1356 // Just changing the size shouldn't notify the scale change nor | 1347 // Just changing the size shouldn't notify the scale change nor |
| 1357 // trigger repaint. | 1348 // trigger repaint. |
| 1358 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); | 1349 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); |
| 1359 // No scale change, so no scale notification. | 1350 // No scale change, so no scale notification. |
| 1360 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); | 1351 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); |
| 1361 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); | 1352 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1379 GetCompositor()->SetRootLayer(root.get()); | 1370 GetCompositor()->SetRootLayer(root.get()); |
| 1380 WaitForDraw(); | 1371 WaitForDraw(); |
| 1381 | 1372 |
| 1382 root->Add(l1.get()); | 1373 root->Add(l1.get()); |
| 1383 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1374 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
| 1384 gfx::Size cc_bounds_size = l1->cc_layer()->bounds(); | 1375 gfx::Size cc_bounds_size = l1->cc_layer()->bounds(); |
| 1385 EXPECT_EQ("140x180", cc_bounds_size.ToString()); | 1376 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
| 1386 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); | 1377 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); |
| 1387 | 1378 |
| 1388 WaitForDraw(); | 1379 WaitForDraw(); |
| 1389 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); | |
| 1390 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); | |
| 1391 | 1380 |
| 1392 // Remove l1 from root and change the scale. | 1381 // Remove l1 from root and change the scale. |
| 1393 root->Remove(l1.get()); | 1382 root->Remove(l1.get()); |
| 1394 EXPECT_EQ(NULL, l1->parent()); | 1383 EXPECT_EQ(NULL, l1->parent()); |
| 1395 EXPECT_EQ(NULL, l1->GetCompositor()); | 1384 EXPECT_EQ(NULL, l1->GetCompositor()); |
| 1396 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); | 1385 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); |
| 1397 // Sanity check on root and l1. | 1386 // Sanity check on root and l1. |
| 1398 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); | 1387 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
| 1399 cc_bounds_size = l1->cc_layer()->bounds(); | 1388 cc_bounds_size = l1->cc_layer()->bounds(); |
| 1400 EXPECT_EQ("140x180", cc_bounds_size.ToString()); | 1389 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
| 1401 | 1390 |
| 1402 root->Add(l1.get()); | 1391 root->Add(l1.get()); |
| 1403 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1392 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
| 1404 cc_bounds_size = l1->cc_layer()->bounds(); | 1393 cc_bounds_size = l1->cc_layer()->bounds(); |
| 1405 EXPECT_EQ("140x180", cc_bounds_size.ToString()); | 1394 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
| 1406 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); | 1395 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); |
| 1407 WaitForDraw(); | 1396 WaitForDraw(); |
| 1408 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); | |
| 1409 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); | |
| 1410 } | 1397 } |
| 1411 | 1398 |
| 1412 // Verifies that when changing bounds on a layer that is invisible, and then | 1399 // Verifies that when changing bounds on a layer that is invisible, and then |
| 1413 // made visible, the right thing happens: | 1400 // made visible, the right thing happens: |
| 1414 // - if just a move, then no painting should happen. | 1401 // - if just a move, then no painting should happen. |
| 1415 // - if a resize, the layer should be repainted. | 1402 // - if a resize, the layer should be repainted. |
| 1416 TEST_F(LayerWithDelegateTest, SetBoundsWhenInvisible) { | 1403 TEST_F(LayerWithDelegateTest, SetBoundsWhenInvisible) { |
| 1417 scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); | 1404 scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); |
| 1418 | 1405 |
| 1419 scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); | 1406 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)))); | 1753 MakeFrameData(gfx::Size(10, 10)))); |
| 1767 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); | 1754 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); |
| 1768 | 1755 |
| 1769 EXPECT_FALSE(delegate.delegated_frame_damage_called()); | 1756 EXPECT_FALSE(delegate.delegated_frame_damage_called()); |
| 1770 layer->OnDelegatedFrameDamage(damage_rect); | 1757 layer->OnDelegatedFrameDamage(damage_rect); |
| 1771 EXPECT_TRUE(delegate.delegated_frame_damage_called()); | 1758 EXPECT_TRUE(delegate.delegated_frame_damage_called()); |
| 1772 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); | 1759 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); |
| 1773 } | 1760 } |
| 1774 | 1761 |
| 1775 } // namespace ui | 1762 } // namespace ui |
| OLD | NEW |