OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1483 host_impl_.ActivateSyncTree(); | 1483 host_impl_.ActivateSyncTree(); |
1484 | 1484 |
1485 active_layer_ = static_cast<FakePictureLayerImpl*>( | 1485 active_layer_ = static_cast<FakePictureLayerImpl*>( |
1486 host_impl_.active_tree()->LayerById(id_)); | 1486 host_impl_.active_tree()->LayerById(id_)); |
1487 | 1487 |
1488 EXPECT_EQ(0u, active_layer_->num_tilings()); | 1488 EXPECT_EQ(0u, active_layer_->num_tilings()); |
1489 EXPECT_EQ(raster_page_scale, active_layer_->raster_page_scale()); | 1489 EXPECT_EQ(raster_page_scale, active_layer_->raster_page_scale()); |
1490 EXPECT_FALSE(active_layer_->needs_post_commit_initialization()); | 1490 EXPECT_FALSE(active_layer_->needs_post_commit_initialization()); |
1491 } | 1491 } |
1492 | 1492 |
1493 TEST_F(PictureLayerImplTest, RemoveInvalidTilesOnActivation) { | 1493 TEST_F(PictureLayerImplTest, ShareTilesOnSync) { |
1494 SetupDefaultTrees(gfx::Size(1500, 1500)); | 1494 SetupDefaultTrees(gfx::Size(1500, 1500)); |
1495 AddDefaultTilingsWithInvalidation(gfx::Rect(0, 0, 1, 1)); | 1495 AddDefaultTilingsWithInvalidation(gfx::Rect()); |
1496 | 1496 |
1497 FakePictureLayerImpl* recycled_layer = pending_layer_; | |
1498 host_impl_.ActivateSyncTree(); | 1497 host_impl_.ActivateSyncTree(); |
1499 | 1498 host_impl_.CreatePendingTree(); |
1500 active_layer_ = static_cast<FakePictureLayerImpl*>( | 1499 active_layer_ = static_cast<FakePictureLayerImpl*>( |
1501 host_impl_.active_tree()->LayerById(id_)); | 1500 host_impl_.active_tree()->LayerById(id_)); |
1502 | 1501 |
| 1502 // Force the active tree to sync to the pending tree "post-commit". |
| 1503 pending_layer_->DoPostCommitInitializationIfNeeded(); |
| 1504 |
| 1505 // Both invalidations should drop tiles from the pending tree. |
1503 EXPECT_EQ(3u, active_layer_->num_tilings()); | 1506 EXPECT_EQ(3u, active_layer_->num_tilings()); |
1504 EXPECT_EQ(3u, recycled_layer->num_tilings()); | 1507 EXPECT_EQ(3u, pending_layer_->num_tilings()); |
1505 EXPECT_FALSE(host_impl_.pending_tree()); | |
1506 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { | 1508 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { |
1507 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(i); | 1509 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(i); |
1508 PictureLayerTiling* recycled_tiling = | 1510 PictureLayerTiling* pending_tiling = |
1509 recycled_layer->tilings()->tiling_at(i); | 1511 pending_layer_->tilings()->tiling_at(i); |
1510 | 1512 |
1511 ASSERT_TRUE(active_tiling); | 1513 ASSERT_TRUE(active_tiling); |
1512 ASSERT_TRUE(recycled_tiling); | 1514 ASSERT_TRUE(pending_tiling); |
1513 | 1515 |
1514 EXPECT_TRUE(active_tiling->TileAt(0, 0)); | 1516 EXPECT_TRUE(active_tiling->TileAt(0, 0)); |
1515 EXPECT_TRUE(active_tiling->TileAt(1, 0)); | 1517 EXPECT_TRUE(active_tiling->TileAt(1, 0)); |
1516 EXPECT_TRUE(active_tiling->TileAt(0, 1)); | 1518 EXPECT_TRUE(active_tiling->TileAt(0, 1)); |
1517 EXPECT_TRUE(active_tiling->TileAt(1, 1)); | 1519 EXPECT_TRUE(active_tiling->TileAt(1, 1)); |
1518 | 1520 |
1519 EXPECT_FALSE(recycled_tiling->TileAt(0, 0)); | 1521 EXPECT_TRUE(pending_tiling->TileAt(0, 0)); |
1520 EXPECT_TRUE(recycled_tiling->TileAt(1, 0)); | 1522 EXPECT_TRUE(pending_tiling->TileAt(1, 0)); |
1521 EXPECT_TRUE(recycled_tiling->TileAt(0, 1)); | 1523 EXPECT_TRUE(pending_tiling->TileAt(0, 1)); |
1522 EXPECT_TRUE(recycled_tiling->TileAt(1, 1)); | 1524 EXPECT_TRUE(pending_tiling->TileAt(1, 1)); |
1523 | 1525 |
1524 EXPECT_EQ(active_tiling->TileAt(1, 0), recycled_tiling->TileAt(1, 0)); | 1526 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0)); |
1525 EXPECT_EQ(active_tiling->TileAt(0, 1), recycled_tiling->TileAt(0, 1)); | 1527 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0)); |
1526 EXPECT_EQ(active_tiling->TileAt(1, 1), recycled_tiling->TileAt(1, 1)); | 1528 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1)); |
| 1529 EXPECT_EQ(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1)); |
1527 } | 1530 } |
1528 } | 1531 } |
1529 | 1532 |
| 1533 TEST_F(PictureLayerImplTest, RemoveInvalidActiveTreeTilesOnSync) { |
| 1534 SetupDefaultTrees(gfx::Size(1500, 1500)); |
| 1535 AddDefaultTilingsWithInvalidation(gfx::Rect(0, 0, 1, 1)); |
| 1536 |
| 1537 // This activates the 0,0,1,1 invalidation. |
| 1538 host_impl_.ActivateSyncTree(); |
| 1539 host_impl_.CreatePendingTree(); |
| 1540 active_layer_ = static_cast<FakePictureLayerImpl*>( |
| 1541 host_impl_.active_tree()->LayerById(id_)); |
| 1542 |
| 1543 // Force the active tree to sync to the pending tree "post-commit". |
| 1544 pending_layer_->DoPostCommitInitializationIfNeeded(); |
| 1545 |
| 1546 // Both invalidations should drop tiles from the pending tree. |
| 1547 EXPECT_EQ(3u, active_layer_->num_tilings()); |
| 1548 EXPECT_EQ(3u, pending_layer_->num_tilings()); |
| 1549 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { |
| 1550 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(i); |
| 1551 PictureLayerTiling* pending_tiling = |
| 1552 pending_layer_->tilings()->tiling_at(i); |
| 1553 |
| 1554 ASSERT_TRUE(active_tiling); |
| 1555 ASSERT_TRUE(pending_tiling); |
| 1556 |
| 1557 EXPECT_TRUE(active_tiling->TileAt(0, 0)); |
| 1558 EXPECT_TRUE(active_tiling->TileAt(1, 0)); |
| 1559 EXPECT_TRUE(active_tiling->TileAt(0, 1)); |
| 1560 EXPECT_TRUE(active_tiling->TileAt(1, 1)); |
| 1561 |
| 1562 EXPECT_TRUE(pending_tiling->TileAt(0, 0)); |
| 1563 EXPECT_TRUE(pending_tiling->TileAt(1, 0)); |
| 1564 EXPECT_TRUE(pending_tiling->TileAt(0, 1)); |
| 1565 EXPECT_TRUE(pending_tiling->TileAt(1, 1)); |
| 1566 |
| 1567 EXPECT_NE(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0)); |
| 1568 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0)); |
| 1569 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1)); |
| 1570 EXPECT_EQ(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1)); |
| 1571 } |
| 1572 } |
| 1573 |
| 1574 TEST_F(PictureLayerImplTest, RemoveInvalidPendingTreeTilesOnSync) { |
| 1575 SetupDefaultTrees(gfx::Size(1500, 1500)); |
| 1576 AddDefaultTilingsWithInvalidation(gfx::Rect()); |
| 1577 |
| 1578 host_impl_.ActivateSyncTree(); |
| 1579 host_impl_.CreatePendingTree(); |
| 1580 active_layer_ = static_cast<FakePictureLayerImpl*>( |
| 1581 host_impl_.active_tree()->LayerById(id_)); |
| 1582 |
| 1583 // Set some invalidation on the pending tree "during commit". We should |
| 1584 // replace raster tiles that touch this. |
| 1585 pending_layer_->set_invalidation(gfx::Rect(1, 1)); |
| 1586 |
| 1587 // Force the active tree to sync to the pending tree "post-commit". |
| 1588 pending_layer_->DoPostCommitInitializationIfNeeded(); |
| 1589 |
| 1590 // Both invalidations should drop tiles from the pending tree. |
| 1591 EXPECT_EQ(3u, active_layer_->num_tilings()); |
| 1592 EXPECT_EQ(3u, pending_layer_->num_tilings()); |
| 1593 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { |
| 1594 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(i); |
| 1595 PictureLayerTiling* pending_tiling = |
| 1596 pending_layer_->tilings()->tiling_at(i); |
| 1597 |
| 1598 ASSERT_TRUE(active_tiling); |
| 1599 ASSERT_TRUE(pending_tiling); |
| 1600 |
| 1601 EXPECT_TRUE(active_tiling->TileAt(0, 0)); |
| 1602 EXPECT_TRUE(active_tiling->TileAt(1, 0)); |
| 1603 EXPECT_TRUE(active_tiling->TileAt(0, 1)); |
| 1604 EXPECT_TRUE(active_tiling->TileAt(1, 1)); |
| 1605 |
| 1606 EXPECT_TRUE(pending_tiling->TileAt(0, 0)); |
| 1607 EXPECT_TRUE(pending_tiling->TileAt(1, 0)); |
| 1608 EXPECT_TRUE(pending_tiling->TileAt(0, 1)); |
| 1609 EXPECT_TRUE(pending_tiling->TileAt(1, 1)); |
| 1610 |
| 1611 EXPECT_NE(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0)); |
| 1612 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0)); |
| 1613 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1)); |
| 1614 EXPECT_EQ(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1)); |
| 1615 } |
| 1616 } |
| 1617 |
1530 TEST_F(PictureLayerImplTest, SyncTilingAfterReleaseResource) { | 1618 TEST_F(PictureLayerImplTest, SyncTilingAfterReleaseResource) { |
1531 SetupDefaultTrees(gfx::Size(10, 10)); | 1619 SetupDefaultTrees(gfx::Size(10, 10)); |
1532 host_impl_.active_tree()->UpdateDrawProperties(); | 1620 host_impl_.active_tree()->UpdateDrawProperties(); |
1533 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties()); | 1621 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties()); |
1534 | 1622 |
1535 // Contrived unit test of a real crash. A layer is transparent during a | 1623 // Contrived unit test of a real crash. A layer is transparent during a |
1536 // context loss, and later becomes opaque, causing active layer SyncTiling to | 1624 // context loss, and later becomes opaque, causing active layer SyncTiling to |
1537 // be called. | 1625 // be called. |
1538 float new_scale = 1.f; | 1626 float new_scale = 1.f; |
1539 active_layer_->ReleaseResources(); | 1627 active_layer_->ReleaseResources(); |
(...skipping 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3095 NOTREACHED(); | 3183 NOTREACHED(); |
3096 } | 3184 } |
3097 | 3185 |
3098 tiling_count++; | 3186 tiling_count++; |
3099 } | 3187 } |
3100 | 3188 |
3101 EXPECT_EQ(tiling_count, 5); | 3189 EXPECT_EQ(tiling_count, 5); |
3102 } | 3190 } |
3103 } // namespace | 3191 } // namespace |
3104 } // namespace cc | 3192 } // namespace cc |
OLD | NEW |