Index: gpu/command_buffer/tests/gl_texture_mailbox_unittests.cc |
=================================================================== |
--- gpu/command_buffer/tests/gl_texture_mailbox_unittests.cc (revision 133928) |
+++ gpu/command_buffer/tests/gl_texture_mailbox_unittests.cc (working copy) |
@@ -2,38 +2,149 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#define GL_GLEXT_PROTOTYPES |
+ |
#include <GLES2/gl2.h> |
+#include <GLES2/gl2ext.h> |
+#include "gpu/command_buffer/service/mailbox_manager.h" |
#include "gpu/command_buffer/tests/gl_manager.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "ui/gfx/gl/gl_share_group.h" |
namespace gpu { |
-class GLTest : public testing::Test { |
+namespace { |
+uint32 ReadTexel(GLuint id, GLint x, GLint y) { |
+ GLint old_fbo = 0; |
+ glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo); |
+ |
+ GLuint fbo; |
+ glGenFramebuffers(1, &fbo); |
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
+ glFramebufferTexture2D(GL_FRAMEBUFFER, |
+ GL_COLOR_ATTACHMENT0, |
+ GL_TEXTURE_2D, |
+ id, |
+ 0); |
+ EXPECT_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
+ |
+ uint32 texel; |
+ glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &texel); |
+ |
+ glBindFramebuffer(GL_FRAMEBUFFER, old_fbo); |
+ |
+ glDeleteFramebuffers(1, &fbo); |
+ |
+ return texel; |
+} |
+} |
+ |
+class GLTextureMailboxTest : public testing::Test { |
protected: |
+ GLTextureMailboxTest() { |
+ gles2::MailboxManager* mailbox_manager = new gles2::MailboxManager; |
+ gfx::GLShareGroup* share_group = new gfx::GLShareGroup; |
+ gl1_.reset(new GLManager(mailbox_manager, share_group)); |
+ gl2_.reset(new GLManager(mailbox_manager, share_group)); |
+ } |
+ |
virtual void SetUp() { |
- gl_.Initialize(gfx::Size(4, 4)); |
+ gl1_->Initialize(gfx::Size(4, 4)); |
+ gl2_->Initialize(gfx::Size(4, 4)); |
} |
virtual void TearDown() { |
- gl_.Destroy(); |
+ gl1_->Destroy(); |
+ gl2_->Destroy(); |
} |
- GLManager gl_; |
+ scoped_ptr<GLManager> gl1_; |
+ scoped_ptr<GLManager> gl2_; |
}; |
-// Test that GL is at least minimally working. |
-TEST_F(GLTest, Basic) { |
- glClearColor(0.0f, 1.0f, 0.0f, 1.0f); |
- glClear(GL_COLOR_BUFFER_BIT); |
- uint8 pixels[4] = { 0, }; |
- glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
- EXPECT_EQ(0u, pixels[0]); |
- EXPECT_EQ(255u, pixels[1]); |
- EXPECT_EQ(0u, pixels[2]); |
- EXPECT_EQ(255u, pixels[3]); |
+TEST_F(GLTextureMailboxTest, ProduceAndConsumeTexture) { |
+ gl1_->MakeCurrent(); |
+ |
+ GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; |
+ glGenMailboxCHROMIUM(mailbox1); |
+ |
+ GLbyte mailbox2[GL_MAILBOX_SIZE_CHROMIUM]; |
+ glGenMailboxCHROMIUM(mailbox2); |
+ |
+ GLuint tex1; |
+ glGenTextures(1, &tex1); |
+ |
+ glBindTexture(GL_TEXTURE_2D, tex1); |
+ uint32 source_pixel = 0xFF0000FF; |
+ glTexImage2D(GL_TEXTURE_2D, |
+ 0, |
+ GL_RGBA, |
+ 1, 1, |
+ 0, |
+ GL_RGBA, |
+ GL_UNSIGNED_BYTE, |
+ &source_pixel); |
+ |
+ glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox1); |
+ glFlush(); |
+ |
+ gl2_->MakeCurrent(); |
+ |
+ GLuint tex2; |
+ glGenTextures(1, &tex2); |
+ |
+ glBindTexture(GL_TEXTURE_2D, tex2); |
+ glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox1); |
+ EXPECT_EQ(source_pixel, ReadTexel(tex2, 0, 0)); |
+ glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); |
+ glFlush(); |
+ |
+ gl1_->MakeCurrent(); |
+ |
+ glBindTexture(GL_TEXTURE_2D, tex1); |
+ glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); |
+ EXPECT_EQ(source_pixel, ReadTexel(tex1, 0, 0)); |
} |
+TEST_F(GLTextureMailboxTest, ProduceTextureValidatesKey) { |
+ GLuint tex; |
+ glGenTextures(1, &tex); |
+ |
+ glBindTexture(GL_TEXTURE_2D, tex); |
+ glTexImage2D(GL_TEXTURE_2D, |
+ 0, |
+ GL_RGBA, |
+ 1, 1, |
+ 0, |
+ GL_RGBA, |
+ GL_UNSIGNED_BYTE, |
+ NULL); |
+ |
+ GLbyte invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM]; |
+ glGenMailboxCHROMIUM(invalid_mailbox); |
+ ++invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM - 1]; |
+ |
+ EXPECT_EQ(GL_NO_ERROR, glGetError()); |
+ glProduceTextureCHROMIUM(GL_TEXTURE_2D, invalid_mailbox); |
+ EXPECT_EQ(GL_INVALID_OPERATION, glGetError()); |
Ken Russell (switch to Gerrit)
2012/04/26 22:34:14
Ideally would also test whether the texture was de
apatrick_chromium
2012/04/27 22:31:58
Done.
|
+} |
+ |
+TEST_F(GLTextureMailboxTest, ConsumeTextureValidatesKey) { |
+ GLuint tex; |
+ glGenTextures(1, &tex); |
+ |
+ glBindTexture(GL_TEXTURE_2D, tex); |
+ |
+ GLbyte invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM]; |
+ glGenMailboxCHROMIUM(invalid_mailbox); |
+ ++invalid_mailbox[GL_MAILBOX_SIZE_CHROMIUM - 1]; |
+ |
+ EXPECT_EQ(GL_NO_ERROR, glGetError()); |
+ glConsumeTextureCHROMIUM(GL_TEXTURE_2D, invalid_mailbox); |
+ EXPECT_EQ(GL_INVALID_OPERATION, glGetError()); |
+} |
+ |
} // namespace gpu |