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 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_split.h"
13 #include "gpu/command_buffer/common/gles2_cmd_format.h"
14 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
15 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
16 #include "gpu/command_buffer/service/context_group.h"
17 #include "gpu/command_buffer/service/logger.h"
18 #include "gpu/command_buffer/service/program_manager.h"
19 #include "gpu/command_buffer/service/test_helper.h"
20 #include "gpu/command_buffer/service/vertex_attrib_manager.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/gl/gl_implementation.h"
23 #include "ui/gl/gl_mock.h"
24 #include "ui/gl/gl_surface.h"
26 using ::gfx::MockGLInterface;
28 using ::testing::DoAll;
29 using ::testing::InSequence;
30 using ::testing::Invoke;
31 using ::testing::InvokeWithoutArgs;
32 using ::testing::MatcherCast;
33 using ::testing::Pointee;
34 using ::testing::Return;
35 using ::testing::SetArrayArgument;
36 using ::testing::SetArgPointee;
37 using ::testing::SetArgumentPointee;
38 using ::testing::StrEq;
39 using ::testing::StrictMock;
40 using ::testing::WithArg;
44 void NormalizeInitState(gpu::gles2::GLES2DecoderTestBase::InitState* init) {
46 const char* kVAOExtensions[] = {
47 "GL_OES_vertex_array_object",
48 "GL_ARB_vertex_array_object",
49 "GL_APPLE_vertex_array_object"
51 bool contains_vao_extension = false;
52 for (size_t ii = 0; ii < arraysize(kVAOExtensions); ++ii) {
53 if (init->extensions.find(kVAOExtensions[ii]) != std::string::npos) {
54 contains_vao_extension = true;
58 if (init->use_native_vao) {
59 if (contains_vao_extension)
61 if (!init->extensions.empty())
62 init->extensions += " ";
63 if (StartsWithASCII(init->gl_version, "opengl es", false)) {
64 init->extensions += kVAOExtensions[0];
66 #if !defined(OS_MACOSX)
67 init->extensions += kVAOExtensions[1];
69 init->extensions += kVAOExtensions[2];
73 // Make sure we don't set up an invalid InitState.
74 CHECK(!contains_vao_extension);
78 } // namespace Anonymous
83 GLES2DecoderTestBase::GLES2DecoderTestBase()
86 memory_tracker_(NULL),
87 client_buffer_id_(100),
88 client_framebuffer_id_(101),
89 client_program_id_(102),
90 client_renderbuffer_id_(103),
91 client_shader_id_(104),
92 client_texture_id_(106),
93 client_element_buffer_id_(107),
94 client_vertex_shader_id_(121),
95 client_fragment_shader_id_(122),
96 client_query_id_(123),
97 client_vertexarray_id_(124),
98 service_renderbuffer_id_(0),
99 service_renderbuffer_valid_(false),
100 ignore_cached_state_for_test_(GetParam()),
101 cached_color_mask_red_(true),
102 cached_color_mask_green_(true),
103 cached_color_mask_blue_(true),
104 cached_color_mask_alpha_(true),
105 cached_depth_mask_(true),
106 cached_stencil_front_mask_(static_cast<GLuint>(-1)),
107 cached_stencil_back_mask_(static_cast<GLuint>(-1)) {
108 memset(immediate_buffer_, 0xEE, sizeof(immediate_buffer_));
111 GLES2DecoderTestBase::~GLES2DecoderTestBase() {}
113 void GLES2DecoderTestBase::SetUp() {
115 init.gl_version = "3.0";
116 init.has_alpha = true;
117 init.has_depth = true;
118 init.request_alpha = true;
119 init.request_depth = true;
120 init.bind_generates_resource = true;
124 void GLES2DecoderTestBase::AddExpectationsForVertexAttribManager() {
125 for (GLint ii = 0; ii < kNumVertexAttribs; ++ii) {
126 EXPECT_CALL(*gl_, VertexAttrib4f(ii, 0.0f, 0.0f, 0.0f, 1.0f))
128 .RetiresOnSaturation();
132 GLES2DecoderTestBase::InitState::InitState()
136 request_alpha(false),
137 request_depth(false),
138 request_stencil(false),
139 bind_generates_resource(false),
140 lose_context_when_out_of_memory(false),
141 use_native_vao(true) {
144 void GLES2DecoderTestBase::InitDecoder(const InitState& init) {
145 InitDecoderWithCommandLine(init, NULL);
148 void GLES2DecoderTestBase::InitDecoderWithCommandLine(
149 const InitState& init,
150 const base::CommandLine* command_line) {
151 InitState normalized_init = init;
152 NormalizeInitState(&normalized_init);
153 Framebuffer::ClearFramebufferCompleteComboMap();
155 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress);
156 gfx::GLSurface::InitializeOneOffWithMockBindingsForTests();
158 gl_.reset(new StrictMock<MockGLInterface>());
159 ::gfx::MockGLInterface::SetGLInterface(gl_.get());
161 SetupMockGLBehaviors();
163 // Only create stream texture manager if extension is requested.
164 std::vector<std::string> list;
165 base::SplitString(normalized_init.extensions, ' ', &list);
166 scoped_refptr<FeatureInfo> feature_info;
168 feature_info = new FeatureInfo(*command_line);
169 group_ = scoped_refptr<ContextGroup>(
170 new ContextGroup(NULL,
172 new ShaderTranslatorCache,
174 normalized_init.bind_generates_resource));
175 bool use_default_textures = normalized_init.bind_generates_resource;
179 surface_ = new gfx::GLSurfaceStub;
180 surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight));
182 // Context needs to be created before initializing ContextGroup, which will
183 // in turn initialize FeatureInfo, which needs a context to determine
184 // extension support.
185 context_ = new gfx::GLContextStubWithExtensions;
186 context_->AddExtensionsString(normalized_init.extensions.c_str());
187 context_->SetGLVersionString(normalized_init.gl_version.c_str());
189 context_->MakeCurrent(surface_.get());
190 gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_);
192 TestHelper::SetupContextGroupInitExpectations(
194 DisallowedFeatures(),
195 normalized_init.extensions.c_str(),
196 normalized_init.gl_version.c_str(),
197 normalized_init.bind_generates_resource);
199 // We initialize the ContextGroup with a MockGLES2Decoder so that
200 // we can use the ContextGroup to figure out how the real GLES2Decoder
201 // will initialize itself.
202 mock_decoder_.reset(new MockGLES2Decoder());
204 group_->Initialize(mock_decoder_.get(), DisallowedFeatures()));
206 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
207 EXPECT_CALL(*gl_, GenVertexArraysOES(1, _))
208 .WillOnce(SetArgumentPointee<1>(kServiceVertexArrayId))
209 .RetiresOnSaturation();
210 EXPECT_CALL(*gl_, BindVertexArrayOES(_)).Times(1).RetiresOnSaturation();
213 if (group_->feature_info()->workarounds().init_vertex_attributes)
214 AddExpectationsForVertexAttribManager();
216 AddExpectationsForBindVertexArrayOES();
218 EXPECT_CALL(*gl_, EnableVertexAttribArray(0))
220 .RetiresOnSaturation();
221 static GLuint attrib_0_id[] = {
222 kServiceAttrib0BufferId,
224 static GLuint fixed_attrib_buffer_id[] = {
225 kServiceFixedAttribBufferId,
227 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(attrib_0_id), _))
228 .WillOnce(SetArrayArgument<1>(attrib_0_id,
229 attrib_0_id + arraysize(attrib_0_id)))
230 .RetiresOnSaturation();
231 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
233 .RetiresOnSaturation();
234 EXPECT_CALL(*gl_, VertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL))
236 .RetiresOnSaturation();
237 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
239 .RetiresOnSaturation();
240 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(fixed_attrib_buffer_id), _))
241 .WillOnce(SetArrayArgument<1>(
242 fixed_attrib_buffer_id,
243 fixed_attrib_buffer_id + arraysize(fixed_attrib_buffer_id)))
244 .RetiresOnSaturation();
246 for (GLint tt = 0; tt < TestHelper::kNumTextureUnits; ++tt) {
247 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0 + tt))
249 .RetiresOnSaturation();
250 if (group_->feature_info()->feature_flags().oes_egl_image_external) {
252 BindTexture(GL_TEXTURE_EXTERNAL_OES,
254 ? TestHelper::kServiceDefaultExternalTextureId
257 .RetiresOnSaturation();
259 if (group_->feature_info()->feature_flags().arb_texture_rectangle) {
262 BindTexture(GL_TEXTURE_RECTANGLE_ARB,
264 ? TestHelper::kServiceDefaultRectangleTextureId
267 .RetiresOnSaturation();
270 BindTexture(GL_TEXTURE_CUBE_MAP,
272 ? TestHelper::kServiceDefaultTextureCubemapId
275 .RetiresOnSaturation();
280 use_default_textures ? TestHelper::kServiceDefaultTexture2dId : 0))
282 .RetiresOnSaturation();
284 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
286 .RetiresOnSaturation();
288 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
290 .RetiresOnSaturation();
291 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _))
292 .WillOnce(SetArgumentPointee<1>(normalized_init.has_alpha ? 8 : 0))
293 .RetiresOnSaturation();
294 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
295 .WillOnce(SetArgumentPointee<1>(normalized_init.has_depth ? 24 : 0))
296 .RetiresOnSaturation();
297 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
298 .WillOnce(SetArgumentPointee<1>(normalized_init.has_stencil ? 8 : 0))
299 .RetiresOnSaturation();
301 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE))
303 .RetiresOnSaturation();
305 EXPECT_CALL(*gl_, Enable(GL_POINT_SPRITE))
307 .RetiresOnSaturation();
309 static GLint max_viewport_dims[] = {
313 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VIEWPORT_DIMS, _))
314 .WillOnce(SetArrayArgument<1>(
315 max_viewport_dims, max_viewport_dims + arraysize(max_viewport_dims)))
316 .RetiresOnSaturation();
318 SetupInitCapabilitiesExpectations();
319 SetupInitStateExpectations();
321 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
323 .RetiresOnSaturation();
325 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
327 .RetiresOnSaturation();
328 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0))
330 .RetiresOnSaturation();
331 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
333 .RetiresOnSaturation();
334 EXPECT_CALL(*gl_, BindRenderbufferEXT(GL_RENDERBUFFER, 0))
336 .RetiresOnSaturation();
338 // TODO(boliu): Remove OS_ANDROID once crbug.com/259023 is fixed and the
339 // workaround has been reverted.
340 #if !defined(OS_ANDROID)
341 EXPECT_CALL(*gl_, Clear(
342 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
344 .RetiresOnSaturation();
347 engine_.reset(new StrictMock<MockCommandBufferEngine>());
348 scoped_refptr<gpu::Buffer> buffer =
349 engine_->GetSharedMemoryBuffer(kSharedMemoryId);
350 shared_memory_offset_ = kSharedMemoryOffset;
351 shared_memory_address_ =
352 reinterpret_cast<int8*>(buffer->memory()) + shared_memory_offset_;
353 shared_memory_id_ = kSharedMemoryId;
354 shared_memory_base_ = buffer->memory();
356 static const int32 kLoseContextWhenOutOfMemory = 0x10002;
358 int32 attributes[] = {
360 normalized_init.request_alpha ? 8 : 0,
362 normalized_init.request_depth ? 24 : 0,
364 normalized_init.request_stencil ? 8 : 0,
365 kLoseContextWhenOutOfMemory,
366 normalized_init.lose_context_when_out_of_memory ? 1 : 0, };
367 std::vector<int32> attribs(attributes, attributes + arraysize(attributes));
369 decoder_.reset(GLES2Decoder::Create(group_.get()));
370 decoder_->SetIgnoreCachedStateForTest(ignore_cached_state_for_test_);
371 decoder_->GetLogger()->set_log_synthesized_gl_errors(false);
372 decoder_->Initialize(surface_,
376 DisallowedFeatures(),
378 decoder_->MakeCurrent();
379 decoder_->set_engine(engine_.get());
380 decoder_->BeginDecoding();
382 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
383 .WillOnce(SetArgumentPointee<1>(kServiceBufferId))
384 .RetiresOnSaturation();
385 GenHelper<cmds::GenBuffersImmediate>(client_buffer_id_);
386 EXPECT_CALL(*gl_, GenFramebuffersEXT(_, _))
387 .WillOnce(SetArgumentPointee<1>(kServiceFramebufferId))
388 .RetiresOnSaturation();
389 GenHelper<cmds::GenFramebuffersImmediate>(client_framebuffer_id_);
390 EXPECT_CALL(*gl_, GenRenderbuffersEXT(_, _))
391 .WillOnce(SetArgumentPointee<1>(kServiceRenderbufferId))
392 .RetiresOnSaturation();
393 GenHelper<cmds::GenRenderbuffersImmediate>(client_renderbuffer_id_);
394 EXPECT_CALL(*gl_, GenTextures(_, _))
395 .WillOnce(SetArgumentPointee<1>(kServiceTextureId))
396 .RetiresOnSaturation();
397 GenHelper<cmds::GenTexturesImmediate>(client_texture_id_);
398 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
399 .WillOnce(SetArgumentPointee<1>(kServiceElementBufferId))
400 .RetiresOnSaturation();
401 GenHelper<cmds::GenBuffersImmediate>(client_element_buffer_id_);
403 DoCreateProgram(client_program_id_, kServiceProgramId);
404 DoCreateShader(GL_VERTEX_SHADER, client_shader_id_, kServiceShaderId);
406 EXPECT_EQ(GL_NO_ERROR, GetGLError());
409 void GLES2DecoderTestBase::ResetDecoder() {
412 // All Tests should have read all their GLErrors before getting here.
413 EXPECT_EQ(GL_NO_ERROR, GetGLError());
415 EXPECT_CALL(*gl_, DeleteBuffersARB(1, _))
417 .RetiresOnSaturation();
418 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
419 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, Pointee(kServiceVertexArrayId)))
421 .RetiresOnSaturation();
424 decoder_->EndDecoding();
425 decoder_->Destroy(true);
427 group_->Destroy(mock_decoder_.get(), false);
429 ::gfx::MockGLInterface::SetGLInterface(NULL);
431 gfx::ClearGLBindings();
434 void GLES2DecoderTestBase::TearDown() {
438 void GLES2DecoderTestBase::ExpectEnableDisable(GLenum cap, bool enable) {
440 EXPECT_CALL(*gl_, Enable(cap))
442 .RetiresOnSaturation();
444 EXPECT_CALL(*gl_, Disable(cap))
446 .RetiresOnSaturation();
451 GLint GLES2DecoderTestBase::GetGLError() {
452 EXPECT_CALL(*gl_, GetError())
453 .WillOnce(Return(GL_NO_ERROR))
454 .RetiresOnSaturation();
456 cmd.Init(shared_memory_id_, shared_memory_offset_);
457 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
458 return static_cast<GLint>(*GetSharedMemoryAs<GLenum*>());
461 void GLES2DecoderTestBase::DoCreateShader(
462 GLenum shader_type, GLuint client_id, GLuint service_id) {
463 EXPECT_CALL(*gl_, CreateShader(shader_type))
465 .WillOnce(Return(service_id))
466 .RetiresOnSaturation();
467 cmds::CreateShader cmd;
468 cmd.Init(shader_type, client_id);
469 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
472 bool GLES2DecoderTestBase::DoIsShader(GLuint client_id) {
473 return IsObjectHelper<cmds::IsShader, cmds::IsShader::Result>(client_id);
476 void GLES2DecoderTestBase::DoDeleteShader(
477 GLuint client_id, GLuint service_id) {
478 EXPECT_CALL(*gl_, DeleteShader(service_id))
480 .RetiresOnSaturation();
481 cmds::DeleteShader cmd;
483 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
486 void GLES2DecoderTestBase::DoCreateProgram(
487 GLuint client_id, GLuint service_id) {
488 EXPECT_CALL(*gl_, CreateProgram())
490 .WillOnce(Return(service_id))
491 .RetiresOnSaturation();
492 cmds::CreateProgram cmd;
494 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
497 bool GLES2DecoderTestBase::DoIsProgram(GLuint client_id) {
498 return IsObjectHelper<cmds::IsProgram, cmds::IsProgram::Result>(client_id);
501 void GLES2DecoderTestBase::DoDeleteProgram(
502 GLuint client_id, GLuint /* service_id */) {
503 cmds::DeleteProgram cmd;
505 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
508 void GLES2DecoderTestBase::SetBucketAsCString(
509 uint32 bucket_id, const char* str) {
510 uint32 size = str ? (strlen(str) + 1) : 0;
511 cmd::SetBucketSize cmd1;
512 cmd1.Init(bucket_id, size);
513 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
515 memcpy(shared_memory_address_, str, size);
516 cmd::SetBucketData cmd2;
517 cmd2.Init(bucket_id, 0, size, kSharedMemoryId, kSharedMemoryOffset);
518 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
523 void GLES2DecoderTestBase::SetupClearTextureExpectations(
525 GLuint old_service_id,
529 GLenum internal_format,
534 EXPECT_CALL(*gl_, BindTexture(bind_target, service_id))
536 .RetiresOnSaturation();
537 EXPECT_CALL(*gl_, TexImage2D(
538 target, level, internal_format, width, height, 0, format, type, _))
540 .RetiresOnSaturation();
541 EXPECT_CALL(*gl_, BindTexture(bind_target, old_service_id))
543 .RetiresOnSaturation();
546 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearing(
549 GLclampf restore_red,
550 GLclampf restore_green,
551 GLclampf restore_blue,
552 GLclampf restore_alpha,
553 GLuint restore_stencil,
554 GLclampf restore_depth,
555 bool restore_scissor_test) {
556 SetupExpectationsForFramebufferClearingMulti(
567 restore_scissor_test);
570 void GLES2DecoderTestBase::SetupExpectationsForRestoreClearState(
571 GLclampf restore_red,
572 GLclampf restore_green,
573 GLclampf restore_blue,
574 GLclampf restore_alpha,
575 GLuint restore_stencil,
576 GLclampf restore_depth,
577 bool restore_scissor_test) {
578 EXPECT_CALL(*gl_, ClearColor(
579 restore_red, restore_green, restore_blue, restore_alpha))
581 .RetiresOnSaturation();
582 EXPECT_CALL(*gl_, ClearStencil(restore_stencil))
584 .RetiresOnSaturation();
585 EXPECT_CALL(*gl_, ClearDepth(restore_depth))
587 .RetiresOnSaturation();
588 if (restore_scissor_test) {
589 EXPECT_CALL(*gl_, Enable(GL_SCISSOR_TEST))
591 .RetiresOnSaturation();
595 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearingMulti(
596 GLuint read_framebuffer_service_id,
597 GLuint draw_framebuffer_service_id,
600 GLclampf restore_red,
601 GLclampf restore_green,
602 GLclampf restore_blue,
603 GLclampf restore_alpha,
604 GLuint restore_stencil,
605 GLclampf restore_depth,
606 bool restore_scissor_test) {
607 // TODO(gman): Figure out why InSequence stopped working.
608 // InSequence sequence;
609 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(target))
610 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
611 .RetiresOnSaturation();
612 if (target == GL_READ_FRAMEBUFFER_EXT) {
613 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0))
615 .RetiresOnSaturation();
616 EXPECT_CALL(*gl_, BindFramebufferEXT(
617 GL_DRAW_FRAMEBUFFER_EXT, read_framebuffer_service_id))
619 .RetiresOnSaturation();
621 if ((clear_bits & GL_COLOR_BUFFER_BIT) != 0) {
622 EXPECT_CALL(*gl_, ClearColor(0.0f, 0.0f, 0.0f, 0.0f))
624 .RetiresOnSaturation();
625 SetupExpectationsForColorMask(true, true, true, true);
627 if ((clear_bits & GL_STENCIL_BUFFER_BIT) != 0) {
628 EXPECT_CALL(*gl_, ClearStencil(0))
630 .RetiresOnSaturation();
631 EXPECT_CALL(*gl_, StencilMask(static_cast<GLuint>(-1)))
633 .RetiresOnSaturation();
635 if ((clear_bits & GL_DEPTH_BUFFER_BIT) != 0) {
636 EXPECT_CALL(*gl_, ClearDepth(1.0f))
638 .RetiresOnSaturation();
639 SetupExpectationsForDepthMask(true);
641 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST, false);
642 EXPECT_CALL(*gl_, Clear(clear_bits))
644 .RetiresOnSaturation();
645 SetupExpectationsForRestoreClearState(
646 restore_red, restore_green, restore_blue, restore_alpha,
647 restore_stencil, restore_depth, restore_scissor_test);
648 if (target == GL_READ_FRAMEBUFFER_EXT) {
649 EXPECT_CALL(*gl_, BindFramebufferEXT(
650 GL_READ_FRAMEBUFFER_EXT, read_framebuffer_service_id))
652 .RetiresOnSaturation();
653 EXPECT_CALL(*gl_, BindFramebufferEXT(
654 GL_DRAW_FRAMEBUFFER_EXT, draw_framebuffer_service_id))
656 .RetiresOnSaturation();
660 void GLES2DecoderTestBase::SetupShaderForUniform(GLenum uniform_type) {
661 static AttribInfo attribs[] = {
662 { "foo", 1, GL_FLOAT, 1, },
663 { "goo", 1, GL_FLOAT, 2, },
665 UniformInfo uniforms[] = {
666 { "bar", 1, uniform_type, 0, 2, -1, },
667 { "car", 4, uniform_type, 1, 1, -1, },
669 const GLuint kClientVertexShaderId = 5001;
670 const GLuint kServiceVertexShaderId = 6001;
671 const GLuint kClientFragmentShaderId = 5002;
672 const GLuint kServiceFragmentShaderId = 6002;
673 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
674 client_program_id_, kServiceProgramId,
675 kClientVertexShaderId, kServiceVertexShaderId,
676 kClientFragmentShaderId, kServiceFragmentShaderId);
678 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
680 .RetiresOnSaturation();
681 cmds::UseProgram cmd;
682 cmd.Init(client_program_id_);
683 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
686 void GLES2DecoderTestBase::DoBindBuffer(
687 GLenum target, GLuint client_id, GLuint service_id) {
688 EXPECT_CALL(*gl_, BindBuffer(target, service_id))
690 .RetiresOnSaturation();
691 cmds::BindBuffer cmd;
692 cmd.Init(target, client_id);
693 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
696 bool GLES2DecoderTestBase::DoIsBuffer(GLuint client_id) {
697 return IsObjectHelper<cmds::IsBuffer, cmds::IsBuffer::Result>(client_id);
700 void GLES2DecoderTestBase::DoDeleteBuffer(
701 GLuint client_id, GLuint service_id) {
702 EXPECT_CALL(*gl_, DeleteBuffersARB(1, Pointee(service_id)))
704 .RetiresOnSaturation();
705 GenHelper<cmds::DeleteBuffersImmediate>(client_id);
708 void GLES2DecoderTestBase::SetupExpectationsForColorMask(bool red,
712 if (ignore_cached_state_for_test_ || cached_color_mask_red_ != red ||
713 cached_color_mask_green_ != green || cached_color_mask_blue_ != blue ||
714 cached_color_mask_alpha_ != alpha) {
715 cached_color_mask_red_ = red;
716 cached_color_mask_green_ = green;
717 cached_color_mask_blue_ = blue;
718 cached_color_mask_alpha_ = alpha;
719 EXPECT_CALL(*gl_, ColorMask(red, green, blue, alpha))
721 .RetiresOnSaturation();
725 void GLES2DecoderTestBase::SetupExpectationsForDepthMask(bool mask) {
726 if (ignore_cached_state_for_test_ || cached_depth_mask_ != mask) {
727 cached_depth_mask_ = mask;
728 EXPECT_CALL(*gl_, DepthMask(mask)).Times(1).RetiresOnSaturation();
732 void GLES2DecoderTestBase::SetupExpectationsForStencilMask(GLuint front_mask,
734 if (ignore_cached_state_for_test_ ||
735 cached_stencil_front_mask_ != front_mask) {
736 cached_stencil_front_mask_ = front_mask;
737 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_FRONT, front_mask))
739 .RetiresOnSaturation();
742 if (ignore_cached_state_for_test_ ||
743 cached_stencil_back_mask_ != back_mask) {
744 cached_stencil_back_mask_ = back_mask;
745 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_BACK, back_mask))
747 .RetiresOnSaturation();
751 void GLES2DecoderTestBase::SetupExpectationsForEnableDisable(GLenum cap,
755 if (enable_flags_.cached_blend == enable &&
756 !ignore_cached_state_for_test_)
758 enable_flags_.cached_blend = enable;
761 if (enable_flags_.cached_cull_face == enable &&
762 !ignore_cached_state_for_test_)
764 enable_flags_.cached_cull_face = enable;
767 if (enable_flags_.cached_depth_test == enable &&
768 !ignore_cached_state_for_test_)
770 enable_flags_.cached_depth_test = enable;
773 if (enable_flags_.cached_dither == enable &&
774 !ignore_cached_state_for_test_)
776 enable_flags_.cached_dither = enable;
778 case GL_POLYGON_OFFSET_FILL:
779 if (enable_flags_.cached_polygon_offset_fill == enable &&
780 !ignore_cached_state_for_test_)
782 enable_flags_.cached_polygon_offset_fill = enable;
784 case GL_SAMPLE_ALPHA_TO_COVERAGE:
785 if (enable_flags_.cached_sample_alpha_to_coverage == enable &&
786 !ignore_cached_state_for_test_)
788 enable_flags_.cached_sample_alpha_to_coverage = enable;
790 case GL_SAMPLE_COVERAGE:
791 if (enable_flags_.cached_sample_coverage == enable &&
792 !ignore_cached_state_for_test_)
794 enable_flags_.cached_sample_coverage = enable;
796 case GL_SCISSOR_TEST:
797 if (enable_flags_.cached_scissor_test == enable &&
798 !ignore_cached_state_for_test_)
800 enable_flags_.cached_scissor_test = enable;
802 case GL_STENCIL_TEST:
803 if (enable_flags_.cached_stencil_test == enable &&
804 !ignore_cached_state_for_test_)
806 enable_flags_.cached_stencil_test = enable;
813 EXPECT_CALL(*gl_, Enable(cap)).Times(1).RetiresOnSaturation();
815 EXPECT_CALL(*gl_, Disable(cap)).Times(1).RetiresOnSaturation();
819 void GLES2DecoderTestBase::SetupExpectationsForApplyingDirtyState(
820 bool framebuffer_is_rgb,
821 bool framebuffer_has_depth,
822 bool framebuffer_has_stencil,
826 GLuint front_stencil_mask,
827 GLuint back_stencil_mask,
828 bool stencil_enabled) {
829 bool color_mask_red = (color_bits & 0x1000) != 0;
830 bool color_mask_green = (color_bits & 0x0100) != 0;
831 bool color_mask_blue = (color_bits & 0x0010) != 0;
832 bool color_mask_alpha = (color_bits & 0x0001) && !framebuffer_is_rgb;
834 SetupExpectationsForColorMask(
835 color_mask_red, color_mask_green, color_mask_blue, color_mask_alpha);
836 SetupExpectationsForDepthMask(depth_mask);
837 SetupExpectationsForStencilMask(front_stencil_mask, back_stencil_mask);
838 SetupExpectationsForEnableDisable(GL_DEPTH_TEST,
839 framebuffer_has_depth && depth_enabled);
840 SetupExpectationsForEnableDisable(GL_STENCIL_TEST,
841 framebuffer_has_stencil && stencil_enabled);
844 void GLES2DecoderTestBase::SetupExpectationsForApplyingDefaultDirtyState() {
845 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
846 false, // Framebuffer has depth
847 false, // Framebuffer has stencil
848 0x1111, // color bits
850 false, // depth enabled
851 0, // front stencil mask
852 0, // back stencil mask
853 false); // stencil enabled
856 GLES2DecoderTestBase::EnableFlags::EnableFlags()
857 : cached_blend(false),
858 cached_cull_face(false),
859 cached_depth_test(false),
861 cached_polygon_offset_fill(false),
862 cached_sample_alpha_to_coverage(false),
863 cached_sample_coverage(false),
864 cached_scissor_test(false),
865 cached_stencil_test(false) {
868 void GLES2DecoderTestBase::DoBindFramebuffer(
869 GLenum target, GLuint client_id, GLuint service_id) {
870 EXPECT_CALL(*gl_, BindFramebufferEXT(target, service_id))
872 .RetiresOnSaturation();
873 cmds::BindFramebuffer cmd;
874 cmd.Init(target, client_id);
875 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
878 bool GLES2DecoderTestBase::DoIsFramebuffer(GLuint client_id) {
879 return IsObjectHelper<cmds::IsFramebuffer, cmds::IsFramebuffer::Result>(
883 void GLES2DecoderTestBase::DoDeleteFramebuffer(
884 GLuint client_id, GLuint service_id,
885 bool reset_draw, GLenum draw_target, GLuint draw_id,
886 bool reset_read, GLenum read_target, GLuint read_id) {
888 EXPECT_CALL(*gl_, BindFramebufferEXT(draw_target, draw_id))
890 .RetiresOnSaturation();
893 EXPECT_CALL(*gl_, BindFramebufferEXT(read_target, read_id))
895 .RetiresOnSaturation();
897 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, Pointee(service_id)))
899 .RetiresOnSaturation();
900 GenHelper<cmds::DeleteFramebuffersImmediate>(client_id);
903 void GLES2DecoderTestBase::DoBindRenderbuffer(
904 GLenum target, GLuint client_id, GLuint service_id) {
905 service_renderbuffer_id_ = service_id;
906 service_renderbuffer_valid_ = true;
907 EXPECT_CALL(*gl_, BindRenderbufferEXT(target, service_id))
909 .RetiresOnSaturation();
910 cmds::BindRenderbuffer cmd;
911 cmd.Init(target, client_id);
912 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
915 void GLES2DecoderTestBase::DoRenderbufferStorageMultisampleCHROMIUM(
918 GLenum internal_format,
922 EXPECT_CALL(*gl_, GetError())
923 .WillOnce(Return(GL_NO_ERROR))
924 .RetiresOnSaturation();
926 RenderbufferStorageMultisampleEXT(
927 target, samples, gl_format, width, height))
929 .RetiresOnSaturation();
930 EXPECT_CALL(*gl_, GetError())
931 .WillOnce(Return(GL_NO_ERROR))
932 .RetiresOnSaturation();
933 cmds::RenderbufferStorageMultisampleCHROMIUM cmd;
934 cmd.Init(target, samples, internal_format, width, height);
935 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
936 EXPECT_EQ(GL_NO_ERROR, GetGLError());
939 void GLES2DecoderTestBase::RestoreRenderbufferBindings() {
940 GetDecoder()->RestoreRenderbufferBindings();
941 service_renderbuffer_valid_ = false;
944 void GLES2DecoderTestBase::EnsureRenderbufferBound(bool expect_bind) {
945 EXPECT_NE(expect_bind, service_renderbuffer_valid_);
948 service_renderbuffer_valid_ = true;
950 BindRenderbufferEXT(GL_RENDERBUFFER, service_renderbuffer_id_))
952 .RetiresOnSaturation();
954 EXPECT_CALL(*gl_, BindRenderbufferEXT(_, _)).Times(0);
958 bool GLES2DecoderTestBase::DoIsRenderbuffer(GLuint client_id) {
959 return IsObjectHelper<cmds::IsRenderbuffer, cmds::IsRenderbuffer::Result>(
963 void GLES2DecoderTestBase::DoDeleteRenderbuffer(
964 GLuint client_id, GLuint service_id) {
965 EXPECT_CALL(*gl_, DeleteRenderbuffersEXT(1, Pointee(service_id)))
967 .RetiresOnSaturation();
968 GenHelper<cmds::DeleteRenderbuffersImmediate>(client_id);
971 void GLES2DecoderTestBase::DoBindTexture(
972 GLenum target, GLuint client_id, GLuint service_id) {
973 EXPECT_CALL(*gl_, BindTexture(target, service_id))
975 .RetiresOnSaturation();
976 cmds::BindTexture cmd;
977 cmd.Init(target, client_id);
978 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
981 bool GLES2DecoderTestBase::DoIsTexture(GLuint client_id) {
982 return IsObjectHelper<cmds::IsTexture, cmds::IsTexture::Result>(client_id);
985 void GLES2DecoderTestBase::DoDeleteTexture(
986 GLuint client_id, GLuint service_id) {
987 EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(service_id)))
989 .RetiresOnSaturation();
990 GenHelper<cmds::DeleteTexturesImmediate>(client_id);
993 void GLES2DecoderTestBase::DoTexImage2D(
994 GLenum target, GLint level, GLenum internal_format,
995 GLsizei width, GLsizei height, GLint border,
996 GLenum format, GLenum type,
997 uint32 shared_memory_id, uint32 shared_memory_offset) {
998 EXPECT_CALL(*gl_, GetError())
999 .WillOnce(Return(GL_NO_ERROR))
1000 .RetiresOnSaturation();
1001 EXPECT_CALL(*gl_, TexImage2D(target, level, internal_format,
1002 width, height, border, format, type, _))
1004 .RetiresOnSaturation();
1005 EXPECT_CALL(*gl_, GetError())
1006 .WillOnce(Return(GL_NO_ERROR))
1007 .RetiresOnSaturation();
1008 cmds::TexImage2D cmd;
1009 cmd.Init(target, level, internal_format, width, height, format,
1010 type, shared_memory_id, shared_memory_offset);
1011 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1014 void GLES2DecoderTestBase::DoTexImage2DConvertInternalFormat(
1015 GLenum target, GLint level, GLenum requested_internal_format,
1016 GLsizei width, GLsizei height, GLint border,
1017 GLenum format, GLenum type,
1018 uint32 shared_memory_id, uint32 shared_memory_offset,
1019 GLenum expected_internal_format) {
1020 EXPECT_CALL(*gl_, GetError())
1021 .WillOnce(Return(GL_NO_ERROR))
1022 .RetiresOnSaturation();
1023 EXPECT_CALL(*gl_, TexImage2D(target, level, expected_internal_format,
1024 width, height, border, format, type, _))
1026 .RetiresOnSaturation();
1027 EXPECT_CALL(*gl_, GetError())
1028 .WillOnce(Return(GL_NO_ERROR))
1029 .RetiresOnSaturation();
1030 cmds::TexImage2D cmd;
1031 cmd.Init(target, level, requested_internal_format, width, height,
1032 format, type, shared_memory_id, shared_memory_offset);
1033 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1036 void GLES2DecoderTestBase::DoCompressedTexImage2D(
1037 GLenum target, GLint level, GLenum format,
1038 GLsizei width, GLsizei height, GLint border,
1039 GLsizei size, uint32 bucket_id) {
1040 EXPECT_CALL(*gl_, GetError())
1041 .WillOnce(Return(GL_NO_ERROR))
1042 .RetiresOnSaturation();
1043 EXPECT_CALL(*gl_, CompressedTexImage2D(
1044 target, level, format, width, height, border, size, _))
1046 .RetiresOnSaturation();
1047 EXPECT_CALL(*gl_, GetError())
1048 .WillOnce(Return(GL_NO_ERROR))
1049 .RetiresOnSaturation();
1050 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(bucket_id);
1051 bucket->SetSize(size);
1052 cmds::CompressedTexImage2DBucket cmd;
1054 target, level, format, width, height,
1056 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1059 void GLES2DecoderTestBase::DoRenderbufferStorage(
1060 GLenum target, GLenum internal_format, GLenum actual_format,
1061 GLsizei width, GLsizei height, GLenum error) {
1062 EXPECT_CALL(*gl_, GetError())
1063 .WillOnce(Return(GL_NO_ERROR))
1064 .RetiresOnSaturation();
1065 EXPECT_CALL(*gl_, RenderbufferStorageEXT(
1066 target, actual_format, width, height))
1068 .RetiresOnSaturation();
1069 EXPECT_CALL(*gl_, GetError())
1070 .WillOnce(Return(error))
1071 .RetiresOnSaturation();
1072 cmds::RenderbufferStorage cmd;
1073 cmd.Init(target, internal_format, width, height);
1074 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1077 void GLES2DecoderTestBase::DoFramebufferTexture2D(
1078 GLenum target, GLenum attachment, GLenum textarget,
1079 GLuint texture_client_id, GLuint texture_service_id, GLint level,
1081 EXPECT_CALL(*gl_, GetError())
1082 .WillOnce(Return(GL_NO_ERROR))
1083 .RetiresOnSaturation();
1084 EXPECT_CALL(*gl_, FramebufferTexture2DEXT(
1085 target, attachment, textarget, texture_service_id, level))
1087 .RetiresOnSaturation();
1088 EXPECT_CALL(*gl_, GetError())
1089 .WillOnce(Return(error))
1090 .RetiresOnSaturation();
1091 cmds::FramebufferTexture2D cmd;
1092 cmd.Init(target, attachment, textarget, texture_client_id);
1093 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1096 void GLES2DecoderTestBase::DoFramebufferRenderbuffer(
1099 GLenum renderbuffer_target,
1100 GLuint renderbuffer_client_id,
1101 GLuint renderbuffer_service_id,
1103 EXPECT_CALL(*gl_, GetError())
1104 .WillOnce(Return(GL_NO_ERROR))
1105 .RetiresOnSaturation();
1106 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
1107 target, attachment, renderbuffer_target, renderbuffer_service_id))
1109 .RetiresOnSaturation();
1110 EXPECT_CALL(*gl_, GetError())
1111 .WillOnce(Return(error))
1112 .RetiresOnSaturation();
1113 cmds::FramebufferRenderbuffer cmd;
1114 cmd.Init(target, attachment, renderbuffer_target, renderbuffer_client_id);
1115 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1118 void GLES2DecoderTestBase::DoVertexAttribPointer(
1119 GLuint index, GLint size, GLenum type, GLsizei stride, GLuint offset) {
1121 VertexAttribPointer(index, size, type, GL_FALSE, stride,
1122 BufferOffset(offset)))
1124 .RetiresOnSaturation();
1125 cmds::VertexAttribPointer cmd;
1126 cmd.Init(index, size, GL_FLOAT, GL_FALSE, stride, offset);
1127 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1130 void GLES2DecoderTestBase::DoVertexAttribDivisorANGLE(
1131 GLuint index, GLuint divisor) {
1133 VertexAttribDivisorANGLE(index, divisor))
1135 .RetiresOnSaturation();
1136 cmds::VertexAttribDivisorANGLE cmd;
1137 cmd.Init(index, divisor);
1138 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1141 void GLES2DecoderTestBase::AddExpectationsForGenVertexArraysOES(){
1142 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
1143 EXPECT_CALL(*gl_, GenVertexArraysOES(1, _))
1144 .WillOnce(SetArgumentPointee<1>(kServiceVertexArrayId))
1145 .RetiresOnSaturation();
1149 void GLES2DecoderTestBase::AddExpectationsForDeleteVertexArraysOES(){
1150 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
1151 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, _))
1153 .RetiresOnSaturation();
1157 void GLES2DecoderTestBase::AddExpectationsForDeleteBoundVertexArraysOES() {
1158 // Expectations are the same as a delete, followed by binding VAO 0.
1159 AddExpectationsForDeleteVertexArraysOES();
1160 AddExpectationsForBindVertexArrayOES();
1163 void GLES2DecoderTestBase::AddExpectationsForBindVertexArrayOES() {
1164 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
1165 EXPECT_CALL(*gl_, BindVertexArrayOES(_))
1167 .RetiresOnSaturation();
1169 for (uint32 vv = 0; vv < group_->max_vertex_attribs(); ++vv) {
1170 AddExpectationsForRestoreAttribState(vv);
1173 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _))
1175 .RetiresOnSaturation();
1179 void GLES2DecoderTestBase::AddExpectationsForRestoreAttribState(GLuint attrib) {
1180 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1182 .RetiresOnSaturation();
1184 EXPECT_CALL(*gl_, VertexAttribPointer(attrib, _, _, _, _, _))
1186 .RetiresOnSaturation();
1188 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(attrib, _))
1189 .Times(testing::AtMost(1))
1190 .RetiresOnSaturation();
1192 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1194 .RetiresOnSaturation();
1197 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
1199 // TODO(bajones): Not sure if I can tell which of these will be called
1200 EXPECT_CALL(*gl_, EnableVertexAttribArray(attrib))
1201 .Times(testing::AtMost(1))
1202 .RetiresOnSaturation();
1204 EXPECT_CALL(*gl_, DisableVertexAttribArray(attrib))
1205 .Times(testing::AtMost(1))
1206 .RetiresOnSaturation();
1210 // GCC requires these declarations, but MSVC requires they not be present
1211 #ifndef COMPILER_MSVC
1212 const int GLES2DecoderTestBase::kBackBufferWidth;
1213 const int GLES2DecoderTestBase::kBackBufferHeight;
1215 const GLint GLES2DecoderTestBase::kMaxTextureSize;
1216 const GLint GLES2DecoderTestBase::kMaxCubeMapTextureSize;
1217 const GLint GLES2DecoderTestBase::kNumVertexAttribs;
1218 const GLint GLES2DecoderTestBase::kNumTextureUnits;
1219 const GLint GLES2DecoderTestBase::kMaxTextureImageUnits;
1220 const GLint GLES2DecoderTestBase::kMaxVertexTextureImageUnits;
1221 const GLint GLES2DecoderTestBase::kMaxFragmentUniformVectors;
1222 const GLint GLES2DecoderTestBase::kMaxVaryingVectors;
1223 const GLint GLES2DecoderTestBase::kMaxVertexUniformVectors;
1224 const GLint GLES2DecoderTestBase::kMaxViewportWidth;
1225 const GLint GLES2DecoderTestBase::kMaxViewportHeight;
1227 const GLint GLES2DecoderTestBase::kViewportX;
1228 const GLint GLES2DecoderTestBase::kViewportY;
1229 const GLint GLES2DecoderTestBase::kViewportWidth;
1230 const GLint GLES2DecoderTestBase::kViewportHeight;
1232 const GLuint GLES2DecoderTestBase::kServiceAttrib0BufferId;
1233 const GLuint GLES2DecoderTestBase::kServiceFixedAttribBufferId;
1235 const GLuint GLES2DecoderTestBase::kServiceBufferId;
1236 const GLuint GLES2DecoderTestBase::kServiceFramebufferId;
1237 const GLuint GLES2DecoderTestBase::kServiceRenderbufferId;
1238 const GLuint GLES2DecoderTestBase::kServiceTextureId;
1239 const GLuint GLES2DecoderTestBase::kServiceProgramId;
1240 const GLuint GLES2DecoderTestBase::kServiceShaderId;
1241 const GLuint GLES2DecoderTestBase::kServiceElementBufferId;
1242 const GLuint GLES2DecoderTestBase::kServiceQueryId;
1243 const GLuint GLES2DecoderTestBase::kServiceVertexArrayId;
1245 const int32 GLES2DecoderTestBase::kSharedMemoryId;
1246 const size_t GLES2DecoderTestBase::kSharedBufferSize;
1247 const uint32 GLES2DecoderTestBase::kSharedMemoryOffset;
1248 const int32 GLES2DecoderTestBase::kInvalidSharedMemoryId;
1249 const uint32 GLES2DecoderTestBase::kInvalidSharedMemoryOffset;
1250 const uint32 GLES2DecoderTestBase::kInitialResult;
1251 const uint8 GLES2DecoderTestBase::kInitialMemoryValue;
1253 const uint32 GLES2DecoderTestBase::kNewClientId;
1254 const uint32 GLES2DecoderTestBase::kNewServiceId;
1255 const uint32 GLES2DecoderTestBase::kInvalidClientId;
1257 const GLuint GLES2DecoderTestBase::kServiceVertexShaderId;
1258 const GLuint GLES2DecoderTestBase::kServiceFragmentShaderId;
1260 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumShaderId;
1261 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumProgramId;
1263 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTextureBufferId;
1264 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumVertexBufferId;
1265 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumFBOId;
1266 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumPositionAttrib;
1267 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTexAttrib;
1268 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumSamplerLocation;
1270 const GLsizei GLES2DecoderTestBase::kNumVertices;
1271 const GLsizei GLES2DecoderTestBase::kNumIndices;
1272 const int GLES2DecoderTestBase::kValidIndexRangeStart;
1273 const int GLES2DecoderTestBase::kValidIndexRangeCount;
1274 const int GLES2DecoderTestBase::kInvalidIndexRangeStart;
1275 const int GLES2DecoderTestBase::kInvalidIndexRangeCount;
1276 const int GLES2DecoderTestBase::kOutOfRangeIndexRangeEnd;
1277 const GLuint GLES2DecoderTestBase::kMaxValidIndex;
1279 const GLint GLES2DecoderTestBase::kMaxAttribLength;
1280 const GLint GLES2DecoderTestBase::kAttrib1Size;
1281 const GLint GLES2DecoderTestBase::kAttrib2Size;
1282 const GLint GLES2DecoderTestBase::kAttrib3Size;
1283 const GLint GLES2DecoderTestBase::kAttrib1Location;
1284 const GLint GLES2DecoderTestBase::kAttrib2Location;
1285 const GLint GLES2DecoderTestBase::kAttrib3Location;
1286 const GLenum GLES2DecoderTestBase::kAttrib1Type;
1287 const GLenum GLES2DecoderTestBase::kAttrib2Type;
1288 const GLenum GLES2DecoderTestBase::kAttrib3Type;
1289 const GLint GLES2DecoderTestBase::kInvalidAttribLocation;
1290 const GLint GLES2DecoderTestBase::kBadAttribIndex;
1292 const GLint GLES2DecoderTestBase::kMaxUniformLength;
1293 const GLint GLES2DecoderTestBase::kUniform1Size;
1294 const GLint GLES2DecoderTestBase::kUniform2Size;
1295 const GLint GLES2DecoderTestBase::kUniform3Size;
1296 const GLint GLES2DecoderTestBase::kUniform1RealLocation;
1297 const GLint GLES2DecoderTestBase::kUniform2RealLocation;
1298 const GLint GLES2DecoderTestBase::kUniform2ElementRealLocation;
1299 const GLint GLES2DecoderTestBase::kUniform3RealLocation;
1300 const GLint GLES2DecoderTestBase::kUniform1FakeLocation;
1301 const GLint GLES2DecoderTestBase::kUniform2FakeLocation;
1302 const GLint GLES2DecoderTestBase::kUniform2ElementFakeLocation;
1303 const GLint GLES2DecoderTestBase::kUniform3FakeLocation;
1304 const GLint GLES2DecoderTestBase::kUniform1DesiredLocation;
1305 const GLint GLES2DecoderTestBase::kUniform2DesiredLocation;
1306 const GLint GLES2DecoderTestBase::kUniform3DesiredLocation;
1307 const GLenum GLES2DecoderTestBase::kUniform1Type;
1308 const GLenum GLES2DecoderTestBase::kUniform2Type;
1309 const GLenum GLES2DecoderTestBase::kUniform3Type;
1310 const GLenum GLES2DecoderTestBase::kUniformCubemapType;
1311 const GLint GLES2DecoderTestBase::kInvalidUniformLocation;
1312 const GLint GLES2DecoderTestBase::kBadUniformIndex;
1316 const char* GLES2DecoderTestBase::kAttrib1Name = "attrib1";
1317 const char* GLES2DecoderTestBase::kAttrib2Name = "attrib2";
1318 const char* GLES2DecoderTestBase::kAttrib3Name = "attrib3";
1319 const char* GLES2DecoderTestBase::kUniform1Name = "uniform1";
1320 const char* GLES2DecoderTestBase::kUniform2Name = "uniform2[0]";
1321 const char* GLES2DecoderTestBase::kUniform3Name = "uniform3[0]";
1323 void GLES2DecoderTestBase::SetupDefaultProgram() {
1325 static AttribInfo attribs[] = {
1326 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1327 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1328 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1330 static UniformInfo uniforms[] = {
1331 { kUniform1Name, kUniform1Size, kUniform1Type,
1332 kUniform1FakeLocation, kUniform1RealLocation,
1333 kUniform1DesiredLocation },
1334 { kUniform2Name, kUniform2Size, kUniform2Type,
1335 kUniform2FakeLocation, kUniform2RealLocation,
1336 kUniform2DesiredLocation },
1337 { kUniform3Name, kUniform3Size, kUniform3Type,
1338 kUniform3FakeLocation, kUniform3RealLocation,
1339 kUniform3DesiredLocation },
1341 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1342 client_program_id_, kServiceProgramId,
1343 client_vertex_shader_id_, kServiceVertexShaderId,
1344 client_fragment_shader_id_, kServiceFragmentShaderId);
1348 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1350 .RetiresOnSaturation();
1351 cmds::UseProgram cmd;
1352 cmd.Init(client_program_id_);
1353 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1357 void GLES2DecoderTestBase::SetupCubemapProgram() {
1359 static AttribInfo attribs[] = {
1360 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1361 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1362 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1364 static UniformInfo uniforms[] = {
1365 { kUniform1Name, kUniform1Size, kUniformCubemapType,
1366 kUniform1FakeLocation, kUniform1RealLocation,
1367 kUniform1DesiredLocation, },
1368 { kUniform2Name, kUniform2Size, kUniform2Type,
1369 kUniform2FakeLocation, kUniform2RealLocation,
1370 kUniform2DesiredLocation, },
1371 { kUniform3Name, kUniform3Size, kUniform3Type,
1372 kUniform3FakeLocation, kUniform3RealLocation,
1373 kUniform3DesiredLocation, },
1375 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1376 client_program_id_, kServiceProgramId,
1377 client_vertex_shader_id_, kServiceVertexShaderId,
1378 client_fragment_shader_id_, kServiceFragmentShaderId);
1382 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1384 .RetiresOnSaturation();
1385 cmds::UseProgram cmd;
1386 cmd.Init(client_program_id_);
1387 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1391 void GLES2DecoderTestBase::SetupSamplerExternalProgram() {
1393 static AttribInfo attribs[] = {
1394 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1395 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1396 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1398 static UniformInfo uniforms[] = {
1399 { kUniform1Name, kUniform1Size, kUniformSamplerExternalType,
1400 kUniform1FakeLocation, kUniform1RealLocation,
1401 kUniform1DesiredLocation, },
1402 { kUniform2Name, kUniform2Size, kUniform2Type,
1403 kUniform2FakeLocation, kUniform2RealLocation,
1404 kUniform2DesiredLocation, },
1405 { kUniform3Name, kUniform3Size, kUniform3Type,
1406 kUniform3FakeLocation, kUniform3RealLocation,
1407 kUniform3DesiredLocation, },
1409 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1410 client_program_id_, kServiceProgramId,
1411 client_vertex_shader_id_, kServiceVertexShaderId,
1412 client_fragment_shader_id_, kServiceFragmentShaderId);
1416 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1418 .RetiresOnSaturation();
1419 cmds::UseProgram cmd;
1420 cmd.Init(client_program_id_);
1421 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1425 void GLES2DecoderWithShaderTestBase::TearDown() {
1426 GLES2DecoderTestBase::TearDown();
1429 void GLES2DecoderTestBase::SetupShader(
1430 GLES2DecoderTestBase::AttribInfo* attribs, size_t num_attribs,
1431 GLES2DecoderTestBase::UniformInfo* uniforms, size_t num_uniforms,
1432 GLuint program_client_id, GLuint program_service_id,
1433 GLuint vertex_shader_client_id, GLuint vertex_shader_service_id,
1434 GLuint fragment_shader_client_id, GLuint fragment_shader_service_id) {
1439 AttachShader(program_service_id, vertex_shader_service_id))
1441 .RetiresOnSaturation();
1443 AttachShader(program_service_id, fragment_shader_service_id))
1445 .RetiresOnSaturation();
1446 TestHelper::SetupShader(
1447 gl_.get(), attribs, num_attribs, uniforms, num_uniforms,
1448 program_service_id);
1452 GL_VERTEX_SHADER, vertex_shader_client_id, vertex_shader_service_id);
1454 GL_FRAGMENT_SHADER, fragment_shader_client_id,
1455 fragment_shader_service_id);
1457 GetShader(vertex_shader_client_id)->SetStatus(true, "", NULL);
1458 GetShader(fragment_shader_client_id)->SetStatus(true, "", NULL);
1460 cmds::AttachShader attach_cmd;
1461 attach_cmd.Init(program_client_id, vertex_shader_client_id);
1462 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1464 attach_cmd.Init(program_client_id, fragment_shader_client_id);
1465 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1467 cmds::LinkProgram link_cmd;
1468 link_cmd.Init(program_client_id);
1470 EXPECT_EQ(error::kNoError, ExecuteCmd(link_cmd));
1473 void GLES2DecoderTestBase::DoEnableDisable(GLenum cap, bool enable) {
1474 SetupExpectationsForEnableDisable(cap, enable);
1478 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1482 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1486 void GLES2DecoderTestBase::DoEnableVertexAttribArray(GLint index) {
1487 EXPECT_CALL(*gl_, EnableVertexAttribArray(index))
1489 .RetiresOnSaturation();
1490 cmds::EnableVertexAttribArray cmd;
1492 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1495 void GLES2DecoderTestBase::DoBufferData(GLenum target, GLsizei size) {
1496 EXPECT_CALL(*gl_, GetError())
1497 .WillOnce(Return(GL_NO_ERROR))
1498 .RetiresOnSaturation();
1499 EXPECT_CALL(*gl_, BufferData(target, size, _, GL_STREAM_DRAW))
1501 .RetiresOnSaturation();
1502 EXPECT_CALL(*gl_, GetError())
1503 .WillOnce(Return(GL_NO_ERROR))
1504 .RetiresOnSaturation();
1505 cmds::BufferData cmd;
1506 cmd.Init(target, size, 0, 0, GL_STREAM_DRAW);
1507 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1510 void GLES2DecoderTestBase::DoBufferSubData(
1511 GLenum target, GLint offset, GLsizei size, const void* data) {
1512 EXPECT_CALL(*gl_, BufferSubData(target, offset, size,
1513 shared_memory_address_))
1515 .RetiresOnSaturation();
1516 memcpy(shared_memory_address_, data, size);
1517 cmds::BufferSubData cmd;
1518 cmd.Init(target, offset, size, shared_memory_id_, shared_memory_offset_);
1519 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1522 void GLES2DecoderTestBase::SetupVertexBuffer() {
1523 DoEnableVertexAttribArray(1);
1524 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1526 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 2 * sizeof(f));
1529 void GLES2DecoderTestBase::SetupAllNeededVertexBuffers() {
1530 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1531 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 16 * sizeof(float));
1532 DoEnableVertexAttribArray(0);
1533 DoEnableVertexAttribArray(1);
1534 DoEnableVertexAttribArray(2);
1535 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1536 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1537 DoVertexAttribPointer(2, 2, GL_FLOAT, 0, 0);
1540 void GLES2DecoderTestBase::SetupIndexBuffer() {
1541 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
1542 client_element_buffer_id_,
1543 kServiceElementBufferId);
1544 static const GLshort indices[] = {100, 1, 2, 3, 4, 5, 6, 7, 100, 9};
1545 COMPILE_ASSERT(arraysize(indices) == kNumIndices, Indices_is_not_10);
1546 DoBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices));
1547 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, 2, indices);
1548 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 2, sizeof(indices) - 2, &indices[1]);
1551 void GLES2DecoderTestBase::SetupTexture() {
1552 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1553 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1554 kSharedMemoryId, kSharedMemoryOffset);
1557 void GLES2DecoderTestBase::DeleteVertexBuffer() {
1558 DoDeleteBuffer(client_buffer_id_, kServiceBufferId);
1561 void GLES2DecoderTestBase::DeleteIndexBuffer() {
1562 DoDeleteBuffer(client_element_buffer_id_, kServiceElementBufferId);
1565 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0WithError(
1566 GLsizei num_vertices, GLuint buffer_id, GLenum error) {
1567 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
1571 EXPECT_CALL(*gl_, GetError())
1572 .WillOnce(Return(GL_NO_ERROR))
1573 .WillOnce(Return(error))
1574 .RetiresOnSaturation();
1575 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
1577 .RetiresOnSaturation();
1578 EXPECT_CALL(*gl_, BufferData(GL_ARRAY_BUFFER,
1579 num_vertices * sizeof(GLfloat) * 4,
1580 _, GL_DYNAMIC_DRAW))
1582 .RetiresOnSaturation();
1583 if (error == GL_NO_ERROR) {
1584 EXPECT_CALL(*gl_, BufferSubData(
1585 GL_ARRAY_BUFFER, 0, num_vertices * sizeof(GLfloat) * 4, _))
1587 .RetiresOnSaturation();
1588 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL))
1590 .RetiresOnSaturation();
1591 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, buffer_id))
1593 .RetiresOnSaturation();
1597 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0(
1598 GLsizei num_vertices, GLuint buffer_id) {
1599 AddExpectationsForSimulatedAttrib0WithError(
1600 num_vertices, buffer_id, GL_NO_ERROR);
1603 void GLES2DecoderTestBase::SetupMockGLBehaviors() {
1604 ON_CALL(*gl_, BindVertexArrayOES(_))
1605 .WillByDefault(Invoke(
1607 &GLES2DecoderTestBase::MockGLStates::OnBindVertexArrayOES));
1608 ON_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1609 .WillByDefault(WithArg<1>(Invoke(
1611 &GLES2DecoderTestBase::MockGLStates::OnBindArrayBuffer)));
1612 ON_CALL(*gl_, VertexAttribPointer(_, _, _, _, _, NULL))
1613 .WillByDefault(InvokeWithoutArgs(
1615 &GLES2DecoderTestBase::MockGLStates::OnVertexAttribNullPointer));
1618 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1619 MockCommandBufferEngine() {
1621 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory());
1622 shm->CreateAndMapAnonymous(kSharedBufferSize);
1623 valid_buffer_ = MakeBufferFromSharedMemory(shm.Pass(), kSharedBufferSize);
1625 ClearSharedMemory();
1628 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1629 ~MockCommandBufferEngine() {}
1631 scoped_refptr<gpu::Buffer>
1632 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetSharedMemoryBuffer(
1634 return shm_id == kSharedMemoryId ? valid_buffer_ : invalid_buffer_;
1637 void GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::set_token(
1642 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetBuffer(
1643 int32 /* transfer_buffer_id */) {
1648 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetOffset(
1654 int32 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetGetOffset() {
1659 void GLES2DecoderWithShaderTestBase::SetUp() {
1660 GLES2DecoderTestBase::SetUp();
1661 SetupDefaultProgram();
1664 // Include the auto-generated part of this file. We split this because it means
1665 // we can easily edit the non-auto generated parts right here in this file
1666 // instead of having to edit some template or the code generator.
1667 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h"
1669 } // namespace gles2