Index: gpu/command_buffer/tests/gl_texture_mailbox_unittest.cc |
diff --git a/gpu/command_buffer/tests/gl_texture_mailbox_unittest.cc b/gpu/command_buffer/tests/gl_texture_mailbox_unittest.cc |
index beacdfb3163cb9080fc1618e4c615b67cc201732..81298299cb8e0e19a6c5271b334ab7ac8839ac66 100644 |
--- a/gpu/command_buffer/tests/gl_texture_mailbox_unittest.cc |
+++ b/gpu/command_buffer/tests/gl_texture_mailbox_unittest.cc |
@@ -68,6 +68,29 @@ class GLTextureMailboxTest : public testing::Test { |
gl2_.Destroy(); |
} |
+ // The second GL context takes and consumes a mailbox from the first GL |
+ // context. Assumes that |gl1_| is current. |
+ Mailbox TakeAndConsumeMailbox() { |
+ glResizeCHROMIUM(10, 10, 1, true); |
+ glClearColor(0, 1, 1, 1); |
+ glClear(GL_COLOR_BUFFER_BIT); |
+ ::gles2::GetGLContext()->SwapBuffers(); |
+ |
+ Mailbox mailbox; |
+ glGenMailboxCHROMIUM(mailbox.name); |
+ gl1_.decoder()->TakeFrontBuffer(mailbox); |
+ |
+ gl2_.MakeCurrent(); |
+ GLuint tex; |
+ glGenTextures(1, &tex); |
+ glBindTexture(GL_TEXTURE_2D, tex); |
+ glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
+ glDeleteTextures(1, &tex); |
+ glFlush(); |
+ gl1_.MakeCurrent(); |
+ return mailbox; |
+ } |
+ |
GLManager gl1_; |
GLManager gl2_; |
}; |
@@ -327,13 +350,17 @@ TEST_F(GLTextureMailboxTest, SharedTextures) { |
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
} |
-TEST_F(GLTextureMailboxTest, ProduceFrontBuffer) { |
+TEST_F(GLTextureMailboxTest, TakeFrontBuffer) { |
gl1_.MakeCurrent(); |
Mailbox mailbox; |
glGenMailboxCHROMIUM(mailbox.name); |
gl2_.MakeCurrent(); |
- gl2_.decoder()->ProduceFrontBuffer(mailbox); |
+ glResizeCHROMIUM(10, 10, 1, true); |
+ glClearColor(0, 1, 1, 1); |
+ glClear(GL_COLOR_BUFFER_BIT); |
+ ::gles2::GetGLContext()->SwapBuffers(); |
+ gl2_.decoder()->TakeFrontBuffer(mailbox); |
gl1_.MakeCurrent(); |
GLuint tex1; |
@@ -341,41 +368,85 @@ TEST_F(GLTextureMailboxTest, ProduceFrontBuffer) { |
glBindTexture(GL_TEXTURE_2D, tex1); |
glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
+ EXPECT_EQ(0xFFFFFF00u, ReadTexel(tex1, 0, 0)); |
gl2_.MakeCurrent(); |
- glResizeCHROMIUM(10, 10, 1, true); |
glClearColor(1, 0, 0, 1); |
glClear(GL_COLOR_BUFFER_BIT); |
::gles2::GetGLContext()->SwapBuffers(); |
gl1_.MakeCurrent(); |
- EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 0, 0)); |
- EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 9, 9)); |
- EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
+ EXPECT_EQ(0xFFFFFF00u, ReadTexel(tex1, 0, 0)); |
+ |
+ glDeleteTextures(1, &tex1); |
+ |
+ Mailbox mailbox2; |
+ glGenMailboxCHROMIUM(mailbox2.name); |
gl2_.MakeCurrent(); |
+ gl2_.decoder()->ReturnFrontBuffer(mailbox, false); |
+ |
+ // Flushing doesn't matter, only SwapBuffers(). |
glClearColor(0, 1, 0, 1); |
glClear(GL_COLOR_BUFFER_BIT); |
glFlush(); |
- gl1_.MakeCurrent(); |
- EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 0, 0)); |
- |
- gl2_.MakeCurrent(); |
- ::gles2::GetGLContext()->SwapBuffers(); |
+ gl2_.decoder()->TakeFrontBuffer(mailbox2); |
gl1_.MakeCurrent(); |
- EXPECT_EQ(0xFF00FF00u, ReadTexel(tex1, 0, 0)); |
+ glGenTextures(1, &tex1); |
+ glBindTexture(GL_TEXTURE_2D, tex1); |
+ glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox2.name); |
+ EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
+ EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 0, 0)); |
gl2_.MakeCurrent(); |
gl2_.Destroy(); |
gl1_.MakeCurrent(); |
- EXPECT_EQ(0xFF00FF00u, ReadTexel(tex1, 0, 0)); |
+ EXPECT_EQ(0xFF0000FFu, ReadTexel(tex1, 0, 0)); |
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
glDeleteTextures(1, &tex1); |
} |
+// The client, represented by |gl2_|, will request 5 frontbuffers, and then |
+// start returning them. |
+TEST_F(GLTextureMailboxTest, FrontBufferCache) { |
+ gl1_.MakeCurrent(); |
+ |
+ std::vector<Mailbox> mailboxes; |
+ for (int i = 0; i < 5; ++i) { |
+ Mailbox mailbox = TakeAndConsumeMailbox(); |
+ mailboxes.push_back(mailbox); |
+ } |
+ EXPECT_EQ(5u, gl1_.decoder()->GetSavedBackTextureCountForTest()); |
+ EXPECT_EQ(5u, gl1_.decoder()->GetCreatedBackTextureCountForTest()); |
+ |
+ // If the textures aren't lost, they're reused. |
+ for (int i = 0; i < 100; ++i) { |
+ gl1_.decoder()->ReturnFrontBuffer(mailboxes[0], false); |
+ mailboxes.erase(mailboxes.begin()); |
+ |
+ Mailbox mailbox = TakeAndConsumeMailbox(); |
+ mailboxes.push_back(mailbox); |
+ } |
+ |
+ EXPECT_EQ(5u, gl1_.decoder()->GetSavedBackTextureCountForTest()); |
+ EXPECT_EQ(5u, gl1_.decoder()->GetCreatedBackTextureCountForTest()); |
+ |
+ // If the textures are lost, they're not reused. |
+ for (int i = 0; i < 100; ++i) { |
+ gl1_.decoder()->ReturnFrontBuffer(mailboxes[0], true); |
+ mailboxes.erase(mailboxes.begin()); |
+ |
+ Mailbox mailbox = TakeAndConsumeMailbox(); |
+ mailboxes.push_back(mailbox); |
+ } |
+ |
+ EXPECT_EQ(5u, gl1_.decoder()->GetSavedBackTextureCountForTest()); |
+ EXPECT_EQ(105u, gl1_.decoder()->GetCreatedBackTextureCountForTest()); |
+} |
+ |
TEST_F(GLTextureMailboxTest, ProduceTextureDirectInvalidTarget) { |
gl1_.MakeCurrent(); |
@@ -402,7 +473,7 @@ TEST_F(GLTextureMailboxTest, ProduceTextureDirectInvalidTarget) { |
// http://crbug.com/281565 |
#if !defined(OS_ANDROID) |
-TEST_F(GLTextureMailboxTest, ProduceFrontBufferMultipleContexts) { |
+TEST_F(GLTextureMailboxTest, TakeFrontBufferMultipleContexts) { |
gl1_.MakeCurrent(); |
Mailbox mailbox[2]; |
glGenMailboxCHROMIUM(mailbox[0].name); |
@@ -416,13 +487,16 @@ TEST_F(GLTextureMailboxTest, ProduceFrontBufferMultipleContexts) { |
for (size_t i = 0; i < 2; ++i) { |
other_gl[i].Initialize(options); |
other_gl[i].MakeCurrent(); |
- other_gl[i].decoder()->ProduceFrontBuffer(mailbox[i]); |
+ glResizeCHROMIUM(10, 10, 1, true); |
+ glClearColor(1 - i % 2, i % 2, 0, 1); |
+ glClear(GL_COLOR_BUFFER_BIT); |
+ ::gles2::GetGLContext()->SwapBuffers(); |
+ other_gl[i].decoder()->TakeFrontBuffer(mailbox[i]); |
// Make sure both "other gl" are in the same share group. |
if (!options.share_group_manager) |
options.share_group_manager = other_gl+i; |
} |
- |
gl1_.MakeCurrent(); |
for (size_t i = 0; i < 2; ++i) { |
glBindTexture(GL_TEXTURE_2D, tex[i]); |
@@ -430,14 +504,6 @@ TEST_F(GLTextureMailboxTest, ProduceFrontBufferMultipleContexts) { |
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
} |
- for (size_t i = 0; i < 2; ++i) { |
- other_gl[i].MakeCurrent(); |
- glResizeCHROMIUM(10, 10, 1, true); |
- glClearColor(1-i%2, i%2, 0, 1); |
- glClear(GL_COLOR_BUFFER_BIT); |
- ::gles2::GetGLContext()->SwapBuffers(); |
- } |
- |
gl1_.MakeCurrent(); |
EXPECT_EQ(0xFF0000FFu, ReadTexel(tex[0], 0, 0)); |
EXPECT_EQ(0xFF00FF00u, ReadTexel(tex[1], 9, 9)); |