| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "gpu/command_buffer/service/gles2_cmd_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 .Times(1) | 733 .Times(1) |
| 734 .RetiresOnSaturation(); | 734 .RetiresOnSaturation(); |
| 735 CopyTexImage2D cmd; | 735 CopyTexImage2D cmd; |
| 736 cmd.Init(target, level, internal_format, 0, 0, width, height); | 736 cmd.Init(target, level, internal_format, 0, 0, width, height); |
| 737 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 737 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 738 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); | 738 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); |
| 739 EXPECT_FALSE( | 739 EXPECT_FALSE( |
| 740 texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height, nullptr)); | 740 texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height, nullptr)); |
| 741 } | 741 } |
| 742 | 742 |
| 743 TEST_P(GLES2DecoderManualInitTest, CopyTexImage2DUnsizedInternalFormat) { |
| 744 base::CommandLine command_line(0, NULL); |
| 745 command_line.AppendSwitch(switches::kEnableUnsafeES3APIs); |
| 746 InitState init; |
| 747 init.gl_version = "OpenGL ES 3.0"; |
| 748 init.extensions = "GL_APPLE_texture_format_BGRA8888 GL_EXT_sRGB"; |
| 749 init.has_alpha = true; |
| 750 init.request_alpha = true; |
| 751 init.bind_generates_resource = true; |
| 752 init.context_type = CONTEXT_TYPE_OPENGLES2; |
| 753 InitDecoderWithCommandLine(init, &command_line); |
| 754 |
| 755 GLenum kUnsizedInternalFormats[] = { |
| 756 GL_RED, |
| 757 GL_RG, |
| 758 GL_RGB, |
| 759 GL_RGBA, |
| 760 GL_BGRA_EXT, |
| 761 GL_LUMINANCE, |
| 762 GL_LUMINANCE_ALPHA, |
| 763 GL_SRGB, |
| 764 GL_SRGB_ALPHA, |
| 765 }; |
| 766 GLenum target = GL_TEXTURE_2D; |
| 767 GLint level = 0; |
| 768 GLsizei width = 2; |
| 769 GLsizei height = 4; |
| 770 GLint border = 0; |
| 771 EXPECT_CALL(*gl_, GenTextures(_, _)) |
| 772 .WillOnce(SetArgumentPointee<1>(kNewServiceId)) |
| 773 .RetiresOnSaturation(); |
| 774 GenHelper<cmds::GenTexturesImmediate>(kNewClientId); |
| 775 |
| 776 TextureManager* manager = group().texture_manager(); |
| 777 |
| 778 EXPECT_CALL(*gl_, GetError()).WillRepeatedly(Return(GL_NO_ERROR)); |
| 779 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(_)) |
| 780 .WillRepeatedly(Return(GL_FRAMEBUFFER_COMPLETE)); |
| 781 for (size_t i = 0; i < arraysize(kUnsizedInternalFormats); ++i) { |
| 782 // Copy from main framebuffer to texture, using the unsized internal format. |
| 783 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0); |
| 784 GLenum internal_format = kUnsizedInternalFormats[i]; |
| 785 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); |
| 786 EXPECT_CALL(*gl_, CopyTexImage2D(target, level, internal_format, 0, 0, |
| 787 width, height, border)) |
| 788 .Times(1) |
| 789 .RetiresOnSaturation(); |
| 790 CopyTexImage2D cmd; |
| 791 cmd.Init(target, level, internal_format, 0, 0, width, height); |
| 792 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 793 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 794 |
| 795 TextureRef* ref = manager->GetTexture(client_texture_id_); |
| 796 ASSERT_TRUE(ref != nullptr); |
| 797 Texture* texture = ref->texture(); |
| 798 GLenum chosen_type = 0; |
| 799 GLenum chosen_internal_format = 0; |
| 800 texture->GetLevelType(target, level, &chosen_type, &chosen_internal_format); |
| 801 EXPECT_NE(0u, chosen_type); |
| 802 EXPECT_NE(0u, chosen_internal_format); |
| 803 |
| 804 // Attach texture to FBO, and copy into second texture. |
| 805 DoBindFramebuffer( |
| 806 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId); |
| 807 DoFramebufferTexture2D(GL_FRAMEBUFFER, |
| 808 GL_COLOR_ATTACHMENT0, |
| 809 GL_TEXTURE_2D, |
| 810 client_texture_id_, |
| 811 kServiceTextureId, |
| 812 0, |
| 813 GL_NO_ERROR); |
| 814 DoBindTexture(GL_TEXTURE_2D, kNewClientId, kNewServiceId); |
| 815 |
| 816 bool complete = |
| 817 (DoCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); |
| 818 if (complete) { |
| 819 EXPECT_CALL(*gl_, CopyTexImage2D(target, level, internal_format, 0, 0, |
| 820 width, height, border)) |
| 821 .Times(1) |
| 822 .RetiresOnSaturation(); |
| 823 } |
| 824 cmd.Init(target, level, internal_format, 0, 0, width, height); |
| 825 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 826 if (complete) { |
| 827 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 828 } else { |
| 829 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION, GetGLError()); |
| 830 } |
| 831 } |
| 832 } |
| 833 |
| 834 TEST_P(GLES2DecoderManualInitTest, CopyTexImage2DUnsizedInternalFormatES3) { |
| 835 base::CommandLine command_line(0, NULL); |
| 836 command_line.AppendSwitch(switches::kEnableUnsafeES3APIs); |
| 837 InitState init; |
| 838 init.gl_version = "OpenGL ES 3.0"; |
| 839 init.extensions = "GL_APPLE_texture_format_BGRA8888"; |
| 840 init.has_alpha = true; |
| 841 init.request_alpha = true; |
| 842 init.bind_generates_resource = true; |
| 843 init.context_type = CONTEXT_TYPE_OPENGLES3; |
| 844 InitDecoderWithCommandLine(init, &command_line); |
| 845 |
| 846 struct UnsizedSizedInternalFormat { |
| 847 GLenum unsized; |
| 848 GLenum sized; |
| 849 }; |
| 850 UnsizedSizedInternalFormat kUnsizedInternalFormats[] = { |
| 851 {GL_RED, GL_R8}, |
| 852 {GL_RG, GL_RG8}, |
| 853 {GL_RGB, GL_RGB8}, |
| 854 {GL_RGBA, GL_RGBA8}, |
| 855 {GL_BGRA_EXT, GL_RGBA8}, |
| 856 {GL_LUMINANCE, GL_RGB8}, |
| 857 {GL_LUMINANCE_ALPHA, GL_RGBA8}, |
| 858 }; |
| 859 GLenum target = GL_TEXTURE_2D; |
| 860 GLint level = 0; |
| 861 GLsizei width = 2; |
| 862 GLsizei height = 4; |
| 863 GLint border = 0; |
| 864 EXPECT_CALL(*gl_, GenTextures(_, _)) |
| 865 .WillOnce(SetArgumentPointee<1>(kNewServiceId)) |
| 866 .RetiresOnSaturation(); |
| 867 GenHelper<cmds::GenTexturesImmediate>(kNewClientId); |
| 868 |
| 869 TextureManager* manager = group().texture_manager(); |
| 870 |
| 871 EXPECT_CALL(*gl_, GetError()).WillRepeatedly(Return(GL_NO_ERROR)); |
| 872 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(_)) |
| 873 .WillRepeatedly(Return(GL_FRAMEBUFFER_COMPLETE)); |
| 874 for (size_t i = 0; i < arraysize(kUnsizedInternalFormats); ++i) { |
| 875 // Copy from main framebuffer to texture, using the unsized internal format. |
| 876 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0); |
| 877 GLenum internal_format = kUnsizedInternalFormats[i].unsized; |
| 878 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); |
| 879 EXPECT_CALL(*gl_, CopyTexImage2D(target, level, internal_format, 0, 0, |
| 880 width, height, border)) |
| 881 .Times(1) |
| 882 .RetiresOnSaturation(); |
| 883 CopyTexImage2D cmd; |
| 884 cmd.Init(target, level, internal_format, 0, 0, width, height); |
| 885 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 886 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 887 |
| 888 TextureRef* ref = manager->GetTexture(client_texture_id_); |
| 889 ASSERT_TRUE(ref != nullptr); |
| 890 Texture* texture = ref->texture(); |
| 891 GLenum chosen_type = 0; |
| 892 GLenum chosen_internal_format = 0; |
| 893 texture->GetLevelType(target, level, &chosen_type, &chosen_internal_format); |
| 894 EXPECT_NE(0u, chosen_type); |
| 895 EXPECT_NE(0u, chosen_internal_format); |
| 896 |
| 897 // Attach texture to FBO, and copy into second texture using the sized |
| 898 // internal format. |
| 899 DoBindFramebuffer( |
| 900 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId); |
| 901 DoFramebufferTexture2D(GL_FRAMEBUFFER, |
| 902 GL_COLOR_ATTACHMENT0, |
| 903 GL_TEXTURE_2D, |
| 904 client_texture_id_, |
| 905 kServiceTextureId, |
| 906 0, |
| 907 GL_NO_ERROR); |
| 908 if (DoCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) |
| 909 continue; |
| 910 |
| 911 internal_format = kUnsizedInternalFormats[i].sized; |
| 912 DoBindTexture(GL_TEXTURE_2D, kNewClientId, kNewServiceId); |
| 913 |
| 914 bool complete = |
| 915 (DoCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); |
| 916 if (complete) { |
| 917 EXPECT_CALL(*gl_, CopyTexImage2D(target, level, internal_format, 0, 0, |
| 918 width, height, border)) |
| 919 .Times(1) |
| 920 .RetiresOnSaturation(); |
| 921 } |
| 922 cmd.Init(target, level, internal_format, 0, 0, width, height); |
| 923 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 924 if (complete) { |
| 925 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 926 } else { |
| 927 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION, GetGLError()); |
| 928 } |
| 929 } |
| 930 } |
| 931 |
| 743 TEST_P(GLES3DecoderTest, CompressedTexImage3DBucket) { | 932 TEST_P(GLES3DecoderTest, CompressedTexImage3DBucket) { |
| 744 const uint32_t kBucketId = 123; | 933 const uint32_t kBucketId = 123; |
| 745 const uint32_t kBadBucketId = 99; | 934 const uint32_t kBadBucketId = 99; |
| 746 const GLenum kTarget = GL_TEXTURE_2D_ARRAY; | 935 const GLenum kTarget = GL_TEXTURE_2D_ARRAY; |
| 747 const GLint kLevel = 0; | 936 const GLint kLevel = 0; |
| 748 const GLenum kInternalFormat = GL_COMPRESSED_R11_EAC; | 937 const GLenum kInternalFormat = GL_COMPRESSED_R11_EAC; |
| 749 const GLsizei kWidth = 4; | 938 const GLsizei kWidth = 4; |
| 750 const GLsizei kHeight = 4; | 939 const GLsizei kHeight = 4; |
| 751 const GLsizei kDepth = 4; | 940 const GLsizei kDepth = 4; |
| 752 const GLint kBorder = 0; | 941 const GLint kBorder = 0; |
| (...skipping 3138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3891 // TODO(gman): CompressedTexSubImage2DImmediate | 4080 // TODO(gman): CompressedTexSubImage2DImmediate |
| 3892 | 4081 |
| 3893 // TODO(gman): TexImage2D | 4082 // TODO(gman): TexImage2D |
| 3894 | 4083 |
| 3895 // TODO(gman): TexImage2DImmediate | 4084 // TODO(gman): TexImage2DImmediate |
| 3896 | 4085 |
| 3897 // TODO(gman): TexSubImage2DImmediate | 4086 // TODO(gman): TexSubImage2DImmediate |
| 3898 | 4087 |
| 3899 } // namespace gles2 | 4088 } // namespace gles2 |
| 3900 } // namespace gpu | 4089 } // namespace gpu |
| OLD | NEW |