| 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 fe333fa1997ca1a6f76f6c99144014c7ebbdfbb5..19ae22c9c5035be2a0fd020ed70838bc1369e07c 100644
|
| --- a/ui/gl/test/gl_image_test_template.h
|
| +++ b/ui/gl/test/gl_image_test_template.h
|
| @@ -35,60 +35,85 @@
|
| namespace gl {
|
| namespace {
|
|
|
| +GLuint LoadVertexShader() {
|
| + bool is_desktop_core_profile =
|
| + GLContext::GetCurrent()->GetVersionInfo()->is_desktop_core_profile;
|
| + std::string vertex_shader = base::StringPrintf(
|
| + "%s" // version
|
| + "%s vec2 a_position;\n"
|
| + "%s 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"
|
| + "}",
|
| + is_desktop_core_profile ? "#version 150\n" : "",
|
| + is_desktop_core_profile ? "in" : "attribute",
|
| + is_desktop_core_profile ? "out" : "varying");
|
| + return GLHelper::LoadShader(GL_VERTEX_SHADER, vertex_shader.c_str());
|
| +}
|
| +
|
| // Compiles a fragment shader for sampling out of a texture of |size| bound to
|
| // |target| and checks for compilation errors.
|
| GLuint LoadFragmentShader(unsigned target, const gfx::Size& size) {
|
| - // clang-format off
|
| - const char kFragmentShader[] = STRINGIZE(
|
| - uniform SamplerType a_texture;
|
| - varying vec2 v_texCoord;
|
| - void main() {
|
| - gl_FragColor = TextureLookup(a_texture, v_texCoord * TextureScale);
|
| - }
|
| - );
|
| - const char kShaderFloatPrecision[] = STRINGIZE(
|
| - precision mediump float;
|
| - );
|
| - // clang-format on
|
| -
|
| + bool is_desktop_core_profile =
|
| + GLContext::GetCurrent()->GetVersionInfo()->is_desktop_core_profile;
|
| bool is_gles = GLContext::GetCurrent()->GetVersionInfo()->is_es;
|
| +
|
| + std::string fragment_shader_main = base::StringPrintf(
|
| + "uniform SamplerType a_texture;\n"
|
| + "%s vec2 v_texCoord;\n"
|
| + "%s" // output variable declaration
|
| + "void main() {\n"
|
| + " %s = TextureLookup(a_texture, v_texCoord * TextureScale);\n"
|
| + "}",
|
| + is_desktop_core_profile ? "in" : "varying",
|
| + is_desktop_core_profile ? "out vec4 my_FragData;\n" : "",
|
| + is_desktop_core_profile ? "my_FragData" : "gl_FragData[0]");
|
| +
|
| switch (target) {
|
| case GL_TEXTURE_2D:
|
| return GLHelper::LoadShader(
|
| GL_FRAGMENT_SHADER,
|
| - base::StringPrintf("%s\n"
|
| + base::StringPrintf("%s" // version
|
| + "%s" // precision
|
| "#define SamplerType sampler2D\n"
|
| - "#define TextureLookup texture2D\n"
|
| + "#define TextureLookup %s\n"
|
| "#define TextureScale vec2(1.0, 1.0)\n"
|
| - "%s",
|
| - is_gles ? kShaderFloatPrecision : "",
|
| - kFragmentShader)
|
| + "%s", // main function
|
| + is_desktop_core_profile ? "#version 150\n" : "",
|
| + is_gles ? "precision mediump float;\n" : "",
|
| + is_desktop_core_profile ? "texture" : "texture2D",
|
| + fragment_shader_main.c_str())
|
| .c_str());
|
| case GL_TEXTURE_RECTANGLE_ARB:
|
| + DCHECK(!is_gles);
|
| return GLHelper::LoadShader(
|
| GL_FRAGMENT_SHADER,
|
| - base::StringPrintf("#extension GL_ARB_texture_rectangle : require\n"
|
| - "%s\n"
|
| - "#define SamplerType sampler2DRect\n"
|
| - "#define TextureLookup texture2DRect\n"
|
| - "#define TextureScale vec2(%f, %f)\n"
|
| - "%s",
|
| - is_gles ? kShaderFloatPrecision : "",
|
| - static_cast<double>(size.width()),
|
| - static_cast<double>(size.height()),
|
| - kFragmentShader)
|
| + base::StringPrintf(
|
| + "%s" // version
|
| + "%s" // extension
|
| + "#define SamplerType sampler2DRect\n"
|
| + "#define TextureLookup %s\n"
|
| + "#define TextureScale vec2(%f, %f)\n"
|
| + "%s", // main function
|
| + is_desktop_core_profile ? "#version 150\n" : "",
|
| + is_desktop_core_profile
|
| + ? ""
|
| + : "#extension GL_ARB_texture_rectangle : require\n",
|
| + is_desktop_core_profile ? "texture" : "texture2DRect",
|
| + static_cast<double>(size.width()),
|
| + static_cast<double>(size.height()), fragment_shader_main.c_str())
|
| .c_str());
|
| case GL_TEXTURE_EXTERNAL_OES:
|
| + DCHECK(is_gles);
|
| return GLHelper::LoadShader(
|
| GL_FRAGMENT_SHADER,
|
| base::StringPrintf("#extension GL_OES_EGL_image_external : require\n"
|
| - "%s\n"
|
| "#define SamplerType samplerExternalOES\n"
|
| "#define TextureLookup texture2D\n"
|
| "#define TextureScale vec2(1.0, 1.0)\n"
|
| - "%s",
|
| - is_gles ? kShaderFloatPrecision : "",
|
| - kFragmentShader)
|
| + "%s", // main function
|
| + fragment_shader_main.c_str())
|
| .c_str());
|
| default:
|
| NOTREACHED();
|
| @@ -99,24 +124,13 @@ GLuint LoadFragmentShader(unsigned target, const gfx::Size& size) {
|
| // Draws texture bound to |target| of texture unit 0 to the currently bound
|
| // frame buffer.
|
| void DrawTextureQuad(GLenum target, const gfx::Size& size) {
|
| - // 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;
|
| - }
|
| - );
|
| - // clang-format on
|
| -
|
| GLuint vao = 0;
|
| if (GLHelper::ShouldTestsUseVAOs()) {
|
| glGenVertexArraysOES(1, &vao);
|
| glBindVertexArrayOES(vao);
|
| }
|
|
|
| - GLuint vertex_shader = GLHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader);
|
| + GLuint vertex_shader = LoadVertexShader();
|
| GLuint fragment_shader = LoadFragmentShader(target, size);
|
| GLuint program = GLHelper::SetupProgram(vertex_shader, fragment_shader);
|
| EXPECT_NE(program, 0u);
|
| @@ -314,6 +328,13 @@ TYPED_TEST_P(GLImageCopyTest, CopyTexImage) {
|
| const uint8_t* image_color = this->delegate_.GetImageColor();
|
| const uint8_t texture_color[] = {0, 0, 0xff, 0xff};
|
|
|
| + GLuint vao = 0;
|
| + if (GLContext::GetCurrent()->GetVersionInfo()->IsAtLeastGL(3, 3)) {
|
| + // To avoid glGetVertexAttribiv(0, ...) failing.
|
| + glGenVertexArraysOES(1, &vao);
|
| + glBindVertexArrayOES(vao);
|
| + }
|
| +
|
| GLuint framebuffer =
|
| GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height());
|
| ASSERT_TRUE(framebuffer);
|
| @@ -355,6 +376,9 @@ TYPED_TEST_P(GLImageCopyTest, CopyTexImage) {
|
| glDeleteTextures(1, &texture);
|
| glDeleteFramebuffersEXT(1, &framebuffer);
|
| image->Destroy(true /* have_context */);
|
| + if (vao) {
|
| + glDeleteVertexArraysOES(1, &vao);
|
| + }
|
| }
|
|
|
| // The GLImageCopyTest test case verifies that the GLImage implementation
|
|
|