Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_base.h
blob42a44e29611bb5574b7ac2b66380ba6db28368fa
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"
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.
202 unsigned webgl_version; // default to 0, i.e., not WebGL context.
205 void InitDecoder(const InitState& init);
206 void InitDecoderWithCommandLine(const InitState& init,
207 const base::CommandLine* command_line);
209 void ResetDecoder();
211 const ContextGroup& group() const {
212 return *group_.get();
215 void LoseContexts(error::ContextLostReason reason) const {
216 group_->LoseContexts(reason);
219 ::testing::StrictMock< ::gfx::MockGLInterface>* GetGLMock() const {
220 return gl_.get();
223 GLES2Decoder* GetDecoder() const {
224 return decoder_.get();
227 typedef TestHelper::AttribInfo AttribInfo;
228 typedef TestHelper::UniformInfo UniformInfo;
230 void SetupShader(
231 AttribInfo* attribs, size_t num_attribs,
232 UniformInfo* uniforms, size_t num_uniforms,
233 GLuint client_id, GLuint service_id,
234 GLuint vertex_shader_client_id, GLuint vertex_shader_service_id,
235 GLuint fragment_shader_client_id, GLuint fragment_shader_service_id);
237 void SetupInitCapabilitiesExpectations(bool es3_capable);
238 void SetupInitStateExpectations();
239 void ExpectEnableDisable(GLenum cap, bool enable);
241 // Setups up a shader for testing glUniform.
242 void SetupShaderForUniform(GLenum uniform_type);
243 void SetupDefaultProgram();
244 void SetupCubemapProgram();
245 void SetupSamplerExternalProgram();
246 void SetupTexture();
248 // Note that the error is returned as GLint instead of GLenum.
249 // This is because there is a mismatch in the types of GLenum and
250 // the error values GL_NO_ERROR, GL_INVALID_ENUM, etc. GLenum is
251 // typedef'd as unsigned int while the error values are defined as
252 // integers. This is problematic for template functions such as
253 // EXPECT_EQ that expect both types to be the same.
254 GLint GetGLError();
256 void DoBindBuffer(GLenum target, GLuint client_id, GLuint service_id);
257 void DoBindFramebuffer(GLenum target, GLuint client_id, GLuint service_id);
258 void DoBindRenderbuffer(GLenum target, GLuint client_id, GLuint service_id);
259 void DoRenderbufferStorageMultisampleCHROMIUM(GLenum target,
260 GLsizei samples,
261 GLenum internal_format,
262 GLenum gl_format,
263 GLsizei width,
264 GLsizei height);
265 void RestoreRenderbufferBindings();
266 void EnsureRenderbufferBound(bool expect_bind);
267 void DoBindTexture(GLenum target, GLuint client_id, GLuint service_id);
268 void DoBindVertexArrayOES(GLuint client_id, GLuint service_id);
270 bool DoIsBuffer(GLuint client_id);
271 bool DoIsFramebuffer(GLuint client_id);
272 bool DoIsProgram(GLuint client_id);
273 bool DoIsRenderbuffer(GLuint client_id);
274 bool DoIsShader(GLuint client_id);
275 bool DoIsTexture(GLuint client_id);
277 void DoDeleteBuffer(GLuint client_id, GLuint service_id);
278 void DoDeleteFramebuffer(
279 GLuint client_id, GLuint service_id,
280 bool reset_draw, GLenum draw_target, GLuint draw_id,
281 bool reset_read, GLenum read_target, GLuint read_id);
282 void DoDeleteProgram(GLuint client_id, GLuint service_id);
283 void DoDeleteRenderbuffer(GLuint client_id, GLuint service_id);
284 void DoDeleteShader(GLuint client_id, GLuint service_id);
285 void DoDeleteTexture(GLuint client_id, GLuint service_id);
287 void DoCompressedTexImage2D(
288 GLenum target, GLint level, GLenum format,
289 GLsizei width, GLsizei height, GLint border,
290 GLsizei size, uint32 bucket_id);
291 void DoBindTexImage2DCHROMIUM(GLenum target, GLint image_id);
292 void DoTexImage2D(
293 GLenum target, GLint level, GLenum internal_format,
294 GLsizei width, GLsizei height, GLint border,
295 GLenum format, GLenum type,
296 uint32 shared_memory_id, uint32 shared_memory_offset);
297 void DoTexImage2DConvertInternalFormat(
298 GLenum target, GLint level, GLenum requested_internal_format,
299 GLsizei width, GLsizei height, GLint border,
300 GLenum format, GLenum type,
301 uint32 shared_memory_id, uint32 shared_memory_offset,
302 GLenum expected_internal_format);
303 void DoRenderbufferStorage(
304 GLenum target, GLenum internal_format, GLenum actual_format,
305 GLsizei width, GLsizei height, GLenum error);
306 void DoFramebufferRenderbuffer(
307 GLenum target,
308 GLenum attachment,
309 GLenum renderbuffer_target,
310 GLuint renderbuffer_client_id,
311 GLuint renderbuffer_service_id,
312 GLenum error);
313 void DoFramebufferTexture2D(
314 GLenum target, GLenum attachment, GLenum tex_target,
315 GLuint texture_client_id, GLuint texture_service_id,
316 GLint level, GLenum error);
317 void DoVertexAttribPointer(
318 GLuint index, GLint size, GLenum type, GLsizei stride, GLuint offset);
319 void DoVertexAttribDivisorANGLE(GLuint index, GLuint divisor);
321 void DoEnableDisable(GLenum cap, bool enable);
323 void DoEnableVertexAttribArray(GLint index);
325 void DoBufferData(GLenum target, GLsizei size);
327 void DoBufferSubData(
328 GLenum target, GLint offset, GLsizei size, const void* data);
330 void DoScissor(GLint x, GLint y, GLsizei width, GLsizei height);
332 void SetupVertexBuffer();
333 void SetupAllNeededVertexBuffers();
335 void SetupIndexBuffer();
337 void DeleteVertexBuffer();
339 void DeleteIndexBuffer();
341 void SetupClearTextureExpectations(GLuint service_id,
342 GLuint old_service_id,
343 GLenum bind_target,
344 GLenum target,
345 GLint level,
346 GLenum internal_format,
347 GLenum format,
348 GLenum type,
349 GLint xoffset,
350 GLint yoffset,
351 GLsizei width,
352 GLsizei height);
354 void SetupExpectationsForRestoreClearState(GLclampf restore_red,
355 GLclampf restore_green,
356 GLclampf restore_blue,
357 GLclampf restore_alpha,
358 GLuint restore_stencil,
359 GLclampf restore_depth,
360 bool restore_scissor_test,
361 GLint restore_scissor_x,
362 GLint restore_scissor_y,
363 GLsizei restore_scissor_width,
364 GLsizei restore_scissor_height);
366 void SetupExpectationsForFramebufferClearing(GLenum target,
367 GLuint clear_bits,
368 GLclampf restore_red,
369 GLclampf restore_green,
370 GLclampf restore_blue,
371 GLclampf restore_alpha,
372 GLuint restore_stencil,
373 GLclampf restore_depth,
374 bool restore_scissor_test,
375 GLint restore_scissor_x,
376 GLint restore_scissor_y,
377 GLsizei restore_scissor_width,
378 GLsizei restore_scissor_height);
380 void SetupExpectationsForFramebufferClearingMulti(
381 GLuint read_framebuffer_service_id,
382 GLuint draw_framebuffer_service_id,
383 GLenum target,
384 GLuint clear_bits,
385 GLclampf restore_red,
386 GLclampf restore_green,
387 GLclampf restore_blue,
388 GLclampf restore_alpha,
389 GLuint restore_stencil,
390 GLclampf restore_depth,
391 bool restore_scissor_test,
392 GLint restore_scissor_x,
393 GLint restore_scissor_y,
394 GLsizei restore_scissor_width,
395 GLsizei restore_scissor_height);
397 void SetupExpectationsForDepthMask(bool mask);
398 void SetupExpectationsForEnableDisable(GLenum cap, bool enable);
399 void SetupExpectationsForColorMask(bool red,
400 bool green,
401 bool blue,
402 bool alpha);
403 void SetupExpectationsForStencilMask(GLuint front_mask, GLuint back_mask);
405 void SetupExpectationsForApplyingDirtyState(
406 bool framebuffer_is_rgb,
407 bool framebuffer_has_depth,
408 bool framebuffer_has_stencil,
409 GLuint color_bits, // NOTE! bits are 0x1000, 0x0100, 0x0010, and 0x0001
410 bool depth_mask,
411 bool depth_enabled,
412 GLuint front_stencil_mask,
413 GLuint back_stencil_mask,
414 bool stencil_enabled);
416 void SetupExpectationsForApplyingDefaultDirtyState();
418 void AddExpectationsForSimulatedAttrib0WithError(
419 GLsizei num_vertices, GLuint buffer_id, GLenum error);
421 void AddExpectationsForSimulatedAttrib0(
422 GLsizei num_vertices, GLuint buffer_id);
424 void AddExpectationsForGenVertexArraysOES();
425 void AddExpectationsForDeleteVertexArraysOES();
426 void AddExpectationsForDeleteBoundVertexArraysOES();
427 void AddExpectationsForBindVertexArrayOES();
428 void AddExpectationsForRestoreAttribState(GLuint attrib);
430 GLvoid* BufferOffset(unsigned i) {
431 return static_cast<int8 *>(NULL)+(i);
434 template <typename Command, typename Result>
435 bool IsObjectHelper(GLuint client_id) {
436 Result* result = static_cast<Result*>(shared_memory_address_);
437 Command cmd;
438 cmd.Init(client_id, kSharedMemoryId, kSharedMemoryOffset);
439 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
440 bool isObject = static_cast<bool>(*result);
441 EXPECT_EQ(GL_NO_ERROR, GetGLError());
442 return isObject;
445 protected:
446 static const int kBackBufferWidth = 128;
447 static const int kBackBufferHeight = 64;
449 static const GLint kMaxTextureSize = 2048;
450 static const GLint kMaxCubeMapTextureSize = 256;
451 static const GLint kNumVertexAttribs = 16;
452 static const GLint kNumTextureUnits = 8;
453 static const GLint kMaxTextureImageUnits = 8;
454 static const GLint kMaxVertexTextureImageUnits = 2;
455 static const GLint kMaxFragmentUniformVectors = 16;
456 static const GLint kMaxVaryingVectors = 8;
457 static const GLint kMaxVertexUniformVectors = 128;
458 static const GLint kMaxViewportWidth = 8192;
459 static const GLint kMaxViewportHeight = 8192;
461 static const GLint kViewportX = 0;
462 static const GLint kViewportY = 0;
463 static const GLint kViewportWidth = kBackBufferWidth;
464 static const GLint kViewportHeight = kBackBufferHeight;
466 static const GLuint kServiceAttrib0BufferId = 801;
467 static const GLuint kServiceFixedAttribBufferId = 802;
469 static const GLuint kServiceBufferId = 301;
470 static const GLuint kServiceFramebufferId = 302;
471 static const GLuint kServiceRenderbufferId = 303;
472 static const GLuint kServiceTextureId = 304;
473 static const GLuint kServiceProgramId = 305;
474 static const GLuint kServiceSamplerId = 306;
475 static const GLuint kServiceShaderId = 307;
476 static const GLuint kServiceElementBufferId = 308;
477 static const GLuint kServiceQueryId = 309;
478 static const GLuint kServiceVertexArrayId = 310;
479 static const GLuint kServiceTransformFeedbackId = 311;
480 static const GLuint kServiceSyncId = 312;
482 static const int32 kSharedMemoryId = 401;
483 static const size_t kSharedBufferSize = 2048;
484 static const uint32 kSharedMemoryOffset = 132;
485 static const int32 kInvalidSharedMemoryId = 402;
486 static const uint32 kInvalidSharedMemoryOffset = kSharedBufferSize + 1;
487 static const uint32 kInitialResult = 0xBDBDBDBDu;
488 static const uint8 kInitialMemoryValue = 0xBDu;
490 static const uint32 kNewClientId = 501;
491 static const uint32 kNewServiceId = 502;
492 static const uint32 kInvalidClientId = 601;
494 static const GLuint kServiceVertexShaderId = 321;
495 static const GLuint kServiceFragmentShaderId = 322;
497 static const GLuint kServiceCopyTextureChromiumShaderId = 701;
498 static const GLuint kServiceCopyTextureChromiumProgramId = 721;
500 static const GLuint kServiceCopyTextureChromiumTextureBufferId = 751;
501 static const GLuint kServiceCopyTextureChromiumVertexBufferId = 752;
502 static const GLuint kServiceCopyTextureChromiumFBOId = 753;
503 static const GLuint kServiceCopyTextureChromiumPositionAttrib = 761;
504 static const GLuint kServiceCopyTextureChromiumTexAttrib = 762;
505 static const GLuint kServiceCopyTextureChromiumSamplerLocation = 763;
507 static const GLsizei kNumVertices = 100;
508 static const GLsizei kNumIndices = 10;
509 static const int kValidIndexRangeStart = 1;
510 static const int kValidIndexRangeCount = 7;
511 static const int kInvalidIndexRangeStart = 0;
512 static const int kInvalidIndexRangeCount = 7;
513 static const int kOutOfRangeIndexRangeEnd = 10;
514 static const GLuint kMaxValidIndex = 7;
516 static const GLint kMaxAttribLength = 10;
517 static const char* kAttrib1Name;
518 static const char* kAttrib2Name;
519 static const char* kAttrib3Name;
520 static const GLint kAttrib1Size = 1;
521 static const GLint kAttrib2Size = 1;
522 static const GLint kAttrib3Size = 1;
523 static const GLint kAttrib1Location = 0;
524 static const GLint kAttrib2Location = 1;
525 static const GLint kAttrib3Location = 2;
526 static const GLenum kAttrib1Type = GL_FLOAT_VEC4;
527 static const GLenum kAttrib2Type = GL_FLOAT_VEC2;
528 static const GLenum kAttrib3Type = GL_FLOAT_VEC3;
529 static const GLint kInvalidAttribLocation = 30;
530 static const GLint kBadAttribIndex = kNumVertexAttribs;
532 static const GLint kMaxUniformLength = 12;
533 static const char* kUniform1Name;
534 static const char* kUniform2Name;
535 static const char* kUniform3Name;
536 static const GLint kUniform1Size = 1;
537 static const GLint kUniform2Size = 3;
538 static const GLint kUniform3Size = 2;
539 static const GLint kUniform1RealLocation = 3;
540 static const GLint kUniform2RealLocation = 10;
541 static const GLint kUniform2ElementRealLocation = 12;
542 static const GLint kUniform3RealLocation = 20;
543 static const GLint kUniform1FakeLocation = 0; // These are
544 static const GLint kUniform2FakeLocation = 1; // hardcoded
545 static const GLint kUniform2ElementFakeLocation = 0x10001; // to match
546 static const GLint kUniform3FakeLocation = 2; // ProgramManager.
547 static const GLint kUniform1DesiredLocation = -1;
548 static const GLint kUniform2DesiredLocation = -1;
549 static const GLint kUniform3DesiredLocation = -1;
550 static const GLenum kUniform1Type = GL_SAMPLER_2D;
551 static const GLenum kUniform2Type = GL_INT_VEC2;
552 static const GLenum kUniform3Type = GL_FLOAT_VEC3;
553 static const GLenum kUniformSamplerExternalType = GL_SAMPLER_EXTERNAL_OES;
554 static const GLenum kUniformCubemapType = GL_SAMPLER_CUBE;
555 static const GLint kInvalidUniformLocation = 30;
556 static const GLint kBadUniformIndex = 1000;
558 // Use StrictMock to make 100% sure we know how GL will be called.
559 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
560 scoped_refptr<gfx::GLSurfaceStub> surface_;
561 scoped_refptr<GLContextMock> context_;
562 scoped_ptr<MockGLES2Decoder> mock_decoder_;
563 scoped_ptr<GLES2Decoder> decoder_;
564 MemoryTracker* memory_tracker_;
566 GLuint client_buffer_id_;
567 GLuint client_framebuffer_id_;
568 GLuint client_program_id_;
569 GLuint client_renderbuffer_id_;
570 GLuint client_sampler_id_;
571 GLuint client_shader_id_;
572 GLuint client_texture_id_;
573 GLuint client_element_buffer_id_;
574 GLuint client_vertex_shader_id_;
575 GLuint client_fragment_shader_id_;
576 GLuint client_query_id_;
577 GLuint client_vertexarray_id_;
578 GLuint client_valuebuffer_id_;
579 GLuint client_transformfeedback_id_;
580 GLuint client_sync_id_;
582 uint32 shared_memory_id_;
583 uint32 shared_memory_offset_;
584 void* shared_memory_address_;
585 void* shared_memory_base_;
587 GLuint service_renderbuffer_id_;
588 bool service_renderbuffer_valid_;
590 uint32 immediate_buffer_[64];
592 const bool ignore_cached_state_for_test_;
593 bool cached_color_mask_red_;
594 bool cached_color_mask_green_;
595 bool cached_color_mask_blue_;
596 bool cached_color_mask_alpha_;
597 bool cached_depth_mask_;
598 GLuint cached_stencil_front_mask_;
599 GLuint cached_stencil_back_mask_;
601 struct EnableFlags {
602 EnableFlags();
603 bool cached_blend;
604 bool cached_cull_face;
605 bool cached_depth_test;
606 bool cached_dither;
607 bool cached_polygon_offset_fill;
608 bool cached_sample_alpha_to_coverage;
609 bool cached_sample_coverage;
610 bool cached_scissor_test;
611 bool cached_stencil_test;
614 EnableFlags enable_flags_;
616 private:
617 class MockCommandBufferEngine : public CommandBufferEngine {
618 public:
619 MockCommandBufferEngine();
621 ~MockCommandBufferEngine() override;
623 scoped_refptr<gpu::Buffer> GetSharedMemoryBuffer(int32 shm_id) override;
625 void ClearSharedMemory() {
626 memset(valid_buffer_->memory(), kInitialMemoryValue, kSharedBufferSize);
629 void set_token(int32 token) override;
631 bool SetGetBuffer(int32 /* transfer_buffer_id */) override;
633 // Overridden from CommandBufferEngine.
634 bool SetGetOffset(int32 offset) override;
636 // Overridden from CommandBufferEngine.
637 int32 GetGetOffset() override;
639 private:
640 scoped_refptr<gpu::Buffer> valid_buffer_;
641 scoped_refptr<gpu::Buffer> invalid_buffer_;
644 // MockGLStates is used to track GL states and emulate driver
645 // behaviors on top of MockGLInterface.
646 class MockGLStates {
647 public:
648 MockGLStates()
649 : bound_array_buffer_object_(0),
650 bound_vertex_array_object_(0) {
653 ~MockGLStates() {
656 void OnBindArrayBuffer(GLuint id) {
657 bound_array_buffer_object_ = id;
660 void OnBindVertexArrayOES(GLuint id) {
661 bound_vertex_array_object_ = id;
664 void OnVertexAttribNullPointer() {
665 // When a vertex array object is bound, some drivers (AMD Linux,
666 // Qualcomm, etc.) have a bug where it incorrectly generates an
667 // GL_INVALID_OPERATION on glVertexAttribPointer() if pointer
668 // is NULL, no buffer is bound on GL_ARRAY_BUFFER.
669 // Make sure we don't trigger this bug.
670 if (bound_vertex_array_object_ != 0)
671 EXPECT_TRUE(bound_array_buffer_object_ != 0);
674 private:
675 GLuint bound_array_buffer_object_;
676 GLuint bound_vertex_array_object_;
677 }; // class MockGLStates
679 void AddExpectationsForVertexAttribManager();
680 void SetupMockGLBehaviors();
682 scoped_ptr< ::testing::StrictMock<MockCommandBufferEngine> > engine_;
683 scoped_refptr<ContextGroup> group_;
684 MockGLStates gl_states_;
687 class GLES2DecoderWithShaderTestBase : public GLES2DecoderTestBase {
688 public:
689 GLES2DecoderWithShaderTestBase()
690 : GLES2DecoderTestBase() {
693 protected:
694 void SetUp() override;
695 void TearDown() override;
698 // SpecializedSetup specializations that are needed in multiple unittest files.
699 template <>
700 void GLES2DecoderTestBase::SpecializedSetup<cmds::LinkProgram, 0>(bool valid);
702 } // namespace gles2
703 } // namespace gpu
705 #endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_BASE_H_