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/common/value_state.h"
16 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
17 #include "gpu/command_buffer/service/context_group.h"
18 #include "gpu/command_buffer/service/logger.h"
19 #include "gpu/command_buffer/service/mailbox_manager.h"
20 #include "gpu/command_buffer/service/program_manager.h"
21 #include "gpu/command_buffer/service/test_helper.h"
22 #include "gpu/command_buffer/service/vertex_attrib_manager.h"
23 #include "testing/gtest/include/gtest/gtest.h"
24 #include "ui/gl/gl_implementation.h"
25 #include "ui/gl/gl_mock.h"
26 #include "ui/gl/test/gl_surface_test_support.h"
28 using ::gfx::MockGLInterface
;
30 using ::testing::DoAll
;
31 using ::testing::InSequence
;
32 using ::testing::Invoke
;
33 using ::testing::InvokeWithoutArgs
;
34 using ::testing::MatcherCast
;
35 using ::testing::Pointee
;
36 using ::testing::Return
;
37 using ::testing::SetArrayArgument
;
38 using ::testing::SetArgPointee
;
39 using ::testing::SetArgumentPointee
;
40 using ::testing::StrEq
;
41 using ::testing::StrictMock
;
42 using ::testing::WithArg
;
46 void NormalizeInitState(gpu::gles2::GLES2DecoderTestBase::InitState
* init
) {
48 const char* kVAOExtensions
[] = {
49 "GL_OES_vertex_array_object",
50 "GL_ARB_vertex_array_object",
51 "GL_APPLE_vertex_array_object"
53 bool contains_vao_extension
= false;
54 for (size_t ii
= 0; ii
< arraysize(kVAOExtensions
); ++ii
) {
55 if (init
->extensions
.find(kVAOExtensions
[ii
]) != std::string::npos
) {
56 contains_vao_extension
= true;
61 if (init
->use_native_vao
) {
62 if (contains_vao_extension
)
64 if (!init
->extensions
.empty())
65 init
->extensions
+= " ";
66 if (base::StartsWith(init
->gl_version
, "opengl es",
67 base::CompareCase::INSENSITIVE_ASCII
)) {
68 init
->extensions
+= kVAOExtensions
[0];
70 #if !defined(OS_MACOSX)
71 init
->extensions
+= kVAOExtensions
[1];
73 init
->extensions
+= kVAOExtensions
[2];
77 // Make sure we don't set up an invalid InitState.
78 CHECK(!contains_vao_extension
);
81 if (!init
->extensions
.empty())
82 init
->extensions
+= " ";
83 init
->extensions
+= "GL_EXT_framebuffer_object ";
86 const uint32 kMaxColorAttachments
= 16;
87 const uint32 kMaxDrawBuffers
= 16;
89 } // namespace Anonymous
94 GLES2DecoderTestBase::GLES2DecoderTestBase()
97 memory_tracker_(NULL
),
98 client_buffer_id_(100),
99 client_framebuffer_id_(101),
100 client_program_id_(102),
101 client_renderbuffer_id_(103),
102 client_sampler_id_(104),
103 client_shader_id_(105),
104 client_texture_id_(106),
105 client_element_buffer_id_(107),
106 client_vertex_shader_id_(121),
107 client_fragment_shader_id_(122),
108 client_query_id_(123),
109 client_vertexarray_id_(124),
110 client_valuebuffer_id_(125),
111 client_transformfeedback_id_(126),
112 client_sync_id_(127),
113 service_renderbuffer_id_(0),
114 service_renderbuffer_valid_(false),
115 ignore_cached_state_for_test_(GetParam()),
116 cached_color_mask_red_(true),
117 cached_color_mask_green_(true),
118 cached_color_mask_blue_(true),
119 cached_color_mask_alpha_(true),
120 cached_depth_mask_(true),
121 cached_stencil_front_mask_(static_cast<GLuint
>(-1)),
122 cached_stencil_back_mask_(static_cast<GLuint
>(-1)) {
123 memset(immediate_buffer_
, 0xEE, sizeof(immediate_buffer_
));
126 GLES2DecoderTestBase::~GLES2DecoderTestBase() {}
128 void GLES2DecoderTestBase::SetUp() {
130 // Autogenerated tests do not overwrite version or extension string,
131 // so we have to pick something that supports everything here.
132 init
.gl_version
= "4.4";
133 init
.extensions
+= " GL_ARB_compatibility";
134 init
.has_alpha
= true;
135 init
.has_depth
= true;
136 init
.request_alpha
= true;
137 init
.request_depth
= true;
138 init
.bind_generates_resource
= true;
142 void GLES2DecoderTestBase::AddExpectationsForVertexAttribManager() {
143 for (GLint ii
= 0; ii
< kNumVertexAttribs
; ++ii
) {
144 EXPECT_CALL(*gl_
, VertexAttrib4f(ii
, 0.0f
, 0.0f
, 0.0f
, 1.0f
))
146 .RetiresOnSaturation();
150 GLES2DecoderTestBase::InitState::InitState()
151 : extensions("GL_EXT_framebuffer_object"),
156 request_alpha(false),
157 request_depth(false),
158 request_stencil(false),
159 bind_generates_resource(false),
160 lose_context_when_out_of_memory(false),
161 use_native_vao(true),
165 void GLES2DecoderTestBase::InitDecoder(const InitState
& init
) {
166 InitDecoderWithCommandLine(init
, NULL
);
169 void GLES2DecoderTestBase::InitDecoderWithCommandLine(
170 const InitState
& init
,
171 const base::CommandLine
* command_line
) {
172 InitState normalized_init
= init
;
173 NormalizeInitState(&normalized_init
);
174 // For easier substring/extension matching
175 DCHECK(normalized_init
.extensions
.empty() ||
176 *normalized_init
.extensions
.rbegin() == ' ');
177 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress
);
178 gfx::GLSurfaceTestSupport::InitializeOneOffWithMockBindings();
180 gl_
.reset(new StrictMock
<MockGLInterface
>());
181 ::gfx::MockGLInterface::SetGLInterface(gl_
.get());
183 SetupMockGLBehaviors();
185 scoped_refptr
<FeatureInfo
> feature_info
;
187 feature_info
= new FeatureInfo(*command_line
);
188 group_
= scoped_refptr
<ContextGroup
>(
189 new ContextGroup(NULL
, memory_tracker_
, new ShaderTranslatorCache
,
190 new FramebufferCompletenessCache
, feature_info
.get(),
191 new SubscriptionRefSet
, new ValueStateMap
,
192 normalized_init
.bind_generates_resource
));
193 bool use_default_textures
= normalized_init
.bind_generates_resource
;
197 surface_
= new gfx::GLSurfaceStub
;
198 surface_
->SetSize(gfx::Size(kBackBufferWidth
, kBackBufferHeight
));
200 // Context needs to be created before initializing ContextGroup, which will
201 // in turn initialize FeatureInfo, which needs a context to determine
202 // extension support.
203 context_
= new StrictMock
<GLContextMock
>();
204 context_
->AddExtensionsString(normalized_init
.extensions
.c_str());
205 context_
->SetGLVersionString(normalized_init
.gl_version
.c_str());
207 context_
->GLContextStubWithExtensions::MakeCurrent(surface_
.get());
208 gfx::GLSurfaceTestSupport::InitializeDynamicMockBindings(context_
.get());
210 TestHelper::SetupContextGroupInitExpectations(
212 DisallowedFeatures(),
213 normalized_init
.extensions
.c_str(),
214 normalized_init
.gl_version
.c_str(),
215 normalized_init
.bind_generates_resource
);
217 // We initialize the ContextGroup with a MockGLES2Decoder so that
218 // we can use the ContextGroup to figure out how the real GLES2Decoder
219 // will initialize itself.
220 mock_decoder_
.reset(new MockGLES2Decoder());
222 // Install FakeDoCommands handler so we can use individual DoCommand()
224 EXPECT_CALL(*mock_decoder_
, DoCommands(_
, _
, _
, _
)).WillRepeatedly(
225 Invoke(mock_decoder_
.get(), &MockGLES2Decoder::FakeDoCommands
));
228 EXPECT_TRUE(group_
->Initialize(
230 ContextGroup::GetContextType(init
.webgl_version
),
231 DisallowedFeatures()));
233 if (init
.webgl_version
== 2) {
234 EXPECT_CALL(*gl_
, GetIntegerv(GL_MAX_COLOR_ATTACHMENTS
, _
))
235 .WillOnce(SetArgumentPointee
<1>(kMaxColorAttachments
))
236 .RetiresOnSaturation();
237 EXPECT_CALL(*gl_
, GetIntegerv(GL_MAX_DRAW_BUFFERS
, _
))
238 .WillOnce(SetArgumentPointee
<1>(kMaxDrawBuffers
))
239 .RetiresOnSaturation();
242 if (group_
->feature_info()->feature_flags().native_vertex_array_object
) {
243 EXPECT_CALL(*gl_
, GenVertexArraysOES(1, _
))
244 .WillOnce(SetArgumentPointee
<1>(kServiceVertexArrayId
))
245 .RetiresOnSaturation();
246 EXPECT_CALL(*gl_
, BindVertexArrayOES(_
)).Times(1).RetiresOnSaturation();
249 if (group_
->feature_info()->workarounds().init_vertex_attributes
)
250 AddExpectationsForVertexAttribManager();
252 AddExpectationsForBindVertexArrayOES();
254 EXPECT_CALL(*gl_
, EnableVertexAttribArray(0))
256 .RetiresOnSaturation();
257 static GLuint attrib_0_id
[] = {
258 kServiceAttrib0BufferId
,
260 static GLuint fixed_attrib_buffer_id
[] = {
261 kServiceFixedAttribBufferId
,
263 EXPECT_CALL(*gl_
, GenBuffersARB(arraysize(attrib_0_id
), _
))
264 .WillOnce(SetArrayArgument
<1>(attrib_0_id
,
265 attrib_0_id
+ arraysize(attrib_0_id
)))
266 .RetiresOnSaturation();
267 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, kServiceAttrib0BufferId
))
269 .RetiresOnSaturation();
270 EXPECT_CALL(*gl_
, VertexAttribPointer(0, 1, GL_FLOAT
, GL_FALSE
, 0, NULL
))
272 .RetiresOnSaturation();
273 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, 0))
275 .RetiresOnSaturation();
276 EXPECT_CALL(*gl_
, GenBuffersARB(arraysize(fixed_attrib_buffer_id
), _
))
277 .WillOnce(SetArrayArgument
<1>(
278 fixed_attrib_buffer_id
,
279 fixed_attrib_buffer_id
+ arraysize(fixed_attrib_buffer_id
)))
280 .RetiresOnSaturation();
282 for (GLint tt
= 0; tt
< TestHelper::kNumTextureUnits
; ++tt
) {
283 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
+ tt
))
285 .RetiresOnSaturation();
286 if (group_
->feature_info()->feature_flags().oes_egl_image_external
) {
288 BindTexture(GL_TEXTURE_EXTERNAL_OES
,
290 ? TestHelper::kServiceDefaultExternalTextureId
293 .RetiresOnSaturation();
295 if (group_
->feature_info()->feature_flags().arb_texture_rectangle
) {
298 BindTexture(GL_TEXTURE_RECTANGLE_ARB
,
300 ? TestHelper::kServiceDefaultRectangleTextureId
303 .RetiresOnSaturation();
306 BindTexture(GL_TEXTURE_CUBE_MAP
,
308 ? TestHelper::kServiceDefaultTextureCubemapId
311 .RetiresOnSaturation();
316 use_default_textures
? TestHelper::kServiceDefaultTexture2dId
: 0))
318 .RetiresOnSaturation();
320 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
322 .RetiresOnSaturation();
324 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_FRAMEBUFFER
, 0))
326 .RetiresOnSaturation();
327 EXPECT_CALL(*gl_
, GetIntegerv(GL_ALPHA_BITS
, _
))
328 .WillOnce(SetArgumentPointee
<1>(normalized_init
.has_alpha
? 8 : 0))
329 .RetiresOnSaturation();
330 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_BITS
, _
))
331 .WillOnce(SetArgumentPointee
<1>(normalized_init
.has_depth
? 24 : 0))
332 .RetiresOnSaturation();
333 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_BITS
, _
))
334 .WillOnce(SetArgumentPointee
<1>(normalized_init
.has_stencil
? 8 : 0))
335 .RetiresOnSaturation();
337 if (!group_
->feature_info()->gl_version_info().BehavesLikeGLES()) {
338 EXPECT_CALL(*gl_
, Enable(GL_VERTEX_PROGRAM_POINT_SIZE
))
340 .RetiresOnSaturation();
342 EXPECT_CALL(*gl_
, Enable(GL_POINT_SPRITE
))
344 .RetiresOnSaturation();
347 static GLint max_viewport_dims
[] = {
351 EXPECT_CALL(*gl_
, GetIntegerv(GL_MAX_VIEWPORT_DIMS
, _
))
352 .WillOnce(SetArrayArgument
<1>(
353 max_viewport_dims
, max_viewport_dims
+ arraysize(max_viewport_dims
)))
354 .RetiresOnSaturation();
356 SetupInitCapabilitiesExpectations(group_
->feature_info()->IsES3Capable());
357 SetupInitStateExpectations();
359 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
361 .RetiresOnSaturation();
363 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, 0))
365 .RetiresOnSaturation();
366 EXPECT_CALL(*gl_
, BindBuffer(GL_ELEMENT_ARRAY_BUFFER
, 0))
368 .RetiresOnSaturation();
369 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_FRAMEBUFFER
, 0))
371 .RetiresOnSaturation();
372 EXPECT_CALL(*gl_
, BindRenderbufferEXT(GL_RENDERBUFFER
, 0))
374 .RetiresOnSaturation();
376 // TODO(boliu): Remove OS_ANDROID once crbug.com/259023 is fixed and the
377 // workaround has been reverted.
378 #if !defined(OS_ANDROID)
379 if (normalized_init
.has_alpha
&& !normalized_init
.request_alpha
) {
380 EXPECT_CALL(*gl_
, ClearColor(0, 0, 0, 1)).Times(1).RetiresOnSaturation();
383 EXPECT_CALL(*gl_
, Clear(
384 GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
386 .RetiresOnSaturation();
388 if (normalized_init
.has_alpha
&& !normalized_init
.request_alpha
) {
389 EXPECT_CALL(*gl_
, ClearColor(0, 0, 0, 0)).Times(1).RetiresOnSaturation();
393 engine_
.reset(new StrictMock
<MockCommandBufferEngine
>());
394 scoped_refptr
<gpu::Buffer
> buffer
=
395 engine_
->GetSharedMemoryBuffer(kSharedMemoryId
);
396 shared_memory_offset_
= kSharedMemoryOffset
;
397 shared_memory_address_
=
398 reinterpret_cast<int8
*>(buffer
->memory()) + shared_memory_offset_
;
399 shared_memory_id_
= kSharedMemoryId
;
400 shared_memory_base_
= buffer
->memory();
402 static const int32 kLoseContextWhenOutOfMemory
= 0x10002;
403 static const int32 kWebGLVersion
= 0x10003;
405 int32 attributes
[] = {
407 normalized_init
.request_alpha
? 8 : 0,
409 normalized_init
.request_depth
? 24 : 0,
411 normalized_init
.request_stencil
? 8 : 0,
412 kLoseContextWhenOutOfMemory
,
413 normalized_init
.lose_context_when_out_of_memory
? 1 : 0,
417 std::vector
<int32
> attribs(attributes
, attributes
+ arraysize(attributes
));
419 decoder_
.reset(GLES2Decoder::Create(group_
.get()));
420 decoder_
->SetIgnoreCachedStateForTest(ignore_cached_state_for_test_
);
421 decoder_
->GetLogger()->set_log_synthesized_gl_errors(false);
422 decoder_
->Initialize(surface_
,
426 DisallowedFeatures(),
428 EXPECT_CALL(*context_
, MakeCurrent(surface_
.get())).WillOnce(Return(true));
429 if (context_
->WasAllocatedUsingRobustnessExtension()) {
430 EXPECT_CALL(*gl_
, GetGraphicsResetStatusARB())
431 .WillOnce(Return(GL_NO_ERROR
));
433 decoder_
->MakeCurrent();
434 decoder_
->set_engine(engine_
.get());
435 decoder_
->BeginDecoding();
437 EXPECT_CALL(*gl_
, GenBuffersARB(_
, _
))
438 .WillOnce(SetArgumentPointee
<1>(kServiceBufferId
))
439 .RetiresOnSaturation();
440 GenHelper
<cmds::GenBuffersImmediate
>(client_buffer_id_
);
441 EXPECT_CALL(*gl_
, GenFramebuffersEXT(_
, _
))
442 .WillOnce(SetArgumentPointee
<1>(kServiceFramebufferId
))
443 .RetiresOnSaturation();
444 GenHelper
<cmds::GenFramebuffersImmediate
>(client_framebuffer_id_
);
445 EXPECT_CALL(*gl_
, GenRenderbuffersEXT(_
, _
))
446 .WillOnce(SetArgumentPointee
<1>(kServiceRenderbufferId
))
447 .RetiresOnSaturation();
448 GenHelper
<cmds::GenRenderbuffersImmediate
>(client_renderbuffer_id_
);
449 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
450 .WillOnce(SetArgumentPointee
<1>(kServiceTextureId
))
451 .RetiresOnSaturation();
452 GenHelper
<cmds::GenTexturesImmediate
>(client_texture_id_
);
453 EXPECT_CALL(*gl_
, GenBuffersARB(_
, _
))
454 .WillOnce(SetArgumentPointee
<1>(kServiceElementBufferId
))
455 .RetiresOnSaturation();
456 GenHelper
<cmds::GenBuffersImmediate
>(client_element_buffer_id_
);
458 DoCreateProgram(client_program_id_
, kServiceProgramId
);
459 DoCreateShader(GL_VERTEX_SHADER
, client_shader_id_
, kServiceShaderId
);
462 bool reset_unsafe_es3_apis_enabled
= false;
463 if (!decoder_
->unsafe_es3_apis_enabled()) {
464 decoder_
->set_unsafe_es3_apis_enabled(true);
465 reset_unsafe_es3_apis_enabled
= true;
468 const gfx::GLVersionInfo
* version
= context_
->GetVersionInfo();
469 if (version
->IsAtLeastGL(3, 3) || version
->IsAtLeastGLES(3, 0)) {
470 EXPECT_CALL(*gl_
, GenSamplers(_
, _
))
471 .WillOnce(SetArgumentPointee
<1>(kServiceSamplerId
))
472 .RetiresOnSaturation();
473 GenHelper
<cmds::GenSamplersImmediate
>(client_sampler_id_
);
475 if (version
->IsAtLeastGL(4, 0) || version
->IsAtLeastGLES(3, 0)) {
476 EXPECT_CALL(*gl_
, GenTransformFeedbacks(_
, _
))
477 .WillOnce(SetArgumentPointee
<1>(kServiceTransformFeedbackId
))
478 .RetiresOnSaturation();
479 GenHelper
<cmds::GenTransformFeedbacksImmediate
>(
480 client_transformfeedback_id_
);
483 if (init
.extensions
.find("GL_ARB_sync ") != std::string::npos
||
484 version
->IsAtLeastGL(3, 2) || version
->IsAtLeastGLES(3, 0)) {
485 DoFenceSync(client_sync_id_
, kServiceSyncId
);
488 if (reset_unsafe_es3_apis_enabled
) {
489 decoder_
->set_unsafe_es3_apis_enabled(false);
492 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
495 void GLES2DecoderTestBase::ResetDecoder() {
498 // All Tests should have read all their GLErrors before getting here.
499 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
501 EXPECT_CALL(*gl_
, DeleteBuffersARB(1, _
))
503 .RetiresOnSaturation();
504 if (group_
->feature_info()->feature_flags().native_vertex_array_object
) {
505 EXPECT_CALL(*gl_
, DeleteVertexArraysOES(1, Pointee(kServiceVertexArrayId
)))
507 .RetiresOnSaturation();
510 decoder_
->EndDecoding();
511 decoder_
->Destroy(true);
513 group_
->Destroy(mock_decoder_
.get(), false);
515 ::gfx::MockGLInterface::SetGLInterface(NULL
);
517 gfx::ClearGLBindings();
520 void GLES2DecoderTestBase::TearDown() {
524 void GLES2DecoderTestBase::ExpectEnableDisable(GLenum cap
, bool enable
) {
526 EXPECT_CALL(*gl_
, Enable(cap
))
528 .RetiresOnSaturation();
530 EXPECT_CALL(*gl_
, Disable(cap
))
532 .RetiresOnSaturation();
537 GLint
GLES2DecoderTestBase::GetGLError() {
538 EXPECT_CALL(*gl_
, GetError())
539 .WillOnce(Return(GL_NO_ERROR
))
540 .RetiresOnSaturation();
542 cmd
.Init(shared_memory_id_
, shared_memory_offset_
);
543 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
544 return static_cast<GLint
>(*GetSharedMemoryAs
<GLenum
*>());
547 void GLES2DecoderTestBase::DoCreateShader(
548 GLenum shader_type
, GLuint client_id
, GLuint service_id
) {
549 EXPECT_CALL(*gl_
, CreateShader(shader_type
))
551 .WillOnce(Return(service_id
))
552 .RetiresOnSaturation();
553 cmds::CreateShader cmd
;
554 cmd
.Init(shader_type
, client_id
);
555 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
558 bool GLES2DecoderTestBase::DoIsShader(GLuint client_id
) {
559 return IsObjectHelper
<cmds::IsShader
, cmds::IsShader::Result
>(client_id
);
562 void GLES2DecoderTestBase::DoDeleteShader(
563 GLuint client_id
, GLuint service_id
) {
564 EXPECT_CALL(*gl_
, DeleteShader(service_id
))
566 .RetiresOnSaturation();
567 cmds::DeleteShader cmd
;
569 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
572 void GLES2DecoderTestBase::DoCreateProgram(
573 GLuint client_id
, GLuint service_id
) {
574 EXPECT_CALL(*gl_
, CreateProgram())
576 .WillOnce(Return(service_id
))
577 .RetiresOnSaturation();
578 cmds::CreateProgram cmd
;
580 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
583 bool GLES2DecoderTestBase::DoIsProgram(GLuint client_id
) {
584 return IsObjectHelper
<cmds::IsProgram
, cmds::IsProgram::Result
>(client_id
);
587 void GLES2DecoderTestBase::DoDeleteProgram(
588 GLuint client_id
, GLuint
/* service_id */) {
589 cmds::DeleteProgram cmd
;
591 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
594 void GLES2DecoderTestBase::DoFenceSync(
595 GLuint client_id
, GLuint service_id
) {
596 EXPECT_CALL(*gl_
, FenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE
, 0))
598 .WillOnce(Return(reinterpret_cast<GLsync
>(service_id
)))
599 .RetiresOnSaturation();
602 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
605 void GLES2DecoderTestBase::SetBucketData(
606 uint32_t bucket_id
, const void* data
, uint32_t data_size
) {
607 DCHECK(data
|| data_size
== 0);
608 cmd::SetBucketSize cmd1
;
609 cmd1
.Init(bucket_id
, data_size
);
610 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
612 memcpy(shared_memory_address_
, data
, data_size
);
613 cmd::SetBucketData cmd2
;
614 cmd2
.Init(bucket_id
, 0, data_size
, kSharedMemoryId
, kSharedMemoryOffset
);
615 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
620 void GLES2DecoderTestBase::SetBucketAsCString(
621 uint32 bucket_id
, const char* str
) {
622 SetBucketData(bucket_id
, str
, str
? (strlen(str
) + 1) : 0);
625 void GLES2DecoderTestBase::SetBucketAsCStrings(
626 uint32 bucket_id
, GLsizei count
, const char** str
,
627 GLsizei count_in_header
, char str_end
) {
628 uint32_t header_size
= sizeof(GLint
) * (count
+ 1);
629 uint32_t total_size
= header_size
;
630 scoped_ptr
<GLint
[]> header(new GLint
[count
+ 1]);
631 header
[0] = static_cast<GLint
>(count_in_header
);
632 for (GLsizei ii
= 0; ii
< count
; ++ii
) {
633 header
[ii
+ 1] = str
&& str
[ii
] ? strlen(str
[ii
]) : 0;
634 total_size
+= header
[ii
+ 1] + 1;
636 cmd::SetBucketSize cmd1
;
637 cmd1
.Init(bucket_id
, total_size
);
638 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
639 memcpy(shared_memory_address_
, header
.get(), header_size
);
640 uint32_t offset
= header_size
;
641 for (GLsizei ii
= 0; ii
< count
; ++ii
) {
642 if (str
&& str
[ii
]) {
643 size_t str_len
= strlen(str
[ii
]);
644 memcpy(reinterpret_cast<char*>(shared_memory_address_
) + offset
,
648 memcpy(reinterpret_cast<char*>(shared_memory_address_
) + offset
,
652 cmd::SetBucketData cmd2
;
653 cmd2
.Init(bucket_id
, 0, total_size
, kSharedMemoryId
, kSharedMemoryOffset
);
654 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
658 void GLES2DecoderTestBase::SetupClearTextureExpectations(GLuint service_id
,
659 GLuint old_service_id
,
663 GLenum internal_format
,
670 EXPECT_CALL(*gl_
, BindTexture(bind_target
, service_id
))
672 .RetiresOnSaturation();
673 EXPECT_CALL(*gl_
, TexSubImage2D(target
, level
, xoffset
, yoffset
, width
,
674 height
, format
, type
, _
))
676 .RetiresOnSaturation();
677 EXPECT_CALL(*gl_
, BindTexture(bind_target
, old_service_id
))
679 .RetiresOnSaturation();
682 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearing(
685 GLclampf restore_red
,
686 GLclampf restore_green
,
687 GLclampf restore_blue
,
688 GLclampf restore_alpha
,
689 GLuint restore_stencil
,
690 GLclampf restore_depth
,
691 bool restore_scissor_test
,
692 GLint restore_scissor_x
,
693 GLint restore_scissor_y
,
694 GLsizei restore_scissor_width
,
695 GLsizei restore_scissor_height
) {
696 SetupExpectationsForFramebufferClearingMulti(
697 0, 0, target
, clear_bits
, restore_red
, restore_green
, restore_blue
,
698 restore_alpha
, restore_stencil
, restore_depth
, restore_scissor_test
,
699 restore_scissor_x
, restore_scissor_y
, restore_scissor_width
,
700 restore_scissor_height
);
703 void GLES2DecoderTestBase::SetupExpectationsForRestoreClearState(
704 GLclampf restore_red
,
705 GLclampf restore_green
,
706 GLclampf restore_blue
,
707 GLclampf restore_alpha
,
708 GLuint restore_stencil
,
709 GLclampf restore_depth
,
710 bool restore_scissor_test
,
711 GLint restore_scissor_x
,
712 GLint restore_scissor_y
,
713 GLsizei restore_scissor_width
,
714 GLsizei restore_scissor_height
) {
715 EXPECT_CALL(*gl_
, ClearColor(
716 restore_red
, restore_green
, restore_blue
, restore_alpha
))
718 .RetiresOnSaturation();
719 EXPECT_CALL(*gl_
, ClearStencil(restore_stencil
))
721 .RetiresOnSaturation();
722 EXPECT_CALL(*gl_
, ClearDepth(restore_depth
))
724 .RetiresOnSaturation();
725 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST
, restore_scissor_test
);
726 EXPECT_CALL(*gl_
, Scissor(restore_scissor_x
, restore_scissor_y
,
727 restore_scissor_width
, restore_scissor_height
))
729 .RetiresOnSaturation();
732 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearingMulti(
733 GLuint read_framebuffer_service_id
,
734 GLuint draw_framebuffer_service_id
,
737 GLclampf restore_red
,
738 GLclampf restore_green
,
739 GLclampf restore_blue
,
740 GLclampf restore_alpha
,
741 GLuint restore_stencil
,
742 GLclampf restore_depth
,
743 bool restore_scissor_test
,
744 GLint restore_scissor_x
,
745 GLint restore_scissor_y
,
746 GLsizei restore_scissor_width
,
747 GLsizei restore_scissor_height
) {
748 // TODO(gman): Figure out why InSequence stopped working.
749 // InSequence sequence;
750 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(target
))
751 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
752 .RetiresOnSaturation();
753 if (target
== GL_READ_FRAMEBUFFER_EXT
) {
754 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT
, 0))
756 .RetiresOnSaturation();
757 EXPECT_CALL(*gl_
, BindFramebufferEXT(
758 GL_DRAW_FRAMEBUFFER_EXT
, read_framebuffer_service_id
))
760 .RetiresOnSaturation();
762 if ((clear_bits
& GL_COLOR_BUFFER_BIT
) != 0) {
763 EXPECT_CALL(*gl_
, ClearColor(0.0f
, 0.0f
, 0.0f
, 0.0f
))
765 .RetiresOnSaturation();
766 SetupExpectationsForColorMask(true, true, true, true);
768 if ((clear_bits
& GL_STENCIL_BUFFER_BIT
) != 0) {
769 EXPECT_CALL(*gl_
, ClearStencil(0))
771 .RetiresOnSaturation();
772 EXPECT_CALL(*gl_
, StencilMask(static_cast<GLuint
>(-1)))
774 .RetiresOnSaturation();
776 if ((clear_bits
& GL_DEPTH_BUFFER_BIT
) != 0) {
777 EXPECT_CALL(*gl_
, ClearDepth(1.0f
))
779 .RetiresOnSaturation();
780 SetupExpectationsForDepthMask(true);
782 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST
, false);
783 EXPECT_CALL(*gl_
, Clear(clear_bits
))
785 .RetiresOnSaturation();
786 SetupExpectationsForRestoreClearState(
787 restore_red
, restore_green
, restore_blue
, restore_alpha
, restore_stencil
,
788 restore_depth
, restore_scissor_test
, restore_scissor_x
, restore_scissor_y
,
789 restore_scissor_width
, restore_scissor_height
);
790 if (target
== GL_READ_FRAMEBUFFER_EXT
) {
791 EXPECT_CALL(*gl_
, BindFramebufferEXT(
792 GL_READ_FRAMEBUFFER_EXT
, read_framebuffer_service_id
))
794 .RetiresOnSaturation();
795 EXPECT_CALL(*gl_
, BindFramebufferEXT(
796 GL_DRAW_FRAMEBUFFER_EXT
, draw_framebuffer_service_id
))
798 .RetiresOnSaturation();
802 void GLES2DecoderTestBase::SetupShaderForUniform(GLenum uniform_type
) {
803 static AttribInfo attribs
[] = {
804 { "foo", 1, GL_FLOAT
, 1, },
805 { "goo", 1, GL_FLOAT
, 2, },
807 UniformInfo uniforms
[] = {
808 { "bar", 1, uniform_type
, 0, 2, -1, },
809 { "car", 4, uniform_type
, 1, 1, -1, },
811 const GLuint kClientVertexShaderId
= 5001;
812 const GLuint kServiceVertexShaderId
= 6001;
813 const GLuint kClientFragmentShaderId
= 5002;
814 const GLuint kServiceFragmentShaderId
= 6002;
815 SetupShader(attribs
, arraysize(attribs
), uniforms
, arraysize(uniforms
),
816 client_program_id_
, kServiceProgramId
,
817 kClientVertexShaderId
, kServiceVertexShaderId
,
818 kClientFragmentShaderId
, kServiceFragmentShaderId
);
820 EXPECT_CALL(*gl_
, UseProgram(kServiceProgramId
))
822 .RetiresOnSaturation();
823 cmds::UseProgram cmd
;
824 cmd
.Init(client_program_id_
);
825 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
828 void GLES2DecoderTestBase::DoBindBuffer(
829 GLenum target
, GLuint client_id
, GLuint service_id
) {
830 EXPECT_CALL(*gl_
, BindBuffer(target
, service_id
))
832 .RetiresOnSaturation();
833 cmds::BindBuffer cmd
;
834 cmd
.Init(target
, client_id
);
835 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
838 bool GLES2DecoderTestBase::DoIsBuffer(GLuint client_id
) {
839 return IsObjectHelper
<cmds::IsBuffer
, cmds::IsBuffer::Result
>(client_id
);
842 void GLES2DecoderTestBase::DoDeleteBuffer(
843 GLuint client_id
, GLuint service_id
) {
844 EXPECT_CALL(*gl_
, DeleteBuffersARB(1, Pointee(service_id
)))
846 .RetiresOnSaturation();
847 GenHelper
<cmds::DeleteBuffersImmediate
>(client_id
);
850 void GLES2DecoderTestBase::SetupExpectationsForColorMask(bool red
,
854 if (ignore_cached_state_for_test_
|| cached_color_mask_red_
!= red
||
855 cached_color_mask_green_
!= green
|| cached_color_mask_blue_
!= blue
||
856 cached_color_mask_alpha_
!= alpha
) {
857 cached_color_mask_red_
= red
;
858 cached_color_mask_green_
= green
;
859 cached_color_mask_blue_
= blue
;
860 cached_color_mask_alpha_
= alpha
;
861 EXPECT_CALL(*gl_
, ColorMask(red
, green
, blue
, alpha
))
863 .RetiresOnSaturation();
867 void GLES2DecoderTestBase::SetupExpectationsForDepthMask(bool mask
) {
868 if (ignore_cached_state_for_test_
|| cached_depth_mask_
!= mask
) {
869 cached_depth_mask_
= mask
;
870 EXPECT_CALL(*gl_
, DepthMask(mask
)).Times(1).RetiresOnSaturation();
874 void GLES2DecoderTestBase::SetupExpectationsForStencilMask(GLuint front_mask
,
876 if (ignore_cached_state_for_test_
||
877 cached_stencil_front_mask_
!= front_mask
) {
878 cached_stencil_front_mask_
= front_mask
;
879 EXPECT_CALL(*gl_
, StencilMaskSeparate(GL_FRONT
, front_mask
))
881 .RetiresOnSaturation();
884 if (ignore_cached_state_for_test_
||
885 cached_stencil_back_mask_
!= back_mask
) {
886 cached_stencil_back_mask_
= back_mask
;
887 EXPECT_CALL(*gl_
, StencilMaskSeparate(GL_BACK
, back_mask
))
889 .RetiresOnSaturation();
893 void GLES2DecoderTestBase::SetupExpectationsForEnableDisable(GLenum cap
,
897 if (enable_flags_
.cached_blend
== enable
&&
898 !ignore_cached_state_for_test_
)
900 enable_flags_
.cached_blend
= enable
;
903 if (enable_flags_
.cached_cull_face
== enable
&&
904 !ignore_cached_state_for_test_
)
906 enable_flags_
.cached_cull_face
= enable
;
909 if (enable_flags_
.cached_depth_test
== enable
&&
910 !ignore_cached_state_for_test_
)
912 enable_flags_
.cached_depth_test
= enable
;
915 if (enable_flags_
.cached_dither
== enable
&&
916 !ignore_cached_state_for_test_
)
918 enable_flags_
.cached_dither
= enable
;
920 case GL_POLYGON_OFFSET_FILL
:
921 if (enable_flags_
.cached_polygon_offset_fill
== enable
&&
922 !ignore_cached_state_for_test_
)
924 enable_flags_
.cached_polygon_offset_fill
= enable
;
926 case GL_SAMPLE_ALPHA_TO_COVERAGE
:
927 if (enable_flags_
.cached_sample_alpha_to_coverage
== enable
&&
928 !ignore_cached_state_for_test_
)
930 enable_flags_
.cached_sample_alpha_to_coverage
= enable
;
932 case GL_SAMPLE_COVERAGE
:
933 if (enable_flags_
.cached_sample_coverage
== enable
&&
934 !ignore_cached_state_for_test_
)
936 enable_flags_
.cached_sample_coverage
= enable
;
938 case GL_SCISSOR_TEST
:
939 if (enable_flags_
.cached_scissor_test
== enable
&&
940 !ignore_cached_state_for_test_
)
942 enable_flags_
.cached_scissor_test
= enable
;
944 case GL_STENCIL_TEST
:
945 if (enable_flags_
.cached_stencil_test
== enable
&&
946 !ignore_cached_state_for_test_
)
948 enable_flags_
.cached_stencil_test
= enable
;
955 EXPECT_CALL(*gl_
, Enable(cap
)).Times(1).RetiresOnSaturation();
957 EXPECT_CALL(*gl_
, Disable(cap
)).Times(1).RetiresOnSaturation();
961 void GLES2DecoderTestBase::SetupExpectationsForApplyingDirtyState(
962 bool framebuffer_is_rgb
,
963 bool framebuffer_has_depth
,
964 bool framebuffer_has_stencil
,
968 GLuint front_stencil_mask
,
969 GLuint back_stencil_mask
,
970 bool stencil_enabled
) {
971 bool color_mask_red
= (color_bits
& 0x1000) != 0;
972 bool color_mask_green
= (color_bits
& 0x0100) != 0;
973 bool color_mask_blue
= (color_bits
& 0x0010) != 0;
974 bool color_mask_alpha
= (color_bits
& 0x0001) && !framebuffer_is_rgb
;
976 SetupExpectationsForColorMask(
977 color_mask_red
, color_mask_green
, color_mask_blue
, color_mask_alpha
);
978 SetupExpectationsForDepthMask(depth_mask
);
979 SetupExpectationsForStencilMask(front_stencil_mask
, back_stencil_mask
);
980 SetupExpectationsForEnableDisable(GL_DEPTH_TEST
,
981 framebuffer_has_depth
&& depth_enabled
);
982 SetupExpectationsForEnableDisable(GL_STENCIL_TEST
,
983 framebuffer_has_stencil
&& stencil_enabled
);
986 void GLES2DecoderTestBase::SetupExpectationsForApplyingDefaultDirtyState() {
987 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
988 false, // Framebuffer has depth
989 false, // Framebuffer has stencil
990 0x1111, // color bits
992 false, // depth enabled
993 0, // front stencil mask
994 0, // back stencil mask
995 false); // stencil enabled
998 GLES2DecoderTestBase::EnableFlags::EnableFlags()
999 : cached_blend(false),
1000 cached_cull_face(false),
1001 cached_depth_test(false),
1002 cached_dither(true),
1003 cached_polygon_offset_fill(false),
1004 cached_sample_alpha_to_coverage(false),
1005 cached_sample_coverage(false),
1006 cached_scissor_test(false),
1007 cached_stencil_test(false) {
1010 void GLES2DecoderTestBase::DoBindFramebuffer(
1011 GLenum target
, GLuint client_id
, GLuint service_id
) {
1012 EXPECT_CALL(*gl_
, BindFramebufferEXT(target
, service_id
))
1014 .RetiresOnSaturation();
1015 cmds::BindFramebuffer cmd
;
1016 cmd
.Init(target
, client_id
);
1017 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1020 bool GLES2DecoderTestBase::DoIsFramebuffer(GLuint client_id
) {
1021 return IsObjectHelper
<cmds::IsFramebuffer
, cmds::IsFramebuffer::Result
>(
1025 void GLES2DecoderTestBase::DoDeleteFramebuffer(
1026 GLuint client_id
, GLuint service_id
,
1027 bool reset_draw
, GLenum draw_target
, GLuint draw_id
,
1028 bool reset_read
, GLenum read_target
, GLuint read_id
) {
1030 EXPECT_CALL(*gl_
, BindFramebufferEXT(draw_target
, draw_id
))
1032 .RetiresOnSaturation();
1035 EXPECT_CALL(*gl_
, BindFramebufferEXT(read_target
, read_id
))
1037 .RetiresOnSaturation();
1039 EXPECT_CALL(*gl_
, DeleteFramebuffersEXT(1, Pointee(service_id
)))
1041 .RetiresOnSaturation();
1042 GenHelper
<cmds::DeleteFramebuffersImmediate
>(client_id
);
1045 void GLES2DecoderTestBase::DoBindRenderbuffer(
1046 GLenum target
, GLuint client_id
, GLuint service_id
) {
1047 service_renderbuffer_id_
= service_id
;
1048 service_renderbuffer_valid_
= true;
1049 EXPECT_CALL(*gl_
, BindRenderbufferEXT(target
, service_id
))
1051 .RetiresOnSaturation();
1052 cmds::BindRenderbuffer cmd
;
1053 cmd
.Init(target
, client_id
);
1054 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1057 void GLES2DecoderTestBase::DoRenderbufferStorageMultisampleCHROMIUM(
1060 GLenum internal_format
,
1064 EXPECT_CALL(*gl_
, GetError())
1065 .WillOnce(Return(GL_NO_ERROR
))
1066 .RetiresOnSaturation();
1068 RenderbufferStorageMultisampleEXT(
1069 target
, samples
, gl_format
, width
, height
))
1071 .RetiresOnSaturation();
1072 EXPECT_CALL(*gl_
, GetError())
1073 .WillOnce(Return(GL_NO_ERROR
))
1074 .RetiresOnSaturation();
1075 cmds::RenderbufferStorageMultisampleCHROMIUM cmd
;
1076 cmd
.Init(target
, samples
, internal_format
, width
, height
);
1077 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1078 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1081 void GLES2DecoderTestBase::RestoreRenderbufferBindings() {
1082 GetDecoder()->RestoreRenderbufferBindings();
1083 service_renderbuffer_valid_
= false;
1086 void GLES2DecoderTestBase::EnsureRenderbufferBound(bool expect_bind
) {
1087 EXPECT_NE(expect_bind
, service_renderbuffer_valid_
);
1090 service_renderbuffer_valid_
= true;
1092 BindRenderbufferEXT(GL_RENDERBUFFER
, service_renderbuffer_id_
))
1094 .RetiresOnSaturation();
1096 EXPECT_CALL(*gl_
, BindRenderbufferEXT(_
, _
)).Times(0);
1100 bool GLES2DecoderTestBase::DoIsRenderbuffer(GLuint client_id
) {
1101 return IsObjectHelper
<cmds::IsRenderbuffer
, cmds::IsRenderbuffer::Result
>(
1105 void GLES2DecoderTestBase::DoDeleteRenderbuffer(
1106 GLuint client_id
, GLuint service_id
) {
1107 EXPECT_CALL(*gl_
, DeleteRenderbuffersEXT(1, Pointee(service_id
)))
1109 .RetiresOnSaturation();
1110 GenHelper
<cmds::DeleteRenderbuffersImmediate
>(client_id
);
1113 void GLES2DecoderTestBase::DoBindTexture(
1114 GLenum target
, GLuint client_id
, GLuint service_id
) {
1115 EXPECT_CALL(*gl_
, BindTexture(target
, service_id
))
1117 .RetiresOnSaturation();
1118 cmds::BindTexture cmd
;
1119 cmd
.Init(target
, client_id
);
1120 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1123 bool GLES2DecoderTestBase::DoIsTexture(GLuint client_id
) {
1124 return IsObjectHelper
<cmds::IsTexture
, cmds::IsTexture::Result
>(client_id
);
1127 void GLES2DecoderTestBase::DoDeleteTexture(
1128 GLuint client_id
, GLuint service_id
) {
1129 EXPECT_CALL(*gl_
, DeleteTextures(1, Pointee(service_id
)))
1131 .RetiresOnSaturation();
1132 GenHelper
<cmds::DeleteTexturesImmediate
>(client_id
);
1135 void GLES2DecoderTestBase::DoBindTexImage2DCHROMIUM(GLenum target
,
1137 cmds::BindTexImage2DCHROMIUM bind_tex_image_2d_cmd
;
1138 bind_tex_image_2d_cmd
.Init(target
, image_id
);
1139 EXPECT_CALL(*gl_
, GetError())
1140 .WillOnce(Return(GL_NO_ERROR
))
1141 .WillOnce(Return(GL_NO_ERROR
))
1142 .RetiresOnSaturation();
1143 EXPECT_EQ(error::kNoError
, ExecuteCmd(bind_tex_image_2d_cmd
));
1144 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1147 void GLES2DecoderTestBase::DoTexImage2D(
1148 GLenum target
, GLint level
, GLenum internal_format
,
1149 GLsizei width
, GLsizei height
, GLint border
,
1150 GLenum format
, GLenum type
,
1151 uint32 shared_memory_id
, uint32 shared_memory_offset
) {
1152 EXPECT_CALL(*gl_
, GetError())
1153 .WillOnce(Return(GL_NO_ERROR
))
1154 .RetiresOnSaturation();
1155 EXPECT_CALL(*gl_
, TexImage2D(target
, level
, internal_format
,
1156 width
, height
, border
, format
, type
, _
))
1158 .RetiresOnSaturation();
1159 EXPECT_CALL(*gl_
, GetError())
1160 .WillOnce(Return(GL_NO_ERROR
))
1161 .RetiresOnSaturation();
1162 cmds::TexImage2D cmd
;
1163 cmd
.Init(target
, level
, internal_format
, width
, height
, format
,
1164 type
, shared_memory_id
, shared_memory_offset
);
1165 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1168 void GLES2DecoderTestBase::DoTexImage2DConvertInternalFormat(
1169 GLenum target
, GLint level
, GLenum requested_internal_format
,
1170 GLsizei width
, GLsizei height
, GLint border
,
1171 GLenum format
, GLenum type
,
1172 uint32 shared_memory_id
, uint32 shared_memory_offset
,
1173 GLenum expected_internal_format
) {
1174 EXPECT_CALL(*gl_
, GetError())
1175 .WillOnce(Return(GL_NO_ERROR
))
1176 .RetiresOnSaturation();
1177 EXPECT_CALL(*gl_
, TexImage2D(target
, level
, expected_internal_format
,
1178 width
, height
, border
, format
, type
, _
))
1180 .RetiresOnSaturation();
1181 EXPECT_CALL(*gl_
, GetError())
1182 .WillOnce(Return(GL_NO_ERROR
))
1183 .RetiresOnSaturation();
1184 cmds::TexImage2D cmd
;
1185 cmd
.Init(target
, level
, requested_internal_format
, width
, height
,
1186 format
, type
, shared_memory_id
, shared_memory_offset
);
1187 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1190 void GLES2DecoderTestBase::DoCompressedTexImage2D(
1191 GLenum target
, GLint level
, GLenum format
,
1192 GLsizei width
, GLsizei height
, GLint border
,
1193 GLsizei size
, uint32 bucket_id
) {
1194 EXPECT_CALL(*gl_
, GetError())
1195 .WillOnce(Return(GL_NO_ERROR
))
1196 .RetiresOnSaturation();
1197 EXPECT_CALL(*gl_
, CompressedTexImage2D(
1198 target
, level
, format
, width
, height
, border
, size
, _
))
1200 .RetiresOnSaturation();
1201 EXPECT_CALL(*gl_
, GetError())
1202 .WillOnce(Return(GL_NO_ERROR
))
1203 .RetiresOnSaturation();
1204 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(bucket_id
);
1205 bucket
->SetSize(size
);
1206 cmds::CompressedTexImage2DBucket cmd
;
1208 target
, level
, format
, width
, height
,
1210 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1213 void GLES2DecoderTestBase::DoRenderbufferStorage(
1214 GLenum target
, GLenum internal_format
, GLenum actual_format
,
1215 GLsizei width
, GLsizei height
, GLenum error
) {
1216 EXPECT_CALL(*gl_
, GetError())
1217 .WillOnce(Return(GL_NO_ERROR
))
1218 .RetiresOnSaturation();
1219 EXPECT_CALL(*gl_
, RenderbufferStorageEXT(
1220 target
, actual_format
, width
, height
))
1222 .RetiresOnSaturation();
1223 EXPECT_CALL(*gl_
, GetError())
1224 .WillOnce(Return(error
))
1225 .RetiresOnSaturation();
1226 cmds::RenderbufferStorage cmd
;
1227 cmd
.Init(target
, internal_format
, width
, height
);
1228 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1231 void GLES2DecoderTestBase::DoFramebufferTexture2D(
1232 GLenum target
, GLenum attachment
, GLenum textarget
,
1233 GLuint texture_client_id
, GLuint texture_service_id
, GLint level
,
1235 EXPECT_CALL(*gl_
, GetError())
1236 .WillOnce(Return(GL_NO_ERROR
))
1237 .RetiresOnSaturation();
1238 EXPECT_CALL(*gl_
, FramebufferTexture2DEXT(
1239 target
, attachment
, textarget
, texture_service_id
, level
))
1241 .RetiresOnSaturation();
1242 EXPECT_CALL(*gl_
, GetError())
1243 .WillOnce(Return(error
))
1244 .RetiresOnSaturation();
1245 cmds::FramebufferTexture2D cmd
;
1246 cmd
.Init(target
, attachment
, textarget
, texture_client_id
);
1247 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1250 void GLES2DecoderTestBase::DoFramebufferRenderbuffer(
1253 GLenum renderbuffer_target
,
1254 GLuint renderbuffer_client_id
,
1255 GLuint renderbuffer_service_id
,
1257 EXPECT_CALL(*gl_
, GetError())
1258 .WillOnce(Return(GL_NO_ERROR
))
1259 .RetiresOnSaturation();
1260 EXPECT_CALL(*gl_
, FramebufferRenderbufferEXT(
1261 target
, attachment
, renderbuffer_target
, renderbuffer_service_id
))
1263 .RetiresOnSaturation();
1264 EXPECT_CALL(*gl_
, GetError())
1265 .WillOnce(Return(error
))
1266 .RetiresOnSaturation();
1267 cmds::FramebufferRenderbuffer cmd
;
1268 cmd
.Init(target
, attachment
, renderbuffer_target
, renderbuffer_client_id
);
1269 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1272 void GLES2DecoderTestBase::DoVertexAttribPointer(
1273 GLuint index
, GLint size
, GLenum type
, GLsizei stride
, GLuint offset
) {
1275 VertexAttribPointer(index
, size
, type
, GL_FALSE
, stride
,
1276 BufferOffset(offset
)))
1278 .RetiresOnSaturation();
1279 cmds::VertexAttribPointer cmd
;
1280 cmd
.Init(index
, size
, GL_FLOAT
, GL_FALSE
, stride
, offset
);
1281 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1284 void GLES2DecoderTestBase::DoVertexAttribDivisorANGLE(
1285 GLuint index
, GLuint divisor
) {
1287 VertexAttribDivisorANGLE(index
, divisor
))
1289 .RetiresOnSaturation();
1290 cmds::VertexAttribDivisorANGLE cmd
;
1291 cmd
.Init(index
, divisor
);
1292 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1295 void GLES2DecoderTestBase::AddExpectationsForGenVertexArraysOES(){
1296 if (group_
->feature_info()->feature_flags().native_vertex_array_object
) {
1297 EXPECT_CALL(*gl_
, GenVertexArraysOES(1, _
))
1298 .WillOnce(SetArgumentPointee
<1>(kServiceVertexArrayId
))
1299 .RetiresOnSaturation();
1303 void GLES2DecoderTestBase::AddExpectationsForDeleteVertexArraysOES(){
1304 if (group_
->feature_info()->feature_flags().native_vertex_array_object
) {
1305 EXPECT_CALL(*gl_
, DeleteVertexArraysOES(1, _
))
1307 .RetiresOnSaturation();
1311 void GLES2DecoderTestBase::AddExpectationsForDeleteBoundVertexArraysOES() {
1312 // Expectations are the same as a delete, followed by binding VAO 0.
1313 AddExpectationsForDeleteVertexArraysOES();
1314 AddExpectationsForBindVertexArrayOES();
1317 void GLES2DecoderTestBase::AddExpectationsForBindVertexArrayOES() {
1318 if (group_
->feature_info()->feature_flags().native_vertex_array_object
) {
1319 EXPECT_CALL(*gl_
, BindVertexArrayOES(_
))
1321 .RetiresOnSaturation();
1323 for (uint32 vv
= 0; vv
< group_
->max_vertex_attribs(); ++vv
) {
1324 AddExpectationsForRestoreAttribState(vv
);
1327 EXPECT_CALL(*gl_
, BindBuffer(GL_ELEMENT_ARRAY_BUFFER
, _
))
1329 .RetiresOnSaturation();
1333 void GLES2DecoderTestBase::AddExpectationsForRestoreAttribState(GLuint attrib
) {
1334 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, _
))
1336 .RetiresOnSaturation();
1338 EXPECT_CALL(*gl_
, VertexAttribPointer(attrib
, _
, _
, _
, _
, _
))
1340 .RetiresOnSaturation();
1342 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(attrib
, _
))
1343 .Times(testing::AtMost(1))
1344 .RetiresOnSaturation();
1346 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, _
))
1348 .RetiresOnSaturation();
1351 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2
) {
1353 // TODO(bajones): Not sure if I can tell which of these will be called
1354 EXPECT_CALL(*gl_
, EnableVertexAttribArray(attrib
))
1355 .Times(testing::AtMost(1))
1356 .RetiresOnSaturation();
1358 EXPECT_CALL(*gl_
, DisableVertexAttribArray(attrib
))
1359 .Times(testing::AtMost(1))
1360 .RetiresOnSaturation();
1364 // GCC requires these declarations, but MSVC requires they not be present
1365 #ifndef COMPILER_MSVC
1366 const int GLES2DecoderTestBase::kBackBufferWidth
;
1367 const int GLES2DecoderTestBase::kBackBufferHeight
;
1369 const GLint
GLES2DecoderTestBase::kMaxTextureSize
;
1370 const GLint
GLES2DecoderTestBase::kMaxCubeMapTextureSize
;
1371 const GLint
GLES2DecoderTestBase::kNumVertexAttribs
;
1372 const GLint
GLES2DecoderTestBase::kNumTextureUnits
;
1373 const GLint
GLES2DecoderTestBase::kMaxTextureImageUnits
;
1374 const GLint
GLES2DecoderTestBase::kMaxVertexTextureImageUnits
;
1375 const GLint
GLES2DecoderTestBase::kMaxFragmentUniformVectors
;
1376 const GLint
GLES2DecoderTestBase::kMaxVaryingVectors
;
1377 const GLint
GLES2DecoderTestBase::kMaxVertexUniformVectors
;
1378 const GLint
GLES2DecoderTestBase::kMaxViewportWidth
;
1379 const GLint
GLES2DecoderTestBase::kMaxViewportHeight
;
1381 const GLint
GLES2DecoderTestBase::kViewportX
;
1382 const GLint
GLES2DecoderTestBase::kViewportY
;
1383 const GLint
GLES2DecoderTestBase::kViewportWidth
;
1384 const GLint
GLES2DecoderTestBase::kViewportHeight
;
1386 const GLuint
GLES2DecoderTestBase::kServiceAttrib0BufferId
;
1387 const GLuint
GLES2DecoderTestBase::kServiceFixedAttribBufferId
;
1389 const GLuint
GLES2DecoderTestBase::kServiceBufferId
;
1390 const GLuint
GLES2DecoderTestBase::kServiceFramebufferId
;
1391 const GLuint
GLES2DecoderTestBase::kServiceRenderbufferId
;
1392 const GLuint
GLES2DecoderTestBase::kServiceSamplerId
;
1393 const GLuint
GLES2DecoderTestBase::kServiceTextureId
;
1394 const GLuint
GLES2DecoderTestBase::kServiceProgramId
;
1395 const GLuint
GLES2DecoderTestBase::kServiceShaderId
;
1396 const GLuint
GLES2DecoderTestBase::kServiceElementBufferId
;
1397 const GLuint
GLES2DecoderTestBase::kServiceQueryId
;
1398 const GLuint
GLES2DecoderTestBase::kServiceVertexArrayId
;
1399 const GLuint
GLES2DecoderTestBase::kServiceTransformFeedbackId
;
1400 const GLuint
GLES2DecoderTestBase::kServiceSyncId
;
1402 const int32
GLES2DecoderTestBase::kSharedMemoryId
;
1403 const size_t GLES2DecoderTestBase::kSharedBufferSize
;
1404 const uint32
GLES2DecoderTestBase::kSharedMemoryOffset
;
1405 const int32
GLES2DecoderTestBase::kInvalidSharedMemoryId
;
1406 const uint32
GLES2DecoderTestBase::kInvalidSharedMemoryOffset
;
1407 const uint32
GLES2DecoderTestBase::kInitialResult
;
1408 const uint8
GLES2DecoderTestBase::kInitialMemoryValue
;
1410 const uint32
GLES2DecoderTestBase::kNewClientId
;
1411 const uint32
GLES2DecoderTestBase::kNewServiceId
;
1412 const uint32
GLES2DecoderTestBase::kInvalidClientId
;
1414 const GLuint
GLES2DecoderTestBase::kServiceVertexShaderId
;
1415 const GLuint
GLES2DecoderTestBase::kServiceFragmentShaderId
;
1417 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumShaderId
;
1418 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumProgramId
;
1420 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumTextureBufferId
;
1421 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumVertexBufferId
;
1422 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumFBOId
;
1423 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumPositionAttrib
;
1424 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumTexAttrib
;
1425 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumSamplerLocation
;
1427 const GLsizei
GLES2DecoderTestBase::kNumVertices
;
1428 const GLsizei
GLES2DecoderTestBase::kNumIndices
;
1429 const int GLES2DecoderTestBase::kValidIndexRangeStart
;
1430 const int GLES2DecoderTestBase::kValidIndexRangeCount
;
1431 const int GLES2DecoderTestBase::kInvalidIndexRangeStart
;
1432 const int GLES2DecoderTestBase::kInvalidIndexRangeCount
;
1433 const int GLES2DecoderTestBase::kOutOfRangeIndexRangeEnd
;
1434 const GLuint
GLES2DecoderTestBase::kMaxValidIndex
;
1436 const GLint
GLES2DecoderTestBase::kMaxAttribLength
;
1437 const GLint
GLES2DecoderTestBase::kAttrib1Size
;
1438 const GLint
GLES2DecoderTestBase::kAttrib2Size
;
1439 const GLint
GLES2DecoderTestBase::kAttrib3Size
;
1440 const GLint
GLES2DecoderTestBase::kAttrib1Location
;
1441 const GLint
GLES2DecoderTestBase::kAttrib2Location
;
1442 const GLint
GLES2DecoderTestBase::kAttrib3Location
;
1443 const GLenum
GLES2DecoderTestBase::kAttrib1Type
;
1444 const GLenum
GLES2DecoderTestBase::kAttrib2Type
;
1445 const GLenum
GLES2DecoderTestBase::kAttrib3Type
;
1446 const GLint
GLES2DecoderTestBase::kInvalidAttribLocation
;
1447 const GLint
GLES2DecoderTestBase::kBadAttribIndex
;
1449 const GLint
GLES2DecoderTestBase::kMaxUniformLength
;
1450 const GLint
GLES2DecoderTestBase::kUniform1Size
;
1451 const GLint
GLES2DecoderTestBase::kUniform2Size
;
1452 const GLint
GLES2DecoderTestBase::kUniform3Size
;
1453 const GLint
GLES2DecoderTestBase::kUniform1RealLocation
;
1454 const GLint
GLES2DecoderTestBase::kUniform2RealLocation
;
1455 const GLint
GLES2DecoderTestBase::kUniform2ElementRealLocation
;
1456 const GLint
GLES2DecoderTestBase::kUniform3RealLocation
;
1457 const GLint
GLES2DecoderTestBase::kUniform1FakeLocation
;
1458 const GLint
GLES2DecoderTestBase::kUniform2FakeLocation
;
1459 const GLint
GLES2DecoderTestBase::kUniform2ElementFakeLocation
;
1460 const GLint
GLES2DecoderTestBase::kUniform3FakeLocation
;
1461 const GLint
GLES2DecoderTestBase::kUniform1DesiredLocation
;
1462 const GLint
GLES2DecoderTestBase::kUniform2DesiredLocation
;
1463 const GLint
GLES2DecoderTestBase::kUniform3DesiredLocation
;
1464 const GLenum
GLES2DecoderTestBase::kUniform1Type
;
1465 const GLenum
GLES2DecoderTestBase::kUniform2Type
;
1466 const GLenum
GLES2DecoderTestBase::kUniform3Type
;
1467 const GLenum
GLES2DecoderTestBase::kUniformCubemapType
;
1468 const GLint
GLES2DecoderTestBase::kInvalidUniformLocation
;
1469 const GLint
GLES2DecoderTestBase::kBadUniformIndex
;
1473 const char* GLES2DecoderTestBase::kAttrib1Name
= "attrib1";
1474 const char* GLES2DecoderTestBase::kAttrib2Name
= "attrib2";
1475 const char* GLES2DecoderTestBase::kAttrib3Name
= "attrib3";
1476 const char* GLES2DecoderTestBase::kUniform1Name
= "uniform1";
1477 const char* GLES2DecoderTestBase::kUniform2Name
= "uniform2[0]";
1478 const char* GLES2DecoderTestBase::kUniform3Name
= "uniform3[0]";
1480 void GLES2DecoderTestBase::SetupDefaultProgram() {
1482 static AttribInfo attribs
[] = {
1483 { kAttrib1Name
, kAttrib1Size
, kAttrib1Type
, kAttrib1Location
, },
1484 { kAttrib2Name
, kAttrib2Size
, kAttrib2Type
, kAttrib2Location
, },
1485 { kAttrib3Name
, kAttrib3Size
, kAttrib3Type
, kAttrib3Location
, },
1487 static UniformInfo uniforms
[] = {
1488 { kUniform1Name
, kUniform1Size
, kUniform1Type
,
1489 kUniform1FakeLocation
, kUniform1RealLocation
,
1490 kUniform1DesiredLocation
},
1491 { kUniform2Name
, kUniform2Size
, kUniform2Type
,
1492 kUniform2FakeLocation
, kUniform2RealLocation
,
1493 kUniform2DesiredLocation
},
1494 { kUniform3Name
, kUniform3Size
, kUniform3Type
,
1495 kUniform3FakeLocation
, kUniform3RealLocation
,
1496 kUniform3DesiredLocation
},
1498 SetupShader(attribs
, arraysize(attribs
), uniforms
, arraysize(uniforms
),
1499 client_program_id_
, kServiceProgramId
,
1500 client_vertex_shader_id_
, kServiceVertexShaderId
,
1501 client_fragment_shader_id_
, kServiceFragmentShaderId
);
1505 EXPECT_CALL(*gl_
, UseProgram(kServiceProgramId
))
1507 .RetiresOnSaturation();
1508 cmds::UseProgram cmd
;
1509 cmd
.Init(client_program_id_
);
1510 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1514 void GLES2DecoderTestBase::SetupCubemapProgram() {
1516 static AttribInfo attribs
[] = {
1517 { kAttrib1Name
, kAttrib1Size
, kAttrib1Type
, kAttrib1Location
, },
1518 { kAttrib2Name
, kAttrib2Size
, kAttrib2Type
, kAttrib2Location
, },
1519 { kAttrib3Name
, kAttrib3Size
, kAttrib3Type
, kAttrib3Location
, },
1521 static UniformInfo uniforms
[] = {
1522 { kUniform1Name
, kUniform1Size
, kUniformCubemapType
,
1523 kUniform1FakeLocation
, kUniform1RealLocation
,
1524 kUniform1DesiredLocation
, },
1525 { kUniform2Name
, kUniform2Size
, kUniform2Type
,
1526 kUniform2FakeLocation
, kUniform2RealLocation
,
1527 kUniform2DesiredLocation
, },
1528 { kUniform3Name
, kUniform3Size
, kUniform3Type
,
1529 kUniform3FakeLocation
, kUniform3RealLocation
,
1530 kUniform3DesiredLocation
, },
1532 SetupShader(attribs
, arraysize(attribs
), uniforms
, arraysize(uniforms
),
1533 client_program_id_
, kServiceProgramId
,
1534 client_vertex_shader_id_
, kServiceVertexShaderId
,
1535 client_fragment_shader_id_
, kServiceFragmentShaderId
);
1539 EXPECT_CALL(*gl_
, UseProgram(kServiceProgramId
))
1541 .RetiresOnSaturation();
1542 cmds::UseProgram cmd
;
1543 cmd
.Init(client_program_id_
);
1544 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1548 void GLES2DecoderTestBase::SetupSamplerExternalProgram() {
1550 static AttribInfo attribs
[] = {
1551 { kAttrib1Name
, kAttrib1Size
, kAttrib1Type
, kAttrib1Location
, },
1552 { kAttrib2Name
, kAttrib2Size
, kAttrib2Type
, kAttrib2Location
, },
1553 { kAttrib3Name
, kAttrib3Size
, kAttrib3Type
, kAttrib3Location
, },
1555 static UniformInfo uniforms
[] = {
1556 { kUniform1Name
, kUniform1Size
, kUniformSamplerExternalType
,
1557 kUniform1FakeLocation
, kUniform1RealLocation
,
1558 kUniform1DesiredLocation
, },
1559 { kUniform2Name
, kUniform2Size
, kUniform2Type
,
1560 kUniform2FakeLocation
, kUniform2RealLocation
,
1561 kUniform2DesiredLocation
, },
1562 { kUniform3Name
, kUniform3Size
, kUniform3Type
,
1563 kUniform3FakeLocation
, kUniform3RealLocation
,
1564 kUniform3DesiredLocation
, },
1566 SetupShader(attribs
, arraysize(attribs
), uniforms
, arraysize(uniforms
),
1567 client_program_id_
, kServiceProgramId
,
1568 client_vertex_shader_id_
, kServiceVertexShaderId
,
1569 client_fragment_shader_id_
, kServiceFragmentShaderId
);
1573 EXPECT_CALL(*gl_
, UseProgram(kServiceProgramId
))
1575 .RetiresOnSaturation();
1576 cmds::UseProgram cmd
;
1577 cmd
.Init(client_program_id_
);
1578 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1582 void GLES2DecoderWithShaderTestBase::TearDown() {
1583 GLES2DecoderTestBase::TearDown();
1586 void GLES2DecoderTestBase::SetupShader(
1587 GLES2DecoderTestBase::AttribInfo
* attribs
, size_t num_attribs
,
1588 GLES2DecoderTestBase::UniformInfo
* uniforms
, size_t num_uniforms
,
1589 GLuint program_client_id
, GLuint program_service_id
,
1590 GLuint vertex_shader_client_id
, GLuint vertex_shader_service_id
,
1591 GLuint fragment_shader_client_id
, GLuint fragment_shader_service_id
) {
1596 AttachShader(program_service_id
, vertex_shader_service_id
))
1598 .RetiresOnSaturation();
1600 AttachShader(program_service_id
, fragment_shader_service_id
))
1602 .RetiresOnSaturation();
1603 TestHelper::SetupShader(
1604 gl_
.get(), attribs
, num_attribs
, uniforms
, num_uniforms
,
1605 program_service_id
);
1609 GL_VERTEX_SHADER
, vertex_shader_client_id
, vertex_shader_service_id
);
1611 GL_FRAGMENT_SHADER
, fragment_shader_client_id
,
1612 fragment_shader_service_id
);
1614 TestHelper::SetShaderStates(
1615 gl_
.get(), GetShader(vertex_shader_client_id
), true);
1616 TestHelper::SetShaderStates(
1617 gl_
.get(), GetShader(fragment_shader_client_id
), true);
1619 cmds::AttachShader attach_cmd
;
1620 attach_cmd
.Init(program_client_id
, vertex_shader_client_id
);
1621 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
1623 attach_cmd
.Init(program_client_id
, fragment_shader_client_id
);
1624 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
1626 cmds::LinkProgram link_cmd
;
1627 link_cmd
.Init(program_client_id
);
1629 EXPECT_EQ(error::kNoError
, ExecuteCmd(link_cmd
));
1632 void GLES2DecoderTestBase::DoEnableDisable(GLenum cap
, bool enable
) {
1633 SetupExpectationsForEnableDisable(cap
, enable
);
1637 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1641 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1645 void GLES2DecoderTestBase::DoEnableVertexAttribArray(GLint index
) {
1646 EXPECT_CALL(*gl_
, EnableVertexAttribArray(index
))
1648 .RetiresOnSaturation();
1649 cmds::EnableVertexAttribArray cmd
;
1651 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1654 void GLES2DecoderTestBase::DoBufferData(GLenum target
, GLsizei size
) {
1655 EXPECT_CALL(*gl_
, GetError())
1656 .WillOnce(Return(GL_NO_ERROR
))
1657 .RetiresOnSaturation();
1658 EXPECT_CALL(*gl_
, BufferData(target
, size
, _
, GL_STREAM_DRAW
))
1660 .RetiresOnSaturation();
1661 EXPECT_CALL(*gl_
, GetError())
1662 .WillOnce(Return(GL_NO_ERROR
))
1663 .RetiresOnSaturation();
1664 cmds::BufferData cmd
;
1665 cmd
.Init(target
, size
, 0, 0, GL_STREAM_DRAW
);
1666 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1669 void GLES2DecoderTestBase::DoBufferSubData(
1670 GLenum target
, GLint offset
, GLsizei size
, const void* data
) {
1671 EXPECT_CALL(*gl_
, BufferSubData(target
, offset
, size
,
1672 shared_memory_address_
))
1674 .RetiresOnSaturation();
1675 memcpy(shared_memory_address_
, data
, size
);
1676 cmds::BufferSubData cmd
;
1677 cmd
.Init(target
, offset
, size
, shared_memory_id_
, shared_memory_offset_
);
1678 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1681 void GLES2DecoderTestBase::DoScissor(GLint x
,
1685 EXPECT_CALL(*gl_
, Scissor(x
, y
, width
, height
))
1687 .RetiresOnSaturation();
1689 cmd
.Init(x
, y
, width
, height
);
1690 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1693 void GLES2DecoderTestBase::SetupVertexBuffer() {
1694 DoEnableVertexAttribArray(1);
1695 DoBindBuffer(GL_ARRAY_BUFFER
, client_buffer_id_
, kServiceBufferId
);
1696 DoBufferData(GL_ARRAY_BUFFER
, kNumVertices
* 2 * sizeof(GLfloat
));
1699 void GLES2DecoderTestBase::SetupAllNeededVertexBuffers() {
1700 DoBindBuffer(GL_ARRAY_BUFFER
, client_buffer_id_
, kServiceBufferId
);
1701 DoBufferData(GL_ARRAY_BUFFER
, kNumVertices
* 16 * sizeof(float));
1702 DoEnableVertexAttribArray(0);
1703 DoEnableVertexAttribArray(1);
1704 DoEnableVertexAttribArray(2);
1705 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1706 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1707 DoVertexAttribPointer(2, 2, GL_FLOAT
, 0, 0);
1710 void GLES2DecoderTestBase::SetupIndexBuffer() {
1711 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER
,
1712 client_element_buffer_id_
,
1713 kServiceElementBufferId
);
1714 static const GLshort indices
[] = {100, 1, 2, 3, 4, 5, 6, 7, 100, 9};
1715 static_assert(arraysize(indices
) == kNumIndices
,
1716 "indices should have kNumIndices elements");
1717 DoBufferData(GL_ELEMENT_ARRAY_BUFFER
, sizeof(indices
));
1718 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER
, 0, 2, indices
);
1719 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER
, 2, sizeof(indices
) - 2, &indices
[1]);
1722 void GLES2DecoderTestBase::SetupTexture() {
1723 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1724 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
1725 kSharedMemoryId
, kSharedMemoryOffset
);
1728 void GLES2DecoderTestBase::DeleteVertexBuffer() {
1729 DoDeleteBuffer(client_buffer_id_
, kServiceBufferId
);
1732 void GLES2DecoderTestBase::DeleteIndexBuffer() {
1733 DoDeleteBuffer(client_element_buffer_id_
, kServiceElementBufferId
);
1736 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0WithError(
1737 GLsizei num_vertices
, GLuint buffer_id
, GLenum error
) {
1738 if (group_
->feature_info()->gl_version_info().BehavesLikeGLES()) {
1742 EXPECT_CALL(*gl_
, GetError())
1743 .WillOnce(Return(GL_NO_ERROR
))
1744 .WillOnce(Return(error
))
1745 .RetiresOnSaturation();
1746 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, kServiceAttrib0BufferId
))
1748 .RetiresOnSaturation();
1749 EXPECT_CALL(*gl_
, BufferData(GL_ARRAY_BUFFER
,
1750 num_vertices
* sizeof(GLfloat
) * 4,
1751 _
, GL_DYNAMIC_DRAW
))
1753 .RetiresOnSaturation();
1754 if (error
== GL_NO_ERROR
) {
1755 EXPECT_CALL(*gl_
, BufferSubData(
1756 GL_ARRAY_BUFFER
, 0, num_vertices
* sizeof(GLfloat
) * 4, _
))
1758 .RetiresOnSaturation();
1759 EXPECT_CALL(*gl_
, VertexAttribPointer(0, 4, GL_FLOAT
, GL_FALSE
, 0, NULL
))
1761 .RetiresOnSaturation();
1762 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, buffer_id
))
1764 .RetiresOnSaturation();
1768 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0(
1769 GLsizei num_vertices
, GLuint buffer_id
) {
1770 AddExpectationsForSimulatedAttrib0WithError(
1771 num_vertices
, buffer_id
, GL_NO_ERROR
);
1774 void GLES2DecoderTestBase::SetupMockGLBehaviors() {
1775 ON_CALL(*gl_
, BindVertexArrayOES(_
))
1776 .WillByDefault(Invoke(
1778 &GLES2DecoderTestBase::MockGLStates::OnBindVertexArrayOES
));
1779 ON_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, _
))
1780 .WillByDefault(WithArg
<1>(Invoke(
1782 &GLES2DecoderTestBase::MockGLStates::OnBindArrayBuffer
)));
1783 ON_CALL(*gl_
, VertexAttribPointer(_
, _
, _
, _
, _
, NULL
))
1784 .WillByDefault(InvokeWithoutArgs(
1786 &GLES2DecoderTestBase::MockGLStates::OnVertexAttribNullPointer
));
1789 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1790 MockCommandBufferEngine() {
1792 scoped_ptr
<base::SharedMemory
> shm(new base::SharedMemory());
1793 shm
->CreateAndMapAnonymous(kSharedBufferSize
);
1794 valid_buffer_
= MakeBufferFromSharedMemory(shm
.Pass(), kSharedBufferSize
);
1796 ClearSharedMemory();
1799 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1800 ~MockCommandBufferEngine() {}
1802 scoped_refptr
<gpu::Buffer
>
1803 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetSharedMemoryBuffer(
1805 return shm_id
== kSharedMemoryId
? valid_buffer_
: invalid_buffer_
;
1808 void GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::set_token(
1813 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetBuffer(
1814 int32
/* transfer_buffer_id */) {
1819 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetOffset(
1825 int32
GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetGetOffset() {
1830 void GLES2DecoderWithShaderTestBase::SetUp() {
1831 GLES2DecoderTestBase::SetUp();
1832 SetupDefaultProgram();
1835 // Include the auto-generated part of this file. We split this because it means
1836 // we can easily edit the non-auto generated parts right here in this file
1837 // instead of having to edit some template or the code generator.
1838 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h"
1840 } // namespace gles2