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 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 PrintChannel(source, 1); | 835 PrintChannel(source, 1); |
836 LOG(ERROR) << "-------before yuv conversion: blue-------"; | 836 LOG(ERROR) << "-------before yuv conversion: blue-------"; |
837 PrintChannel(source, 2); | 837 PrintChannel(source, 2); |
838 } | 838 } |
839 return; | 839 return; |
840 } | 840 } |
841 } | 841 } |
842 } | 842 } |
843 } | 843 } |
844 | 844 |
| 845 void DrawGridToBitmap(int w, int h, |
| 846 SkColor background_color, |
| 847 SkColor grid_color, |
| 848 int grid_pitch, |
| 849 int grid_width, |
| 850 SkBitmap& bmp) { |
| 851 ASSERT_GT(grid_pitch, 0); |
| 852 ASSERT_GT(grid_width, 0); |
| 853 ASSERT_NE(background_color, grid_color); |
| 854 |
| 855 for (int y = 0; y < h; ++y) { |
| 856 bool y_on_grid = ((y % grid_pitch) < grid_width); |
| 857 |
| 858 for (int x = 0; x < w; ++x) { |
| 859 bool on_grid = (y_on_grid || ((x % grid_pitch) < grid_width)); |
| 860 |
| 861 if (bmp.getConfig() == SkBitmap::kARGB_8888_Config) { |
| 862 *bmp.getAddr32(x, y) = (on_grid ? grid_color : background_color); |
| 863 } else if (bmp.getConfig() == SkBitmap::kRGB_565_Config) { |
| 864 *bmp.getAddr16(x, y) = (on_grid ? grid_color : background_color); |
| 865 } |
| 866 } |
| 867 } |
| 868 } |
| 869 |
| 870 void DrawCheckerToBitmap(int w, int h, |
| 871 SkColor color1, SkColor color2, |
| 872 int rect_w, int rect_h, |
| 873 SkBitmap& bmp) { |
| 874 ASSERT_GT(rect_w, 0); |
| 875 ASSERT_GT(rect_h, 0); |
| 876 ASSERT_NE(color1, color2); |
| 877 |
| 878 for (int y = 0; y < h; ++y) { |
| 879 bool y_bit = (((y / rect_h) & 0x1) == 0); |
| 880 |
| 881 for (int x = 0; x < w; ++x) { |
| 882 bool x_bit = (((x / rect_w) & 0x1) == 0); |
| 883 |
| 884 bool use_color2 = (x_bit != y_bit); // xor |
| 885 if (bmp.getConfig() == SkBitmap::kARGB_8888_Config) { |
| 886 *bmp.getAddr32(x, y) = (use_color2 ? color2 : color1); |
| 887 } else if (bmp.getConfig() == SkBitmap::kRGB_565_Config) { |
| 888 *bmp.getAddr16(x, y) = (use_color2 ? color2 : color1); |
| 889 } |
| 890 } |
| 891 } |
| 892 } |
| 893 |
845 bool ColorComponentsClose(SkColor component1, | 894 bool ColorComponentsClose(SkColor component1, |
846 SkColor component2, | 895 SkColor component2, |
847 SkBitmap::Config config) { | 896 SkBitmap::Config config) { |
848 int c1 = static_cast<int>(component1); | 897 int c1 = static_cast<int>(component1); |
849 int c2 = static_cast<int>(component2); | 898 int c2 = static_cast<int>(component2); |
850 bool result = false; | 899 bool result = false; |
851 switch (config) { | 900 switch (config) { |
852 case SkBitmap::kARGB_8888_Config: | 901 case SkBitmap::kARGB_8888_Config: |
853 result = (std::abs(c1 - c2) == 0); | 902 result = (std::abs(c1 - c2) == 0); |
854 break; | 903 break; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 bmp2.getColor(x,y), | 948 bmp2.getColor(x,y), |
900 bmp1.getConfig())) { | 949 bmp1.getConfig())) { |
901 LOG(ERROR) << "Bitmap color comparision failure"; | 950 LOG(ERROR) << "Bitmap color comparision failure"; |
902 return false; | 951 return false; |
903 } | 952 } |
904 } | 953 } |
905 } | 954 } |
906 return true; | 955 return true; |
907 } | 956 } |
908 | 957 |
909 // Test basic format readback. | 958 void BindAndAttachTextureWithPixels(GLuint src_texture, |
910 bool TestTextureFormatReadback(const gfx::Size& src_size, | 959 SkBitmap::Config bitmap_config, |
911 SkBitmap::Config bitmap_config, | 960 const gfx::Size& src_size, |
912 bool readback_async) { | 961 const SkBitmap& input_pixels) { |
913 DCHECK((bitmap_config == SkBitmap::kRGB_565_Config) || | |
914 (bitmap_config == SkBitmap::kARGB_8888_Config)); | |
915 bool rgb565_format = (bitmap_config == SkBitmap::kRGB_565_Config); | |
916 if (rgb565_format && !helper_->CanUseRgb565Readback()) { | |
917 LOG(INFO) << "RGB565 Format Not supported on this platform"; | |
918 LOG(INFO) << "Skipping RGB565ReadBackTest"; | |
919 return true; | |
920 } | |
921 WebGLId src_texture = context_->createTexture(); | |
922 SkBitmap input_pixels; | |
923 input_pixels.setConfig(bitmap_config, src_size.width(), | |
924 src_size.height()); | |
925 input_pixels.allocPixels(); | |
926 SkAutoLockPixels lock1(input_pixels); | |
927 // Erase the input bitmap with red color. | |
928 input_pixels.eraseColor(SK_ColorRED); | |
929 context_->bindTexture(GL_TEXTURE_2D, src_texture); | 962 context_->bindTexture(GL_TEXTURE_2D, src_texture); |
930 GLenum format = (bitmap_config == SkBitmap::kRGB_565_Config) ? | 963 GLenum format = (bitmap_config == SkBitmap::kRGB_565_Config) ? |
931 GL_RGB : GL_RGBA; | 964 GL_RGB : GL_RGBA; |
932 GLenum type = (bitmap_config == SkBitmap::kRGB_565_Config) ? | 965 GLenum type = (bitmap_config == SkBitmap::kRGB_565_Config) ? |
933 GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE; | 966 GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE; |
934 context_->texImage2D(GL_TEXTURE_2D, | 967 context_->texImage2D(GL_TEXTURE_2D, |
935 0, | 968 0, |
936 format, | 969 format, |
937 src_size.width(), | 970 src_size.width(), |
938 src_size.height(), | 971 src_size.height(), |
939 0, | 972 0, |
940 format, | 973 format, |
941 type, | 974 type, |
942 input_pixels.getPixels()); | 975 input_pixels.getPixels()); |
943 SkBitmap output_pixels; | 976 } |
944 output_pixels.setConfig(bitmap_config, src_size.width(), | 977 |
945 src_size.height()); | 978 void ReadBackTexture(GLuint src_texture, |
946 output_pixels.allocPixels(); | 979 const gfx::Size& src_size, |
947 SkAutoLockPixels lock2(output_pixels); | 980 unsigned char* pixels, |
948 // Initialize the output bitmap with Green color. | 981 SkBitmap::Config bitmap_config, |
949 // When the readback is over output bitmap should have the red color. | 982 bool async) { |
950 output_pixels.eraseColor(SK_ColorGREEN); | 983 if (async) { |
951 uint8* pixels = static_cast<uint8*>(output_pixels.getPixels()); | |
952 if (readback_async) { | |
953 base::RunLoop run_loop; | 984 base::RunLoop run_loop; |
954 helper_->ReadbackTextureAsync(src_texture, | 985 helper_->ReadbackTextureAsync(src_texture, |
955 src_size, | 986 src_size, |
956 pixels, | 987 pixels, |
957 bitmap_config, | 988 bitmap_config, |
958 base::Bind(&callcallback, | 989 base::Bind(&callcallback, |
959 run_loop.QuitClosure())); | 990 run_loop.QuitClosure())); |
960 run_loop.Run(); | 991 run_loop.Run(); |
961 } else { | 992 } else { |
962 helper_->ReadbackTextureSync(src_texture, | 993 helper_->ReadbackTextureSync(src_texture, |
963 gfx::Rect(src_size), | 994 gfx::Rect(src_size), |
964 pixels, | 995 pixels, |
965 bitmap_config); | 996 bitmap_config); |
966 } | 997 } |
| 998 } |
| 999 |
| 1000 // Test basic format readback. |
| 1001 bool TestTextureFormatReadback(const gfx::Size& src_size, |
| 1002 SkBitmap::Config bitmap_config, |
| 1003 bool async) { |
| 1004 DCHECK((bitmap_config == SkBitmap::kRGB_565_Config) || |
| 1005 (bitmap_config == SkBitmap::kARGB_8888_Config)); |
| 1006 bool rgb565_format = (bitmap_config == SkBitmap::kRGB_565_Config); |
| 1007 if (rgb565_format && !helper_->CanUseRgb565Readback()) { |
| 1008 LOG(INFO) << "RGB565 Format Not supported on this platform"; |
| 1009 LOG(INFO) << "Skipping RGB565ReadBackTest"; |
| 1010 return true; |
| 1011 } |
| 1012 WebGLId src_texture = context_->createTexture(); |
| 1013 SkBitmap input_pixels; |
| 1014 input_pixels.setConfig(bitmap_config, src_size.width(), |
| 1015 src_size.height()); |
| 1016 input_pixels.allocPixels(); |
| 1017 SkAutoLockPixels lock1(input_pixels); |
| 1018 // Test Pattern-1, Fill with Plain color pattern. |
| 1019 // Erase the input bitmap with red color. |
| 1020 input_pixels.eraseColor(SK_ColorRED); |
| 1021 BindAndAttachTextureWithPixels(src_texture, |
| 1022 bitmap_config, |
| 1023 src_size, |
| 1024 input_pixels); |
| 1025 SkBitmap output_pixels; |
| 1026 output_pixels.setConfig(bitmap_config, src_size.width(), |
| 1027 src_size.height()); |
| 1028 output_pixels.allocPixels(); |
| 1029 SkAutoLockPixels lock2(output_pixels); |
| 1030 // Initialize the output bitmap with Green color. |
| 1031 // When the readback is over output bitmap should have the red color. |
| 1032 output_pixels.eraseColor(SK_ColorGREEN); |
| 1033 uint8* pixels = static_cast<uint8*>(output_pixels.getPixels()); |
| 1034 ReadBackTexture(src_texture, src_size, pixels, bitmap_config, async); |
967 bool result = IsEqual(input_pixels, output_pixels); | 1035 bool result = IsEqual(input_pixels, output_pixels); |
968 if (!result) { | 1036 if (!result) { |
969 LOG(ERROR) << "Bitmap comparision failure"; | 1037 LOG(ERROR) << "Bitmap comparision failure Pattern-1"; |
| 1038 return false; |
| 1039 } |
| 1040 const int rect_w = 10, rect_h = 4, src_grid_pitch = 10, src_grid_width = 4; |
| 1041 const SkColor color1 = SK_ColorRED, color2 = SK_ColorBLUE; |
| 1042 // Test Pattern-2, Fill with Grid Pattern. |
| 1043 DrawGridToBitmap(src_size.width(), src_size.height(), |
| 1044 color2, color1, |
| 1045 src_grid_pitch, src_grid_width, |
| 1046 input_pixels); |
| 1047 BindAndAttachTextureWithPixels(src_texture, |
| 1048 bitmap_config, |
| 1049 src_size, |
| 1050 input_pixels); |
| 1051 ReadBackTexture(src_texture, src_size, pixels, bitmap_config, async); |
| 1052 result = IsEqual(input_pixels, output_pixels); |
| 1053 if (!result) { |
| 1054 LOG(ERROR) << "Bitmap comparision failure Pattern-2"; |
| 1055 return false; |
| 1056 } |
| 1057 // Test Pattern-3, Fill with CheckerBoard Pattern. |
| 1058 DrawCheckerToBitmap(src_size.width(), |
| 1059 src_size.height(), |
| 1060 color1, |
| 1061 color2, rect_w, rect_h, input_pixels); |
| 1062 BindAndAttachTextureWithPixels(src_texture, |
| 1063 bitmap_config, |
| 1064 src_size, |
| 1065 input_pixels); |
| 1066 ReadBackTexture(src_texture, src_size, pixels, bitmap_config, async); |
| 1067 result = IsEqual(input_pixels, output_pixels); |
| 1068 if (!result) { |
| 1069 LOG(ERROR) << "Bitmap comparision failure Pattern-3"; |
970 return false; | 1070 return false; |
971 } | 1071 } |
972 context_->deleteTexture(src_texture); | 1072 context_->deleteTexture(src_texture); |
973 if (HasFailure()) { | 1073 if (HasFailure()) { |
974 return false; | 1074 return false; |
975 } | 1075 } |
976 return true; | 1076 return true; |
977 } | 1077 } |
978 | 1078 |
979 // YUV readback test. Create a test pattern, convert to YUV | 1079 // YUV readback test. Create a test pattern, convert to YUV |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1570 #endif | 1670 #endif |
1571 #if defined(TOOLKIT_GTK) | 1671 #if defined(TOOLKIT_GTK) |
1572 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); | 1672 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); |
1573 #endif | 1673 #endif |
1574 gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess()); | 1674 gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess()); |
1575 | 1675 |
1576 content::UnitTestTestSuite runner(suite); | 1676 content::UnitTestTestSuite runner(suite); |
1577 base::MessageLoop message_loop; | 1677 base::MessageLoop message_loop; |
1578 return runner.Run(); | 1678 return runner.Run(); |
1579 } | 1679 } |
OLD | NEW |