| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 6 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 7 #include "gpu/command_buffer/service/gl_mock.h" | 7 #include "gpu/command_buffer/service/gl_mock.h" |
| 8 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 8 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 using ::gles2::MockGLInterface; |
| 11 using ::testing::_; | 12 using ::testing::_; |
| 12 using ::testing::DoAll; | 13 using ::testing::DoAll; |
| 13 using ::testing::InSequence; | 14 using ::testing::InSequence; |
| 14 using ::testing::MatcherCast; | 15 using ::testing::MatcherCast; |
| 15 using ::testing::Pointee; | 16 using ::testing::Pointee; |
| 16 using ::testing::Return; | 17 using ::testing::Return; |
| 17 using ::testing::SetArrayArgument; | 18 using ::testing::SetArrayArgument; |
| 18 using ::testing::SetArgumentPointee; | 19 using ::testing::SetArgumentPointee; |
| 19 using ::testing::StrEq; | 20 using ::testing::StrEq; |
| 20 | 21 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 T* GetImmediateAs() { | 77 T* GetImmediateAs() { |
| 77 return reinterpret_cast<T*>(immediate_buffer_); | 78 return reinterpret_cast<T*>(immediate_buffer_); |
| 78 } | 79 } |
| 79 | 80 |
| 80 template <typename T, typename Command> | 81 template <typename T, typename Command> |
| 81 T GetImmediateDataAs(Command* cmd) { | 82 T GetImmediateDataAs(Command* cmd) { |
| 82 reinterpret_cast<T>(ImmediateDataAddress(cmd)); | 83 reinterpret_cast<T>(ImmediateDataAddress(cmd)); |
| 83 } | 84 } |
| 84 | 85 |
| 85 virtual void SetUp() { | 86 virtual void SetUp() { |
| 86 gl_.reset(new ::gles2::MockGLInterface()); | 87 gl_.reset(new MockGLInterface()); |
| 87 ::gles2::GLInterface::SetGLInterface(gl_.get()); | 88 ::gles2::GLInterface::SetGLInterface(gl_.get()); |
| 88 | 89 |
| 89 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VERTEX_ATTRIBS, _)) | 90 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VERTEX_ATTRIBS, _)) |
| 90 .WillOnce(SetArgumentPointee<1>(kNumVertexAttribs)) | 91 .WillOnce(SetArgumentPointee<1>(kNumVertexAttribs)) |
| 91 .RetiresOnSaturation(); | 92 .RetiresOnSaturation(); |
| 92 EXPECT_CALL(*gl_, GetError()) | 93 EXPECT_CALL(*gl_, GetError()) |
| 93 .WillRepeatedly(Return(GL_NO_ERROR)); | 94 .WillRepeatedly(Return(GL_NO_ERROR)); |
| 94 | 95 |
| 95 engine_.reset(new MockCommandBufferEngine()); | 96 engine_.reset(new MockCommandBufferEngine()); |
| 96 Buffer buffer = engine_->GetSharedMemoryBuffer(kSharedMemoryId); | 97 Buffer buffer = engine_->GetSharedMemoryBuffer(kSharedMemoryId); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 179 |
| 179 template <typename T> | 180 template <typename T> |
| 180 T GetSharedMemoryAs() { | 181 T GetSharedMemoryAs() { |
| 181 return reinterpret_cast<T>(shared_memory_address_); | 182 return reinterpret_cast<T>(shared_memory_address_); |
| 182 } | 183 } |
| 183 | 184 |
| 184 uint32 GetServiceId(uint32 client_id) { | 185 uint32 GetServiceId(uint32 client_id) { |
| 185 return decoder_->GetServiceIdForTesting(client_id); | 186 return decoder_->GetServiceIdForTesting(client_id); |
| 186 } | 187 } |
| 187 | 188 |
| 188 GLenum GetGLError() { | 189 // Note that the error is returned as GLint instead of GLenum. |
| 190 // This is because there is a mismatch in the types of GLenum and |
| 191 // the error values GL_NO_ERROR, GL_INVALID_ENUM, etc. GLenum is |
| 192 // typedef'd as unsigned int while the error values are defined as |
| 193 // integers. This is problematic for template functions such as |
| 194 // EXPECT_EQ that expect both types to be the same. |
| 195 GLint GetGLError() { |
| 189 EXPECT_CALL(*gl_, GetError()) | 196 EXPECT_CALL(*gl_, GetError()) |
| 190 .WillOnce(Return(GL_NO_ERROR)) | 197 .WillOnce(Return(GL_NO_ERROR)) |
| 191 .RetiresOnSaturation(); | 198 .RetiresOnSaturation(); |
| 192 GetError cmd; | 199 GetError cmd; |
| 193 cmd.Init(shared_memory_id_, shared_memory_offset_); | 200 cmd.Init(shared_memory_id_, shared_memory_offset_); |
| 194 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 201 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 195 return *GetSharedMemoryAs<GLenum*>(); | 202 return static_cast<GLint>(*GetSharedMemoryAs<GLenum*>()); |
| 196 } | 203 } |
| 197 | 204 |
| 198 scoped_ptr<::gles2::MockGLInterface> gl_; | 205 scoped_ptr<MockGLInterface> gl_; |
| 199 scoped_ptr<GLES2Decoder> decoder_; | 206 scoped_ptr<GLES2Decoder> decoder_; |
| 200 | 207 |
| 201 GLuint client_buffer_id_; | 208 GLuint client_buffer_id_; |
| 202 GLuint client_framebuffer_id_; | 209 GLuint client_framebuffer_id_; |
| 203 GLuint client_program_id_; | 210 GLuint client_program_id_; |
| 204 GLuint client_renderbuffer_id_; | 211 GLuint client_renderbuffer_id_; |
| 205 GLuint client_shader_id_; | 212 GLuint client_shader_id_; |
| 206 GLuint client_texture_id_; | 213 GLuint client_texture_id_; |
| 207 GLuint client_element_buffer_id_; | 214 GLuint client_element_buffer_id_; |
| 208 | 215 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 254 |
| 248 private: | 255 private: |
| 249 scoped_array<int8> data_; | 256 scoped_array<int8> data_; |
| 250 Buffer valid_buffer_; | 257 Buffer valid_buffer_; |
| 251 Buffer invalid_buffer_; | 258 Buffer invalid_buffer_; |
| 252 }; | 259 }; |
| 253 | 260 |
| 254 scoped_ptr<MockCommandBufferEngine> engine_; | 261 scoped_ptr<MockCommandBufferEngine> engine_; |
| 255 }; | 262 }; |
| 256 | 263 |
| 264 const GLint GLES2DecoderTest::kNumVertexAttribs; |
| 265 const GLuint GLES2DecoderTest::kServiceBufferId; |
| 266 const GLuint GLES2DecoderTest::kServiceFramebufferId; |
| 267 const GLuint GLES2DecoderTest::kServiceRenderbufferId; |
| 268 const GLuint GLES2DecoderTest::kServiceTextureId; |
| 269 const GLuint GLES2DecoderTest::kServiceProgramId; |
| 270 const GLuint GLES2DecoderTest::kServiceShaderId; |
| 271 const GLuint GLES2DecoderTest::kServiceElementBufferId; |
| 272 const int32 GLES2DecoderTest::kSharedMemoryId; |
| 273 const size_t GLES2DecoderTest::kSharedBufferSize; |
| 274 const uint32 GLES2DecoderTest::kSharedMemoryOffset; |
| 275 const int32 GLES2DecoderTest::kInvalidSharedMemoryId; |
| 276 const uint32 GLES2DecoderTest::kInvalidSharedMemoryOffset; |
| 277 const uint32 GLES2DecoderTest::kInitialResult; |
| 278 const uint32 GLES2DecoderTest::kNewClientId; |
| 279 const uint32 GLES2DecoderTest::kNewServiceId; |
| 280 const uint32 GLES2DecoderTest::kInvalidClientId; |
| 281 |
| 257 template <> | 282 template <> |
| 258 void GLES2DecoderTest::SpecializedSetup<LinkProgram, 0>() { | 283 void GLES2DecoderTest::SpecializedSetup<LinkProgram, 0>() { |
| 259 InSequence dummy; | 284 InSequence dummy; |
| 260 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_ACTIVE_ATTRIBUTES, _)) | 285 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_ACTIVE_ATTRIBUTES, _)) |
| 261 .WillOnce(SetArgumentPointee<2>(0)); | 286 .WillOnce(SetArgumentPointee<2>(0)); |
| 262 EXPECT_CALL( | 287 EXPECT_CALL( |
| 263 *gl_, | 288 *gl_, |
| 264 GetProgramiv(kServiceProgramId, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, _)) | 289 GetProgramiv(kServiceProgramId, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, _)) |
| 265 .WillOnce(SetArgumentPointee<2>(0)); | 290 .WillOnce(SetArgumentPointee<2>(0)); |
| 266 }; | 291 }; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 | 474 |
| 450 void DeleteVertexBuffer() { | 475 void DeleteVertexBuffer() { |
| 451 DoDeleteBuffer(client_buffer_id_, kServiceBufferId); | 476 DoDeleteBuffer(client_buffer_id_, kServiceBufferId); |
| 452 } | 477 } |
| 453 | 478 |
| 454 void DeleteIndexBuffer() { | 479 void DeleteIndexBuffer() { |
| 455 DoDeleteBuffer(client_element_buffer_id_, kServiceElementBufferId); | 480 DoDeleteBuffer(client_element_buffer_id_, kServiceElementBufferId); |
| 456 } | 481 } |
| 457 }; | 482 }; |
| 458 | 483 |
| 484 const GLint GLES2DecoderWithShaderTest::kNumAttribs; |
| 485 const GLint GLES2DecoderWithShaderTest::kMaxAttribLength; |
| 486 const GLsizei GLES2DecoderWithShaderTest::kNumVertices; |
| 487 const GLsizei GLES2DecoderWithShaderTest::kNumIndices; |
| 488 const int GLES2DecoderWithShaderTest::kValidIndexRangeStart; |
| 489 const int GLES2DecoderWithShaderTest::kValidIndexRangeCount; |
| 490 const int GLES2DecoderWithShaderTest::kInvalidIndexRangeStart; |
| 491 const int GLES2DecoderWithShaderTest::kInvalidIndexRangeCount; |
| 492 const int GLES2DecoderWithShaderTest::kOutOfRangeIndexRangeEnd; |
| 459 const char* GLES2DecoderWithShaderTest::kAttrib1Name = "attrib1"; | 493 const char* GLES2DecoderWithShaderTest::kAttrib1Name = "attrib1"; |
| 460 const char* GLES2DecoderWithShaderTest::kAttrib2Name = "attrib2"; | 494 const char* GLES2DecoderWithShaderTest::kAttrib2Name = "attrib2"; |
| 461 const char* GLES2DecoderWithShaderTest::kAttrib3Name = "attrib3"; | 495 const char* GLES2DecoderWithShaderTest::kAttrib3Name = "attrib3"; |
| 462 | 496 |
| 463 TEST_F(GLES2DecoderWithShaderTest, DrawArraysNoAttributesSucceeds) { | 497 TEST_F(GLES2DecoderWithShaderTest, DrawArraysNoAttributesSucceeds) { |
| 464 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices)) | 498 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices)) |
| 465 .Times(1) | 499 .Times(1) |
| 466 .RetiresOnSaturation(); | 500 .RetiresOnSaturation(); |
| 467 DrawArrays cmd; | 501 DrawArrays cmd; |
| 468 cmd.Init(GL_TRIANGLES, 0, kNumVertices); | 502 cmd.Init(GL_TRIANGLES, 0, kNumVertices); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 EXPECT_NE(error::kNoError, ExecuteCmd(cmd)); | 790 EXPECT_NE(error::kNoError, ExecuteCmd(cmd)); |
| 757 } | 791 } |
| 758 | 792 |
| 759 | 793 |
| 760 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_autogen.h" | 794 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_autogen.h" |
| 761 | 795 |
| 762 } // namespace gles2 | 796 } // namespace gles2 |
| 763 } // namespace gpu | 797 } // namespace gpu |
| 764 | 798 |
| 765 | 799 |
| OLD | NEW |