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