Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc

Issue 11428140: gpu: Add async pixel transfer interface, stub and tests. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address Feedback. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 7917 matching lines...) Expand 10 before | Expand all | Expand 10 after
7968 7970
7969 EXPECT_TRUE(info->pool() == GL_TEXTURE_POOL_MANAGED_CHROMIUM); 7971 EXPECT_TRUE(info->pool() == GL_TEXTURE_POOL_MANAGED_CHROMIUM);
7970 7972
7971 cmd.Init(GL_TEXTURE_2D, 7973 cmd.Init(GL_TEXTURE_2D,
7972 GL_TEXTURE_POOL_CHROMIUM, 7974 GL_TEXTURE_POOL_CHROMIUM,
7973 GL_NONE); 7975 GL_NONE);
7974 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 7976 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7975 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 7977 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
7976 } 7978 }
7977 7979
7980 TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransfers) {
7981 InitDecoder(
7982 "GL_CHROMIUM_async_pixel_transfers", // extensions
7983 false, false, false, // has alpha/depth/stencil
7984 false, false, false, // request alpha/depth/stencil
7985 true); // bind generates resource
7986
7987 // Set up the texture.
7988 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
7989 TextureManager::TextureInfo* info = GetTextureInfo(client_texture_id_);
7990
7991 // Set a mock Async delegate
7992 // Async state is returned as a scoped_ptr, but we keep a raw copy.
7993 StrictMock<gfx::MockAsyncPixelTransferDelegate>* delegate =
7994 new StrictMock<gfx::MockAsyncPixelTransferDelegate>;
7995 decoder_->SetAsyncPixelTransferDelegate(delegate);
7996 StrictMock<gfx::MockAsyncPixelTransferState>* state = NULL;
7997
7998 // Tex(Sub)Image2D upload commands.
7999 AsyncTexImage2DCHROMIUM teximage_cmd;
8000 teximage_cmd.Init(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA,
8001 GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset);
8002 AsyncTexSubImage2DCHROMIUM texsubimage_cmd;
8003 texsubimage_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGBA,
8004 GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset);
8005 gfx::AsyncTexImage2DParams teximage_params =
8006 {GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE};
8007
8008 // No transfer state exists initially.
8009 EXPECT_FALSE(info->GetAsyncTransferState());
8010
8011 // AsyncTexImage2D
8012 {
8013 // Create transfer state since it doesn't exist.
8014 EXPECT_CALL(*delegate, CreateRawPixelTransferState(kServiceTextureId))
8015 .WillOnce(Return(
8016 state = new StrictMock<gfx::MockAsyncPixelTransferState>))
8017 .RetiresOnSaturation();
8018 EXPECT_CALL(*delegate, AsyncTexImage2D(state, _, _))
8019 .RetiresOnSaturation();
8020 // Command succeeds.
8021 EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd));
8022 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8023 EXPECT_TRUE(info->GetAsyncTransferState());
8024 EXPECT_TRUE(info->IsImmutable());
8025 // The texture is safe but the level has not been defined yet.
8026 EXPECT_TRUE(info->SafeToRenderFrom());
8027 GLsizei width, height;
8028 EXPECT_FALSE(info->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
8029 }
8030 {
8031 // Async redefinitions are not allowed!
8032 // Command fails.
8033 EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd));
8034 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
8035 EXPECT_TRUE(info->GetAsyncTransferState());
8036 EXPECT_TRUE(info->IsImmutable());
8037 EXPECT_TRUE(info->SafeToRenderFrom());
8038 }
8039
8040 // Lazy binding/defining of the async transfer
8041 {
8042 // We the code should check that the transfer is done,
8043 // call bind transfer on it, and update the texture info.
8044 InSequence scoped_in_sequence;
8045 EXPECT_CALL(*state, TransferIsInProgress())
8046 .WillOnce(Return(false))
8047 .RetiresOnSaturation();
8048 EXPECT_CALL(*state, BindTransfer(_))
8049 .WillOnce(SetArgPointee<0>(teximage_params))
8050 .RetiresOnSaturation();
8051 TextureManager* manager = decoder_->GetContextGroup()->texture_manager();
8052 bool texture_dirty, framebuffer_dirty;
8053 manager->BindFinishedAsyncPixelTransfers(&texture_dirty,
8054 &framebuffer_dirty);
8055 EXPECT_TRUE(texture_dirty);
8056 EXPECT_FALSE(framebuffer_dirty);
8057 // Texture is safe, and has the right size etc.
8058 EXPECT_TRUE(info->SafeToRenderFrom());
8059 GLsizei width, height;
8060 EXPECT_TRUE(info->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
8061 EXPECT_EQ(width, 8);
8062 EXPECT_EQ(height, 8);
8063 }
8064
8065 // AsyncTexSubImage2D
8066 info->SetAsyncTransferState(scoped_ptr<gfx::AsyncPixelTransferState>());
8067 info->SetImmutable(false);
8068 {
8069 // Create transfer state since it doesn't exist.
8070 EXPECT_CALL(*delegate, CreateRawPixelTransferState(kServiceTextureId))
8071 .WillOnce(Return(
8072 state = new StrictMock<gfx::MockAsyncPixelTransferState>))
8073 .RetiresOnSaturation();
8074 EXPECT_CALL(*delegate, AsyncTexSubImage2D(state, _, _))
8075 .RetiresOnSaturation();
8076 // Command succeeds.
8077 EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd));
8078 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8079 EXPECT_TRUE(info->GetAsyncTransferState());
8080 EXPECT_TRUE(info->IsImmutable());
8081 EXPECT_TRUE(info->SafeToRenderFrom());
8082 }
8083 {
8084 // No transfer is in progress.
8085 EXPECT_CALL(*state, TransferIsInProgress())
8086 .WillOnce(Return(false)) // texSubImage validation
8087 .WillOnce(Return(false)) // async validation
8088 .RetiresOnSaturation();
8089 EXPECT_CALL(*delegate, AsyncTexSubImage2D(state, _, _))
8090 .RetiresOnSaturation();
8091 // Command succeeds.
8092 EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd));
8093 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8094 EXPECT_TRUE(info->GetAsyncTransferState());
8095 EXPECT_TRUE(info->IsImmutable());
8096 EXPECT_TRUE(info->SafeToRenderFrom());
8097 }
8098 {
8099 // A transfer is still in progress!
8100 EXPECT_CALL(*state, TransferIsInProgress())
8101 .WillOnce(Return(true))
8102 .RetiresOnSaturation();
8103 // No async call, command fails.
8104 EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd));
8105 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
8106 EXPECT_TRUE(info->GetAsyncTransferState());
8107 EXPECT_TRUE(info->IsImmutable());
8108 EXPECT_TRUE(info->SafeToRenderFrom());
8109 }
8110
8111 decoder_->SetAsyncPixelTransferDelegate(NULL);
8112 info->SetAsyncTransferState(scoped_ptr<gfx::AsyncPixelTransferState>());
8113 }
8114
7978 // TODO(gman): Complete this test. 8115 // TODO(gman): Complete this test.
7979 // TEST_F(GLES2DecoderTest, CompressedTexImage2DGLError) { 8116 // TEST_F(GLES2DecoderTest, CompressedTexImage2DGLError) {
7980 // } 8117 // }
7981 8118
7982 // TODO(gman): BufferData 8119 // TODO(gman): BufferData
7983 8120
7984 // TODO(gman): BufferDataImmediate 8121 // TODO(gman): BufferDataImmediate
7985 8122
7986 // TODO(gman): BufferSubData 8123 // TODO(gman): BufferSubData
7987 8124
(...skipping 16 matching lines...) Expand all
8004 // TODO(gman): TexImage2DImmediate 8141 // TODO(gman): TexImage2DImmediate
8005 8142
8006 // TODO(gman): TexSubImage2DImmediate 8143 // TODO(gman): TexSubImage2DImmediate
8007 8144
8008 // TODO(gman): UseProgram 8145 // TODO(gman): UseProgram
8009 8146
8010 // TODO(gman): SwapBuffers 8147 // TODO(gman): SwapBuffers
8011 8148
8012 } // namespace gles2 8149 } // namespace gles2
8013 } // namespace gpu 8150 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder_mock.h ('k') | gpu/command_buffer/service/query_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698