Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_base.h
blob2eac8b3204b0b5c18f39e1f44a7a962a71a66996
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
3 // found in the LICENSE file.
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_BASE_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_BASE_H_
8 #include "gpu/command_buffer/common/gles2_cmd_format.h"
9 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
10 #include "gpu/command_buffer/service/buffer_manager.h"
11 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
12 #include "gpu/command_buffer/service/context_group.h"
13 #include "gpu/command_buffer/service/framebuffer_manager.h"
14 #include "gpu/command_buffer/service/gl_context_mock.h"
15 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
16 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
17 #include "gpu/command_buffer/service/program_manager.h"
18 #include "gpu/command_buffer/service/query_manager.h"
19 #include "gpu/command_buffer/service/renderbuffer_manager.h"
20 #include "gpu/command_buffer/service/shader_manager.h"
21 #include "gpu/command_buffer/service/test_helper.h"
22 #include "gpu/command_buffer/service/texture_manager.h"
23 #include "gpu/command_buffer/service/valuebuffer_manager.h"
24 #include "gpu/command_buffer/service/vertex_array_manager.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/gl/gl_surface_stub.h"
27 #include "ui/gl/gl_mock.h"
28 #include "ui/gl/gl_version_info.h"
30 namespace base {
31 class CommandLine;
34 namespace gpu {
35 namespace gles2 {
37 class MemoryTracker;
39 class GLES2DecoderTestBase : public ::testing::TestWithParam<bool> {
40 public:
41 GLES2DecoderTestBase();
42 virtual ~GLES2DecoderTestBase();
44 // Template to call glGenXXX functions.
45 template <typename T>
46 void GenHelper(GLuint client_id) {
47 int8 buffer[sizeof(T) + sizeof(client_id)];
48 T& cmd = *reinterpret_cast<T*>(&buffer);
49 cmd.Init(1, &client_id);
50 EXPECT_EQ(error::kNoError,
51 ExecuteImmediateCmd(cmd, sizeof(client_id)));
54 // This template exists solely so we can specialize it for
55 // certain commands.
56 template <typename T, int id>
57 void SpecializedSetup(bool valid) {
60 template <typename T>
61 T* GetImmediateAs() {
62 return reinterpret_cast<T*>(immediate_buffer_);
65 template <typename T, typename Command>
66 T GetImmediateDataAs(Command* cmd) {
67 return reinterpret_cast<T>(ImmediateDataAddress(cmd));
70 void ClearSharedMemory() {
71 engine_->ClearSharedMemory();
74 void SetUp() override;
75 void TearDown() override;
77 template <typename T>
78 error::Error ExecuteCmd(const T& cmd) {
79 static_assert(T::kArgFlags == cmd::kFixed,
80 "T::kArgFlags should equal cmd::kFixed");
81 return decoder_->DoCommands(
82 1, (const void*)&cmd, ComputeNumEntries(sizeof(cmd)), 0);
85 template <typename T>
86 error::Error ExecuteImmediateCmd(const T& cmd, size_t data_size) {
87 static_assert(T::kArgFlags == cmd::kAtLeastN,
88 "T::kArgFlags should equal cmd::kAtLeastN");
89 return decoder_->DoCommands(
90 1, (const void*)&cmd, ComputeNumEntries(sizeof(cmd) + data_size), 0);
93 template <typename T>
94 T GetSharedMemoryAs() {
95 return reinterpret_cast<T>(shared_memory_address_);
98 template <typename T>
99 T GetSharedMemoryAsWithOffset(uint32 offset) {
100 void* ptr = reinterpret_cast<int8*>(shared_memory_address_) + offset;
101 return reinterpret_cast<T>(ptr);
104 Buffer* GetBuffer(GLuint service_id) {
105 return group_->buffer_manager()->GetBuffer(service_id);
108 Framebuffer* GetFramebuffer(GLuint service_id) {
109 return group_->framebuffer_manager()->GetFramebuffer(service_id);
112 Renderbuffer* GetRenderbuffer(
113 GLuint service_id) {
114 return group_->renderbuffer_manager()->GetRenderbuffer(service_id);
117 TextureRef* GetTexture(GLuint client_id) {
118 return group_->texture_manager()->GetTexture(client_id);
121 Shader* GetShader(GLuint client_id) {
122 return group_->shader_manager()->GetShader(client_id);
125 Program* GetProgram(GLuint client_id) {
126 return group_->program_manager()->GetProgram(client_id);
129 Valuebuffer* GetValuebuffer(GLuint client_id) {
130 return group_->valuebuffer_manager()->GetValuebuffer(client_id);
133 QueryManager::Query* GetQueryInfo(GLuint client_id) {
134 return decoder_->GetQueryManager()->GetQuery(client_id);
137 bool GetSamplerServiceId(GLuint client_id, GLuint* service_id) const {
138 return group_->GetSamplerServiceId(client_id, service_id);
141 bool GetTransformFeedbackServiceId(
142 GLuint client_id, GLuint* service_id) const {
143 return group_->GetTransformFeedbackServiceId(client_id, service_id);
146 bool GetSyncServiceId(GLuint client_id, GLsync* service_id) const {
147 return group_->GetSyncServiceId(client_id, service_id);
150 // This name doesn't match the underlying function, but doing it this way
151 // prevents the need to special-case the unit test generation
152 VertexAttribManager* GetVertexArrayInfo(GLuint client_id) {
153 return decoder_->GetVertexArrayManager()->GetVertexAttribManager(client_id);
156 ProgramManager* program_manager() {
157 return group_->program_manager();
160 ValuebufferManager* valuebuffer_manager() {
161 return group_->valuebuffer_manager();
164 ValueStateMap* pending_valuebuffer_state() {
165 return group_->pending_valuebuffer_state();
168 FeatureInfo* feature_info() {
169 return group_->feature_info();
172 ImageManager* GetImageManager() { return decoder_->GetImageManager(); }
174 void DoCreateProgram(GLuint client_id, GLuint service_id);
175 void DoCreateShader(GLenum shader_type, GLuint client_id, GLuint service_id);
176 void DoFenceSync(GLuint client_id, GLuint service_id);
178 void SetBucketData(uint32_t bucket_id, const void* data, uint32_t data_size);
179 void SetBucketAsCString(uint32 bucket_id, const char* str);
180 // If we want a valid bucket, just set |count_in_header| as |count|,
181 // and set |str_end| as 0.
182 void SetBucketAsCStrings(uint32 bucket_id, GLsizei count, const char** str,
183 GLsizei count_in_header, char str_end);
185 void set_memory_tracker(MemoryTracker* memory_tracker) {
186 memory_tracker_ = memory_tracker;
189 struct InitState {
190 InitState();
192 std::string extensions;
193 std::string gl_version;
194 bool has_alpha;
195 bool has_depth;
196 bool has_stencil;
197 bool request_alpha;
198 bool request_depth;
199 bool request_stencil;
200 bool bind_generates_resource;
201 bool lose_context_when_out_of_memory;
202 bool use_native_vao; // default is true.
203 unsigned webgl_version; // default to 0, i.e., not WebGL context.
206 void InitDecoder(const InitState& init);
207 void InitDecoderWithCommandLine(const InitState& init,
208 const base::CommandLine* command_line);
210 void ResetDecoder();
212 const ContextGroup& group() const {
213 return *group_.get();
216 void LoseContexts(error::ContextLostReason reason) const {
217 group_->LoseContexts(reason);
220 ::testing::StrictMock< ::gfx::MockGLInterface>* GetGLMock() const {
221 return gl_.get();
224 GLES2Decoder* GetDecoder() const {
225 return decoder_.get();
228 typedef TestHelper::AttribInfo AttribInfo;
229 typedef TestHelper::UniformInfo UniformInfo;
231 void SetupShader(
232 AttribInfo* attribs, size_t num_attribs,
233 UniformInfo* uniforms, size_t num_uniforms,
234 GLuint client_id, GLuint service_id,
235 GLuint vertex_shader_client_id, GLuint vertex_shader_service_id,
236 GLuint fragment_shader_client_id, GLuint fragment_shader_service_id);
238 void SetupInitCapabilitiesExpectations(bool es3_capable);
239 void SetupInitStateExpectations();
240 void ExpectEnableDisable(GLenum cap, bool enable);
242 // Setups up a shader for testing glUniform.
243 void SetupShaderForUniform(GLenum uniform_type);
244 void SetupDefaultProgram();
245 void SetupCubemapProgram();
246 void SetupSamplerExternalProgram();
247 void SetupTexture();
249 // Note that the error is returned as GLint instead of GLenum.
250 // This is because there is a mismatch in the types of GLenum and
251 // the error values GL_NO_ERROR, GL_INVALID_ENUM, etc. GLenum is
252 // typedef'd as unsigned int while the error values are defined as
253 // integers. This is problematic for template functions such as
254 // EXPECT_EQ that expect both types to be the same.
255 GLint GetGLError();
257 void DoBindBuffer(GLenum target, GLuint client_id, GLuint service_id);
258 void DoBindFramebuffer(GLenum target, GLuint client_id, GLuint service_id);
259 void DoBindRenderbuffer(GLenum target, GLuint client_id, GLuint service_id);
260 void DoRenderbufferStorageMultisampleCHROMIUM(GLenum target,
261 GLsizei samples,
262 GLenum internal_format,
263 GLenum gl_format,
264 GLsizei width,
265 GLsizei height);
266 void RestoreRenderbufferBindings();
267 void EnsureRenderbufferBound(bool expect_bind);
268 void DoBindTexture(GLenum target, GLuint client_id, GLuint service_id);
269 void DoBindVertexArrayOES(GLuint client_id, GLuint service_id);
271 bool DoIsBuffer(GLuint client_id);
272 bool DoIsFramebuffer(GLuint client_id);
273 bool DoIsProgram(GLuint client_id);
274 bool DoIsRenderbuffer(GLuint client_id);
275 bool DoIsShader(GLuint client_id);
276 bool DoIsTexture(GLuint client_id);
278 void DoDeleteBuffer(GLuint client_id, GLuint service_id);
279 void DoDeleteFramebuffer(
280 GLuint client_id, GLuint service_id,
281 bool reset_draw, GLenum draw_target, GLuint draw_id,
282 bool reset_read, GLenum read_target, GLuint read_id);
283 void DoDeleteProgram(GLuint client_id, GLuint service_id);
284 void DoDeleteRenderbuffer(GLuint client_id, GLuint service_id);
285 void DoDeleteShader(GLuint client_id, GLuint service_id);
286 void DoDeleteTexture(GLuint client_id, GLuint service_id);
288 void DoCompressedTexImage2D(
289 GLenum target, GLint level, GLenum format,
290 GLsizei width, GLsizei height, GLint border,
291 GLsizei size, uint32 bucket_id);
292 void DoBindTexImage2DCHROMIUM(GLenum target, GLint image_id);
293 void DoTexImage2D(
294 GLenum target, GLint level, GLenum internal_format,
295 GLsizei width, GLsizei height, GLint border,
296 GLenum format, GLenum type,
297 uint32 shared_memory_id, uint32 shared_memory_offset);
298 void DoTexImage2DConvertInternalFormat(
299 GLenum target, GLint level, GLenum requested_internal_format,
300 GLsizei width, GLsizei height, GLint border,
301 GLenum format, GLenum type,
302 uint32 shared_memory_id, uint32 shared_memory_offset,
303 GLenum expected_internal_format);
304 void DoRenderbufferStorage(
305 GLenum target, GLenum internal_format, GLenum actual_format,
306 GLsizei width, GLsizei height, GLenum error);
307 void DoFramebufferRenderbuffer(
308 GLenum target,
309 GLenum attachment,
310 GLenum renderbuffer_target,
311 GLuint renderbuffer_client_id,
312 GLuint renderbuffer_service_id,
313 GLenum error);
314 void DoFramebufferTexture2D(
315 GLenum target, GLenum attachment, GLenum tex_target,
316 GLuint texture_client_id, GLuint texture_service_id,
317 GLint level, GLenum error);
318 void DoVertexAttribPointer(
319 GLuint index, GLint size, GLenum type, GLsizei stride, GLuint offset);
320 void DoVertexAttribDivisorANGLE(GLuint index, GLuint divisor);
322 void DoEnableDisable(GLenum cap, bool enable);
324 void DoEnableVertexAttribArray(GLint index);
326 void DoBufferData(GLenum target, GLsizei size);
328 void DoBufferSubData(
329 GLenum target, GLint offset, GLsizei size, const void* data);
331 void DoScissor(GLint x, GLint y, GLsizei width, GLsizei height);
333 void SetupVertexBuffer();
334 void SetupAllNeededVertexBuffers();
336 void SetupIndexBuffer();
338 void DeleteVertexBuffer();
340 void DeleteIndexBuffer();
342 void SetupClearTextureExpectations(GLuint service_id,
343 GLuint old_service_id,
344 GLenum bind_target,
345 GLenum target,
346 GLint level,
347 GLenum internal_format,
348 GLenum format,
349 GLenum type,
350 GLint xoffset,
351 GLint yoffset,
352 GLsizei width,
353 GLsizei height);
355 void SetupExpectationsForRestoreClearState(GLclampf restore_red,
356 GLclampf restore_green,
357 GLclampf restore_blue,
358 GLclampf restore_alpha,
359 GLuint restore_stencil,
360 GLclampf restore_depth,
361 bool restore_scissor_test,
362 GLint restore_scissor_x,
363 GLint restore_scissor_y,
364 GLsizei restore_scissor_width,
365 GLsizei restore_scissor_height);
367 void SetupExpectationsForFramebufferClearing(GLenum target,
368 GLuint clear_bits,
369 GLclampf restore_red,
370 GLclampf restore_green,
371 GLclampf restore_blue,
372 GLclampf restore_alpha,
373 GLuint restore_stencil,
374 GLclampf restore_depth,
375 bool restore_scissor_test,
376 GLint restore_scissor_x,
377 GLint restore_scissor_y,
378 GLsizei restore_scissor_width,
379 GLsizei restore_scissor_height);
381 void SetupExpectationsForFramebufferClearingMulti(
382 GLuint read_framebuffer_service_id,
383 GLuint draw_framebuffer_service_id,
384 GLenum target,
385 GLuint clear_bits,
386 GLclampf restore_red,
387 GLclampf restore_green,
388 GLclampf restore_blue,
389 GLclampf restore_alpha,
390 GLuint restore_stencil,
391 GLclampf restore_depth,
392 bool restore_scissor_test,
393 GLint restore_scissor_x,
394 GLint restore_scissor_y,
395 GLsizei restore_scissor_width,
396 GLsizei restore_scissor_height);
398 void SetupExpectationsForDepthMask(bool mask);
399 void SetupExpectationsForEnableDisable(GLenum cap, bool enable);
400 void SetupExpectationsForColorMask(bool red,
401 bool green,
402 bool blue,
403 bool alpha);
404 void SetupExpectationsForStencilMask(GLuint front_mask, GLuint back_mask);
406 void SetupExpectationsForApplyingDirtyState(
407 bool framebuffer_is_rgb,
408 bool framebuffer_has_depth,
409 bool framebuffer_has_stencil,
410 GLuint color_bits, // NOTE! bits are 0x1000, 0x0100, 0x0010, and 0x0001
411 bool depth_mask,
412 bool depth_enabled,
413 GLuint front_stencil_mask,
414 GLuint back_stencil_mask,
415 bool stencil_enabled);
417 void SetupExpectationsForApplyingDefaultDirtyState();
419 void AddExpectationsForSimulatedAttrib0WithError(
420 GLsizei num_vertices, GLuint buffer_id, GLenum error);
422 void AddExpectationsForSimulatedAttrib0(
423 GLsizei num_vertices, GLuint buffer_id);
425 void AddExpectationsForGenVertexArraysOES();
426 void AddExpectationsForDeleteVertexArraysOES();
427 void AddExpectationsForDeleteBoundVertexArraysOES();
428 void AddExpectationsForBindVertexArrayOES();
429 void AddExpectationsForRestoreAttribState(GLuint attrib);
431 GLvoid* BufferOffset(unsigned i) {
432 return static_cast<int8 *>(NULL)+(i);
435 template <typename Command, typename Result>
436 bool IsObjectHelper(GLuint client_id) {
437 Result* result = static_cast<Result*>(shared_memory_address_);
438 Command cmd;
439 cmd.Init(client_id, kSharedMemoryId, kSharedMemoryOffset);
440 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
441 bool isObject = static_cast<bool>(*result);
442 EXPECT_EQ(GL_NO_ERROR, GetGLError());
443 return isObject;
446 protected:
447 static const int kBackBufferWidth = 128;
448 static const int kBackBufferHeight = 64;
450 static const GLint kMaxTextureSize = 2048;
451 static const GLint kMaxCubeMapTextureSize = 256;
452 static const GLint kNumVertexAttribs = 16;
453 static const GLint kNumTextureUnits = 8;
454 static const GLint kMaxTextureImageUnits = 8;
455 static const GLint kMaxVertexTextureImageUnits = 2;
456 static const GLint kMaxFragmentUniformVectors = 16;
457 static const GLint kMaxVaryingVectors = 8;
458 static const GLint kMaxVertexUniformVectors = 128;
459 static const GLint kMaxViewportWidth = 8192;
460 static const GLint kMaxViewportHeight = 8192;
462 static const GLint kViewportX = 0;
463 static const GLint kViewportY = 0;
464 static const GLint kViewportWidth = kBackBufferWidth;
465 static const GLint kViewportHeight = kBackBufferHeight;
467 static const GLuint kServiceAttrib0BufferId = 801;
468 static const GLuint kServiceFixedAttribBufferId = 802;
470 static const GLuint kServiceBufferId = 301;
471 static const GLuint kServiceFramebufferId = 302;
472 static const GLuint kServiceRenderbufferId = 303;
473 static const GLuint kServiceTextureId = 304;
474 static const GLuint kServiceProgramId = 305;
475 static const GLuint kServiceSamplerId = 306;
476 static const GLuint kServiceShaderId = 307;
477 static const GLuint kServiceElementBufferId = 308;
478 static const GLuint kServiceQueryId = 309;
479 static const GLuint kServiceVertexArrayId = 310;
480 static const GLuint kServiceTransformFeedbackId = 311;
481 static const GLuint kServiceSyncId = 312;
483 static const int32 kSharedMemoryId = 401;
484 static const size_t kSharedBufferSize = 2048;
485 static const uint32 kSharedMemoryOffset = 132;
486 static const int32 kInvalidSharedMemoryId = 402;
487 static const uint32 kInvalidSharedMemoryOffset = kSharedBufferSize + 1;
488 static const uint32 kInitialResult = 0xBDBDBDBDu;
489 static const uint8 kInitialMemoryValue = 0xBDu;
491 static const uint32 kNewClientId = 501;
492 static const uint32 kNewServiceId = 502;
493 static const uint32 kInvalidClientId = 601;
495 static const GLuint kServiceVertexShaderId = 321;
496 static const GLuint kServiceFragmentShaderId = 322;
498 static const GLuint kServiceCopyTextureChromiumShaderId = 701;
499 static const GLuint kServiceCopyTextureChromiumProgramId = 721;
501 static const GLuint kServiceCopyTextureChromiumTextureBufferId = 751;
502 static const GLuint kServiceCopyTextureChromiumVertexBufferId = 752;
503 static const GLuint kServiceCopyTextureChromiumFBOId = 753;
504 static const GLuint kServiceCopyTextureChromiumPositionAttrib = 761;
505 static const GLuint kServiceCopyTextureChromiumTexAttrib = 762;
506 static const GLuint kServiceCopyTextureChromiumSamplerLocation = 763;
508 static const GLsizei kNumVertices = 100;
509 static const GLsizei kNumIndices = 10;
510 static const int kValidIndexRangeStart = 1;
511 static const int kValidIndexRangeCount = 7;
512 static const int kInvalidIndexRangeStart = 0;
513 static const int kInvalidIndexRangeCount = 7;
514 static const int kOutOfRangeIndexRangeEnd = 10;
515 static const GLuint kMaxValidIndex = 7;
517 static const GLint kMaxAttribLength = 10;
518 static const char* kAttrib1Name;
519 static const char* kAttrib2Name;
520 static const char* kAttrib3Name;
521 static const GLint kAttrib1Size = 1;
522 static const GLint kAttrib2Size = 1;
523 static const GLint kAttrib3Size = 1;
524 static const GLint kAttrib1Location = 0;
525 static const GLint kAttrib2Location = 1;
526 static const GLint kAttrib3Location = 2;
527 static const GLenum kAttrib1Type = GL_FLOAT_VEC4;
528 static const GLenum kAttrib2Type = GL_FLOAT_VEC2;
529 static const GLenum kAttrib3Type = GL_FLOAT_VEC3;
530 static const GLint kInvalidAttribLocation = 30;
531 static const GLint kBadAttribIndex = kNumVertexAttribs;
533 static const GLint kMaxUniformLength = 12;
534 static const char* kUniform1Name;
535 static const char* kUniform2Name;
536 static const char* kUniform3Name;
537 static const char* kUniform4Name;
538 static const char* kUniform5Name;
539 static const char* kUniform6Name;
540 static const char* kUniform7Name;
541 static const GLint kUniform1Size = 1;
542 static const GLint kUniform2Size = 3;
543 static const GLint kUniform3Size = 2;
544 static const GLint kUniform4Size = 1;
545 static const GLint kUniform5Size = 1;
546 static const GLint kUniform6Size = 1;
547 static const GLint kUniform7Size = 1;
548 static const GLint kUniform1RealLocation = 3;
549 static const GLint kUniform2RealLocation = 10;
550 static const GLint kUniform2ElementRealLocation = 12;
551 static const GLint kUniform3RealLocation = 20;
552 static const GLint kUniform4RealLocation = 22;
553 static const GLint kUniform5RealLocation = 30;
554 static const GLint kUniform6RealLocation = 32;
555 static const GLint kUniform7RealLocation = 44;
556 static const GLint kUniform1FakeLocation = 0; // These are
557 static const GLint kUniform2FakeLocation = 1; // hardcoded
558 static const GLint kUniform2ElementFakeLocation = 0x10001; // to match
559 static const GLint kUniform3FakeLocation = 2; // ProgramManager.
560 static const GLint kUniform4FakeLocation = 3; //
561 static const GLint kUniform5FakeLocation = 4; //
562 static const GLint kUniform6FakeLocation = 5; //
563 static const GLint kUniform7FakeLocation = 6; //
564 static const GLint kUniform1DesiredLocation = -1;
565 static const GLint kUniform2DesiredLocation = -1;
566 static const GLint kUniform3DesiredLocation = -1;
567 static const GLint kUniform4DesiredLocation = -1;
568 static const GLint kUniform5DesiredLocation = -1;
569 static const GLint kUniform6DesiredLocation = -1;
570 static const GLint kUniform7DesiredLocation = -1;
571 static const GLenum kUniform1Type = GL_SAMPLER_2D;
572 static const GLenum kUniform2Type = GL_INT_VEC2;
573 static const GLenum kUniform3Type = GL_FLOAT_VEC3;
574 static const GLenum kUniform4Type = GL_UNSIGNED_INT;
575 static const GLenum kUniform5Type = GL_UNSIGNED_INT_VEC2;
576 static const GLenum kUniform6Type = GL_UNSIGNED_INT_VEC3;
577 static const GLenum kUniform7Type = GL_UNSIGNED_INT_VEC4;
578 static const GLenum kUniformSamplerExternalType = GL_SAMPLER_EXTERNAL_OES;
579 static const GLenum kUniformCubemapType = GL_SAMPLER_CUBE;
580 static const GLint kInvalidUniformLocation = 30;
581 static const GLint kBadUniformIndex = 1000;
583 // Use StrictMock to make 100% sure we know how GL will be called.
584 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
585 scoped_refptr<gfx::GLSurfaceStub> surface_;
586 scoped_refptr<GLContextMock> context_;
587 scoped_ptr<MockGLES2Decoder> mock_decoder_;
588 scoped_ptr<GLES2Decoder> decoder_;
589 MemoryTracker* memory_tracker_;
591 GLuint client_buffer_id_;
592 GLuint client_framebuffer_id_;
593 GLuint client_program_id_;
594 GLuint client_renderbuffer_id_;
595 GLuint client_sampler_id_;
596 GLuint client_shader_id_;
597 GLuint client_texture_id_;
598 GLuint client_element_buffer_id_;
599 GLuint client_vertex_shader_id_;
600 GLuint client_fragment_shader_id_;
601 GLuint client_query_id_;
602 GLuint client_vertexarray_id_;
603 GLuint client_valuebuffer_id_;
604 GLuint client_transformfeedback_id_;
605 GLuint client_sync_id_;
607 uint32 shared_memory_id_;
608 uint32 shared_memory_offset_;
609 void* shared_memory_address_;
610 void* shared_memory_base_;
612 GLuint service_renderbuffer_id_;
613 bool service_renderbuffer_valid_;
615 uint32 immediate_buffer_[64];
617 const bool ignore_cached_state_for_test_;
618 bool cached_color_mask_red_;
619 bool cached_color_mask_green_;
620 bool cached_color_mask_blue_;
621 bool cached_color_mask_alpha_;
622 bool cached_depth_mask_;
623 GLuint cached_stencil_front_mask_;
624 GLuint cached_stencil_back_mask_;
626 struct EnableFlags {
627 EnableFlags();
628 bool cached_blend;
629 bool cached_cull_face;
630 bool cached_depth_test;
631 bool cached_dither;
632 bool cached_polygon_offset_fill;
633 bool cached_sample_alpha_to_coverage;
634 bool cached_sample_coverage;
635 bool cached_scissor_test;
636 bool cached_stencil_test;
639 EnableFlags enable_flags_;
641 private:
642 class MockCommandBufferEngine : public CommandBufferEngine {
643 public:
644 MockCommandBufferEngine();
646 ~MockCommandBufferEngine() override;
648 scoped_refptr<gpu::Buffer> GetSharedMemoryBuffer(int32 shm_id) override;
650 void ClearSharedMemory() {
651 memset(valid_buffer_->memory(), kInitialMemoryValue, kSharedBufferSize);
654 void set_token(int32 token) override;
656 bool SetGetBuffer(int32 /* transfer_buffer_id */) override;
658 // Overridden from CommandBufferEngine.
659 bool SetGetOffset(int32 offset) override;
661 // Overridden from CommandBufferEngine.
662 int32 GetGetOffset() override;
664 private:
665 scoped_refptr<gpu::Buffer> valid_buffer_;
666 scoped_refptr<gpu::Buffer> invalid_buffer_;
669 // MockGLStates is used to track GL states and emulate driver
670 // behaviors on top of MockGLInterface.
671 class MockGLStates {
672 public:
673 MockGLStates()
674 : bound_array_buffer_object_(0),
675 bound_vertex_array_object_(0) {
678 ~MockGLStates() {
681 void OnBindArrayBuffer(GLuint id) {
682 bound_array_buffer_object_ = id;
685 void OnBindVertexArrayOES(GLuint id) {
686 bound_vertex_array_object_ = id;
689 void OnVertexAttribNullPointer() {
690 // When a vertex array object is bound, some drivers (AMD Linux,
691 // Qualcomm, etc.) have a bug where it incorrectly generates an
692 // GL_INVALID_OPERATION on glVertexAttribPointer() if pointer
693 // is NULL, no buffer is bound on GL_ARRAY_BUFFER.
694 // Make sure we don't trigger this bug.
695 if (bound_vertex_array_object_ != 0)
696 EXPECT_TRUE(bound_array_buffer_object_ != 0);
699 private:
700 GLuint bound_array_buffer_object_;
701 GLuint bound_vertex_array_object_;
702 }; // class MockGLStates
704 void AddExpectationsForVertexAttribManager();
705 void SetupMockGLBehaviors();
707 scoped_ptr< ::testing::StrictMock<MockCommandBufferEngine> > engine_;
708 scoped_refptr<ContextGroup> group_;
709 MockGLStates gl_states_;
712 class GLES2DecoderWithShaderTestBase : public GLES2DecoderTestBase {
713 public:
714 GLES2DecoderWithShaderTestBase()
715 : GLES2DecoderTestBase() {
718 protected:
719 void SetUp() override;
720 void TearDown() override;
723 // SpecializedSetup specializations that are needed in multiple unittest files.
724 template <>
725 void GLES2DecoderTestBase::SpecializedSetup<cmds::LinkProgram, 0>(bool valid);
727 } // namespace gles2
728 } // namespace gpu
730 #endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_BASE_H_