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_unittest_base.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "app/gfx/gl/gl_mock.h" | 10 #include "app/gfx/gl/gl_mock.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 12 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
13 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 13 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
14 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 14 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
15 #include "gpu/command_buffer/service/context_group.h" | 15 #include "gpu/command_buffer/service/context_group.h" |
16 #include "gpu/command_buffer/service/program_manager.h" | 16 #include "gpu/command_buffer/service/program_manager.h" |
| 17 #include "gpu/command_buffer/service/test_helper.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 using ::gfx::MockGLInterface; | 20 using ::gfx::MockGLInterface; |
20 using ::testing::_; | 21 using ::testing::_; |
21 using ::testing::DoAll; | 22 using ::testing::DoAll; |
22 using ::testing::InSequence; | 23 using ::testing::InSequence; |
23 using ::testing::MatcherCast; | 24 using ::testing::MatcherCast; |
24 using ::testing::Pointee; | 25 using ::testing::Pointee; |
25 using ::testing::Return; | 26 using ::testing::Return; |
26 using ::testing::SetArrayArgument; | 27 using ::testing::SetArrayArgument; |
27 using ::testing::SetArgumentPointee; | 28 using ::testing::SetArgumentPointee; |
28 using ::testing::StrEq; | 29 using ::testing::StrEq; |
29 using ::testing::StrictMock; | 30 using ::testing::StrictMock; |
30 | 31 |
31 namespace gpu { | 32 namespace gpu { |
32 namespace gles2 { | 33 namespace gles2 { |
33 | 34 |
34 void GLES2DecoderTestBase::SetUp() { | 35 void GLES2DecoderTestBase::SetUp() { |
35 InitDecoder(""); | 36 InitDecoder(""); |
36 } | 37 } |
37 | 38 |
38 void GLES2DecoderTestBase::InitDecoder(const char* extensions) { | 39 void GLES2DecoderTestBase::InitDecoder(const char* extensions) { |
39 gl_.reset(new StrictMock<MockGLInterface>()); | 40 gl_.reset(new StrictMock<MockGLInterface>()); |
40 ::gfx::GLInterface::SetGLInterface(gl_.get()); | 41 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
41 | 42 |
42 InSequence sequence; | 43 InSequence sequence; |
43 | 44 |
44 EXPECT_CALL(*gl_, GetString(GL_EXTENSIONS)) | 45 TestHelper::SetupContextGroupInitExpectations(gl_.get(), ""); |
45 .WillOnce(Return(reinterpret_cast<const uint8*>(extensions))) | 46 |
46 .RetiresOnSaturation(); | |
47 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VERTEX_ATTRIBS, _)) | |
48 .WillOnce(SetArgumentPointee<1>(kNumVertexAttribs)) | |
49 .RetiresOnSaturation(); | |
50 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, _)) | |
51 .WillOnce(SetArgumentPointee<1>(kNumTextureUnits)) | |
52 .RetiresOnSaturation(); | |
53 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_TEXTURE_SIZE, _)) | |
54 .WillOnce(SetArgumentPointee<1>(kMaxTextureSize)) | |
55 .RetiresOnSaturation(); | |
56 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, _)) | |
57 .WillOnce(SetArgumentPointee<1>(kMaxCubeMapTextureSize)) | |
58 .RetiresOnSaturation(); | |
59 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, _)) | |
60 .WillOnce(SetArgumentPointee<1>(kMaxTextureImageUnits)) | |
61 .RetiresOnSaturation(); | |
62 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, _)) | |
63 .WillOnce(SetArgumentPointee<1>(kMaxVertexTextureImageUnits)) | |
64 .RetiresOnSaturation(); | |
65 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, _)) | |
66 .WillOnce(SetArgumentPointee<1>(kMaxFragmentUniformVectors)) | |
67 .RetiresOnSaturation(); | |
68 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VARYING_FLOATS, _)) | |
69 .WillOnce(SetArgumentPointee<1>(kMaxVaryingVectors)) | |
70 .RetiresOnSaturation(); | |
71 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, _)) | |
72 .WillOnce(SetArgumentPointee<1>(kMaxVertexUniformVectors)) | |
73 .RetiresOnSaturation(); | |
74 EXPECT_CALL(*gl_, EnableVertexAttribArray(0)) | 47 EXPECT_CALL(*gl_, EnableVertexAttribArray(0)) |
75 .Times(1) | 48 .Times(1) |
76 .RetiresOnSaturation(); | 49 .RetiresOnSaturation(); |
77 static GLuint attrib_ids[] = { | 50 static GLuint attrib_ids[] = { |
78 kServiceAttrib0BufferId, | 51 kServiceAttrib0BufferId, |
79 }; | 52 }; |
80 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(attrib_ids), _)) | 53 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(attrib_ids), _)) |
81 .WillOnce(SetArrayArgument<1>(attrib_ids, | 54 .WillOnce(SetArrayArgument<1>(attrib_ids, |
82 attrib_ids + arraysize(attrib_ids))) | 55 attrib_ids + arraysize(attrib_ids))) |
83 .RetiresOnSaturation(); | 56 .RetiresOnSaturation(); |
84 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId)) | 57 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId)) |
85 .Times(1) | 58 .Times(1) |
86 .RetiresOnSaturation(); | 59 .RetiresOnSaturation(); |
87 EXPECT_CALL(*gl_, VertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL)) | 60 EXPECT_CALL(*gl_, VertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL)) |
88 .Times(1) | 61 .Times(1) |
89 .RetiresOnSaturation(); | 62 .RetiresOnSaturation(); |
90 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0)) | 63 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0)) |
91 .Times(1) | 64 .Times(1) |
92 .RetiresOnSaturation(); | 65 .RetiresOnSaturation(); |
93 | 66 |
94 static GLuint black_ids[] = { | 67 for (GLint tt = 0; tt < TestHelper::kNumTextureUnits; ++tt) { |
95 kServiceBlackTexture2dId, | 68 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0 + tt)) |
96 kServiceBlackTextureCubemapId, | 69 .Times(1) |
97 }; | 70 .RetiresOnSaturation(); |
98 EXPECT_CALL(*gl_, GenTextures(arraysize(black_ids), _)) | 71 EXPECT_CALL(*gl_, BindTexture( |
99 .WillOnce(SetArrayArgument<1>(black_ids, | 72 GL_TEXTURE_CUBE_MAP, TestHelper::kServiceDefaultTextureCubemapId)) |
100 black_ids + arraysize(black_ids))) | 73 .Times(1) |
101 .RetiresOnSaturation(); | 74 .RetiresOnSaturation(); |
102 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceBlackTexture2dId)) | 75 EXPECT_CALL(*gl_, BindTexture( |
103 .Times(1) | 76 GL_TEXTURE_2D, TestHelper::kServiceDefaultTexture2dId)) |
104 .RetiresOnSaturation(); | |
105 EXPECT_CALL(*gl_, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, | |
106 GL_UNSIGNED_BYTE, _)) | |
107 .Times(1) | |
108 .RetiresOnSaturation(); | |
109 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0)) | |
110 .Times(1) | |
111 .RetiresOnSaturation(); | |
112 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, | |
113 kServiceBlackTextureCubemapId)) | |
114 .Times(1) | |
115 .RetiresOnSaturation(); | |
116 static GLenum faces[] = { | |
117 GL_TEXTURE_CUBE_MAP_POSITIVE_X, | |
118 GL_TEXTURE_CUBE_MAP_NEGATIVE_X, | |
119 GL_TEXTURE_CUBE_MAP_POSITIVE_Y, | |
120 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, | |
121 GL_TEXTURE_CUBE_MAP_POSITIVE_Z, | |
122 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, | |
123 }; | |
124 for (size_t ii = 0; ii < arraysize(faces); ++ii) { | |
125 EXPECT_CALL(*gl_, TexImage2D(faces[ii], 0, GL_RGBA, 1, 1, 0, GL_RGBA, | |
126 GL_UNSIGNED_BYTE, _)) | |
127 .Times(1) | 77 .Times(1) |
128 .RetiresOnSaturation(); | 78 .RetiresOnSaturation(); |
129 } | 79 } |
130 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0)) | 80 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) |
131 .Times(1) | 81 .Times(1) |
132 .RetiresOnSaturation(); | 82 .RetiresOnSaturation(); |
| 83 |
133 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE)) | 84 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE)) |
134 .Times(1) | 85 .Times(1) |
135 .RetiresOnSaturation(); | 86 .RetiresOnSaturation(); |
136 | 87 |
137 engine_.reset(new StrictMock<MockCommandBufferEngine>()); | 88 engine_.reset(new StrictMock<MockCommandBufferEngine>()); |
138 Buffer buffer = engine_->GetSharedMemoryBuffer(kSharedMemoryId); | 89 Buffer buffer = engine_->GetSharedMemoryBuffer(kSharedMemoryId); |
139 shared_memory_offset_ = kSharedMemoryOffset; | 90 shared_memory_offset_ = kSharedMemoryOffset; |
140 shared_memory_address_ = reinterpret_cast<int8*>(buffer.ptr) + | 91 shared_memory_address_ = reinterpret_cast<int8*>(buffer.ptr) + |
141 shared_memory_offset_; | 92 shared_memory_offset_; |
142 shared_memory_id_ = kSharedMemoryId; | 93 shared_memory_id_ = kSharedMemoryId; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 } | 130 } |
180 | 131 |
181 DoCreateShader(GL_VERTEX_SHADER, client_shader_id_, kServiceShaderId); | 132 DoCreateShader(GL_VERTEX_SHADER, client_shader_id_, kServiceShaderId); |
182 | 133 |
183 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 134 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
184 } | 135 } |
185 | 136 |
186 void GLES2DecoderTestBase::TearDown() { | 137 void GLES2DecoderTestBase::TearDown() { |
187 // All Tests should have read all their GLErrors before getting here. | 138 // All Tests should have read all their GLErrors before getting here. |
188 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 139 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
189 EXPECT_CALL(*gl_, DeleteTextures(1, _)) | |
190 .Times(2) | |
191 .RetiresOnSaturation(); | |
192 EXPECT_CALL(*gl_, DeleteBuffersARB(1, _)) | 140 EXPECT_CALL(*gl_, DeleteBuffersARB(1, _)) |
193 .Times(1) | 141 .Times(1) |
194 .RetiresOnSaturation(); | 142 .RetiresOnSaturation(); |
195 decoder_->Destroy(); | 143 decoder_->Destroy(); |
196 decoder_.reset(); | 144 decoder_.reset(); |
197 group_.Destroy(false); | 145 group_.Destroy(false); |
198 engine_.reset(); | 146 engine_.reset(); |
199 ::gfx::GLInterface::SetGLInterface(NULL); | 147 ::gfx::GLInterface::SetGLInterface(NULL); |
200 gl_.reset(); | 148 gl_.reset(); |
201 } | 149 } |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 const GLint GLES2DecoderTestBase::kMaxTextureSize; | 377 const GLint GLES2DecoderTestBase::kMaxTextureSize; |
430 const GLint GLES2DecoderTestBase::kMaxCubeMapTextureSize; | 378 const GLint GLES2DecoderTestBase::kMaxCubeMapTextureSize; |
431 const GLint GLES2DecoderTestBase::kNumVertexAttribs; | 379 const GLint GLES2DecoderTestBase::kNumVertexAttribs; |
432 const GLint GLES2DecoderTestBase::kNumTextureUnits; | 380 const GLint GLES2DecoderTestBase::kNumTextureUnits; |
433 const GLint GLES2DecoderTestBase::kMaxTextureImageUnits; | 381 const GLint GLES2DecoderTestBase::kMaxTextureImageUnits; |
434 const GLint GLES2DecoderTestBase::kMaxVertexTextureImageUnits; | 382 const GLint GLES2DecoderTestBase::kMaxVertexTextureImageUnits; |
435 const GLint GLES2DecoderTestBase::kMaxFragmentUniformVectors; | 383 const GLint GLES2DecoderTestBase::kMaxFragmentUniformVectors; |
436 const GLint GLES2DecoderTestBase::kMaxVaryingVectors; | 384 const GLint GLES2DecoderTestBase::kMaxVaryingVectors; |
437 const GLint GLES2DecoderTestBase::kMaxVertexUniformVectors; | 385 const GLint GLES2DecoderTestBase::kMaxVertexUniformVectors; |
438 | 386 |
439 const GLuint GLES2DecoderTestBase::kServiceBlackTexture2dId; | |
440 const GLuint GLES2DecoderTestBase::kServiceBlackTextureCubemapId; | |
441 | |
442 const GLuint GLES2DecoderTestBase::kServiceAttrib0BufferId; | 387 const GLuint GLES2DecoderTestBase::kServiceAttrib0BufferId; |
443 | 388 |
444 const GLuint GLES2DecoderTestBase::kServiceBufferId; | 389 const GLuint GLES2DecoderTestBase::kServiceBufferId; |
445 const GLuint GLES2DecoderTestBase::kServiceFramebufferId; | 390 const GLuint GLES2DecoderTestBase::kServiceFramebufferId; |
446 const GLuint GLES2DecoderTestBase::kServiceRenderbufferId; | 391 const GLuint GLES2DecoderTestBase::kServiceRenderbufferId; |
447 const GLuint GLES2DecoderTestBase::kServiceTextureId; | 392 const GLuint GLES2DecoderTestBase::kServiceTextureId; |
448 const GLuint GLES2DecoderTestBase::kServiceProgramId; | 393 const GLuint GLES2DecoderTestBase::kServiceProgramId; |
449 const GLuint GLES2DecoderTestBase::kServiceShaderId; | 394 const GLuint GLES2DecoderTestBase::kServiceShaderId; |
450 const GLuint GLES2DecoderTestBase::kServiceElementBufferId; | 395 const GLuint GLES2DecoderTestBase::kServiceElementBufferId; |
451 | 396 |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 const char* GLES2DecoderWithShaderTestBase::kAttrib2Name = "attrib2"; | 696 const char* GLES2DecoderWithShaderTestBase::kAttrib2Name = "attrib2"; |
752 const char* GLES2DecoderWithShaderTestBase::kAttrib3Name = "attrib3"; | 697 const char* GLES2DecoderWithShaderTestBase::kAttrib3Name = "attrib3"; |
753 const char* GLES2DecoderWithShaderTestBase::kUniform1Name = "uniform1"; | 698 const char* GLES2DecoderWithShaderTestBase::kUniform1Name = "uniform1"; |
754 const char* GLES2DecoderWithShaderTestBase::kUniform2Name = "uniform2[0]"; | 699 const char* GLES2DecoderWithShaderTestBase::kUniform2Name = "uniform2[0]"; |
755 const char* GLES2DecoderWithShaderTestBase::kUniform3Name = "uniform3[0]"; | 700 const char* GLES2DecoderWithShaderTestBase::kUniform3Name = "uniform3[0]"; |
756 | 701 |
757 } // namespace gles2 | 702 } // namespace gles2 |
758 } // namespace gpu | 703 } // namespace gpu |
759 | 704 |
760 | 705 |
OLD | NEW |