| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <GLES2/gl2.h> | 5 #include <GLES2/gl2.h> |
| 6 #include <GLES2/gl2ext.h> | 6 #include <GLES2/gl2ext.h> |
| 7 #include <GLES2/gl2extchromium.h> | 7 #include <GLES2/gl2extchromium.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 GLManager::Options options; | 61 GLManager::Options options; |
| 62 options.share_mailbox_manager = &gl1_; | 62 options.share_mailbox_manager = &gl1_; |
| 63 gl2_.Initialize(options); | 63 gl2_.Initialize(options); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void TearDown() override { | 66 void TearDown() override { |
| 67 gl1_.Destroy(); | 67 gl1_.Destroy(); |
| 68 gl2_.Destroy(); | 68 gl2_.Destroy(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // The second GL context takes and consumes a mailbox from the first GL | |
| 72 // context. Assumes that |gl1_| is current. | |
| 73 Mailbox TakeAndConsumeMailbox() { | |
| 74 glResizeCHROMIUM(10, 10, 1, true); | |
| 75 glClearColor(0, 1, 1, 1); | |
| 76 glClear(GL_COLOR_BUFFER_BIT); | |
| 77 ::gles2::GetGLContext()->SwapBuffers(); | |
| 78 | |
| 79 Mailbox mailbox; | |
| 80 glGenMailboxCHROMIUM(mailbox.name); | |
| 81 gl1_.decoder()->TakeFrontBuffer(mailbox); | |
| 82 | |
| 83 gl2_.MakeCurrent(); | |
| 84 GLuint tex; | |
| 85 glGenTextures(1, &tex); | |
| 86 glBindTexture(GL_TEXTURE_2D, tex); | |
| 87 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | |
| 88 glDeleteTextures(1, &tex); | |
| 89 glFlush(); | |
| 90 gl1_.MakeCurrent(); | |
| 91 return mailbox; | |
| 92 } | |
| 93 | |
| 94 GLManager gl1_; | 71 GLManager gl1_; |
| 95 GLManager gl2_; | 72 GLManager gl2_; |
| 96 }; | 73 }; |
| 97 | 74 |
| 98 TEST_F(GLTextureMailboxTest, ProduceAndConsumeTexture) { | 75 TEST_F(GLTextureMailboxTest, ProduceAndConsumeTexture) { |
| 99 gl1_.MakeCurrent(); | 76 gl1_.MakeCurrent(); |
| 100 | 77 |
| 101 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; | 78 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; |
| 102 glGenMailboxCHROMIUM(mailbox1); | 79 glGenMailboxCHROMIUM(mailbox1); |
| 103 | 80 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 320 |
| 344 // Mailbox should be gone now. | 321 // Mailbox should be gone now. |
| 345 glGenTextures(1, &tex2); | 322 glGenTextures(1, &tex2); |
| 346 glBindTexture(GL_TEXTURE_2D, tex2); | 323 glBindTexture(GL_TEXTURE_2D, tex2); |
| 347 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox); | 324 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox); |
| 348 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); | 325 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); |
| 349 glDeleteTextures(1, &tex2); | 326 glDeleteTextures(1, &tex2); |
| 350 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 327 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 351 } | 328 } |
| 352 | 329 |
| 353 TEST_F(GLTextureMailboxTest, TakeFrontBuffer) { | 330 TEST_F(GLTextureMailboxTest, ProduceFrontBuffer) { |
| 354 gl1_.MakeCurrent(); | 331 gl1_.MakeCurrent(); |
| 355 Mailbox mailbox; | 332 Mailbox mailbox; |
| 356 glGenMailboxCHROMIUM(mailbox.name); | 333 glGenMailboxCHROMIUM(mailbox.name); |
| 357 | 334 |
| 358 gl2_.MakeCurrent(); | 335 gl2_.MakeCurrent(); |
| 359 glResizeCHROMIUM(10, 10, 1, true); | 336 gl2_.decoder()->ProduceFrontBuffer(mailbox); |
| 360 glClearColor(0, 1, 1, 1); | |
| 361 glClear(GL_COLOR_BUFFER_BIT); | |
| 362 ::gles2::GetGLContext()->SwapBuffers(); | |
| 363 gl2_.decoder()->TakeFrontBuffer(mailbox); | |
| 364 | 337 |
| 365 gl1_.MakeCurrent(); | 338 gl1_.MakeCurrent(); |
| 366 GLuint tex1; | 339 GLuint tex1; |
| 367 glGenTextures(1, &tex1); | 340 glGenTextures(1, &tex1); |
| 368 glBindTexture(GL_TEXTURE_2D, tex1); | 341 glBindTexture(GL_TEXTURE_2D, tex1); |
| 369 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 342 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 370 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 343 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 371 EXPECT_EQ(0xFFFFFF00u, ReadTexel(tex1, 0, 0)); | |
| 372 | 344 |
| 373 gl2_.MakeCurrent(); | 345 gl2_.MakeCurrent(); |
| 346 glResizeCHROMIUM(10, 10, 1, true); |
| 374 glClearColor(1, 0, 0, 1); | 347 glClearColor(1, 0, 0, 1); |
| 375 glClear(GL_COLOR_BUFFER_BIT); | 348 glClear(GL_COLOR_BUFFER_BIT); |
| 376 ::gles2::GetGLContext()->SwapBuffers(); | 349 ::gles2::GetGLContext()->SwapBuffers(); |
| 377 | 350 |
| 378 gl1_.MakeCurrent(); | 351 gl1_.MakeCurrent(); |
| 379 EXPECT_EQ(0xFFFFFF00u, ReadTexel(tex1, 0, 0)); | 352 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 0, 0)); |
| 380 | 353 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 9, 9)); |
| 381 glDeleteTextures(1, &tex1); | 354 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 382 | |
| 383 Mailbox mailbox2; | |
| 384 glGenMailboxCHROMIUM(mailbox2.name); | |
| 385 | 355 |
| 386 gl2_.MakeCurrent(); | 356 gl2_.MakeCurrent(); |
| 387 gl2_.decoder()->ReturnFrontBuffer(mailbox, false); | |
| 388 | |
| 389 // Flushing doesn't matter, only SwapBuffers(). | |
| 390 glClearColor(0, 1, 0, 1); | 357 glClearColor(0, 1, 0, 1); |
| 391 glClear(GL_COLOR_BUFFER_BIT); | 358 glClear(GL_COLOR_BUFFER_BIT); |
| 392 glFlush(); | 359 glFlush(); |
| 393 | 360 |
| 394 gl2_.decoder()->TakeFrontBuffer(mailbox2); | 361 gl1_.MakeCurrent(); |
| 362 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 0, 0)); |
| 363 |
| 364 gl2_.MakeCurrent(); |
| 365 ::gles2::GetGLContext()->SwapBuffers(); |
| 395 | 366 |
| 396 gl1_.MakeCurrent(); | 367 gl1_.MakeCurrent(); |
| 397 glGenTextures(1, &tex1); | 368 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex1, 0, 0)); |
| 398 glBindTexture(GL_TEXTURE_2D, tex1); | |
| 399 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox2.name); | |
| 400 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 401 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 0, 0)); | |
| 402 | 369 |
| 403 gl2_.MakeCurrent(); | 370 gl2_.MakeCurrent(); |
| 404 gl2_.Destroy(); | 371 gl2_.Destroy(); |
| 405 | 372 |
| 406 gl1_.MakeCurrent(); | 373 gl1_.MakeCurrent(); |
| 407 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 0, 0)); | 374 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex1, 0, 0)); |
| 408 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 375 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 409 glDeleteTextures(1, &tex1); | 376 glDeleteTextures(1, &tex1); |
| 410 } | 377 } |
| 411 | 378 |
| 412 // The client, represented by |gl2_|, will request 5 frontbuffers, and then | |
| 413 // start returning them. | |
| 414 TEST_F(GLTextureMailboxTest, FrontBufferCache) { | |
| 415 gl1_.MakeCurrent(); | |
| 416 | |
| 417 std::vector<Mailbox> mailboxes; | |
| 418 for (int i = 0; i < 5; ++i) { | |
| 419 Mailbox mailbox = TakeAndConsumeMailbox(); | |
| 420 mailboxes.push_back(mailbox); | |
| 421 } | |
| 422 EXPECT_EQ(5u, gl1_.decoder()->GetSavedBackTextureCountForTest()); | |
| 423 EXPECT_EQ(5u, gl1_.decoder()->GetCreatedBackTextureCountForTest()); | |
| 424 | |
| 425 // If the textures aren't lost, they're reused. | |
| 426 for (int i = 0; i < 100; ++i) { | |
| 427 gl1_.decoder()->ReturnFrontBuffer(mailboxes[0], false); | |
| 428 mailboxes.erase(mailboxes.begin()); | |
| 429 | |
| 430 Mailbox mailbox = TakeAndConsumeMailbox(); | |
| 431 mailboxes.push_back(mailbox); | |
| 432 } | |
| 433 | |
| 434 EXPECT_EQ(5u, gl1_.decoder()->GetSavedBackTextureCountForTest()); | |
| 435 EXPECT_EQ(5u, gl1_.decoder()->GetCreatedBackTextureCountForTest()); | |
| 436 | |
| 437 // If the textures are lost, they're not reused. | |
| 438 for (int i = 0; i < 100; ++i) { | |
| 439 gl1_.decoder()->ReturnFrontBuffer(mailboxes[0], true); | |
| 440 mailboxes.erase(mailboxes.begin()); | |
| 441 | |
| 442 Mailbox mailbox = TakeAndConsumeMailbox(); | |
| 443 mailboxes.push_back(mailbox); | |
| 444 } | |
| 445 | |
| 446 EXPECT_EQ(5u, gl1_.decoder()->GetSavedBackTextureCountForTest()); | |
| 447 EXPECT_EQ(105u, gl1_.decoder()->GetCreatedBackTextureCountForTest()); | |
| 448 } | |
| 449 | |
| 450 // The client, represented by |gl2_|, will request and return 5 frontbuffers. | |
| 451 // Then the size of the buffer will be changed. All cached frontbuffers should | |
| 452 // be discarded. | |
| 453 TEST_F(GLTextureMailboxTest, FrontBufferChangeSize) { | |
| 454 gl1_.MakeCurrent(); | |
| 455 | |
| 456 std::vector<Mailbox> mailboxes; | |
| 457 for (int i = 0; i < 5; ++i) { | |
| 458 Mailbox mailbox = TakeAndConsumeMailbox(); | |
| 459 mailboxes.push_back(mailbox); | |
| 460 } | |
| 461 EXPECT_EQ(5u, gl1_.decoder()->GetSavedBackTextureCountForTest()); | |
| 462 | |
| 463 for (int i = 0; i < 5; ++i) { | |
| 464 gl1_.decoder()->ReturnFrontBuffer(mailboxes[i], false); | |
| 465 } | |
| 466 mailboxes.clear(); | |
| 467 EXPECT_EQ(5u, gl1_.decoder()->GetSavedBackTextureCountForTest()); | |
| 468 | |
| 469 glResizeCHROMIUM(21, 31, 1, true); | |
| 470 ::gles2::GetGLContext()->SwapBuffers(); | |
| 471 EXPECT_EQ(0u, gl1_.decoder()->GetSavedBackTextureCountForTest()); | |
| 472 } | |
| 473 | |
| 474 TEST_F(GLTextureMailboxTest, ProduceTextureDirectInvalidTarget) { | 379 TEST_F(GLTextureMailboxTest, ProduceTextureDirectInvalidTarget) { |
| 475 gl1_.MakeCurrent(); | 380 gl1_.MakeCurrent(); |
| 476 | 381 |
| 477 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; | 382 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; |
| 478 glGenMailboxCHROMIUM(mailbox1); | 383 glGenMailboxCHROMIUM(mailbox1); |
| 479 | 384 |
| 480 GLuint tex1; | 385 GLuint tex1; |
| 481 glGenTextures(1, &tex1); | 386 glGenTextures(1, &tex1); |
| 482 | 387 |
| 483 glBindTexture(GL_TEXTURE_CUBE_MAP, tex1); | 388 glBindTexture(GL_TEXTURE_CUBE_MAP, tex1); |
| 484 uint32_t source_pixel = 0xFF0000FF; | 389 uint32_t source_pixel = 0xFF0000FF; |
| 485 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, | 390 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
| 486 0, | 391 0, |
| 487 GL_RGBA, | 392 GL_RGBA, |
| 488 1, 1, | 393 1, 1, |
| 489 0, | 394 0, |
| 490 GL_RGBA, | 395 GL_RGBA, |
| 491 GL_UNSIGNED_BYTE, | 396 GL_UNSIGNED_BYTE, |
| 492 &source_pixel); | 397 &source_pixel); |
| 493 | 398 |
| 494 glProduceTextureDirectCHROMIUM(tex1, GL_TEXTURE_2D, mailbox1); | 399 glProduceTextureDirectCHROMIUM(tex1, GL_TEXTURE_2D, mailbox1); |
| 495 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); | 400 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); |
| 496 } | 401 } |
| 497 | 402 |
| 498 // http://crbug.com/281565 | 403 // http://crbug.com/281565 |
| 499 #if !defined(OS_ANDROID) | 404 #if !defined(OS_ANDROID) |
| 500 TEST_F(GLTextureMailboxTest, TakeFrontBufferMultipleContexts) { | 405 TEST_F(GLTextureMailboxTest, ProduceFrontBufferMultipleContexts) { |
| 501 gl1_.MakeCurrent(); | 406 gl1_.MakeCurrent(); |
| 502 Mailbox mailbox[2]; | 407 Mailbox mailbox[2]; |
| 503 glGenMailboxCHROMIUM(mailbox[0].name); | 408 glGenMailboxCHROMIUM(mailbox[0].name); |
| 504 glGenMailboxCHROMIUM(mailbox[1].name); | 409 glGenMailboxCHROMIUM(mailbox[1].name); |
| 505 GLuint tex[2]; | 410 GLuint tex[2]; |
| 506 glGenTextures(2, tex); | 411 glGenTextures(2, tex); |
| 507 | 412 |
| 508 GLManager::Options options; | 413 GLManager::Options options; |
| 509 options.share_mailbox_manager = &gl1_; | 414 options.share_mailbox_manager = &gl1_; |
| 510 GLManager other_gl[2]; | 415 GLManager other_gl[2]; |
| 511 for (size_t i = 0; i < 2; ++i) { | 416 for (size_t i = 0; i < 2; ++i) { |
| 512 other_gl[i].Initialize(options); | 417 other_gl[i].Initialize(options); |
| 513 other_gl[i].MakeCurrent(); | 418 other_gl[i].MakeCurrent(); |
| 514 glResizeCHROMIUM(10, 10, 1, true); | 419 other_gl[i].decoder()->ProduceFrontBuffer(mailbox[i]); |
| 515 glClearColor(1 - i % 2, i % 2, 0, 1); | |
| 516 glClear(GL_COLOR_BUFFER_BIT); | |
| 517 ::gles2::GetGLContext()->SwapBuffers(); | |
| 518 other_gl[i].decoder()->TakeFrontBuffer(mailbox[i]); | |
| 519 // Make sure both "other gl" are in the same share group. | 420 // Make sure both "other gl" are in the same share group. |
| 520 if (!options.share_group_manager) | 421 if (!options.share_group_manager) |
| 521 options.share_group_manager = other_gl+i; | 422 options.share_group_manager = other_gl+i; |
| 522 } | 423 } |
| 523 | 424 |
| 425 |
| 524 gl1_.MakeCurrent(); | 426 gl1_.MakeCurrent(); |
| 525 for (size_t i = 0; i < 2; ++i) { | 427 for (size_t i = 0; i < 2; ++i) { |
| 526 glBindTexture(GL_TEXTURE_2D, tex[i]); | 428 glBindTexture(GL_TEXTURE_2D, tex[i]); |
| 527 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox[i].name); | 429 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox[i].name); |
| 528 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 430 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 529 } | 431 } |
| 530 | 432 |
| 433 for (size_t i = 0; i < 2; ++i) { |
| 434 other_gl[i].MakeCurrent(); |
| 435 glResizeCHROMIUM(10, 10, 1, true); |
| 436 glClearColor(1-i%2, i%2, 0, 1); |
| 437 glClear(GL_COLOR_BUFFER_BIT); |
| 438 ::gles2::GetGLContext()->SwapBuffers(); |
| 439 } |
| 440 |
| 531 gl1_.MakeCurrent(); | 441 gl1_.MakeCurrent(); |
| 532 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex[0], 0, 0)); | 442 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex[0], 0, 0)); |
| 533 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex[1], 9, 9)); | 443 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex[1], 9, 9)); |
| 534 | 444 |
| 535 for (size_t i = 0; i < 2; ++i) { | 445 for (size_t i = 0; i < 2; ++i) { |
| 536 other_gl[i].MakeCurrent(); | 446 other_gl[i].MakeCurrent(); |
| 537 other_gl[i].Destroy(); | 447 other_gl[i].Destroy(); |
| 538 } | 448 } |
| 539 | 449 |
| 540 gl1_.MakeCurrent(); | 450 gl1_.MakeCurrent(); |
| 541 glDeleteTextures(2, tex); | 451 glDeleteTextures(2, tex); |
| 542 } | 452 } |
| 543 #endif | 453 #endif |
| 544 | 454 |
| 545 } // namespace gpu | 455 } // namespace gpu |
| 546 | 456 |
| OLD | NEW |