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 |
| 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 |
379 TEST_F(GLTextureMailboxTest, ProduceTextureDirectInvalidTarget) { | 474 TEST_F(GLTextureMailboxTest, ProduceTextureDirectInvalidTarget) { |
380 gl1_.MakeCurrent(); | 475 gl1_.MakeCurrent(); |
381 | 476 |
382 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; | 477 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; |
383 glGenMailboxCHROMIUM(mailbox1); | 478 glGenMailboxCHROMIUM(mailbox1); |
384 | 479 |
385 GLuint tex1; | 480 GLuint tex1; |
386 glGenTextures(1, &tex1); | 481 glGenTextures(1, &tex1); |
387 | 482 |
388 glBindTexture(GL_TEXTURE_CUBE_MAP, tex1); | 483 glBindTexture(GL_TEXTURE_CUBE_MAP, tex1); |
389 uint32_t source_pixel = 0xFF0000FF; | 484 uint32_t source_pixel = 0xFF0000FF; |
390 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, | 485 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
391 0, | 486 0, |
392 GL_RGBA, | 487 GL_RGBA, |
393 1, 1, | 488 1, 1, |
394 0, | 489 0, |
395 GL_RGBA, | 490 GL_RGBA, |
396 GL_UNSIGNED_BYTE, | 491 GL_UNSIGNED_BYTE, |
397 &source_pixel); | 492 &source_pixel); |
398 | 493 |
399 glProduceTextureDirectCHROMIUM(tex1, GL_TEXTURE_2D, mailbox1); | 494 glProduceTextureDirectCHROMIUM(tex1, GL_TEXTURE_2D, mailbox1); |
400 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); | 495 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); |
401 } | 496 } |
402 | 497 |
403 // http://crbug.com/281565 | 498 // http://crbug.com/281565 |
404 #if !defined(OS_ANDROID) | 499 #if !defined(OS_ANDROID) |
405 TEST_F(GLTextureMailboxTest, ProduceFrontBufferMultipleContexts) { | 500 TEST_F(GLTextureMailboxTest, TakeFrontBufferMultipleContexts) { |
406 gl1_.MakeCurrent(); | 501 gl1_.MakeCurrent(); |
407 Mailbox mailbox[2]; | 502 Mailbox mailbox[2]; |
408 glGenMailboxCHROMIUM(mailbox[0].name); | 503 glGenMailboxCHROMIUM(mailbox[0].name); |
409 glGenMailboxCHROMIUM(mailbox[1].name); | 504 glGenMailboxCHROMIUM(mailbox[1].name); |
410 GLuint tex[2]; | 505 GLuint tex[2]; |
411 glGenTextures(2, tex); | 506 glGenTextures(2, tex); |
412 | 507 |
413 GLManager::Options options; | 508 GLManager::Options options; |
414 options.share_mailbox_manager = &gl1_; | 509 options.share_mailbox_manager = &gl1_; |
415 GLManager other_gl[2]; | 510 GLManager other_gl[2]; |
416 for (size_t i = 0; i < 2; ++i) { | 511 for (size_t i = 0; i < 2; ++i) { |
417 other_gl[i].Initialize(options); | 512 other_gl[i].Initialize(options); |
418 other_gl[i].MakeCurrent(); | 513 other_gl[i].MakeCurrent(); |
419 other_gl[i].decoder()->ProduceFrontBuffer(mailbox[i]); | 514 glResizeCHROMIUM(10, 10, 1, true); |
| 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]); |
420 // Make sure both "other gl" are in the same share group. | 519 // Make sure both "other gl" are in the same share group. |
421 if (!options.share_group_manager) | 520 if (!options.share_group_manager) |
422 options.share_group_manager = other_gl+i; | 521 options.share_group_manager = other_gl+i; |
423 } | 522 } |
424 | 523 |
425 | |
426 gl1_.MakeCurrent(); | 524 gl1_.MakeCurrent(); |
427 for (size_t i = 0; i < 2; ++i) { | 525 for (size_t i = 0; i < 2; ++i) { |
428 glBindTexture(GL_TEXTURE_2D, tex[i]); | 526 glBindTexture(GL_TEXTURE_2D, tex[i]); |
429 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox[i].name); | 527 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox[i].name); |
430 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 528 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
431 } | 529 } |
432 | 530 |
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(); | 531 gl1_.MakeCurrent(); |
442 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex[0], 0, 0)); | 532 EXPECT_EQ(0xFF0000FFu, ReadTexel(tex[0], 0, 0)); |
443 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex[1], 9, 9)); | 533 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex[1], 9, 9)); |
444 | 534 |
445 for (size_t i = 0; i < 2; ++i) { | 535 for (size_t i = 0; i < 2; ++i) { |
446 other_gl[i].MakeCurrent(); | 536 other_gl[i].MakeCurrent(); |
447 other_gl[i].Destroy(); | 537 other_gl[i].Destroy(); |
448 } | 538 } |
449 | 539 |
450 gl1_.MakeCurrent(); | 540 gl1_.MakeCurrent(); |
451 glDeleteTextures(2, tex); | 541 glDeleteTextures(2, tex); |
452 } | 542 } |
453 #endif | 543 #endif |
454 | 544 |
455 } // namespace gpu | 545 } // namespace gpu |
456 | 546 |
OLD | NEW |