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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/synchronization/waitable_event.h" | |
11 #include "base/threading/thread.h" | |
12 #include "base/time/time.h" | |
13 #include "cc/layers/delegated_renderer_layer.h" | 10 #include "cc/layers/delegated_renderer_layer.h" |
14 #include "cc/layers/delegated_renderer_layer_client.h" | 11 #include "cc/layers/delegated_renderer_layer_client.h" |
15 #include "cc/layers/delegated_renderer_layer_impl.h" | 12 #include "cc/layers/delegated_renderer_layer_impl.h" |
16 #include "cc/output/compositor_frame.h" | 13 #include "cc/output/compositor_frame.h" |
17 #include "cc/output/compositor_frame_ack.h" | 14 #include "cc/output/compositor_frame_ack.h" |
18 #include "cc/output/delegated_frame_data.h" | 15 #include "cc/output/delegated_frame_data.h" |
19 #include "cc/quads/shared_quad_state.h" | 16 #include "cc/quads/shared_quad_state.h" |
20 #include "cc/quads/texture_draw_quad.h" | 17 #include "cc/quads/texture_draw_quad.h" |
21 #include "cc/resources/returned_resource.h" | 18 #include "cc/resources/returned_resource.h" |
22 #include "cc/test/fake_delegated_renderer_layer.h" | 19 #include "cc/test/fake_delegated_renderer_layer.h" |
(...skipping 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1578 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | 1575 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); |
1579 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | 1576 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); |
1580 } | 1577 } |
1581 } | 1578 } |
1582 | 1579 |
1583 virtual void AfterTest() OVERRIDE {} | 1580 virtual void AfterTest() OVERRIDE {} |
1584 }; | 1581 }; |
1585 | 1582 |
1586 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake); | 1583 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake); |
1587 | 1584 |
1588 class DelegatedFrameIsActivatedDuringCommit | |
1589 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | |
1590 protected: | |
1591 DelegatedFrameIsActivatedDuringCommit() | |
1592 : wait_thread_("WAIT"), | |
1593 wait_event_(false, false) { | |
1594 wait_thread_.Start(); | |
1595 } | |
1596 | |
1597 virtual void BeginTest() OVERRIDE { | |
1598 activate_count_ = 0; | |
1599 | |
1600 scoped_ptr<DelegatedFrameData> frame = | |
1601 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | |
1602 AddTextureQuad(frame.get(), 999); | |
1603 AddTransferableResource(frame.get(), 999); | |
1604 delegated_->SetFrameData(frame.Pass()); | |
1605 | |
1606 PostSetNeedsCommitToMainThread(); | |
1607 } | |
1608 | |
1609 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
1610 // Slow down activation so the main thread DidCommit() will run if | |
1611 // not blocked. | |
1612 wait_thread_.message_loop()->PostDelayedTask( | |
1613 FROM_HERE, | |
1614 base::Bind(&base::WaitableEvent::Signal, | |
1615 base::Unretained(&wait_event_)), | |
1616 base::TimeDelta::FromMilliseconds(10)); | |
1617 wait_event_.Wait(); | |
1618 } | |
1619 | |
1620 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
1621 { | |
1622 base::AutoLock lock(activate_lock_); | |
1623 ++activate_count_; | |
1624 } | |
1625 | |
1626 proxy()->MainThreadTaskRunner()->PostTask( | |
1627 FROM_HERE, | |
1628 base::Bind(&DelegatedFrameIsActivatedDuringCommit::DidActivate, | |
1629 base::Unretained(this))); | |
1630 } | |
1631 | |
1632 void DidActivate() { | |
1633 base::AutoLock lock(activate_lock_); | |
1634 switch (activate_count_) { | |
1635 case 1: { | |
1636 // The first frame has been activated. Set a new frame, and | |
1637 // expect the next commit to finish *after* it is activated. | |
1638 scoped_ptr<DelegatedFrameData> frame = | |
1639 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | |
1640 AddTextureQuad(frame.get(), 555); | |
1641 AddTransferableResource(frame.get(), 555); | |
1642 delegated_->SetFrameData(frame.Pass()); | |
1643 // So this commit number should complete after the second activate. | |
1644 EXPECT_EQ(1, layer_tree_host()->source_frame_number()); | |
1645 break; | |
1646 } | |
1647 case 2: | |
1648 // The second frame has been activated. Remove the layer from | |
1649 // the tree to cause another commit/activation. The commit should | |
1650 // finish *after* the layer is removed from the active tree. | |
1651 delegated_->RemoveFromParent(); | |
1652 // So this commit number should complete after the third activate. | |
1653 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); | |
1654 break; | |
1655 } | |
1656 } | |
1657 | |
1658 virtual void DidCommit() OVERRIDE { | |
1659 switch (layer_tree_host()->source_frame_number()) { | |
1660 case 2: { | |
1661 // The activate for the 2nd frame should have happened before now. | |
1662 base::AutoLock lock(activate_lock_); | |
1663 EXPECT_EQ(2, activate_count_); | |
1664 break; | |
1665 } | |
1666 case 3: { | |
1667 // The activate to remove the layer should have happened before now. | |
1668 base::AutoLock lock(activate_lock_); | |
1669 EXPECT_EQ(3, activate_count_); | |
1670 | |
1671 EndTest(); | |
1672 break; | |
1673 } | |
1674 } | |
1675 } | |
1676 | |
1677 | |
1678 virtual void AfterTest() OVERRIDE {} | |
1679 | |
1680 base::Thread wait_thread_; | |
1681 base::WaitableEvent wait_event_; | |
1682 base::Lock activate_lock_; | |
1683 int activate_count_; | |
1684 }; | |
1685 | |
1686 SINGLE_AND_MULTI_THREAD_TEST_F( | |
1687 DelegatedFrameIsActivatedDuringCommit); | |
1688 | |
1689 } // namespace | 1585 } // namespace |
1690 } // namespace cc | 1586 } // namespace cc |
OLD | NEW |