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 = gl::GetGLImplementation() == gl::kGLImplementationEGLGLES2; | 54 bool is_gles = GetGLImplementation() == kGLImplementationEGLGLES2; |
55 switch (target) { | 55 switch (target) { |
56 case GL_TEXTURE_2D: | 56 case GL_TEXTURE_2D: |
57 return gl::GLHelper::LoadShader( | 57 return 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 gl::GLHelper::LoadShader( | 68 return 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 12 matching lines...) Expand all Loading... |
91 const char kVertexShader[] = STRINGIZE( | 91 const char kVertexShader[] = STRINGIZE( |
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 = GLHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader); |
102 gl::GLHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader); | |
103 GLuint fragment_shader = LoadFragmentShader(target, size); | 102 GLuint fragment_shader = LoadFragmentShader(target, size); |
104 GLuint program = gl::GLHelper::SetupProgram(vertex_shader, fragment_shader); | 103 GLuint program = GLHelper::SetupProgram(vertex_shader, fragment_shader); |
105 EXPECT_NE(program, 0u); | 104 EXPECT_NE(program, 0u); |
106 glUseProgram(program); | 105 glUseProgram(program); |
107 | 106 |
108 GLint sampler_location = glGetUniformLocation(program, "a_texture"); | 107 GLint sampler_location = glGetUniformLocation(program, "a_texture"); |
109 ASSERT_NE(sampler_location, -1); | 108 ASSERT_NE(sampler_location, -1); |
110 glUniform1i(sampler_location, 0); | 109 glUniform1i(sampler_location, 0); |
111 | 110 |
112 GLuint vertex_buffer = gl::GLHelper::SetupQuadVertexBuffer(); | 111 GLuint vertex_buffer = GLHelper::SetupQuadVertexBuffer(); |
113 gl::GLHelper::DrawQuad(vertex_buffer); | 112 GLHelper::DrawQuad(vertex_buffer); |
114 | 113 |
115 glDeleteShader(vertex_shader); | 114 glDeleteShader(vertex_shader); |
116 glDeleteShader(fragment_shader); | 115 glDeleteShader(fragment_shader); |
117 glDeleteProgram(program); | 116 glDeleteProgram(program); |
118 glDeleteBuffersARB(1, &vertex_buffer); | 117 glDeleteBuffersARB(1, &vertex_buffer); |
119 } | 118 } |
120 | 119 |
121 } // namespace | 120 } // namespace |
122 | 121 |
123 template <typename GLImageTestDelegate> | 122 template <typename GLImageTestDelegate> |
124 class GLImageTest : public testing::Test { | 123 class GLImageTest : public testing::Test { |
125 protected: | 124 protected: |
126 // Overridden from testing::Test: | 125 // Overridden from testing::Test: |
127 void SetUp() override { | 126 void SetUp() override { |
128 GLImageTestSupport::InitializeGL(); | 127 GLImageTestSupport::InitializeGL(); |
129 surface_ = gl::init::CreateOffscreenGLSurface(gfx::Size()); | 128 surface_ = gl::init::CreateOffscreenGLSurface(gfx::Size()); |
130 context_ = gl::init::CreateGLContext(nullptr, surface_.get(), | 129 context_ = |
131 gl::PreferIntegratedGpu); | 130 gl::init::CreateGLContext(nullptr, surface_.get(), PreferIntegratedGpu); |
132 context_->MakeCurrent(surface_.get()); | 131 context_->MakeCurrent(surface_.get()); |
133 } | 132 } |
134 void TearDown() override { | 133 void TearDown() override { |
135 context_->ReleaseCurrent(surface_.get()); | 134 context_->ReleaseCurrent(surface_.get()); |
136 context_ = nullptr; | 135 context_ = nullptr; |
137 surface_ = nullptr; | 136 surface_ = nullptr; |
138 GLImageTestSupport::CleanupGL(); | 137 GLImageTestSupport::CleanupGL(); |
139 } | 138 } |
140 | 139 |
141 protected: | 140 protected: |
142 scoped_refptr<gl::GLSurface> surface_; | 141 scoped_refptr<GLSurface> surface_; |
143 scoped_refptr<gl::GLContext> context_; | 142 scoped_refptr<GLContext> context_; |
144 GLImageTestDelegate delegate_; | 143 GLImageTestDelegate delegate_; |
145 }; | 144 }; |
146 | 145 |
147 TYPED_TEST_CASE_P(GLImageTest); | 146 TYPED_TEST_CASE_P(GLImageTest); |
148 | 147 |
149 TYPED_TEST_P(GLImageTest, CreateAndDestroy) { | 148 TYPED_TEST_P(GLImageTest, CreateAndDestroy) { |
150 const gfx::Size small_image_size(4, 4); | 149 const gfx::Size small_image_size(4, 4); |
151 const gfx::Size large_image_size(512, 512); | 150 const gfx::Size large_image_size(512, 512); |
152 const uint8_t image_color[] = {0, 0xff, 0, 0xff}; | 151 const uint8_t image_color[] = {0, 0xff, 0, 0xff}; |
153 | 152 |
154 // Create a small solid color green image of preferred format. This must | 153 // Create a small solid color green image of preferred format. This must |
155 // succeed in order for a GLImage to be conformant. | 154 // succeed in order for a GLImage to be conformant. |
156 scoped_refptr<gl::GLImage> small_image = | 155 scoped_refptr<GLImage> small_image = |
157 this->delegate_.CreateSolidColorImage(small_image_size, image_color); | 156 this->delegate_.CreateSolidColorImage(small_image_size, image_color); |
158 ASSERT_TRUE(small_image); | 157 ASSERT_TRUE(small_image); |
159 | 158 |
160 // Create a large solid color green image of preferred format. This must | 159 // Create a large solid color green image of preferred format. This must |
161 // succeed in order for a GLImage to be conformant. | 160 // succeed in order for a GLImage to be conformant. |
162 scoped_refptr<gl::GLImage> large_image = | 161 scoped_refptr<GLImage> large_image = |
163 this->delegate_.CreateSolidColorImage(large_image_size, image_color); | 162 this->delegate_.CreateSolidColorImage(large_image_size, image_color); |
164 ASSERT_TRUE(large_image); | 163 ASSERT_TRUE(large_image); |
165 | 164 |
166 // Verify that image size is correct. | 165 // Verify that image size is correct. |
167 EXPECT_EQ(small_image->GetSize().ToString(), small_image_size.ToString()); | 166 EXPECT_EQ(small_image->GetSize().ToString(), small_image_size.ToString()); |
168 EXPECT_EQ(large_image->GetSize().ToString(), large_image_size.ToString()); | 167 EXPECT_EQ(large_image->GetSize().ToString(), large_image_size.ToString()); |
169 | 168 |
170 // Verify that destruction of images work correctly both when we have a | 169 // Verify that destruction of images work correctly both when we have a |
171 // context and when we don't. | 170 // context and when we don't. |
172 small_image->Destroy(true /* have_context */); | 171 small_image->Destroy(true /* have_context */); |
(...skipping 21 matching lines...) Expand all Loading... |
194 | 193 |
195 const gfx::Size image_size(256, 256); | 194 const gfx::Size image_size(256, 256); |
196 | 195 |
197 GLuint framebuffer = | 196 GLuint framebuffer = |
198 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); | 197 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); |
199 ASSERT_TRUE(framebuffer); | 198 ASSERT_TRUE(framebuffer); |
200 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); | 199 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); |
201 glViewport(0, 0, image_size.width(), image_size.height()); | 200 glViewport(0, 0, image_size.width(), image_size.height()); |
202 | 201 |
203 // Create an uninitialized image of preferred format. | 202 // Create an uninitialized image of preferred format. |
204 scoped_refptr<gl::GLImage> image = this->delegate_.CreateImage(image_size); | 203 scoped_refptr<GLImage> image = this->delegate_.CreateImage(image_size); |
205 | 204 |
206 // Create a texture that |image| will be bound to. | 205 // Create a texture that |image| will be bound to. |
207 GLenum target = this->delegate_.GetTextureTarget(); | 206 GLenum target = this->delegate_.GetTextureTarget(); |
208 GLuint texture = GLTestHelper::CreateTexture(target); | 207 GLuint texture = GLTestHelper::CreateTexture(target); |
209 glBindTexture(target, texture); | 208 glBindTexture(target, texture); |
210 | 209 |
211 // Bind |image| to |texture|. | 210 // Bind |image| to |texture|. |
212 bool rv = image->BindTexImage(target); | 211 bool rv = image->BindTexImage(target); |
213 EXPECT_TRUE(rv); | 212 EXPECT_TRUE(rv); |
214 | 213 |
(...skipping 26 matching lines...) Expand all Loading... |
241 const uint8_t image_color[] = {0x10, 0x20, 0, 0xff}; | 240 const uint8_t image_color[] = {0x10, 0x20, 0, 0xff}; |
242 | 241 |
243 GLuint framebuffer = | 242 GLuint framebuffer = |
244 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); | 243 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); |
245 ASSERT_TRUE(framebuffer); | 244 ASSERT_TRUE(framebuffer); |
246 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); | 245 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); |
247 glViewport(0, 0, image_size.width(), image_size.height()); | 246 glViewport(0, 0, image_size.width(), image_size.height()); |
248 | 247 |
249 // Create a solid color green image of preferred format. This must succeed | 248 // Create a solid color green image of preferred format. This must succeed |
250 // in order for a GLImage to be conformant. | 249 // in order for a GLImage to be conformant. |
251 scoped_refptr<gl::GLImage> image = | 250 scoped_refptr<GLImage> image = |
252 this->delegate_.CreateSolidColorImage(image_size, image_color); | 251 this->delegate_.CreateSolidColorImage(image_size, image_color); |
253 ASSERT_TRUE(image); | 252 ASSERT_TRUE(image); |
254 | 253 |
255 // Initialize a blue texture of the same size as |image|. | 254 // Initialize a blue texture of the same size as |image|. |
256 unsigned target = this->delegate_.GetTextureTarget(); | 255 unsigned target = this->delegate_.GetTextureTarget(); |
257 GLuint texture = GLTestHelper::CreateTexture(target); | 256 GLuint texture = GLTestHelper::CreateTexture(target); |
258 glBindTexture(target, texture); | 257 glBindTexture(target, texture); |
259 | 258 |
260 // Bind |image| to |texture|. | 259 // Bind |image| to |texture|. |
261 bool rv = image->BindTexImage(target); | 260 bool rv = image->BindTexImage(target); |
(...skipping 30 matching lines...) Expand all Loading... |
292 const uint8_t texture_color[] = {0, 0, 0xff, 0xff}; | 291 const uint8_t texture_color[] = {0, 0, 0xff, 0xff}; |
293 | 292 |
294 GLuint framebuffer = | 293 GLuint framebuffer = |
295 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); | 294 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); |
296 ASSERT_TRUE(framebuffer); | 295 ASSERT_TRUE(framebuffer); |
297 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); | 296 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); |
298 glViewport(0, 0, image_size.width(), image_size.height()); | 297 glViewport(0, 0, image_size.width(), image_size.height()); |
299 | 298 |
300 // Create a solid color green image of preferred format. This must succeed | 299 // Create a solid color green image of preferred format. This must succeed |
301 // in order for a GLImage to be conformant. | 300 // in order for a GLImage to be conformant. |
302 scoped_refptr<gl::GLImage> image = | 301 scoped_refptr<GLImage> image = |
303 this->delegate_.CreateSolidColorImage(image_size, image_color); | 302 this->delegate_.CreateSolidColorImage(image_size, image_color); |
304 ASSERT_TRUE(image); | 303 ASSERT_TRUE(image); |
305 | 304 |
306 // Create a solid color blue texture of the same size as |image|. | 305 // Create a solid color blue texture of the same size as |image|. |
307 unsigned target = this->delegate_.GetTextureTarget(); | 306 unsigned target = this->delegate_.GetTextureTarget(); |
308 GLuint texture = GLTestHelper::CreateTexture(target); | 307 GLuint texture = GLTestHelper::CreateTexture(target); |
309 std::unique_ptr<uint8_t[]> pixels(new uint8_t[BufferSizeForBufferFormat( | 308 std::unique_ptr<uint8_t[]> pixels(new uint8_t[BufferSizeForBufferFormat( |
310 image_size, gfx::BufferFormat::RGBA_8888)]); | 309 image_size, gfx::BufferFormat::RGBA_8888)]); |
311 GLImageTestSupport::SetBufferDataToColor( | 310 GLImageTestSupport::SetBufferDataToColor( |
312 image_size.width(), image_size.height(), | 311 image_size.width(), image_size.height(), |
(...skipping 21 matching lines...) Expand all Loading... |
334 image->Destroy(true /* have_context */); | 333 image->Destroy(true /* have_context */); |
335 } | 334 } |
336 | 335 |
337 // The GLImageCopyTest test case verifies that the GLImage implementation | 336 // The GLImageCopyTest test case verifies that the GLImage implementation |
338 // handles CopyTexImage correctly. | 337 // handles CopyTexImage correctly. |
339 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); | 338 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); |
340 | 339 |
341 } // namespace gl | 340 } // namespace gl |
342 | 341 |
343 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ | 342 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ |
OLD | NEW |