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