Elim cr-checkbox
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_base.cc
blob47343d4d128b464f1cf669f0673d9cc65e3a23b7
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::AnyNumber;
31 using ::testing::DoAll;
32 using ::testing::InSequence;
33 using ::testing::Invoke;
34 using ::testing::InvokeWithoutArgs;
35 using ::testing::MatcherCast;
36 using ::testing::Pointee;
37 using ::testing::Return;
38 using ::testing::SetArrayArgument;
39 using ::testing::SetArgPointee;
40 using ::testing::SetArgumentPointee;
41 using ::testing::StrEq;
42 using ::testing::StrictMock;
43 using ::testing::WithArg;
45 namespace {
47 void NormalizeInitState(gpu::gles2::GLES2DecoderTestBase::InitState* init) {
48 CHECK(init);
49 const char* kVAOExtensions[] = {
50 "GL_OES_vertex_array_object",
51 "GL_ARB_vertex_array_object",
52 "GL_APPLE_vertex_array_object"
54 bool contains_vao_extension = false;
55 for (size_t ii = 0; ii < arraysize(kVAOExtensions); ++ii) {
56 if (init->extensions.find(kVAOExtensions[ii]) != std::string::npos) {
57 contains_vao_extension = true;
58 break;
62 if (init->use_native_vao) {
63 if (contains_vao_extension)
64 return;
65 if (!init->extensions.empty())
66 init->extensions += " ";
67 if (base::StartsWith(init->gl_version, "opengl es",
68 base::CompareCase::INSENSITIVE_ASCII)) {
69 init->extensions += kVAOExtensions[0];
70 } else {
71 #if !defined(OS_MACOSX)
72 init->extensions += kVAOExtensions[1];
73 #else
74 init->extensions += kVAOExtensions[2];
75 #endif // OS_MACOSX
77 } else {
78 // Make sure we don't set up an invalid InitState.
79 CHECK(!contains_vao_extension);
82 if (!init->extensions.empty())
83 init->extensions += " ";
84 init->extensions += "GL_EXT_framebuffer_object ";
87 const uint32 kMaxColorAttachments = 16;
88 const uint32 kMaxDrawBuffers = 16;
90 } // namespace Anonymous
92 namespace gpu {
93 namespace gles2 {
95 GLES2DecoderTestBase::GLES2DecoderTestBase()
96 : surface_(NULL),
97 context_(NULL),
98 memory_tracker_(NULL),
99 client_buffer_id_(100),
100 client_framebuffer_id_(101),
101 client_program_id_(102),
102 client_renderbuffer_id_(103),
103 client_sampler_id_(104),
104 client_shader_id_(105),
105 client_texture_id_(106),
106 client_element_buffer_id_(107),
107 client_vertex_shader_id_(121),
108 client_fragment_shader_id_(122),
109 client_query_id_(123),
110 client_vertexarray_id_(124),
111 client_valuebuffer_id_(125),
112 client_transformfeedback_id_(126),
113 client_sync_id_(127),
114 service_renderbuffer_id_(0),
115 service_renderbuffer_valid_(false),
116 ignore_cached_state_for_test_(GetParam()),
117 cached_color_mask_red_(true),
118 cached_color_mask_green_(true),
119 cached_color_mask_blue_(true),
120 cached_color_mask_alpha_(true),
121 cached_depth_mask_(true),
122 cached_stencil_front_mask_(static_cast<GLuint>(-1)),
123 cached_stencil_back_mask_(static_cast<GLuint>(-1)) {
124 memset(immediate_buffer_, 0xEE, sizeof(immediate_buffer_));
127 GLES2DecoderTestBase::~GLES2DecoderTestBase() {}
129 void GLES2DecoderTestBase::SetUp() {
130 InitState init;
131 // Autogenerated tests do not overwrite version or extension string,
132 // so we have to pick something that supports everything here.
133 init.gl_version = "4.4";
134 init.extensions += " GL_ARB_compatibility";
135 init.has_alpha = true;
136 init.has_depth = true;
137 init.request_alpha = true;
138 init.request_depth = true;
139 init.bind_generates_resource = true;
140 InitDecoder(init);
143 void GLES2DecoderTestBase::AddExpectationsForVertexAttribManager() {
144 for (GLint ii = 0; ii < kNumVertexAttribs; ++ii) {
145 EXPECT_CALL(*gl_, VertexAttrib4f(ii, 0.0f, 0.0f, 0.0f, 1.0f))
146 .Times(1)
147 .RetiresOnSaturation();
151 GLES2DecoderTestBase::InitState::InitState()
152 : extensions("GL_EXT_framebuffer_object"),
153 gl_version("2.1"),
154 has_alpha(false),
155 has_depth(false),
156 has_stencil(false),
157 request_alpha(false),
158 request_depth(false),
159 request_stencil(false),
160 bind_generates_resource(false),
161 lose_context_when_out_of_memory(false),
162 use_native_vao(true),
163 webgl_version(0) {
166 void GLES2DecoderTestBase::InitDecoder(const InitState& init) {
167 InitDecoderWithCommandLine(init, NULL);
170 void GLES2DecoderTestBase::InitDecoderWithCommandLine(
171 const InitState& init,
172 const base::CommandLine* command_line) {
173 InitState normalized_init = init;
174 NormalizeInitState(&normalized_init);
175 // For easier substring/extension matching
176 DCHECK(normalized_init.extensions.empty() ||
177 *normalized_init.extensions.rbegin() == ' ');
178 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress);
179 gfx::GLSurfaceTestSupport::InitializeOneOffWithMockBindings();
181 gl_.reset(new StrictMock<MockGLInterface>());
182 ::gfx::MockGLInterface::SetGLInterface(gl_.get());
184 SetupMockGLBehaviors();
186 scoped_refptr<FeatureInfo> feature_info;
187 if (command_line)
188 feature_info = new FeatureInfo(*command_line);
189 group_ = scoped_refptr<ContextGroup>(
190 new ContextGroup(NULL, memory_tracker_, new ShaderTranslatorCache,
191 new FramebufferCompletenessCache, feature_info.get(),
192 new SubscriptionRefSet, new ValueStateMap,
193 normalized_init.bind_generates_resource));
194 bool use_default_textures = normalized_init.bind_generates_resource;
196 InSequence sequence;
198 surface_ = new gfx::GLSurfaceStub;
199 surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight));
201 // Context needs to be created before initializing ContextGroup, which will
202 // in turn initialize FeatureInfo, which needs a context to determine
203 // extension support.
204 context_ = new StrictMock<GLContextMock>();
205 context_->AddExtensionsString(normalized_init.extensions.c_str());
206 context_->SetGLVersionString(normalized_init.gl_version.c_str());
208 context_->GLContextStubWithExtensions::MakeCurrent(surface_.get());
209 gfx::GLSurfaceTestSupport::InitializeDynamicMockBindings(context_.get());
211 TestHelper::SetupContextGroupInitExpectations(
212 gl_.get(),
213 DisallowedFeatures(),
214 normalized_init.extensions.c_str(),
215 normalized_init.gl_version.c_str(),
216 normalized_init.bind_generates_resource);
218 // We initialize the ContextGroup with a MockGLES2Decoder so that
219 // we can use the ContextGroup to figure out how the real GLES2Decoder
220 // will initialize itself.
221 mock_decoder_.reset(new MockGLES2Decoder());
223 // Install FakeDoCommands handler so we can use individual DoCommand()
224 // expectations.
225 EXPECT_CALL(*mock_decoder_, DoCommands(_, _, _, _)).WillRepeatedly(
226 Invoke(mock_decoder_.get(), &MockGLES2Decoder::FakeDoCommands));
229 EXPECT_TRUE(group_->Initialize(
230 mock_decoder_.get(),
231 ContextGroup::GetContextType(init.webgl_version),
232 DisallowedFeatures()));
234 if (init.webgl_version == 2) {
235 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_COLOR_ATTACHMENTS, _))
236 .WillOnce(SetArgumentPointee<1>(kMaxColorAttachments))
237 .RetiresOnSaturation();
238 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_DRAW_BUFFERS, _))
239 .WillOnce(SetArgumentPointee<1>(kMaxDrawBuffers))
240 .RetiresOnSaturation();
243 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
244 EXPECT_CALL(*gl_, GenVertexArraysOES(1, _))
245 .WillOnce(SetArgumentPointee<1>(kServiceVertexArrayId))
246 .RetiresOnSaturation();
247 EXPECT_CALL(*gl_, BindVertexArrayOES(_)).Times(1).RetiresOnSaturation();
250 if (group_->feature_info()->workarounds().init_vertex_attributes)
251 AddExpectationsForVertexAttribManager();
253 AddExpectationsForBindVertexArrayOES();
255 EXPECT_CALL(*gl_, EnableVertexAttribArray(0))
256 .Times(1)
257 .RetiresOnSaturation();
258 static GLuint attrib_0_id[] = {
259 kServiceAttrib0BufferId,
261 static GLuint fixed_attrib_buffer_id[] = {
262 kServiceFixedAttribBufferId,
264 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(attrib_0_id), _))
265 .WillOnce(SetArrayArgument<1>(attrib_0_id,
266 attrib_0_id + arraysize(attrib_0_id)))
267 .RetiresOnSaturation();
268 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
269 .Times(1)
270 .RetiresOnSaturation();
271 EXPECT_CALL(*gl_, VertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL))
272 .Times(1)
273 .RetiresOnSaturation();
274 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
275 .Times(1)
276 .RetiresOnSaturation();
277 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(fixed_attrib_buffer_id), _))
278 .WillOnce(SetArrayArgument<1>(
279 fixed_attrib_buffer_id,
280 fixed_attrib_buffer_id + arraysize(fixed_attrib_buffer_id)))
281 .RetiresOnSaturation();
283 for (GLint tt = 0; tt < TestHelper::kNumTextureUnits; ++tt) {
284 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0 + tt))
285 .Times(1)
286 .RetiresOnSaturation();
287 if (group_->feature_info()->feature_flags().oes_egl_image_external) {
288 EXPECT_CALL(*gl_,
289 BindTexture(GL_TEXTURE_EXTERNAL_OES,
290 use_default_textures
291 ? TestHelper::kServiceDefaultExternalTextureId
292 : 0))
293 .Times(1)
294 .RetiresOnSaturation();
296 if (group_->feature_info()->feature_flags().arb_texture_rectangle) {
297 EXPECT_CALL(
298 *gl_,
299 BindTexture(GL_TEXTURE_RECTANGLE_ARB,
300 use_default_textures
301 ? TestHelper::kServiceDefaultRectangleTextureId
302 : 0))
303 .Times(1)
304 .RetiresOnSaturation();
306 EXPECT_CALL(*gl_,
307 BindTexture(GL_TEXTURE_CUBE_MAP,
308 use_default_textures
309 ? TestHelper::kServiceDefaultTextureCubemapId
310 : 0))
311 .Times(1)
312 .RetiresOnSaturation();
313 EXPECT_CALL(
314 *gl_,
315 BindTexture(
316 GL_TEXTURE_2D,
317 use_default_textures ? TestHelper::kServiceDefaultTexture2dId : 0))
318 .Times(1)
319 .RetiresOnSaturation();
321 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
322 .Times(1)
323 .RetiresOnSaturation();
325 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
326 .Times(1)
327 .RetiresOnSaturation();
328 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _))
329 .WillOnce(SetArgumentPointee<1>(normalized_init.has_alpha ? 8 : 0))
330 .RetiresOnSaturation();
331 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
332 .WillOnce(SetArgumentPointee<1>(normalized_init.has_depth ? 24 : 0))
333 .RetiresOnSaturation();
334 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
335 .WillOnce(SetArgumentPointee<1>(normalized_init.has_stencil ? 8 : 0))
336 .RetiresOnSaturation();
338 if (!group_->feature_info()->gl_version_info().BehavesLikeGLES()) {
339 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE))
340 .Times(1)
341 .RetiresOnSaturation();
343 EXPECT_CALL(*gl_, Enable(GL_POINT_SPRITE))
344 .Times(1)
345 .RetiresOnSaturation();
348 static GLint max_viewport_dims[] = {
349 kMaxViewportWidth,
350 kMaxViewportHeight
352 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VIEWPORT_DIMS, _))
353 .WillOnce(SetArrayArgument<1>(
354 max_viewport_dims, max_viewport_dims + arraysize(max_viewport_dims)))
355 .RetiresOnSaturation();
357 SetupInitCapabilitiesExpectations(group_->feature_info()->IsES3Capable());
358 SetupInitStateExpectations();
360 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
361 .Times(1)
362 .RetiresOnSaturation();
364 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
365 .Times(1)
366 .RetiresOnSaturation();
367 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0))
368 .Times(1)
369 .RetiresOnSaturation();
370 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
371 .Times(1)
372 .RetiresOnSaturation();
373 EXPECT_CALL(*gl_, BindRenderbufferEXT(GL_RENDERBUFFER, 0))
374 .Times(1)
375 .RetiresOnSaturation();
377 // TODO(boliu): Remove OS_ANDROID once crbug.com/259023 is fixed and the
378 // workaround has been reverted.
379 #if !defined(OS_ANDROID)
380 if (normalized_init.has_alpha && !normalized_init.request_alpha) {
381 EXPECT_CALL(*gl_, ClearColor(0, 0, 0, 1)).Times(1).RetiresOnSaturation();
384 EXPECT_CALL(*gl_, Clear(
385 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
386 .Times(1)
387 .RetiresOnSaturation();
389 if (normalized_init.has_alpha && !normalized_init.request_alpha) {
390 EXPECT_CALL(*gl_, ClearColor(0, 0, 0, 0)).Times(1).RetiresOnSaturation();
392 #endif
394 engine_.reset(new StrictMock<MockCommandBufferEngine>());
395 scoped_refptr<gpu::Buffer> buffer =
396 engine_->GetSharedMemoryBuffer(kSharedMemoryId);
397 shared_memory_offset_ = kSharedMemoryOffset;
398 shared_memory_address_ =
399 reinterpret_cast<int8*>(buffer->memory()) + shared_memory_offset_;
400 shared_memory_id_ = kSharedMemoryId;
401 shared_memory_base_ = buffer->memory();
403 static const int32 kLoseContextWhenOutOfMemory = 0x10002;
404 static const int32 kWebGLVersion = 0x10003;
406 int32 attributes[] = {
407 EGL_ALPHA_SIZE,
408 normalized_init.request_alpha ? 8 : 0,
409 EGL_DEPTH_SIZE,
410 normalized_init.request_depth ? 24 : 0,
411 EGL_STENCIL_SIZE,
412 normalized_init.request_stencil ? 8 : 0,
413 kLoseContextWhenOutOfMemory,
414 normalized_init.lose_context_when_out_of_memory ? 1 : 0,
415 kWebGLVersion,
416 init.webgl_version
418 std::vector<int32> attribs(attributes, attributes + arraysize(attributes));
420 decoder_.reset(GLES2Decoder::Create(group_.get()));
421 decoder_->SetIgnoreCachedStateForTest(ignore_cached_state_for_test_);
422 decoder_->GetLogger()->set_log_synthesized_gl_errors(false);
423 decoder_->Initialize(surface_,
424 context_,
425 false,
426 surface_->GetSize(),
427 DisallowedFeatures(),
428 attribs);
429 EXPECT_CALL(*context_, MakeCurrent(surface_.get())).WillOnce(Return(true));
430 if (context_->WasAllocatedUsingRobustnessExtension()) {
431 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB())
432 .WillOnce(Return(GL_NO_ERROR));
434 decoder_->MakeCurrent();
435 decoder_->set_engine(engine_.get());
436 decoder_->BeginDecoding();
438 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
439 .WillOnce(SetArgumentPointee<1>(kServiceBufferId))
440 .RetiresOnSaturation();
441 GenHelper<cmds::GenBuffersImmediate>(client_buffer_id_);
442 EXPECT_CALL(*gl_, GenFramebuffersEXT(_, _))
443 .WillOnce(SetArgumentPointee<1>(kServiceFramebufferId))
444 .RetiresOnSaturation();
445 GenHelper<cmds::GenFramebuffersImmediate>(client_framebuffer_id_);
446 EXPECT_CALL(*gl_, GenRenderbuffersEXT(_, _))
447 .WillOnce(SetArgumentPointee<1>(kServiceRenderbufferId))
448 .RetiresOnSaturation();
449 GenHelper<cmds::GenRenderbuffersImmediate>(client_renderbuffer_id_);
450 EXPECT_CALL(*gl_, GenTextures(_, _))
451 .WillOnce(SetArgumentPointee<1>(kServiceTextureId))
452 .RetiresOnSaturation();
453 GenHelper<cmds::GenTexturesImmediate>(client_texture_id_);
454 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
455 .WillOnce(SetArgumentPointee<1>(kServiceElementBufferId))
456 .RetiresOnSaturation();
457 GenHelper<cmds::GenBuffersImmediate>(client_element_buffer_id_);
459 DoCreateProgram(client_program_id_, kServiceProgramId);
460 DoCreateShader(GL_VERTEX_SHADER, client_shader_id_, kServiceShaderId);
462 // Unsafe commands.
463 bool reset_unsafe_es3_apis_enabled = false;
464 if (!decoder_->unsafe_es3_apis_enabled()) {
465 decoder_->set_unsafe_es3_apis_enabled(true);
466 reset_unsafe_es3_apis_enabled = true;
469 const gfx::GLVersionInfo* version = context_->GetVersionInfo();
470 if (version->IsAtLeastGL(3, 3) || version->IsAtLeastGLES(3, 0)) {
471 EXPECT_CALL(*gl_, GenSamplers(_, _))
472 .WillOnce(SetArgumentPointee<1>(kServiceSamplerId))
473 .RetiresOnSaturation();
474 GenHelper<cmds::GenSamplersImmediate>(client_sampler_id_);
476 if (version->IsAtLeastGL(4, 0) || version->IsAtLeastGLES(3, 0)) {
477 EXPECT_CALL(*gl_, GenTransformFeedbacks(_, _))
478 .WillOnce(SetArgumentPointee<1>(kServiceTransformFeedbackId))
479 .RetiresOnSaturation();
480 GenHelper<cmds::GenTransformFeedbacksImmediate>(
481 client_transformfeedback_id_);
484 if (init.extensions.find("GL_ARB_sync ") != std::string::npos ||
485 version->IsAtLeastGL(3, 2) || version->IsAtLeastGLES(3, 0)) {
486 DoFenceSync(client_sync_id_, kServiceSyncId);
489 if (reset_unsafe_es3_apis_enabled) {
490 decoder_->set_unsafe_es3_apis_enabled(false);
493 EXPECT_EQ(GL_NO_ERROR, GetGLError());
496 void GLES2DecoderTestBase::ResetDecoder() {
497 if (!decoder_.get())
498 return;
499 // All Tests should have read all their GLErrors before getting here.
500 EXPECT_EQ(GL_NO_ERROR, GetGLError());
502 EXPECT_CALL(*gl_, DeleteBuffersARB(1, _))
503 .Times(2)
504 .RetiresOnSaturation();
505 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
506 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, Pointee(kServiceVertexArrayId)))
507 .Times(1)
508 .RetiresOnSaturation();
511 decoder_->EndDecoding();
512 decoder_->Destroy(true);
513 decoder_.reset();
514 group_->Destroy(mock_decoder_.get(), false);
515 engine_.reset();
516 ::gfx::MockGLInterface::SetGLInterface(NULL);
517 gl_.reset();
518 gfx::ClearGLBindings();
521 void GLES2DecoderTestBase::TearDown() {
522 ResetDecoder();
525 void GLES2DecoderTestBase::ExpectEnableDisable(GLenum cap, bool enable) {
526 if (enable) {
527 EXPECT_CALL(*gl_, Enable(cap))
528 .Times(1)
529 .RetiresOnSaturation();
530 } else {
531 EXPECT_CALL(*gl_, Disable(cap))
532 .Times(1)
533 .RetiresOnSaturation();
538 GLint GLES2DecoderTestBase::GetGLError() {
539 EXPECT_CALL(*gl_, GetError())
540 .WillOnce(Return(GL_NO_ERROR))
541 .RetiresOnSaturation();
542 cmds::GetError cmd;
543 cmd.Init(shared_memory_id_, shared_memory_offset_);
544 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
545 return static_cast<GLint>(*GetSharedMemoryAs<GLenum*>());
548 void GLES2DecoderTestBase::DoCreateShader(
549 GLenum shader_type, GLuint client_id, GLuint service_id) {
550 EXPECT_CALL(*gl_, CreateShader(shader_type))
551 .Times(1)
552 .WillOnce(Return(service_id))
553 .RetiresOnSaturation();
554 cmds::CreateShader cmd;
555 cmd.Init(shader_type, client_id);
556 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
559 bool GLES2DecoderTestBase::DoIsShader(GLuint client_id) {
560 return IsObjectHelper<cmds::IsShader, cmds::IsShader::Result>(client_id);
563 void GLES2DecoderTestBase::DoDeleteShader(
564 GLuint client_id, GLuint service_id) {
565 EXPECT_CALL(*gl_, DeleteShader(service_id))
566 .Times(1)
567 .RetiresOnSaturation();
568 cmds::DeleteShader cmd;
569 cmd.Init(client_id);
570 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
573 void GLES2DecoderTestBase::DoCreateProgram(
574 GLuint client_id, GLuint service_id) {
575 EXPECT_CALL(*gl_, CreateProgram())
576 .Times(1)
577 .WillOnce(Return(service_id))
578 .RetiresOnSaturation();
579 cmds::CreateProgram cmd;
580 cmd.Init(client_id);
581 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
584 bool GLES2DecoderTestBase::DoIsProgram(GLuint client_id) {
585 return IsObjectHelper<cmds::IsProgram, cmds::IsProgram::Result>(client_id);
588 void GLES2DecoderTestBase::DoDeleteProgram(
589 GLuint client_id, GLuint /* service_id */) {
590 cmds::DeleteProgram cmd;
591 cmd.Init(client_id);
592 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
595 void GLES2DecoderTestBase::DoFenceSync(
596 GLuint client_id, GLuint service_id) {
597 EXPECT_CALL(*gl_, FenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0))
598 .Times(1)
599 .WillOnce(Return(reinterpret_cast<GLsync>(service_id)))
600 .RetiresOnSaturation();
601 cmds::FenceSync cmd;
602 cmd.Init(client_id);
603 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
606 void GLES2DecoderTestBase::SetBucketData(
607 uint32_t bucket_id, const void* data, uint32_t data_size) {
608 DCHECK(data || data_size == 0);
609 cmd::SetBucketSize cmd1;
610 cmd1.Init(bucket_id, data_size);
611 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
612 if (data) {
613 memcpy(shared_memory_address_, data, data_size);
614 cmd::SetBucketData cmd2;
615 cmd2.Init(bucket_id, 0, data_size, kSharedMemoryId, kSharedMemoryOffset);
616 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
617 ClearSharedMemory();
621 void GLES2DecoderTestBase::SetBucketAsCString(
622 uint32 bucket_id, const char* str) {
623 SetBucketData(bucket_id, str, str ? (strlen(str) + 1) : 0);
626 void GLES2DecoderTestBase::SetBucketAsCStrings(
627 uint32 bucket_id, GLsizei count, const char** str,
628 GLsizei count_in_header, char str_end) {
629 uint32_t header_size = sizeof(GLint) * (count + 1);
630 uint32_t total_size = header_size;
631 scoped_ptr<GLint[]> header(new GLint[count + 1]);
632 header[0] = static_cast<GLint>(count_in_header);
633 for (GLsizei ii = 0; ii < count; ++ii) {
634 header[ii + 1] = str && str[ii] ? strlen(str[ii]) : 0;
635 total_size += header[ii + 1] + 1;
637 cmd::SetBucketSize cmd1;
638 cmd1.Init(bucket_id, total_size);
639 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
640 memcpy(shared_memory_address_, header.get(), header_size);
641 uint32_t offset = header_size;
642 for (GLsizei ii = 0; ii < count; ++ii) {
643 if (str && str[ii]) {
644 size_t str_len = strlen(str[ii]);
645 memcpy(reinterpret_cast<char*>(shared_memory_address_) + offset,
646 str[ii], str_len);
647 offset += str_len;
649 memcpy(reinterpret_cast<char*>(shared_memory_address_) + offset,
650 &str_end, 1);
651 offset += 1;
653 cmd::SetBucketData cmd2;
654 cmd2.Init(bucket_id, 0, total_size, kSharedMemoryId, kSharedMemoryOffset);
655 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
656 ClearSharedMemory();
659 void GLES2DecoderTestBase::SetupClearTextureExpectations(GLuint service_id,
660 GLuint old_service_id,
661 GLenum bind_target,
662 GLenum target,
663 GLint level,
664 GLenum internal_format,
665 GLenum format,
666 GLenum type,
667 GLint xoffset,
668 GLint yoffset,
669 GLsizei width,
670 GLsizei height) {
671 EXPECT_CALL(*gl_, BindTexture(bind_target, service_id))
672 .Times(1)
673 .RetiresOnSaturation();
674 EXPECT_CALL(*gl_, TexSubImage2D(target, level, xoffset, yoffset, width,
675 height, format, type, _))
676 .Times(1)
677 .RetiresOnSaturation();
678 EXPECT_CALL(*gl_, BindTexture(bind_target, old_service_id))
679 .Times(1)
680 .RetiresOnSaturation();
683 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearing(
684 GLenum target,
685 GLuint clear_bits,
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 GLint restore_scissor_x,
694 GLint restore_scissor_y,
695 GLsizei restore_scissor_width,
696 GLsizei restore_scissor_height) {
697 SetupExpectationsForFramebufferClearingMulti(
698 0, 0, target, clear_bits, restore_red, restore_green, restore_blue,
699 restore_alpha, restore_stencil, restore_depth, restore_scissor_test,
700 restore_scissor_x, restore_scissor_y, restore_scissor_width,
701 restore_scissor_height);
704 void GLES2DecoderTestBase::SetupExpectationsForRestoreClearState(
705 GLclampf restore_red,
706 GLclampf restore_green,
707 GLclampf restore_blue,
708 GLclampf restore_alpha,
709 GLuint restore_stencil,
710 GLclampf restore_depth,
711 bool restore_scissor_test,
712 GLint restore_scissor_x,
713 GLint restore_scissor_y,
714 GLsizei restore_scissor_width,
715 GLsizei restore_scissor_height) {
716 EXPECT_CALL(*gl_, ClearColor(
717 restore_red, restore_green, restore_blue, restore_alpha))
718 .Times(1)
719 .RetiresOnSaturation();
720 EXPECT_CALL(*gl_, ClearStencil(restore_stencil))
721 .Times(1)
722 .RetiresOnSaturation();
723 EXPECT_CALL(*gl_, ClearDepth(restore_depth))
724 .Times(1)
725 .RetiresOnSaturation();
726 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST, restore_scissor_test);
727 EXPECT_CALL(*gl_, Scissor(restore_scissor_x, restore_scissor_y,
728 restore_scissor_width, restore_scissor_height))
729 .Times(1)
730 .RetiresOnSaturation();
733 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearingMulti(
734 GLuint read_framebuffer_service_id,
735 GLuint draw_framebuffer_service_id,
736 GLenum target,
737 GLuint clear_bits,
738 GLclampf restore_red,
739 GLclampf restore_green,
740 GLclampf restore_blue,
741 GLclampf restore_alpha,
742 GLuint restore_stencil,
743 GLclampf restore_depth,
744 bool restore_scissor_test,
745 GLint restore_scissor_x,
746 GLint restore_scissor_y,
747 GLsizei restore_scissor_width,
748 GLsizei restore_scissor_height) {
749 // TODO(gman): Figure out why InSequence stopped working.
750 // InSequence sequence;
751 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(target))
752 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
753 .RetiresOnSaturation();
754 if (target == GL_READ_FRAMEBUFFER_EXT) {
755 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0))
756 .Times(1)
757 .RetiresOnSaturation();
758 EXPECT_CALL(*gl_, BindFramebufferEXT(
759 GL_DRAW_FRAMEBUFFER_EXT, read_framebuffer_service_id))
760 .Times(1)
761 .RetiresOnSaturation();
763 if ((clear_bits & GL_COLOR_BUFFER_BIT) != 0) {
764 EXPECT_CALL(*gl_, ClearColor(0.0f, 0.0f, 0.0f, 0.0f))
765 .Times(1)
766 .RetiresOnSaturation();
767 SetupExpectationsForColorMask(true, true, true, true);
769 if ((clear_bits & GL_STENCIL_BUFFER_BIT) != 0) {
770 EXPECT_CALL(*gl_, ClearStencil(0))
771 .Times(1)
772 .RetiresOnSaturation();
773 EXPECT_CALL(*gl_, StencilMask(static_cast<GLuint>(-1)))
774 .Times(1)
775 .RetiresOnSaturation();
777 if ((clear_bits & GL_DEPTH_BUFFER_BIT) != 0) {
778 EXPECT_CALL(*gl_, ClearDepth(1.0f))
779 .Times(1)
780 .RetiresOnSaturation();
781 SetupExpectationsForDepthMask(true);
783 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST, false);
784 EXPECT_CALL(*gl_, Clear(clear_bits))
785 .Times(1)
786 .RetiresOnSaturation();
787 SetupExpectationsForRestoreClearState(
788 restore_red, restore_green, restore_blue, restore_alpha, restore_stencil,
789 restore_depth, restore_scissor_test, restore_scissor_x, restore_scissor_y,
790 restore_scissor_width, restore_scissor_height);
791 if (target == GL_READ_FRAMEBUFFER_EXT) {
792 EXPECT_CALL(*gl_, BindFramebufferEXT(
793 GL_READ_FRAMEBUFFER_EXT, read_framebuffer_service_id))
794 .Times(1)
795 .RetiresOnSaturation();
796 EXPECT_CALL(*gl_, BindFramebufferEXT(
797 GL_DRAW_FRAMEBUFFER_EXT, draw_framebuffer_service_id))
798 .Times(1)
799 .RetiresOnSaturation();
803 void GLES2DecoderTestBase::SetupShaderForUniform(GLenum uniform_type) {
804 static AttribInfo attribs[] = {
805 { "foo", 1, GL_FLOAT, 1, },
806 { "goo", 1, GL_FLOAT, 2, },
808 UniformInfo uniforms[] = {
809 { "bar", 1, uniform_type, 0, 2, -1, },
810 { "car", 4, uniform_type, 1, 1, -1, },
812 const GLuint kClientVertexShaderId = 5001;
813 const GLuint kServiceVertexShaderId = 6001;
814 const GLuint kClientFragmentShaderId = 5002;
815 const GLuint kServiceFragmentShaderId = 6002;
816 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
817 client_program_id_, kServiceProgramId,
818 kClientVertexShaderId, kServiceVertexShaderId,
819 kClientFragmentShaderId, kServiceFragmentShaderId);
821 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
822 .Times(1)
823 .RetiresOnSaturation();
824 cmds::UseProgram cmd;
825 cmd.Init(client_program_id_);
826 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
829 void GLES2DecoderTestBase::DoBindBuffer(
830 GLenum target, GLuint client_id, GLuint service_id) {
831 EXPECT_CALL(*gl_, BindBuffer(target, service_id))
832 .Times(1)
833 .RetiresOnSaturation();
834 cmds::BindBuffer cmd;
835 cmd.Init(target, client_id);
836 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
839 bool GLES2DecoderTestBase::DoIsBuffer(GLuint client_id) {
840 return IsObjectHelper<cmds::IsBuffer, cmds::IsBuffer::Result>(client_id);
843 void GLES2DecoderTestBase::DoDeleteBuffer(
844 GLuint client_id, GLuint service_id) {
845 EXPECT_CALL(*gl_, DeleteBuffersARB(1, Pointee(service_id)))
846 .Times(1)
847 .RetiresOnSaturation();
848 GenHelper<cmds::DeleteBuffersImmediate>(client_id);
851 void GLES2DecoderTestBase::SetupExpectationsForColorMask(bool red,
852 bool green,
853 bool blue,
854 bool alpha) {
855 if (ignore_cached_state_for_test_ || cached_color_mask_red_ != red ||
856 cached_color_mask_green_ != green || cached_color_mask_blue_ != blue ||
857 cached_color_mask_alpha_ != alpha) {
858 cached_color_mask_red_ = red;
859 cached_color_mask_green_ = green;
860 cached_color_mask_blue_ = blue;
861 cached_color_mask_alpha_ = alpha;
862 EXPECT_CALL(*gl_, ColorMask(red, green, blue, alpha))
863 .Times(1)
864 .RetiresOnSaturation();
868 void GLES2DecoderTestBase::SetupExpectationsForDepthMask(bool mask) {
869 if (ignore_cached_state_for_test_ || cached_depth_mask_ != mask) {
870 cached_depth_mask_ = mask;
871 EXPECT_CALL(*gl_, DepthMask(mask)).Times(1).RetiresOnSaturation();
875 void GLES2DecoderTestBase::SetupExpectationsForStencilMask(GLuint front_mask,
876 GLuint back_mask) {
877 if (ignore_cached_state_for_test_ ||
878 cached_stencil_front_mask_ != front_mask) {
879 cached_stencil_front_mask_ = front_mask;
880 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_FRONT, front_mask))
881 .Times(1)
882 .RetiresOnSaturation();
885 if (ignore_cached_state_for_test_ ||
886 cached_stencil_back_mask_ != back_mask) {
887 cached_stencil_back_mask_ = back_mask;
888 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_BACK, back_mask))
889 .Times(1)
890 .RetiresOnSaturation();
894 void GLES2DecoderTestBase::SetupExpectationsForEnableDisable(GLenum cap,
895 bool enable) {
896 switch (cap) {
897 case GL_BLEND:
898 if (enable_flags_.cached_blend == enable &&
899 !ignore_cached_state_for_test_)
900 return;
901 enable_flags_.cached_blend = enable;
902 break;
903 case GL_CULL_FACE:
904 if (enable_flags_.cached_cull_face == enable &&
905 !ignore_cached_state_for_test_)
906 return;
907 enable_flags_.cached_cull_face = enable;
908 break;
909 case GL_DEPTH_TEST:
910 if (enable_flags_.cached_depth_test == enable &&
911 !ignore_cached_state_for_test_)
912 return;
913 enable_flags_.cached_depth_test = enable;
914 break;
915 case GL_DITHER:
916 if (enable_flags_.cached_dither == enable &&
917 !ignore_cached_state_for_test_)
918 return;
919 enable_flags_.cached_dither = enable;
920 break;
921 case GL_POLYGON_OFFSET_FILL:
922 if (enable_flags_.cached_polygon_offset_fill == enable &&
923 !ignore_cached_state_for_test_)
924 return;
925 enable_flags_.cached_polygon_offset_fill = enable;
926 break;
927 case GL_SAMPLE_ALPHA_TO_COVERAGE:
928 if (enable_flags_.cached_sample_alpha_to_coverage == enable &&
929 !ignore_cached_state_for_test_)
930 return;
931 enable_flags_.cached_sample_alpha_to_coverage = enable;
932 break;
933 case GL_SAMPLE_COVERAGE:
934 if (enable_flags_.cached_sample_coverage == enable &&
935 !ignore_cached_state_for_test_)
936 return;
937 enable_flags_.cached_sample_coverage = enable;
938 break;
939 case GL_SCISSOR_TEST:
940 if (enable_flags_.cached_scissor_test == enable &&
941 !ignore_cached_state_for_test_)
942 return;
943 enable_flags_.cached_scissor_test = enable;
944 break;
945 case GL_STENCIL_TEST:
946 if (enable_flags_.cached_stencil_test == enable &&
947 !ignore_cached_state_for_test_)
948 return;
949 enable_flags_.cached_stencil_test = enable;
950 break;
951 default:
952 NOTREACHED();
953 return;
955 if (enable) {
956 EXPECT_CALL(*gl_, Enable(cap)).Times(1).RetiresOnSaturation();
957 } else {
958 EXPECT_CALL(*gl_, Disable(cap)).Times(1).RetiresOnSaturation();
962 void GLES2DecoderTestBase::SetupExpectationsForApplyingDirtyState(
963 bool framebuffer_is_rgb,
964 bool framebuffer_has_depth,
965 bool framebuffer_has_stencil,
966 GLuint color_bits,
967 bool depth_mask,
968 bool depth_enabled,
969 GLuint front_stencil_mask,
970 GLuint back_stencil_mask,
971 bool stencil_enabled) {
972 bool color_mask_red = (color_bits & 0x1000) != 0;
973 bool color_mask_green = (color_bits & 0x0100) != 0;
974 bool color_mask_blue = (color_bits & 0x0010) != 0;
975 bool color_mask_alpha = (color_bits & 0x0001) && !framebuffer_is_rgb;
977 SetupExpectationsForColorMask(
978 color_mask_red, color_mask_green, color_mask_blue, color_mask_alpha);
979 SetupExpectationsForDepthMask(depth_mask);
980 SetupExpectationsForStencilMask(front_stencil_mask, back_stencil_mask);
981 SetupExpectationsForEnableDisable(GL_DEPTH_TEST,
982 framebuffer_has_depth && depth_enabled);
983 SetupExpectationsForEnableDisable(GL_STENCIL_TEST,
984 framebuffer_has_stencil && stencil_enabled);
987 void GLES2DecoderTestBase::SetupExpectationsForApplyingDefaultDirtyState() {
988 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
989 false, // Framebuffer has depth
990 false, // Framebuffer has stencil
991 0x1111, // color bits
992 true, // depth mask
993 false, // depth enabled
994 0, // front stencil mask
995 0, // back stencil mask
996 false); // stencil enabled
999 GLES2DecoderTestBase::EnableFlags::EnableFlags()
1000 : cached_blend(false),
1001 cached_cull_face(false),
1002 cached_depth_test(false),
1003 cached_dither(true),
1004 cached_polygon_offset_fill(false),
1005 cached_sample_alpha_to_coverage(false),
1006 cached_sample_coverage(false),
1007 cached_scissor_test(false),
1008 cached_stencil_test(false) {
1011 void GLES2DecoderTestBase::DoBindFramebuffer(
1012 GLenum target, GLuint client_id, GLuint service_id) {
1013 EXPECT_CALL(*gl_, BindFramebufferEXT(target, service_id))
1014 .Times(1)
1015 .RetiresOnSaturation();
1016 cmds::BindFramebuffer cmd;
1017 cmd.Init(target, client_id);
1018 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1021 bool GLES2DecoderTestBase::DoIsFramebuffer(GLuint client_id) {
1022 return IsObjectHelper<cmds::IsFramebuffer, cmds::IsFramebuffer::Result>(
1023 client_id);
1026 void GLES2DecoderTestBase::DoDeleteFramebuffer(
1027 GLuint client_id, GLuint service_id,
1028 bool reset_draw, GLenum draw_target, GLuint draw_id,
1029 bool reset_read, GLenum read_target, GLuint read_id) {
1030 if (reset_draw) {
1031 EXPECT_CALL(*gl_, BindFramebufferEXT(draw_target, draw_id))
1032 .Times(1)
1033 .RetiresOnSaturation();
1035 if (reset_read) {
1036 EXPECT_CALL(*gl_, BindFramebufferEXT(read_target, read_id))
1037 .Times(1)
1038 .RetiresOnSaturation();
1040 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, Pointee(service_id)))
1041 .Times(1)
1042 .RetiresOnSaturation();
1043 GenHelper<cmds::DeleteFramebuffersImmediate>(client_id);
1046 void GLES2DecoderTestBase::DoBindRenderbuffer(
1047 GLenum target, GLuint client_id, GLuint service_id) {
1048 service_renderbuffer_id_ = service_id;
1049 service_renderbuffer_valid_ = true;
1050 EXPECT_CALL(*gl_, BindRenderbufferEXT(target, service_id))
1051 .Times(1)
1052 .RetiresOnSaturation();
1053 cmds::BindRenderbuffer cmd;
1054 cmd.Init(target, client_id);
1055 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1058 void GLES2DecoderTestBase::DoRenderbufferStorageMultisampleCHROMIUM(
1059 GLenum target,
1060 GLsizei samples,
1061 GLenum internal_format,
1062 GLenum gl_format,
1063 GLsizei width,
1064 GLsizei height) {
1065 EXPECT_CALL(*gl_, GetError())
1066 .WillOnce(Return(GL_NO_ERROR))
1067 .RetiresOnSaturation();
1068 EXPECT_CALL(*gl_,
1069 RenderbufferStorageMultisampleEXT(
1070 target, samples, gl_format, width, height))
1071 .Times(1)
1072 .RetiresOnSaturation();
1073 EXPECT_CALL(*gl_, GetError())
1074 .WillOnce(Return(GL_NO_ERROR))
1075 .RetiresOnSaturation();
1076 cmds::RenderbufferStorageMultisampleCHROMIUM cmd;
1077 cmd.Init(target, samples, internal_format, width, height);
1078 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1079 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1082 void GLES2DecoderTestBase::RestoreRenderbufferBindings() {
1083 GetDecoder()->RestoreRenderbufferBindings();
1084 service_renderbuffer_valid_ = false;
1087 void GLES2DecoderTestBase::EnsureRenderbufferBound(bool expect_bind) {
1088 EXPECT_NE(expect_bind, service_renderbuffer_valid_);
1090 if (expect_bind) {
1091 service_renderbuffer_valid_ = true;
1092 EXPECT_CALL(*gl_,
1093 BindRenderbufferEXT(GL_RENDERBUFFER, service_renderbuffer_id_))
1094 .Times(1)
1095 .RetiresOnSaturation();
1096 } else {
1097 EXPECT_CALL(*gl_, BindRenderbufferEXT(_, _)).Times(0);
1101 bool GLES2DecoderTestBase::DoIsRenderbuffer(GLuint client_id) {
1102 return IsObjectHelper<cmds::IsRenderbuffer, cmds::IsRenderbuffer::Result>(
1103 client_id);
1106 void GLES2DecoderTestBase::DoDeleteRenderbuffer(
1107 GLuint client_id, GLuint service_id) {
1108 EXPECT_CALL(*gl_, DeleteRenderbuffersEXT(1, Pointee(service_id)))
1109 .Times(1)
1110 .RetiresOnSaturation();
1111 GenHelper<cmds::DeleteRenderbuffersImmediate>(client_id);
1114 void GLES2DecoderTestBase::DoBindTexture(
1115 GLenum target, GLuint client_id, GLuint service_id) {
1116 EXPECT_CALL(*gl_, BindTexture(target, service_id))
1117 .Times(1)
1118 .RetiresOnSaturation();
1119 cmds::BindTexture cmd;
1120 cmd.Init(target, client_id);
1121 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1124 bool GLES2DecoderTestBase::DoIsTexture(GLuint client_id) {
1125 return IsObjectHelper<cmds::IsTexture, cmds::IsTexture::Result>(client_id);
1128 void GLES2DecoderTestBase::DoDeleteTexture(
1129 GLuint client_id, GLuint service_id) {
1132 InSequence s;
1134 // Calling DoDeleteTexture will unbind the texture from any texture units
1135 // it's currently bound to.
1136 EXPECT_CALL(*gl_, BindTexture(_, 0))
1137 .Times(AnyNumber());
1139 EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(service_id)))
1140 .Times(1)
1141 .RetiresOnSaturation();
1143 GenHelper<cmds::DeleteTexturesImmediate>(client_id);
1147 void GLES2DecoderTestBase::DoBindTexImage2DCHROMIUM(GLenum target,
1148 GLint image_id) {
1149 cmds::BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
1150 bind_tex_image_2d_cmd.Init(target, image_id);
1151 EXPECT_CALL(*gl_, GetError())
1152 .WillOnce(Return(GL_NO_ERROR))
1153 .WillOnce(Return(GL_NO_ERROR))
1154 .RetiresOnSaturation();
1155 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
1156 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1159 void GLES2DecoderTestBase::DoTexImage2D(
1160 GLenum target, GLint level, GLenum internal_format,
1161 GLsizei width, GLsizei height, GLint border,
1162 GLenum format, GLenum type,
1163 uint32 shared_memory_id, uint32 shared_memory_offset) {
1164 EXPECT_CALL(*gl_, GetError())
1165 .WillOnce(Return(GL_NO_ERROR))
1166 .RetiresOnSaturation();
1167 EXPECT_CALL(*gl_, TexImage2D(target, level, internal_format,
1168 width, height, border, format, type, _))
1169 .Times(1)
1170 .RetiresOnSaturation();
1171 EXPECT_CALL(*gl_, GetError())
1172 .WillOnce(Return(GL_NO_ERROR))
1173 .RetiresOnSaturation();
1174 cmds::TexImage2D cmd;
1175 cmd.Init(target, level, internal_format, width, height, format,
1176 type, shared_memory_id, shared_memory_offset);
1177 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1180 void GLES2DecoderTestBase::DoTexImage2DConvertInternalFormat(
1181 GLenum target, GLint level, GLenum requested_internal_format,
1182 GLsizei width, GLsizei height, GLint border,
1183 GLenum format, GLenum type,
1184 uint32 shared_memory_id, uint32 shared_memory_offset,
1185 GLenum expected_internal_format) {
1186 EXPECT_CALL(*gl_, GetError())
1187 .WillOnce(Return(GL_NO_ERROR))
1188 .RetiresOnSaturation();
1189 EXPECT_CALL(*gl_, TexImage2D(target, level, expected_internal_format,
1190 width, height, border, format, type, _))
1191 .Times(1)
1192 .RetiresOnSaturation();
1193 EXPECT_CALL(*gl_, GetError())
1194 .WillOnce(Return(GL_NO_ERROR))
1195 .RetiresOnSaturation();
1196 cmds::TexImage2D cmd;
1197 cmd.Init(target, level, requested_internal_format, width, height,
1198 format, type, shared_memory_id, shared_memory_offset);
1199 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1202 void GLES2DecoderTestBase::DoCompressedTexImage2D(
1203 GLenum target, GLint level, GLenum format,
1204 GLsizei width, GLsizei height, GLint border,
1205 GLsizei size, uint32 bucket_id) {
1206 EXPECT_CALL(*gl_, GetError())
1207 .WillOnce(Return(GL_NO_ERROR))
1208 .RetiresOnSaturation();
1209 EXPECT_CALL(*gl_, CompressedTexImage2D(
1210 target, level, format, width, height, border, size, _))
1211 .Times(1)
1212 .RetiresOnSaturation();
1213 EXPECT_CALL(*gl_, GetError())
1214 .WillOnce(Return(GL_NO_ERROR))
1215 .RetiresOnSaturation();
1216 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(bucket_id);
1217 bucket->SetSize(size);
1218 cmds::CompressedTexImage2DBucket cmd;
1219 cmd.Init(
1220 target, level, format, width, height,
1221 bucket_id);
1222 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1225 void GLES2DecoderTestBase::DoRenderbufferStorage(
1226 GLenum target, GLenum internal_format, GLenum actual_format,
1227 GLsizei width, GLsizei height, GLenum error) {
1228 EXPECT_CALL(*gl_, GetError())
1229 .WillOnce(Return(GL_NO_ERROR))
1230 .RetiresOnSaturation();
1231 EXPECT_CALL(*gl_, RenderbufferStorageEXT(
1232 target, actual_format, width, height))
1233 .Times(1)
1234 .RetiresOnSaturation();
1235 EXPECT_CALL(*gl_, GetError())
1236 .WillOnce(Return(error))
1237 .RetiresOnSaturation();
1238 cmds::RenderbufferStorage cmd;
1239 cmd.Init(target, internal_format, width, height);
1240 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1243 void GLES2DecoderTestBase::DoFramebufferTexture2D(
1244 GLenum target, GLenum attachment, GLenum textarget,
1245 GLuint texture_client_id, GLuint texture_service_id, GLint level,
1246 GLenum error) {
1247 EXPECT_CALL(*gl_, GetError())
1248 .WillOnce(Return(GL_NO_ERROR))
1249 .RetiresOnSaturation();
1250 EXPECT_CALL(*gl_, FramebufferTexture2DEXT(
1251 target, attachment, textarget, texture_service_id, level))
1252 .Times(1)
1253 .RetiresOnSaturation();
1254 EXPECT_CALL(*gl_, GetError())
1255 .WillOnce(Return(error))
1256 .RetiresOnSaturation();
1257 cmds::FramebufferTexture2D cmd;
1258 cmd.Init(target, attachment, textarget, texture_client_id);
1259 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1262 void GLES2DecoderTestBase::DoFramebufferRenderbuffer(
1263 GLenum target,
1264 GLenum attachment,
1265 GLenum renderbuffer_target,
1266 GLuint renderbuffer_client_id,
1267 GLuint renderbuffer_service_id,
1268 GLenum error) {
1269 EXPECT_CALL(*gl_, GetError())
1270 .WillOnce(Return(GL_NO_ERROR))
1271 .RetiresOnSaturation();
1272 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
1273 target, attachment, renderbuffer_target, renderbuffer_service_id))
1274 .Times(1)
1275 .RetiresOnSaturation();
1276 EXPECT_CALL(*gl_, GetError())
1277 .WillOnce(Return(error))
1278 .RetiresOnSaturation();
1279 cmds::FramebufferRenderbuffer cmd;
1280 cmd.Init(target, attachment, renderbuffer_target, renderbuffer_client_id);
1281 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1284 void GLES2DecoderTestBase::DoVertexAttribPointer(
1285 GLuint index, GLint size, GLenum type, GLsizei stride, GLuint offset) {
1286 EXPECT_CALL(*gl_,
1287 VertexAttribPointer(index, size, type, GL_FALSE, stride,
1288 BufferOffset(offset)))
1289 .Times(1)
1290 .RetiresOnSaturation();
1291 cmds::VertexAttribPointer cmd;
1292 cmd.Init(index, size, GL_FLOAT, GL_FALSE, stride, offset);
1293 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1296 void GLES2DecoderTestBase::DoVertexAttribDivisorANGLE(
1297 GLuint index, GLuint divisor) {
1298 EXPECT_CALL(*gl_,
1299 VertexAttribDivisorANGLE(index, divisor))
1300 .Times(1)
1301 .RetiresOnSaturation();
1302 cmds::VertexAttribDivisorANGLE cmd;
1303 cmd.Init(index, divisor);
1304 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1307 void GLES2DecoderTestBase::AddExpectationsForGenVertexArraysOES(){
1308 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
1309 EXPECT_CALL(*gl_, GenVertexArraysOES(1, _))
1310 .WillOnce(SetArgumentPointee<1>(kServiceVertexArrayId))
1311 .RetiresOnSaturation();
1315 void GLES2DecoderTestBase::AddExpectationsForDeleteVertexArraysOES(){
1316 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
1317 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, _))
1318 .Times(1)
1319 .RetiresOnSaturation();
1323 void GLES2DecoderTestBase::AddExpectationsForDeleteBoundVertexArraysOES() {
1324 // Expectations are the same as a delete, followed by binding VAO 0.
1325 AddExpectationsForDeleteVertexArraysOES();
1326 AddExpectationsForBindVertexArrayOES();
1329 void GLES2DecoderTestBase::AddExpectationsForBindVertexArrayOES() {
1330 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
1331 EXPECT_CALL(*gl_, BindVertexArrayOES(_))
1332 .Times(1)
1333 .RetiresOnSaturation();
1334 } else {
1335 for (uint32 vv = 0; vv < group_->max_vertex_attribs(); ++vv) {
1336 AddExpectationsForRestoreAttribState(vv);
1339 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _))
1340 .Times(1)
1341 .RetiresOnSaturation();
1345 void GLES2DecoderTestBase::AddExpectationsForRestoreAttribState(GLuint attrib) {
1346 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1347 .Times(1)
1348 .RetiresOnSaturation();
1350 EXPECT_CALL(*gl_, VertexAttribPointer(attrib, _, _, _, _, _))
1351 .Times(1)
1352 .RetiresOnSaturation();
1354 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(attrib, _))
1355 .Times(testing::AtMost(1))
1356 .RetiresOnSaturation();
1358 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1359 .Times(1)
1360 .RetiresOnSaturation();
1362 if (attrib != 0 ||
1363 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
1365 // TODO(bajones): Not sure if I can tell which of these will be called
1366 EXPECT_CALL(*gl_, EnableVertexAttribArray(attrib))
1367 .Times(testing::AtMost(1))
1368 .RetiresOnSaturation();
1370 EXPECT_CALL(*gl_, DisableVertexAttribArray(attrib))
1371 .Times(testing::AtMost(1))
1372 .RetiresOnSaturation();
1376 // GCC requires these declarations, but MSVC requires they not be present
1377 #ifndef COMPILER_MSVC
1378 const int GLES2DecoderTestBase::kBackBufferWidth;
1379 const int GLES2DecoderTestBase::kBackBufferHeight;
1381 const GLint GLES2DecoderTestBase::kMaxTextureSize;
1382 const GLint GLES2DecoderTestBase::kMaxCubeMapTextureSize;
1383 const GLint GLES2DecoderTestBase::kNumVertexAttribs;
1384 const GLint GLES2DecoderTestBase::kNumTextureUnits;
1385 const GLint GLES2DecoderTestBase::kMaxTextureImageUnits;
1386 const GLint GLES2DecoderTestBase::kMaxVertexTextureImageUnits;
1387 const GLint GLES2DecoderTestBase::kMaxFragmentUniformVectors;
1388 const GLint GLES2DecoderTestBase::kMaxVaryingVectors;
1389 const GLint GLES2DecoderTestBase::kMaxVertexUniformVectors;
1390 const GLint GLES2DecoderTestBase::kMaxViewportWidth;
1391 const GLint GLES2DecoderTestBase::kMaxViewportHeight;
1393 const GLint GLES2DecoderTestBase::kViewportX;
1394 const GLint GLES2DecoderTestBase::kViewportY;
1395 const GLint GLES2DecoderTestBase::kViewportWidth;
1396 const GLint GLES2DecoderTestBase::kViewportHeight;
1398 const GLuint GLES2DecoderTestBase::kServiceAttrib0BufferId;
1399 const GLuint GLES2DecoderTestBase::kServiceFixedAttribBufferId;
1401 const GLuint GLES2DecoderTestBase::kServiceBufferId;
1402 const GLuint GLES2DecoderTestBase::kServiceFramebufferId;
1403 const GLuint GLES2DecoderTestBase::kServiceRenderbufferId;
1404 const GLuint GLES2DecoderTestBase::kServiceSamplerId;
1405 const GLuint GLES2DecoderTestBase::kServiceTextureId;
1406 const GLuint GLES2DecoderTestBase::kServiceProgramId;
1407 const GLuint GLES2DecoderTestBase::kServiceShaderId;
1408 const GLuint GLES2DecoderTestBase::kServiceElementBufferId;
1409 const GLuint GLES2DecoderTestBase::kServiceQueryId;
1410 const GLuint GLES2DecoderTestBase::kServiceVertexArrayId;
1411 const GLuint GLES2DecoderTestBase::kServiceTransformFeedbackId;
1412 const GLuint GLES2DecoderTestBase::kServiceSyncId;
1414 const int32 GLES2DecoderTestBase::kSharedMemoryId;
1415 const size_t GLES2DecoderTestBase::kSharedBufferSize;
1416 const uint32 GLES2DecoderTestBase::kSharedMemoryOffset;
1417 const int32 GLES2DecoderTestBase::kInvalidSharedMemoryId;
1418 const uint32 GLES2DecoderTestBase::kInvalidSharedMemoryOffset;
1419 const uint32 GLES2DecoderTestBase::kInitialResult;
1420 const uint8 GLES2DecoderTestBase::kInitialMemoryValue;
1422 const uint32 GLES2DecoderTestBase::kNewClientId;
1423 const uint32 GLES2DecoderTestBase::kNewServiceId;
1424 const uint32 GLES2DecoderTestBase::kInvalidClientId;
1426 const GLuint GLES2DecoderTestBase::kServiceVertexShaderId;
1427 const GLuint GLES2DecoderTestBase::kServiceFragmentShaderId;
1429 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumShaderId;
1430 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumProgramId;
1432 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTextureBufferId;
1433 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumVertexBufferId;
1434 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumFBOId;
1435 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumPositionAttrib;
1436 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTexAttrib;
1437 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumSamplerLocation;
1439 const GLsizei GLES2DecoderTestBase::kNumVertices;
1440 const GLsizei GLES2DecoderTestBase::kNumIndices;
1441 const int GLES2DecoderTestBase::kValidIndexRangeStart;
1442 const int GLES2DecoderTestBase::kValidIndexRangeCount;
1443 const int GLES2DecoderTestBase::kInvalidIndexRangeStart;
1444 const int GLES2DecoderTestBase::kInvalidIndexRangeCount;
1445 const int GLES2DecoderTestBase::kOutOfRangeIndexRangeEnd;
1446 const GLuint GLES2DecoderTestBase::kMaxValidIndex;
1448 const GLint GLES2DecoderTestBase::kMaxAttribLength;
1449 const GLint GLES2DecoderTestBase::kAttrib1Size;
1450 const GLint GLES2DecoderTestBase::kAttrib2Size;
1451 const GLint GLES2DecoderTestBase::kAttrib3Size;
1452 const GLint GLES2DecoderTestBase::kAttrib1Location;
1453 const GLint GLES2DecoderTestBase::kAttrib2Location;
1454 const GLint GLES2DecoderTestBase::kAttrib3Location;
1455 const GLenum GLES2DecoderTestBase::kAttrib1Type;
1456 const GLenum GLES2DecoderTestBase::kAttrib2Type;
1457 const GLenum GLES2DecoderTestBase::kAttrib3Type;
1458 const GLint GLES2DecoderTestBase::kInvalidAttribLocation;
1459 const GLint GLES2DecoderTestBase::kBadAttribIndex;
1461 const GLint GLES2DecoderTestBase::kMaxUniformLength;
1462 const GLint GLES2DecoderTestBase::kUniform1Size;
1463 const GLint GLES2DecoderTestBase::kUniform2Size;
1464 const GLint GLES2DecoderTestBase::kUniform3Size;
1465 const GLint GLES2DecoderTestBase::kUniform4Size;
1466 const GLint GLES2DecoderTestBase::kUniform5Size;
1467 const GLint GLES2DecoderTestBase::kUniform6Size;
1468 const GLint GLES2DecoderTestBase::kUniform7Size;
1469 const GLint GLES2DecoderTestBase::kUniform1RealLocation;
1470 const GLint GLES2DecoderTestBase::kUniform2RealLocation;
1471 const GLint GLES2DecoderTestBase::kUniform2ElementRealLocation;
1472 const GLint GLES2DecoderTestBase::kUniform3RealLocation;
1473 const GLint GLES2DecoderTestBase::kUniform4RealLocation;
1474 const GLint GLES2DecoderTestBase::kUniform5RealLocation;
1475 const GLint GLES2DecoderTestBase::kUniform6RealLocation;
1476 const GLint GLES2DecoderTestBase::kUniform7RealLocation;
1477 const GLint GLES2DecoderTestBase::kUniform1FakeLocation;
1478 const GLint GLES2DecoderTestBase::kUniform2FakeLocation;
1479 const GLint GLES2DecoderTestBase::kUniform2ElementFakeLocation;
1480 const GLint GLES2DecoderTestBase::kUniform3FakeLocation;
1481 const GLint GLES2DecoderTestBase::kUniform4FakeLocation;
1482 const GLint GLES2DecoderTestBase::kUniform5FakeLocation;
1483 const GLint GLES2DecoderTestBase::kUniform6FakeLocation;
1484 const GLint GLES2DecoderTestBase::kUniform7FakeLocation;
1485 const GLint GLES2DecoderTestBase::kUniform1DesiredLocation;
1486 const GLint GLES2DecoderTestBase::kUniform2DesiredLocation;
1487 const GLint GLES2DecoderTestBase::kUniform3DesiredLocation;
1488 const GLint GLES2DecoderTestBase::kUniform4DesiredLocation;
1489 const GLint GLES2DecoderTestBase::kUniform5DesiredLocation;
1490 const GLint GLES2DecoderTestBase::kUniform6DesiredLocation;
1491 const GLint GLES2DecoderTestBase::kUniform7DesiredLocation;
1492 const GLenum GLES2DecoderTestBase::kUniform1Type;
1493 const GLenum GLES2DecoderTestBase::kUniform2Type;
1494 const GLenum GLES2DecoderTestBase::kUniform3Type;
1495 const GLenum GLES2DecoderTestBase::kUniform4Type;
1496 const GLenum GLES2DecoderTestBase::kUniform5Type;
1497 const GLenum GLES2DecoderTestBase::kUniform6Type;
1498 const GLenum GLES2DecoderTestBase::kUniform7Type;
1499 const GLenum GLES2DecoderTestBase::kUniformCubemapType;
1500 const GLint GLES2DecoderTestBase::kInvalidUniformLocation;
1501 const GLint GLES2DecoderTestBase::kBadUniformIndex;
1503 #endif
1505 const char* GLES2DecoderTestBase::kAttrib1Name = "attrib1";
1506 const char* GLES2DecoderTestBase::kAttrib2Name = "attrib2";
1507 const char* GLES2DecoderTestBase::kAttrib3Name = "attrib3";
1508 const char* GLES2DecoderTestBase::kUniform1Name = "uniform1";
1509 const char* GLES2DecoderTestBase::kUniform2Name = "uniform2[0]";
1510 const char* GLES2DecoderTestBase::kUniform3Name = "uniform3[0]";
1511 const char* GLES2DecoderTestBase::kUniform4Name = "uniform4";
1512 const char* GLES2DecoderTestBase::kUniform5Name = "uniform5";
1513 const char* GLES2DecoderTestBase::kUniform6Name = "uniform6";
1514 const char* GLES2DecoderTestBase::kUniform7Name = "uniform7";
1516 void GLES2DecoderTestBase::SetupDefaultProgram() {
1518 static AttribInfo attribs[] = {
1519 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1520 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1521 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1523 static UniformInfo uniforms[] = {
1524 { kUniform1Name, kUniform1Size, kUniform1Type,
1525 kUniform1FakeLocation, kUniform1RealLocation,
1526 kUniform1DesiredLocation },
1527 { kUniform2Name, kUniform2Size, kUniform2Type,
1528 kUniform2FakeLocation, kUniform2RealLocation,
1529 kUniform2DesiredLocation },
1530 { kUniform3Name, kUniform3Size, kUniform3Type,
1531 kUniform3FakeLocation, kUniform3RealLocation,
1532 kUniform3DesiredLocation },
1533 { kUniform4Name, kUniform4Size, kUniform4Type,
1534 kUniform4FakeLocation, kUniform4RealLocation,
1535 kUniform4DesiredLocation },
1536 { kUniform5Name, kUniform5Size, kUniform5Type,
1537 kUniform5FakeLocation, kUniform5RealLocation,
1538 kUniform5DesiredLocation },
1539 { kUniform6Name, kUniform6Size, kUniform6Type,
1540 kUniform6FakeLocation, kUniform6RealLocation,
1541 kUniform6DesiredLocation },
1542 { kUniform7Name, kUniform7Size, kUniform7Type,
1543 kUniform7FakeLocation, kUniform7RealLocation,
1544 kUniform7DesiredLocation },
1546 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1547 client_program_id_, kServiceProgramId,
1548 client_vertex_shader_id_, kServiceVertexShaderId,
1549 client_fragment_shader_id_, kServiceFragmentShaderId);
1553 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1554 .Times(1)
1555 .RetiresOnSaturation();
1556 cmds::UseProgram cmd;
1557 cmd.Init(client_program_id_);
1558 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1562 void GLES2DecoderTestBase::SetupCubemapProgram() {
1564 static AttribInfo attribs[] = {
1565 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1566 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1567 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1569 static UniformInfo uniforms[] = {
1570 { kUniform1Name, kUniform1Size, kUniformCubemapType,
1571 kUniform1FakeLocation, kUniform1RealLocation,
1572 kUniform1DesiredLocation, },
1573 { kUniform2Name, kUniform2Size, kUniform2Type,
1574 kUniform2FakeLocation, kUniform2RealLocation,
1575 kUniform2DesiredLocation, },
1576 { kUniform3Name, kUniform3Size, kUniform3Type,
1577 kUniform3FakeLocation, kUniform3RealLocation,
1578 kUniform3DesiredLocation, },
1579 { kUniform4Name, kUniform4Size, kUniform4Type,
1580 kUniform4FakeLocation, kUniform4RealLocation,
1581 kUniform4DesiredLocation, },
1582 { kUniform5Name, kUniform5Size, kUniform5Type,
1583 kUniform5FakeLocation, kUniform5RealLocation,
1584 kUniform5DesiredLocation },
1585 { kUniform6Name, kUniform6Size, kUniform6Type,
1586 kUniform6FakeLocation, kUniform6RealLocation,
1587 kUniform6DesiredLocation },
1588 { kUniform7Name, kUniform7Size, kUniform7Type,
1589 kUniform7FakeLocation, kUniform7RealLocation,
1590 kUniform7DesiredLocation },
1592 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1593 client_program_id_, kServiceProgramId,
1594 client_vertex_shader_id_, kServiceVertexShaderId,
1595 client_fragment_shader_id_, kServiceFragmentShaderId);
1599 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1600 .Times(1)
1601 .RetiresOnSaturation();
1602 cmds::UseProgram cmd;
1603 cmd.Init(client_program_id_);
1604 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1608 void GLES2DecoderTestBase::SetupSamplerExternalProgram() {
1610 static AttribInfo attribs[] = {
1611 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1612 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1613 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1615 static UniformInfo uniforms[] = {
1616 { kUniform1Name, kUniform1Size, kUniformSamplerExternalType,
1617 kUniform1FakeLocation, kUniform1RealLocation,
1618 kUniform1DesiredLocation, },
1619 { kUniform2Name, kUniform2Size, kUniform2Type,
1620 kUniform2FakeLocation, kUniform2RealLocation,
1621 kUniform2DesiredLocation, },
1622 { kUniform3Name, kUniform3Size, kUniform3Type,
1623 kUniform3FakeLocation, kUniform3RealLocation,
1624 kUniform3DesiredLocation, },
1625 { kUniform4Name, kUniform4Size, kUniform4Type,
1626 kUniform4FakeLocation, kUniform4RealLocation,
1627 kUniform4DesiredLocation, },
1628 { kUniform5Name, kUniform5Size, kUniform5Type,
1629 kUniform5FakeLocation, kUniform5RealLocation,
1630 kUniform5DesiredLocation },
1631 { kUniform6Name, kUniform6Size, kUniform6Type,
1632 kUniform6FakeLocation, kUniform6RealLocation,
1633 kUniform6DesiredLocation },
1634 { kUniform7Name, kUniform7Size, kUniform7Type,
1635 kUniform7FakeLocation, kUniform7RealLocation,
1636 kUniform7DesiredLocation },
1638 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1639 client_program_id_, kServiceProgramId,
1640 client_vertex_shader_id_, kServiceVertexShaderId,
1641 client_fragment_shader_id_, kServiceFragmentShaderId);
1645 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1646 .Times(1)
1647 .RetiresOnSaturation();
1648 cmds::UseProgram cmd;
1649 cmd.Init(client_program_id_);
1650 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1654 void GLES2DecoderWithShaderTestBase::TearDown() {
1655 GLES2DecoderTestBase::TearDown();
1658 void GLES2DecoderTestBase::SetupShader(
1659 GLES2DecoderTestBase::AttribInfo* attribs, size_t num_attribs,
1660 GLES2DecoderTestBase::UniformInfo* uniforms, size_t num_uniforms,
1661 GLuint program_client_id, GLuint program_service_id,
1662 GLuint vertex_shader_client_id, GLuint vertex_shader_service_id,
1663 GLuint fragment_shader_client_id, GLuint fragment_shader_service_id) {
1665 InSequence s;
1667 EXPECT_CALL(*gl_,
1668 AttachShader(program_service_id, vertex_shader_service_id))
1669 .Times(1)
1670 .RetiresOnSaturation();
1671 EXPECT_CALL(*gl_,
1672 AttachShader(program_service_id, fragment_shader_service_id))
1673 .Times(1)
1674 .RetiresOnSaturation();
1675 TestHelper::SetupShader(
1676 gl_.get(), attribs, num_attribs, uniforms, num_uniforms,
1677 program_service_id);
1680 DoCreateShader(
1681 GL_VERTEX_SHADER, vertex_shader_client_id, vertex_shader_service_id);
1682 DoCreateShader(
1683 GL_FRAGMENT_SHADER, fragment_shader_client_id,
1684 fragment_shader_service_id);
1686 TestHelper::SetShaderStates(
1687 gl_.get(), GetShader(vertex_shader_client_id), true);
1688 TestHelper::SetShaderStates(
1689 gl_.get(), GetShader(fragment_shader_client_id), true);
1691 cmds::AttachShader attach_cmd;
1692 attach_cmd.Init(program_client_id, vertex_shader_client_id);
1693 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1695 attach_cmd.Init(program_client_id, fragment_shader_client_id);
1696 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1698 cmds::LinkProgram link_cmd;
1699 link_cmd.Init(program_client_id);
1701 EXPECT_EQ(error::kNoError, ExecuteCmd(link_cmd));
1704 void GLES2DecoderTestBase::DoEnableDisable(GLenum cap, bool enable) {
1705 SetupExpectationsForEnableDisable(cap, enable);
1706 if (enable) {
1707 cmds::Enable cmd;
1708 cmd.Init(cap);
1709 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1710 } else {
1711 cmds::Disable cmd;
1712 cmd.Init(cap);
1713 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1717 void GLES2DecoderTestBase::DoEnableVertexAttribArray(GLint index) {
1718 EXPECT_CALL(*gl_, EnableVertexAttribArray(index))
1719 .Times(1)
1720 .RetiresOnSaturation();
1721 cmds::EnableVertexAttribArray cmd;
1722 cmd.Init(index);
1723 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1726 void GLES2DecoderTestBase::DoBufferData(GLenum target, GLsizei size) {
1727 EXPECT_CALL(*gl_, GetError())
1728 .WillOnce(Return(GL_NO_ERROR))
1729 .RetiresOnSaturation();
1730 EXPECT_CALL(*gl_, BufferData(target, size, _, GL_STREAM_DRAW))
1731 .Times(1)
1732 .RetiresOnSaturation();
1733 EXPECT_CALL(*gl_, GetError())
1734 .WillOnce(Return(GL_NO_ERROR))
1735 .RetiresOnSaturation();
1736 cmds::BufferData cmd;
1737 cmd.Init(target, size, 0, 0, GL_STREAM_DRAW);
1738 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1741 void GLES2DecoderTestBase::DoBufferSubData(
1742 GLenum target, GLint offset, GLsizei size, const void* data) {
1743 EXPECT_CALL(*gl_, BufferSubData(target, offset, size,
1744 shared_memory_address_))
1745 .Times(1)
1746 .RetiresOnSaturation();
1747 memcpy(shared_memory_address_, data, size);
1748 cmds::BufferSubData cmd;
1749 cmd.Init(target, offset, size, shared_memory_id_, shared_memory_offset_);
1750 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1753 void GLES2DecoderTestBase::DoScissor(GLint x,
1754 GLint y,
1755 GLsizei width,
1756 GLsizei height) {
1757 EXPECT_CALL(*gl_, Scissor(x, y, width, height))
1758 .Times(1)
1759 .RetiresOnSaturation();
1760 cmds::Scissor cmd;
1761 cmd.Init(x, y, width, height);
1762 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1765 void GLES2DecoderTestBase::SetupVertexBuffer() {
1766 DoEnableVertexAttribArray(1);
1767 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1768 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 2 * sizeof(GLfloat));
1771 void GLES2DecoderTestBase::SetupAllNeededVertexBuffers() {
1772 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1773 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 16 * sizeof(float));
1774 DoEnableVertexAttribArray(0);
1775 DoEnableVertexAttribArray(1);
1776 DoEnableVertexAttribArray(2);
1777 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1778 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1779 DoVertexAttribPointer(2, 2, GL_FLOAT, 0, 0);
1782 void GLES2DecoderTestBase::SetupIndexBuffer() {
1783 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
1784 client_element_buffer_id_,
1785 kServiceElementBufferId);
1786 static const GLshort indices[] = {100, 1, 2, 3, 4, 5, 6, 7, 100, 9};
1787 static_assert(arraysize(indices) == kNumIndices,
1788 "indices should have kNumIndices elements");
1789 DoBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices));
1790 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, 2, indices);
1791 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 2, sizeof(indices) - 2, &indices[1]);
1794 void GLES2DecoderTestBase::SetupTexture() {
1795 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1796 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1797 kSharedMemoryId, kSharedMemoryOffset);
1800 void GLES2DecoderTestBase::DeleteVertexBuffer() {
1801 DoDeleteBuffer(client_buffer_id_, kServiceBufferId);
1804 void GLES2DecoderTestBase::DeleteIndexBuffer() {
1805 DoDeleteBuffer(client_element_buffer_id_, kServiceElementBufferId);
1808 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0WithError(
1809 GLsizei num_vertices, GLuint buffer_id, GLenum error) {
1810 if (group_->feature_info()->gl_version_info().BehavesLikeGLES()) {
1811 return;
1814 EXPECT_CALL(*gl_, GetError())
1815 .WillOnce(Return(GL_NO_ERROR))
1816 .WillOnce(Return(error))
1817 .RetiresOnSaturation();
1818 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
1819 .Times(1)
1820 .RetiresOnSaturation();
1821 EXPECT_CALL(*gl_, BufferData(GL_ARRAY_BUFFER,
1822 num_vertices * sizeof(GLfloat) * 4,
1823 _, GL_DYNAMIC_DRAW))
1824 .Times(1)
1825 .RetiresOnSaturation();
1826 if (error == GL_NO_ERROR) {
1827 EXPECT_CALL(*gl_, BufferSubData(
1828 GL_ARRAY_BUFFER, 0, num_vertices * sizeof(GLfloat) * 4, _))
1829 .Times(1)
1830 .RetiresOnSaturation();
1831 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL))
1832 .Times(1)
1833 .RetiresOnSaturation();
1834 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, buffer_id))
1835 .Times(1)
1836 .RetiresOnSaturation();
1840 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0(
1841 GLsizei num_vertices, GLuint buffer_id) {
1842 AddExpectationsForSimulatedAttrib0WithError(
1843 num_vertices, buffer_id, GL_NO_ERROR);
1846 void GLES2DecoderTestBase::SetupMockGLBehaviors() {
1847 ON_CALL(*gl_, BindVertexArrayOES(_))
1848 .WillByDefault(Invoke(
1849 &gl_states_,
1850 &GLES2DecoderTestBase::MockGLStates::OnBindVertexArrayOES));
1851 ON_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1852 .WillByDefault(WithArg<1>(Invoke(
1853 &gl_states_,
1854 &GLES2DecoderTestBase::MockGLStates::OnBindArrayBuffer)));
1855 ON_CALL(*gl_, VertexAttribPointer(_, _, _, _, _, NULL))
1856 .WillByDefault(InvokeWithoutArgs(
1857 &gl_states_,
1858 &GLES2DecoderTestBase::MockGLStates::OnVertexAttribNullPointer));
1861 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1862 MockCommandBufferEngine() {
1864 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory());
1865 shm->CreateAndMapAnonymous(kSharedBufferSize);
1866 valid_buffer_ = MakeBufferFromSharedMemory(shm.Pass(), kSharedBufferSize);
1868 ClearSharedMemory();
1871 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1872 ~MockCommandBufferEngine() {}
1874 scoped_refptr<gpu::Buffer>
1875 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetSharedMemoryBuffer(
1876 int32 shm_id) {
1877 return shm_id == kSharedMemoryId ? valid_buffer_ : invalid_buffer_;
1880 void GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::set_token(
1881 int32 token) {
1882 DCHECK(false);
1885 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetBuffer(
1886 int32 /* transfer_buffer_id */) {
1887 DCHECK(false);
1888 return false;
1891 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetOffset(
1892 int32 offset) {
1893 DCHECK(false);
1894 return false;
1897 int32 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetGetOffset() {
1898 DCHECK(false);
1899 return 0;
1902 void GLES2DecoderWithShaderTestBase::SetUp() {
1903 GLES2DecoderTestBase::SetUp();
1904 SetupDefaultProgram();
1907 // Include the auto-generated part of this file. We split this because it means
1908 // we can easily edit the non-auto generated parts right here in this file
1909 // instead of having to edit some template or the code generator.
1910 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h"
1912 } // namespace gles2
1913 } // namespace gpu