| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file defines tests that implementations of GLImage should pass in order | 5 // This file defines tests that implementations of GLImage should pass in order |
| 6 // to be conformant. | 6 // to be conformant. |
| 7 | 7 |
| 8 #ifndef UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ | 8 #ifndef UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ |
| 9 #define UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ | 9 #define UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 varying vec2 v_texCoord; | 44 varying vec2 v_texCoord; |
| 45 void main() { | 45 void main() { |
| 46 gl_FragColor = TextureLookup(a_texture, v_texCoord * TextureScale); | 46 gl_FragColor = TextureLookup(a_texture, v_texCoord * TextureScale); |
| 47 } | 47 } |
| 48 ); | 48 ); |
| 49 const char kShaderFloatPrecision[] = STRINGIZE( | 49 const char kShaderFloatPrecision[] = STRINGIZE( |
| 50 precision mediump float; | 50 precision mediump float; |
| 51 ); | 51 ); |
| 52 // clang-format on | 52 // clang-format on |
| 53 | 53 |
| 54 bool is_gles = gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; | 54 bool is_gles = gl::GetGLImplementation() == gl::kGLImplementationEGLGLES2; |
| 55 switch (target) { | 55 switch (target) { |
| 56 case GL_TEXTURE_2D: | 56 case GL_TEXTURE_2D: |
| 57 return gfx::GLHelper::LoadShader( | 57 return gl::GLHelper::LoadShader( |
| 58 GL_FRAGMENT_SHADER, | 58 GL_FRAGMENT_SHADER, |
| 59 base::StringPrintf("%s\n" | 59 base::StringPrintf("%s\n" |
| 60 "#define SamplerType sampler2D\n" | 60 "#define SamplerType sampler2D\n" |
| 61 "#define TextureLookup texture2D\n" | 61 "#define TextureLookup texture2D\n" |
| 62 "#define TextureScale vec2(1.0, 1.0)\n" | 62 "#define TextureScale vec2(1.0, 1.0)\n" |
| 63 "%s", | 63 "%s", |
| 64 is_gles ? kShaderFloatPrecision : "", | 64 is_gles ? kShaderFloatPrecision : "", |
| 65 kFragmentShader) | 65 kFragmentShader) |
| 66 .c_str()); | 66 .c_str()); |
| 67 case GL_TEXTURE_RECTANGLE_ARB: | 67 case GL_TEXTURE_RECTANGLE_ARB: |
| 68 return gfx::GLHelper::LoadShader( | 68 return gl::GLHelper::LoadShader( |
| 69 GL_FRAGMENT_SHADER, | 69 GL_FRAGMENT_SHADER, |
| 70 base::StringPrintf("%s\n" | 70 base::StringPrintf("%s\n" |
| 71 "#extension GL_ARB_texture_rectangle : require\n" | 71 "#extension GL_ARB_texture_rectangle : require\n" |
| 72 "#define SamplerType sampler2DRect\n" | 72 "#define SamplerType sampler2DRect\n" |
| 73 "#define TextureLookup texture2DRect\n" | 73 "#define TextureLookup texture2DRect\n" |
| 74 "#define TextureScale vec2(%f, %f)\n" | 74 "#define TextureScale vec2(%f, %f)\n" |
| 75 "%s", | 75 "%s", |
| 76 is_gles ? kShaderFloatPrecision : "", | 76 is_gles ? kShaderFloatPrecision : "", |
| 77 static_cast<double>(size.width()), | 77 static_cast<double>(size.width()), |
| 78 static_cast<double>(size.height()), | 78 static_cast<double>(size.height()), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 92 attribute vec2 a_position; | 92 attribute vec2 a_position; |
| 93 varying vec2 v_texCoord; | 93 varying vec2 v_texCoord; |
| 94 void main() { | 94 void main() { |
| 95 gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0); | 95 gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0); |
| 96 v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5; | 96 v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5; |
| 97 } | 97 } |
| 98 ); | 98 ); |
| 99 // clang-format on | 99 // clang-format on |
| 100 | 100 |
| 101 GLuint vertex_shader = | 101 GLuint vertex_shader = |
| 102 gfx::GLHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader); | 102 gl::GLHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader); |
| 103 GLuint fragment_shader = LoadFragmentShader(target, size); | 103 GLuint fragment_shader = LoadFragmentShader(target, size); |
| 104 GLuint program = gfx::GLHelper::SetupProgram(vertex_shader, fragment_shader); | 104 GLuint program = gl::GLHelper::SetupProgram(vertex_shader, fragment_shader); |
| 105 EXPECT_NE(program, 0u); | 105 EXPECT_NE(program, 0u); |
| 106 glUseProgram(program); | 106 glUseProgram(program); |
| 107 | 107 |
| 108 GLint sampler_location = glGetUniformLocation(program, "a_texture"); | 108 GLint sampler_location = glGetUniformLocation(program, "a_texture"); |
| 109 ASSERT_NE(sampler_location, -1); | 109 ASSERT_NE(sampler_location, -1); |
| 110 glUniform1i(sampler_location, 0); | 110 glUniform1i(sampler_location, 0); |
| 111 | 111 |
| 112 GLuint vertex_buffer = gfx::GLHelper::SetupQuadVertexBuffer(); | 112 GLuint vertex_buffer = gl::GLHelper::SetupQuadVertexBuffer(); |
| 113 gfx::GLHelper::DrawQuad(vertex_buffer); | 113 gl::GLHelper::DrawQuad(vertex_buffer); |
| 114 | 114 |
| 115 glDeleteShader(vertex_shader); | 115 glDeleteShader(vertex_shader); |
| 116 glDeleteShader(fragment_shader); | 116 glDeleteShader(fragment_shader); |
| 117 glDeleteProgram(program); | 117 glDeleteProgram(program); |
| 118 glDeleteBuffersARB(1, &vertex_buffer); | 118 glDeleteBuffersARB(1, &vertex_buffer); |
| 119 } | 119 } |
| 120 | 120 |
| 121 } // namespace | 121 } // namespace |
| 122 | 122 |
| 123 template <typename GLImageTestDelegate> | 123 template <typename GLImageTestDelegate> |
| 124 class GLImageTest : public testing::Test { | 124 class GLImageTest : public testing::Test { |
| 125 protected: | 125 protected: |
| 126 // Overridden from testing::Test: | 126 // Overridden from testing::Test: |
| 127 void SetUp() override { | 127 void SetUp() override { |
| 128 GLImageTestSupport::InitializeGL(); | 128 GLImageTestSupport::InitializeGL(); |
| 129 surface_ = gl::init::CreateOffscreenGLSurface(gfx::Size()); | 129 surface_ = gl::init::CreateOffscreenGLSurface(gfx::Size()); |
| 130 context_ = gl::init::CreateGLContext(nullptr, surface_.get(), | 130 context_ = gl::init::CreateGLContext(nullptr, surface_.get(), |
| 131 gfx::PreferIntegratedGpu); | 131 gl::PreferIntegratedGpu); |
| 132 context_->MakeCurrent(surface_.get()); | 132 context_->MakeCurrent(surface_.get()); |
| 133 } | 133 } |
| 134 void TearDown() override { | 134 void TearDown() override { |
| 135 context_->ReleaseCurrent(surface_.get()); | 135 context_->ReleaseCurrent(surface_.get()); |
| 136 context_ = nullptr; | 136 context_ = nullptr; |
| 137 surface_ = nullptr; | 137 surface_ = nullptr; |
| 138 GLImageTestSupport::CleanupGL(); | 138 GLImageTestSupport::CleanupGL(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 protected: | 141 protected: |
| 142 scoped_refptr<gfx::GLSurface> surface_; | 142 scoped_refptr<gl::GLSurface> surface_; |
| 143 scoped_refptr<gfx::GLContext> context_; | 143 scoped_refptr<gl::GLContext> context_; |
| 144 GLImageTestDelegate delegate_; | 144 GLImageTestDelegate delegate_; |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 TYPED_TEST_CASE_P(GLImageTest); | 147 TYPED_TEST_CASE_P(GLImageTest); |
| 148 | 148 |
| 149 TYPED_TEST_P(GLImageTest, CreateAndDestroy) { | 149 TYPED_TEST_P(GLImageTest, CreateAndDestroy) { |
| 150 const gfx::Size small_image_size(4, 4); | 150 const gfx::Size small_image_size(4, 4); |
| 151 const gfx::Size large_image_size(512, 512); | 151 const gfx::Size large_image_size(512, 512); |
| 152 const uint8_t image_color[] = {0, 0xff, 0, 0xff}; | 152 const uint8_t image_color[] = {0, 0xff, 0, 0xff}; |
| 153 | 153 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 image->Destroy(true /* have_context */); | 334 image->Destroy(true /* have_context */); |
| 335 } | 335 } |
| 336 | 336 |
| 337 // The GLImageCopyTest test case verifies that the GLImage implementation | 337 // The GLImageCopyTest test case verifies that the GLImage implementation |
| 338 // handles CopyTexImage correctly. | 338 // handles CopyTexImage correctly. |
| 339 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); | 339 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); |
| 340 | 340 |
| 341 } // namespace gl | 341 } // namespace gl |
| 342 | 342 |
| 343 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ | 343 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ |
| OLD | NEW |