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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient); | 94 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient); |
95 }; | 95 }; |
96 | 96 |
97 class MockMailboxCallback { | 97 class MockMailboxCallback { |
98 public: | 98 public: |
99 MOCK_METHOD3(Release, | 99 MOCK_METHOD3(Release, |
100 void(const gpu::Mailbox& mailbox, | 100 void(const gpu::Mailbox& mailbox, |
101 uint32 sync_point, | 101 uint32 sync_point, |
102 bool lost_resource)); | 102 bool lost_resource)); |
103 MOCK_METHOD3(Release2, | 103 MOCK_METHOD3(Release2, |
104 void(base::SharedMemory* shared_memory, | 104 void(SharedBitmap* shared_bitmap, |
105 uint32 sync_point, | 105 uint32 sync_point, |
106 bool lost_resource)); | 106 bool lost_resource)); |
107 MOCK_METHOD4(ReleaseImpl, | 107 MOCK_METHOD4(ReleaseImpl, |
108 void(const gpu::Mailbox& mailbox, | 108 void(const gpu::Mailbox& mailbox, |
109 uint32 sync_point, | 109 uint32 sync_point, |
110 bool lost_resource, | 110 bool lost_resource, |
111 BlockingTaskRunner* main_thread_task_runner)); | 111 BlockingTaskRunner* main_thread_task_runner)); |
112 MOCK_METHOD4(ReleaseImpl2, | 112 MOCK_METHOD4(ReleaseImpl2, |
113 void(base::SharedMemory* shared_memory, | 113 void(SharedBitmap* shared_bitmap, |
114 uint32 sync_point, | 114 uint32 sync_point, |
115 bool lost_resource, | 115 bool lost_resource, |
116 BlockingTaskRunner* main_thread_task_runner)); | 116 BlockingTaskRunner* main_thread_task_runner)); |
117 }; | 117 }; |
118 | 118 |
119 struct CommonMailboxObjects { | 119 struct CommonMailboxObjects { |
120 CommonMailboxObjects() | 120 explicit CommonMailboxObjects(SharedBitmapManager* manager) |
121 : mailbox_name1_(MailboxFromChar('1')), | 121 : mailbox_name1_(MailboxFromChar('1')), |
122 mailbox_name2_(MailboxFromChar('2')), | 122 mailbox_name2_(MailboxFromChar('2')), |
123 sync_point1_(1), | 123 sync_point1_(1), |
124 sync_point2_(2), | 124 sync_point2_(2) { |
125 shared_memory_(new base::SharedMemory) { | |
126 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, | 125 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, |
127 base::Unretained(&mock_callback_), | 126 base::Unretained(&mock_callback_), |
128 mailbox_name1_); | 127 mailbox_name1_); |
129 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, | 128 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, |
130 base::Unretained(&mock_callback_), | 129 base::Unretained(&mock_callback_), |
131 mailbox_name2_); | 130 mailbox_name2_); |
132 release_mailbox1_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl, | 131 release_mailbox1_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl, |
133 base::Unretained(&mock_callback_), | 132 base::Unretained(&mock_callback_), |
134 mailbox_name1_); | 133 mailbox_name1_); |
135 release_mailbox2_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl, | 134 release_mailbox2_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl, |
136 base::Unretained(&mock_callback_), | 135 base::Unretained(&mock_callback_), |
137 mailbox_name2_); | 136 mailbox_name2_); |
138 const uint32 arbitrary_target1 = GL_TEXTURE_2D; | 137 const uint32 arbitrary_target1 = GL_TEXTURE_2D; |
139 const uint32 arbitrary_target2 = GL_TEXTURE_EXTERNAL_OES; | 138 const uint32 arbitrary_target2 = GL_TEXTURE_EXTERNAL_OES; |
140 mailbox1_ = TextureMailbox(mailbox_name1_, arbitrary_target1, sync_point1_); | 139 mailbox1_ = TextureMailbox(mailbox_name1_, arbitrary_target1, sync_point1_); |
141 mailbox2_ = TextureMailbox(mailbox_name2_, arbitrary_target2, sync_point2_); | 140 mailbox2_ = TextureMailbox(mailbox_name2_, arbitrary_target2, sync_point2_); |
142 gfx::Size size(128, 128); | 141 gfx::Size size(128, 128); |
143 EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea())); | 142 shared_bitmap_ = manager->AllocateSharedBitmap(size); |
144 release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2, | 143 DCHECK(shared_bitmap_); |
145 base::Unretained(&mock_callback_), | 144 release_mailbox3_ = |
146 shared_memory_.get()); | 145 base::Bind(&MockMailboxCallback::Release2, |
147 release_mailbox3_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl2, | 146 base::Unretained(&mock_callback_), shared_bitmap_.get()); |
148 base::Unretained(&mock_callback_), | 147 release_mailbox3_impl_ = |
149 shared_memory_.get()); | 148 base::Bind(&MockMailboxCallback::ReleaseImpl2, |
150 mailbox3_ = TextureMailbox(shared_memory_.get(), size); | 149 base::Unretained(&mock_callback_), shared_bitmap_.get()); |
| 150 mailbox3_ = TextureMailbox(shared_bitmap_.get(), size); |
151 } | 151 } |
152 | 152 |
153 gpu::Mailbox mailbox_name1_; | 153 gpu::Mailbox mailbox_name1_; |
154 gpu::Mailbox mailbox_name2_; | 154 gpu::Mailbox mailbox_name2_; |
155 MockMailboxCallback mock_callback_; | 155 MockMailboxCallback mock_callback_; |
156 ReleaseCallback release_mailbox1_; | 156 ReleaseCallback release_mailbox1_; |
157 ReleaseCallback release_mailbox2_; | 157 ReleaseCallback release_mailbox2_; |
158 ReleaseCallback release_mailbox3_; | 158 ReleaseCallback release_mailbox3_; |
159 ReleaseCallbackImpl release_mailbox1_impl_; | 159 ReleaseCallbackImpl release_mailbox1_impl_; |
160 ReleaseCallbackImpl release_mailbox2_impl_; | 160 ReleaseCallbackImpl release_mailbox2_impl_; |
161 ReleaseCallbackImpl release_mailbox3_impl_; | 161 ReleaseCallbackImpl release_mailbox3_impl_; |
162 TextureMailbox mailbox1_; | 162 TextureMailbox mailbox1_; |
163 TextureMailbox mailbox2_; | 163 TextureMailbox mailbox2_; |
164 TextureMailbox mailbox3_; | 164 TextureMailbox mailbox3_; |
165 uint32 sync_point1_; | 165 uint32 sync_point1_; |
166 uint32 sync_point2_; | 166 uint32 sync_point2_; |
167 scoped_ptr<base::SharedMemory> shared_memory_; | 167 scoped_ptr<SharedBitmap> shared_bitmap_; |
168 }; | 168 }; |
169 | 169 |
170 class TextureLayerTest : public testing::Test { | 170 class TextureLayerTest : public testing::Test { |
171 public: | 171 public: |
172 TextureLayerTest() | 172 TextureLayerTest() |
173 : fake_client_( | 173 : fake_client_( |
174 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)), | 174 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)), |
175 host_impl_(&proxy_, &shared_bitmap_manager_) {} | 175 host_impl_(&proxy_, &shared_bitmap_manager_), |
| 176 test_data_(&shared_bitmap_manager_) {} |
176 | 177 |
177 protected: | 178 protected: |
178 virtual void SetUp() { | 179 virtual void SetUp() { |
179 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); | 180 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); |
180 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 181 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
181 layer_tree_host_->SetViewportSize(gfx::Size(10, 10)); | 182 layer_tree_host_->SetViewportSize(gfx::Size(10, 10)); |
182 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 183 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
183 } | 184 } |
184 | 185 |
185 virtual void TearDown() { | 186 virtual void TearDown() { |
186 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 187 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
187 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 188 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
188 | 189 |
189 layer_tree_host_->SetRootLayer(nullptr); | 190 layer_tree_host_->SetRootLayer(nullptr); |
190 layer_tree_host_ = nullptr; | 191 layer_tree_host_ = nullptr; |
191 } | 192 } |
192 | 193 |
193 scoped_ptr<MockLayerTreeHost> layer_tree_host_; | 194 scoped_ptr<MockLayerTreeHost> layer_tree_host_; |
194 FakeImplProxy proxy_; | 195 FakeImplProxy proxy_; |
195 FakeLayerTreeHostClient fake_client_; | 196 FakeLayerTreeHostClient fake_client_; |
196 TestSharedBitmapManager shared_bitmap_manager_; | 197 TestSharedBitmapManager shared_bitmap_manager_; |
197 FakeLayerTreeHostImpl host_impl_; | 198 FakeLayerTreeHostImpl host_impl_; |
| 199 CommonMailboxObjects test_data_; |
198 }; | 200 }; |
199 | 201 |
200 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { | 202 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { |
201 scoped_refptr<TextureLayer> test_layer = | 203 scoped_refptr<TextureLayer> test_layer = |
202 TextureLayer::CreateForMailbox(nullptr); | 204 TextureLayer::CreateForMailbox(nullptr); |
203 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer)); | 205 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer)); |
204 | 206 |
205 // Test properties that should call SetNeedsCommit. All properties need to | 207 // Test properties that should call SetNeedsCommit. All properties need to |
206 // be set to new values in order for SetNeedsCommit to be called. | 208 // be set to new values in order for SetNeedsCommit to be called. |
207 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false)); | 209 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false)); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 class TextureLayerWithMailboxTest : public TextureLayerTest { | 304 class TextureLayerWithMailboxTest : public TextureLayerTest { |
303 protected: | 305 protected: |
304 virtual void TearDown() { | 306 virtual void TearDown() { |
305 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 307 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
306 EXPECT_CALL(test_data_.mock_callback_, | 308 EXPECT_CALL(test_data_.mock_callback_, |
307 Release(test_data_.mailbox_name1_, | 309 Release(test_data_.mailbox_name1_, |
308 test_data_.sync_point1_, | 310 test_data_.sync_point1_, |
309 false)).Times(1); | 311 false)).Times(1); |
310 TextureLayerTest::TearDown(); | 312 TextureLayerTest::TearDown(); |
311 } | 313 } |
312 | |
313 CommonMailboxObjects test_data_; | |
314 }; | 314 }; |
315 | 315 |
316 TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) { | 316 TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) { |
317 scoped_refptr<TextureLayer> test_layer = | 317 scoped_refptr<TextureLayer> test_layer = |
318 TextureLayer::CreateForMailbox(nullptr); | 318 TextureLayer::CreateForMailbox(nullptr); |
319 ASSERT_TRUE(test_layer.get()); | 319 ASSERT_TRUE(test_layer.get()); |
320 | 320 |
321 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 321 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
322 layer_tree_host_->SetRootLayer(test_layer); | 322 layer_tree_host_->SetRootLayer(test_layer); |
323 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 323 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
(...skipping 28 matching lines...) Expand all Loading... |
352 | 352 |
353 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 353 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
354 test_layer->SetTextureMailbox( | 354 test_layer->SetTextureMailbox( |
355 test_data_.mailbox3_, | 355 test_data_.mailbox3_, |
356 SingleReleaseCallback::Create(test_data_.release_mailbox3_)); | 356 SingleReleaseCallback::Create(test_data_.release_mailbox3_)); |
357 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 357 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
358 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 358 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
359 | 359 |
360 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 360 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
361 EXPECT_CALL(test_data_.mock_callback_, | 361 EXPECT_CALL(test_data_.mock_callback_, |
362 Release2(test_data_.shared_memory_.get(), | 362 Release2(test_data_.shared_bitmap_.get(), 0, false)).Times(1); |
363 0, false)) | |
364 .Times(1); | |
365 test_layer->SetTextureMailbox(TextureMailbox(), nullptr); | 363 test_layer->SetTextureMailbox(TextureMailbox(), nullptr); |
366 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 364 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
367 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 365 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
368 | 366 |
369 // Test destructor. | 367 // Test destructor. |
370 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 368 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
371 test_layer->SetTextureMailbox( | 369 test_layer->SetTextureMailbox( |
372 test_data_.mailbox1_, | 370 test_data_.mailbox1_, |
373 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); | 371 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); |
374 } | 372 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 protected: | 443 protected: |
446 void InitializeOnMain() { | 444 void InitializeOnMain() { |
447 main_thread_task_runner_ = | 445 main_thread_task_runner_ = |
448 BlockingTaskRunner::Create(main_thread_.message_loop_proxy()); | 446 BlockingTaskRunner::Create(main_thread_.message_loop_proxy()); |
449 } | 447 } |
450 | 448 |
451 scoped_ptr<TestMailboxHolder::MainThreadReference> | 449 scoped_ptr<TestMailboxHolder::MainThreadReference> |
452 main_ref_; | 450 main_ref_; |
453 base::Thread main_thread_; | 451 base::Thread main_thread_; |
454 scoped_ptr<BlockingTaskRunner> main_thread_task_runner_; | 452 scoped_ptr<BlockingTaskRunner> main_thread_task_runner_; |
455 CommonMailboxObjects test_data_; | |
456 }; | 453 }; |
457 | 454 |
458 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) { | 455 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) { |
459 scoped_refptr<TextureLayer> test_layer = | 456 scoped_refptr<TextureLayer> test_layer = |
460 TextureLayer::CreateForMailbox(nullptr); | 457 TextureLayer::CreateForMailbox(nullptr); |
461 ASSERT_TRUE(test_layer.get()); | 458 ASSERT_TRUE(test_layer.get()); |
462 | 459 |
463 main_thread_.message_loop()->PostTask( | 460 main_thread_.message_loop()->PostTask( |
464 FROM_HERE, | 461 FROM_HERE, |
465 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, | 462 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 } | 936 } |
940 | 937 |
941 bool WillDraw(TextureLayerImpl* layer, DrawMode mode) { | 938 bool WillDraw(TextureLayerImpl* layer, DrawMode mode) { |
942 bool will_draw = layer->WillDraw( | 939 bool will_draw = layer->WillDraw( |
943 mode, host_impl_.active_tree()->resource_provider()); | 940 mode, host_impl_.active_tree()->resource_provider()); |
944 if (will_draw) | 941 if (will_draw) |
945 layer->DidDraw(host_impl_.active_tree()->resource_provider()); | 942 layer->DidDraw(host_impl_.active_tree()->resource_provider()); |
946 return will_draw; | 943 return will_draw; |
947 } | 944 } |
948 | 945 |
949 CommonMailboxObjects test_data_; | |
950 FakeLayerTreeHostClient fake_client_; | 946 FakeLayerTreeHostClient fake_client_; |
951 }; | 947 }; |
952 | 948 |
953 // Test conditions for results of TextureLayerImpl::WillDraw under | 949 // Test conditions for results of TextureLayerImpl::WillDraw under |
954 // different configurations of different mailbox, texture_id, and draw_mode. | 950 // different configurations of different mailbox, texture_id, and draw_mode. |
955 TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) { | 951 TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) { |
956 EXPECT_CALL( | 952 EXPECT_CALL( |
957 test_data_.mock_callback_, | 953 test_data_.mock_callback_, |
958 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_point1_, false, _)) | 954 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_point1_, false, _)) |
959 .Times(AnyNumber()); | 955 .Times(AnyNumber()); |
960 EXPECT_CALL(test_data_.mock_callback_, | 956 EXPECT_CALL(test_data_.mock_callback_, |
961 ReleaseImpl2(test_data_.shared_memory_.get(), 0, false, _)) | 957 ReleaseImpl2(test_data_.shared_bitmap_.get(), 0, false, _)) |
962 .Times(AnyNumber()); | 958 .Times(AnyNumber()); |
963 // Hardware mode. | 959 // Hardware mode. |
964 { | 960 { |
965 scoped_ptr<TextureLayerImpl> impl_layer = | 961 scoped_ptr<TextureLayerImpl> impl_layer = |
966 TextureLayerImpl::Create(host_impl_.active_tree(), 1); | 962 TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
967 impl_layer->SetTextureMailbox( | 963 impl_layer->SetTextureMailbox( |
968 test_data_.mailbox1_, | 964 test_data_.mailbox1_, |
969 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); | 965 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
970 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); | 966 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
971 } | 967 } |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 int callback_count_; | 1558 int callback_count_; |
1563 scoped_refptr<Layer> root_; | 1559 scoped_refptr<Layer> root_; |
1564 scoped_refptr<TextureLayer> layer_; | 1560 scoped_refptr<TextureLayer> layer_; |
1565 }; | 1561 }; |
1566 | 1562 |
1567 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1563 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
1568 TextureLayerWithMailboxImplThreadDeleted); | 1564 TextureLayerWithMailboxImplThreadDeleted); |
1569 | 1565 |
1570 } // namespace | 1566 } // namespace |
1571 } // namespace cc | 1567 } // namespace cc |
OLD | NEW |