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 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));
137 // These two workarounds are always turned on.
138 group_->feature_info(
139 )->workarounds_.set_texture_filter_before_generating_mipmap = true;
140 group_->feature_info()->workarounds_.clear_alpha_in_readpixels = true;
144 surface_ = new gfx::GLSurfaceStub;
145 surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight));
147 // Context needs to be created before initializing ContextGroup, which will
148 // in turn initialize FeatureInfo, which needs a context to determine
149 // extension support.
150 context_ = new gfx::GLContextStubWithExtensions;
151 context_->AddExtensionsString(extensions);
152 context_->SetGLVersionString(gl_version);
154 context_->MakeCurrent(surface_.get());
155 gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_);
157 TestHelper::SetupContextGroupInitExpectations(gl_.get(),
158 DisallowedFeatures(), extensions, gl_version);
160 // We initialize the ContextGroup with a MockGLES2Decoder so that
161 // we can use the ContextGroup to figure out how the real GLES2Decoder
162 // will initialize itself.
163 mock_decoder_.reset(new MockGLES2Decoder());
165 group_->Initialize(mock_decoder_.get(), DisallowedFeatures()));
167 AddExpectationsForVertexAttribManager();
169 AddExpectationsForBindVertexArrayOES();
171 EXPECT_CALL(*gl_, EnableVertexAttribArray(0))
173 .RetiresOnSaturation();
174 static GLuint attrib_0_id[] = {
175 kServiceAttrib0BufferId,
177 static GLuint fixed_attrib_buffer_id[] = {
178 kServiceFixedAttribBufferId,
180 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(attrib_0_id), _))
181 .WillOnce(SetArrayArgument<1>(attrib_0_id,
182 attrib_0_id + arraysize(attrib_0_id)))
183 .RetiresOnSaturation();
184 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
186 .RetiresOnSaturation();
187 EXPECT_CALL(*gl_, VertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL))
189 .RetiresOnSaturation();
190 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
192 .RetiresOnSaturation();
193 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(fixed_attrib_buffer_id), _))
194 .WillOnce(SetArrayArgument<1>(
195 fixed_attrib_buffer_id,
196 fixed_attrib_buffer_id + arraysize(fixed_attrib_buffer_id)))
197 .RetiresOnSaturation();
199 for (GLint tt = 0; tt < TestHelper::kNumTextureUnits; ++tt) {
200 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0 + tt))
202 .RetiresOnSaturation();
203 if (group_->feature_info()->feature_flags().oes_egl_image_external) {
204 EXPECT_CALL(*gl_, BindTexture(
205 GL_TEXTURE_EXTERNAL_OES,
206 TestHelper::kServiceDefaultExternalTextureId))
208 .RetiresOnSaturation();
210 if (group_->feature_info()->feature_flags().arb_texture_rectangle) {
211 EXPECT_CALL(*gl_, BindTexture(
212 GL_TEXTURE_RECTANGLE_ARB,
213 TestHelper::kServiceDefaultRectangleTextureId))
215 .RetiresOnSaturation();
217 EXPECT_CALL(*gl_, BindTexture(
218 GL_TEXTURE_CUBE_MAP, TestHelper::kServiceDefaultTextureCubemapId))
220 .RetiresOnSaturation();
221 EXPECT_CALL(*gl_, BindTexture(
222 GL_TEXTURE_2D, TestHelper::kServiceDefaultTexture2dId))
224 .RetiresOnSaturation();
226 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
228 .RetiresOnSaturation();
230 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
232 .RetiresOnSaturation();
233 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _))
234 .WillOnce(SetArgumentPointee<1>(has_alpha ? 8 : 0))
235 .RetiresOnSaturation();
236 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
237 .WillOnce(SetArgumentPointee<1>(has_depth ? 24 : 0))
238 .RetiresOnSaturation();
239 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
240 .WillOnce(SetArgumentPointee<1>(has_stencil ? 8 : 0))
241 .RetiresOnSaturation();
243 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE))
245 .RetiresOnSaturation();
247 EXPECT_CALL(*gl_, Enable(GL_POINT_SPRITE))
249 .RetiresOnSaturation();
251 static GLint max_viewport_dims[] = {
255 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VIEWPORT_DIMS, _))
256 .WillOnce(SetArrayArgument<1>(
257 max_viewport_dims, max_viewport_dims + arraysize(max_viewport_dims)))
258 .RetiresOnSaturation();
260 SetupInitCapabilitiesExpectations();
261 SetupInitStateExpectations();
263 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
265 .RetiresOnSaturation();
267 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
269 .RetiresOnSaturation();
270 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0))
272 .RetiresOnSaturation();
273 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
275 .RetiresOnSaturation();
276 EXPECT_CALL(*gl_, BindRenderbufferEXT(GL_RENDERBUFFER, 0))
278 .RetiresOnSaturation();
280 // TODO(boliu): Remove OS_ANDROID once crbug.com/259023 is fixed and the
281 // workaround has been reverted.
282 #if !defined(OS_ANDROID)
283 EXPECT_CALL(*gl_, Clear(
284 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
286 .RetiresOnSaturation();
289 engine_.reset(new StrictMock<MockCommandBufferEngine>());
290 gpu::Buffer buffer = engine_->GetSharedMemoryBuffer(kSharedMemoryId);
291 shared_memory_offset_ = kSharedMemoryOffset;
292 shared_memory_address_ = reinterpret_cast<int8*>(buffer.ptr) +
293 shared_memory_offset_;
294 shared_memory_id_ = kSharedMemoryId;
295 shared_memory_base_ = buffer.ptr;
297 int32 attributes[] = {
298 EGL_ALPHA_SIZE, request_alpha ? 8 : 0,
299 EGL_DEPTH_SIZE, request_depth ? 24 : 0,
300 EGL_STENCIL_SIZE, request_stencil ? 8 : 0,
302 std::vector<int32> attribs(attributes, attributes + arraysize(attributes));
304 decoder_.reset(GLES2Decoder::Create(group_.get()));
305 decoder_->GetLogger()->set_log_synthesized_gl_errors(false);
306 decoder_->Initialize(surface_,
310 DisallowedFeatures(),
312 decoder_->MakeCurrent();
313 decoder_->set_engine(engine_.get());
314 decoder_->BeginDecoding();
316 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
317 .WillOnce(SetArgumentPointee<1>(kServiceBufferId))
318 .RetiresOnSaturation();
319 GenHelper<cmds::GenBuffersImmediate>(client_buffer_id_);
320 EXPECT_CALL(*gl_, GenFramebuffersEXT(_, _))
321 .WillOnce(SetArgumentPointee<1>(kServiceFramebufferId))
322 .RetiresOnSaturation();
323 GenHelper<cmds::GenFramebuffersImmediate>(client_framebuffer_id_);
324 EXPECT_CALL(*gl_, GenRenderbuffersEXT(_, _))
325 .WillOnce(SetArgumentPointee<1>(kServiceRenderbufferId))
326 .RetiresOnSaturation();
327 GenHelper<cmds::GenRenderbuffersImmediate>(client_renderbuffer_id_);
328 EXPECT_CALL(*gl_, GenTextures(_, _))
329 .WillOnce(SetArgumentPointee<1>(kServiceTextureId))
330 .RetiresOnSaturation();
331 GenHelper<cmds::GenTexturesImmediate>(client_texture_id_);
332 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
333 .WillOnce(SetArgumentPointee<1>(kServiceElementBufferId))
334 .RetiresOnSaturation();
335 GenHelper<cmds::GenBuffersImmediate>(client_element_buffer_id_);
337 DoCreateProgram(client_program_id_, kServiceProgramId);
338 DoCreateShader(GL_VERTEX_SHADER, client_shader_id_, kServiceShaderId);
340 EXPECT_EQ(GL_NO_ERROR, GetGLError());
343 void GLES2DecoderTestBase::TearDown() {
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::ExpectEnableDisable(GLenum cap, bool enable) {
362 EXPECT_CALL(*gl_, Enable(cap))
364 .RetiresOnSaturation();
366 EXPECT_CALL(*gl_, Disable(cap))
368 .RetiresOnSaturation();
373 GLint GLES2DecoderTestBase::GetGLError() {
374 EXPECT_CALL(*gl_, GetError())
375 .WillOnce(Return(GL_NO_ERROR))
376 .RetiresOnSaturation();
378 cmd.Init(shared_memory_id_, shared_memory_offset_);
379 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
380 return static_cast<GLint>(*GetSharedMemoryAs<GLenum*>());
383 void GLES2DecoderTestBase::DoCreateShader(
384 GLenum shader_type, GLuint client_id, GLuint service_id) {
385 EXPECT_CALL(*gl_, CreateShader(shader_type))
387 .WillOnce(Return(service_id))
388 .RetiresOnSaturation();
389 cmds::CreateShader cmd;
390 cmd.Init(shader_type, client_id);
391 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
394 bool GLES2DecoderTestBase::DoIsShader(GLuint client_id) {
395 return IsObjectHelper<cmds::IsShader, cmds::IsShader::Result>(client_id);
398 void GLES2DecoderTestBase::DoDeleteShader(
399 GLuint client_id, GLuint service_id) {
400 EXPECT_CALL(*gl_, DeleteShader(service_id))
402 .RetiresOnSaturation();
403 cmds::DeleteShader cmd;
405 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
408 void GLES2DecoderTestBase::DoCreateProgram(
409 GLuint client_id, GLuint service_id) {
410 EXPECT_CALL(*gl_, CreateProgram())
412 .WillOnce(Return(service_id))
413 .RetiresOnSaturation();
414 cmds::CreateProgram cmd;
416 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
419 bool GLES2DecoderTestBase::DoIsProgram(GLuint client_id) {
420 return IsObjectHelper<cmds::IsProgram, cmds::IsProgram::Result>(client_id);
423 void GLES2DecoderTestBase::DoDeleteProgram(
424 GLuint client_id, GLuint /* service_id */) {
425 cmds::DeleteProgram cmd;
427 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
430 void GLES2DecoderTestBase::SetBucketAsCString(
431 uint32 bucket_id, const char* str) {
432 uint32 size = str ? (strlen(str) + 1) : 0;
433 cmd::SetBucketSize cmd1;
434 cmd1.Init(bucket_id, size);
435 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
437 memcpy(shared_memory_address_, str, size);
438 cmd::SetBucketData cmd2;
439 cmd2.Init(bucket_id, 0, size, kSharedMemoryId, kSharedMemoryOffset);
440 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
445 void GLES2DecoderTestBase::SetupClearTextureExpections(
447 GLuint old_service_id,
455 EXPECT_CALL(*gl_, BindTexture(bind_target, service_id))
457 .RetiresOnSaturation();
458 EXPECT_CALL(*gl_, TexImage2D(
459 target, level, format, width, height, 0, format, type, _))
461 .RetiresOnSaturation();
462 EXPECT_CALL(*gl_, BindTexture(bind_target, old_service_id))
464 .RetiresOnSaturation();
467 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearing(
470 GLclampf restore_red,
471 GLclampf restore_green,
472 GLclampf restore_blue,
473 GLclampf restore_alpha,
474 GLuint restore_stencil,
475 GLclampf restore_depth,
476 bool restore_scissor_test) {
477 SetupExpectationsForFramebufferClearingMulti(
488 restore_scissor_test);
491 void GLES2DecoderTestBase::SetupExpectationsForRestoreClearState(
492 GLclampf restore_red,
493 GLclampf restore_green,
494 GLclampf restore_blue,
495 GLclampf restore_alpha,
496 GLuint restore_stencil,
497 GLclampf restore_depth,
498 bool restore_scissor_test) {
499 EXPECT_CALL(*gl_, ClearColor(
500 restore_red, restore_green, restore_blue, restore_alpha))
502 .RetiresOnSaturation();
503 EXPECT_CALL(*gl_, ClearStencil(restore_stencil))
505 .RetiresOnSaturation();
506 EXPECT_CALL(*gl_, ClearDepth(restore_depth))
508 .RetiresOnSaturation();
509 if (restore_scissor_test) {
510 EXPECT_CALL(*gl_, Enable(GL_SCISSOR_TEST))
512 .RetiresOnSaturation();
516 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearingMulti(
517 GLuint read_framebuffer_service_id,
518 GLuint draw_framebuffer_service_id,
521 GLclampf restore_red,
522 GLclampf restore_green,
523 GLclampf restore_blue,
524 GLclampf restore_alpha,
525 GLuint restore_stencil,
526 GLclampf restore_depth,
527 bool restore_scissor_test) {
528 // TODO(gman): Figure out why InSequence stopped working.
529 // InSequence sequence;
530 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(target))
531 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
532 .RetiresOnSaturation();
533 if (target == GL_READ_FRAMEBUFFER_EXT) {
534 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0))
536 .RetiresOnSaturation();
537 EXPECT_CALL(*gl_, BindFramebufferEXT(
538 GL_DRAW_FRAMEBUFFER_EXT, read_framebuffer_service_id))
540 .RetiresOnSaturation();
542 if ((clear_bits & GL_COLOR_BUFFER_BIT) != 0) {
543 EXPECT_CALL(*gl_, ClearColor(0.0f, 0.0f, 0.0f, 0.0f))
545 .RetiresOnSaturation();
546 EXPECT_CALL(*gl_, ColorMask(true, true, true, true))
548 .RetiresOnSaturation();
550 if ((clear_bits & GL_STENCIL_BUFFER_BIT) != 0) {
551 EXPECT_CALL(*gl_, ClearStencil(0))
553 .RetiresOnSaturation();
554 EXPECT_CALL(*gl_, StencilMask(static_cast<GLuint>(-1)))
556 .RetiresOnSaturation();
558 if ((clear_bits & GL_DEPTH_BUFFER_BIT) != 0) {
559 EXPECT_CALL(*gl_, ClearDepth(1.0f))
561 .RetiresOnSaturation();
562 EXPECT_CALL(*gl_, DepthMask(1))
564 .RetiresOnSaturation();
566 EXPECT_CALL(*gl_, Disable(GL_SCISSOR_TEST))
568 .RetiresOnSaturation();
569 EXPECT_CALL(*gl_, Clear(clear_bits))
571 .RetiresOnSaturation();
572 SetupExpectationsForRestoreClearState(
573 restore_red, restore_green, restore_blue, restore_alpha,
574 restore_stencil, restore_depth, restore_scissor_test);
575 if (target == GL_READ_FRAMEBUFFER_EXT) {
576 EXPECT_CALL(*gl_, BindFramebufferEXT(
577 GL_READ_FRAMEBUFFER_EXT, read_framebuffer_service_id))
579 .RetiresOnSaturation();
580 EXPECT_CALL(*gl_, BindFramebufferEXT(
581 GL_DRAW_FRAMEBUFFER_EXT, draw_framebuffer_service_id))
583 .RetiresOnSaturation();
587 void GLES2DecoderTestBase::SetupShaderForUniform(GLenum uniform_type) {
588 static AttribInfo attribs[] = {
589 { "foo", 1, GL_FLOAT, 1, },
590 { "goo", 1, GL_FLOAT, 2, },
592 UniformInfo uniforms[] = {
593 { "bar", 1, uniform_type, 0, 2, -1, },
594 { "car", 4, uniform_type, 1, 1, -1, },
596 const GLuint kClientVertexShaderId = 5001;
597 const GLuint kServiceVertexShaderId = 6001;
598 const GLuint kClientFragmentShaderId = 5002;
599 const GLuint kServiceFragmentShaderId = 6002;
600 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
601 client_program_id_, kServiceProgramId,
602 kClientVertexShaderId, kServiceVertexShaderId,
603 kClientFragmentShaderId, kServiceFragmentShaderId);
605 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
607 .RetiresOnSaturation();
608 cmds::UseProgram cmd;
609 cmd.Init(client_program_id_);
610 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
613 void GLES2DecoderTestBase::DoBindBuffer(
614 GLenum target, GLuint client_id, GLuint service_id) {
615 EXPECT_CALL(*gl_, BindBuffer(target, service_id))
617 .RetiresOnSaturation();
618 cmds::BindBuffer cmd;
619 cmd.Init(target, client_id);
620 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
623 bool GLES2DecoderTestBase::DoIsBuffer(GLuint client_id) {
624 return IsObjectHelper<cmds::IsBuffer, cmds::IsBuffer::Result>(client_id);
627 void GLES2DecoderTestBase::DoDeleteBuffer(
628 GLuint client_id, GLuint service_id) {
629 EXPECT_CALL(*gl_, DeleteBuffersARB(1, Pointee(service_id)))
631 .RetiresOnSaturation();
632 cmds::DeleteBuffers cmd;
633 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
634 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
635 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
638 void GLES2DecoderTestBase::SetupExpectationsForApplyingDirtyState(
639 bool framebuffer_is_rgb,
640 bool framebuffer_has_depth,
641 bool framebuffer_has_stencil,
645 GLuint front_stencil_mask,
646 GLuint back_stencil_mask,
647 bool stencil_enabled,
648 bool cull_face_enabled,
649 bool scissor_test_enabled,
650 bool blend_enabled) {
651 EXPECT_CALL(*gl_, ColorMask(
652 (color_bits & 0x1000) != 0,
653 (color_bits & 0x0100) != 0,
654 (color_bits & 0x0010) != 0,
655 (color_bits & 0x0001) && !framebuffer_is_rgb))
657 .RetiresOnSaturation();
658 EXPECT_CALL(*gl_, DepthMask(depth_mask))
660 .RetiresOnSaturation();
661 if (framebuffer_has_depth && depth_enabled) {
662 EXPECT_CALL(*gl_, Enable(GL_DEPTH_TEST))
664 .RetiresOnSaturation();
666 EXPECT_CALL(*gl_, Disable(GL_DEPTH_TEST))
668 .RetiresOnSaturation();
670 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_FRONT, front_stencil_mask))
672 .RetiresOnSaturation();
673 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_BACK, back_stencil_mask))
675 .RetiresOnSaturation();
676 if (framebuffer_has_stencil && stencil_enabled) {
677 EXPECT_CALL(*gl_, Enable(GL_STENCIL_TEST))
679 .RetiresOnSaturation();
681 EXPECT_CALL(*gl_, Disable(GL_STENCIL_TEST))
683 .RetiresOnSaturation();
685 if (cull_face_enabled) {
686 EXPECT_CALL(*gl_, Enable(GL_CULL_FACE))
688 .RetiresOnSaturation();
690 EXPECT_CALL(*gl_, Disable(GL_CULL_FACE))
692 .RetiresOnSaturation();
694 if (scissor_test_enabled) {
695 EXPECT_CALL(*gl_, Enable(GL_SCISSOR_TEST))
697 .RetiresOnSaturation();
699 EXPECT_CALL(*gl_, Disable(GL_SCISSOR_TEST))
701 .RetiresOnSaturation();
704 EXPECT_CALL(*gl_, Enable(GL_BLEND))
706 .RetiresOnSaturation();
708 EXPECT_CALL(*gl_, Disable(GL_BLEND))
710 .RetiresOnSaturation();
714 void GLES2DecoderTestBase::SetupExpectationsForApplyingDefaultDirtyState() {
715 SetupExpectationsForApplyingDirtyState(
716 false, // Framebuffer is RGB
717 false, // Framebuffer has depth
718 false, // Framebuffer has stencil
719 0x1111, // color bits
721 false, // depth enabled
722 0, // front stencil mask
723 0, // back stencil mask
724 false, // stencil enabled
725 false, // cull_face_enabled
726 false, // scissor_test_enabled
727 false); // blend_enabled
730 void GLES2DecoderTestBase::DoBindFramebuffer(
731 GLenum target, GLuint client_id, GLuint service_id) {
732 EXPECT_CALL(*gl_, BindFramebufferEXT(target, service_id))
734 .RetiresOnSaturation();
735 cmds::BindFramebuffer cmd;
736 cmd.Init(target, client_id);
737 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
740 bool GLES2DecoderTestBase::DoIsFramebuffer(GLuint client_id) {
741 return IsObjectHelper<cmds::IsFramebuffer, cmds::IsFramebuffer::Result>(
745 void GLES2DecoderTestBase::DoDeleteFramebuffer(
746 GLuint client_id, GLuint service_id,
747 bool reset_draw, GLenum draw_target, GLuint draw_id,
748 bool reset_read, GLenum read_target, GLuint read_id) {
750 EXPECT_CALL(*gl_, BindFramebufferEXT(draw_target, draw_id))
752 .RetiresOnSaturation();
755 EXPECT_CALL(*gl_, BindFramebufferEXT(read_target, read_id))
757 .RetiresOnSaturation();
759 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, Pointee(service_id)))
761 .RetiresOnSaturation();
762 cmds::DeleteFramebuffers cmd;
763 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
764 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
765 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
768 void GLES2DecoderTestBase::DoBindRenderbuffer(
769 GLenum target, GLuint client_id, GLuint service_id) {
770 EXPECT_CALL(*gl_, BindRenderbufferEXT(target, service_id))
772 .RetiresOnSaturation();
773 cmds::BindRenderbuffer cmd;
774 cmd.Init(target, client_id);
775 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
778 bool GLES2DecoderTestBase::DoIsRenderbuffer(GLuint client_id) {
779 return IsObjectHelper<cmds::IsRenderbuffer, cmds::IsRenderbuffer::Result>(
783 void GLES2DecoderTestBase::DoDeleteRenderbuffer(
784 GLuint client_id, GLuint service_id) {
785 EXPECT_CALL(*gl_, DeleteRenderbuffersEXT(1, Pointee(service_id)))
787 .RetiresOnSaturation();
788 cmds::DeleteRenderbuffers cmd;
789 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
790 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
791 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
794 void GLES2DecoderTestBase::DoBindTexture(
795 GLenum target, GLuint client_id, GLuint service_id) {
796 EXPECT_CALL(*gl_, BindTexture(target, service_id))
798 .RetiresOnSaturation();
799 cmds::BindTexture cmd;
800 cmd.Init(target, client_id);
801 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
804 bool GLES2DecoderTestBase::DoIsTexture(GLuint client_id) {
805 return IsObjectHelper<cmds::IsTexture, cmds::IsTexture::Result>(client_id);
808 void GLES2DecoderTestBase::DoDeleteTexture(
809 GLuint client_id, GLuint service_id) {
810 EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(service_id)))
812 .RetiresOnSaturation();
813 cmds::DeleteTextures cmd;
814 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
815 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
816 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
819 void GLES2DecoderTestBase::DoTexImage2D(
820 GLenum target, GLint level, GLenum internal_format,
821 GLsizei width, GLsizei height, GLint border,
822 GLenum format, GLenum type,
823 uint32 shared_memory_id, uint32 shared_memory_offset) {
824 EXPECT_CALL(*gl_, GetError())
825 .WillOnce(Return(GL_NO_ERROR))
826 .RetiresOnSaturation();
827 EXPECT_CALL(*gl_, TexImage2D(target, level, internal_format,
828 width, height, border, format, type, _))
830 .RetiresOnSaturation();
831 EXPECT_CALL(*gl_, GetError())
832 .WillOnce(Return(GL_NO_ERROR))
833 .RetiresOnSaturation();
834 cmds::TexImage2D cmd;
835 cmd.Init(target, level, internal_format, width, height, border, format,
836 type, shared_memory_id, shared_memory_offset);
837 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
840 void GLES2DecoderTestBase::DoTexImage2DConvertInternalFormat(
841 GLenum target, GLint level, GLenum requested_internal_format,
842 GLsizei width, GLsizei height, GLint border,
843 GLenum format, GLenum type,
844 uint32 shared_memory_id, uint32 shared_memory_offset,
845 GLenum expected_internal_format) {
846 EXPECT_CALL(*gl_, GetError())
847 .WillOnce(Return(GL_NO_ERROR))
848 .RetiresOnSaturation();
849 EXPECT_CALL(*gl_, TexImage2D(target, level, expected_internal_format,
850 width, height, border, format, type, _))
852 .RetiresOnSaturation();
853 EXPECT_CALL(*gl_, GetError())
854 .WillOnce(Return(GL_NO_ERROR))
855 .RetiresOnSaturation();
856 cmds::TexImage2D cmd;
857 cmd.Init(target, level, requested_internal_format, width, height, border,
858 format, type, shared_memory_id, shared_memory_offset);
859 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
862 void GLES2DecoderTestBase::DoCompressedTexImage2D(
863 GLenum target, GLint level, GLenum format,
864 GLsizei width, GLsizei height, GLint border,
865 GLsizei size, uint32 bucket_id) {
866 EXPECT_CALL(*gl_, GetError())
867 .WillOnce(Return(GL_NO_ERROR))
868 .RetiresOnSaturation();
869 EXPECT_CALL(*gl_, CompressedTexImage2D(
870 target, level, format, width, height, border, size, _))
872 .RetiresOnSaturation();
873 EXPECT_CALL(*gl_, GetError())
874 .WillOnce(Return(GL_NO_ERROR))
875 .RetiresOnSaturation();
876 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(bucket_id);
877 bucket->SetSize(size);
878 cmds::CompressedTexImage2DBucket cmd;
880 target, level, format, width, height, border,
882 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
885 void GLES2DecoderTestBase::DoRenderbufferStorage(
886 GLenum target, GLenum internal_format, GLenum actual_format,
887 GLsizei width, GLsizei height, GLenum error) {
888 EXPECT_CALL(*gl_, GetError())
889 .WillOnce(Return(GL_NO_ERROR))
890 .RetiresOnSaturation();
891 EXPECT_CALL(*gl_, RenderbufferStorageEXT(
892 target, actual_format, width, height))
894 .RetiresOnSaturation();
895 EXPECT_CALL(*gl_, GetError())
896 .WillOnce(Return(error))
897 .RetiresOnSaturation();
898 cmds::RenderbufferStorage cmd;
899 cmd.Init(target, internal_format, width, height);
900 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
903 void GLES2DecoderTestBase::DoFramebufferTexture2D(
904 GLenum target, GLenum attachment, GLenum textarget,
905 GLuint texture_client_id, GLuint texture_service_id, GLint level,
907 EXPECT_CALL(*gl_, GetError())
908 .WillOnce(Return(GL_NO_ERROR))
909 .RetiresOnSaturation();
910 EXPECT_CALL(*gl_, FramebufferTexture2DEXT(
911 target, attachment, textarget, texture_service_id, level))
913 .RetiresOnSaturation();
914 EXPECT_CALL(*gl_, GetError())
915 .WillOnce(Return(error))
916 .RetiresOnSaturation();
917 cmds::FramebufferTexture2D cmd;
918 cmd.Init(target, attachment, textarget, texture_client_id, level);
919 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
922 void GLES2DecoderTestBase::DoFramebufferRenderbuffer(
925 GLenum renderbuffer_target,
926 GLuint renderbuffer_client_id,
927 GLuint renderbuffer_service_id,
929 EXPECT_CALL(*gl_, GetError())
930 .WillOnce(Return(GL_NO_ERROR))
931 .RetiresOnSaturation();
932 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
933 target, attachment, renderbuffer_target, renderbuffer_service_id))
935 .RetiresOnSaturation();
936 EXPECT_CALL(*gl_, GetError())
937 .WillOnce(Return(error))
938 .RetiresOnSaturation();
939 cmds::FramebufferRenderbuffer cmd;
940 cmd.Init(target, attachment, renderbuffer_target, renderbuffer_client_id);
941 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
944 void GLES2DecoderTestBase::DoVertexAttribPointer(
945 GLuint index, GLint size, GLenum type, GLsizei stride, GLuint offset) {
947 VertexAttribPointer(index, size, type, GL_FALSE, stride,
948 BufferOffset(offset)))
950 .RetiresOnSaturation();
951 cmds::VertexAttribPointer cmd;
952 cmd.Init(index, size, GL_FLOAT, GL_FALSE, stride, offset);
953 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
956 void GLES2DecoderTestBase::DoVertexAttribDivisorANGLE(
957 GLuint index, GLuint divisor) {
959 VertexAttribDivisorANGLE(index, divisor))
961 .RetiresOnSaturation();
962 cmds::VertexAttribDivisorANGLE cmd;
963 cmd.Init(index, divisor);
964 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
967 void GLES2DecoderTestBase::AddExpectationsForGenVertexArraysOES(){
968 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
969 EXPECT_CALL(*gl_, GenVertexArraysOES(1, _))
970 .WillOnce(SetArgumentPointee<1>(kServiceVertexArrayId))
971 .RetiresOnSaturation();
975 void GLES2DecoderTestBase::AddExpectationsForDeleteVertexArraysOES(){
976 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
977 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, _))
979 .RetiresOnSaturation();
983 void GLES2DecoderTestBase::AddExpectationsForBindVertexArrayOES() {
984 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
985 EXPECT_CALL(*gl_, BindVertexArrayOES(_))
987 .RetiresOnSaturation();
989 for (uint32 vv = 0; vv < group_->max_vertex_attribs(); ++vv) {
990 AddExpectationsForRestoreAttribState(vv);
993 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _))
995 .RetiresOnSaturation();
999 void GLES2DecoderTestBase::AddExpectationsForRestoreAttribState(GLuint attrib) {
1000 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1002 .RetiresOnSaturation();
1004 EXPECT_CALL(*gl_, VertexAttribPointer(attrib, _, _, _, _, _))
1006 .RetiresOnSaturation();
1008 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(attrib, _))
1009 .Times(testing::AtMost(1))
1010 .RetiresOnSaturation();
1012 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1014 .RetiresOnSaturation();
1017 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
1019 // TODO(bajones): Not sure if I can tell which of these will be called
1020 EXPECT_CALL(*gl_, EnableVertexAttribArray(attrib))
1021 .Times(testing::AtMost(1))
1022 .RetiresOnSaturation();
1024 EXPECT_CALL(*gl_, DisableVertexAttribArray(attrib))
1025 .Times(testing::AtMost(1))
1026 .RetiresOnSaturation();
1030 // GCC requires these declarations, but MSVC requires they not be present
1031 #ifndef COMPILER_MSVC
1032 const int GLES2DecoderTestBase::kBackBufferWidth;
1033 const int GLES2DecoderTestBase::kBackBufferHeight;
1035 const GLint GLES2DecoderTestBase::kMaxTextureSize;
1036 const GLint GLES2DecoderTestBase::kMaxCubeMapTextureSize;
1037 const GLint GLES2DecoderTestBase::kNumVertexAttribs;
1038 const GLint GLES2DecoderTestBase::kNumTextureUnits;
1039 const GLint GLES2DecoderTestBase::kMaxTextureImageUnits;
1040 const GLint GLES2DecoderTestBase::kMaxVertexTextureImageUnits;
1041 const GLint GLES2DecoderTestBase::kMaxFragmentUniformVectors;
1042 const GLint GLES2DecoderTestBase::kMaxVaryingVectors;
1043 const GLint GLES2DecoderTestBase::kMaxVertexUniformVectors;
1044 const GLint GLES2DecoderTestBase::kMaxViewportWidth;
1045 const GLint GLES2DecoderTestBase::kMaxViewportHeight;
1047 const GLint GLES2DecoderTestBase::kViewportX;
1048 const GLint GLES2DecoderTestBase::kViewportY;
1049 const GLint GLES2DecoderTestBase::kViewportWidth;
1050 const GLint GLES2DecoderTestBase::kViewportHeight;
1052 const GLuint GLES2DecoderTestBase::kServiceAttrib0BufferId;
1053 const GLuint GLES2DecoderTestBase::kServiceFixedAttribBufferId;
1055 const GLuint GLES2DecoderTestBase::kServiceBufferId;
1056 const GLuint GLES2DecoderTestBase::kServiceFramebufferId;
1057 const GLuint GLES2DecoderTestBase::kServiceRenderbufferId;
1058 const GLuint GLES2DecoderTestBase::kServiceTextureId;
1059 const GLuint GLES2DecoderTestBase::kServiceProgramId;
1060 const GLuint GLES2DecoderTestBase::kServiceShaderId;
1061 const GLuint GLES2DecoderTestBase::kServiceElementBufferId;
1062 const GLuint GLES2DecoderTestBase::kServiceQueryId;
1063 const GLuint GLES2DecoderTestBase::kServiceVertexArrayId;
1065 const int32 GLES2DecoderTestBase::kSharedMemoryId;
1066 const size_t GLES2DecoderTestBase::kSharedBufferSize;
1067 const uint32 GLES2DecoderTestBase::kSharedMemoryOffset;
1068 const int32 GLES2DecoderTestBase::kInvalidSharedMemoryId;
1069 const uint32 GLES2DecoderTestBase::kInvalidSharedMemoryOffset;
1070 const uint32 GLES2DecoderTestBase::kInitialResult;
1071 const uint8 GLES2DecoderTestBase::kInitialMemoryValue;
1073 const uint32 GLES2DecoderTestBase::kNewClientId;
1074 const uint32 GLES2DecoderTestBase::kNewServiceId;
1075 const uint32 GLES2DecoderTestBase::kInvalidClientId;
1077 const GLuint GLES2DecoderTestBase::kServiceVertexShaderId;
1078 const GLuint GLES2DecoderTestBase::kServiceFragmentShaderId;
1080 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumShaderId;
1081 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumProgramId;
1083 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTextureBufferId;
1084 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumVertexBufferId;
1085 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumFBOId;
1086 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumPositionAttrib;
1087 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTexAttrib;
1088 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumSamplerLocation;
1090 const GLsizei GLES2DecoderTestBase::kNumVertices;
1091 const GLsizei GLES2DecoderTestBase::kNumIndices;
1092 const int GLES2DecoderTestBase::kValidIndexRangeStart;
1093 const int GLES2DecoderTestBase::kValidIndexRangeCount;
1094 const int GLES2DecoderTestBase::kInvalidIndexRangeStart;
1095 const int GLES2DecoderTestBase::kInvalidIndexRangeCount;
1096 const int GLES2DecoderTestBase::kOutOfRangeIndexRangeEnd;
1097 const GLuint GLES2DecoderTestBase::kMaxValidIndex;
1099 const GLint GLES2DecoderTestBase::kMaxAttribLength;
1100 const GLint GLES2DecoderTestBase::kAttrib1Size;
1101 const GLint GLES2DecoderTestBase::kAttrib2Size;
1102 const GLint GLES2DecoderTestBase::kAttrib3Size;
1103 const GLint GLES2DecoderTestBase::kAttrib1Location;
1104 const GLint GLES2DecoderTestBase::kAttrib2Location;
1105 const GLint GLES2DecoderTestBase::kAttrib3Location;
1106 const GLenum GLES2DecoderTestBase::kAttrib1Type;
1107 const GLenum GLES2DecoderTestBase::kAttrib2Type;
1108 const GLenum GLES2DecoderTestBase::kAttrib3Type;
1109 const GLint GLES2DecoderTestBase::kInvalidAttribLocation;
1110 const GLint GLES2DecoderTestBase::kBadAttribIndex;
1112 const GLint GLES2DecoderTestBase::kMaxUniformLength;
1113 const GLint GLES2DecoderTestBase::kUniform1Size;
1114 const GLint GLES2DecoderTestBase::kUniform2Size;
1115 const GLint GLES2DecoderTestBase::kUniform3Size;
1116 const GLint GLES2DecoderTestBase::kUniform1RealLocation;
1117 const GLint GLES2DecoderTestBase::kUniform2RealLocation;
1118 const GLint GLES2DecoderTestBase::kUniform2ElementRealLocation;
1119 const GLint GLES2DecoderTestBase::kUniform3RealLocation;
1120 const GLint GLES2DecoderTestBase::kUniform1FakeLocation;
1121 const GLint GLES2DecoderTestBase::kUniform2FakeLocation;
1122 const GLint GLES2DecoderTestBase::kUniform2ElementFakeLocation;
1123 const GLint GLES2DecoderTestBase::kUniform3FakeLocation;
1124 const GLint GLES2DecoderTestBase::kUniform1DesiredLocation;
1125 const GLint GLES2DecoderTestBase::kUniform2DesiredLocation;
1126 const GLint GLES2DecoderTestBase::kUniform3DesiredLocation;
1127 const GLenum GLES2DecoderTestBase::kUniform1Type;
1128 const GLenum GLES2DecoderTestBase::kUniform2Type;
1129 const GLenum GLES2DecoderTestBase::kUniform3Type;
1130 const GLenum GLES2DecoderTestBase::kUniformCubemapType;
1131 const GLint GLES2DecoderTestBase::kInvalidUniformLocation;
1132 const GLint GLES2DecoderTestBase::kBadUniformIndex;
1136 const char* GLES2DecoderTestBase::kAttrib1Name = "attrib1";
1137 const char* GLES2DecoderTestBase::kAttrib2Name = "attrib2";
1138 const char* GLES2DecoderTestBase::kAttrib3Name = "attrib3";
1139 const char* GLES2DecoderTestBase::kUniform1Name = "uniform1";
1140 const char* GLES2DecoderTestBase::kUniform2Name = "uniform2[0]";
1141 const char* GLES2DecoderTestBase::kUniform3Name = "uniform3[0]";
1143 void GLES2DecoderTestBase::SetupDefaultProgram() {
1145 static AttribInfo attribs[] = {
1146 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1147 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1148 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1150 static UniformInfo uniforms[] = {
1151 { kUniform1Name, kUniform1Size, kUniform1Type,
1152 kUniform1FakeLocation, kUniform1RealLocation,
1153 kUniform1DesiredLocation },
1154 { kUniform2Name, kUniform2Size, kUniform2Type,
1155 kUniform2FakeLocation, kUniform2RealLocation,
1156 kUniform2DesiredLocation },
1157 { kUniform3Name, kUniform3Size, kUniform3Type,
1158 kUniform3FakeLocation, kUniform3RealLocation,
1159 kUniform3DesiredLocation },
1161 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1162 client_program_id_, kServiceProgramId,
1163 client_vertex_shader_id_, kServiceVertexShaderId,
1164 client_fragment_shader_id_, kServiceFragmentShaderId);
1168 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1170 .RetiresOnSaturation();
1171 cmds::UseProgram cmd;
1172 cmd.Init(client_program_id_);
1173 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1177 void GLES2DecoderTestBase::SetupCubemapProgram() {
1179 static AttribInfo attribs[] = {
1180 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1181 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1182 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1184 static UniformInfo uniforms[] = {
1185 { kUniform1Name, kUniform1Size, kUniformCubemapType,
1186 kUniform1FakeLocation, kUniform1RealLocation,
1187 kUniform1DesiredLocation, },
1188 { kUniform2Name, kUniform2Size, kUniform2Type,
1189 kUniform2FakeLocation, kUniform2RealLocation,
1190 kUniform2DesiredLocation, },
1191 { kUniform3Name, kUniform3Size, kUniform3Type,
1192 kUniform3FakeLocation, kUniform3RealLocation,
1193 kUniform3DesiredLocation, },
1195 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1196 client_program_id_, kServiceProgramId,
1197 client_vertex_shader_id_, kServiceVertexShaderId,
1198 client_fragment_shader_id_, kServiceFragmentShaderId);
1202 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1204 .RetiresOnSaturation();
1205 cmds::UseProgram cmd;
1206 cmd.Init(client_program_id_);
1207 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1211 void GLES2DecoderTestBase::SetupSamplerExternalProgram() {
1213 static AttribInfo attribs[] = {
1214 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1215 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1216 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1218 static UniformInfo uniforms[] = {
1219 { kUniform1Name, kUniform1Size, kUniformSamplerExternalType,
1220 kUniform1FakeLocation, kUniform1RealLocation,
1221 kUniform1DesiredLocation, },
1222 { kUniform2Name, kUniform2Size, kUniform2Type,
1223 kUniform2FakeLocation, kUniform2RealLocation,
1224 kUniform2DesiredLocation, },
1225 { kUniform3Name, kUniform3Size, kUniform3Type,
1226 kUniform3FakeLocation, kUniform3RealLocation,
1227 kUniform3DesiredLocation, },
1229 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1230 client_program_id_, kServiceProgramId,
1231 client_vertex_shader_id_, kServiceVertexShaderId,
1232 client_fragment_shader_id_, kServiceFragmentShaderId);
1236 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1238 .RetiresOnSaturation();
1239 cmds::UseProgram cmd;
1240 cmd.Init(client_program_id_);
1241 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1245 void GLES2DecoderWithShaderTestBase::TearDown() {
1246 GLES2DecoderTestBase::TearDown();
1249 void GLES2DecoderTestBase::SetupShader(
1250 GLES2DecoderTestBase::AttribInfo* attribs, size_t num_attribs,
1251 GLES2DecoderTestBase::UniformInfo* uniforms, size_t num_uniforms,
1252 GLuint program_client_id, GLuint program_service_id,
1253 GLuint vertex_shader_client_id, GLuint vertex_shader_service_id,
1254 GLuint fragment_shader_client_id, GLuint fragment_shader_service_id) {
1259 AttachShader(program_service_id, vertex_shader_service_id))
1261 .RetiresOnSaturation();
1263 AttachShader(program_service_id, fragment_shader_service_id))
1265 .RetiresOnSaturation();
1266 TestHelper::SetupShader(
1267 gl_.get(), attribs, num_attribs, uniforms, num_uniforms,
1268 program_service_id);
1272 GL_VERTEX_SHADER, vertex_shader_client_id, vertex_shader_service_id);
1274 GL_FRAGMENT_SHADER, fragment_shader_client_id,
1275 fragment_shader_service_id);
1277 GetShader(vertex_shader_client_id)->SetStatus(true, "", NULL);
1278 GetShader(fragment_shader_client_id)->SetStatus(true, "", NULL);
1280 cmds::AttachShader attach_cmd;
1281 attach_cmd.Init(program_client_id, vertex_shader_client_id);
1282 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1284 attach_cmd.Init(program_client_id, fragment_shader_client_id);
1285 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1287 cmds::LinkProgram link_cmd;
1288 link_cmd.Init(program_client_id);
1290 EXPECT_EQ(error::kNoError, ExecuteCmd(link_cmd));
1293 void GLES2DecoderTestBase::DoEnableVertexAttribArray(GLint index) {
1294 EXPECT_CALL(*gl_, EnableVertexAttribArray(index))
1296 .RetiresOnSaturation();
1297 cmds::EnableVertexAttribArray cmd;
1299 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1302 void GLES2DecoderTestBase::DoBufferData(GLenum target, GLsizei size) {
1303 EXPECT_CALL(*gl_, GetError())
1304 .WillOnce(Return(GL_NO_ERROR))
1305 .RetiresOnSaturation();
1306 EXPECT_CALL(*gl_, BufferData(target, size, _, GL_STREAM_DRAW))
1308 .RetiresOnSaturation();
1309 EXPECT_CALL(*gl_, GetError())
1310 .WillOnce(Return(GL_NO_ERROR))
1311 .RetiresOnSaturation();
1312 cmds::BufferData cmd;
1313 cmd.Init(target, size, 0, 0, GL_STREAM_DRAW);
1314 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1317 void GLES2DecoderTestBase::DoBufferSubData(
1318 GLenum target, GLint offset, GLsizei size, const void* data) {
1319 EXPECT_CALL(*gl_, BufferSubData(target, offset, size,
1320 shared_memory_address_))
1322 .RetiresOnSaturation();
1323 memcpy(shared_memory_address_, data, size);
1324 cmds::BufferSubData cmd;
1325 cmd.Init(target, offset, size, shared_memory_id_, shared_memory_offset_);
1326 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1329 void GLES2DecoderTestBase::SetupVertexBuffer() {
1330 DoEnableVertexAttribArray(1);
1331 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1333 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 2 * sizeof(f));
1336 void GLES2DecoderTestBase::SetupAllNeededVertexBuffers() {
1337 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1338 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 16 * sizeof(float));
1339 DoEnableVertexAttribArray(0);
1340 DoEnableVertexAttribArray(1);
1341 DoEnableVertexAttribArray(2);
1342 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1343 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1344 DoVertexAttribPointer(2, 2, GL_FLOAT, 0, 0);
1347 void GLES2DecoderTestBase::SetupIndexBuffer() {
1348 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
1349 client_element_buffer_id_,
1350 kServiceElementBufferId);
1351 static const GLshort indices[] = {100, 1, 2, 3, 4, 5, 6, 7, 100, 9};
1352 COMPILE_ASSERT(arraysize(indices) == kNumIndices, Indices_is_not_10);
1353 DoBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices));
1354 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, 2, indices);
1355 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 2, sizeof(indices) - 2, &indices[1]);
1358 void GLES2DecoderTestBase::SetupTexture() {
1359 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1360 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1361 kSharedMemoryId, kSharedMemoryOffset);
1364 void GLES2DecoderTestBase::DeleteVertexBuffer() {
1365 DoDeleteBuffer(client_buffer_id_, kServiceBufferId);
1368 void GLES2DecoderTestBase::DeleteIndexBuffer() {
1369 DoDeleteBuffer(client_element_buffer_id_, kServiceElementBufferId);
1372 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0WithError(
1373 GLsizei num_vertices, GLuint buffer_id, GLenum error) {
1374 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
1378 EXPECT_CALL(*gl_, GetError())
1379 .WillOnce(Return(GL_NO_ERROR))
1380 .WillOnce(Return(error))
1381 .RetiresOnSaturation();
1382 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
1384 .RetiresOnSaturation();
1385 EXPECT_CALL(*gl_, BufferData(GL_ARRAY_BUFFER,
1386 num_vertices * sizeof(GLfloat) * 4,
1387 _, GL_DYNAMIC_DRAW))
1389 .RetiresOnSaturation();
1390 if (error == GL_NO_ERROR) {
1391 EXPECT_CALL(*gl_, BufferSubData(
1392 GL_ARRAY_BUFFER, 0, num_vertices * sizeof(GLfloat) * 4, _))
1394 .RetiresOnSaturation();
1395 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL))
1397 .RetiresOnSaturation();
1398 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
1400 .RetiresOnSaturation();
1401 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL))
1403 .RetiresOnSaturation();
1404 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, buffer_id))
1406 .RetiresOnSaturation();
1410 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0(
1411 GLsizei num_vertices, GLuint buffer_id) {
1412 AddExpectationsForSimulatedAttrib0WithError(
1413 num_vertices, buffer_id, GL_NO_ERROR);
1416 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1417 MockCommandBufferEngine() {
1418 data_.reset(new int8[kSharedBufferSize]);
1419 ClearSharedMemory();
1420 valid_buffer_.ptr = data_.get();
1421 valid_buffer_.size = kSharedBufferSize;
1424 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1425 ~MockCommandBufferEngine() {}
1428 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetSharedMemoryBuffer(
1430 return shm_id == kSharedMemoryId ? valid_buffer_ : invalid_buffer_;
1433 void GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::set_token(
1438 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetBuffer(
1439 int32 /* transfer_buffer_id */) {
1444 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetOffset(
1450 int32 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetGetOffset() {
1455 void GLES2DecoderWithShaderTestBase::SetUp() {
1456 GLES2DecoderTestBase::SetUp();
1457 SetupDefaultProgram();
1460 // Include the auto-generated part of this file. We split this because it means
1461 // we can easily edit the non-auto generated parts right here in this file
1462 // instead of having to edit some template or the code generator.
1463 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h"
1465 } // namespace gles2