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/gles2_cmd_decoder_mock.h"
18 #include "gpu/command_buffer/service/logger.h"
19 #include "gpu/command_buffer/service/program_manager.h"
20 #include "gpu/command_buffer/service/test_helper.h"
21 #include "gpu/command_buffer/service/vertex_attrib_manager.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "ui/gl/gl_implementation.h"
24 #include "ui/gl/gl_mock.h"
25 #include "ui/gl/gl_surface.h"
27 using ::gfx::MockGLInterface;
29 using ::testing::DoAll;
30 using ::testing::InSequence;
31 using ::testing::MatcherCast;
32 using ::testing::Pointee;
33 using ::testing::Return;
34 using ::testing::SetArrayArgument;
35 using ::testing::SetArgPointee;
36 using ::testing::SetArgumentPointee;
37 using ::testing::StrEq;
38 using ::testing::StrictMock;
43 GLES2DecoderTestBase::GLES2DecoderTestBase()
46 memory_tracker_(NULL),
47 client_buffer_id_(100),
48 client_framebuffer_id_(101),
49 client_program_id_(102),
50 client_renderbuffer_id_(103),
51 client_shader_id_(104),
52 client_texture_id_(106),
53 client_element_buffer_id_(107),
54 client_vertex_shader_id_(121),
55 client_fragment_shader_id_(122),
56 client_query_id_(123),
57 client_vertexarray_id_(124) {
58 memset(immediate_buffer_, 0xEE, sizeof(immediate_buffer_));
61 GLES2DecoderTestBase::~GLES2DecoderTestBase() {}
63 void GLES2DecoderTestBase::SetUp() {
70 true, // request alpha
71 true, // request depth
72 false, // request stencil
73 true); // bind generates resource
76 void GLES2DecoderTestBase::AddExpectationsForVertexAttribManager() {
77 for (GLint ii = 0; ii < kNumVertexAttribs; ++ii) {
78 EXPECT_CALL(*gl_, VertexAttrib4f(ii, 0.0f, 0.0f, 0.0f, 1.0f))
80 .RetiresOnSaturation();
84 void GLES2DecoderTestBase::InitDecoder(
85 const char* extensions,
86 const char* gl_version,
93 bool bind_generates_resource) {
94 InitDecoderWithCommandLine(extensions,
102 bind_generates_resource,
106 void GLES2DecoderTestBase::InitDecoderWithCommandLine(
107 const char* extensions,
108 const char* gl_version,
114 bool request_stencil,
115 bool bind_generates_resource,
116 const base::CommandLine* command_line) {
117 Framebuffer::ClearFramebufferCompleteComboMap();
119 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress);
120 gfx::GLSurface::InitializeOneOffWithMockBindingsForTests();
122 gl_.reset(new StrictMock<MockGLInterface>());
123 ::gfx::MockGLInterface::SetGLInterface(gl_.get());
125 // Only create stream texture manager if extension is requested.
126 std::vector<std::string> list;
127 base::SplitString(std::string(extensions), ' ', &list);
128 scoped_refptr<FeatureInfo> feature_info;
130 feature_info = new FeatureInfo(*command_line);
131 group_ = scoped_refptr<ContextGroup>(new ContextGroup(
136 bind_generates_resource));
140 surface_ = new gfx::GLSurfaceStub;
141 surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight));
143 // Context needs to be created before initializing ContextGroup, which will
144 // in turn initialize FeatureInfo, which needs a context to determine
145 // extension support.
146 context_ = new gfx::GLContextStubWithExtensions;
147 context_->AddExtensionsString(extensions);
148 context_->SetGLVersionString(gl_version);
150 context_->MakeCurrent(surface_.get());
151 gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_);
153 TestHelper::SetupContextGroupInitExpectations(gl_.get(),
154 DisallowedFeatures(), extensions, gl_version);
156 // We initialize the ContextGroup with a MockGLES2Decoder so that
157 // we can use the ContextGroup to figure out how the real GLES2Decoder
158 // will initialize itself.
159 mock_decoder_.reset(new MockGLES2Decoder());
161 group_->Initialize(mock_decoder_.get(), DisallowedFeatures()));
163 if (group_->feature_info()->workarounds().init_vertex_attributes)
164 AddExpectationsForVertexAttribManager();
166 AddExpectationsForBindVertexArrayOES();
168 EXPECT_CALL(*gl_, EnableVertexAttribArray(0))
170 .RetiresOnSaturation();
171 static GLuint attrib_0_id[] = {
172 kServiceAttrib0BufferId,
174 static GLuint fixed_attrib_buffer_id[] = {
175 kServiceFixedAttribBufferId,
177 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(attrib_0_id), _))
178 .WillOnce(SetArrayArgument<1>(attrib_0_id,
179 attrib_0_id + arraysize(attrib_0_id)))
180 .RetiresOnSaturation();
181 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
183 .RetiresOnSaturation();
184 EXPECT_CALL(*gl_, VertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL))
186 .RetiresOnSaturation();
187 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
189 .RetiresOnSaturation();
190 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(fixed_attrib_buffer_id), _))
191 .WillOnce(SetArrayArgument<1>(
192 fixed_attrib_buffer_id,
193 fixed_attrib_buffer_id + arraysize(fixed_attrib_buffer_id)))
194 .RetiresOnSaturation();
196 for (GLint tt = 0; tt < TestHelper::kNumTextureUnits; ++tt) {
197 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0 + tt))
199 .RetiresOnSaturation();
200 if (group_->feature_info()->feature_flags().oes_egl_image_external) {
201 EXPECT_CALL(*gl_, BindTexture(
202 GL_TEXTURE_EXTERNAL_OES,
203 TestHelper::kServiceDefaultExternalTextureId))
205 .RetiresOnSaturation();
207 if (group_->feature_info()->feature_flags().arb_texture_rectangle) {
208 EXPECT_CALL(*gl_, BindTexture(
209 GL_TEXTURE_RECTANGLE_ARB,
210 TestHelper::kServiceDefaultRectangleTextureId))
212 .RetiresOnSaturation();
214 EXPECT_CALL(*gl_, BindTexture(
215 GL_TEXTURE_CUBE_MAP, TestHelper::kServiceDefaultTextureCubemapId))
217 .RetiresOnSaturation();
218 EXPECT_CALL(*gl_, BindTexture(
219 GL_TEXTURE_2D, TestHelper::kServiceDefaultTexture2dId))
221 .RetiresOnSaturation();
223 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
225 .RetiresOnSaturation();
227 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
229 .RetiresOnSaturation();
230 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _))
231 .WillOnce(SetArgumentPointee<1>(has_alpha ? 8 : 0))
232 .RetiresOnSaturation();
233 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
234 .WillOnce(SetArgumentPointee<1>(has_depth ? 24 : 0))
235 .RetiresOnSaturation();
236 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
237 .WillOnce(SetArgumentPointee<1>(has_stencil ? 8 : 0))
238 .RetiresOnSaturation();
240 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE))
242 .RetiresOnSaturation();
244 EXPECT_CALL(*gl_, Enable(GL_POINT_SPRITE))
246 .RetiresOnSaturation();
248 static GLint max_viewport_dims[] = {
252 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VIEWPORT_DIMS, _))
253 .WillOnce(SetArrayArgument<1>(
254 max_viewport_dims, max_viewport_dims + arraysize(max_viewport_dims)))
255 .RetiresOnSaturation();
257 SetupInitCapabilitiesExpectations();
258 SetupInitStateExpectations();
260 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
262 .RetiresOnSaturation();
264 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
266 .RetiresOnSaturation();
267 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0))
269 .RetiresOnSaturation();
270 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
272 .RetiresOnSaturation();
273 EXPECT_CALL(*gl_, BindRenderbufferEXT(GL_RENDERBUFFER, 0))
275 .RetiresOnSaturation();
277 // TODO(boliu): Remove OS_ANDROID once crbug.com/259023 is fixed and the
278 // workaround has been reverted.
279 #if !defined(OS_ANDROID)
280 EXPECT_CALL(*gl_, Clear(
281 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
283 .RetiresOnSaturation();
286 engine_.reset(new StrictMock<MockCommandBufferEngine>());
287 scoped_refptr<gpu::Buffer> buffer =
288 engine_->GetSharedMemoryBuffer(kSharedMemoryId);
289 shared_memory_offset_ = kSharedMemoryOffset;
290 shared_memory_address_ =
291 reinterpret_cast<int8*>(buffer->memory()) + shared_memory_offset_;
292 shared_memory_id_ = kSharedMemoryId;
293 shared_memory_base_ = buffer->memory();
295 int32 attributes[] = {
296 EGL_ALPHA_SIZE, request_alpha ? 8 : 0,
297 EGL_DEPTH_SIZE, request_depth ? 24 : 0,
298 EGL_STENCIL_SIZE, request_stencil ? 8 : 0,
300 std::vector<int32> attribs(attributes, attributes + arraysize(attributes));
302 decoder_.reset(GLES2Decoder::Create(group_.get()));
303 decoder_->GetLogger()->set_log_synthesized_gl_errors(false);
304 decoder_->Initialize(surface_,
308 DisallowedFeatures(),
310 decoder_->MakeCurrent();
311 decoder_->set_engine(engine_.get());
312 decoder_->BeginDecoding();
314 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
315 .WillOnce(SetArgumentPointee<1>(kServiceBufferId))
316 .RetiresOnSaturation();
317 GenHelper<cmds::GenBuffersImmediate>(client_buffer_id_);
318 EXPECT_CALL(*gl_, GenFramebuffersEXT(_, _))
319 .WillOnce(SetArgumentPointee<1>(kServiceFramebufferId))
320 .RetiresOnSaturation();
321 GenHelper<cmds::GenFramebuffersImmediate>(client_framebuffer_id_);
322 EXPECT_CALL(*gl_, GenRenderbuffersEXT(_, _))
323 .WillOnce(SetArgumentPointee<1>(kServiceRenderbufferId))
324 .RetiresOnSaturation();
325 GenHelper<cmds::GenRenderbuffersImmediate>(client_renderbuffer_id_);
326 EXPECT_CALL(*gl_, GenTextures(_, _))
327 .WillOnce(SetArgumentPointee<1>(kServiceTextureId))
328 .RetiresOnSaturation();
329 GenHelper<cmds::GenTexturesImmediate>(client_texture_id_);
330 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
331 .WillOnce(SetArgumentPointee<1>(kServiceElementBufferId))
332 .RetiresOnSaturation();
333 GenHelper<cmds::GenBuffersImmediate>(client_element_buffer_id_);
335 DoCreateProgram(client_program_id_, kServiceProgramId);
336 DoCreateShader(GL_VERTEX_SHADER, client_shader_id_, kServiceShaderId);
338 EXPECT_EQ(GL_NO_ERROR, GetGLError());
341 void GLES2DecoderTestBase::ResetDecoder() {
344 // All Tests should have read all their GLErrors before getting here.
345 EXPECT_EQ(GL_NO_ERROR, GetGLError());
347 EXPECT_CALL(*gl_, DeleteBuffersARB(1, _))
349 .RetiresOnSaturation();
351 decoder_->EndDecoding();
352 decoder_->Destroy(true);
354 group_->Destroy(mock_decoder_.get(), false);
356 ::gfx::MockGLInterface::SetGLInterface(NULL);
360 void GLES2DecoderTestBase::TearDown() {
364 void GLES2DecoderTestBase::ExpectEnableDisable(GLenum cap, bool enable) {
366 EXPECT_CALL(*gl_, Enable(cap))
368 .RetiresOnSaturation();
370 EXPECT_CALL(*gl_, Disable(cap))
372 .RetiresOnSaturation();
377 GLint GLES2DecoderTestBase::GetGLError() {
378 EXPECT_CALL(*gl_, GetError())
379 .WillOnce(Return(GL_NO_ERROR))
380 .RetiresOnSaturation();
382 cmd.Init(shared_memory_id_, shared_memory_offset_);
383 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
384 return static_cast<GLint>(*GetSharedMemoryAs<GLenum*>());
387 void GLES2DecoderTestBase::DoCreateShader(
388 GLenum shader_type, GLuint client_id, GLuint service_id) {
389 EXPECT_CALL(*gl_, CreateShader(shader_type))
391 .WillOnce(Return(service_id))
392 .RetiresOnSaturation();
393 cmds::CreateShader cmd;
394 cmd.Init(shader_type, client_id);
395 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
398 bool GLES2DecoderTestBase::DoIsShader(GLuint client_id) {
399 return IsObjectHelper<cmds::IsShader, cmds::IsShader::Result>(client_id);
402 void GLES2DecoderTestBase::DoDeleteShader(
403 GLuint client_id, GLuint service_id) {
404 EXPECT_CALL(*gl_, DeleteShader(service_id))
406 .RetiresOnSaturation();
407 cmds::DeleteShader cmd;
409 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
412 void GLES2DecoderTestBase::DoCreateProgram(
413 GLuint client_id, GLuint service_id) {
414 EXPECT_CALL(*gl_, CreateProgram())
416 .WillOnce(Return(service_id))
417 .RetiresOnSaturation();
418 cmds::CreateProgram cmd;
420 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
423 bool GLES2DecoderTestBase::DoIsProgram(GLuint client_id) {
424 return IsObjectHelper<cmds::IsProgram, cmds::IsProgram::Result>(client_id);
427 void GLES2DecoderTestBase::DoDeleteProgram(
428 GLuint client_id, GLuint /* service_id */) {
429 cmds::DeleteProgram cmd;
431 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
434 void GLES2DecoderTestBase::SetBucketAsCString(
435 uint32 bucket_id, const char* str) {
436 uint32 size = str ? (strlen(str) + 1) : 0;
437 cmd::SetBucketSize cmd1;
438 cmd1.Init(bucket_id, size);
439 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
441 memcpy(shared_memory_address_, str, size);
442 cmd::SetBucketData cmd2;
443 cmd2.Init(bucket_id, 0, size, kSharedMemoryId, kSharedMemoryOffset);
444 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
449 void GLES2DecoderTestBase::SetupClearTextureExpectations(
451 GLuint old_service_id,
455 GLenum internal_format,
460 EXPECT_CALL(*gl_, BindTexture(bind_target, service_id))
462 .RetiresOnSaturation();
463 EXPECT_CALL(*gl_, TexImage2D(
464 target, level, internal_format, width, height, 0, format, type, _))
466 .RetiresOnSaturation();
467 EXPECT_CALL(*gl_, BindTexture(bind_target, old_service_id))
469 .RetiresOnSaturation();
472 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearing(
475 GLclampf restore_red,
476 GLclampf restore_green,
477 GLclampf restore_blue,
478 GLclampf restore_alpha,
479 GLuint restore_stencil,
480 GLclampf restore_depth,
481 bool restore_scissor_test) {
482 SetupExpectationsForFramebufferClearingMulti(
493 restore_scissor_test);
496 void GLES2DecoderTestBase::SetupExpectationsForRestoreClearState(
497 GLclampf restore_red,
498 GLclampf restore_green,
499 GLclampf restore_blue,
500 GLclampf restore_alpha,
501 GLuint restore_stencil,
502 GLclampf restore_depth,
503 bool restore_scissor_test) {
504 EXPECT_CALL(*gl_, ClearColor(
505 restore_red, restore_green, restore_blue, restore_alpha))
507 .RetiresOnSaturation();
508 EXPECT_CALL(*gl_, ClearStencil(restore_stencil))
510 .RetiresOnSaturation();
511 EXPECT_CALL(*gl_, ClearDepth(restore_depth))
513 .RetiresOnSaturation();
514 if (restore_scissor_test) {
515 EXPECT_CALL(*gl_, Enable(GL_SCISSOR_TEST))
517 .RetiresOnSaturation();
521 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearingMulti(
522 GLuint read_framebuffer_service_id,
523 GLuint draw_framebuffer_service_id,
526 GLclampf restore_red,
527 GLclampf restore_green,
528 GLclampf restore_blue,
529 GLclampf restore_alpha,
530 GLuint restore_stencil,
531 GLclampf restore_depth,
532 bool restore_scissor_test) {
533 // TODO(gman): Figure out why InSequence stopped working.
534 // InSequence sequence;
535 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(target))
536 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
537 .RetiresOnSaturation();
538 if (target == GL_READ_FRAMEBUFFER_EXT) {
539 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0))
541 .RetiresOnSaturation();
542 EXPECT_CALL(*gl_, BindFramebufferEXT(
543 GL_DRAW_FRAMEBUFFER_EXT, read_framebuffer_service_id))
545 .RetiresOnSaturation();
547 if ((clear_bits & GL_COLOR_BUFFER_BIT) != 0) {
548 EXPECT_CALL(*gl_, ClearColor(0.0f, 0.0f, 0.0f, 0.0f))
550 .RetiresOnSaturation();
551 EXPECT_CALL(*gl_, ColorMask(true, true, true, true))
553 .RetiresOnSaturation();
555 if ((clear_bits & GL_STENCIL_BUFFER_BIT) != 0) {
556 EXPECT_CALL(*gl_, ClearStencil(0))
558 .RetiresOnSaturation();
559 EXPECT_CALL(*gl_, StencilMask(static_cast<GLuint>(-1)))
561 .RetiresOnSaturation();
563 if ((clear_bits & GL_DEPTH_BUFFER_BIT) != 0) {
564 EXPECT_CALL(*gl_, ClearDepth(1.0f))
566 .RetiresOnSaturation();
567 EXPECT_CALL(*gl_, DepthMask(1))
569 .RetiresOnSaturation();
571 EXPECT_CALL(*gl_, Disable(GL_SCISSOR_TEST))
573 .RetiresOnSaturation();
574 EXPECT_CALL(*gl_, Clear(clear_bits))
576 .RetiresOnSaturation();
577 SetupExpectationsForRestoreClearState(
578 restore_red, restore_green, restore_blue, restore_alpha,
579 restore_stencil, restore_depth, restore_scissor_test);
580 if (target == GL_READ_FRAMEBUFFER_EXT) {
581 EXPECT_CALL(*gl_, BindFramebufferEXT(
582 GL_READ_FRAMEBUFFER_EXT, read_framebuffer_service_id))
584 .RetiresOnSaturation();
585 EXPECT_CALL(*gl_, BindFramebufferEXT(
586 GL_DRAW_FRAMEBUFFER_EXT, draw_framebuffer_service_id))
588 .RetiresOnSaturation();
592 void GLES2DecoderTestBase::SetupShaderForUniform(GLenum uniform_type) {
593 static AttribInfo attribs[] = {
594 { "foo", 1, GL_FLOAT, 1, },
595 { "goo", 1, GL_FLOAT, 2, },
597 UniformInfo uniforms[] = {
598 { "bar", 1, uniform_type, 0, 2, -1, },
599 { "car", 4, uniform_type, 1, 1, -1, },
601 const GLuint kClientVertexShaderId = 5001;
602 const GLuint kServiceVertexShaderId = 6001;
603 const GLuint kClientFragmentShaderId = 5002;
604 const GLuint kServiceFragmentShaderId = 6002;
605 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
606 client_program_id_, kServiceProgramId,
607 kClientVertexShaderId, kServiceVertexShaderId,
608 kClientFragmentShaderId, kServiceFragmentShaderId);
610 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
612 .RetiresOnSaturation();
613 cmds::UseProgram cmd;
614 cmd.Init(client_program_id_);
615 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
618 void GLES2DecoderTestBase::DoBindBuffer(
619 GLenum target, GLuint client_id, GLuint service_id) {
620 EXPECT_CALL(*gl_, BindBuffer(target, service_id))
622 .RetiresOnSaturation();
623 cmds::BindBuffer cmd;
624 cmd.Init(target, client_id);
625 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
628 bool GLES2DecoderTestBase::DoIsBuffer(GLuint client_id) {
629 return IsObjectHelper<cmds::IsBuffer, cmds::IsBuffer::Result>(client_id);
632 void GLES2DecoderTestBase::DoDeleteBuffer(
633 GLuint client_id, GLuint service_id) {
634 EXPECT_CALL(*gl_, DeleteBuffersARB(1, Pointee(service_id)))
636 .RetiresOnSaturation();
637 cmds::DeleteBuffers cmd;
638 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
639 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
640 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
643 void GLES2DecoderTestBase::SetupExpectationsForApplyingDirtyState(
644 bool framebuffer_is_rgb,
645 bool framebuffer_has_depth,
646 bool framebuffer_has_stencil,
650 GLuint front_stencil_mask,
651 GLuint back_stencil_mask,
652 bool stencil_enabled,
653 bool cull_face_enabled,
654 bool scissor_test_enabled,
655 bool blend_enabled) {
656 EXPECT_CALL(*gl_, ColorMask(
657 (color_bits & 0x1000) != 0,
658 (color_bits & 0x0100) != 0,
659 (color_bits & 0x0010) != 0,
660 (color_bits & 0x0001) && !framebuffer_is_rgb))
662 .RetiresOnSaturation();
663 EXPECT_CALL(*gl_, DepthMask(depth_mask))
665 .RetiresOnSaturation();
666 if (framebuffer_has_depth && depth_enabled) {
667 EXPECT_CALL(*gl_, Enable(GL_DEPTH_TEST))
669 .RetiresOnSaturation();
671 EXPECT_CALL(*gl_, Disable(GL_DEPTH_TEST))
673 .RetiresOnSaturation();
675 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_FRONT, front_stencil_mask))
677 .RetiresOnSaturation();
678 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_BACK, back_stencil_mask))
680 .RetiresOnSaturation();
681 if (framebuffer_has_stencil && stencil_enabled) {
682 EXPECT_CALL(*gl_, Enable(GL_STENCIL_TEST))
684 .RetiresOnSaturation();
686 EXPECT_CALL(*gl_, Disable(GL_STENCIL_TEST))
688 .RetiresOnSaturation();
690 if (cull_face_enabled) {
691 EXPECT_CALL(*gl_, Enable(GL_CULL_FACE))
693 .RetiresOnSaturation();
695 EXPECT_CALL(*gl_, Disable(GL_CULL_FACE))
697 .RetiresOnSaturation();
699 if (scissor_test_enabled) {
700 EXPECT_CALL(*gl_, Enable(GL_SCISSOR_TEST))
702 .RetiresOnSaturation();
704 EXPECT_CALL(*gl_, Disable(GL_SCISSOR_TEST))
706 .RetiresOnSaturation();
709 EXPECT_CALL(*gl_, Enable(GL_BLEND))
711 .RetiresOnSaturation();
713 EXPECT_CALL(*gl_, Disable(GL_BLEND))
715 .RetiresOnSaturation();
719 void GLES2DecoderTestBase::SetupExpectationsForApplyingDefaultDirtyState() {
720 SetupExpectationsForApplyingDirtyState(
721 false, // Framebuffer is RGB
722 false, // Framebuffer has depth
723 false, // Framebuffer has stencil
724 0x1111, // color bits
726 false, // depth enabled
727 0, // front stencil mask
728 0, // back stencil mask
729 false, // stencil enabled
730 false, // cull_face_enabled
731 false, // scissor_test_enabled
732 false); // blend_enabled
735 void GLES2DecoderTestBase::DoBindFramebuffer(
736 GLenum target, GLuint client_id, GLuint service_id) {
737 EXPECT_CALL(*gl_, BindFramebufferEXT(target, service_id))
739 .RetiresOnSaturation();
740 cmds::BindFramebuffer cmd;
741 cmd.Init(target, client_id);
742 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
745 bool GLES2DecoderTestBase::DoIsFramebuffer(GLuint client_id) {
746 return IsObjectHelper<cmds::IsFramebuffer, cmds::IsFramebuffer::Result>(
750 void GLES2DecoderTestBase::DoDeleteFramebuffer(
751 GLuint client_id, GLuint service_id,
752 bool reset_draw, GLenum draw_target, GLuint draw_id,
753 bool reset_read, GLenum read_target, GLuint read_id) {
755 EXPECT_CALL(*gl_, BindFramebufferEXT(draw_target, draw_id))
757 .RetiresOnSaturation();
760 EXPECT_CALL(*gl_, BindFramebufferEXT(read_target, read_id))
762 .RetiresOnSaturation();
764 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, Pointee(service_id)))
766 .RetiresOnSaturation();
767 cmds::DeleteFramebuffers cmd;
768 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
769 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
770 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
773 void GLES2DecoderTestBase::DoBindRenderbuffer(
774 GLenum target, GLuint client_id, GLuint service_id) {
775 EXPECT_CALL(*gl_, BindRenderbufferEXT(target, service_id))
777 .RetiresOnSaturation();
778 cmds::BindRenderbuffer cmd;
779 cmd.Init(target, client_id);
780 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
783 bool GLES2DecoderTestBase::DoIsRenderbuffer(GLuint client_id) {
784 return IsObjectHelper<cmds::IsRenderbuffer, cmds::IsRenderbuffer::Result>(
788 void GLES2DecoderTestBase::DoDeleteRenderbuffer(
789 GLuint client_id, GLuint service_id) {
790 EXPECT_CALL(*gl_, DeleteRenderbuffersEXT(1, Pointee(service_id)))
792 .RetiresOnSaturation();
793 cmds::DeleteRenderbuffers cmd;
794 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
795 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
796 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
799 void GLES2DecoderTestBase::DoBindTexture(
800 GLenum target, GLuint client_id, GLuint service_id) {
801 EXPECT_CALL(*gl_, BindTexture(target, service_id))
803 .RetiresOnSaturation();
804 cmds::BindTexture cmd;
805 cmd.Init(target, client_id);
806 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
809 bool GLES2DecoderTestBase::DoIsTexture(GLuint client_id) {
810 return IsObjectHelper<cmds::IsTexture, cmds::IsTexture::Result>(client_id);
813 void GLES2DecoderTestBase::DoDeleteTexture(
814 GLuint client_id, GLuint service_id) {
815 EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(service_id)))
817 .RetiresOnSaturation();
818 cmds::DeleteTextures cmd;
819 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
820 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
821 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
824 void GLES2DecoderTestBase::DoTexImage2D(
825 GLenum target, GLint level, GLenum internal_format,
826 GLsizei width, GLsizei height, GLint border,
827 GLenum format, GLenum type,
828 uint32 shared_memory_id, uint32 shared_memory_offset) {
829 EXPECT_CALL(*gl_, GetError())
830 .WillOnce(Return(GL_NO_ERROR))
831 .RetiresOnSaturation();
832 EXPECT_CALL(*gl_, TexImage2D(target, level, internal_format,
833 width, height, border, format, type, _))
835 .RetiresOnSaturation();
836 EXPECT_CALL(*gl_, GetError())
837 .WillOnce(Return(GL_NO_ERROR))
838 .RetiresOnSaturation();
839 cmds::TexImage2D cmd;
840 cmd.Init(target, level, internal_format, width, height, border, format,
841 type, shared_memory_id, shared_memory_offset);
842 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
845 void GLES2DecoderTestBase::DoTexImage2DConvertInternalFormat(
846 GLenum target, GLint level, GLenum requested_internal_format,
847 GLsizei width, GLsizei height, GLint border,
848 GLenum format, GLenum type,
849 uint32 shared_memory_id, uint32 shared_memory_offset,
850 GLenum expected_internal_format) {
851 EXPECT_CALL(*gl_, GetError())
852 .WillOnce(Return(GL_NO_ERROR))
853 .RetiresOnSaturation();
854 EXPECT_CALL(*gl_, TexImage2D(target, level, expected_internal_format,
855 width, height, border, format, type, _))
857 .RetiresOnSaturation();
858 EXPECT_CALL(*gl_, GetError())
859 .WillOnce(Return(GL_NO_ERROR))
860 .RetiresOnSaturation();
861 cmds::TexImage2D cmd;
862 cmd.Init(target, level, requested_internal_format, width, height, border,
863 format, type, shared_memory_id, shared_memory_offset);
864 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
867 void GLES2DecoderTestBase::DoCompressedTexImage2D(
868 GLenum target, GLint level, GLenum format,
869 GLsizei width, GLsizei height, GLint border,
870 GLsizei size, uint32 bucket_id) {
871 EXPECT_CALL(*gl_, GetError())
872 .WillOnce(Return(GL_NO_ERROR))
873 .RetiresOnSaturation();
874 EXPECT_CALL(*gl_, CompressedTexImage2D(
875 target, level, format, width, height, border, size, _))
877 .RetiresOnSaturation();
878 EXPECT_CALL(*gl_, GetError())
879 .WillOnce(Return(GL_NO_ERROR))
880 .RetiresOnSaturation();
881 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(bucket_id);
882 bucket->SetSize(size);
883 cmds::CompressedTexImage2DBucket cmd;
885 target, level, format, width, height, border,
887 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
890 void GLES2DecoderTestBase::DoRenderbufferStorage(
891 GLenum target, GLenum internal_format, GLenum actual_format,
892 GLsizei width, GLsizei height, GLenum error) {
893 EXPECT_CALL(*gl_, GetError())
894 .WillOnce(Return(GL_NO_ERROR))
895 .RetiresOnSaturation();
896 EXPECT_CALL(*gl_, RenderbufferStorageEXT(
897 target, actual_format, width, height))
899 .RetiresOnSaturation();
900 EXPECT_CALL(*gl_, GetError())
901 .WillOnce(Return(error))
902 .RetiresOnSaturation();
903 cmds::RenderbufferStorage cmd;
904 cmd.Init(target, internal_format, width, height);
905 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
908 void GLES2DecoderTestBase::DoFramebufferTexture2D(
909 GLenum target, GLenum attachment, GLenum textarget,
910 GLuint texture_client_id, GLuint texture_service_id, GLint level,
912 EXPECT_CALL(*gl_, GetError())
913 .WillOnce(Return(GL_NO_ERROR))
914 .RetiresOnSaturation();
915 EXPECT_CALL(*gl_, FramebufferTexture2DEXT(
916 target, attachment, textarget, texture_service_id, level))
918 .RetiresOnSaturation();
919 EXPECT_CALL(*gl_, GetError())
920 .WillOnce(Return(error))
921 .RetiresOnSaturation();
922 cmds::FramebufferTexture2D cmd;
923 cmd.Init(target, attachment, textarget, texture_client_id, level);
924 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
927 void GLES2DecoderTestBase::DoFramebufferRenderbuffer(
930 GLenum renderbuffer_target,
931 GLuint renderbuffer_client_id,
932 GLuint renderbuffer_service_id,
934 EXPECT_CALL(*gl_, GetError())
935 .WillOnce(Return(GL_NO_ERROR))
936 .RetiresOnSaturation();
937 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
938 target, attachment, renderbuffer_target, renderbuffer_service_id))
940 .RetiresOnSaturation();
941 EXPECT_CALL(*gl_, GetError())
942 .WillOnce(Return(error))
943 .RetiresOnSaturation();
944 cmds::FramebufferRenderbuffer cmd;
945 cmd.Init(target, attachment, renderbuffer_target, renderbuffer_client_id);
946 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
949 void GLES2DecoderTestBase::DoVertexAttribPointer(
950 GLuint index, GLint size, GLenum type, GLsizei stride, GLuint offset) {
952 VertexAttribPointer(index, size, type, GL_FALSE, stride,
953 BufferOffset(offset)))
955 .RetiresOnSaturation();
956 cmds::VertexAttribPointer cmd;
957 cmd.Init(index, size, GL_FLOAT, GL_FALSE, stride, offset);
958 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
961 void GLES2DecoderTestBase::DoVertexAttribDivisorANGLE(
962 GLuint index, GLuint divisor) {
964 VertexAttribDivisorANGLE(index, divisor))
966 .RetiresOnSaturation();
967 cmds::VertexAttribDivisorANGLE cmd;
968 cmd.Init(index, divisor);
969 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
972 void GLES2DecoderTestBase::AddExpectationsForGenVertexArraysOES(){
973 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
974 EXPECT_CALL(*gl_, GenVertexArraysOES(1, _))
975 .WillOnce(SetArgumentPointee<1>(kServiceVertexArrayId))
976 .RetiresOnSaturation();
980 void GLES2DecoderTestBase::AddExpectationsForDeleteVertexArraysOES(){
981 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
982 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, _))
984 .RetiresOnSaturation();
988 void GLES2DecoderTestBase::AddExpectationsForBindVertexArrayOES() {
989 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
990 EXPECT_CALL(*gl_, BindVertexArrayOES(_))
992 .RetiresOnSaturation();
994 for (uint32 vv = 0; vv < group_->max_vertex_attribs(); ++vv) {
995 AddExpectationsForRestoreAttribState(vv);
998 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _))
1000 .RetiresOnSaturation();
1004 void GLES2DecoderTestBase::AddExpectationsForRestoreAttribState(GLuint attrib) {
1005 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1007 .RetiresOnSaturation();
1009 EXPECT_CALL(*gl_, VertexAttribPointer(attrib, _, _, _, _, _))
1011 .RetiresOnSaturation();
1013 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(attrib, _))
1014 .Times(testing::AtMost(1))
1015 .RetiresOnSaturation();
1017 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1019 .RetiresOnSaturation();
1022 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
1024 // TODO(bajones): Not sure if I can tell which of these will be called
1025 EXPECT_CALL(*gl_, EnableVertexAttribArray(attrib))
1026 .Times(testing::AtMost(1))
1027 .RetiresOnSaturation();
1029 EXPECT_CALL(*gl_, DisableVertexAttribArray(attrib))
1030 .Times(testing::AtMost(1))
1031 .RetiresOnSaturation();
1035 // GCC requires these declarations, but MSVC requires they not be present
1036 #ifndef COMPILER_MSVC
1037 const int GLES2DecoderTestBase::kBackBufferWidth;
1038 const int GLES2DecoderTestBase::kBackBufferHeight;
1040 const GLint GLES2DecoderTestBase::kMaxTextureSize;
1041 const GLint GLES2DecoderTestBase::kMaxCubeMapTextureSize;
1042 const GLint GLES2DecoderTestBase::kNumVertexAttribs;
1043 const GLint GLES2DecoderTestBase::kNumTextureUnits;
1044 const GLint GLES2DecoderTestBase::kMaxTextureImageUnits;
1045 const GLint GLES2DecoderTestBase::kMaxVertexTextureImageUnits;
1046 const GLint GLES2DecoderTestBase::kMaxFragmentUniformVectors;
1047 const GLint GLES2DecoderTestBase::kMaxVaryingVectors;
1048 const GLint GLES2DecoderTestBase::kMaxVertexUniformVectors;
1049 const GLint GLES2DecoderTestBase::kMaxViewportWidth;
1050 const GLint GLES2DecoderTestBase::kMaxViewportHeight;
1052 const GLint GLES2DecoderTestBase::kViewportX;
1053 const GLint GLES2DecoderTestBase::kViewportY;
1054 const GLint GLES2DecoderTestBase::kViewportWidth;
1055 const GLint GLES2DecoderTestBase::kViewportHeight;
1057 const GLuint GLES2DecoderTestBase::kServiceAttrib0BufferId;
1058 const GLuint GLES2DecoderTestBase::kServiceFixedAttribBufferId;
1060 const GLuint GLES2DecoderTestBase::kServiceBufferId;
1061 const GLuint GLES2DecoderTestBase::kServiceFramebufferId;
1062 const GLuint GLES2DecoderTestBase::kServiceRenderbufferId;
1063 const GLuint GLES2DecoderTestBase::kServiceTextureId;
1064 const GLuint GLES2DecoderTestBase::kServiceProgramId;
1065 const GLuint GLES2DecoderTestBase::kServiceShaderId;
1066 const GLuint GLES2DecoderTestBase::kServiceElementBufferId;
1067 const GLuint GLES2DecoderTestBase::kServiceQueryId;
1068 const GLuint GLES2DecoderTestBase::kServiceVertexArrayId;
1070 const int32 GLES2DecoderTestBase::kSharedMemoryId;
1071 const size_t GLES2DecoderTestBase::kSharedBufferSize;
1072 const uint32 GLES2DecoderTestBase::kSharedMemoryOffset;
1073 const int32 GLES2DecoderTestBase::kInvalidSharedMemoryId;
1074 const uint32 GLES2DecoderTestBase::kInvalidSharedMemoryOffset;
1075 const uint32 GLES2DecoderTestBase::kInitialResult;
1076 const uint8 GLES2DecoderTestBase::kInitialMemoryValue;
1078 const uint32 GLES2DecoderTestBase::kNewClientId;
1079 const uint32 GLES2DecoderTestBase::kNewServiceId;
1080 const uint32 GLES2DecoderTestBase::kInvalidClientId;
1082 const GLuint GLES2DecoderTestBase::kServiceVertexShaderId;
1083 const GLuint GLES2DecoderTestBase::kServiceFragmentShaderId;
1085 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumShaderId;
1086 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumProgramId;
1088 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTextureBufferId;
1089 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumVertexBufferId;
1090 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumFBOId;
1091 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumPositionAttrib;
1092 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTexAttrib;
1093 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumSamplerLocation;
1095 const GLsizei GLES2DecoderTestBase::kNumVertices;
1096 const GLsizei GLES2DecoderTestBase::kNumIndices;
1097 const int GLES2DecoderTestBase::kValidIndexRangeStart;
1098 const int GLES2DecoderTestBase::kValidIndexRangeCount;
1099 const int GLES2DecoderTestBase::kInvalidIndexRangeStart;
1100 const int GLES2DecoderTestBase::kInvalidIndexRangeCount;
1101 const int GLES2DecoderTestBase::kOutOfRangeIndexRangeEnd;
1102 const GLuint GLES2DecoderTestBase::kMaxValidIndex;
1104 const GLint GLES2DecoderTestBase::kMaxAttribLength;
1105 const GLint GLES2DecoderTestBase::kAttrib1Size;
1106 const GLint GLES2DecoderTestBase::kAttrib2Size;
1107 const GLint GLES2DecoderTestBase::kAttrib3Size;
1108 const GLint GLES2DecoderTestBase::kAttrib1Location;
1109 const GLint GLES2DecoderTestBase::kAttrib2Location;
1110 const GLint GLES2DecoderTestBase::kAttrib3Location;
1111 const GLenum GLES2DecoderTestBase::kAttrib1Type;
1112 const GLenum GLES2DecoderTestBase::kAttrib2Type;
1113 const GLenum GLES2DecoderTestBase::kAttrib3Type;
1114 const GLint GLES2DecoderTestBase::kInvalidAttribLocation;
1115 const GLint GLES2DecoderTestBase::kBadAttribIndex;
1117 const GLint GLES2DecoderTestBase::kMaxUniformLength;
1118 const GLint GLES2DecoderTestBase::kUniform1Size;
1119 const GLint GLES2DecoderTestBase::kUniform2Size;
1120 const GLint GLES2DecoderTestBase::kUniform3Size;
1121 const GLint GLES2DecoderTestBase::kUniform1RealLocation;
1122 const GLint GLES2DecoderTestBase::kUniform2RealLocation;
1123 const GLint GLES2DecoderTestBase::kUniform2ElementRealLocation;
1124 const GLint GLES2DecoderTestBase::kUniform3RealLocation;
1125 const GLint GLES2DecoderTestBase::kUniform1FakeLocation;
1126 const GLint GLES2DecoderTestBase::kUniform2FakeLocation;
1127 const GLint GLES2DecoderTestBase::kUniform2ElementFakeLocation;
1128 const GLint GLES2DecoderTestBase::kUniform3FakeLocation;
1129 const GLint GLES2DecoderTestBase::kUniform1DesiredLocation;
1130 const GLint GLES2DecoderTestBase::kUniform2DesiredLocation;
1131 const GLint GLES2DecoderTestBase::kUniform3DesiredLocation;
1132 const GLenum GLES2DecoderTestBase::kUniform1Type;
1133 const GLenum GLES2DecoderTestBase::kUniform2Type;
1134 const GLenum GLES2DecoderTestBase::kUniform3Type;
1135 const GLenum GLES2DecoderTestBase::kUniformCubemapType;
1136 const GLint GLES2DecoderTestBase::kInvalidUniformLocation;
1137 const GLint GLES2DecoderTestBase::kBadUniformIndex;
1141 const char* GLES2DecoderTestBase::kAttrib1Name = "attrib1";
1142 const char* GLES2DecoderTestBase::kAttrib2Name = "attrib2";
1143 const char* GLES2DecoderTestBase::kAttrib3Name = "attrib3";
1144 const char* GLES2DecoderTestBase::kUniform1Name = "uniform1";
1145 const char* GLES2DecoderTestBase::kUniform2Name = "uniform2[0]";
1146 const char* GLES2DecoderTestBase::kUniform3Name = "uniform3[0]";
1148 void GLES2DecoderTestBase::SetupDefaultProgram() {
1150 static AttribInfo attribs[] = {
1151 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1152 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1153 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1155 static UniformInfo uniforms[] = {
1156 { kUniform1Name, kUniform1Size, kUniform1Type,
1157 kUniform1FakeLocation, kUniform1RealLocation,
1158 kUniform1DesiredLocation },
1159 { kUniform2Name, kUniform2Size, kUniform2Type,
1160 kUniform2FakeLocation, kUniform2RealLocation,
1161 kUniform2DesiredLocation },
1162 { kUniform3Name, kUniform3Size, kUniform3Type,
1163 kUniform3FakeLocation, kUniform3RealLocation,
1164 kUniform3DesiredLocation },
1166 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1167 client_program_id_, kServiceProgramId,
1168 client_vertex_shader_id_, kServiceVertexShaderId,
1169 client_fragment_shader_id_, kServiceFragmentShaderId);
1173 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1175 .RetiresOnSaturation();
1176 cmds::UseProgram cmd;
1177 cmd.Init(client_program_id_);
1178 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1182 void GLES2DecoderTestBase::SetupCubemapProgram() {
1184 static AttribInfo attribs[] = {
1185 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1186 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1187 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1189 static UniformInfo uniforms[] = {
1190 { kUniform1Name, kUniform1Size, kUniformCubemapType,
1191 kUniform1FakeLocation, kUniform1RealLocation,
1192 kUniform1DesiredLocation, },
1193 { kUniform2Name, kUniform2Size, kUniform2Type,
1194 kUniform2FakeLocation, kUniform2RealLocation,
1195 kUniform2DesiredLocation, },
1196 { kUniform3Name, kUniform3Size, kUniform3Type,
1197 kUniform3FakeLocation, kUniform3RealLocation,
1198 kUniform3DesiredLocation, },
1200 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1201 client_program_id_, kServiceProgramId,
1202 client_vertex_shader_id_, kServiceVertexShaderId,
1203 client_fragment_shader_id_, kServiceFragmentShaderId);
1207 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1209 .RetiresOnSaturation();
1210 cmds::UseProgram cmd;
1211 cmd.Init(client_program_id_);
1212 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1216 void GLES2DecoderTestBase::SetupSamplerExternalProgram() {
1218 static AttribInfo attribs[] = {
1219 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1220 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1221 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1223 static UniformInfo uniforms[] = {
1224 { kUniform1Name, kUniform1Size, kUniformSamplerExternalType,
1225 kUniform1FakeLocation, kUniform1RealLocation,
1226 kUniform1DesiredLocation, },
1227 { kUniform2Name, kUniform2Size, kUniform2Type,
1228 kUniform2FakeLocation, kUniform2RealLocation,
1229 kUniform2DesiredLocation, },
1230 { kUniform3Name, kUniform3Size, kUniform3Type,
1231 kUniform3FakeLocation, kUniform3RealLocation,
1232 kUniform3DesiredLocation, },
1234 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1235 client_program_id_, kServiceProgramId,
1236 client_vertex_shader_id_, kServiceVertexShaderId,
1237 client_fragment_shader_id_, kServiceFragmentShaderId);
1241 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1243 .RetiresOnSaturation();
1244 cmds::UseProgram cmd;
1245 cmd.Init(client_program_id_);
1246 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1250 void GLES2DecoderWithShaderTestBase::TearDown() {
1251 GLES2DecoderTestBase::TearDown();
1254 void GLES2DecoderTestBase::SetupShader(
1255 GLES2DecoderTestBase::AttribInfo* attribs, size_t num_attribs,
1256 GLES2DecoderTestBase::UniformInfo* uniforms, size_t num_uniforms,
1257 GLuint program_client_id, GLuint program_service_id,
1258 GLuint vertex_shader_client_id, GLuint vertex_shader_service_id,
1259 GLuint fragment_shader_client_id, GLuint fragment_shader_service_id) {
1264 AttachShader(program_service_id, vertex_shader_service_id))
1266 .RetiresOnSaturation();
1268 AttachShader(program_service_id, fragment_shader_service_id))
1270 .RetiresOnSaturation();
1271 TestHelper::SetupShader(
1272 gl_.get(), attribs, num_attribs, uniforms, num_uniforms,
1273 program_service_id);
1277 GL_VERTEX_SHADER, vertex_shader_client_id, vertex_shader_service_id);
1279 GL_FRAGMENT_SHADER, fragment_shader_client_id,
1280 fragment_shader_service_id);
1282 GetShader(vertex_shader_client_id)->SetStatus(true, "", NULL);
1283 GetShader(fragment_shader_client_id)->SetStatus(true, "", NULL);
1285 cmds::AttachShader attach_cmd;
1286 attach_cmd.Init(program_client_id, vertex_shader_client_id);
1287 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1289 attach_cmd.Init(program_client_id, fragment_shader_client_id);
1290 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1292 cmds::LinkProgram link_cmd;
1293 link_cmd.Init(program_client_id);
1295 EXPECT_EQ(error::kNoError, ExecuteCmd(link_cmd));
1298 void GLES2DecoderTestBase::DoEnableVertexAttribArray(GLint index) {
1299 EXPECT_CALL(*gl_, EnableVertexAttribArray(index))
1301 .RetiresOnSaturation();
1302 cmds::EnableVertexAttribArray cmd;
1304 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1307 void GLES2DecoderTestBase::DoBufferData(GLenum target, GLsizei size) {
1308 EXPECT_CALL(*gl_, GetError())
1309 .WillOnce(Return(GL_NO_ERROR))
1310 .RetiresOnSaturation();
1311 EXPECT_CALL(*gl_, BufferData(target, size, _, GL_STREAM_DRAW))
1313 .RetiresOnSaturation();
1314 EXPECT_CALL(*gl_, GetError())
1315 .WillOnce(Return(GL_NO_ERROR))
1316 .RetiresOnSaturation();
1317 cmds::BufferData cmd;
1318 cmd.Init(target, size, 0, 0, GL_STREAM_DRAW);
1319 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1322 void GLES2DecoderTestBase::DoBufferSubData(
1323 GLenum target, GLint offset, GLsizei size, const void* data) {
1324 EXPECT_CALL(*gl_, BufferSubData(target, offset, size,
1325 shared_memory_address_))
1327 .RetiresOnSaturation();
1328 memcpy(shared_memory_address_, data, size);
1329 cmds::BufferSubData cmd;
1330 cmd.Init(target, offset, size, shared_memory_id_, shared_memory_offset_);
1331 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1334 void GLES2DecoderTestBase::SetupVertexBuffer() {
1335 DoEnableVertexAttribArray(1);
1336 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1338 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 2 * sizeof(f));
1341 void GLES2DecoderTestBase::SetupAllNeededVertexBuffers() {
1342 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1343 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 16 * sizeof(float));
1344 DoEnableVertexAttribArray(0);
1345 DoEnableVertexAttribArray(1);
1346 DoEnableVertexAttribArray(2);
1347 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1348 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1349 DoVertexAttribPointer(2, 2, GL_FLOAT, 0, 0);
1352 void GLES2DecoderTestBase::SetupIndexBuffer() {
1353 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
1354 client_element_buffer_id_,
1355 kServiceElementBufferId);
1356 static const GLshort indices[] = {100, 1, 2, 3, 4, 5, 6, 7, 100, 9};
1357 COMPILE_ASSERT(arraysize(indices) == kNumIndices, Indices_is_not_10);
1358 DoBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices));
1359 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, 2, indices);
1360 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 2, sizeof(indices) - 2, &indices[1]);
1363 void GLES2DecoderTestBase::SetupTexture() {
1364 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1365 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1366 kSharedMemoryId, kSharedMemoryOffset);
1369 void GLES2DecoderTestBase::DeleteVertexBuffer() {
1370 DoDeleteBuffer(client_buffer_id_, kServiceBufferId);
1373 void GLES2DecoderTestBase::DeleteIndexBuffer() {
1374 DoDeleteBuffer(client_element_buffer_id_, kServiceElementBufferId);
1377 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0WithError(
1378 GLsizei num_vertices, GLuint buffer_id, GLenum error) {
1379 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
1383 EXPECT_CALL(*gl_, GetError())
1384 .WillOnce(Return(GL_NO_ERROR))
1385 .WillOnce(Return(error))
1386 .RetiresOnSaturation();
1387 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
1389 .RetiresOnSaturation();
1390 EXPECT_CALL(*gl_, BufferData(GL_ARRAY_BUFFER,
1391 num_vertices * sizeof(GLfloat) * 4,
1392 _, GL_DYNAMIC_DRAW))
1394 .RetiresOnSaturation();
1395 if (error == GL_NO_ERROR) {
1396 EXPECT_CALL(*gl_, BufferSubData(
1397 GL_ARRAY_BUFFER, 0, num_vertices * sizeof(GLfloat) * 4, _))
1399 .RetiresOnSaturation();
1400 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL))
1402 .RetiresOnSaturation();
1403 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
1405 .RetiresOnSaturation();
1406 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL))
1408 .RetiresOnSaturation();
1409 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, buffer_id))
1411 .RetiresOnSaturation();
1415 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0(
1416 GLsizei num_vertices, GLuint buffer_id) {
1417 AddExpectationsForSimulatedAttrib0WithError(
1418 num_vertices, buffer_id, GL_NO_ERROR);
1421 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1422 MockCommandBufferEngine() {
1424 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory());
1425 shm->CreateAndMapAnonymous(kSharedBufferSize);
1426 valid_buffer_ = new gpu::Buffer(shm.Pass(), kSharedBufferSize);
1428 ClearSharedMemory();
1431 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1432 ~MockCommandBufferEngine() {}
1434 scoped_refptr<gpu::Buffer>
1435 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetSharedMemoryBuffer(
1437 return shm_id == kSharedMemoryId ? valid_buffer_ : invalid_buffer_;
1440 void GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::set_token(
1445 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetBuffer(
1446 int32 /* transfer_buffer_id */) {
1451 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetOffset(
1457 int32 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetGetOffset() {
1462 void GLES2DecoderWithShaderTestBase::SetUp() {
1463 GLES2DecoderTestBase::SetUp();
1464 SetupDefaultProgram();
1467 // Include the auto-generated part of this file. We split this because it means
1468 // we can easily edit the non-auto generated parts right here in this file
1469 // instead of having to edit some template or the code generator.
1470 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h"
1472 } // namespace gles2