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

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h

Issue 8341128: Defer clearing textures and renderbuffers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix one more unit test Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_BASE_H_ 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_BASE_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_BASE_H_ 6 #define GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_BASE_H_
7 7
8 #include "gpu/command_buffer/common/gl_mock.h" 8 #include "gpu/command_buffer/common/gl_mock.h"
9 #include "gpu/command_buffer/common/gles2_cmd_format.h" 9 #include "gpu/command_buffer/common/gles2_cmd_format.h"
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 10 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 static const uint32 kInitialResult = 0xBDBDBDBDu; 59 static const uint32 kInitialResult = 0xBDBDBDBDu;
60 static const uint8 kInitialMemoryValue = 0xBDu; 60 static const uint8 kInitialMemoryValue = 0xBDu;
61 61
62 static const uint32 kNewClientId = 501; 62 static const uint32 kNewClientId = 501;
63 static const uint32 kNewServiceId = 502; 63 static const uint32 kNewServiceId = 502;
64 static const uint32 kInvalidClientId = 601; 64 static const uint32 kInvalidClientId = 601;
65 65
66 static const int kBackBufferWidth = 128; 66 static const int kBackBufferWidth = 128;
67 static const int kBackBufferHeight = 64; 67 static const int kBackBufferHeight = 64;
68 68
69 static const GLuint kServiceVertexShaderId = 321;
70 static const GLuint kServiceFragmentShaderId = 322;
71
72 static const GLsizei kNumVertices = 100;
73 static const GLsizei kNumIndices = 10;
74 static const int kValidIndexRangeStart = 1;
75 static const int kValidIndexRangeCount = 7;
76 static const int kInvalidIndexRangeStart = 0;
77 static const int kInvalidIndexRangeCount = 7;
78 static const int kOutOfRangeIndexRangeEnd = 10;
79 static const GLuint kMaxValidIndex = 7;
80
81 static const GLint kMaxAttribLength = 10;
82 static const char* kAttrib1Name;
83 static const char* kAttrib2Name;
84 static const char* kAttrib3Name;
85 static const GLint kAttrib1Size = 1;
86 static const GLint kAttrib2Size = 1;
87 static const GLint kAttrib3Size = 1;
88 static const GLint kAttrib1Location = 0;
89 static const GLint kAttrib2Location = 1;
90 static const GLint kAttrib3Location = 2;
91 static const GLenum kAttrib1Type = GL_FLOAT_VEC4;
92 static const GLenum kAttrib2Type = GL_FLOAT_VEC2;
93 static const GLenum kAttrib3Type = GL_FLOAT_VEC3;
94 static const GLint kInvalidAttribLocation = 30;
95 static const GLint kBadAttribIndex = kNumVertexAttribs;
96
97 static const GLint kMaxUniformLength = 12;
98 static const char* kUniform1Name;
99 static const char* kUniform2Name;
100 static const char* kUniform3Name;
101 static const GLint kUniform1Size = 1;
102 static const GLint kUniform2Size = 3;
103 static const GLint kUniform3Size = 2;
104 static const GLint kUniform1Location = 3;
105 static const GLint kUniform2Location = 10;
106 static const GLint kUniform2ElementLocation = 12;
107 static const GLint kUniform3Location = 20;
108 static const GLenum kUniform1Type = GL_SAMPLER_2D;
109 static const GLenum kUniform2Type = GL_INT_VEC2;
110 static const GLenum kUniform3Type = GL_FLOAT_VEC3;
111 static const GLenum kUniformCubemapType = GL_SAMPLER_CUBE;
112 static const GLint kInvalidUniformLocation = 30;
113 static const GLint kBadUniformIndex = 1000;
114
69 // Template to call glGenXXX functions. 115 // Template to call glGenXXX functions.
70 template <typename T> 116 template <typename T>
71 void GenHelper(GLuint client_id) { 117 void GenHelper(GLuint client_id) {
72 int8 buffer[sizeof(T) + sizeof(client_id)]; 118 int8 buffer[sizeof(T) + sizeof(client_id)];
73 T& cmd = *reinterpret_cast<T*>(&buffer); 119 T& cmd = *reinterpret_cast<T*>(&buffer);
74 cmd.Init(1, &client_id); 120 cmd.Init(1, &client_id);
75 EXPECT_EQ(error::kNoError, 121 EXPECT_EQ(error::kNoError,
76 ExecuteImmediateCmd(cmd, sizeof(client_id))); 122 ExecuteImmediateCmd(cmd, sizeof(client_id)));
77 } 123 }
78 124
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 236
191 void SetupShader( 237 void SetupShader(
192 AttribInfo* attribs, size_t num_attribs, 238 AttribInfo* attribs, size_t num_attribs,
193 UniformInfo* uniforms, size_t num_uniforms, 239 UniformInfo* uniforms, size_t num_uniforms,
194 GLuint client_id, GLuint service_id, 240 GLuint client_id, GLuint service_id,
195 GLuint vertex_shader_client_id, GLuint vertex_shader_service_id, 241 GLuint vertex_shader_client_id, GLuint vertex_shader_service_id,
196 GLuint fragment_shader_client_id, GLuint fragment_shader_service_id); 242 GLuint fragment_shader_client_id, GLuint fragment_shader_service_id);
197 243
198 // Setups up a shader for testing glUniform. 244 // Setups up a shader for testing glUniform.
199 void SetupShaderForUniform(); 245 void SetupShaderForUniform();
246 void SetupDefaultProgram();
247 void SetupCubemapProgram();
248 void SetupTexture();
200 249
201 // Note that the error is returned as GLint instead of GLenum. 250 // Note that the error is returned as GLint instead of GLenum.
202 // This is because there is a mismatch in the types of GLenum and 251 // This is because there is a mismatch in the types of GLenum and
203 // the error values GL_NO_ERROR, GL_INVALID_ENUM, etc. GLenum is 252 // the error values GL_NO_ERROR, GL_INVALID_ENUM, etc. GLenum is
204 // typedef'd as unsigned int while the error values are defined as 253 // typedef'd as unsigned int while the error values are defined as
205 // integers. This is problematic for template functions such as 254 // integers. This is problematic for template functions such as
206 // EXPECT_EQ that expect both types to be the same. 255 // EXPECT_EQ that expect both types to be the same.
207 GLint GetGLError(); 256 GLint GetGLError();
208 257
209 void DoBindBuffer(GLenum target, GLuint client_id, GLuint service_id); 258 void DoBindBuffer(GLenum target, GLuint client_id, GLuint service_id);
210 void DoBindFramebuffer(GLenum target, GLuint client_id, GLuint service_id); 259 void DoBindFramebuffer(GLenum target, GLuint client_id, GLuint service_id);
211 void DoBindRenderbuffer(GLenum target, GLuint client_id, GLuint service_id); 260 void DoBindRenderbuffer(GLenum target, GLuint client_id, GLuint service_id);
212 void DoBindTexture(GLenum target, GLuint client_id, GLuint service_id); 261 void DoBindTexture(GLenum target, GLuint client_id, GLuint service_id);
213 262
214 bool DoIsBuffer(GLuint client_id); 263 bool DoIsBuffer(GLuint client_id);
215 bool DoIsFramebuffer(GLuint client_id); 264 bool DoIsFramebuffer(GLuint client_id);
216 bool DoIsProgram(GLuint client_id); 265 bool DoIsProgram(GLuint client_id);
217 bool DoIsRenderbuffer(GLuint client_id); 266 bool DoIsRenderbuffer(GLuint client_id);
218 bool DoIsShader(GLuint client_id); 267 bool DoIsShader(GLuint client_id);
219 bool DoIsTexture(GLuint client_id); 268 bool DoIsTexture(GLuint client_id);
220 269
221 void DoDeleteBuffer(GLuint client_id, GLuint service_id); 270 void DoDeleteBuffer(GLuint client_id, GLuint service_id);
222 void DoDeleteFramebuffer(GLuint client_id, GLuint service_id); 271 void DoDeleteFramebuffer(GLuint client_id, GLuint service_id);
223 void DoDeleteProgram(GLuint client_id, GLuint service_id); 272 void DoDeleteProgram(GLuint client_id, GLuint service_id);
224 void DoDeleteRenderbuffer(GLuint client_id, GLuint service_id); 273 void DoDeleteRenderbuffer(GLuint client_id, GLuint service_id);
225 void DoDeleteShader(GLuint client_id, GLuint service_id); 274 void DoDeleteShader(GLuint client_id, GLuint service_id);
226 void DoDeleteTexture(GLuint client_id, GLuint service_id); 275 void DoDeleteTexture(GLuint client_id, GLuint service_id);
227 276
228 void DoTexImage2D(GLenum target, GLint level, GLenum internal_format, 277 void DoTexImage2D(
229 GLsizei width, GLsizei height, GLint border, 278 GLenum target, GLint level, GLenum internal_format,
230 GLenum format, GLenum type, 279 GLsizei width, GLsizei height, GLint border,
231 uint32 shared_memory_id, uint32 shared_memory_offset); 280 GLenum format, GLenum type,
281 uint32 shared_memory_id, uint32 shared_memory_offset);
282 void DoRenderbufferStorage(
283 GLenum target, GLenum internal_format, GLenum actual_format,
284 GLsizei width, GLsizei height, GLenum error);
285 void DoFramebufferRenderbuffer(
286 GLenum target,
287 GLenum attachment,
288 GLenum renderbuffer_target,
289 GLuint renderbuffer_client_id,
290 GLuint renderbuffer_service_id,
291 GLenum error);
292 void DoFramebufferTexture2D(
293 GLenum target, GLenum attachment, GLenum tex_target,
294 GLuint texture_client_id, GLuint texture_service_id,
295 GLint level, GLenum error);
232 void DoVertexAttribPointer( 296 void DoVertexAttribPointer(
233 GLuint index, GLint size, GLenum type, GLsizei stride, GLuint offset); 297 GLuint index, GLint size, GLenum type, GLsizei stride, GLuint offset);
234 298
235 void SetupExpectationsForFramebufferAttachment( 299 void DoEnableVertexAttribArray(GLint index);
300
301 void DoBufferData(GLenum target, GLsizei size);
302
303 void DoBufferSubData(
304 GLenum target, GLint offset, GLsizei size, const void* data);
305
306 void SetupVertexBuffer();
307
308 void SetupIndexBuffer();
309
310 void DeleteVertexBuffer();
311
312 void DeleteIndexBuffer();
313
314 void SetupClearTextureExpections(
315 GLuint service_id,
316 GLuint old_service_id,
317 GLenum bind_target,
318 GLenum target,
319 GLint level,
320 GLenum format,
321 GLenum type,
322 GLsizei width,
323 GLsizei height);
324
325 void SetupExpectationsForFramebufferClearing(
326 GLenum target,
236 GLuint clear_bits, 327 GLuint clear_bits,
237 GLclampf restore_red, 328 GLclampf restore_red,
238 GLclampf restore_green, 329 GLclampf restore_green,
239 GLclampf restore_blue, 330 GLclampf restore_blue,
240 GLclampf restore_alpha, 331 GLclampf restore_alpha,
241 GLuint restore_stencil, 332 GLuint restore_stencil,
242 GLclampf restore_depth, 333 GLclampf restore_depth,
243 bool restore_scissor_test); 334 bool restore_scissor_test);
244 335
245 void SetupExpectationsForApplyingDirtyState( 336 void SetupExpectationsForApplyingDirtyState(
246 bool framebuffer_is_rgb, 337 bool framebuffer_is_rgb,
247 bool framebuffer_has_depth, 338 bool framebuffer_has_depth,
248 bool framebuffer_has_stencil, 339 bool framebuffer_has_stencil,
249 GLuint color_bits, // NOTE! bits are 0x1000, 0x0100, 0x0010, and 0x0001 340 GLuint color_bits, // NOTE! bits are 0x1000, 0x0100, 0x0010, and 0x0001
250 bool depth_mask, 341 bool depth_mask,
251 bool depth_enabled, 342 bool depth_enabled,
252 GLuint front_stencil_mask, 343 GLuint front_stencil_mask,
253 GLuint back_stencil_mask, 344 GLuint back_stencil_mask,
254 bool stencil_enabled); 345 bool stencil_enabled);
255 346
256 void SetupExpectationsForApplyingDefaultDirtyState(); 347 void SetupExpectationsForApplyingDefaultDirtyState();
257 348
349 void AddExpectationsForSimulatedAttrib0WithError(
350 GLsizei num_vertices, GLuint buffer_id, GLenum error);
351
352 void AddExpectationsForSimulatedAttrib0(
353 GLsizei num_vertices, GLuint buffer_id);
354
258 GLvoid* BufferOffset(unsigned i) { 355 GLvoid* BufferOffset(unsigned i) {
259 return static_cast<int8 *>(NULL)+(i); 356 return static_cast<int8 *>(NULL)+(i);
260 } 357 }
261 358
262 template <typename Command, typename Result> 359 template <typename Command, typename Result>
263 bool IsObjectHelper(GLuint client_id) { 360 bool IsObjectHelper(GLuint client_id) {
264 Result* result = static_cast<Result*>(shared_memory_address_); 361 Result* result = static_cast<Result*>(shared_memory_address_);
265 Command cmd; 362 Command cmd;
266 cmd.Init(client_id, kSharedMemoryId, kSharedMemoryOffset); 363 cmd.Init(client_id, kSharedMemoryId, kSharedMemoryOffset);
267 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 364 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
268 bool isObject = static_cast<bool>(*result); 365 bool isObject = static_cast<bool>(*result);
269 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 366 EXPECT_EQ(GL_NO_ERROR, GetGLError());
270 return isObject; 367 return isObject;
271 } 368 }
272 369
273 // Use StrictMock to make 100% sure we know how GL will be called. 370 // Use StrictMock to make 100% sure we know how GL will be called.
274 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; 371 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
275 scoped_refptr<gfx::GLSurfaceStub> surface_; 372 scoped_refptr<gfx::GLSurfaceStub> surface_;
276 scoped_refptr<gfx::GLContextStub> context_; 373 scoped_refptr<gfx::GLContextStub> context_;
277 scoped_ptr<GLES2Decoder> decoder_; 374 scoped_ptr<GLES2Decoder> decoder_;
278 375
279 GLuint client_buffer_id_; 376 GLuint client_buffer_id_;
280 GLuint client_framebuffer_id_; 377 GLuint client_framebuffer_id_;
281 GLuint client_program_id_; 378 GLuint client_program_id_;
282 GLuint client_renderbuffer_id_; 379 GLuint client_renderbuffer_id_;
283 GLuint client_shader_id_; 380 GLuint client_shader_id_;
284 GLuint client_texture_id_; 381 GLuint client_texture_id_;
285 GLuint client_element_buffer_id_; 382 GLuint client_element_buffer_id_;
383 GLuint client_vertex_shader_id_;
384 GLuint client_fragment_shader_id_;
286 385
287 uint32 shared_memory_id_; 386 uint32 shared_memory_id_;
288 uint32 shared_memory_offset_; 387 uint32 shared_memory_offset_;
289 void* shared_memory_address_; 388 void* shared_memory_address_;
290 void* shared_memory_base_; 389 void* shared_memory_base_;
291 390
292 int8 immediate_buffer_[256]; 391 int8 immediate_buffer_[256];
293 392
294 private: 393 private:
295 class MockCommandBufferEngine : public CommandBufferEngine { 394 class MockCommandBufferEngine : public CommandBufferEngine {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 Buffer invalid_buffer_; 433 Buffer invalid_buffer_;
335 }; 434 };
336 435
337 scoped_ptr< ::testing::StrictMock<MockCommandBufferEngine> > engine_; 436 scoped_ptr< ::testing::StrictMock<MockCommandBufferEngine> > engine_;
338 ContextGroup::Ref group_; 437 ContextGroup::Ref group_;
339 }; 438 };
340 439
341 class GLES2DecoderWithShaderTestBase : public GLES2DecoderTestBase { 440 class GLES2DecoderWithShaderTestBase : public GLES2DecoderTestBase {
342 public: 441 public:
343 GLES2DecoderWithShaderTestBase() 442 GLES2DecoderWithShaderTestBase()
344 : GLES2DecoderTestBase(), 443 : GLES2DecoderTestBase() {
345 client_vertex_shader_id_(121),
346 client_fragment_shader_id_(122) {
347 } 444 }
348 445
349 static const GLuint kServiceVertexShaderId = 321;
350 static const GLuint kServiceFragmentShaderId = 322;
351
352 static const GLsizei kNumVertices = 100;
353 static const GLsizei kNumIndices = 10;
354 static const int kValidIndexRangeStart = 1;
355 static const int kValidIndexRangeCount = 7;
356 static const int kInvalidIndexRangeStart = 0;
357 static const int kInvalidIndexRangeCount = 7;
358 static const int kOutOfRangeIndexRangeEnd = 10;
359 static const GLuint kMaxValidIndex = 7;
360
361 static const GLint kMaxAttribLength = 10;
362 static const char* kAttrib1Name;
363 static const char* kAttrib2Name;
364 static const char* kAttrib3Name;
365 static const GLint kAttrib1Size = 1;
366 static const GLint kAttrib2Size = 1;
367 static const GLint kAttrib3Size = 1;
368 static const GLint kAttrib1Location = 0;
369 static const GLint kAttrib2Location = 1;
370 static const GLint kAttrib3Location = 2;
371 static const GLenum kAttrib1Type = GL_FLOAT_VEC4;
372 static const GLenum kAttrib2Type = GL_FLOAT_VEC2;
373 static const GLenum kAttrib3Type = GL_FLOAT_VEC3;
374 static const GLint kInvalidAttribLocation = 30;
375 static const GLint kBadAttribIndex = kNumVertexAttribs;
376
377 static const GLint kMaxUniformLength = 12;
378 static const char* kUniform1Name;
379 static const char* kUniform2Name;
380 static const char* kUniform3Name;
381 static const GLint kUniform1Size = 1;
382 static const GLint kUniform2Size = 3;
383 static const GLint kUniform3Size = 2;
384 static const GLint kUniform1Location = 3;
385 static const GLint kUniform2Location = 10;
386 static const GLint kUniform2ElementLocation = 12;
387 static const GLint kUniform3Location = 20;
388 static const GLenum kUniform1Type = GL_SAMPLER_2D;
389 static const GLenum kUniform2Type = GL_INT_VEC2;
390 static const GLenum kUniform3Type = GL_FLOAT_VEC3;
391 static const GLint kInvalidUniformLocation = 30;
392 static const GLint kBadUniformIndex = 1000;
393
394 protected: 446 protected:
395 virtual void SetUp(); 447 virtual void SetUp();
396 virtual void TearDown(); 448 virtual void TearDown();
397 449
398 void SetupDefaultProgram();
399 void SetupTexture();
400
401 void DoEnableVertexAttribArray(GLint index);
402
403 void DoBufferData(GLenum target, GLsizei size);
404
405 void DoBufferSubData(
406 GLenum target, GLint offset, GLsizei size, const void* data);
407
408 void SetupVertexBuffer();
409
410 void SetupIndexBuffer();
411
412 void DeleteVertexBuffer();
413
414 void DeleteIndexBuffer();
415
416 GLuint client_vertex_shader_id_;
417 GLuint client_fragment_shader_id_;
418 }; 450 };
419 451
420 } // namespace gles2 452 } // namespace gles2
421 } // namespace gpu 453 } // namespace gpu
422 454
423 #endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_BASE_H_ 455 #endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698