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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 | 655 |
656 SkBitmap output_pixels; | 656 SkBitmap output_pixels; |
657 output_pixels.setConfig( | 657 output_pixels.setConfig( |
658 SkBitmap::kARGB_8888_Config, scaled_xsize, scaled_ysize); | 658 SkBitmap::kARGB_8888_Config, scaled_xsize, scaled_ysize); |
659 output_pixels.allocPixels(); | 659 output_pixels.allocPixels(); |
660 SkAutoLockPixels output_lock(output_pixels); | 660 SkAutoLockPixels output_lock(output_pixels); |
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 SkBitmap::kARGB_8888_Config); |
666 if (flip) { | 667 if (flip) { |
667 // Flip the pixels back. | 668 // Flip the pixels back. |
668 FlipSKBitmap(&output_pixels); | 669 FlipSKBitmap(&output_pixels); |
669 } | 670 } |
670 if (xsize == scaled_xsize && ysize == scaled_ysize) { | 671 if (xsize == scaled_xsize && ysize == scaled_ysize) { |
671 Compare(&input_pixels, | 672 Compare(&input_pixels, |
672 &output_pixels, | 673 &output_pixels, |
673 2, | 674 2, |
674 NULL, | 675 NULL, |
675 stages, | 676 stages, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 PrintChannel(source, 1); | 835 PrintChannel(source, 1); |
835 LOG(ERROR) << "-------before yuv conversion: blue-------"; | 836 LOG(ERROR) << "-------before yuv conversion: blue-------"; |
836 PrintChannel(source, 2); | 837 PrintChannel(source, 2); |
837 } | 838 } |
838 return; | 839 return; |
839 } | 840 } |
840 } | 841 } |
841 } | 842 } |
842 } | 843 } |
843 | 844 |
| 845 bool ColorComponentsClose(SkColor component1, |
| 846 SkColor component2, |
| 847 SkBitmap::Config config) { |
| 848 int c1 = static_cast<int>(component1); |
| 849 int c2 = static_cast<int>(component2); |
| 850 bool result = false; |
| 851 switch (config) { |
| 852 case SkBitmap::kARGB_8888_Config: |
| 853 result = (std::abs(c1 - c2) == 0); |
| 854 break; |
| 855 case SkBitmap::kRGB_565_Config: |
| 856 result = (std::abs(c1 - c2) <= 7); |
| 857 break; |
| 858 default: |
| 859 break; |
| 860 } |
| 861 return result; |
| 862 } |
| 863 |
| 864 bool ColorsClose(SkColor color1, SkColor color2, SkBitmap::Config config) { |
| 865 bool red = ColorComponentsClose(SkColorGetR(color1), |
| 866 SkColorGetR(color2), config); |
| 867 bool green = ColorComponentsClose(SkColorGetG(color1), |
| 868 SkColorGetG(color2), config); |
| 869 bool blue = ColorComponentsClose(SkColorGetB(color1), |
| 870 SkColorGetB(color2), config); |
| 871 bool alpha = ColorComponentsClose(SkColorGetA(color1), |
| 872 SkColorGetA(color2), config); |
| 873 if (config == SkBitmap::kRGB_565_Config) { |
| 874 return red && blue && green; |
| 875 } |
| 876 return red && blue && green && alpha; |
| 877 } |
| 878 |
| 879 bool IsEqual(const SkBitmap& bmp1, const SkBitmap& bmp2) { |
| 880 if (bmp1.isNull() && bmp2.isNull()) |
| 881 return true; |
| 882 if (bmp1.width() != bmp2.width() || |
| 883 bmp1.height() != bmp2.height()) { |
| 884 LOG(ERROR) << "Bitmap geometry check failure"; |
| 885 return false; |
| 886 } |
| 887 if (bmp1.getConfig() != bmp2.getConfig()) |
| 888 return false; |
| 889 |
| 890 SkAutoLockPixels lock1(bmp1); |
| 891 SkAutoLockPixels lock2(bmp2); |
| 892 if (!bmp1.getPixels() || !bmp2.getPixels()) { |
| 893 LOG(ERROR) << "Empty Bitmap!"; |
| 894 return false; |
| 895 } |
| 896 for (int y = 0; y < bmp1.height(); ++y) { |
| 897 for (int x = 0; x < bmp1.width(); ++x) { |
| 898 if (!ColorsClose(bmp1.getColor(x,y), |
| 899 bmp2.getColor(x,y), |
| 900 bmp1.getConfig())) { |
| 901 LOG(ERROR) << "Bitmap color comparision failure"; |
| 902 return false; |
| 903 } |
| 904 } |
| 905 } |
| 906 return true; |
| 907 } |
| 908 |
| 909 // Test basic format readback. |
| 910 bool TestTextureFormatReadback(const gfx::Size& src_size, |
| 911 SkBitmap::Config bitmap_config) { |
| 912 DCHECK((bitmap_config == SkBitmap::kRGB_565_Config) || |
| 913 (bitmap_config == SkBitmap::kARGB_8888_Config)); |
| 914 bool rgb565_format = (bitmap_config == SkBitmap::kRGB_565_Config); |
| 915 if (rgb565_format && !helper_->CanUseRgb565Readback()) { |
| 916 LOG(INFO) << "RGB565 Format Not supported on this platform"; |
| 917 LOG(INFO) << "Skipping RGB565ReadBackTest"; |
| 918 return true; |
| 919 } |
| 920 WebGLId src_texture = context_->createTexture(); |
| 921 SkBitmap input_pixels; |
| 922 input_pixels.setConfig(bitmap_config, src_size.width(), |
| 923 src_size.height()); |
| 924 input_pixels.allocPixels(); |
| 925 SkAutoLockPixels lock1(input_pixels); |
| 926 // Erase the input bitmap with red color. |
| 927 input_pixels.eraseColor(SK_ColorRED); |
| 928 context_->bindTexture(GL_TEXTURE_2D, src_texture); |
| 929 GLenum format = (bitmap_config == SkBitmap::kRGB_565_Config) ? |
| 930 GL_RGB : GL_RGBA; |
| 931 GLenum type = (bitmap_config == SkBitmap::kRGB_565_Config) ? |
| 932 GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE; |
| 933 context_->texImage2D(GL_TEXTURE_2D, |
| 934 0, |
| 935 format, |
| 936 src_size.width(), |
| 937 src_size.height(), |
| 938 0, |
| 939 format, |
| 940 type, |
| 941 input_pixels.getPixels()); |
| 942 SkBitmap output_pixels; |
| 943 output_pixels.setConfig(bitmap_config, src_size.width(), |
| 944 src_size.height()); |
| 945 output_pixels.allocPixels(); |
| 946 SkAutoLockPixels lock2(output_pixels); |
| 947 // Initialize the output bitmap with Green color. |
| 948 // When the readback is over output bitmap should have the red color. |
| 949 output_pixels.eraseColor(SK_ColorGREEN); |
| 950 uint8* pixels = static_cast<uint8*>(output_pixels.getPixels()); |
| 951 helper_->ReadbackTextureSync(src_texture, |
| 952 gfx::Rect(src_size), |
| 953 pixels, |
| 954 bitmap_config); |
| 955 bool result = IsEqual(input_pixels, output_pixels); |
| 956 if (!result) { |
| 957 LOG(ERROR) << "Bitmap comparision failure"; |
| 958 return false; |
| 959 } |
| 960 context_->deleteTexture(src_texture); |
| 961 if (HasFailure()) { |
| 962 return false; |
| 963 } |
| 964 return true; |
| 965 } |
| 966 |
844 // YUV readback test. Create a test pattern, convert to YUV | 967 // YUV readback test. Create a test pattern, convert to YUV |
845 // with reference implementation and compare to what gl_helper | 968 // with reference implementation and compare to what gl_helper |
846 // returns. | 969 // returns. |
847 void TestYUVReadback(int xsize, | 970 void TestYUVReadback(int xsize, |
848 int ysize, | 971 int ysize, |
849 int output_xsize, | 972 int output_xsize, |
850 int output_ysize, | 973 int output_ysize, |
851 int xmargin, | 974 int xmargin, |
852 int ymargin, | 975 int ymargin, |
853 int test_pattern, | 976 int test_pattern, |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1209 "8x1 -> 1x1 bilinear4 X\n"); | 1332 "8x1 -> 1x1 bilinear4 X\n"); |
1210 } | 1333 } |
1211 | 1334 |
1212 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context_; | 1335 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context_; |
1213 gpu::ContextSupport* context_support_; | 1336 gpu::ContextSupport* context_support_; |
1214 scoped_ptr<content::GLHelper> helper_; | 1337 scoped_ptr<content::GLHelper> helper_; |
1215 scoped_ptr<content::GLHelperScaling> helper_scaling_; | 1338 scoped_ptr<content::GLHelperScaling> helper_scaling_; |
1216 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; | 1339 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; |
1217 }; | 1340 }; |
1218 | 1341 |
| 1342 TEST_F(GLHelperTest, RGBAReadBackTest) { |
| 1343 const int kTestSize = 64; |
| 1344 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), |
| 1345 SkBitmap::kARGB_8888_Config); |
| 1346 EXPECT_EQ(result, true); |
| 1347 } |
| 1348 |
| 1349 TEST_F(GLHelperTest, RGB565ReadBackTest) { |
| 1350 const int kTestSize = 64; |
| 1351 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), |
| 1352 SkBitmap::kRGB_565_Config); |
| 1353 EXPECT_EQ(result, true); |
| 1354 } |
| 1355 |
1219 TEST_F(GLHelperTest, YUVReadbackOptTest) { | 1356 TEST_F(GLHelperTest, YUVReadbackOptTest) { |
1220 // This test uses the cb_command tracing events to detect how many | 1357 // This test uses the cb_command tracing events to detect how many |
1221 // scaling passes are actually performed by the YUV readback pipeline. | 1358 // scaling passes are actually performed by the YUV readback pipeline. |
1222 StartTracing(TRACE_DISABLED_BY_DEFAULT("cb_command")); | 1359 StartTracing(TRACE_DISABLED_BY_DEFAULT("cb_command")); |
1223 | 1360 |
1224 TestYUVReadback(800, | 1361 TestYUVReadback(800, |
1225 400, | 1362 400, |
1226 800, | 1363 800, |
1227 400, | 1364 400, |
1228 0, | 1365 0, |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 #if defined(TOOLKIT_GTK) | 1541 #if defined(TOOLKIT_GTK) |
1405 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); | 1542 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); |
1406 #endif | 1543 #endif |
1407 gfx::GLSurface::InitializeOneOff(); | 1544 gfx::GLSurface::InitializeOneOff(); |
1408 gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess()); | 1545 gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess()); |
1409 | 1546 |
1410 content::UnitTestTestSuite runner(suite); | 1547 content::UnitTestTestSuite runner(suite); |
1411 base::MessageLoop message_loop; | 1548 base::MessageLoop message_loop; |
1412 return runner.Run(); | 1549 return runner.Run(); |
1413 } | 1550 } |
OLD | NEW |