| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "gpu/command_buffer/common/sync_token.h" | 6 #include "gpu/command_buffer/common/sync_token.h" |
| 7 #include "gpu/command_buffer/service/feature_info.h" | 7 #include "gpu/command_buffer/service/feature_info.h" |
| 8 #include "gpu/command_buffer/service/gpu_service_test.h" | 8 #include "gpu/command_buffer/service/gpu_service_test.h" |
| 9 #include "gpu/command_buffer/service/mailbox_manager_impl.h" | 9 #include "gpu/command_buffer/service/mailbox_manager_impl.h" |
| 10 #include "gpu/command_buffer/service/mailbox_manager_sync.h" | 10 #include "gpu/command_buffer/service/mailbox_manager_sync.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 GLenum target, | 73 GLenum target, |
| 74 GLint level, | 74 GLint level, |
| 75 bool cleared) { | 75 bool cleared) { |
| 76 texture->SetLevelCleared(target, level, cleared); | 76 texture->SetLevelCleared(target, level, cleared); |
| 77 } | 77 } |
| 78 | 78 |
| 79 GLenum SetParameter(Texture* texture, GLenum pname, GLint param) { | 79 GLenum SetParameter(Texture* texture, GLenum pname, GLint param) { |
| 80 return texture->SetParameteri(feature_info_.get(), pname, param); | 80 return texture->SetParameteri(feature_info_.get(), pname, param); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void DestroyTexture(Texture* texture) { | 83 void DestroyTexture(TextureBase* texture) { delete texture; } |
| 84 delete texture; | |
| 85 } | |
| 86 | 84 |
| 87 scoped_refptr<MailboxManager> manager_; | 85 scoped_refptr<MailboxManager> manager_; |
| 88 | 86 |
| 89 private: | 87 private: |
| 90 scoped_refptr<FeatureInfo> feature_info_; | 88 scoped_refptr<FeatureInfo> feature_info_; |
| 91 | 89 |
| 92 DISALLOW_COPY_AND_ASSIGN(MailboxManagerTest); | 90 DISALLOW_COPY_AND_ASSIGN(MailboxManagerTest); |
| 93 }; | 91 }; |
| 94 | 92 |
| 95 // Tests basic produce/consume behavior. | 93 // Tests basic produce/consume behavior. |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); | 322 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); |
| 325 | 323 |
| 326 // Synchronize | 324 // Synchronize |
| 327 manager_->PushTextureUpdates(g_sync_token); | 325 manager_->PushTextureUpdates(g_sync_token); |
| 328 manager2_->PullTextureUpdates(g_sync_token); | 326 manager2_->PullTextureUpdates(g_sync_token); |
| 329 | 327 |
| 330 EXPECT_CALL(*gl_, GenTextures(1, _)) | 328 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 331 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 329 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
| 332 SetupUpdateTexParamExpectations( | 330 SetupUpdateTexParamExpectations( |
| 333 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 331 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 334 Texture* new_texture = manager2_->ConsumeTexture(name); | 332 Texture* new_texture = static_cast<Texture*>(manager2_->ConsumeTexture(name)); |
| 335 EXPECT_FALSE(new_texture == NULL); | 333 EXPECT_NE(nullptr, new_texture); |
| 336 EXPECT_NE(texture, new_texture); | 334 EXPECT_NE(texture, new_texture); |
| 337 EXPECT_EQ(kNewTextureId, new_texture->service_id()); | 335 EXPECT_EQ(kNewTextureId, new_texture->service_id()); |
| 338 | 336 |
| 339 // Resize original texture | 337 // Resize original texture |
| 340 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 16, 32, 1, 0, GL_RGBA, | 338 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 16, 32, 1, 0, GL_RGBA, |
| 341 GL_UNSIGNED_BYTE, gfx::Rect(16, 32)); | 339 GL_UNSIGNED_BYTE, gfx::Rect(16, 32)); |
| 342 // Should have been orphaned | 340 // Should have been orphaned |
| 343 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); | 341 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); |
| 344 | 342 |
| 345 // Synchronize again | 343 // Synchronize again |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 // pushed in both directions, i.e. makes sure we don't clobber a shared | 379 // pushed in both directions, i.e. makes sure we don't clobber a shared |
| 382 // texture definition with an older version. | 380 // texture definition with an older version. |
| 383 TEST_F(MailboxManagerSyncTest, ProduceConsumeBidirectional) { | 381 TEST_F(MailboxManagerSyncTest, ProduceConsumeBidirectional) { |
| 384 const GLuint kNewTextureId1 = 1234; | 382 const GLuint kNewTextureId1 = 1234; |
| 385 const GLuint kNewTextureId2 = 4321; | 383 const GLuint kNewTextureId2 = 4321; |
| 386 | 384 |
| 387 Texture* texture1 = DefineTexture(); | 385 Texture* texture1 = DefineTexture(); |
| 388 Mailbox name1 = Mailbox::Generate(); | 386 Mailbox name1 = Mailbox::Generate(); |
| 389 Texture* texture2 = DefineTexture(); | 387 Texture* texture2 = DefineTexture(); |
| 390 Mailbox name2 = Mailbox::Generate(); | 388 Mailbox name2 = Mailbox::Generate(); |
| 391 Texture* new_texture1 = NULL; | 389 TextureBase* new_texture1 = NULL; |
| 392 Texture* new_texture2 = NULL; | 390 TextureBase* new_texture2 = NULL; |
| 393 | 391 |
| 394 manager_->ProduceTexture(name1, texture1); | 392 manager_->ProduceTexture(name1, texture1); |
| 395 manager2_->ProduceTexture(name2, texture2); | 393 manager2_->ProduceTexture(name2, texture2); |
| 396 | 394 |
| 397 // Make visible. | 395 // Make visible. |
| 398 manager_->PushTextureUpdates(g_sync_token); | 396 manager_->PushTextureUpdates(g_sync_token); |
| 399 manager2_->PushTextureUpdates(g_sync_token); | 397 manager2_->PushTextureUpdates(g_sync_token); |
| 400 | 398 |
| 401 // Create textures in the other manager instances for texture1 and texture2, | 399 // Create textures in the other manager instances for texture1 and texture2, |
| 402 // respectively to create a real sharing scenario. Otherwise, there would | 400 // respectively to create a real sharing scenario. Otherwise, there would |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); | 462 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); |
| 465 | 463 |
| 466 // Synchronize | 464 // Synchronize |
| 467 manager_->PushTextureUpdates(g_sync_token); | 465 manager_->PushTextureUpdates(g_sync_token); |
| 468 manager2_->PullTextureUpdates(g_sync_token); | 466 manager2_->PullTextureUpdates(g_sync_token); |
| 469 | 467 |
| 470 EXPECT_CALL(*gl_, GenTextures(1, _)) | 468 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 471 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 469 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
| 472 SetupUpdateTexParamExpectations( | 470 SetupUpdateTexParamExpectations( |
| 473 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 471 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 474 Texture* new_texture = manager2_->ConsumeTexture(name); | 472 Texture* new_texture = static_cast<Texture*>(manager2_->ConsumeTexture(name)); |
| 475 EXPECT_FALSE(new_texture == NULL); | 473 EXPECT_NE(nullptr, new_texture); |
| 476 EXPECT_NE(texture, new_texture); | 474 EXPECT_NE(texture, new_texture); |
| 477 EXPECT_EQ(kNewTextureId, new_texture->service_id()); | 475 EXPECT_EQ(kNewTextureId, new_texture->service_id()); |
| 478 | 476 |
| 479 Texture* old_texture = texture; | 477 Texture* old_texture = texture; |
| 480 texture = DefineTexture(); | 478 texture = DefineTexture(); |
| 481 manager_->ProduceTexture(name, texture); | 479 manager_->ProduceTexture(name, texture); |
| 482 | 480 |
| 483 // Make a change to the new texture | 481 // Make a change to the new texture |
| 484 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture->min_filter()); | 482 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture->min_filter()); |
| 485 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), | 483 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 498 // Synchronize and expect update | 496 // Synchronize and expect update |
| 499 manager_->PushTextureUpdates(g_sync_token); | 497 manager_->PushTextureUpdates(g_sync_token); |
| 500 SetupUpdateTexParamExpectations( | 498 SetupUpdateTexParamExpectations( |
| 501 new_texture->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT); | 499 new_texture->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT); |
| 502 manager2_->PullTextureUpdates(g_sync_token); | 500 manager2_->PullTextureUpdates(g_sync_token); |
| 503 | 501 |
| 504 EXPECT_CALL(*gl_, GenTextures(1, _)) | 502 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 505 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 503 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
| 506 SetupUpdateTexParamExpectations( | 504 SetupUpdateTexParamExpectations( |
| 507 kNewTextureId, GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 505 kNewTextureId, GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 508 Texture* tmp_texture = manager2_->ConsumeTexture(name); | 506 TextureBase* tmp_texture = manager2_->ConsumeTexture(name); |
| 509 EXPECT_NE(new_texture, tmp_texture); | 507 EXPECT_NE(new_texture, tmp_texture); |
| 510 DestroyTexture(tmp_texture); | 508 DestroyTexture(tmp_texture); |
| 511 | 509 |
| 512 DestroyTexture(old_texture); | 510 DestroyTexture(old_texture); |
| 513 DestroyTexture(texture); | 511 DestroyTexture(texture); |
| 514 DestroyTexture(new_texture); | 512 DestroyTexture(new_texture); |
| 515 | 513 |
| 516 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); | 514 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); |
| 517 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); | 515 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); |
| 518 } | 516 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 529 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); | 527 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); |
| 530 | 528 |
| 531 // Synchronize | 529 // Synchronize |
| 532 manager_->PushTextureUpdates(g_sync_token); | 530 manager_->PushTextureUpdates(g_sync_token); |
| 533 manager2_->PullTextureUpdates(g_sync_token); | 531 manager2_->PullTextureUpdates(g_sync_token); |
| 534 | 532 |
| 535 EXPECT_CALL(*gl_, GenTextures(1, _)) | 533 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 536 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 534 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
| 537 SetupUpdateTexParamExpectations( | 535 SetupUpdateTexParamExpectations( |
| 538 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 536 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 539 Texture* new_texture = manager2_->ConsumeTexture(name); | 537 Texture* new_texture = static_cast<Texture*>(manager2_->ConsumeTexture(name)); |
| 540 EXPECT_FALSE(new_texture == NULL); | 538 EXPECT_NE(nullptr, new_texture); |
| 541 EXPECT_NE(texture, new_texture); | 539 EXPECT_NE(texture, new_texture); |
| 542 EXPECT_EQ(kNewTextureId, new_texture->service_id()); | 540 EXPECT_EQ(kNewTextureId, new_texture->service_id()); |
| 543 EXPECT_TRUE(texture->SafeToRenderFrom()); | 541 EXPECT_TRUE(texture->SafeToRenderFrom()); |
| 544 | 542 |
| 545 // Change cleared to false. | 543 // Change cleared to false. |
| 546 SetLevelCleared(texture, texture->target(), 0, false); | 544 SetLevelCleared(texture, texture->target(), 0, false); |
| 547 EXPECT_FALSE(texture->SafeToRenderFrom()); | 545 EXPECT_FALSE(texture->SafeToRenderFrom()); |
| 548 | 546 |
| 549 // Synchronize | 547 // Synchronize |
| 550 manager_->PushTextureUpdates(g_sync_token); | 548 manager_->PushTextureUpdates(g_sync_token); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 577 // Synchronize | 575 // Synchronize |
| 578 manager_->PushTextureUpdates(g_sync_token); | 576 manager_->PushTextureUpdates(g_sync_token); |
| 579 manager2_->PullTextureUpdates(g_sync_token); | 577 manager2_->PullTextureUpdates(g_sync_token); |
| 580 | 578 |
| 581 // Should sync to new texture which is not defined. | 579 // Should sync to new texture which is not defined. |
| 582 EXPECT_CALL(*gl_, GenTextures(1, _)) | 580 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 583 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 581 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
| 584 SetupUpdateTexParamExpectations(kNewTextureId, texture->min_filter(), | 582 SetupUpdateTexParamExpectations(kNewTextureId, texture->min_filter(), |
| 585 texture->mag_filter(), texture->wrap_s(), | 583 texture->mag_filter(), texture->wrap_s(), |
| 586 texture->wrap_t()); | 584 texture->wrap_t()); |
| 587 Texture* new_texture = manager2_->ConsumeTexture(name); | 585 Texture* new_texture = static_cast<Texture*>(manager2_->ConsumeTexture(name)); |
| 588 ASSERT_TRUE(new_texture); | 586 EXPECT_NE(nullptr, new_texture); |
| 589 EXPECT_NE(texture, new_texture); | 587 EXPECT_NE(texture, new_texture); |
| 590 EXPECT_EQ(kNewTextureId, new_texture->service_id()); | 588 EXPECT_EQ(kNewTextureId, new_texture->service_id()); |
| 591 EXPECT_FALSE(new_texture->IsDefined()); | 589 EXPECT_FALSE(new_texture->IsDefined()); |
| 592 | 590 |
| 593 // Change cleared to false. | 591 // Change cleared to false. |
| 594 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, | 592 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, |
| 595 GL_UNSIGNED_BYTE, gfx::Rect(1, 1)); | 593 GL_UNSIGNED_BYTE, gfx::Rect(1, 1)); |
| 596 SetParameter(texture, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 594 SetParameter(texture, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 597 SetParameter(texture, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 595 SetParameter(texture, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 598 EXPECT_TRUE(texture->IsDefined()); | 596 EXPECT_TRUE(texture->IsDefined()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 625 | 623 |
| 626 manager_->ProduceTexture(name1, texture); | 624 manager_->ProduceTexture(name1, texture); |
| 627 | 625 |
| 628 // Share | 626 // Share |
| 629 manager_->PushTextureUpdates(g_sync_token); | 627 manager_->PushTextureUpdates(g_sync_token); |
| 630 EXPECT_CALL(*gl_, GenTextures(1, _)) | 628 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 631 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 629 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
| 632 manager2_->PullTextureUpdates(g_sync_token); | 630 manager2_->PullTextureUpdates(g_sync_token); |
| 633 SetupUpdateTexParamExpectations( | 631 SetupUpdateTexParamExpectations( |
| 634 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 632 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 635 Texture* new_texture = manager2_->ConsumeTexture(name1); | 633 TextureBase* new_texture = manager2_->ConsumeTexture(name1); |
| 636 EXPECT_EQ(kNewTextureId, new_texture->service_id()); | 634 EXPECT_EQ(kNewTextureId, new_texture->service_id()); |
| 637 | 635 |
| 638 manager_->ProduceTexture(name2, texture); | 636 manager_->ProduceTexture(name2, texture); |
| 639 | 637 |
| 640 // Synchronize | 638 // Synchronize |
| 641 manager_->PushTextureUpdates(g_sync_token); | 639 manager_->PushTextureUpdates(g_sync_token); |
| 642 manager2_->PullTextureUpdates(g_sync_token); | 640 manager2_->PullTextureUpdates(g_sync_token); |
| 643 | 641 |
| 644 // name2 should return the same texture | 642 // name2 should return the same texture |
| 645 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name2)); | 643 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name2)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 663 Mailbox name = Mailbox::Generate(); | 661 Mailbox name = Mailbox::Generate(); |
| 664 | 662 |
| 665 manager_->ProduceTexture(name, texture1); | 663 manager_->ProduceTexture(name, texture1); |
| 666 | 664 |
| 667 // Share | 665 // Share |
| 668 manager_->PushTextureUpdates(g_sync_token); | 666 manager_->PushTextureUpdates(g_sync_token); |
| 669 EXPECT_CALL(*gl_, GenTextures(1, _)) | 667 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 670 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 668 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
| 671 SetupUpdateTexParamExpectations( | 669 SetupUpdateTexParamExpectations( |
| 672 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 670 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 673 Texture* new_texture = manager2_->ConsumeTexture(name); | 671 TextureBase* new_texture = manager2_->ConsumeTexture(name); |
| 674 EXPECT_EQ(kNewTextureId, new_texture->service_id()); | 672 EXPECT_EQ(kNewTextureId, new_texture->service_id()); |
| 675 | 673 |
| 676 // Clobber | 674 // Clobber |
| 677 manager2_->ProduceTexture(name, texture2); | 675 manager2_->ProduceTexture(name, texture2); |
| 678 manager_->ProduceTexture(name, texture1); | 676 manager_->ProduceTexture(name, texture1); |
| 679 | 677 |
| 680 // Synchronize manager -> manager2 | 678 // Synchronize manager -> manager2 |
| 681 manager_->PushTextureUpdates(g_sync_token); | 679 manager_->PushTextureUpdates(g_sync_token); |
| 682 manager2_->PullTextureUpdates(g_sync_token); | 680 manager2_->PullTextureUpdates(g_sync_token); |
| 683 | 681 |
| 684 // name should return the original texture, and not texture2 or a new one. | 682 // name should return the original texture, and not texture2 or a new one. |
| 685 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name)); | 683 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name)); |
| 686 | 684 |
| 687 DestroyTexture(texture1); | 685 DestroyTexture(texture1); |
| 688 DestroyTexture(texture2); | 686 DestroyTexture(texture2); |
| 689 DestroyTexture(new_texture); | 687 DestroyTexture(new_texture); |
| 690 } | 688 } |
| 691 | 689 |
| 692 // TODO: Texture::level_infos_[][].size() | 690 // TODO: Texture::level_infos_[][].size() |
| 693 | 691 |
| 694 // TODO: unsupported targets and formats | 692 // TODO: unsupported targets and formats |
| 695 | 693 |
| 696 } // namespace gles2 | 694 } // namespace gles2 |
| 697 } // namespace gpu | 695 } // namespace gpu |
| OLD | NEW |