OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef GL_GLEXT_PROTOTYPES | 5 #ifndef GL_GLEXT_PROTOTYPES |
6 #define GL_GLEXT_PROTOTYPES | 6 #define GL_GLEXT_PROTOTYPES |
7 #endif | 7 #endif |
8 | 8 |
9 #include <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
10 #include <GLES2/gl2ext.h> | 10 #include <GLES2/gl2ext.h> |
11 #include <GLES2/gl2extchromium.h> | 11 #include <GLES2/gl2extchromium.h> |
| 12 #include <GLES3/gl3.h> |
12 #include <stddef.h> | 13 #include <stddef.h> |
13 #include <stdint.h> | 14 #include <stdint.h> |
14 | 15 |
| 16 #include "base/command_line.h" |
15 #include "gpu/command_buffer/tests/gl_manager.h" | 17 #include "gpu/command_buffer/tests/gl_manager.h" |
16 #include "gpu/command_buffer/tests/gl_test_utils.h" | 18 #include "gpu/command_buffer/tests/gl_test_utils.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/gl/gl_switches.h" |
19 | 22 |
20 namespace gpu { | 23 namespace gpu { |
21 | 24 |
22 namespace { | 25 namespace { |
23 enum CopyType { TexImage, TexSubImage }; | 26 enum CopyType { TexImage, TexSubImage }; |
24 const CopyType kCopyTypes[] = { | 27 const CopyType kCopyTypes[] = { |
25 TexImage, | 28 TexImage, |
26 TexSubImage, | 29 TexSubImage, |
27 }; | 30 }; |
| 31 |
| 32 static const char* kSimpleVertexShaderES3 = |
| 33 "#version 300 es\n" |
| 34 "in vec2 a_position;\n" |
| 35 "out vec2 v_texCoord;\n" |
| 36 "void main() {\n" |
| 37 " gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);\n" |
| 38 " v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;\n" |
| 39 "}\n"; |
| 40 |
| 41 static const char* kIntTextureFragmentShaderES3 = |
| 42 "#version 300 es\n" |
| 43 "precision mediump float;\n" |
| 44 "uniform mediump isampler2D u_texture;\n" |
| 45 "in vec2 v_texCoord;\n" |
| 46 "out vec4 fragData;\n" |
| 47 "void main() {\n" |
| 48 " ivec4 color = texture(u_texture, v_texCoord);\n" |
| 49 " fragData = vec4(float(color[0])/255.0, float(color[1])/255.0," |
| 50 "float(color[2])/255.0, float(color[3])/255.0);\n" |
| 51 "}\n"; |
| 52 |
28 } | 53 } |
29 | 54 |
30 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. | 55 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. |
31 class GLCopyTextureCHROMIUMTest | 56 class GLCopyTextureCHROMIUMTest |
32 : public testing::Test, | 57 : public testing::Test, |
33 public ::testing::WithParamInterface<CopyType> { | 58 public ::testing::WithParamInterface<CopyType> { |
34 protected: | 59 protected: |
35 | 60 |
36 void CreateAndBindDestinationTextureAndFBO(GLenum target) { | 61 void CreateAndBindDestinationTextureAndFBO(GLenum target) { |
37 glGenTextures(2, textures_); | 62 glGenTextures(2, textures_); |
38 glBindTexture(target, textures_[1]); | 63 glBindTexture(target, textures_[1]); |
39 | 64 |
40 // Some drivers (NVidia/SGX) require texture settings to be a certain way or | 65 // Some drivers (NVidia/SGX) require texture settings to be a certain way or |
41 // they won't report FRAMEBUFFER_COMPLETE. | 66 // they won't report FRAMEBUFFER_COMPLETE. |
42 glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 67 glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
43 glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 68 glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
44 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 69 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
45 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 70 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
46 | 71 |
47 glGenFramebuffers(1, &framebuffer_id_); | 72 glGenFramebuffers(1, &framebuffer_id_); |
48 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_); | 73 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_); |
49 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, | 74 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, |
50 textures_[1], 0); | 75 textures_[1], 0); |
51 } | 76 } |
52 | 77 |
53 void SetUp() override { | 78 void SetUp() override { |
54 gl_.Initialize(GLManager::Options()); | 79 GLManager::Options options; |
| 80 options.context_type = gles2::CONTEXT_TYPE_OPENGLES3; |
| 81 options.size = gfx::Size(64, 64); |
| 82 gl_.Initialize(options); |
55 | 83 |
56 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D); | 84 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D); |
57 } | 85 } |
58 | 86 |
59 void TearDown() override { | 87 void TearDown() override { |
60 glDeleteTextures(2, textures_); | 88 glDeleteTextures(2, textures_); |
61 glDeleteFramebuffers(1, &framebuffer_id_); | 89 glDeleteFramebuffers(1, &framebuffer_id_); |
62 gl_.Destroy(); | 90 gl_.Destroy(); |
63 } | 91 } |
64 | 92 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 EXPECT_EQ(framebuffer_id_, fb_id); | 153 EXPECT_EQ(framebuffer_id_, fb_id); |
126 | 154 |
127 // Check that FB is complete. | 155 // Check that FB is complete. |
128 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | 156 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
129 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | 157 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
130 | 158 |
131 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); | 159 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); |
132 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 160 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
133 } | 161 } |
134 | 162 |
| 163 // Color-renderable to color-renderable |
| 164 TEST_P(GLCopyTextureCHROMIUMTest, R8ToR8) { |
| 165 CopyType copy_type = GetParam(); |
| 166 uint8_t pixels[1 * 4] = {255u, 0u, 0u, 255u}; |
| 167 |
| 168 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 169 glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 1, 1, 0, GL_RED, GL_UNSIGNED_BYTE, |
| 170 pixels); |
| 171 |
| 172 if (copy_type == TexImage) { |
| 173 glCopyTextureCHROMIUM(textures_[0], textures_[1], GL_R8, |
| 174 GL_UNSIGNED_BYTE, false, false, false); |
| 175 } else { |
| 176 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
| 177 glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 1, 1, 0, GL_RED, GL_UNSIGNED_BYTE, |
| 178 nullptr); |
| 179 |
| 180 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0, |
| 181 0, 1, 1, false, false, false); |
| 182 } |
| 183 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 184 |
| 185 // Check the FB is still bound. |
| 186 GLint value = 0; |
| 187 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value); |
| 188 GLuint fb_id = value; |
| 189 EXPECT_EQ(framebuffer_id_, fb_id); |
| 190 |
| 191 // Check that FB is complete. |
| 192 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 193 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 194 |
| 195 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); |
| 196 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 197 } |
| 198 |
| 199 // Color-renderable to non-color-renderable |
| 200 TEST_P(GLCopyTextureCHROMIUMTest, RGBA8IToRGB8I) { |
| 201 CopyType copy_type = GetParam(); |
| 202 const GLsizei kWidth = 8, kHeight = 8; |
| 203 uint8_t pixels[8 * 8 * 4]; |
| 204 for (int i = 0; i < kWidth * kHeight * 4; i += 4) { |
| 205 pixels[i + 0] = 0; |
| 206 pixels[i + 1] = 1; |
| 207 pixels[i + 2] = 2; |
| 208 pixels[i + 3] = 3; |
| 209 } |
| 210 |
| 211 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 212 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 213 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 214 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, kWidth, kHeight, 0, |
| 215 GL_RGBA_INTEGER, GL_BYTE, pixels); |
| 216 |
| 217 if (copy_type == TexImage) { |
| 218 glCopyTextureCHROMIUM(textures_[0], textures_[1], GL_RGB8I, |
| 219 GL_BYTE, false, false, false); |
| 220 } else { |
| 221 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
| 222 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, kWidth, kHeight, 0, |
| 223 GL_RGB_INTEGER, GL_BYTE, nullptr); |
| 224 |
| 225 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0, |
| 226 0, kWidth, kHeight, false, false, false); |
| 227 } |
| 228 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 229 |
| 230 // Check the FB is still bound. |
| 231 GLint value = 0; |
| 232 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value); |
| 233 GLuint fb_id = value; |
| 234 EXPECT_EQ(framebuffer_id_, fb_id); |
| 235 |
| 236 glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 237 GLuint framebuffer = 0; |
| 238 glGenFramebuffers(1, &framebuffer); |
| 239 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 240 GLuint texture = 0; |
| 241 glGenTextures(1, &texture); |
| 242 glBindTexture(GL_TEXTURE_2D, texture); |
| 243 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 244 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 245 CreateBackingForTexture(GL_TEXTURE_2D, kWidth, kHeight); |
| 246 glFramebufferTexture2D( |
| 247 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
| 248 |
| 249 glViewport(0, 0, kWidth, kHeight); |
| 250 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 251 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 252 |
| 253 GLuint program = GLTestHelper::LoadProgram( |
| 254 kSimpleVertexShaderES3, kIntTextureFragmentShaderES3); |
| 255 EXPECT_NE(program, 0u); |
| 256 GLint position_loc = glGetAttribLocation(program, "a_position"); |
| 257 GLint texture_loc = glGetUniformLocation(program, "u_texture"); |
| 258 ASSERT_NE(position_loc, -1); |
| 259 ASSERT_NE(texture_loc, -1); |
| 260 glUseProgram(program); |
| 261 |
| 262 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc); |
| 263 ASSERT_NE(vbo, 0u); |
| 264 |
| 265 glActiveTexture(GL_TEXTURE0); |
| 266 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
| 267 |
| 268 glDrawArrays(GL_TRIANGLES, 0, 6); |
| 269 |
| 270 // Destination texture does not contain alpha channel, sampling returns 1. |
| 271 uint8_t expected_color[4] = {0, 1, 2, 1}; |
| 272 uint8_t result_pixels[kHeight][kWidth][4] = {{{1}}}; |
| 273 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, result_pixels); |
| 274 for (int x = 0; x < kWidth; ++x) { |
| 275 for (int y = 0; y < kHeight; ++y) { |
| 276 EXPECT_EQ(expected_color[0], result_pixels[y][x][0]); |
| 277 EXPECT_EQ(expected_color[1], result_pixels[y][x][1]); |
| 278 EXPECT_EQ(expected_color[2], result_pixels[y][x][2]); |
| 279 } |
| 280 } |
| 281 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 282 } |
| 283 |
135 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { | 284 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { |
136 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { | 285 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { |
137 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; | 286 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; |
138 return; | 287 return; |
139 } | 288 } |
140 CopyType copy_type = GetParam(); | 289 CopyType copy_type = GetParam(); |
141 GLenum src_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; | 290 GLenum src_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; |
142 GLenum dest_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; | 291 GLenum dest_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; |
143 | 292 |
144 uint8_t pixels[1 * 4] = {255u, 0u, 255u, 255u}; | 293 uint8_t pixels[1 * 4] = {255u, 0u, 255u, 255u}; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 372 } |
224 | 373 |
225 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) { | 374 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) { |
226 CopyType copy_type = GetParam(); | 375 CopyType copy_type = GetParam(); |
227 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 376 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
228 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 377 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
229 nullptr); | 378 nullptr); |
230 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 379 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
231 | 380 |
232 // Check unsupported format reports error. | 381 // Check unsupported format reports error. |
233 GLint unsupported_dest_formats[] = {GL_ALPHA, GL_LUMINANCE, | 382 // TODO(qiankun.miao@intel.com): find real unsupported formats. |
234 GL_LUMINANCE_ALPHA}; | 383 GLint unsupported_dest_formats[] = {GL_RGBA8UI}; |
235 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats); | 384 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats); |
236 dest_index++) { | 385 dest_index++) { |
237 if (copy_type == TexImage) { | 386 if (copy_type == TexImage) { |
238 glCopyTextureCHROMIUM(textures_[0], textures_[1], | 387 glCopyTextureCHROMIUM(textures_[0], textures_[1], |
239 unsupported_dest_formats[dest_index], | 388 unsupported_dest_formats[dest_index], |
240 GL_UNSIGNED_BYTE, false, false, false); | 389 GL_UNSIGNED_BYTE, false, false, false); |
241 } else { | 390 } else { |
242 glBindTexture(GL_TEXTURE_2D, textures_[1]); | 391 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
243 glTexImage2D(GL_TEXTURE_2D, 0, unsupported_dest_formats[dest_index], 1, 1, | 392 glTexImage2D(GL_TEXTURE_2D, 0, unsupported_dest_formats[dest_index], 1, 1, |
244 0, unsupported_dest_formats[dest_index], GL_UNSIGNED_BYTE, | 393 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, |
245 nullptr); | 394 nullptr); |
246 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, | 395 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, |
247 0, 0, 1, 1, false, false, false); | 396 0, 0, 1, 1, false, false, false); |
248 } | 397 } |
249 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()) | 398 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()) |
250 << "dest_index:" << dest_index; | 399 << "dest_index:" << dest_index; |
251 } | 400 } |
252 } | 401 } |
253 | 402 |
254 TEST_F(GLCopyTextureCHROMIUMTest, InternalFormatTypeCombinationNotSupported) { | 403 TEST_F(GLCopyTextureCHROMIUMTest, InternalFormatTypeCombinationNotSupported) { |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 } | 709 } |
561 | 710 |
562 TEST_P(GLCopyTextureCHROMIUMTest, ProgramStatePreservation) { | 711 TEST_P(GLCopyTextureCHROMIUMTest, ProgramStatePreservation) { |
563 CopyType copy_type = GetParam(); | 712 CopyType copy_type = GetParam(); |
564 // unbind the one created in setup. | 713 // unbind the one created in setup. |
565 glBindFramebuffer(GL_FRAMEBUFFER, 0); | 714 glBindFramebuffer(GL_FRAMEBUFFER, 0); |
566 glBindTexture(GL_TEXTURE_2D, 0); | 715 glBindTexture(GL_TEXTURE_2D, 0); |
567 | 716 |
568 GLManager gl2; | 717 GLManager gl2; |
569 GLManager::Options options; | 718 GLManager::Options options; |
| 719 options.context_type = gles2::CONTEXT_TYPE_OPENGLES3; |
570 options.size = gfx::Size(16, 16); | 720 options.size = gfx::Size(16, 16); |
571 options.share_group_manager = &gl_; | 721 options.share_group_manager = &gl_; |
572 gl2.Initialize(options); | 722 gl2.Initialize(options); |
573 gl_.MakeCurrent(); | 723 gl_.MakeCurrent(); |
574 | 724 |
575 static const char* v_shader_str = | 725 static const char* v_shader_str = |
576 "attribute vec4 g_Position;\n" | 726 "attribute vec4 g_Position;\n" |
577 "void main()\n" | 727 "void main()\n" |
578 "{\n" | 728 "{\n" |
579 " gl_Position = g_Position;\n" | 729 " gl_Position = g_Position;\n" |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 expected_color = y < copy_region_y + 1 ? blue : white; | 1044 expected_color = y < copy_region_y + 1 ? blue : white; |
895 } | 1045 } |
896 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color); | 1046 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color); |
897 } | 1047 } |
898 } | 1048 } |
899 } | 1049 } |
900 } | 1050 } |
901 } | 1051 } |
902 | 1052 |
903 } // namespace gpu | 1053 } // namespace gpu |
OLD | NEW |