| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "cc/base/thread.h" | 10 #include "cc/base/thread.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 198 |
| 199 // Calling SetTextureId can call AcquireLayerTextures. | 199 // Calling SetTextureId can call AcquireLayerTextures. |
| 200 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); | 200 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); |
| 201 } | 201 } |
| 202 | 202 |
| 203 class MockMailboxCallback { | 203 class MockMailboxCallback { |
| 204 public: | 204 public: |
| 205 MOCK_METHOD3(Release, void(const std::string& mailbox, | 205 MOCK_METHOD3(Release, void(const std::string& mailbox, |
| 206 unsigned sync_point, | 206 unsigned sync_point, |
| 207 bool lost_resource)); | 207 bool lost_resource)); |
| 208 MOCK_METHOD3(Release2, void(base::SharedMemory* shared_memory, |
| 209 unsigned sync_point, |
| 210 bool lost_resource)); |
| 208 }; | 211 }; |
| 209 | 212 |
| 210 struct CommonMailboxObjects { | 213 struct CommonMailboxObjects { |
| 211 CommonMailboxObjects() | 214 CommonMailboxObjects() |
| 212 : mailbox_name1_(64, '1'), | 215 : mailbox_name1_(64, '1'), |
| 213 mailbox_name2_(64, '2'), | 216 mailbox_name2_(64, '2'), |
| 214 sync_point1_(1), | 217 sync_point1_(1), |
| 215 sync_point2_(2) { | 218 sync_point2_(2), |
| 219 shared_memory_(new base::SharedMemory) { |
| 216 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, | 220 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, |
| 217 base::Unretained(&mock_callback_), | 221 base::Unretained(&mock_callback_), |
| 218 mailbox_name1_); | 222 mailbox_name1_); |
| 219 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, | 223 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, |
| 220 base::Unretained(&mock_callback_), | 224 base::Unretained(&mock_callback_), |
| 221 mailbox_name2_); | 225 mailbox_name2_); |
| 222 gpu::Mailbox m1; | 226 gpu::Mailbox m1; |
| 223 m1.SetName(reinterpret_cast<const int8*>(mailbox_name1_.data())); | 227 m1.SetName(reinterpret_cast<const int8*>(mailbox_name1_.data())); |
| 224 mailbox1_ = TextureMailbox(m1, release_mailbox1_, sync_point1_); | 228 mailbox1_ = TextureMailbox(m1, release_mailbox1_, sync_point1_); |
| 225 gpu::Mailbox m2; | 229 gpu::Mailbox m2; |
| 226 m2.SetName(reinterpret_cast<const int8*>(mailbox_name2_.data())); | 230 m2.SetName(reinterpret_cast<const int8*>(mailbox_name2_.data())); |
| 227 mailbox2_ = TextureMailbox(m2, release_mailbox2_, sync_point2_); | 231 mailbox2_ = TextureMailbox(m2, release_mailbox2_, sync_point2_); |
| 232 |
| 233 gfx::Size size(128, 128); |
| 234 EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea())); |
| 235 release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2, |
| 236 base::Unretained(&mock_callback_), |
| 237 shared_memory_.get()); |
| 238 mailbox3_ = TextureMailbox(shared_memory_.get(), size, release_mailbox3_); |
| 228 } | 239 } |
| 229 | 240 |
| 230 std::string mailbox_name1_; | 241 std::string mailbox_name1_; |
| 231 std::string mailbox_name2_; | 242 std::string mailbox_name2_; |
| 232 MockMailboxCallback mock_callback_; | 243 MockMailboxCallback mock_callback_; |
| 233 TextureMailbox::ReleaseCallback release_mailbox1_; | 244 TextureMailbox::ReleaseCallback release_mailbox1_; |
| 234 TextureMailbox::ReleaseCallback release_mailbox2_; | 245 TextureMailbox::ReleaseCallback release_mailbox2_; |
| 246 TextureMailbox::ReleaseCallback release_mailbox3_; |
| 235 TextureMailbox mailbox1_; | 247 TextureMailbox mailbox1_; |
| 236 TextureMailbox mailbox2_; | 248 TextureMailbox mailbox2_; |
| 249 TextureMailbox mailbox3_; |
| 237 unsigned sync_point1_; | 250 unsigned sync_point1_; |
| 238 unsigned sync_point2_; | 251 unsigned sync_point2_; |
| 252 scoped_ptr<base::SharedMemory> shared_memory_; |
| 239 }; | 253 }; |
| 240 | 254 |
| 241 class TextureLayerWithMailboxTest : public TextureLayerTest { | 255 class TextureLayerWithMailboxTest : public TextureLayerTest { |
| 242 protected: | 256 protected: |
| 243 virtual void TearDown() { | 257 virtual void TearDown() { |
| 244 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 258 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 245 EXPECT_CALL(test_data_.mock_callback_, | 259 EXPECT_CALL(test_data_.mock_callback_, |
| 246 Release(test_data_.mailbox_name1_, | 260 Release(test_data_.mailbox_name1_, |
| 247 test_data_.sync_point1_, | 261 test_data_.sync_point1_, |
| 248 false)).Times(1); | 262 false)).Times(1); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 295 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 282 EXPECT_CALL(test_data_.mock_callback_, | 296 EXPECT_CALL(test_data_.mock_callback_, |
| 283 Release(test_data_.mailbox_name2_, | 297 Release(test_data_.mailbox_name2_, |
| 284 test_data_.sync_point2_, | 298 test_data_.sync_point2_, |
| 285 false)) | 299 false)) |
| 286 .Times(1); | 300 .Times(1); |
| 287 test_layer->SetTextureMailbox(TextureMailbox()); | 301 test_layer->SetTextureMailbox(TextureMailbox()); |
| 288 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 302 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 289 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 303 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 290 | 304 |
| 305 test_layer->SetTextureMailbox(test_data_.mailbox3_); |
| 306 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 307 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 308 |
| 309 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 310 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 311 EXPECT_CALL(test_data_.mock_callback_, |
| 312 Release2(test_data_.shared_memory_.get(), |
| 313 0, false)) |
| 314 .Times(1); |
| 315 test_layer->SetTextureMailbox(TextureMailbox()); |
| 316 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 317 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 318 |
| 291 // Test destructor. | 319 // Test destructor. |
| 292 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 320 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 293 test_layer->SetTextureMailbox(test_data_.mailbox1_); | 321 test_layer->SetTextureMailbox(test_data_.mailbox1_); |
| 294 } | 322 } |
| 295 | 323 |
| 296 class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { | 324 class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
| 297 public: | 325 public: |
| 298 TextureLayerImplWithMailboxThreadedCallback() | 326 TextureLayerImplWithMailboxThreadedCallback() |
| 299 : callback_count_(0), | 327 : callback_count_(0), |
| 300 commit_count_(0) {} | 328 commit_count_(0) {} |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 base::Lock lock_; | 717 base::Lock lock_; |
| 690 unsigned expected_used_textures_on_commit_; | 718 unsigned expected_used_textures_on_commit_; |
| 691 }; | 719 }; |
| 692 | 720 |
| 693 // The TextureLayerClient does not use mailboxes, so can't use a delegating | 721 // The TextureLayerClient does not use mailboxes, so can't use a delegating |
| 694 // renderer. | 722 // renderer. |
| 695 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerClientTest); | 723 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerClientTest); |
| 696 | 724 |
| 697 } // namespace | 725 } // namespace |
| 698 } // namespace cc | 726 } // namespace cc |
| OLD | NEW |