OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <cmath> | 6 #include <cmath> |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include <GLES2/gl2.h> | 10 #include <GLES2/gl2.h> |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 flip, | 656 flip, |
657 kQualities[quality]); | 657 kQualities[quality]); |
658 | 658 |
659 SkBitmap output_pixels; | 659 SkBitmap output_pixels; |
660 output_pixels.allocN32Pixels(scaled_xsize, scaled_ysize); | 660 output_pixels.allocN32Pixels(scaled_xsize, scaled_ysize); |
661 | 661 |
662 helper_->ReadbackTextureSync( | 662 helper_->ReadbackTextureSync( |
663 dst_texture, | 663 dst_texture, |
664 gfx::Rect(0, 0, scaled_xsize, scaled_ysize), | 664 gfx::Rect(0, 0, scaled_xsize, scaled_ysize), |
665 static_cast<unsigned char*>(output_pixels.getPixels()), | 665 static_cast<unsigned char*>(output_pixels.getPixels()), |
666 kN32_SkColorType); | 666 kRGBA_8888_SkColorType); |
667 if (flip) { | 667 if (flip) { |
668 // Flip the pixels back. | 668 // Flip the pixels back. |
669 FlipSKBitmap(&output_pixels); | 669 FlipSKBitmap(&output_pixels); |
670 } | 670 } |
671 if (xsize == scaled_xsize && ysize == scaled_ysize) { | 671 if (xsize == scaled_xsize && ysize == scaled_ysize) { |
672 Compare(&input_pixels, | 672 Compare(&input_pixels, |
673 &output_pixels, | 673 &output_pixels, |
674 2, | 674 2, |
675 NULL, | 675 NULL, |
676 stages, | 676 stages, |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 ASSERT_GT(grid_pitch, 0); | 852 ASSERT_GT(grid_pitch, 0); |
853 ASSERT_GT(grid_width, 0); | 853 ASSERT_GT(grid_width, 0); |
854 ASSERT_NE(background_color, grid_color); | 854 ASSERT_NE(background_color, grid_color); |
855 | 855 |
856 for (int y = 0; y < h; ++y) { | 856 for (int y = 0; y < h; ++y) { |
857 bool y_on_grid = ((y % grid_pitch) < grid_width); | 857 bool y_on_grid = ((y % grid_pitch) < grid_width); |
858 | 858 |
859 for (int x = 0; x < w; ++x) { | 859 for (int x = 0; x < w; ++x) { |
860 bool on_grid = (y_on_grid || ((x % grid_pitch) < grid_width)); | 860 bool on_grid = (y_on_grid || ((x % grid_pitch) < grid_width)); |
861 | 861 |
862 if (bmp.colorType() == kN32_SkColorType) { | 862 if (bmp.colorType() == kRGBA_8888_SkColorType || |
| 863 bmp.colorType() == kBGRA_8888_SkColorType) { |
863 *bmp.getAddr32(x, y) = (on_grid ? grid_color : background_color); | 864 *bmp.getAddr32(x, y) = (on_grid ? grid_color : background_color); |
864 } else if (bmp.colorType() == kRGB_565_SkColorType) { | 865 } else if (bmp.colorType() == kRGB_565_SkColorType) { |
865 *bmp.getAddr16(x, y) = (on_grid ? grid_color : background_color); | 866 *bmp.getAddr16(x, y) = (on_grid ? grid_color : background_color); |
866 } | 867 } |
867 } | 868 } |
868 } | 869 } |
869 } | 870 } |
870 | 871 |
871 void DrawCheckerToBitmap(int w, int h, | 872 void DrawCheckerToBitmap(int w, int h, |
872 SkColor color1, SkColor color2, | 873 SkColor color1, SkColor color2, |
873 int rect_w, int rect_h, | 874 int rect_w, int rect_h, |
874 SkBitmap& bmp) { | 875 SkBitmap& bmp) { |
875 ASSERT_GT(rect_w, 0); | 876 ASSERT_GT(rect_w, 0); |
876 ASSERT_GT(rect_h, 0); | 877 ASSERT_GT(rect_h, 0); |
877 ASSERT_NE(color1, color2); | 878 ASSERT_NE(color1, color2); |
878 | 879 |
879 for (int y = 0; y < h; ++y) { | 880 for (int y = 0; y < h; ++y) { |
880 bool y_bit = (((y / rect_h) & 0x1) == 0); | 881 bool y_bit = (((y / rect_h) & 0x1) == 0); |
881 | 882 |
882 for (int x = 0; x < w; ++x) { | 883 for (int x = 0; x < w; ++x) { |
883 bool x_bit = (((x / rect_w) & 0x1) == 0); | 884 bool x_bit = (((x / rect_w) & 0x1) == 0); |
884 | 885 |
885 bool use_color2 = (x_bit != y_bit); // xor | 886 bool use_color2 = (x_bit != y_bit); // xor |
886 if (bmp.colorType() == kN32_SkColorType) { | 887 if (bmp.colorType() == kRGBA_8888_SkColorType || |
| 888 bmp.colorType() == kBGRA_8888_SkColorType) { |
887 *bmp.getAddr32(x, y) = (use_color2 ? color2 : color1); | 889 *bmp.getAddr32(x, y) = (use_color2 ? color2 : color1); |
888 } else if (bmp.colorType() == kRGB_565_SkColorType) { | 890 } else if (bmp.colorType() == kRGB_565_SkColorType) { |
889 *bmp.getAddr16(x, y) = (use_color2 ? color2 : color1); | 891 *bmp.getAddr16(x, y) = (use_color2 ? color2 : color1); |
890 } | 892 } |
891 } | 893 } |
892 } | 894 } |
893 } | 895 } |
894 | 896 |
895 bool ColorComponentsClose(SkColor component1, | 897 bool ColorComponentsClose(SkColor component1, |
896 SkColor component2, | 898 SkColor component2, |
897 SkColorType color_type) { | 899 SkColorType color_type) { |
898 int c1 = static_cast<int>(component1); | 900 int c1 = static_cast<int>(component1); |
899 int c2 = static_cast<int>(component2); | 901 int c2 = static_cast<int>(component2); |
900 bool result = false; | 902 bool result = false; |
901 switch (color_type) { | 903 switch (color_type) { |
902 case kN32_SkColorType: | 904 case kRGBA_8888_SkColorType: |
| 905 case kBGRA_8888_SkColorType: |
903 result = (std::abs(c1 - c2) == 0); | 906 result = (std::abs(c1 - c2) == 0); |
904 break; | 907 break; |
905 case kRGB_565_SkColorType: | 908 case kRGB_565_SkColorType: |
906 result = (std::abs(c1 - c2) <= 7); | 909 result = (std::abs(c1 - c2) <= 7); |
907 break; | 910 break; |
908 default: | 911 default: |
909 break; | 912 break; |
910 } | 913 } |
911 return result; | 914 return result; |
912 } | 915 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 } | 957 } |
955 } | 958 } |
956 return true; | 959 return true; |
957 } | 960 } |
958 | 961 |
959 void BindAndAttachTextureWithPixels(GLuint src_texture, | 962 void BindAndAttachTextureWithPixels(GLuint src_texture, |
960 SkColorType color_type, | 963 SkColorType color_type, |
961 const gfx::Size& src_size, | 964 const gfx::Size& src_size, |
962 const SkBitmap& input_pixels) { | 965 const SkBitmap& input_pixels) { |
963 context_->bindTexture(GL_TEXTURE_2D, src_texture); | 966 context_->bindTexture(GL_TEXTURE_2D, src_texture); |
964 GLenum format = (color_type == kRGB_565_SkColorType) ? | 967 GLenum format = 0; |
965 GL_RGB : GL_RGBA; | 968 switch (color_type) { |
| 969 case kBGRA_8888_SkColorType: |
| 970 format = GL_BGRA_EXT; |
| 971 break; |
| 972 case kRGBA_8888_SkColorType: |
| 973 format = GL_RGBA; |
| 974 break; |
| 975 case kRGB_565_SkColorType: |
| 976 format = GL_RGB; |
| 977 break; |
| 978 default: |
| 979 NOTREACHED(); |
| 980 } |
966 GLenum type = (color_type == kRGB_565_SkColorType) ? | 981 GLenum type = (color_type == kRGB_565_SkColorType) ? |
967 GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE; | 982 GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE; |
968 context_->texImage2D(GL_TEXTURE_2D, | 983 context_->texImage2D(GL_TEXTURE_2D, |
969 0, | 984 0, |
970 format, | 985 format, |
971 src_size.width(), | 986 src_size.width(), |
972 src_size.height(), | 987 src_size.height(), |
973 0, | 988 0, |
974 format, | 989 format, |
975 type, | 990 type, |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1446 scoped_ptr<content::GLHelper> helper_; | 1461 scoped_ptr<content::GLHelper> helper_; |
1447 scoped_ptr<content::GLHelperScaling> helper_scaling_; | 1462 scoped_ptr<content::GLHelperScaling> helper_scaling_; |
1448 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; | 1463 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; |
1449 }; | 1464 }; |
1450 | 1465 |
1451 class GLHelperPixelTest : public GLHelperTest { | 1466 class GLHelperPixelTest : public GLHelperTest { |
1452 private: | 1467 private: |
1453 gfx::DisableNullDrawGLBindings enable_pixel_output_; | 1468 gfx::DisableNullDrawGLBindings enable_pixel_output_; |
1454 }; | 1469 }; |
1455 | 1470 |
1456 TEST_F(GLHelperTest, ARGBSyncReadbackTest) { | 1471 TEST_F(GLHelperTest, RGBASyncReadbackTest) { |
1457 const int kTestSize = 64; | 1472 const int kTestSize = 64; |
1458 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | 1473 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), |
1459 kN32_SkColorType, | 1474 kRGBA_8888_SkColorType, |
1460 false); | 1475 false); |
1461 EXPECT_EQ(result, true); | 1476 EXPECT_EQ(result, true); |
1462 } | 1477 } |
| 1478 |
| 1479 |
| 1480 TEST_F(GLHelperTest, BGRASyncReadbackTest) { |
| 1481 const int kTestSize = 64; |
| 1482 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), |
| 1483 kBGRA_8888_SkColorType, |
| 1484 false); |
| 1485 EXPECT_EQ(result, true); |
| 1486 } |
1463 | 1487 |
1464 TEST_F(GLHelperTest, RGB565SyncReadbackTest) { | 1488 TEST_F(GLHelperTest, RGB565SyncReadbackTest) { |
1465 const int kTestSize = 64; | 1489 const int kTestSize = 64; |
1466 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | 1490 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), |
1467 kRGB_565_SkColorType, | 1491 kRGB_565_SkColorType, |
1468 false); | 1492 false); |
1469 EXPECT_EQ(result, true); | 1493 EXPECT_EQ(result, true); |
1470 } | 1494 } |
1471 | 1495 |
1472 TEST_F(GLHelperTest, ARGBASyncReadbackTest) { | 1496 TEST_F(GLHelperTest, RGBAASyncReadbackTest) { |
1473 const int kTestSize = 64; | 1497 const int kTestSize = 64; |
1474 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | 1498 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), |
1475 kN32_SkColorType, | 1499 kRGBA_8888_SkColorType, |
1476 true); | 1500 true); |
1477 EXPECT_EQ(result, true); | 1501 EXPECT_EQ(result, true); |
1478 } | 1502 } |
| 1503 |
| 1504 TEST_F(GLHelperTest, BGRAASyncReadbackTest) { |
| 1505 const int kTestSize = 64; |
| 1506 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), |
| 1507 kBGRA_8888_SkColorType, |
| 1508 true); |
| 1509 EXPECT_EQ(result, true); |
| 1510 } |
1479 | 1511 |
1480 TEST_F(GLHelperTest, RGB565ASyncReadbackTest) { | 1512 TEST_F(GLHelperTest, RGB565ASyncReadbackTest) { |
1481 const int kTestSize = 64; | 1513 const int kTestSize = 64; |
1482 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | 1514 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), |
1483 kRGB_565_SkColorType, | 1515 kRGB_565_SkColorType, |
1484 true); | 1516 true); |
1485 EXPECT_EQ(result, true); | 1517 EXPECT_EQ(result, true); |
1486 } | 1518 } |
1487 | 1519 |
1488 TEST_F(GLHelperPixelTest, YUVReadbackOptTest) { | 1520 TEST_F(GLHelperPixelTest, YUVReadbackOptTest) { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1668 CommandLine::Init(argc, argv); | 1700 CommandLine::Init(argc, argv); |
1669 base::TestSuite* suite = new content::ContentTestSuite(argc, argv); | 1701 base::TestSuite* suite = new content::ContentTestSuite(argc, argv); |
1670 #if defined(OS_MACOSX) | 1702 #if defined(OS_MACOSX) |
1671 base::mac::ScopedNSAutoreleasePool pool; | 1703 base::mac::ScopedNSAutoreleasePool pool; |
1672 #endif | 1704 #endif |
1673 | 1705 |
1674 content::UnitTestTestSuite runner(suite); | 1706 content::UnitTestTestSuite runner(suite); |
1675 base::MessageLoop message_loop; | 1707 base::MessageLoop message_loop; |
1676 return runner.Run(); | 1708 return runner.Run(); |
1677 } | 1709 } |
OLD | NEW |