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

Side by Side Diff: cc/layers/texture_layer_unittest.cc

Issue 140693015: cc: Free Mailbox on TextureLayerImpl::ReleaseResources (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tests Created 6 years, 11 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/layers/texture_layer_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/texture_layer.h" 5 #include "cc/layers/texture_layer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 1697 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); 1708 EXPECT_EQ(2, layer_tree_host()->source_frame_number());
1709 EndTest(); 1709 EndTest();
1710 } 1710 }
1711 1711
1712 virtual void SetupTree() OVERRIDE { 1712 virtual void SetupTree() OVERRIDE {
1713 scoped_refptr<Layer> root = Layer::Create(); 1713 scoped_refptr<Layer> root = Layer::Create();
1714 root->SetBounds(gfx::Size(10, 10)); 1714 root->SetBounds(gfx::Size(10, 10));
1715 root->SetAnchorPoint(gfx::PointF()); 1715 root->SetAnchorPoint(gfx::PointF());
1716 root->SetIsDrawable(true); 1716 root->SetIsDrawable(true);
1717 1717
1718 solid_layer_ = SolidColorLayer::Create();
1719 solid_layer_->SetBounds(gfx::Size(10, 10));
1720 solid_layer_->SetIsDrawable(true);
1721 solid_layer_->SetBackgroundColor(SK_ColorWHITE);
1722 root->AddChild(solid_layer_);
1723
1724 parent_layer_ = Layer::Create();
1725 parent_layer_->SetBounds(gfx::Size(10, 10));
1726 parent_layer_->SetIsDrawable(true);
1727 root->AddChild(parent_layer_);
1728
1729 texture_layer_ = TextureLayer::CreateForMailbox(this); 1718 texture_layer_ = TextureLayer::CreateForMailbox(this);
1730 texture_layer_->SetBounds(gfx::Size(10, 10)); 1719 texture_layer_->SetBounds(gfx::Size(10, 10));
1731 texture_layer_->SetAnchorPoint(gfx::PointF()); 1720 texture_layer_->SetAnchorPoint(gfx::PointF());
1732 texture_layer_->SetIsDrawable(true); 1721 texture_layer_->SetIsDrawable(true);
1733 parent_layer_->AddChild(texture_layer_); 1722 root->AddChild(texture_layer_);
1734 1723
1735 layer_tree_host()->SetRootLayer(root); 1724 layer_tree_host()->SetRootLayer(root);
1736 LayerTreeTest::SetupTree(); 1725 LayerTreeTest::SetupTree();
1737 } 1726 }
1738 1727
1739 virtual void BeginTest() OVERRIDE { 1728 virtual void BeginTest() OVERRIDE {
1740 PostSetNeedsCommitToMainThread(); 1729 PostSetNeedsCommitToMainThread();
1741 } 1730 }
1742 1731
1743 virtual void DidCommitAndDrawFrame() OVERRIDE { 1732 virtual void DidCommitAndDrawFrame() OVERRIDE {
(...skipping 27 matching lines...) Expand all
1771 CompositorFrameAck ack; 1760 CompositorFrameAck ack;
1772 for (size_t i = 0; i < resources_to_return.size(); ++i) 1761 for (size_t i = 0; i < resources_to_return.size(); ++i)
1773 output_surface()->ReturnResource(resources_to_return[i].id, &ack); 1762 output_surface()->ReturnResource(resources_to_return[i].id, &ack);
1774 host_impl->ReclaimResources(&ack); 1763 host_impl->ReclaimResources(&ack);
1775 host_impl->OnSwapBuffersComplete(); 1764 host_impl->OnSwapBuffersComplete();
1776 } 1765 }
1777 1766
1778 virtual void AfterTest() OVERRIDE {} 1767 virtual void AfterTest() OVERRIDE {}
1779 1768
1780 private: 1769 private:
1781 scoped_refptr<SolidColorLayer> solid_layer_;
1782 scoped_refptr<Layer> parent_layer_;
1783 scoped_refptr<TextureLayer> texture_layer_; 1770 scoped_refptr<TextureLayer> texture_layer_;
1784 }; 1771 };
1785 1772
1786 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerNoExtraCommitForMailboxTest); 1773 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerNoExtraCommitForMailboxTest);
1787 1774
1788 // Checks that changing a mailbox in the client for a TextureLayer that's 1775 // Checks that changing a mailbox in the client for a TextureLayer that's
1789 // invisible correctly works and uses the new mailbox as soon as the layer 1776 // invisible correctly works and uses the new mailbox as soon as the layer
1790 // becomes visible (and returns the old one). 1777 // becomes visible (and returns the old one).
1791 class TextureLayerChangeInvisibleMailboxTest 1778 class TextureLayerChangeInvisibleMailboxTest
1792 : public LayerTreeTest, 1779 : public LayerTreeTest,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 // Used on the main thread. 1919 // Used on the main thread.
1933 bool mailbox_changed_; 1920 bool mailbox_changed_;
1934 TextureMailbox mailbox_; 1921 TextureMailbox mailbox_;
1935 int mailbox_returned_; 1922 int mailbox_returned_;
1936 int prepare_called_; 1923 int prepare_called_;
1937 int commit_count_; 1924 int commit_count_;
1938 }; 1925 };
1939 1926
1940 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest); 1927 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest);
1941 1928
1929 // Test that TextureLayerImpl::ReleaseResources can be called which releases
1930 // the mailbox back to TextureLayerClient.
1931 class TextureLayerReleaseResourcesBase
1932 : public LayerTreeTest,
1933 public TextureLayerClient {
1934 public:
1935 // TextureLayerClient implementation.
1936 virtual unsigned PrepareTexture() OVERRIDE {
1937 NOTREACHED();
1938 return 0;
1939 }
1940 virtual bool PrepareTextureMailbox(
1941 TextureMailbox* mailbox,
1942 scoped_ptr<SingleReleaseCallback>* release_callback,
1943 bool use_shared_memory) OVERRIDE {
1944 *mailbox = TextureMailbox(std::string(64, '1'));
1945 *release_callback = SingleReleaseCallback::Create(
1946 base::Bind(&TextureLayerReleaseResourcesBase::MailboxReleased,
1947 base::Unretained(this)));
1948 return true;
1949 }
1950
1951 void MailboxReleased(unsigned sync_point, bool lost_resource) {
1952 mailbox_released_ = true;
1953 }
1954
1955 virtual void SetupTree() OVERRIDE {
1956 scoped_refptr<TextureLayer> texture_layer =
1957 TextureLayer::CreateForMailbox(this);
1958 texture_layer->SetBounds(gfx::Size(10, 10));
1959 texture_layer->SetAnchorPoint(gfx::PointF());
1960 texture_layer->SetIsDrawable(true);
1961
1962 layer_tree_host()->SetRootLayer(texture_layer);
danakj 2014/01/23 18:06:43 Add this as a child of the root instead of making
boliu 2014/01/23 18:54:10 Done. Of course also had to update the code to get
1963 LayerTreeTest::SetupTree();
1964 }
1965
1966 virtual void BeginTest() OVERRIDE {
1967 mailbox_released_ = false;
1968 PostSetNeedsCommitToMainThread();
1969 }
1970
1971 virtual void DidCommitAndDrawFrame() OVERRIDE {
1972 EndTest();
1973 }
1974
1975 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
danakj 2014/01/23 18:06:43 This belongs only in the subclasses right?
boliu 2014/01/23 18:54:10 Doh! Good catch, removed.
1976 host_impl->active_tree()->root_layer()->ReleaseResources();
1977 }
1978
1979 virtual void AfterTest() OVERRIDE {
1980 EXPECT_TRUE(mailbox_released_);
1981 }
1982
1983 private:
1984 bool mailbox_released_;
1985 };
1986
1987 class TextureLayerReleaseResourcesAfterCommit
1988 : public TextureLayerReleaseResourcesBase {
1989 public:
1990 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1991 LayerTreeImpl* tree = NULL;
1992 if (host_impl->settings().impl_side_painting)
1993 tree = host_impl->pending_tree();
1994 else
1995 tree = host_impl->active_tree();
1996 tree->root_layer()->ReleaseResources();
1997 }
1998 };
1999
2000 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterCommit);
2001
2002 class TextureLayerReleaseResourcesAfterActivate
2003 : public TextureLayerReleaseResourcesBase {
2004 public:
2005 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
2006 host_impl->active_tree()->root_layer()->ReleaseResources();
2007 }
2008 };
2009
2010 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterActivate);
2011
1942 // Test recovering from a lost context. 2012 // Test recovering from a lost context.
1943 class TextureLayerLostContextTest 2013 class TextureLayerLostContextTest
1944 : public LayerTreeTest, 2014 : public LayerTreeTest,
1945 public TextureLayerClient { 2015 public TextureLayerClient {
1946 public: 2016 public:
1947 TextureLayerLostContextTest() 2017 TextureLayerLostContextTest()
1948 : context_lost_(false), 2018 : context_lost_(false),
1949 draw_count_(0) {} 2019 draw_count_(0) {}
1950 2020
1951 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) 2021 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 int callback_count_; 2225 int callback_count_;
2156 scoped_refptr<Layer> root_; 2226 scoped_refptr<Layer> root_;
2157 scoped_refptr<TextureLayer> layer_; 2227 scoped_refptr<TextureLayer> layer_;
2158 }; 2228 };
2159 2229
2160 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 2230 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
2161 TextureLayerWithMailboxImplThreadDeleted); 2231 TextureLayerWithMailboxImplThreadDeleted);
2162 2232
2163 } // namespace 2233 } // namespace
2164 } // namespace cc 2234 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/texture_layer_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698