1 // Copyright 2014 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.h" 6 7 #include "base/command_line.h" 8 #include "base/strings/string_number_conversions.h" 9 #include "gpu/command_buffer/common/gles2_cmd_format.h" 10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 11 #include "gpu/command_buffer/common/id_allocator.h" 12 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h" 13 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" 14 #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.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/context_state.h" 18 #include "gpu/command_buffer/service/gl_surface_mock.h" 19 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h" 20 21 #include "gpu/command_buffer/service/gpu_switches.h" 22 #include "gpu/command_buffer/service/image_manager.h" 23 #include "gpu/command_buffer/service/mailbox_manager.h" 24 #include "gpu/command_buffer/service/mocks.h" 25 #include "gpu/command_buffer/service/program_manager.h" 26 #include "gpu/command_buffer/service/test_helper.h" 27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "ui/gl/gl_implementation.h" 29 #include "ui/gl/gl_mock.h" 30 #include "ui/gl/gl_surface_stub.h" 31 32 #if !defined(GL_DEPTH24_STENCIL8) 33 #define GL_DEPTH24_STENCIL8 0x88F0 34 #endif 35 36 using ::gfx::MockGLInterface; 37 using ::testing::_; 38 using ::testing::DoAll; 39 using ::testing::InSequence; 40 using ::testing::Invoke; 41 using ::testing::MatcherCast; 42 using ::testing::Mock; 43 using ::testing::Pointee; 44 using ::testing::Return; 45 using ::testing::SaveArg; 46 using ::testing::SetArrayArgument; 47 using ::testing::SetArgumentPointee; 48 using ::testing::SetArgPointee; 49 using ::testing::StrEq; 50 using ::testing::StrictMock; 51 52 namespace gpu { 53 namespace gles2 { 54 55 using namespace cmds; 56 57 TEST_P(GLES2DecoderTest, GenerateMipmapWrongFormatsFails) { 58 EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0); 59 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 60 DoTexImage2D( 61 GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 62 GenerateMipmap cmd; 63 cmd.Init(GL_TEXTURE_2D); 64 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 65 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 66 } 67 68 TEST_P(GLES2DecoderTest, GenerateMipmapHandlesOutOfMemory) { 69 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 70 TextureManager* manager = group().texture_manager(); 71 TextureRef* texture_ref = manager->GetTexture(client_texture_id_); 72 ASSERT_TRUE(texture_ref != NULL); 73 Texture* texture = texture_ref->texture(); 74 GLint width = 0; 75 GLint height = 0; 76 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, 2, &width, &height)); 77 DoTexImage2D(GL_TEXTURE_2D, 78 0, 79 GL_RGBA, 80 16, 81 16, 82 0, 83 GL_RGBA, 84 GL_UNSIGNED_BYTE, 85 kSharedMemoryId, 86 kSharedMemoryOffset); 87 EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D)).Times(1); 88 EXPECT_CALL(*gl_, GetError()) 89 .WillOnce(Return(GL_NO_ERROR)) 90 .WillOnce(Return(GL_OUT_OF_MEMORY)) 91 .RetiresOnSaturation(); 92 GenerateMipmap cmd; 93 cmd.Init(GL_TEXTURE_2D); 94 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 95 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); 96 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, 2, &width, &height)); 97 } 98 99 TEST_P(GLES2DecoderTest, GenerateMipmapClearsUnclearedTexture) { 100 EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0); 101 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 102 DoTexImage2D( 103 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 104 SetupClearTextureExpectations(kServiceTextureId, 105 kServiceTextureId, 106 GL_TEXTURE_2D, 107 GL_TEXTURE_2D, 108 0, 109 GL_RGBA, 110 GL_RGBA, 111 GL_UNSIGNED_BYTE, 112 2, 113 2); 114 EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D)); 115 EXPECT_CALL(*gl_, GetError()) 116 .WillOnce(Return(GL_NO_ERROR)) 117 .WillOnce(Return(GL_NO_ERROR)) 118 .RetiresOnSaturation(); 119 GenerateMipmap cmd; 120 cmd.Init(GL_TEXTURE_2D); 121 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 122 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 123 } 124 125 // Same as GenerateMipmapClearsUnclearedTexture, but with workaround 126 // |set_texture_filters_before_generating_mipmap|. 127 TEST_P(GLES2DecoderManualInitTest, SetTextureFiltersBeforeGenerateMipmap) { 128 CommandLine command_line(0, NULL); 129 command_line.AppendSwitchASCII( 130 switches::kGpuDriverBugWorkarounds, 131 base::IntToString(gpu::SET_TEXTURE_FILTER_BEFORE_GENERATING_MIPMAP)); 132 InitState init; 133 init.gl_version = "3.0"; 134 init.bind_generates_resource = true; 135 InitDecoderWithCommandLine(init, &command_line); 136 137 EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0); 138 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 139 DoTexImage2D( 140 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 141 SetupClearTextureExpectations(kServiceTextureId, 142 kServiceTextureId, 143 GL_TEXTURE_2D, 144 GL_TEXTURE_2D, 145 0, 146 GL_RGBA, 147 GL_RGBA, 148 GL_UNSIGNED_BYTE, 149 2, 150 2); 151 EXPECT_CALL( 152 *gl_, 153 TexParameteri( 154 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST)) 155 .Times(1) 156 .RetiresOnSaturation(); 157 EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D)); 158 EXPECT_CALL( 159 *gl_, 160 TexParameteri( 161 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR)) 162 .Times(1) 163 .RetiresOnSaturation(); 164 EXPECT_CALL(*gl_, GetError()) 165 .WillOnce(Return(GL_NO_ERROR)) 166 .WillOnce(Return(GL_NO_ERROR)) 167 .RetiresOnSaturation(); 168 GenerateMipmap cmd; 169 cmd.Init(GL_TEXTURE_2D); 170 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 171 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 172 } 173 174 TEST_P(GLES2DecoderTest, ActiveTextureValidArgs) { 175 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)); 176 SpecializedSetup<ActiveTexture, 0>(true); 177 ActiveTexture cmd; 178 cmd.Init(GL_TEXTURE1); 179 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 180 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 181 } 182 183 TEST_P(GLES2DecoderTest, ActiveTextureInvalidArgs) { 184 EXPECT_CALL(*gl_, ActiveTexture(_)).Times(0); 185 SpecializedSetup<ActiveTexture, 0>(false); 186 ActiveTexture cmd; 187 cmd.Init(GL_TEXTURE0 - 1); 188 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 189 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 190 cmd.Init(kNumTextureUnits); 191 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 192 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 193 } 194 195 TEST_P(GLES2DecoderTest, TexSubImage2DValidArgs) { 196 const int kWidth = 16; 197 const int kHeight = 8; 198 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 199 DoTexImage2D(GL_TEXTURE_2D, 200 1, 201 GL_RGBA, 202 kWidth, 203 kHeight, 204 0, 205 GL_RGBA, 206 GL_UNSIGNED_BYTE, 207 kSharedMemoryId, 208 kSharedMemoryOffset); 209 EXPECT_CALL(*gl_, 210 TexSubImage2D(GL_TEXTURE_2D, 211 1, 212 1, 213 0, 214 kWidth - 1, 215 kHeight, 216 GL_RGBA, 217 GL_UNSIGNED_BYTE, 218 shared_memory_address_)) 219 .Times(1) 220 .RetiresOnSaturation(); 221 TexSubImage2D cmd; 222 cmd.Init(GL_TEXTURE_2D, 223 1, 224 1, 225 0, 226 kWidth - 1, 227 kHeight, 228 GL_RGBA, 229 GL_UNSIGNED_BYTE, 230 kSharedMemoryId, 231 kSharedMemoryOffset, 232 GL_FALSE); 233 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 234 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 235 } 236 237 TEST_P(GLES2DecoderTest, TexSubImage2DBadArgs) { 238 const int kWidth = 16; 239 const int kHeight = 8; 240 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 241 DoTexImage2D(GL_TEXTURE_2D, 242 1, 243 GL_RGBA, 244 kWidth, 245 kHeight, 246 0, 247 GL_RGBA, 248 GL_UNSIGNED_BYTE, 249 0, 250 0); 251 TexSubImage2D cmd; 252 cmd.Init(GL_TEXTURE0, 253 1, 254 0, 255 0, 256 kWidth, 257 kHeight, 258 GL_RGBA, 259 GL_UNSIGNED_BYTE, 260 kSharedMemoryId, 261 kSharedMemoryOffset, 262 GL_FALSE); 263 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 264 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 265 cmd.Init(GL_TEXTURE_2D, 266 1, 267 0, 268 0, 269 kWidth, 270 kHeight, 271 GL_TRUE, 272 GL_UNSIGNED_BYTE, 273 kSharedMemoryId, 274 kSharedMemoryOffset, 275 GL_FALSE); 276 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 277 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 278 cmd.Init(GL_TEXTURE_2D, 279 1, 280 0, 281 0, 282 kWidth, 283 kHeight, 284 GL_RGBA, 285 GL_UNSIGNED_INT, 286 kSharedMemoryId, 287 kSharedMemoryOffset, 288 GL_FALSE); 289 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 290 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 291 cmd.Init(GL_TEXTURE_2D, 292 1, 293 -1, 294 0, 295 kWidth, 296 kHeight, 297 GL_RGBA, 298 GL_UNSIGNED_BYTE, 299 kSharedMemoryId, 300 kSharedMemoryOffset, 301 GL_FALSE); 302 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 303 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 304 cmd.Init(GL_TEXTURE_2D, 305 1, 306 1, 307 0, 308 kWidth, 309 kHeight, 310 GL_RGBA, 311 GL_UNSIGNED_BYTE, 312 kSharedMemoryId, 313 kSharedMemoryOffset, 314 GL_FALSE); 315 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 316 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 317 cmd.Init(GL_TEXTURE_2D, 318 1, 319 0, 320 -1, 321 kWidth, 322 kHeight, 323 GL_RGBA, 324 GL_UNSIGNED_BYTE, 325 kSharedMemoryId, 326 kSharedMemoryOffset, 327 GL_FALSE); 328 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 329 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 330 cmd.Init(GL_TEXTURE_2D, 331 1, 332 0, 333 1, 334 kWidth, 335 kHeight, 336 GL_RGBA, 337 GL_UNSIGNED_BYTE, 338 kSharedMemoryId, 339 kSharedMemoryOffset, 340 GL_FALSE); 341 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 342 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 343 cmd.Init(GL_TEXTURE_2D, 344 1, 345 0, 346 0, 347 kWidth + 1, 348 kHeight, 349 GL_RGBA, 350 GL_UNSIGNED_BYTE, 351 kSharedMemoryId, 352 kSharedMemoryOffset, 353 GL_FALSE); 354 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 355 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 356 cmd.Init(GL_TEXTURE_2D, 357 1, 358 0, 359 0, 360 kWidth, 361 kHeight + 1, 362 GL_RGBA, 363 GL_UNSIGNED_BYTE, 364 kSharedMemoryId, 365 kSharedMemoryOffset, 366 GL_FALSE); 367 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 368 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 369 cmd.Init(GL_TEXTURE_2D, 370 1, 371 0, 372 0, 373 kWidth, 374 kHeight, 375 GL_RGB, 376 GL_UNSIGNED_BYTE, 377 kSharedMemoryId, 378 kSharedMemoryOffset, 379 GL_FALSE); 380 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 381 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 382 cmd.Init(GL_TEXTURE_2D, 383 1, 384 0, 385 0, 386 kWidth, 387 kHeight, 388 GL_RGBA, 389 GL_UNSIGNED_SHORT_4_4_4_4, 390 kSharedMemoryId, 391 kSharedMemoryOffset, 392 GL_FALSE); 393 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 394 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 395 cmd.Init(GL_TEXTURE_2D, 396 1, 397 0, 398 0, 399 kWidth, 400 kHeight, 401 GL_RGBA, 402 GL_UNSIGNED_BYTE, 403 kInvalidSharedMemoryId, 404 kSharedMemoryOffset, 405 GL_FALSE); 406 EXPECT_NE(error::kNoError, ExecuteCmd(cmd)); 407 cmd.Init(GL_TEXTURE_2D, 408 1, 409 0, 410 0, 411 kWidth, 412 kHeight, 413 GL_RGBA, 414 GL_UNSIGNED_BYTE, 415 kSharedMemoryId, 416 kInvalidSharedMemoryOffset, 417 GL_FALSE); 418 EXPECT_NE(error::kNoError, ExecuteCmd(cmd)); 419 } 420 421 TEST_P(GLES2DecoderTest, CopyTexSubImage2DValidArgs) { 422 const int kWidth = 16; 423 const int kHeight = 8; 424 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 425 DoTexImage2D(GL_TEXTURE_2D, 426 1, 427 GL_RGBA, 428 kWidth, 429 kHeight, 430 0, 431 GL_RGBA, 432 GL_UNSIGNED_BYTE, 433 kSharedMemoryId, 434 kSharedMemoryOffset); 435 EXPECT_CALL(*gl_, 436 CopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight)) 437 .Times(1) 438 .RetiresOnSaturation(); 439 CopyTexSubImage2D cmd; 440 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight); 441 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 442 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 443 } 444 445 TEST_P(GLES2DecoderTest, CopyTexSubImage2DBadArgs) { 446 const int kWidth = 16; 447 const int kHeight = 8; 448 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 449 DoTexImage2D(GL_TEXTURE_2D, 450 1, 451 GL_RGBA, 452 kWidth, 453 kHeight, 454 0, 455 GL_RGBA, 456 GL_UNSIGNED_BYTE, 457 0, 458 0); 459 CopyTexSubImage2D cmd; 460 cmd.Init(GL_TEXTURE0, 1, 0, 0, 0, 0, kWidth, kHeight); 461 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 462 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 463 cmd.Init(GL_TEXTURE_2D, 1, -1, 0, 0, 0, kWidth, kHeight); 464 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 465 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 466 cmd.Init(GL_TEXTURE_2D, 1, 1, 0, 0, 0, kWidth, kHeight); 467 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 468 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 469 cmd.Init(GL_TEXTURE_2D, 1, 0, -1, 0, 0, kWidth, kHeight); 470 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 471 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 472 cmd.Init(GL_TEXTURE_2D, 1, 0, 1, 0, 0, kWidth, kHeight); 473 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 474 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 475 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth + 1, kHeight); 476 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 477 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 478 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight + 1); 479 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 480 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 481 } 482 483 TEST_P(GLES2DecoderTest, TexImage2DRedefinitionSucceeds) { 484 const int kWidth = 16; 485 const int kHeight = 8; 486 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 487 EXPECT_CALL(*gl_, GetError()).WillRepeatedly(Return(GL_NO_ERROR)); 488 for (int ii = 0; ii < 2; ++ii) { 489 TexImage2D cmd; 490 if (ii == 0) { 491 EXPECT_CALL(*gl_, 492 TexImage2D(GL_TEXTURE_2D, 493 0, 494 GL_RGBA, 495 kWidth, 496 kHeight, 497 0, 498 GL_RGBA, 499 GL_UNSIGNED_BYTE, 500 _)) 501 .Times(1) 502 .RetiresOnSaturation(); 503 cmd.Init(GL_TEXTURE_2D, 504 0, 505 GL_RGBA, 506 kWidth, 507 kHeight, 508 GL_RGBA, 509 GL_UNSIGNED_BYTE, 510 kSharedMemoryId, 511 kSharedMemoryOffset); 512 } else { 513 SetupClearTextureExpectations(kServiceTextureId, 514 kServiceTextureId, 515 GL_TEXTURE_2D, 516 GL_TEXTURE_2D, 517 0, 518 GL_RGBA, 519 GL_RGBA, 520 GL_UNSIGNED_BYTE, 521 kWidth, 522 kHeight); 523 cmd.Init(GL_TEXTURE_2D, 524 0, 525 GL_RGBA, 526 kWidth, 527 kHeight, 528 GL_RGBA, 529 GL_UNSIGNED_BYTE, 530 0, 531 0); 532 } 533 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 534 EXPECT_CALL(*gl_, 535 TexSubImage2D(GL_TEXTURE_2D, 536 0, 537 0, 538 0, 539 kWidth, 540 kHeight - 1, 541 GL_RGBA, 542 GL_UNSIGNED_BYTE, 543 shared_memory_address_)) 544 .Times(1) 545 .RetiresOnSaturation(); 546 // Consider this TexSubImage2D command part of the previous TexImage2D 547 // (last GL_TRUE argument). It will be skipped if there are bugs in the 548 // redefinition case. 549 TexSubImage2D cmd2; 550 cmd2.Init(GL_TEXTURE_2D, 551 0, 552 0, 553 0, 554 kWidth, 555 kHeight - 1, 556 GL_RGBA, 557 GL_UNSIGNED_BYTE, 558 kSharedMemoryId, 559 kSharedMemoryOffset, 560 GL_TRUE); 561 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2)); 562 } 563 } 564 565 TEST_P(GLES2DecoderTest, TexImage2DGLError) { 566 GLenum target = GL_TEXTURE_2D; 567 GLint level = 0; 568 GLenum internal_format = GL_RGBA; 569 GLsizei width = 2; 570 GLsizei height = 4; 571 GLint border = 0; 572 GLenum format = GL_RGBA; 573 GLenum type = GL_UNSIGNED_BYTE; 574 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 575 TextureManager* manager = group().texture_manager(); 576 TextureRef* texture_ref = manager->GetTexture(client_texture_id_); 577 ASSERT_TRUE(texture_ref != NULL); 578 Texture* texture = texture_ref->texture(); 579 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height)); 580 EXPECT_CALL(*gl_, GetError()) 581 .WillOnce(Return(GL_NO_ERROR)) 582 .WillOnce(Return(GL_OUT_OF_MEMORY)) 583 .RetiresOnSaturation(); 584 EXPECT_CALL(*gl_, 585 TexImage2D(target, 586 level, 587 internal_format, 588 width, 589 height, 590 border, 591 format, 592 type, 593 _)) 594 .Times(1) 595 .RetiresOnSaturation(); 596 TexImage2D cmd; 597 cmd.Init(target, 598 level, 599 internal_format, 600 width, 601 height, 602 format, 603 type, 604 kSharedMemoryId, 605 kSharedMemoryOffset); 606 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 607 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); 608 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height)); 609 } 610 611 TEST_P(GLES2DecoderTest, CopyTexImage2DGLError) { 612 GLenum target = GL_TEXTURE_2D; 613 GLint level = 0; 614 GLenum internal_format = GL_RGBA; 615 GLsizei width = 2; 616 GLsizei height = 4; 617 GLint border = 0; 618 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 619 TextureManager* manager = group().texture_manager(); 620 TextureRef* texture_ref = manager->GetTexture(client_texture_id_); 621 ASSERT_TRUE(texture_ref != NULL); 622 Texture* texture = texture_ref->texture(); 623 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height)); 624 EXPECT_CALL(*gl_, GetError()) 625 .WillOnce(Return(GL_NO_ERROR)) 626 .WillOnce(Return(GL_OUT_OF_MEMORY)) 627 .RetiresOnSaturation(); 628 EXPECT_CALL(*gl_, 629 CopyTexImage2D( 630 target, level, internal_format, 0, 0, width, height, border)) 631 .Times(1) 632 .RetiresOnSaturation(); 633 CopyTexImage2D cmd; 634 cmd.Init(target, level, internal_format, 0, 0, width, height); 635 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 636 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); 637 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height)); 638 } 639 640 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DBucketBadBucket) { 641 InitState init; 642 init.extensions = "GL_EXT_texture_compression_s3tc"; 643 init.gl_version = "3.0"; 644 init.bind_generates_resource = true; 645 InitDecoder(init); 646 647 const uint32 kBadBucketId = 123; 648 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 649 CompressedTexImage2DBucket cmd; 650 cmd.Init(GL_TEXTURE_2D, 651 0, 652 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 653 4, 654 4, 655 kBadBucketId); 656 EXPECT_NE(error::kNoError, ExecuteCmd(cmd)); 657 CompressedTexSubImage2DBucket cmd2; 658 cmd2.Init(GL_TEXTURE_2D, 659 0, 660 0, 661 0, 662 4, 663 4, 664 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 665 kBadBucketId); 666 EXPECT_NE(error::kNoError, ExecuteCmd(cmd)); 667 } 668 669 namespace { 670 671 struct S3TCTestData { 672 GLenum format; 673 size_t block_size; 674 }; 675 676 } // anonymous namespace. 677 678 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DS3TC) { 679 InitState init; 680 init.extensions = "GL_EXT_texture_compression_s3tc"; 681 init.gl_version = "3.0"; 682 init.bind_generates_resource = true; 683 InitDecoder(init); 684 const uint32 kBucketId = 123; 685 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId); 686 ASSERT_TRUE(bucket != NULL); 687 688 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 689 690 static const S3TCTestData test_data[] = { 691 { 692 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 8, 693 }, 694 { 695 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 8, 696 }, 697 { 698 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 16, 699 }, 700 { 701 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 16, 702 }, 703 }; 704 705 for (size_t ii = 0; ii < arraysize(test_data); ++ii) { 706 const S3TCTestData& test = test_data[ii]; 707 CompressedTexImage2DBucket cmd; 708 // test small width. 709 DoCompressedTexImage2D( 710 GL_TEXTURE_2D, 0, test.format, 2, 4, 0, test.block_size, kBucketId); 711 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 712 713 // test bad width. 714 cmd.Init(GL_TEXTURE_2D, 0, test.format, 5, 4, kBucketId); 715 bucket->SetSize(test.block_size * 2); 716 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 717 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 718 719 // test small height. 720 DoCompressedTexImage2D( 721 GL_TEXTURE_2D, 0, test.format, 4, 2, 0, test.block_size, kBucketId); 722 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 723 724 // test too bad height. 725 cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 5, kBucketId); 726 bucket->SetSize(test.block_size * 2); 727 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 728 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 729 730 // test small for level 0. 731 DoCompressedTexImage2D( 732 GL_TEXTURE_2D, 0, test.format, 1, 1, 0, test.block_size, kBucketId); 733 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 734 735 // test small for level 0. 736 DoCompressedTexImage2D( 737 GL_TEXTURE_2D, 0, test.format, 2, 2, 0, test.block_size, kBucketId); 738 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 739 740 // test size too large. 741 cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 4, kBucketId); 742 bucket->SetSize(test.block_size * 2); 743 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 744 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 745 746 // test size too small. 747 cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 4, kBucketId); 748 bucket->SetSize(test.block_size / 2); 749 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 750 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 751 752 // test with 3 mips. 753 DoCompressedTexImage2D( 754 GL_TEXTURE_2D, 0, test.format, 4, 4, 0, test.block_size, kBucketId); 755 DoCompressedTexImage2D( 756 GL_TEXTURE_2D, 1, test.format, 2, 2, 0, test.block_size, kBucketId); 757 DoCompressedTexImage2D( 758 GL_TEXTURE_2D, 2, test.format, 1, 1, 0, test.block_size, kBucketId); 759 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 760 761 // Test a 16x16 762 DoCompressedTexImage2D(GL_TEXTURE_2D, 763 0, 764 test.format, 765 16, 766 16, 767 0, 768 test.block_size * 4 * 4, 769 kBucketId); 770 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 771 772 CompressedTexSubImage2DBucket sub_cmd; 773 bucket->SetSize(test.block_size); 774 // Test sub image bad xoffset 775 sub_cmd.Init(GL_TEXTURE_2D, 0, 1, 0, 4, 4, test.format, kBucketId); 776 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd)); 777 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 778 779 // Test sub image bad yoffset 780 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 2, 4, 4, test.format, kBucketId); 781 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd)); 782 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 783 784 // Test sub image bad width 785 bucket->SetSize(test.block_size * 2); 786 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 5, 4, test.format, kBucketId); 787 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd)); 788 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 789 790 // Test sub image bad height 791 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 5, test.format, kBucketId); 792 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd)); 793 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 794 795 // Test sub image bad size 796 bucket->SetSize(test.block_size + 1); 797 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, test.format, kBucketId); 798 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd)); 799 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 800 801 for (GLint yoffset = 0; yoffset <= 8; yoffset += 4) { 802 for (GLint xoffset = 0; xoffset <= 8; xoffset += 4) { 803 for (GLsizei height = 4; height <= 8; height += 4) { 804 for (GLsizei width = 4; width <= 8; width += 4) { 805 GLsizei size = test.block_size * (width / 4) * (height / 4); 806 bucket->SetSize(size); 807 EXPECT_CALL(*gl_, 808 CompressedTexSubImage2D(GL_TEXTURE_2D, 809 0, 810 xoffset, 811 yoffset, 812 width, 813 height, 814 test.format, 815 size, 816 _)) 817 .Times(1) 818 .RetiresOnSaturation(); 819 sub_cmd.Init(GL_TEXTURE_2D, 820 0, 821 xoffset, 822 yoffset, 823 width, 824 height, 825 test.format, 826 kBucketId); 827 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd)); 828 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 829 } 830 } 831 } 832 } 833 } 834 } 835 836 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DETC1) { 837 InitState init; 838 init.extensions = "GL_OES_compressed_ETC1_RGB8_texture"; 839 init.gl_version = "opengl es 2.0"; 840 init.bind_generates_resource = true; 841 InitDecoder(init); 842 const uint32 kBucketId = 123; 843 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId); 844 ASSERT_TRUE(bucket != NULL); 845 846 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 847 848 const GLenum kFormat = GL_ETC1_RGB8_OES; 849 const size_t kBlockSize = 8; 850 851 CompressedTexImage2DBucket cmd; 852 // test small width. 853 DoCompressedTexImage2D(GL_TEXTURE_2D, 0, kFormat, 4, 8, 0, 16, kBucketId); 854 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 855 856 // test small height. 857 DoCompressedTexImage2D(GL_TEXTURE_2D, 0, kFormat, 8, 4, 0, 16, kBucketId); 858 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 859 860 // test size too large. 861 cmd.Init(GL_TEXTURE_2D, 0, kFormat, 4, 4, kBucketId); 862 bucket->SetSize(kBlockSize * 2); 863 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 864 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 865 866 // test size too small. 867 cmd.Init(GL_TEXTURE_2D, 0, kFormat, 4, 4, kBucketId); 868 bucket->SetSize(kBlockSize / 2); 869 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 870 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 871 872 // Test a 16x16 873 DoCompressedTexImage2D( 874 GL_TEXTURE_2D, 0, kFormat, 16, 16, 0, kBlockSize * 16, kBucketId); 875 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 876 877 // Test CompressedTexSubImage not allowed 878 CompressedTexSubImage2DBucket sub_cmd; 879 bucket->SetSize(kBlockSize); 880 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, kFormat, kBucketId); 881 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd)); 882 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 883 884 // Test TexSubImage not allowed for ETC1 compressed texture 885 TextureRef* texture_ref = GetTexture(client_texture_id_); 886 ASSERT_TRUE(texture_ref != NULL); 887 Texture* texture = texture_ref->texture(); 888 GLenum type, internal_format; 889 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format)); 890 EXPECT_EQ(kFormat, internal_format); 891 TexSubImage2D texsub_cmd; 892 texsub_cmd.Init(GL_TEXTURE_2D, 893 0, 894 0, 895 0, 896 4, 897 4, 898 GL_RGBA, 899 GL_UNSIGNED_BYTE, 900 kSharedMemoryId, 901 kSharedMemoryOffset, 902 GL_FALSE); 903 EXPECT_EQ(error::kNoError, ExecuteCmd(texsub_cmd)); 904 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 905 906 // Test CopyTexSubImage not allowed for ETC1 compressed texture 907 CopyTexSubImage2D copy_cmd; 908 copy_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 4, 4); 909 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_cmd)); 910 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 911 } 912 913 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalBindTexture) { 914 InitState init; 915 init.extensions = "GL_OES_EGL_image_external"; 916 init.gl_version = "opengl es 2.0"; 917 init.bind_generates_resource = true; 918 InitDecoder(init); 919 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_EXTERNAL_OES, kNewServiceId)); 920 EXPECT_CALL(*gl_, GenTextures(1, _)) 921 .WillOnce(SetArgumentPointee<1>(kNewServiceId)); 922 BindTexture cmd; 923 cmd.Init(GL_TEXTURE_EXTERNAL_OES, kNewClientId); 924 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 925 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 926 TextureRef* texture_ref = GetTexture(kNewClientId); 927 EXPECT_TRUE(texture_ref != NULL); 928 EXPECT_TRUE(texture_ref->texture()->target() == GL_TEXTURE_EXTERNAL_OES); 929 } 930 931 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalGetBinding) { 932 InitState init; 933 init.extensions = "GL_OES_EGL_image_external"; 934 init.gl_version = "opengl es 2.0"; 935 init.bind_generates_resource = true; 936 InitDecoder(init); 937 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId); 938 939 EXPECT_CALL(*gl_, GetError()) 940 .WillOnce(Return(GL_NO_ERROR)) 941 .WillOnce(Return(GL_NO_ERROR)) 942 .RetiresOnSaturation(); 943 typedef GetIntegerv::Result Result; 944 Result* result = static_cast<Result*>(shared_memory_address_); 945 EXPECT_CALL(*gl_, 946 GetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, result->GetData())) 947 .Times(0); 948 result->size = 0; 949 GetIntegerv cmd; 950 cmd.Init(GL_TEXTURE_BINDING_EXTERNAL_OES, 951 shared_memory_id_, 952 shared_memory_offset_); 953 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 954 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned( 955 GL_TEXTURE_BINDING_EXTERNAL_OES), 956 result->GetNumResults()); 957 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 958 EXPECT_EQ(client_texture_id_, (uint32)result->GetData()[0]); 959 } 960 961 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureDefaults) { 962 InitState init; 963 init.extensions = "GL_OES_EGL_image_external"; 964 init.gl_version = "opengl es 2.0"; 965 init.bind_generates_resource = true; 966 InitDecoder(init); 967 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId); 968 969 TextureRef* texture_ref = GetTexture(client_texture_id_); 970 EXPECT_TRUE(texture_ref != NULL); 971 Texture* texture = texture_ref->texture(); 972 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES); 973 EXPECT_TRUE(texture->min_filter() == GL_LINEAR); 974 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE); 975 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE); 976 } 977 978 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureParam) { 979 InitState init; 980 init.extensions = "GL_OES_EGL_image_external"; 981 init.gl_version = "opengl es 2.0"; 982 init.bind_generates_resource = true; 983 InitDecoder(init); 984 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId); 985 986 EXPECT_CALL(*gl_, 987 TexParameteri( 988 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); 989 EXPECT_CALL( 990 *gl_, 991 TexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 992 EXPECT_CALL( 993 *gl_, 994 TexParameteri( 995 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 996 EXPECT_CALL( 997 *gl_, 998 TexParameteri( 999 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 1000 TexParameteri cmd; 1001 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 1002 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1003 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1004 1005 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1006 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1007 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1008 1009 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 1010 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1011 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1012 1013 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 1014 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1015 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1016 1017 TextureRef* texture_ref = GetTexture(client_texture_id_); 1018 EXPECT_TRUE(texture_ref != NULL); 1019 Texture* texture = texture_ref->texture(); 1020 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES); 1021 EXPECT_TRUE(texture->min_filter() == GL_LINEAR); 1022 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE); 1023 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE); 1024 } 1025 1026 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureParamInvalid) { 1027 InitState init; 1028 init.extensions = "GL_OES_EGL_image_external"; 1029 init.gl_version = "opengl es 2.0"; 1030 init.bind_generates_resource = true; 1031 InitDecoder(init); 1032 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId); 1033 1034 TexParameteri cmd; 1035 cmd.Init(GL_TEXTURE_EXTERNAL_OES, 1036 GL_TEXTURE_MIN_FILTER, 1037 GL_NEAREST_MIPMAP_NEAREST); 1038 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1039 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 1040 1041 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_REPEAT); 1042 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1043 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 1044 1045 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_REPEAT); 1046 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1047 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 1048 1049 TextureRef* texture_ref = GetTexture(client_texture_id_); 1050 EXPECT_TRUE(texture_ref != NULL); 1051 Texture* texture = texture_ref->texture(); 1052 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES); 1053 EXPECT_TRUE(texture->min_filter() == GL_LINEAR); 1054 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE); 1055 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE); 1056 } 1057 1058 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTexImage2DError) { 1059 InitState init; 1060 init.extensions = "GL_OES_EGL_image_external"; 1061 init.gl_version = "opengl es 2.0"; 1062 init.bind_generates_resource = true; 1063 InitDecoder(init); 1064 1065 GLenum target = GL_TEXTURE_EXTERNAL_OES; 1066 GLint level = 0; 1067 GLenum internal_format = GL_RGBA; 1068 GLsizei width = 2; 1069 GLsizei height = 4; 1070 GLenum format = GL_RGBA; 1071 GLenum type = GL_UNSIGNED_BYTE; 1072 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId); 1073 ASSERT_TRUE(GetTexture(client_texture_id_) != NULL); 1074 TexImage2D cmd; 1075 cmd.Init(target, 1076 level, 1077 internal_format, 1078 width, 1079 height, 1080 format, 1081 type, 1082 kSharedMemoryId, 1083 kSharedMemoryOffset); 1084 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1085 1086 // TexImage2D is not allowed with GL_TEXTURE_EXTERNAL_OES targets. 1087 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 1088 } 1089 1090 TEST_P(GLES2DecoderManualInitTest, DefaultTextureZero) { 1091 InitState init; 1092 init.gl_version = "3.0"; 1093 InitDecoder(init); 1094 1095 BindTexture cmd1; 1096 cmd1.Init(GL_TEXTURE_2D, 0); 1097 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0)); 1098 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1)); 1099 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1100 1101 BindTexture cmd2; 1102 cmd2.Init(GL_TEXTURE_CUBE_MAP, 0); 1103 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0)); 1104 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2)); 1105 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1106 } 1107 1108 TEST_P(GLES2DecoderManualInitTest, DefaultTextureBGR) { 1109 InitState init; 1110 init.gl_version = "3.0"; 1111 init.bind_generates_resource = true; 1112 InitDecoder(init); 1113 1114 BindTexture cmd1; 1115 cmd1.Init(GL_TEXTURE_2D, 0); 1116 EXPECT_CALL( 1117 *gl_, BindTexture(GL_TEXTURE_2D, TestHelper::kServiceDefaultTexture2dId)); 1118 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1)); 1119 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1120 1121 BindTexture cmd2; 1122 cmd2.Init(GL_TEXTURE_CUBE_MAP, 0); 1123 EXPECT_CALL(*gl_, 1124 BindTexture(GL_TEXTURE_CUBE_MAP, 1125 TestHelper::kServiceDefaultTextureCubemapId)); 1126 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2)); 1127 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1128 } 1129 1130 // Test that default texture 0 is immutable. 1131 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameterf) { 1132 InitState init; 1133 init.gl_version = "3.0"; 1134 InitDecoder(init); 1135 1136 { 1137 BindTexture cmd1; 1138 cmd1.Init(GL_TEXTURE_2D, 0); 1139 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0)); 1140 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1)); 1141 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1142 1143 TexParameterf cmd2; 1144 cmd2.Init(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1145 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2)); 1146 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 1147 } 1148 1149 { 1150 BindTexture cmd1; 1151 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0); 1152 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0)); 1153 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1)); 1154 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1155 1156 TexParameterf cmd2; 1157 cmd2.Init(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1158 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2)); 1159 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 1160 } 1161 } 1162 1163 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameteri) { 1164 InitState init; 1165 init.gl_version = "3.0"; 1166 InitDecoder(init); 1167 1168 { 1169 BindTexture cmd1; 1170 cmd1.Init(GL_TEXTURE_2D, 0); 1171 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0)); 1172 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1)); 1173 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1174 1175 TexParameteri cmd2; 1176 cmd2.Init(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1177 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2)); 1178 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 1179 } 1180 1181 { 1182 BindTexture cmd1; 1183 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0); 1184 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0)); 1185 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1)); 1186 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1187 1188 TexParameteri cmd2; 1189 cmd2.Init(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1190 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2)); 1191 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 1192 } 1193 } 1194 1195 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameterfv) { 1196 InitState init; 1197 init.gl_version = "3.0"; 1198 InitDecoder(init); 1199 1200 { 1201 BindTexture cmd1; 1202 cmd1.Init(GL_TEXTURE_2D, 0); 1203 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0)); 1204 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1)); 1205 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1206 1207 GLfloat data = GL_NEAREST; 1208 TexParameterfvImmediate& cmd2 = 1209 *GetImmediateAs<TexParameterfvImmediate>(); 1210 cmd2.Init(GL_TEXTURE_2D, 1211 GL_TEXTURE_MAG_FILTER, 1212 &data); 1213 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data))); 1214 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 1215 } 1216 1217 { 1218 BindTexture cmd1; 1219 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0); 1220 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0)); 1221 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1)); 1222 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1223 1224 GLfloat data = GL_NEAREST; 1225 TexParameterfvImmediate& cmd2 = 1226 *GetImmediateAs<TexParameterfvImmediate>(); 1227 cmd2.Init(GL_TEXTURE_CUBE_MAP, 1228 GL_TEXTURE_MAG_FILTER, 1229 &data); 1230 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data))); 1231 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 1232 } 1233 } 1234 1235 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameteriv) { 1236 InitState init; 1237 init.gl_version = "3.0"; 1238 InitDecoder(init); 1239 1240 { 1241 BindTexture cmd1; 1242 cmd1.Init(GL_TEXTURE_2D, 0); 1243 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0)); 1244 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1)); 1245 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1246 1247 GLfloat data = GL_NEAREST; 1248 TexParameterfvImmediate& cmd2 = 1249 *GetImmediateAs<TexParameterfvImmediate>(); 1250 cmd2.Init(GL_TEXTURE_2D, 1251 GL_TEXTURE_MAG_FILTER, 1252 &data); 1253 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data))); 1254 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 1255 } 1256 1257 { 1258 BindTexture cmd1; 1259 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0); 1260 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0)); 1261 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1)); 1262 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1263 1264 GLfloat data = GL_NEAREST; 1265 TexParameterfvImmediate& cmd2 = 1266 *GetImmediateAs<TexParameterfvImmediate>(); 1267 cmd2.Init(GL_TEXTURE_CUBE_MAP, 1268 GL_TEXTURE_MAG_FILTER, 1269 &data); 1270 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data))); 1271 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); 1272 } 1273 } 1274 1275 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexImage2D) { 1276 InitState init; 1277 init.gl_version = "3.0"; 1278 InitDecoder(init); 1279 1280 BindTexture cmd1; 1281 cmd1.Init(GL_TEXTURE_2D, 0); 1282 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0)); 1283 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1)); 1284 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1285 1286 TexImage2D cmd2; 1287 cmd2.Init(GL_TEXTURE_2D, 1288 0, 1289 GL_RGBA, 1290 2, 1291 2, 1292 GL_RGBA, 1293 GL_UNSIGNED_BYTE, 1294 kSharedMemoryId, 1295 kSharedMemoryOffset); 1296 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2)); 1297 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 1298 } 1299 1300 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexSubImage2D) { 1301 InitState init; 1302 init.gl_version = "3.0"; 1303 InitDecoder(init); 1304 1305 BindTexture cmd1; 1306 cmd1.Init(GL_TEXTURE_2D, 0); 1307 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0)); 1308 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1)); 1309 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1310 1311 TexSubImage2D cmd2; 1312 cmd2.Init(GL_TEXTURE_2D, 1313 0, 1314 1, 1315 1, 1316 1, 1317 1, 1318 GL_RGBA, 1319 GL_UNSIGNED_BYTE, 1320 kSharedMemoryId, 1321 kSharedMemoryOffset, 1322 GL_FALSE); 1323 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2)); 1324 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 1325 } 1326 1327 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleBindTexture) { 1328 InitState init; 1329 init.extensions = "GL_ARB_texture_rectangle"; 1330 init.gl_version = "3.0"; 1331 init.bind_generates_resource = true; 1332 InitDecoder(init); 1333 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_RECTANGLE_ARB, kNewServiceId)); 1334 EXPECT_CALL(*gl_, GenTextures(1, _)) 1335 .WillOnce(SetArgumentPointee<1>(kNewServiceId)); 1336 BindTexture cmd; 1337 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, kNewClientId); 1338 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1339 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1340 Texture* texture = GetTexture(kNewClientId)->texture(); 1341 EXPECT_TRUE(texture != NULL); 1342 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB); 1343 } 1344 1345 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleGetBinding) { 1346 InitState init; 1347 init.extensions = "GL_ARB_texture_rectangle"; 1348 init.gl_version = "3.0"; 1349 init.bind_generates_resource = true; 1350 InitDecoder(init); 1351 DoBindTexture( 1352 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId); 1353 1354 EXPECT_CALL(*gl_, GetError()) 1355 .WillOnce(Return(GL_NO_ERROR)) 1356 .WillOnce(Return(GL_NO_ERROR)) 1357 .RetiresOnSaturation(); 1358 typedef GetIntegerv::Result Result; 1359 Result* result = static_cast<Result*>(shared_memory_address_); 1360 EXPECT_CALL(*gl_, 1361 GetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, result->GetData())) 1362 .Times(0); 1363 result->size = 0; 1364 GetIntegerv cmd; 1365 cmd.Init(GL_TEXTURE_BINDING_RECTANGLE_ARB, 1366 shared_memory_id_, 1367 shared_memory_offset_); 1368 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1369 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned( 1370 GL_TEXTURE_BINDING_RECTANGLE_ARB), 1371 result->GetNumResults()); 1372 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1373 EXPECT_EQ(client_texture_id_, (uint32)result->GetData()[0]); 1374 } 1375 1376 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTextureDefaults) { 1377 InitState init; 1378 init.extensions = "GL_ARB_texture_rectangle"; 1379 init.gl_version = "3.0"; 1380 init.bind_generates_resource = true; 1381 InitDecoder(init); 1382 DoBindTexture( 1383 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId); 1384 1385 Texture* texture = GetTexture(client_texture_id_)->texture(); 1386 EXPECT_TRUE(texture != NULL); 1387 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB); 1388 EXPECT_TRUE(texture->min_filter() == GL_LINEAR); 1389 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE); 1390 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE); 1391 } 1392 1393 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTextureParam) { 1394 InitState init; 1395 init.extensions = "GL_ARB_texture_rectangle"; 1396 init.gl_version = "3.0"; 1397 init.bind_generates_resource = true; 1398 InitDecoder(init); 1399 1400 DoBindTexture( 1401 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId); 1402 1403 EXPECT_CALL(*gl_, 1404 TexParameteri( 1405 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); 1406 EXPECT_CALL(*gl_, 1407 TexParameteri( 1408 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 1409 EXPECT_CALL( 1410 *gl_, 1411 TexParameteri( 1412 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 1413 EXPECT_CALL( 1414 *gl_, 1415 TexParameteri( 1416 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 1417 TexParameteri cmd; 1418 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 1419 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1420 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1421 1422 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1423 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1424 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1425 1426 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 1427 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1428 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1429 1430 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 1431 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1432 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1433 1434 Texture* texture = GetTexture(client_texture_id_)->texture(); 1435 EXPECT_TRUE(texture != NULL); 1436 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB); 1437 EXPECT_TRUE(texture->min_filter() == GL_LINEAR); 1438 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE); 1439 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE); 1440 } 1441 1442 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTextureParamInvalid) { 1443 InitState init; 1444 init.extensions = "GL_ARB_texture_rectangle"; 1445 init.gl_version = "3.0"; 1446 init.bind_generates_resource = true; 1447 InitDecoder(init); 1448 1449 DoBindTexture( 1450 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId); 1451 1452 TexParameteri cmd; 1453 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, 1454 GL_TEXTURE_MIN_FILTER, 1455 GL_NEAREST_MIPMAP_NEAREST); 1456 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1457 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 1458 1459 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_REPEAT); 1460 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1461 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 1462 1463 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_REPEAT); 1464 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1465 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 1466 1467 Texture* texture = GetTexture(client_texture_id_)->texture(); 1468 EXPECT_TRUE(texture != NULL); 1469 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB); 1470 EXPECT_TRUE(texture->min_filter() == GL_LINEAR); 1471 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE); 1472 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE); 1473 } 1474 1475 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTexImage2DError) { 1476 InitState init; 1477 init.extensions = "GL_ARB_texture_rectangle"; 1478 init.gl_version = "3.0"; 1479 init.bind_generates_resource = true; 1480 InitDecoder(init); 1481 1482 GLenum target = GL_TEXTURE_RECTANGLE_ARB; 1483 GLint level = 0; 1484 GLenum internal_format = GL_RGBA; 1485 GLsizei width = 2; 1486 GLsizei height = 4; 1487 GLenum format = GL_RGBA; 1488 GLenum type = GL_UNSIGNED_BYTE; 1489 DoBindTexture( 1490 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId); 1491 ASSERT_TRUE(GetTexture(client_texture_id_) != NULL); 1492 TexImage2D cmd; 1493 cmd.Init(target, 1494 level, 1495 internal_format, 1496 width, 1497 height, 1498 format, 1499 type, 1500 kSharedMemoryId, 1501 kSharedMemoryOffset); 1502 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1503 1504 // TexImage2D is not allowed with GL_TEXTURE_RECTANGLE_ARB targets. 1505 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 1506 } 1507 1508 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DClearsAfterTexImage2DNULL) { 1509 InitState init; 1510 init.gl_version = "opengl es 2.0"; 1511 init.has_alpha = true; 1512 init.has_depth = true; 1513 init.request_alpha = true; 1514 init.request_depth = true; 1515 InitDecoder(init); 1516 1517 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 1518 DoTexImage2D( 1519 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 1520 SetupClearTextureExpectations(kServiceTextureId, 1521 kServiceTextureId, 1522 GL_TEXTURE_2D, 1523 GL_TEXTURE_2D, 1524 0, 1525 GL_RGBA, 1526 GL_RGBA, 1527 GL_UNSIGNED_BYTE, 1528 2, 1529 2); 1530 EXPECT_CALL(*gl_, 1531 TexSubImage2D(GL_TEXTURE_2D, 1532 0, 1533 1, 1534 1, 1535 1, 1536 1, 1537 GL_RGBA, 1538 GL_UNSIGNED_BYTE, 1539 shared_memory_address_)) 1540 .Times(1) 1541 .RetiresOnSaturation(); 1542 TexSubImage2D cmd; 1543 cmd.Init(GL_TEXTURE_2D, 1544 0, 1545 1, 1546 1, 1547 1, 1548 1, 1549 GL_RGBA, 1550 GL_UNSIGNED_BYTE, 1551 kSharedMemoryId, 1552 kSharedMemoryOffset, 1553 GL_FALSE); 1554 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1555 // Test if we call it again it does not clear. 1556 EXPECT_CALL(*gl_, 1557 TexSubImage2D(GL_TEXTURE_2D, 1558 0, 1559 1, 1560 1, 1561 1, 1562 1, 1563 GL_RGBA, 1564 GL_UNSIGNED_BYTE, 1565 shared_memory_address_)) 1566 .Times(1) 1567 .RetiresOnSaturation(); 1568 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1569 } 1570 1571 TEST_P(GLES2DecoderTest, TexSubImage2DDoesNotClearAfterTexImage2DNULLThenData) { 1572 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 1573 DoTexImage2D( 1574 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 1575 DoTexImage2D(GL_TEXTURE_2D, 1576 0, 1577 GL_RGBA, 1578 2, 1579 2, 1580 0, 1581 GL_RGBA, 1582 GL_UNSIGNED_BYTE, 1583 kSharedMemoryId, 1584 kSharedMemoryOffset); 1585 EXPECT_CALL(*gl_, 1586 TexSubImage2D(GL_TEXTURE_2D, 1587 0, 1588 1, 1589 1, 1590 1, 1591 1, 1592 GL_RGBA, 1593 GL_UNSIGNED_BYTE, 1594 shared_memory_address_)) 1595 .Times(1) 1596 .RetiresOnSaturation(); 1597 TexSubImage2D cmd; 1598 cmd.Init(GL_TEXTURE_2D, 1599 0, 1600 1, 1601 1, 1602 1, 1603 1, 1604 GL_RGBA, 1605 GL_UNSIGNED_BYTE, 1606 kSharedMemoryId, 1607 kSharedMemoryOffset, 1608 GL_FALSE); 1609 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1610 // Test if we call it again it does not clear. 1611 EXPECT_CALL(*gl_, 1612 TexSubImage2D(GL_TEXTURE_2D, 1613 0, 1614 1, 1615 1, 1616 1, 1617 1, 1618 GL_RGBA, 1619 GL_UNSIGNED_BYTE, 1620 shared_memory_address_)) 1621 .Times(1) 1622 .RetiresOnSaturation(); 1623 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1624 } 1625 1626 TEST_P( 1627 GLES2DecoderManualInitTest, 1628 TexSubImage2DDoesNotClearAfterTexImage2DNULLThenDataWithTexImage2DIsFaster) { 1629 CommandLine command_line(0, NULL); 1630 command_line.AppendSwitchASCII( 1631 switches::kGpuDriverBugWorkarounds, 1632 base::IntToString(gpu::TEXSUBIMAGE2D_FASTER_THAN_TEXIMAGE2D)); 1633 InitState init; 1634 init.gl_version = "3.0"; 1635 init.bind_generates_resource = true; 1636 InitDecoderWithCommandLine(init, &command_line); 1637 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 1638 DoTexImage2D( 1639 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 1640 1641 { 1642 // Uses texSubimage internally because the above workaround is active and 1643 // the update is for the full size of the texture. 1644 EXPECT_CALL(*gl_, 1645 TexSubImage2D( 1646 GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, _)) 1647 .Times(1) 1648 .RetiresOnSaturation(); 1649 cmds::TexImage2D cmd; 1650 cmd.Init(GL_TEXTURE_2D, 1651 0, 1652 GL_RGBA, 1653 2, 1654 2, 1655 GL_RGBA, 1656 GL_UNSIGNED_BYTE, 1657 kSharedMemoryId, 1658 kSharedMemoryOffset); 1659 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1660 } 1661 1662 EXPECT_CALL(*gl_, 1663 TexSubImage2D(GL_TEXTURE_2D, 1664 0, 1665 1, 1666 1, 1667 1, 1668 1, 1669 GL_RGBA, 1670 GL_UNSIGNED_BYTE, 1671 shared_memory_address_)) 1672 .Times(1) 1673 .RetiresOnSaturation(); 1674 TexSubImage2D cmd; 1675 cmd.Init(GL_TEXTURE_2D, 1676 0, 1677 1, 1678 1, 1679 1, 1680 1, 1681 GL_RGBA, 1682 GL_UNSIGNED_BYTE, 1683 kSharedMemoryId, 1684 kSharedMemoryOffset, 1685 GL_FALSE); 1686 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1687 // Test if we call it again it does not clear. 1688 EXPECT_CALL(*gl_, 1689 TexSubImage2D(GL_TEXTURE_2D, 1690 0, 1691 1, 1692 1, 1693 1, 1694 1, 1695 GL_RGBA, 1696 GL_UNSIGNED_BYTE, 1697 shared_memory_address_)) 1698 .Times(1) 1699 .RetiresOnSaturation(); 1700 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1701 } 1702 1703 TEST_P(GLES2DecoderTest, TexSubImage2DClearsAfterTexImage2DWithDataThenNULL) { 1704 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 1705 // Put in data (so it should be marked as cleared) 1706 DoTexImage2D(GL_TEXTURE_2D, 1707 0, 1708 GL_RGBA, 1709 2, 1710 2, 1711 0, 1712 GL_RGBA, 1713 GL_UNSIGNED_BYTE, 1714 kSharedMemoryId, 1715 kSharedMemoryOffset); 1716 // Put in no data. 1717 TexImage2D tex_cmd; 1718 tex_cmd.Init( 1719 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 1720 // It won't actually call TexImage2D, just mark it as uncleared. 1721 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd)); 1722 // Next call to TexSubImage2d should clear. 1723 SetupClearTextureExpectations(kServiceTextureId, 1724 kServiceTextureId, 1725 GL_TEXTURE_2D, 1726 GL_TEXTURE_2D, 1727 0, 1728 GL_RGBA, 1729 GL_RGBA, 1730 GL_UNSIGNED_BYTE, 1731 2, 1732 2); 1733 EXPECT_CALL(*gl_, 1734 TexSubImage2D(GL_TEXTURE_2D, 1735 0, 1736 1, 1737 1, 1738 1, 1739 1, 1740 GL_RGBA, 1741 GL_UNSIGNED_BYTE, 1742 shared_memory_address_)) 1743 .Times(1) 1744 .RetiresOnSaturation(); 1745 TexSubImage2D cmd; 1746 cmd.Init(GL_TEXTURE_2D, 1747 0, 1748 1, 1749 1, 1750 1, 1751 1, 1752 GL_RGBA, 1753 GL_UNSIGNED_BYTE, 1754 kSharedMemoryId, 1755 kSharedMemoryOffset, 1756 GL_FALSE); 1757 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1758 } 1759 1760 TEST_P(GLES2DecoderTest, CopyTexImage2DMarksTextureAsCleared) { 1761 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 1762 1763 TextureManager* manager = group().texture_manager(); 1764 TextureRef* texture_ref = manager->GetTexture(client_texture_id_); 1765 ASSERT_TRUE(texture_ref != NULL); 1766 Texture* texture = texture_ref->texture(); 1767 1768 EXPECT_CALL(*gl_, GetError()) 1769 .WillOnce(Return(GL_NO_ERROR)) 1770 .RetiresOnSaturation(); 1771 EXPECT_CALL(*gl_, CopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1, 0)) 1772 .Times(1) 1773 .RetiresOnSaturation(); 1774 EXPECT_CALL(*gl_, GetError()) 1775 .WillOnce(Return(GL_NO_ERROR)) 1776 .RetiresOnSaturation(); 1777 CopyTexImage2D cmd; 1778 cmd.Init(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1); 1779 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1780 1781 EXPECT_TRUE(texture->SafeToRenderFrom()); 1782 } 1783 1784 TEST_P(GLES2DecoderTest, CopyTexSubImage2DClearsUnclearedTexture) { 1785 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 1786 DoTexImage2D( 1787 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 1788 1789 SetupClearTextureExpectations(kServiceTextureId, 1790 kServiceTextureId, 1791 GL_TEXTURE_2D, 1792 GL_TEXTURE_2D, 1793 0, 1794 GL_RGBA, 1795 GL_RGBA, 1796 GL_UNSIGNED_BYTE, 1797 2, 1798 2); 1799 EXPECT_CALL(*gl_, CopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1)) 1800 .Times(1) 1801 .RetiresOnSaturation(); 1802 CopyTexSubImage2D cmd; 1803 cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1); 1804 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1805 } 1806 1807 TEST_P(GLES2DecoderManualInitTest, CompressedImage2DMarksTextureAsCleared) { 1808 InitState init; 1809 init.extensions = "GL_EXT_texture_compression_s3tc"; 1810 init.gl_version = "3.0"; 1811 init.bind_generates_resource = true; 1812 InitDecoder(init); 1813 1814 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 1815 EXPECT_CALL(*gl_, GetError()) 1816 .WillOnce(Return(GL_NO_ERROR)) 1817 .RetiresOnSaturation(); 1818 EXPECT_CALL( 1819 *gl_, 1820 CompressedTexImage2D( 1821 GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 8, _)) 1822 .Times(1) 1823 .RetiresOnSaturation(); 1824 EXPECT_CALL(*gl_, GetError()) 1825 .WillOnce(Return(GL_NO_ERROR)) 1826 .RetiresOnSaturation(); 1827 CompressedTexImage2D cmd; 1828 cmd.Init(GL_TEXTURE_2D, 1829 0, 1830 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1831 4, 1832 4, 1833 8, 1834 kSharedMemoryId, 1835 kSharedMemoryOffset); 1836 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1837 TextureManager* manager = group().texture_manager(); 1838 TextureRef* texture_ref = manager->GetTexture(client_texture_id_); 1839 EXPECT_TRUE(texture_ref->texture()->SafeToRenderFrom()); 1840 } 1841 1842 TEST_P(GLES2DecoderTest, TextureUsageAngleExtNotEnabledByDefault) { 1843 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 1844 1845 TexParameteri cmd; 1846 cmd.Init( 1847 GL_TEXTURE_2D, GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE); 1848 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1849 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 1850 } 1851 1852 TEST_P(GLES2DecoderTest, ProduceAndConsumeTextureCHROMIUM) { 1853 Mailbox mailbox = Mailbox::Generate(); 1854 1855 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 1856 DoTexImage2D( 1857 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 1858 DoTexImage2D( 1859 GL_TEXTURE_2D, 1, GL_RGBA, 2, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 1860 TextureRef* texture_ref = 1861 group().texture_manager()->GetTexture(client_texture_id_); 1862 ASSERT_TRUE(texture_ref != NULL); 1863 Texture* texture = texture_ref->texture(); 1864 EXPECT_EQ(kServiceTextureId, texture->service_id()); 1865 1866 ProduceTextureCHROMIUMImmediate& produce_cmd = 1867 *GetImmediateAs<ProduceTextureCHROMIUMImmediate>(); 1868 produce_cmd.Init(GL_TEXTURE_2D, mailbox.name); 1869 EXPECT_EQ(error::kNoError, 1870 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name))); 1871 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1872 1873 // Texture didn't change. 1874 GLsizei width; 1875 GLsizei height; 1876 GLenum type; 1877 GLenum internal_format; 1878 1879 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); 1880 EXPECT_EQ(3, width); 1881 EXPECT_EQ(1, height); 1882 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format)); 1883 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format); 1884 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type); 1885 1886 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height)); 1887 EXPECT_EQ(2, width); 1888 EXPECT_EQ(4, height); 1889 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format)); 1890 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format); 1891 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type); 1892 1893 // Service ID has not changed. 1894 EXPECT_EQ(kServiceTextureId, texture->service_id()); 1895 1896 // Create new texture for consume. 1897 EXPECT_CALL(*gl_, GenTextures(_, _)) 1898 .WillOnce(SetArgumentPointee<1>(kNewServiceId)) 1899 .RetiresOnSaturation(); 1900 DoBindTexture(GL_TEXTURE_2D, kNewClientId, kNewServiceId); 1901 1902 // Assigns and binds original service size texture ID. 1903 EXPECT_CALL(*gl_, DeleteTextures(1, _)).Times(1).RetiresOnSaturation(); 1904 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId)) 1905 .Times(1) 1906 .RetiresOnSaturation(); 1907 1908 ConsumeTextureCHROMIUMImmediate& consume_cmd = 1909 *GetImmediateAs<ConsumeTextureCHROMIUMImmediate>(); 1910 consume_cmd.Init(GL_TEXTURE_2D, mailbox.name); 1911 EXPECT_EQ(error::kNoError, 1912 ExecuteImmediateCmd(consume_cmd, sizeof(mailbox.name))); 1913 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1914 1915 // Texture is redefined. 1916 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); 1917 EXPECT_EQ(3, width); 1918 EXPECT_EQ(1, height); 1919 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format)); 1920 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format); 1921 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type); 1922 1923 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height)); 1924 EXPECT_EQ(2, width); 1925 EXPECT_EQ(4, height); 1926 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format)); 1927 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format); 1928 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type); 1929 1930 // Service ID is restored. 1931 EXPECT_EQ(kServiceTextureId, texture->service_id()); 1932 } 1933 1934 TEST_P(GLES2DecoderTest, ProduceAndConsumeDirectTextureCHROMIUM) { 1935 Mailbox mailbox = Mailbox::Generate(); 1936 1937 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 1938 DoTexImage2D( 1939 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 1940 DoTexImage2D( 1941 GL_TEXTURE_2D, 1, GL_RGBA, 2, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 1942 TextureRef* texture_ref = 1943 group().texture_manager()->GetTexture(client_texture_id_); 1944 ASSERT_TRUE(texture_ref != NULL); 1945 Texture* texture = texture_ref->texture(); 1946 EXPECT_EQ(kServiceTextureId, texture->service_id()); 1947 1948 ProduceTextureDirectCHROMIUMImmediate& produce_cmd = 1949 *GetImmediateAs<ProduceTextureDirectCHROMIUMImmediate>(); 1950 produce_cmd.Init(client_texture_id_, GL_TEXTURE_2D, mailbox.name); 1951 EXPECT_EQ(error::kNoError, 1952 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name))); 1953 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1954 1955 // Texture didn't change. 1956 GLsizei width; 1957 GLsizei height; 1958 GLenum type; 1959 GLenum internal_format; 1960 1961 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); 1962 EXPECT_EQ(3, width); 1963 EXPECT_EQ(1, height); 1964 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format)); 1965 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format); 1966 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type); 1967 1968 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height)); 1969 EXPECT_EQ(2, width); 1970 EXPECT_EQ(4, height); 1971 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format)); 1972 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format); 1973 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type); 1974 1975 // Service ID has not changed. 1976 EXPECT_EQ(kServiceTextureId, texture->service_id()); 1977 1978 // Consume the texture into a new client ID. 1979 GLuint new_texture_id = kNewClientId; 1980 CreateAndConsumeTextureCHROMIUMImmediate& consume_cmd = 1981 *GetImmediateAs<CreateAndConsumeTextureCHROMIUMImmediate>(); 1982 consume_cmd.Init(GL_TEXTURE_2D, new_texture_id, mailbox.name); 1983 EXPECT_EQ(error::kNoError, 1984 ExecuteImmediateCmd(consume_cmd, sizeof(mailbox.name))); 1985 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 1986 1987 // Make sure the new client ID is associated with the produced service ID. 1988 texture_ref = group().texture_manager()->GetTexture(new_texture_id); 1989 ASSERT_TRUE(texture_ref != NULL); 1990 texture = texture_ref->texture(); 1991 EXPECT_EQ(kServiceTextureId, texture->service_id()); 1992 1993 DoBindTexture(GL_TEXTURE_2D, kNewClientId, kServiceTextureId); 1994 1995 // Texture is redefined. 1996 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); 1997 EXPECT_EQ(3, width); 1998 EXPECT_EQ(1, height); 1999 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format)); 2000 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format); 2001 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type); 2002 2003 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height)); 2004 EXPECT_EQ(2, width); 2005 EXPECT_EQ(4, height); 2006 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format)); 2007 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format); 2008 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type); 2009 } 2010 2011 TEST_P(GLES2DecoderTest, ProduceTextureCHROMIUMInvalidTarget) { 2012 Mailbox mailbox = Mailbox::Generate(); 2013 2014 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId); 2015 DoTexImage2D( 2016 GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 3, 1, 0, GL_RGBA, 2017 GL_UNSIGNED_BYTE, 0, 0); 2018 TextureRef* texture_ref = 2019 group().texture_manager()->GetTexture(client_texture_id_); 2020 ASSERT_TRUE(texture_ref != NULL); 2021 Texture* texture = texture_ref->texture(); 2022 EXPECT_EQ(kServiceTextureId, texture->service_id()); 2023 2024 ProduceTextureDirectCHROMIUMImmediate& produce_cmd = 2025 *GetImmediateAs<ProduceTextureDirectCHROMIUMImmediate>(); 2026 produce_cmd.Init(client_texture_id_, GL_TEXTURE_2D, mailbox.name); 2027 EXPECT_EQ(error::kNoError, 2028 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name))); 2029 2030 // ProduceTexture should fail it the texture and produce targets don't match. 2031 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 2032 } 2033 2034 TEST_P(GLES2DecoderManualInitTest, DepthTextureBadArgs) { 2035 InitState init; 2036 init.extensions = "GL_ANGLE_depth_texture"; 2037 init.gl_version = "opengl es 2.0"; 2038 init.has_depth = true; 2039 init.has_stencil = true; 2040 init.request_depth = true; 2041 init.request_stencil = true; 2042 init.bind_generates_resource = true; 2043 InitDecoder(init); 2044 2045 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 2046 // Check trying to upload data fails. 2047 TexImage2D tex_cmd; 2048 tex_cmd.Init(GL_TEXTURE_2D, 2049 0, 2050 GL_DEPTH_COMPONENT, 2051 1, 2052 1, 2053 GL_DEPTH_COMPONENT, 2054 GL_UNSIGNED_INT, 2055 kSharedMemoryId, 2056 kSharedMemoryOffset); 2057 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd)); 2058 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 2059 // Try level > 0. 2060 tex_cmd.Init(GL_TEXTURE_2D, 2061 1, 2062 GL_DEPTH_COMPONENT, 2063 1, 2064 1, 2065 GL_DEPTH_COMPONENT, 2066 GL_UNSIGNED_INT, 2067 0, 2068 0); 2069 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd)); 2070 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 2071 // Make a 1 pixel depth texture. 2072 DoTexImage2D(GL_TEXTURE_2D, 2073 0, 2074 GL_DEPTH_COMPONENT, 2075 1, 2076 1, 2077 0, 2078 GL_DEPTH_COMPONENT, 2079 GL_UNSIGNED_INT, 2080 0, 2081 0); 2082 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 2083 2084 // Check that trying to update it fails. 2085 TexSubImage2D tex_sub_cmd; 2086 tex_sub_cmd.Init(GL_TEXTURE_2D, 2087 0, 2088 0, 2089 0, 2090 1, 2091 1, 2092 GL_DEPTH_COMPONENT, 2093 GL_UNSIGNED_INT, 2094 kSharedMemoryId, 2095 kSharedMemoryOffset, 2096 GL_FALSE); 2097 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_sub_cmd)); 2098 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 2099 2100 // Check that trying to CopyTexImage2D fails 2101 CopyTexImage2D copy_tex_cmd; 2102 copy_tex_cmd.Init(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, 1, 1); 2103 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_tex_cmd)); 2104 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 2105 2106 // Check that trying to CopyTexSubImage2D fails 2107 CopyTexSubImage2D copy_sub_cmd; 2108 copy_sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1); 2109 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_sub_cmd)); 2110 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 2111 } 2112 2113 TEST_P(GLES2DecoderManualInitTest, GenerateMipmapDepthTexture) { 2114 InitState init; 2115 init.extensions = "GL_ANGLE_depth_texture"; 2116 init.gl_version = "opengl es 2.0"; 2117 init.has_depth = true; 2118 init.has_stencil = true; 2119 init.request_depth = true; 2120 init.request_stencil = true; 2121 init.bind_generates_resource = true; 2122 InitDecoder(init); 2123 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 2124 DoTexImage2D(GL_TEXTURE_2D, 2125 0, 2126 GL_DEPTH_COMPONENT, 2127 2, 2128 2, 2129 0, 2130 GL_DEPTH_COMPONENT, 2131 GL_UNSIGNED_INT, 2132 0, 2133 0); 2134 GenerateMipmap cmd; 2135 cmd.Init(GL_TEXTURE_2D); 2136 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 2137 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); 2138 } 2139 2140 TEST_P(GLES2DecoderTest, BindTexImage2DCHROMIUM) { 2141 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 2142 DoTexImage2D( 2143 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 2144 TextureRef* texture_ref = 2145 group().texture_manager()->GetTexture(client_texture_id_); 2146 ASSERT_TRUE(texture_ref != NULL); 2147 Texture* texture = texture_ref->texture(); 2148 EXPECT_EQ(kServiceTextureId, texture->service_id()); 2149 2150 group().image_manager()->AddImage(gfx::GLImage::CreateGLImage(0).get(), 1); 2151 EXPECT_FALSE(group().image_manager()->LookupImage(1) == NULL); 2152 2153 GLsizei width; 2154 GLsizei height; 2155 GLenum type; 2156 GLenum internal_format; 2157 2158 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); 2159 EXPECT_EQ(3, width); 2160 EXPECT_EQ(1, height); 2161 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format)); 2162 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format); 2163 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type); 2164 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 2165 2166 // Bind image to texture. 2167 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. 2168 EXPECT_CALL(*gl_, GetError()) 2169 .WillOnce(Return(GL_NO_ERROR)) 2170 .WillOnce(Return(GL_NO_ERROR)) 2171 .RetiresOnSaturation(); 2172 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd; 2173 bind_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1); 2174 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd)); 2175 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); 2176 // Image should now be set. 2177 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 2178 2179 // Define new texture image. 2180 DoTexImage2D( 2181 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 2182 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); 2183 // Image should no longer be set. 2184 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 2185 } 2186 2187 TEST_P(GLES2DecoderTest, BindTexImage2DCHROMIUMCubeMapNotAllowed) { 2188 group().image_manager()->AddImage(gfx::GLImage::CreateGLImage(0).get(), 1); 2189 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId); 2190 2191 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd; 2192 bind_tex_image_2d_cmd.Init(GL_TEXTURE_CUBE_MAP, 1); 2193 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd)); 2194 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 2195 } 2196 2197 TEST_P(GLES2DecoderTest, OrphanGLImageWithTexImage2D) { 2198 group().image_manager()->AddImage(gfx::GLImage::CreateGLImage(0).get(), 1); 2199 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId); 2200 2201 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd; 2202 bind_tex_image_2d_cmd.Init(GL_TEXTURE_CUBE_MAP, 1); 2203 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd)); 2204 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 2205 2206 DoTexImage2D( 2207 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 2208 TextureRef* texture_ref = 2209 group().texture_manager()->GetTexture(client_texture_id_); 2210 ASSERT_TRUE(texture_ref != NULL); 2211 Texture* texture = texture_ref->texture(); 2212 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 2213 } 2214 2215 TEST_P(GLES2DecoderTest, ReleaseTexImage2DCHROMIUM) { 2216 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 2217 DoTexImage2D( 2218 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 2219 TextureRef* texture_ref = 2220 group().texture_manager()->GetTexture(client_texture_id_); 2221 ASSERT_TRUE(texture_ref != NULL); 2222 Texture* texture = texture_ref->texture(); 2223 EXPECT_EQ(kServiceTextureId, texture->service_id()); 2224 2225 group().image_manager()->AddImage(gfx::GLImage::CreateGLImage(0).get(), 1); 2226 EXPECT_FALSE(group().image_manager()->LookupImage(1) == NULL); 2227 2228 GLsizei width; 2229 GLsizei height; 2230 GLenum type; 2231 GLenum internal_format; 2232 2233 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); 2234 EXPECT_EQ(3, width); 2235 EXPECT_EQ(1, height); 2236 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format)); 2237 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format); 2238 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type); 2239 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 2240 2241 // Bind image to texture. 2242 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. 2243 EXPECT_CALL(*gl_, GetError()) 2244 .WillOnce(Return(GL_NO_ERROR)) 2245 .WillOnce(Return(GL_NO_ERROR)) 2246 .RetiresOnSaturation(); 2247 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd; 2248 bind_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1); 2249 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd)); 2250 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); 2251 // Image should now be set. 2252 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 2253 2254 // Release image from texture. 2255 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. 2256 EXPECT_CALL(*gl_, GetError()) 2257 .WillOnce(Return(GL_NO_ERROR)) 2258 .WillOnce(Return(GL_NO_ERROR)) 2259 .RetiresOnSaturation(); 2260 ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd; 2261 release_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1); 2262 EXPECT_EQ(error::kNoError, ExecuteCmd(release_tex_image_2d_cmd)); 2263 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); 2264 // Image should no longer be set. 2265 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 2266 } 2267 2268 class MockGLImage : public gfx::GLImage { 2269 public: 2270 MockGLImage() {} 2271 2272 // Overridden from gfx::GLImage: 2273 MOCK_METHOD0(Destroy, void()); 2274 MOCK_METHOD0(GetSize, gfx::Size()); 2275 MOCK_METHOD1(BindTexImage, bool(unsigned)); 2276 MOCK_METHOD1(ReleaseTexImage, void(unsigned)); 2277 MOCK_METHOD0(WillUseTexImage, void()); 2278 MOCK_METHOD0(DidUseTexImage, void()); 2279 MOCK_METHOD0(WillModifyTexImage, void()); 2280 MOCK_METHOD0(DidModifyTexImage, void()); 2281 2282 protected: 2283 virtual ~MockGLImage() {} 2284 }; 2285 2286 TEST_P(GLES2DecoderWithShaderTest, UseTexImage) { 2287 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 2288 DoTexImage2D(GL_TEXTURE_2D, 2289 0, 2290 GL_RGBA, 2291 1, 2292 1, 2293 0, 2294 GL_RGBA, 2295 GL_UNSIGNED_BYTE, 2296 kSharedMemoryId, 2297 kSharedMemoryOffset); 2298 2299 TextureRef* texture_ref = 2300 group().texture_manager()->GetTexture(client_texture_id_); 2301 ASSERT_TRUE(texture_ref != NULL); 2302 Texture* texture = texture_ref->texture(); 2303 EXPECT_EQ(kServiceTextureId, texture->service_id()); 2304 2305 const int32 kImageId = 1; 2306 scoped_refptr<MockGLImage> image(new MockGLImage); 2307 group().image_manager()->AddImage(image.get(), kImageId); 2308 2309 // Bind image to texture. 2310 EXPECT_CALL(*image, BindTexImage(GL_TEXTURE_2D)) 2311 .Times(1) 2312 .WillOnce(Return(true)) 2313 .RetiresOnSaturation(); 2314 EXPECT_CALL(*image, GetSize()) 2315 .Times(1) 2316 .WillOnce(Return(gfx::Size(1, 1))) 2317 .RetiresOnSaturation(); 2318 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. 2319 EXPECT_CALL(*gl_, GetError()) 2320 .WillOnce(Return(GL_NO_ERROR)) 2321 .WillOnce(Return(GL_NO_ERROR)) 2322 .RetiresOnSaturation(); 2323 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd; 2324 bind_tex_image_2d_cmd.Init(GL_TEXTURE_2D, kImageId); 2325 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd)); 2326 2327 AddExpectationsForSimulatedAttrib0(kNumVertices, 0); 2328 SetupExpectationsForApplyingDefaultDirtyState(); 2329 2330 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. 2331 EXPECT_CALL(*gl_, GetError()) 2332 .WillOnce(Return(GL_NO_ERROR)) 2333 .WillOnce(Return(GL_NO_ERROR)) 2334 .WillOnce(Return(GL_NO_ERROR)) 2335 .WillOnce(Return(GL_NO_ERROR)) 2336 .RetiresOnSaturation(); 2337 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(3).RetiresOnSaturation(); 2338 EXPECT_CALL(*image, WillUseTexImage()).Times(1).RetiresOnSaturation(); 2339 EXPECT_CALL(*image, DidUseTexImage()).Times(1).RetiresOnSaturation(); 2340 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices)) 2341 .Times(1) 2342 .RetiresOnSaturation(); 2343 DrawArrays cmd; 2344 cmd.Init(GL_TRIANGLES, 0, kNumVertices); 2345 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 2346 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 2347 2348 DoBindFramebuffer( 2349 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId); 2350 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. 2351 EXPECT_CALL(*gl_, GetError()) 2352 .WillOnce(Return(GL_NO_ERROR)) 2353 .WillOnce(Return(GL_NO_ERROR)) 2354 .RetiresOnSaturation(); 2355 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation(); 2356 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId)) 2357 .Times(2) 2358 .RetiresOnSaturation(); 2359 // Image will be 'in use' as long as bound to a framebuffer. 2360 EXPECT_CALL(*image, WillUseTexImage()).Times(1).RetiresOnSaturation(); 2361 EXPECT_CALL(*gl_, 2362 FramebufferTexture2DEXT(GL_FRAMEBUFFER, 2363 GL_COLOR_ATTACHMENT0, 2364 GL_TEXTURE_2D, 2365 kServiceTextureId, 2366 0)) 2367 .Times(1) 2368 .RetiresOnSaturation(); 2369 EXPECT_CALL(*gl_, GetError()) 2370 .WillOnce(Return(GL_NO_ERROR)) 2371 .WillOnce(Return(GL_NO_ERROR)) 2372 .RetiresOnSaturation(); 2373 FramebufferTexture2D fbtex_cmd; 2374 fbtex_cmd.Init(GL_FRAMEBUFFER, 2375 GL_COLOR_ATTACHMENT0, 2376 GL_TEXTURE_2D, 2377 client_texture_id_); 2378 EXPECT_EQ(error::kNoError, ExecuteCmd(fbtex_cmd)); 2379 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 2380 2381 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. 2382 EXPECT_CALL(*gl_, GetError()) 2383 .WillOnce(Return(GL_NO_ERROR)) 2384 .WillOnce(Return(GL_NO_ERROR)) 2385 .RetiresOnSaturation(); 2386 EXPECT_CALL(*gl_, 2387 FramebufferRenderbufferEXT(GL_FRAMEBUFFER, 2388 GL_COLOR_ATTACHMENT0, 2389 GL_RENDERBUFFER, 2390 kServiceRenderbufferId)) 2391 .Times(1) 2392 .RetiresOnSaturation(); 2393 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation(); 2394 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId)) 2395 .Times(2) 2396 .RetiresOnSaturation(); 2397 // Image should no longer be 'in use' after being unbound from framebuffer. 2398 EXPECT_CALL(*image, DidUseTexImage()).Times(1).RetiresOnSaturation(); 2399 EXPECT_CALL(*gl_, GetError()) 2400 .WillOnce(Return(GL_NO_ERROR)) 2401 .WillOnce(Return(GL_NO_ERROR)) 2402 .RetiresOnSaturation(); 2403 FramebufferRenderbuffer fbrb_cmd; 2404 fbrb_cmd.Init(GL_FRAMEBUFFER, 2405 GL_COLOR_ATTACHMENT0, 2406 GL_RENDERBUFFER, 2407 client_renderbuffer_id_); 2408 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd)); 2409 } 2410 2411 TEST_P(GLES2DecoderManualInitTest, DrawWithGLImageExternal) { 2412 InitState init; 2413 init.extensions = "GL_OES_EGL_image_external"; 2414 init.gl_version = "opengl es 2.0"; 2415 init.has_alpha = true; 2416 init.has_depth = true; 2417 init.request_alpha = true; 2418 init.request_depth = true; 2419 init.bind_generates_resource = true; 2420 InitDecoder(init); 2421 2422 TextureRef* texture_ref = GetTexture(client_texture_id_); 2423 scoped_refptr<MockGLImage> image(new MockGLImage); 2424 group().texture_manager()->SetTarget(texture_ref, GL_TEXTURE_EXTERNAL_OES); 2425 group().texture_manager()->SetLevelInfo(texture_ref, 2426 GL_TEXTURE_EXTERNAL_OES, 2427 0, 2428 GL_RGBA, 2429 0, 2430 0, 2431 1, 2432 0, 2433 GL_RGBA, 2434 GL_UNSIGNED_BYTE, 2435 true); 2436 group().texture_manager()->SetLevelImage( 2437 texture_ref, GL_TEXTURE_EXTERNAL_OES, 0, image); 2438 2439 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId); 2440 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 2441 2442 SetupSamplerExternalProgram(); 2443 SetupIndexBuffer(); 2444 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0); 2445 SetupExpectationsForApplyingDefaultDirtyState(); 2446 EXPECT_TRUE(group().texture_manager()->CanRender(texture_ref)); 2447 2448 InSequence s; 2449 EXPECT_CALL(*gl_, GetError()) 2450 .WillOnce(Return(GL_NO_ERROR)) 2451 .RetiresOnSaturation(); 2452 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation(); 2453 EXPECT_CALL(*image, WillUseTexImage()).Times(1).RetiresOnSaturation(); 2454 EXPECT_CALL(*gl_, GetError()) 2455 .WillOnce(Return(GL_NO_ERROR)) 2456 .RetiresOnSaturation(); 2457 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(1); 2458 EXPECT_CALL(*gl_, GetError()) 2459 .WillOnce(Return(GL_NO_ERROR)) 2460 .RetiresOnSaturation(); 2461 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation(); 2462 EXPECT_CALL(*image, DidUseTexImage()).Times(1).RetiresOnSaturation(); 2463 EXPECT_CALL(*gl_, GetError()) 2464 .WillOnce(Return(GL_NO_ERROR)) 2465 .RetiresOnSaturation(); 2466 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation(); 2467 DrawElements cmd; 2468 cmd.Init(GL_TRIANGLES, 2469 kValidIndexRangeCount, 2470 GL_UNSIGNED_SHORT, 2471 kValidIndexRangeStart * 2); 2472 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 2473 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 2474 } 2475 2476 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatOnGLES2) { 2477 InitState init; 2478 init.extensions = "GL_OES_texture_float"; 2479 init.gl_version = "opengl es 2.0"; 2480 InitDecoder(init); 2481 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 2482 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0); 2483 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 17, 0, GL_RGB, GL_FLOAT, 0, 0); 2484 DoTexImage2D( 2485 GL_TEXTURE_2D, 0, GL_LUMINANCE, 16, 17, 0, GL_LUMINANCE, GL_FLOAT, 0, 0); 2486 DoTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 16, 17, 0, GL_ALPHA, GL_FLOAT, 0, 0); 2487 DoTexImage2D(GL_TEXTURE_2D, 2488 0, 2489 GL_LUMINANCE_ALPHA, 2490 16, 2491 17, 2492 0, 2493 GL_LUMINANCE_ALPHA, 2494 GL_FLOAT, 2495 0, 2496 0); 2497 } 2498 2499 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatOnGLES3) { 2500 InitState init; 2501 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float"; 2502 init.gl_version = "opengl es 3.0"; 2503 InitDecoder(init); 2504 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 2505 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0); 2506 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 17, 0, GL_RGB, GL_FLOAT, 0, 0); 2507 DoTexImage2D( 2508 GL_TEXTURE_2D, 0, GL_RGBA32F, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0); 2509 DoTexImage2D( 2510 GL_TEXTURE_2D, 0, GL_LUMINANCE, 16, 17, 0, GL_LUMINANCE, GL_FLOAT, 0, 0); 2511 DoTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 16, 17, 0, GL_ALPHA, GL_FLOAT, 0, 0); 2512 DoTexImage2D(GL_TEXTURE_2D, 2513 0, 2514 GL_LUMINANCE_ALPHA, 2515 16, 2516 17, 2517 0, 2518 GL_LUMINANCE_ALPHA, 2519 GL_FLOAT, 2520 0, 2521 0); 2522 } 2523 2524 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DFloatOnGLES3) { 2525 InitState init; 2526 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float"; 2527 init.gl_version = "opengl es 3.0"; 2528 InitDecoder(init); 2529 const int kWidth = 8; 2530 const int kHeight = 4; 2531 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 2532 DoTexImage2D(GL_TEXTURE_2D, 2533 0, 2534 GL_RGBA32F, 2535 kWidth, 2536 kHeight, 2537 0, 2538 GL_RGBA, 2539 GL_FLOAT, 2540 0, 2541 0); 2542 EXPECT_CALL(*gl_, 2543 TexImage2D(GL_TEXTURE_2D, 2544 0, 2545 GL_RGBA32F, 2546 kWidth, 2547 kHeight, 2548 0, 2549 GL_RGBA, 2550 GL_FLOAT, 2551 shared_memory_address_)) 2552 .Times(1) 2553 .RetiresOnSaturation(); 2554 TexSubImage2D cmd; 2555 cmd.Init(GL_TEXTURE_2D, 2556 0, 2557 0, 2558 0, 2559 kWidth, 2560 kHeight, 2561 GL_RGBA, 2562 GL_FLOAT, 2563 kSharedMemoryId, 2564 kSharedMemoryOffset, 2565 GL_FALSE); 2566 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 2567 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 2568 } 2569 2570 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DFloatDoesClearOnGLES3) { 2571 InitState init; 2572 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float"; 2573 init.gl_version = "opengl es 3.0"; 2574 InitDecoder(init); 2575 const int kWidth = 8; 2576 const int kHeight = 4; 2577 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 2578 DoTexImage2D(GL_TEXTURE_2D, 2579 0, 2580 GL_RGBA32F, 2581 kWidth, 2582 kHeight, 2583 0, 2584 GL_RGBA, 2585 GL_FLOAT, 2586 0, 2587 0); 2588 SetupClearTextureExpectations(kServiceTextureId, 2589 kServiceTextureId, 2590 GL_TEXTURE_2D, 2591 GL_TEXTURE_2D, 2592 0, 2593 GL_RGBA32F, 2594 GL_RGBA, 2595 GL_FLOAT, 2596 kWidth, 2597 kHeight); 2598 EXPECT_CALL(*gl_, 2599 TexSubImage2D(GL_TEXTURE_2D, 2600 0, 2601 1, 2602 0, 2603 kWidth - 1, 2604 kHeight, 2605 GL_RGBA, 2606 GL_FLOAT, 2607 shared_memory_address_)) 2608 .Times(1) 2609 .RetiresOnSaturation(); 2610 TexSubImage2D cmd; 2611 cmd.Init(GL_TEXTURE_2D, 2612 0, 2613 1, 2614 0, 2615 kWidth - 1, 2616 kHeight, 2617 GL_RGBA, 2618 GL_FLOAT, 2619 kSharedMemoryId, 2620 kSharedMemoryOffset, 2621 GL_FALSE); 2622 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 2623 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 2624 } 2625 2626 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatConvertsFormatDesktop) { 2627 InitState init; 2628 init.extensions = "GL_ARB_texture_float"; 2629 init.gl_version = "2.1"; 2630 InitDecoder(init); 2631 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 2632 DoTexImage2D( 2633 GL_TEXTURE_2D, 0, GL_RGBA32F, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0); 2634 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 16, 17, 0, GL_RGB, GL_FLOAT, 0, 0); 2635 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D, 2636 0, 2637 GL_RGBA, 2638 16, 2639 17, 2640 0, 2641 GL_RGBA, 2642 GL_FLOAT, 2643 0, 2644 0, 2645 GL_RGBA32F_ARB); 2646 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D, 2647 0, 2648 GL_RGB, 2649 16, 2650 17, 2651 0, 2652 GL_RGB, 2653 GL_FLOAT, 2654 0, 2655 0, 2656 GL_RGB32F_ARB); 2657 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D, 2658 0, 2659 GL_LUMINANCE, 2660 16, 2661 17, 2662 0, 2663 GL_LUMINANCE, 2664 GL_FLOAT, 2665 0, 2666 0, 2667 GL_LUMINANCE32F_ARB); 2668 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D, 2669 0, 2670 GL_ALPHA, 2671 16, 2672 17, 2673 0, 2674 GL_ALPHA, 2675 GL_FLOAT, 2676 0, 2677 0, 2678 GL_ALPHA32F_ARB); 2679 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D, 2680 0, 2681 GL_LUMINANCE_ALPHA, 2682 16, 2683 17, 2684 0, 2685 GL_LUMINANCE_ALPHA, 2686 GL_FLOAT, 2687 0, 2688 0, 2689 GL_LUMINANCE_ALPHA32F_ARB); 2690 } 2691 2692 class GLES2DecoderCompressedFormatsTest : public GLES2DecoderManualInitTest { 2693 public: 2694 GLES2DecoderCompressedFormatsTest() {} 2695 2696 static bool ValueInArray(GLint value, GLint* array, GLint count) { 2697 for (GLint ii = 0; ii < count; ++ii) { 2698 if (array[ii] == value) { 2699 return true; 2700 } 2701 } 2702 return false; 2703 } 2704 2705 void CheckFormats(const char* extension, const GLenum* formats, int count) { 2706 InitState init; 2707 init.extensions = extension; 2708 init.gl_version = "3.0"; 2709 init.bind_generates_resource = true; 2710 InitDecoder(init); 2711 2712 EXPECT_CALL(*gl_, GetError()) 2713 .WillOnce(Return(GL_NO_ERROR)) 2714 .WillOnce(Return(GL_NO_ERROR)) 2715 .WillOnce(Return(GL_NO_ERROR)) 2716 .WillOnce(Return(GL_NO_ERROR)) 2717 .RetiresOnSaturation(); 2718 2719 typedef GetIntegerv::Result Result; 2720 Result* result = static_cast<Result*>(shared_memory_address_); 2721 GetIntegerv cmd; 2722 result->size = 0; 2723 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation(); 2724 cmd.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS, 2725 shared_memory_id_, 2726 shared_memory_offset_); 2727 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 2728 EXPECT_EQ(1, result->GetNumResults()); 2729 GLint num_formats = result->GetData()[0]; 2730 EXPECT_EQ(count, num_formats); 2731 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 2732 2733 result->size = 0; 2734 cmd.Init(GL_COMPRESSED_TEXTURE_FORMATS, 2735 shared_memory_id_, 2736 shared_memory_offset_); 2737 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 2738 EXPECT_EQ(num_formats, result->GetNumResults()); 2739 2740 for (int i = 0; i < count; ++i) { 2741 EXPECT_TRUE( 2742 ValueInArray(formats[i], result->GetData(), result->GetNumResults())); 2743 } 2744 2745 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 2746 } 2747 }; 2748 2749 INSTANTIATE_TEST_CASE_P(Service, 2750 GLES2DecoderCompressedFormatsTest, 2751 ::testing::Bool()); 2752 2753 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsS3TC) { 2754 const GLenum formats[] = { 2755 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 2756 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT}; 2757 CheckFormats("GL_EXT_texture_compression_s3tc", formats, 4); 2758 } 2759 2760 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsATC) { 2761 const GLenum formats[] = {GL_ATC_RGB_AMD, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD, 2762 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD}; 2763 CheckFormats("GL_AMD_compressed_ATC_texture", formats, 3); 2764 } 2765 2766 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsPVRTC) { 2767 const GLenum formats[] = { 2768 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, 2769 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}; 2770 CheckFormats("GL_IMG_texture_compression_pvrtc", formats, 4); 2771 } 2772 2773 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsETC1) { 2774 const GLenum formats[] = {GL_ETC1_RGB8_OES}; 2775 CheckFormats("GL_OES_compressed_ETC1_RGB8_texture", formats, 1); 2776 } 2777 2778 TEST_P(GLES2DecoderManualInitTest, GetNoCompressedTextureFormats) { 2779 InitState init; 2780 init.gl_version = "3.0"; 2781 init.bind_generates_resource = true; 2782 InitDecoder(init); 2783 2784 EXPECT_CALL(*gl_, GetError()) 2785 .WillOnce(Return(GL_NO_ERROR)) 2786 .WillOnce(Return(GL_NO_ERROR)) 2787 .WillOnce(Return(GL_NO_ERROR)) 2788 .WillOnce(Return(GL_NO_ERROR)) 2789 .RetiresOnSaturation(); 2790 2791 typedef GetIntegerv::Result Result; 2792 Result* result = static_cast<Result*>(shared_memory_address_); 2793 GetIntegerv cmd; 2794 result->size = 0; 2795 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation(); 2796 cmd.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS, 2797 shared_memory_id_, 2798 shared_memory_offset_); 2799 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 2800 EXPECT_EQ(1, result->GetNumResults()); 2801 GLint num_formats = result->GetData()[0]; 2802 EXPECT_EQ(0, num_formats); 2803 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 2804 2805 result->size = 0; 2806 cmd.Init( 2807 GL_COMPRESSED_TEXTURE_FORMATS, shared_memory_id_, shared_memory_offset_); 2808 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 2809 EXPECT_EQ(num_formats, result->GetNumResults()); 2810 2811 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 2812 } 2813 2814 // TODO(gman): Complete this test. 2815 // TEST_P(GLES2DecoderTest, CompressedTexImage2DGLError) { 2816 // } 2817 2818 // TODO(gman): CompressedTexImage2D 2819 2820 // TODO(gman): CompressedTexImage2DImmediate 2821 2822 // TODO(gman): CompressedTexSubImage2DImmediate 2823 2824 // TODO(gman): TexImage2D 2825 2826 // TODO(gman): TexImage2DImmediate 2827 2828 // TODO(gman): TexSubImage2DImmediate 2829 2830 } // namespace gles2 2831 } // namespace gpu 2832