| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #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 <stdint.h> |
| 12 | 13 |
| 13 #include "gpu/command_buffer/tests/gl_manager.h" | 14 #include "gpu/command_buffer/tests/gl_manager.h" |
| 14 #include "gpu/command_buffer/tests/gl_test_utils.h" | 15 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 #define SHADER(src) #src | 19 #define SHADER(src) #src |
| 19 | 20 |
| 20 namespace gpu { | 21 namespace gpu { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 enum CopyType { TexImage, TexSubImage }; | 25 enum CopyType { TexImage, TexSubImage }; |
| 25 const CopyType kCopyTypes[] = { | 26 const CopyType kCopyTypes[] = { |
| 26 TexImage, | 27 TexImage, |
| 27 TexSubImage, | 28 TexSubImage, |
| 28 }; | 29 }; |
| 29 | 30 |
| 30 const uint8 kCompressedImageColor[4] = { 255u, 0u, 0u, 255u }; | 31 const uint8_t kCompressedImageColor[4] = {255u, 0u, 0u, 255u}; |
| 31 | 32 |
| 32 // Single compressed ATC block of source pixels all set to: | 33 // Single compressed ATC block of source pixels all set to: |
| 33 // kCompressedImageColor. | 34 // kCompressedImageColor. |
| 34 const uint8 kCompressedImageATC[8] = { | 35 const uint8_t kCompressedImageATC[8] = {0x0, 0x7c, 0x0, 0xf8, |
| 35 0x0, 0x7c, 0x0, 0xf8, 0x55, 0x55, 0x55, 0x55 }; | 36 0x55, 0x55, 0x55, 0x55}; |
| 36 | 37 |
| 37 // Single compressed ATCIA block of source pixels all set to: | 38 // Single compressed ATCIA block of source pixels all set to: |
| 38 // kCompressedImageColor. | 39 // kCompressedImageColor. |
| 39 const uint8 kCompressedImageATCIA[16] = { | 40 const uint8_t kCompressedImageATCIA[16] = {0xff, 0xff, 0x0, 0x0, 0x0, 0x0, |
| 40 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | 41 0x0, 0x0, 0x0, 0x7c, 0x0, 0xf8, |
| 41 0x7c, 0x0, 0xf8, 0x55, 0x55, 0x55, 0x55 }; | 42 0x55, 0x55, 0x55, 0x55}; |
| 42 | 43 |
| 43 // Single compressed DXT1 block of source pixels all set to: | 44 // Single compressed DXT1 block of source pixels all set to: |
| 44 // kCompressedImageColor. | 45 // kCompressedImageColor. |
| 45 const uint8 kCompressedImageDXT1[8] = { | 46 const uint8_t kCompressedImageDXT1[8] = {0x00, 0xf8, 0x00, 0xf8, |
| 46 0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa }; | 47 0xaa, 0xaa, 0xaa, 0xaa}; |
| 47 | 48 |
| 48 // Four compressed DXT1 blocks solidly colored in red, green, blue and black: | 49 // Four compressed DXT1 blocks solidly colored in red, green, blue and black: |
| 49 // [R][G] | 50 // [R][G] |
| 50 // [B][b] | 51 // [B][b] |
| 51 const uint8 kCompressedImageDXT1RGB[32] = { | 52 const uint8_t kCompressedImageDXT1RGB[32] = { |
| 52 0x0, 0xf8, 0x0, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa, | 53 0x0, 0xf8, 0x0, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa, 0xe0, 0x7, 0xe0, |
| 53 0xe0, 0x7, 0xe0, 0x7, 0xaa, 0xaa, 0xaa, 0xaa, | 54 0x7, 0xaa, 0xaa, 0xaa, 0xaa, 0x1f, 0x0, 0x1f, 0x0, 0xaa, 0xaa, |
| 54 0x1f, 0x0, 0x1f, 0x0, 0xaa, 0xaa, 0xaa, 0xaa, | 55 0xaa, 0xaa, 0x0, 0x0, 0x0, 0x0, 0xaa, 0xaa, 0xaa, 0xaa}; |
| 55 0x0, 0x0, 0x0, 0x0, 0xaa, 0xaa, 0xaa, 0xaa }; | |
| 56 | 56 |
| 57 // Single compressed DXT5 block of source pixels all set to: | 57 // Single compressed DXT5 block of source pixels all set to: |
| 58 // kCompressedImageColor. | 58 // kCompressedImageColor. |
| 59 const uint8 kCompressedImageDXT5[16] = { | 59 const uint8_t kCompressedImageDXT5[16] = {0xff, 0xff, 0x0, 0x0, 0x0, 0x0, |
| 60 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | 60 0x0, 0x0, 0x0, 0xf8, 0x0, 0xf8, |
| 61 0xf8, 0x0, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa }; | 61 0xaa, 0xaa, 0xaa, 0xaa}; |
| 62 | 62 |
| 63 // Single compressed DXT1 block of source pixels all set to: | 63 // Single compressed DXT1 block of source pixels all set to: |
| 64 // kCompressedImageColor. | 64 // kCompressedImageColor. |
| 65 const uint8 kCompressedImageETC1[8] = { | 65 const uint8_t kCompressedImageETC1[8] = {0x0, 0x0, 0xf8, 0x2, |
| 66 0x0, 0x0, 0xf8, 0x2, 0xff, 0xff, 0x0, 0x0 }; | 66 0xff, 0xff, 0x0, 0x0}; |
| 67 | 67 |
| 68 // Single block of zeroes, used for texture pre-allocation. | 68 // Single block of zeroes, used for texture pre-allocation. |
| 69 const uint8 kInvalidCompressedImage[8] = { | 69 const uint8_t kInvalidCompressedImage[8] = {0x0, 0x0, 0x0, 0x0, |
| 70 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; | 70 0x0, 0x0, 0x0, 0x0}; |
| 71 | 71 |
| 72 // Four blocks of zeroes, used for texture pre-allocation. | 72 // Four blocks of zeroes, used for texture pre-allocation. |
| 73 const uint8 kInvalidCompressedImageLarge[32] = { | 73 const uint8_t kInvalidCompressedImageLarge[32] = { |
| 74 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | 74 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
| 75 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | 75 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
| 76 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | 76 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; |
| 77 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; | |
| 78 | 77 |
| 79 void glEnableDisable(GLint param, GLboolean value) { | 78 void glEnableDisable(GLint param, GLboolean value) { |
| 80 if (value) | 79 if (value) |
| 81 glEnable(param); | 80 glEnable(param); |
| 82 else | 81 else |
| 83 glDisable(param); | 82 glDisable(param); |
| 84 } | 83 } |
| 85 | 84 |
| 86 } // unnamed namespace | 85 } // unnamed namespace |
| 87 | 86 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 | 191 |
| 193 GLTestHelper::CheckPixels(0, 0, 4, 4, 0, kCompressedImageColor); | 192 GLTestHelper::CheckPixels(0, 0, 4, 4, 0, kCompressedImageColor); |
| 194 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 193 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 195 } | 194 } |
| 196 | 195 |
| 197 TEST_P(GLCompressedCopyTextureCHROMIUMTest, InternalFormat) { | 196 TEST_P(GLCompressedCopyTextureCHROMIUMTest, InternalFormat) { |
| 198 CopyType copy_type = GetParam(); | 197 CopyType copy_type = GetParam(); |
| 199 | 198 |
| 200 struct Image { | 199 struct Image { |
| 201 const GLint format; | 200 const GLint format; |
| 202 const uint8* data; | 201 const uint8_t* data; |
| 203 const GLsizei data_size; | 202 const GLsizei data_size; |
| 204 | 203 |
| 205 Image(const GLint format, const uint8* data, const GLsizei data_size) : | 204 Image(const GLint format, const uint8_t* data, const GLsizei data_size) |
| 206 format(format), data(data), data_size(data_size) {} | 205 : format(format), data(data), data_size(data_size) {} |
| 207 }; | 206 }; |
| 208 std::vector<scoped_ptr<Image>> supported_formats; | 207 std::vector<scoped_ptr<Image>> supported_formats; |
| 209 | 208 |
| 210 if ((GLTestHelper::HasExtension("GL_AMD_compressed_ATC_texture") || | 209 if ((GLTestHelper::HasExtension("GL_AMD_compressed_ATC_texture") || |
| 211 GLTestHelper::HasExtension("GL_ATI_texture_compression_atitc")) && | 210 GLTestHelper::HasExtension("GL_ATI_texture_compression_atitc")) && |
| 212 copy_type != TexSubImage) { | 211 copy_type != TexSubImage) { |
| 213 supported_formats.push_back(make_scoped_ptr(new Image( | 212 supported_formats.push_back(make_scoped_ptr(new Image( |
| 214 GL_ATC_RGB_AMD, | 213 GL_ATC_RGB_AMD, |
| 215 kCompressedImageATC, | 214 kCompressedImageATC, |
| 216 sizeof(kCompressedImageATC)))); | 215 sizeof(kCompressedImageATC)))); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 271 |
| 273 TEST_P(GLCompressedCopyTextureCHROMIUMTest, InternalFormatNotSupported) { | 272 TEST_P(GLCompressedCopyTextureCHROMIUMTest, InternalFormatNotSupported) { |
| 274 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { | 273 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) { |
| 275 LOG(INFO) << | 274 LOG(INFO) << |
| 276 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; | 275 "GL_EXT_texture_compression_dxt1 not supported. Skipping test..."; |
| 277 return; | 276 return; |
| 278 } | 277 } |
| 279 | 278 |
| 280 CopyType copy_type = GetParam(); | 279 CopyType copy_type = GetParam(); |
| 281 | 280 |
| 282 const uint8 kUncompressedPixels[1 * 4] = { 255u, 0u, 0u, 255u }; | 281 const uint8_t kUncompressedPixels[1 * 4] = {255u, 0u, 0u, 255u}; |
| 283 | 282 |
| 284 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 283 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 285 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 284 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 286 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 285 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 287 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 286 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 288 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 287 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 289 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 288 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 290 kUncompressedPixels); | 289 kUncompressedPixels); |
| 291 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | 290 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 292 | 291 |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 | 627 |
| 629 // Load geometry. | 628 // Load geometry. |
| 630 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc); | 629 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc); |
| 631 ASSERT_NE(vbo, 0u); | 630 ASSERT_NE(vbo, 0u); |
| 632 | 631 |
| 633 // Load texture. | 632 // Load texture. |
| 634 glActiveTexture(GL_TEXTURE0); | 633 glActiveTexture(GL_TEXTURE0); |
| 635 glBindTexture(GL_TEXTURE_2D, textures_[1]); | 634 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
| 636 glUniform1i(texture_loc, 0); | 635 glUniform1i(texture_loc, 0); |
| 637 | 636 |
| 638 const uint8 kBlack[1 * 4] = {0u, 0u, 0u, 255u}; | 637 const uint8_t kBlack[1 * 4] = {0u, 0u, 0u, 255u}; |
| 639 const uint8 kRed[1 * 4] = {255u, 0u, 0u, 255u}; | 638 const uint8_t kRed[1 * 4] = {255u, 0u, 0u, 255u}; |
| 640 const uint8 kGreen[1 * 4] = {0u, 255u, 0u, 255u}; | 639 const uint8_t kGreen[1 * 4] = {0u, 255u, 0u, 255u}; |
| 641 const uint8 kBlue[1 * 4] = {0u, 0u, 255u, 255u}; | 640 const uint8_t kBlue[1 * 4] = {0u, 0u, 255u, 255u}; |
| 642 | 641 |
| 643 // Copy each block one by one in a clockwise fashion. Note that we reset the | 642 // Copy each block one by one in a clockwise fashion. Note that we reset the |
| 644 // destination texture after each copy operation. That's because on some | 643 // destination texture after each copy operation. That's because on some |
| 645 // platforms we might fallback into replacing the compressed destination | 644 // platforms we might fallback into replacing the compressed destination |
| 646 // texture with an uncompressed one. | 645 // texture with an uncompressed one. |
| 647 | 646 |
| 648 // Move blue block up. | 647 // Move blue block up. |
| 649 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], | 648 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], |
| 650 textures_[1], 0, 0, 0, 4, 4, 4); | 649 textures_[1], 0, 0, 0, 4, 4, 4); |
| 651 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | 650 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 | 749 |
| 751 // Load texture. | 750 // Load texture. |
| 752 glActiveTexture(GL_TEXTURE0); | 751 glActiveTexture(GL_TEXTURE0); |
| 753 glBindTexture(GL_TEXTURE_2D, textures_[1]); | 752 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
| 754 glUniform1i(texture_loc, 0); | 753 glUniform1i(texture_loc, 0); |
| 755 | 754 |
| 756 // Draw. | 755 // Draw. |
| 757 glDrawArrays(GL_TRIANGLES, 0, 6); | 756 glDrawArrays(GL_TRIANGLES, 0, 6); |
| 758 glFlush(); | 757 glFlush(); |
| 759 | 758 |
| 760 const uint8 kBlack[1 * 4] = {0u, 0u, 0u, 255u}; | 759 const uint8_t kBlack[1 * 4] = {0u, 0u, 0u, 255u}; |
| 761 const uint8 kRed[1 * 4] = {255u, 0u, 0u, 255u}; | 760 const uint8_t kRed[1 * 4] = {255u, 0u, 0u, 255u}; |
| 762 const uint8 kBlue[1 * 4] = {0u, 0u, 255u, 255u}; | 761 const uint8_t kBlue[1 * 4] = {0u, 0u, 255u, 255u}; |
| 763 | 762 |
| 764 // Note that while destination texture is 8 x 8 pixels the viewport is only | 763 // Note that while destination texture is 8 x 8 pixels the viewport is only |
| 765 // 4 x 4. | 764 // 4 x 4. |
| 766 GLTestHelper::CheckPixels(0, 0, 4, 2, 0, kRed); | 765 GLTestHelper::CheckPixels(0, 0, 4, 2, 0, kRed); |
| 767 GLTestHelper::CheckPixels(0, 2, 2, 2, 0, kBlue); | 766 GLTestHelper::CheckPixels(0, 2, 2, 2, 0, kBlue); |
| 768 GLTestHelper::CheckPixels(2, 2, 2, 2, 0, kBlack); | 767 GLTestHelper::CheckPixels(2, 2, 2, 2, 0, kBlack); |
| 769 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 768 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 770 } | 769 } |
| 771 | 770 |
| 772 } // namespace gpu | 771 } // namespace gpu |
| OLD | NEW |