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

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: blockcommit: fix flake 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
« no previous file with comments | « cc/trees/layer_tree_host.cc ('k') | cc/trees/proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
12 #include "base/time/time.h"
10 #include "cc/layers/delegated_renderer_layer.h" 13 #include "cc/layers/delegated_renderer_layer.h"
11 #include "cc/layers/delegated_renderer_layer_client.h" 14 #include "cc/layers/delegated_renderer_layer_client.h"
12 #include "cc/layers/delegated_renderer_layer_impl.h" 15 #include "cc/layers/delegated_renderer_layer_impl.h"
13 #include "cc/output/compositor_frame.h" 16 #include "cc/output/compositor_frame.h"
14 #include "cc/output/compositor_frame_ack.h" 17 #include "cc/output/compositor_frame_ack.h"
15 #include "cc/output/delegated_frame_data.h" 18 #include "cc/output/delegated_frame_data.h"
16 #include "cc/quads/shared_quad_state.h" 19 #include "cc/quads/shared_quad_state.h"
17 #include "cc/quads/texture_draw_quad.h" 20 #include "cc/quads/texture_draw_quad.h"
18 #include "cc/resources/returned_resource.h" 21 #include "cc/resources/returned_resource.h"
19 #include "cc/test/fake_delegated_renderer_layer.h" 22 #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)); 1578 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
1576 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); 1579 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
1577 } 1580 }
1578 } 1581 }
1579 1582
1580 virtual void AfterTest() OVERRIDE {} 1583 virtual void AfterTest() OVERRIDE {}
1581 }; 1584 };
1582 1585
1583 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake); 1586 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake);
1584 1587
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 base::AutoLock lock(activate_lock_);
1620 ++activate_count_;
1621 }
1622
1623 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1624 // The main thread is awake now, and will run DidCommit() immediately.
1625 // Run DidActivate() afterwards by posting it now.
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 case 3:
1656 EndTest();
1657 break;
1658 }
1659 }
1660
1661 virtual void DidCommit() OVERRIDE {
1662 switch (layer_tree_host()->source_frame_number()) {
1663 case 2: {
1664 // The activate for the 2nd frame should have happened before now.
1665 base::AutoLock lock(activate_lock_);
1666 EXPECT_EQ(2, activate_count_);
1667 break;
1668 }
1669 case 3: {
1670 // The activate to remove the layer should have happened before now.
1671 base::AutoLock lock(activate_lock_);
1672 EXPECT_EQ(3, activate_count_);
1673 break;
1674 }
1675 }
1676 }
1677
1678
1679 virtual void AfterTest() OVERRIDE {}
1680
1681 base::Thread wait_thread_;
1682 base::WaitableEvent wait_event_;
1683 base::Lock activate_lock_;
1684 int activate_count_;
1685 };
1686
1687 SINGLE_AND_MULTI_THREAD_TEST_F(
1688 DelegatedFrameIsActivatedDuringCommit);
1689
1585 } // namespace 1690 } // namespace
1586 } // namespace cc 1691 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host.cc ('k') | cc/trees/proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698