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/gl_surface.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 (StartsWithASCII(init
->gl_version
, "opengl es", false)) {
67 init
->extensions
+= kVAOExtensions
[0];
69 #if !defined(OS_MACOSX)
70 init
->extensions
+= kVAOExtensions
[1];
72 init
->extensions
+= kVAOExtensions
[2];
76 // Make sure we don't set up an invalid InitState.
77 CHECK(!contains_vao_extension
);
80 if (!init
->extensions
.empty())
81 init
->extensions
+= " ";
82 init
->extensions
+= "GL_EXT_framebuffer_object ";
85 } // namespace Anonymous
90 GLES2DecoderTestBase::GLES2DecoderTestBase()
93 memory_tracker_(NULL
),
94 client_buffer_id_(100),
95 client_framebuffer_id_(101),
96 client_program_id_(102),
97 client_renderbuffer_id_(103),
98 client_sampler_id_(104),
99 client_shader_id_(105),
100 client_texture_id_(106),
101 client_element_buffer_id_(107),
102 client_vertex_shader_id_(121),
103 client_fragment_shader_id_(122),
104 client_query_id_(123),
105 client_vertexarray_id_(124),
106 client_valuebuffer_id_(125),
107 client_transformfeedback_id_(126),
108 client_sync_id_(127),
109 service_renderbuffer_id_(0),
110 service_renderbuffer_valid_(false),
111 ignore_cached_state_for_test_(GetParam()),
112 cached_color_mask_red_(true),
113 cached_color_mask_green_(true),
114 cached_color_mask_blue_(true),
115 cached_color_mask_alpha_(true),
116 cached_depth_mask_(true),
117 cached_stencil_front_mask_(static_cast<GLuint
>(-1)),
118 cached_stencil_back_mask_(static_cast<GLuint
>(-1)) {
119 memset(immediate_buffer_
, 0xEE, sizeof(immediate_buffer_
));
122 GLES2DecoderTestBase::~GLES2DecoderTestBase() {}
124 void GLES2DecoderTestBase::SetUp() {
126 // Autogenerated tests do not overwrite version or extension string,
127 // so we have to pick something that supports everything here.
128 init
.gl_version
= "4.4";
129 init
.has_alpha
= true;
130 init
.has_depth
= true;
131 init
.request_alpha
= true;
132 init
.request_depth
= true;
133 init
.bind_generates_resource
= true;
137 void GLES2DecoderTestBase::AddExpectationsForVertexAttribManager() {
138 for (GLint ii
= 0; ii
< kNumVertexAttribs
; ++ii
) {
139 EXPECT_CALL(*gl_
, VertexAttrib4f(ii
, 0.0f
, 0.0f
, 0.0f
, 1.0f
))
141 .RetiresOnSaturation();
145 GLES2DecoderTestBase::InitState::InitState()
146 : extensions("GL_EXT_framebuffer_object"),
151 request_alpha(false),
152 request_depth(false),
153 request_stencil(false),
154 bind_generates_resource(false),
155 lose_context_when_out_of_memory(false),
156 use_native_vao(true) {
159 void GLES2DecoderTestBase::InitDecoder(const InitState
& init
) {
160 InitDecoderWithCommandLine(init
, NULL
);
163 void GLES2DecoderTestBase::InitDecoderWithCommandLine(
164 const InitState
& init
,
165 const base::CommandLine
* command_line
) {
166 InitState normalized_init
= init
;
167 NormalizeInitState(&normalized_init
);
168 // For easier substring/extension matching
169 DCHECK(normalized_init
.extensions
.empty() ||
170 *normalized_init
.extensions
.rbegin() == ' ');
171 Framebuffer::ClearFramebufferCompleteComboMap();
173 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress
);
174 gfx::GLSurface::InitializeOneOffWithMockBindingsForTests();
176 gl_
.reset(new StrictMock
<MockGLInterface
>());
177 ::gfx::MockGLInterface::SetGLInterface(gl_
.get());
179 SetupMockGLBehaviors();
181 scoped_refptr
<FeatureInfo
> feature_info
;
183 feature_info
= new FeatureInfo(*command_line
);
184 group_
= scoped_refptr
<ContextGroup
>(
185 new ContextGroup(NULL
,
187 new ShaderTranslatorCache
,
189 new SubscriptionRefSet
,
191 normalized_init
.bind_generates_resource
));
192 bool use_default_textures
= normalized_init
.bind_generates_resource
;
196 surface_
= new gfx::GLSurfaceStub
;
197 surface_
->SetSize(gfx::Size(kBackBufferWidth
, kBackBufferHeight
));
199 // Context needs to be created before initializing ContextGroup, which will
200 // in turn initialize FeatureInfo, which needs a context to determine
201 // extension support.
202 context_
= new gfx::GLContextStubWithExtensions
;
203 context_
->AddExtensionsString(normalized_init
.extensions
.c_str());
204 context_
->SetGLVersionString(normalized_init
.gl_version
.c_str());
206 context_
->MakeCurrent(surface_
.get());
207 gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_
.get());
209 TestHelper::SetupContextGroupInitExpectations(
211 DisallowedFeatures(),
212 normalized_init
.extensions
.c_str(),
213 normalized_init
.gl_version
.c_str(),
214 normalized_init
.bind_generates_resource
);
216 // We initialize the ContextGroup with a MockGLES2Decoder so that
217 // we can use the ContextGroup to figure out how the real GLES2Decoder
218 // will initialize itself.
219 mock_decoder_
.reset(new MockGLES2Decoder());
221 // Install FakeDoCommands handler so we can use individual DoCommand()
223 EXPECT_CALL(*mock_decoder_
, DoCommands(_
, _
, _
, _
)).WillRepeatedly(
224 Invoke(mock_decoder_
.get(), &MockGLES2Decoder::FakeDoCommands
));
227 group_
->Initialize(mock_decoder_
.get(), DisallowedFeatures()));
229 if (group_
->feature_info()->feature_flags().native_vertex_array_object
) {
230 EXPECT_CALL(*gl_
, GenVertexArraysOES(1, _
))
231 .WillOnce(SetArgumentPointee
<1>(kServiceVertexArrayId
))
232 .RetiresOnSaturation();
233 EXPECT_CALL(*gl_
, BindVertexArrayOES(_
)).Times(1).RetiresOnSaturation();
236 if (group_
->feature_info()->workarounds().init_vertex_attributes
)
237 AddExpectationsForVertexAttribManager();
239 AddExpectationsForBindVertexArrayOES();
241 EXPECT_CALL(*gl_
, EnableVertexAttribArray(0))
243 .RetiresOnSaturation();
244 static GLuint attrib_0_id
[] = {
245 kServiceAttrib0BufferId
,
247 static GLuint fixed_attrib_buffer_id
[] = {
248 kServiceFixedAttribBufferId
,
250 EXPECT_CALL(*gl_
, GenBuffersARB(arraysize(attrib_0_id
), _
))
251 .WillOnce(SetArrayArgument
<1>(attrib_0_id
,
252 attrib_0_id
+ arraysize(attrib_0_id
)))
253 .RetiresOnSaturation();
254 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, kServiceAttrib0BufferId
))
256 .RetiresOnSaturation();
257 EXPECT_CALL(*gl_
, VertexAttribPointer(0, 1, GL_FLOAT
, GL_FALSE
, 0, NULL
))
259 .RetiresOnSaturation();
260 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, 0))
262 .RetiresOnSaturation();
263 EXPECT_CALL(*gl_
, GenBuffersARB(arraysize(fixed_attrib_buffer_id
), _
))
264 .WillOnce(SetArrayArgument
<1>(
265 fixed_attrib_buffer_id
,
266 fixed_attrib_buffer_id
+ arraysize(fixed_attrib_buffer_id
)))
267 .RetiresOnSaturation();
269 for (GLint tt
= 0; tt
< TestHelper::kNumTextureUnits
; ++tt
) {
270 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
+ tt
))
272 .RetiresOnSaturation();
273 if (group_
->feature_info()->feature_flags().oes_egl_image_external
) {
275 BindTexture(GL_TEXTURE_EXTERNAL_OES
,
277 ? TestHelper::kServiceDefaultExternalTextureId
280 .RetiresOnSaturation();
282 if (group_
->feature_info()->feature_flags().arb_texture_rectangle
) {
285 BindTexture(GL_TEXTURE_RECTANGLE_ARB
,
287 ? TestHelper::kServiceDefaultRectangleTextureId
290 .RetiresOnSaturation();
293 BindTexture(GL_TEXTURE_CUBE_MAP
,
295 ? TestHelper::kServiceDefaultTextureCubemapId
298 .RetiresOnSaturation();
303 use_default_textures
? TestHelper::kServiceDefaultTexture2dId
: 0))
305 .RetiresOnSaturation();
307 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
309 .RetiresOnSaturation();
311 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_FRAMEBUFFER
, 0))
313 .RetiresOnSaturation();
314 EXPECT_CALL(*gl_
, GetIntegerv(GL_ALPHA_BITS
, _
))
315 .WillOnce(SetArgumentPointee
<1>(normalized_init
.has_alpha
? 8 : 0))
316 .RetiresOnSaturation();
317 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_BITS
, _
))
318 .WillOnce(SetArgumentPointee
<1>(normalized_init
.has_depth
? 24 : 0))
319 .RetiresOnSaturation();
320 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_BITS
, _
))
321 .WillOnce(SetArgumentPointee
<1>(normalized_init
.has_stencil
? 8 : 0))
322 .RetiresOnSaturation();
324 EXPECT_CALL(*gl_
, Enable(GL_VERTEX_PROGRAM_POINT_SIZE
))
326 .RetiresOnSaturation();
328 EXPECT_CALL(*gl_
, Enable(GL_POINT_SPRITE
))
330 .RetiresOnSaturation();
332 static GLint max_viewport_dims
[] = {
336 EXPECT_CALL(*gl_
, GetIntegerv(GL_MAX_VIEWPORT_DIMS
, _
))
337 .WillOnce(SetArrayArgument
<1>(
338 max_viewport_dims
, max_viewport_dims
+ arraysize(max_viewport_dims
)))
339 .RetiresOnSaturation();
341 SetupInitCapabilitiesExpectations();
342 SetupInitStateExpectations();
344 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
346 .RetiresOnSaturation();
348 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, 0))
350 .RetiresOnSaturation();
351 EXPECT_CALL(*gl_
, BindBuffer(GL_ELEMENT_ARRAY_BUFFER
, 0))
353 .RetiresOnSaturation();
354 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_FRAMEBUFFER
, 0))
356 .RetiresOnSaturation();
357 EXPECT_CALL(*gl_
, BindRenderbufferEXT(GL_RENDERBUFFER
, 0))
359 .RetiresOnSaturation();
361 // TODO(boliu): Remove OS_ANDROID once crbug.com/259023 is fixed and the
362 // workaround has been reverted.
363 #if !defined(OS_ANDROID)
364 EXPECT_CALL(*gl_
, Clear(
365 GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
367 .RetiresOnSaturation();
370 engine_
.reset(new StrictMock
<MockCommandBufferEngine
>());
371 scoped_refptr
<gpu::Buffer
> buffer
=
372 engine_
->GetSharedMemoryBuffer(kSharedMemoryId
);
373 shared_memory_offset_
= kSharedMemoryOffset
;
374 shared_memory_address_
=
375 reinterpret_cast<int8
*>(buffer
->memory()) + shared_memory_offset_
;
376 shared_memory_id_
= kSharedMemoryId
;
377 shared_memory_base_
= buffer
->memory();
379 static const int32 kLoseContextWhenOutOfMemory
= 0x10002;
381 int32 attributes
[] = {
383 normalized_init
.request_alpha
? 8 : 0,
385 normalized_init
.request_depth
? 24 : 0,
387 normalized_init
.request_stencil
? 8 : 0,
388 kLoseContextWhenOutOfMemory
,
389 normalized_init
.lose_context_when_out_of_memory
? 1 : 0, };
390 std::vector
<int32
> attribs(attributes
, attributes
+ arraysize(attributes
));
392 decoder_
.reset(GLES2Decoder::Create(group_
.get()));
393 decoder_
->SetIgnoreCachedStateForTest(ignore_cached_state_for_test_
);
394 decoder_
->GetLogger()->set_log_synthesized_gl_errors(false);
395 decoder_
->Initialize(surface_
,
399 DisallowedFeatures(),
401 decoder_
->MakeCurrent();
402 decoder_
->set_engine(engine_
.get());
403 decoder_
->BeginDecoding();
405 EXPECT_CALL(*gl_
, GenBuffersARB(_
, _
))
406 .WillOnce(SetArgumentPointee
<1>(kServiceBufferId
))
407 .RetiresOnSaturation();
408 GenHelper
<cmds::GenBuffersImmediate
>(client_buffer_id_
);
409 EXPECT_CALL(*gl_
, GenFramebuffersEXT(_
, _
))
410 .WillOnce(SetArgumentPointee
<1>(kServiceFramebufferId
))
411 .RetiresOnSaturation();
412 GenHelper
<cmds::GenFramebuffersImmediate
>(client_framebuffer_id_
);
413 EXPECT_CALL(*gl_
, GenRenderbuffersEXT(_
, _
))
414 .WillOnce(SetArgumentPointee
<1>(kServiceRenderbufferId
))
415 .RetiresOnSaturation();
416 GenHelper
<cmds::GenRenderbuffersImmediate
>(client_renderbuffer_id_
);
417 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
418 .WillOnce(SetArgumentPointee
<1>(kServiceTextureId
))
419 .RetiresOnSaturation();
420 GenHelper
<cmds::GenTexturesImmediate
>(client_texture_id_
);
421 EXPECT_CALL(*gl_
, GenBuffersARB(_
, _
))
422 .WillOnce(SetArgumentPointee
<1>(kServiceElementBufferId
))
423 .RetiresOnSaturation();
424 GenHelper
<cmds::GenBuffersImmediate
>(client_element_buffer_id_
);
426 DoCreateProgram(client_program_id_
, kServiceProgramId
);
427 DoCreateShader(GL_VERTEX_SHADER
, client_shader_id_
, kServiceShaderId
);
430 bool reset_unsafe_es3_apis_enabled
= false;
431 if (!decoder_
->unsafe_es3_apis_enabled()) {
432 decoder_
->set_unsafe_es3_apis_enabled(true);
433 reset_unsafe_es3_apis_enabled
= true;
436 const gfx::GLVersionInfo
* version
= context_
->GetVersionInfo();
437 if (version
->IsAtLeastGL(3, 3) || version
->IsAtLeastGLES(3, 0)) {
438 EXPECT_CALL(*gl_
, GenSamplers(_
, _
))
439 .WillOnce(SetArgumentPointee
<1>(kServiceSamplerId
))
440 .RetiresOnSaturation();
441 GenHelper
<cmds::GenSamplersImmediate
>(client_sampler_id_
);
443 if (version
->IsAtLeastGL(4, 0) || version
->IsAtLeastGLES(3, 0)) {
444 EXPECT_CALL(*gl_
, GenTransformFeedbacks(_
, _
))
445 .WillOnce(SetArgumentPointee
<1>(kServiceTransformFeedbackId
))
446 .RetiresOnSaturation();
447 GenHelper
<cmds::GenTransformFeedbacksImmediate
>(
448 client_transformfeedback_id_
);
451 if (init
.extensions
.find("GL_ARB_sync ") != std::string::npos
||
452 version
->IsAtLeastGL(3, 2) || version
->IsAtLeastGLES(3, 0)) {
453 DoFenceSync(client_sync_id_
, kServiceSyncId
);
456 if (reset_unsafe_es3_apis_enabled
) {
457 decoder_
->set_unsafe_es3_apis_enabled(false);
460 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
463 void GLES2DecoderTestBase::ResetDecoder() {
466 // All Tests should have read all their GLErrors before getting here.
467 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
469 EXPECT_CALL(*gl_
, DeleteBuffersARB(1, _
))
471 .RetiresOnSaturation();
472 if (group_
->feature_info()->feature_flags().native_vertex_array_object
) {
473 EXPECT_CALL(*gl_
, DeleteVertexArraysOES(1, Pointee(kServiceVertexArrayId
)))
475 .RetiresOnSaturation();
478 decoder_
->EndDecoding();
479 decoder_
->Destroy(true);
481 group_
->Destroy(mock_decoder_
.get(), false);
483 ::gfx::MockGLInterface::SetGLInterface(NULL
);
485 gfx::ClearGLBindings();
488 void GLES2DecoderTestBase::TearDown() {
492 void GLES2DecoderTestBase::ExpectEnableDisable(GLenum cap
, bool enable
) {
494 EXPECT_CALL(*gl_
, Enable(cap
))
496 .RetiresOnSaturation();
498 EXPECT_CALL(*gl_
, Disable(cap
))
500 .RetiresOnSaturation();
505 GLint
GLES2DecoderTestBase::GetGLError() {
506 EXPECT_CALL(*gl_
, GetError())
507 .WillOnce(Return(GL_NO_ERROR
))
508 .RetiresOnSaturation();
510 cmd
.Init(shared_memory_id_
, shared_memory_offset_
);
511 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
512 return static_cast<GLint
>(*GetSharedMemoryAs
<GLenum
*>());
515 void GLES2DecoderTestBase::DoCreateShader(
516 GLenum shader_type
, GLuint client_id
, GLuint service_id
) {
517 EXPECT_CALL(*gl_
, CreateShader(shader_type
))
519 .WillOnce(Return(service_id
))
520 .RetiresOnSaturation();
521 cmds::CreateShader cmd
;
522 cmd
.Init(shader_type
, client_id
);
523 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
526 bool GLES2DecoderTestBase::DoIsShader(GLuint client_id
) {
527 return IsObjectHelper
<cmds::IsShader
, cmds::IsShader::Result
>(client_id
);
530 void GLES2DecoderTestBase::DoDeleteShader(
531 GLuint client_id
, GLuint service_id
) {
532 EXPECT_CALL(*gl_
, DeleteShader(service_id
))
534 .RetiresOnSaturation();
535 cmds::DeleteShader cmd
;
537 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
540 void GLES2DecoderTestBase::DoCreateProgram(
541 GLuint client_id
, GLuint service_id
) {
542 EXPECT_CALL(*gl_
, CreateProgram())
544 .WillOnce(Return(service_id
))
545 .RetiresOnSaturation();
546 cmds::CreateProgram cmd
;
548 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
551 bool GLES2DecoderTestBase::DoIsProgram(GLuint client_id
) {
552 return IsObjectHelper
<cmds::IsProgram
, cmds::IsProgram::Result
>(client_id
);
555 void GLES2DecoderTestBase::DoDeleteProgram(
556 GLuint client_id
, GLuint
/* service_id */) {
557 cmds::DeleteProgram cmd
;
559 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
562 void GLES2DecoderTestBase::DoFenceSync(
563 GLuint client_id
, GLuint service_id
) {
564 EXPECT_CALL(*gl_
, FenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE
, 0))
566 .WillOnce(Return(reinterpret_cast<GLsync
>(service_id
)))
567 .RetiresOnSaturation();
570 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
573 void GLES2DecoderTestBase::SetBucketData(
574 uint32_t bucket_id
, const void* data
, uint32_t data_size
) {
575 DCHECK(data
|| data_size
== 0);
576 cmd::SetBucketSize cmd1
;
577 cmd1
.Init(bucket_id
, data_size
);
578 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
580 memcpy(shared_memory_address_
, data
, data_size
);
581 cmd::SetBucketData cmd2
;
582 cmd2
.Init(bucket_id
, 0, data_size
, kSharedMemoryId
, kSharedMemoryOffset
);
583 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
588 void GLES2DecoderTestBase::SetBucketAsCString(
589 uint32 bucket_id
, const char* str
) {
590 SetBucketData(bucket_id
, str
, str
? (strlen(str
) + 1) : 0);
593 void GLES2DecoderTestBase::SetBucketAsCStrings(
594 uint32 bucket_id
, GLsizei count
, const char** str
,
595 GLsizei count_in_header
, char str_end
) {
596 uint32_t header_size
= sizeof(GLint
) * (count
+ 1);
597 uint32_t total_size
= header_size
;
598 scoped_ptr
<GLint
[]> header(new GLint
[count
+ 1]);
599 header
[0] = static_cast<GLint
>(count_in_header
);
600 for (GLsizei ii
= 0; ii
< count
; ++ii
) {
601 header
[ii
+ 1] = str
&& str
[ii
] ? strlen(str
[ii
]) : 0;
602 total_size
+= header
[ii
+ 1] + 1;
604 cmd::SetBucketSize cmd1
;
605 cmd1
.Init(bucket_id
, total_size
);
606 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
607 memcpy(shared_memory_address_
, header
.get(), header_size
);
608 uint32_t offset
= header_size
;
609 for (GLsizei ii
= 0; ii
< count
; ++ii
) {
610 if (str
&& str
[ii
]) {
611 size_t str_len
= strlen(str
[ii
]);
612 memcpy(reinterpret_cast<char*>(shared_memory_address_
) + offset
,
616 memcpy(reinterpret_cast<char*>(shared_memory_address_
) + offset
,
620 cmd::SetBucketData cmd2
;
621 cmd2
.Init(bucket_id
, 0, total_size
, kSharedMemoryId
, kSharedMemoryOffset
);
622 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
626 void GLES2DecoderTestBase::SetupClearTextureExpectations(
628 GLuint old_service_id
,
632 GLenum internal_format
,
637 EXPECT_CALL(*gl_
, BindTexture(bind_target
, service_id
))
639 .RetiresOnSaturation();
640 EXPECT_CALL(*gl_
, TexImage2D(
641 target
, level
, internal_format
, width
, height
, 0, format
, type
, _
))
643 .RetiresOnSaturation();
644 EXPECT_CALL(*gl_
, BindTexture(bind_target
, old_service_id
))
646 .RetiresOnSaturation();
649 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearing(
652 GLclampf restore_red
,
653 GLclampf restore_green
,
654 GLclampf restore_blue
,
655 GLclampf restore_alpha
,
656 GLuint restore_stencil
,
657 GLclampf restore_depth
,
658 bool restore_scissor_test
) {
659 SetupExpectationsForFramebufferClearingMulti(
670 restore_scissor_test
);
673 void GLES2DecoderTestBase::SetupExpectationsForRestoreClearState(
674 GLclampf restore_red
,
675 GLclampf restore_green
,
676 GLclampf restore_blue
,
677 GLclampf restore_alpha
,
678 GLuint restore_stencil
,
679 GLclampf restore_depth
,
680 bool restore_scissor_test
) {
681 EXPECT_CALL(*gl_
, ClearColor(
682 restore_red
, restore_green
, restore_blue
, restore_alpha
))
684 .RetiresOnSaturation();
685 EXPECT_CALL(*gl_
, ClearStencil(restore_stencil
))
687 .RetiresOnSaturation();
688 EXPECT_CALL(*gl_
, ClearDepth(restore_depth
))
690 .RetiresOnSaturation();
691 if (restore_scissor_test
) {
692 EXPECT_CALL(*gl_
, Enable(GL_SCISSOR_TEST
))
694 .RetiresOnSaturation();
698 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearingMulti(
699 GLuint read_framebuffer_service_id
,
700 GLuint draw_framebuffer_service_id
,
703 GLclampf restore_red
,
704 GLclampf restore_green
,
705 GLclampf restore_blue
,
706 GLclampf restore_alpha
,
707 GLuint restore_stencil
,
708 GLclampf restore_depth
,
709 bool restore_scissor_test
) {
710 // TODO(gman): Figure out why InSequence stopped working.
711 // InSequence sequence;
712 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(target
))
713 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
714 .RetiresOnSaturation();
715 if (target
== GL_READ_FRAMEBUFFER_EXT
) {
716 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT
, 0))
718 .RetiresOnSaturation();
719 EXPECT_CALL(*gl_
, BindFramebufferEXT(
720 GL_DRAW_FRAMEBUFFER_EXT
, read_framebuffer_service_id
))
722 .RetiresOnSaturation();
724 if ((clear_bits
& GL_COLOR_BUFFER_BIT
) != 0) {
725 EXPECT_CALL(*gl_
, ClearColor(0.0f
, 0.0f
, 0.0f
, 0.0f
))
727 .RetiresOnSaturation();
728 SetupExpectationsForColorMask(true, true, true, true);
730 if ((clear_bits
& GL_STENCIL_BUFFER_BIT
) != 0) {
731 EXPECT_CALL(*gl_
, ClearStencil(0))
733 .RetiresOnSaturation();
734 EXPECT_CALL(*gl_
, StencilMask(static_cast<GLuint
>(-1)))
736 .RetiresOnSaturation();
738 if ((clear_bits
& GL_DEPTH_BUFFER_BIT
) != 0) {
739 EXPECT_CALL(*gl_
, ClearDepth(1.0f
))
741 .RetiresOnSaturation();
742 SetupExpectationsForDepthMask(true);
744 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST
, false);
745 EXPECT_CALL(*gl_
, Clear(clear_bits
))
747 .RetiresOnSaturation();
748 SetupExpectationsForRestoreClearState(
749 restore_red
, restore_green
, restore_blue
, restore_alpha
,
750 restore_stencil
, restore_depth
, restore_scissor_test
);
751 if (target
== GL_READ_FRAMEBUFFER_EXT
) {
752 EXPECT_CALL(*gl_
, BindFramebufferEXT(
753 GL_READ_FRAMEBUFFER_EXT
, read_framebuffer_service_id
))
755 .RetiresOnSaturation();
756 EXPECT_CALL(*gl_
, BindFramebufferEXT(
757 GL_DRAW_FRAMEBUFFER_EXT
, draw_framebuffer_service_id
))
759 .RetiresOnSaturation();
763 void GLES2DecoderTestBase::SetupShaderForUniform(GLenum uniform_type
) {
764 static AttribInfo attribs
[] = {
765 { "foo", 1, GL_FLOAT
, 1, },
766 { "goo", 1, GL_FLOAT
, 2, },
768 UniformInfo uniforms
[] = {
769 { "bar", 1, uniform_type
, 0, 2, -1, },
770 { "car", 4, uniform_type
, 1, 1, -1, },
772 const GLuint kClientVertexShaderId
= 5001;
773 const GLuint kServiceVertexShaderId
= 6001;
774 const GLuint kClientFragmentShaderId
= 5002;
775 const GLuint kServiceFragmentShaderId
= 6002;
776 SetupShader(attribs
, arraysize(attribs
), uniforms
, arraysize(uniforms
),
777 client_program_id_
, kServiceProgramId
,
778 kClientVertexShaderId
, kServiceVertexShaderId
,
779 kClientFragmentShaderId
, kServiceFragmentShaderId
);
781 EXPECT_CALL(*gl_
, UseProgram(kServiceProgramId
))
783 .RetiresOnSaturation();
784 cmds::UseProgram cmd
;
785 cmd
.Init(client_program_id_
);
786 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
789 void GLES2DecoderTestBase::DoBindBuffer(
790 GLenum target
, GLuint client_id
, GLuint service_id
) {
791 EXPECT_CALL(*gl_
, BindBuffer(target
, service_id
))
793 .RetiresOnSaturation();
794 cmds::BindBuffer cmd
;
795 cmd
.Init(target
, client_id
);
796 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
799 bool GLES2DecoderTestBase::DoIsBuffer(GLuint client_id
) {
800 return IsObjectHelper
<cmds::IsBuffer
, cmds::IsBuffer::Result
>(client_id
);
803 void GLES2DecoderTestBase::DoDeleteBuffer(
804 GLuint client_id
, GLuint service_id
) {
805 EXPECT_CALL(*gl_
, DeleteBuffersARB(1, Pointee(service_id
)))
807 .RetiresOnSaturation();
808 GenHelper
<cmds::DeleteBuffersImmediate
>(client_id
);
811 void GLES2DecoderTestBase::SetupExpectationsForColorMask(bool red
,
815 if (ignore_cached_state_for_test_
|| cached_color_mask_red_
!= red
||
816 cached_color_mask_green_
!= green
|| cached_color_mask_blue_
!= blue
||
817 cached_color_mask_alpha_
!= alpha
) {
818 cached_color_mask_red_
= red
;
819 cached_color_mask_green_
= green
;
820 cached_color_mask_blue_
= blue
;
821 cached_color_mask_alpha_
= alpha
;
822 EXPECT_CALL(*gl_
, ColorMask(red
, green
, blue
, alpha
))
824 .RetiresOnSaturation();
828 void GLES2DecoderTestBase::SetupExpectationsForDepthMask(bool mask
) {
829 if (ignore_cached_state_for_test_
|| cached_depth_mask_
!= mask
) {
830 cached_depth_mask_
= mask
;
831 EXPECT_CALL(*gl_
, DepthMask(mask
)).Times(1).RetiresOnSaturation();
835 void GLES2DecoderTestBase::SetupExpectationsForStencilMask(GLuint front_mask
,
837 if (ignore_cached_state_for_test_
||
838 cached_stencil_front_mask_
!= front_mask
) {
839 cached_stencil_front_mask_
= front_mask
;
840 EXPECT_CALL(*gl_
, StencilMaskSeparate(GL_FRONT
, front_mask
))
842 .RetiresOnSaturation();
845 if (ignore_cached_state_for_test_
||
846 cached_stencil_back_mask_
!= back_mask
) {
847 cached_stencil_back_mask_
= back_mask
;
848 EXPECT_CALL(*gl_
, StencilMaskSeparate(GL_BACK
, back_mask
))
850 .RetiresOnSaturation();
854 void GLES2DecoderTestBase::SetupExpectationsForEnableDisable(GLenum cap
,
858 if (enable_flags_
.cached_blend
== enable
&&
859 !ignore_cached_state_for_test_
)
861 enable_flags_
.cached_blend
= enable
;
864 if (enable_flags_
.cached_cull_face
== enable
&&
865 !ignore_cached_state_for_test_
)
867 enable_flags_
.cached_cull_face
= enable
;
870 if (enable_flags_
.cached_depth_test
== enable
&&
871 !ignore_cached_state_for_test_
)
873 enable_flags_
.cached_depth_test
= enable
;
876 if (enable_flags_
.cached_dither
== enable
&&
877 !ignore_cached_state_for_test_
)
879 enable_flags_
.cached_dither
= enable
;
881 case GL_POLYGON_OFFSET_FILL
:
882 if (enable_flags_
.cached_polygon_offset_fill
== enable
&&
883 !ignore_cached_state_for_test_
)
885 enable_flags_
.cached_polygon_offset_fill
= enable
;
887 case GL_SAMPLE_ALPHA_TO_COVERAGE
:
888 if (enable_flags_
.cached_sample_alpha_to_coverage
== enable
&&
889 !ignore_cached_state_for_test_
)
891 enable_flags_
.cached_sample_alpha_to_coverage
= enable
;
893 case GL_SAMPLE_COVERAGE
:
894 if (enable_flags_
.cached_sample_coverage
== enable
&&
895 !ignore_cached_state_for_test_
)
897 enable_flags_
.cached_sample_coverage
= enable
;
899 case GL_SCISSOR_TEST
:
900 if (enable_flags_
.cached_scissor_test
== enable
&&
901 !ignore_cached_state_for_test_
)
903 enable_flags_
.cached_scissor_test
= enable
;
905 case GL_STENCIL_TEST
:
906 if (enable_flags_
.cached_stencil_test
== enable
&&
907 !ignore_cached_state_for_test_
)
909 enable_flags_
.cached_stencil_test
= enable
;
916 EXPECT_CALL(*gl_
, Enable(cap
)).Times(1).RetiresOnSaturation();
918 EXPECT_CALL(*gl_
, Disable(cap
)).Times(1).RetiresOnSaturation();
922 void GLES2DecoderTestBase::SetupExpectationsForApplyingDirtyState(
923 bool framebuffer_is_rgb
,
924 bool framebuffer_has_depth
,
925 bool framebuffer_has_stencil
,
929 GLuint front_stencil_mask
,
930 GLuint back_stencil_mask
,
931 bool stencil_enabled
) {
932 bool color_mask_red
= (color_bits
& 0x1000) != 0;
933 bool color_mask_green
= (color_bits
& 0x0100) != 0;
934 bool color_mask_blue
= (color_bits
& 0x0010) != 0;
935 bool color_mask_alpha
= (color_bits
& 0x0001) && !framebuffer_is_rgb
;
937 SetupExpectationsForColorMask(
938 color_mask_red
, color_mask_green
, color_mask_blue
, color_mask_alpha
);
939 SetupExpectationsForDepthMask(depth_mask
);
940 SetupExpectationsForStencilMask(front_stencil_mask
, back_stencil_mask
);
941 SetupExpectationsForEnableDisable(GL_DEPTH_TEST
,
942 framebuffer_has_depth
&& depth_enabled
);
943 SetupExpectationsForEnableDisable(GL_STENCIL_TEST
,
944 framebuffer_has_stencil
&& stencil_enabled
);
947 void GLES2DecoderTestBase::SetupExpectationsForApplyingDefaultDirtyState() {
948 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
949 false, // Framebuffer has depth
950 false, // Framebuffer has stencil
951 0x1111, // color bits
953 false, // depth enabled
954 0, // front stencil mask
955 0, // back stencil mask
956 false); // stencil enabled
959 GLES2DecoderTestBase::EnableFlags::EnableFlags()
960 : cached_blend(false),
961 cached_cull_face(false),
962 cached_depth_test(false),
964 cached_polygon_offset_fill(false),
965 cached_sample_alpha_to_coverage(false),
966 cached_sample_coverage(false),
967 cached_scissor_test(false),
968 cached_stencil_test(false) {
971 void GLES2DecoderTestBase::DoBindFramebuffer(
972 GLenum target
, GLuint client_id
, GLuint service_id
) {
973 EXPECT_CALL(*gl_
, BindFramebufferEXT(target
, service_id
))
975 .RetiresOnSaturation();
976 cmds::BindFramebuffer cmd
;
977 cmd
.Init(target
, client_id
);
978 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
981 bool GLES2DecoderTestBase::DoIsFramebuffer(GLuint client_id
) {
982 return IsObjectHelper
<cmds::IsFramebuffer
, cmds::IsFramebuffer::Result
>(
986 void GLES2DecoderTestBase::DoDeleteFramebuffer(
987 GLuint client_id
, GLuint service_id
,
988 bool reset_draw
, GLenum draw_target
, GLuint draw_id
,
989 bool reset_read
, GLenum read_target
, GLuint read_id
) {
991 EXPECT_CALL(*gl_
, BindFramebufferEXT(draw_target
, draw_id
))
993 .RetiresOnSaturation();
996 EXPECT_CALL(*gl_
, BindFramebufferEXT(read_target
, read_id
))
998 .RetiresOnSaturation();
1000 EXPECT_CALL(*gl_
, DeleteFramebuffersEXT(1, Pointee(service_id
)))
1002 .RetiresOnSaturation();
1003 GenHelper
<cmds::DeleteFramebuffersImmediate
>(client_id
);
1006 void GLES2DecoderTestBase::DoBindRenderbuffer(
1007 GLenum target
, GLuint client_id
, GLuint service_id
) {
1008 service_renderbuffer_id_
= service_id
;
1009 service_renderbuffer_valid_
= true;
1010 EXPECT_CALL(*gl_
, BindRenderbufferEXT(target
, service_id
))
1012 .RetiresOnSaturation();
1013 cmds::BindRenderbuffer cmd
;
1014 cmd
.Init(target
, client_id
);
1015 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1018 void GLES2DecoderTestBase::DoRenderbufferStorageMultisampleCHROMIUM(
1021 GLenum internal_format
,
1025 EXPECT_CALL(*gl_
, GetError())
1026 .WillOnce(Return(GL_NO_ERROR
))
1027 .RetiresOnSaturation();
1029 RenderbufferStorageMultisampleEXT(
1030 target
, samples
, gl_format
, width
, height
))
1032 .RetiresOnSaturation();
1033 EXPECT_CALL(*gl_
, GetError())
1034 .WillOnce(Return(GL_NO_ERROR
))
1035 .RetiresOnSaturation();
1036 cmds::RenderbufferStorageMultisampleCHROMIUM cmd
;
1037 cmd
.Init(target
, samples
, internal_format
, width
, height
);
1038 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1039 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1042 void GLES2DecoderTestBase::RestoreRenderbufferBindings() {
1043 GetDecoder()->RestoreRenderbufferBindings();
1044 service_renderbuffer_valid_
= false;
1047 void GLES2DecoderTestBase::EnsureRenderbufferBound(bool expect_bind
) {
1048 EXPECT_NE(expect_bind
, service_renderbuffer_valid_
);
1051 service_renderbuffer_valid_
= true;
1053 BindRenderbufferEXT(GL_RENDERBUFFER
, service_renderbuffer_id_
))
1055 .RetiresOnSaturation();
1057 EXPECT_CALL(*gl_
, BindRenderbufferEXT(_
, _
)).Times(0);
1061 bool GLES2DecoderTestBase::DoIsRenderbuffer(GLuint client_id
) {
1062 return IsObjectHelper
<cmds::IsRenderbuffer
, cmds::IsRenderbuffer::Result
>(
1066 void GLES2DecoderTestBase::DoDeleteRenderbuffer(
1067 GLuint client_id
, GLuint service_id
) {
1068 EXPECT_CALL(*gl_
, DeleteRenderbuffersEXT(1, Pointee(service_id
)))
1070 .RetiresOnSaturation();
1071 GenHelper
<cmds::DeleteRenderbuffersImmediate
>(client_id
);
1074 void GLES2DecoderTestBase::DoBindTexture(
1075 GLenum target
, GLuint client_id
, GLuint service_id
) {
1076 EXPECT_CALL(*gl_
, BindTexture(target
, service_id
))
1078 .RetiresOnSaturation();
1079 cmds::BindTexture cmd
;
1080 cmd
.Init(target
, client_id
);
1081 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1084 bool GLES2DecoderTestBase::DoIsTexture(GLuint client_id
) {
1085 return IsObjectHelper
<cmds::IsTexture
, cmds::IsTexture::Result
>(client_id
);
1088 void GLES2DecoderTestBase::DoDeleteTexture(
1089 GLuint client_id
, GLuint service_id
) {
1090 EXPECT_CALL(*gl_
, DeleteTextures(1, Pointee(service_id
)))
1092 .RetiresOnSaturation();
1093 GenHelper
<cmds::DeleteTexturesImmediate
>(client_id
);
1096 void GLES2DecoderTestBase::DoBindTexImage2DCHROMIUM(GLenum target
,
1098 cmds::BindTexImage2DCHROMIUM bind_tex_image_2d_cmd
;
1099 bind_tex_image_2d_cmd
.Init(target
, image_id
);
1100 EXPECT_CALL(*gl_
, GetError())
1101 .WillOnce(Return(GL_NO_ERROR
))
1102 .WillOnce(Return(GL_NO_ERROR
))
1103 .RetiresOnSaturation();
1104 EXPECT_EQ(error::kNoError
, ExecuteCmd(bind_tex_image_2d_cmd
));
1105 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1108 void GLES2DecoderTestBase::DoTexImage2D(
1109 GLenum target
, GLint level
, GLenum internal_format
,
1110 GLsizei width
, GLsizei height
, GLint border
,
1111 GLenum format
, GLenum type
,
1112 uint32 shared_memory_id
, uint32 shared_memory_offset
) {
1113 EXPECT_CALL(*gl_
, GetError())
1114 .WillOnce(Return(GL_NO_ERROR
))
1115 .RetiresOnSaturation();
1116 EXPECT_CALL(*gl_
, TexImage2D(target
, level
, internal_format
,
1117 width
, height
, border
, format
, type
, _
))
1119 .RetiresOnSaturation();
1120 EXPECT_CALL(*gl_
, GetError())
1121 .WillOnce(Return(GL_NO_ERROR
))
1122 .RetiresOnSaturation();
1123 cmds::TexImage2D cmd
;
1124 cmd
.Init(target
, level
, internal_format
, width
, height
, format
,
1125 type
, shared_memory_id
, shared_memory_offset
);
1126 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1129 void GLES2DecoderTestBase::DoTexImage2DConvertInternalFormat(
1130 GLenum target
, GLint level
, GLenum requested_internal_format
,
1131 GLsizei width
, GLsizei height
, GLint border
,
1132 GLenum format
, GLenum type
,
1133 uint32 shared_memory_id
, uint32 shared_memory_offset
,
1134 GLenum expected_internal_format
) {
1135 EXPECT_CALL(*gl_
, GetError())
1136 .WillOnce(Return(GL_NO_ERROR
))
1137 .RetiresOnSaturation();
1138 EXPECT_CALL(*gl_
, TexImage2D(target
, level
, expected_internal_format
,
1139 width
, height
, border
, format
, type
, _
))
1141 .RetiresOnSaturation();
1142 EXPECT_CALL(*gl_
, GetError())
1143 .WillOnce(Return(GL_NO_ERROR
))
1144 .RetiresOnSaturation();
1145 cmds::TexImage2D cmd
;
1146 cmd
.Init(target
, level
, requested_internal_format
, width
, height
,
1147 format
, type
, shared_memory_id
, shared_memory_offset
);
1148 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1151 void GLES2DecoderTestBase::DoCompressedTexImage2D(
1152 GLenum target
, GLint level
, GLenum format
,
1153 GLsizei width
, GLsizei height
, GLint border
,
1154 GLsizei size
, uint32 bucket_id
) {
1155 EXPECT_CALL(*gl_
, GetError())
1156 .WillOnce(Return(GL_NO_ERROR
))
1157 .RetiresOnSaturation();
1158 EXPECT_CALL(*gl_
, CompressedTexImage2D(
1159 target
, level
, format
, width
, height
, border
, size
, _
))
1161 .RetiresOnSaturation();
1162 EXPECT_CALL(*gl_
, GetError())
1163 .WillOnce(Return(GL_NO_ERROR
))
1164 .RetiresOnSaturation();
1165 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(bucket_id
);
1166 bucket
->SetSize(size
);
1167 cmds::CompressedTexImage2DBucket cmd
;
1169 target
, level
, format
, width
, height
,
1171 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1174 void GLES2DecoderTestBase::DoRenderbufferStorage(
1175 GLenum target
, GLenum internal_format
, GLenum actual_format
,
1176 GLsizei width
, GLsizei height
, GLenum error
) {
1177 EXPECT_CALL(*gl_
, GetError())
1178 .WillOnce(Return(GL_NO_ERROR
))
1179 .RetiresOnSaturation();
1180 EXPECT_CALL(*gl_
, RenderbufferStorageEXT(
1181 target
, actual_format
, width
, height
))
1183 .RetiresOnSaturation();
1184 EXPECT_CALL(*gl_
, GetError())
1185 .WillOnce(Return(error
))
1186 .RetiresOnSaturation();
1187 cmds::RenderbufferStorage cmd
;
1188 cmd
.Init(target
, internal_format
, width
, height
);
1189 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1192 void GLES2DecoderTestBase::DoFramebufferTexture2D(
1193 GLenum target
, GLenum attachment
, GLenum textarget
,
1194 GLuint texture_client_id
, GLuint texture_service_id
, GLint level
,
1196 EXPECT_CALL(*gl_
, GetError())
1197 .WillOnce(Return(GL_NO_ERROR
))
1198 .RetiresOnSaturation();
1199 EXPECT_CALL(*gl_
, FramebufferTexture2DEXT(
1200 target
, attachment
, textarget
, texture_service_id
, level
))
1202 .RetiresOnSaturation();
1203 EXPECT_CALL(*gl_
, GetError())
1204 .WillOnce(Return(error
))
1205 .RetiresOnSaturation();
1206 cmds::FramebufferTexture2D cmd
;
1207 cmd
.Init(target
, attachment
, textarget
, texture_client_id
);
1208 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1211 void GLES2DecoderTestBase::DoFramebufferRenderbuffer(
1214 GLenum renderbuffer_target
,
1215 GLuint renderbuffer_client_id
,
1216 GLuint renderbuffer_service_id
,
1218 EXPECT_CALL(*gl_
, GetError())
1219 .WillOnce(Return(GL_NO_ERROR
))
1220 .RetiresOnSaturation();
1221 EXPECT_CALL(*gl_
, FramebufferRenderbufferEXT(
1222 target
, attachment
, renderbuffer_target
, renderbuffer_service_id
))
1224 .RetiresOnSaturation();
1225 EXPECT_CALL(*gl_
, GetError())
1226 .WillOnce(Return(error
))
1227 .RetiresOnSaturation();
1228 cmds::FramebufferRenderbuffer cmd
;
1229 cmd
.Init(target
, attachment
, renderbuffer_target
, renderbuffer_client_id
);
1230 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1233 void GLES2DecoderTestBase::DoVertexAttribPointer(
1234 GLuint index
, GLint size
, GLenum type
, GLsizei stride
, GLuint offset
) {
1236 VertexAttribPointer(index
, size
, type
, GL_FALSE
, stride
,
1237 BufferOffset(offset
)))
1239 .RetiresOnSaturation();
1240 cmds::VertexAttribPointer cmd
;
1241 cmd
.Init(index
, size
, GL_FLOAT
, GL_FALSE
, stride
, offset
);
1242 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1245 void GLES2DecoderTestBase::DoVertexAttribDivisorANGLE(
1246 GLuint index
, GLuint divisor
) {
1248 VertexAttribDivisorANGLE(index
, divisor
))
1250 .RetiresOnSaturation();
1251 cmds::VertexAttribDivisorANGLE cmd
;
1252 cmd
.Init(index
, divisor
);
1253 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1256 void GLES2DecoderTestBase::AddExpectationsForGenVertexArraysOES(){
1257 if (group_
->feature_info()->feature_flags().native_vertex_array_object
) {
1258 EXPECT_CALL(*gl_
, GenVertexArraysOES(1, _
))
1259 .WillOnce(SetArgumentPointee
<1>(kServiceVertexArrayId
))
1260 .RetiresOnSaturation();
1264 void GLES2DecoderTestBase::AddExpectationsForDeleteVertexArraysOES(){
1265 if (group_
->feature_info()->feature_flags().native_vertex_array_object
) {
1266 EXPECT_CALL(*gl_
, DeleteVertexArraysOES(1, _
))
1268 .RetiresOnSaturation();
1272 void GLES2DecoderTestBase::AddExpectationsForDeleteBoundVertexArraysOES() {
1273 // Expectations are the same as a delete, followed by binding VAO 0.
1274 AddExpectationsForDeleteVertexArraysOES();
1275 AddExpectationsForBindVertexArrayOES();
1278 void GLES2DecoderTestBase::AddExpectationsForBindVertexArrayOES() {
1279 if (group_
->feature_info()->feature_flags().native_vertex_array_object
) {
1280 EXPECT_CALL(*gl_
, BindVertexArrayOES(_
))
1282 .RetiresOnSaturation();
1284 for (uint32 vv
= 0; vv
< group_
->max_vertex_attribs(); ++vv
) {
1285 AddExpectationsForRestoreAttribState(vv
);
1288 EXPECT_CALL(*gl_
, BindBuffer(GL_ELEMENT_ARRAY_BUFFER
, _
))
1290 .RetiresOnSaturation();
1294 void GLES2DecoderTestBase::AddExpectationsForRestoreAttribState(GLuint attrib
) {
1295 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, _
))
1297 .RetiresOnSaturation();
1299 EXPECT_CALL(*gl_
, VertexAttribPointer(attrib
, _
, _
, _
, _
, _
))
1301 .RetiresOnSaturation();
1303 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(attrib
, _
))
1304 .Times(testing::AtMost(1))
1305 .RetiresOnSaturation();
1307 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, _
))
1309 .RetiresOnSaturation();
1312 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2
) {
1314 // TODO(bajones): Not sure if I can tell which of these will be called
1315 EXPECT_CALL(*gl_
, EnableVertexAttribArray(attrib
))
1316 .Times(testing::AtMost(1))
1317 .RetiresOnSaturation();
1319 EXPECT_CALL(*gl_
, DisableVertexAttribArray(attrib
))
1320 .Times(testing::AtMost(1))
1321 .RetiresOnSaturation();
1325 // GCC requires these declarations, but MSVC requires they not be present
1326 #ifndef COMPILER_MSVC
1327 const int GLES2DecoderTestBase::kBackBufferWidth
;
1328 const int GLES2DecoderTestBase::kBackBufferHeight
;
1330 const GLint
GLES2DecoderTestBase::kMaxTextureSize
;
1331 const GLint
GLES2DecoderTestBase::kMaxCubeMapTextureSize
;
1332 const GLint
GLES2DecoderTestBase::kNumVertexAttribs
;
1333 const GLint
GLES2DecoderTestBase::kNumTextureUnits
;
1334 const GLint
GLES2DecoderTestBase::kMaxTextureImageUnits
;
1335 const GLint
GLES2DecoderTestBase::kMaxVertexTextureImageUnits
;
1336 const GLint
GLES2DecoderTestBase::kMaxFragmentUniformVectors
;
1337 const GLint
GLES2DecoderTestBase::kMaxVaryingVectors
;
1338 const GLint
GLES2DecoderTestBase::kMaxVertexUniformVectors
;
1339 const GLint
GLES2DecoderTestBase::kMaxViewportWidth
;
1340 const GLint
GLES2DecoderTestBase::kMaxViewportHeight
;
1342 const GLint
GLES2DecoderTestBase::kViewportX
;
1343 const GLint
GLES2DecoderTestBase::kViewportY
;
1344 const GLint
GLES2DecoderTestBase::kViewportWidth
;
1345 const GLint
GLES2DecoderTestBase::kViewportHeight
;
1347 const GLuint
GLES2DecoderTestBase::kServiceAttrib0BufferId
;
1348 const GLuint
GLES2DecoderTestBase::kServiceFixedAttribBufferId
;
1350 const GLuint
GLES2DecoderTestBase::kServiceBufferId
;
1351 const GLuint
GLES2DecoderTestBase::kServiceFramebufferId
;
1352 const GLuint
GLES2DecoderTestBase::kServiceRenderbufferId
;
1353 const GLuint
GLES2DecoderTestBase::kServiceSamplerId
;
1354 const GLuint
GLES2DecoderTestBase::kServiceTextureId
;
1355 const GLuint
GLES2DecoderTestBase::kServiceProgramId
;
1356 const GLuint
GLES2DecoderTestBase::kServiceShaderId
;
1357 const GLuint
GLES2DecoderTestBase::kServiceElementBufferId
;
1358 const GLuint
GLES2DecoderTestBase::kServiceQueryId
;
1359 const GLuint
GLES2DecoderTestBase::kServiceVertexArrayId
;
1360 const GLuint
GLES2DecoderTestBase::kServiceTransformFeedbackId
;
1361 const GLuint
GLES2DecoderTestBase::kServiceSyncId
;
1363 const int32
GLES2DecoderTestBase::kSharedMemoryId
;
1364 const size_t GLES2DecoderTestBase::kSharedBufferSize
;
1365 const uint32
GLES2DecoderTestBase::kSharedMemoryOffset
;
1366 const int32
GLES2DecoderTestBase::kInvalidSharedMemoryId
;
1367 const uint32
GLES2DecoderTestBase::kInvalidSharedMemoryOffset
;
1368 const uint32
GLES2DecoderTestBase::kInitialResult
;
1369 const uint8
GLES2DecoderTestBase::kInitialMemoryValue
;
1371 const uint32
GLES2DecoderTestBase::kNewClientId
;
1372 const uint32
GLES2DecoderTestBase::kNewServiceId
;
1373 const uint32
GLES2DecoderTestBase::kInvalidClientId
;
1375 const GLuint
GLES2DecoderTestBase::kServiceVertexShaderId
;
1376 const GLuint
GLES2DecoderTestBase::kServiceFragmentShaderId
;
1378 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumShaderId
;
1379 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumProgramId
;
1381 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumTextureBufferId
;
1382 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumVertexBufferId
;
1383 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumFBOId
;
1384 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumPositionAttrib
;
1385 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumTexAttrib
;
1386 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumSamplerLocation
;
1388 const GLsizei
GLES2DecoderTestBase::kNumVertices
;
1389 const GLsizei
GLES2DecoderTestBase::kNumIndices
;
1390 const int GLES2DecoderTestBase::kValidIndexRangeStart
;
1391 const int GLES2DecoderTestBase::kValidIndexRangeCount
;
1392 const int GLES2DecoderTestBase::kInvalidIndexRangeStart
;
1393 const int GLES2DecoderTestBase::kInvalidIndexRangeCount
;
1394 const int GLES2DecoderTestBase::kOutOfRangeIndexRangeEnd
;
1395 const GLuint
GLES2DecoderTestBase::kMaxValidIndex
;
1397 const GLint
GLES2DecoderTestBase::kMaxAttribLength
;
1398 const GLint
GLES2DecoderTestBase::kAttrib1Size
;
1399 const GLint
GLES2DecoderTestBase::kAttrib2Size
;
1400 const GLint
GLES2DecoderTestBase::kAttrib3Size
;
1401 const GLint
GLES2DecoderTestBase::kAttrib1Location
;
1402 const GLint
GLES2DecoderTestBase::kAttrib2Location
;
1403 const GLint
GLES2DecoderTestBase::kAttrib3Location
;
1404 const GLenum
GLES2DecoderTestBase::kAttrib1Type
;
1405 const GLenum
GLES2DecoderTestBase::kAttrib2Type
;
1406 const GLenum
GLES2DecoderTestBase::kAttrib3Type
;
1407 const GLint
GLES2DecoderTestBase::kInvalidAttribLocation
;
1408 const GLint
GLES2DecoderTestBase::kBadAttribIndex
;
1410 const GLint
GLES2DecoderTestBase::kMaxUniformLength
;
1411 const GLint
GLES2DecoderTestBase::kUniform1Size
;
1412 const GLint
GLES2DecoderTestBase::kUniform2Size
;
1413 const GLint
GLES2DecoderTestBase::kUniform3Size
;
1414 const GLint
GLES2DecoderTestBase::kUniform1RealLocation
;
1415 const GLint
GLES2DecoderTestBase::kUniform2RealLocation
;
1416 const GLint
GLES2DecoderTestBase::kUniform2ElementRealLocation
;
1417 const GLint
GLES2DecoderTestBase::kUniform3RealLocation
;
1418 const GLint
GLES2DecoderTestBase::kUniform1FakeLocation
;
1419 const GLint
GLES2DecoderTestBase::kUniform2FakeLocation
;
1420 const GLint
GLES2DecoderTestBase::kUniform2ElementFakeLocation
;
1421 const GLint
GLES2DecoderTestBase::kUniform3FakeLocation
;
1422 const GLint
GLES2DecoderTestBase::kUniform1DesiredLocation
;
1423 const GLint
GLES2DecoderTestBase::kUniform2DesiredLocation
;
1424 const GLint
GLES2DecoderTestBase::kUniform3DesiredLocation
;
1425 const GLenum
GLES2DecoderTestBase::kUniform1Type
;
1426 const GLenum
GLES2DecoderTestBase::kUniform2Type
;
1427 const GLenum
GLES2DecoderTestBase::kUniform3Type
;
1428 const GLenum
GLES2DecoderTestBase::kUniformCubemapType
;
1429 const GLint
GLES2DecoderTestBase::kInvalidUniformLocation
;
1430 const GLint
GLES2DecoderTestBase::kBadUniformIndex
;
1434 const char* GLES2DecoderTestBase::kAttrib1Name
= "attrib1";
1435 const char* GLES2DecoderTestBase::kAttrib2Name
= "attrib2";
1436 const char* GLES2DecoderTestBase::kAttrib3Name
= "attrib3";
1437 const char* GLES2DecoderTestBase::kUniform1Name
= "uniform1";
1438 const char* GLES2DecoderTestBase::kUniform2Name
= "uniform2[0]";
1439 const char* GLES2DecoderTestBase::kUniform3Name
= "uniform3[0]";
1441 void GLES2DecoderTestBase::SetupDefaultProgram() {
1443 static AttribInfo attribs
[] = {
1444 { kAttrib1Name
, kAttrib1Size
, kAttrib1Type
, kAttrib1Location
, },
1445 { kAttrib2Name
, kAttrib2Size
, kAttrib2Type
, kAttrib2Location
, },
1446 { kAttrib3Name
, kAttrib3Size
, kAttrib3Type
, kAttrib3Location
, },
1448 static UniformInfo uniforms
[] = {
1449 { kUniform1Name
, kUniform1Size
, kUniform1Type
,
1450 kUniform1FakeLocation
, kUniform1RealLocation
,
1451 kUniform1DesiredLocation
},
1452 { kUniform2Name
, kUniform2Size
, kUniform2Type
,
1453 kUniform2FakeLocation
, kUniform2RealLocation
,
1454 kUniform2DesiredLocation
},
1455 { kUniform3Name
, kUniform3Size
, kUniform3Type
,
1456 kUniform3FakeLocation
, kUniform3RealLocation
,
1457 kUniform3DesiredLocation
},
1459 SetupShader(attribs
, arraysize(attribs
), uniforms
, arraysize(uniforms
),
1460 client_program_id_
, kServiceProgramId
,
1461 client_vertex_shader_id_
, kServiceVertexShaderId
,
1462 client_fragment_shader_id_
, kServiceFragmentShaderId
);
1466 EXPECT_CALL(*gl_
, UseProgram(kServiceProgramId
))
1468 .RetiresOnSaturation();
1469 cmds::UseProgram cmd
;
1470 cmd
.Init(client_program_id_
);
1471 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1475 void GLES2DecoderTestBase::SetupCubemapProgram() {
1477 static AttribInfo attribs
[] = {
1478 { kAttrib1Name
, kAttrib1Size
, kAttrib1Type
, kAttrib1Location
, },
1479 { kAttrib2Name
, kAttrib2Size
, kAttrib2Type
, kAttrib2Location
, },
1480 { kAttrib3Name
, kAttrib3Size
, kAttrib3Type
, kAttrib3Location
, },
1482 static UniformInfo uniforms
[] = {
1483 { kUniform1Name
, kUniform1Size
, kUniformCubemapType
,
1484 kUniform1FakeLocation
, kUniform1RealLocation
,
1485 kUniform1DesiredLocation
, },
1486 { kUniform2Name
, kUniform2Size
, kUniform2Type
,
1487 kUniform2FakeLocation
, kUniform2RealLocation
,
1488 kUniform2DesiredLocation
, },
1489 { kUniform3Name
, kUniform3Size
, kUniform3Type
,
1490 kUniform3FakeLocation
, kUniform3RealLocation
,
1491 kUniform3DesiredLocation
, },
1493 SetupShader(attribs
, arraysize(attribs
), uniforms
, arraysize(uniforms
),
1494 client_program_id_
, kServiceProgramId
,
1495 client_vertex_shader_id_
, kServiceVertexShaderId
,
1496 client_fragment_shader_id_
, kServiceFragmentShaderId
);
1500 EXPECT_CALL(*gl_
, UseProgram(kServiceProgramId
))
1502 .RetiresOnSaturation();
1503 cmds::UseProgram cmd
;
1504 cmd
.Init(client_program_id_
);
1505 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1509 void GLES2DecoderTestBase::SetupSamplerExternalProgram() {
1511 static AttribInfo attribs
[] = {
1512 { kAttrib1Name
, kAttrib1Size
, kAttrib1Type
, kAttrib1Location
, },
1513 { kAttrib2Name
, kAttrib2Size
, kAttrib2Type
, kAttrib2Location
, },
1514 { kAttrib3Name
, kAttrib3Size
, kAttrib3Type
, kAttrib3Location
, },
1516 static UniformInfo uniforms
[] = {
1517 { kUniform1Name
, kUniform1Size
, kUniformSamplerExternalType
,
1518 kUniform1FakeLocation
, kUniform1RealLocation
,
1519 kUniform1DesiredLocation
, },
1520 { kUniform2Name
, kUniform2Size
, kUniform2Type
,
1521 kUniform2FakeLocation
, kUniform2RealLocation
,
1522 kUniform2DesiredLocation
, },
1523 { kUniform3Name
, kUniform3Size
, kUniform3Type
,
1524 kUniform3FakeLocation
, kUniform3RealLocation
,
1525 kUniform3DesiredLocation
, },
1527 SetupShader(attribs
, arraysize(attribs
), uniforms
, arraysize(uniforms
),
1528 client_program_id_
, kServiceProgramId
,
1529 client_vertex_shader_id_
, kServiceVertexShaderId
,
1530 client_fragment_shader_id_
, kServiceFragmentShaderId
);
1534 EXPECT_CALL(*gl_
, UseProgram(kServiceProgramId
))
1536 .RetiresOnSaturation();
1537 cmds::UseProgram cmd
;
1538 cmd
.Init(client_program_id_
);
1539 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1543 void GLES2DecoderWithShaderTestBase::TearDown() {
1544 GLES2DecoderTestBase::TearDown();
1547 void GLES2DecoderTestBase::SetupShader(
1548 GLES2DecoderTestBase::AttribInfo
* attribs
, size_t num_attribs
,
1549 GLES2DecoderTestBase::UniformInfo
* uniforms
, size_t num_uniforms
,
1550 GLuint program_client_id
, GLuint program_service_id
,
1551 GLuint vertex_shader_client_id
, GLuint vertex_shader_service_id
,
1552 GLuint fragment_shader_client_id
, GLuint fragment_shader_service_id
) {
1557 AttachShader(program_service_id
, vertex_shader_service_id
))
1559 .RetiresOnSaturation();
1561 AttachShader(program_service_id
, fragment_shader_service_id
))
1563 .RetiresOnSaturation();
1564 TestHelper::SetupShader(
1565 gl_
.get(), attribs
, num_attribs
, uniforms
, num_uniforms
,
1566 program_service_id
);
1570 GL_VERTEX_SHADER
, vertex_shader_client_id
, vertex_shader_service_id
);
1572 GL_FRAGMENT_SHADER
, fragment_shader_client_id
,
1573 fragment_shader_service_id
);
1575 TestHelper::SetShaderStates(
1576 gl_
.get(), GetShader(vertex_shader_client_id
), true);
1577 TestHelper::SetShaderStates(
1578 gl_
.get(), GetShader(fragment_shader_client_id
), true);
1580 cmds::AttachShader attach_cmd
;
1581 attach_cmd
.Init(program_client_id
, vertex_shader_client_id
);
1582 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
1584 attach_cmd
.Init(program_client_id
, fragment_shader_client_id
);
1585 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
1587 cmds::LinkProgram link_cmd
;
1588 link_cmd
.Init(program_client_id
);
1590 EXPECT_EQ(error::kNoError
, ExecuteCmd(link_cmd
));
1593 void GLES2DecoderTestBase::DoEnableDisable(GLenum cap
, bool enable
) {
1594 SetupExpectationsForEnableDisable(cap
, enable
);
1598 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1602 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1606 void GLES2DecoderTestBase::DoEnableVertexAttribArray(GLint index
) {
1607 EXPECT_CALL(*gl_
, EnableVertexAttribArray(index
))
1609 .RetiresOnSaturation();
1610 cmds::EnableVertexAttribArray cmd
;
1612 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1615 void GLES2DecoderTestBase::DoBufferData(GLenum target
, GLsizei size
) {
1616 EXPECT_CALL(*gl_
, GetError())
1617 .WillOnce(Return(GL_NO_ERROR
))
1618 .RetiresOnSaturation();
1619 EXPECT_CALL(*gl_
, BufferData(target
, size
, _
, GL_STREAM_DRAW
))
1621 .RetiresOnSaturation();
1622 EXPECT_CALL(*gl_
, GetError())
1623 .WillOnce(Return(GL_NO_ERROR
))
1624 .RetiresOnSaturation();
1625 cmds::BufferData cmd
;
1626 cmd
.Init(target
, size
, 0, 0, GL_STREAM_DRAW
);
1627 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1630 void GLES2DecoderTestBase::DoBufferSubData(
1631 GLenum target
, GLint offset
, GLsizei size
, const void* data
) {
1632 EXPECT_CALL(*gl_
, BufferSubData(target
, offset
, size
,
1633 shared_memory_address_
))
1635 .RetiresOnSaturation();
1636 memcpy(shared_memory_address_
, data
, size
);
1637 cmds::BufferSubData cmd
;
1638 cmd
.Init(target
, offset
, size
, shared_memory_id_
, shared_memory_offset_
);
1639 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1642 void GLES2DecoderTestBase::SetupVertexBuffer() {
1643 DoEnableVertexAttribArray(1);
1644 DoBindBuffer(GL_ARRAY_BUFFER
, client_buffer_id_
, kServiceBufferId
);
1645 DoBufferData(GL_ARRAY_BUFFER
, kNumVertices
* 2 * sizeof(GLfloat
));
1648 void GLES2DecoderTestBase::SetupAllNeededVertexBuffers() {
1649 DoBindBuffer(GL_ARRAY_BUFFER
, client_buffer_id_
, kServiceBufferId
);
1650 DoBufferData(GL_ARRAY_BUFFER
, kNumVertices
* 16 * sizeof(float));
1651 DoEnableVertexAttribArray(0);
1652 DoEnableVertexAttribArray(1);
1653 DoEnableVertexAttribArray(2);
1654 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1655 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1656 DoVertexAttribPointer(2, 2, GL_FLOAT
, 0, 0);
1659 void GLES2DecoderTestBase::SetupIndexBuffer() {
1660 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER
,
1661 client_element_buffer_id_
,
1662 kServiceElementBufferId
);
1663 static const GLshort indices
[] = {100, 1, 2, 3, 4, 5, 6, 7, 100, 9};
1664 static_assert(arraysize(indices
) == kNumIndices
,
1665 "indices should have kNumIndices elements");
1666 DoBufferData(GL_ELEMENT_ARRAY_BUFFER
, sizeof(indices
));
1667 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER
, 0, 2, indices
);
1668 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER
, 2, sizeof(indices
) - 2, &indices
[1]);
1671 void GLES2DecoderTestBase::SetupTexture() {
1672 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1673 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
1674 kSharedMemoryId
, kSharedMemoryOffset
);
1677 void GLES2DecoderTestBase::DeleteVertexBuffer() {
1678 DoDeleteBuffer(client_buffer_id_
, kServiceBufferId
);
1681 void GLES2DecoderTestBase::DeleteIndexBuffer() {
1682 DoDeleteBuffer(client_element_buffer_id_
, kServiceElementBufferId
);
1685 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0WithError(
1686 GLsizei num_vertices
, GLuint buffer_id
, GLenum error
) {
1687 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2
) {
1691 EXPECT_CALL(*gl_
, GetError())
1692 .WillOnce(Return(GL_NO_ERROR
))
1693 .WillOnce(Return(error
))
1694 .RetiresOnSaturation();
1695 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, kServiceAttrib0BufferId
))
1697 .RetiresOnSaturation();
1698 EXPECT_CALL(*gl_
, BufferData(GL_ARRAY_BUFFER
,
1699 num_vertices
* sizeof(GLfloat
) * 4,
1700 _
, GL_DYNAMIC_DRAW
))
1702 .RetiresOnSaturation();
1703 if (error
== GL_NO_ERROR
) {
1704 EXPECT_CALL(*gl_
, BufferSubData(
1705 GL_ARRAY_BUFFER
, 0, num_vertices
* sizeof(GLfloat
) * 4, _
))
1707 .RetiresOnSaturation();
1708 EXPECT_CALL(*gl_
, VertexAttribPointer(0, 4, GL_FLOAT
, GL_FALSE
, 0, NULL
))
1710 .RetiresOnSaturation();
1711 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, buffer_id
))
1713 .RetiresOnSaturation();
1717 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0(
1718 GLsizei num_vertices
, GLuint buffer_id
) {
1719 AddExpectationsForSimulatedAttrib0WithError(
1720 num_vertices
, buffer_id
, GL_NO_ERROR
);
1723 void GLES2DecoderTestBase::SetupMockGLBehaviors() {
1724 ON_CALL(*gl_
, BindVertexArrayOES(_
))
1725 .WillByDefault(Invoke(
1727 &GLES2DecoderTestBase::MockGLStates::OnBindVertexArrayOES
));
1728 ON_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, _
))
1729 .WillByDefault(WithArg
<1>(Invoke(
1731 &GLES2DecoderTestBase::MockGLStates::OnBindArrayBuffer
)));
1732 ON_CALL(*gl_
, VertexAttribPointer(_
, _
, _
, _
, _
, NULL
))
1733 .WillByDefault(InvokeWithoutArgs(
1735 &GLES2DecoderTestBase::MockGLStates::OnVertexAttribNullPointer
));
1738 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1739 MockCommandBufferEngine() {
1741 scoped_ptr
<base::SharedMemory
> shm(new base::SharedMemory());
1742 shm
->CreateAndMapAnonymous(kSharedBufferSize
);
1743 valid_buffer_
= MakeBufferFromSharedMemory(shm
.Pass(), kSharedBufferSize
);
1745 ClearSharedMemory();
1748 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1749 ~MockCommandBufferEngine() {}
1751 scoped_refptr
<gpu::Buffer
>
1752 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetSharedMemoryBuffer(
1754 return shm_id
== kSharedMemoryId
? valid_buffer_
: invalid_buffer_
;
1757 void GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::set_token(
1762 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetBuffer(
1763 int32
/* transfer_buffer_id */) {
1768 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetOffset(
1774 int32
GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetGetOffset() {
1779 void GLES2DecoderWithShaderTestBase::SetUp() {
1780 GLES2DecoderTestBase::SetUp();
1781 SetupDefaultProgram();
1784 // Include the auto-generated part of this file. We split this because it means
1785 // we can easily edit the non-auto generated parts right here in this file
1786 // instead of having to edit some template or the code generator.
1787 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h"
1789 } // namespace gles2