OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // Tests for the Command Buffer Helper. | 5 // Tests for the Command Buffer Helper. |
6 | 6 |
7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
8 #include "gpu/command_buffer/common/command_buffer.h" | 8 #include "gpu/command_buffer/common/command_buffer.h" |
| 9 #include "gpu/GLES2/gles2_command_buffer.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
11 | 12 |
12 namespace gpu { | 13 namespace gpu { |
13 | 14 |
14 class GLES2MockCommandBufferHelper : public CommandBuffer { | 15 class GLES2MockCommandBufferHelper : public CommandBuffer { |
15 public: | 16 public: |
16 static const int32 kTransferBufferId = 0x123; | 17 static const int32 kTransferBufferId = 0x123; |
17 | 18 |
18 GLES2MockCommandBufferHelper() { } | 19 GLES2MockCommandBufferHelper() { } |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 #endif // defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) | 630 #endif // defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) |
630 | 631 |
631 TEST_F(GLES2ImplementationTest, ReservedIds) { | 632 TEST_F(GLES2ImplementationTest, ReservedIds) { |
632 // Only the get error command should be issued. | 633 // Only the get error command should be issued. |
633 struct Cmds { | 634 struct Cmds { |
634 GetError get; | 635 GetError get; |
635 }; | 636 }; |
636 Cmds expected; | 637 Cmds expected; |
637 expected.get.Init(kTransferBufferId, 0); | 638 expected.get.Init(kTransferBufferId, 0); |
638 | 639 |
639 // One call to flush to way for GetError | 640 // One call to flush to wait for GetError |
640 EXPECT_CALL(*command_buffer_, OnFlush(_)) | 641 EXPECT_CALL(*command_buffer_, OnFlush(_)) |
641 .WillOnce(SetMemory(GLuint(GL_NO_ERROR))) | 642 .WillOnce(SetMemory(GLuint(GL_NO_ERROR))) |
642 .RetiresOnSaturation(); | 643 .RetiresOnSaturation(); |
643 | 644 |
644 gl_->BindBuffer( | 645 gl_->BindBuffer( |
645 GL_ARRAY_BUFFER, | 646 GL_ARRAY_BUFFER, |
646 GLES2Implementation::kClientSideArrayId); | 647 GLES2Implementation::kClientSideArrayId); |
647 gl_->BindBuffer( | 648 gl_->BindBuffer( |
648 GL_ARRAY_BUFFER, | 649 GL_ARRAY_BUFFER, |
649 GLES2Implementation::kClientSideElementArrayId); | 650 GLES2Implementation::kClientSideElementArrayId); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 | 683 |
683 EXPECT_CALL(*command_buffer_, OnFlush(_)) | 684 EXPECT_CALL(*command_buffer_, OnFlush(_)) |
684 .WillOnce(SetMemory(static_cast<uint32>(1))) | 685 .WillOnce(SetMemory(static_cast<uint32>(1))) |
685 .WillOnce(SetMemory(static_cast<uint32>(1))) | 686 .WillOnce(SetMemory(static_cast<uint32>(1))) |
686 .RetiresOnSaturation(); | 687 .RetiresOnSaturation(); |
687 | 688 |
688 gl_->ReadPixels(0, 0, kWidth, kHeight, kFormat, kType, buffer.get()); | 689 gl_->ReadPixels(0, 0, kWidth, kHeight, kFormat, kType, buffer.get()); |
689 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); | 690 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); |
690 } | 691 } |
691 | 692 |
| 693 TEST_F(GLES2ImplementationTest, MapUnMapBufferSubData) { |
| 694 struct Cmds { |
| 695 BufferSubData buf; |
| 696 cmd::SetToken set_token; |
| 697 }; |
| 698 const GLenum kTarget = GL_ELEMENT_ARRAY_BUFFER; |
| 699 const GLintptr kOffset = 15; |
| 700 const GLsizeiptr kSize = 16; |
| 701 |
| 702 int32 token = 1; |
| 703 uint32 offset = 0; |
| 704 Cmds expected; |
| 705 expected.buf.Init( |
| 706 kTarget, kOffset, kSize, kTransferBufferId, offset); |
| 707 expected.set_token.Init(token++); |
| 708 |
| 709 void* mem = gl_->MapBufferSubData(kTarget, kOffset, kSize, GL_WRITE_ONLY); |
| 710 ASSERT_TRUE(mem != NULL); |
| 711 gl_->UnmapBufferSubData(mem); |
| 712 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); |
| 713 } |
| 714 |
| 715 TEST_F(GLES2ImplementationTest, MapUnMapBufferSubDataBadArgs) { |
| 716 const GLenum kTarget = GL_ELEMENT_ARRAY_BUFFER; |
| 717 const GLintptr kOffset = 15; |
| 718 const GLsizeiptr kSize = 16; |
| 719 |
| 720 // Calls to flush to wait for GetError |
| 721 EXPECT_CALL(*command_buffer_, OnFlush(_)) |
| 722 .WillOnce(SetMemory(GLuint(GL_NO_ERROR))) |
| 723 .WillOnce(SetMemory(GLuint(GL_NO_ERROR))) |
| 724 .WillOnce(SetMemory(GLuint(GL_NO_ERROR))) |
| 725 .WillOnce(SetMemory(GLuint(GL_NO_ERROR))) |
| 726 .RetiresOnSaturation(); |
| 727 |
| 728 void* mem; |
| 729 mem = gl_->MapBufferSubData(kTarget, -1, kSize, GL_WRITE_ONLY); |
| 730 ASSERT_TRUE(mem == NULL); |
| 731 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError()); |
| 732 mem = gl_->MapBufferSubData(kTarget, kOffset, -1, GL_WRITE_ONLY); |
| 733 ASSERT_TRUE(mem == NULL); |
| 734 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError()); |
| 735 mem = gl_->MapBufferSubData(kTarget, kOffset, kSize, GL_READ_ONLY); |
| 736 ASSERT_TRUE(mem == NULL); |
| 737 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), gl_->GetError()); |
| 738 const char* kPtr = "something"; |
| 739 gl_->UnmapBufferSubData(kPtr); |
| 740 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError()); |
| 741 } |
| 742 |
| 743 TEST_F(GLES2ImplementationTest, MapUnMapTexSubImage2D) { |
| 744 struct Cmds { |
| 745 TexSubImage2D tex; |
| 746 cmd::SetToken set_token; |
| 747 }; |
| 748 const GLint kLevel = 1; |
| 749 const GLint kXOffset = 2; |
| 750 const GLint kYOffset = 3; |
| 751 const GLint kWidth = 4; |
| 752 const GLint kHeight = 5; |
| 753 const GLenum kFormat = GL_RGBA; |
| 754 const GLenum kType = GL_UNSIGNED_BYTE; |
| 755 |
| 756 int32 token = 1; |
| 757 uint32 offset = 0; |
| 758 Cmds expected; |
| 759 expected.tex.Init( |
| 760 GL_TEXTURE_2D, kLevel, kXOffset, kYOffset, kWidth, kHeight, kFormat, |
| 761 kType, kTransferBufferId, offset); |
| 762 expected.set_token.Init(token++); |
| 763 |
| 764 void* mem = gl_->MapTexSubImage2D( |
| 765 GL_TEXTURE_2D, |
| 766 kLevel, |
| 767 kXOffset, |
| 768 kYOffset, |
| 769 kWidth, |
| 770 kHeight, |
| 771 kFormat, |
| 772 kType, |
| 773 GL_WRITE_ONLY); |
| 774 ASSERT_TRUE(mem != NULL); |
| 775 gl_->UnmapTexSubImage2D(mem); |
| 776 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); |
| 777 } |
| 778 |
| 779 TEST_F(GLES2ImplementationTest, MapUnMapTexSubImage2DBadArgs) { |
| 780 const GLint kLevel = 1; |
| 781 const GLint kXOffset = 2; |
| 782 const GLint kYOffset = 3; |
| 783 const GLint kWidth = 4; |
| 784 const GLint kHeight = 5; |
| 785 const GLenum kFormat = GL_RGBA; |
| 786 const GLenum kType = GL_UNSIGNED_BYTE; |
| 787 |
| 788 // Calls to flush to wait for GetError |
| 789 EXPECT_CALL(*command_buffer_, OnFlush(_)) |
| 790 .WillOnce(SetMemory(GLuint(GL_NO_ERROR))) |
| 791 .WillOnce(SetMemory(GLuint(GL_NO_ERROR))) |
| 792 .WillOnce(SetMemory(GLuint(GL_NO_ERROR))) |
| 793 .WillOnce(SetMemory(GLuint(GL_NO_ERROR))) |
| 794 .WillOnce(SetMemory(GLuint(GL_NO_ERROR))) |
| 795 .WillOnce(SetMemory(GLuint(GL_NO_ERROR))) |
| 796 .WillOnce(SetMemory(GLuint(GL_NO_ERROR))) |
| 797 .RetiresOnSaturation(); |
| 798 |
| 799 void* mem; |
| 800 mem = gl_->MapTexSubImage2D( |
| 801 GL_TEXTURE_2D, |
| 802 -1, |
| 803 kXOffset, |
| 804 kYOffset, |
| 805 kWidth, |
| 806 kHeight, |
| 807 kFormat, |
| 808 kType, |
| 809 GL_WRITE_ONLY); |
| 810 EXPECT_TRUE(mem == NULL); |
| 811 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError()); |
| 812 mem = gl_->MapTexSubImage2D( |
| 813 GL_TEXTURE_2D, |
| 814 kLevel, |
| 815 -1, |
| 816 kYOffset, |
| 817 kWidth, |
| 818 kHeight, |
| 819 kFormat, |
| 820 kType, |
| 821 GL_WRITE_ONLY); |
| 822 EXPECT_TRUE(mem == NULL); |
| 823 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError()); |
| 824 mem = gl_->MapTexSubImage2D( |
| 825 GL_TEXTURE_2D, |
| 826 kLevel, |
| 827 kXOffset, |
| 828 -1, |
| 829 kWidth, |
| 830 kHeight, |
| 831 kFormat, |
| 832 kType, |
| 833 GL_WRITE_ONLY); |
| 834 EXPECT_TRUE(mem == NULL); |
| 835 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError()); |
| 836 mem = gl_->MapTexSubImage2D( |
| 837 GL_TEXTURE_2D, |
| 838 kLevel, |
| 839 kXOffset, |
| 840 kYOffset, |
| 841 -1, |
| 842 kHeight, |
| 843 kFormat, |
| 844 kType, |
| 845 GL_WRITE_ONLY); |
| 846 EXPECT_TRUE(mem == NULL); |
| 847 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError()); |
| 848 mem = gl_->MapTexSubImage2D( |
| 849 GL_TEXTURE_2D, |
| 850 kLevel, |
| 851 kXOffset, |
| 852 kYOffset, |
| 853 kWidth, |
| 854 -1, |
| 855 kFormat, |
| 856 kType, |
| 857 GL_WRITE_ONLY); |
| 858 EXPECT_TRUE(mem == NULL); |
| 859 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError()); |
| 860 mem = gl_->MapTexSubImage2D( |
| 861 GL_TEXTURE_2D, |
| 862 kLevel, |
| 863 kXOffset, |
| 864 kYOffset, |
| 865 kWidth, |
| 866 kHeight, |
| 867 kFormat, |
| 868 kType, |
| 869 GL_READ_ONLY); |
| 870 EXPECT_TRUE(mem == NULL); |
| 871 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), gl_->GetError()); |
| 872 const char* kPtr = "something"; |
| 873 gl_->UnmapTexSubImage2D(kPtr); |
| 874 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError()); |
| 875 } |
| 876 |
692 } // namespace gles2 | 877 } // namespace gles2 |
693 } // namespace gpu | 878 } // namespace gpu |
694 | 879 |
695 | 880 |
OLD | NEW |