| 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 Mailbox mailbox; |
| 75 glGenMailboxCHROMIUM(mailbox.name); |
| 76 gl1_.decoder()->TakeFrontBuffer(mailbox); |
| 77 |
| 78 gl2_.MakeCurrent(); |
| 79 GLuint tex; |
| 80 glGenTextures(1, &tex); |
| 81 glBindTexture(GL_TEXTURE_2D, tex); |
| 82 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 83 glDeleteTextures(1, &tex); |
| 84 glFlush(); |
| 85 gl1_.MakeCurrent(); |
| 86 return mailbox; |
| 87 } |
| 88 |
| 71 GLManager gl1_; | 89 GLManager gl1_; |
| 72 GLManager gl2_; | 90 GLManager gl2_; |
| 73 }; | 91 }; |
| 74 | 92 |
| 75 TEST_F(GLTextureMailboxTest, ProduceAndConsumeTexture) { | 93 TEST_F(GLTextureMailboxTest, ProduceAndConsumeTexture) { |
| 76 gl1_.MakeCurrent(); | 94 gl1_.MakeCurrent(); |
| 77 | 95 |
| 78 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; | 96 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; |
| 79 glGenMailboxCHROMIUM(mailbox1); | 97 glGenMailboxCHROMIUM(mailbox1); |
| 80 | 98 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 338 |
| 321 // Mailbox should be gone now. | 339 // Mailbox should be gone now. |
| 322 glGenTextures(1, &tex2); | 340 glGenTextures(1, &tex2); |
| 323 glBindTexture(GL_TEXTURE_2D, tex2); | 341 glBindTexture(GL_TEXTURE_2D, tex2); |
| 324 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox); | 342 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox); |
| 325 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); | 343 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); |
| 326 glDeleteTextures(1, &tex2); | 344 glDeleteTextures(1, &tex2); |
| 327 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 345 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 328 } | 346 } |
| 329 | 347 |
| 330 TEST_F(GLTextureMailboxTest, ProduceFrontBuffer) { | 348 TEST_F(GLTextureMailboxTest, TakeFrontBuffer) { |
| 331 gl1_.MakeCurrent(); | 349 gl1_.MakeCurrent(); |
| 332 Mailbox mailbox; | 350 Mailbox mailbox; |
| 333 glGenMailboxCHROMIUM(mailbox.name); | 351 glGenMailboxCHROMIUM(mailbox.name); |
| 334 | 352 |
| 335 gl2_.MakeCurrent(); | 353 gl2_.MakeCurrent(); |
| 336 gl2_.decoder()->ProduceFrontBuffer(mailbox); | 354 glResizeCHROMIUM(10, 10, 1, true); |
| 355 glClearColor(0, 1, 1, 1); |
| 356 glClear(GL_COLOR_BUFFER_BIT); |
| 357 ::gles2::GetGLContext()->SwapBuffers(); |
| 358 gl2_.decoder()->TakeFrontBuffer(mailbox); |
| 337 | 359 |
| 338 gl1_.MakeCurrent(); | 360 gl1_.MakeCurrent(); |
| 339 GLuint tex1; | 361 GLuint tex1; |
| 340 glGenTextures(1, &tex1); | 362 glGenTextures(1, &tex1); |
| 341 glBindTexture(GL_TEXTURE_2D, tex1); | 363 glBindTexture(GL_TEXTURE_2D, tex1); |
| 342 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 364 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 343 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 365 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 366 EXPECT_EQ(0xFFFFFF00u, ReadTexel(tex1, 0, 0)); |
| 344 | 367 |
| 345 gl2_.MakeCurrent(); | 368 gl2_.MakeCurrent(); |
| 346 glResizeCHROMIUM(10, 10, 1, true); | |
| 347 glClearColor(1, 0, 0, 1); | 369 glClearColor(1, 0, 0, 1); |
| 348 glClear(GL_COLOR_BUFFER_BIT); | 370 glClear(GL_COLOR_BUFFER_BIT); |
| 349 ::gles2::GetGLContext()->SwapBuffers(); | 371 ::gles2::GetGLContext()->SwapBuffers(); |
| 350 | 372 |
| 351 gl1_.MakeCurrent(); | 373 gl1_.MakeCurrent(); |
| 352 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 0, 0)); | 374 EXPECT_EQ(0xFFFFFF00u, ReadTexel(tex1, 0, 0)); |
| 353 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 9, 9)); | 375 |
| 354 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 376 glDeleteTextures(1, &tex1); |
| 377 |
| 378 Mailbox mailbox2; |
| 379 glGenMailboxCHROMIUM(mailbox2.name); |
| 355 | 380 |
| 356 gl2_.MakeCurrent(); | 381 gl2_.MakeCurrent(); |
| 382 gl2_.decoder()->ReturnFrontBuffer(mailbox, false); |
| 383 |
| 384 // Flushing doesn't matter, only SwapBuffers(). |
| 357 glClearColor(0, 1, 0, 1); | 385 glClearColor(0, 1, 0, 1); |
| 358 glClear(GL_COLOR_BUFFER_BIT); | 386 glClear(GL_COLOR_BUFFER_BIT); |
| 359 glFlush(); | 387 glFlush(); |
| 360 | 388 |
| 361 gl1_.MakeCurrent(); | 389 gl2_.decoder()->TakeFrontBuffer(mailbox2); |
| 362 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 0, 0)); | |
| 363 | |
| 364 gl2_.MakeCurrent(); | |
| 365 ::gles2::GetGLContext()->SwapBuffers(); | |
| 366 | 390 |
| 367 gl1_.MakeCurrent(); | 391 gl1_.MakeCurrent(); |
| 368 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex1, 0, 0)); | 392 glGenTextures(1, &tex1); |
| 393 glBindTexture(GL_TEXTURE_2D, tex1); |
| 394 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox2.name); |
| 395 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 396 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 0, 0)); |
| 369 | 397 |
| 370 gl2_.MakeCurrent(); | 398 gl2_.MakeCurrent(); |
| 371 gl2_.Destroy(); | 399 gl2_.Destroy(); |
| 372 | 400 |
| 373 gl1_.MakeCurrent(); | 401 gl1_.MakeCurrent(); |
| 374 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex1, 0, 0)); | 402 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 0, 0)); |
| 375 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 403 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 376 glDeleteTextures(1, &tex1); | 404 glDeleteTextures(1, &tex1); |
| 377 } | 405 } |
| 378 | 406 |
| 407 // The client, represented by |gl2_|, will request 5 frontbuffers, and then |
| 408 // start returning them. |
| 409 TEST_F(GLTextureMailboxTest, FrontBufferCache) { |
| 410 gl1_.MakeCurrent(); |
| 411 |
| 412 std::vector<Mailbox> mailboxes; |
| 413 for (int i = 0; i < 5; ++i) { |
| 414 Mailbox mailbox = TakeAndConsumeMailbox(); |
| 415 mailboxes.push_back(mailbox); |
| 416 } |
| 417 EXPECT_EQ(5u, gl1_.decoder()->GetSavedBackTextureCountForTest()); |
| 418 EXPECT_EQ(5u, gl1_.decoder()->GetCreatedBackTextureCountForTest()); |
| 419 |
| 420 // If the textures aren't lost, they're reused. |
| 421 for (int i = 0; i < 100; ++i) { |
| 422 gl1_.decoder()->ReturnFrontBuffer(mailboxes[0], false); |
| 423 mailboxes.erase(mailboxes.begin()); |
| 424 |
| 425 Mailbox mailbox = TakeAndConsumeMailbox(); |
| 426 mailboxes.push_back(mailbox); |
| 427 } |
| 428 |
| 429 EXPECT_EQ(5u, gl1_.decoder()->GetSavedBackTextureCountForTest()); |
| 430 EXPECT_EQ(6u, gl1_.decoder()->GetCreatedBackTextureCountForTest()); |
| 431 |
| 432 // If the textures are lost, they're not reused. |
| 433 for (int i = 0; i < 100; ++i) { |
| 434 gl1_.decoder()->ReturnFrontBuffer(mailboxes[0], true); |
| 435 mailboxes.erase(mailboxes.begin()); |
| 436 |
| 437 Mailbox mailbox = TakeAndConsumeMailbox(); |
| 438 mailboxes.push_back(mailbox); |
| 439 } |
| 440 |
| 441 EXPECT_EQ(5u, gl1_.decoder()->GetSavedBackTextureCountForTest()); |
| 442 EXPECT_EQ(106u, gl1_.decoder()->GetCreatedBackTextureCountForTest()); |
| 443 } |
| 444 |
| 379 TEST_F(GLTextureMailboxTest, ProduceTextureDirectInvalidTarget) { | 445 TEST_F(GLTextureMailboxTest, ProduceTextureDirectInvalidTarget) { |
| 380 gl1_.MakeCurrent(); | 446 gl1_.MakeCurrent(); |
| 381 | 447 |
| 382 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; | 448 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; |
| 383 glGenMailboxCHROMIUM(mailbox1); | 449 glGenMailboxCHROMIUM(mailbox1); |
| 384 | 450 |
| 385 GLuint tex1; | 451 GLuint tex1; |
| 386 glGenTextures(1, &tex1); | 452 glGenTextures(1, &tex1); |
| 387 | 453 |
| 388 glBindTexture(GL_TEXTURE_CUBE_MAP, tex1); | 454 glBindTexture(GL_TEXTURE_CUBE_MAP, tex1); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 409 glGenMailboxCHROMIUM(mailbox[1].name); | 475 glGenMailboxCHROMIUM(mailbox[1].name); |
| 410 GLuint tex[2]; | 476 GLuint tex[2]; |
| 411 glGenTextures(2, tex); | 477 glGenTextures(2, tex); |
| 412 | 478 |
| 413 GLManager::Options options; | 479 GLManager::Options options; |
| 414 options.share_mailbox_manager = &gl1_; | 480 options.share_mailbox_manager = &gl1_; |
| 415 GLManager other_gl[2]; | 481 GLManager other_gl[2]; |
| 416 for (size_t i = 0; i < 2; ++i) { | 482 for (size_t i = 0; i < 2; ++i) { |
| 417 other_gl[i].Initialize(options); | 483 other_gl[i].Initialize(options); |
| 418 other_gl[i].MakeCurrent(); | 484 other_gl[i].MakeCurrent(); |
| 419 other_gl[i].decoder()->ProduceFrontBuffer(mailbox[i]); | 485 glResizeCHROMIUM(10, 10, 1, true); |
| 486 glClearColor(1-i%2, i%2, 0, 1); |
| 487 glClear(GL_COLOR_BUFFER_BIT); |
| 488 ::gles2::GetGLContext()->SwapBuffers(); |
| 489 other_gl[i].decoder()->TakeFrontBuffer(mailbox[i]); |
| 420 // Make sure both "other gl" are in the same share group. | 490 // Make sure both "other gl" are in the same share group. |
| 421 if (!options.share_group_manager) | 491 if (!options.share_group_manager) |
| 422 options.share_group_manager = other_gl+i; | 492 options.share_group_manager = other_gl+i; |
| 423 } | 493 } |
| 424 | 494 |
| 425 | |
| 426 gl1_.MakeCurrent(); | 495 gl1_.MakeCurrent(); |
| 427 for (size_t i = 0; i < 2; ++i) { | 496 for (size_t i = 0; i < 2; ++i) { |
| 428 glBindTexture(GL_TEXTURE_2D, tex[i]); | 497 glBindTexture(GL_TEXTURE_2D, tex[i]); |
| 429 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox[i].name); | 498 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox[i].name); |
| 430 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 499 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 431 } | 500 } |
| 432 | 501 |
| 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(); | 502 gl1_.MakeCurrent(); |
| 442 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex[0], 0, 0)); | 503 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex[0], 0, 0)); |
| 443 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex[1], 9, 9)); | 504 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex[1], 9, 9)); |
| 444 | 505 |
| 445 for (size_t i = 0; i < 2; ++i) { | 506 for (size_t i = 0; i < 2; ++i) { |
| 446 other_gl[i].MakeCurrent(); | 507 other_gl[i].MakeCurrent(); |
| 447 other_gl[i].Destroy(); | 508 other_gl[i].Destroy(); |
| 448 } | 509 } |
| 449 | 510 |
| 450 gl1_.MakeCurrent(); | 511 gl1_.MakeCurrent(); |
| 451 glDeleteTextures(2, tex); | 512 glDeleteTextures(2, tex); |
| 452 } | 513 } |
| 453 #endif | 514 #endif |
| 454 | 515 |
| 455 } // namespace gpu | 516 } // namespace gpu |
| 456 | 517 |
| OLD | NEW |