diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-08 18:10:22 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-08 18:10:22 +0000 |
commit | 5904806bfc6c3ab2497500f764ed3927c8af7c5a (patch) | |
tree | 9a465fec4034bd42cc68f0a611eaeed99e4455b4 /gpu | |
parent | f2c33c65320e1ec409184c8469ace54d9baaa499 (diff) | |
download | chromium_src-5904806bfc6c3ab2497500f764ed3927c8af7c5a.zip chromium_src-5904806bfc6c3ab2497500f764ed3927c8af7c5a.tar.gz chromium_src-5904806bfc6c3ab2497500f764ed3927c8af7c5a.tar.bz2 |
Make unit test to check glCopyTextureCHROMIUM works with deleted programs
TEST=unit tests
BUG=124720
Review URL: https://chromiumcodereview.appspot.com/10317034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135876 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/client/gles2_implementation.cc | 8 | ||||
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder.cc | 12 | ||||
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc | 12 | ||||
-rw-r--r-- | gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc | 70 | ||||
-rw-r--r-- | gpu/command_buffer/tests/gl_manager.cc | 56 | ||||
-rw-r--r-- | gpu/command_buffer/tests/gl_manager.h | 25 | ||||
-rw-r--r-- | gpu/command_buffer/tests/gl_test_utils.cc | 53 | ||||
-rw-r--r-- | gpu/command_buffer/tests/gl_test_utils.h | 24 | ||||
-rw-r--r-- | gpu/command_buffer/tests/gl_tests_main.cc | 12 | ||||
-rw-r--r-- | gpu/command_buffer/tests/gl_texture_mailbox_unittests.cc | 25 | ||||
-rw-r--r-- | gpu/command_buffer/tests/gl_unittests.cc | 41 | ||||
-rw-r--r-- | gpu/command_buffer/tests/occlusion_query_unittests.cc | 26 | ||||
-rw-r--r-- | gpu/gpu_common.gypi | 30 |
13 files changed, 285 insertions, 109 deletions
diff --git a/gpu/command_buffer/client/gles2_implementation.cc b/gpu/command_buffer/client/gles2_implementation.cc index 1375fe8..ad3ab11 100644 --- a/gpu/command_buffer/client/gles2_implementation.cc +++ b/gpu/command_buffer/client/gles2_implementation.cc @@ -1181,8 +1181,14 @@ GLint GLES2Implementation::GetUniformLocation( bool GLES2Implementation::GetProgramivHelper( GLuint program, GLenum pname, GLint* params) { - return share_group_->program_info_manager()->GetProgramiv( + bool got_value = share_group_->program_info_manager()->GetProgramiv( this, program, pname, params); + GPU_CLIENT_LOG_CODE_BLOCK({ + if (got_value) { + GPU_CLIENT_LOG(" 0: " << *params); + } + }); + return got_value; } void GLES2Implementation::LinkProgram(GLuint program) { diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index e4feafc..f486555 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -2239,16 +2239,14 @@ bool GLES2DecoderImpl::Initialize( return false; } - GLint viewport_params[4]; - glGetIntegerv(GL_VIEWPORT, viewport_params); - viewport_x_ = viewport_params[0]; - viewport_y_ = viewport_params[1]; - viewport_width_ = viewport_params[2]; - viewport_height_ = viewport_params[3]; + viewport_width_ = size.width(); + viewport_height_ = size.height(); + glViewport(viewport_x_, viewport_y_, viewport_width_, viewport_height_); + GLint viewport_params[4] = { 0 }; glGetIntegerv(GL_MAX_VIEWPORT_DIMS, viewport_params); viewport_max_width_ = viewport_params[0]; - viewport_max_height_ = viewport_params[0]; + viewport_max_height_ = viewport_params[1]; return true; } diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc index 1e717f5..4cf8bd2 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc @@ -293,15 +293,9 @@ void GLES2DecoderTestBase::InitDecoder( .RetiresOnSaturation(); #endif - static GLint viewport_dims[] = { - kViewportX, - kViewportY, - kViewportWidth, - kViewportHeight, - }; - EXPECT_CALL(*gl_, GetIntegerv(GL_VIEWPORT, _)) - .WillOnce(SetArrayArgument<1>(viewport_dims, - viewport_dims + arraysize(viewport_dims))) + EXPECT_CALL(*gl_, Viewport( + kViewportX, kViewportY, kViewportWidth, kViewportHeight)) + .Times(1) .RetiresOnSaturation(); static GLint max_viewport_dims[] = { diff --git a/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc b/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc index 28b1518..3cf025d 100644 --- a/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc +++ b/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc @@ -10,6 +10,7 @@ #include <GLES2/gl2ext.h> #include "gpu/command_buffer/tests/gl_manager.h" +#include "gpu/command_buffer/tests/gl_test_utils.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -18,9 +19,6 @@ namespace gpu { // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. class GLCopyTextureCHROMIUMTest : public testing::Test { protected: - GLCopyTextureCHROMIUMTest() : gl_(NULL, NULL) { - } - virtual void SetUp() { gl_.Initialize(gfx::Size(4, 4)); @@ -217,4 +215,70 @@ TEST_F(GLCopyTextureCHROMIUMTest, BasicStatePreservation) { EXPECT_TRUE(GL_NO_ERROR == glGetError()); }; +TEST_F(GLCopyTextureCHROMIUMTest, ProgramStatePreservation) { + // unbind the one created in setup. + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindTexture(GL_TEXTURE_2D, 0); + + GLManager gl2; + gl2.InitializeShared(gfx::Size(16, 16), &gl_); + gl_.MakeCurrent(); + + static const char* v_shader_str = + "attribute vec4 g_Position;\n" + "void main()\n" + "{\n" + " gl_Position = g_Position;\n" + "}\n"; + static const char* f_shader_str = + "precision mediump float;\n" + "void main()\n" + "{\n" + " gl_FragColor = vec4(0,1,0,1);\n" + "}\n"; + + GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str); + glUseProgram(program); + GLuint position_loc = glGetAttribLocation(program, "g_Position"); + glFlush(); + + // Delete program from other context. + gl2.MakeCurrent(); + glDeleteProgram(program); + EXPECT_TRUE(GL_NO_ERROR == glGetError()); + glFlush(); + + // Program should still be usable on this context. + gl_.MakeCurrent(); + + GLTestHelper::SetupUnitQuad(position_loc); + + // test using program before + uint8 expected[] = { 0, 255, 0, 255, }; + uint8 zero[] = { 0, 0, 0, 0, }; + glClear(GL_COLOR_BUFFER_BIT); + EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero)); + glDrawArrays(GL_TRIANGLES, 0, 6); + EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected)); + + // Call copyTextureCHROMIUM + uint8 pixels[1 * 4] = { 255u, 0u, 0u, 255u }; + glBindTexture(GL_TEXTURE_2D, textures_[0]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, + pixels); + glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA); + + // test using program after + glClear(GL_COLOR_BUFFER_BIT); + EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero)); + glDrawArrays(GL_TRIANGLES, 0, 6); + EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected)); + + EXPECT_TRUE(GL_NO_ERROR == glGetError()); + + gl2.MakeCurrent(); + gl2.Destroy(); + gl_.MakeCurrent(); +} + } // namespace gpu diff --git a/gpu/command_buffer/tests/gl_manager.cc b/gpu/command_buffer/tests/gl_manager.cc index 3629fe6..05dfd42 100644 --- a/gpu/command_buffer/tests/gl_manager.cc +++ b/gpu/command_buffer/tests/gl_manager.cc @@ -20,21 +20,50 @@ namespace gpu { -GLManager::GLManager(gles2::MailboxManager* mailbox_manager, - gfx::GLShareGroup* share_group) - : mailbox_manager_( - mailbox_manager ? mailbox_manager : new gles2::MailboxManager), - share_group_(share_group ? share_group : new gfx::GLShareGroup) { +GLManager::GLManager() { } GLManager::~GLManager() { } void GLManager::Initialize(const gfx::Size& size) { + Setup(size, NULL, NULL, NULL, NULL); +} + +void GLManager::InitializeShared( + const gfx::Size& size, GLManager* gl_manager) { + DCHECK(gl_manager); + Setup( + size, + gl_manager->mailbox_manager(), + gl_manager->share_group(), + gl_manager->decoder_->GetContextGroup(), + gl_manager->gles2_implementation()->share_group()); +} + +void GLManager::InitializeSharedMailbox( + const gfx::Size& size, GLManager* gl_manager) { + DCHECK(gl_manager); + Setup( + size, + gl_manager->mailbox_manager(), + gl_manager->share_group(), + NULL, + NULL); +} + +void GLManager::Setup( + const gfx::Size& size, + gles2::MailboxManager* mailbox_manager, + gfx::GLShareGroup* share_group, + gles2::ContextGroup* context_group, + gles2::ShareGroup* client_share_group) { const int32 kCommandBufferSize = 1024 * 1024; const size_t kStartTransferBufferSize = 4 * 1024 * 1024; const size_t kMinTransferBufferSize = 1 * 256 * 1024; const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; + const bool kBindGeneratesResource = false; + const bool kShareResources = true; // From <EGL/egl.h>. const int32 EGL_ALPHA_SIZE = 0x3021; @@ -44,6 +73,11 @@ void GLManager::Initialize(const gfx::Size& size) { const int32 EGL_DEPTH_SIZE = 0x3025; const int32 EGL_NONE = 0x3038; + mailbox_manager_ = + mailbox_manager ? mailbox_manager : new gles2::MailboxManager; + share_group_ = + share_group ? share_group : new gfx::GLShareGroup; + gfx::GpuPreference gpu_preference(gfx::PreferDiscreteGpu); const char* allowed_extensions = "*"; std::vector<int32> attribs; @@ -64,7 +98,9 @@ void GLManager::Initialize(const gfx::Size& size) { << "could not create command buffer service"; decoder_.reset(::gpu::gles2::GLES2Decoder::Create( - new gles2::ContextGroup(mailbox_manager_.get(), false))); + context_group ? context_group : + new gles2::ContextGroup( + mailbox_manager_.get(), kBindGeneratesResource))); gpu_scheduler_.reset(new GpuScheduler(command_buffer_.get(), decoder_.get(), @@ -104,10 +140,10 @@ void GLManager::Initialize(const gfx::Size& size) { // Create the object exposing the OpenGL API. gles2_implementation_.reset(new gles2::GLES2Implementation( gles2_helper_.get(), - NULL, + client_share_group, transfer_buffer_.get(), - true, - false)); + kShareResources, + kBindGeneratesResource)); ASSERT_TRUE(gles2_implementation_->Initialize( kStartTransferBufferSize, @@ -123,6 +159,8 @@ void GLManager::MakeCurrent() { void GLManager::Destroy() { if (gles2_implementation_.get()) { + MakeCurrent(); + EXPECT_TRUE(glGetError() == GL_NONE); gles2_implementation_->Flush(); gles2_implementation_.reset(); } diff --git a/gpu/command_buffer/tests/gl_manager.h b/gpu/command_buffer/tests/gl_manager.h index b25bbfb..ba5b7d0 100644 --- a/gpu/command_buffer/tests/gl_manager.h +++ b/gpu/command_buffer/tests/gl_manager.h @@ -25,25 +25,46 @@ class GpuScheduler; namespace gles2 { +class ContextGroup; class MailboxManager; class GLES2Decoder; class GLES2CmdHelper; class GLES2Implementation; +class ShareGroup; }; class GLManager { public: - GLManager(gles2::MailboxManager* mailbox_manager, - gfx::GLShareGroup* share_group); + GLManager(); ~GLManager(); void Initialize(const gfx::Size& size); + void InitializeShared(const gfx::Size& size, GLManager* gl_manager); + void InitializeSharedMailbox(const gfx::Size& size, GLManager* gl_manager); void Destroy(); void MakeCurrent(); + gles2::MailboxManager* mailbox_manager() const { + return mailbox_manager_.get(); + } + + gfx::GLShareGroup* share_group() const { + return share_group_.get(); + } + + gles2::GLES2Implementation* gles2_implementation() const { + return gles2_implementation_.get(); + } + private: + void Setup( + const gfx::Size& size, + gles2::MailboxManager* mailbox_manager, + gfx::GLShareGroup* share_group, + gles2::ContextGroup* context_group, + gles2::ShareGroup* client_share_group); void PumpCommands(); bool GetBufferChanged(int32 transfer_buffer_id); diff --git a/gpu/command_buffer/tests/gl_test_utils.cc b/gpu/command_buffer/tests/gl_test_utils.cc index 82e6222..cfbba24 100644 --- a/gpu/command_buffer/tests/gl_test_utils.cc +++ b/gpu/command_buffer/tests/gl_test_utils.cc @@ -7,6 +7,7 @@ #include <stdio.h> #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" +#include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" bool GLTestHelper::HasExtension(const char* extension) { @@ -83,6 +84,52 @@ GLuint GLTestHelper::LoadProgram( return SetupProgram(vertex_shader, fragment_shader); } +GLuint GLTestHelper::SetupUnitQuad(GLint position_location) { + GLuint vbo = 0; + glGenBuffers(1, &vbo); + glBindBuffer(GL_ARRAY_BUFFER, vbo); + static float vertices[] = { + 1.0f, 1.0f, + -1.0f, 1.0f, + -1.0f, -1.0f, + 1.0f, 1.0f, + -1.0f, -1.0f, + 1.0f, -1.0f, + }; + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); + glEnableVertexAttribArray(position_location); + glVertexAttribPointer(position_location, 2, GL_FLOAT, GL_FALSE, 0, 0); + + return vbo; +} + +bool GLTestHelper::CheckPixels( + GLint x, GLint y, GLsizei width, GLsizei height, GLint tolerance, + uint8* color) { + GLsizei size = width * height * 4; + scoped_array<uint8> pixels(new uint8[size]); + memset(pixels.get(), 123, size); + glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); + bool same = true; + for (GLint yy = 0; yy < height; ++yy) { + for (GLint xx = 0; xx < width; ++xx) { + int offset = ((yy + y) * width + (xx + x)) * 4; + for (int jj = 0; jj < 4; ++jj) { + uint8 actual = pixels[offset + jj]; + uint8 expected = color[jj]; + int diff = actual - expected; + diff = diff < 0 ? -diff: diff; + if (diff > tolerance) { + EXPECT_EQ(expected, actual) << " at " << (xx + x) << ", " << (yy + y) + << " channel " << jj; + same = false; + } + } + } + } + return same; +} + namespace { void Set16BitValue(uint8 dest[2], uint16 value) { @@ -123,6 +170,7 @@ struct BitmapInfoHeader{ bool GLTestHelper::SaveBackbufferAsBMP( const char* filename, int width, int height) { FILE* fp = fopen(filename, "wb"); + EXPECT_TRUE(fp != NULL); glPixelStorei(GL_PACK_ALIGNMENT, 1); int num_pixels = width * height; int size = num_pixels * 4; @@ -162,9 +210,12 @@ bool GLTestHelper::SaveBackbufferAsBMP( fwrite(&bih, sizeof(bih), 1, fp); fwrite(pixels, size, 1, fp); fclose(fp); - return true; } +int GLTestHelper::RunTests(int argc, char** argv) { + testing::InitGoogleMock(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/gpu/command_buffer/tests/gl_test_utils.h b/gpu/command_buffer/tests/gl_test_utils.h index c5c6ec9..9f8f234 100644 --- a/gpu/command_buffer/tests/gl_test_utils.h +++ b/gpu/command_buffer/tests/gl_test_utils.h @@ -8,17 +8,41 @@ #define GPU_COMMAND_BUFFER_TESTS_GL_TEST_UTILS_H_ #include <GLES2/gl2.h> +#include "base/basictypes.h" class GLTestHelper { public: static bool HasExtension(const char* extension); static bool CheckGLError(const char* msg, int line); + + // Compiles a shader. + // Returns shader, 0 on failure.. static GLuint LoadShader(GLenum type, const char* shaderSrc); + + // Attaches 2 shaders and links them to a program. + // Returns program, 0 on failure.. static GLuint SetupProgram(GLuint vertex_shader, GLuint fragment_shader); + + // Compiles 2 shaders, attaches and links them to a program + // Returns program, 0 on failure. static GLuint LoadProgram( const char* vertex_shader_source, const char* fragment_shader_source); + + // Make a unit quad with position only. + // Returns the created buffer. + static GLuint SetupUnitQuad(GLint position_location); + + // Checks an area of pixels for a color. + static bool CheckPixels( + GLint x, GLint y, GLsizei width, GLsizei height, GLint tolerance, + uint8* color); + + // Uses ReadPixels to save an area of the current FBO/Backbuffer. static bool SaveBackbufferAsBMP(const char* filename, int width, int height); + + // Run unit tests. + static int RunTests(int argc, char** argv); }; #endif // GPU_COMMAND_BUFFER_TESTS_GL_TEST_UTILS_H_ diff --git a/gpu/command_buffer/tests/gl_tests_main.cc b/gpu/command_buffer/tests/gl_tests_main.cc index 326ef5e..544f8b3 100644 --- a/gpu/command_buffer/tests/gl_tests_main.cc +++ b/gpu/command_buffer/tests/gl_tests_main.cc @@ -5,9 +5,11 @@ #include "base/at_exit.h" #include "base/command_line.h" #include "base/message_loop.h" +#if defined(OS_MACOSX) +#include "base/mac/scoped_nsautorelease_pool.h" +#endif #include "gpu/command_buffer/client/gles2_lib.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" +#include "gpu/command_buffer/tests/gl_test_utils.h" #include "ui/gfx/gl/gl_surface.h" #if defined(TOOLKIT_GTK) @@ -17,6 +19,9 @@ int main(int argc, char** argv) { base::AtExitManager exit_manager; CommandLine::Init(argc, argv); +#if defined(OS_MACOSX) + base::mac::ScopedNSAutoreleasePool pool; +#endif #if defined(TOOLKIT_GTK) gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); #endif @@ -24,8 +29,7 @@ int main(int argc, char** argv) { ::gles2::Initialize(); MessageLoop::Type message_loop_type = MessageLoop::TYPE_UI; MessageLoop main_message_loop(message_loop_type); - testing::InitGoogleMock(&argc, argv); - return RUN_ALL_TESTS(); + return GLTestHelper::RunTests(argc, argv); } diff --git a/gpu/command_buffer/tests/gl_texture_mailbox_unittests.cc b/gpu/command_buffer/tests/gl_texture_mailbox_unittests.cc index d9633ec..2dbcafe 100644 --- a/gpu/command_buffer/tests/gl_texture_mailbox_unittests.cc +++ b/gpu/command_buffer/tests/gl_texture_mailbox_unittests.cc @@ -42,29 +42,22 @@ uint32 ReadTexel(GLuint id, GLint x, GLint y) { 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() { - gl1_->Initialize(gfx::Size(4, 4)); - gl2_->Initialize(gfx::Size(4, 4)); + gl1_.Initialize(gfx::Size(4, 4)); + gl2_.InitializeSharedMailbox(gfx::Size(4, 4), &gl1_); } virtual void TearDown() { - gl1_->Destroy(); - gl2_->Destroy(); + gl1_.Destroy(); + gl2_.Destroy(); } - scoped_ptr<GLManager> gl1_; - scoped_ptr<GLManager> gl2_; + GLManager gl1_; + GLManager gl2_; }; TEST_F(GLTextureMailboxTest, ProduceAndConsumeTexture) { - gl1_->MakeCurrent(); + gl1_.MakeCurrent(); GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; glGenMailboxCHROMIUM(mailbox1); @@ -89,7 +82,7 @@ TEST_F(GLTextureMailboxTest, ProduceAndConsumeTexture) { glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox1); glFlush(); - gl2_->MakeCurrent(); + gl2_.MakeCurrent(); GLuint tex2; glGenTextures(1, &tex2); @@ -100,7 +93,7 @@ TEST_F(GLTextureMailboxTest, ProduceAndConsumeTexture) { glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); glFlush(); - gl1_->MakeCurrent(); + gl1_.MakeCurrent(); glBindTexture(GL_TEXTURE_2D, tex1); glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); diff --git a/gpu/command_buffer/tests/gl_unittests.cc b/gpu/command_buffer/tests/gl_unittests.cc index acac95e..1a01c6a 100644 --- a/gpu/command_buffer/tests/gl_unittests.cc +++ b/gpu/command_buffer/tests/gl_unittests.cc @@ -6,6 +6,7 @@ #include <GLES2/gl2ext.h> #include "gpu/command_buffer/tests/gl_manager.h" +#include "gpu/command_buffer/tests/gl_test_utils.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -13,9 +14,6 @@ namespace gpu { class GLTest : public testing::Test { protected: - GLTest() : gl_(NULL, NULL) { - } - virtual void SetUp() { gl_.Initialize(gfx::Size(4, 4)); } @@ -31,12 +29,37 @@ class GLTest : public testing::Test { 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]); + uint8 expected[] = { 0, 255, 0, 255, }; + EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected)); +} + +TEST_F(GLTest, SimpleShader) { + static const char* v_shader_str = + "attribute vec4 a_Position;\n" + "void main()\n" + "{\n" + " gl_Position = a_Position;\n" + "}\n"; + static const char* f_shader_str = + "precision mediump float;\n" + "void main()\n" + "{\n" + " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" + "}\n"; + + GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str); + glUseProgram(program); + GLuint position_loc = glGetAttribLocation(program, "a_Position"); + + GLTestHelper::SetupUnitQuad(position_loc); + + uint8 expected_clear[] = { 127, 0, 255, 0, }; + glClearColor(0.5f, 0.0f, 1.0f, 0.0f); + glClear(GL_COLOR_BUFFER_BIT); + EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 1, expected_clear)); + uint8 expected_draw[] = { 0, 255, 0, 255, }; + glDrawArrays(GL_TRIANGLES, 0, 6); + EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_draw)); } } // namespace gpu diff --git a/gpu/command_buffer/tests/occlusion_query_unittests.cc b/gpu/command_buffer/tests/occlusion_query_unittests.cc index efdabf3..ddf1db9 100644 --- a/gpu/command_buffer/tests/occlusion_query_unittests.cc +++ b/gpu/command_buffer/tests/occlusion_query_unittests.cc @@ -14,10 +14,6 @@ namespace gpu { class OcclusionQueryTest : public testing::Test { protected: - OcclusionQueryTest() - : gl_(NULL, NULL) { - } - virtual void SetUp() { gl_.Initialize(gfx::Size(512, 512)); } @@ -96,22 +92,7 @@ TEST_F(OcclusionQueryTest, Occlusion) { matrix_loc_ = glGetUniformLocation(program, "worldMatrix"); color_loc_ = glGetUniformLocation(program, "color"); - GLuint vbo = 0; - glGenBuffers(1, &vbo); - glBindBuffer(GL_ARRAY_BUFFER, vbo); - static float vertices[] = { - 1, 1, 0.0, - -1, 1, 0.0, - -1, -1, 0.0, - 1, 1, 0.0, - -1, -1, 0.0, - 1, -1, 0.0, - }; - glBufferData(GL_ARRAY_BUFFER, - sizeof(vertices), - NULL, - GL_STATIC_DRAW); - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); + GLTestHelper::SetupUnitQuad(position_loc_); GLuint query = 0; glGenQueriesEXT(1, &query); @@ -122,10 +103,6 @@ TEST_F(OcclusionQueryTest, Occlusion) { // Use the program object glUseProgram(program); - // Load the vertex data - glEnableVertexAttribArray(position_loc_); - glVertexAttribPointer(position_loc_, 3, GL_FLOAT, GL_FALSE, 0, 0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); static float red[] = { 1.0f, 0.0f, 0.0f, 1.0f }; DrawRect(0, 0.0f, 0.50f, red); @@ -159,7 +136,6 @@ TEST_F(OcclusionQueryTest, Occlusion) { EXPECT_TRUE(result); glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_EXT, &query_status); EXPECT_TRUE(query_status); - GLTestHelper::CheckGLError("no errors", __LINE__); } diff --git a/gpu/gpu_common.gypi b/gpu/gpu_common.gypi index 2d13ec9..4d24613 100644 --- a/gpu/gpu_common.gypi +++ b/gpu/gpu_common.gypi @@ -196,28 +196,6 @@ ], }, { - 'target_name': 'gl_unittests', - 'type': 'static_library', - 'dependencies': [ - '../base/base.gyp:base', - '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', - '../testing/gmock.gyp:gmock', - '../testing/gtest.gyp:gtest', - 'gles2_implementation_client_side_arrays', - ], - 'defines': [ - 'GLES2_C_LIB_IMPLEMENTATION', - 'GL_GLEXT_PROTOTYPES', - ], - 'sources': [ - 'command_buffer/tests/gl_test_utils.cc', - 'command_buffer/tests/gl_test_utils.h', - 'command_buffer/tests/gl_texture_mailbox_unittests.cc', - 'command_buffer/tests/gl_unittests.cc', - 'command_buffer/tests/occlusion_query_unittests.cc', - ], - }, - { 'target_name': 'gl_tests', 'type': 'executable', 'dependencies': [ @@ -235,17 +213,23 @@ 'gpu_unittest_utils', 'gles2_implementation_client_side_arrays', 'gles2_cmd_helper', - 'gl_unittests', + #'gl_unittests', ], 'defines': [ 'GLES2_C_LIB_IMPLEMENTATION', + 'GL_GLEXT_PROTOTYPES', ], 'sources': [ '<@(gles2_c_lib_source_files)', + 'command_buffer/tests/occlusion_query_unittests.cc', 'command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc', 'command_buffer/tests/gl_manager.cc', 'command_buffer/tests/gl_manager.h', 'command_buffer/tests/gl_tests_main.cc', + 'command_buffer/tests/gl_test_utils.cc', + 'command_buffer/tests/gl_test_utils.h', + 'command_buffer/tests/gl_texture_mailbox_unittests.cc', + 'command_buffer/tests/gl_unittests.cc', ], }, { |