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 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1485 host_impl_.ActivateSyncTree(); | 1485 host_impl_.ActivateSyncTree(); |
1486 | 1486 |
1487 active_layer_ = static_cast<FakePictureLayerImpl*>( | 1487 active_layer_ = static_cast<FakePictureLayerImpl*>( |
1488 host_impl_.active_tree()->LayerById(id_)); | 1488 host_impl_.active_tree()->LayerById(id_)); |
1489 | 1489 |
1490 EXPECT_EQ(0u, active_layer_->num_tilings()); | 1490 EXPECT_EQ(0u, active_layer_->num_tilings()); |
1491 EXPECT_EQ(raster_page_scale, active_layer_->raster_page_scale()); | 1491 EXPECT_EQ(raster_page_scale, active_layer_->raster_page_scale()); |
1492 EXPECT_FALSE(active_layer_->needs_post_commit_initialization()); | 1492 EXPECT_FALSE(active_layer_->needs_post_commit_initialization()); |
1493 } | 1493 } |
1494 | 1494 |
1495 TEST_F(PictureLayerImplTest, RemoveInvalidTilesOnActivation) { | 1495 TEST_F(PictureLayerImplTest, ShareTilesOnSync) { |
1496 SetupDefaultTrees(gfx::Size(1500, 1500)); | 1496 SetupDefaultTrees(gfx::Size(1500, 1500)); |
1497 AddDefaultTilingsWithInvalidation(gfx::Rect(0, 0, 1, 1)); | 1497 AddDefaultTilingsWithInvalidation(gfx::Rect()); |
1498 | 1498 |
1499 FakePictureLayerImpl* recycled_layer = pending_layer_; | |
1500 host_impl_.ActivateSyncTree(); | 1499 host_impl_.ActivateSyncTree(); |
1501 | 1500 host_impl_.CreatePendingTree(); |
1502 active_layer_ = static_cast<FakePictureLayerImpl*>( | 1501 active_layer_ = static_cast<FakePictureLayerImpl*>( |
1503 host_impl_.active_tree()->LayerById(id_)); | 1502 host_impl_.active_tree()->LayerById(id_)); |
1504 | 1503 |
| 1504 // Force the active tree to sync to the pending tree "post-commit". |
| 1505 pending_layer_->DoPostCommitInitializationIfNeeded(); |
| 1506 |
| 1507 // Both invalidations should drop tiles from the pending tree. |
1505 EXPECT_EQ(3u, active_layer_->num_tilings()); | 1508 EXPECT_EQ(3u, active_layer_->num_tilings()); |
1506 EXPECT_EQ(3u, recycled_layer->num_tilings()); | 1509 EXPECT_EQ(3u, pending_layer_->num_tilings()); |
1507 EXPECT_FALSE(host_impl_.pending_tree()); | |
1508 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { | 1510 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { |
1509 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(i); | 1511 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(i); |
1510 PictureLayerTiling* recycled_tiling = | 1512 PictureLayerTiling* pending_tiling = |
1511 recycled_layer->tilings()->tiling_at(i); | 1513 pending_layer_->tilings()->tiling_at(i); |
1512 | 1514 |
1513 ASSERT_TRUE(active_tiling); | 1515 ASSERT_TRUE(active_tiling); |
1514 ASSERT_TRUE(recycled_tiling); | 1516 ASSERT_TRUE(pending_tiling); |
1515 | 1517 |
1516 EXPECT_TRUE(active_tiling->TileAt(0, 0)); | 1518 EXPECT_TRUE(active_tiling->TileAt(0, 0)); |
1517 EXPECT_TRUE(active_tiling->TileAt(1, 0)); | 1519 EXPECT_TRUE(active_tiling->TileAt(1, 0)); |
1518 EXPECT_TRUE(active_tiling->TileAt(0, 1)); | 1520 EXPECT_TRUE(active_tiling->TileAt(0, 1)); |
1519 EXPECT_TRUE(active_tiling->TileAt(1, 1)); | 1521 EXPECT_TRUE(active_tiling->TileAt(1, 1)); |
1520 | 1522 |
1521 EXPECT_FALSE(recycled_tiling->TileAt(0, 0)); | 1523 EXPECT_TRUE(pending_tiling->TileAt(0, 0)); |
1522 EXPECT_TRUE(recycled_tiling->TileAt(1, 0)); | 1524 EXPECT_TRUE(pending_tiling->TileAt(1, 0)); |
1523 EXPECT_TRUE(recycled_tiling->TileAt(0, 1)); | 1525 EXPECT_TRUE(pending_tiling->TileAt(0, 1)); |
1524 EXPECT_TRUE(recycled_tiling->TileAt(1, 1)); | 1526 EXPECT_TRUE(pending_tiling->TileAt(1, 1)); |
1525 | 1527 |
1526 EXPECT_EQ(active_tiling->TileAt(1, 0), recycled_tiling->TileAt(1, 0)); | 1528 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0)); |
1527 EXPECT_EQ(active_tiling->TileAt(0, 1), recycled_tiling->TileAt(0, 1)); | 1529 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0)); |
1528 EXPECT_EQ(active_tiling->TileAt(1, 1), recycled_tiling->TileAt(1, 1)); | 1530 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1)); |
| 1531 EXPECT_EQ(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1)); |
1529 } | 1532 } |
1530 } | 1533 } |
1531 | 1534 |
| 1535 TEST_F(PictureLayerImplTest, RemoveInvalidActiveTreeTilesOnSync) { |
| 1536 SetupDefaultTrees(gfx::Size(1500, 1500)); |
| 1537 AddDefaultTilingsWithInvalidation(gfx::Rect(0, 0, 1, 1)); |
| 1538 |
| 1539 // This activates the 0,0,1,1 invalidation. |
| 1540 host_impl_.ActivateSyncTree(); |
| 1541 host_impl_.CreatePendingTree(); |
| 1542 active_layer_ = static_cast<FakePictureLayerImpl*>( |
| 1543 host_impl_.active_tree()->LayerById(id_)); |
| 1544 |
| 1545 // Force the active tree to sync to the pending tree "post-commit". |
| 1546 pending_layer_->DoPostCommitInitializationIfNeeded(); |
| 1547 |
| 1548 // Both invalidations should drop tiles from the pending tree. |
| 1549 EXPECT_EQ(3u, active_layer_->num_tilings()); |
| 1550 EXPECT_EQ(3u, pending_layer_->num_tilings()); |
| 1551 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { |
| 1552 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(i); |
| 1553 PictureLayerTiling* pending_tiling = |
| 1554 pending_layer_->tilings()->tiling_at(i); |
| 1555 |
| 1556 ASSERT_TRUE(active_tiling); |
| 1557 ASSERT_TRUE(pending_tiling); |
| 1558 |
| 1559 EXPECT_TRUE(active_tiling->TileAt(0, 0)); |
| 1560 EXPECT_TRUE(active_tiling->TileAt(1, 0)); |
| 1561 EXPECT_TRUE(active_tiling->TileAt(0, 1)); |
| 1562 EXPECT_TRUE(active_tiling->TileAt(1, 1)); |
| 1563 |
| 1564 EXPECT_TRUE(pending_tiling->TileAt(0, 0)); |
| 1565 EXPECT_TRUE(pending_tiling->TileAt(1, 0)); |
| 1566 EXPECT_TRUE(pending_tiling->TileAt(0, 1)); |
| 1567 EXPECT_TRUE(pending_tiling->TileAt(1, 1)); |
| 1568 |
| 1569 EXPECT_NE(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0)); |
| 1570 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0)); |
| 1571 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1)); |
| 1572 EXPECT_EQ(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1)); |
| 1573 } |
| 1574 } |
| 1575 |
| 1576 TEST_F(PictureLayerImplTest, RemoveInvalidPendingTreeTilesOnSync) { |
| 1577 SetupDefaultTrees(gfx::Size(1500, 1500)); |
| 1578 AddDefaultTilingsWithInvalidation(gfx::Rect()); |
| 1579 |
| 1580 host_impl_.ActivateSyncTree(); |
| 1581 host_impl_.CreatePendingTree(); |
| 1582 active_layer_ = static_cast<FakePictureLayerImpl*>( |
| 1583 host_impl_.active_tree()->LayerById(id_)); |
| 1584 |
| 1585 // Set some invalidation on the pending tree "during commit". We should |
| 1586 // replace raster tiles that touch this. |
| 1587 pending_layer_->set_invalidation(gfx::Rect(1, 1)); |
| 1588 |
| 1589 // Force the active tree to sync to the pending tree "post-commit". |
| 1590 pending_layer_->DoPostCommitInitializationIfNeeded(); |
| 1591 |
| 1592 // Both invalidations should drop tiles from the pending tree. |
| 1593 EXPECT_EQ(3u, active_layer_->num_tilings()); |
| 1594 EXPECT_EQ(3u, pending_layer_->num_tilings()); |
| 1595 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { |
| 1596 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(i); |
| 1597 PictureLayerTiling* pending_tiling = |
| 1598 pending_layer_->tilings()->tiling_at(i); |
| 1599 |
| 1600 ASSERT_TRUE(active_tiling); |
| 1601 ASSERT_TRUE(pending_tiling); |
| 1602 |
| 1603 EXPECT_TRUE(active_tiling->TileAt(0, 0)); |
| 1604 EXPECT_TRUE(active_tiling->TileAt(1, 0)); |
| 1605 EXPECT_TRUE(active_tiling->TileAt(0, 1)); |
| 1606 EXPECT_TRUE(active_tiling->TileAt(1, 1)); |
| 1607 |
| 1608 EXPECT_TRUE(pending_tiling->TileAt(0, 0)); |
| 1609 EXPECT_TRUE(pending_tiling->TileAt(1, 0)); |
| 1610 EXPECT_TRUE(pending_tiling->TileAt(0, 1)); |
| 1611 EXPECT_TRUE(pending_tiling->TileAt(1, 1)); |
| 1612 |
| 1613 EXPECT_NE(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0)); |
| 1614 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0)); |
| 1615 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1)); |
| 1616 EXPECT_EQ(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1)); |
| 1617 } |
| 1618 } |
| 1619 |
1532 TEST_F(PictureLayerImplTest, SyncTilingAfterReleaseResource) { | 1620 TEST_F(PictureLayerImplTest, SyncTilingAfterReleaseResource) { |
1533 SetupDefaultTrees(gfx::Size(10, 10)); | 1621 SetupDefaultTrees(gfx::Size(10, 10)); |
1534 host_impl_.active_tree()->UpdateDrawProperties(); | 1622 host_impl_.active_tree()->UpdateDrawProperties(); |
1535 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties()); | 1623 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties()); |
1536 | 1624 |
1537 // Contrived unit test of a real crash. A layer is transparent during a | 1625 // Contrived unit test of a real crash. A layer is transparent during a |
1538 // context loss, and later becomes opaque, causing active layer SyncTiling to | 1626 // context loss, and later becomes opaque, causing active layer SyncTiling to |
1539 // be called. | 1627 // be called. |
1540 float new_scale = 1.f; | 1628 float new_scale = 1.f; |
1541 active_layer_->ReleaseResources(); | 1629 active_layer_->ReleaseResources(); |
(...skipping 1661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3203 // Unshared tiles are occluded on the active tree iff they lie beneath | 3291 // Unshared tiles are occluded on the active tree iff they lie beneath |
3204 // the occluding layer. | 3292 // the occluding layer. |
3205 EXPECT_EQ(tile->is_occluded(ACTIVE_TREE), | 3293 EXPECT_EQ(tile->is_occluded(ACTIVE_TREE), |
3206 scaled_content_rect.x() >= occluding_layer_position.x()); | 3294 scaled_content_rect.x() >= occluding_layer_position.x()); |
3207 } | 3295 } |
3208 } | 3296 } |
3209 } | 3297 } |
3210 } | 3298 } |
3211 } // namespace | 3299 } // namespace |
3212 } // namespace cc | 3300 } // namespace cc |
OLD | NEW |