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