| 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 23 matching lines...) Expand all Loading... |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 | 35 |
| 36 using ::testing::Mock; | 36 using ::testing::Mock; |
| 37 using ::testing::_; | 37 using ::testing::_; |
| 38 using ::testing::AtLeast; | 38 using ::testing::AtLeast; |
| 39 using ::testing::AnyNumber; | 39 using ::testing::AnyNumber; |
| 40 | 40 |
| 41 namespace cc { | 41 namespace cc { |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 gpu::Mailbox MailboxFromChar(char value) { | 44 gpu::Mailbox MailboxFromString(const std::string& string) { |
| 45 gpu::Mailbox mailbox; | 45 gpu::Mailbox mailbox; |
| 46 memset(mailbox.name, value, sizeof(mailbox.name)); | 46 mailbox.SetName(reinterpret_cast<const int8*>(string.data())); |
| 47 return mailbox; | 47 return mailbox; |
| 48 } | 48 } |
| 49 | 49 |
| 50 class MockLayerTreeHost : public LayerTreeHost { | 50 class MockLayerTreeHost : public LayerTreeHost { |
| 51 public: | 51 public: |
| 52 explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) | 52 explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) |
| 53 : LayerTreeHost(client, NULL, LayerTreeSettings()) { | 53 : LayerTreeHost(client, NULL, LayerTreeSettings()) { |
| 54 InitializeSingleThreaded(client); | 54 InitializeSingleThreaded(client); |
| 55 } | 55 } |
| 56 | 56 |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 315 |
| 316 // Stop rate limiter when we're removed from the tree. | 316 // Stop rate limiter when we're removed from the tree. |
| 317 EXPECT_CALL(*layer_tree_host_, StopRateLimiter()); | 317 EXPECT_CALL(*layer_tree_host_, StopRateLimiter()); |
| 318 layer_tree_host_->SetRootLayer(NULL); | 318 layer_tree_host_->SetRootLayer(NULL); |
| 319 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 319 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 320 } | 320 } |
| 321 | 321 |
| 322 class MockMailboxCallback { | 322 class MockMailboxCallback { |
| 323 public: | 323 public: |
| 324 MOCK_METHOD3(Release, | 324 MOCK_METHOD3(Release, |
| 325 void(const gpu::Mailbox& mailbox, | 325 void(const std::string& mailbox, |
| 326 uint32 sync_point, | 326 uint32 sync_point, |
| 327 bool lost_resource)); | 327 bool lost_resource)); |
| 328 MOCK_METHOD3(Release2, | 328 MOCK_METHOD3(Release2, |
| 329 void(base::SharedMemory* shared_memory, | 329 void(base::SharedMemory* shared_memory, |
| 330 uint32 sync_point, | 330 uint32 sync_point, |
| 331 bool lost_resource)); | 331 bool lost_resource)); |
| 332 }; | 332 }; |
| 333 | 333 |
| 334 struct CommonMailboxObjects { | 334 struct CommonMailboxObjects { |
| 335 CommonMailboxObjects() | 335 CommonMailboxObjects() |
| 336 : mailbox_name1_(MailboxFromChar('1')), | 336 : mailbox_name1_(64, '1'), |
| 337 mailbox_name2_(MailboxFromChar('2')), | 337 mailbox_name2_(64, '2'), |
| 338 sync_point1_(1), | 338 sync_point1_(1), |
| 339 sync_point2_(2), | 339 sync_point2_(2), |
| 340 shared_memory_(new base::SharedMemory) { | 340 shared_memory_(new base::SharedMemory) { |
| 341 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, | 341 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, |
| 342 base::Unretained(&mock_callback_), | 342 base::Unretained(&mock_callback_), |
| 343 mailbox_name1_); | 343 mailbox_name1_); |
| 344 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, | 344 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, |
| 345 base::Unretained(&mock_callback_), | 345 base::Unretained(&mock_callback_), |
| 346 mailbox_name2_); | 346 mailbox_name2_); |
| 347 const uint32 arbitrary_target1 = 1; | 347 const uint32 arbitrary_target1 = 1; |
| 348 const uint32 arbitrary_target2 = 2; | 348 const uint32 arbitrary_target2 = 2; |
| 349 mailbox1_ = TextureMailbox(mailbox_name1_, arbitrary_target1, sync_point1_); | 349 mailbox1_ = TextureMailbox( |
| 350 mailbox2_ = TextureMailbox(mailbox_name2_, arbitrary_target2, sync_point2_); | 350 MailboxFromString(mailbox_name1_), arbitrary_target1, sync_point1_); |
| 351 mailbox2_ = TextureMailbox( |
| 352 MailboxFromString(mailbox_name2_), arbitrary_target2, sync_point2_); |
| 351 gfx::Size size(128, 128); | 353 gfx::Size size(128, 128); |
| 352 EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea())); | 354 EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea())); |
| 353 release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2, | 355 release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2, |
| 354 base::Unretained(&mock_callback_), | 356 base::Unretained(&mock_callback_), |
| 355 shared_memory_.get()); | 357 shared_memory_.get()); |
| 356 mailbox3_ = TextureMailbox(shared_memory_.get(), size); | 358 mailbox3_ = TextureMailbox(shared_memory_.get(), size); |
| 357 } | 359 } |
| 358 | 360 |
| 359 gpu::Mailbox mailbox_name1_; | 361 std::string mailbox_name1_; |
| 360 gpu::Mailbox mailbox_name2_; | 362 std::string mailbox_name2_; |
| 361 MockMailboxCallback mock_callback_; | 363 MockMailboxCallback mock_callback_; |
| 362 ReleaseCallback release_mailbox1_; | 364 ReleaseCallback release_mailbox1_; |
| 363 ReleaseCallback release_mailbox2_; | 365 ReleaseCallback release_mailbox2_; |
| 364 ReleaseCallback release_mailbox3_; | 366 ReleaseCallback release_mailbox3_; |
| 365 TextureMailbox mailbox1_; | 367 TextureMailbox mailbox1_; |
| 366 TextureMailbox mailbox2_; | 368 TextureMailbox mailbox2_; |
| 367 TextureMailbox mailbox3_; | 369 TextureMailbox mailbox3_; |
| 368 uint32 sync_point1_; | 370 uint32 sync_point1_; |
| 369 uint32 sync_point2_; | 371 uint32 sync_point2_; |
| 370 scoped_ptr<base::SharedMemory> shared_memory_; | 372 scoped_ptr<base::SharedMemory> shared_memory_; |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 ++callback_count_; | 767 ++callback_count_; |
| 766 } | 768 } |
| 767 | 769 |
| 768 void SetMailbox(char mailbox_char) { | 770 void SetMailbox(char mailbox_char) { |
| 769 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 771 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 770 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( | 772 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
| 771 base::Bind( | 773 base::Bind( |
| 772 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback, | 774 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback, |
| 773 base::Unretained(this))); | 775 base::Unretained(this))); |
| 774 layer_->SetTextureMailbox( | 776 layer_->SetTextureMailbox( |
| 775 TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), | 777 TextureMailbox( |
| 778 MailboxFromString(std::string(64, mailbox_char)), GL_TEXTURE_2D, 0), |
| 776 callback.Pass()); | 779 callback.Pass()); |
| 777 } | 780 } |
| 778 | 781 |
| 779 virtual void BeginTest() OVERRIDE { | 782 virtual void BeginTest() OVERRIDE { |
| 780 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 783 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 781 | 784 |
| 782 gfx::Size bounds(100, 100); | 785 gfx::Size bounds(100, 100); |
| 783 root_ = Layer::Create(); | 786 root_ = Layer::Create(); |
| 784 root_->SetAnchorPoint(gfx::PointF()); | 787 root_->SetAnchorPoint(gfx::PointF()); |
| 785 root_->SetBounds(bounds); | 788 root_->SetBounds(bounds); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 protected: | 986 protected: |
| 984 TextureLayerMailboxIsActivatedDuringCommit() : activate_count_(0) {} | 987 TextureLayerMailboxIsActivatedDuringCommit() : activate_count_(0) {} |
| 985 | 988 |
| 986 static void ReleaseCallback(uint32 sync_point, bool lost_resource) {} | 989 static void ReleaseCallback(uint32 sync_point, bool lost_resource) {} |
| 987 | 990 |
| 988 void SetMailbox(char mailbox_char) { | 991 void SetMailbox(char mailbox_char) { |
| 989 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( | 992 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
| 990 base::Bind( | 993 base::Bind( |
| 991 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback)); | 994 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback)); |
| 992 layer_->SetTextureMailbox( | 995 layer_->SetTextureMailbox( |
| 993 TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), | 996 TextureMailbox( |
| 997 MailboxFromString(std::string(64, mailbox_char)), GL_TEXTURE_2D, 0), |
| 994 callback.Pass()); | 998 callback.Pass()); |
| 995 } | 999 } |
| 996 | 1000 |
| 997 virtual void BeginTest() OVERRIDE { | 1001 virtual void BeginTest() OVERRIDE { |
| 998 gfx::Size bounds(100, 100); | 1002 gfx::Size bounds(100, 100); |
| 999 root_ = Layer::Create(); | 1003 root_ = Layer::Create(); |
| 1000 root_->SetAnchorPoint(gfx::PointF()); | 1004 root_->SetAnchorPoint(gfx::PointF()); |
| 1001 root_->SetBounds(bounds); | 1005 root_->SetBounds(bounds); |
| 1002 | 1006 |
| 1003 layer_ = TextureLayer::CreateForMailbox(NULL); | 1007 layer_ = TextureLayer::CreateForMailbox(NULL); |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1629 } | 1633 } |
| 1630 virtual bool PrepareTextureMailbox( | 1634 virtual bool PrepareTextureMailbox( |
| 1631 TextureMailbox* texture_mailbox, | 1635 TextureMailbox* texture_mailbox, |
| 1632 scoped_ptr<SingleReleaseCallback>* release_callback, | 1636 scoped_ptr<SingleReleaseCallback>* release_callback, |
| 1633 bool use_shared_memory) OVERRIDE { | 1637 bool use_shared_memory) OVERRIDE { |
| 1634 if (layer_tree_host()->source_frame_number() == 1) { | 1638 if (layer_tree_host()->source_frame_number() == 1) { |
| 1635 *texture_mailbox = TextureMailbox(); | 1639 *texture_mailbox = TextureMailbox(); |
| 1636 return true; | 1640 return true; |
| 1637 } | 1641 } |
| 1638 | 1642 |
| 1639 *texture_mailbox = TextureMailbox(MailboxFromChar('1'), GL_TEXTURE_2D, 0); | 1643 *texture_mailbox = TextureMailbox( |
| 1644 MailboxFromString(std::string(64, '1')), GL_TEXTURE_2D, 0); |
| 1640 *release_callback = SingleReleaseCallback::Create( | 1645 *release_callback = SingleReleaseCallback::Create( |
| 1641 base::Bind(&TextureLayerNoExtraCommitForMailboxTest::MailboxReleased, | 1646 base::Bind(&TextureLayerNoExtraCommitForMailboxTest::MailboxReleased, |
| 1642 base::Unretained(this))); | 1647 base::Unretained(this))); |
| 1643 return true; | 1648 return true; |
| 1644 } | 1649 } |
| 1645 | 1650 |
| 1646 void MailboxReleased(uint32 sync_point, bool lost_resource) { | 1651 void MailboxReleased(uint32 sync_point, bool lost_resource) { |
| 1647 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); | 1652 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); |
| 1648 EndTest(); | 1653 EndTest(); |
| 1649 } | 1654 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1740 if (!mailbox_changed_) | 1745 if (!mailbox_changed_) |
| 1741 return false; | 1746 return false; |
| 1742 *mailbox = mailbox_; | 1747 *mailbox = mailbox_; |
| 1743 *release_callback = SingleReleaseCallback::Create( | 1748 *release_callback = SingleReleaseCallback::Create( |
| 1744 base::Bind(&TextureLayerChangeInvisibleMailboxTest::MailboxReleased, | 1749 base::Bind(&TextureLayerChangeInvisibleMailboxTest::MailboxReleased, |
| 1745 base::Unretained(this))); | 1750 base::Unretained(this))); |
| 1746 return true; | 1751 return true; |
| 1747 } | 1752 } |
| 1748 | 1753 |
| 1749 TextureMailbox MakeMailbox(char name) { | 1754 TextureMailbox MakeMailbox(char name) { |
| 1750 return TextureMailbox(MailboxFromChar(name), GL_TEXTURE_2D, 0); | 1755 return TextureMailbox( |
| 1756 MailboxFromString(std::string(64, name)), GL_TEXTURE_2D, 0); |
| 1751 } | 1757 } |
| 1752 | 1758 |
| 1753 void MailboxReleased(uint32 sync_point, bool lost_resource) { | 1759 void MailboxReleased(uint32 sync_point, bool lost_resource) { |
| 1754 ++mailbox_returned_; | 1760 ++mailbox_returned_; |
| 1755 } | 1761 } |
| 1756 | 1762 |
| 1757 virtual void SetupTree() OVERRIDE { | 1763 virtual void SetupTree() OVERRIDE { |
| 1758 scoped_refptr<Layer> root = Layer::Create(); | 1764 scoped_refptr<Layer> root = Layer::Create(); |
| 1759 root->SetBounds(gfx::Size(10, 10)); | 1765 root->SetBounds(gfx::Size(10, 10)); |
| 1760 root->SetAnchorPoint(gfx::PointF()); | 1766 root->SetAnchorPoint(gfx::PointF()); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1873 public: | 1879 public: |
| 1874 // TextureLayerClient implementation. | 1880 // TextureLayerClient implementation. |
| 1875 virtual unsigned PrepareTexture() OVERRIDE { | 1881 virtual unsigned PrepareTexture() OVERRIDE { |
| 1876 NOTREACHED(); | 1882 NOTREACHED(); |
| 1877 return 0; | 1883 return 0; |
| 1878 } | 1884 } |
| 1879 virtual bool PrepareTextureMailbox( | 1885 virtual bool PrepareTextureMailbox( |
| 1880 TextureMailbox* mailbox, | 1886 TextureMailbox* mailbox, |
| 1881 scoped_ptr<SingleReleaseCallback>* release_callback, | 1887 scoped_ptr<SingleReleaseCallback>* release_callback, |
| 1882 bool use_shared_memory) OVERRIDE { | 1888 bool use_shared_memory) OVERRIDE { |
| 1883 *mailbox = TextureMailbox(MailboxFromChar('1'), GL_TEXTURE_2D, 0); | 1889 *mailbox = TextureMailbox( |
| 1890 MailboxFromString(std::string(64, '1')), GL_TEXTURE_2D, 0); |
| 1884 *release_callback = SingleReleaseCallback::Create( | 1891 *release_callback = SingleReleaseCallback::Create( |
| 1885 base::Bind(&TextureLayerReleaseResourcesBase::MailboxReleased, | 1892 base::Bind(&TextureLayerReleaseResourcesBase::MailboxReleased, |
| 1886 base::Unretained(this))); | 1893 base::Unretained(this))); |
| 1887 return true; | 1894 return true; |
| 1888 } | 1895 } |
| 1889 | 1896 |
| 1890 void MailboxReleased(unsigned sync_point, bool lost_resource) { | 1897 void MailboxReleased(unsigned sync_point, bool lost_resource) { |
| 1891 mailbox_released_ = true; | 1898 mailbox_released_ = true; |
| 1892 } | 1899 } |
| 1893 | 1900 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2029 EndTest(); | 2036 EndTest(); |
| 2030 } | 2037 } |
| 2031 | 2038 |
| 2032 void SetMailbox(char mailbox_char) { | 2039 void SetMailbox(char mailbox_char) { |
| 2033 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 2040 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 2034 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( | 2041 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
| 2035 base::Bind( | 2042 base::Bind( |
| 2036 &TextureLayerWithMailboxMainThreadDeleted::ReleaseCallback, | 2043 &TextureLayerWithMailboxMainThreadDeleted::ReleaseCallback, |
| 2037 base::Unretained(this))); | 2044 base::Unretained(this))); |
| 2038 layer_->SetTextureMailbox( | 2045 layer_->SetTextureMailbox( |
| 2039 TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), | 2046 TextureMailbox( |
| 2047 MailboxFromString(std::string(64, mailbox_char)), GL_TEXTURE_2D, 0), |
| 2040 callback.Pass()); | 2048 callback.Pass()); |
| 2041 } | 2049 } |
| 2042 | 2050 |
| 2043 virtual void SetupTree() OVERRIDE { | 2051 virtual void SetupTree() OVERRIDE { |
| 2044 gfx::Size bounds(100, 100); | 2052 gfx::Size bounds(100, 100); |
| 2045 root_ = Layer::Create(); | 2053 root_ = Layer::Create(); |
| 2046 root_->SetAnchorPoint(gfx::PointF()); | 2054 root_->SetAnchorPoint(gfx::PointF()); |
| 2047 root_->SetBounds(bounds); | 2055 root_->SetBounds(bounds); |
| 2048 | 2056 |
| 2049 layer_ = TextureLayer::CreateForMailbox(NULL); | 2057 layer_ = TextureLayer::CreateForMailbox(NULL); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2102 EndTest(); | 2110 EndTest(); |
| 2103 } | 2111 } |
| 2104 | 2112 |
| 2105 void SetMailbox(char mailbox_char) { | 2113 void SetMailbox(char mailbox_char) { |
| 2106 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 2114 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 2107 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( | 2115 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
| 2108 base::Bind( | 2116 base::Bind( |
| 2109 &TextureLayerWithMailboxImplThreadDeleted::ReleaseCallback, | 2117 &TextureLayerWithMailboxImplThreadDeleted::ReleaseCallback, |
| 2110 base::Unretained(this))); | 2118 base::Unretained(this))); |
| 2111 layer_->SetTextureMailbox( | 2119 layer_->SetTextureMailbox( |
| 2112 TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), | 2120 TextureMailbox( |
| 2121 MailboxFromString(std::string(64, mailbox_char)), GL_TEXTURE_2D, 0), |
| 2113 callback.Pass()); | 2122 callback.Pass()); |
| 2114 } | 2123 } |
| 2115 | 2124 |
| 2116 virtual void SetupTree() OVERRIDE { | 2125 virtual void SetupTree() OVERRIDE { |
| 2117 gfx::Size bounds(100, 100); | 2126 gfx::Size bounds(100, 100); |
| 2118 root_ = Layer::Create(); | 2127 root_ = Layer::Create(); |
| 2119 root_->SetAnchorPoint(gfx::PointF()); | 2128 root_->SetAnchorPoint(gfx::PointF()); |
| 2120 root_->SetBounds(bounds); | 2129 root_->SetBounds(bounds); |
| 2121 | 2130 |
| 2122 layer_ = TextureLayer::CreateForMailbox(NULL); | 2131 layer_ = TextureLayer::CreateForMailbox(NULL); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2164 int callback_count_; | 2173 int callback_count_; |
| 2165 scoped_refptr<Layer> root_; | 2174 scoped_refptr<Layer> root_; |
| 2166 scoped_refptr<TextureLayer> layer_; | 2175 scoped_refptr<TextureLayer> layer_; |
| 2167 }; | 2176 }; |
| 2168 | 2177 |
| 2169 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 2178 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 2170 TextureLayerWithMailboxImplThreadDeleted); | 2179 TextureLayerWithMailboxImplThreadDeleted); |
| 2171 | 2180 |
| 2172 } // namespace | 2181 } // namespace |
| 2173 } // namespace cc | 2182 } // namespace cc |
| OLD | NEW |