Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: cc/trees/layer_tree_host_unittest_delegated.cc

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

Powered by Google App Engine
This is Rietveld 408576698