| 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) { |
| 84 delete texture; | 84 delete texture; |
| 85 } | 85 } |
| 86 | 86 |
| 87 scoped_refptr<MailboxManager> manager_; | 87 scoped_refptr<MailboxManager> manager_; |
| 88 | 88 |
| 89 private: | 89 private: |
| 90 scoped_refptr<FeatureInfo> feature_info_; | 90 scoped_refptr<FeatureInfo> feature_info_; |
| 91 | 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(MailboxManagerTest); | 92 DISALLOW_COPY_AND_ASSIGN(MailboxManagerTest); |
| 93 }; | 93 }; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); | 324 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); |
| 325 | 325 |
| 326 // Synchronize | 326 // Synchronize |
| 327 manager_->PushTextureUpdates(g_sync_token); | 327 manager_->PushTextureUpdates(g_sync_token); |
| 328 manager2_->PullTextureUpdates(g_sync_token); | 328 manager2_->PullTextureUpdates(g_sync_token); |
| 329 | 329 |
| 330 EXPECT_CALL(*gl_, GenTextures(1, _)) | 330 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 331 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 331 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
| 332 SetupUpdateTexParamExpectations( | 332 SetupUpdateTexParamExpectations( |
| 333 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 333 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 334 Texture* new_texture = manager2_->ConsumeTexture(name); | 334 TextureBase* new_texture_base = manager2_->ConsumeTexture(name); |
| 335 EXPECT_FALSE(new_texture == NULL); | 335 EXPECT_NE(nullptr, new_texture_base); |
| 336 Texture* new_texture = new_texture_base->AsTexture(); |
| 337 EXPECT_NE(nullptr, new_texture); |
| 336 EXPECT_NE(texture, new_texture); | 338 EXPECT_NE(texture, new_texture); |
| 337 EXPECT_EQ(kNewTextureId, new_texture->service_id()); | 339 EXPECT_EQ(kNewTextureId, new_texture->service_id()); |
| 338 | 340 |
| 339 // Resize original texture | 341 // Resize original texture |
| 340 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 16, 32, 1, 0, GL_RGBA, | 342 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 16, 32, 1, 0, GL_RGBA, |
| 341 GL_UNSIGNED_BYTE, gfx::Rect(16, 32)); | 343 GL_UNSIGNED_BYTE, gfx::Rect(16, 32)); |
| 342 // Should have been orphaned | 344 // Should have been orphaned |
| 343 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); | 345 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); |
| 344 | 346 |
| 345 // Synchronize again | 347 // 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 | 383 // pushed in both directions, i.e. makes sure we don't clobber a shared |
| 382 // texture definition with an older version. | 384 // texture definition with an older version. |
| 383 TEST_F(MailboxManagerSyncTest, ProduceConsumeBidirectional) { | 385 TEST_F(MailboxManagerSyncTest, ProduceConsumeBidirectional) { |
| 384 const GLuint kNewTextureId1 = 1234; | 386 const GLuint kNewTextureId1 = 1234; |
| 385 const GLuint kNewTextureId2 = 4321; | 387 const GLuint kNewTextureId2 = 4321; |
| 386 | 388 |
| 387 Texture* texture1 = DefineTexture(); | 389 Texture* texture1 = DefineTexture(); |
| 388 Mailbox name1 = Mailbox::Generate(); | 390 Mailbox name1 = Mailbox::Generate(); |
| 389 Texture* texture2 = DefineTexture(); | 391 Texture* texture2 = DefineTexture(); |
| 390 Mailbox name2 = Mailbox::Generate(); | 392 Mailbox name2 = Mailbox::Generate(); |
| 391 Texture* new_texture1 = NULL; | 393 TextureBase* new_texture1 = NULL; |
| 392 Texture* new_texture2 = NULL; | 394 TextureBase* new_texture2 = NULL; |
| 393 | 395 |
| 394 manager_->ProduceTexture(name1, texture1); | 396 manager_->ProduceTexture(name1, texture1); |
| 395 manager2_->ProduceTexture(name2, texture2); | 397 manager2_->ProduceTexture(name2, texture2); |
| 396 | 398 |
| 397 // Make visible. | 399 // Make visible. |
| 398 manager_->PushTextureUpdates(g_sync_token); | 400 manager_->PushTextureUpdates(g_sync_token); |
| 399 manager2_->PushTextureUpdates(g_sync_token); | 401 manager2_->PushTextureUpdates(g_sync_token); |
| 400 | 402 |
| 401 // Create textures in the other manager instances for texture1 and texture2, | 403 // Create textures in the other manager instances for texture1 and texture2, |
| 402 // respectively to create a real sharing scenario. Otherwise, there would | 404 // 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)); | 466 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); |
| 465 | 467 |
| 466 // Synchronize | 468 // Synchronize |
| 467 manager_->PushTextureUpdates(g_sync_token); | 469 manager_->PushTextureUpdates(g_sync_token); |
| 468 manager2_->PullTextureUpdates(g_sync_token); | 470 manager2_->PullTextureUpdates(g_sync_token); |
| 469 | 471 |
| 470 EXPECT_CALL(*gl_, GenTextures(1, _)) | 472 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 471 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 473 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
| 472 SetupUpdateTexParamExpectations( | 474 SetupUpdateTexParamExpectations( |
| 473 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 475 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 474 Texture* new_texture = manager2_->ConsumeTexture(name); | 476 TextureBase* new_texture_base = manager2_->ConsumeTexture(name); |
| 475 EXPECT_FALSE(new_texture == NULL); | 477 EXPECT_NE(nullptr, new_texture_base); |
| 478 Texture* new_texture = new_texture_base->AsTexture(); |
| 479 EXPECT_NE(nullptr, new_texture); |
| 476 EXPECT_NE(texture, new_texture); | 480 EXPECT_NE(texture, new_texture); |
| 477 EXPECT_EQ(kNewTextureId, new_texture->service_id()); | 481 EXPECT_EQ(kNewTextureId, new_texture->service_id()); |
| 478 | 482 |
| 479 Texture* old_texture = texture; | 483 Texture* old_texture = texture; |
| 480 texture = DefineTexture(); | 484 texture = DefineTexture(); |
| 481 manager_->ProduceTexture(name, texture); | 485 manager_->ProduceTexture(name, texture); |
| 482 | 486 |
| 483 // Make a change to the new texture | 487 // Make a change to the new texture |
| 484 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture->min_filter()); | 488 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture->min_filter()); |
| 485 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), | 489 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 498 // Synchronize and expect update | 502 // Synchronize and expect update |
| 499 manager_->PushTextureUpdates(g_sync_token); | 503 manager_->PushTextureUpdates(g_sync_token); |
| 500 SetupUpdateTexParamExpectations( | 504 SetupUpdateTexParamExpectations( |
| 501 new_texture->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT); | 505 new_texture->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT); |
| 502 manager2_->PullTextureUpdates(g_sync_token); | 506 manager2_->PullTextureUpdates(g_sync_token); |
| 503 | 507 |
| 504 EXPECT_CALL(*gl_, GenTextures(1, _)) | 508 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 505 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 509 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
| 506 SetupUpdateTexParamExpectations( | 510 SetupUpdateTexParamExpectations( |
| 507 kNewTextureId, GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 511 kNewTextureId, GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 508 Texture* tmp_texture = manager2_->ConsumeTexture(name); | 512 TextureBase* tmp_texture = manager2_->ConsumeTexture(name); |
| 509 EXPECT_NE(new_texture, tmp_texture); | 513 EXPECT_NE(new_texture, tmp_texture); |
| 510 DestroyTexture(tmp_texture); | 514 DestroyTexture(tmp_texture); |
| 511 | 515 |
| 512 DestroyTexture(old_texture); | 516 DestroyTexture(old_texture); |
| 513 DestroyTexture(texture); | 517 DestroyTexture(texture); |
| 514 DestroyTexture(new_texture); | 518 DestroyTexture(new_texture); |
| 515 | 519 |
| 516 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); | 520 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); |
| 517 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); | 521 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); |
| 518 } | 522 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 529 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); | 533 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); |
| 530 | 534 |
| 531 // Synchronize | 535 // Synchronize |
| 532 manager_->PushTextureUpdates(g_sync_token); | 536 manager_->PushTextureUpdates(g_sync_token); |
| 533 manager2_->PullTextureUpdates(g_sync_token); | 537 manager2_->PullTextureUpdates(g_sync_token); |
| 534 | 538 |
| 535 EXPECT_CALL(*gl_, GenTextures(1, _)) | 539 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 536 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 540 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
| 537 SetupUpdateTexParamExpectations( | 541 SetupUpdateTexParamExpectations( |
| 538 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 542 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 539 Texture* new_texture = manager2_->ConsumeTexture(name); | 543 TextureBase* new_texture_base = manager2_->ConsumeTexture(name); |
| 540 EXPECT_FALSE(new_texture == NULL); | 544 EXPECT_NE(nullptr, new_texture_base); |
| 545 Texture* new_texture = new_texture_base->AsTexture(); |
| 546 EXPECT_NE(nullptr, new_texture); |
| 541 EXPECT_NE(texture, new_texture); | 547 EXPECT_NE(texture, new_texture); |
| 542 EXPECT_EQ(kNewTextureId, new_texture->service_id()); | 548 EXPECT_EQ(kNewTextureId, new_texture->service_id()); |
| 543 EXPECT_TRUE(texture->SafeToRenderFrom()); | 549 EXPECT_TRUE(texture->SafeToRenderFrom()); |
| 544 | 550 |
| 545 // Change cleared to false. | 551 // Change cleared to false. |
| 546 SetLevelCleared(texture, texture->target(), 0, false); | 552 SetLevelCleared(texture, texture->target(), 0, false); |
| 547 EXPECT_FALSE(texture->SafeToRenderFrom()); | 553 EXPECT_FALSE(texture->SafeToRenderFrom()); |
| 548 | 554 |
| 549 // Synchronize | 555 // Synchronize |
| 550 manager_->PushTextureUpdates(g_sync_token); | 556 manager_->PushTextureUpdates(g_sync_token); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 577 // Synchronize | 583 // Synchronize |
| 578 manager_->PushTextureUpdates(g_sync_token); | 584 manager_->PushTextureUpdates(g_sync_token); |
| 579 manager2_->PullTextureUpdates(g_sync_token); | 585 manager2_->PullTextureUpdates(g_sync_token); |
| 580 | 586 |
| 581 // Should sync to new texture which is not defined. | 587 // Should sync to new texture which is not defined. |
| 582 EXPECT_CALL(*gl_, GenTextures(1, _)) | 588 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 583 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 589 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
| 584 SetupUpdateTexParamExpectations(kNewTextureId, texture->min_filter(), | 590 SetupUpdateTexParamExpectations(kNewTextureId, texture->min_filter(), |
| 585 texture->mag_filter(), texture->wrap_s(), | 591 texture->mag_filter(), texture->wrap_s(), |
| 586 texture->wrap_t()); | 592 texture->wrap_t()); |
| 587 Texture* new_texture = manager2_->ConsumeTexture(name); | 593 TextureBase* new_texture_base = manager2_->ConsumeTexture(name); |
| 588 ASSERT_TRUE(new_texture); | 594 EXPECT_NE(nullptr, new_texture_base); |
| 595 Texture* new_texture = new_texture_base->AsTexture(); |
| 596 EXPECT_NE(nullptr, new_texture); |
| 589 EXPECT_NE(texture, new_texture); | 597 EXPECT_NE(texture, new_texture); |
| 590 EXPECT_EQ(kNewTextureId, new_texture->service_id()); | 598 EXPECT_EQ(kNewTextureId, new_texture->service_id()); |
| 591 EXPECT_FALSE(new_texture->IsDefined()); | 599 EXPECT_FALSE(new_texture->IsDefined()); |
| 592 | 600 |
| 593 // Change cleared to false. | 601 // Change cleared to false. |
| 594 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, | 602 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, |
| 595 GL_UNSIGNED_BYTE, gfx::Rect(1, 1)); | 603 GL_UNSIGNED_BYTE, gfx::Rect(1, 1)); |
| 596 SetParameter(texture, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 604 SetParameter(texture, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 597 SetParameter(texture, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 605 SetParameter(texture, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 598 EXPECT_TRUE(texture->IsDefined()); | 606 EXPECT_TRUE(texture->IsDefined()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 625 | 633 |
| 626 manager_->ProduceTexture(name1, texture); | 634 manager_->ProduceTexture(name1, texture); |
| 627 | 635 |
| 628 // Share | 636 // Share |
| 629 manager_->PushTextureUpdates(g_sync_token); | 637 manager_->PushTextureUpdates(g_sync_token); |
| 630 EXPECT_CALL(*gl_, GenTextures(1, _)) | 638 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 631 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 639 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
| 632 manager2_->PullTextureUpdates(g_sync_token); | 640 manager2_->PullTextureUpdates(g_sync_token); |
| 633 SetupUpdateTexParamExpectations( | 641 SetupUpdateTexParamExpectations( |
| 634 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 642 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 635 Texture* new_texture = manager2_->ConsumeTexture(name1); | 643 TextureBase* new_texture = manager2_->ConsumeTexture(name1); |
| 636 EXPECT_EQ(kNewTextureId, new_texture->service_id()); | 644 EXPECT_EQ(kNewTextureId, new_texture->service_id()); |
| 637 | 645 |
| 638 manager_->ProduceTexture(name2, texture); | 646 manager_->ProduceTexture(name2, texture); |
| 639 | 647 |
| 640 // Synchronize | 648 // Synchronize |
| 641 manager_->PushTextureUpdates(g_sync_token); | 649 manager_->PushTextureUpdates(g_sync_token); |
| 642 manager2_->PullTextureUpdates(g_sync_token); | 650 manager2_->PullTextureUpdates(g_sync_token); |
| 643 | 651 |
| 644 // name2 should return the same texture | 652 // name2 should return the same texture |
| 645 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name2)); | 653 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name2)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 663 Mailbox name = Mailbox::Generate(); | 671 Mailbox name = Mailbox::Generate(); |
| 664 | 672 |
| 665 manager_->ProduceTexture(name, texture1); | 673 manager_->ProduceTexture(name, texture1); |
| 666 | 674 |
| 667 // Share | 675 // Share |
| 668 manager_->PushTextureUpdates(g_sync_token); | 676 manager_->PushTextureUpdates(g_sync_token); |
| 669 EXPECT_CALL(*gl_, GenTextures(1, _)) | 677 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 670 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 678 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
| 671 SetupUpdateTexParamExpectations( | 679 SetupUpdateTexParamExpectations( |
| 672 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 680 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 673 Texture* new_texture = manager2_->ConsumeTexture(name); | 681 TextureBase* new_texture = manager2_->ConsumeTexture(name); |
| 674 EXPECT_EQ(kNewTextureId, new_texture->service_id()); | 682 EXPECT_EQ(kNewTextureId, new_texture->service_id()); |
| 675 | 683 |
| 676 // Clobber | 684 // Clobber |
| 677 manager2_->ProduceTexture(name, texture2); | 685 manager2_->ProduceTexture(name, texture2); |
| 678 manager_->ProduceTexture(name, texture1); | 686 manager_->ProduceTexture(name, texture1); |
| 679 | 687 |
| 680 // Synchronize manager -> manager2 | 688 // Synchronize manager -> manager2 |
| 681 manager_->PushTextureUpdates(g_sync_token); | 689 manager_->PushTextureUpdates(g_sync_token); |
| 682 manager2_->PullTextureUpdates(g_sync_token); | 690 manager2_->PullTextureUpdates(g_sync_token); |
| 683 | 691 |
| 684 // name should return the original texture, and not texture2 or a new one. | 692 // name should return the original texture, and not texture2 or a new one. |
| 685 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name)); | 693 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name)); |
| 686 | 694 |
| 687 DestroyTexture(texture1); | 695 DestroyTexture(texture1); |
| 688 DestroyTexture(texture2); | 696 DestroyTexture(texture2); |
| 689 DestroyTexture(new_texture); | 697 DestroyTexture(new_texture); |
| 690 } | 698 } |
| 691 | 699 |
| 692 // TODO: Texture::level_infos_[][].size() | 700 // TODO: Texture::level_infos_[][].size() |
| 693 | 701 |
| 694 // TODO: unsupported targets and formats | 702 // TODO: unsupported targets and formats |
| 695 | 703 |
| 696 } // namespace gles2 | 704 } // namespace gles2 |
| 697 } // namespace gpu | 705 } // namespace gpu |
| OLD | NEW |