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/test_helper.h" | 5 #include "gpu/command_buffer/service/test_helper.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 const GLint TestHelper::kMaxVertexTextureImageUnits; | 54 const GLint TestHelper::kMaxVertexTextureImageUnits; |
55 const GLint TestHelper::kMaxFragmentUniformVectors; | 55 const GLint TestHelper::kMaxFragmentUniformVectors; |
56 const GLint TestHelper::kMaxFragmentUniformComponents; | 56 const GLint TestHelper::kMaxFragmentUniformComponents; |
57 const GLint TestHelper::kMaxVaryingVectors; | 57 const GLint TestHelper::kMaxVaryingVectors; |
58 const GLint TestHelper::kMaxVaryingFloats; | 58 const GLint TestHelper::kMaxVaryingFloats; |
59 const GLint TestHelper::kMaxVertexUniformVectors; | 59 const GLint TestHelper::kMaxVertexUniformVectors; |
60 const GLint TestHelper::kMaxVertexUniformComponents; | 60 const GLint TestHelper::kMaxVertexUniformComponents; |
61 #endif | 61 #endif |
62 | 62 |
63 void TestHelper::SetupTextureInitializationExpectations( | 63 void TestHelper::SetupTextureInitializationExpectations( |
64 ::gfx::MockGLInterface* gl, GLenum target) { | 64 ::gfx::MockGLInterface* gl, |
| 65 GLenum target, |
| 66 bool use_default_textures) { |
65 InSequence sequence; | 67 InSequence sequence; |
66 | 68 |
67 bool needs_initialization = (target != GL_TEXTURE_EXTERNAL_OES); | 69 bool needs_initialization = (target != GL_TEXTURE_EXTERNAL_OES); |
68 bool needs_faces = (target == GL_TEXTURE_CUBE_MAP); | 70 bool needs_faces = (target == GL_TEXTURE_CUBE_MAP); |
69 | 71 |
70 static GLuint texture_2d_ids[] = { | 72 static GLuint texture_2d_ids[] = { |
71 kServiceBlackTexture2dId, | 73 kServiceBlackTexture2dId, |
72 kServiceDefaultTexture2dId }; | 74 kServiceDefaultTexture2dId }; |
73 static GLuint texture_cube_map_ids[] = { | 75 static GLuint texture_cube_map_ids[] = { |
74 kServiceBlackTextureCubemapId, | 76 kServiceBlackTextureCubemapId, |
(...skipping 16 matching lines...) Expand all Loading... |
91 case GL_TEXTURE_EXTERNAL_OES: | 93 case GL_TEXTURE_EXTERNAL_OES: |
92 texture_ids = &texture_external_oes_ids[0]; | 94 texture_ids = &texture_external_oes_ids[0]; |
93 break; | 95 break; |
94 case GL_TEXTURE_RECTANGLE_ARB: | 96 case GL_TEXTURE_RECTANGLE_ARB: |
95 texture_ids = &texture_rectangle_arb_ids[0]; | 97 texture_ids = &texture_rectangle_arb_ids[0]; |
96 break; | 98 break; |
97 default: | 99 default: |
98 NOTREACHED(); | 100 NOTREACHED(); |
99 } | 101 } |
100 | 102 |
101 int array_size = 2; | 103 int array_size = use_default_textures ? 2 : 1; |
102 | 104 |
103 EXPECT_CALL(*gl, GenTextures(array_size, _)) | 105 EXPECT_CALL(*gl, GenTextures(array_size, _)) |
104 .WillOnce(SetArrayArgument<1>(texture_ids, | 106 .WillOnce(SetArrayArgument<1>(texture_ids, |
105 texture_ids + array_size)) | 107 texture_ids + array_size)) |
106 .RetiresOnSaturation(); | 108 .RetiresOnSaturation(); |
107 for (int ii = 0; ii < array_size; ++ii) { | 109 for (int ii = 0; ii < array_size; ++ii) { |
108 EXPECT_CALL(*gl, BindTexture(target, texture_ids[ii])) | 110 EXPECT_CALL(*gl, BindTexture(target, texture_ids[ii])) |
109 .Times(1) | 111 .Times(1) |
110 .RetiresOnSaturation(); | 112 .RetiresOnSaturation(); |
111 if (needs_initialization) { | 113 if (needs_initialization) { |
(...skipping 20 matching lines...) Expand all Loading... |
132 } | 134 } |
133 } | 135 } |
134 } | 136 } |
135 EXPECT_CALL(*gl, BindTexture(target, 0)) | 137 EXPECT_CALL(*gl, BindTexture(target, 0)) |
136 .Times(1) | 138 .Times(1) |
137 .RetiresOnSaturation(); | 139 .RetiresOnSaturation(); |
138 } | 140 } |
139 | 141 |
140 void TestHelper::SetupTextureManagerInitExpectations( | 142 void TestHelper::SetupTextureManagerInitExpectations( |
141 ::gfx::MockGLInterface* gl, | 143 ::gfx::MockGLInterface* gl, |
142 const char* extensions) { | 144 const char* extensions, |
| 145 bool use_default_textures) { |
143 InSequence sequence; | 146 InSequence sequence; |
144 | 147 |
145 SetupTextureInitializationExpectations(gl, GL_TEXTURE_2D); | 148 SetupTextureInitializationExpectations( |
146 SetupTextureInitializationExpectations(gl, GL_TEXTURE_CUBE_MAP); | 149 gl, GL_TEXTURE_2D, use_default_textures); |
| 150 SetupTextureInitializationExpectations( |
| 151 gl, GL_TEXTURE_CUBE_MAP, use_default_textures); |
147 | 152 |
148 bool ext_image_external = false; | 153 bool ext_image_external = false; |
149 bool arb_texture_rectangle = false; | 154 bool arb_texture_rectangle = false; |
150 base::CStringTokenizer t(extensions, extensions + strlen(extensions), " "); | 155 base::CStringTokenizer t(extensions, extensions + strlen(extensions), " "); |
151 while (t.GetNext()) { | 156 while (t.GetNext()) { |
152 if (t.token() == "GL_OES_EGL_image_external") { | 157 if (t.token() == "GL_OES_EGL_image_external") { |
153 ext_image_external = true; | 158 ext_image_external = true; |
154 break; | 159 break; |
155 } | 160 } |
156 if (t.token() == "GL_ARB_texture_rectangle") { | 161 if (t.token() == "GL_ARB_texture_rectangle") { |
157 arb_texture_rectangle = true; | 162 arb_texture_rectangle = true; |
158 break; | 163 break; |
159 } | 164 } |
160 } | 165 } |
161 | 166 |
162 if (ext_image_external) { | 167 if (ext_image_external) { |
163 SetupTextureInitializationExpectations(gl, GL_TEXTURE_EXTERNAL_OES); | 168 SetupTextureInitializationExpectations( |
| 169 gl, GL_TEXTURE_EXTERNAL_OES, use_default_textures); |
164 } | 170 } |
165 if (arb_texture_rectangle) { | 171 if (arb_texture_rectangle) { |
166 SetupTextureInitializationExpectations(gl, GL_TEXTURE_RECTANGLE_ARB); | 172 SetupTextureInitializationExpectations( |
| 173 gl, GL_TEXTURE_RECTANGLE_ARB, use_default_textures); |
167 } | 174 } |
168 } | 175 } |
169 | 176 |
170 void TestHelper::SetupTextureDestructionExpectations( | 177 void TestHelper::SetupTextureDestructionExpectations( |
171 ::gfx::MockGLInterface* gl, GLenum target) { | 178 ::gfx::MockGLInterface* gl, |
| 179 GLenum target, |
| 180 bool use_default_textures) { |
| 181 if (!use_default_textures) |
| 182 return; |
| 183 |
172 GLuint texture_id = 0; | 184 GLuint texture_id = 0; |
173 switch (target) { | 185 switch (target) { |
174 case GL_TEXTURE_2D: | 186 case GL_TEXTURE_2D: |
175 texture_id = kServiceDefaultTexture2dId; | 187 texture_id = kServiceDefaultTexture2dId; |
176 break; | 188 break; |
177 case GL_TEXTURE_CUBE_MAP: | 189 case GL_TEXTURE_CUBE_MAP: |
178 texture_id = kServiceDefaultTextureCubemapId; | 190 texture_id = kServiceDefaultTextureCubemapId; |
179 break; | 191 break; |
180 case GL_TEXTURE_EXTERNAL_OES: | 192 case GL_TEXTURE_EXTERNAL_OES: |
181 texture_id = kServiceDefaultExternalTextureId; | 193 texture_id = kServiceDefaultExternalTextureId; |
182 break; | 194 break; |
183 case GL_TEXTURE_RECTANGLE_ARB: | 195 case GL_TEXTURE_RECTANGLE_ARB: |
184 texture_id = kServiceDefaultRectangleTextureId; | 196 texture_id = kServiceDefaultRectangleTextureId; |
185 break; | 197 break; |
186 default: | 198 default: |
187 NOTREACHED(); | 199 NOTREACHED(); |
188 } | 200 } |
189 | 201 |
190 EXPECT_CALL(*gl, DeleteTextures(1, Pointee(texture_id))) | 202 EXPECT_CALL(*gl, DeleteTextures(1, Pointee(texture_id))) |
191 .Times(1) | 203 .Times(1) |
192 .RetiresOnSaturation(); | 204 .RetiresOnSaturation(); |
193 } | 205 } |
194 | 206 |
195 void TestHelper::SetupTextureManagerDestructionExpectations( | 207 void TestHelper::SetupTextureManagerDestructionExpectations( |
196 ::gfx::MockGLInterface* gl, | 208 ::gfx::MockGLInterface* gl, |
197 const char* extensions) { | 209 const char* extensions, |
198 SetupTextureDestructionExpectations(gl, GL_TEXTURE_2D); | 210 bool use_default_textures) { |
199 SetupTextureDestructionExpectations(gl, GL_TEXTURE_CUBE_MAP); | 211 SetupTextureDestructionExpectations(gl, GL_TEXTURE_2D, use_default_textures); |
| 212 SetupTextureDestructionExpectations( |
| 213 gl, GL_TEXTURE_CUBE_MAP, use_default_textures); |
200 | 214 |
201 bool ext_image_external = false; | 215 bool ext_image_external = false; |
202 bool arb_texture_rectangle = false; | 216 bool arb_texture_rectangle = false; |
203 base::CStringTokenizer t(extensions, extensions + strlen(extensions), " "); | 217 base::CStringTokenizer t(extensions, extensions + strlen(extensions), " "); |
204 while (t.GetNext()) { | 218 while (t.GetNext()) { |
205 if (t.token() == "GL_OES_EGL_image_external") { | 219 if (t.token() == "GL_OES_EGL_image_external") { |
206 ext_image_external = true; | 220 ext_image_external = true; |
207 break; | 221 break; |
208 } | 222 } |
209 if (t.token() == "GL_ARB_texture_rectangle") { | 223 if (t.token() == "GL_ARB_texture_rectangle") { |
210 arb_texture_rectangle = true; | 224 arb_texture_rectangle = true; |
211 break; | 225 break; |
212 } | 226 } |
213 } | 227 } |
214 | 228 |
215 if (ext_image_external) { | 229 if (ext_image_external) { |
216 SetupTextureDestructionExpectations(gl, GL_TEXTURE_EXTERNAL_OES); | 230 SetupTextureDestructionExpectations( |
| 231 gl, GL_TEXTURE_EXTERNAL_OES, use_default_textures); |
217 } | 232 } |
218 if (arb_texture_rectangle) { | 233 if (arb_texture_rectangle) { |
219 SetupTextureDestructionExpectations(gl, GL_TEXTURE_RECTANGLE_ARB); | 234 SetupTextureDestructionExpectations( |
| 235 gl, GL_TEXTURE_RECTANGLE_ARB, use_default_textures); |
220 } | 236 } |
221 | 237 |
222 EXPECT_CALL(*gl, DeleteTextures(4, _)) | 238 EXPECT_CALL(*gl, DeleteTextures(4, _)) |
223 .Times(1) | 239 .Times(1) |
224 .RetiresOnSaturation(); | 240 .RetiresOnSaturation(); |
225 } | 241 } |
226 | 242 |
227 void TestHelper::SetupContextGroupInitExpectations( | 243 void TestHelper::SetupContextGroupInitExpectations( |
228 ::gfx::MockGLInterface* gl, | 244 ::gfx::MockGLInterface* gl, |
229 const DisallowedFeatures& disallowed_features, | 245 const DisallowedFeatures& disallowed_features, |
230 const char* extensions, | 246 const char* extensions, |
231 const char* gl_version) { | 247 const char* gl_version, |
| 248 bool bind_generates_resource) { |
232 InSequence sequence; | 249 InSequence sequence; |
233 | 250 |
234 SetupFeatureInfoInitExpectationsWithGLVersion(gl, extensions, "", gl_version); | 251 SetupFeatureInfoInitExpectationsWithGLVersion(gl, extensions, "", gl_version); |
235 | 252 |
236 std::string l_version(StringToLowerASCII(std::string(gl_version))); | 253 std::string l_version(StringToLowerASCII(std::string(gl_version))); |
237 bool is_es3 = (l_version.substr(0, 12) == "opengl es 3."); | 254 bool is_es3 = (l_version.substr(0, 12) == "opengl es 3."); |
238 | 255 |
239 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_RENDERBUFFER_SIZE, _)) | 256 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_RENDERBUFFER_SIZE, _)) |
240 .WillOnce(SetArgumentPointee<1>(kMaxRenderbufferSize)) | 257 .WillOnce(SetArgumentPointee<1>(kMaxRenderbufferSize)) |
241 .RetiresOnSaturation(); | 258 .RetiresOnSaturation(); |
(...skipping 28 matching lines...) Expand all Loading... |
270 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, _)) | 287 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, _)) |
271 .WillOnce(SetArgumentPointee<1>(kMaxFragmentUniformComponents)) | 288 .WillOnce(SetArgumentPointee<1>(kMaxFragmentUniformComponents)) |
272 .RetiresOnSaturation(); | 289 .RetiresOnSaturation(); |
273 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_VARYING_FLOATS, _)) | 290 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_VARYING_FLOATS, _)) |
274 .WillOnce(SetArgumentPointee<1>(kMaxVaryingFloats)) | 291 .WillOnce(SetArgumentPointee<1>(kMaxVaryingFloats)) |
275 .RetiresOnSaturation(); | 292 .RetiresOnSaturation(); |
276 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, _)) | 293 EXPECT_CALL(*gl, GetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, _)) |
277 .WillOnce(SetArgumentPointee<1>(kMaxVertexUniformComponents)) | 294 .WillOnce(SetArgumentPointee<1>(kMaxVertexUniformComponents)) |
278 .RetiresOnSaturation(); | 295 .RetiresOnSaturation(); |
279 | 296 |
280 SetupTextureManagerInitExpectations(gl, extensions); | 297 bool use_default_textures = bind_generates_resource; |
| 298 SetupTextureManagerInitExpectations(gl, extensions, use_default_textures); |
281 } | 299 } |
282 | 300 |
283 void TestHelper::SetupFeatureInfoInitExpectations( | 301 void TestHelper::SetupFeatureInfoInitExpectations( |
284 ::gfx::MockGLInterface* gl, const char* extensions) { | 302 ::gfx::MockGLInterface* gl, const char* extensions) { |
285 SetupFeatureInfoInitExpectationsWithGLVersion(gl, extensions, "", ""); | 303 SetupFeatureInfoInitExpectationsWithGLVersion(gl, extensions, "", ""); |
286 } | 304 } |
287 | 305 |
288 void TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion( | 306 void TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion( |
289 ::gfx::MockGLInterface* gl, | 307 ::gfx::MockGLInterface* gl, |
290 const char* extensions, | 308 const char* extensions, |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 gfx::SetGLImplementation(implementation); | 647 gfx::SetGLImplementation(implementation); |
630 } | 648 } |
631 | 649 |
632 ScopedGLImplementationSetter::~ScopedGLImplementationSetter() { | 650 ScopedGLImplementationSetter::~ScopedGLImplementationSetter() { |
633 gfx::SetGLImplementation(old_implementation_); | 651 gfx::SetGLImplementation(old_implementation_); |
634 } | 652 } |
635 | 653 |
636 } // namespace gles2 | 654 } // namespace gles2 |
637 } // namespace gpu | 655 } // namespace gpu |
638 | 656 |
OLD | NEW |