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