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 9f2b0716b59a33cf2775bba19f9f9d03644aa10d..adcb2588034b4c1d0a4ae35a002d30bc71c9191a 100644 |
--- a/ui/gl/test/gl_image_test_template.h |
+++ b/ui/gl/test/gl_image_test_template.h |
@@ -46,6 +46,52 @@ class GLImageTest : public testing::Test { |
} |
protected: |
+ // Create GL program drawing a texture on a framebuffer. |
+ static GLuint CreateSingleTextureProgram() { |
+ // 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); |
+ DCHECK_NE(program, 0u); |
+ glUseProgram(program); |
+ |
+ GLint sampler_location = glGetUniformLocation(program, "a_texture"); |
+ DCHECK_NE(sampler_location, -1); |
+ glUniform1i(sampler_location, 0); |
+ |
+ glDeleteShader(vertex_shader); |
+ glDeleteShader(fragment_shader); |
+ |
+ return program; |
+ } |
+ |
scoped_refptr<gfx::GLSurface> surface_; |
scoped_refptr<gfx::GLContext> context_; |
GLImageTestDelegate delegate_; |
@@ -58,26 +104,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()) { |
reveman
2016/01/13 15:50:09
I think it was much better to have the format to t
dshwang
2016/01/13 17:07:42
That's difficult because ozone knows the supported
reveman
2016/01/13 19:48:47
I'd like us to move away from that type of test st
dshwang
2016/01/14 12:54:49
It's unfortunate. following code minimizes less cl
|
+ if (!TypeParam::IsSupported(format)) { |
+ 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 |
@@ -103,89 +157,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); |
+ GLuint program = this->CreateSingleTextureProgram(); |
+ GLuint vertex_buffer = gfx::GLHelper::SetupQuadVertexBuffer(); |
+ |
+ for (auto format : gfx::GetBufferFormatsForTesting()) { |
+ if (!TypeParam::IsSupported(format)) { |
+ continue; |
} |
- ); |
- 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 vertex_buffer = gfx::GLHelper::SetupQuadVertexBuffer(); |
- // Draw |texture| to viewport and read back pixels to check expectations. |
- gfx::GLHelper::DrawQuad(vertex_buffer); |
+ // 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); |
- GLTestHelper::CheckPixels(0, 0, image_size.width(), image_size.height(), |
- image_color); |
+ // Draw |texture| to viewport and read back pixels to check expectations. |
+ gfx::GLHelper::DrawQuad(vertex_buffer); |
- // Clean up. |
+ 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) { |
reveman
2016/01/13 15:50:09
Please add this in a separate patch. Easier to rev
dshwang
2016/01/13 17:07:42
got it. I extract it to https://codereview.chromiu
|
+ 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 = this->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_ |