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

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: fix-opengl-lessthan-32 Created 4 years 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
« no previous file with comments | « gpu/command_buffer/service/texture_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 adjusted_color[4];
84 switch (src_internal_format) {
85 case GL_ALPHA:
86 setColor(0, 0, 0, color[0], adjusted_color);
87 break;
88 case GL_R8:
89 setColor(color[0], 0, 0, 255, adjusted_color);
90 break;
91 case GL_LUMINANCE:
92 setColor(color[0], color[0], color[0], 255, adjusted_color);
93 break;
94 case GL_LUMINANCE_ALPHA:
95 setColor(color[0], color[0], color[0], color[1], adjusted_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, adjusted_color);
102 break;
103 case GL_RGBA:
104 case GL_RGBA8:
105 setColor(color[0], color[1], color[2], color[3], adjusted_color);
106 break;
107 case GL_BGRA_EXT:
108 case GL_BGRA8_EXT:
109 setColor(color[2], color[1], color[0], color[3], adjusted_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, adjusted_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(adjusted_color[0], 0, 0, 0, expected_color);
126 setColor(1, 0, 0, 0, mask);
127 break;
128 case GL_LUMINANCE:
129 setColor(adjusted_color[0], 0, 0, 0, expected_color);
130 setColor(1, 0, 0, 0, mask);
131 break;
132 case GL_LUMINANCE_ALPHA:
133 setColor(adjusted_color[0], 0, 0, adjusted_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(adjusted_color[0], adjusted_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(adjusted_color[0], adjusted_color[1], adjusted_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(adjusted_color[0], adjusted_color[1], adjusted_color[2],
168 adjusted_color[3], expected_color);
169 setColor(1, 1, 1, 1, mask);
170 break;
171 case GL_RGB5_A1:
172 setColor(adjusted_color[0], adjusted_color[1], adjusted_color[2],
173 (adjusted_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
262 void TearDown() override { gl_.Destroy(); }
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 underlying context is ES.
271 // TODO(qiankun.miao@intel.com): we should support RGB9_E5 in ES context.
272 // Maybe, we can add a readback path for RGB9_E5 format in ES context.
273 bool ShouldSkipRGB9_E5() const {
274 DCHECK(!ShouldSkipTest());
275 const gl::GLVersionInfo& gl_version_info =
276 gl_.decoder()->GetFeatureInfo()->gl_version_info();
277 return gl_version_info.is_es;
278 }
279
280 // If EXT_color_buffer_float isn't available, float format isn't supported.
281 bool ShouldSkipFloatFormat() const {
282 DCHECK(!ShouldSkipTest());
283 return !gl_.decoder()->GetFeatureInfo()->ext_color_buffer_float_available();
284 }
285
286 bool ShouldSkipBGRA() const {
287 DCHECK(!ShouldSkipTest());
288 return !gl_.decoder()
289 ->GetFeatureInfo()
290 ->feature_flags()
291 .ext_texture_format_bgra8888;
292 }
293
294 bool ShouldSkipSRGBEXT() const {
295 DCHECK(!ShouldSkipTest());
296 return !gl_.decoder()->GetFeatureInfo()->feature_flags().ext_srgb;
297 }
298 };
299
95 INSTANTIATE_TEST_CASE_P(CopyType, 300 INSTANTIATE_TEST_CASE_P(CopyType,
96 GLCopyTextureCHROMIUMTest, 301 GLCopyTextureCHROMIUMTest,
97 ::testing::ValuesIn(kCopyTypes)); 302 ::testing::ValuesIn(kCopyTypes));
98 303
304 INSTANTIATE_TEST_CASE_P(CopyType,
305 GLCopyTextureCHROMIUMES3Test,
306 ::testing::ValuesIn(kCopyTypes));
307
99 // Test to ensure that the basic functionality of the extension works. 308 // Test to ensure that the basic functionality of the extension works.
100 TEST_P(GLCopyTextureCHROMIUMTest, Basic) { 309 TEST_P(GLCopyTextureCHROMIUMTest, Basic) {
101 CopyType copy_type = GetParam(); 310 CopyType copy_type = GetParam();
102 uint8_t pixels[1 * 4] = {255u, 0u, 0u, 255u}; 311 uint8_t pixels[1 * 4] = {255u, 0u, 0u, 255u};
103 312
104 glBindTexture(GL_TEXTURE_2D, textures_[0]); 313 glBindTexture(GL_TEXTURE_2D, textures_[0]);
105 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 314 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
106 pixels); 315 pixels);
107 316
108 if (copy_type == TexImage) { 317 if (copy_type == TexImage) {
(...skipping 16 matching lines...) Expand all
125 EXPECT_EQ(framebuffer_id_, fb_id); 334 EXPECT_EQ(framebuffer_id_, fb_id);
126 335
127 // Check that FB is complete. 336 // Check that FB is complete.
128 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), 337 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
129 glCheckFramebufferStatus(GL_FRAMEBUFFER)); 338 glCheckFramebufferStatus(GL_FRAMEBUFFER));
130 339
131 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); 340 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels);
132 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 341 EXPECT_TRUE(GL_NO_ERROR == glGetError());
133 } 342 }
134 343
344 TEST_P(GLCopyTextureCHROMIUMES3Test, FormatCombinations) {
345 if (ShouldSkipTest())
346 return;
347 CopyType copy_type = GetParam();
348
349 struct FormatType {
350 GLenum internal_format;
351 GLenum format;
352 GLenum type;
353 };
354
355 FormatType src_format_types[] = {
356 {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE},
357 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE},
358 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE},
359 {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE},
360 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE},
361 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE},
362 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE},
363 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE},
364 };
365
366 FormatType dest_format_types[] = {
367 // TODO(qiankun.miao@intel.com): ALPHA and LUMINANCE formats have bug on
368 // GL core profile. See crbug.com/577144. Enable these formats after
369 // using workaround in gles2_cmd_copy_tex_image.cc.
370 // {GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE},
371 // {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE},
372 // {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE},
373
374 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE},
375 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE},
376 {GL_SRGB_EXT, GL_SRGB_EXT, GL_UNSIGNED_BYTE},
377 {GL_SRGB_ALPHA_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE},
378 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE},
379 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE},
380 {GL_R8, GL_RED, GL_UNSIGNED_BYTE},
381 {GL_R16F, GL_RED, GL_HALF_FLOAT},
382 {GL_R16F, GL_RED, GL_FLOAT},
383 {GL_R32F, GL_RED, GL_FLOAT},
384 {GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE},
385 {GL_RG8, GL_RG, GL_UNSIGNED_BYTE},
386 {GL_RG16F, GL_RG, GL_HALF_FLOAT},
387 {GL_RG16F, GL_RG, GL_FLOAT},
388 {GL_RG32F, GL_RG, GL_FLOAT},
389 {GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE},
390 {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE},
391 {GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE},
392 {GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE},
393 {GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT},
394 {GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT},
395 {GL_RGB9_E5, GL_RGB, GL_FLOAT},
396 {GL_RGB16F, GL_RGB, GL_HALF_FLOAT},
397 {GL_RGB16F, GL_RGB, GL_FLOAT},
398 {GL_RGB32F, GL_RGB, GL_FLOAT},
399 {GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE},
400 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE},
401 {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE},
402 {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE},
403 {GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE},
404 {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT},
405 {GL_RGBA16F, GL_RGBA, GL_FLOAT},
406 {GL_RGBA32F, GL_RGBA, GL_FLOAT},
407 {GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE},
408 };
409
410 for (auto src_format_type : src_format_types) {
411 for (auto dest_format_type : dest_format_types) {
412 if (dest_format_type.internal_format == GL_RGB9_E5 && ShouldSkipRGB9_E5())
413 continue;
414 if ((src_format_type.internal_format == GL_BGRA_EXT ||
415 src_format_type.internal_format == GL_BGRA8_EXT ||
416 dest_format_type.internal_format == GL_BGRA_EXT ||
417 dest_format_type.internal_format == GL_BGRA8_EXT) &&
418 ShouldSkipBGRA()) {
419 continue;
420 }
421 if (gles2::GLES2Util::IsFloatFormat(dest_format_type.internal_format) &&
422 ShouldSkipFloatFormat())
423 continue;
424 if ((dest_format_type.internal_format == GL_SRGB_EXT ||
425 dest_format_type.internal_format == GL_SRGB_ALPHA_EXT) &&
426 ShouldSkipSRGBEXT())
427 continue;
428
429 const GLsizei kWidth = 8, kHeight = 8;
430 const int src_channel_count = gles2::GLES2Util::ElementsPerGroup(
431 src_format_type.format, src_format_type.type);
432 uint8_t color[4] = {1, 63, 127, 255};
433 uint8_t pixels[8 * 8 * 4];
434 for (int i = 0; i < kWidth * kHeight * src_channel_count;
435 i += src_channel_count)
436 for (int j = 0; j < src_channel_count; ++j)
437 pixels[i + j] = color[j];
438 uint8_t expected_color[4];
439 uint8_t mask[4];
440 getExpectedColor(src_format_type.internal_format,
441 dest_format_type.internal_format, color, expected_color,
442 mask);
443
444 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D);
445 glBindTexture(GL_TEXTURE_2D, textures_[0]);
446 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
447 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
448 glTexImage2D(GL_TEXTURE_2D, 0, src_format_type.internal_format, kWidth,
449 kHeight, 0, src_format_type.format, src_format_type.type,
450 pixels);
451
452 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
453 if (copy_type == TexImage) {
454 glCopyTextureCHROMIUM(textures_[0], textures_[1],
455 dest_format_type.internal_format,
456 dest_format_type.type, false, false, false);
457 } else {
458 glBindTexture(GL_TEXTURE_2D, textures_[1]);
459 glTexImage2D(GL_TEXTURE_2D, 0, dest_format_type.internal_format, kWidth,
460 kHeight, 0, dest_format_type.format, dest_format_type.type,
461 nullptr);
462
463 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0, 0, kWidth,
464 kHeight, false, false, false);
465 }
466 EXPECT_TRUE(glGetError() == GL_NO_ERROR)
467 << " src_internal_format: "
468 << gles2::GLES2Util::GetStringEnum(src_format_type.internal_format)
469 << " dest_internal_format: "
470 << gles2::GLES2Util::GetStringEnum(dest_format_type.internal_format);
471
472 // Draw destination texture to a fbo with attachment in RGBA format.
473 glBindFramebuffer(GL_FRAMEBUFFER, 0);
474 GLuint framebuffer = 0;
475 glGenFramebuffers(1, &framebuffer);
476 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
477 GLuint texture = 0;
478 glGenTextures(1, &texture);
479 glBindTexture(GL_TEXTURE_2D, texture);
480 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
481 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
482 CreateBackingForTexture(GL_TEXTURE_2D, kWidth, kHeight);
483 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
484 GL_TEXTURE_2D, texture, 0);
485 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
486 glCheckFramebufferStatus(GL_FRAMEBUFFER));
487 glViewport(0, 0, kWidth, kHeight);
488
489 std::string fragment_shader_source =
490 GetFragmentShaderSource(dest_format_type.internal_format);
491 GLuint program = GLTestHelper::LoadProgram(
492 kSimpleVertexShaderES3, fragment_shader_source.c_str());
493 EXPECT_NE(program, 0u);
494 GLint position_loc = glGetAttribLocation(program, "a_position");
495 GLint texture_loc = glGetUniformLocation(program, "u_texture");
496 ASSERT_NE(position_loc, -1);
497 ASSERT_NE(texture_loc, -1);
498 glUseProgram(program);
499
500 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc);
501 ASSERT_NE(vbo, 0u);
502
503 glActiveTexture(GL_TEXTURE0);
504 glBindTexture(GL_TEXTURE_2D, textures_[1]);
505
506 glDrawArrays(GL_TRIANGLES, 0, 6);
507
508 EXPECT_TRUE(GL_NO_ERROR == glGetError());
509
510 GLsizei size = kWidth * kHeight * 4;
511 std::unique_ptr<uint8_t[]> result(new uint8_t[size]);
512 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
513 result.get());
514 uint8_t tolerance = dest_format_type.internal_format == GL_RGBA4 ? 20 : 7;
515 for (GLint yy = 0; yy < kHeight; ++yy) {
516 for (GLint xx = 0; xx < kWidth; ++xx) {
517 int offset = yy * kWidth * 4 + xx * 4;
518 for (int jj = 0; jj < 4; ++jj) {
519 uint8_t actual = result[offset + jj];
520 uint8_t expected = expected_color[jj];
521 int diff = actual - expected;
522 diff = diff < 0 ? -diff : diff;
523 if (mask[jj] && diff > tolerance) {
524 EXPECT_EQ(expected, actual)
525 << " at " << xx << ", " << yy << " channel " << jj
526 << " src_internal_format: "
527 << gles2::GLES2Util::GetStringEnum(
528 src_format_type.internal_format)
529 << " dest_internal_format: "
530 << gles2::GLES2Util::GetStringEnum(
531 dest_format_type.internal_format);
532 }
533 }
534 }
535 }
536
537 glDeleteTextures(1, &texture);
538 glDeleteFramebuffers(1, &framebuffer);
539 glDeleteTextures(2, textures_);
540 glDeleteFramebuffers(1, &framebuffer_id_);
541 }
542 }
543 }
544
135 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { 545 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) {
136 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { 546 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) {
137 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; 547 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test...";
138 return; 548 return;
139 } 549 }
140 CopyType copy_type = GetParam(); 550 CopyType copy_type = GetParam();
141 GLenum src_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; 551 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}; 552 GLenum dest_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT};
143 553
144 uint8_t pixels[1 * 4] = {255u, 0u, 255u, 255u}; 554 uint8_t pixels[1 * 4] = {255u, 0u, 255u, 255u};
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 633 }
224 634
225 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) { 635 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) {
226 CopyType copy_type = GetParam(); 636 CopyType copy_type = GetParam();
227 glBindTexture(GL_TEXTURE_2D, textures_[0]); 637 glBindTexture(GL_TEXTURE_2D, textures_[0]);
228 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 638 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
229 nullptr); 639 nullptr);
230 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 640 EXPECT_TRUE(GL_NO_ERROR == glGetError());
231 641
232 // Check unsupported format reports error. 642 // Check unsupported format reports error.
233 GLint unsupported_dest_formats[] = {GL_ALPHA, GL_LUMINANCE, 643 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); 644 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats);
236 dest_index++) { 645 dest_index++) {
237 if (copy_type == TexImage) { 646 if (copy_type == TexImage) {
238 glCopyTextureCHROMIUM(textures_[0], textures_[1], 647 glCopyTextureCHROMIUM(textures_[0], textures_[1],
239 unsupported_dest_formats[dest_index], 648 unsupported_dest_formats[dest_index],
240 GL_UNSIGNED_BYTE, false, false, false); 649 GL_UNSIGNED_BYTE, false, false, false);
241 } else { 650 } else {
242 glBindTexture(GL_TEXTURE_2D, textures_[1]); 651 glBindTexture(GL_TEXTURE_2D, textures_[1]);
243 glTexImage2D(GL_TEXTURE_2D, 0, unsupported_dest_formats[dest_index], 1, 1, 652 glTexImage2D(GL_TEXTURE_2D, 0, unsupported_dest_formats[dest_index], 1, 1,
244 0, unsupported_dest_formats[dest_index], GL_UNSIGNED_BYTE, 653 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; 1303 expected_color = y < copy_region_y + 1 ? blue : white;
895 } 1304 }
896 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color); 1305 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color);
897 } 1306 }
898 } 1307 }
899 } 1308 }
900 } 1309 }
901 } 1310 }
902 1311
903 } // namespace gpu 1312 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/texture_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698