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