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::MatcherCast;
31 using ::testing::Pointee;
32 using ::testing::Return;
33 using ::testing::SetArrayArgument;
34 using ::testing::SetArgPointee;
35 using ::testing::SetArgumentPointee;
36 using ::testing::StrEq;
37 using ::testing::StrictMock;
42 GLES2DecoderTestBase::GLES2DecoderTestBase()
45 memory_tracker_(NULL),
46 client_buffer_id_(100),
47 client_framebuffer_id_(101),
48 client_program_id_(102),
49 client_renderbuffer_id_(103),
50 client_shader_id_(104),
51 client_texture_id_(106),
52 client_element_buffer_id_(107),
53 client_vertex_shader_id_(121),
54 client_fragment_shader_id_(122),
55 client_query_id_(123),
56 client_vertexarray_id_(124) {
57 memset(immediate_buffer_, 0xEE, sizeof(immediate_buffer_));
60 GLES2DecoderTestBase::~GLES2DecoderTestBase() {}
62 void GLES2DecoderTestBase::SetUp() {
64 init.gl_version = "3.0";
65 init.has_alpha = true;
66 init.has_depth = true;
67 init.request_alpha = true;
68 init.request_depth = true;
69 init.bind_generates_resource = true;
73 void GLES2DecoderTestBase::AddExpectationsForVertexAttribManager() {
74 for (GLint ii = 0; ii < kNumVertexAttribs; ++ii) {
75 EXPECT_CALL(*gl_, VertexAttrib4f(ii, 0.0f, 0.0f, 0.0f, 1.0f))
77 .RetiresOnSaturation();
81 GLES2DecoderTestBase::InitState::InitState()
87 request_stencil(false),
88 bind_generates_resource(false),
89 lose_context_when_out_of_memory(false) {}
91 void GLES2DecoderTestBase::InitDecoder(const InitState& init) {
92 InitDecoderWithCommandLine(init, NULL);
95 void GLES2DecoderTestBase::InitDecoderWithCommandLine(
96 const InitState& init,
97 const base::CommandLine* command_line) {
98 Framebuffer::ClearFramebufferCompleteComboMap();
100 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress);
101 gfx::GLSurface::InitializeOneOffWithMockBindingsForTests();
103 gl_.reset(new StrictMock<MockGLInterface>());
104 ::gfx::MockGLInterface::SetGLInterface(gl_.get());
106 // Only create stream texture manager if extension is requested.
107 std::vector<std::string> list;
108 base::SplitString(init.extensions, ' ', &list);
109 scoped_refptr<FeatureInfo> feature_info;
111 feature_info = new FeatureInfo(*command_line);
112 group_ = scoped_refptr<ContextGroup>(
113 new ContextGroup(NULL,
117 init.bind_generates_resource));
121 surface_ = new gfx::GLSurfaceStub;
122 surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight));
124 // Context needs to be created before initializing ContextGroup, which will
125 // in turn initialize FeatureInfo, which needs a context to determine
126 // extension support.
127 context_ = new gfx::GLContextStubWithExtensions;
128 context_->AddExtensionsString(init.extensions.c_str());
129 context_->SetGLVersionString(init.gl_version.c_str());
131 context_->MakeCurrent(surface_.get());
132 gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_);
134 TestHelper::SetupContextGroupInitExpectations(gl_.get(),
135 DisallowedFeatures(),
136 init.extensions.c_str(),
137 init.gl_version.c_str());
139 // We initialize the ContextGroup with a MockGLES2Decoder so that
140 // we can use the ContextGroup to figure out how the real GLES2Decoder
141 // will initialize itself.
142 mock_decoder_.reset(new MockGLES2Decoder());
144 group_->Initialize(mock_decoder_.get(), DisallowedFeatures()));
146 if (group_->feature_info()->workarounds().init_vertex_attributes)
147 AddExpectationsForVertexAttribManager();
149 AddExpectationsForBindVertexArrayOES();
151 EXPECT_CALL(*gl_, EnableVertexAttribArray(0))
153 .RetiresOnSaturation();
154 static GLuint attrib_0_id[] = {
155 kServiceAttrib0BufferId,
157 static GLuint fixed_attrib_buffer_id[] = {
158 kServiceFixedAttribBufferId,
160 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(attrib_0_id), _))
161 .WillOnce(SetArrayArgument<1>(attrib_0_id,
162 attrib_0_id + arraysize(attrib_0_id)))
163 .RetiresOnSaturation();
164 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
166 .RetiresOnSaturation();
167 EXPECT_CALL(*gl_, VertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL))
169 .RetiresOnSaturation();
170 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
172 .RetiresOnSaturation();
173 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(fixed_attrib_buffer_id), _))
174 .WillOnce(SetArrayArgument<1>(
175 fixed_attrib_buffer_id,
176 fixed_attrib_buffer_id + arraysize(fixed_attrib_buffer_id)))
177 .RetiresOnSaturation();
179 for (GLint tt = 0; tt < TestHelper::kNumTextureUnits; ++tt) {
180 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0 + tt))
182 .RetiresOnSaturation();
183 if (group_->feature_info()->feature_flags().oes_egl_image_external) {
184 EXPECT_CALL(*gl_, BindTexture(
185 GL_TEXTURE_EXTERNAL_OES,
186 TestHelper::kServiceDefaultExternalTextureId))
188 .RetiresOnSaturation();
190 if (group_->feature_info()->feature_flags().arb_texture_rectangle) {
191 EXPECT_CALL(*gl_, BindTexture(
192 GL_TEXTURE_RECTANGLE_ARB,
193 TestHelper::kServiceDefaultRectangleTextureId))
195 .RetiresOnSaturation();
197 EXPECT_CALL(*gl_, BindTexture(
198 GL_TEXTURE_CUBE_MAP, TestHelper::kServiceDefaultTextureCubemapId))
200 .RetiresOnSaturation();
201 EXPECT_CALL(*gl_, BindTexture(
202 GL_TEXTURE_2D, TestHelper::kServiceDefaultTexture2dId))
204 .RetiresOnSaturation();
206 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
208 .RetiresOnSaturation();
210 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
212 .RetiresOnSaturation();
213 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _))
214 .WillOnce(SetArgumentPointee<1>(init.has_alpha ? 8 : 0))
215 .RetiresOnSaturation();
216 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
217 .WillOnce(SetArgumentPointee<1>(init.has_depth ? 24 : 0))
218 .RetiresOnSaturation();
219 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
220 .WillOnce(SetArgumentPointee<1>(init.has_stencil ? 8 : 0))
221 .RetiresOnSaturation();
223 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE))
225 .RetiresOnSaturation();
227 EXPECT_CALL(*gl_, Enable(GL_POINT_SPRITE))
229 .RetiresOnSaturation();
231 static GLint max_viewport_dims[] = {
235 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VIEWPORT_DIMS, _))
236 .WillOnce(SetArrayArgument<1>(
237 max_viewport_dims, max_viewport_dims + arraysize(max_viewport_dims)))
238 .RetiresOnSaturation();
240 SetupInitCapabilitiesExpectations();
241 SetupInitStateExpectations();
243 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
245 .RetiresOnSaturation();
247 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
249 .RetiresOnSaturation();
250 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0))
252 .RetiresOnSaturation();
253 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
255 .RetiresOnSaturation();
256 EXPECT_CALL(*gl_, BindRenderbufferEXT(GL_RENDERBUFFER, 0))
258 .RetiresOnSaturation();
260 // TODO(boliu): Remove OS_ANDROID once crbug.com/259023 is fixed and the
261 // workaround has been reverted.
262 #if !defined(OS_ANDROID)
263 EXPECT_CALL(*gl_, Clear(
264 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
266 .RetiresOnSaturation();
269 engine_.reset(new StrictMock<MockCommandBufferEngine>());
270 scoped_refptr<gpu::Buffer> buffer =
271 engine_->GetSharedMemoryBuffer(kSharedMemoryId);
272 shared_memory_offset_ = kSharedMemoryOffset;
273 shared_memory_address_ =
274 reinterpret_cast<int8*>(buffer->memory()) + shared_memory_offset_;
275 shared_memory_id_ = kSharedMemoryId;
276 shared_memory_base_ = buffer->memory();
278 static const int32 kLoseContextWhenOutOfMemory = 0x10003;
280 int32 attributes[] = {EGL_ALPHA_SIZE,
281 init.request_alpha ? 8 : 0,
283 init.request_depth ? 24 : 0,
285 init.request_stencil ? 8 : 0,
286 kLoseContextWhenOutOfMemory,
287 init.lose_context_when_out_of_memory ? 1 : 0, };
288 std::vector<int32> attribs(attributes, attributes + arraysize(attributes));
290 decoder_.reset(GLES2Decoder::Create(group_.get()));
291 decoder_->GetLogger()->set_log_synthesized_gl_errors(false);
292 decoder_->Initialize(surface_,
296 DisallowedFeatures(),
298 decoder_->MakeCurrent();
299 decoder_->set_engine(engine_.get());
300 decoder_->BeginDecoding();
302 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
303 .WillOnce(SetArgumentPointee<1>(kServiceBufferId))
304 .RetiresOnSaturation();
305 GenHelper<cmds::GenBuffersImmediate>(client_buffer_id_);
306 EXPECT_CALL(*gl_, GenFramebuffersEXT(_, _))
307 .WillOnce(SetArgumentPointee<1>(kServiceFramebufferId))
308 .RetiresOnSaturation();
309 GenHelper<cmds::GenFramebuffersImmediate>(client_framebuffer_id_);
310 EXPECT_CALL(*gl_, GenRenderbuffersEXT(_, _))
311 .WillOnce(SetArgumentPointee<1>(kServiceRenderbufferId))
312 .RetiresOnSaturation();
313 GenHelper<cmds::GenRenderbuffersImmediate>(client_renderbuffer_id_);
314 EXPECT_CALL(*gl_, GenTextures(_, _))
315 .WillOnce(SetArgumentPointee<1>(kServiceTextureId))
316 .RetiresOnSaturation();
317 GenHelper<cmds::GenTexturesImmediate>(client_texture_id_);
318 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
319 .WillOnce(SetArgumentPointee<1>(kServiceElementBufferId))
320 .RetiresOnSaturation();
321 GenHelper<cmds::GenBuffersImmediate>(client_element_buffer_id_);
323 DoCreateProgram(client_program_id_, kServiceProgramId);
324 DoCreateShader(GL_VERTEX_SHADER, client_shader_id_, kServiceShaderId);
326 EXPECT_EQ(GL_NO_ERROR, GetGLError());
329 void GLES2DecoderTestBase::ResetDecoder() {
332 // All Tests should have read all their GLErrors before getting here.
333 EXPECT_EQ(GL_NO_ERROR, GetGLError());
335 EXPECT_CALL(*gl_, DeleteBuffersARB(1, _))
337 .RetiresOnSaturation();
339 decoder_->EndDecoding();
340 decoder_->Destroy(true);
342 group_->Destroy(mock_decoder_.get(), false);
344 ::gfx::MockGLInterface::SetGLInterface(NULL);
348 void GLES2DecoderTestBase::TearDown() {
352 void GLES2DecoderTestBase::ExpectEnableDisable(GLenum cap, bool enable) {
354 EXPECT_CALL(*gl_, Enable(cap))
356 .RetiresOnSaturation();
358 EXPECT_CALL(*gl_, Disable(cap))
360 .RetiresOnSaturation();
365 GLint GLES2DecoderTestBase::GetGLError() {
366 EXPECT_CALL(*gl_, GetError())
367 .WillOnce(Return(GL_NO_ERROR))
368 .RetiresOnSaturation();
370 cmd.Init(shared_memory_id_, shared_memory_offset_);
371 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
372 return static_cast<GLint>(*GetSharedMemoryAs<GLenum*>());
375 void GLES2DecoderTestBase::DoCreateShader(
376 GLenum shader_type, GLuint client_id, GLuint service_id) {
377 EXPECT_CALL(*gl_, CreateShader(shader_type))
379 .WillOnce(Return(service_id))
380 .RetiresOnSaturation();
381 cmds::CreateShader cmd;
382 cmd.Init(shader_type, client_id);
383 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
386 bool GLES2DecoderTestBase::DoIsShader(GLuint client_id) {
387 return IsObjectHelper<cmds::IsShader, cmds::IsShader::Result>(client_id);
390 void GLES2DecoderTestBase::DoDeleteShader(
391 GLuint client_id, GLuint service_id) {
392 EXPECT_CALL(*gl_, DeleteShader(service_id))
394 .RetiresOnSaturation();
395 cmds::DeleteShader cmd;
397 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
400 void GLES2DecoderTestBase::DoCreateProgram(
401 GLuint client_id, GLuint service_id) {
402 EXPECT_CALL(*gl_, CreateProgram())
404 .WillOnce(Return(service_id))
405 .RetiresOnSaturation();
406 cmds::CreateProgram cmd;
408 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
411 bool GLES2DecoderTestBase::DoIsProgram(GLuint client_id) {
412 return IsObjectHelper<cmds::IsProgram, cmds::IsProgram::Result>(client_id);
415 void GLES2DecoderTestBase::DoDeleteProgram(
416 GLuint client_id, GLuint /* service_id */) {
417 cmds::DeleteProgram cmd;
419 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
422 void GLES2DecoderTestBase::SetBucketAsCString(
423 uint32 bucket_id, const char* str) {
424 uint32 size = str ? (strlen(str) + 1) : 0;
425 cmd::SetBucketSize cmd1;
426 cmd1.Init(bucket_id, size);
427 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
429 memcpy(shared_memory_address_, str, size);
430 cmd::SetBucketData cmd2;
431 cmd2.Init(bucket_id, 0, size, kSharedMemoryId, kSharedMemoryOffset);
432 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
437 void GLES2DecoderTestBase::SetupClearTextureExpectations(
439 GLuint old_service_id,
443 GLenum internal_format,
448 EXPECT_CALL(*gl_, BindTexture(bind_target, service_id))
450 .RetiresOnSaturation();
451 EXPECT_CALL(*gl_, TexImage2D(
452 target, level, internal_format, width, height, 0, format, type, _))
454 .RetiresOnSaturation();
455 EXPECT_CALL(*gl_, BindTexture(bind_target, old_service_id))
457 .RetiresOnSaturation();
460 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearing(
463 GLclampf restore_red,
464 GLclampf restore_green,
465 GLclampf restore_blue,
466 GLclampf restore_alpha,
467 GLuint restore_stencil,
468 GLclampf restore_depth,
469 bool restore_scissor_test) {
470 SetupExpectationsForFramebufferClearingMulti(
481 restore_scissor_test);
484 void GLES2DecoderTestBase::SetupExpectationsForRestoreClearState(
485 GLclampf restore_red,
486 GLclampf restore_green,
487 GLclampf restore_blue,
488 GLclampf restore_alpha,
489 GLuint restore_stencil,
490 GLclampf restore_depth,
491 bool restore_scissor_test) {
492 EXPECT_CALL(*gl_, ClearColor(
493 restore_red, restore_green, restore_blue, restore_alpha))
495 .RetiresOnSaturation();
496 EXPECT_CALL(*gl_, ClearStencil(restore_stencil))
498 .RetiresOnSaturation();
499 EXPECT_CALL(*gl_, ClearDepth(restore_depth))
501 .RetiresOnSaturation();
502 if (restore_scissor_test) {
503 EXPECT_CALL(*gl_, Enable(GL_SCISSOR_TEST))
505 .RetiresOnSaturation();
509 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearingMulti(
510 GLuint read_framebuffer_service_id,
511 GLuint draw_framebuffer_service_id,
514 GLclampf restore_red,
515 GLclampf restore_green,
516 GLclampf restore_blue,
517 GLclampf restore_alpha,
518 GLuint restore_stencil,
519 GLclampf restore_depth,
520 bool restore_scissor_test) {
521 // TODO(gman): Figure out why InSequence stopped working.
522 // InSequence sequence;
523 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(target))
524 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
525 .RetiresOnSaturation();
526 if (target == GL_READ_FRAMEBUFFER_EXT) {
527 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0))
529 .RetiresOnSaturation();
530 EXPECT_CALL(*gl_, BindFramebufferEXT(
531 GL_DRAW_FRAMEBUFFER_EXT, read_framebuffer_service_id))
533 .RetiresOnSaturation();
535 if ((clear_bits & GL_COLOR_BUFFER_BIT) != 0) {
536 EXPECT_CALL(*gl_, ClearColor(0.0f, 0.0f, 0.0f, 0.0f))
538 .RetiresOnSaturation();
539 EXPECT_CALL(*gl_, ColorMask(true, true, true, true))
541 .RetiresOnSaturation();
543 if ((clear_bits & GL_STENCIL_BUFFER_BIT) != 0) {
544 EXPECT_CALL(*gl_, ClearStencil(0))
546 .RetiresOnSaturation();
547 EXPECT_CALL(*gl_, StencilMask(static_cast<GLuint>(-1)))
549 .RetiresOnSaturation();
551 if ((clear_bits & GL_DEPTH_BUFFER_BIT) != 0) {
552 EXPECT_CALL(*gl_, ClearDepth(1.0f))
554 .RetiresOnSaturation();
555 EXPECT_CALL(*gl_, DepthMask(1))
557 .RetiresOnSaturation();
559 EXPECT_CALL(*gl_, Disable(GL_SCISSOR_TEST))
561 .RetiresOnSaturation();
562 EXPECT_CALL(*gl_, Clear(clear_bits))
564 .RetiresOnSaturation();
565 SetupExpectationsForRestoreClearState(
566 restore_red, restore_green, restore_blue, restore_alpha,
567 restore_stencil, restore_depth, restore_scissor_test);
568 if (target == GL_READ_FRAMEBUFFER_EXT) {
569 EXPECT_CALL(*gl_, BindFramebufferEXT(
570 GL_READ_FRAMEBUFFER_EXT, read_framebuffer_service_id))
572 .RetiresOnSaturation();
573 EXPECT_CALL(*gl_, BindFramebufferEXT(
574 GL_DRAW_FRAMEBUFFER_EXT, draw_framebuffer_service_id))
576 .RetiresOnSaturation();
580 void GLES2DecoderTestBase::SetupShaderForUniform(GLenum uniform_type) {
581 static AttribInfo attribs[] = {
582 { "foo", 1, GL_FLOAT, 1, },
583 { "goo", 1, GL_FLOAT, 2, },
585 UniformInfo uniforms[] = {
586 { "bar", 1, uniform_type, 0, 2, -1, },
587 { "car", 4, uniform_type, 1, 1, -1, },
589 const GLuint kClientVertexShaderId = 5001;
590 const GLuint kServiceVertexShaderId = 6001;
591 const GLuint kClientFragmentShaderId = 5002;
592 const GLuint kServiceFragmentShaderId = 6002;
593 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
594 client_program_id_, kServiceProgramId,
595 kClientVertexShaderId, kServiceVertexShaderId,
596 kClientFragmentShaderId, kServiceFragmentShaderId);
598 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
600 .RetiresOnSaturation();
601 cmds::UseProgram cmd;
602 cmd.Init(client_program_id_);
603 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
606 void GLES2DecoderTestBase::DoBindBuffer(
607 GLenum target, GLuint client_id, GLuint service_id) {
608 EXPECT_CALL(*gl_, BindBuffer(target, service_id))
610 .RetiresOnSaturation();
611 cmds::BindBuffer cmd;
612 cmd.Init(target, client_id);
613 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
616 bool GLES2DecoderTestBase::DoIsBuffer(GLuint client_id) {
617 return IsObjectHelper<cmds::IsBuffer, cmds::IsBuffer::Result>(client_id);
620 void GLES2DecoderTestBase::DoDeleteBuffer(
621 GLuint client_id, GLuint service_id) {
622 EXPECT_CALL(*gl_, DeleteBuffersARB(1, Pointee(service_id)))
624 .RetiresOnSaturation();
625 cmds::DeleteBuffers cmd;
626 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
627 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
628 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
631 void GLES2DecoderTestBase::SetupExpectationsForApplyingDirtyState(
632 bool framebuffer_is_rgb,
633 bool framebuffer_has_depth,
634 bool framebuffer_has_stencil,
638 GLuint front_stencil_mask,
639 GLuint back_stencil_mask,
640 bool stencil_enabled,
641 bool cull_face_enabled,
642 bool scissor_test_enabled,
643 bool blend_enabled) {
644 EXPECT_CALL(*gl_, ColorMask(
645 (color_bits & 0x1000) != 0,
646 (color_bits & 0x0100) != 0,
647 (color_bits & 0x0010) != 0,
648 (color_bits & 0x0001) && !framebuffer_is_rgb))
650 .RetiresOnSaturation();
651 EXPECT_CALL(*gl_, DepthMask(depth_mask))
653 .RetiresOnSaturation();
654 if (framebuffer_has_depth && depth_enabled) {
655 EXPECT_CALL(*gl_, Enable(GL_DEPTH_TEST))
657 .RetiresOnSaturation();
659 EXPECT_CALL(*gl_, Disable(GL_DEPTH_TEST))
661 .RetiresOnSaturation();
663 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_FRONT, front_stencil_mask))
665 .RetiresOnSaturation();
666 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_BACK, back_stencil_mask))
668 .RetiresOnSaturation();
669 if (framebuffer_has_stencil && stencil_enabled) {
670 EXPECT_CALL(*gl_, Enable(GL_STENCIL_TEST))
672 .RetiresOnSaturation();
674 EXPECT_CALL(*gl_, Disable(GL_STENCIL_TEST))
676 .RetiresOnSaturation();
678 if (cull_face_enabled) {
679 EXPECT_CALL(*gl_, Enable(GL_CULL_FACE))
681 .RetiresOnSaturation();
683 EXPECT_CALL(*gl_, Disable(GL_CULL_FACE))
685 .RetiresOnSaturation();
687 if (scissor_test_enabled) {
688 EXPECT_CALL(*gl_, Enable(GL_SCISSOR_TEST))
690 .RetiresOnSaturation();
692 EXPECT_CALL(*gl_, Disable(GL_SCISSOR_TEST))
694 .RetiresOnSaturation();
697 EXPECT_CALL(*gl_, Enable(GL_BLEND))
699 .RetiresOnSaturation();
701 EXPECT_CALL(*gl_, Disable(GL_BLEND))
703 .RetiresOnSaturation();
707 void GLES2DecoderTestBase::SetupExpectationsForApplyingDefaultDirtyState() {
708 SetupExpectationsForApplyingDirtyState(
709 false, // Framebuffer is RGB
710 false, // Framebuffer has depth
711 false, // Framebuffer has stencil
712 0x1111, // color bits
714 false, // depth enabled
715 0, // front stencil mask
716 0, // back stencil mask
717 false, // stencil enabled
718 false, // cull_face_enabled
719 false, // scissor_test_enabled
720 false); // blend_enabled
723 void GLES2DecoderTestBase::DoBindFramebuffer(
724 GLenum target, GLuint client_id, GLuint service_id) {
725 EXPECT_CALL(*gl_, BindFramebufferEXT(target, service_id))
727 .RetiresOnSaturation();
728 cmds::BindFramebuffer cmd;
729 cmd.Init(target, client_id);
730 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
733 bool GLES2DecoderTestBase::DoIsFramebuffer(GLuint client_id) {
734 return IsObjectHelper<cmds::IsFramebuffer, cmds::IsFramebuffer::Result>(
738 void GLES2DecoderTestBase::DoDeleteFramebuffer(
739 GLuint client_id, GLuint service_id,
740 bool reset_draw, GLenum draw_target, GLuint draw_id,
741 bool reset_read, GLenum read_target, GLuint read_id) {
743 EXPECT_CALL(*gl_, BindFramebufferEXT(draw_target, draw_id))
745 .RetiresOnSaturation();
748 EXPECT_CALL(*gl_, BindFramebufferEXT(read_target, read_id))
750 .RetiresOnSaturation();
752 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, Pointee(service_id)))
754 .RetiresOnSaturation();
755 cmds::DeleteFramebuffers cmd;
756 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
757 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
758 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
761 void GLES2DecoderTestBase::DoBindRenderbuffer(
762 GLenum target, GLuint client_id, GLuint service_id) {
763 EXPECT_CALL(*gl_, BindRenderbufferEXT(target, service_id))
765 .RetiresOnSaturation();
766 cmds::BindRenderbuffer cmd;
767 cmd.Init(target, client_id);
768 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
771 bool GLES2DecoderTestBase::DoIsRenderbuffer(GLuint client_id) {
772 return IsObjectHelper<cmds::IsRenderbuffer, cmds::IsRenderbuffer::Result>(
776 void GLES2DecoderTestBase::DoDeleteRenderbuffer(
777 GLuint client_id, GLuint service_id) {
778 EXPECT_CALL(*gl_, DeleteRenderbuffersEXT(1, Pointee(service_id)))
780 .RetiresOnSaturation();
781 cmds::DeleteRenderbuffers cmd;
782 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
783 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
784 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
787 void GLES2DecoderTestBase::DoBindTexture(
788 GLenum target, GLuint client_id, GLuint service_id) {
789 EXPECT_CALL(*gl_, BindTexture(target, service_id))
791 .RetiresOnSaturation();
792 cmds::BindTexture cmd;
793 cmd.Init(target, client_id);
794 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
797 bool GLES2DecoderTestBase::DoIsTexture(GLuint client_id) {
798 return IsObjectHelper<cmds::IsTexture, cmds::IsTexture::Result>(client_id);
801 void GLES2DecoderTestBase::DoDeleteTexture(
802 GLuint client_id, GLuint service_id) {
803 EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(service_id)))
805 .RetiresOnSaturation();
806 cmds::DeleteTextures cmd;
807 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
808 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
809 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
812 void GLES2DecoderTestBase::DoTexImage2D(
813 GLenum target, GLint level, GLenum internal_format,
814 GLsizei width, GLsizei height, GLint border,
815 GLenum format, GLenum type,
816 uint32 shared_memory_id, uint32 shared_memory_offset) {
817 EXPECT_CALL(*gl_, GetError())
818 .WillOnce(Return(GL_NO_ERROR))
819 .RetiresOnSaturation();
820 EXPECT_CALL(*gl_, TexImage2D(target, level, internal_format,
821 width, height, border, format, type, _))
823 .RetiresOnSaturation();
824 EXPECT_CALL(*gl_, GetError())
825 .WillOnce(Return(GL_NO_ERROR))
826 .RetiresOnSaturation();
827 cmds::TexImage2D cmd;
828 cmd.Init(target, level, internal_format, width, height, border, format,
829 type, shared_memory_id, shared_memory_offset);
830 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
833 void GLES2DecoderTestBase::DoTexImage2DConvertInternalFormat(
834 GLenum target, GLint level, GLenum requested_internal_format,
835 GLsizei width, GLsizei height, GLint border,
836 GLenum format, GLenum type,
837 uint32 shared_memory_id, uint32 shared_memory_offset,
838 GLenum expected_internal_format) {
839 EXPECT_CALL(*gl_, GetError())
840 .WillOnce(Return(GL_NO_ERROR))
841 .RetiresOnSaturation();
842 EXPECT_CALL(*gl_, TexImage2D(target, level, expected_internal_format,
843 width, height, border, format, type, _))
845 .RetiresOnSaturation();
846 EXPECT_CALL(*gl_, GetError())
847 .WillOnce(Return(GL_NO_ERROR))
848 .RetiresOnSaturation();
849 cmds::TexImage2D cmd;
850 cmd.Init(target, level, requested_internal_format, width, height, border,
851 format, type, shared_memory_id, shared_memory_offset);
852 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
855 void GLES2DecoderTestBase::DoCompressedTexImage2D(
856 GLenum target, GLint level, GLenum format,
857 GLsizei width, GLsizei height, GLint border,
858 GLsizei size, uint32 bucket_id) {
859 EXPECT_CALL(*gl_, GetError())
860 .WillOnce(Return(GL_NO_ERROR))
861 .RetiresOnSaturation();
862 EXPECT_CALL(*gl_, CompressedTexImage2D(
863 target, level, format, width, height, border, size, _))
865 .RetiresOnSaturation();
866 EXPECT_CALL(*gl_, GetError())
867 .WillOnce(Return(GL_NO_ERROR))
868 .RetiresOnSaturation();
869 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(bucket_id);
870 bucket->SetSize(size);
871 cmds::CompressedTexImage2DBucket cmd;
873 target, level, format, width, height, border,
875 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
878 void GLES2DecoderTestBase::DoRenderbufferStorage(
879 GLenum target, GLenum internal_format, GLenum actual_format,
880 GLsizei width, GLsizei height, GLenum error) {
881 EXPECT_CALL(*gl_, GetError())
882 .WillOnce(Return(GL_NO_ERROR))
883 .RetiresOnSaturation();
884 EXPECT_CALL(*gl_, RenderbufferStorageEXT(
885 target, actual_format, width, height))
887 .RetiresOnSaturation();
888 EXPECT_CALL(*gl_, GetError())
889 .WillOnce(Return(error))
890 .RetiresOnSaturation();
891 cmds::RenderbufferStorage cmd;
892 cmd.Init(target, internal_format, width, height);
893 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
896 void GLES2DecoderTestBase::DoFramebufferTexture2D(
897 GLenum target, GLenum attachment, GLenum textarget,
898 GLuint texture_client_id, GLuint texture_service_id, GLint level,
900 EXPECT_CALL(*gl_, GetError())
901 .WillOnce(Return(GL_NO_ERROR))
902 .RetiresOnSaturation();
903 EXPECT_CALL(*gl_, FramebufferTexture2DEXT(
904 target, attachment, textarget, texture_service_id, level))
906 .RetiresOnSaturation();
907 EXPECT_CALL(*gl_, GetError())
908 .WillOnce(Return(error))
909 .RetiresOnSaturation();
910 cmds::FramebufferTexture2D cmd;
911 cmd.Init(target, attachment, textarget, texture_client_id, level);
912 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
915 void GLES2DecoderTestBase::DoFramebufferRenderbuffer(
918 GLenum renderbuffer_target,
919 GLuint renderbuffer_client_id,
920 GLuint renderbuffer_service_id,
922 EXPECT_CALL(*gl_, GetError())
923 .WillOnce(Return(GL_NO_ERROR))
924 .RetiresOnSaturation();
925 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
926 target, attachment, renderbuffer_target, renderbuffer_service_id))
928 .RetiresOnSaturation();
929 EXPECT_CALL(*gl_, GetError())
930 .WillOnce(Return(error))
931 .RetiresOnSaturation();
932 cmds::FramebufferRenderbuffer cmd;
933 cmd.Init(target, attachment, renderbuffer_target, renderbuffer_client_id);
934 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
937 void GLES2DecoderTestBase::DoVertexAttribPointer(
938 GLuint index, GLint size, GLenum type, GLsizei stride, GLuint offset) {
940 VertexAttribPointer(index, size, type, GL_FALSE, stride,
941 BufferOffset(offset)))
943 .RetiresOnSaturation();
944 cmds::VertexAttribPointer cmd;
945 cmd.Init(index, size, GL_FLOAT, GL_FALSE, stride, offset);
946 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
949 void GLES2DecoderTestBase::DoVertexAttribDivisorANGLE(
950 GLuint index, GLuint divisor) {
952 VertexAttribDivisorANGLE(index, divisor))
954 .RetiresOnSaturation();
955 cmds::VertexAttribDivisorANGLE cmd;
956 cmd.Init(index, divisor);
957 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
960 void GLES2DecoderTestBase::AddExpectationsForGenVertexArraysOES(){
961 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
962 EXPECT_CALL(*gl_, GenVertexArraysOES(1, _))
963 .WillOnce(SetArgumentPointee<1>(kServiceVertexArrayId))
964 .RetiresOnSaturation();
968 void GLES2DecoderTestBase::AddExpectationsForDeleteVertexArraysOES(){
969 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
970 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, _))
972 .RetiresOnSaturation();
976 void GLES2DecoderTestBase::AddExpectationsForBindVertexArrayOES() {
977 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
978 EXPECT_CALL(*gl_, BindVertexArrayOES(_))
980 .RetiresOnSaturation();
982 for (uint32 vv = 0; vv < group_->max_vertex_attribs(); ++vv) {
983 AddExpectationsForRestoreAttribState(vv);
986 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _))
988 .RetiresOnSaturation();
992 void GLES2DecoderTestBase::AddExpectationsForRestoreAttribState(GLuint attrib) {
993 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
995 .RetiresOnSaturation();
997 EXPECT_CALL(*gl_, VertexAttribPointer(attrib, _, _, _, _, _))
999 .RetiresOnSaturation();
1001 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(attrib, _))
1002 .Times(testing::AtMost(1))
1003 .RetiresOnSaturation();
1005 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1007 .RetiresOnSaturation();
1010 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
1012 // TODO(bajones): Not sure if I can tell which of these will be called
1013 EXPECT_CALL(*gl_, EnableVertexAttribArray(attrib))
1014 .Times(testing::AtMost(1))
1015 .RetiresOnSaturation();
1017 EXPECT_CALL(*gl_, DisableVertexAttribArray(attrib))
1018 .Times(testing::AtMost(1))
1019 .RetiresOnSaturation();
1023 // GCC requires these declarations, but MSVC requires they not be present
1024 #ifndef COMPILER_MSVC
1025 const int GLES2DecoderTestBase::kBackBufferWidth;
1026 const int GLES2DecoderTestBase::kBackBufferHeight;
1028 const GLint GLES2DecoderTestBase::kMaxTextureSize;
1029 const GLint GLES2DecoderTestBase::kMaxCubeMapTextureSize;
1030 const GLint GLES2DecoderTestBase::kNumVertexAttribs;
1031 const GLint GLES2DecoderTestBase::kNumTextureUnits;
1032 const GLint GLES2DecoderTestBase::kMaxTextureImageUnits;
1033 const GLint GLES2DecoderTestBase::kMaxVertexTextureImageUnits;
1034 const GLint GLES2DecoderTestBase::kMaxFragmentUniformVectors;
1035 const GLint GLES2DecoderTestBase::kMaxVaryingVectors;
1036 const GLint GLES2DecoderTestBase::kMaxVertexUniformVectors;
1037 const GLint GLES2DecoderTestBase::kMaxViewportWidth;
1038 const GLint GLES2DecoderTestBase::kMaxViewportHeight;
1040 const GLint GLES2DecoderTestBase::kViewportX;
1041 const GLint GLES2DecoderTestBase::kViewportY;
1042 const GLint GLES2DecoderTestBase::kViewportWidth;
1043 const GLint GLES2DecoderTestBase::kViewportHeight;
1045 const GLuint GLES2DecoderTestBase::kServiceAttrib0BufferId;
1046 const GLuint GLES2DecoderTestBase::kServiceFixedAttribBufferId;
1048 const GLuint GLES2DecoderTestBase::kServiceBufferId;
1049 const GLuint GLES2DecoderTestBase::kServiceFramebufferId;
1050 const GLuint GLES2DecoderTestBase::kServiceRenderbufferId;
1051 const GLuint GLES2DecoderTestBase::kServiceTextureId;
1052 const GLuint GLES2DecoderTestBase::kServiceProgramId;
1053 const GLuint GLES2DecoderTestBase::kServiceShaderId;
1054 const GLuint GLES2DecoderTestBase::kServiceElementBufferId;
1055 const GLuint GLES2DecoderTestBase::kServiceQueryId;
1056 const GLuint GLES2DecoderTestBase::kServiceVertexArrayId;
1058 const int32 GLES2DecoderTestBase::kSharedMemoryId;
1059 const size_t GLES2DecoderTestBase::kSharedBufferSize;
1060 const uint32 GLES2DecoderTestBase::kSharedMemoryOffset;
1061 const int32 GLES2DecoderTestBase::kInvalidSharedMemoryId;
1062 const uint32 GLES2DecoderTestBase::kInvalidSharedMemoryOffset;
1063 const uint32 GLES2DecoderTestBase::kInitialResult;
1064 const uint8 GLES2DecoderTestBase::kInitialMemoryValue;
1066 const uint32 GLES2DecoderTestBase::kNewClientId;
1067 const uint32 GLES2DecoderTestBase::kNewServiceId;
1068 const uint32 GLES2DecoderTestBase::kInvalidClientId;
1070 const GLuint GLES2DecoderTestBase::kServiceVertexShaderId;
1071 const GLuint GLES2DecoderTestBase::kServiceFragmentShaderId;
1073 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumShaderId;
1074 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumProgramId;
1076 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTextureBufferId;
1077 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumVertexBufferId;
1078 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumFBOId;
1079 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumPositionAttrib;
1080 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTexAttrib;
1081 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumSamplerLocation;
1083 const GLsizei GLES2DecoderTestBase::kNumVertices;
1084 const GLsizei GLES2DecoderTestBase::kNumIndices;
1085 const int GLES2DecoderTestBase::kValidIndexRangeStart;
1086 const int GLES2DecoderTestBase::kValidIndexRangeCount;
1087 const int GLES2DecoderTestBase::kInvalidIndexRangeStart;
1088 const int GLES2DecoderTestBase::kInvalidIndexRangeCount;
1089 const int GLES2DecoderTestBase::kOutOfRangeIndexRangeEnd;
1090 const GLuint GLES2DecoderTestBase::kMaxValidIndex;
1092 const GLint GLES2DecoderTestBase::kMaxAttribLength;
1093 const GLint GLES2DecoderTestBase::kAttrib1Size;
1094 const GLint GLES2DecoderTestBase::kAttrib2Size;
1095 const GLint GLES2DecoderTestBase::kAttrib3Size;
1096 const GLint GLES2DecoderTestBase::kAttrib1Location;
1097 const GLint GLES2DecoderTestBase::kAttrib2Location;
1098 const GLint GLES2DecoderTestBase::kAttrib3Location;
1099 const GLenum GLES2DecoderTestBase::kAttrib1Type;
1100 const GLenum GLES2DecoderTestBase::kAttrib2Type;
1101 const GLenum GLES2DecoderTestBase::kAttrib3Type;
1102 const GLint GLES2DecoderTestBase::kInvalidAttribLocation;
1103 const GLint GLES2DecoderTestBase::kBadAttribIndex;
1105 const GLint GLES2DecoderTestBase::kMaxUniformLength;
1106 const GLint GLES2DecoderTestBase::kUniform1Size;
1107 const GLint GLES2DecoderTestBase::kUniform2Size;
1108 const GLint GLES2DecoderTestBase::kUniform3Size;
1109 const GLint GLES2DecoderTestBase::kUniform1RealLocation;
1110 const GLint GLES2DecoderTestBase::kUniform2RealLocation;
1111 const GLint GLES2DecoderTestBase::kUniform2ElementRealLocation;
1112 const GLint GLES2DecoderTestBase::kUniform3RealLocation;
1113 const GLint GLES2DecoderTestBase::kUniform1FakeLocation;
1114 const GLint GLES2DecoderTestBase::kUniform2FakeLocation;
1115 const GLint GLES2DecoderTestBase::kUniform2ElementFakeLocation;
1116 const GLint GLES2DecoderTestBase::kUniform3FakeLocation;
1117 const GLint GLES2DecoderTestBase::kUniform1DesiredLocation;
1118 const GLint GLES2DecoderTestBase::kUniform2DesiredLocation;
1119 const GLint GLES2DecoderTestBase::kUniform3DesiredLocation;
1120 const GLenum GLES2DecoderTestBase::kUniform1Type;
1121 const GLenum GLES2DecoderTestBase::kUniform2Type;
1122 const GLenum GLES2DecoderTestBase::kUniform3Type;
1123 const GLenum GLES2DecoderTestBase::kUniformCubemapType;
1124 const GLint GLES2DecoderTestBase::kInvalidUniformLocation;
1125 const GLint GLES2DecoderTestBase::kBadUniformIndex;
1129 const char* GLES2DecoderTestBase::kAttrib1Name = "attrib1";
1130 const char* GLES2DecoderTestBase::kAttrib2Name = "attrib2";
1131 const char* GLES2DecoderTestBase::kAttrib3Name = "attrib3";
1132 const char* GLES2DecoderTestBase::kUniform1Name = "uniform1";
1133 const char* GLES2DecoderTestBase::kUniform2Name = "uniform2[0]";
1134 const char* GLES2DecoderTestBase::kUniform3Name = "uniform3[0]";
1136 void GLES2DecoderTestBase::SetupDefaultProgram() {
1138 static AttribInfo attribs[] = {
1139 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1140 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1141 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1143 static UniformInfo uniforms[] = {
1144 { kUniform1Name, kUniform1Size, kUniform1Type,
1145 kUniform1FakeLocation, kUniform1RealLocation,
1146 kUniform1DesiredLocation },
1147 { kUniform2Name, kUniform2Size, kUniform2Type,
1148 kUniform2FakeLocation, kUniform2RealLocation,
1149 kUniform2DesiredLocation },
1150 { kUniform3Name, kUniform3Size, kUniform3Type,
1151 kUniform3FakeLocation, kUniform3RealLocation,
1152 kUniform3DesiredLocation },
1154 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1155 client_program_id_, kServiceProgramId,
1156 client_vertex_shader_id_, kServiceVertexShaderId,
1157 client_fragment_shader_id_, kServiceFragmentShaderId);
1161 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1163 .RetiresOnSaturation();
1164 cmds::UseProgram cmd;
1165 cmd.Init(client_program_id_);
1166 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1170 void GLES2DecoderTestBase::SetupCubemapProgram() {
1172 static AttribInfo attribs[] = {
1173 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1174 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1175 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1177 static UniformInfo uniforms[] = {
1178 { kUniform1Name, kUniform1Size, kUniformCubemapType,
1179 kUniform1FakeLocation, kUniform1RealLocation,
1180 kUniform1DesiredLocation, },
1181 { kUniform2Name, kUniform2Size, kUniform2Type,
1182 kUniform2FakeLocation, kUniform2RealLocation,
1183 kUniform2DesiredLocation, },
1184 { kUniform3Name, kUniform3Size, kUniform3Type,
1185 kUniform3FakeLocation, kUniform3RealLocation,
1186 kUniform3DesiredLocation, },
1188 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1189 client_program_id_, kServiceProgramId,
1190 client_vertex_shader_id_, kServiceVertexShaderId,
1191 client_fragment_shader_id_, kServiceFragmentShaderId);
1195 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1197 .RetiresOnSaturation();
1198 cmds::UseProgram cmd;
1199 cmd.Init(client_program_id_);
1200 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1204 void GLES2DecoderTestBase::SetupSamplerExternalProgram() {
1206 static AttribInfo attribs[] = {
1207 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1208 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1209 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1211 static UniformInfo uniforms[] = {
1212 { kUniform1Name, kUniform1Size, kUniformSamplerExternalType,
1213 kUniform1FakeLocation, kUniform1RealLocation,
1214 kUniform1DesiredLocation, },
1215 { kUniform2Name, kUniform2Size, kUniform2Type,
1216 kUniform2FakeLocation, kUniform2RealLocation,
1217 kUniform2DesiredLocation, },
1218 { kUniform3Name, kUniform3Size, kUniform3Type,
1219 kUniform3FakeLocation, kUniform3RealLocation,
1220 kUniform3DesiredLocation, },
1222 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1223 client_program_id_, kServiceProgramId,
1224 client_vertex_shader_id_, kServiceVertexShaderId,
1225 client_fragment_shader_id_, kServiceFragmentShaderId);
1229 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1231 .RetiresOnSaturation();
1232 cmds::UseProgram cmd;
1233 cmd.Init(client_program_id_);
1234 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1238 void GLES2DecoderWithShaderTestBase::TearDown() {
1239 GLES2DecoderTestBase::TearDown();
1242 void GLES2DecoderTestBase::SetupShader(
1243 GLES2DecoderTestBase::AttribInfo* attribs, size_t num_attribs,
1244 GLES2DecoderTestBase::UniformInfo* uniforms, size_t num_uniforms,
1245 GLuint program_client_id, GLuint program_service_id,
1246 GLuint vertex_shader_client_id, GLuint vertex_shader_service_id,
1247 GLuint fragment_shader_client_id, GLuint fragment_shader_service_id) {
1252 AttachShader(program_service_id, vertex_shader_service_id))
1254 .RetiresOnSaturation();
1256 AttachShader(program_service_id, fragment_shader_service_id))
1258 .RetiresOnSaturation();
1259 TestHelper::SetupShader(
1260 gl_.get(), attribs, num_attribs, uniforms, num_uniforms,
1261 program_service_id);
1265 GL_VERTEX_SHADER, vertex_shader_client_id, vertex_shader_service_id);
1267 GL_FRAGMENT_SHADER, fragment_shader_client_id,
1268 fragment_shader_service_id);
1270 GetShader(vertex_shader_client_id)->SetStatus(true, "", NULL);
1271 GetShader(fragment_shader_client_id)->SetStatus(true, "", NULL);
1273 cmds::AttachShader attach_cmd;
1274 attach_cmd.Init(program_client_id, vertex_shader_client_id);
1275 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1277 attach_cmd.Init(program_client_id, fragment_shader_client_id);
1278 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1280 cmds::LinkProgram link_cmd;
1281 link_cmd.Init(program_client_id);
1283 EXPECT_EQ(error::kNoError, ExecuteCmd(link_cmd));
1286 void GLES2DecoderTestBase::DoEnableVertexAttribArray(GLint index) {
1287 EXPECT_CALL(*gl_, EnableVertexAttribArray(index))
1289 .RetiresOnSaturation();
1290 cmds::EnableVertexAttribArray cmd;
1292 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1295 void GLES2DecoderTestBase::DoBufferData(GLenum target, GLsizei size) {
1296 EXPECT_CALL(*gl_, GetError())
1297 .WillOnce(Return(GL_NO_ERROR))
1298 .RetiresOnSaturation();
1299 EXPECT_CALL(*gl_, BufferData(target, size, _, GL_STREAM_DRAW))
1301 .RetiresOnSaturation();
1302 EXPECT_CALL(*gl_, GetError())
1303 .WillOnce(Return(GL_NO_ERROR))
1304 .RetiresOnSaturation();
1305 cmds::BufferData cmd;
1306 cmd.Init(target, size, 0, 0, GL_STREAM_DRAW);
1307 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1310 void GLES2DecoderTestBase::DoBufferSubData(
1311 GLenum target, GLint offset, GLsizei size, const void* data) {
1312 EXPECT_CALL(*gl_, BufferSubData(target, offset, size,
1313 shared_memory_address_))
1315 .RetiresOnSaturation();
1316 memcpy(shared_memory_address_, data, size);
1317 cmds::BufferSubData cmd;
1318 cmd.Init(target, offset, size, shared_memory_id_, shared_memory_offset_);
1319 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1322 void GLES2DecoderTestBase::SetupVertexBuffer() {
1323 DoEnableVertexAttribArray(1);
1324 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1326 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 2 * sizeof(f));
1329 void GLES2DecoderTestBase::SetupAllNeededVertexBuffers() {
1330 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1331 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 16 * sizeof(float));
1332 DoEnableVertexAttribArray(0);
1333 DoEnableVertexAttribArray(1);
1334 DoEnableVertexAttribArray(2);
1335 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1336 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1337 DoVertexAttribPointer(2, 2, GL_FLOAT, 0, 0);
1340 void GLES2DecoderTestBase::SetupIndexBuffer() {
1341 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
1342 client_element_buffer_id_,
1343 kServiceElementBufferId);
1344 static const GLshort indices[] = {100, 1, 2, 3, 4, 5, 6, 7, 100, 9};
1345 COMPILE_ASSERT(arraysize(indices) == kNumIndices, Indices_is_not_10);
1346 DoBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices));
1347 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, 2, indices);
1348 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 2, sizeof(indices) - 2, &indices[1]);
1351 void GLES2DecoderTestBase::SetupTexture() {
1352 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1353 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1354 kSharedMemoryId, kSharedMemoryOffset);
1357 void GLES2DecoderTestBase::DeleteVertexBuffer() {
1358 DoDeleteBuffer(client_buffer_id_, kServiceBufferId);
1361 void GLES2DecoderTestBase::DeleteIndexBuffer() {
1362 DoDeleteBuffer(client_element_buffer_id_, kServiceElementBufferId);
1365 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0WithError(
1366 GLsizei num_vertices, GLuint buffer_id, GLenum error) {
1367 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
1371 EXPECT_CALL(*gl_, GetError())
1372 .WillOnce(Return(GL_NO_ERROR))
1373 .WillOnce(Return(error))
1374 .RetiresOnSaturation();
1375 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
1377 .RetiresOnSaturation();
1378 EXPECT_CALL(*gl_, BufferData(GL_ARRAY_BUFFER,
1379 num_vertices * sizeof(GLfloat) * 4,
1380 _, GL_DYNAMIC_DRAW))
1382 .RetiresOnSaturation();
1383 if (error == GL_NO_ERROR) {
1384 EXPECT_CALL(*gl_, BufferSubData(
1385 GL_ARRAY_BUFFER, 0, num_vertices * sizeof(GLfloat) * 4, _))
1387 .RetiresOnSaturation();
1388 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL))
1390 .RetiresOnSaturation();
1391 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
1393 .RetiresOnSaturation();
1394 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL))
1396 .RetiresOnSaturation();
1397 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, buffer_id))
1399 .RetiresOnSaturation();
1403 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0(
1404 GLsizei num_vertices, GLuint buffer_id) {
1405 AddExpectationsForSimulatedAttrib0WithError(
1406 num_vertices, buffer_id, GL_NO_ERROR);
1409 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1410 MockCommandBufferEngine() {
1412 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory());
1413 shm->CreateAndMapAnonymous(kSharedBufferSize);
1414 valid_buffer_ = new gpu::Buffer(shm.Pass(), kSharedBufferSize);
1416 ClearSharedMemory();
1419 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1420 ~MockCommandBufferEngine() {}
1422 scoped_refptr<gpu::Buffer>
1423 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetSharedMemoryBuffer(
1425 return shm_id == kSharedMemoryId ? valid_buffer_ : invalid_buffer_;
1428 void GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::set_token(
1433 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetBuffer(
1434 int32 /* transfer_buffer_id */) {
1439 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetOffset(
1445 int32 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetGetOffset() {
1450 void GLES2DecoderWithShaderTestBase::SetUp() {
1451 GLES2DecoderTestBase::SetUp();
1452 SetupDefaultProgram();
1455 // Include the auto-generated part of this file. We split this because it means
1456 // we can easily edit the non-auto generated parts right here in this file
1457 // instead of having to edit some template or the code generator.
1458 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h"
1460 } // namespace gles2