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"
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() {
68 true, // request alpha
69 true, // request depth
70 false, // request stencil
71 true); // bind generates resource
74 void GLES2DecoderTestBase::AddExpectationsForVertexAttribManager() {
75 for (GLint ii = 0; ii < kNumVertexAttribs; ++ii) {
76 EXPECT_CALL(*gl_, VertexAttrib4f(ii, 0.0f, 0.0f, 0.0f, 1.0f))
78 .RetiresOnSaturation();
82 void GLES2DecoderTestBase::InitDecoder(
83 const char* extensions,
90 bool bind_generates_resource) {
91 Framebuffer::ClearFramebufferCompleteComboMap();
92 gl_.reset(new StrictMock<MockGLInterface>());
93 ::gfx::GLInterface::SetGLInterface(gl_.get());
95 // Only create stream texture manager if extension is requested.
96 std::vector<std::string> list;
97 base::SplitString(std::string(extensions), ' ', &list);
98 if (std::find(list.begin(), list.end(),
99 "GL_CHROMIUM_stream_texture") != list.end())
100 stream_texture_manager_.reset(new StrictMock<MockStreamTextureManager>);
101 group_ = scoped_refptr<ContextGroup>(new ContextGroup(
105 stream_texture_manager_.get(),
106 bind_generates_resource));
107 // These two workarounds are always turned on.
108 group_->feature_info(
109 )->workarounds_.set_texture_filter_before_generating_mipmap = true;
110 group_->feature_info()->workarounds_.clear_alpha_in_readpixels = true;
114 TestHelper::SetupContextGroupInitExpectations(gl_.get(),
115 DisallowedFeatures(), extensions);
117 // We initialize the ContextGroup with a MockGLES2Decoder so that
118 // we can use the ContextGroup to figure out how the real GLES2Decoder
119 // will initialize itself.
120 mock_decoder_.reset(new MockGLES2Decoder());
122 group_->Initialize(mock_decoder_.get(), DisallowedFeatures()));
124 AddExpectationsForVertexAttribManager();
126 AddExpectationsForBindVertexArrayOES();
128 EXPECT_CALL(*gl_, EnableVertexAttribArray(0))
130 .RetiresOnSaturation();
131 static GLuint attrib_0_id[] = {
132 kServiceAttrib0BufferId,
134 static GLuint fixed_attrib_buffer_id[] = {
135 kServiceFixedAttribBufferId,
137 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(attrib_0_id), _))
138 .WillOnce(SetArrayArgument<1>(attrib_0_id,
139 attrib_0_id + arraysize(attrib_0_id)))
140 .RetiresOnSaturation();
141 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
143 .RetiresOnSaturation();
144 EXPECT_CALL(*gl_, VertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL))
146 .RetiresOnSaturation();
147 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
149 .RetiresOnSaturation();
150 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(fixed_attrib_buffer_id), _))
151 .WillOnce(SetArrayArgument<1>(
152 fixed_attrib_buffer_id,
153 fixed_attrib_buffer_id + arraysize(fixed_attrib_buffer_id)))
154 .RetiresOnSaturation();
156 for (GLint tt = 0; tt < TestHelper::kNumTextureUnits; ++tt) {
157 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0 + tt))
159 .RetiresOnSaturation();
160 if (group_->feature_info()->feature_flags().oes_egl_image_external) {
161 EXPECT_CALL(*gl_, BindTexture(
162 GL_TEXTURE_EXTERNAL_OES,
163 TestHelper::kServiceDefaultExternalTextureId))
165 .RetiresOnSaturation();
167 if (group_->feature_info()->feature_flags().arb_texture_rectangle) {
168 EXPECT_CALL(*gl_, BindTexture(
169 GL_TEXTURE_RECTANGLE_ARB,
170 TestHelper::kServiceDefaultRectangleTextureId))
172 .RetiresOnSaturation();
174 EXPECT_CALL(*gl_, BindTexture(
175 GL_TEXTURE_CUBE_MAP, TestHelper::kServiceDefaultTextureCubemapId))
177 .RetiresOnSaturation();
178 EXPECT_CALL(*gl_, BindTexture(
179 GL_TEXTURE_2D, TestHelper::kServiceDefaultTexture2dId))
181 .RetiresOnSaturation();
183 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
185 .RetiresOnSaturation();
187 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
189 .RetiresOnSaturation();
190 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _))
191 .WillOnce(SetArgumentPointee<1>(has_alpha ? 8 : 0))
192 .RetiresOnSaturation();
193 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
194 .WillOnce(SetArgumentPointee<1>(has_depth ? 24 : 0))
195 .RetiresOnSaturation();
196 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
197 .WillOnce(SetArgumentPointee<1>(has_stencil ? 8 : 0))
198 .RetiresOnSaturation();
200 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE))
202 .RetiresOnSaturation();
204 EXPECT_CALL(*gl_, Enable(GL_POINT_SPRITE))
206 .RetiresOnSaturation();
208 static GLint max_viewport_dims[] = {
212 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VIEWPORT_DIMS, _))
213 .WillOnce(SetArrayArgument<1>(
214 max_viewport_dims, max_viewport_dims + arraysize(max_viewport_dims)))
215 .RetiresOnSaturation();
217 SetupInitCapabilitiesExpectations();
218 SetupInitStateExpectations();
220 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
222 .RetiresOnSaturation();
224 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
226 .RetiresOnSaturation();
227 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0))
229 .RetiresOnSaturation();
230 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
232 .RetiresOnSaturation();
233 EXPECT_CALL(*gl_, BindRenderbufferEXT(GL_RENDERBUFFER, 0))
235 .RetiresOnSaturation();
237 // TODO(boliu): Remove OS_ANDROID once crbug.com/259023 is fixed and the
238 // workaround has been reverted.
239 #if !defined(OS_ANDROID)
240 EXPECT_CALL(*gl_, Clear(
241 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
243 .RetiresOnSaturation();
246 engine_.reset(new StrictMock<MockCommandBufferEngine>());
247 gpu::Buffer buffer = engine_->GetSharedMemoryBuffer(kSharedMemoryId);
248 shared_memory_offset_ = kSharedMemoryOffset;
249 shared_memory_address_ = reinterpret_cast<int8*>(buffer.ptr) +
250 shared_memory_offset_;
251 shared_memory_id_ = kSharedMemoryId;
252 shared_memory_base_ = buffer.ptr;
254 surface_ = new gfx::GLSurfaceStub;
255 surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight));
257 context_ = new gfx::GLContextStub;
259 context_->MakeCurrent(surface_.get());
261 int32 attributes[] = {
262 EGL_ALPHA_SIZE, request_alpha ? 8 : 0,
263 EGL_DEPTH_SIZE, request_depth ? 24 : 0,
264 EGL_STENCIL_SIZE, request_stencil ? 8 : 0,
266 std::vector<int32> attribs(attributes, attributes + arraysize(attributes));
268 decoder_.reset(GLES2Decoder::Create(group_.get()));
269 decoder_->GetLogger()->set_log_synthesized_gl_errors(false);
270 decoder_->Initialize(surface_,
274 DisallowedFeatures(),
276 decoder_->MakeCurrent();
277 decoder_->set_engine(engine_.get());
279 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
280 .WillOnce(SetArgumentPointee<1>(kServiceBufferId))
281 .RetiresOnSaturation();
282 GenHelper<cmds::GenBuffersImmediate>(client_buffer_id_);
283 EXPECT_CALL(*gl_, GenFramebuffersEXT(_, _))
284 .WillOnce(SetArgumentPointee<1>(kServiceFramebufferId))
285 .RetiresOnSaturation();
286 GenHelper<cmds::GenFramebuffersImmediate>(client_framebuffer_id_);
287 EXPECT_CALL(*gl_, GenRenderbuffersEXT(_, _))
288 .WillOnce(SetArgumentPointee<1>(kServiceRenderbufferId))
289 .RetiresOnSaturation();
290 GenHelper<cmds::GenRenderbuffersImmediate>(client_renderbuffer_id_);
291 EXPECT_CALL(*gl_, GenTextures(_, _))
292 .WillOnce(SetArgumentPointee<1>(kServiceTextureId))
293 .RetiresOnSaturation();
294 GenHelper<cmds::GenTexturesImmediate>(client_texture_id_);
295 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
296 .WillOnce(SetArgumentPointee<1>(kServiceElementBufferId))
297 .RetiresOnSaturation();
298 GenHelper<cmds::GenBuffersImmediate>(client_element_buffer_id_);
300 DoCreateProgram(client_program_id_, kServiceProgramId);
301 DoCreateShader(GL_VERTEX_SHADER, client_shader_id_, kServiceShaderId);
303 EXPECT_EQ(GL_NO_ERROR, GetGLError());
306 void GLES2DecoderTestBase::TearDown() {
307 // All Tests should have read all their GLErrors before getting here.
308 EXPECT_EQ(GL_NO_ERROR, GetGLError());
310 EXPECT_CALL(*gl_, DeleteBuffersARB(1, _))
312 .RetiresOnSaturation();
314 decoder_->Destroy(true);
316 group_->Destroy(mock_decoder_.get(), false);
318 ::gfx::GLInterface::SetGLInterface(NULL);
322 void GLES2DecoderTestBase::ExpectEnableDisable(GLenum cap, bool enable) {
324 EXPECT_CALL(*gl_, Enable(cap))
326 .RetiresOnSaturation();
328 EXPECT_CALL(*gl_, Disable(cap))
330 .RetiresOnSaturation();
335 GLint GLES2DecoderTestBase::GetGLError() {
336 EXPECT_CALL(*gl_, GetError())
337 .WillOnce(Return(GL_NO_ERROR))
338 .RetiresOnSaturation();
340 cmd.Init(shared_memory_id_, shared_memory_offset_);
341 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
342 return static_cast<GLint>(*GetSharedMemoryAs<GLenum*>());
345 void GLES2DecoderTestBase::DoCreateShader(
346 GLenum shader_type, GLuint client_id, GLuint service_id) {
347 EXPECT_CALL(*gl_, CreateShader(shader_type))
349 .WillOnce(Return(service_id))
350 .RetiresOnSaturation();
351 cmds::CreateShader cmd;
352 cmd.Init(shader_type, client_id);
353 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
356 bool GLES2DecoderTestBase::DoIsShader(GLuint client_id) {
357 return IsObjectHelper<cmds::IsShader, cmds::IsShader::Result>(client_id);
360 void GLES2DecoderTestBase::DoDeleteShader(
361 GLuint client_id, GLuint service_id) {
362 EXPECT_CALL(*gl_, DeleteShader(service_id))
364 .RetiresOnSaturation();
365 cmds::DeleteShader cmd;
367 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
370 void GLES2DecoderTestBase::DoCreateProgram(
371 GLuint client_id, GLuint service_id) {
372 EXPECT_CALL(*gl_, CreateProgram())
374 .WillOnce(Return(service_id))
375 .RetiresOnSaturation();
376 cmds::CreateProgram cmd;
378 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
381 bool GLES2DecoderTestBase::DoIsProgram(GLuint client_id) {
382 return IsObjectHelper<cmds::IsProgram, cmds::IsProgram::Result>(client_id);
385 void GLES2DecoderTestBase::DoDeleteProgram(
386 GLuint client_id, GLuint /* service_id */) {
387 cmds::DeleteProgram cmd;
389 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
392 void GLES2DecoderTestBase::SetBucketAsCString(
393 uint32 bucket_id, const char* str) {
394 uint32 size = str ? (strlen(str) + 1) : 0;
395 cmd::SetBucketSize cmd1;
396 cmd1.Init(bucket_id, size);
397 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
399 memcpy(shared_memory_address_, str, size);
400 cmd::SetBucketData cmd2;
401 cmd2.Init(bucket_id, 0, size, kSharedMemoryId, kSharedMemoryOffset);
402 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
407 void GLES2DecoderTestBase::SetupClearTextureExpections(
409 GLuint old_service_id,
417 EXPECT_CALL(*gl_, BindTexture(bind_target, service_id))
419 .RetiresOnSaturation();
420 EXPECT_CALL(*gl_, TexImage2D(
421 target, level, format, width, height, 0, format, type, _))
423 .RetiresOnSaturation();
424 EXPECT_CALL(*gl_, BindTexture(bind_target, old_service_id))
426 .RetiresOnSaturation();
429 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearing(
432 GLclampf restore_red,
433 GLclampf restore_green,
434 GLclampf restore_blue,
435 GLclampf restore_alpha,
436 GLuint restore_stencil,
437 GLclampf restore_depth,
438 bool restore_scissor_test) {
439 SetupExpectationsForFramebufferClearingMulti(
450 restore_scissor_test);
453 void GLES2DecoderTestBase::SetupExpectationsForRestoreClearState(
454 GLclampf restore_red,
455 GLclampf restore_green,
456 GLclampf restore_blue,
457 GLclampf restore_alpha,
458 GLuint restore_stencil,
459 GLclampf restore_depth,
460 bool restore_scissor_test) {
461 EXPECT_CALL(*gl_, ClearColor(
462 restore_red, restore_green, restore_blue, restore_alpha))
464 .RetiresOnSaturation();
465 EXPECT_CALL(*gl_, ClearStencil(restore_stencil))
467 .RetiresOnSaturation();
468 EXPECT_CALL(*gl_, ClearDepth(restore_depth))
470 .RetiresOnSaturation();
471 if (restore_scissor_test) {
472 EXPECT_CALL(*gl_, Enable(GL_SCISSOR_TEST))
474 .RetiresOnSaturation();
478 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearingMulti(
479 GLuint read_framebuffer_service_id,
480 GLuint draw_framebuffer_service_id,
483 GLclampf restore_red,
484 GLclampf restore_green,
485 GLclampf restore_blue,
486 GLclampf restore_alpha,
487 GLuint restore_stencil,
488 GLclampf restore_depth,
489 bool restore_scissor_test) {
490 // TODO(gman): Figure out why InSequence stopped working.
491 // InSequence sequence;
492 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(target))
493 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
494 .RetiresOnSaturation();
495 if (target == GL_READ_FRAMEBUFFER_EXT) {
496 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0))
498 .RetiresOnSaturation();
499 EXPECT_CALL(*gl_, BindFramebufferEXT(
500 GL_DRAW_FRAMEBUFFER_EXT, read_framebuffer_service_id))
502 .RetiresOnSaturation();
504 if ((clear_bits & GL_COLOR_BUFFER_BIT) != 0) {
505 EXPECT_CALL(*gl_, ClearColor(0.0f, 0.0f, 0.0f, 0.0f))
507 .RetiresOnSaturation();
508 EXPECT_CALL(*gl_, ColorMask(true, true, true, true))
510 .RetiresOnSaturation();
512 if ((clear_bits & GL_STENCIL_BUFFER_BIT) != 0) {
513 EXPECT_CALL(*gl_, ClearStencil(0))
515 .RetiresOnSaturation();
516 EXPECT_CALL(*gl_, StencilMask(static_cast<GLuint>(-1)))
518 .RetiresOnSaturation();
520 if ((clear_bits & GL_DEPTH_BUFFER_BIT) != 0) {
521 EXPECT_CALL(*gl_, ClearDepth(1.0f))
523 .RetiresOnSaturation();
524 EXPECT_CALL(*gl_, DepthMask(1))
526 .RetiresOnSaturation();
528 EXPECT_CALL(*gl_, Disable(GL_SCISSOR_TEST))
530 .RetiresOnSaturation();
531 EXPECT_CALL(*gl_, Clear(clear_bits))
533 .RetiresOnSaturation();
534 SetupExpectationsForRestoreClearState(
535 restore_red, restore_green, restore_blue, restore_alpha,
536 restore_stencil, restore_depth, restore_scissor_test);
537 if (target == GL_READ_FRAMEBUFFER_EXT) {
538 EXPECT_CALL(*gl_, BindFramebufferEXT(
539 GL_READ_FRAMEBUFFER_EXT, read_framebuffer_service_id))
541 .RetiresOnSaturation();
542 EXPECT_CALL(*gl_, BindFramebufferEXT(
543 GL_DRAW_FRAMEBUFFER_EXT, draw_framebuffer_service_id))
545 .RetiresOnSaturation();
549 void GLES2DecoderTestBase::SetupShaderForUniform(GLenum uniform_type) {
550 static AttribInfo attribs[] = {
551 { "foo", 1, GL_FLOAT, 1, },
552 { "goo", 1, GL_FLOAT, 2, },
554 UniformInfo uniforms[] = {
555 { "bar", 1, uniform_type, 0, 2, -1, },
556 { "car", 4, uniform_type, 1, 1, -1, },
558 const GLuint kClientVertexShaderId = 5001;
559 const GLuint kServiceVertexShaderId = 6001;
560 const GLuint kClientFragmentShaderId = 5002;
561 const GLuint kServiceFragmentShaderId = 6002;
562 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
563 client_program_id_, kServiceProgramId,
564 kClientVertexShaderId, kServiceVertexShaderId,
565 kClientFragmentShaderId, kServiceFragmentShaderId);
567 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
569 .RetiresOnSaturation();
570 cmds::UseProgram cmd;
571 cmd.Init(client_program_id_);
572 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
575 void GLES2DecoderTestBase::DoBindBuffer(
576 GLenum target, GLuint client_id, GLuint service_id) {
577 EXPECT_CALL(*gl_, BindBuffer(target, service_id))
579 .RetiresOnSaturation();
580 cmds::BindBuffer cmd;
581 cmd.Init(target, client_id);
582 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
585 bool GLES2DecoderTestBase::DoIsBuffer(GLuint client_id) {
586 return IsObjectHelper<cmds::IsBuffer, cmds::IsBuffer::Result>(client_id);
589 void GLES2DecoderTestBase::DoDeleteBuffer(
590 GLuint client_id, GLuint service_id) {
591 EXPECT_CALL(*gl_, DeleteBuffersARB(1, Pointee(service_id)))
593 .RetiresOnSaturation();
594 cmds::DeleteBuffers cmd;
595 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
596 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
597 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
600 void GLES2DecoderTestBase::SetupExpectationsForApplyingDirtyState(
601 bool framebuffer_is_rgb,
602 bool framebuffer_has_depth,
603 bool framebuffer_has_stencil,
607 GLuint front_stencil_mask,
608 GLuint back_stencil_mask,
609 bool stencil_enabled,
610 bool cull_face_enabled,
611 bool scissor_test_enabled,
612 bool blend_enabled) {
613 EXPECT_CALL(*gl_, ColorMask(
614 (color_bits & 0x1000) != 0,
615 (color_bits & 0x0100) != 0,
616 (color_bits & 0x0010) != 0,
617 (color_bits & 0x0001) && !framebuffer_is_rgb))
619 .RetiresOnSaturation();
620 EXPECT_CALL(*gl_, DepthMask(depth_mask))
622 .RetiresOnSaturation();
623 if (framebuffer_has_depth && depth_enabled) {
624 EXPECT_CALL(*gl_, Enable(GL_DEPTH_TEST))
626 .RetiresOnSaturation();
628 EXPECT_CALL(*gl_, Disable(GL_DEPTH_TEST))
630 .RetiresOnSaturation();
632 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_FRONT, front_stencil_mask))
634 .RetiresOnSaturation();
635 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_BACK, back_stencil_mask))
637 .RetiresOnSaturation();
638 if (framebuffer_has_stencil && stencil_enabled) {
639 EXPECT_CALL(*gl_, Enable(GL_STENCIL_TEST))
641 .RetiresOnSaturation();
643 EXPECT_CALL(*gl_, Disable(GL_STENCIL_TEST))
645 .RetiresOnSaturation();
647 if (cull_face_enabled) {
648 EXPECT_CALL(*gl_, Enable(GL_CULL_FACE))
650 .RetiresOnSaturation();
652 EXPECT_CALL(*gl_, Disable(GL_CULL_FACE))
654 .RetiresOnSaturation();
656 if (scissor_test_enabled) {
657 EXPECT_CALL(*gl_, Enable(GL_SCISSOR_TEST))
659 .RetiresOnSaturation();
661 EXPECT_CALL(*gl_, Disable(GL_SCISSOR_TEST))
663 .RetiresOnSaturation();
666 EXPECT_CALL(*gl_, Enable(GL_BLEND))
668 .RetiresOnSaturation();
670 EXPECT_CALL(*gl_, Disable(GL_BLEND))
672 .RetiresOnSaturation();
676 void GLES2DecoderTestBase::SetupExpectationsForApplyingDefaultDirtyState() {
677 SetupExpectationsForApplyingDirtyState(
678 false, // Framebuffer is RGB
679 false, // Framebuffer has depth
680 false, // Framebuffer has stencil
681 0x1111, // color bits
683 false, // depth enabled
684 0, // front stencil mask
685 0, // back stencil mask
686 false, // stencil enabled
687 false, // cull_face_enabled
688 false, // scissor_test_enabled
689 false); // blend_enabled
692 void GLES2DecoderTestBase::DoBindFramebuffer(
693 GLenum target, GLuint client_id, GLuint service_id) {
694 EXPECT_CALL(*gl_, BindFramebufferEXT(target, service_id))
696 .RetiresOnSaturation();
697 cmds::BindFramebuffer cmd;
698 cmd.Init(target, client_id);
699 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
702 bool GLES2DecoderTestBase::DoIsFramebuffer(GLuint client_id) {
703 return IsObjectHelper<cmds::IsFramebuffer, cmds::IsFramebuffer::Result>(
707 void GLES2DecoderTestBase::DoDeleteFramebuffer(
708 GLuint client_id, GLuint service_id,
709 bool reset_draw, GLenum draw_target, GLuint draw_id,
710 bool reset_read, GLenum read_target, GLuint read_id) {
712 EXPECT_CALL(*gl_, BindFramebufferEXT(draw_target, draw_id))
714 .RetiresOnSaturation();
717 EXPECT_CALL(*gl_, BindFramebufferEXT(read_target, read_id))
719 .RetiresOnSaturation();
721 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, Pointee(service_id)))
723 .RetiresOnSaturation();
724 cmds::DeleteFramebuffers cmd;
725 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
726 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
727 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
730 void GLES2DecoderTestBase::DoBindRenderbuffer(
731 GLenum target, GLuint client_id, GLuint service_id) {
732 EXPECT_CALL(*gl_, BindRenderbufferEXT(target, service_id))
734 .RetiresOnSaturation();
735 cmds::BindRenderbuffer cmd;
736 cmd.Init(target, client_id);
737 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
740 bool GLES2DecoderTestBase::DoIsRenderbuffer(GLuint client_id) {
741 return IsObjectHelper<cmds::IsRenderbuffer, cmds::IsRenderbuffer::Result>(
745 void GLES2DecoderTestBase::DoDeleteRenderbuffer(
746 GLuint client_id, GLuint service_id) {
747 EXPECT_CALL(*gl_, DeleteRenderbuffersEXT(1, Pointee(service_id)))
749 .RetiresOnSaturation();
750 cmds::DeleteRenderbuffers cmd;
751 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
752 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
753 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
756 void GLES2DecoderTestBase::DoBindTexture(
757 GLenum target, GLuint client_id, GLuint service_id) {
758 EXPECT_CALL(*gl_, BindTexture(target, service_id))
760 .RetiresOnSaturation();
761 cmds::BindTexture cmd;
762 cmd.Init(target, client_id);
763 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
766 bool GLES2DecoderTestBase::DoIsTexture(GLuint client_id) {
767 return IsObjectHelper<cmds::IsTexture, cmds::IsTexture::Result>(client_id);
770 void GLES2DecoderTestBase::DoDeleteTexture(
771 GLuint client_id, GLuint service_id) {
772 EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(service_id)))
774 .RetiresOnSaturation();
775 cmds::DeleteTextures cmd;
776 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
777 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
778 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
781 void GLES2DecoderTestBase::DoTexImage2D(
782 GLenum target, GLint level, GLenum internal_format,
783 GLsizei width, GLsizei height, GLint border,
784 GLenum format, GLenum type,
785 uint32 shared_memory_id, uint32 shared_memory_offset) {
786 EXPECT_CALL(*gl_, GetError())
787 .WillOnce(Return(GL_NO_ERROR))
788 .RetiresOnSaturation();
789 EXPECT_CALL(*gl_, TexImage2D(target, level, internal_format,
790 width, height, border, format, type, _))
792 .RetiresOnSaturation();
793 EXPECT_CALL(*gl_, GetError())
794 .WillOnce(Return(GL_NO_ERROR))
795 .RetiresOnSaturation();
796 cmds::TexImage2D cmd;
797 cmd.Init(target, level, internal_format, width, height, border, format,
798 type, shared_memory_id, shared_memory_offset);
799 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
802 void GLES2DecoderTestBase::DoCompressedTexImage2D(
803 GLenum target, GLint level, GLenum format,
804 GLsizei width, GLsizei height, GLint border,
805 GLsizei size, uint32 bucket_id) {
806 EXPECT_CALL(*gl_, GetError())
807 .WillOnce(Return(GL_NO_ERROR))
808 .RetiresOnSaturation();
809 EXPECT_CALL(*gl_, CompressedTexImage2D(
810 target, level, format, width, height, border, size, _))
812 .RetiresOnSaturation();
813 EXPECT_CALL(*gl_, GetError())
814 .WillOnce(Return(GL_NO_ERROR))
815 .RetiresOnSaturation();
816 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(bucket_id);
817 bucket->SetSize(size);
818 cmds::CompressedTexImage2DBucket cmd;
820 target, level, format, width, height, border,
822 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
825 void GLES2DecoderTestBase::DoTexImage2DSameSize(
826 GLenum target, GLint level, GLenum internal_format,
827 GLsizei width, GLsizei height, GLint border,
828 GLenum format, GLenum type,
829 uint32 shared_memory_id, uint32 shared_memory_offset) {
830 if (GLES2Decoder::IsAngle()) {
831 EXPECT_CALL(*gl_, TexSubImage2D(
832 target, level, 0, 0, width, height, format, type, _))
834 .RetiresOnSaturation();
836 EXPECT_CALL(*gl_, GetError())
837 .WillOnce(Return(GL_NO_ERROR))
838 .RetiresOnSaturation();
839 EXPECT_CALL(*gl_, TexImage2D(target, level, internal_format,
840 width, height, border, format, type, _))
842 .RetiresOnSaturation();
843 EXPECT_CALL(*gl_, GetError())
844 .WillOnce(Return(GL_NO_ERROR))
845 .RetiresOnSaturation();
847 cmds::TexImage2D cmd;
848 cmd.Init(target, level, internal_format, width, height, border, format,
849 type, shared_memory_id, shared_memory_offset);
850 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
853 void GLES2DecoderTestBase::DoRenderbufferStorage(
854 GLenum target, GLenum internal_format, GLenum actual_format,
855 GLsizei width, GLsizei height, GLenum error) {
856 EXPECT_CALL(*gl_, GetError())
857 .WillOnce(Return(GL_NO_ERROR))
858 .RetiresOnSaturation();
859 EXPECT_CALL(*gl_, RenderbufferStorageEXT(
860 target, actual_format, width, height))
862 .RetiresOnSaturation();
863 EXPECT_CALL(*gl_, GetError())
864 .WillOnce(Return(error))
865 .RetiresOnSaturation();
866 cmds::RenderbufferStorage cmd;
867 cmd.Init(target, internal_format, width, height);
868 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
871 void GLES2DecoderTestBase::DoFramebufferTexture2D(
872 GLenum target, GLenum attachment, GLenum textarget,
873 GLuint texture_client_id, GLuint texture_service_id, GLint level,
875 EXPECT_CALL(*gl_, GetError())
876 .WillOnce(Return(GL_NO_ERROR))
877 .RetiresOnSaturation();
878 EXPECT_CALL(*gl_, FramebufferTexture2DEXT(
879 target, attachment, textarget, texture_service_id, level))
881 .RetiresOnSaturation();
882 EXPECT_CALL(*gl_, GetError())
883 .WillOnce(Return(error))
884 .RetiresOnSaturation();
885 cmds::FramebufferTexture2D cmd;
886 cmd.Init(target, attachment, textarget, texture_client_id, level);
887 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
890 void GLES2DecoderTestBase::DoFramebufferRenderbuffer(
893 GLenum renderbuffer_target,
894 GLuint renderbuffer_client_id,
895 GLuint renderbuffer_service_id,
897 EXPECT_CALL(*gl_, GetError())
898 .WillOnce(Return(GL_NO_ERROR))
899 .RetiresOnSaturation();
900 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
901 target, attachment, renderbuffer_target, renderbuffer_service_id))
903 .RetiresOnSaturation();
904 EXPECT_CALL(*gl_, GetError())
905 .WillOnce(Return(error))
906 .RetiresOnSaturation();
907 cmds::FramebufferRenderbuffer cmd;
908 cmd.Init(target, attachment, renderbuffer_target, renderbuffer_client_id);
909 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
912 void GLES2DecoderTestBase::DoVertexAttribPointer(
913 GLuint index, GLint size, GLenum type, GLsizei stride, GLuint offset) {
915 VertexAttribPointer(index, size, type, GL_FALSE, stride,
916 BufferOffset(offset)))
918 .RetiresOnSaturation();
919 cmds::VertexAttribPointer cmd;
920 cmd.Init(index, size, GL_FLOAT, GL_FALSE, stride, offset);
921 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
924 void GLES2DecoderTestBase::DoVertexAttribDivisorANGLE(
925 GLuint index, GLuint divisor) {
927 VertexAttribDivisorANGLE(index, divisor))
929 .RetiresOnSaturation();
930 cmds::VertexAttribDivisorANGLE cmd;
931 cmd.Init(index, divisor);
932 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
935 void GLES2DecoderTestBase::AddExpectationsForGenVertexArraysOES(){
936 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
937 EXPECT_CALL(*gl_, GenVertexArraysOES(1, _))
938 .WillOnce(SetArgumentPointee<1>(kServiceVertexArrayId))
939 .RetiresOnSaturation();
943 void GLES2DecoderTestBase::AddExpectationsForDeleteVertexArraysOES(){
944 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
945 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, _))
947 .RetiresOnSaturation();
951 void GLES2DecoderTestBase::AddExpectationsForBindVertexArrayOES() {
952 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
953 EXPECT_CALL(*gl_, BindVertexArrayOES(_))
955 .RetiresOnSaturation();
957 for (uint32 vv = 0; vv < group_->max_vertex_attribs(); ++vv) {
958 AddExpectationsForRestoreAttribState(vv);
961 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _))
963 .RetiresOnSaturation();
967 void GLES2DecoderTestBase::AddExpectationsForRestoreAttribState(GLuint attrib) {
968 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
970 .RetiresOnSaturation();
972 EXPECT_CALL(*gl_, VertexAttribPointer(attrib, _, _, _, _, _))
974 .RetiresOnSaturation();
976 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(attrib, _))
977 .Times(testing::AtMost(1))
978 .RetiresOnSaturation();
980 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
982 .RetiresOnSaturation();
985 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
987 // TODO(bajones): Not sure if I can tell which of these will be called
988 EXPECT_CALL(*gl_, EnableVertexAttribArray(attrib))
989 .Times(testing::AtMost(1))
990 .RetiresOnSaturation();
992 EXPECT_CALL(*gl_, DisableVertexAttribArray(attrib))
993 .Times(testing::AtMost(1))
994 .RetiresOnSaturation();
998 // GCC requires these declarations, but MSVC requires they not be present
999 #ifndef COMPILER_MSVC
1000 const int GLES2DecoderTestBase::kBackBufferWidth;
1001 const int GLES2DecoderTestBase::kBackBufferHeight;
1003 const GLint GLES2DecoderTestBase::kMaxTextureSize;
1004 const GLint GLES2DecoderTestBase::kMaxCubeMapTextureSize;
1005 const GLint GLES2DecoderTestBase::kNumVertexAttribs;
1006 const GLint GLES2DecoderTestBase::kNumTextureUnits;
1007 const GLint GLES2DecoderTestBase::kMaxTextureImageUnits;
1008 const GLint GLES2DecoderTestBase::kMaxVertexTextureImageUnits;
1009 const GLint GLES2DecoderTestBase::kMaxFragmentUniformVectors;
1010 const GLint GLES2DecoderTestBase::kMaxVaryingVectors;
1011 const GLint GLES2DecoderTestBase::kMaxVertexUniformVectors;
1012 const GLint GLES2DecoderTestBase::kMaxViewportWidth;
1013 const GLint GLES2DecoderTestBase::kMaxViewportHeight;
1015 const GLint GLES2DecoderTestBase::kViewportX;
1016 const GLint GLES2DecoderTestBase::kViewportY;
1017 const GLint GLES2DecoderTestBase::kViewportWidth;
1018 const GLint GLES2DecoderTestBase::kViewportHeight;
1020 const GLuint GLES2DecoderTestBase::kServiceAttrib0BufferId;
1021 const GLuint GLES2DecoderTestBase::kServiceFixedAttribBufferId;
1023 const GLuint GLES2DecoderTestBase::kServiceBufferId;
1024 const GLuint GLES2DecoderTestBase::kServiceFramebufferId;
1025 const GLuint GLES2DecoderTestBase::kServiceRenderbufferId;
1026 const GLuint GLES2DecoderTestBase::kServiceTextureId;
1027 const GLuint GLES2DecoderTestBase::kServiceProgramId;
1028 const GLuint GLES2DecoderTestBase::kServiceShaderId;
1029 const GLuint GLES2DecoderTestBase::kServiceElementBufferId;
1030 const GLuint GLES2DecoderTestBase::kServiceQueryId;
1031 const GLuint GLES2DecoderTestBase::kServiceVertexArrayId;
1033 const int32 GLES2DecoderTestBase::kSharedMemoryId;
1034 const size_t GLES2DecoderTestBase::kSharedBufferSize;
1035 const uint32 GLES2DecoderTestBase::kSharedMemoryOffset;
1036 const int32 GLES2DecoderTestBase::kInvalidSharedMemoryId;
1037 const uint32 GLES2DecoderTestBase::kInvalidSharedMemoryOffset;
1038 const uint32 GLES2DecoderTestBase::kInitialResult;
1039 const uint8 GLES2DecoderTestBase::kInitialMemoryValue;
1041 const uint32 GLES2DecoderTestBase::kNewClientId;
1042 const uint32 GLES2DecoderTestBase::kNewServiceId;
1043 const uint32 GLES2DecoderTestBase::kInvalidClientId;
1045 const GLuint GLES2DecoderTestBase::kServiceVertexShaderId;
1046 const GLuint GLES2DecoderTestBase::kServiceFragmentShaderId;
1048 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumShaderId;
1049 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumProgramId;
1051 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTextureBufferId;
1052 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumVertexBufferId;
1053 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumFBOId;
1054 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumPositionAttrib;
1055 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTexAttrib;
1056 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumSamplerLocation;
1058 const GLsizei GLES2DecoderTestBase::kNumVertices;
1059 const GLsizei GLES2DecoderTestBase::kNumIndices;
1060 const int GLES2DecoderTestBase::kValidIndexRangeStart;
1061 const int GLES2DecoderTestBase::kValidIndexRangeCount;
1062 const int GLES2DecoderTestBase::kInvalidIndexRangeStart;
1063 const int GLES2DecoderTestBase::kInvalidIndexRangeCount;
1064 const int GLES2DecoderTestBase::kOutOfRangeIndexRangeEnd;
1065 const GLuint GLES2DecoderTestBase::kMaxValidIndex;
1067 const GLint GLES2DecoderTestBase::kMaxAttribLength;
1068 const GLint GLES2DecoderTestBase::kAttrib1Size;
1069 const GLint GLES2DecoderTestBase::kAttrib2Size;
1070 const GLint GLES2DecoderTestBase::kAttrib3Size;
1071 const GLint GLES2DecoderTestBase::kAttrib1Location;
1072 const GLint GLES2DecoderTestBase::kAttrib2Location;
1073 const GLint GLES2DecoderTestBase::kAttrib3Location;
1074 const GLenum GLES2DecoderTestBase::kAttrib1Type;
1075 const GLenum GLES2DecoderTestBase::kAttrib2Type;
1076 const GLenum GLES2DecoderTestBase::kAttrib3Type;
1077 const GLint GLES2DecoderTestBase::kInvalidAttribLocation;
1078 const GLint GLES2DecoderTestBase::kBadAttribIndex;
1080 const GLint GLES2DecoderTestBase::kMaxUniformLength;
1081 const GLint GLES2DecoderTestBase::kUniform1Size;
1082 const GLint GLES2DecoderTestBase::kUniform2Size;
1083 const GLint GLES2DecoderTestBase::kUniform3Size;
1084 const GLint GLES2DecoderTestBase::kUniform1RealLocation;
1085 const GLint GLES2DecoderTestBase::kUniform2RealLocation;
1086 const GLint GLES2DecoderTestBase::kUniform2ElementRealLocation;
1087 const GLint GLES2DecoderTestBase::kUniform3RealLocation;
1088 const GLint GLES2DecoderTestBase::kUniform1FakeLocation;
1089 const GLint GLES2DecoderTestBase::kUniform2FakeLocation;
1090 const GLint GLES2DecoderTestBase::kUniform2ElementFakeLocation;
1091 const GLint GLES2DecoderTestBase::kUniform3FakeLocation;
1092 const GLint GLES2DecoderTestBase::kUniform1DesiredLocation;
1093 const GLint GLES2DecoderTestBase::kUniform2DesiredLocation;
1094 const GLint GLES2DecoderTestBase::kUniform3DesiredLocation;
1095 const GLenum GLES2DecoderTestBase::kUniform1Type;
1096 const GLenum GLES2DecoderTestBase::kUniform2Type;
1097 const GLenum GLES2DecoderTestBase::kUniform3Type;
1098 const GLenum GLES2DecoderTestBase::kUniformCubemapType;
1099 const GLint GLES2DecoderTestBase::kInvalidUniformLocation;
1100 const GLint GLES2DecoderTestBase::kBadUniformIndex;
1104 const char* GLES2DecoderTestBase::kAttrib1Name = "attrib1";
1105 const char* GLES2DecoderTestBase::kAttrib2Name = "attrib2";
1106 const char* GLES2DecoderTestBase::kAttrib3Name = "attrib3";
1107 const char* GLES2DecoderTestBase::kUniform1Name = "uniform1";
1108 const char* GLES2DecoderTestBase::kUniform2Name = "uniform2[0]";
1109 const char* GLES2DecoderTestBase::kUniform3Name = "uniform3[0]";
1111 void GLES2DecoderTestBase::SetupDefaultProgram() {
1113 static AttribInfo attribs[] = {
1114 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1115 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1116 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1118 static UniformInfo uniforms[] = {
1119 { kUniform1Name, kUniform1Size, kUniform1Type,
1120 kUniform1FakeLocation, kUniform1RealLocation,
1121 kUniform1DesiredLocation },
1122 { kUniform2Name, kUniform2Size, kUniform2Type,
1123 kUniform2FakeLocation, kUniform2RealLocation,
1124 kUniform2DesiredLocation },
1125 { kUniform3Name, kUniform3Size, kUniform3Type,
1126 kUniform3FakeLocation, kUniform3RealLocation,
1127 kUniform3DesiredLocation },
1129 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1130 client_program_id_, kServiceProgramId,
1131 client_vertex_shader_id_, kServiceVertexShaderId,
1132 client_fragment_shader_id_, kServiceFragmentShaderId);
1136 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1138 .RetiresOnSaturation();
1139 cmds::UseProgram cmd;
1140 cmd.Init(client_program_id_);
1141 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1145 void GLES2DecoderTestBase::SetupCubemapProgram() {
1147 static AttribInfo attribs[] = {
1148 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1149 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1150 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1152 static UniformInfo uniforms[] = {
1153 { kUniform1Name, kUniform1Size, kUniformCubemapType,
1154 kUniform1FakeLocation, kUniform1RealLocation,
1155 kUniform1DesiredLocation, },
1156 { kUniform2Name, kUniform2Size, kUniform2Type,
1157 kUniform2FakeLocation, kUniform2RealLocation,
1158 kUniform2DesiredLocation, },
1159 { kUniform3Name, kUniform3Size, kUniform3Type,
1160 kUniform3FakeLocation, kUniform3RealLocation,
1161 kUniform3DesiredLocation, },
1163 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1164 client_program_id_, kServiceProgramId,
1165 client_vertex_shader_id_, kServiceVertexShaderId,
1166 client_fragment_shader_id_, kServiceFragmentShaderId);
1170 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1172 .RetiresOnSaturation();
1173 cmds::UseProgram cmd;
1174 cmd.Init(client_program_id_);
1175 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1179 void GLES2DecoderTestBase::SetupSamplerExternalProgram() {
1181 static AttribInfo attribs[] = {
1182 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1183 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1184 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1186 static UniformInfo uniforms[] = {
1187 { kUniform1Name, kUniform1Size, kUniformSamplerExternalType,
1188 kUniform1FakeLocation, kUniform1RealLocation,
1189 kUniform1DesiredLocation, },
1190 { kUniform2Name, kUniform2Size, kUniform2Type,
1191 kUniform2FakeLocation, kUniform2RealLocation,
1192 kUniform2DesiredLocation, },
1193 { kUniform3Name, kUniform3Size, kUniform3Type,
1194 kUniform3FakeLocation, kUniform3RealLocation,
1195 kUniform3DesiredLocation, },
1197 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1198 client_program_id_, kServiceProgramId,
1199 client_vertex_shader_id_, kServiceVertexShaderId,
1200 client_fragment_shader_id_, kServiceFragmentShaderId);
1204 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1206 .RetiresOnSaturation();
1207 cmds::UseProgram cmd;
1208 cmd.Init(client_program_id_);
1209 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1213 void GLES2DecoderWithShaderTestBase::TearDown() {
1214 GLES2DecoderTestBase::TearDown();
1217 void GLES2DecoderTestBase::SetupShader(
1218 GLES2DecoderTestBase::AttribInfo* attribs, size_t num_attribs,
1219 GLES2DecoderTestBase::UniformInfo* uniforms, size_t num_uniforms,
1220 GLuint program_client_id, GLuint program_service_id,
1221 GLuint vertex_shader_client_id, GLuint vertex_shader_service_id,
1222 GLuint fragment_shader_client_id, GLuint fragment_shader_service_id) {
1227 AttachShader(program_service_id, vertex_shader_service_id))
1229 .RetiresOnSaturation();
1231 AttachShader(program_service_id, fragment_shader_service_id))
1233 .RetiresOnSaturation();
1234 TestHelper::SetupShader(
1235 gl_.get(), attribs, num_attribs, uniforms, num_uniforms,
1236 program_service_id);
1240 GL_VERTEX_SHADER, vertex_shader_client_id, vertex_shader_service_id);
1242 GL_FRAGMENT_SHADER, fragment_shader_client_id,
1243 fragment_shader_service_id);
1245 GetShader(vertex_shader_client_id)->SetStatus(true, "", NULL);
1246 GetShader(fragment_shader_client_id)->SetStatus(true, "", NULL);
1248 cmds::AttachShader attach_cmd;
1249 attach_cmd.Init(program_client_id, vertex_shader_client_id);
1250 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1252 attach_cmd.Init(program_client_id, fragment_shader_client_id);
1253 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1255 cmds::LinkProgram link_cmd;
1256 link_cmd.Init(program_client_id);
1258 EXPECT_EQ(error::kNoError, ExecuteCmd(link_cmd));
1260 // Assume the next command will be UseProgram.
1261 SetupExpectationsForClearingUniforms(uniforms, num_uniforms);
1264 void GLES2DecoderTestBase::DoEnableVertexAttribArray(GLint index) {
1265 EXPECT_CALL(*gl_, EnableVertexAttribArray(index))
1267 .RetiresOnSaturation();
1268 cmds::EnableVertexAttribArray cmd;
1270 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1273 void GLES2DecoderTestBase::DoBufferData(GLenum target, GLsizei size) {
1274 EXPECT_CALL(*gl_, GetError())
1275 .WillOnce(Return(GL_NO_ERROR))
1276 .RetiresOnSaturation();
1277 EXPECT_CALL(*gl_, BufferData(target, size, _, GL_STREAM_DRAW))
1279 .RetiresOnSaturation();
1280 EXPECT_CALL(*gl_, GetError())
1281 .WillOnce(Return(GL_NO_ERROR))
1282 .RetiresOnSaturation();
1283 cmds::BufferData cmd;
1284 cmd.Init(target, size, 0, 0, GL_STREAM_DRAW);
1285 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1288 void GLES2DecoderTestBase::DoBufferSubData(
1289 GLenum target, GLint offset, GLsizei size, const void* data) {
1290 EXPECT_CALL(*gl_, BufferSubData(target, offset, size,
1291 shared_memory_address_))
1293 .RetiresOnSaturation();
1294 memcpy(shared_memory_address_, data, size);
1295 cmds::BufferSubData cmd;
1296 cmd.Init(target, offset, size, shared_memory_id_, shared_memory_offset_);
1297 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1300 void GLES2DecoderTestBase::SetupVertexBuffer() {
1301 DoEnableVertexAttribArray(1);
1302 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1304 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 2 * sizeof(f));
1307 void GLES2DecoderTestBase::SetupAllNeededVertexBuffers() {
1308 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1309 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 16 * sizeof(float));
1310 DoEnableVertexAttribArray(0);
1311 DoEnableVertexAttribArray(1);
1312 DoEnableVertexAttribArray(2);
1313 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1314 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1315 DoVertexAttribPointer(2, 2, GL_FLOAT, 0, 0);
1318 void GLES2DecoderTestBase::SetupIndexBuffer() {
1319 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
1320 client_element_buffer_id_,
1321 kServiceElementBufferId);
1322 static const GLshort indices[] = {100, 1, 2, 3, 4, 5, 6, 7, 100, 9};
1323 COMPILE_ASSERT(arraysize(indices) == kNumIndices, Indices_is_not_10);
1324 DoBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices));
1325 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, 2, indices);
1326 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 2, sizeof(indices) - 2, &indices[1]);
1329 void GLES2DecoderTestBase::SetupTexture() {
1330 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1331 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1332 kSharedMemoryId, kSharedMemoryOffset);
1335 void GLES2DecoderTestBase::DeleteVertexBuffer() {
1336 DoDeleteBuffer(client_buffer_id_, kServiceBufferId);
1339 void GLES2DecoderTestBase::DeleteIndexBuffer() {
1340 DoDeleteBuffer(client_element_buffer_id_, kServiceElementBufferId);
1343 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0WithError(
1344 GLsizei num_vertices, GLuint buffer_id, GLenum error) {
1345 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
1349 EXPECT_CALL(*gl_, GetError())
1350 .WillOnce(Return(GL_NO_ERROR))
1351 .WillOnce(Return(error))
1352 .RetiresOnSaturation();
1353 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
1355 .RetiresOnSaturation();
1356 EXPECT_CALL(*gl_, BufferData(GL_ARRAY_BUFFER,
1357 num_vertices * sizeof(GLfloat) * 4,
1358 _, GL_DYNAMIC_DRAW))
1360 .RetiresOnSaturation();
1361 if (error == GL_NO_ERROR) {
1362 EXPECT_CALL(*gl_, BufferSubData(
1363 GL_ARRAY_BUFFER, 0, num_vertices * sizeof(GLfloat) * 4, _))
1365 .RetiresOnSaturation();
1366 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL))
1368 .RetiresOnSaturation();
1369 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
1371 .RetiresOnSaturation();
1372 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL))
1374 .RetiresOnSaturation();
1375 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, buffer_id))
1377 .RetiresOnSaturation();
1381 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0(
1382 GLsizei num_vertices, GLuint buffer_id) {
1383 AddExpectationsForSimulatedAttrib0WithError(
1384 num_vertices, buffer_id, GL_NO_ERROR);
1387 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1388 MockCommandBufferEngine() {
1389 data_.reset(new int8[kSharedBufferSize]);
1390 ClearSharedMemory();
1391 valid_buffer_.ptr = data_.get();
1392 valid_buffer_.size = kSharedBufferSize;
1395 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1396 ~MockCommandBufferEngine() {}
1399 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetSharedMemoryBuffer(
1401 return shm_id == kSharedMemoryId ? valid_buffer_ : invalid_buffer_;
1404 void GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::set_token(
1409 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetBuffer(
1410 int32 /* transfer_buffer_id */) {
1415 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetOffset(
1421 int32 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetGetOffset() {
1426 void GLES2DecoderWithShaderTestBase::SetUp() {
1427 GLES2DecoderTestBase::SetUp();
1428 SetupDefaultProgram();
1431 // Include the auto-generated part of this file. We split this because it means
1432 // we can easily edit the non-auto generated parts right here in this file
1433 // instead of having to edit some template or the code generator.
1434 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h"
1436 } // namespace gles2