Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(782)

Side by Side Diff: gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc

Issue 2479513002: Reland of Extend CopyTextureCHROMIUM to more ES 3.0 texture formats. (Closed)
Patch Set: rebase and minor fix for premultiply and un-premultiply alpha Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
15 #include "gpu/command_buffer/tests/gl_manager.h" 16 #include "gpu/command_buffer/tests/gl_manager.h"
16 #include "gpu/command_buffer/tests/gl_test_utils.h" 17 #include "gpu/command_buffer/tests/gl_test_utils.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/gl/gl_version_info.h"
19 21
20 namespace gpu { 22 namespace gpu {
21 23
22 namespace { 24 namespace {
25
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 std::string GetFragmentShaderSource(GLenum format) {
42 std::string source;
43 source += std::string(
44 "#version 300 es\n"
45 "precision mediump float;\n");
46 if (gles2::GLES2Util::IsSignedIntegerFormat(format)) {
47 source += std::string("#define SamplerType isampler2D\n");
48 source += std::string("#define TextureType ivec4\n");
49 source += std::string("#define ScaleValue 255.0\n");
50 } else if (gles2::GLES2Util::IsUnsignedIntegerFormat(format)) {
51 source += std::string("#define SamplerType usampler2D\n");
52 source += std::string("#define TextureType uvec4\n");
53 source += std::string("#define ScaleValue 255.0\n");
54 } else {
55 source += std::string("#define SamplerType sampler2D\n");
56 source += std::string("#define TextureType vec4\n");
57 source += std::string("#define ScaleValue 1.0\n");
58 }
59
60 source += std::string(
61 "uniform mediump SamplerType u_texture;\n"
62 "in vec2 v_texCoord;\n"
63 "out vec4 fragData;\n"
64 "void main() {\n"
65 " TextureType color = texture(u_texture, v_texCoord);\n"
66 " fragData = vec4(color) / ScaleValue;\n"
67 "}\n");
68 return source;
28 } 69 }
29 70
71 void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t* color) {
72 color[0] = r;
73 color[1] = g;
74 color[2] = b;
75 color[3] = a;
76 }
77
78 void getExpectedColor(GLenum src_internal_format,
79 GLenum dest_internal_format,
80 uint8_t* color,
81 uint8_t* expected_color,
82 uint8_t* mask) {
83 uint8_t adjust_color[4];
84 switch (src_internal_format) {
85 case GL_ALPHA:
86 setColor(0, 0, 0, color[0], adjust_color);
87 break;
88 case GL_R8:
89 setColor(color[0], 0, 0, 255, adjust_color);
90 break;
91 case GL_LUMINANCE:
92 setColor(color[0], color[0], color[0], 255, adjust_color);
93 break;
94 case GL_LUMINANCE_ALPHA:
95 setColor(color[0], color[0], color[0], color[1], adjust_color);
96 break;
97 case GL_RGB:
98 case GL_RGB8:
99 case GL_RGB_YCBCR_420V_CHROMIUM:
100 case GL_RGB_YCBCR_422_CHROMIUM:
101 setColor(color[0], color[1], color[2], 255, adjust_color);
102 break;
103 case GL_RGBA:
104 case GL_RGBA8:
105 setColor(color[0], color[1], color[2], color[3], adjust_color);
106 break;
107 case GL_BGRA_EXT:
108 case GL_BGRA8_EXT:
109 setColor(color[2], color[1], color[0], color[3], adjust_color);
110 break;
111 default:
112 NOTREACHED();
113 break;
114 }
115
116 switch (dest_internal_format) {
117 case GL_ALPHA:
118 setColor(0, 0, 0, adjust_color[3], expected_color);
119 setColor(0, 0, 0, 1, mask);
120 break;
121 case GL_R8:
122 case GL_R16F:
123 case GL_R32F:
124 case GL_R8UI:
125 setColor(adjust_color[0], 0, 0, 0, expected_color);
126 setColor(1, 0, 0, 0, mask);
127 break;
128 case GL_LUMINANCE:
129 setColor(adjust_color[0], 0, 0, 0, expected_color);
130 setColor(1, 0, 0, 0, mask);
131 break;
132 case GL_LUMINANCE_ALPHA:
133 setColor(adjust_color[0], 0, 0, adjust_color[3], expected_color);
134 setColor(1, 0, 0, 1, mask);
135 break;
136 case GL_RG8:
137 case GL_RG16F:
138 case GL_RG32F:
139 case GL_RG8UI:
140 setColor(adjust_color[0], adjust_color[1], 0, 0, expected_color);
141 setColor(1, 1, 0, 0, mask);
142 break;
143 case GL_RGB:
144 case GL_RGB8:
145 case GL_SRGB_EXT:
146 case GL_SRGB8:
147 case GL_RGB565:
148 case GL_R11F_G11F_B10F:
149 case GL_RGB9_E5:
150 case GL_RGB16F:
151 case GL_RGB32F:
152 case GL_RGB8UI:
153 setColor(adjust_color[0], adjust_color[1], adjust_color[2], 0,
154 expected_color);
155 setColor(1, 1, 1, 0, mask);
156 break;
157 case GL_RGBA:
158 case GL_RGBA8:
159 case GL_BGRA_EXT:
160 case GL_BGRA8_EXT:
161 case GL_SRGB_ALPHA_EXT:
162 case GL_SRGB8_ALPHA8:
163 case GL_RGBA4:
164 case GL_RGBA16F:
165 case GL_RGBA32F:
166 case GL_RGBA8UI:
167 setColor(adjust_color[0], adjust_color[1], adjust_color[2],
168 adjust_color[3], expected_color);
169 setColor(1, 1, 1, 1, mask);
170 break;
171 case GL_RGB5_A1:
172 setColor(adjust_color[0], adjust_color[1], adjust_color[2],
173 (adjust_color[3] >> 7) ? 0xFF : 0x0, expected_color);
174 // TODO(qiankun.miao@intel.com): On some Windows platforms, the alpha
175 // channel of expected color is the source alpha value other than 255.
176 // This should be wrong. Skip the alpha channel check and revisit this in
177 // future.
178 setColor(1, 1, 1, 0, mask);
179 break;
180 default:
181 NOTREACHED();
182 break;
183 }
184 }
185
186 } // namespace
187
30 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. 188 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension.
31 class GLCopyTextureCHROMIUMTest 189 class GLCopyTextureCHROMIUMTest
32 : public testing::Test, 190 : public testing::Test,
33 public ::testing::WithParamInterface<CopyType> { 191 public ::testing::WithParamInterface<CopyType> {
34 protected: 192 protected:
35 193
36 void CreateAndBindDestinationTextureAndFBO(GLenum target) { 194 void CreateAndBindDestinationTextureAndFBO(GLenum target) {
37 glGenTextures(2, textures_); 195 glGenTextures(2, textures_);
38 glBindTexture(target, textures_[1]); 196 glBindTexture(target, textures_[1]);
39 197
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 NOTREACHED(); 243 NOTREACHED();
86 return GL_NONE; 244 return GL_NONE;
87 } 245 }
88 } 246 }
89 247
90 GLManager gl_; 248 GLManager gl_;
91 GLuint textures_[2]; 249 GLuint textures_[2];
92 GLuint framebuffer_id_; 250 GLuint framebuffer_id_;
93 }; 251 };
94 252
253 class GLCopyTextureCHROMIUMES3Test : public GLCopyTextureCHROMIUMTest {
254 protected:
255 void SetUp() override {
256 GLManager::Options options;
257 options.context_type = gles2::CONTEXT_TYPE_OPENGLES3;
258 options.size = gfx::Size(64, 64);
259 gl_.Initialize(options);
260
261 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D);
262 }
263
264 // If a driver isn't capable of supporting ES3 context, creating
265 // ContextGroup will fail. Just skip the test.
266 bool ShouldSkipTest() const {
267 return (!gl_.decoder() || !gl_.decoder()->GetContextGroup());
268 }
269
270 // RGB9_E5 isn't accepted by glCopyTexImage2D if underneath context is ES.
271 bool ShouldSkipRGB9_E5() const {
272 DCHECK(!ShouldSkipTest());
273 const gl::GLVersionInfo& gl_version_info =
274 gl_.decoder()->GetFeatureInfo()->gl_version_info();
275 return gl_version_info.is_es;
276 }
277
278 // If EXT_color_buffer_float isn't available, float format isn't supported.
279 bool ShouldSkipFloatFormat() const {
280 DCHECK(!ShouldSkipTest());
281 return !gl_.decoder()->GetFeatureInfo()->ext_color_buffer_float_available();
282 }
283
284 bool ShouldSkipBGRA() const {
285 DCHECK(!ShouldSkipTest());
286 return !gl_.decoder()
287 ->GetFeatureInfo()
288 ->texture_format_bgra8888_available();
289 }
290
291 bool ShouldSkipSRGBEXT() const {
292 DCHECK(!ShouldSkipTest());
293 return !gl_.decoder()->GetFeatureInfo()->ext_srgb_available();
294 }
295 };
296
95 INSTANTIATE_TEST_CASE_P(CopyType, 297 INSTANTIATE_TEST_CASE_P(CopyType,
96 GLCopyTextureCHROMIUMTest, 298 GLCopyTextureCHROMIUMTest,
97 ::testing::ValuesIn(kCopyTypes)); 299 ::testing::ValuesIn(kCopyTypes));
98 300
301 INSTANTIATE_TEST_CASE_P(CopyType,
302 GLCopyTextureCHROMIUMES3Test,
303 ::testing::ValuesIn(kCopyTypes));
304
99 // Test to ensure that the basic functionality of the extension works. 305 // Test to ensure that the basic functionality of the extension works.
100 TEST_P(GLCopyTextureCHROMIUMTest, Basic) { 306 TEST_P(GLCopyTextureCHROMIUMTest, Basic) {
101 CopyType copy_type = GetParam(); 307 CopyType copy_type = GetParam();
102 uint8_t pixels[1 * 4] = {255u, 0u, 0u, 255u}; 308 uint8_t pixels[1 * 4] = {255u, 0u, 0u, 255u};
103 309
104 glBindTexture(GL_TEXTURE_2D, textures_[0]); 310 glBindTexture(GL_TEXTURE_2D, textures_[0]);
105 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 311 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
106 pixels); 312 pixels);
107 313
108 if (copy_type == TexImage) { 314 if (copy_type == TexImage) {
(...skipping 16 matching lines...) Expand all
125 EXPECT_EQ(framebuffer_id_, fb_id); 331 EXPECT_EQ(framebuffer_id_, fb_id);
126 332
127 // Check that FB is complete. 333 // Check that FB is complete.
128 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), 334 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
129 glCheckFramebufferStatus(GL_FRAMEBUFFER)); 335 glCheckFramebufferStatus(GL_FRAMEBUFFER));
130 336
131 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); 337 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels);
132 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 338 EXPECT_TRUE(GL_NO_ERROR == glGetError());
133 } 339 }
134 340
341 TEST_P(GLCopyTextureCHROMIUMES3Test, FormatCombinations) {
342 if (ShouldSkipTest())
343 return;
344 CopyType copy_type = GetParam();
345
346 struct FormatType {
347 GLenum internal_format;
348 GLenum format;
349 GLenum type;
350 };
351
352 FormatType src_format_types[] = {
353 {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE},
354 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE},
355 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE},
356 {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE},
357 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE},
358 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE},
359 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE},
360 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE},
361 };
362
363 FormatType dest_format_types[] = {
364 // TODO(qiankun.miao@intel.com): ALPHA and LUMINANCE formats have bug on
365 // GL core profile. See crbug.com/577144. Enable these formats after
366 // using workaround in gles2_cmd_copy_tex_image.cc.
367 // {GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE},
368 // {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE},
369 // {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE},
370
371 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE},
372 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE},
373 {GL_SRGB_EXT, GL_SRGB_EXT, GL_UNSIGNED_BYTE},
374 {GL_SRGB_ALPHA_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE},
375 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE},
376 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE},
377 {GL_R8, GL_RED, GL_UNSIGNED_BYTE},
378 {GL_R16F, GL_RED, GL_HALF_FLOAT},
379 {GL_R16F, GL_RED, GL_FLOAT},
380 {GL_R32F, GL_RED, GL_FLOAT},
381 {GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE},
382 {GL_RG8, GL_RG, GL_UNSIGNED_BYTE},
383 {GL_RG16F, GL_RG, GL_HALF_FLOAT},
384 {GL_RG16F, GL_RG, GL_FLOAT},
385 {GL_RG32F, GL_RG, GL_FLOAT},
386 {GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE},
387 {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE},
388 {GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE},
389 {GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE},
390 {GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT},
391 {GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT},
392 {GL_RGB9_E5, GL_RGB, GL_FLOAT},
393 {GL_RGB16F, GL_RGB, GL_HALF_FLOAT},
394 {GL_RGB16F, GL_RGB, GL_FLOAT},
395 {GL_RGB32F, GL_RGB, GL_FLOAT},
396 {GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE},
397 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE},
398 {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE},
399 {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE},
400 {GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE},
401 {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT},
402 {GL_RGBA16F, GL_RGBA, GL_FLOAT},
403 {GL_RGBA32F, GL_RGBA, GL_FLOAT},
404 {GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE},
405 };
406
407 for (auto src_format_type : src_format_types) {
408 for (auto dest_format_type : dest_format_types) {
409 if (dest_format_type.internal_format == GL_RGB9_E5 && ShouldSkipRGB9_E5())
410 continue;
411 if ((src_format_type.internal_format == GL_BGRA_EXT ||
412 src_format_type.internal_format == GL_BGRA8_EXT ||
413 dest_format_type.internal_format == GL_BGRA_EXT ||
414 dest_format_type.internal_format == GL_BGRA8_EXT) &&
415 ShouldSkipBGRA())
416 continue;
417 if (gles2::GLES2Util::IsFloatFormat(dest_format_type.internal_format) &&
418 ShouldSkipFloatFormat())
419 continue;
420 if ((dest_format_type.internal_format == GL_SRGB_EXT ||
421 dest_format_type.internal_format == GL_SRGB_ALPHA_EXT) &&
422 ShouldSkipSRGBEXT())
423 continue;
424
425 const GLsizei kWidth = 8, kHeight = 8;
426 const int src_channel_count = gles2::GLES2Util::ElementsPerGroup(
427 src_format_type.format, src_format_type.type);
428 uint8_t color[4] = {1, 63, 127, 255};
429 uint8_t pixels[8 * 8 * 4];
430 for (int i = 0; i < kWidth * kHeight * src_channel_count;
431 i += src_channel_count)
432 for (int j = 0; j < src_channel_count; ++j)
433 pixels[i + j] = color[j];
434 uint8_t expected_color[4];
435 uint8_t mask[4];
436 getExpectedColor(src_format_type.internal_format,
437 dest_format_type.internal_format, color, expected_color,
438 mask);
439
440 glDeleteTextures(2, textures_);
441 glDeleteFramebuffers(1, &framebuffer_id_);
442 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D);
443
444 glBindTexture(GL_TEXTURE_2D, textures_[0]);
445 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
446 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
447 glTexImage2D(GL_TEXTURE_2D, 0, src_format_type.internal_format, kWidth,
448 kHeight, 0, src_format_type.format, src_format_type.type,
449 pixels);
450
451 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
452 if (copy_type == TexImage) {
453 glCopyTextureCHROMIUM(textures_[0], textures_[1],
454 dest_format_type.internal_format,
455 dest_format_type.type, false, false, false);
456 } else {
457 glBindTexture(GL_TEXTURE_2D, textures_[1]);
458 glTexImage2D(GL_TEXTURE_2D, 0, dest_format_type.internal_format, kWidth,
459 kHeight, 0, dest_format_type.format, dest_format_type.type,
460 nullptr);
461
462 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0, 0, kWidth,
463 kHeight, false, false, false);
464 }
465 EXPECT_TRUE(glGetError() == GL_NO_ERROR)
466 << " src_internal_format: "
467 << gles2::GLES2Util::GetStringEnum(src_format_type.internal_format)
468 << " dest_internal_format: "
469 << gles2::GLES2Util::GetStringEnum(dest_format_type.internal_format);
470
471 // Draw destination texture to a fbo with attachment in RGBA format.
472 glBindFramebuffer(GL_FRAMEBUFFER, 0);
473 GLuint framebuffer = 0;
474 glGenFramebuffers(1, &framebuffer);
475 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
476 GLuint texture = 0;
477 glGenTextures(1, &texture);
478 glBindTexture(GL_TEXTURE_2D, texture);
479 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
480 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
481 CreateBackingForTexture(GL_TEXTURE_2D, kWidth, kHeight);
482 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
483 GL_TEXTURE_2D, texture, 0);
484 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
485 glCheckFramebufferStatus(GL_FRAMEBUFFER));
486 glViewport(0, 0, kWidth, kHeight);
487
488 std::string fragment_shader_source =
489 GetFragmentShaderSource(dest_format_type.internal_format);
490 GLuint program = GLTestHelper::LoadProgram(
491 kSimpleVertexShaderES3, fragment_shader_source.c_str());
492 EXPECT_NE(program, 0u);
493 GLint position_loc = glGetAttribLocation(program, "a_position");
494 GLint texture_loc = glGetUniformLocation(program, "u_texture");
495 ASSERT_NE(position_loc, -1);
496 ASSERT_NE(texture_loc, -1);
497 glUseProgram(program);
498
499 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc);
500 ASSERT_NE(vbo, 0u);
501
502 glActiveTexture(GL_TEXTURE0);
503 glBindTexture(GL_TEXTURE_2D, textures_[1]);
504
505 glDrawArrays(GL_TRIANGLES, 0, 6);
506
507 EXPECT_TRUE(GL_NO_ERROR == glGetError());
508
509 GLsizei size = kWidth * kHeight * 4;
510 std::unique_ptr<uint8_t[]> result(new uint8_t[size]);
511 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
512 result.get());
513 uint8_t tolerance = dest_format_type.internal_format == GL_RGBA4 ? 20 : 7;
514 for (GLint yy = 0; yy < kHeight; ++yy) {
515 for (GLint xx = 0; xx < kWidth; ++xx) {
516 int offset = yy * kWidth * 4 + xx * 4;
517 for (int jj = 0; jj < 4; ++jj) {
518 uint8_t actual = result[offset + jj];
519 uint8_t expected = expected_color[jj];
520 int diff = actual - expected;
521 diff = diff < 0 ? -diff : diff;
522 if (mask[jj] && diff > tolerance) {
523 EXPECT_EQ(expected, actual)
524 << " at " << xx << ", " << yy << " channel " << jj
525 << " src_internal_format: "
526 << gles2::GLES2Util::GetStringEnum(
527 src_format_type.internal_format)
528 << " dest_internal_format: "
529 << gles2::GLES2Util::GetStringEnum(
530 dest_format_type.internal_format);
531 }
532 }
533 }
534 }
535
536 glDeleteTextures(1, &texture);
537 glDeleteFramebuffers(1, &framebuffer);
538 }
539 }
540 }
541
135 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { 542 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) {
136 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { 543 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) {
137 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; 544 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test...";
138 return; 545 return;
139 } 546 }
140 CopyType copy_type = GetParam(); 547 CopyType copy_type = GetParam();
141 GLenum src_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; 548 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}; 549 GLenum dest_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT};
143 550
144 uint8_t pixels[1 * 4] = {255u, 0u, 255u, 255u}; 551 uint8_t pixels[1 * 4] = {255u, 0u, 255u, 255u};
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 630 }
224 631
225 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) { 632 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) {
226 CopyType copy_type = GetParam(); 633 CopyType copy_type = GetParam();
227 glBindTexture(GL_TEXTURE_2D, textures_[0]); 634 glBindTexture(GL_TEXTURE_2D, textures_[0]);
228 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 635 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
229 nullptr); 636 nullptr);
230 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 637 EXPECT_TRUE(GL_NO_ERROR == glGetError());
231 638
232 // Check unsupported format reports error. 639 // Check unsupported format reports error.
233 GLint unsupported_dest_formats[] = {GL_ALPHA, GL_LUMINANCE, 640 GLint unsupported_dest_formats[] = {GL_RED, GL_RG};
234 GL_LUMINANCE_ALPHA};
235 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats); 641 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats);
236 dest_index++) { 642 dest_index++) {
237 if (copy_type == TexImage) { 643 if (copy_type == TexImage) {
238 glCopyTextureCHROMIUM(textures_[0], textures_[1], 644 glCopyTextureCHROMIUM(textures_[0], textures_[1],
239 unsupported_dest_formats[dest_index], 645 unsupported_dest_formats[dest_index],
240 GL_UNSIGNED_BYTE, false, false, false); 646 GL_UNSIGNED_BYTE, false, false, false);
241 } else { 647 } else {
242 glBindTexture(GL_TEXTURE_2D, textures_[1]); 648 glBindTexture(GL_TEXTURE_2D, textures_[1]);
243 glTexImage2D(GL_TEXTURE_2D, 0, unsupported_dest_formats[dest_index], 1, 1, 649 glTexImage2D(GL_TEXTURE_2D, 0, unsupported_dest_formats[dest_index], 1, 1,
244 0, unsupported_dest_formats[dest_index], GL_UNSIGNED_BYTE, 650 0, unsupported_dest_formats[dest_index], GL_UNSIGNED_BYTE,
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 expected_color = y < copy_region_y + 1 ? blue : white; 1300 expected_color = y < copy_region_y + 1 ? blue : white;
895 } 1301 }
896 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color); 1302 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color);
897 } 1303 }
898 } 1304 }
899 } 1305 }
900 } 1306 }
901 } 1307 }
902 1308
903 } // namespace gpu 1309 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698