Don't add an aura tooltip to bubble close buttons on Windows.
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_base.cc
blob86481344fda2471d26da139c226ecaa69e85c748
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/gl_surface.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 (StartsWithASCII(init->gl_version, "opengl es", false)) {
67 init->extensions += kVAOExtensions[0];
68 } else {
69 #if !defined(OS_MACOSX)
70 init->extensions += kVAOExtensions[1];
71 #else
72 init->extensions += kVAOExtensions[2];
73 #endif // OS_MACOSX
75 } else {
76 // Make sure we don't set up an invalid InitState.
77 CHECK(!contains_vao_extension);
80 if (!init->extensions.empty())
81 init->extensions += " ";
82 init->extensions += "GL_EXT_framebuffer_object ";
85 } // namespace Anonymous
87 namespace gpu {
88 namespace gles2 {
90 GLES2DecoderTestBase::GLES2DecoderTestBase()
91 : surface_(NULL),
92 context_(NULL),
93 memory_tracker_(NULL),
94 client_buffer_id_(100),
95 client_framebuffer_id_(101),
96 client_program_id_(102),
97 client_renderbuffer_id_(103),
98 client_sampler_id_(104),
99 client_shader_id_(105),
100 client_texture_id_(106),
101 client_element_buffer_id_(107),
102 client_vertex_shader_id_(121),
103 client_fragment_shader_id_(122),
104 client_query_id_(123),
105 client_vertexarray_id_(124),
106 client_valuebuffer_id_(125),
107 client_transformfeedback_id_(126),
108 client_sync_id_(127),
109 service_renderbuffer_id_(0),
110 service_renderbuffer_valid_(false),
111 ignore_cached_state_for_test_(GetParam()),
112 cached_color_mask_red_(true),
113 cached_color_mask_green_(true),
114 cached_color_mask_blue_(true),
115 cached_color_mask_alpha_(true),
116 cached_depth_mask_(true),
117 cached_stencil_front_mask_(static_cast<GLuint>(-1)),
118 cached_stencil_back_mask_(static_cast<GLuint>(-1)) {
119 memset(immediate_buffer_, 0xEE, sizeof(immediate_buffer_));
122 GLES2DecoderTestBase::~GLES2DecoderTestBase() {}
124 void GLES2DecoderTestBase::SetUp() {
125 InitState init;
126 // Autogenerated tests do not overwrite version or extension string,
127 // so we have to pick something that supports everything here.
128 init.gl_version = "4.4";
129 init.extensions += " GL_ARB_compatibility";
130 init.has_alpha = true;
131 init.has_depth = true;
132 init.request_alpha = true;
133 init.request_depth = true;
134 init.bind_generates_resource = true;
135 InitDecoder(init);
138 void GLES2DecoderTestBase::AddExpectationsForVertexAttribManager() {
139 for (GLint ii = 0; ii < kNumVertexAttribs; ++ii) {
140 EXPECT_CALL(*gl_, VertexAttrib4f(ii, 0.0f, 0.0f, 0.0f, 1.0f))
141 .Times(1)
142 .RetiresOnSaturation();
146 GLES2DecoderTestBase::InitState::InitState()
147 : extensions("GL_EXT_framebuffer_object"),
148 gl_version("2.1"),
149 has_alpha(false),
150 has_depth(false),
151 has_stencil(false),
152 request_alpha(false),
153 request_depth(false),
154 request_stencil(false),
155 bind_generates_resource(false),
156 lose_context_when_out_of_memory(false),
157 use_native_vao(true) {
160 void GLES2DecoderTestBase::InitDecoder(const InitState& init) {
161 InitDecoderWithCommandLine(init, NULL);
164 void GLES2DecoderTestBase::InitDecoderWithCommandLine(
165 const InitState& init,
166 const base::CommandLine* command_line) {
167 InitState normalized_init = init;
168 NormalizeInitState(&normalized_init);
169 // For easier substring/extension matching
170 DCHECK(normalized_init.extensions.empty() ||
171 *normalized_init.extensions.rbegin() == ' ');
172 Framebuffer::ClearFramebufferCompleteComboMap();
174 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress);
175 gfx::GLSurface::InitializeOneOffWithMockBindingsForTests();
177 gl_.reset(new StrictMock<MockGLInterface>());
178 ::gfx::MockGLInterface::SetGLInterface(gl_.get());
180 SetupMockGLBehaviors();
182 scoped_refptr<FeatureInfo> feature_info;
183 if (command_line)
184 feature_info = new FeatureInfo(*command_line);
185 group_ = scoped_refptr<ContextGroup>(
186 new ContextGroup(NULL,
187 memory_tracker_,
188 new ShaderTranslatorCache,
189 feature_info.get(),
190 new SubscriptionRefSet,
191 new ValueStateMap,
192 normalized_init.bind_generates_resource));
193 bool use_default_textures = normalized_init.bind_generates_resource;
195 InSequence sequence;
197 surface_ = new gfx::GLSurfaceStub;
198 surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight));
200 // Context needs to be created before initializing ContextGroup, which will
201 // in turn initialize FeatureInfo, which needs a context to determine
202 // extension support.
203 context_ = new gfx::GLContextStubWithExtensions;
204 context_->AddExtensionsString(normalized_init.extensions.c_str());
205 context_->SetGLVersionString(normalized_init.gl_version.c_str());
207 context_->MakeCurrent(surface_.get());
208 gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_.get());
210 TestHelper::SetupContextGroupInitExpectations(
211 gl_.get(),
212 DisallowedFeatures(),
213 normalized_init.extensions.c_str(),
214 normalized_init.gl_version.c_str(),
215 normalized_init.bind_generates_resource);
217 // We initialize the ContextGroup with a MockGLES2Decoder so that
218 // we can use the ContextGroup to figure out how the real GLES2Decoder
219 // will initialize itself.
220 mock_decoder_.reset(new MockGLES2Decoder());
222 // Install FakeDoCommands handler so we can use individual DoCommand()
223 // expectations.
224 EXPECT_CALL(*mock_decoder_, DoCommands(_, _, _, _)).WillRepeatedly(
225 Invoke(mock_decoder_.get(), &MockGLES2Decoder::FakeDoCommands));
227 EXPECT_TRUE(
228 group_->Initialize(mock_decoder_.get(), DisallowedFeatures()));
230 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
231 EXPECT_CALL(*gl_, GenVertexArraysOES(1, _))
232 .WillOnce(SetArgumentPointee<1>(kServiceVertexArrayId))
233 .RetiresOnSaturation();
234 EXPECT_CALL(*gl_, BindVertexArrayOES(_)).Times(1).RetiresOnSaturation();
237 if (group_->feature_info()->workarounds().init_vertex_attributes)
238 AddExpectationsForVertexAttribManager();
240 AddExpectationsForBindVertexArrayOES();
242 EXPECT_CALL(*gl_, EnableVertexAttribArray(0))
243 .Times(1)
244 .RetiresOnSaturation();
245 static GLuint attrib_0_id[] = {
246 kServiceAttrib0BufferId,
248 static GLuint fixed_attrib_buffer_id[] = {
249 kServiceFixedAttribBufferId,
251 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(attrib_0_id), _))
252 .WillOnce(SetArrayArgument<1>(attrib_0_id,
253 attrib_0_id + arraysize(attrib_0_id)))
254 .RetiresOnSaturation();
255 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
256 .Times(1)
257 .RetiresOnSaturation();
258 EXPECT_CALL(*gl_, VertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL))
259 .Times(1)
260 .RetiresOnSaturation();
261 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
262 .Times(1)
263 .RetiresOnSaturation();
264 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(fixed_attrib_buffer_id), _))
265 .WillOnce(SetArrayArgument<1>(
266 fixed_attrib_buffer_id,
267 fixed_attrib_buffer_id + arraysize(fixed_attrib_buffer_id)))
268 .RetiresOnSaturation();
270 for (GLint tt = 0; tt < TestHelper::kNumTextureUnits; ++tt) {
271 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0 + tt))
272 .Times(1)
273 .RetiresOnSaturation();
274 if (group_->feature_info()->feature_flags().oes_egl_image_external) {
275 EXPECT_CALL(*gl_,
276 BindTexture(GL_TEXTURE_EXTERNAL_OES,
277 use_default_textures
278 ? TestHelper::kServiceDefaultExternalTextureId
279 : 0))
280 .Times(1)
281 .RetiresOnSaturation();
283 if (group_->feature_info()->feature_flags().arb_texture_rectangle) {
284 EXPECT_CALL(
285 *gl_,
286 BindTexture(GL_TEXTURE_RECTANGLE_ARB,
287 use_default_textures
288 ? TestHelper::kServiceDefaultRectangleTextureId
289 : 0))
290 .Times(1)
291 .RetiresOnSaturation();
293 EXPECT_CALL(*gl_,
294 BindTexture(GL_TEXTURE_CUBE_MAP,
295 use_default_textures
296 ? TestHelper::kServiceDefaultTextureCubemapId
297 : 0))
298 .Times(1)
299 .RetiresOnSaturation();
300 EXPECT_CALL(
301 *gl_,
302 BindTexture(
303 GL_TEXTURE_2D,
304 use_default_textures ? TestHelper::kServiceDefaultTexture2dId : 0))
305 .Times(1)
306 .RetiresOnSaturation();
308 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
309 .Times(1)
310 .RetiresOnSaturation();
312 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
313 .Times(1)
314 .RetiresOnSaturation();
315 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _))
316 .WillOnce(SetArgumentPointee<1>(normalized_init.has_alpha ? 8 : 0))
317 .RetiresOnSaturation();
318 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
319 .WillOnce(SetArgumentPointee<1>(normalized_init.has_depth ? 24 : 0))
320 .RetiresOnSaturation();
321 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
322 .WillOnce(SetArgumentPointee<1>(normalized_init.has_stencil ? 8 : 0))
323 .RetiresOnSaturation();
325 if (!group_->feature_info()->gl_version_info().BehavesLikeGLES()) {
326 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE))
327 .Times(1)
328 .RetiresOnSaturation();
330 EXPECT_CALL(*gl_, Enable(GL_POINT_SPRITE))
331 .Times(1)
332 .RetiresOnSaturation();
335 static GLint max_viewport_dims[] = {
336 kMaxViewportWidth,
337 kMaxViewportHeight
339 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VIEWPORT_DIMS, _))
340 .WillOnce(SetArrayArgument<1>(
341 max_viewport_dims, max_viewport_dims + arraysize(max_viewport_dims)))
342 .RetiresOnSaturation();
344 SetupInitCapabilitiesExpectations(group_->feature_info()->IsES3Capable());
345 SetupInitStateExpectations();
347 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
348 .Times(1)
349 .RetiresOnSaturation();
351 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0))
352 .Times(1)
353 .RetiresOnSaturation();
354 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0))
355 .Times(1)
356 .RetiresOnSaturation();
357 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0))
358 .Times(1)
359 .RetiresOnSaturation();
360 EXPECT_CALL(*gl_, BindRenderbufferEXT(GL_RENDERBUFFER, 0))
361 .Times(1)
362 .RetiresOnSaturation();
364 // TODO(boliu): Remove OS_ANDROID once crbug.com/259023 is fixed and the
365 // workaround has been reverted.
366 #if !defined(OS_ANDROID)
367 EXPECT_CALL(*gl_, Clear(
368 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
369 .Times(1)
370 .RetiresOnSaturation();
371 #endif
373 engine_.reset(new StrictMock<MockCommandBufferEngine>());
374 scoped_refptr<gpu::Buffer> buffer =
375 engine_->GetSharedMemoryBuffer(kSharedMemoryId);
376 shared_memory_offset_ = kSharedMemoryOffset;
377 shared_memory_address_ =
378 reinterpret_cast<int8*>(buffer->memory()) + shared_memory_offset_;
379 shared_memory_id_ = kSharedMemoryId;
380 shared_memory_base_ = buffer->memory();
382 static const int32 kLoseContextWhenOutOfMemory = 0x10002;
384 int32 attributes[] = {
385 EGL_ALPHA_SIZE,
386 normalized_init.request_alpha ? 8 : 0,
387 EGL_DEPTH_SIZE,
388 normalized_init.request_depth ? 24 : 0,
389 EGL_STENCIL_SIZE,
390 normalized_init.request_stencil ? 8 : 0,
391 kLoseContextWhenOutOfMemory,
392 normalized_init.lose_context_when_out_of_memory ? 1 : 0, };
393 std::vector<int32> attribs(attributes, attributes + arraysize(attributes));
395 decoder_.reset(GLES2Decoder::Create(group_.get()));
396 decoder_->SetIgnoreCachedStateForTest(ignore_cached_state_for_test_);
397 decoder_->GetLogger()->set_log_synthesized_gl_errors(false);
398 decoder_->Initialize(surface_,
399 context_,
400 false,
401 surface_->GetSize(),
402 DisallowedFeatures(),
403 attribs);
404 decoder_->MakeCurrent();
405 decoder_->set_engine(engine_.get());
406 decoder_->BeginDecoding();
408 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
409 .WillOnce(SetArgumentPointee<1>(kServiceBufferId))
410 .RetiresOnSaturation();
411 GenHelper<cmds::GenBuffersImmediate>(client_buffer_id_);
412 EXPECT_CALL(*gl_, GenFramebuffersEXT(_, _))
413 .WillOnce(SetArgumentPointee<1>(kServiceFramebufferId))
414 .RetiresOnSaturation();
415 GenHelper<cmds::GenFramebuffersImmediate>(client_framebuffer_id_);
416 EXPECT_CALL(*gl_, GenRenderbuffersEXT(_, _))
417 .WillOnce(SetArgumentPointee<1>(kServiceRenderbufferId))
418 .RetiresOnSaturation();
419 GenHelper<cmds::GenRenderbuffersImmediate>(client_renderbuffer_id_);
420 EXPECT_CALL(*gl_, GenTextures(_, _))
421 .WillOnce(SetArgumentPointee<1>(kServiceTextureId))
422 .RetiresOnSaturation();
423 GenHelper<cmds::GenTexturesImmediate>(client_texture_id_);
424 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
425 .WillOnce(SetArgumentPointee<1>(kServiceElementBufferId))
426 .RetiresOnSaturation();
427 GenHelper<cmds::GenBuffersImmediate>(client_element_buffer_id_);
429 DoCreateProgram(client_program_id_, kServiceProgramId);
430 DoCreateShader(GL_VERTEX_SHADER, client_shader_id_, kServiceShaderId);
432 // Unsafe commands.
433 bool reset_unsafe_es3_apis_enabled = false;
434 if (!decoder_->unsafe_es3_apis_enabled()) {
435 decoder_->set_unsafe_es3_apis_enabled(true);
436 reset_unsafe_es3_apis_enabled = true;
439 const gfx::GLVersionInfo* version = context_->GetVersionInfo();
440 if (version->IsAtLeastGL(3, 3) || version->IsAtLeastGLES(3, 0)) {
441 EXPECT_CALL(*gl_, GenSamplers(_, _))
442 .WillOnce(SetArgumentPointee<1>(kServiceSamplerId))
443 .RetiresOnSaturation();
444 GenHelper<cmds::GenSamplersImmediate>(client_sampler_id_);
446 if (version->IsAtLeastGL(4, 0) || version->IsAtLeastGLES(3, 0)) {
447 EXPECT_CALL(*gl_, GenTransformFeedbacks(_, _))
448 .WillOnce(SetArgumentPointee<1>(kServiceTransformFeedbackId))
449 .RetiresOnSaturation();
450 GenHelper<cmds::GenTransformFeedbacksImmediate>(
451 client_transformfeedback_id_);
454 if (init.extensions.find("GL_ARB_sync ") != std::string::npos ||
455 version->IsAtLeastGL(3, 2) || version->IsAtLeastGLES(3, 0)) {
456 DoFenceSync(client_sync_id_, kServiceSyncId);
459 if (reset_unsafe_es3_apis_enabled) {
460 decoder_->set_unsafe_es3_apis_enabled(false);
463 EXPECT_EQ(GL_NO_ERROR, GetGLError());
466 void GLES2DecoderTestBase::ResetDecoder() {
467 if (!decoder_.get())
468 return;
469 // All Tests should have read all their GLErrors before getting here.
470 EXPECT_EQ(GL_NO_ERROR, GetGLError());
472 EXPECT_CALL(*gl_, DeleteBuffersARB(1, _))
473 .Times(2)
474 .RetiresOnSaturation();
475 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
476 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, Pointee(kServiceVertexArrayId)))
477 .Times(1)
478 .RetiresOnSaturation();
481 decoder_->EndDecoding();
482 decoder_->Destroy(true);
483 decoder_.reset();
484 group_->Destroy(mock_decoder_.get(), false);
485 engine_.reset();
486 ::gfx::MockGLInterface::SetGLInterface(NULL);
487 gl_.reset();
488 gfx::ClearGLBindings();
491 void GLES2DecoderTestBase::TearDown() {
492 ResetDecoder();
495 void GLES2DecoderTestBase::ExpectEnableDisable(GLenum cap, bool enable) {
496 if (enable) {
497 EXPECT_CALL(*gl_, Enable(cap))
498 .Times(1)
499 .RetiresOnSaturation();
500 } else {
501 EXPECT_CALL(*gl_, Disable(cap))
502 .Times(1)
503 .RetiresOnSaturation();
508 GLint GLES2DecoderTestBase::GetGLError() {
509 EXPECT_CALL(*gl_, GetError())
510 .WillOnce(Return(GL_NO_ERROR))
511 .RetiresOnSaturation();
512 cmds::GetError cmd;
513 cmd.Init(shared_memory_id_, shared_memory_offset_);
514 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
515 return static_cast<GLint>(*GetSharedMemoryAs<GLenum*>());
518 void GLES2DecoderTestBase::DoCreateShader(
519 GLenum shader_type, GLuint client_id, GLuint service_id) {
520 EXPECT_CALL(*gl_, CreateShader(shader_type))
521 .Times(1)
522 .WillOnce(Return(service_id))
523 .RetiresOnSaturation();
524 cmds::CreateShader cmd;
525 cmd.Init(shader_type, client_id);
526 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
529 bool GLES2DecoderTestBase::DoIsShader(GLuint client_id) {
530 return IsObjectHelper<cmds::IsShader, cmds::IsShader::Result>(client_id);
533 void GLES2DecoderTestBase::DoDeleteShader(
534 GLuint client_id, GLuint service_id) {
535 EXPECT_CALL(*gl_, DeleteShader(service_id))
536 .Times(1)
537 .RetiresOnSaturation();
538 cmds::DeleteShader cmd;
539 cmd.Init(client_id);
540 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
543 void GLES2DecoderTestBase::DoCreateProgram(
544 GLuint client_id, GLuint service_id) {
545 EXPECT_CALL(*gl_, CreateProgram())
546 .Times(1)
547 .WillOnce(Return(service_id))
548 .RetiresOnSaturation();
549 cmds::CreateProgram cmd;
550 cmd.Init(client_id);
551 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
554 bool GLES2DecoderTestBase::DoIsProgram(GLuint client_id) {
555 return IsObjectHelper<cmds::IsProgram, cmds::IsProgram::Result>(client_id);
558 void GLES2DecoderTestBase::DoDeleteProgram(
559 GLuint client_id, GLuint /* service_id */) {
560 cmds::DeleteProgram cmd;
561 cmd.Init(client_id);
562 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
565 void GLES2DecoderTestBase::DoFenceSync(
566 GLuint client_id, GLuint service_id) {
567 EXPECT_CALL(*gl_, FenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0))
568 .Times(1)
569 .WillOnce(Return(reinterpret_cast<GLsync>(service_id)))
570 .RetiresOnSaturation();
571 cmds::FenceSync cmd;
572 cmd.Init(client_id);
573 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
576 void GLES2DecoderTestBase::SetBucketData(
577 uint32_t bucket_id, const void* data, uint32_t data_size) {
578 DCHECK(data || data_size == 0);
579 cmd::SetBucketSize cmd1;
580 cmd1.Init(bucket_id, data_size);
581 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
582 if (data) {
583 memcpy(shared_memory_address_, data, data_size);
584 cmd::SetBucketData cmd2;
585 cmd2.Init(bucket_id, 0, data_size, kSharedMemoryId, kSharedMemoryOffset);
586 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
587 ClearSharedMemory();
591 void GLES2DecoderTestBase::SetBucketAsCString(
592 uint32 bucket_id, const char* str) {
593 SetBucketData(bucket_id, str, str ? (strlen(str) + 1) : 0);
596 void GLES2DecoderTestBase::SetBucketAsCStrings(
597 uint32 bucket_id, GLsizei count, const char** str,
598 GLsizei count_in_header, char str_end) {
599 uint32_t header_size = sizeof(GLint) * (count + 1);
600 uint32_t total_size = header_size;
601 scoped_ptr<GLint[]> header(new GLint[count + 1]);
602 header[0] = static_cast<GLint>(count_in_header);
603 for (GLsizei ii = 0; ii < count; ++ii) {
604 header[ii + 1] = str && str[ii] ? strlen(str[ii]) : 0;
605 total_size += header[ii + 1] + 1;
607 cmd::SetBucketSize cmd1;
608 cmd1.Init(bucket_id, total_size);
609 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
610 memcpy(shared_memory_address_, header.get(), header_size);
611 uint32_t offset = header_size;
612 for (GLsizei ii = 0; ii < count; ++ii) {
613 if (str && str[ii]) {
614 size_t str_len = strlen(str[ii]);
615 memcpy(reinterpret_cast<char*>(shared_memory_address_) + offset,
616 str[ii], str_len);
617 offset += str_len;
619 memcpy(reinterpret_cast<char*>(shared_memory_address_) + offset,
620 &str_end, 1);
621 offset += 1;
623 cmd::SetBucketData cmd2;
624 cmd2.Init(bucket_id, 0, total_size, kSharedMemoryId, kSharedMemoryOffset);
625 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
626 ClearSharedMemory();
629 void GLES2DecoderTestBase::SetupClearTextureExpectations(
630 GLuint service_id,
631 GLuint old_service_id,
632 GLenum bind_target,
633 GLenum target,
634 GLint level,
635 GLenum internal_format,
636 GLenum format,
637 GLenum type,
638 GLsizei width,
639 GLsizei height) {
640 EXPECT_CALL(*gl_, BindTexture(bind_target, service_id))
641 .Times(1)
642 .RetiresOnSaturation();
643 EXPECT_CALL(*gl_, TexImage2D(
644 target, level, internal_format, width, height, 0, format, type, _))
645 .Times(1)
646 .RetiresOnSaturation();
647 EXPECT_CALL(*gl_, BindTexture(bind_target, old_service_id))
648 .Times(1)
649 .RetiresOnSaturation();
652 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearing(
653 GLenum target,
654 GLuint clear_bits,
655 GLclampf restore_red,
656 GLclampf restore_green,
657 GLclampf restore_blue,
658 GLclampf restore_alpha,
659 GLuint restore_stencil,
660 GLclampf restore_depth,
661 bool restore_scissor_test) {
662 SetupExpectationsForFramebufferClearingMulti(
665 target,
666 clear_bits,
667 restore_red,
668 restore_green,
669 restore_blue,
670 restore_alpha,
671 restore_stencil,
672 restore_depth,
673 restore_scissor_test);
676 void GLES2DecoderTestBase::SetupExpectationsForRestoreClearState(
677 GLclampf restore_red,
678 GLclampf restore_green,
679 GLclampf restore_blue,
680 GLclampf restore_alpha,
681 GLuint restore_stencil,
682 GLclampf restore_depth,
683 bool restore_scissor_test) {
684 EXPECT_CALL(*gl_, ClearColor(
685 restore_red, restore_green, restore_blue, restore_alpha))
686 .Times(1)
687 .RetiresOnSaturation();
688 EXPECT_CALL(*gl_, ClearStencil(restore_stencil))
689 .Times(1)
690 .RetiresOnSaturation();
691 EXPECT_CALL(*gl_, ClearDepth(restore_depth))
692 .Times(1)
693 .RetiresOnSaturation();
694 if (restore_scissor_test) {
695 EXPECT_CALL(*gl_, Enable(GL_SCISSOR_TEST))
696 .Times(1)
697 .RetiresOnSaturation();
701 void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearingMulti(
702 GLuint read_framebuffer_service_id,
703 GLuint draw_framebuffer_service_id,
704 GLenum target,
705 GLuint clear_bits,
706 GLclampf restore_red,
707 GLclampf restore_green,
708 GLclampf restore_blue,
709 GLclampf restore_alpha,
710 GLuint restore_stencil,
711 GLclampf restore_depth,
712 bool restore_scissor_test) {
713 // TODO(gman): Figure out why InSequence stopped working.
714 // InSequence sequence;
715 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(target))
716 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
717 .RetiresOnSaturation();
718 if (target == GL_READ_FRAMEBUFFER_EXT) {
719 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0))
720 .Times(1)
721 .RetiresOnSaturation();
722 EXPECT_CALL(*gl_, BindFramebufferEXT(
723 GL_DRAW_FRAMEBUFFER_EXT, read_framebuffer_service_id))
724 .Times(1)
725 .RetiresOnSaturation();
727 if ((clear_bits & GL_COLOR_BUFFER_BIT) != 0) {
728 EXPECT_CALL(*gl_, ClearColor(0.0f, 0.0f, 0.0f, 0.0f))
729 .Times(1)
730 .RetiresOnSaturation();
731 SetupExpectationsForColorMask(true, true, true, true);
733 if ((clear_bits & GL_STENCIL_BUFFER_BIT) != 0) {
734 EXPECT_CALL(*gl_, ClearStencil(0))
735 .Times(1)
736 .RetiresOnSaturation();
737 EXPECT_CALL(*gl_, StencilMask(static_cast<GLuint>(-1)))
738 .Times(1)
739 .RetiresOnSaturation();
741 if ((clear_bits & GL_DEPTH_BUFFER_BIT) != 0) {
742 EXPECT_CALL(*gl_, ClearDepth(1.0f))
743 .Times(1)
744 .RetiresOnSaturation();
745 SetupExpectationsForDepthMask(true);
747 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST, false);
748 EXPECT_CALL(*gl_, Clear(clear_bits))
749 .Times(1)
750 .RetiresOnSaturation();
751 SetupExpectationsForRestoreClearState(
752 restore_red, restore_green, restore_blue, restore_alpha,
753 restore_stencil, restore_depth, restore_scissor_test);
754 if (target == GL_READ_FRAMEBUFFER_EXT) {
755 EXPECT_CALL(*gl_, BindFramebufferEXT(
756 GL_READ_FRAMEBUFFER_EXT, read_framebuffer_service_id))
757 .Times(1)
758 .RetiresOnSaturation();
759 EXPECT_CALL(*gl_, BindFramebufferEXT(
760 GL_DRAW_FRAMEBUFFER_EXT, draw_framebuffer_service_id))
761 .Times(1)
762 .RetiresOnSaturation();
766 void GLES2DecoderTestBase::SetupShaderForUniform(GLenum uniform_type) {
767 static AttribInfo attribs[] = {
768 { "foo", 1, GL_FLOAT, 1, },
769 { "goo", 1, GL_FLOAT, 2, },
771 UniformInfo uniforms[] = {
772 { "bar", 1, uniform_type, 0, 2, -1, },
773 { "car", 4, uniform_type, 1, 1, -1, },
775 const GLuint kClientVertexShaderId = 5001;
776 const GLuint kServiceVertexShaderId = 6001;
777 const GLuint kClientFragmentShaderId = 5002;
778 const GLuint kServiceFragmentShaderId = 6002;
779 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
780 client_program_id_, kServiceProgramId,
781 kClientVertexShaderId, kServiceVertexShaderId,
782 kClientFragmentShaderId, kServiceFragmentShaderId);
784 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
785 .Times(1)
786 .RetiresOnSaturation();
787 cmds::UseProgram cmd;
788 cmd.Init(client_program_id_);
789 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
792 void GLES2DecoderTestBase::DoBindBuffer(
793 GLenum target, GLuint client_id, GLuint service_id) {
794 EXPECT_CALL(*gl_, BindBuffer(target, service_id))
795 .Times(1)
796 .RetiresOnSaturation();
797 cmds::BindBuffer cmd;
798 cmd.Init(target, client_id);
799 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
802 bool GLES2DecoderTestBase::DoIsBuffer(GLuint client_id) {
803 return IsObjectHelper<cmds::IsBuffer, cmds::IsBuffer::Result>(client_id);
806 void GLES2DecoderTestBase::DoDeleteBuffer(
807 GLuint client_id, GLuint service_id) {
808 EXPECT_CALL(*gl_, DeleteBuffersARB(1, Pointee(service_id)))
809 .Times(1)
810 .RetiresOnSaturation();
811 GenHelper<cmds::DeleteBuffersImmediate>(client_id);
814 void GLES2DecoderTestBase::SetupExpectationsForColorMask(bool red,
815 bool green,
816 bool blue,
817 bool alpha) {
818 if (ignore_cached_state_for_test_ || cached_color_mask_red_ != red ||
819 cached_color_mask_green_ != green || cached_color_mask_blue_ != blue ||
820 cached_color_mask_alpha_ != alpha) {
821 cached_color_mask_red_ = red;
822 cached_color_mask_green_ = green;
823 cached_color_mask_blue_ = blue;
824 cached_color_mask_alpha_ = alpha;
825 EXPECT_CALL(*gl_, ColorMask(red, green, blue, alpha))
826 .Times(1)
827 .RetiresOnSaturation();
831 void GLES2DecoderTestBase::SetupExpectationsForDepthMask(bool mask) {
832 if (ignore_cached_state_for_test_ || cached_depth_mask_ != mask) {
833 cached_depth_mask_ = mask;
834 EXPECT_CALL(*gl_, DepthMask(mask)).Times(1).RetiresOnSaturation();
838 void GLES2DecoderTestBase::SetupExpectationsForStencilMask(GLuint front_mask,
839 GLuint back_mask) {
840 if (ignore_cached_state_for_test_ ||
841 cached_stencil_front_mask_ != front_mask) {
842 cached_stencil_front_mask_ = front_mask;
843 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_FRONT, front_mask))
844 .Times(1)
845 .RetiresOnSaturation();
848 if (ignore_cached_state_for_test_ ||
849 cached_stencil_back_mask_ != back_mask) {
850 cached_stencil_back_mask_ = back_mask;
851 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_BACK, back_mask))
852 .Times(1)
853 .RetiresOnSaturation();
857 void GLES2DecoderTestBase::SetupExpectationsForEnableDisable(GLenum cap,
858 bool enable) {
859 switch (cap) {
860 case GL_BLEND:
861 if (enable_flags_.cached_blend == enable &&
862 !ignore_cached_state_for_test_)
863 return;
864 enable_flags_.cached_blend = enable;
865 break;
866 case GL_CULL_FACE:
867 if (enable_flags_.cached_cull_face == enable &&
868 !ignore_cached_state_for_test_)
869 return;
870 enable_flags_.cached_cull_face = enable;
871 break;
872 case GL_DEPTH_TEST:
873 if (enable_flags_.cached_depth_test == enable &&
874 !ignore_cached_state_for_test_)
875 return;
876 enable_flags_.cached_depth_test = enable;
877 break;
878 case GL_DITHER:
879 if (enable_flags_.cached_dither == enable &&
880 !ignore_cached_state_for_test_)
881 return;
882 enable_flags_.cached_dither = enable;
883 break;
884 case GL_POLYGON_OFFSET_FILL:
885 if (enable_flags_.cached_polygon_offset_fill == enable &&
886 !ignore_cached_state_for_test_)
887 return;
888 enable_flags_.cached_polygon_offset_fill = enable;
889 break;
890 case GL_SAMPLE_ALPHA_TO_COVERAGE:
891 if (enable_flags_.cached_sample_alpha_to_coverage == enable &&
892 !ignore_cached_state_for_test_)
893 return;
894 enable_flags_.cached_sample_alpha_to_coverage = enable;
895 break;
896 case GL_SAMPLE_COVERAGE:
897 if (enable_flags_.cached_sample_coverage == enable &&
898 !ignore_cached_state_for_test_)
899 return;
900 enable_flags_.cached_sample_coverage = enable;
901 break;
902 case GL_SCISSOR_TEST:
903 if (enable_flags_.cached_scissor_test == enable &&
904 !ignore_cached_state_for_test_)
905 return;
906 enable_flags_.cached_scissor_test = enable;
907 break;
908 case GL_STENCIL_TEST:
909 if (enable_flags_.cached_stencil_test == enable &&
910 !ignore_cached_state_for_test_)
911 return;
912 enable_flags_.cached_stencil_test = enable;
913 break;
914 default:
915 NOTREACHED();
916 return;
918 if (enable) {
919 EXPECT_CALL(*gl_, Enable(cap)).Times(1).RetiresOnSaturation();
920 } else {
921 EXPECT_CALL(*gl_, Disable(cap)).Times(1).RetiresOnSaturation();
925 void GLES2DecoderTestBase::SetupExpectationsForApplyingDirtyState(
926 bool framebuffer_is_rgb,
927 bool framebuffer_has_depth,
928 bool framebuffer_has_stencil,
929 GLuint color_bits,
930 bool depth_mask,
931 bool depth_enabled,
932 GLuint front_stencil_mask,
933 GLuint back_stencil_mask,
934 bool stencil_enabled) {
935 bool color_mask_red = (color_bits & 0x1000) != 0;
936 bool color_mask_green = (color_bits & 0x0100) != 0;
937 bool color_mask_blue = (color_bits & 0x0010) != 0;
938 bool color_mask_alpha = (color_bits & 0x0001) && !framebuffer_is_rgb;
940 SetupExpectationsForColorMask(
941 color_mask_red, color_mask_green, color_mask_blue, color_mask_alpha);
942 SetupExpectationsForDepthMask(depth_mask);
943 SetupExpectationsForStencilMask(front_stencil_mask, back_stencil_mask);
944 SetupExpectationsForEnableDisable(GL_DEPTH_TEST,
945 framebuffer_has_depth && depth_enabled);
946 SetupExpectationsForEnableDisable(GL_STENCIL_TEST,
947 framebuffer_has_stencil && stencil_enabled);
950 void GLES2DecoderTestBase::SetupExpectationsForApplyingDefaultDirtyState() {
951 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
952 false, // Framebuffer has depth
953 false, // Framebuffer has stencil
954 0x1111, // color bits
955 true, // depth mask
956 false, // depth enabled
957 0, // front stencil mask
958 0, // back stencil mask
959 false); // stencil enabled
962 GLES2DecoderTestBase::EnableFlags::EnableFlags()
963 : cached_blend(false),
964 cached_cull_face(false),
965 cached_depth_test(false),
966 cached_dither(true),
967 cached_polygon_offset_fill(false),
968 cached_sample_alpha_to_coverage(false),
969 cached_sample_coverage(false),
970 cached_scissor_test(false),
971 cached_stencil_test(false) {
974 void GLES2DecoderTestBase::DoBindFramebuffer(
975 GLenum target, GLuint client_id, GLuint service_id) {
976 EXPECT_CALL(*gl_, BindFramebufferEXT(target, service_id))
977 .Times(1)
978 .RetiresOnSaturation();
979 cmds::BindFramebuffer cmd;
980 cmd.Init(target, client_id);
981 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
984 bool GLES2DecoderTestBase::DoIsFramebuffer(GLuint client_id) {
985 return IsObjectHelper<cmds::IsFramebuffer, cmds::IsFramebuffer::Result>(
986 client_id);
989 void GLES2DecoderTestBase::DoDeleteFramebuffer(
990 GLuint client_id, GLuint service_id,
991 bool reset_draw, GLenum draw_target, GLuint draw_id,
992 bool reset_read, GLenum read_target, GLuint read_id) {
993 if (reset_draw) {
994 EXPECT_CALL(*gl_, BindFramebufferEXT(draw_target, draw_id))
995 .Times(1)
996 .RetiresOnSaturation();
998 if (reset_read) {
999 EXPECT_CALL(*gl_, BindFramebufferEXT(read_target, read_id))
1000 .Times(1)
1001 .RetiresOnSaturation();
1003 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, Pointee(service_id)))
1004 .Times(1)
1005 .RetiresOnSaturation();
1006 GenHelper<cmds::DeleteFramebuffersImmediate>(client_id);
1009 void GLES2DecoderTestBase::DoBindRenderbuffer(
1010 GLenum target, GLuint client_id, GLuint service_id) {
1011 service_renderbuffer_id_ = service_id;
1012 service_renderbuffer_valid_ = true;
1013 EXPECT_CALL(*gl_, BindRenderbufferEXT(target, service_id))
1014 .Times(1)
1015 .RetiresOnSaturation();
1016 cmds::BindRenderbuffer cmd;
1017 cmd.Init(target, client_id);
1018 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1021 void GLES2DecoderTestBase::DoRenderbufferStorageMultisampleCHROMIUM(
1022 GLenum target,
1023 GLsizei samples,
1024 GLenum internal_format,
1025 GLenum gl_format,
1026 GLsizei width,
1027 GLsizei height) {
1028 EXPECT_CALL(*gl_, GetError())
1029 .WillOnce(Return(GL_NO_ERROR))
1030 .RetiresOnSaturation();
1031 EXPECT_CALL(*gl_,
1032 RenderbufferStorageMultisampleEXT(
1033 target, samples, gl_format, width, height))
1034 .Times(1)
1035 .RetiresOnSaturation();
1036 EXPECT_CALL(*gl_, GetError())
1037 .WillOnce(Return(GL_NO_ERROR))
1038 .RetiresOnSaturation();
1039 cmds::RenderbufferStorageMultisampleCHROMIUM cmd;
1040 cmd.Init(target, samples, internal_format, width, height);
1041 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1042 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1045 void GLES2DecoderTestBase::RestoreRenderbufferBindings() {
1046 GetDecoder()->RestoreRenderbufferBindings();
1047 service_renderbuffer_valid_ = false;
1050 void GLES2DecoderTestBase::EnsureRenderbufferBound(bool expect_bind) {
1051 EXPECT_NE(expect_bind, service_renderbuffer_valid_);
1053 if (expect_bind) {
1054 service_renderbuffer_valid_ = true;
1055 EXPECT_CALL(*gl_,
1056 BindRenderbufferEXT(GL_RENDERBUFFER, service_renderbuffer_id_))
1057 .Times(1)
1058 .RetiresOnSaturation();
1059 } else {
1060 EXPECT_CALL(*gl_, BindRenderbufferEXT(_, _)).Times(0);
1064 bool GLES2DecoderTestBase::DoIsRenderbuffer(GLuint client_id) {
1065 return IsObjectHelper<cmds::IsRenderbuffer, cmds::IsRenderbuffer::Result>(
1066 client_id);
1069 void GLES2DecoderTestBase::DoDeleteRenderbuffer(
1070 GLuint client_id, GLuint service_id) {
1071 EXPECT_CALL(*gl_, DeleteRenderbuffersEXT(1, Pointee(service_id)))
1072 .Times(1)
1073 .RetiresOnSaturation();
1074 GenHelper<cmds::DeleteRenderbuffersImmediate>(client_id);
1077 void GLES2DecoderTestBase::DoBindTexture(
1078 GLenum target, GLuint client_id, GLuint service_id) {
1079 EXPECT_CALL(*gl_, BindTexture(target, service_id))
1080 .Times(1)
1081 .RetiresOnSaturation();
1082 cmds::BindTexture cmd;
1083 cmd.Init(target, client_id);
1084 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1087 bool GLES2DecoderTestBase::DoIsTexture(GLuint client_id) {
1088 return IsObjectHelper<cmds::IsTexture, cmds::IsTexture::Result>(client_id);
1091 void GLES2DecoderTestBase::DoDeleteTexture(
1092 GLuint client_id, GLuint service_id) {
1093 EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(service_id)))
1094 .Times(1)
1095 .RetiresOnSaturation();
1096 GenHelper<cmds::DeleteTexturesImmediate>(client_id);
1099 void GLES2DecoderTestBase::DoBindTexImage2DCHROMIUM(GLenum target,
1100 GLint image_id) {
1101 cmds::BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
1102 bind_tex_image_2d_cmd.Init(target, image_id);
1103 EXPECT_CALL(*gl_, GetError())
1104 .WillOnce(Return(GL_NO_ERROR))
1105 .WillOnce(Return(GL_NO_ERROR))
1106 .RetiresOnSaturation();
1107 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
1108 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1111 void GLES2DecoderTestBase::DoTexImage2D(
1112 GLenum target, GLint level, GLenum internal_format,
1113 GLsizei width, GLsizei height, GLint border,
1114 GLenum format, GLenum type,
1115 uint32 shared_memory_id, uint32 shared_memory_offset) {
1116 EXPECT_CALL(*gl_, GetError())
1117 .WillOnce(Return(GL_NO_ERROR))
1118 .RetiresOnSaturation();
1119 EXPECT_CALL(*gl_, TexImage2D(target, level, internal_format,
1120 width, height, border, format, type, _))
1121 .Times(1)
1122 .RetiresOnSaturation();
1123 EXPECT_CALL(*gl_, GetError())
1124 .WillOnce(Return(GL_NO_ERROR))
1125 .RetiresOnSaturation();
1126 cmds::TexImage2D cmd;
1127 cmd.Init(target, level, internal_format, width, height, format,
1128 type, shared_memory_id, shared_memory_offset);
1129 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1132 void GLES2DecoderTestBase::DoTexImage2DConvertInternalFormat(
1133 GLenum target, GLint level, GLenum requested_internal_format,
1134 GLsizei width, GLsizei height, GLint border,
1135 GLenum format, GLenum type,
1136 uint32 shared_memory_id, uint32 shared_memory_offset,
1137 GLenum expected_internal_format) {
1138 EXPECT_CALL(*gl_, GetError())
1139 .WillOnce(Return(GL_NO_ERROR))
1140 .RetiresOnSaturation();
1141 EXPECT_CALL(*gl_, TexImage2D(target, level, expected_internal_format,
1142 width, height, border, format, type, _))
1143 .Times(1)
1144 .RetiresOnSaturation();
1145 EXPECT_CALL(*gl_, GetError())
1146 .WillOnce(Return(GL_NO_ERROR))
1147 .RetiresOnSaturation();
1148 cmds::TexImage2D cmd;
1149 cmd.Init(target, level, requested_internal_format, width, height,
1150 format, type, shared_memory_id, shared_memory_offset);
1151 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1154 void GLES2DecoderTestBase::DoCompressedTexImage2D(
1155 GLenum target, GLint level, GLenum format,
1156 GLsizei width, GLsizei height, GLint border,
1157 GLsizei size, uint32 bucket_id) {
1158 EXPECT_CALL(*gl_, GetError())
1159 .WillOnce(Return(GL_NO_ERROR))
1160 .RetiresOnSaturation();
1161 EXPECT_CALL(*gl_, CompressedTexImage2D(
1162 target, level, format, width, height, border, size, _))
1163 .Times(1)
1164 .RetiresOnSaturation();
1165 EXPECT_CALL(*gl_, GetError())
1166 .WillOnce(Return(GL_NO_ERROR))
1167 .RetiresOnSaturation();
1168 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(bucket_id);
1169 bucket->SetSize(size);
1170 cmds::CompressedTexImage2DBucket cmd;
1171 cmd.Init(
1172 target, level, format, width, height,
1173 bucket_id);
1174 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1177 void GLES2DecoderTestBase::DoRenderbufferStorage(
1178 GLenum target, GLenum internal_format, GLenum actual_format,
1179 GLsizei width, GLsizei height, GLenum error) {
1180 EXPECT_CALL(*gl_, GetError())
1181 .WillOnce(Return(GL_NO_ERROR))
1182 .RetiresOnSaturation();
1183 EXPECT_CALL(*gl_, RenderbufferStorageEXT(
1184 target, actual_format, width, height))
1185 .Times(1)
1186 .RetiresOnSaturation();
1187 EXPECT_CALL(*gl_, GetError())
1188 .WillOnce(Return(error))
1189 .RetiresOnSaturation();
1190 cmds::RenderbufferStorage cmd;
1191 cmd.Init(target, internal_format, width, height);
1192 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1195 void GLES2DecoderTestBase::DoFramebufferTexture2D(
1196 GLenum target, GLenum attachment, GLenum textarget,
1197 GLuint texture_client_id, GLuint texture_service_id, GLint level,
1198 GLenum error) {
1199 EXPECT_CALL(*gl_, GetError())
1200 .WillOnce(Return(GL_NO_ERROR))
1201 .RetiresOnSaturation();
1202 EXPECT_CALL(*gl_, FramebufferTexture2DEXT(
1203 target, attachment, textarget, texture_service_id, level))
1204 .Times(1)
1205 .RetiresOnSaturation();
1206 EXPECT_CALL(*gl_, GetError())
1207 .WillOnce(Return(error))
1208 .RetiresOnSaturation();
1209 cmds::FramebufferTexture2D cmd;
1210 cmd.Init(target, attachment, textarget, texture_client_id);
1211 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1214 void GLES2DecoderTestBase::DoFramebufferRenderbuffer(
1215 GLenum target,
1216 GLenum attachment,
1217 GLenum renderbuffer_target,
1218 GLuint renderbuffer_client_id,
1219 GLuint renderbuffer_service_id,
1220 GLenum error) {
1221 EXPECT_CALL(*gl_, GetError())
1222 .WillOnce(Return(GL_NO_ERROR))
1223 .RetiresOnSaturation();
1224 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
1225 target, attachment, renderbuffer_target, renderbuffer_service_id))
1226 .Times(1)
1227 .RetiresOnSaturation();
1228 EXPECT_CALL(*gl_, GetError())
1229 .WillOnce(Return(error))
1230 .RetiresOnSaturation();
1231 cmds::FramebufferRenderbuffer cmd;
1232 cmd.Init(target, attachment, renderbuffer_target, renderbuffer_client_id);
1233 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1236 void GLES2DecoderTestBase::DoVertexAttribPointer(
1237 GLuint index, GLint size, GLenum type, GLsizei stride, GLuint offset) {
1238 EXPECT_CALL(*gl_,
1239 VertexAttribPointer(index, size, type, GL_FALSE, stride,
1240 BufferOffset(offset)))
1241 .Times(1)
1242 .RetiresOnSaturation();
1243 cmds::VertexAttribPointer cmd;
1244 cmd.Init(index, size, GL_FLOAT, GL_FALSE, stride, offset);
1245 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1248 void GLES2DecoderTestBase::DoVertexAttribDivisorANGLE(
1249 GLuint index, GLuint divisor) {
1250 EXPECT_CALL(*gl_,
1251 VertexAttribDivisorANGLE(index, divisor))
1252 .Times(1)
1253 .RetiresOnSaturation();
1254 cmds::VertexAttribDivisorANGLE cmd;
1255 cmd.Init(index, divisor);
1256 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1259 void GLES2DecoderTestBase::AddExpectationsForGenVertexArraysOES(){
1260 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
1261 EXPECT_CALL(*gl_, GenVertexArraysOES(1, _))
1262 .WillOnce(SetArgumentPointee<1>(kServiceVertexArrayId))
1263 .RetiresOnSaturation();
1267 void GLES2DecoderTestBase::AddExpectationsForDeleteVertexArraysOES(){
1268 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
1269 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, _))
1270 .Times(1)
1271 .RetiresOnSaturation();
1275 void GLES2DecoderTestBase::AddExpectationsForDeleteBoundVertexArraysOES() {
1276 // Expectations are the same as a delete, followed by binding VAO 0.
1277 AddExpectationsForDeleteVertexArraysOES();
1278 AddExpectationsForBindVertexArrayOES();
1281 void GLES2DecoderTestBase::AddExpectationsForBindVertexArrayOES() {
1282 if (group_->feature_info()->feature_flags().native_vertex_array_object) {
1283 EXPECT_CALL(*gl_, BindVertexArrayOES(_))
1284 .Times(1)
1285 .RetiresOnSaturation();
1286 } else {
1287 for (uint32 vv = 0; vv < group_->max_vertex_attribs(); ++vv) {
1288 AddExpectationsForRestoreAttribState(vv);
1291 EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _))
1292 .Times(1)
1293 .RetiresOnSaturation();
1297 void GLES2DecoderTestBase::AddExpectationsForRestoreAttribState(GLuint attrib) {
1298 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1299 .Times(1)
1300 .RetiresOnSaturation();
1302 EXPECT_CALL(*gl_, VertexAttribPointer(attrib, _, _, _, _, _))
1303 .Times(1)
1304 .RetiresOnSaturation();
1306 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(attrib, _))
1307 .Times(testing::AtMost(1))
1308 .RetiresOnSaturation();
1310 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1311 .Times(1)
1312 .RetiresOnSaturation();
1314 if (attrib != 0 ||
1315 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
1317 // TODO(bajones): Not sure if I can tell which of these will be called
1318 EXPECT_CALL(*gl_, EnableVertexAttribArray(attrib))
1319 .Times(testing::AtMost(1))
1320 .RetiresOnSaturation();
1322 EXPECT_CALL(*gl_, DisableVertexAttribArray(attrib))
1323 .Times(testing::AtMost(1))
1324 .RetiresOnSaturation();
1328 // GCC requires these declarations, but MSVC requires they not be present
1329 #ifndef COMPILER_MSVC
1330 const int GLES2DecoderTestBase::kBackBufferWidth;
1331 const int GLES2DecoderTestBase::kBackBufferHeight;
1333 const GLint GLES2DecoderTestBase::kMaxTextureSize;
1334 const GLint GLES2DecoderTestBase::kMaxCubeMapTextureSize;
1335 const GLint GLES2DecoderTestBase::kNumVertexAttribs;
1336 const GLint GLES2DecoderTestBase::kNumTextureUnits;
1337 const GLint GLES2DecoderTestBase::kMaxTextureImageUnits;
1338 const GLint GLES2DecoderTestBase::kMaxVertexTextureImageUnits;
1339 const GLint GLES2DecoderTestBase::kMaxFragmentUniformVectors;
1340 const GLint GLES2DecoderTestBase::kMaxVaryingVectors;
1341 const GLint GLES2DecoderTestBase::kMaxVertexUniformVectors;
1342 const GLint GLES2DecoderTestBase::kMaxViewportWidth;
1343 const GLint GLES2DecoderTestBase::kMaxViewportHeight;
1345 const GLint GLES2DecoderTestBase::kViewportX;
1346 const GLint GLES2DecoderTestBase::kViewportY;
1347 const GLint GLES2DecoderTestBase::kViewportWidth;
1348 const GLint GLES2DecoderTestBase::kViewportHeight;
1350 const GLuint GLES2DecoderTestBase::kServiceAttrib0BufferId;
1351 const GLuint GLES2DecoderTestBase::kServiceFixedAttribBufferId;
1353 const GLuint GLES2DecoderTestBase::kServiceBufferId;
1354 const GLuint GLES2DecoderTestBase::kServiceFramebufferId;
1355 const GLuint GLES2DecoderTestBase::kServiceRenderbufferId;
1356 const GLuint GLES2DecoderTestBase::kServiceSamplerId;
1357 const GLuint GLES2DecoderTestBase::kServiceTextureId;
1358 const GLuint GLES2DecoderTestBase::kServiceProgramId;
1359 const GLuint GLES2DecoderTestBase::kServiceShaderId;
1360 const GLuint GLES2DecoderTestBase::kServiceElementBufferId;
1361 const GLuint GLES2DecoderTestBase::kServiceQueryId;
1362 const GLuint GLES2DecoderTestBase::kServiceVertexArrayId;
1363 const GLuint GLES2DecoderTestBase::kServiceTransformFeedbackId;
1364 const GLuint GLES2DecoderTestBase::kServiceSyncId;
1366 const int32 GLES2DecoderTestBase::kSharedMemoryId;
1367 const size_t GLES2DecoderTestBase::kSharedBufferSize;
1368 const uint32 GLES2DecoderTestBase::kSharedMemoryOffset;
1369 const int32 GLES2DecoderTestBase::kInvalidSharedMemoryId;
1370 const uint32 GLES2DecoderTestBase::kInvalidSharedMemoryOffset;
1371 const uint32 GLES2DecoderTestBase::kInitialResult;
1372 const uint8 GLES2DecoderTestBase::kInitialMemoryValue;
1374 const uint32 GLES2DecoderTestBase::kNewClientId;
1375 const uint32 GLES2DecoderTestBase::kNewServiceId;
1376 const uint32 GLES2DecoderTestBase::kInvalidClientId;
1378 const GLuint GLES2DecoderTestBase::kServiceVertexShaderId;
1379 const GLuint GLES2DecoderTestBase::kServiceFragmentShaderId;
1381 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumShaderId;
1382 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumProgramId;
1384 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTextureBufferId;
1385 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumVertexBufferId;
1386 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumFBOId;
1387 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumPositionAttrib;
1388 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTexAttrib;
1389 const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumSamplerLocation;
1391 const GLsizei GLES2DecoderTestBase::kNumVertices;
1392 const GLsizei GLES2DecoderTestBase::kNumIndices;
1393 const int GLES2DecoderTestBase::kValidIndexRangeStart;
1394 const int GLES2DecoderTestBase::kValidIndexRangeCount;
1395 const int GLES2DecoderTestBase::kInvalidIndexRangeStart;
1396 const int GLES2DecoderTestBase::kInvalidIndexRangeCount;
1397 const int GLES2DecoderTestBase::kOutOfRangeIndexRangeEnd;
1398 const GLuint GLES2DecoderTestBase::kMaxValidIndex;
1400 const GLint GLES2DecoderTestBase::kMaxAttribLength;
1401 const GLint GLES2DecoderTestBase::kAttrib1Size;
1402 const GLint GLES2DecoderTestBase::kAttrib2Size;
1403 const GLint GLES2DecoderTestBase::kAttrib3Size;
1404 const GLint GLES2DecoderTestBase::kAttrib1Location;
1405 const GLint GLES2DecoderTestBase::kAttrib2Location;
1406 const GLint GLES2DecoderTestBase::kAttrib3Location;
1407 const GLenum GLES2DecoderTestBase::kAttrib1Type;
1408 const GLenum GLES2DecoderTestBase::kAttrib2Type;
1409 const GLenum GLES2DecoderTestBase::kAttrib3Type;
1410 const GLint GLES2DecoderTestBase::kInvalidAttribLocation;
1411 const GLint GLES2DecoderTestBase::kBadAttribIndex;
1413 const GLint GLES2DecoderTestBase::kMaxUniformLength;
1414 const GLint GLES2DecoderTestBase::kUniform1Size;
1415 const GLint GLES2DecoderTestBase::kUniform2Size;
1416 const GLint GLES2DecoderTestBase::kUniform3Size;
1417 const GLint GLES2DecoderTestBase::kUniform1RealLocation;
1418 const GLint GLES2DecoderTestBase::kUniform2RealLocation;
1419 const GLint GLES2DecoderTestBase::kUniform2ElementRealLocation;
1420 const GLint GLES2DecoderTestBase::kUniform3RealLocation;
1421 const GLint GLES2DecoderTestBase::kUniform1FakeLocation;
1422 const GLint GLES2DecoderTestBase::kUniform2FakeLocation;
1423 const GLint GLES2DecoderTestBase::kUniform2ElementFakeLocation;
1424 const GLint GLES2DecoderTestBase::kUniform3FakeLocation;
1425 const GLint GLES2DecoderTestBase::kUniform1DesiredLocation;
1426 const GLint GLES2DecoderTestBase::kUniform2DesiredLocation;
1427 const GLint GLES2DecoderTestBase::kUniform3DesiredLocation;
1428 const GLenum GLES2DecoderTestBase::kUniform1Type;
1429 const GLenum GLES2DecoderTestBase::kUniform2Type;
1430 const GLenum GLES2DecoderTestBase::kUniform3Type;
1431 const GLenum GLES2DecoderTestBase::kUniformCubemapType;
1432 const GLint GLES2DecoderTestBase::kInvalidUniformLocation;
1433 const GLint GLES2DecoderTestBase::kBadUniformIndex;
1435 #endif
1437 const char* GLES2DecoderTestBase::kAttrib1Name = "attrib1";
1438 const char* GLES2DecoderTestBase::kAttrib2Name = "attrib2";
1439 const char* GLES2DecoderTestBase::kAttrib3Name = "attrib3";
1440 const char* GLES2DecoderTestBase::kUniform1Name = "uniform1";
1441 const char* GLES2DecoderTestBase::kUniform2Name = "uniform2[0]";
1442 const char* GLES2DecoderTestBase::kUniform3Name = "uniform3[0]";
1444 void GLES2DecoderTestBase::SetupDefaultProgram() {
1446 static AttribInfo attribs[] = {
1447 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1448 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1449 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1451 static UniformInfo uniforms[] = {
1452 { kUniform1Name, kUniform1Size, kUniform1Type,
1453 kUniform1FakeLocation, kUniform1RealLocation,
1454 kUniform1DesiredLocation },
1455 { kUniform2Name, kUniform2Size, kUniform2Type,
1456 kUniform2FakeLocation, kUniform2RealLocation,
1457 kUniform2DesiredLocation },
1458 { kUniform3Name, kUniform3Size, kUniform3Type,
1459 kUniform3FakeLocation, kUniform3RealLocation,
1460 kUniform3DesiredLocation },
1462 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1463 client_program_id_, kServiceProgramId,
1464 client_vertex_shader_id_, kServiceVertexShaderId,
1465 client_fragment_shader_id_, kServiceFragmentShaderId);
1469 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1470 .Times(1)
1471 .RetiresOnSaturation();
1472 cmds::UseProgram cmd;
1473 cmd.Init(client_program_id_);
1474 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1478 void GLES2DecoderTestBase::SetupCubemapProgram() {
1480 static AttribInfo attribs[] = {
1481 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1482 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1483 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1485 static UniformInfo uniforms[] = {
1486 { kUniform1Name, kUniform1Size, kUniformCubemapType,
1487 kUniform1FakeLocation, kUniform1RealLocation,
1488 kUniform1DesiredLocation, },
1489 { kUniform2Name, kUniform2Size, kUniform2Type,
1490 kUniform2FakeLocation, kUniform2RealLocation,
1491 kUniform2DesiredLocation, },
1492 { kUniform3Name, kUniform3Size, kUniform3Type,
1493 kUniform3FakeLocation, kUniform3RealLocation,
1494 kUniform3DesiredLocation, },
1496 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1497 client_program_id_, kServiceProgramId,
1498 client_vertex_shader_id_, kServiceVertexShaderId,
1499 client_fragment_shader_id_, kServiceFragmentShaderId);
1503 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1504 .Times(1)
1505 .RetiresOnSaturation();
1506 cmds::UseProgram cmd;
1507 cmd.Init(client_program_id_);
1508 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1512 void GLES2DecoderTestBase::SetupSamplerExternalProgram() {
1514 static AttribInfo attribs[] = {
1515 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1516 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1517 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1519 static UniformInfo uniforms[] = {
1520 { kUniform1Name, kUniform1Size, kUniformSamplerExternalType,
1521 kUniform1FakeLocation, kUniform1RealLocation,
1522 kUniform1DesiredLocation, },
1523 { kUniform2Name, kUniform2Size, kUniform2Type,
1524 kUniform2FakeLocation, kUniform2RealLocation,
1525 kUniform2DesiredLocation, },
1526 { kUniform3Name, kUniform3Size, kUniform3Type,
1527 kUniform3FakeLocation, kUniform3RealLocation,
1528 kUniform3DesiredLocation, },
1530 SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms),
1531 client_program_id_, kServiceProgramId,
1532 client_vertex_shader_id_, kServiceVertexShaderId,
1533 client_fragment_shader_id_, kServiceFragmentShaderId);
1537 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
1538 .Times(1)
1539 .RetiresOnSaturation();
1540 cmds::UseProgram cmd;
1541 cmd.Init(client_program_id_);
1542 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1546 void GLES2DecoderWithShaderTestBase::TearDown() {
1547 GLES2DecoderTestBase::TearDown();
1550 void GLES2DecoderTestBase::SetupShader(
1551 GLES2DecoderTestBase::AttribInfo* attribs, size_t num_attribs,
1552 GLES2DecoderTestBase::UniformInfo* uniforms, size_t num_uniforms,
1553 GLuint program_client_id, GLuint program_service_id,
1554 GLuint vertex_shader_client_id, GLuint vertex_shader_service_id,
1555 GLuint fragment_shader_client_id, GLuint fragment_shader_service_id) {
1557 InSequence s;
1559 EXPECT_CALL(*gl_,
1560 AttachShader(program_service_id, vertex_shader_service_id))
1561 .Times(1)
1562 .RetiresOnSaturation();
1563 EXPECT_CALL(*gl_,
1564 AttachShader(program_service_id, fragment_shader_service_id))
1565 .Times(1)
1566 .RetiresOnSaturation();
1567 TestHelper::SetupShader(
1568 gl_.get(), attribs, num_attribs, uniforms, num_uniforms,
1569 program_service_id);
1572 DoCreateShader(
1573 GL_VERTEX_SHADER, vertex_shader_client_id, vertex_shader_service_id);
1574 DoCreateShader(
1575 GL_FRAGMENT_SHADER, fragment_shader_client_id,
1576 fragment_shader_service_id);
1578 TestHelper::SetShaderStates(
1579 gl_.get(), GetShader(vertex_shader_client_id), true);
1580 TestHelper::SetShaderStates(
1581 gl_.get(), GetShader(fragment_shader_client_id), true);
1583 cmds::AttachShader attach_cmd;
1584 attach_cmd.Init(program_client_id, vertex_shader_client_id);
1585 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1587 attach_cmd.Init(program_client_id, fragment_shader_client_id);
1588 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1590 cmds::LinkProgram link_cmd;
1591 link_cmd.Init(program_client_id);
1593 EXPECT_EQ(error::kNoError, ExecuteCmd(link_cmd));
1596 void GLES2DecoderTestBase::DoEnableDisable(GLenum cap, bool enable) {
1597 SetupExpectationsForEnableDisable(cap, enable);
1598 if (enable) {
1599 cmds::Enable cmd;
1600 cmd.Init(cap);
1601 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1602 } else {
1603 cmds::Disable cmd;
1604 cmd.Init(cap);
1605 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1609 void GLES2DecoderTestBase::DoEnableVertexAttribArray(GLint index) {
1610 EXPECT_CALL(*gl_, EnableVertexAttribArray(index))
1611 .Times(1)
1612 .RetiresOnSaturation();
1613 cmds::EnableVertexAttribArray cmd;
1614 cmd.Init(index);
1615 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1618 void GLES2DecoderTestBase::DoBufferData(GLenum target, GLsizei size) {
1619 EXPECT_CALL(*gl_, GetError())
1620 .WillOnce(Return(GL_NO_ERROR))
1621 .RetiresOnSaturation();
1622 EXPECT_CALL(*gl_, BufferData(target, size, _, GL_STREAM_DRAW))
1623 .Times(1)
1624 .RetiresOnSaturation();
1625 EXPECT_CALL(*gl_, GetError())
1626 .WillOnce(Return(GL_NO_ERROR))
1627 .RetiresOnSaturation();
1628 cmds::BufferData cmd;
1629 cmd.Init(target, size, 0, 0, GL_STREAM_DRAW);
1630 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1633 void GLES2DecoderTestBase::DoBufferSubData(
1634 GLenum target, GLint offset, GLsizei size, const void* data) {
1635 EXPECT_CALL(*gl_, BufferSubData(target, offset, size,
1636 shared_memory_address_))
1637 .Times(1)
1638 .RetiresOnSaturation();
1639 memcpy(shared_memory_address_, data, size);
1640 cmds::BufferSubData cmd;
1641 cmd.Init(target, offset, size, shared_memory_id_, shared_memory_offset_);
1642 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1645 void GLES2DecoderTestBase::SetupVertexBuffer() {
1646 DoEnableVertexAttribArray(1);
1647 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1648 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 2 * sizeof(GLfloat));
1651 void GLES2DecoderTestBase::SetupAllNeededVertexBuffers() {
1652 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1653 DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 16 * sizeof(float));
1654 DoEnableVertexAttribArray(0);
1655 DoEnableVertexAttribArray(1);
1656 DoEnableVertexAttribArray(2);
1657 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1658 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1659 DoVertexAttribPointer(2, 2, GL_FLOAT, 0, 0);
1662 void GLES2DecoderTestBase::SetupIndexBuffer() {
1663 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
1664 client_element_buffer_id_,
1665 kServiceElementBufferId);
1666 static const GLshort indices[] = {100, 1, 2, 3, 4, 5, 6, 7, 100, 9};
1667 static_assert(arraysize(indices) == kNumIndices,
1668 "indices should have kNumIndices elements");
1669 DoBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices));
1670 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, 2, indices);
1671 DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 2, sizeof(indices) - 2, &indices[1]);
1674 void GLES2DecoderTestBase::SetupTexture() {
1675 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1676 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1677 kSharedMemoryId, kSharedMemoryOffset);
1680 void GLES2DecoderTestBase::DeleteVertexBuffer() {
1681 DoDeleteBuffer(client_buffer_id_, kServiceBufferId);
1684 void GLES2DecoderTestBase::DeleteIndexBuffer() {
1685 DoDeleteBuffer(client_element_buffer_id_, kServiceElementBufferId);
1688 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0WithError(
1689 GLsizei num_vertices, GLuint buffer_id, GLenum error) {
1690 if (group_->feature_info()->gl_version_info().BehavesLikeGLES()) {
1691 return;
1694 EXPECT_CALL(*gl_, GetError())
1695 .WillOnce(Return(GL_NO_ERROR))
1696 .WillOnce(Return(error))
1697 .RetiresOnSaturation();
1698 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId))
1699 .Times(1)
1700 .RetiresOnSaturation();
1701 EXPECT_CALL(*gl_, BufferData(GL_ARRAY_BUFFER,
1702 num_vertices * sizeof(GLfloat) * 4,
1703 _, GL_DYNAMIC_DRAW))
1704 .Times(1)
1705 .RetiresOnSaturation();
1706 if (error == GL_NO_ERROR) {
1707 EXPECT_CALL(*gl_, BufferSubData(
1708 GL_ARRAY_BUFFER, 0, num_vertices * sizeof(GLfloat) * 4, _))
1709 .Times(1)
1710 .RetiresOnSaturation();
1711 EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL))
1712 .Times(1)
1713 .RetiresOnSaturation();
1714 EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, buffer_id))
1715 .Times(1)
1716 .RetiresOnSaturation();
1720 void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0(
1721 GLsizei num_vertices, GLuint buffer_id) {
1722 AddExpectationsForSimulatedAttrib0WithError(
1723 num_vertices, buffer_id, GL_NO_ERROR);
1726 void GLES2DecoderTestBase::SetupMockGLBehaviors() {
1727 ON_CALL(*gl_, BindVertexArrayOES(_))
1728 .WillByDefault(Invoke(
1729 &gl_states_,
1730 &GLES2DecoderTestBase::MockGLStates::OnBindVertexArrayOES));
1731 ON_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _))
1732 .WillByDefault(WithArg<1>(Invoke(
1733 &gl_states_,
1734 &GLES2DecoderTestBase::MockGLStates::OnBindArrayBuffer)));
1735 ON_CALL(*gl_, VertexAttribPointer(_, _, _, _, _, NULL))
1736 .WillByDefault(InvokeWithoutArgs(
1737 &gl_states_,
1738 &GLES2DecoderTestBase::MockGLStates::OnVertexAttribNullPointer));
1741 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1742 MockCommandBufferEngine() {
1744 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory());
1745 shm->CreateAndMapAnonymous(kSharedBufferSize);
1746 valid_buffer_ = MakeBufferFromSharedMemory(shm.Pass(), kSharedBufferSize);
1748 ClearSharedMemory();
1751 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::
1752 ~MockCommandBufferEngine() {}
1754 scoped_refptr<gpu::Buffer>
1755 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetSharedMemoryBuffer(
1756 int32 shm_id) {
1757 return shm_id == kSharedMemoryId ? valid_buffer_ : invalid_buffer_;
1760 void GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::set_token(
1761 int32 token) {
1762 DCHECK(false);
1765 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetBuffer(
1766 int32 /* transfer_buffer_id */) {
1767 DCHECK(false);
1768 return false;
1771 bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetOffset(
1772 int32 offset) {
1773 DCHECK(false);
1774 return false;
1777 int32 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetGetOffset() {
1778 DCHECK(false);
1779 return 0;
1782 void GLES2DecoderWithShaderTestBase::SetUp() {
1783 GLES2DecoderTestBase::SetUp();
1784 SetupDefaultProgram();
1787 // Include the auto-generated part of this file. We split this because it means
1788 // we can easily edit the non-auto generated parts right here in this file
1789 // instead of having to edit some template or the code generator.
1790 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h"
1792 } // namespace gles2
1793 } // namespace gpu