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"
39 class GLES2DecoderTestBase
: public ::testing::TestWithParam
<bool> {
41 GLES2DecoderTestBase();
42 virtual ~GLES2DecoderTestBase();
44 // Template to call glGenXXX functions.
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
56 template <typename T
, int id
>
57 void SpecializedSetup(bool valid
) {
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
;
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);
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);
94 T
GetSharedMemoryAs() {
95 return reinterpret_cast<T
>(shared_memory_address_
);
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(
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
;
192 std::string extensions
;
193 std::string gl_version
;
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
);
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 {
224 GLES2Decoder
* GetDecoder() const {
225 return decoder_
.get();
228 typedef TestHelper::AttribInfo AttribInfo
;
229 typedef TestHelper::UniformInfo UniformInfo
;
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();
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.
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
,
262 GLenum internal_format
,
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
);
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(
310 GLenum renderbuffer_target
,
311 GLuint renderbuffer_client_id
,
312 GLuint renderbuffer_service_id
,
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
,
347 GLenum internal_format
,
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
,
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
,
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
,
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
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_
);
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());
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 GLint kUniform1Size
= 1;
538 static const GLint kUniform2Size
= 3;
539 static const GLint kUniform3Size
= 2;
540 static const GLint kUniform1RealLocation
= 3;
541 static const GLint kUniform2RealLocation
= 10;
542 static const GLint kUniform2ElementRealLocation
= 12;
543 static const GLint kUniform3RealLocation
= 20;
544 static const GLint kUniform1FakeLocation
= 0; // These are
545 static const GLint kUniform2FakeLocation
= 1; // hardcoded
546 static const GLint kUniform2ElementFakeLocation
= 0x10001; // to match
547 static const GLint kUniform3FakeLocation
= 2; // ProgramManager.
548 static const GLint kUniform1DesiredLocation
= -1;
549 static const GLint kUniform2DesiredLocation
= -1;
550 static const GLint kUniform3DesiredLocation
= -1;
551 static const GLenum kUniform1Type
= GL_SAMPLER_2D
;
552 static const GLenum kUniform2Type
= GL_INT_VEC2
;
553 static const GLenum kUniform3Type
= GL_FLOAT_VEC3
;
554 static const GLenum kUniformSamplerExternalType
= GL_SAMPLER_EXTERNAL_OES
;
555 static const GLenum kUniformCubemapType
= GL_SAMPLER_CUBE
;
556 static const GLint kInvalidUniformLocation
= 30;
557 static const GLint kBadUniformIndex
= 1000;
559 // Use StrictMock to make 100% sure we know how GL will be called.
560 scoped_ptr
< ::testing::StrictMock
< ::gfx::MockGLInterface
> > gl_
;
561 scoped_refptr
<gfx::GLSurfaceStub
> surface_
;
562 scoped_refptr
<GLContextMock
> context_
;
563 scoped_ptr
<MockGLES2Decoder
> mock_decoder_
;
564 scoped_ptr
<GLES2Decoder
> decoder_
;
565 MemoryTracker
* memory_tracker_
;
567 GLuint client_buffer_id_
;
568 GLuint client_framebuffer_id_
;
569 GLuint client_program_id_
;
570 GLuint client_renderbuffer_id_
;
571 GLuint client_sampler_id_
;
572 GLuint client_shader_id_
;
573 GLuint client_texture_id_
;
574 GLuint client_element_buffer_id_
;
575 GLuint client_vertex_shader_id_
;
576 GLuint client_fragment_shader_id_
;
577 GLuint client_query_id_
;
578 GLuint client_vertexarray_id_
;
579 GLuint client_valuebuffer_id_
;
580 GLuint client_transformfeedback_id_
;
581 GLuint client_sync_id_
;
583 uint32 shared_memory_id_
;
584 uint32 shared_memory_offset_
;
585 void* shared_memory_address_
;
586 void* shared_memory_base_
;
588 GLuint service_renderbuffer_id_
;
589 bool service_renderbuffer_valid_
;
591 uint32 immediate_buffer_
[64];
593 const bool ignore_cached_state_for_test_
;
594 bool cached_color_mask_red_
;
595 bool cached_color_mask_green_
;
596 bool cached_color_mask_blue_
;
597 bool cached_color_mask_alpha_
;
598 bool cached_depth_mask_
;
599 GLuint cached_stencil_front_mask_
;
600 GLuint cached_stencil_back_mask_
;
605 bool cached_cull_face
;
606 bool cached_depth_test
;
608 bool cached_polygon_offset_fill
;
609 bool cached_sample_alpha_to_coverage
;
610 bool cached_sample_coverage
;
611 bool cached_scissor_test
;
612 bool cached_stencil_test
;
615 EnableFlags enable_flags_
;
618 class MockCommandBufferEngine
: public CommandBufferEngine
{
620 MockCommandBufferEngine();
622 ~MockCommandBufferEngine() override
;
624 scoped_refptr
<gpu::Buffer
> GetSharedMemoryBuffer(int32 shm_id
) override
;
626 void ClearSharedMemory() {
627 memset(valid_buffer_
->memory(), kInitialMemoryValue
, kSharedBufferSize
);
630 void set_token(int32 token
) override
;
632 bool SetGetBuffer(int32
/* transfer_buffer_id */) override
;
634 // Overridden from CommandBufferEngine.
635 bool SetGetOffset(int32 offset
) override
;
637 // Overridden from CommandBufferEngine.
638 int32
GetGetOffset() override
;
641 scoped_refptr
<gpu::Buffer
> valid_buffer_
;
642 scoped_refptr
<gpu::Buffer
> invalid_buffer_
;
645 // MockGLStates is used to track GL states and emulate driver
646 // behaviors on top of MockGLInterface.
650 : bound_array_buffer_object_(0),
651 bound_vertex_array_object_(0) {
657 void OnBindArrayBuffer(GLuint id
) {
658 bound_array_buffer_object_
= id
;
661 void OnBindVertexArrayOES(GLuint id
) {
662 bound_vertex_array_object_
= id
;
665 void OnVertexAttribNullPointer() {
666 // When a vertex array object is bound, some drivers (AMD Linux,
667 // Qualcomm, etc.) have a bug where it incorrectly generates an
668 // GL_INVALID_OPERATION on glVertexAttribPointer() if pointer
669 // is NULL, no buffer is bound on GL_ARRAY_BUFFER.
670 // Make sure we don't trigger this bug.
671 if (bound_vertex_array_object_
!= 0)
672 EXPECT_TRUE(bound_array_buffer_object_
!= 0);
676 GLuint bound_array_buffer_object_
;
677 GLuint bound_vertex_array_object_
;
678 }; // class MockGLStates
680 void AddExpectationsForVertexAttribManager();
681 void SetupMockGLBehaviors();
683 scoped_ptr
< ::testing::StrictMock
<MockCommandBufferEngine
> > engine_
;
684 scoped_refptr
<ContextGroup
> group_
;
685 MockGLStates gl_states_
;
688 class GLES2DecoderWithShaderTestBase
: public GLES2DecoderTestBase
{
690 GLES2DecoderWithShaderTestBase()
691 : GLES2DecoderTestBase() {
695 void SetUp() override
;
696 void TearDown() override
;
699 // SpecializedSetup specializations that are needed in multiple unittest files.
701 void GLES2DecoderTestBase::SpecializedSetup
<cmds::LinkProgram
, 0>(bool valid
);
706 #endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_BASE_H_