Chromium Code Reviews| Index: ui/gl/test/gl_image_test_template.h |
| diff --git a/ui/gl/test/gl_image_test_template.h b/ui/gl/test/gl_image_test_template.h |
| index 8b146445eddc7ccf96fccffe96e8f78e17fd60b1..985bffee1dd2691eaa37d13d517970c64e277163 100644 |
| --- a/ui/gl/test/gl_image_test_template.h |
| +++ b/ui/gl/test/gl_image_test_template.h |
| @@ -10,8 +10,6 @@ |
| #include "base/basictypes.h" |
| #include "base/memory/scoped_ptr.h" |
| -#include "base/strings/stringize_macros.h" |
| -#include "base/strings/stringprintf.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "ui/gfx/buffer_format_util.h" |
| #include "ui/gfx/buffer_types.h" |
| @@ -57,26 +55,34 @@ TYPED_TEST_P(GLImageTest, CreateAndDestroy) { |
| const gfx::Size large_image_size(512, 512); |
| const uint8_t image_color[] = {0, 0xff, 0, 0xff}; |
| - // Create a small solid color green image of preferred format. This must |
| - // succeed in order for a GLImage to be conformant. |
| - scoped_refptr<gl::GLImage> small_image = |
| - this->delegate_.CreateSolidColorImage(small_image_size, image_color); |
| - ASSERT_TRUE(small_image); |
| - |
| - // Create a large solid color green image of preferred format. This must |
| - // succeed in order for a GLImage to be conformant. |
| - scoped_refptr<gl::GLImage> large_image = |
| - this->delegate_.CreateSolidColorImage(large_image_size, image_color); |
| - ASSERT_TRUE(large_image); |
| - |
| - // Verify that image size is correct. |
| - EXPECT_EQ(small_image->GetSize().ToString(), small_image_size.ToString()); |
| - EXPECT_EQ(large_image->GetSize().ToString(), large_image_size.ToString()); |
| - |
| - // Verify that destruction of images work correctly both when we have a |
| - // context and when we don't. |
| - small_image->Destroy(true /* have_context */); |
| - large_image->Destroy(false /* have_context */); |
| + for (auto format : gfx::GetBufferFormatsForTesting()) { |
| + if (!TypeParam::IsSupported(format)) { |
|
reveman
2015/12/18 21:51:04
can we keep requiring each implementation to decid
dshwang
2016/01/11 15:31:10
I agree, but we cannot.
each ozone backend support
|
| + continue; |
| + } |
| + |
| + // Create a small solid color green image of preferred format. This must |
| + // succeed in order for a GLImage to be conformant. |
| + scoped_refptr<gl::GLImage> small_image = |
| + this->delegate_.CreateSolidColorImage(small_image_size, format, |
| + image_color); |
| + ASSERT_TRUE(small_image); |
| + |
| + // Create a large solid color green image of preferred format. This must |
| + // succeed in order for a GLImage to be conformant. |
| + scoped_refptr<gl::GLImage> large_image = |
| + this->delegate_.CreateSolidColorImage(large_image_size, format, |
| + image_color); |
| + ASSERT_TRUE(large_image); |
| + |
| + // Verify that image size is correct. |
| + EXPECT_EQ(small_image->GetSize().ToString(), small_image_size.ToString()); |
| + EXPECT_EQ(large_image->GetSize().ToString(), large_image_size.ToString()); |
| + |
| + // Verify that destruction of images work correctly both when we have a |
| + // context and when we don't. |
| + small_image->Destroy(true /* have_context */); |
| + large_image->Destroy(false /* have_context */); |
| + } |
| } |
| // The GLImageTest test case verifies the behaviour that is expected from a |
| @@ -102,89 +108,113 @@ TYPED_TEST_P(GLImageCopyTest, CopyTexImage) { |
| glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); |
| glViewport(0, 0, image_size.width(), image_size.height()); |
| - // Create a solid color green image of preferred format. This must succeed |
| - // in order for a GLImage to be conformant. |
| - scoped_refptr<gl::GLImage> image = |
| - this->delegate_.CreateSolidColorImage(image_size, image_color); |
| - ASSERT_TRUE(image); |
| - |
| - // Create a solid color blue texture of the same size as |image|. |
| - GLuint texture = GLTestHelper::CreateTexture(GL_TEXTURE_2D); |
| - scoped_ptr<uint8_t[]> pixels(new uint8_t[BufferSizeForBufferFormat( |
| - image_size, gfx::BufferFormat::RGBA_8888)]); |
| - GLImageTestSupport::SetBufferDataToColor( |
| - image_size.width(), image_size.height(), |
| - static_cast<int>(RowSizeForBufferFormat(image_size.width(), |
| - gfx::BufferFormat::RGBA_8888, 0)), |
| - 0, gfx::BufferFormat::RGBA_8888, texture_color, pixels.get()); |
| - // Note: This test assume that |image| can be used with GL_TEXTURE_2D but |
| - // that might not be the case for some GLImage implementations. |
| - glBindTexture(GL_TEXTURE_2D, texture); |
| - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_size.width(), |
| - image_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); |
| - |
| - // Copy |image| to |texture|. |
| - bool rv = image->CopyTexImage(GL_TEXTURE_2D); |
| - EXPECT_TRUE(rv); |
| - |
| - // clang-format off |
| - const char kVertexShader[] = STRINGIZE( |
| - attribute vec2 a_position; |
| - varying vec2 v_texCoord; |
| - void main() { |
| - gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0); |
| - v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5; |
| - } |
| - ); |
| - const char kFragmentShader[] = STRINGIZE( |
| - uniform sampler2D a_texture; |
| - varying vec2 v_texCoord; |
| - void main() { |
| - gl_FragColor = texture2D(a_texture, v_texCoord); |
| - } |
| - ); |
| - const char kShaderFloatPrecision[] = STRINGIZE( |
| - precision mediump float; |
| - ); |
| - // clang-format on |
| - |
| - GLuint vertex_shader = |
| - gfx::GLHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader); |
| - bool is_gles = gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; |
| - GLuint fragment_shader = gfx::GLHelper::LoadShader( |
| - GL_FRAGMENT_SHADER, |
| - base::StringPrintf("%s%s", is_gles ? kShaderFloatPrecision : "", |
| - kFragmentShader) |
| - .c_str()); |
| - GLuint program = gfx::GLHelper::SetupProgram(vertex_shader, fragment_shader); |
| - EXPECT_NE(program, 0u); |
| - glUseProgram(program); |
| - |
| - GLint sampler_location = glGetUniformLocation(program, "a_texture"); |
| - ASSERT_NE(sampler_location, -1); |
| - glUniform1i(sampler_location, 0); |
| - |
| + GLuint program = GLImageTestSupport::CreateSingleTextureProgram(); |
| GLuint vertex_buffer = gfx::GLHelper::SetupQuadVertexBuffer(); |
| - // Draw |texture| to viewport and read back pixels to check expectations. |
| - gfx::GLHelper::DrawQuad(vertex_buffer); |
| - GLTestHelper::CheckPixels(0, 0, image_size.width(), image_size.height(), |
| - image_color); |
| + for (auto format : gfx::GetBufferFormatsForTesting()) { |
| + if (!TypeParam::IsSupported(format)) { |
| + continue; |
| + } |
| - // Clean up. |
| + // Create a solid color green image of preferred format. This must succeed |
| + // in order for a GLImage to be conformant. |
| + scoped_refptr<gl::GLImage> image = |
| + this->delegate_.CreateSolidColorImage(image_size, format, image_color); |
| + ASSERT_TRUE(image); |
| + |
| + // Create a solid color blue texture of the same size as |image|. |
| + GLuint texture = GLTestHelper::CreateTexture(GL_TEXTURE_2D); |
| + scoped_ptr<uint8_t[]> pixels(new uint8_t[BufferSizeForBufferFormat( |
| + image_size, gfx::BufferFormat::RGBA_8888)]); |
| + GLImageTestSupport::SetBufferDataToColor( |
| + image_size.width(), image_size.height(), |
| + static_cast<int>(RowSizeForBufferFormat( |
| + image_size.width(), gfx::BufferFormat::RGBA_8888, 0)), |
| + 0, gfx::BufferFormat::RGBA_8888, texture_color, pixels.get()); |
| + // Note: This test assume that |image| can be used with GL_TEXTURE_2D but |
| + // that might not be the case for some GLImage implementations. |
| + glBindTexture(GL_TEXTURE_2D, texture); |
| + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_size.width(), |
| + image_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| + pixels.get()); |
| + |
| + // Copy |image| to |texture|. |
| + bool rv = image->CopyTexImage(GL_TEXTURE_2D); |
| + EXPECT_TRUE(rv); |
| + |
| + // Draw |texture| to viewport and read back pixels to check expectations. |
| + gfx::GLHelper::DrawQuad(vertex_buffer); |
| + |
| + GLTestHelper::CheckPixels(0, 0, image_size.width(), image_size.height(), |
| + image_color); |
| + |
| + // Clean up. |
| + glDeleteTextures(1, &texture); |
| + image->Destroy(true); |
| + } |
| glDeleteProgram(program); |
| - glDeleteShader(vertex_shader); |
| - glDeleteShader(fragment_shader); |
| glDeleteBuffersARB(1, &vertex_buffer); |
| - glDeleteTextures(1, &texture); |
| glDeleteFramebuffersEXT(1, &framebuffer); |
| - image->Destroy(true); |
| } |
| // The GLImageCopyTest test case verifies that the GLImage implementation |
| // handles CopyTexImage correctly. |
| REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); |
| +template <typename GLImageTestDelegate> |
| +class GLImageBindTest : public GLImageTest<GLImageTestDelegate> {}; |
| + |
| +TYPED_TEST_CASE_P(GLImageBindTest); |
| + |
| +TYPED_TEST_P(GLImageBindTest, BindTexImage) { |
| + const gfx::Size image_size(256, 256); |
| + const uint8_t image_color[] = {0x10, 0x20, 0, 0xff}; |
| + |
| + GLuint framebuffer = |
| + GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); |
| + ASSERT_TRUE(framebuffer); |
| + glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); |
| + glViewport(0, 0, image_size.width(), image_size.height()); |
| + |
| + GLuint program = GLImageTestSupport::CreateSingleTextureProgram(); |
| + GLuint vertex_buffer = gfx::GLHelper::SetupQuadVertexBuffer(); |
| + |
| + for (auto format : gfx::GetBufferFormatsForTesting()) { |
| + if (!TypeParam::IsSupported(format)) { |
| + continue; |
| + } |
| + |
| + // Create a solid color green image of preferred format. This must succeed |
| + // in order for a GLImage to be conformant. |
| + scoped_refptr<gl::GLImage> image = |
| + this->delegate_.CreateSolidColorImage(image_size, format, image_color); |
| + ASSERT_TRUE(image); |
| + |
| + GLuint texture = GLTestHelper::CreateTexture(GL_TEXTURE_2D); |
| + |
| + // Bind |image| to |texture|. |
| + bool rv = image->BindTexImage(GL_TEXTURE_2D); |
| + EXPECT_TRUE(rv); |
| + |
| + // Draw |texture| to viewport and read back pixels to check expectations. |
| + gfx::GLHelper::DrawQuad(vertex_buffer); |
| + |
| + GLTestHelper::CheckPixels(0, 0, image_size.width(), image_size.height(), |
| + image_color); |
| + |
| + // Clean up. |
| + glDeleteTextures(1, &texture); |
| + image->Destroy(true); |
| + } |
| + glDeleteProgram(program); |
| + glDeleteBuffersARB(1, &vertex_buffer); |
| + glDeleteFramebuffersEXT(1, &framebuffer); |
| +} |
| + |
| +// The GLImageBindTest test case verifies that the GLImage implementation |
| +// handles BindTexImage correctly. |
| +REGISTER_TYPED_TEST_CASE_P(GLImageBindTest, BindTexImage); |
| + |
| } // namespace gl |
| #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ |