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 const uint32 kMaxColorAttachments
= 16;
86 const uint32 kMaxDrawBuffers
= 16;
88 } // namespace Anonymous
93 GLES2DecoderTestBase::GLES2DecoderTestBase()
96 memory_tracker_(NULL
),
97 client_buffer_id_(100),
98 client_framebuffer_id_(101),
99 client_program_id_(102),
100 client_renderbuffer_id_(103),
101 client_sampler_id_(104),
102 client_shader_id_(105),
103 client_texture_id_(106),
104 client_element_buffer_id_(107),
105 client_vertex_shader_id_(121),
106 client_fragment_shader_id_(122),
107 client_query_id_(123),
108 client_vertexarray_id_(124),
109 client_valuebuffer_id_(125),
110 client_transformfeedback_id_(126),
111 client_sync_id_(127),
112 service_renderbuffer_id_(0),
113 service_renderbuffer_valid_(false),
114 ignore_cached_state_for_test_(GetParam()),
115 cached_color_mask_red_(true),
116 cached_color_mask_green_(true),
117 cached_color_mask_blue_(true),
118 cached_color_mask_alpha_(true),
119 cached_depth_mask_(true),
120 cached_stencil_front_mask_(static_cast<GLuint
>(-1)),
121 cached_stencil_back_mask_(static_cast<GLuint
>(-1)) {
122 memset(immediate_buffer_
, 0xEE, sizeof(immediate_buffer_
));
125 GLES2DecoderTestBase::~GLES2DecoderTestBase() {}
127 void GLES2DecoderTestBase::SetUp() {
129 // Autogenerated tests do not overwrite version or extension string,
130 // so we have to pick something that supports everything here.
131 init
.gl_version
= "4.4";
132 init
.extensions
+= " GL_ARB_compatibility";
133 init
.has_alpha
= true;
134 init
.has_depth
= true;
135 init
.request_alpha
= true;
136 init
.request_depth
= true;
137 init
.bind_generates_resource
= true;
141 void GLES2DecoderTestBase::AddExpectationsForVertexAttribManager() {
142 for (GLint ii
= 0; ii
< kNumVertexAttribs
; ++ii
) {
143 EXPECT_CALL(*gl_
, VertexAttrib4f(ii
, 0.0f
, 0.0f
, 0.0f
, 1.0f
))
145 .RetiresOnSaturation();
149 GLES2DecoderTestBase::InitState::InitState()
150 : extensions("GL_EXT_framebuffer_object"),
155 request_alpha(false),
156 request_depth(false),
157 request_stencil(false),
158 bind_generates_resource(false),
159 lose_context_when_out_of_memory(false),
160 use_native_vao(true) {
163 void GLES2DecoderTestBase::InitDecoder(const InitState
& init
) {
164 InitDecoderWithCommandLine(init
, NULL
);
167 void GLES2DecoderTestBase::InitDecoderWithCommandLine(
168 const InitState
& init
,
169 const base::CommandLine
* command_line
) {
170 InitState normalized_init
= init
;
171 NormalizeInitState(&normalized_init
);
172 // For easier substring/extension matching
173 DCHECK(normalized_init
.extensions
.empty() ||
174 *normalized_init
.extensions
.rbegin() == ' ');
175 Framebuffer::ClearFramebufferCompleteComboMap();
177 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress
);
178 gfx::GLSurface::InitializeOneOffWithMockBindingsForTests();
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
,
191 new ShaderTranslatorCache
,
193 new SubscriptionRefSet
,
195 normalized_init
.bind_generates_resource
));
196 bool use_default_textures
= normalized_init
.bind_generates_resource
;
200 surface_
= new gfx::GLSurfaceStub
;
201 surface_
->SetSize(gfx::Size(kBackBufferWidth
, kBackBufferHeight
));
203 // Context needs to be created before initializing ContextGroup, which will
204 // in turn initialize FeatureInfo, which needs a context to determine
205 // extension support.
206 context_
= new StrictMock
<GLContextMock
>();
207 context_
->AddExtensionsString(normalized_init
.extensions
.c_str());
208 context_
->SetGLVersionString(normalized_init
.gl_version
.c_str());
210 context_
->GLContextStubWithExtensions::MakeCurrent(surface_
.get());
211 gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_
.get());
213 TestHelper::SetupContextGroupInitExpectations(
215 DisallowedFeatures(),
216 normalized_init
.extensions
.c_str(),
217 normalized_init
.gl_version
.c_str(),
218 normalized_init
.bind_generates_resource
);
220 // We initialize the ContextGroup with a MockGLES2Decoder so that
221 // we can use the ContextGroup to figure out how the real GLES2Decoder
222 // will initialize itself.
223 mock_decoder_
.reset(new MockGLES2Decoder());
225 // Install FakeDoCommands handler so we can use individual DoCommand()
227 EXPECT_CALL(*mock_decoder_
, DoCommands(_
, _
, _
, _
)).WillRepeatedly(
228 Invoke(mock_decoder_
.get(), &MockGLES2Decoder::FakeDoCommands
));
231 group_
->Initialize(mock_decoder_
.get(), DisallowedFeatures()));
233 if (group_
->feature_info()->IsES3Capable()) {
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 kES3ContextRequired
= 0x10003;
405 bool es3_context_required
= group_
->feature_info()->IsES3Capable();
407 int32 attributes
[] = {
409 normalized_init
.request_alpha
? 8 : 0,
411 normalized_init
.request_depth
? 24 : 0,
413 normalized_init
.request_stencil
? 8 : 0,
414 kLoseContextWhenOutOfMemory
,
415 normalized_init
.lose_context_when_out_of_memory
? 1 : 0,
417 es3_context_required
? 1 : 0
419 std::vector
<int32
> attribs(attributes
, attributes
+ arraysize(attributes
));
421 decoder_
.reset(GLES2Decoder::Create(group_
.get()));
422 decoder_
->SetIgnoreCachedStateForTest(ignore_cached_state_for_test_
);
423 decoder_
->GetLogger()->set_log_synthesized_gl_errors(false);
424 decoder_
->Initialize(surface_
,
428 DisallowedFeatures(),
430 EXPECT_CALL(*context_
, MakeCurrent(surface_
.get())).WillOnce(Return(true));
431 if (context_
->WasAllocatedUsingRobustnessExtension()) {
432 EXPECT_CALL(*gl_
, GetGraphicsResetStatusARB())
433 .WillOnce(Return(GL_NO_ERROR
));
435 decoder_
->MakeCurrent();
436 decoder_
->set_engine(engine_
.get());
437 decoder_
->BeginDecoding();
439 EXPECT_CALL(*gl_
, GenBuffersARB(_
, _
))
440 .WillOnce(SetArgumentPointee
<1>(kServiceBufferId
))
441 .RetiresOnSaturation();
442 GenHelper
<cmds::GenBuffersImmediate
>(client_buffer_id_
);
443 EXPECT_CALL(*gl_
, GenFramebuffersEXT(_
, _
))
444 .WillOnce(SetArgumentPointee
<1>(kServiceFramebufferId
))
445 .RetiresOnSaturation();
446 GenHelper
<cmds::GenFramebuffersImmediate
>(client_framebuffer_id_
);
447 EXPECT_CALL(*gl_
, GenRenderbuffersEXT(_
, _
))
448 .WillOnce(SetArgumentPointee
<1>(kServiceRenderbufferId
))
449 .RetiresOnSaturation();
450 GenHelper
<cmds::GenRenderbuffersImmediate
>(client_renderbuffer_id_
);
451 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
452 .WillOnce(SetArgumentPointee
<1>(kServiceTextureId
))
453 .RetiresOnSaturation();
454 GenHelper
<cmds::GenTexturesImmediate
>(client_texture_id_
);
455 EXPECT_CALL(*gl_
, GenBuffersARB(_
, _
))
456 .WillOnce(SetArgumentPointee
<1>(kServiceElementBufferId
))
457 .RetiresOnSaturation();
458 GenHelper
<cmds::GenBuffersImmediate
>(client_element_buffer_id_
);
460 DoCreateProgram(client_program_id_
, kServiceProgramId
);
461 DoCreateShader(GL_VERTEX_SHADER
, client_shader_id_
, kServiceShaderId
);
464 bool reset_unsafe_es3_apis_enabled
= false;
465 if (!decoder_
->unsafe_es3_apis_enabled()) {
466 decoder_
->set_unsafe_es3_apis_enabled(true);
467 reset_unsafe_es3_apis_enabled
= true;
470 const gfx::GLVersionInfo
* version
= context_
->GetVersionInfo();
471 if (version
->IsAtLeastGL(3, 3) || version
->IsAtLeastGLES(3, 0)) {
472 EXPECT_CALL(*gl_
, GenSamplers(_
, _
))
473 .WillOnce(SetArgumentPointee
<1>(kServiceSamplerId
))
474 .RetiresOnSaturation();
475 GenHelper
<cmds::GenSamplersImmediate
>(client_sampler_id_
);
477 if (version
->IsAtLeastGL(4, 0) || version
->IsAtLeastGLES(3, 0)) {
478 EXPECT_CALL(*gl_
, GenTransformFeedbacks(_
, _
))
479 .WillOnce(SetArgumentPointee
<1>(kServiceTransformFeedbackId
))
480 .RetiresOnSaturation();
481 GenHelper
<cmds::GenTransformFeedbacksImmediate
>(
482 client_transformfeedback_id_
);
485 if (init
.extensions
.find("GL_ARB_sync ") != std::string::npos
||
486 version
->IsAtLeastGL(3, 2) || version
->IsAtLeastGLES(3, 0)) {
487 DoFenceSync(client_sync_id_
, kServiceSyncId
);
490 if (reset_unsafe_es3_apis_enabled
) {
491 decoder_
->set_unsafe_es3_apis_enabled(false);
494 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
497 void GLES2DecoderTestBase::ResetDecoder() {
500 // All Tests should have read all their GLErrors before getting here.
501 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
503 EXPECT_CALL(*gl_
, DeleteBuffersARB(1, _
))
505 .RetiresOnSaturation();
506 if (group_
->feature_info()->feature_flags().native_vertex_array_object
) {
507 EXPECT_CALL(*gl_
, DeleteVertexArraysOES(1, Pointee(kServiceVertexArrayId
)))
509 .RetiresOnSaturation();
512 decoder_
->EndDecoding();
513 decoder_
->Destroy(true);
515 group_
->Destroy(mock_decoder_
.get(), false);
517 ::gfx::MockGLInterface::SetGLInterface(NULL
);
519 gfx::ClearGLBindings();
522 void GLES2DecoderTestBase::TearDown() {
526 void GLES2DecoderTestBase::ExpectEnableDisable(GLenum cap
, bool enable
) {
528 EXPECT_CALL(*gl_
, Enable(cap
))
530 .RetiresOnSaturation();
532 EXPECT_CALL(*gl_
, Disable(cap
))
534 .RetiresOnSaturation();
539 GLint
GLES2DecoderTestBase::GetGLError() {
540 EXPECT_CALL(*gl_
, GetError())
541 .WillOnce(Return(GL_NO_ERROR
))
542 .RetiresOnSaturation();
544 cmd
.Init(shared_memory_id_
, shared_memory_offset_
);
545 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
546 return static_cast<GLint
>(*GetSharedMemoryAs
<GLenum
*>());
549 void GLES2DecoderTestBase::DoCreateShader(
550 GLenum shader_type
, GLuint client_id
, GLuint service_id
) {
551 EXPECT_CALL(*gl_
, CreateShader(shader_type
))
553 .WillOnce(Return(service_id
))
554 .RetiresOnSaturation();
555 cmds::CreateShader cmd
;
556 cmd
.Init(shader_type
, client_id
);
557 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
560 bool GLES2DecoderTestBase::DoIsShader(GLuint client_id
) {
561 return IsObjectHelper
<cmds::IsShader
, cmds::IsShader::Result
>(client_id
);
564 void GLES2DecoderTestBase::DoDeleteShader(
565 GLuint client_id
, GLuint service_id
) {
566 EXPECT_CALL(*gl_
, DeleteShader(service_id
))
568 .RetiresOnSaturation();
569 cmds::DeleteShader cmd
;
571 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
574 void GLES2DecoderTestBase::DoCreateProgram(
575 GLuint client_id
, GLuint service_id
) {
576 EXPECT_CALL(*gl_
, CreateProgram())
578 .WillOnce(Return(service_id
))
579 .RetiresOnSaturation();
580 cmds::CreateProgram cmd
;
582 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
585 bool GLES2DecoderTestBase::DoIsProgram(GLuint client_id
) {
586 return IsObjectHelper
<cmds::IsProgram
, cmds::IsProgram::Result
>(client_id
);
589 void GLES2DecoderTestBase::DoDeleteProgram(
590 GLuint client_id
, GLuint
/* service_id */) {
591 cmds::DeleteProgram cmd
;
593 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
596 void GLES2DecoderTestBase::DoFenceSync(
597 GLuint client_id
, GLuint service_id
) {
598 EXPECT_CALL(*gl_
, FenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE
, 0))
600 .WillOnce(Return(reinterpret_cast<GLsync
>(service_id
)))
601 .RetiresOnSaturation();
604 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
607 void GLES2DecoderTestBase::SetBucketData(
608 uint32_t bucket_id
, const void* data
, uint32_t data_size
) {
609 DCHECK(data
|| data_size
== 0);
610 cmd::SetBucketSize cmd1
;
611 cmd1
.Init(bucket_id
, data_size
);
612 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
614 memcpy(shared_memory_address_
, data
, data_size
);
615 cmd::SetBucketData cmd2
;
616 cmd2
.Init(bucket_id
, 0, data_size
, kSharedMemoryId
, kSharedMemoryOffset
);
617 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
622 void GLES2DecoderTestBase::SetBucketAsCString(
623 uint32 bucket_id
, const char* str
) {
624 SetBucketData(bucket_id
, str
, str
? (strlen(str
) + 1) : 0);
627 void GLES2DecoderTestBase::SetBucketAsCStrings(
628 uint32 bucket_id
, GLsizei count
, const char** str
,
629 GLsizei count_in_header
, char str_end
) {
630 uint32_t header_size
= sizeof(GLint
) * (count
+ 1);
631 uint32_t total_size
= header_size
;
632 scoped_ptr
<GLint
[]> header(new GLint
[count
+ 1]);
633 header
[0] = static_cast<GLint
>(count_in_header
);
634 for (GLsizei ii
= 0; ii
< count
; ++ii
) {
635 header
[ii
+ 1] = str
&& str
[ii
] ? strlen(str
[ii
]) : 0;
636 total_size
+= header
[ii
+ 1] + 1;
638 cmd::SetBucketSize cmd1
;
639 cmd1
.Init(bucket_id
, total_size
);
640 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
641 memcpy(shared_memory_address_
, header
.get(), header_size
);
642 uint32_t offset
= header_size
;
643 for (GLsizei ii
= 0; ii
< count
; ++ii
) {
644 if (str
&& str
[ii
]) {
645 size_t str_len
= strlen(str
[ii
]);
646 memcpy(reinterpret_cast<char*>(shared_memory_address_
) + offset
,
650 memcpy(reinterpret_cast<char*>(shared_memory_address_
) + offset
,
654 cmd::SetBucketData cmd2
;
655 cmd2
.Init(bucket_id
, 0, total_size
, kSharedMemoryId
, kSharedMemoryOffset
);
656 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
660 void GLES2DecoderTestBase::SetupClearTextureExpectations(
662 GLuint old_service_id
,
666 GLenum internal_format
,
671 EXPECT_CALL(*gl_
, BindTexture(bind_target
, service_id
))
673 .RetiresOnSaturation();
674 EXPECT_CALL(*gl_
, TexImage2D(
675 target
, level
, internal_format
, width
, height
, 0, format
, type
, _
))
677 .RetiresOnSaturation();
678 EXPECT_CALL(*gl_
, BindTexture(bind_target
, old_service_id
))
680 .RetiresOnSaturation();
683 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearing(
686 GLclampf restore_red
,
687 GLclampf restore_green
,
688 GLclampf restore_blue
,
689 GLclampf restore_alpha
,
690 GLuint restore_stencil
,
691 GLclampf restore_depth
,
692 bool restore_scissor_test
) {
693 SetupExpectationsForFramebufferClearingMulti(
704 restore_scissor_test
);
707 void GLES2DecoderTestBase::SetupExpectationsForRestoreClearState(
708 GLclampf restore_red
,
709 GLclampf restore_green
,
710 GLclampf restore_blue
,
711 GLclampf restore_alpha
,
712 GLuint restore_stencil
,
713 GLclampf restore_depth
,
714 bool restore_scissor_test
) {
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 if (restore_scissor_test
) {
726 EXPECT_CALL(*gl_
, Enable(GL_SCISSOR_TEST
))
728 .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 // TODO(gman): Figure out why InSequence stopped working.
745 // InSequence sequence;
746 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(target
))
747 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
748 .RetiresOnSaturation();
749 if (target
== GL_READ_FRAMEBUFFER_EXT
) {
750 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT
, 0))
752 .RetiresOnSaturation();
753 EXPECT_CALL(*gl_
, BindFramebufferEXT(
754 GL_DRAW_FRAMEBUFFER_EXT
, read_framebuffer_service_id
))
756 .RetiresOnSaturation();
758 if ((clear_bits
& GL_COLOR_BUFFER_BIT
) != 0) {
759 EXPECT_CALL(*gl_
, ClearColor(0.0f
, 0.0f
, 0.0f
, 0.0f
))
761 .RetiresOnSaturation();
762 SetupExpectationsForColorMask(true, true, true, true);
764 if ((clear_bits
& GL_STENCIL_BUFFER_BIT
) != 0) {
765 EXPECT_CALL(*gl_
, ClearStencil(0))
767 .RetiresOnSaturation();
768 EXPECT_CALL(*gl_
, StencilMask(static_cast<GLuint
>(-1)))
770 .RetiresOnSaturation();
772 if ((clear_bits
& GL_DEPTH_BUFFER_BIT
) != 0) {
773 EXPECT_CALL(*gl_
, ClearDepth(1.0f
))
775 .RetiresOnSaturation();
776 SetupExpectationsForDepthMask(true);
778 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST
, false);
779 EXPECT_CALL(*gl_
, Clear(clear_bits
))
781 .RetiresOnSaturation();
782 SetupExpectationsForRestoreClearState(
783 restore_red
, restore_green
, restore_blue
, restore_alpha
,
784 restore_stencil
, restore_depth
, restore_scissor_test
);
785 if (target
== GL_READ_FRAMEBUFFER_EXT
) {
786 EXPECT_CALL(*gl_
, BindFramebufferEXT(
787 GL_READ_FRAMEBUFFER_EXT
, read_framebuffer_service_id
))
789 .RetiresOnSaturation();
790 EXPECT_CALL(*gl_
, BindFramebufferEXT(
791 GL_DRAW_FRAMEBUFFER_EXT
, draw_framebuffer_service_id
))
793 .RetiresOnSaturation();
797 void GLES2DecoderTestBase::SetupShaderForUniform(GLenum uniform_type
) {
798 static AttribInfo attribs
[] = {
799 { "foo", 1, GL_FLOAT
, 1, },
800 { "goo", 1, GL_FLOAT
, 2, },
802 UniformInfo uniforms
[] = {
803 { "bar", 1, uniform_type
, 0, 2, -1, },
804 { "car", 4, uniform_type
, 1, 1, -1, },
806 const GLuint kClientVertexShaderId
= 5001;
807 const GLuint kServiceVertexShaderId
= 6001;
808 const GLuint kClientFragmentShaderId
= 5002;
809 const GLuint kServiceFragmentShaderId
= 6002;
810 SetupShader(attribs
, arraysize(attribs
), uniforms
, arraysize(uniforms
),
811 client_program_id_
, kServiceProgramId
,
812 kClientVertexShaderId
, kServiceVertexShaderId
,
813 kClientFragmentShaderId
, kServiceFragmentShaderId
);
815 EXPECT_CALL(*gl_
, UseProgram(kServiceProgramId
))
817 .RetiresOnSaturation();
818 cmds::UseProgram cmd
;
819 cmd
.Init(client_program_id_
);
820 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
823 void GLES2DecoderTestBase::DoBindBuffer(
824 GLenum target
, GLuint client_id
, GLuint service_id
) {
825 EXPECT_CALL(*gl_
, BindBuffer(target
, service_id
))
827 .RetiresOnSaturation();
828 cmds::BindBuffer cmd
;
829 cmd
.Init(target
, client_id
);
830 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
833 bool GLES2DecoderTestBase::DoIsBuffer(GLuint client_id
) {
834 return IsObjectHelper
<cmds::IsBuffer
, cmds::IsBuffer::Result
>(client_id
);
837 void GLES2DecoderTestBase::DoDeleteBuffer(
838 GLuint client_id
, GLuint service_id
) {
839 EXPECT_CALL(*gl_
, DeleteBuffersARB(1, Pointee(service_id
)))
841 .RetiresOnSaturation();
842 GenHelper
<cmds::DeleteBuffersImmediate
>(client_id
);
845 void GLES2DecoderTestBase::SetupExpectationsForColorMask(bool red
,
849 if (ignore_cached_state_for_test_
|| cached_color_mask_red_
!= red
||
850 cached_color_mask_green_
!= green
|| cached_color_mask_blue_
!= blue
||
851 cached_color_mask_alpha_
!= alpha
) {
852 cached_color_mask_red_
= red
;
853 cached_color_mask_green_
= green
;
854 cached_color_mask_blue_
= blue
;
855 cached_color_mask_alpha_
= alpha
;
856 EXPECT_CALL(*gl_
, ColorMask(red
, green
, blue
, alpha
))
858 .RetiresOnSaturation();
862 void GLES2DecoderTestBase::SetupExpectationsForDepthMask(bool mask
) {
863 if (ignore_cached_state_for_test_
|| cached_depth_mask_
!= mask
) {
864 cached_depth_mask_
= mask
;
865 EXPECT_CALL(*gl_
, DepthMask(mask
)).Times(1).RetiresOnSaturation();
869 void GLES2DecoderTestBase::SetupExpectationsForStencilMask(GLuint front_mask
,
871 if (ignore_cached_state_for_test_
||
872 cached_stencil_front_mask_
!= front_mask
) {
873 cached_stencil_front_mask_
= front_mask
;
874 EXPECT_CALL(*gl_
, StencilMaskSeparate(GL_FRONT
, front_mask
))
876 .RetiresOnSaturation();
879 if (ignore_cached_state_for_test_
||
880 cached_stencil_back_mask_
!= back_mask
) {
881 cached_stencil_back_mask_
= back_mask
;
882 EXPECT_CALL(*gl_
, StencilMaskSeparate(GL_BACK
, back_mask
))
884 .RetiresOnSaturation();
888 void GLES2DecoderTestBase::SetupExpectationsForEnableDisable(GLenum cap
,
892 if (enable_flags_
.cached_blend
== enable
&&
893 !ignore_cached_state_for_test_
)
895 enable_flags_
.cached_blend
= enable
;
898 if (enable_flags_
.cached_cull_face
== enable
&&
899 !ignore_cached_state_for_test_
)
901 enable_flags_
.cached_cull_face
= enable
;
904 if (enable_flags_
.cached_depth_test
== enable
&&
905 !ignore_cached_state_for_test_
)
907 enable_flags_
.cached_depth_test
= enable
;
910 if (enable_flags_
.cached_dither
== enable
&&
911 !ignore_cached_state_for_test_
)
913 enable_flags_
.cached_dither
= enable
;
915 case GL_POLYGON_OFFSET_FILL
:
916 if (enable_flags_
.cached_polygon_offset_fill
== enable
&&
917 !ignore_cached_state_for_test_
)
919 enable_flags_
.cached_polygon_offset_fill
= enable
;
921 case GL_SAMPLE_ALPHA_TO_COVERAGE
:
922 if (enable_flags_
.cached_sample_alpha_to_coverage
== enable
&&
923 !ignore_cached_state_for_test_
)
925 enable_flags_
.cached_sample_alpha_to_coverage
= enable
;
927 case GL_SAMPLE_COVERAGE
:
928 if (enable_flags_
.cached_sample_coverage
== enable
&&
929 !ignore_cached_state_for_test_
)
931 enable_flags_
.cached_sample_coverage
= enable
;
933 case GL_SCISSOR_TEST
:
934 if (enable_flags_
.cached_scissor_test
== enable
&&
935 !ignore_cached_state_for_test_
)
937 enable_flags_
.cached_scissor_test
= enable
;
939 case GL_STENCIL_TEST
:
940 if (enable_flags_
.cached_stencil_test
== enable
&&
941 !ignore_cached_state_for_test_
)
943 enable_flags_
.cached_stencil_test
= enable
;
950 EXPECT_CALL(*gl_
, Enable(cap
)).Times(1).RetiresOnSaturation();
952 EXPECT_CALL(*gl_
, Disable(cap
)).Times(1).RetiresOnSaturation();
956 void GLES2DecoderTestBase::SetupExpectationsForApplyingDirtyState(
957 bool framebuffer_is_rgb
,
958 bool framebuffer_has_depth
,
959 bool framebuffer_has_stencil
,
963 GLuint front_stencil_mask
,
964 GLuint back_stencil_mask
,
965 bool stencil_enabled
) {
966 bool color_mask_red
= (color_bits
& 0x1000) != 0;
967 bool color_mask_green
= (color_bits
& 0x0100) != 0;
968 bool color_mask_blue
= (color_bits
& 0x0010) != 0;
969 bool color_mask_alpha
= (color_bits
& 0x0001) && !framebuffer_is_rgb
;
971 SetupExpectationsForColorMask(
972 color_mask_red
, color_mask_green
, color_mask_blue
, color_mask_alpha
);
973 SetupExpectationsForDepthMask(depth_mask
);
974 SetupExpectationsForStencilMask(front_stencil_mask
, back_stencil_mask
);
975 SetupExpectationsForEnableDisable(GL_DEPTH_TEST
,
976 framebuffer_has_depth
&& depth_enabled
);
977 SetupExpectationsForEnableDisable(GL_STENCIL_TEST
,
978 framebuffer_has_stencil
&& stencil_enabled
);
981 void GLES2DecoderTestBase::SetupExpectationsForApplyingDefaultDirtyState() {
982 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
983 false, // Framebuffer has depth
984 false, // Framebuffer has stencil
985 0x1111, // color bits
987 false, // depth enabled
988 0, // front stencil mask
989 0, // back stencil mask
990 false); // stencil enabled
993 GLES2DecoderTestBase::EnableFlags::EnableFlags()
994 : cached_blend(false),
995 cached_cull_face(false),
996 cached_depth_test(false),
998 cached_polygon_offset_fill(false),
999 cached_sample_alpha_to_coverage(false),
1000 cached_sample_coverage(false),
1001 cached_scissor_test(false),
1002 cached_stencil_test(false) {
1005 void GLES2DecoderTestBase::DoBindFramebuffer(
1006 GLenum target
, GLuint client_id
, GLuint service_id
) {
1007 EXPECT_CALL(*gl_
, BindFramebufferEXT(target
, service_id
))
1009 .RetiresOnSaturation();
1010 cmds::BindFramebuffer cmd
;
1011 cmd
.Init(target
, client_id
);
1012 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1015 bool GLES2DecoderTestBase::DoIsFramebuffer(GLuint client_id
) {
1016 return IsObjectHelper
<cmds::IsFramebuffer
, cmds::IsFramebuffer::Result
>(
1020 void GLES2DecoderTestBase::DoDeleteFramebuffer(
1021 GLuint client_id
, GLuint service_id
,
1022 bool reset_draw
, GLenum draw_target
, GLuint draw_id
,
1023 bool reset_read
, GLenum read_target
, GLuint read_id
) {
1025 EXPECT_CALL(*gl_
, BindFramebufferEXT(draw_target
, draw_id
))
1027 .RetiresOnSaturation();
1030 EXPECT_CALL(*gl_
, BindFramebufferEXT(read_target
, read_id
))
1032 .RetiresOnSaturation();
1034 EXPECT_CALL(*gl_
, DeleteFramebuffersEXT(1, Pointee(service_id
)))
1036 .RetiresOnSaturation();
1037 GenHelper
<cmds::DeleteFramebuffersImmediate
>(client_id
);
1040 void GLES2DecoderTestBase::DoBindRenderbuffer(
1041 GLenum target
, GLuint client_id
, GLuint service_id
) {
1042 service_renderbuffer_id_
= service_id
;
1043 service_renderbuffer_valid_
= true;
1044 EXPECT_CALL(*gl_
, BindRenderbufferEXT(target
, service_id
))
1046 .RetiresOnSaturation();
1047 cmds::BindRenderbuffer cmd
;
1048 cmd
.Init(target
, client_id
);
1049 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1052 void GLES2DecoderTestBase::DoRenderbufferStorageMultisampleCHROMIUM(
1055 GLenum internal_format
,
1059 EXPECT_CALL(*gl_
, GetError())
1060 .WillOnce(Return(GL_NO_ERROR
))
1061 .RetiresOnSaturation();
1063 RenderbufferStorageMultisampleEXT(
1064 target
, samples
, gl_format
, width
, height
))
1066 .RetiresOnSaturation();
1067 EXPECT_CALL(*gl_
, GetError())
1068 .WillOnce(Return(GL_NO_ERROR
))
1069 .RetiresOnSaturation();
1070 cmds::RenderbufferStorageMultisampleCHROMIUM cmd
;
1071 cmd
.Init(target
, samples
, internal_format
, width
, height
);
1072 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1073 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1076 void GLES2DecoderTestBase::RestoreRenderbufferBindings() {
1077 GetDecoder()->RestoreRenderbufferBindings();
1078 service_renderbuffer_valid_
= false;
1081 void GLES2DecoderTestBase::EnsureRenderbufferBound(bool expect_bind
) {
1082 EXPECT_NE(expect_bind
, service_renderbuffer_valid_
);
1085 service_renderbuffer_valid_
= true;
1087 BindRenderbufferEXT(GL_RENDERBUFFER
, service_renderbuffer_id_
))
1089 .RetiresOnSaturation();
1091 EXPECT_CALL(*gl_
, BindRenderbufferEXT(_
, _
)).Times(0);
1095 bool GLES2DecoderTestBase::DoIsRenderbuffer(GLuint client_id
) {
1096 return IsObjectHelper
<cmds::IsRenderbuffer
, cmds::IsRenderbuffer::Result
>(
1100 void GLES2DecoderTestBase::DoDeleteRenderbuffer(
1101 GLuint client_id
, GLuint service_id
) {
1102 EXPECT_CALL(*gl_
, DeleteRenderbuffersEXT(1, Pointee(service_id
)))
1104 .RetiresOnSaturation();
1105 GenHelper
<cmds::DeleteRenderbuffersImmediate
>(client_id
);
1108 void GLES2DecoderTestBase::DoBindTexture(
1109 GLenum target
, GLuint client_id
, GLuint service_id
) {
1110 EXPECT_CALL(*gl_
, BindTexture(target
, service_id
))
1112 .RetiresOnSaturation();
1113 cmds::BindTexture cmd
;
1114 cmd
.Init(target
, client_id
);
1115 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1118 bool GLES2DecoderTestBase::DoIsTexture(GLuint client_id
) {
1119 return IsObjectHelper
<cmds::IsTexture
, cmds::IsTexture::Result
>(client_id
);
1122 void GLES2DecoderTestBase::DoDeleteTexture(
1123 GLuint client_id
, GLuint service_id
) {
1124 EXPECT_CALL(*gl_
, DeleteTextures(1, Pointee(service_id
)))
1126 .RetiresOnSaturation();
1127 GenHelper
<cmds::DeleteTexturesImmediate
>(client_id
);
1130 void GLES2DecoderTestBase::DoBindTexImage2DCHROMIUM(GLenum target
,
1132 cmds::BindTexImage2DCHROMIUM bind_tex_image_2d_cmd
;
1133 bind_tex_image_2d_cmd
.Init(target
, image_id
);
1134 EXPECT_CALL(*gl_
, GetError())
1135 .WillOnce(Return(GL_NO_ERROR
))
1136 .WillOnce(Return(GL_NO_ERROR
))
1137 .RetiresOnSaturation();
1138 EXPECT_EQ(error::kNoError
, ExecuteCmd(bind_tex_image_2d_cmd
));
1139 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1142 void GLES2DecoderTestBase::DoTexImage2D(
1143 GLenum target
, GLint level
, GLenum internal_format
,
1144 GLsizei width
, GLsizei height
, GLint border
,
1145 GLenum format
, GLenum type
,
1146 uint32 shared_memory_id
, uint32 shared_memory_offset
) {
1147 EXPECT_CALL(*gl_
, GetError())
1148 .WillOnce(Return(GL_NO_ERROR
))
1149 .RetiresOnSaturation();
1150 EXPECT_CALL(*gl_
, TexImage2D(target
, level
, internal_format
,
1151 width
, height
, border
, format
, type
, _
))
1153 .RetiresOnSaturation();
1154 EXPECT_CALL(*gl_
, GetError())
1155 .WillOnce(Return(GL_NO_ERROR
))
1156 .RetiresOnSaturation();
1157 cmds::TexImage2D cmd
;
1158 cmd
.Init(target
, level
, internal_format
, width
, height
, format
,
1159 type
, shared_memory_id
, shared_memory_offset
);
1160 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1163 void GLES2DecoderTestBase::DoTexImage2DConvertInternalFormat(
1164 GLenum target
, GLint level
, GLenum requested_internal_format
,
1165 GLsizei width
, GLsizei height
, GLint border
,
1166 GLenum format
, GLenum type
,
1167 uint32 shared_memory_id
, uint32 shared_memory_offset
,
1168 GLenum expected_internal_format
) {
1169 EXPECT_CALL(*gl_
, GetError())
1170 .WillOnce(Return(GL_NO_ERROR
))
1171 .RetiresOnSaturation();
1172 EXPECT_CALL(*gl_
, TexImage2D(target
, level
, expected_internal_format
,
1173 width
, height
, border
, format
, type
, _
))
1175 .RetiresOnSaturation();
1176 EXPECT_CALL(*gl_
, GetError())
1177 .WillOnce(Return(GL_NO_ERROR
))
1178 .RetiresOnSaturation();
1179 cmds::TexImage2D cmd
;
1180 cmd
.Init(target
, level
, requested_internal_format
, width
, height
,
1181 format
, type
, shared_memory_id
, shared_memory_offset
);
1182 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1185 void GLES2DecoderTestBase::DoCompressedTexImage2D(
1186 GLenum target
, GLint level
, GLenum format
,
1187 GLsizei width
, GLsizei height
, GLint border
,
1188 GLsizei size
, uint32 bucket_id
) {
1189 EXPECT_CALL(*gl_
, GetError())
1190 .WillOnce(Return(GL_NO_ERROR
))
1191 .RetiresOnSaturation();
1192 EXPECT_CALL(*gl_
, CompressedTexImage2D(
1193 target
, level
, format
, width
, height
, border
, size
, _
))
1195 .RetiresOnSaturation();
1196 EXPECT_CALL(*gl_
, GetError())
1197 .WillOnce(Return(GL_NO_ERROR
))
1198 .RetiresOnSaturation();
1199 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(bucket_id
);
1200 bucket
->SetSize(size
);
1201 cmds::CompressedTexImage2DBucket cmd
;
1203 target
, level
, format
, width
, height
,
1205 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1208 void GLES2DecoderTestBase::DoRenderbufferStorage(
1209 GLenum target
, GLenum internal_format
, GLenum actual_format
,
1210 GLsizei width
, GLsizei height
, GLenum error
) {
1211 EXPECT_CALL(*gl_
, GetError())
1212 .WillOnce(Return(GL_NO_ERROR
))
1213 .RetiresOnSaturation();
1214 EXPECT_CALL(*gl_
, RenderbufferStorageEXT(
1215 target
, actual_format
, width
, height
))
1217 .RetiresOnSaturation();
1218 EXPECT_CALL(*gl_
, GetError())
1219 .WillOnce(Return(error
))
1220 .RetiresOnSaturation();
1221 cmds::RenderbufferStorage cmd
;
1222 cmd
.Init(target
, internal_format
, width
, height
);
1223 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1226 void GLES2DecoderTestBase::DoFramebufferTexture2D(
1227 GLenum target
, GLenum attachment
, GLenum textarget
,
1228 GLuint texture_client_id
, GLuint texture_service_id
, GLint level
,
1230 EXPECT_CALL(*gl_
, GetError())
1231 .WillOnce(Return(GL_NO_ERROR
))
1232 .RetiresOnSaturation();
1233 EXPECT_CALL(*gl_
, FramebufferTexture2DEXT(
1234 target
, attachment
, textarget
, texture_service_id
, level
))
1236 .RetiresOnSaturation();
1237 EXPECT_CALL(*gl_
, GetError())
1238 .WillOnce(Return(error
))
1239 .RetiresOnSaturation();
1240 cmds::FramebufferTexture2D cmd
;
1241 cmd
.Init(target
, attachment
, textarget
, texture_client_id
);
1242 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1245 void GLES2DecoderTestBase::DoFramebufferRenderbuffer(
1248 GLenum renderbuffer_target
,
1249 GLuint renderbuffer_client_id
,
1250 GLuint renderbuffer_service_id
,
1252 EXPECT_CALL(*gl_
, GetError())
1253 .WillOnce(Return(GL_NO_ERROR
))
1254 .RetiresOnSaturation();
1255 EXPECT_CALL(*gl_
, FramebufferRenderbufferEXT(
1256 target
, attachment
, renderbuffer_target
, renderbuffer_service_id
))
1258 .RetiresOnSaturation();
1259 EXPECT_CALL(*gl_
, GetError())
1260 .WillOnce(Return(error
))
1261 .RetiresOnSaturation();
1262 cmds::FramebufferRenderbuffer cmd
;
1263 cmd
.Init(target
, attachment
, renderbuffer_target
, renderbuffer_client_id
);
1264 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1267 void GLES2DecoderTestBase::DoVertexAttribPointer(
1268 GLuint index
, GLint size
, GLenum type
, GLsizei stride
, GLuint offset
) {
1270 VertexAttribPointer(index
, size
, type
, GL_FALSE
, stride
,
1271 BufferOffset(offset
)))
1273 .RetiresOnSaturation();
1274 cmds::VertexAttribPointer cmd
;
1275 cmd
.Init(index
, size
, GL_FLOAT
, GL_FALSE
, stride
, offset
);
1276 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1279 void GLES2DecoderTestBase::DoVertexAttribDivisorANGLE(
1280 GLuint index
, GLuint divisor
) {
1282 VertexAttribDivisorANGLE(index
, divisor
))
1284 .RetiresOnSaturation();
1285 cmds::VertexAttribDivisorANGLE cmd
;
1286 cmd
.Init(index
, divisor
);
1287 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1290 void GLES2DecoderTestBase::AddExpectationsForGenVertexArraysOES(){
1291 if (group_
->feature_info()->feature_flags().native_vertex_array_object
) {
1292 EXPECT_CALL(*gl_
, GenVertexArraysOES(1, _
))
1293 .WillOnce(SetArgumentPointee
<1>(kServiceVertexArrayId
))
1294 .RetiresOnSaturation();
1298 void GLES2DecoderTestBase::AddExpectationsForDeleteVertexArraysOES(){
1299 if (group_
->feature_info()->feature_flags().native_vertex_array_object
) {
1300 EXPECT_CALL(*gl_
, DeleteVertexArraysOES(1, _
))
1302 .RetiresOnSaturation();
1306 void GLES2DecoderTestBase::AddExpectationsForDeleteBoundVertexArraysOES() {
1307 // Expectations are the same as a delete, followed by binding VAO 0.
1308 AddExpectationsForDeleteVertexArraysOES();
1309 AddExpectationsForBindVertexArrayOES();
1312 void GLES2DecoderTestBase::AddExpectationsForBindVertexArrayOES() {
1313 if (group_
->feature_info()->feature_flags().native_vertex_array_object
) {
1314 EXPECT_CALL(*gl_
, BindVertexArrayOES(_
))
1316 .RetiresOnSaturation();
1318 for (uint32 vv
= 0; vv
< group_
->max_vertex_attribs(); ++vv
) {
1319 AddExpectationsForRestoreAttribState(vv
);
1322 EXPECT_CALL(*gl_
, BindBuffer(GL_ELEMENT_ARRAY_BUFFER
, _
))
1324 .RetiresOnSaturation();
1328 void GLES2DecoderTestBase::AddExpectationsForRestoreAttribState(GLuint attrib
) {
1329 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, _
))
1331 .RetiresOnSaturation();
1333 EXPECT_CALL(*gl_
, VertexAttribPointer(attrib
, _
, _
, _
, _
, _
))
1335 .RetiresOnSaturation();
1337 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(attrib
, _
))
1338 .Times(testing::AtMost(1))
1339 .RetiresOnSaturation();
1341 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, _
))
1343 .RetiresOnSaturation();
1346 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2
) {
1348 // TODO(bajones): Not sure if I can tell which of these will be called
1349 EXPECT_CALL(*gl_
, EnableVertexAttribArray(attrib
))
1350 .Times(testing::AtMost(1))
1351 .RetiresOnSaturation();
1353 EXPECT_CALL(*gl_
, DisableVertexAttribArray(attrib
))
1354 .Times(testing::AtMost(1))
1355 .RetiresOnSaturation();
1359 // GCC requires these declarations, but MSVC requires they not be present
1360 #ifndef COMPILER_MSVC
1361 const int GLES2DecoderTestBase::kBackBufferWidth
;
1362 const int GLES2DecoderTestBase::kBackBufferHeight
;
1364 const GLint
GLES2DecoderTestBase::kMaxTextureSize
;
1365 const GLint
GLES2DecoderTestBase::kMaxCubeMapTextureSize
;
1366 const GLint
GLES2DecoderTestBase::kNumVertexAttribs
;
1367 const GLint
GLES2DecoderTestBase::kNumTextureUnits
;
1368 const GLint
GLES2DecoderTestBase::kMaxTextureImageUnits
;
1369 const GLint
GLES2DecoderTestBase::kMaxVertexTextureImageUnits
;
1370 const GLint
GLES2DecoderTestBase::kMaxFragmentUniformVectors
;
1371 const GLint
GLES2DecoderTestBase::kMaxVaryingVectors
;
1372 const GLint
GLES2DecoderTestBase::kMaxVertexUniformVectors
;
1373 const GLint
GLES2DecoderTestBase::kMaxViewportWidth
;
1374 const GLint
GLES2DecoderTestBase::kMaxViewportHeight
;
1376 const GLint
GLES2DecoderTestBase::kViewportX
;
1377 const GLint
GLES2DecoderTestBase::kViewportY
;
1378 const GLint
GLES2DecoderTestBase::kViewportWidth
;
1379 const GLint
GLES2DecoderTestBase::kViewportHeight
;
1381 const GLuint
GLES2DecoderTestBase::kServiceAttrib0BufferId
;
1382 const GLuint
GLES2DecoderTestBase::kServiceFixedAttribBufferId
;
1384 const GLuint
GLES2DecoderTestBase::kServiceBufferId
;
1385 const GLuint
GLES2DecoderTestBase::kServiceFramebufferId
;
1386 const GLuint
GLES2DecoderTestBase::kServiceRenderbufferId
;
1387 const GLuint
GLES2DecoderTestBase::kServiceSamplerId
;
1388 const GLuint
GLES2DecoderTestBase::kServiceTextureId
;
1389 const GLuint
GLES2DecoderTestBase::kServiceProgramId
;
1390 const GLuint
GLES2DecoderTestBase::kServiceShaderId
;
1391 const GLuint
GLES2DecoderTestBase::kServiceElementBufferId
;
1392 const GLuint
GLES2DecoderTestBase::kServiceQueryId
;
1393 const GLuint
GLES2DecoderTestBase::kServiceVertexArrayId
;
1394 const GLuint
GLES2DecoderTestBase::kServiceTransformFeedbackId
;
1395 const GLuint
GLES2DecoderTestBase::kServiceSyncId
;
1397 const int32
GLES2DecoderTestBase::kSharedMemoryId
;
1398 const size_t GLES2DecoderTestBase::kSharedBufferSize
;
1399 const uint32
GLES2DecoderTestBase::kSharedMemoryOffset
;
1400 const int32
GLES2DecoderTestBase::kInvalidSharedMemoryId
;
1401 const uint32
GLES2DecoderTestBase::kInvalidSharedMemoryOffset
;
1402 const uint32
GLES2DecoderTestBase::kInitialResult
;
1403 const uint8
GLES2DecoderTestBase::kInitialMemoryValue
;
1405 const uint32
GLES2DecoderTestBase::kNewClientId
;
1406 const uint32
GLES2DecoderTestBase::kNewServiceId
;
1407 const uint32
GLES2DecoderTestBase::kInvalidClientId
;
1409 const GLuint
GLES2DecoderTestBase::kServiceVertexShaderId
;
1410 const GLuint
GLES2DecoderTestBase::kServiceFragmentShaderId
;
1412 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumShaderId
;
1413 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumProgramId
;
1415 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumTextureBufferId
;
1416 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumVertexBufferId
;
1417 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumFBOId
;
1418 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumPositionAttrib
;
1419 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumTexAttrib
;
1420 const GLuint
GLES2DecoderTestBase::kServiceCopyTextureChromiumSamplerLocation
;
1422 const GLsizei
GLES2DecoderTestBase::kNumVertices
;
1423 const GLsizei
GLES2DecoderTestBase::kNumIndices
;
1424 const int GLES2DecoderTestBase::kValidIndexRangeStart
;
1425 const int GLES2DecoderTestBase::kValidIndexRangeCount
;
1426 const int GLES2DecoderTestBase::kInvalidIndexRangeStart
;
1427 const int GLES2DecoderTestBase::kInvalidIndexRangeCount
;
1428 const int GLES2DecoderTestBase::kOutOfRangeIndexRangeEnd
;
1429 const GLuint
GLES2DecoderTestBase::kMaxValidIndex
;
1431 const GLint
GLES2DecoderTestBase::kMaxAttribLength
;
1432 const GLint
GLES2DecoderTestBase::kAttrib1Size
;
1433 const GLint
GLES2DecoderTestBase::kAttrib2Size
;
1434 const GLint
GLES2DecoderTestBase::kAttrib3Size
;
1435 const GLint
GLES2DecoderTestBase::kAttrib1Location
;
1436 const GLint
GLES2DecoderTestBase::kAttrib2Location
;
1437 const GLint
GLES2DecoderTestBase::kAttrib3Location
;
1438 const GLenum
GLES2DecoderTestBase::kAttrib1Type
;
1439 const GLenum
GLES2DecoderTestBase::kAttrib2Type
;
1440 const GLenum
GLES2DecoderTestBase::kAttrib3Type
;
1441 const GLint
GLES2DecoderTestBase::kInvalidAttribLocation
;
1442 const GLint
GLES2DecoderTestBase::kBadAttribIndex
;
1444 const GLint
GLES2DecoderTestBase::kMaxUniformLength
;
1445 const GLint
GLES2DecoderTestBase::kUniform1Size
;
1446 const GLint
GLES2DecoderTestBase::kUniform2Size
;
1447 const GLint
GLES2DecoderTestBase::kUniform3Size
;
1448 const GLint
GLES2DecoderTestBase::kUniform1RealLocation
;
1449 const GLint
GLES2DecoderTestBase::kUniform2RealLocation
;
1450 const GLint
GLES2DecoderTestBase::kUniform2ElementRealLocation
;
1451 const GLint
GLES2DecoderTestBase::kUniform3RealLocation
;
1452 const GLint
GLES2DecoderTestBase::kUniform1FakeLocation
;
1453 const GLint
GLES2DecoderTestBase::kUniform2FakeLocation
;
1454 const GLint
GLES2DecoderTestBase::kUniform2ElementFakeLocation
;
1455 const GLint
GLES2DecoderTestBase::kUniform3FakeLocation
;
1456 const GLint
GLES2DecoderTestBase::kUniform1DesiredLocation
;
1457 const GLint
GLES2DecoderTestBase::kUniform2DesiredLocation
;
1458 const GLint
GLES2DecoderTestBase::kUniform3DesiredLocation
;
1459 const GLenum
GLES2DecoderTestBase::kUniform1Type
;
1460 const GLenum
GLES2DecoderTestBase::kUniform2Type
;
1461 const GLenum
GLES2DecoderTestBase::kUniform3Type
;
1462 const GLenum
GLES2DecoderTestBase::kUniformCubemapType
;
1463 const GLint
GLES2DecoderTestBase::kInvalidUniformLocation
;
1464 const GLint
GLES2DecoderTestBase::kBadUniformIndex
;
1468 const char* GLES2DecoderTestBase::kAttrib1Name
= "attrib1";
1469 const char* GLES2DecoderTestBase::kAttrib2Name
= "attrib2";
1470 const char* GLES2DecoderTestBase::kAttrib3Name
= "attrib3";
1471 const char* GLES2DecoderTestBase::kUniform1Name
= "uniform1";
1472 const char* GLES2DecoderTestBase::kUniform2Name
= "uniform2[0]";
1473 const char* GLES2DecoderTestBase::kUniform3Name
= "uniform3[0]";
1475 void GLES2DecoderTestBase::SetupDefaultProgram() {
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
, kUniform1Type
,
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::SetupCubemapProgram() {
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
, kUniformCubemapType
,
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 GLES2DecoderTestBase::SetupSamplerExternalProgram() {
1545 static AttribInfo attribs
[] = {
1546 { kAttrib1Name
, kAttrib1Size
, kAttrib1Type
, kAttrib1Location
, },
1547 { kAttrib2Name
, kAttrib2Size
, kAttrib2Type
, kAttrib2Location
, },
1548 { kAttrib3Name
, kAttrib3Size
, kAttrib3Type
, kAttrib3Location
, },
1550 static UniformInfo uniforms
[] = {
1551 { kUniform1Name
, kUniform1Size
, kUniformSamplerExternalType
,
1552 kUniform1FakeLocation
, kUniform1RealLocation
,
1553 kUniform1DesiredLocation
, },
1554 { kUniform2Name
, kUniform2Size
, kUniform2Type
,
1555 kUniform2FakeLocation
, kUniform2RealLocation
,
1556 kUniform2DesiredLocation
, },
1557 { kUniform3Name
, kUniform3Size
, kUniform3Type
,
1558 kUniform3FakeLocation
, kUniform3RealLocation
,
1559 kUniform3DesiredLocation
, },
1561 SetupShader(attribs
, arraysize(attribs
), uniforms
, arraysize(uniforms
),
1562 client_program_id_
, kServiceProgramId
,
1563 client_vertex_shader_id_
, kServiceVertexShaderId
,
1564 client_fragment_shader_id_
, kServiceFragmentShaderId
);
1568 EXPECT_CALL(*gl_
, UseProgram(kServiceProgramId
))
1570 .RetiresOnSaturation();
1571 cmds::UseProgram cmd
;
1572 cmd
.Init(client_program_id_
);
1573 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1577 void GLES2DecoderWithShaderTestBase::TearDown() {
1578 GLES2DecoderTestBase::TearDown();
1581 void GLES2DecoderTestBase::SetupShader(
1582 GLES2DecoderTestBase::AttribInfo
* attribs
, size_t num_attribs
,
1583 GLES2DecoderTestBase::UniformInfo
* uniforms
, size_t num_uniforms
,
1584 GLuint program_client_id
, GLuint program_service_id
,
1585 GLuint vertex_shader_client_id
, GLuint vertex_shader_service_id
,
1586 GLuint fragment_shader_client_id
, GLuint fragment_shader_service_id
) {
1591 AttachShader(program_service_id
, vertex_shader_service_id
))
1593 .RetiresOnSaturation();
1595 AttachShader(program_service_id
, fragment_shader_service_id
))
1597 .RetiresOnSaturation();
1598 TestHelper::SetupShader(
1599 gl_
.get(), attribs
, num_attribs
, uniforms
, num_uniforms
,
1600 program_service_id
);
1604 GL_VERTEX_SHADER
, vertex_shader_client_id
, vertex_shader_service_id
);
1606 GL_FRAGMENT_SHADER
, fragment_shader_client_id
,
1607 fragment_shader_service_id
);
1609 TestHelper::SetShaderStates(
1610 gl_
.get(), GetShader(vertex_shader_client_id
), true);
1611 TestHelper::SetShaderStates(
1612 gl_
.get(), GetShader(fragment_shader_client_id
), true);
1614 cmds::AttachShader attach_cmd
;
1615 attach_cmd
.Init(program_client_id
, vertex_shader_client_id
);
1616 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
1618 attach_cmd
.Init(program_client_id
, fragment_shader_client_id
);
1619 EXPECT_EQ(error::kNoError
, ExecuteCmd(attach_cmd
));
1621 cmds::LinkProgram link_cmd
;
1622 link_cmd
.Init(program_client_id
);
1624 EXPECT_EQ(error::kNoError
, ExecuteCmd(link_cmd
));
1627 void GLES2DecoderTestBase::DoEnableDisable(GLenum cap
, bool enable
) {
1628 SetupExpectationsForEnableDisable(cap
, enable
);
1632 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1636 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1640 void GLES2DecoderTestBase::DoEnableVertexAttribArray(GLint index
) {
1641 EXPECT_CALL(*gl_
, EnableVertexAttribArray(index
))
1643 .RetiresOnSaturation();
1644 cmds::EnableVertexAttribArray cmd
;
1646 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1649 void GLES2DecoderTestBase::DoBufferData(GLenum target
, GLsizei size
) {
1650 EXPECT_CALL(*gl_
, GetError())
1651 .WillOnce(Return(GL_NO_ERROR
))
1652 .RetiresOnSaturation();
1653 EXPECT_CALL(*gl_
, BufferData(target
, size
, _
, GL_STREAM_DRAW
))
1655 .RetiresOnSaturation();
1656 EXPECT_CALL(*gl_
, GetError())
1657 .WillOnce(Return(GL_NO_ERROR
))
1658 .RetiresOnSaturation();
1659 cmds::BufferData cmd
;
1660 cmd
.Init(target
, size
, 0, 0, GL_STREAM_DRAW
);
1661 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1664 void GLES2DecoderTestBase::DoBufferSubData(
1665 GLenum target
, GLint offset
, GLsizei size
, const void* data
) {
1666 EXPECT_CALL(*gl_
, BufferSubData(target
, offset
, size
,
1667 shared_memory_address_
))
1669 .RetiresOnSaturation();
1670 memcpy(shared_memory_address_
, data
, size
);
1671 cmds::BufferSubData cmd
;
1672 cmd
.Init(target
, offset
, size
, shared_memory_id_
, shared_memory_offset_
);
1673 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1676 void GLES2DecoderTestBase::SetupVertexBuffer() {
1677 DoEnableVertexAttribArray(1);
1678 DoBindBuffer(GL_ARRAY_BUFFER
, client_buffer_id_
, kServiceBufferId
);
1679 DoBufferData(GL_ARRAY_BUFFER
, kNumVertices
* 2 * sizeof(GLfloat
));
1682 void GLES2DecoderTestBase::SetupAllNeededVertexBuffers() {
1683 DoBindBuffer(GL_ARRAY_BUFFER
, client_buffer_id_
, kServiceBufferId
);
1684 DoBufferData(GL_ARRAY_BUFFER
, kNumVertices
* 16 * sizeof(float));
1685 DoEnableVertexAttribArray(0);
1686 DoEnableVertexAttribArray(1);
1687 DoEnableVertexAttribArray(2);
1688 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1689 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1690 DoVertexAttribPointer(2, 2, GL_FLOAT
, 0, 0);
1693 void GLES2DecoderTestBase::SetupIndexBuffer() {
1694 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER
,
1695 client_element_buffer_id_
,
1696 kServiceElementBufferId
);
1697 static const GLshort indices
[] = {100, 1, 2, 3, 4, 5, 6, 7, 100, 9};
1698 static_assert(arraysize(indices
) == kNumIndices
,
1699 "indices should have kNumIndices elements");
1700 DoBufferData(GL_ELEMENT_ARRAY_BUFFER
, sizeof(indices
));
1701 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER
, 0, 2, indices
);
1702 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER
, 2, sizeof(indices
) - 2, &indices
[1]);
1705 void GLES2DecoderTestBase::SetupTexture() {
1706 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1707 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
1708 kSharedMemoryId
, kSharedMemoryOffset
);
1711 void GLES2DecoderTestBase::DeleteVertexBuffer() {
1712 DoDeleteBuffer(client_buffer_id_
, kServiceBufferId
);
1715 void GLES2DecoderTestBase::DeleteIndexBuffer() {
1716 DoDeleteBuffer(client_element_buffer_id_
, kServiceElementBufferId
);
1719 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0WithError(
1720 GLsizei num_vertices
, GLuint buffer_id
, GLenum error
) {
1721 if (group_
->feature_info()->gl_version_info().BehavesLikeGLES()) {
1725 EXPECT_CALL(*gl_
, GetError())
1726 .WillOnce(Return(GL_NO_ERROR
))
1727 .WillOnce(Return(error
))
1728 .RetiresOnSaturation();
1729 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, kServiceAttrib0BufferId
))
1731 .RetiresOnSaturation();
1732 EXPECT_CALL(*gl_
, BufferData(GL_ARRAY_BUFFER
,
1733 num_vertices
* sizeof(GLfloat
) * 4,
1734 _
, GL_DYNAMIC_DRAW
))
1736 .RetiresOnSaturation();
1737 if (error
== GL_NO_ERROR
) {
1738 EXPECT_CALL(*gl_
, BufferSubData(
1739 GL_ARRAY_BUFFER
, 0, num_vertices
* sizeof(GLfloat
) * 4, _
))
1741 .RetiresOnSaturation();
1742 EXPECT_CALL(*gl_
, VertexAttribPointer(0, 4, GL_FLOAT
, GL_FALSE
, 0, NULL
))
1744 .RetiresOnSaturation();
1745 EXPECT_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, buffer_id
))
1747 .RetiresOnSaturation();
1751 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0(
1752 GLsizei num_vertices
, GLuint buffer_id
) {
1753 AddExpectationsForSimulatedAttrib0WithError(
1754 num_vertices
, buffer_id
, GL_NO_ERROR
);
1757 void GLES2DecoderTestBase::SetupMockGLBehaviors() {
1758 ON_CALL(*gl_
, BindVertexArrayOES(_
))
1759 .WillByDefault(Invoke(
1761 &GLES2DecoderTestBase::MockGLStates::OnBindVertexArrayOES
));
1762 ON_CALL(*gl_
, BindBuffer(GL_ARRAY_BUFFER
, _
))
1763 .WillByDefault(WithArg
<1>(Invoke(
1765 &GLES2DecoderTestBase::MockGLStates::OnBindArrayBuffer
)));
1766 ON_CALL(*gl_
, VertexAttribPointer(_
, _
, _
, _
, _
, NULL
))
1767 .WillByDefault(InvokeWithoutArgs(
1769 &GLES2DecoderTestBase::MockGLStates::OnVertexAttribNullPointer
));
1772 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1773 MockCommandBufferEngine() {
1775 scoped_ptr
<base::SharedMemory
> shm(new base::SharedMemory());
1776 shm
->CreateAndMapAnonymous(kSharedBufferSize
);
1777 valid_buffer_
= MakeBufferFromSharedMemory(shm
.Pass(), kSharedBufferSize
);
1779 ClearSharedMemory();
1782 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1783 ~MockCommandBufferEngine() {}
1785 scoped_refptr
<gpu::Buffer
>
1786 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetSharedMemoryBuffer(
1788 return shm_id
== kSharedMemoryId
? valid_buffer_
: invalid_buffer_
;
1791 void GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::set_token(
1796 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetBuffer(
1797 int32
/* transfer_buffer_id */) {
1802 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetOffset(
1808 int32
GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetGetOffset() {
1813 void GLES2DecoderWithShaderTestBase::SetUp() {
1814 GLES2DecoderTestBase::SetUp();
1815 SetupDefaultProgram();
1818 // Include the auto-generated part of this file. We split this because it means
1819 // we can easily edit the non-auto generated parts right here in this file
1820 // instead of having to edit some template or the code generator.
1821 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h"
1823 } // namespace gles2