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> |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 GLenum dest_internal_format, | 159 GLenum dest_internal_format, |
160 uint8_t* color, | 160 uint8_t* color, |
161 uint8_t* expected_color, | 161 uint8_t* expected_color, |
162 uint8_t* mask) { | 162 uint8_t* mask) { |
163 uint8_t adjusted_color[4]; | 163 uint8_t adjusted_color[4]; |
164 switch (src_internal_format) { | 164 switch (src_internal_format) { |
165 case GL_ALPHA: | 165 case GL_ALPHA: |
166 setColor(0, 0, 0, color[0], adjusted_color); | 166 setColor(0, 0, 0, color[0], adjusted_color); |
167 break; | 167 break; |
168 case GL_R8: | 168 case GL_R8: |
169 case GL_R16_EXT: | |
169 setColor(color[0], 0, 0, 255, adjusted_color); | 170 setColor(color[0], 0, 0, 255, adjusted_color); |
170 break; | 171 break; |
171 case GL_LUMINANCE: | 172 case GL_LUMINANCE: |
172 setColor(color[0], color[0], color[0], 255, adjusted_color); | 173 setColor(color[0], color[0], color[0], 255, adjusted_color); |
173 break; | 174 break; |
174 case GL_LUMINANCE_ALPHA: | 175 case GL_LUMINANCE_ALPHA: |
175 setColor(color[0], color[0], color[0], color[1], adjusted_color); | 176 setColor(color[0], color[0], color[0], color[1], adjusted_color); |
176 break; | 177 break; |
177 case GL_RGB: | 178 case GL_RGB: |
178 case GL_RGB8: | 179 case GL_RGB8: |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 // This should be wrong. Skip the alpha channel check and revisit this in | 257 // This should be wrong. Skip the alpha channel check and revisit this in |
257 // future. | 258 // future. |
258 setColor(1, 1, 1, 0, mask); | 259 setColor(1, 1, 1, 0, mask); |
259 break; | 260 break; |
260 default: | 261 default: |
261 NOTREACHED(); | 262 NOTREACHED(); |
262 break; | 263 break; |
263 } | 264 } |
264 } | 265 } |
265 | 266 |
267 std::unique_ptr<uint8_t[]> getTextureDataAndExpectedRGBA( | |
268 FormatType src_format_type, | |
269 FormatType dest_format_type, | |
270 GLsizei width, | |
271 GLsizei height, | |
272 uint8_t* expected_color, | |
273 uint8_t* expected_mask) { | |
274 const int src_channel_count = gles2::GLES2Util::ElementsPerGroup( | |
275 src_format_type.format, src_format_type.type); | |
276 uint8_t color[4] = {1u, 63u, 127u, 255u}; | |
277 getExpectedColor(src_format_type.internal_format, | |
278 dest_format_type.internal_format, color, expected_color, | |
279 expected_mask); | |
280 if (src_format_type.type == GL_UNSIGNED_BYTE) { | |
281 std::unique_ptr<uint8_t[]> pixels( | |
282 new uint8_t[width * height * src_channel_count]); | |
283 for (int i = 0; i < width * height * src_channel_count; | |
284 i += src_channel_count) { | |
285 for (int j = 0; j < src_channel_count; ++j) | |
286 pixels[i + j] = color[j]; | |
287 } | |
288 return pixels; | |
289 } else if (src_format_type.type == GL_UNSIGNED_SHORT) { | |
290 uint16_t color_16bit[4] = {1u << 8, 63u << 8, 127u << 8, 255u << 8}; | |
291 std::unique_ptr<uint8_t[]> data( | |
292 new uint8_t[width * height * src_channel_count * sizeof(uint16_t)]); | |
293 uint16_t* pixels = reinterpret_cast<uint16_t*>(data.get()); | |
294 int16_t flip_sign = -1; | |
295 for (int i = 0; i < width * height * src_channel_count; | |
296 i += src_channel_count) { | |
297 for (int j = 0; j < src_channel_count; ++j) { | |
298 // Introduce an offset to the value to check. Expected value should be | |
299 // the same as without the offset. | |
300 flip_sign *= -1; | |
301 pixels[i + j] = | |
302 color_16bit[j] + flip_sign * (0x7F * (i + j)) / (width * height); | |
303 } | |
304 } | |
305 return data; | |
306 } | |
307 NOTREACHED(); | |
308 return nullptr; | |
309 } | |
310 | |
266 } // namespace | 311 } // namespace |
267 | 312 |
268 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. | 313 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. |
269 class GLCopyTextureCHROMIUMTest | 314 class GLCopyTextureCHROMIUMTest |
270 : public testing::Test, | 315 : public testing::Test, |
271 public ::testing::WithParamInterface<CopyType> { | 316 public ::testing::WithParamInterface<CopyType> { |
272 protected: | 317 protected: |
273 void CreateAndBindDestinationTextureAndFBO(GLenum target) { | 318 void CreateAndBindDestinationTextureAndFBO(GLenum target) { |
274 glGenTextures(2, textures_); | 319 glGenTextures(2, textures_); |
275 glBindTexture(target, textures_[1]); | 320 glBindTexture(target, textures_[1]); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 } | 389 } |
345 } | 390 } |
346 | 391 |
347 void RunCopyTexture(GLenum dest_target, | 392 void RunCopyTexture(GLenum dest_target, |
348 CopyType copy_type, | 393 CopyType copy_type, |
349 FormatType src_format_type, | 394 FormatType src_format_type, |
350 GLint source_level, | 395 GLint source_level, |
351 FormatType dest_format_type, | 396 FormatType dest_format_type, |
352 GLint dest_level, | 397 GLint dest_level, |
353 bool is_es3) { | 398 bool is_es3) { |
354 const int src_channel_count = gles2::GLES2Util::ElementsPerGroup( | |
355 src_format_type.format, src_format_type.type); | |
356 uint8_t color[4] = {1u, 63u, 127u, 255u}; | |
357 std::unique_ptr<uint8_t[]> pixels(new uint8_t[width_ * height_ * 4]); | |
358 for (int i = 0; i < width_ * height_ * src_channel_count; | |
359 i += src_channel_count) | |
360 for (int j = 0; j < src_channel_count; ++j) | |
361 pixels[i + j] = color[j]; | |
362 uint8_t expected_color[4]; | 399 uint8_t expected_color[4]; |
363 uint8_t mask[4]; | 400 uint8_t mask[4]; |
364 getExpectedColor(src_format_type.internal_format, | 401 std::unique_ptr<uint8_t[]> pixels = |
365 dest_format_type.internal_format, color, expected_color, | 402 getTextureDataAndExpectedRGBA(src_format_type, dest_format_type, width_, |
366 mask); | 403 height_, expected_color, mask); |
367 | |
368 GLenum source_target = GL_TEXTURE_2D; | 404 GLenum source_target = GL_TEXTURE_2D; |
369 glGenTextures(2, textures_); | 405 glGenTextures(2, textures_); |
370 glBindTexture(source_target, textures_[0]); | 406 glBindTexture(source_target, textures_[0]); |
371 glTexParameteri(source_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 407 glTexParameteri(source_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
372 glTexParameteri(source_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 408 glTexParameteri(source_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
373 #if defined(OS_MACOSX) | 409 #if defined(OS_MACOSX) |
374 // TODO(qiankun.miao@intel.com): Remove this workaround for Mac OSX, once | 410 // TODO(qiankun.miao@intel.com): Remove this workaround for Mac OSX, once |
375 // integer texture rendering bug is fixed on Mac OSX: crbug.com/679639. | 411 // integer texture rendering bug is fixed on Mac OSX: crbug.com/679639. |
376 glTexImage2D(source_target, 0, src_format_type.internal_format, | 412 glTexImage2D(source_target, 0, src_format_type.internal_format, |
377 width_ << source_level, height_ << source_level, 0, | 413 width_ << source_level, height_ << source_level, 0, |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 return !gl_.decoder() | 556 return !gl_.decoder() |
521 ->GetFeatureInfo() | 557 ->GetFeatureInfo() |
522 ->feature_flags() | 558 ->feature_flags() |
523 .ext_texture_format_bgra8888; | 559 .ext_texture_format_bgra8888; |
524 } | 560 } |
525 | 561 |
526 bool ShouldSkipSRGBEXT() const { | 562 bool ShouldSkipSRGBEXT() const { |
527 DCHECK(!ShouldSkipTest()); | 563 DCHECK(!ShouldSkipTest()); |
528 return !gl_.decoder()->GetFeatureInfo()->feature_flags().ext_srgb; | 564 return !gl_.decoder()->GetFeatureInfo()->feature_flags().ext_srgb; |
529 } | 565 } |
566 | |
567 bool ShouldSkipNorm16() const { | |
568 DCHECK(!ShouldSkipTest()); | |
569 #if (defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX)) && \ | |
570 (defined(ARCH_CPU_X86) || defined(ARCH_CPU_X86_64)) | |
571 // Make sure it's tested on desktop; it is safe to assume that the | |
572 // functionality is supported on desktop. | |
573 return false; | |
hubbe
2017/04/26 18:09:31
Why can't we just always use the feature flag?
May
aleksandar.stojiljkovic
2017/04/26 19:04:50
Done.
| |
574 #else | |
575 return !gl_.decoder()->GetFeatureInfo()->feature_flags().ext_texture_norm16; | |
576 #endif | |
577 } | |
530 }; | 578 }; |
531 | 579 |
532 INSTANTIATE_TEST_CASE_P(CopyType, | 580 INSTANTIATE_TEST_CASE_P(CopyType, |
533 GLCopyTextureCHROMIUMTest, | 581 GLCopyTextureCHROMIUMTest, |
534 ::testing::ValuesIn(kCopyTypes)); | 582 ::testing::ValuesIn(kCopyTypes)); |
535 | 583 |
536 INSTANTIATE_TEST_CASE_P(CopyType, | 584 INSTANTIATE_TEST_CASE_P(CopyType, |
537 GLCopyTextureCHROMIUMES3Test, | 585 GLCopyTextureCHROMIUMES3Test, |
538 ::testing::ValuesIn(kCopyTypes)); | 586 ::testing::ValuesIn(kCopyTypes)); |
539 | 587 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 | 629 |
582 FormatType src_format_types[] = { | 630 FormatType src_format_types[] = { |
583 {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE}, | 631 {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE}, |
584 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, | 632 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, |
585 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}, | 633 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}, |
586 {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}, | 634 {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}, |
587 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, | 635 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, |
588 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, | 636 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, |
589 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, | 637 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, |
590 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, | 638 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, |
639 {GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT}, | |
591 }; | 640 }; |
592 | 641 |
593 FormatType dest_format_types[] = { | 642 FormatType dest_format_types[] = { |
594 // TODO(qiankun.miao@intel.com): ALPHA and LUMINANCE formats have bug on | 643 // TODO(qiankun.miao@intel.com): ALPHA and LUMINANCE formats have bug on |
595 // GL core profile. See crbug.com/577144. Enable these formats after | 644 // GL core profile. See crbug.com/577144. Enable these formats after |
596 // using workaround in gles2_cmd_copy_tex_image.cc. | 645 // using workaround in gles2_cmd_copy_tex_image.cc. |
597 // {GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE}, | 646 // {GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE}, |
598 // {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE}, | 647 // {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE}, |
599 // {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, | 648 // {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, |
600 | 649 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 ShouldSkipBGRA()) { | 692 ShouldSkipBGRA()) { |
644 continue; | 693 continue; |
645 } | 694 } |
646 if (gles2::GLES2Util::IsFloatFormat(dest_format_type.internal_format) && | 695 if (gles2::GLES2Util::IsFloatFormat(dest_format_type.internal_format) && |
647 ShouldSkipFloatFormat()) | 696 ShouldSkipFloatFormat()) |
648 continue; | 697 continue; |
649 if ((dest_format_type.internal_format == GL_SRGB_EXT || | 698 if ((dest_format_type.internal_format == GL_SRGB_EXT || |
650 dest_format_type.internal_format == GL_SRGB_ALPHA_EXT) && | 699 dest_format_type.internal_format == GL_SRGB_ALPHA_EXT) && |
651 ShouldSkipSRGBEXT()) | 700 ShouldSkipSRGBEXT()) |
652 continue; | 701 continue; |
702 if (src_format_type.internal_format == GL_R16_EXT && ShouldSkipNorm16()) | |
703 continue; | |
653 | 704 |
654 RunCopyTexture(GL_TEXTURE_2D, copy_type, src_format_type, 0, | 705 RunCopyTexture(GL_TEXTURE_2D, copy_type, src_format_type, 0, |
655 dest_format_type, 0, true); | 706 dest_format_type, 0, true); |
656 } | 707 } |
657 } | 708 } |
658 } | 709 } |
659 | 710 |
660 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { | 711 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { |
661 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { | 712 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { |
662 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; | 713 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; |
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1612 } | 1663 } |
1613 } | 1664 } |
1614 | 1665 |
1615 glDeleteTextures(2, textures_); | 1666 glDeleteTextures(2, textures_); |
1616 glDeleteFramebuffers(1, &framebuffer_id_); | 1667 glDeleteFramebuffers(1, &framebuffer_id_); |
1617 } | 1668 } |
1618 } | 1669 } |
1619 } | 1670 } |
1620 | 1671 |
1621 } // namespace gpu | 1672 } // namespace gpu |
OLD | NEW |