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 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 static const GLuint kServiceTextureId = 304; | 43 static const GLuint kServiceTextureId = 304; |
44 static const GLuint kServiceProgramId = 305; | 44 static const GLuint kServiceProgramId = 305; |
45 static const GLuint kServiceShaderId = 306; | 45 static const GLuint kServiceShaderId = 306; |
46 static const GLuint kServiceElementBufferId = 307; | 46 static const GLuint kServiceElementBufferId = 307; |
47 | 47 |
48 static const int32 kSharedMemoryId = 401; | 48 static const int32 kSharedMemoryId = 401; |
49 static const size_t kSharedBufferSize = 2048; | 49 static const size_t kSharedBufferSize = 2048; |
50 static const uint32 kSharedMemoryOffset = 132; | 50 static const uint32 kSharedMemoryOffset = 132; |
51 static const int32 kInvalidSharedMemoryId = 402; | 51 static const int32 kInvalidSharedMemoryId = 402; |
52 static const uint32 kInvalidSharedMemoryOffset = kSharedBufferSize + 1; | 52 static const uint32 kInvalidSharedMemoryOffset = kSharedBufferSize + 1; |
| 53 static const uint32 kInitialResult = 0xDEADBEEFu; |
53 | 54 |
54 static const uint32 kNewClientId = 501; | 55 static const uint32 kNewClientId = 501; |
55 static const uint32 kNewServiceId = 502; | 56 static const uint32 kNewServiceId = 502; |
56 static const uint32 kInvalidClientId = 601; | 57 static const uint32 kInvalidClientId = 601; |
57 | 58 |
58 // Template to call glGenXXX functions. | 59 // Template to call glGenXXX functions. |
59 template <typename T> | 60 template <typename T> |
60 void GenHelper(GLuint client_id) { | 61 void GenHelper(GLuint client_id) { |
61 int8 buffer[sizeof(T) + sizeof(client_id)]; | 62 int8 buffer[sizeof(T) + sizeof(client_id)]; |
62 T& cmd = *reinterpret_cast<T*>(&buffer); | 63 T& cmd = *reinterpret_cast<T*>(&buffer); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 EXPECT_CALL(*gl_, CreateShader(_)) | 138 EXPECT_CALL(*gl_, CreateShader(_)) |
138 .Times(1) | 139 .Times(1) |
139 .WillOnce(Return(kServiceShaderId)) | 140 .WillOnce(Return(kServiceShaderId)) |
140 .RetiresOnSaturation(); | 141 .RetiresOnSaturation(); |
141 CreateShader cmd; | 142 CreateShader cmd; |
142 cmd.Init(GL_VERTEX_SHADER, client_shader_id_); | 143 cmd.Init(GL_VERTEX_SHADER, client_shader_id_); |
143 EXPECT_EQ(parse_error::kParseNoError, ExecuteCmd(cmd)); | 144 EXPECT_EQ(parse_error::kParseNoError, ExecuteCmd(cmd)); |
144 } | 145 } |
145 | 146 |
146 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 147 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 148 |
| 149 result_ = GetSharedMemoryAs<SizedResult*>(); |
| 150 GLuint* result_value = result_->GetDataAs<GLuint*>(); |
| 151 result_->size = kInitialResult; |
| 152 *result_value = kInitialResult; |
147 } | 153 } |
148 | 154 |
149 virtual void TearDown() { | 155 virtual void TearDown() { |
150 decoder_->Destroy(); | 156 decoder_->Destroy(); |
151 decoder_.reset(); | 157 decoder_.reset(); |
152 engine_.reset(); | 158 engine_.reset(); |
153 ::gles2::GLInterface::SetGLInterface(NULL); | 159 ::gles2::GLInterface::SetGLInterface(NULL); |
154 gl_.reset(); | 160 gl_.reset(); |
155 } | 161 } |
156 | 162 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 GLuint client_framebuffer_id_; | 202 GLuint client_framebuffer_id_; |
197 GLuint client_program_id_; | 203 GLuint client_program_id_; |
198 GLuint client_renderbuffer_id_; | 204 GLuint client_renderbuffer_id_; |
199 GLuint client_shader_id_; | 205 GLuint client_shader_id_; |
200 GLuint client_texture_id_; | 206 GLuint client_texture_id_; |
201 GLuint client_element_buffer_id_; | 207 GLuint client_element_buffer_id_; |
202 | 208 |
203 uint32 shared_memory_id_; | 209 uint32 shared_memory_id_; |
204 uint32 shared_memory_offset_; | 210 uint32 shared_memory_offset_; |
205 void* shared_memory_address_; | 211 void* shared_memory_address_; |
| 212 SizedResult* result_; |
206 | 213 |
207 int8 immediate_buffer_[256]; | 214 int8 immediate_buffer_[256]; |
208 | 215 |
209 private: | 216 private: |
210 class MockCommandBufferEngine : public CommandBufferEngine { | 217 class MockCommandBufferEngine : public CommandBufferEngine { |
211 public: | 218 public: |
212 MockCommandBufferEngine() { | 219 MockCommandBufferEngine() { |
213 data_.reset(new int8[kSharedBufferSize]); | 220 data_.reset(new int8[kSharedBufferSize]); |
214 valid_buffer_.ptr = data_.get(); | 221 valid_buffer_.ptr = data_.get(); |
215 valid_buffer_.size = kSharedBufferSize; | 222 valid_buffer_.size = kSharedBufferSize; |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0); | 683 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0); |
677 DrawElements cmd; | 684 DrawElements cmd; |
678 cmd.Init(GL_TRIANGLES, kInvalidIndexRangeCount, GL_UNSIGNED_SHORT, | 685 cmd.Init(GL_TRIANGLES, kInvalidIndexRangeCount, GL_UNSIGNED_SHORT, |
679 kInvalidIndexRangeStart); | 686 kInvalidIndexRangeStart); |
680 EXPECT_EQ(parse_error::kParseNoError, ExecuteCmd(cmd)); | 687 EXPECT_EQ(parse_error::kParseNoError, ExecuteCmd(cmd)); |
681 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); | 688 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
682 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 689 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
683 } | 690 } |
684 #endif | 691 #endif |
685 | 692 |
| 693 TEST_F(GLES2DecoderWithShaderTest, GetVertexAttribPointervSucceeds) { |
| 694 const float dummy = 0; |
| 695 const GLuint kOffsetToTestFor = sizeof(dummy) * 4; |
| 696 const GLuint kIndexToTest = 1; |
| 697 const GLuint* result_value = result_->GetDataAs<const GLuint*>(); |
| 698 // Test that initial value is 0. |
| 699 GetVertexAttribPointerv cmd; |
| 700 cmd.Init(kIndexToTest, GL_VERTEX_ATTRIB_ARRAY_POINTER, |
| 701 shared_memory_id_, shared_memory_offset_); |
| 702 EXPECT_EQ(parse_error::kParseNoError, ExecuteCmd(cmd)); |
| 703 EXPECT_EQ(sizeof(*result_value), result_->size); |
| 704 EXPECT_EQ(0u, *result_value); |
| 705 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 706 |
| 707 // Set the value and see that we get it. |
| 708 SetupVertexBuffer(); |
| 709 DoVertexAttribPointer(kIndexToTest, 2, GL_FLOAT, 0, kOffsetToTestFor); |
| 710 EXPECT_EQ(parse_error::kParseNoError, ExecuteCmd(cmd)); |
| 711 EXPECT_EQ(sizeof(*result_value), result_->size); |
| 712 EXPECT_EQ(kOffsetToTestFor, *result_value); |
| 713 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 714 } |
| 715 |
| 716 TEST_F(GLES2DecoderWithShaderTest, GetVertexAttribPointervBadArgsFails) { |
| 717 const GLuint kIndexToTest = 1; |
| 718 const GLuint* result_value = result_->GetDataAs<const GLuint*>(); |
| 719 // Test pname invalid fails. |
| 720 GetVertexAttribPointerv cmd; |
| 721 cmd.Init(kIndexToTest, GL_VERTEX_ATTRIB_ARRAY_POINTER + 1, |
| 722 shared_memory_id_, shared_memory_offset_); |
| 723 EXPECT_EQ(parse_error::kParseNoError, ExecuteCmd(cmd)); |
| 724 EXPECT_EQ(0u, result_->size); |
| 725 EXPECT_EQ(kInitialResult, *result_value); |
| 726 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); |
| 727 |
| 728 // Test index out of range fails. |
| 729 cmd.Init(kNumVertexAttribs, GL_VERTEX_ATTRIB_ARRAY_POINTER, |
| 730 shared_memory_id_, shared_memory_offset_); |
| 731 EXPECT_EQ(parse_error::kParseNoError, ExecuteCmd(cmd)); |
| 732 EXPECT_EQ(0u, result_->size); |
| 733 EXPECT_EQ(kInitialResult, *result_value); |
| 734 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); |
| 735 |
| 736 // Test memory id bad fails. |
| 737 cmd.Init(kIndexToTest, GL_VERTEX_ATTRIB_ARRAY_POINTER, |
| 738 kInvalidSharedMemoryId, shared_memory_offset_); |
| 739 EXPECT_NE(parse_error::kParseNoError, ExecuteCmd(cmd)); |
| 740 |
| 741 // Test memory offset bad fails. |
| 742 cmd.Init(kIndexToTest, GL_VERTEX_ATTRIB_ARRAY_POINTER, |
| 743 shared_memory_id_, kInvalidSharedMemoryOffset); |
| 744 EXPECT_NE(parse_error::kParseNoError, ExecuteCmd(cmd)); |
| 745 } |
| 746 |
| 747 |
686 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_autogen.h" | 748 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_autogen.h" |
687 | 749 |
688 } // namespace gles2 | 750 } // namespace gles2 |
689 } // namespace gpu | 751 } // namespace gpu |
690 | 752 |
691 | 753 |
OLD | NEW |