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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 9 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
(...skipping 2812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2823 class MockGLImage : public gfx::GLImage { | 2823 class MockGLImage : public gfx::GLImage { |
2824 public: | 2824 public: |
2825 MockGLImage() {} | 2825 MockGLImage() {} |
2826 | 2826 |
2827 // Overridden from gfx::GLImage: | 2827 // Overridden from gfx::GLImage: |
2828 MOCK_METHOD0(GetSize, gfx::Size()); | 2828 MOCK_METHOD0(GetSize, gfx::Size()); |
2829 MOCK_METHOD0(GetInternalFormat, unsigned()); | 2829 MOCK_METHOD0(GetInternalFormat, unsigned()); |
2830 MOCK_METHOD1(Destroy, void(bool)); | 2830 MOCK_METHOD1(Destroy, void(bool)); |
2831 MOCK_METHOD1(BindTexImage, bool(unsigned)); | 2831 MOCK_METHOD1(BindTexImage, bool(unsigned)); |
2832 MOCK_METHOD1(ReleaseTexImage, void(unsigned)); | 2832 MOCK_METHOD1(ReleaseTexImage, void(unsigned)); |
2833 MOCK_METHOD1(CopyTexImage, bool(unsigned)); | |
2834 MOCK_METHOD3(CopyTexSubImage, | 2833 MOCK_METHOD3(CopyTexSubImage, |
2835 bool(unsigned, const gfx::Point&, const gfx::Rect&)); | 2834 bool(unsigned, const gfx::Point&, const gfx::Rect&)); |
| 2835 MOCK_METHOD0(WillUseTexImage, void()); |
| 2836 MOCK_METHOD0(DidUseTexImage, void()); |
| 2837 MOCK_METHOD0(WillModifyTexImage, void()); |
| 2838 MOCK_METHOD0(DidModifyTexImage, void()); |
2836 MOCK_METHOD5(ScheduleOverlayPlane, bool(gfx::AcceleratedWidget, | 2839 MOCK_METHOD5(ScheduleOverlayPlane, bool(gfx::AcceleratedWidget, |
2837 int, | 2840 int, |
2838 gfx::OverlayTransform, | 2841 gfx::OverlayTransform, |
2839 const gfx::Rect&, | 2842 const gfx::Rect&, |
2840 const gfx::RectF&)); | 2843 const gfx::RectF&)); |
2841 MOCK_METHOD3(OnMemoryDump, | 2844 MOCK_METHOD3(OnMemoryDump, |
2842 void(base::trace_event::ProcessMemoryDump*, | 2845 void(base::trace_event::ProcessMemoryDump*, |
2843 uint64_t, | 2846 uint64_t, |
2844 const std::string&)); | 2847 const std::string&)); |
2845 | 2848 |
2846 protected: | 2849 protected: |
2847 virtual ~MockGLImage() {} | 2850 virtual ~MockGLImage() {} |
2848 }; | 2851 }; |
2849 | 2852 |
2850 TEST_P(GLES2DecoderWithShaderTest, CopyTexImage) { | 2853 TEST_P(GLES2DecoderWithShaderTest, UseTexImage) { |
2851 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); | 2854 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); |
2852 DoTexImage2D(GL_TEXTURE_2D, | 2855 DoTexImage2D(GL_TEXTURE_2D, |
2853 0, | 2856 0, |
2854 GL_RGBA, | 2857 GL_RGBA, |
2855 1, | 2858 1, |
2856 1, | 2859 1, |
2857 0, | 2860 0, |
2858 GL_RGBA, | 2861 GL_RGBA, |
2859 GL_UNSIGNED_BYTE, | 2862 GL_UNSIGNED_BYTE, |
2860 kSharedMemoryId, | 2863 kSharedMemoryId, |
2861 kSharedMemoryOffset); | 2864 kSharedMemoryOffset); |
2862 | 2865 |
2863 TextureRef* texture_ref = | 2866 TextureRef* texture_ref = |
2864 group().texture_manager()->GetTexture(client_texture_id_); | 2867 group().texture_manager()->GetTexture(client_texture_id_); |
2865 ASSERT_TRUE(texture_ref != NULL); | 2868 ASSERT_TRUE(texture_ref != NULL); |
2866 Texture* texture = texture_ref->texture(); | 2869 Texture* texture = texture_ref->texture(); |
2867 EXPECT_EQ(kServiceTextureId, texture->service_id()); | 2870 EXPECT_EQ(kServiceTextureId, texture->service_id()); |
2868 | 2871 |
2869 const int32 kImageId = 1; | 2872 const int32 kImageId = 1; |
2870 scoped_refptr<MockGLImage> image(new MockGLImage); | 2873 scoped_refptr<MockGLImage> image(new MockGLImage); |
2871 GetImageManager()->AddImage(image.get(), kImageId); | 2874 GetImageManager()->AddImage(image.get(), kImageId); |
2872 | 2875 |
2873 // Bind image to texture. | 2876 // Bind image to texture. |
2874 EXPECT_CALL(*image.get(), BindTexImage(GL_TEXTURE_2D)) | 2877 EXPECT_CALL(*image.get(), BindTexImage(GL_TEXTURE_2D)) |
2875 .Times(1) | 2878 .Times(1) |
2876 .WillOnce(Return(false)) | 2879 .WillOnce(Return(true)) |
2877 .RetiresOnSaturation(); | 2880 .RetiresOnSaturation(); |
2878 EXPECT_CALL(*image.get(), GetSize()) | 2881 EXPECT_CALL(*image.get(), GetSize()) |
2879 .Times(1) | 2882 .Times(1) |
2880 .WillOnce(Return(gfx::Size(1, 1))) | 2883 .WillOnce(Return(gfx::Size(1, 1))) |
2881 .RetiresOnSaturation(); | 2884 .RetiresOnSaturation(); |
2882 EXPECT_CALL(*image.get(), GetInternalFormat()) | |
2883 .Times(1) | |
2884 .WillOnce(Return(GL_RGBA)) | |
2885 .RetiresOnSaturation(); | |
2886 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. | 2885 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. |
2887 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId); | 2886 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId); |
2888 | 2887 |
2889 AddExpectationsForSimulatedAttrib0(kNumVertices, 0); | 2888 AddExpectationsForSimulatedAttrib0(kNumVertices, 0); |
2890 SetupExpectationsForApplyingDefaultDirtyState(); | 2889 SetupExpectationsForApplyingDefaultDirtyState(); |
2891 | 2890 |
2892 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. | 2891 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. |
2893 EXPECT_CALL(*gl_, GetError()) | 2892 EXPECT_CALL(*gl_, GetError()) |
2894 .WillOnce(Return(GL_NO_ERROR)) | 2893 .WillOnce(Return(GL_NO_ERROR)) |
2895 .WillOnce(Return(GL_NO_ERROR)) | 2894 .WillOnce(Return(GL_NO_ERROR)) |
| 2895 .WillOnce(Return(GL_NO_ERROR)) |
| 2896 .WillOnce(Return(GL_NO_ERROR)) |
2896 .RetiresOnSaturation(); | 2897 .RetiresOnSaturation(); |
2897 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(2).RetiresOnSaturation(); | 2898 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(3).RetiresOnSaturation(); |
2898 EXPECT_CALL(*image.get(), CopyTexImage(GL_TEXTURE_2D)) | 2899 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation(); |
2899 .Times(1) | 2900 EXPECT_CALL(*image.get(), DidUseTexImage()).Times(1).RetiresOnSaturation(); |
2900 .WillOnce(Return(true)) | |
2901 .RetiresOnSaturation(); | |
2902 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices)) | 2901 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices)) |
2903 .Times(1) | 2902 .Times(1) |
2904 .RetiresOnSaturation(); | 2903 .RetiresOnSaturation(); |
2905 DrawArrays cmd; | 2904 DrawArrays cmd; |
2906 cmd.Init(GL_TRIANGLES, 0, kNumVertices); | 2905 cmd.Init(GL_TRIANGLES, 0, kNumVertices); |
2907 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 2906 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
2908 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 2907 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
2909 | 2908 |
2910 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); | |
2911 // Re-bind image to texture. | |
2912 ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd; | |
2913 release_tex_image_2d_cmd.Init(GL_TEXTURE_2D, kImageId); | |
2914 EXPECT_EQ(error::kNoError, ExecuteCmd(release_tex_image_2d_cmd)); | |
2915 EXPECT_CALL(*image.get(), BindTexImage(GL_TEXTURE_2D)) | |
2916 .Times(1) | |
2917 .WillOnce(Return(false)) | |
2918 .RetiresOnSaturation(); | |
2919 EXPECT_CALL(*image.get(), GetSize()) | |
2920 .Times(1) | |
2921 .WillOnce(Return(gfx::Size(1, 1))) | |
2922 .RetiresOnSaturation(); | |
2923 EXPECT_CALL(*image.get(), GetInternalFormat()) | |
2924 .Times(1) | |
2925 .WillOnce(Return(GL_RGBA)) | |
2926 .RetiresOnSaturation(); | |
2927 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId); | |
2928 | |
2929 DoBindFramebuffer( | 2909 DoBindFramebuffer( |
2930 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId); | 2910 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId); |
2931 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. | 2911 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. |
2932 EXPECT_CALL(*gl_, GetError()) | 2912 EXPECT_CALL(*gl_, GetError()) |
2933 .WillOnce(Return(GL_NO_ERROR)) | 2913 .WillOnce(Return(GL_NO_ERROR)) |
2934 .WillOnce(Return(GL_NO_ERROR)) | 2914 .WillOnce(Return(GL_NO_ERROR)) |
2935 .RetiresOnSaturation(); | 2915 .RetiresOnSaturation(); |
2936 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation(); | 2916 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation(); |
2937 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId)) | 2917 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId)) |
2938 .Times(2) | 2918 .Times(2) |
2939 .RetiresOnSaturation(); | 2919 .RetiresOnSaturation(); |
2940 EXPECT_CALL(*image.get(), CopyTexImage(GL_TEXTURE_2D)) | 2920 // Image will be 'in use' as long as bound to a framebuffer. |
2941 .Times(1) | 2921 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation(); |
2942 .WillOnce(Return(true)) | |
2943 .RetiresOnSaturation(); | |
2944 EXPECT_CALL(*gl_, | 2922 EXPECT_CALL(*gl_, |
2945 FramebufferTexture2DEXT(GL_FRAMEBUFFER, | 2923 FramebufferTexture2DEXT(GL_FRAMEBUFFER, |
2946 GL_COLOR_ATTACHMENT0, | 2924 GL_COLOR_ATTACHMENT0, |
2947 GL_TEXTURE_2D, | 2925 GL_TEXTURE_2D, |
2948 kServiceTextureId, | 2926 kServiceTextureId, |
2949 0)) | 2927 0)) |
2950 .Times(1) | 2928 .Times(1) |
2951 .RetiresOnSaturation(); | 2929 .RetiresOnSaturation(); |
2952 EXPECT_CALL(*gl_, GetError()) | 2930 EXPECT_CALL(*gl_, GetError()) |
2953 .WillOnce(Return(GL_NO_ERROR)) | 2931 .WillOnce(Return(GL_NO_ERROR)) |
2954 .WillOnce(Return(GL_NO_ERROR)) | 2932 .WillOnce(Return(GL_NO_ERROR)) |
2955 .RetiresOnSaturation(); | 2933 .RetiresOnSaturation(); |
2956 FramebufferTexture2D fbtex_cmd; | 2934 FramebufferTexture2D fbtex_cmd; |
2957 fbtex_cmd.Init(GL_FRAMEBUFFER, | 2935 fbtex_cmd.Init(GL_FRAMEBUFFER, |
2958 GL_COLOR_ATTACHMENT0, | 2936 GL_COLOR_ATTACHMENT0, |
2959 GL_TEXTURE_2D, | 2937 GL_TEXTURE_2D, |
2960 client_texture_id_); | 2938 client_texture_id_); |
2961 EXPECT_EQ(error::kNoError, ExecuteCmd(fbtex_cmd)); | 2939 EXPECT_EQ(error::kNoError, ExecuteCmd(fbtex_cmd)); |
2962 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 2940 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
2963 | 2941 |
2964 EXPECT_CALL(*image.get(), Destroy(true)).Times(1).RetiresOnSaturation(); | 2942 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. |
2965 image = nullptr; | 2943 EXPECT_CALL(*gl_, GetError()) |
| 2944 .WillOnce(Return(GL_NO_ERROR)) |
| 2945 .WillOnce(Return(GL_NO_ERROR)) |
| 2946 .RetiresOnSaturation(); |
| 2947 EXPECT_CALL(*gl_, |
| 2948 FramebufferRenderbufferEXT(GL_FRAMEBUFFER, |
| 2949 GL_COLOR_ATTACHMENT0, |
| 2950 GL_RENDERBUFFER, |
| 2951 kServiceRenderbufferId)) |
| 2952 .Times(1) |
| 2953 .RetiresOnSaturation(); |
| 2954 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation(); |
| 2955 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId)) |
| 2956 .Times(2) |
| 2957 .RetiresOnSaturation(); |
| 2958 // Image should no longer be 'in use' after being unbound from framebuffer. |
| 2959 EXPECT_CALL(*image.get(), DidUseTexImage()).Times(1).RetiresOnSaturation(); |
| 2960 EXPECT_CALL(*gl_, GetError()) |
| 2961 .WillOnce(Return(GL_NO_ERROR)) |
| 2962 .WillOnce(Return(GL_NO_ERROR)) |
| 2963 .RetiresOnSaturation(); |
| 2964 FramebufferRenderbuffer fbrb_cmd; |
| 2965 fbrb_cmd.Init(GL_FRAMEBUFFER, |
| 2966 GL_COLOR_ATTACHMENT0, |
| 2967 GL_RENDERBUFFER, |
| 2968 client_renderbuffer_id_); |
| 2969 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd)); |
2966 } | 2970 } |
2967 | 2971 |
2968 TEST_P(GLES2DecoderManualInitTest, DrawWithGLImageExternal) { | 2972 TEST_P(GLES2DecoderManualInitTest, DrawWithGLImageExternal) { |
2969 InitState init; | 2973 InitState init; |
2970 init.extensions = "GL_OES_EGL_image_external"; | 2974 init.extensions = "GL_OES_EGL_image_external"; |
2971 init.gl_version = "opengl es 2.0"; | 2975 init.gl_version = "opengl es 2.0"; |
2972 init.has_alpha = true; | 2976 init.has_alpha = true; |
2973 init.has_depth = true; | 2977 init.has_depth = true; |
2974 init.request_alpha = true; | 2978 init.request_alpha = true; |
2975 init.request_depth = true; | 2979 init.request_depth = true; |
2976 init.bind_generates_resource = true; | 2980 init.bind_generates_resource = true; |
2977 InitDecoder(init); | 2981 InitDecoder(init); |
2978 | 2982 |
2979 TextureRef* texture_ref = GetTexture(client_texture_id_); | 2983 TextureRef* texture_ref = GetTexture(client_texture_id_); |
2980 scoped_refptr<MockGLImage> image(new MockGLImage); | 2984 scoped_refptr<MockGLImage> image(new MockGLImage); |
2981 group().texture_manager()->SetTarget(texture_ref, GL_TEXTURE_EXTERNAL_OES); | 2985 group().texture_manager()->SetTarget(texture_ref, GL_TEXTURE_EXTERNAL_OES); |
2982 group().texture_manager()->SetLevelInfo(texture_ref, GL_TEXTURE_EXTERNAL_OES, | 2986 group().texture_manager()->SetLevelInfo(texture_ref, GL_TEXTURE_EXTERNAL_OES, |
2983 0, GL_RGBA, 0, 0, 1, 0, GL_RGBA, | 2987 0, GL_RGBA, 0, 0, 1, 0, GL_RGBA, |
2984 GL_UNSIGNED_BYTE, gfx::Rect()); | 2988 GL_UNSIGNED_BYTE, gfx::Rect()); |
2985 group().texture_manager()->SetLevelImage(texture_ref, GL_TEXTURE_EXTERNAL_OES, | 2989 group().texture_manager()->SetLevelImage( |
2986 0, image.get(), Texture::BOUND); | 2990 texture_ref, GL_TEXTURE_EXTERNAL_OES, 0, image.get()); |
2987 | 2991 |
2988 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId); | 2992 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId); |
2989 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 2993 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
2990 | 2994 |
2991 SetupSamplerExternalProgram(); | 2995 SetupSamplerExternalProgram(); |
2992 SetupIndexBuffer(); | 2996 SetupIndexBuffer(); |
2993 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0); | 2997 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0); |
2994 SetupExpectationsForApplyingDefaultDirtyState(); | 2998 SetupExpectationsForApplyingDefaultDirtyState(); |
2995 EXPECT_TRUE(group().texture_manager()->CanRender(texture_ref)); | 2999 EXPECT_TRUE(group().texture_manager()->CanRender(texture_ref)); |
2996 | 3000 |
2997 InSequence s; | 3001 InSequence s; |
| 3002 EXPECT_CALL(*gl_, GetError()) |
| 3003 .WillOnce(Return(GL_NO_ERROR)) |
| 3004 .RetiresOnSaturation(); |
| 3005 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation(); |
| 3006 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation(); |
| 3007 EXPECT_CALL(*gl_, GetError()) |
| 3008 .WillOnce(Return(GL_NO_ERROR)) |
| 3009 .RetiresOnSaturation(); |
2998 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(1); | 3010 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(1); |
| 3011 EXPECT_CALL(*gl_, GetError()) |
| 3012 .WillOnce(Return(GL_NO_ERROR)) |
| 3013 .RetiresOnSaturation(); |
| 3014 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation(); |
| 3015 EXPECT_CALL(*image.get(), DidUseTexImage()).Times(1).RetiresOnSaturation(); |
| 3016 EXPECT_CALL(*gl_, GetError()) |
| 3017 .WillOnce(Return(GL_NO_ERROR)) |
| 3018 .RetiresOnSaturation(); |
| 3019 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation(); |
2999 DrawElements cmd; | 3020 DrawElements cmd; |
3000 cmd.Init(GL_TRIANGLES, | 3021 cmd.Init(GL_TRIANGLES, |
3001 kValidIndexRangeCount, | 3022 kValidIndexRangeCount, |
3002 GL_UNSIGNED_SHORT, | 3023 GL_UNSIGNED_SHORT, |
3003 kValidIndexRangeStart * 2); | 3024 kValidIndexRangeStart * 2); |
3004 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 3025 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
3005 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 3026 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
3006 } | 3027 } |
3007 | 3028 |
3008 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatOnGLES2) { | 3029 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatOnGLES2) { |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3363 // TODO(gman): CompressedTexSubImage2DImmediate | 3384 // TODO(gman): CompressedTexSubImage2DImmediate |
3364 | 3385 |
3365 // TODO(gman): TexImage2D | 3386 // TODO(gman): TexImage2D |
3366 | 3387 |
3367 // TODO(gman): TexImage2DImmediate | 3388 // TODO(gman): TexImage2DImmediate |
3368 | 3389 |
3369 // TODO(gman): TexSubImage2DImmediate | 3390 // TODO(gman): TexSubImage2DImmediate |
3370 | 3391 |
3371 } // namespace gles2 | 3392 } // namespace gles2 |
3372 } // namespace gpu | 3393 } // namespace gpu |
OLD | NEW |