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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } | 203 } |
204 glDeleteProgram(program); | 204 glDeleteProgram(program); |
205 glDeleteBuffersARB(1, &vertex_buffer); | 205 glDeleteBuffersARB(1, &vertex_buffer); |
206 glDeleteFramebuffersEXT(1, &framebuffer); | 206 glDeleteFramebuffersEXT(1, &framebuffer); |
207 } | 207 } |
208 | 208 |
209 // The GLImageCopyTest test case verifies that the GLImage implementation | 209 // The GLImageCopyTest test case verifies that the GLImage implementation |
210 // handles CopyTexImage correctly. | 210 // handles CopyTexImage correctly. |
211 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); | 211 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); |
212 | 212 |
| 213 template <typename GLImageTestDelegate> |
| 214 class GLImageBindTest : public GLImageTest<GLImageTestDelegate> {}; |
| 215 |
| 216 TYPED_TEST_CASE_P(GLImageBindTest); |
| 217 |
| 218 TYPED_TEST_P(GLImageBindTest, BindTexImage) { |
| 219 const gfx::Size image_size(256, 256); |
| 220 const uint8_t image_color[] = {0x10, 0x20, 0, 0xff}; |
| 221 |
| 222 GLuint framebuffer = |
| 223 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); |
| 224 ASSERT_TRUE(framebuffer); |
| 225 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); |
| 226 glViewport(0, 0, image_size.width(), image_size.height()); |
| 227 |
| 228 GLuint program = this->CreateSingleTextureProgram(); |
| 229 GLuint vertex_buffer = gfx::GLHelper::SetupQuadVertexBuffer(); |
| 230 |
| 231 for (auto format : gfx::GetBufferFormatsForTesting()) { |
| 232 if (!TypeParam::IsSupported(format)) { |
| 233 continue; |
| 234 } |
| 235 |
| 236 // Create a solid color green image of preferred format. This must succeed |
| 237 // in order for a GLImage to be conformant. |
| 238 scoped_refptr<gl::GLImage> image = |
| 239 this->delegate_.CreateSolidColorImage(image_size, format, image_color); |
| 240 ASSERT_TRUE(image); |
| 241 |
| 242 GLuint texture = GLTestHelper::CreateTexture(GL_TEXTURE_2D); |
| 243 |
| 244 // Bind |image| to |texture|. |
| 245 bool rv = image->BindTexImage(GL_TEXTURE_2D); |
| 246 EXPECT_TRUE(rv); |
| 247 |
| 248 // Draw |texture| to viewport and read back pixels to check expectations. |
| 249 gfx::GLHelper::DrawQuad(vertex_buffer); |
| 250 |
| 251 GLTestHelper::CheckPixels(0, 0, image_size.width(), image_size.height(), |
| 252 image_color); |
| 253 |
| 254 // Clean up. |
| 255 glDeleteTextures(1, &texture); |
| 256 image->Destroy(true); |
| 257 } |
| 258 glDeleteProgram(program); |
| 259 glDeleteBuffersARB(1, &vertex_buffer); |
| 260 glDeleteFramebuffersEXT(1, &framebuffer); |
| 261 } |
| 262 |
| 263 // The GLImageBindTest test case verifies that the GLImage implementation |
| 264 // handles BindTexImage correctly. |
| 265 REGISTER_TYPED_TEST_CASE_P(GLImageBindTest, BindTexImage); |
| 266 |
213 } // namespace gl | 267 } // namespace gl |
214 | 268 |
215 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ | 269 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ |
OLD | NEW |