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

Side by Side Diff: content/common/gpu/client/gl_helper_unittest.cc

Issue 151203005: Add test code for readback comparision with more image pattens. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 months 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 | « no previous file | 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 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
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 for (int x = 0; x < bmp1.width(); ++x) { 946 for (int x = 0; x < bmp1.width(); ++x) {
898 if (!ColorsClose(bmp1.getColor(x,y), 947 if (!ColorsClose(bmp1.getColor(x,y),
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 }
piman 2014/02/13 20:34:03 nit: add empty line between functions
sivag 2014/02/14 05:48:47 Done.
908 957 void BindAndAttachTextureWithPixels(GLuint src_texture,
909 // Test basic format readback. 958 SkBitmap::Config bitmap_config,
910 bool TestTextureFormatReadback(const gfx::Size& src_size, 959 const gfx::Size& src_size,
911 SkBitmap::Config bitmap_config, 960 const SkBitmap& input_pixels) {
912 bool readback_async) {
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); 961 context_->bindTexture(GL_TEXTURE_2D, src_texture);
930 GLenum format = (bitmap_config == SkBitmap::kRGB_565_Config) ? 962 GLenum format = (bitmap_config == SkBitmap::kRGB_565_Config) ?
931 GL_RGB : GL_RGBA; 963 GL_RGB : GL_RGBA;
932 GLenum type = (bitmap_config == SkBitmap::kRGB_565_Config) ? 964 GLenum type = (bitmap_config == SkBitmap::kRGB_565_Config) ?
933 GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE; 965 GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE;
934 context_->texImage2D(GL_TEXTURE_2D, 966 context_->texImage2D(GL_TEXTURE_2D,
935 0, 967 0,
936 format, 968 format,
937 src_size.width(), 969 src_size.width(),
938 src_size.height(), 970 src_size.height(),
939 0, 971 0,
940 format, 972 format,
941 type, 973 type,
942 input_pixels.getPixels()); 974 input_pixels.getPixels());
943 SkBitmap output_pixels; 975 }
piman 2014/02/13 20:34:03 nit: add empty line between functions
sivag 2014/02/14 05:48:47 Done.
944 output_pixels.setConfig(bitmap_config, src_size.width(), 976 void ReadBackTexture(GLuint src_texture,
945 src_size.height()); 977 const gfx::Size& src_size,
946 output_pixels.allocPixels(); 978 unsigned char* pixels,
947 SkAutoLockPixels lock2(output_pixels); 979 SkBitmap::Config bitmap_config,
948 // Initialize the output bitmap with Green color. 980 bool async) {
949 // When the readback is over output bitmap should have the red color. 981 if (async) {
950 output_pixels.eraseColor(SK_ColorGREEN);
951 uint8* pixels = static_cast<uint8*>(output_pixels.getPixels());
952 if (readback_async) {
953 base::RunLoop run_loop; 982 base::RunLoop run_loop;
954 helper_->ReadbackTextureAsync(src_texture, 983 helper_->ReadbackTextureAsync(src_texture,
955 src_size, 984 src_size,
956 pixels, 985 pixels,
957 bitmap_config, 986 bitmap_config,
958 base::Bind(&callcallback, 987 base::Bind(&callcallback,
959 run_loop.QuitClosure())); 988 run_loop.QuitClosure()));
960 run_loop.Run(); 989 run_loop.Run();
961 } else { 990 } else {
962 helper_->ReadbackTextureSync(src_texture, 991 helper_->ReadbackTextureSync(src_texture,
963 gfx::Rect(src_size), 992 gfx::Rect(src_size),
964 pixels, 993 pixels,
965 bitmap_config); 994 bitmap_config);
966 } 995 }
996 }
piman 2014/02/13 20:34:03 nit: add empty line between functions
sivag 2014/02/14 05:48:47 Done.
997 // Test basic format readback.
998 bool TestTextureFormatReadback(const gfx::Size& src_size,
999 SkBitmap::Config bitmap_config,
1000 bool async) {
1001 DCHECK((bitmap_config == SkBitmap::kRGB_565_Config) ||
1002 (bitmap_config == SkBitmap::kARGB_8888_Config));
1003 bool rgb565_format = (bitmap_config == SkBitmap::kRGB_565_Config);
1004 if (rgb565_format && !helper_->CanUseRgb565Readback()) {
1005 LOG(INFO) << "RGB565 Format Not supported on this platform";
1006 LOG(INFO) << "Skipping RGB565ReadBackTest";
1007 return true;
1008 }
1009 WebGLId src_texture = context_->createTexture();
1010 SkBitmap input_pixels;
1011 input_pixels.setConfig(bitmap_config, src_size.width(),
1012 src_size.height());
1013 input_pixels.allocPixels();
1014 SkAutoLockPixels lock1(input_pixels);
1015 // Test Pattern-1, Fill with Plain color pattern.
1016 // Erase the input bitmap with red color.
1017 input_pixels.eraseColor(SK_ColorRED);
1018 BindAndAttachTextureWithPixels(src_texture,
1019 bitmap_config,
1020 src_size,
1021 input_pixels);
1022 SkBitmap output_pixels;
1023 output_pixels.setConfig(bitmap_config, src_size.width(),
1024 src_size.height());
1025 output_pixels.allocPixels();
1026 SkAutoLockPixels lock2(output_pixels);
1027 // Initialize the output bitmap with Green color.
1028 // When the readback is over output bitmap should have the red color.
1029 output_pixels.eraseColor(SK_ColorGREEN);
1030 uint8* pixels = static_cast<uint8*>(output_pixels.getPixels());
1031 ReadBackTexture(src_texture, src_size, pixels, bitmap_config, async);
967 bool result = IsEqual(input_pixels, output_pixels); 1032 bool result = IsEqual(input_pixels, output_pixels);
968 if (!result) { 1033 if (!result) {
969 LOG(ERROR) << "Bitmap comparision failure"; 1034 LOG(ERROR) << "Bitmap comparision failure Pattern-1";
1035 return false;
1036 }
1037 const int rect_w = 10, rect_h = 4, src_grid_pitch = 10, src_grid_width = 4;
1038 const SkColor color1 = SK_ColorRED, color2 = SK_ColorBLUE;
1039 // Test Pattern-2, Fill with Grid Pattern.
1040 DrawGridToBitmap(src_size.width(), src_size.height(),
1041 color2, color1,
1042 src_grid_pitch, src_grid_width,
1043 input_pixels);
1044 BindAndAttachTextureWithPixels(src_texture,
1045 bitmap_config,
1046 src_size,
1047 input_pixels);
1048 ReadBackTexture(src_texture, src_size, pixels, bitmap_config, async);
1049 result = IsEqual(input_pixels, output_pixels);
1050 if (!result) {
1051 LOG(ERROR) << "Bitmap comparision failure Pattern-2";
1052 return false;
1053 }
1054 // Test Pattern-3, Fill with CheckerBoard Pattern.
1055 DrawCheckerToBitmap(src_size.width(),
1056 src_size.height(),
1057 color1,
1058 color2, rect_w, rect_h, input_pixels);
1059 BindAndAttachTextureWithPixels(src_texture,
1060 bitmap_config,
1061 src_size,
1062 input_pixels);
1063 ReadBackTexture(src_texture, src_size, pixels, bitmap_config, async);
1064 result = IsEqual(input_pixels, output_pixels);
1065 if (!result) {
1066 LOG(ERROR) << "Bitmap comparision failure Pattern-3";
970 return false; 1067 return false;
971 } 1068 }
972 context_->deleteTexture(src_texture); 1069 context_->deleteTexture(src_texture);
973 if (HasFailure()) { 1070 if (HasFailure()) {
974 return false; 1071 return false;
975 } 1072 }
976 return true; 1073 return true;
977 } 1074 }
978 1075
979 // YUV readback test. Create a test pattern, convert to YUV 1076 // YUV readback test. Create a test pattern, convert to YUV
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 #if defined(TOOLKIT_GTK) 1668 #if defined(TOOLKIT_GTK)
1572 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); 1669 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess());
1573 #endif 1670 #endif
1574 gfx::GLSurface::InitializeOneOff(); 1671 gfx::GLSurface::InitializeOneOff();
1575 gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess()); 1672 gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess());
1576 1673
1577 content::UnitTestTestSuite runner(suite); 1674 content::UnitTestTestSuite runner(suite);
1578 base::MessageLoop message_loop; 1675 base::MessageLoop message_loop;
1579 return runner.Run(); 1676 return runner.Run();
1580 } 1677 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698