| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 LayerTreeTest::SetupTree(); |
| 1957 |
| 1958 scoped_refptr<TextureLayer> texture_layer = |
| 1959 TextureLayer::CreateForMailbox(this); |
| 1960 texture_layer->SetBounds(gfx::Size(10, 10)); |
| 1961 texture_layer->SetAnchorPoint(gfx::PointF()); |
| 1962 texture_layer->SetIsDrawable(true); |
| 1963 |
| 1964 layer_tree_host()->root_layer()->AddChild(texture_layer); |
| 1965 } |
| 1966 |
| 1967 virtual void BeginTest() OVERRIDE { |
| 1968 mailbox_released_ = false; |
| 1969 PostSetNeedsCommitToMainThread(); |
| 1970 } |
| 1971 |
| 1972 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1973 EndTest(); |
| 1974 } |
| 1975 |
| 1976 virtual void AfterTest() OVERRIDE { |
| 1977 EXPECT_TRUE(mailbox_released_); |
| 1978 } |
| 1979 |
| 1980 private: |
| 1981 bool mailbox_released_; |
| 1982 }; |
| 1983 |
| 1984 class TextureLayerReleaseResourcesAfterCommit |
| 1985 : public TextureLayerReleaseResourcesBase { |
| 1986 public: |
| 1987 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 1988 LayerTreeImpl* tree = NULL; |
| 1989 if (host_impl->settings().impl_side_painting) |
| 1990 tree = host_impl->pending_tree(); |
| 1991 else |
| 1992 tree = host_impl->active_tree(); |
| 1993 tree->root_layer()->children()[0]->ReleaseResources(); |
| 1994 } |
| 1995 }; |
| 1996 |
| 1997 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterCommit); |
| 1998 |
| 1999 class TextureLayerReleaseResourcesAfterActivate |
| 2000 : public TextureLayerReleaseResourcesBase { |
| 2001 public: |
| 2002 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 2003 host_impl->active_tree()->root_layer()->children()[0]->ReleaseResources(); |
| 2004 } |
| 2005 }; |
| 2006 |
| 2007 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterActivate); |
| 2008 |
| 1942 // Test recovering from a lost context. | 2009 // Test recovering from a lost context. |
| 1943 class TextureLayerLostContextTest | 2010 class TextureLayerLostContextTest |
| 1944 : public LayerTreeTest, | 2011 : public LayerTreeTest, |
| 1945 public TextureLayerClient { | 2012 public TextureLayerClient { |
| 1946 public: | 2013 public: |
| 1947 TextureLayerLostContextTest() | 2014 TextureLayerLostContextTest() |
| 1948 : context_lost_(false), | 2015 : context_lost_(false), |
| 1949 draw_count_(0) {} | 2016 draw_count_(0) {} |
| 1950 | 2017 |
| 1951 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) | 2018 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2155 int callback_count_; | 2222 int callback_count_; |
| 2156 scoped_refptr<Layer> root_; | 2223 scoped_refptr<Layer> root_; |
| 2157 scoped_refptr<TextureLayer> layer_; | 2224 scoped_refptr<TextureLayer> layer_; |
| 2158 }; | 2225 }; |
| 2159 | 2226 |
| 2160 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 2227 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 2161 TextureLayerWithMailboxImplThreadDeleted); | 2228 TextureLayerWithMailboxImplThreadDeleted); |
| 2162 | 2229 |
| 2163 } // namespace | 2230 } // namespace |
| 2164 } // namespace cc | 2231 } // namespace cc |
| OLD | NEW |