Don't add an aura tooltip to bubble close buttons on Windows.
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_base.h
blob0ca537a8952aaa9e3a6ddf9c23bb5b818e285952
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/gles2_cmd_decoder.h"
15 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
16 #include "gpu/command_buffer/service/program_manager.h"
17 #include "gpu/command_buffer/service/query_manager.h"
18 #include "gpu/command_buffer/service/renderbuffer_manager.h"
19 #include "gpu/command_buffer/service/shader_manager.h"
20 #include "gpu/command_buffer/service/test_helper.h"
21 #include "gpu/command_buffer/service/texture_manager.h"
22 #include "gpu/command_buffer/service/valuebuffer_manager.h"
23 #include "gpu/command_buffer/service/vertex_array_manager.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/gl/gl_context_stub_with_extensions.h"
26 #include "ui/gl/gl_surface_stub.h"
27 #include "ui/gl/gl_mock.h"
29 namespace base {
30 class CommandLine;
33 namespace gpu {
34 namespace gles2 {
36 class MemoryTracker;
38 class GLES2DecoderTestBase : public ::testing::TestWithParam<bool> {
39 public:
40 GLES2DecoderTestBase();
41 virtual ~GLES2DecoderTestBase();
43 // Template to call glGenXXX functions.
44 template <typename T>
45 void GenHelper(GLuint client_id) {
46 int8 buffer[sizeof(T) + sizeof(client_id)];
47 T& cmd = *reinterpret_cast<T*>(&buffer);
48 cmd.Init(1, &client_id);
49 EXPECT_EQ(error::kNoError,
50 ExecuteImmediateCmd(cmd, sizeof(client_id)));
53 // This template exists solely so we can specialize it for
54 // certain commands.
55 template <typename T, int id>
56 void SpecializedSetup(bool valid) {
59 template <typename T>
60 T* GetImmediateAs() {
61 return reinterpret_cast<T*>(immediate_buffer_);
64 template <typename T, typename Command>
65 T GetImmediateDataAs(Command* cmd) {
66 return reinterpret_cast<T>(ImmediateDataAddress(cmd));
69 void ClearSharedMemory() {
70 engine_->ClearSharedMemory();
73 void SetUp() override;
74 void TearDown() override;
76 template <typename T>
77 error::Error ExecuteCmd(const T& cmd) {
78 static_assert(T::kArgFlags == cmd::kFixed,
79 "T::kArgFlags should equal cmd::kFixed");
80 return decoder_->DoCommands(
81 1, (const void*)&cmd, ComputeNumEntries(sizeof(cmd)), 0);
84 template <typename T>
85 error::Error ExecuteImmediateCmd(const T& cmd, size_t data_size) {
86 static_assert(T::kArgFlags == cmd::kAtLeastN,
87 "T::kArgFlags should equal cmd::kAtLeastN");
88 return decoder_->DoCommands(
89 1, (const void*)&cmd, ComputeNumEntries(sizeof(cmd) + data_size), 0);
92 template <typename T>
93 T GetSharedMemoryAs() {
94 return reinterpret_cast<T>(shared_memory_address_);
97 template <typename T>
98 T GetSharedMemoryAsWithOffset(uint32 offset) {
99 void* ptr = reinterpret_cast<int8*>(shared_memory_address_) + offset;
100 return reinterpret_cast<T>(ptr);
103 Buffer* GetBuffer(GLuint service_id) {
104 return group_->buffer_manager()->GetBuffer(service_id);
107 Framebuffer* GetFramebuffer(GLuint service_id) {
108 return group_->framebuffer_manager()->GetFramebuffer(service_id);
111 Renderbuffer* GetRenderbuffer(
112 GLuint service_id) {
113 return group_->renderbuffer_manager()->GetRenderbuffer(service_id);
116 TextureRef* GetTexture(GLuint client_id) {
117 return group_->texture_manager()->GetTexture(client_id);
120 Shader* GetShader(GLuint client_id) {
121 return group_->shader_manager()->GetShader(client_id);
124 Program* GetProgram(GLuint client_id) {
125 return group_->program_manager()->GetProgram(client_id);
128 Valuebuffer* GetValuebuffer(GLuint client_id) {
129 return group_->valuebuffer_manager()->GetValuebuffer(client_id);
132 QueryManager::Query* GetQueryInfo(GLuint client_id) {
133 return decoder_->GetQueryManager()->GetQuery(client_id);
136 bool GetSamplerServiceId(GLuint client_id, GLuint* service_id) const {
137 return group_->GetSamplerServiceId(client_id, service_id);
140 bool GetTransformFeedbackServiceId(
141 GLuint client_id, GLuint* service_id) const {
142 return group_->GetTransformFeedbackServiceId(client_id, service_id);
145 bool GetSyncServiceId(GLuint client_id, GLsync* service_id) const {
146 return group_->GetSyncServiceId(client_id, service_id);
149 // This name doesn't match the underlying function, but doing it this way
150 // prevents the need to special-case the unit test generation
151 VertexAttribManager* GetVertexArrayInfo(GLuint client_id) {
152 return decoder_->GetVertexArrayManager()->GetVertexAttribManager(client_id);
155 ProgramManager* program_manager() {
156 return group_->program_manager();
159 ValuebufferManager* valuebuffer_manager() {
160 return group_->valuebuffer_manager();
163 ValueStateMap* pending_valuebuffer_state() {
164 return group_->pending_valuebuffer_state();
167 FeatureInfo* feature_info() {
168 return group_->feature_info();
171 ImageManager* GetImageManager() { return decoder_->GetImageManager(); }
173 void DoCreateProgram(GLuint client_id, GLuint service_id);
174 void DoCreateShader(GLenum shader_type, GLuint client_id, GLuint service_id);
175 void DoFenceSync(GLuint client_id, GLuint service_id);
177 void SetBucketData(uint32_t bucket_id, const void* data, uint32_t data_size);
178 void SetBucketAsCString(uint32 bucket_id, const char* str);
179 // If we want a valid bucket, just set |count_in_header| as |count|,
180 // and set |str_end| as 0.
181 void SetBucketAsCStrings(uint32 bucket_id, GLsizei count, const char** str,
182 GLsizei count_in_header, char str_end);
184 void set_memory_tracker(MemoryTracker* memory_tracker) {
185 memory_tracker_ = memory_tracker;
188 struct InitState {
189 InitState();
191 std::string extensions;
192 std::string gl_version;
193 bool has_alpha;
194 bool has_depth;
195 bool has_stencil;
196 bool request_alpha;
197 bool request_depth;
198 bool request_stencil;
199 bool bind_generates_resource;
200 bool lose_context_when_out_of_memory;
201 bool use_native_vao; // default is true.
204 void InitDecoder(const InitState& init);
205 void InitDecoderWithCommandLine(const InitState& init,
206 const base::CommandLine* command_line);
208 void ResetDecoder();
210 const ContextGroup& group() const {
211 return *group_.get();
214 ::testing::StrictMock< ::gfx::MockGLInterface>* GetGLMock() const {
215 return gl_.get();
218 GLES2Decoder* GetDecoder() const {
219 return decoder_.get();
222 typedef TestHelper::AttribInfo AttribInfo;
223 typedef TestHelper::UniformInfo UniformInfo;
225 void SetupShader(
226 AttribInfo* attribs, size_t num_attribs,
227 UniformInfo* uniforms, size_t num_uniforms,
228 GLuint client_id, GLuint service_id,
229 GLuint vertex_shader_client_id, GLuint vertex_shader_service_id,
230 GLuint fragment_shader_client_id, GLuint fragment_shader_service_id);
232 void SetupInitCapabilitiesExpectations(bool es3_capable);
233 void SetupInitStateExpectations();
234 void ExpectEnableDisable(GLenum cap, bool enable);
236 // Setups up a shader for testing glUniform.
237 void SetupShaderForUniform(GLenum uniform_type);
238 void SetupDefaultProgram();
239 void SetupCubemapProgram();
240 void SetupSamplerExternalProgram();
241 void SetupTexture();
243 // Note that the error is returned as GLint instead of GLenum.
244 // This is because there is a mismatch in the types of GLenum and
245 // the error values GL_NO_ERROR, GL_INVALID_ENUM, etc. GLenum is
246 // typedef'd as unsigned int while the error values are defined as
247 // integers. This is problematic for template functions such as
248 // EXPECT_EQ that expect both types to be the same.
249 GLint GetGLError();
251 void DoBindBuffer(GLenum target, GLuint client_id, GLuint service_id);
252 void DoBindFramebuffer(GLenum target, GLuint client_id, GLuint service_id);
253 void DoBindRenderbuffer(GLenum target, GLuint client_id, GLuint service_id);
254 void DoRenderbufferStorageMultisampleCHROMIUM(GLenum target,
255 GLsizei samples,
256 GLenum internal_format,
257 GLenum gl_format,
258 GLsizei width,
259 GLsizei height);
260 void RestoreRenderbufferBindings();
261 void EnsureRenderbufferBound(bool expect_bind);
262 void DoBindTexture(GLenum target, GLuint client_id, GLuint service_id);
263 void DoBindVertexArrayOES(GLuint client_id, GLuint service_id);
265 bool DoIsBuffer(GLuint client_id);
266 bool DoIsFramebuffer(GLuint client_id);
267 bool DoIsProgram(GLuint client_id);
268 bool DoIsRenderbuffer(GLuint client_id);
269 bool DoIsShader(GLuint client_id);
270 bool DoIsTexture(GLuint client_id);
272 void DoDeleteBuffer(GLuint client_id, GLuint service_id);
273 void DoDeleteFramebuffer(
274 GLuint client_id, GLuint service_id,
275 bool reset_draw, GLenum draw_target, GLuint draw_id,
276 bool reset_read, GLenum read_target, GLuint read_id);
277 void DoDeleteProgram(GLuint client_id, GLuint service_id);
278 void DoDeleteRenderbuffer(GLuint client_id, GLuint service_id);
279 void DoDeleteShader(GLuint client_id, GLuint service_id);
280 void DoDeleteTexture(GLuint client_id, GLuint service_id);
282 void DoCompressedTexImage2D(
283 GLenum target, GLint level, GLenum format,
284 GLsizei width, GLsizei height, GLint border,
285 GLsizei size, uint32 bucket_id);
286 void DoBindTexImage2DCHROMIUM(GLenum target, GLint image_id);
287 void DoTexImage2D(
288 GLenum target, GLint level, GLenum internal_format,
289 GLsizei width, GLsizei height, GLint border,
290 GLenum format, GLenum type,
291 uint32 shared_memory_id, uint32 shared_memory_offset);
292 void DoTexImage2DConvertInternalFormat(
293 GLenum target, GLint level, GLenum requested_internal_format,
294 GLsizei width, GLsizei height, GLint border,
295 GLenum format, GLenum type,
296 uint32 shared_memory_id, uint32 shared_memory_offset,
297 GLenum expected_internal_format);
298 void DoRenderbufferStorage(
299 GLenum target, GLenum internal_format, GLenum actual_format,
300 GLsizei width, GLsizei height, GLenum error);
301 void DoFramebufferRenderbuffer(
302 GLenum target,
303 GLenum attachment,
304 GLenum renderbuffer_target,
305 GLuint renderbuffer_client_id,
306 GLuint renderbuffer_service_id,
307 GLenum error);
308 void DoFramebufferTexture2D(
309 GLenum target, GLenum attachment, GLenum tex_target,
310 GLuint texture_client_id, GLuint texture_service_id,
311 GLint level, GLenum error);
312 void DoVertexAttribPointer(
313 GLuint index, GLint size, GLenum type, GLsizei stride, GLuint offset);
314 void DoVertexAttribDivisorANGLE(GLuint index, GLuint divisor);
316 void DoEnableDisable(GLenum cap, bool enable);
318 void DoEnableVertexAttribArray(GLint index);
320 void DoBufferData(GLenum target, GLsizei size);
322 void DoBufferSubData(
323 GLenum target, GLint offset, GLsizei size, const void* data);
325 void SetupVertexBuffer();
326 void SetupAllNeededVertexBuffers();
328 void SetupIndexBuffer();
330 void DeleteVertexBuffer();
332 void DeleteIndexBuffer();
334 void SetupClearTextureExpectations(
335 GLuint service_id,
336 GLuint old_service_id,
337 GLenum bind_target,
338 GLenum target,
339 GLint level,
340 GLenum internal_format,
341 GLenum format,
342 GLenum type,
343 GLsizei width,
344 GLsizei height);
346 void SetupExpectationsForRestoreClearState(
347 GLclampf restore_red,
348 GLclampf restore_green,
349 GLclampf restore_blue,
350 GLclampf restore_alpha,
351 GLuint restore_stencil,
352 GLclampf restore_depth,
353 bool restore_scissor_test);
355 void SetupExpectationsForFramebufferClearing(
356 GLenum target,
357 GLuint clear_bits,
358 GLclampf restore_red,
359 GLclampf restore_green,
360 GLclampf restore_blue,
361 GLclampf restore_alpha,
362 GLuint restore_stencil,
363 GLclampf restore_depth,
364 bool restore_scissor_test);
366 void SetupExpectationsForFramebufferClearingMulti(
367 GLuint read_framebuffer_service_id,
368 GLuint draw_framebuffer_service_id,
369 GLenum target,
370 GLuint clear_bits,
371 GLclampf restore_red,
372 GLclampf restore_green,
373 GLclampf restore_blue,
374 GLclampf restore_alpha,
375 GLuint restore_stencil,
376 GLclampf restore_depth,
377 bool restore_scissor_test);
379 void SetupExpectationsForDepthMask(bool mask);
380 void SetupExpectationsForEnableDisable(GLenum cap, bool enable);
381 void SetupExpectationsForColorMask(bool red,
382 bool green,
383 bool blue,
384 bool alpha);
385 void SetupExpectationsForStencilMask(GLuint front_mask, GLuint back_mask);
387 void SetupExpectationsForApplyingDirtyState(
388 bool framebuffer_is_rgb,
389 bool framebuffer_has_depth,
390 bool framebuffer_has_stencil,
391 GLuint color_bits, // NOTE! bits are 0x1000, 0x0100, 0x0010, and 0x0001
392 bool depth_mask,
393 bool depth_enabled,
394 GLuint front_stencil_mask,
395 GLuint back_stencil_mask,
396 bool stencil_enabled);
398 void SetupExpectationsForApplyingDefaultDirtyState();
400 void AddExpectationsForSimulatedAttrib0WithError(
401 GLsizei num_vertices, GLuint buffer_id, GLenum error);
403 void AddExpectationsForSimulatedAttrib0(
404 GLsizei num_vertices, GLuint buffer_id);
406 void AddExpectationsForGenVertexArraysOES();
407 void AddExpectationsForDeleteVertexArraysOES();
408 void AddExpectationsForDeleteBoundVertexArraysOES();
409 void AddExpectationsForBindVertexArrayOES();
410 void AddExpectationsForRestoreAttribState(GLuint attrib);
412 GLvoid* BufferOffset(unsigned i) {
413 return static_cast<int8 *>(NULL)+(i);
416 template <typename Command, typename Result>
417 bool IsObjectHelper(GLuint client_id) {
418 Result* result = static_cast<Result*>(shared_memory_address_);
419 Command cmd;
420 cmd.Init(client_id, kSharedMemoryId, kSharedMemoryOffset);
421 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
422 bool isObject = static_cast<bool>(*result);
423 EXPECT_EQ(GL_NO_ERROR, GetGLError());
424 return isObject;
427 protected:
428 static const int kBackBufferWidth = 128;
429 static const int kBackBufferHeight = 64;
431 static const GLint kMaxTextureSize = 2048;
432 static const GLint kMaxCubeMapTextureSize = 256;
433 static const GLint kNumVertexAttribs = 16;
434 static const GLint kNumTextureUnits = 8;
435 static const GLint kMaxTextureImageUnits = 8;
436 static const GLint kMaxVertexTextureImageUnits = 2;
437 static const GLint kMaxFragmentUniformVectors = 16;
438 static const GLint kMaxVaryingVectors = 8;
439 static const GLint kMaxVertexUniformVectors = 128;
440 static const GLint kMaxViewportWidth = 8192;
441 static const GLint kMaxViewportHeight = 8192;
443 static const GLint kViewportX = 0;
444 static const GLint kViewportY = 0;
445 static const GLint kViewportWidth = kBackBufferWidth;
446 static const GLint kViewportHeight = kBackBufferHeight;
448 static const GLuint kServiceAttrib0BufferId = 801;
449 static const GLuint kServiceFixedAttribBufferId = 802;
451 static const GLuint kServiceBufferId = 301;
452 static const GLuint kServiceFramebufferId = 302;
453 static const GLuint kServiceRenderbufferId = 303;
454 static const GLuint kServiceTextureId = 304;
455 static const GLuint kServiceProgramId = 305;
456 static const GLuint kServiceSamplerId = 306;
457 static const GLuint kServiceShaderId = 307;
458 static const GLuint kServiceElementBufferId = 308;
459 static const GLuint kServiceQueryId = 309;
460 static const GLuint kServiceVertexArrayId = 310;
461 static const GLuint kServiceTransformFeedbackId = 311;
462 static const GLuint kServiceSyncId = 312;
464 static const int32 kSharedMemoryId = 401;
465 static const size_t kSharedBufferSize = 2048;
466 static const uint32 kSharedMemoryOffset = 132;
467 static const int32 kInvalidSharedMemoryId = 402;
468 static const uint32 kInvalidSharedMemoryOffset = kSharedBufferSize + 1;
469 static const uint32 kInitialResult = 0xBDBDBDBDu;
470 static const uint8 kInitialMemoryValue = 0xBDu;
472 static const uint32 kNewClientId = 501;
473 static const uint32 kNewServiceId = 502;
474 static const uint32 kInvalidClientId = 601;
476 static const GLuint kServiceVertexShaderId = 321;
477 static const GLuint kServiceFragmentShaderId = 322;
479 static const GLuint kServiceCopyTextureChromiumShaderId = 701;
480 static const GLuint kServiceCopyTextureChromiumProgramId = 721;
482 static const GLuint kServiceCopyTextureChromiumTextureBufferId = 751;
483 static const GLuint kServiceCopyTextureChromiumVertexBufferId = 752;
484 static const GLuint kServiceCopyTextureChromiumFBOId = 753;
485 static const GLuint kServiceCopyTextureChromiumPositionAttrib = 761;
486 static const GLuint kServiceCopyTextureChromiumTexAttrib = 762;
487 static const GLuint kServiceCopyTextureChromiumSamplerLocation = 763;
489 static const GLsizei kNumVertices = 100;
490 static const GLsizei kNumIndices = 10;
491 static const int kValidIndexRangeStart = 1;
492 static const int kValidIndexRangeCount = 7;
493 static const int kInvalidIndexRangeStart = 0;
494 static const int kInvalidIndexRangeCount = 7;
495 static const int kOutOfRangeIndexRangeEnd = 10;
496 static const GLuint kMaxValidIndex = 7;
498 static const GLint kMaxAttribLength = 10;
499 static const char* kAttrib1Name;
500 static const char* kAttrib2Name;
501 static const char* kAttrib3Name;
502 static const GLint kAttrib1Size = 1;
503 static const GLint kAttrib2Size = 1;
504 static const GLint kAttrib3Size = 1;
505 static const GLint kAttrib1Location = 0;
506 static const GLint kAttrib2Location = 1;
507 static const GLint kAttrib3Location = 2;
508 static const GLenum kAttrib1Type = GL_FLOAT_VEC4;
509 static const GLenum kAttrib2Type = GL_FLOAT_VEC2;
510 static const GLenum kAttrib3Type = GL_FLOAT_VEC3;
511 static const GLint kInvalidAttribLocation = 30;
512 static const GLint kBadAttribIndex = kNumVertexAttribs;
514 static const GLint kMaxUniformLength = 12;
515 static const char* kUniform1Name;
516 static const char* kUniform2Name;
517 static const char* kUniform3Name;
518 static const GLint kUniform1Size = 1;
519 static const GLint kUniform2Size = 3;
520 static const GLint kUniform3Size = 2;
521 static const GLint kUniform1RealLocation = 3;
522 static const GLint kUniform2RealLocation = 10;
523 static const GLint kUniform2ElementRealLocation = 12;
524 static const GLint kUniform3RealLocation = 20;
525 static const GLint kUniform1FakeLocation = 0; // These are
526 static const GLint kUniform2FakeLocation = 1; // hardcoded
527 static const GLint kUniform2ElementFakeLocation = 0x10001; // to match
528 static const GLint kUniform3FakeLocation = 2; // ProgramManager.
529 static const GLint kUniform1DesiredLocation = -1;
530 static const GLint kUniform2DesiredLocation = -1;
531 static const GLint kUniform3DesiredLocation = -1;
532 static const GLenum kUniform1Type = GL_SAMPLER_2D;
533 static const GLenum kUniform2Type = GL_INT_VEC2;
534 static const GLenum kUniform3Type = GL_FLOAT_VEC3;
535 static const GLenum kUniformSamplerExternalType = GL_SAMPLER_EXTERNAL_OES;
536 static const GLenum kUniformCubemapType = GL_SAMPLER_CUBE;
537 static const GLint kInvalidUniformLocation = 30;
538 static const GLint kBadUniformIndex = 1000;
540 // Use StrictMock to make 100% sure we know how GL will be called.
541 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
542 scoped_refptr<gfx::GLSurfaceStub> surface_;
543 scoped_refptr<gfx::GLContextStubWithExtensions> context_;
544 scoped_ptr<MockGLES2Decoder> mock_decoder_;
545 scoped_ptr<GLES2Decoder> decoder_;
546 MemoryTracker* memory_tracker_;
548 GLuint client_buffer_id_;
549 GLuint client_framebuffer_id_;
550 GLuint client_program_id_;
551 GLuint client_renderbuffer_id_;
552 GLuint client_sampler_id_;
553 GLuint client_shader_id_;
554 GLuint client_texture_id_;
555 GLuint client_element_buffer_id_;
556 GLuint client_vertex_shader_id_;
557 GLuint client_fragment_shader_id_;
558 GLuint client_query_id_;
559 GLuint client_vertexarray_id_;
560 GLuint client_valuebuffer_id_;
561 GLuint client_transformfeedback_id_;
562 GLuint client_sync_id_;
564 uint32 shared_memory_id_;
565 uint32 shared_memory_offset_;
566 void* shared_memory_address_;
567 void* shared_memory_base_;
569 GLuint service_renderbuffer_id_;
570 bool service_renderbuffer_valid_;
572 uint32 immediate_buffer_[64];
574 const bool ignore_cached_state_for_test_;
575 bool cached_color_mask_red_;
576 bool cached_color_mask_green_;
577 bool cached_color_mask_blue_;
578 bool cached_color_mask_alpha_;
579 bool cached_depth_mask_;
580 GLuint cached_stencil_front_mask_;
581 GLuint cached_stencil_back_mask_;
583 struct EnableFlags {
584 EnableFlags();
585 bool cached_blend;
586 bool cached_cull_face;
587 bool cached_depth_test;
588 bool cached_dither;
589 bool cached_polygon_offset_fill;
590 bool cached_sample_alpha_to_coverage;
591 bool cached_sample_coverage;
592 bool cached_scissor_test;
593 bool cached_stencil_test;
596 EnableFlags enable_flags_;
598 private:
599 class MockCommandBufferEngine : public CommandBufferEngine {
600 public:
601 MockCommandBufferEngine();
603 ~MockCommandBufferEngine() override;
605 scoped_refptr<gpu::Buffer> GetSharedMemoryBuffer(int32 shm_id) override;
607 void ClearSharedMemory() {
608 memset(valid_buffer_->memory(), kInitialMemoryValue, kSharedBufferSize);
611 void set_token(int32 token) override;
613 bool SetGetBuffer(int32 /* transfer_buffer_id */) override;
615 // Overridden from CommandBufferEngine.
616 bool SetGetOffset(int32 offset) override;
618 // Overridden from CommandBufferEngine.
619 int32 GetGetOffset() override;
621 private:
622 scoped_refptr<gpu::Buffer> valid_buffer_;
623 scoped_refptr<gpu::Buffer> invalid_buffer_;
626 // MockGLStates is used to track GL states and emulate driver
627 // behaviors on top of MockGLInterface.
628 class MockGLStates {
629 public:
630 MockGLStates()
631 : bound_array_buffer_object_(0),
632 bound_vertex_array_object_(0) {
635 ~MockGLStates() {
638 void OnBindArrayBuffer(GLuint id) {
639 bound_array_buffer_object_ = id;
642 void OnBindVertexArrayOES(GLuint id) {
643 bound_vertex_array_object_ = id;
646 void OnVertexAttribNullPointer() {
647 // When a vertex array object is bound, some drivers (AMD Linux,
648 // Qualcomm, etc.) have a bug where it incorrectly generates an
649 // GL_INVALID_OPERATION on glVertexAttribPointer() if pointer
650 // is NULL, no buffer is bound on GL_ARRAY_BUFFER.
651 // Make sure we don't trigger this bug.
652 if (bound_vertex_array_object_ != 0)
653 EXPECT_TRUE(bound_array_buffer_object_ != 0);
656 private:
657 GLuint bound_array_buffer_object_;
658 GLuint bound_vertex_array_object_;
659 }; // class MockGLStates
661 void AddExpectationsForVertexAttribManager();
662 void SetupMockGLBehaviors();
664 scoped_ptr< ::testing::StrictMock<MockCommandBufferEngine> > engine_;
665 scoped_refptr<ContextGroup> group_;
666 MockGLStates gl_states_;
669 class GLES2DecoderWithShaderTestBase : public GLES2DecoderTestBase {
670 public:
671 GLES2DecoderWithShaderTestBase()
672 : GLES2DecoderTestBase() {
675 protected:
676 void SetUp() override;
677 void TearDown() override;
680 // SpecializedSetup specializations that are needed in multiple unittest files.
681 template <>
682 void GLES2DecoderTestBase::SpecializedSetup<cmds::LinkProgram, 0>(bool valid);
684 } // namespace gles2
685 } // namespace gpu
687 #endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_BASE_H_