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" |
(...skipping 10 matching lines...) Expand all Loading... |
31 using ::gfx::MockGLInterface; | 32 using ::gfx::MockGLInterface; |
32 using ::testing::_; | 33 using ::testing::_; |
33 using ::testing::DoAll; | 34 using ::testing::DoAll; |
34 using ::testing::InSequence; | 35 using ::testing::InSequence; |
35 using ::testing::Invoke; | 36 using ::testing::Invoke; |
36 using ::testing::MatcherCast; | 37 using ::testing::MatcherCast; |
37 using ::testing::Pointee; | 38 using ::testing::Pointee; |
38 using ::testing::Return; | 39 using ::testing::Return; |
39 using ::testing::SetArrayArgument; | 40 using ::testing::SetArrayArgument; |
40 using ::testing::SetArgumentPointee; | 41 using ::testing::SetArgumentPointee; |
| 42 using ::testing::SetArgPointee; |
41 using ::testing::StrEq; | 43 using ::testing::StrEq; |
42 using ::testing::StrictMock; | 44 using ::testing::StrictMock; |
43 | 45 |
44 namespace gpu { | 46 namespace gpu { |
45 namespace gles2 { | 47 namespace gles2 { |
46 | 48 |
47 class GLES2DecoderTest : public GLES2DecoderTestBase { | 49 class GLES2DecoderTest : public GLES2DecoderTestBase { |
48 public: | 50 public: |
49 GLES2DecoderTest() { } | 51 GLES2DecoderTest() { } |
50 | 52 |
(...skipping 7877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7928 | 7930 |
7929 // Release image from texture. | 7931 // Release image from texture. |
7930 ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd; | 7932 ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd; |
7931 release_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1); | 7933 release_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1); |
7932 EXPECT_EQ(error::kNoError, ExecuteCmd(release_tex_image_2d_cmd)); | 7934 EXPECT_EQ(error::kNoError, ExecuteCmd(release_tex_image_2d_cmd)); |
7933 EXPECT_TRUE(info->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); | 7935 EXPECT_TRUE(info->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); |
7934 // Image should no longer be set. | 7936 // Image should no longer be set. |
7935 EXPECT_TRUE(info->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); | 7937 EXPECT_TRUE(info->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); |
7936 } | 7938 } |
7937 | 7939 |
| 7940 TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransfers) { |
| 7941 InitDecoder( |
| 7942 "GL_CHROMIUM_async_pixel_transfers", // extensions |
| 7943 false, false, false, // has alpha/depth/stencil |
| 7944 false, false, false, // request alpha/depth/stencil |
| 7945 true); // bind generates resource |
| 7946 |
| 7947 // Set up the texture. |
| 7948 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); |
| 7949 TextureManager::TextureInfo* info = GetTextureInfo(client_texture_id_); |
| 7950 |
| 7951 // Set a mock Async delegate |
| 7952 // Async state is returned as a scoped_ptr, but we keep a raw copy. |
| 7953 StrictMock<gfx::MockAsyncPixelTransferDelegate>* delegate = |
| 7954 new StrictMock<gfx::MockAsyncPixelTransferDelegate>; |
| 7955 decoder_->SetAsyncPixelTransferDelegate(delegate); |
| 7956 StrictMock<gfx::MockAsyncPixelTransferState>* state = NULL; |
| 7957 |
| 7958 // Tex(Sub)Image2D upload commands. |
| 7959 AsyncTexImage2DCHROMIUM teximage_cmd; |
| 7960 teximage_cmd.Init(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, |
| 7961 GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset); |
| 7962 AsyncTexSubImage2DCHROMIUM texsubimage_cmd; |
| 7963 texsubimage_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGBA, |
| 7964 GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset); |
| 7965 gfx::AsyncTexImage2DParams teximage_params = |
| 7966 {GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE}; |
| 7967 |
| 7968 // No transfer state exists initially. |
| 7969 EXPECT_FALSE(info->GetAsyncTransferState()); |
| 7970 |
| 7971 // AsyncTexImage2D |
| 7972 { |
| 7973 // Create transfer state since it doesn't exist. |
| 7974 EXPECT_CALL(*delegate, CreateRawPixelTransferState(kServiceTextureId)) |
| 7975 .WillOnce(Return( |
| 7976 state = new StrictMock<gfx::MockAsyncPixelTransferState>)) |
| 7977 .RetiresOnSaturation(); |
| 7978 EXPECT_CALL(*delegate, AsyncTexImage2D(state, _, _)) |
| 7979 .RetiresOnSaturation(); |
| 7980 // Command succeeds. |
| 7981 EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd)); |
| 7982 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 7983 EXPECT_TRUE(info->GetAsyncTransferState()); |
| 7984 EXPECT_TRUE(info->IsImmutable()); |
| 7985 // The texture is safe but the level has not been defined yet. |
| 7986 EXPECT_TRUE(info->SafeToRenderFrom()); |
| 7987 GLsizei width, height; |
| 7988 EXPECT_FALSE(info->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); |
| 7989 } |
| 7990 { |
| 7991 // Async redefinitions are not allowed! |
| 7992 // Command fails. |
| 7993 EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd)); |
| 7994 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| 7995 EXPECT_TRUE(info->GetAsyncTransferState()); |
| 7996 EXPECT_TRUE(info->IsImmutable()); |
| 7997 EXPECT_TRUE(info->SafeToRenderFrom()); |
| 7998 } |
| 7999 |
| 8000 // Lazy binding/defining of the async transfer |
| 8001 { |
| 8002 // We the code should check that the transfer is done, |
| 8003 // call bind transfer on it, and update the texture info. |
| 8004 InSequence scoped_in_sequence; |
| 8005 EXPECT_CALL(*state, TransferIsInProgress()) |
| 8006 .WillOnce(Return(false)) |
| 8007 .RetiresOnSaturation(); |
| 8008 EXPECT_CALL(*state, BindTransfer(_)) |
| 8009 .WillOnce(SetArgPointee<0>(teximage_params)) |
| 8010 .RetiresOnSaturation(); |
| 8011 TextureManager* manager = decoder_->GetContextGroup()->texture_manager(); |
| 8012 bool texture_dirty, framebuffer_dirty; |
| 8013 manager->BindFinishedAsyncPixelTransfers(&texture_dirty, |
| 8014 &framebuffer_dirty); |
| 8015 EXPECT_TRUE(texture_dirty); |
| 8016 EXPECT_FALSE(framebuffer_dirty); |
| 8017 // Texture is safe, and has the right size etc. |
| 8018 EXPECT_TRUE(info->SafeToRenderFrom()); |
| 8019 GLsizei width, height; |
| 8020 EXPECT_TRUE(info->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); |
| 8021 EXPECT_EQ(width, 8); |
| 8022 EXPECT_EQ(height, 8); |
| 8023 } |
| 8024 |
| 8025 // AsyncTexSubImage2D |
| 8026 info->SetAsyncTransferState(scoped_ptr<gfx::AsyncPixelTransferState>()); |
| 8027 info->SetImmutable(false); |
| 8028 { |
| 8029 // Create transfer state since it doesn't exist. |
| 8030 EXPECT_CALL(*delegate, CreateRawPixelTransferState(kServiceTextureId)) |
| 8031 .WillOnce(Return( |
| 8032 state = new StrictMock<gfx::MockAsyncPixelTransferState>)) |
| 8033 .RetiresOnSaturation(); |
| 8034 EXPECT_CALL(*delegate, AsyncTexSubImage2D(state, _, _)) |
| 8035 .RetiresOnSaturation(); |
| 8036 // Command succeeds. |
| 8037 EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd)); |
| 8038 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 8039 EXPECT_TRUE(info->GetAsyncTransferState()); |
| 8040 EXPECT_TRUE(info->IsImmutable()); |
| 8041 EXPECT_TRUE(info->SafeToRenderFrom()); |
| 8042 } |
| 8043 { |
| 8044 // No transfer is in progress. |
| 8045 EXPECT_CALL(*state, TransferIsInProgress()) |
| 8046 .WillOnce(Return(false)) |
| 8047 .RetiresOnSaturation(); |
| 8048 EXPECT_CALL(*delegate, AsyncTexSubImage2D(state, _, _)) |
| 8049 .RetiresOnSaturation(); |
| 8050 // Command succeeds. |
| 8051 EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd)); |
| 8052 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 8053 EXPECT_TRUE(info->GetAsyncTransferState()); |
| 8054 EXPECT_TRUE(info->IsImmutable()); |
| 8055 EXPECT_TRUE(info->SafeToRenderFrom()); |
| 8056 } |
| 8057 { |
| 8058 // A transfer is still in progress! |
| 8059 EXPECT_CALL(*state, TransferIsInProgress()) |
| 8060 .WillOnce(Return(true)) |
| 8061 .RetiresOnSaturation(); |
| 8062 // No async call, command fails. |
| 8063 EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd)); |
| 8064 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| 8065 EXPECT_TRUE(info->GetAsyncTransferState()); |
| 8066 EXPECT_TRUE(info->IsImmutable()); |
| 8067 EXPECT_TRUE(info->SafeToRenderFrom()); |
| 8068 } |
| 8069 |
| 8070 decoder_->SetAsyncPixelTransferDelegate(NULL); |
| 8071 info->SetAsyncTransferState(scoped_ptr<gfx::AsyncPixelTransferState>()); |
| 8072 } |
| 8073 |
| 8074 |
7938 // TODO(gman): Complete this test. | 8075 // TODO(gman): Complete this test. |
7939 // TEST_F(GLES2DecoderTest, CompressedTexImage2DGLError) { | 8076 // TEST_F(GLES2DecoderTest, CompressedTexImage2DGLError) { |
7940 // } | 8077 // } |
7941 | 8078 |
7942 // TODO(gman): BufferData | 8079 // TODO(gman): BufferData |
7943 | 8080 |
7944 // TODO(gman): BufferDataImmediate | 8081 // TODO(gman): BufferDataImmediate |
7945 | 8082 |
7946 // TODO(gman): BufferSubData | 8083 // TODO(gman): BufferSubData |
7947 | 8084 |
(...skipping 16 matching lines...) Expand all Loading... |
7964 // TODO(gman): TexImage2DImmediate | 8101 // TODO(gman): TexImage2DImmediate |
7965 | 8102 |
7966 // TODO(gman): TexSubImage2DImmediate | 8103 // TODO(gman): TexSubImage2DImmediate |
7967 | 8104 |
7968 // TODO(gman): UseProgram | 8105 // TODO(gman): UseProgram |
7969 | 8106 |
7970 // TODO(gman): SwapBuffers | 8107 // TODO(gman): SwapBuffers |
7971 | 8108 |
7972 } // namespace gles2 | 8109 } // namespace gles2 |
7973 } // namespace gpu | 8110 } // namespace gpu |
OLD | NEW |