Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_base.cc
blobd78ec9853423cbbac6591cd27b862ff17b1b78b0
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"
7 #include <algorithm>
8 #include <string>
9 #include <vector>
11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_split.h"
13 #include "gpu/command_buffer/common/gles2_cmd_format.h"
14 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
15 #include "gpu/command_buffer/common/value_state.h"
16 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
17 #include "gpu/command_buffer/service/context_group.h"
18 #include "gpu/command_buffer/service/logger.h"
19 #include "gpu/command_buffer/service/mailbox_manager.h"
20 #include "gpu/command_buffer/service/program_manager.h"
21 #include "gpu/command_buffer/service/test_helper.h"
22 #include "gpu/command_buffer/service/vertex_attrib_manager.h"
23 #include "testing/gtest/include/gtest/gtest.h"
24 #include "ui/gl/gl_implementation.h"
25 #include "ui/gl/gl_mock.h"
26 #include "ui/gl/test/gl_surface_test_support.h"
28 using ::gfx::MockGLInterface;
29 using ::testing::_;
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;
44 namespace {
46 void NormalizeInitState(gpu::gles2::GLES2DecoderTestBase::InitState* init) {
47 CHECK(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;
57 break;
61 if (init->use_native_vao) {
62 if (contains_vao_extension)
63 return;
64 if (!init->extensions.empty())
65 init->extensions += " ";
66 if (base::StartsWith(init->gl_version, "opengl es",
67 base::CompareCase::INSENSITIVE_ASCII)) {
68 init->extensions += kVAOExtensions[0];
69 } else {
70 #if !defined(OS_MACOSX)
71 init->extensions += kVAOExtensions[1];
72 #else
73 init->extensions += kVAOExtensions[2];
74 #endif // OS_MACOSX
76 } else {
77 // Make sure we don't set up an invalid InitState.
78 CHECK(!contains_vao_extension);
81 if (!init->extensions.empty())
82 init->extensions += " ";
83 init->extensions += "GL_EXT_framebuffer_object ";
86 const uint32 kMaxColorAttachments = 16;
87 const uint32 kMaxDrawBuffers = 16;
89 } // namespace Anonymous
91 namespace gpu {
92 namespace gles2 {
94 GLES2DecoderTestBase::GLES2DecoderTestBase()
95 : surface_(NULL),
96 context_(NULL),
97 memory_tracker_(NULL),
98 client_buffer_id_(100),
99 client_framebuffer_id_(101),
100 client_program_id_(102),
101 client_renderbuffer_id_(103),
102 client_sampler_id_(104),
103 client_shader_id_(105),
104 client_texture_id_(106),
105 client_element_buffer_id_(107),
106 client_vertex_shader_id_(121),
107 client_fragment_shader_id_(122),
108 client_query_id_(123),
109 client_vertexarray_id_(124),
110 client_valuebuffer_id_(125),
111 client_transformfeedback_id_(126),
112 client_sync_id_(127),
113 service_renderbuffer_id_(0),
114 service_renderbuffer_valid_(false),
115 ignore_cached_state_for_test_(GetParam()),
116 cached_color_mask_red_(true),
117 cached_color_mask_green_(true),
118 cached_color_mask_blue_(true),
119 cached_color_mask_alpha_(true),
120 cached_depth_mask_(true),
121 cached_stencil_front_mask_(static_cast<GLuint>(-1)),
122 cached_stencil_back_mask_(static_cast<GLuint>(-1)) {
123 memset(immediate_buffer_, 0xEE, sizeof(immediate_buffer_));
126 GLES2DecoderTestBase::~GLES2DecoderTestBase() {}
128 void GLES2DecoderTestBase::SetUp() {
129 InitState init;
130 // Autogenerated tests do not overwrite version or extension string,
131 // so we have to pick something that supports everything here.
132 init.gl_version = "4.4";
133 init.extensions += " GL_ARB_compatibility";
134 init.has_alpha = true;
135 init.has_depth = true;
136 init.request_alpha = true;
137 init.request_depth = true;
138 init.bind_generates_resource = true;
139 InitDecoder(init);
142 void GLES2DecoderTestBase::AddExpectationsForVertexAttribManager() {
143 for (GLint ii = 0; ii < kNumVertexAttribs; ++ii) {
144 EXPECT_CALL(*gl_, VertexAttrib4f(ii, 0.0f, 0.0f, 0.0f, 1.0f))
145 .Times(1)
146 .RetiresOnSaturation();
150 GLES2DecoderTestBase::InitState::InitState()
151 : extensions("GL_EXT_framebuffer_object"),
152 gl_version("2.1"),
153 has_alpha(false),
154 has_depth(false),
155 has_stencil(false),
156 request_alpha(false),
157 request_depth(false),
158 request_stencil(false),
159 bind_generates_resource(false),
160 lose_context_when_out_of_memory(false),
161 use_native_vao(true),
162 webgl_version(0) {
165 void GLES2DecoderTestBase::InitDecoder(const InitState& init) {
166 InitDecoderWithCommandLine(init, NULL);
169 void GLES2DecoderTestBase::InitDecoderWithCommandLine(
170 const InitState& init,
171 const base::CommandLine* command_line) {
172 InitState normalized_init = init;
173 NormalizeInitState(&normalized_init);
174 // For easier substring/extension matching
175 DCHECK(normalized_init.extensions.empty() ||
176 *normalized_init.extensions.rbegin() == ' ');
177 Framebuffer::ClearFramebufferCompleteComboMap();
179 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress);
180 gfx::GLSurfaceTestSupport::InitializeOneOffWithMockBindings();
182 gl_.reset(new StrictMock<MockGLInterface>());
183 ::gfx::MockGLInterface::SetGLInterface(gl_.get());
185 SetupMockGLBehaviors();
187 scoped_refptr<FeatureInfo> feature_info;
188 if (command_line)
189 feature_info = new FeatureInfo(*command_line);
190 group_ = scoped_refptr<ContextGroup>(
191 new ContextGroup(NULL,
192 memory_tracker_,
193 new ShaderTranslatorCache,
194 feature_info.get(),
195 new SubscriptionRefSet,
196 new ValueStateMap,
197 normalized_init.bind_generates_resource));
198 bool use_default_textures = normalized_init.bind_generates_resource;
200 InSequence sequence;
202 surface_ = new gfx::GLSurfaceStub;
203 surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight));
205 // Context needs to be created before initializing ContextGroup, which will
206 // in turn initialize FeatureInfo, which needs a context to determine
207 // extension support.
208 context_ = new StrictMock<GLContextMock>();
209 context_->AddExtensionsString(normalized_init.extensions.c_str());
210 context_->SetGLVersionString(normalized_init.gl_version.c_str());
212 context_->GLContextStubWithExtensions::MakeCurrent(surface_.get());
213 gfx::GLSurfaceTestSupport::InitializeDynamicMockBindings(context_.get());
215 TestHelper::SetupContextGroupInitExpectations(
216 gl_.get(),
217 DisallowedFeatures(),
218 normalized_init.extensions.c_str(),
219 normalized_init.gl_version.c_str(),
220 normalized_init.bind_generates_resource);
222 // We initialize the ContextGroup with a MockGLES2Decoder so that
223 // we can use the ContextGroup to figure out how the real GLES2Decoder
224 // will initialize itself.
225 mock_decoder_.reset(new MockGLES2Decoder());
227 // Install FakeDoCommands handler so we can use individual DoCommand()
228 // expectations.
229 EXPECT_CALL(*mock_decoder_, DoCommands(_, _, _, _)).WillRepeatedly(
230 Invoke(mock_decoder_.get(), &MockGLES2Decoder::FakeDoCommands));
233 EXPECT_TRUE(group_->Initialize(
234 mock_decoder_.get(),
235 ContextGroup::GetContextType(init.webgl_version),
236 DisallowedFeatures()));
238 if (init.webgl_version == 2) {
239 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_COLOR_ATTACHMENTS, _))
240 .WillOnce(SetArgumentPointee<1>(kMaxColorAttachments))
241 .RetiresOnSaturation();
242 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_DRAW_BUFFERS, _))
243 .WillOnce(SetArgumentPointee<1>(kMaxDrawBuffers))
244 .RetiresOnSaturation();
247 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
248 EXPECT_CALL(*gl_, GenVertexArraysOES(1, _))
249 .WillOnce(SetArgumentPointee<1>(kServiceVertexArrayId))
250 .RetiresOnSaturation();
251 EXPECT_CALL(*gl_, BindVertexArrayOES(_)).Times(1).RetiresOnSaturation();
254 if (group_->feature_info()->workarounds().init_vertex_attributes)
255 AddExpectationsForVertexAttribManager();
257 AddExpectationsForBindVertexArrayOES();
259 EXPECT_CALL(*gl_, EnableVertexAttribArray(0))
260 .Times(1)
261 .RetiresOnSaturation();
262 static GLuint attrib_0_id[] = {
263 kServiceAttrib0BufferId,
265 static GLuint fixed_attrib_buffer_id[] = {
266 kServiceFixedAttribBufferId,
268 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(attrib_0_id), _))
269 .WillOnce(SetArrayArgument<1>(attrib_0_id,
270 attrib_0_id + arraysize(attrib_0_id)))
271 .RetiresOnSaturation();
272 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
273 .Times(1)
274 .RetiresOnSaturation();
275 EXPECT_CALL(*gl_, VertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL))
276 .Times(1)
277 .RetiresOnSaturation();
278 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
279 .Times(1)
280 .RetiresOnSaturation();
281 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(fixed_attrib_buffer_id), _))
282 .WillOnce(SetArrayArgument<1>(
283 fixed_attrib_buffer_id,
284 fixed_attrib_buffer_id + arraysize(fixed_attrib_buffer_id)))
285 .RetiresOnSaturation();
287 for (GLint tt = 0; tt < TestHelper::kNumTextureUnits; ++tt) {
288 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0 + tt))
289 .Times(1)
290 .RetiresOnSaturation();
291 if (group_->feature_info()->feature_flags().oes_egl_image_external) {
292 EXPECT_CALL(*gl_,
293 BindTexture(GL_TEXTURE_EXTERNAL_OES,
294 use_default_textures
295 ? TestHelper::kServiceDefaultExternalTextureId
296 : 0))
297 .Times(1)
298 .RetiresOnSaturation();
300 if (group_->feature_info()->feature_flags().arb_texture_rectangle) {
301 EXPECT_CALL(
302 *gl_,
303 BindTexture(GL_TEXTURE_RECTANGLE_ARB,
304 use_default_textures
305 ? TestHelper::kServiceDefaultRectangleTextureId
306 : 0))
307 .Times(1)
308 .RetiresOnSaturation();
310 EXPECT_CALL(*gl_,
311 BindTexture(GL_TEXTURE_CUBE_MAP,
312 use_default_textures
313 ? TestHelper::kServiceDefaultTextureCubemapId
314 : 0))
315 .Times(1)
316 .RetiresOnSaturation();
317 EXPECT_CALL(
318 *gl_,
319 BindTexture(
320 GL_TEXTURE_2D,
321 use_default_textures ? TestHelper::kServiceDefaultTexture2dId : 0))
322 .Times(1)
323 .RetiresOnSaturation();
325 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
326 .Times(1)
327 .RetiresOnSaturation();
329 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
330 .Times(1)
331 .RetiresOnSaturation();
332 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _))
333 .WillOnce(SetArgumentPointee<1>(normalized_init.has_alpha ? 8 : 0))
334 .RetiresOnSaturation();
335 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
336 .WillOnce(SetArgumentPointee<1>(normalized_init.has_depth ? 24 : 0))
337 .RetiresOnSaturation();
338 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
339 .WillOnce(SetArgumentPointee<1>(normalized_init.has_stencil ? 8 : 0))
340 .RetiresOnSaturation();
342 if (!group_->feature_info()->gl_version_info().BehavesLikeGLES()) {
343 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE))
344 .Times(1)
345 .RetiresOnSaturation();
347 EXPECT_CALL(*gl_, Enable(GL_POINT_SPRITE))
348 .Times(1)
349 .RetiresOnSaturation();
352 static GLint max_viewport_dims[] = {
353 kMaxViewportWidth,
354 kMaxViewportHeight
356 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VIEWPORT_DIMS, _))
357 .WillOnce(SetArrayArgument<1>(
358 max_viewport_dims, max_viewport_dims + arraysize(max_viewport_dims)))
359 .RetiresOnSaturation();
361 SetupInitCapabilitiesExpectations(group_->feature_info()->IsES3Capable());
362 SetupInitStateExpectations();
364 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
365 .Times(1)
366 .RetiresOnSaturation();
368 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
369 .Times(1)
370 .RetiresOnSaturation();
371 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0))
372 .Times(1)
373 .RetiresOnSaturation();
374 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
375 .Times(1)
376 .RetiresOnSaturation();
377 EXPECT_CALL(*gl_, BindRenderbufferEXT(GL_RENDERBUFFER, 0))
378 .Times(1)
379 .RetiresOnSaturation();
381 // TODO(boliu): Remove OS_ANDROID once crbug.com/259023 is fixed and the
382 // workaround has been reverted.
383 #if !defined(OS_ANDROID)
384 if (normalized_init.has_alpha && !normalized_init.request_alpha) {
385 EXPECT_CALL(*gl_, ClearColor(0, 0, 0, 1)).Times(1).RetiresOnSaturation();
388 EXPECT_CALL(*gl_, Clear(
389 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
390 .Times(1)
391 .RetiresOnSaturation();
393 if (normalized_init.has_alpha && !normalized_init.request_alpha) {
394 EXPECT_CALL(*gl_, ClearColor(0, 0, 0, 0)).Times(1).RetiresOnSaturation();
396 #endif
398 engine_.reset(new StrictMock<MockCommandBufferEngine>());
399 scoped_refptr<gpu::Buffer> buffer =
400 engine_->GetSharedMemoryBuffer(kSharedMemoryId);
401 shared_memory_offset_ = kSharedMemoryOffset;
402 shared_memory_address_ =
403 reinterpret_cast<int8*>(buffer->memory()) + shared_memory_offset_;
404 shared_memory_id_ = kSharedMemoryId;
405 shared_memory_base_ = buffer->memory();
407 static const int32 kLoseContextWhenOutOfMemory = 0x10002;
408 static const int32 kWebGLVersion = 0x10003;
410 int32 attributes[] = {
411 EGL_ALPHA_SIZE,
412 normalized_init.request_alpha ? 8 : 0,
413 EGL_DEPTH_SIZE,
414 normalized_init.request_depth ? 24 : 0,
415 EGL_STENCIL_SIZE,
416 normalized_init.request_stencil ? 8 : 0,
417 kLoseContextWhenOutOfMemory,
418 normalized_init.lose_context_when_out_of_memory ? 1 : 0,
419 kWebGLVersion,
420 init.webgl_version
422 std::vector<int32> attribs(attributes, attributes + arraysize(attributes));
424 decoder_.reset(GLES2Decoder::Create(group_.get()));
425 decoder_->SetIgnoreCachedStateForTest(ignore_cached_state_for_test_);
426 decoder_->GetLogger()->set_log_synthesized_gl_errors(false);
427 decoder_->Initialize(surface_,
428 context_,
429 false,
430 surface_->GetSize(),
431 DisallowedFeatures(),
432 attribs);
433 EXPECT_CALL(*context_, MakeCurrent(surface_.get())).WillOnce(Return(true));
434 if (context_->WasAllocatedUsingRobustnessExtension()) {
435 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB())
436 .WillOnce(Return(GL_NO_ERROR));
438 decoder_->MakeCurrent();
439 decoder_->set_engine(engine_.get());
440 decoder_->BeginDecoding();
442 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
443 .WillOnce(SetArgumentPointee<1>(kServiceBufferId))
444 .RetiresOnSaturation();
445 GenHelper<cmds::GenBuffersImmediate>(client_buffer_id_);
446 EXPECT_CALL(*gl_, GenFramebuffersEXT(_, _))
447 .WillOnce(SetArgumentPointee<1>(kServiceFramebufferId))
448 .RetiresOnSaturation();
449 GenHelper<cmds::GenFramebuffersImmediate>(client_framebuffer_id_);
450 EXPECT_CALL(*gl_, GenRenderbuffersEXT(_, _))
451 .WillOnce(SetArgumentPointee<1>(kServiceRenderbufferId))
452 .RetiresOnSaturation();
453 GenHelper<cmds::GenRenderbuffersImmediate>(client_renderbuffer_id_);
454 EXPECT_CALL(*gl_, GenTextures(_, _))
455 .WillOnce(SetArgumentPointee<1>(kServiceTextureId))
456 .RetiresOnSaturation();
457 GenHelper<cmds::GenTexturesImmediate>(client_texture_id_);
458 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
459 .WillOnce(SetArgumentPointee<1>(kServiceElementBufferId))
460 .RetiresOnSaturation();
461 GenHelper<cmds::GenBuffersImmediate>(client_element_buffer_id_);
463 DoCreateProgram(client_program_id_, kServiceProgramId);
464 DoCreateShader(GL_VERTEX_SHADER, client_shader_id_, kServiceShaderId);
466 // Unsafe commands.
467 bool reset_unsafe_es3_apis_enabled = false;
468 if (!decoder_->unsafe_es3_apis_enabled()) {
469 decoder_->set_unsafe_es3_apis_enabled(true);
470 reset_unsafe_es3_apis_enabled = true;
473 const gfx::GLVersionInfo* version = context_->GetVersionInfo();
474 if (version->IsAtLeastGL(3, 3) || version->IsAtLeastGLES(3, 0)) {
475 EXPECT_CALL(*gl_, GenSamplers(_, _))
476 .WillOnce(SetArgumentPointee<1>(kServiceSamplerId))
477 .RetiresOnSaturation();
478 GenHelper<cmds::GenSamplersImmediate>(client_sampler_id_);
480 if (version->IsAtLeastGL(4, 0) || version->IsAtLeastGLES(3, 0)) {
481 EXPECT_CALL(*gl_, GenTransformFeedbacks(_, _))
482 .WillOnce(SetArgumentPointee<1>(kServiceTransformFeedbackId))
483 .RetiresOnSaturation();
484 GenHelper<cmds::GenTransformFeedbacksImmediate>(
485 client_transformfeedback_id_);
488 if (init.extensions.find("GL_ARB_sync ") != std::string::npos ||
489 version->IsAtLeastGL(3, 2) || version->IsAtLeastGLES(3, 0)) {
490 DoFenceSync(client_sync_id_, kServiceSyncId);
493 if (reset_unsafe_es3_apis_enabled) {
494 decoder_->set_unsafe_es3_apis_enabled(false);
497 EXPECT_EQ(GL_NO_ERROR, GetGLError());
500 void GLES2DecoderTestBase::ResetDecoder() {
501 if (!decoder_.get())
502 return;
503 // All Tests should have read all their GLErrors before getting here.
504 EXPECT_EQ(GL_NO_ERROR, GetGLError());
506 EXPECT_CALL(*gl_, DeleteBuffersARB(1, _))
507 .Times(2)
508 .RetiresOnSaturation();
509 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
510 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, Pointee(kServiceVertexArrayId)))
511 .Times(1)
512 .RetiresOnSaturation();
515 decoder_->EndDecoding();
516 decoder_->Destroy(true);
517 decoder_.reset();
518 group_->Destroy(mock_decoder_.get(), false);
519 engine_.reset();
520 ::gfx::MockGLInterface::SetGLInterface(NULL);
521 gl_.reset();
522 gfx::ClearGLBindings();
525 void GLES2DecoderTestBase::TearDown() {
526 ResetDecoder();
529 void GLES2DecoderTestBase::ExpectEnableDisable(GLenum cap, bool enable) {
530 if (enable) {
531 EXPECT_CALL(*gl_, Enable(cap))
532 .Times(1)
533 .RetiresOnSaturation();
534 } else {
535 EXPECT_CALL(*gl_, Disable(cap))
536 .Times(1)
537 .RetiresOnSaturation();
542 GLint GLES2DecoderTestBase::GetGLError() {
543 EXPECT_CALL(*gl_, GetError())
544 .WillOnce(Return(GL_NO_ERROR))
545 .RetiresOnSaturation();
546 cmds::GetError cmd;
547 cmd.Init(shared_memory_id_, shared_memory_offset_);
548 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
549 return static_cast<GLint>(*GetSharedMemoryAs<GLenum*>());
552 void GLES2DecoderTestBase::DoCreateShader(
553 GLenum shader_type, GLuint client_id, GLuint service_id) {
554 EXPECT_CALL(*gl_, CreateShader(shader_type))
555 .Times(1)
556 .WillOnce(Return(service_id))
557 .RetiresOnSaturation();
558 cmds::CreateShader cmd;
559 cmd.Init(shader_type, client_id);
560 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
563 bool GLES2DecoderTestBase::DoIsShader(GLuint client_id) {
564 return IsObjectHelper<cmds::IsShader, cmds::IsShader::Result>(client_id);
567 void GLES2DecoderTestBase::DoDeleteShader(
568 GLuint client_id, GLuint service_id) {
569 EXPECT_CALL(*gl_, DeleteShader(service_id))
570 .Times(1)
571 .RetiresOnSaturation();
572 cmds::DeleteShader cmd;
573 cmd.Init(client_id);
574 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
577 void GLES2DecoderTestBase::DoCreateProgram(
578 GLuint client_id, GLuint service_id) {
579 EXPECT_CALL(*gl_, CreateProgram())
580 .Times(1)
581 .WillOnce(Return(service_id))
582 .RetiresOnSaturation();
583 cmds::CreateProgram cmd;
584 cmd.Init(client_id);
585 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
588 bool GLES2DecoderTestBase::DoIsProgram(GLuint client_id) {
589 return IsObjectHelper<cmds::IsProgram, cmds::IsProgram::Result>(client_id);
592 void GLES2DecoderTestBase::DoDeleteProgram(
593 GLuint client_id, GLuint /* service_id */) {
594 cmds::DeleteProgram cmd;
595 cmd.Init(client_id);
596 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
599 void GLES2DecoderTestBase::DoFenceSync(
600 GLuint client_id, GLuint service_id) {
601 EXPECT_CALL(*gl_, FenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0))
602 .Times(1)
603 .WillOnce(Return(reinterpret_cast<GLsync>(service_id)))
604 .RetiresOnSaturation();
605 cmds::FenceSync cmd;
606 cmd.Init(client_id);
607 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
610 void GLES2DecoderTestBase::SetBucketData(
611 uint32_t bucket_id, const void* data, uint32_t data_size) {
612 DCHECK(data || data_size == 0);
613 cmd::SetBucketSize cmd1;
614 cmd1.Init(bucket_id, data_size);
615 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
616 if (data) {
617 memcpy(shared_memory_address_, data, data_size);
618 cmd::SetBucketData cmd2;
619 cmd2.Init(bucket_id, 0, data_size, kSharedMemoryId, kSharedMemoryOffset);
620 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
621 ClearSharedMemory();
625 void GLES2DecoderTestBase::SetBucketAsCString(
626 uint32 bucket_id, const char* str) {
627 SetBucketData(bucket_id, str, str ? (strlen(str) + 1) : 0);
630 void GLES2DecoderTestBase::SetBucketAsCStrings(
631 uint32 bucket_id, GLsizei count, const char** str,
632 GLsizei count_in_header, char str_end) {
633 uint32_t header_size = sizeof(GLint) * (count + 1);
634 uint32_t total_size = header_size;
635 scoped_ptr<GLint[]> header(new GLint[count + 1]);
636 header[0] = static_cast<GLint>(count_in_header);
637 for (GLsizei ii = 0; ii < count; ++ii) {
638 header[ii + 1] = str && str[ii] ? strlen(str[ii]) : 0;
639 total_size += header[ii + 1] + 1;
641 cmd::SetBucketSize cmd1;
642 cmd1.Init(bucket_id, total_size);
643 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
644 memcpy(shared_memory_address_, header.get(), header_size);
645 uint32_t offset = header_size;
646 for (GLsizei ii = 0; ii < count; ++ii) {
647 if (str && str[ii]) {
648 size_t str_len = strlen(str[ii]);
649 memcpy(reinterpret_cast<char*>(shared_memory_address_) + offset,
650 str[ii], str_len);
651 offset += str_len;
653 memcpy(reinterpret_cast<char*>(shared_memory_address_) + offset,
654 &str_end, 1);
655 offset += 1;
657 cmd::SetBucketData cmd2;
658 cmd2.Init(bucket_id, 0, total_size, kSharedMemoryId, kSharedMemoryOffset);
659 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
660 ClearSharedMemory();
663 void GLES2DecoderTestBase::SetupClearTextureExpectations(GLuint service_id,
664 GLuint old_service_id,
665 GLenum bind_target,
666 GLenum target,
667 GLint level,
668 GLenum internal_format,
669 GLenum format,
670 GLenum type,
671 GLint xoffset,
672 GLint yoffset,
673 GLsizei width,
674 GLsizei height) {
675 EXPECT_CALL(*gl_, BindTexture(bind_target, service_id))
676 .Times(1)
677 .RetiresOnSaturation();
678 EXPECT_CALL(*gl_, TexSubImage2D(target, level, xoffset, yoffset, width,
679 height, format, type, _))
680 .Times(1)
681 .RetiresOnSaturation();
682 EXPECT_CALL(*gl_, BindTexture(bind_target, old_service_id))
683 .Times(1)
684 .RetiresOnSaturation();
687 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearing(
688 GLenum target,
689 GLuint clear_bits,
690 GLclampf restore_red,
691 GLclampf restore_green,
692 GLclampf restore_blue,
693 GLclampf restore_alpha,
694 GLuint restore_stencil,
695 GLclampf restore_depth,
696 bool restore_scissor_test,
697 GLint restore_scissor_x,
698 GLint restore_scissor_y,
699 GLsizei restore_scissor_width,
700 GLsizei restore_scissor_height) {
701 SetupExpectationsForFramebufferClearingMulti(
702 0, 0, target, clear_bits, restore_red, restore_green, restore_blue,
703 restore_alpha, restore_stencil, restore_depth, restore_scissor_test,
704 restore_scissor_x, restore_scissor_y, restore_scissor_width,
705 restore_scissor_height);
708 void GLES2DecoderTestBase::SetupExpectationsForRestoreClearState(
709 GLclampf restore_red,
710 GLclampf restore_green,
711 GLclampf restore_blue,
712 GLclampf restore_alpha,
713 GLuint restore_stencil,
714 GLclampf restore_depth,
715 bool restore_scissor_test,
716 GLint restore_scissor_x,
717 GLint restore_scissor_y,
718 GLsizei restore_scissor_width,
719 GLsizei restore_scissor_height) {
720 EXPECT_CALL(*gl_, ClearColor(
721 restore_red, restore_green, restore_blue, restore_alpha))
722 .Times(1)
723 .RetiresOnSaturation();
724 EXPECT_CALL(*gl_, ClearStencil(restore_stencil))
725 .Times(1)
726 .RetiresOnSaturation();
727 EXPECT_CALL(*gl_, ClearDepth(restore_depth))
728 .Times(1)
729 .RetiresOnSaturation();
730 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST, restore_scissor_test);
731 EXPECT_CALL(*gl_, Scissor(restore_scissor_x, restore_scissor_y,
732 restore_scissor_width, restore_scissor_height))
733 .Times(1)
734 .RetiresOnSaturation();
737 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearingMulti(
738 GLuint read_framebuffer_service_id,
739 GLuint draw_framebuffer_service_id,
740 GLenum target,
741 GLuint clear_bits,
742 GLclampf restore_red,
743 GLclampf restore_green,
744 GLclampf restore_blue,
745 GLclampf restore_alpha,
746 GLuint restore_stencil,
747 GLclampf restore_depth,
748 bool restore_scissor_test,
749 GLint restore_scissor_x,
750 GLint restore_scissor_y,
751 GLsizei restore_scissor_width,
752 GLsizei restore_scissor_height) {
753 // TODO(gman): Figure out why InSequence stopped working.
754 // InSequence sequence;
755 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(target))
756 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
757 .RetiresOnSaturation();
758 if (target == GL_READ_FRAMEBUFFER_EXT) {
759 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0))
760 .Times(1)
761 .RetiresOnSaturation();
762 EXPECT_CALL(*gl_, BindFramebufferEXT(
763 GL_DRAW_FRAMEBUFFER_EXT, read_framebuffer_service_id))
764 .Times(1)
765 .RetiresOnSaturation();
767 if ((clear_bits & GL_COLOR_BUFFER_BIT) != 0) {
768 EXPECT_CALL(*gl_, ClearColor(0.0f, 0.0f, 0.0f, 0.0f))
769 .Times(1)
770 .RetiresOnSaturation();
771 SetupExpectationsForColorMask(true, true, true, true);
773 if ((clear_bits & GL_STENCIL_BUFFER_BIT) != 0) {
774 EXPECT_CALL(*gl_, ClearStencil(0))
775 .Times(1)
776 .RetiresOnSaturation();
777 EXPECT_CALL(*gl_, StencilMask(static_cast<GLuint>(-1)))
778 .Times(1)
779 .RetiresOnSaturation();
781 if ((clear_bits & GL_DEPTH_BUFFER_BIT) != 0) {
782 EXPECT_CALL(*gl_, ClearDepth(1.0f))
783 .Times(1)
784 .RetiresOnSaturation();
785 SetupExpectationsForDepthMask(true);
787 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST, false);
788 EXPECT_CALL(*gl_, Clear(clear_bits))
789 .Times(1)
790 .RetiresOnSaturation();
791 SetupExpectationsForRestoreClearState(
792 restore_red, restore_green, restore_blue, restore_alpha, restore_stencil,
793 restore_depth, restore_scissor_test, restore_scissor_x, restore_scissor_y,
794 restore_scissor_width, restore_scissor_height);
795 if (target == GL_READ_FRAMEBUFFER_EXT) {
796 EXPECT_CALL(*gl_, BindFramebufferEXT(
797 GL_READ_FRAMEBUFFER_EXT, read_framebuffer_service_id))
798 .Times(1)
799 .RetiresOnSaturation();
800 EXPECT_CALL(*gl_, BindFramebufferEXT(
801 GL_DRAW_FRAMEBUFFER_EXT, draw_framebuffer_service_id))
802 .Times(1)
803 .RetiresOnSaturation();
807 void GLES2DecoderTestBase::SetupShaderForUniform(GLenum uniform_type) {
808 static AttribInfo attribs[] = {
809 { "foo", 1, GL_FLOAT, 1, },
810 { "goo", 1, GL_FLOAT, 2, },
812 UniformInfo uniforms[] = {
813 { "bar", 1, uniform_type, 0, 2, -1, },
814 { "car", 4, uniform_type, 1, 1, -1, },
816 const GLuint kClientVertexShaderId = 5001;
817 const GLuint kServiceVertexShaderId = 6001;
818 const GLuint kClientFragmentShaderId = 5002;
819 const GLuint kServiceFragmentShaderId = 6002;
820 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
821 client_program_id_, kServiceProgramId,
822 kClientVertexShaderId, kServiceVertexShaderId,
823 kClientFragmentShaderId, kServiceFragmentShaderId);
825 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
826 .Times(1)
827 .RetiresOnSaturation();
828 cmds::UseProgram cmd;
829 cmd.Init(client_program_id_);
830 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
833 void GLES2DecoderTestBase::DoBindBuffer(
834 GLenum target, GLuint client_id, GLuint service_id) {
835 EXPECT_CALL(*gl_, BindBuffer(target, service_id))
836 .Times(1)
837 .RetiresOnSaturation();
838 cmds::BindBuffer cmd;
839 cmd.Init(target, client_id);
840 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
843 bool GLES2DecoderTestBase::DoIsBuffer(GLuint client_id) {
844 return IsObjectHelper<cmds::IsBuffer, cmds::IsBuffer::Result>(client_id);
847 void GLES2DecoderTestBase::DoDeleteBuffer(
848 GLuint client_id, GLuint service_id) {
849 EXPECT_CALL(*gl_, DeleteBuffersARB(1, Pointee(service_id)))
850 .Times(1)
851 .RetiresOnSaturation();
852 GenHelper<cmds::DeleteBuffersImmediate>(client_id);
855 void GLES2DecoderTestBase::SetupExpectationsForColorMask(bool red,
856 bool green,
857 bool blue,
858 bool alpha) {
859 if (ignore_cached_state_for_test_ || cached_color_mask_red_ != red ||
860 cached_color_mask_green_ != green || cached_color_mask_blue_ != blue ||
861 cached_color_mask_alpha_ != alpha) {
862 cached_color_mask_red_ = red;
863 cached_color_mask_green_ = green;
864 cached_color_mask_blue_ = blue;
865 cached_color_mask_alpha_ = alpha;
866 EXPECT_CALL(*gl_, ColorMask(red, green, blue, alpha))
867 .Times(1)
868 .RetiresOnSaturation();
872 void GLES2DecoderTestBase::SetupExpectationsForDepthMask(bool mask) {
873 if (ignore_cached_state_for_test_ || cached_depth_mask_ != mask) {
874 cached_depth_mask_ = mask;
875 EXPECT_CALL(*gl_, DepthMask(mask)).Times(1).RetiresOnSaturation();
879 void GLES2DecoderTestBase::SetupExpectationsForStencilMask(GLuint front_mask,
880 GLuint back_mask) {
881 if (ignore_cached_state_for_test_ ||
882 cached_stencil_front_mask_ != front_mask) {
883 cached_stencil_front_mask_ = front_mask;
884 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_FRONT, front_mask))
885 .Times(1)
886 .RetiresOnSaturation();
889 if (ignore_cached_state_for_test_ ||
890 cached_stencil_back_mask_ != back_mask) {
891 cached_stencil_back_mask_ = back_mask;
892 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_BACK, back_mask))
893 .Times(1)
894 .RetiresOnSaturation();
898 void GLES2DecoderTestBase::SetupExpectationsForEnableDisable(GLenum cap,
899 bool enable) {
900 switch (cap) {
901 case GL_BLEND:
902 if (enable_flags_.cached_blend == enable &&
903 !ignore_cached_state_for_test_)
904 return;
905 enable_flags_.cached_blend = enable;
906 break;
907 case GL_CULL_FACE:
908 if (enable_flags_.cached_cull_face == enable &&
909 !ignore_cached_state_for_test_)
910 return;
911 enable_flags_.cached_cull_face = enable;
912 break;
913 case GL_DEPTH_TEST:
914 if (enable_flags_.cached_depth_test == enable &&
915 !ignore_cached_state_for_test_)
916 return;
917 enable_flags_.cached_depth_test = enable;
918 break;
919 case GL_DITHER:
920 if (enable_flags_.cached_dither == enable &&
921 !ignore_cached_state_for_test_)
922 return;
923 enable_flags_.cached_dither = enable;
924 break;
925 case GL_POLYGON_OFFSET_FILL:
926 if (enable_flags_.cached_polygon_offset_fill == enable &&
927 !ignore_cached_state_for_test_)
928 return;
929 enable_flags_.cached_polygon_offset_fill = enable;
930 break;
931 case GL_SAMPLE_ALPHA_TO_COVERAGE:
932 if (enable_flags_.cached_sample_alpha_to_coverage == enable &&
933 !ignore_cached_state_for_test_)
934 return;
935 enable_flags_.cached_sample_alpha_to_coverage = enable;
936 break;
937 case GL_SAMPLE_COVERAGE:
938 if (enable_flags_.cached_sample_coverage == enable &&
939 !ignore_cached_state_for_test_)
940 return;
941 enable_flags_.cached_sample_coverage = enable;
942 break;
943 case GL_SCISSOR_TEST:
944 if (enable_flags_.cached_scissor_test == enable &&
945 !ignore_cached_state_for_test_)
946 return;
947 enable_flags_.cached_scissor_test = enable;
948 break;
949 case GL_STENCIL_TEST:
950 if (enable_flags_.cached_stencil_test == enable &&
951 !ignore_cached_state_for_test_)
952 return;
953 enable_flags_.cached_stencil_test = enable;
954 break;
955 default:
956 NOTREACHED();
957 return;
959 if (enable) {
960 EXPECT_CALL(*gl_, Enable(cap)).Times(1).RetiresOnSaturation();
961 } else {
962 EXPECT_CALL(*gl_, Disable(cap)).Times(1).RetiresOnSaturation();
966 void GLES2DecoderTestBase::SetupExpectationsForApplyingDirtyState(
967 bool framebuffer_is_rgb,
968 bool framebuffer_has_depth,
969 bool framebuffer_has_stencil,
970 GLuint color_bits,
971 bool depth_mask,
972 bool depth_enabled,
973 GLuint front_stencil_mask,
974 GLuint back_stencil_mask,
975 bool stencil_enabled) {
976 bool color_mask_red = (color_bits & 0x1000) != 0;
977 bool color_mask_green = (color_bits & 0x0100) != 0;
978 bool color_mask_blue = (color_bits & 0x0010) != 0;
979 bool color_mask_alpha = (color_bits & 0x0001) && !framebuffer_is_rgb;
981 SetupExpectationsForColorMask(
982 color_mask_red, color_mask_green, color_mask_blue, color_mask_alpha);
983 SetupExpectationsForDepthMask(depth_mask);
984 SetupExpectationsForStencilMask(front_stencil_mask, back_stencil_mask);
985 SetupExpectationsForEnableDisable(GL_DEPTH_TEST,
986 framebuffer_has_depth && depth_enabled);
987 SetupExpectationsForEnableDisable(GL_STENCIL_TEST,
988 framebuffer_has_stencil && stencil_enabled);
991 void GLES2DecoderTestBase::SetupExpectationsForApplyingDefaultDirtyState() {
992 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
993 false, // Framebuffer has depth
994 false, // Framebuffer has stencil
995 0x1111, // color bits
996 true, // depth mask
997 false, // depth enabled
998 0, // front stencil mask
999 0, // back stencil mask
1000 false); // stencil enabled
1003 GLES2DecoderTestBase::EnableFlags::EnableFlags()
1004 : cached_blend(false),
1005 cached_cull_face(false),
1006 cached_depth_test(false),
1007 cached_dither(true),
1008 cached_polygon_offset_fill(false),
1009 cached_sample_alpha_to_coverage(false),
1010 cached_sample_coverage(false),
1011 cached_scissor_test(false),
1012 cached_stencil_test(false) {
1015 void GLES2DecoderTestBase::DoBindFramebuffer(
1016 GLenum target, GLuint client_id, GLuint service_id) {
1017 EXPECT_CALL(*gl_, BindFramebufferEXT(target, service_id))
1018 .Times(1)
1019 .RetiresOnSaturation();
1020 cmds::BindFramebuffer cmd;
1021 cmd.Init(target, client_id);
1022 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1025 bool GLES2DecoderTestBase::DoIsFramebuffer(GLuint client_id) {
1026 return IsObjectHelper<cmds::IsFramebuffer, cmds::IsFramebuffer::Result>(
1027 client_id);
1030 void GLES2DecoderTestBase::DoDeleteFramebuffer(
1031 GLuint client_id, GLuint service_id,
1032 bool reset_draw, GLenum draw_target, GLuint draw_id,
1033 bool reset_read, GLenum read_target, GLuint read_id) {
1034 if (reset_draw) {
1035 EXPECT_CALL(*gl_, BindFramebufferEXT(draw_target, draw_id))
1036 .Times(1)
1037 .RetiresOnSaturation();
1039 if (reset_read) {
1040 EXPECT_CALL(*gl_, BindFramebufferEXT(read_target, read_id))
1041 .Times(1)
1042 .RetiresOnSaturation();
1044 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, Pointee(service_id)))
1045 .Times(1)
1046 .RetiresOnSaturation();
1047 GenHelper<cmds::DeleteFramebuffersImmediate>(client_id);
1050 void GLES2DecoderTestBase::DoBindRenderbuffer(
1051 GLenum target, GLuint client_id, GLuint service_id) {
1052 service_renderbuffer_id_ = service_id;
1053 service_renderbuffer_valid_ = true;
1054 EXPECT_CALL(*gl_, BindRenderbufferEXT(target, service_id))
1055 .Times(1)
1056 .RetiresOnSaturation();
1057 cmds::BindRenderbuffer cmd;
1058 cmd.Init(target, client_id);
1059 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1062 void GLES2DecoderTestBase::DoRenderbufferStorageMultisampleCHROMIUM(
1063 GLenum target,
1064 GLsizei samples,
1065 GLenum internal_format,
1066 GLenum gl_format,
1067 GLsizei width,
1068 GLsizei height) {
1069 EXPECT_CALL(*gl_, GetError())
1070 .WillOnce(Return(GL_NO_ERROR))
1071 .RetiresOnSaturation();
1072 EXPECT_CALL(*gl_,
1073 RenderbufferStorageMultisampleEXT(
1074 target, samples, gl_format, width, height))
1075 .Times(1)
1076 .RetiresOnSaturation();
1077 EXPECT_CALL(*gl_, GetError())
1078 .WillOnce(Return(GL_NO_ERROR))
1079 .RetiresOnSaturation();
1080 cmds::RenderbufferStorageMultisampleCHROMIUM cmd;
1081 cmd.Init(target, samples, internal_format, width, height);
1082 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1083 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1086 void GLES2DecoderTestBase::RestoreRenderbufferBindings() {
1087 GetDecoder()->RestoreRenderbufferBindings();
1088 service_renderbuffer_valid_ = false;
1091 void GLES2DecoderTestBase::EnsureRenderbufferBound(bool expect_bind) {
1092 EXPECT_NE(expect_bind, service_renderbuffer_valid_);
1094 if (expect_bind) {
1095 service_renderbuffer_valid_ = true;
1096 EXPECT_CALL(*gl_,
1097 BindRenderbufferEXT(GL_RENDERBUFFER, service_renderbuffer_id_))
1098 .Times(1)
1099 .RetiresOnSaturation();
1100 } else {
1101 EXPECT_CALL(*gl_, BindRenderbufferEXT(_, _)).Times(0);
1105 bool GLES2DecoderTestBase::DoIsRenderbuffer(GLuint client_id) {
1106 return IsObjectHelper<cmds::IsRenderbuffer, cmds::IsRenderbuffer::Result>(
1107 client_id);
1110 void GLES2DecoderTestBase::DoDeleteRenderbuffer(
1111 GLuint client_id, GLuint service_id) {
1112 EXPECT_CALL(*gl_, DeleteRenderbuffersEXT(1, Pointee(service_id)))
1113 .Times(1)
1114 .RetiresOnSaturation();
1115 GenHelper<cmds::DeleteRenderbuffersImmediate>(client_id);
1118 void GLES2DecoderTestBase::DoBindTexture(
1119 GLenum target, GLuint client_id, GLuint service_id) {
1120 EXPECT_CALL(*gl_, BindTexture(target, service_id))
1121 .Times(1)
1122 .RetiresOnSaturation();
1123 cmds::BindTexture cmd;
1124 cmd.Init(target, client_id);
1125 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1128 bool GLES2DecoderTestBase::DoIsTexture(GLuint client_id) {
1129 return IsObjectHelper<cmds::IsTexture, cmds::IsTexture::Result>(client_id);
1132 void GLES2DecoderTestBase::DoDeleteTexture(
1133 GLuint client_id, GLuint service_id) {
1134 EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(service_id)))
1135 .Times(1)
1136 .RetiresOnSaturation();
1137 GenHelper<cmds::DeleteTexturesImmediate>(client_id);
1140 void GLES2DecoderTestBase::DoBindTexImage2DCHROMIUM(GLenum target,
1141 GLint image_id) {
1142 cmds::BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
1143 bind_tex_image_2d_cmd.Init(target, image_id);
1144 EXPECT_CALL(*gl_, GetError())
1145 .WillOnce(Return(GL_NO_ERROR))
1146 .WillOnce(Return(GL_NO_ERROR))
1147 .RetiresOnSaturation();
1148 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
1149 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1152 void GLES2DecoderTestBase::DoTexImage2D(
1153 GLenum target, GLint level, GLenum internal_format,
1154 GLsizei width, GLsizei height, GLint border,
1155 GLenum format, GLenum type,
1156 uint32 shared_memory_id, uint32 shared_memory_offset) {
1157 EXPECT_CALL(*gl_, GetError())
1158 .WillOnce(Return(GL_NO_ERROR))
1159 .RetiresOnSaturation();
1160 EXPECT_CALL(*gl_, TexImage2D(target, level, internal_format,
1161 width, height, border, format, type, _))
1162 .Times(1)
1163 .RetiresOnSaturation();
1164 EXPECT_CALL(*gl_, GetError())
1165 .WillOnce(Return(GL_NO_ERROR))
1166 .RetiresOnSaturation();
1167 cmds::TexImage2D cmd;
1168 cmd.Init(target, level, internal_format, width, height, format,
1169 type, shared_memory_id, shared_memory_offset);
1170 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1173 void GLES2DecoderTestBase::DoTexImage2DConvertInternalFormat(
1174 GLenum target, GLint level, GLenum requested_internal_format,
1175 GLsizei width, GLsizei height, GLint border,
1176 GLenum format, GLenum type,
1177 uint32 shared_memory_id, uint32 shared_memory_offset,
1178 GLenum expected_internal_format) {
1179 EXPECT_CALL(*gl_, GetError())
1180 .WillOnce(Return(GL_NO_ERROR))
1181 .RetiresOnSaturation();
1182 EXPECT_CALL(*gl_, TexImage2D(target, level, expected_internal_format,
1183 width, height, border, format, type, _))
1184 .Times(1)
1185 .RetiresOnSaturation();
1186 EXPECT_CALL(*gl_, GetError())
1187 .WillOnce(Return(GL_NO_ERROR))
1188 .RetiresOnSaturation();
1189 cmds::TexImage2D cmd;
1190 cmd.Init(target, level, requested_internal_format, width, height,
1191 format, type, shared_memory_id, shared_memory_offset);
1192 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1195 void GLES2DecoderTestBase::DoCompressedTexImage2D(
1196 GLenum target, GLint level, GLenum format,
1197 GLsizei width, GLsizei height, GLint border,
1198 GLsizei size, uint32 bucket_id) {
1199 EXPECT_CALL(*gl_, GetError())
1200 .WillOnce(Return(GL_NO_ERROR))
1201 .RetiresOnSaturation();
1202 EXPECT_CALL(*gl_, CompressedTexImage2D(
1203 target, level, format, width, height, border, size, _))
1204 .Times(1)
1205 .RetiresOnSaturation();
1206 EXPECT_CALL(*gl_, GetError())
1207 .WillOnce(Return(GL_NO_ERROR))
1208 .RetiresOnSaturation();
1209 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(bucket_id);
1210 bucket->SetSize(size);
1211 cmds::CompressedTexImage2DBucket cmd;
1212 cmd.Init(
1213 target, level, format, width, height,
1214 bucket_id);
1215 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1218 void GLES2DecoderTestBase::DoRenderbufferStorage(
1219 GLenum target, GLenum internal_format, GLenum actual_format,
1220 GLsizei width, GLsizei height, GLenum error) {
1221 EXPECT_CALL(*gl_, GetError())
1222 .WillOnce(Return(GL_NO_ERROR))
1223 .RetiresOnSaturation();
1224 EXPECT_CALL(*gl_, RenderbufferStorageEXT(
1225 target, actual_format, width, height))
1226 .Times(1)
1227 .RetiresOnSaturation();
1228 EXPECT_CALL(*gl_, GetError())
1229 .WillOnce(Return(error))
1230 .RetiresOnSaturation();
1231 cmds::RenderbufferStorage cmd;
1232 cmd.Init(target, internal_format, width, height);
1233 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1236 void GLES2DecoderTestBase::DoFramebufferTexture2D(
1237 GLenum target, GLenum attachment, GLenum textarget,
1238 GLuint texture_client_id, GLuint texture_service_id, GLint level,
1239 GLenum error) {
1240 EXPECT_CALL(*gl_, GetError())
1241 .WillOnce(Return(GL_NO_ERROR))
1242 .RetiresOnSaturation();
1243 EXPECT_CALL(*gl_, FramebufferTexture2DEXT(
1244 target, attachment, textarget, texture_service_id, level))
1245 .Times(1)
1246 .RetiresOnSaturation();
1247 EXPECT_CALL(*gl_, GetError())
1248 .WillOnce(Return(error))
1249 .RetiresOnSaturation();
1250 cmds::FramebufferTexture2D cmd;
1251 cmd.Init(target, attachment, textarget, texture_client_id);
1252 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1255 void GLES2DecoderTestBase::DoFramebufferRenderbuffer(
1256 GLenum target,
1257 GLenum attachment,
1258 GLenum renderbuffer_target,
1259 GLuint renderbuffer_client_id,
1260 GLuint renderbuffer_service_id,
1261 GLenum error) {
1262 EXPECT_CALL(*gl_, GetError())
1263 .WillOnce(Return(GL_NO_ERROR))
1264 .RetiresOnSaturation();
1265 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
1266 target, attachment, renderbuffer_target, renderbuffer_service_id))
1267 .Times(1)
1268 .RetiresOnSaturation();
1269 EXPECT_CALL(*gl_, GetError())
1270 .WillOnce(Return(error))
1271 .RetiresOnSaturation();
1272 cmds::FramebufferRenderbuffer cmd;
1273 cmd.Init(target, attachment, renderbuffer_target, renderbuffer_client_id);
1274 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1277 void GLES2DecoderTestBase::DoVertexAttribPointer(
1278 GLuint index, GLint size, GLenum type, GLsizei stride, GLuint offset) {
1279 EXPECT_CALL(*gl_,
1280 VertexAttribPointer(index, size, type, GL_FALSE, stride,
1281 BufferOffset(offset)))
1282 .Times(1)
1283 .RetiresOnSaturation();
1284 cmds::VertexAttribPointer cmd;
1285 cmd.Init(index, size, GL_FLOAT, GL_FALSE, stride, offset);
1286 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1289 void GLES2DecoderTestBase::DoVertexAttribDivisorANGLE(
1290 GLuint index, GLuint divisor) {
1291 EXPECT_CALL(*gl_,
1292 VertexAttribDivisorANGLE(index, divisor))
1293 .Times(1)
1294 .RetiresOnSaturation();
1295 cmds::VertexAttribDivisorANGLE cmd;
1296 cmd.Init(index, divisor);
1297 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1300 void GLES2DecoderTestBase::AddExpectationsForGenVertexArraysOES(){
1301 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
1302 EXPECT_CALL(*gl_, GenVertexArraysOES(1, _))
1303 .WillOnce(SetArgumentPointee<1>(kServiceVertexArrayId))
1304 .RetiresOnSaturation();
1308 void GLES2DecoderTestBase::AddExpectationsForDeleteVertexArraysOES(){
1309 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
1310 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, _))
1311 .Times(1)
1312 .RetiresOnSaturation();
1316 void GLES2DecoderTestBase::AddExpectationsForDeleteBoundVertexArraysOES() {
1317 // Expectations are the same as a delete, followed by binding VAO 0.
1318 AddExpectationsForDeleteVertexArraysOES();
1319 AddExpectationsForBindVertexArrayOES();
1322 void GLES2DecoderTestBase::AddExpectationsForBindVertexArrayOES() {
1323 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
1324 EXPECT_CALL(*gl_, BindVertexArrayOES(_))
1325 .Times(1)
1326 .RetiresOnSaturation();
1327 } else {
1328 for (uint32 vv = 0; vv < group_->max_vertex_attribs(); ++vv) {
1329 AddExpectationsForRestoreAttribState(vv);
1332 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _))
1333 .Times(1)
1334 .RetiresOnSaturation();
1338 void GLES2DecoderTestBase::AddExpectationsForRestoreAttribState(GLuint attrib) {
1339 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1340 .Times(1)
1341 .RetiresOnSaturation();
1343 EXPECT_CALL(*gl_, VertexAttribPointer(attrib, _, _, _, _, _))
1344 .Times(1)
1345 .RetiresOnSaturation();
1347 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(attrib, _))
1348 .Times(testing::AtMost(1))
1349 .RetiresOnSaturation();
1351 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1352 .Times(1)
1353 .RetiresOnSaturation();
1355 if (attrib != 0 ||
1356 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
1358 // TODO(bajones): Not sure if I can tell which of these will be called
1359 EXPECT_CALL(*gl_, EnableVertexAttribArray(attrib))
1360 .Times(testing::AtMost(1))
1361 .RetiresOnSaturation();
1363 EXPECT_CALL(*gl_, DisableVertexAttribArray(attrib))
1364 .Times(testing::AtMost(1))
1365 .RetiresOnSaturation();
1369 // GCC requires these declarations, but MSVC requires they not be present
1370 #ifndef COMPILER_MSVC
1371 const int GLES2DecoderTestBase::kBackBufferWidth;
1372 const int GLES2DecoderTestBase::kBackBufferHeight;
1374 const GLint GLES2DecoderTestBase::kMaxTextureSize;
1375 const GLint GLES2DecoderTestBase::kMaxCubeMapTextureSize;
1376 const GLint GLES2DecoderTestBase::kNumVertexAttribs;
1377 const GLint GLES2DecoderTestBase::kNumTextureUnits;
1378 const GLint GLES2DecoderTestBase::kMaxTextureImageUnits;
1379 const GLint GLES2DecoderTestBase::kMaxVertexTextureImageUnits;
1380 const GLint GLES2DecoderTestBase::kMaxFragmentUniformVectors;
1381 const GLint GLES2DecoderTestBase::kMaxVaryingVectors;
1382 const GLint GLES2DecoderTestBase::kMaxVertexUniformVectors;
1383 const GLint GLES2DecoderTestBase::kMaxViewportWidth;
1384 const GLint GLES2DecoderTestBase::kMaxViewportHeight;
1386 const GLint GLES2DecoderTestBase::kViewportX;
1387 const GLint GLES2DecoderTestBase::kViewportY;
1388 const GLint GLES2DecoderTestBase::kViewportWidth;
1389 const GLint GLES2DecoderTestBase::kViewportHeight;
1391 const GLuint GLES2DecoderTestBase::kServiceAttrib0BufferId;
1392 const GLuint GLES2DecoderTestBase::kServiceFixedAttribBufferId;
1394 const GLuint GLES2DecoderTestBase::kServiceBufferId;
1395 const GLuint GLES2DecoderTestBase::kServiceFramebufferId;
1396 const GLuint GLES2DecoderTestBase::kServiceRenderbufferId;
1397 const GLuint GLES2DecoderTestBase::kServiceSamplerId;
1398 const GLuint GLES2DecoderTestBase::kServiceTextureId;
1399 const GLuint GLES2DecoderTestBase::kServiceProgramId;
1400 const GLuint GLES2DecoderTestBase::kServiceShaderId;
1401 const GLuint GLES2DecoderTestBase::kServiceElementBufferId;
1402 const GLuint GLES2DecoderTestBase::kServiceQueryId;
1403 const GLuint GLES2DecoderTestBase::kServiceVertexArrayId;
1404 const GLuint GLES2DecoderTestBase::kServiceTransformFeedbackId;
1405 const GLuint GLES2DecoderTestBase::kServiceSyncId;
1407 const int32 GLES2DecoderTestBase::kSharedMemoryId;
1408 const size_t GLES2DecoderTestBase::kSharedBufferSize;
1409 const uint32 GLES2DecoderTestBase::kSharedMemoryOffset;
1410 const int32 GLES2DecoderTestBase::kInvalidSharedMemoryId;
1411 const uint32 GLES2DecoderTestBase::kInvalidSharedMemoryOffset;
1412 const uint32 GLES2DecoderTestBase::kInitialResult;
1413 const uint8 GLES2DecoderTestBase::kInitialMemoryValue;
1415 const uint32 GLES2DecoderTestBase::kNewClientId;
1416 const uint32 GLES2DecoderTestBase::kNewServiceId;
1417 const uint32 GLES2DecoderTestBase::kInvalidClientId;
1419 const GLuint GLES2DecoderTestBase::kServiceVertexShaderId;
1420 const GLuint GLES2DecoderTestBase::kServiceFragmentShaderId;
1422 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumShaderId;
1423 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumProgramId;
1425 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTextureBufferId;
1426 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumVertexBufferId;
1427 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumFBOId;
1428 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumPositionAttrib;
1429 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTexAttrib;
1430 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumSamplerLocation;
1432 const GLsizei GLES2DecoderTestBase::kNumVertices;
1433 const GLsizei GLES2DecoderTestBase::kNumIndices;
1434 const int GLES2DecoderTestBase::kValidIndexRangeStart;
1435 const int GLES2DecoderTestBase::kValidIndexRangeCount;
1436 const int GLES2DecoderTestBase::kInvalidIndexRangeStart;
1437 const int GLES2DecoderTestBase::kInvalidIndexRangeCount;
1438 const int GLES2DecoderTestBase::kOutOfRangeIndexRangeEnd;
1439 const GLuint GLES2DecoderTestBase::kMaxValidIndex;
1441 const GLint GLES2DecoderTestBase::kMaxAttribLength;
1442 const GLint GLES2DecoderTestBase::kAttrib1Size;
1443 const GLint GLES2DecoderTestBase::kAttrib2Size;
1444 const GLint GLES2DecoderTestBase::kAttrib3Size;
1445 const GLint GLES2DecoderTestBase::kAttrib1Location;
1446 const GLint GLES2DecoderTestBase::kAttrib2Location;
1447 const GLint GLES2DecoderTestBase::kAttrib3Location;
1448 const GLenum GLES2DecoderTestBase::kAttrib1Type;
1449 const GLenum GLES2DecoderTestBase::kAttrib2Type;
1450 const GLenum GLES2DecoderTestBase::kAttrib3Type;
1451 const GLint GLES2DecoderTestBase::kInvalidAttribLocation;
1452 const GLint GLES2DecoderTestBase::kBadAttribIndex;
1454 const GLint GLES2DecoderTestBase::kMaxUniformLength;
1455 const GLint GLES2DecoderTestBase::kUniform1Size;
1456 const GLint GLES2DecoderTestBase::kUniform2Size;
1457 const GLint GLES2DecoderTestBase::kUniform3Size;
1458 const GLint GLES2DecoderTestBase::kUniform1RealLocation;
1459 const GLint GLES2DecoderTestBase::kUniform2RealLocation;
1460 const GLint GLES2DecoderTestBase::kUniform2ElementRealLocation;
1461 const GLint GLES2DecoderTestBase::kUniform3RealLocation;
1462 const GLint GLES2DecoderTestBase::kUniform1FakeLocation;
1463 const GLint GLES2DecoderTestBase::kUniform2FakeLocation;
1464 const GLint GLES2DecoderTestBase::kUniform2ElementFakeLocation;
1465 const GLint GLES2DecoderTestBase::kUniform3FakeLocation;
1466 const GLint GLES2DecoderTestBase::kUniform1DesiredLocation;
1467 const GLint GLES2DecoderTestBase::kUniform2DesiredLocation;
1468 const GLint GLES2DecoderTestBase::kUniform3DesiredLocation;
1469 const GLenum GLES2DecoderTestBase::kUniform1Type;
1470 const GLenum GLES2DecoderTestBase::kUniform2Type;
1471 const GLenum GLES2DecoderTestBase::kUniform3Type;
1472 const GLenum GLES2DecoderTestBase::kUniformCubemapType;
1473 const GLint GLES2DecoderTestBase::kInvalidUniformLocation;
1474 const GLint GLES2DecoderTestBase::kBadUniformIndex;
1476 #endif
1478 const char* GLES2DecoderTestBase::kAttrib1Name = "attrib1";
1479 const char* GLES2DecoderTestBase::kAttrib2Name = "attrib2";
1480 const char* GLES2DecoderTestBase::kAttrib3Name = "attrib3";
1481 const char* GLES2DecoderTestBase::kUniform1Name = "uniform1";
1482 const char* GLES2DecoderTestBase::kUniform2Name = "uniform2[0]";
1483 const char* GLES2DecoderTestBase::kUniform3Name = "uniform3[0]";
1485 void GLES2DecoderTestBase::SetupDefaultProgram() {
1487 static AttribInfo attribs[] = {
1488 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1489 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1490 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1492 static UniformInfo uniforms[] = {
1493 { kUniform1Name, kUniform1Size, kUniform1Type,
1494 kUniform1FakeLocation, kUniform1RealLocation,
1495 kUniform1DesiredLocation },
1496 { kUniform2Name, kUniform2Size, kUniform2Type,
1497 kUniform2FakeLocation, kUniform2RealLocation,
1498 kUniform2DesiredLocation },
1499 { kUniform3Name, kUniform3Size, kUniform3Type,
1500 kUniform3FakeLocation, kUniform3RealLocation,
1501 kUniform3DesiredLocation },
1503 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1504 client_program_id_, kServiceProgramId,
1505 client_vertex_shader_id_, kServiceVertexShaderId,
1506 client_fragment_shader_id_, kServiceFragmentShaderId);
1510 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1511 .Times(1)
1512 .RetiresOnSaturation();
1513 cmds::UseProgram cmd;
1514 cmd.Init(client_program_id_);
1515 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1519 void GLES2DecoderTestBase::SetupCubemapProgram() {
1521 static AttribInfo attribs[] = {
1522 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1523 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1524 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1526 static UniformInfo uniforms[] = {
1527 { kUniform1Name, kUniform1Size, kUniformCubemapType,
1528 kUniform1FakeLocation, kUniform1RealLocation,
1529 kUniform1DesiredLocation, },
1530 { kUniform2Name, kUniform2Size, kUniform2Type,
1531 kUniform2FakeLocation, kUniform2RealLocation,
1532 kUniform2DesiredLocation, },
1533 { kUniform3Name, kUniform3Size, kUniform3Type,
1534 kUniform3FakeLocation, kUniform3RealLocation,
1535 kUniform3DesiredLocation, },
1537 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1538 client_program_id_, kServiceProgramId,
1539 client_vertex_shader_id_, kServiceVertexShaderId,
1540 client_fragment_shader_id_, kServiceFragmentShaderId);
1544 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1545 .Times(1)
1546 .RetiresOnSaturation();
1547 cmds::UseProgram cmd;
1548 cmd.Init(client_program_id_);
1549 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1553 void GLES2DecoderTestBase::SetupSamplerExternalProgram() {
1555 static AttribInfo attribs[] = {
1556 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1557 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1558 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1560 static UniformInfo uniforms[] = {
1561 { kUniform1Name, kUniform1Size, kUniformSamplerExternalType,
1562 kUniform1FakeLocation, kUniform1RealLocation,
1563 kUniform1DesiredLocation, },
1564 { kUniform2Name, kUniform2Size, kUniform2Type,
1565 kUniform2FakeLocation, kUniform2RealLocation,
1566 kUniform2DesiredLocation, },
1567 { kUniform3Name, kUniform3Size, kUniform3Type,
1568 kUniform3FakeLocation, kUniform3RealLocation,
1569 kUniform3DesiredLocation, },
1571 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1572 client_program_id_, kServiceProgramId,
1573 client_vertex_shader_id_, kServiceVertexShaderId,
1574 client_fragment_shader_id_, kServiceFragmentShaderId);
1578 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1579 .Times(1)
1580 .RetiresOnSaturation();
1581 cmds::UseProgram cmd;
1582 cmd.Init(client_program_id_);
1583 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1587 void GLES2DecoderWithShaderTestBase::TearDown() {
1588 GLES2DecoderTestBase::TearDown();
1591 void GLES2DecoderTestBase::SetupShader(
1592 GLES2DecoderTestBase::AttribInfo* attribs, size_t num_attribs,
1593 GLES2DecoderTestBase::UniformInfo* uniforms, size_t num_uniforms,
1594 GLuint program_client_id, GLuint program_service_id,
1595 GLuint vertex_shader_client_id, GLuint vertex_shader_service_id,
1596 GLuint fragment_shader_client_id, GLuint fragment_shader_service_id) {
1598 InSequence s;
1600 EXPECT_CALL(*gl_,
1601 AttachShader(program_service_id, vertex_shader_service_id))
1602 .Times(1)
1603 .RetiresOnSaturation();
1604 EXPECT_CALL(*gl_,
1605 AttachShader(program_service_id, fragment_shader_service_id))
1606 .Times(1)
1607 .RetiresOnSaturation();
1608 TestHelper::SetupShader(
1609 gl_.get(), attribs, num_attribs, uniforms, num_uniforms,
1610 program_service_id);
1613 DoCreateShader(
1614 GL_VERTEX_SHADER, vertex_shader_client_id, vertex_shader_service_id);
1615 DoCreateShader(
1616 GL_FRAGMENT_SHADER, fragment_shader_client_id,
1617 fragment_shader_service_id);
1619 TestHelper::SetShaderStates(
1620 gl_.get(), GetShader(vertex_shader_client_id), true);
1621 TestHelper::SetShaderStates(
1622 gl_.get(), GetShader(fragment_shader_client_id), true);
1624 cmds::AttachShader attach_cmd;
1625 attach_cmd.Init(program_client_id, vertex_shader_client_id);
1626 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1628 attach_cmd.Init(program_client_id, fragment_shader_client_id);
1629 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1631 cmds::LinkProgram link_cmd;
1632 link_cmd.Init(program_client_id);
1634 EXPECT_EQ(error::kNoError, ExecuteCmd(link_cmd));
1637 void GLES2DecoderTestBase::DoEnableDisable(GLenum cap, bool enable) {
1638 SetupExpectationsForEnableDisable(cap, enable);
1639 if (enable) {
1640 cmds::Enable cmd;
1641 cmd.Init(cap);
1642 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1643 } else {
1644 cmds::Disable cmd;
1645 cmd.Init(cap);
1646 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1650 void GLES2DecoderTestBase::DoEnableVertexAttribArray(GLint index) {
1651 EXPECT_CALL(*gl_, EnableVertexAttribArray(index))
1652 .Times(1)
1653 .RetiresOnSaturation();
1654 cmds::EnableVertexAttribArray cmd;
1655 cmd.Init(index);
1656 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1659 void GLES2DecoderTestBase::DoBufferData(GLenum target, GLsizei size) {
1660 EXPECT_CALL(*gl_, GetError())
1661 .WillOnce(Return(GL_NO_ERROR))
1662 .RetiresOnSaturation();
1663 EXPECT_CALL(*gl_, BufferData(target, size, _, GL_STREAM_DRAW))
1664 .Times(1)
1665 .RetiresOnSaturation();
1666 EXPECT_CALL(*gl_, GetError())
1667 .WillOnce(Return(GL_NO_ERROR))
1668 .RetiresOnSaturation();
1669 cmds::BufferData cmd;
1670 cmd.Init(target, size, 0, 0, GL_STREAM_DRAW);
1671 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1674 void GLES2DecoderTestBase::DoBufferSubData(
1675 GLenum target, GLint offset, GLsizei size, const void* data) {
1676 EXPECT_CALL(*gl_, BufferSubData(target, offset, size,
1677 shared_memory_address_))
1678 .Times(1)
1679 .RetiresOnSaturation();
1680 memcpy(shared_memory_address_, data, size);
1681 cmds::BufferSubData cmd;
1682 cmd.Init(target, offset, size, shared_memory_id_, shared_memory_offset_);
1683 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1686 void GLES2DecoderTestBase::DoScissor(GLint x,
1687 GLint y,
1688 GLsizei width,
1689 GLsizei height) {
1690 EXPECT_CALL(*gl_, Scissor(x, y, width, height))
1691 .Times(1)
1692 .RetiresOnSaturation();
1693 cmds::Scissor cmd;
1694 cmd.Init(x, y, width, height);
1695 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1698 void GLES2DecoderTestBase::SetupVertexBuffer() {
1699 DoEnableVertexAttribArray(1);
1700 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1701 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 2 * sizeof(GLfloat));
1704 void GLES2DecoderTestBase::SetupAllNeededVertexBuffers() {
1705 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1706 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 16 * sizeof(float));
1707 DoEnableVertexAttribArray(0);
1708 DoEnableVertexAttribArray(1);
1709 DoEnableVertexAttribArray(2);
1710 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1711 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1712 DoVertexAttribPointer(2, 2, GL_FLOAT, 0, 0);
1715 void GLES2DecoderTestBase::SetupIndexBuffer() {
1716 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
1717 client_element_buffer_id_,
1718 kServiceElementBufferId);
1719 static const GLshort indices[] = {100, 1, 2, 3, 4, 5, 6, 7, 100, 9};
1720 static_assert(arraysize(indices) == kNumIndices,
1721 "indices should have kNumIndices elements");
1722 DoBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices));
1723 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, 2, indices);
1724 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 2, sizeof(indices) - 2, &indices[1]);
1727 void GLES2DecoderTestBase::SetupTexture() {
1728 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1729 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1730 kSharedMemoryId, kSharedMemoryOffset);
1733 void GLES2DecoderTestBase::DeleteVertexBuffer() {
1734 DoDeleteBuffer(client_buffer_id_, kServiceBufferId);
1737 void GLES2DecoderTestBase::DeleteIndexBuffer() {
1738 DoDeleteBuffer(client_element_buffer_id_, kServiceElementBufferId);
1741 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0WithError(
1742 GLsizei num_vertices, GLuint buffer_id, GLenum error) {
1743 if (group_->feature_info()->gl_version_info().BehavesLikeGLES()) {
1744 return;
1747 EXPECT_CALL(*gl_, GetError())
1748 .WillOnce(Return(GL_NO_ERROR))
1749 .WillOnce(Return(error))
1750 .RetiresOnSaturation();
1751 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
1752 .Times(1)
1753 .RetiresOnSaturation();
1754 EXPECT_CALL(*gl_, BufferData(GL_ARRAY_BUFFER,
1755 num_vertices * sizeof(GLfloat) * 4,
1756 _, GL_DYNAMIC_DRAW))
1757 .Times(1)
1758 .RetiresOnSaturation();
1759 if (error == GL_NO_ERROR) {
1760 EXPECT_CALL(*gl_, BufferSubData(
1761 GL_ARRAY_BUFFER, 0, num_vertices * sizeof(GLfloat) * 4, _))
1762 .Times(1)
1763 .RetiresOnSaturation();
1764 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL))
1765 .Times(1)
1766 .RetiresOnSaturation();
1767 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, buffer_id))
1768 .Times(1)
1769 .RetiresOnSaturation();
1773 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0(
1774 GLsizei num_vertices, GLuint buffer_id) {
1775 AddExpectationsForSimulatedAttrib0WithError(
1776 num_vertices, buffer_id, GL_NO_ERROR);
1779 void GLES2DecoderTestBase::SetupMockGLBehaviors() {
1780 ON_CALL(*gl_, BindVertexArrayOES(_))
1781 .WillByDefault(Invoke(
1782 &gl_states_,
1783 &GLES2DecoderTestBase::MockGLStates::OnBindVertexArrayOES));
1784 ON_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1785 .WillByDefault(WithArg<1>(Invoke(
1786 &gl_states_,
1787 &GLES2DecoderTestBase::MockGLStates::OnBindArrayBuffer)));
1788 ON_CALL(*gl_, VertexAttribPointer(_, _, _, _, _, NULL))
1789 .WillByDefault(InvokeWithoutArgs(
1790 &gl_states_,
1791 &GLES2DecoderTestBase::MockGLStates::OnVertexAttribNullPointer));
1794 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1795 MockCommandBufferEngine() {
1797 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory());
1798 shm->CreateAndMapAnonymous(kSharedBufferSize);
1799 valid_buffer_ = MakeBufferFromSharedMemory(shm.Pass(), kSharedBufferSize);
1801 ClearSharedMemory();
1804 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1805 ~MockCommandBufferEngine() {}
1807 scoped_refptr<gpu::Buffer>
1808 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetSharedMemoryBuffer(
1809 int32 shm_id) {
1810 return shm_id == kSharedMemoryId ? valid_buffer_ : invalid_buffer_;
1813 void GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::set_token(
1814 int32 token) {
1815 DCHECK(false);
1818 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetBuffer(
1819 int32 /* transfer_buffer_id */) {
1820 DCHECK(false);
1821 return false;
1824 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetOffset(
1825 int32 offset) {
1826 DCHECK(false);
1827 return false;
1830 int32 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetGetOffset() {
1831 DCHECK(false);
1832 return 0;
1835 void GLES2DecoderWithShaderTestBase::SetUp() {
1836 GLES2DecoderTestBase::SetUp();
1837 SetupDefaultProgram();
1840 // Include the auto-generated part of this file. We split this because it means
1841 // we can easily edit the non-auto generated parts right here in this file
1842 // instead of having to edit some template or the code generator.
1843 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h"
1845 } // namespace gles2
1846 } // namespace gpu