| 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 |
| 71 GLManager gl1_; | 94 GLManager gl1_; |
| 72 GLManager gl2_; | 95 GLManager gl2_; |
| 73 }; | 96 }; |
| 74 | 97 |
| 75 TEST_F(GLTextureMailboxTest, ProduceAndConsumeTexture) { | 98 TEST_F(GLTextureMailboxTest, ProduceAndConsumeTexture) { |
| 76 gl1_.MakeCurrent(); | 99 gl1_.MakeCurrent(); |
| 77 | 100 |
| 78 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; | 101 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; |
| 79 glGenMailboxCHROMIUM(mailbox1); | 102 glGenMailboxCHROMIUM(mailbox1); |
| 80 | 103 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 343 |
| 321 // Mailbox should be gone now. | 344 // Mailbox should be gone now. |
| 322 glGenTextures(1, &tex2); | 345 glGenTextures(1, &tex2); |
| 323 glBindTexture(GL_TEXTURE_2D, tex2); | 346 glBindTexture(GL_TEXTURE_2D, tex2); |
| 324 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox); | 347 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox); |
| 325 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); | 348 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); |
| 326 glDeleteTextures(1, &tex2); | 349 glDeleteTextures(1, &tex2); |
| 327 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 350 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 328 } | 351 } |
| 329 | 352 |
| 330 TEST_F(GLTextureMailboxTest, ProduceFrontBuffer) { | 353 TEST_F(GLTextureMailboxTest, TakeFrontBuffer) { |
| 331 gl1_.MakeCurrent(); | 354 gl1_.MakeCurrent(); |
| 332 Mailbox mailbox; | 355 Mailbox mailbox; |
| 333 glGenMailboxCHROMIUM(mailbox.name); | 356 glGenMailboxCHROMIUM(mailbox.name); |
| 334 | 357 |
| 335 gl2_.MakeCurrent(); | 358 gl2_.MakeCurrent(); |
| 336 gl2_.decoder()->ProduceFrontBuffer(mailbox); | 359 glResizeCHROMIUM(10, 10, 1, true); |
| 360 glClearColor(0, 1, 1, 1); |
| 361 glClear(GL_COLOR_BUFFER_BIT); |
| 362 ::gles2::GetGLContext()->SwapBuffers(); |
| 363 gl2_.decoder()->TakeFrontBuffer(mailbox); |
| 337 | 364 |
| 338 gl1_.MakeCurrent(); | 365 gl1_.MakeCurrent(); |
| 339 GLuint tex1; | 366 GLuint tex1; |
| 340 glGenTextures(1, &tex1); | 367 glGenTextures(1, &tex1); |
| 341 glBindTexture(GL_TEXTURE_2D, tex1); | 368 glBindTexture(GL_TEXTURE_2D, tex1); |
| 342 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 369 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 343 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 370 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 371 EXPECT_EQ(0xFFFFFF00u, ReadTexel(tex1, 0, 0)); |
| 344 | 372 |
| 345 gl2_.MakeCurrent(); | 373 gl2_.MakeCurrent(); |
| 346 glResizeCHROMIUM(10, 10, 1, true); | |
| 347 glClearColor(1, 0, 0, 1); | 374 glClearColor(1, 0, 0, 1); |
| 348 glClear(GL_COLOR_BUFFER_BIT); | 375 glClear(GL_COLOR_BUFFER_BIT); |
| 349 ::gles2::GetGLContext()->SwapBuffers(); | 376 ::gles2::GetGLContext()->SwapBuffers(); |
| 350 | 377 |
| 351 gl1_.MakeCurrent(); | 378 gl1_.MakeCurrent(); |
| 352 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 0, 0)); | 379 EXPECT_EQ(0xFFFFFF00u, ReadTexel(tex1, 0, 0)); |
| 353 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 9, 9)); | 380 |
| 354 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 381 glDeleteTextures(1, &tex1); |
| 382 |
| 383 Mailbox mailbox2; |
| 384 glGenMailboxCHROMIUM(mailbox2.name); |
| 355 | 385 |
| 356 gl2_.MakeCurrent(); | 386 gl2_.MakeCurrent(); |
| 387 gl2_.decoder()->ReturnFrontBuffer(mailbox, false); |
| 388 |
| 389 // Flushing doesn't matter, only SwapBuffers(). |
| 357 glClearColor(0, 1, 0, 1); | 390 glClearColor(0, 1, 0, 1); |
| 358 glClear(GL_COLOR_BUFFER_BIT); | 391 glClear(GL_COLOR_BUFFER_BIT); |
| 359 glFlush(); | 392 glFlush(); |
| 360 | 393 |
| 361 gl1_.MakeCurrent(); | 394 gl2_.decoder()->TakeFrontBuffer(mailbox2); |
| 362 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 0, 0)); | |
| 363 | |
| 364 gl2_.MakeCurrent(); | |
| 365 ::gles2::GetGLContext()->SwapBuffers(); | |
| 366 | 395 |
| 367 gl1_.MakeCurrent(); | 396 gl1_.MakeCurrent(); |
| 368 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex1, 0, 0)); | 397 glGenTextures(1, &tex1); |
| 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)); |
| 369 | 402 |
| 370 gl2_.MakeCurrent(); | 403 gl2_.MakeCurrent(); |
| 371 gl2_.Destroy(); | 404 gl2_.Destroy(); |
| 372 | 405 |
| 373 gl1_.MakeCurrent(); | 406 gl1_.MakeCurrent(); |
| 374 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex1, 0, 0)); | 407 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 0, 0)); |
| 375 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 408 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 376 glDeleteTextures(1, &tex1); | 409 glDeleteTextures(1, &tex1); |
| 377 } | 410 } |
| 378 | 411 |
| 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 |
| 379 TEST_F(GLTextureMailboxTest, ProduceTextureDirectInvalidTarget) { | 450 TEST_F(GLTextureMailboxTest, ProduceTextureDirectInvalidTarget) { |
| 380 gl1_.MakeCurrent(); | 451 gl1_.MakeCurrent(); |
| 381 | 452 |
| 382 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; | 453 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; |
| 383 glGenMailboxCHROMIUM(mailbox1); | 454 glGenMailboxCHROMIUM(mailbox1); |
| 384 | 455 |
| 385 GLuint tex1; | 456 GLuint tex1; |
| 386 glGenTextures(1, &tex1); | 457 glGenTextures(1, &tex1); |
| 387 | 458 |
| 388 glBindTexture(GL_TEXTURE_CUBE_MAP, tex1); | 459 glBindTexture(GL_TEXTURE_CUBE_MAP, tex1); |
| 389 uint32_t source_pixel = 0xFF0000FF; | 460 uint32_t source_pixel = 0xFF0000FF; |
| 390 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, | 461 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
| 391 0, | 462 0, |
| 392 GL_RGBA, | 463 GL_RGBA, |
| 393 1, 1, | 464 1, 1, |
| 394 0, | 465 0, |
| 395 GL_RGBA, | 466 GL_RGBA, |
| 396 GL_UNSIGNED_BYTE, | 467 GL_UNSIGNED_BYTE, |
| 397 &source_pixel); | 468 &source_pixel); |
| 398 | 469 |
| 399 glProduceTextureDirectCHROMIUM(tex1, GL_TEXTURE_2D, mailbox1); | 470 glProduceTextureDirectCHROMIUM(tex1, GL_TEXTURE_2D, mailbox1); |
| 400 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); | 471 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); |
| 401 } | 472 } |
| 402 | 473 |
| 403 // http://crbug.com/281565 | 474 // http://crbug.com/281565 |
| 404 #if !defined(OS_ANDROID) | 475 #if !defined(OS_ANDROID) |
| 405 TEST_F(GLTextureMailboxTest, ProduceFrontBufferMultipleContexts) { | 476 TEST_F(GLTextureMailboxTest, TakeFrontBufferMultipleContexts) { |
| 406 gl1_.MakeCurrent(); | 477 gl1_.MakeCurrent(); |
| 407 Mailbox mailbox[2]; | 478 Mailbox mailbox[2]; |
| 408 glGenMailboxCHROMIUM(mailbox[0].name); | 479 glGenMailboxCHROMIUM(mailbox[0].name); |
| 409 glGenMailboxCHROMIUM(mailbox[1].name); | 480 glGenMailboxCHROMIUM(mailbox[1].name); |
| 410 GLuint tex[2]; | 481 GLuint tex[2]; |
| 411 glGenTextures(2, tex); | 482 glGenTextures(2, tex); |
| 412 | 483 |
| 413 GLManager::Options options; | 484 GLManager::Options options; |
| 414 options.share_mailbox_manager = &gl1_; | 485 options.share_mailbox_manager = &gl1_; |
| 415 GLManager other_gl[2]; | 486 GLManager other_gl[2]; |
| 416 for (size_t i = 0; i < 2; ++i) { | 487 for (size_t i = 0; i < 2; ++i) { |
| 417 other_gl[i].Initialize(options); | 488 other_gl[i].Initialize(options); |
| 418 other_gl[i].MakeCurrent(); | 489 other_gl[i].MakeCurrent(); |
| 419 other_gl[i].decoder()->ProduceFrontBuffer(mailbox[i]); | 490 glResizeCHROMIUM(10, 10, 1, true); |
| 491 glClearColor(1 - i % 2, i % 2, 0, 1); |
| 492 glClear(GL_COLOR_BUFFER_BIT); |
| 493 ::gles2::GetGLContext()->SwapBuffers(); |
| 494 other_gl[i].decoder()->TakeFrontBuffer(mailbox[i]); |
| 420 // Make sure both "other gl" are in the same share group. | 495 // Make sure both "other gl" are in the same share group. |
| 421 if (!options.share_group_manager) | 496 if (!options.share_group_manager) |
| 422 options.share_group_manager = other_gl+i; | 497 options.share_group_manager = other_gl+i; |
| 423 } | 498 } |
| 424 | 499 |
| 425 | |
| 426 gl1_.MakeCurrent(); | 500 gl1_.MakeCurrent(); |
| 427 for (size_t i = 0; i < 2; ++i) { | 501 for (size_t i = 0; i < 2; ++i) { |
| 428 glBindTexture(GL_TEXTURE_2D, tex[i]); | 502 glBindTexture(GL_TEXTURE_2D, tex[i]); |
| 429 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox[i].name); | 503 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox[i].name); |
| 430 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 504 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 431 } | 505 } |
| 432 | 506 |
| 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 | |
| 441 gl1_.MakeCurrent(); | 507 gl1_.MakeCurrent(); |
| 442 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex[0], 0, 0)); | 508 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex[0], 0, 0)); |
| 443 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex[1], 9, 9)); | 509 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex[1], 9, 9)); |
| 444 | 510 |
| 445 for (size_t i = 0; i < 2; ++i) { | 511 for (size_t i = 0; i < 2; ++i) { |
| 446 other_gl[i].MakeCurrent(); | 512 other_gl[i].MakeCurrent(); |
| 447 other_gl[i].Destroy(); | 513 other_gl[i].Destroy(); |
| 448 } | 514 } |
| 449 | 515 |
| 450 gl1_.MakeCurrent(); | 516 gl1_.MakeCurrent(); |
| 451 glDeleteTextures(2, tex); | 517 glDeleteTextures(2, tex); |
| 452 } | 518 } |
| 453 #endif | 519 #endif |
| 454 | 520 |
| 455 } // namespace gpu | 521 } // namespace gpu |
| 456 | 522 |
| OLD | NEW |