OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/atomicops.h" | 7 #include "base/atomicops.h" |
8 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 8 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
9 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 9 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
10 #include "gpu/command_buffer/common/id_allocator.h" | 10 #include "gpu/command_buffer/common/id_allocator.h" |
| 11 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h" |
11 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 12 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
12 #include "gpu/command_buffer/service/context_group.h" | 13 #include "gpu/command_buffer/service/context_group.h" |
13 #include "gpu/command_buffer/service/gl_surface_mock.h" | 14 #include "gpu/command_buffer/service/gl_surface_mock.h" |
14 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h" | 15 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h" |
15 #include "gpu/command_buffer/service/image_manager.h" | 16 #include "gpu/command_buffer/service/image_manager.h" |
16 #include "gpu/command_buffer/service/mailbox_manager.h" | 17 #include "gpu/command_buffer/service/mailbox_manager.h" |
17 #include "gpu/command_buffer/service/program_manager.h" | 18 #include "gpu/command_buffer/service/program_manager.h" |
18 #include "gpu/command_buffer/service/stream_texture_manager_mock.h" | 19 #include "gpu/command_buffer/service/stream_texture_manager_mock.h" |
19 #include "gpu/command_buffer/service/stream_texture_mock.h" | 20 #include "gpu/command_buffer/service/stream_texture_mock.h" |
20 #include "gpu/command_buffer/service/test_helper.h" | 21 #include "gpu/command_buffer/service/test_helper.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "ui/gl/gl_implementation.h" | 23 #include "ui/gl/gl_implementation.h" |
23 #include "ui/gl/gl_mock.h" | 24 #include "ui/gl/gl_mock.h" |
24 #include "ui/gl/gl_surface_stub.h" | 25 #include "ui/gl/gl_surface_stub.h" |
25 | 26 |
26 | 27 |
27 #if !defined(GL_DEPTH24_STENCIL8) | 28 #if !defined(GL_DEPTH24_STENCIL8) |
28 #define GL_DEPTH24_STENCIL8 0x88F0 | 29 #define GL_DEPTH24_STENCIL8 0x88F0 |
29 #endif | 30 #endif |
30 | 31 |
31 using ::gfx::MockGLInterface; | 32 using ::gfx::MockGLInterface; |
32 using ::testing::_; | 33 using ::testing::_; |
| 34 using ::testing::DefaultValue; |
33 using ::testing::DoAll; | 35 using ::testing::DoAll; |
34 using ::testing::InSequence; | 36 using ::testing::InSequence; |
35 using ::testing::Invoke; | 37 using ::testing::Invoke; |
36 using ::testing::MatcherCast; | 38 using ::testing::MatcherCast; |
37 using ::testing::Pointee; | 39 using ::testing::Pointee; |
38 using ::testing::Return; | 40 using ::testing::Return; |
39 using ::testing::SetArrayArgument; | 41 using ::testing::SetArrayArgument; |
40 using ::testing::SetArgumentPointee; | 42 using ::testing::SetArgumentPointee; |
| 43 using ::testing::SetArgPointee; |
41 using ::testing::StrEq; | 44 using ::testing::StrEq; |
42 using ::testing::StrictMock; | 45 using ::testing::StrictMock; |
43 | 46 |
44 namespace gpu { | 47 namespace gpu { |
45 namespace gles2 { | 48 namespace gles2 { |
46 | 49 |
47 class GLES2DecoderTest : public GLES2DecoderTestBase { | 50 class GLES2DecoderTest : public GLES2DecoderTestBase { |
48 public: | 51 public: |
49 GLES2DecoderTest() { } | 52 GLES2DecoderTest() { } |
50 | 53 |
(...skipping 7877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7928 | 7931 |
7929 // Release image from texture. | 7932 // Release image from texture. |
7930 ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd; | 7933 ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd; |
7931 release_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1); | 7934 release_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1); |
7932 EXPECT_EQ(error::kNoError, ExecuteCmd(release_tex_image_2d_cmd)); | 7935 EXPECT_EQ(error::kNoError, ExecuteCmd(release_tex_image_2d_cmd)); |
7933 EXPECT_TRUE(info->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); | 7936 EXPECT_TRUE(info->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); |
7934 // Image should no longer be set. | 7937 // Image should no longer be set. |
7935 EXPECT_TRUE(info->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); | 7938 EXPECT_TRUE(info->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); |
7936 } | 7939 } |
7937 | 7940 |
| 7941 TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransfers) { |
| 7942 InitDecoder( |
| 7943 "GL_CHROMIUM_async_pixel_transfers", // extensions |
| 7944 false, false, false, // has alpha/depth/stencil |
| 7945 false, false, false, // request alpha/depth/stencil |
| 7946 true); // bind generates resource |
| 7947 |
| 7948 // Set up the texture. |
| 7949 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); |
| 7950 TextureManager::TextureInfo* info = GetTextureInfo(client_texture_id_); |
| 7951 |
| 7952 // Set a mock AsyncPixelTransferDelegate |
| 7953 StrictMock<gfx::MockAsyncPixelTransferDelegate>* delegate = |
| 7954 new StrictMock<gfx::MockAsyncPixelTransferDelegate>; |
| 7955 decoder_->SetAsyncPixelTransferDelegate(delegate); |
| 7956 |
| 7957 // Set a default mock AsyncPixelTransferState |
| 7958 scoped_refptr<StrictMock<gfx::MockAsyncPixelTransferState> > state = |
| 7959 new StrictMock<gfx::MockAsyncPixelTransferState>; |
| 7960 DefaultValue<scoped_refptr<gfx::AsyncPixelTransferState> >::Set(state); |
| 7961 |
| 7962 // Tex(Sub)Image2D upload commands. |
| 7963 AsyncTexImage2DCHROMIUM teximage_cmd; |
| 7964 teximage_cmd.Init(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, |
| 7965 GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset); |
| 7966 AsyncTexSubImage2DCHROMIUM texsubimage_cmd; |
| 7967 texsubimage_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGBA, |
| 7968 GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset); |
| 7969 gfx::AsyncTexImage2DParams teximage_params = |
| 7970 {GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE}; |
| 7971 |
| 7972 // No transfer state exists initially. |
| 7973 EXPECT_FALSE(info->GetAsyncTransferState()); |
| 7974 |
| 7975 // AsyncTexImage2D |
| 7976 { |
| 7977 // Create transfer state since it doesn't exist. |
| 7978 EXPECT_CALL(*delegate, CreatePixelTransferState(kServiceTextureId)) |
| 7979 .WillOnce(Return(state)) |
| 7980 .RetiresOnSaturation(); |
| 7981 EXPECT_CALL(*delegate, AsyncTexImage2D(state.get(), _, _)) |
| 7982 .RetiresOnSaturation(); |
| 7983 // Command succeeds. |
| 7984 EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd)); |
| 7985 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 7986 EXPECT_TRUE(info->GetAsyncTransferState()); |
| 7987 EXPECT_TRUE(info->IsImmutable()); |
| 7988 // The texture is safe but the level has not been defined yet. |
| 7989 EXPECT_TRUE(info->SafeToRenderFrom()); |
| 7990 GLsizei width, height; |
| 7991 EXPECT_FALSE(info->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); |
| 7992 } |
| 7993 { |
| 7994 // Async redefinitions are not allowed! |
| 7995 // Command fails. |
| 7996 EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd)); |
| 7997 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| 7998 EXPECT_TRUE(info->GetAsyncTransferState()); |
| 7999 EXPECT_TRUE(info->IsImmutable()); |
| 8000 EXPECT_TRUE(info->SafeToRenderFrom()); |
| 8001 } |
| 8002 // Lazy binding/defining of the async transfer |
| 8003 { |
| 8004 // We should get a real glBindTexture, followed by |
| 8005 // a lazy BindTransfer call on the async state. |
| 8006 // The texture becomes defined after the BindTransfer succeeds. |
| 8007 InSequence scoped_in_sequence; |
| 8008 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId)); |
| 8009 EXPECT_CALL(*state.get(), BindTransfer(GL_TEXTURE_2D, _)) |
| 8010 .WillOnce(DoAll(SetArgPointee<1>(teximage_params), |
| 8011 Return(true))) |
| 8012 .RetiresOnSaturation(); |
| 8013 BindTexture bind_cmd; |
| 8014 bind_cmd.Init(GL_TEXTURE_2D, client_texture_id_); |
| 8015 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_cmd)); |
| 8016 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 8017 EXPECT_TRUE(info->SafeToRenderFrom()); |
| 8018 GLsizei width, height; |
| 8019 EXPECT_TRUE(info->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); |
| 8020 EXPECT_EQ(width, 8); |
| 8021 EXPECT_EQ(height, 8); |
| 8022 } |
| 8023 |
| 8024 // AsyncTexSubImage2D |
| 8025 info->SetAsyncTransferState(NULL); |
| 8026 info->SetImmutable(false); |
| 8027 { |
| 8028 // Create transfer state since it doesn't exist. |
| 8029 EXPECT_CALL(*delegate, CreatePixelTransferState(kServiceTextureId)) |
| 8030 .WillOnce(Return(state)) |
| 8031 .RetiresOnSaturation(); |
| 8032 EXPECT_CALL(*delegate, AsyncTexSubImage2D(state.get(), _, _)) |
| 8033 .RetiresOnSaturation(); |
| 8034 // Command succeeds. |
| 8035 EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd)); |
| 8036 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 8037 EXPECT_TRUE(info->GetAsyncTransferState()); |
| 8038 EXPECT_TRUE(info->IsImmutable()); |
| 8039 EXPECT_TRUE(info->SafeToRenderFrom()); |
| 8040 } |
| 8041 { |
| 8042 // No transfer is in progress. |
| 8043 EXPECT_CALL(*state.get(), TransferIsInProgress()) |
| 8044 .WillOnce(Return(false)) |
| 8045 .RetiresOnSaturation(); |
| 8046 EXPECT_CALL(*delegate, AsyncTexSubImage2D(state.get(), _, _)) |
| 8047 .RetiresOnSaturation(); |
| 8048 // Command succeeds. |
| 8049 EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd)); |
| 8050 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 8051 EXPECT_TRUE(info->GetAsyncTransferState()); |
| 8052 EXPECT_TRUE(info->IsImmutable()); |
| 8053 EXPECT_TRUE(info->SafeToRenderFrom()); |
| 8054 } |
| 8055 { |
| 8056 // A transfer is still in progress! |
| 8057 EXPECT_CALL(*state.get(), TransferIsInProgress()) |
| 8058 .WillOnce(Return(true)) |
| 8059 .RetiresOnSaturation(); |
| 8060 // No async call, command fails. |
| 8061 EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd)); |
| 8062 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| 8063 EXPECT_TRUE(info->GetAsyncTransferState()); |
| 8064 EXPECT_TRUE(info->IsImmutable()); |
| 8065 EXPECT_TRUE(info->SafeToRenderFrom()); |
| 8066 } |
| 8067 |
| 8068 decoder_->SetAsyncPixelTransferDelegate(NULL); |
| 8069 DefaultValue<scoped_refptr<gfx::AsyncPixelTransferState> >::Set(NULL); |
| 8070 } |
| 8071 |
| 8072 |
7938 // TODO(gman): Complete this test. | 8073 // TODO(gman): Complete this test. |
7939 // TEST_F(GLES2DecoderTest, CompressedTexImage2DGLError) { | 8074 // TEST_F(GLES2DecoderTest, CompressedTexImage2DGLError) { |
7940 // } | 8075 // } |
7941 | 8076 |
7942 // TODO(gman): BufferData | 8077 // TODO(gman): BufferData |
7943 | 8078 |
7944 // TODO(gman): BufferDataImmediate | 8079 // TODO(gman): BufferDataImmediate |
7945 | 8080 |
7946 // TODO(gman): BufferSubData | 8081 // TODO(gman): BufferSubData |
7947 | 8082 |
(...skipping 16 matching lines...) Expand all Loading... |
7964 // TODO(gman): TexImage2DImmediate | 8099 // TODO(gman): TexImage2DImmediate |
7965 | 8100 |
7966 // TODO(gman): TexSubImage2DImmediate | 8101 // TODO(gman): TexSubImage2DImmediate |
7967 | 8102 |
7968 // TODO(gman): UseProgram | 8103 // TODO(gman): UseProgram |
7969 | 8104 |
7970 // TODO(gman): SwapBuffers | 8105 // TODO(gman): SwapBuffers |
7971 | 8106 |
7972 } // namespace gles2 | 8107 } // namespace gles2 |
7973 } // namespace gpu | 8108 } // namespace gpu |
OLD | NEW |