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 } | 44 } |
45 | 45 |
46 protected: | 46 protected: |
47 scoped_refptr<GLSurface> surface_; | 47 scoped_refptr<GLSurface> surface_; |
48 scoped_refptr<GLContext> context_; | 48 scoped_refptr<GLContext> context_; |
49 GLImageTestDelegate delegate_; | 49 GLImageTestDelegate delegate_; |
50 }; | 50 }; |
51 | 51 |
52 TYPED_TEST_CASE_P(GLImageTest); | 52 TYPED_TEST_CASE_P(GLImageTest); |
53 | 53 |
54 // Copy image to texture. Support is optional. Texels should be updated if | 54 TYPED_TEST_P(GLImageTest, CreateAndDestroy) { |
55 // supported, and left unchanged if not. | 55 const Size small_image_size(4, 4); |
56 TYPED_TEST_P(GLImageTest, CopyTexSubImage) { | 56 const Size large_image_size(512, 512); |
| 57 const uint8_t image_color[] = {0, 0xff, 0, 0xff}; |
| 58 |
| 59 // Create a small solid color green image of preferred format. This must |
| 60 // succeed in order for a GLImage to be conformant. |
| 61 scoped_refptr<GLImage> small_image = this->delegate_.CreateSolidColorImage( |
| 62 small_image_size, GLImageTestSupport::GetPreferredInternalFormat(), |
| 63 GLImageTestSupport::GetPreferredBufferFormat(), image_color); |
| 64 ASSERT_TRUE(small_image); |
| 65 |
| 66 // Create a large solid color green image of preferred format. This must |
| 67 // succeed in order for a GLImage to be conformant. |
| 68 scoped_refptr<GLImage> large_image = this->delegate_.CreateSolidColorImage( |
| 69 large_image_size, GLImageTestSupport::GetPreferredInternalFormat(), |
| 70 GLImageTestSupport::GetPreferredBufferFormat(), image_color); |
| 71 ASSERT_TRUE(large_image); |
| 72 |
| 73 // Verify that image size is correct. |
| 74 EXPECT_EQ(small_image->GetSize().ToString(), small_image_size.ToString()); |
| 75 EXPECT_EQ(large_image->GetSize().ToString(), large_image_size.ToString()); |
| 76 |
| 77 // Verify that internal format is correct. |
| 78 EXPECT_EQ(small_image->GetInternalFormat(), |
| 79 GLImageTestSupport::GetPreferredInternalFormat()); |
| 80 EXPECT_EQ(large_image->GetInternalFormat(), |
| 81 GLImageTestSupport::GetPreferredInternalFormat()); |
| 82 |
| 83 // Verify that destruction of images work correctly both when we have a |
| 84 // context and when we don't. |
| 85 small_image->Destroy(true /* have_context */); |
| 86 large_image->Destroy(false /* have_context */); |
| 87 } |
| 88 |
| 89 // The GLImageTest test case verifies the behaviour that is expected from a |
| 90 // GLImage in order to be conformant. |
| 91 REGISTER_TYPED_TEST_CASE_P(GLImageTest, CreateAndDestroy); |
| 92 |
| 93 template <typename GLImageTestDelegate> |
| 94 class GLImageCopyTest : public GLImageTest<GLImageTestDelegate> {}; |
| 95 |
| 96 TYPED_TEST_CASE_P(GLImageCopyTest); |
| 97 |
| 98 TYPED_TEST_P(GLImageCopyTest, CopyTexImage) { |
57 const Size image_size(256, 256); | 99 const Size image_size(256, 256); |
58 const uint8_t image_color[] = {0, 0xff, 0, 0xff}; | 100 const uint8_t image_color[] = {0, 0xff, 0, 0xff}; |
59 const uint8_t texture_color[] = {0, 0, 0xff, 0xff}; | 101 const uint8_t texture_color[] = {0, 0, 0xff, 0xff}; |
60 | 102 |
61 GLuint framebuffer = | 103 GLuint framebuffer = |
62 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); | 104 GLTestHelper::SetupFramebuffer(image_size.width(), image_size.height()); |
63 ASSERT_TRUE(framebuffer); | 105 ASSERT_TRUE(framebuffer); |
64 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); | 106 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); |
65 glViewport(0, 0, image_size.width(), image_size.height()); | 107 glViewport(0, 0, image_size.width(), image_size.height()); |
66 | 108 |
(...skipping 17 matching lines...) Expand all Loading... |
84 pixels.get()); | 126 pixels.get()); |
85 // Note: This test assume that |image| can be used with GL_TEXTURE_2D but | 127 // Note: This test assume that |image| can be used with GL_TEXTURE_2D but |
86 // that might not be the case for some GLImage implementations. | 128 // that might not be the case for some GLImage implementations. |
87 glBindTexture(GL_TEXTURE_2D, texture); | 129 glBindTexture(GL_TEXTURE_2D, texture); |
88 glTexImage2D(GL_TEXTURE_2D, 0, | 130 glTexImage2D(GL_TEXTURE_2D, 0, |
89 GLImageTestSupport::GetPreferredInternalFormat(), | 131 GLImageTestSupport::GetPreferredInternalFormat(), |
90 image_size.width(), image_size.height(), 0, | 132 image_size.width(), image_size.height(), 0, |
91 GLImageTestSupport::GetPreferredInternalFormat(), | 133 GLImageTestSupport::GetPreferredInternalFormat(), |
92 GL_UNSIGNED_BYTE, pixels.get()); | 134 GL_UNSIGNED_BYTE, pixels.get()); |
93 | 135 |
94 // Attempt to copy |image| to |texture|. | 136 // Copy |image| to |texture|. |
95 // Returns true on success, false on failure. | 137 bool rv = image->CopyTexImage(GL_TEXTURE_2D); |
96 bool rv = image->CopyTexSubImage(GL_TEXTURE_2D, Point(), Rect(image_size)); | 138 EXPECT_TRUE(rv); |
97 | 139 |
98 // clang-format off | 140 // clang-format off |
99 const char kVertexShader[] = STRINGIZE( | 141 const char kVertexShader[] = STRINGIZE( |
100 attribute vec2 a_position; | 142 attribute vec2 a_position; |
101 attribute vec2 a_texCoord; | 143 attribute vec2 a_texCoord; |
102 varying vec2 v_texCoord; | 144 varying vec2 v_texCoord; |
103 void main() { | 145 void main() { |
104 gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0); | 146 gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0); |
105 v_texCoord = a_texCoord; | 147 v_texCoord = a_texCoord; |
106 } | 148 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 GLint tex_coord_location = glGetAttribLocation(program, "a_texCoord"); | 196 GLint tex_coord_location = glGetAttribLocation(program, "a_texCoord"); |
155 EXPECT_NE(tex_coord_location, -1); | 197 EXPECT_NE(tex_coord_location, -1); |
156 glEnableVertexAttribArray(tex_coord_location); | 198 glEnableVertexAttribArray(tex_coord_location); |
157 glVertexAttribPointer(tex_coord_location, 2, GL_FLOAT, GL_FALSE, | 199 glVertexAttribPointer(tex_coord_location, 2, GL_FLOAT, GL_FALSE, |
158 sizeof(GLfloat) * 4, | 200 sizeof(GLfloat) * 4, |
159 reinterpret_cast<void*>(sizeof(GLfloat) * 2)); | 201 reinterpret_cast<void*>(sizeof(GLfloat) * 2)); |
160 | 202 |
161 // Draw |texture| to viewport and read back pixels to check expectations. | 203 // Draw |texture| to viewport and read back pixels to check expectations. |
162 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | 204 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
163 GLTestHelper::CheckPixels(0, 0, image_size.width(), image_size.height(), | 205 GLTestHelper::CheckPixels(0, 0, image_size.width(), image_size.height(), |
164 rv ? image_color : texture_color); | 206 image_color); |
165 | 207 |
166 // Clean up. | 208 // Clean up. |
167 glDeleteProgram(program); | 209 glDeleteProgram(program); |
168 glDeleteShader(vertex_shader); | 210 glDeleteShader(vertex_shader); |
169 glDeleteShader(fragment_shader); | 211 glDeleteShader(fragment_shader); |
170 glDeleteBuffersARB(1, &vertex_buffer); | 212 glDeleteBuffersARB(1, &vertex_buffer); |
171 glDeleteTextures(1, &texture); | 213 glDeleteTextures(1, &texture); |
172 glDeleteFramebuffersEXT(1, &framebuffer); | 214 glDeleteFramebuffersEXT(1, &framebuffer); |
173 image->Destroy(true); | 215 image->Destroy(true); |
174 } | 216 } |
175 | 217 |
176 // The GLImageTest test case verifies behaviour that is expected from a | 218 // The GLImageCopyTest test case verifies that the GLImage implementation |
177 // GLImage in order to be conformant. | 219 // handles CopyTexImage correctly. |
178 REGISTER_TYPED_TEST_CASE_P(GLImageTest, CopyTexSubImage); | 220 REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage); |
179 | 221 |
180 } // namespace gfx | 222 } // namespace gfx |
181 | 223 |
182 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ | 224 #endif // UI_GL_TEST_GL_IMAGE_TEST_TEMPLATE_H_ |
OLD | NEW |