| Index: gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc
|
| 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 44701c96b195fc0fedef0472d198686c8a72464e..6794649886c40872dabdca7a9882901833ea4643 100644
|
| --- a/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc
|
| +++ b/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc
|
| @@ -9,6 +9,7 @@
|
| #include <GLES2/gl2.h>
|
| #include <GLES2/gl2ext.h>
|
| #include <GLES2/gl2extchromium.h>
|
| +#include <GLES3/gl3.h>
|
| #include <stddef.h>
|
| #include <stdint.h>
|
|
|
| @@ -20,13 +21,54 @@
|
| namespace gpu {
|
|
|
| namespace {
|
| +
|
| enum CopyType { TexImage, TexSubImage };
|
| const CopyType kCopyTypes[] = {
|
| TexImage,
|
| TexSubImage,
|
| };
|
| +
|
| +static const char* kSimpleVertexShaderES3 =
|
| + "#version 300 es\n"
|
| + "in vec2 a_position;\n"
|
| + "out vec2 v_texCoord;\n"
|
| + "void main() {\n"
|
| + " gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);\n"
|
| + " v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;\n"
|
| + "}\n";
|
| +
|
| +std::string GetFragmentShaderSource(GLenum format) {
|
| + std::string source;
|
| + source += std::string(
|
| + "#version 300 es\n"
|
| + "precision mediump float;\n");
|
| + if (gles2::GLES2Util::IsSignedIntegerFormat(format)) {
|
| + source += std::string("#define SamplerType isampler2D\n");
|
| + source += std::string("#define TextureType ivec4\n");
|
| + source += std::string("#define ScaleValue 255.0\n");
|
| + } else if (gles2::GLES2Util::IsUnsignedIntegerFormat(format)) {
|
| + source += std::string("#define SamplerType usampler2D\n");
|
| + source += std::string("#define TextureType uvec4\n");
|
| + source += std::string("#define ScaleValue 255.0\n");
|
| + } else {
|
| + source += std::string("#define SamplerType sampler2D\n");
|
| + source += std::string("#define TextureType vec4\n");
|
| + source += std::string("#define ScaleValue 1.0\n");
|
| + }
|
| +
|
| + source += std::string(
|
| + "uniform mediump SamplerType u_texture;\n"
|
| + "in vec2 v_texCoord;\n"
|
| + "out vec4 fragData;\n"
|
| + "void main() {\n"
|
| + " TextureType color = texture(u_texture, v_texCoord);\n"
|
| + " fragData = vec4(color) / ScaleValue;\n"
|
| + "}\n");
|
| + return source;
|
| }
|
|
|
| +} // namespace
|
| +
|
| // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension.
|
| class GLCopyTextureCHROMIUMTest
|
| : public testing::Test,
|
| @@ -51,7 +93,10 @@ class GLCopyTextureCHROMIUMTest
|
| }
|
|
|
| void SetUp() override {
|
| - gl_.Initialize(GLManager::Options());
|
| + GLManager::Options options;
|
| + options.context_type = gles2::CONTEXT_TYPE_OPENGLES3;
|
| + options.size = gfx::Size(64, 64);
|
| + gl_.Initialize(options);
|
|
|
| CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D);
|
| }
|
| @@ -132,6 +177,85 @@ TEST_P(GLCopyTextureCHROMIUMTest, Basic) {
|
| EXPECT_TRUE(GL_NO_ERROR == glGetError());
|
| }
|
|
|
| +// Copy with glCopyTexImage2D
|
| +TEST_P(GLCopyTextureCHROMIUMTest, RGBA8ToRGB) {
|
| + CopyType copy_type = GetParam();
|
| + GLenum source_internal_format = GL_RGBA8;
|
| + GLenum source_format = GL_RGBA;
|
| + GLenum source_type = GL_UNSIGNED_BYTE;
|
| + GLenum dest_internal_format = GL_RGB;
|
| + GLenum dest_format = GL_RGB;
|
| + GLenum dest_type = GL_UNSIGNED_BYTE;
|
| +
|
| + const GLsizei kWidth = 8, kHeight = 8;
|
| + uint8_t color[4] = {0, 1, 2, 3};
|
| + uint8_t pixels[8 * 8 * 4];
|
| + for (int i = 0; i < kWidth * kHeight * 4; i += 4) {
|
| + pixels[i + 0] = color[0];
|
| + pixels[i + 1] = color[1];
|
| + pixels[i + 2] = color[2];
|
| + pixels[i + 3] = color[3];
|
| + }
|
| +
|
| + glBindTexture(GL_TEXTURE_2D, textures_[0]);
|
| + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
| + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
| + glTexImage2D(GL_TEXTURE_2D, 0, source_internal_format, kWidth, kHeight, 0,
|
| + source_format, source_type, pixels);
|
| +
|
| + if (copy_type == TexImage) {
|
| + glCopyTextureCHROMIUM(textures_[0], textures_[1], dest_internal_format,
|
| + dest_type, false, false, false);
|
| + } else {
|
| + glBindTexture(GL_TEXTURE_2D, textures_[1]);
|
| + glTexImage2D(GL_TEXTURE_2D, 0, dest_internal_format, kWidth, kHeight, 0,
|
| + dest_format, dest_type, nullptr);
|
| +
|
| + glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0, 0, kWidth,
|
| + kHeight, false, false, false);
|
| + }
|
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR);
|
| +
|
| + // Draw destination texture to a fbo with attachment in RGBA format.
|
| + glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
| + GLuint framebuffer = 0;
|
| + glGenFramebuffers(1, &framebuffer);
|
| + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
| + GLuint texture = 0;
|
| + glGenTextures(1, &texture);
|
| + glBindTexture(GL_TEXTURE_2D, texture);
|
| + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
| + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
| + CreateBackingForTexture(GL_TEXTURE_2D, kWidth, kHeight);
|
| + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
| + texture, 0);
|
| + EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
|
| + glCheckFramebufferStatus(GL_FRAMEBUFFER));
|
| + glViewport(0, 0, kWidth, kHeight);
|
| +
|
| + std::string fragment_shader_source =
|
| + GetFragmentShaderSource(dest_internal_format);
|
| + GLuint program = GLTestHelper::LoadProgram(kSimpleVertexShaderES3,
|
| + fragment_shader_source.c_str());
|
| + EXPECT_NE(program, 0u);
|
| + GLint position_loc = glGetAttribLocation(program, "a_position");
|
| + GLint texture_loc = glGetUniformLocation(program, "u_texture");
|
| + ASSERT_NE(position_loc, -1);
|
| + ASSERT_NE(texture_loc, -1);
|
| + glUseProgram(program);
|
| +
|
| + GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc);
|
| + ASSERT_NE(vbo, 0u);
|
| +
|
| + glActiveTexture(GL_TEXTURE0);
|
| + glBindTexture(GL_TEXTURE_2D, textures_[1]);
|
| +
|
| + glDrawArrays(GL_TRIANGLES, 0, 6);
|
| +
|
| + GLTestHelper::CheckPixels(0, 0, kWidth, kHeight, 0, color, 3);
|
| + EXPECT_TRUE(GL_NO_ERROR == glGetError());
|
| +}
|
| +
|
| TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) {
|
| if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) {
|
| LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test...";
|
| @@ -229,25 +353,33 @@ TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) {
|
| nullptr);
|
| EXPECT_TRUE(GL_NO_ERROR == glGetError());
|
|
|
| + struct FormatType {
|
| + GLenum internal_format;
|
| + GLenum format;
|
| + GLenum type;
|
| + };
|
| +
|
| // Check unsupported format reports error.
|
| - GLint unsupported_dest_formats[] = {GL_ALPHA, GL_LUMINANCE,
|
| - GL_LUMINANCE_ALPHA};
|
| - for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats);
|
| - dest_index++) {
|
| + // TODO(qiankun.miao@intel.com): find real unsupported formats.
|
| + FormatType unsupported_format_types[] = {
|
| + {GL_RGBA32UI, GL_RGBA_INTEGER, GL_INT},
|
| + };
|
| + for (size_t i = 0; i < arraysize(unsupported_format_types); i++) {
|
| if (copy_type == TexImage) {
|
| glCopyTextureCHROMIUM(textures_[0], textures_[1],
|
| - unsupported_dest_formats[dest_index],
|
| - GL_UNSIGNED_BYTE, false, false, false);
|
| + unsupported_format_types[i].internal_format,
|
| + unsupported_format_types[i].type, false, false,
|
| + false);
|
| } else {
|
| glBindTexture(GL_TEXTURE_2D, textures_[1]);
|
| - glTexImage2D(GL_TEXTURE_2D, 0, unsupported_dest_formats[dest_index], 1, 1,
|
| - 0, unsupported_dest_formats[dest_index], GL_UNSIGNED_BYTE,
|
| - nullptr);
|
| + glTexImage2D(GL_TEXTURE_2D, 0,
|
| + unsupported_format_types[i].internal_format, 1, 1, 0,
|
| + unsupported_format_types[i].format,
|
| + unsupported_format_types[i].type, nullptr);
|
| glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0,
|
| 0, 0, 1, 1, false, false, false);
|
| }
|
| - EXPECT_TRUE(GL_INVALID_OPERATION == glGetError())
|
| - << "dest_index:" << dest_index;
|
| + EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()) << "i:" << i;
|
| }
|
| }
|
|
|
| @@ -567,6 +699,7 @@ TEST_P(GLCopyTextureCHROMIUMTest, ProgramStatePreservation) {
|
|
|
| GLManager gl2;
|
| GLManager::Options options;
|
| + options.context_type = gles2::CONTEXT_TYPE_OPENGLES3;
|
| options.size = gfx::Size(16, 16);
|
| options.share_group_manager = &gl_;
|
| gl2.Initialize(options);
|
|
|