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); | |
667 if (flip) { | 666 if (flip) { |
668 // Flip the pixels back. | 667 // Flip the pixels back. |
669 FlipSKBitmap(&output_pixels); | 668 FlipSKBitmap(&output_pixels); |
670 } | 669 } |
671 if (xsize == scaled_xsize && ysize == scaled_ysize) { | 670 if (xsize == scaled_xsize && ysize == scaled_ysize) { |
672 Compare(&input_pixels, | 671 Compare(&input_pixels, |
673 &output_pixels, | 672 &output_pixels, |
674 2, | 673 2, |
675 NULL, | 674 NULL, |
676 stages, | 675 stages, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 PrintChannel(source, 1); | 834 PrintChannel(source, 1); |
836 LOG(ERROR) << "-------before yuv conversion: blue-------"; | 835 LOG(ERROR) << "-------before yuv conversion: blue-------"; |
837 PrintChannel(source, 2); | 836 PrintChannel(source, 2); |
838 } | 837 } |
839 return; | 838 return; |
840 } | 839 } |
841 } | 840 } |
842 } | 841 } |
843 } | 842 } |
844 | 843 |
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(ERROR) << "RGB565 Format Not supported on this platform"; | |
917 return false; | |
918 } | |
919 WebGLId src_texture = context_->createTexture(); | |
920 SkBitmap input_pixels; | |
921 input_pixels.setConfig(bitmap_config, src_size.width(), | |
922 src_size.height()); | |
923 input_pixels.allocPixels(); | |
924 SkAutoLockPixels lock1(input_pixels); | |
925 // Erase the input bitmap with red color. | |
926 input_pixels.eraseColor(SK_ColorRED); | |
927 context_->bindTexture(GL_TEXTURE_2D, src_texture); | |
928 GLenum format = (bitmap_config == SkBitmap::kRGB_565_Config) ? | |
929 GL_RGB : GL_RGBA; | |
930 GLenum type = (bitmap_config == SkBitmap::kRGB_565_Config) ? | |
931 GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE; | |
932 context_->texImage2D(GL_TEXTURE_2D, | |
933 0, | |
934 format, | |
935 src_size.width(), | |
936 src_size.height(), | |
937 0, | |
938 format, | |
939 type, | |
940 input_pixels.getPixels()); | |
941 SkBitmap output_pixels; | |
942 output_pixels.setConfig(bitmap_config, src_size.width(), | |
943 src_size.height()); | |
944 output_pixels.allocPixels(); | |
945 SkAutoLockPixels lock2(output_pixels); | |
946 // Initialize the output bitmap with Green color. | |
947 // When the readback is over output bitmap should have the red color. | |
948 output_pixels.eraseColor(SK_ColorGREEN); | |
949 uint8* pixels = static_cast<uint8*>(output_pixels.getPixels()); | |
950 helper_->ReadbackTextureSync(src_texture, | |
951 gfx::Rect(src_size), | |
952 pixels, | |
953 bitmap_config); | |
954 bool result = IsEqual(input_pixels, output_pixels); | |
955 if (!result) { | |
956 LOG(ERROR) << "Bitmap comparision failure"; | |
957 return false; | |
958 } | |
959 context_->deleteTexture(src_texture); | |
960 if (HasFailure()) { | |
961 return false; | |
962 } | |
963 return true; | |
964 } | |
965 | |
966 // YUV readback test. Create a test pattern, convert to YUV | 844 // YUV readback test. Create a test pattern, convert to YUV |
967 // with reference implementation and compare to what gl_helper | 845 // with reference implementation and compare to what gl_helper |
968 // returns. | 846 // returns. |
969 void TestYUVReadback(int xsize, | 847 void TestYUVReadback(int xsize, |
970 int ysize, | 848 int ysize, |
971 int output_xsize, | 849 int output_xsize, |
972 int output_ysize, | 850 int output_ysize, |
973 int xmargin, | 851 int xmargin, |
974 int ymargin, | 852 int ymargin, |
975 int test_pattern, | 853 int test_pattern, |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 "8x1 -> 1x1 bilinear4 X\n"); | 1209 "8x1 -> 1x1 bilinear4 X\n"); |
1332 } | 1210 } |
1333 | 1211 |
1334 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context_; | 1212 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context_; |
1335 gpu::ContextSupport* context_support_; | 1213 gpu::ContextSupport* context_support_; |
1336 scoped_ptr<content::GLHelper> helper_; | 1214 scoped_ptr<content::GLHelper> helper_; |
1337 scoped_ptr<content::GLHelperScaling> helper_scaling_; | 1215 scoped_ptr<content::GLHelperScaling> helper_scaling_; |
1338 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; | 1216 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; |
1339 }; | 1217 }; |
1340 | 1218 |
1341 TEST_F(GLHelperTest, RGBAReadBackTest) { | |
1342 const int kTestSize = 64; | |
1343 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | |
1344 SkBitmap::kARGB_8888_Config); | |
1345 EXPECT_EQ(result, true); | |
1346 } | |
1347 | |
1348 TEST_F(GLHelperTest, RGB565ReadBackTest) { | |
1349 const int kTestSize = 64; | |
1350 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | |
1351 SkBitmap::kRGB_565_Config); | |
1352 EXPECT_EQ(result, true); | |
1353 } | |
1354 | |
1355 TEST_F(GLHelperTest, YUVReadbackOptTest) { | 1219 TEST_F(GLHelperTest, YUVReadbackOptTest) { |
1356 // This test uses the cb_command tracing events to detect how many | 1220 // This test uses the cb_command tracing events to detect how many |
1357 // scaling passes are actually performed by the YUV readback pipeline. | 1221 // scaling passes are actually performed by the YUV readback pipeline. |
1358 StartTracing(TRACE_DISABLED_BY_DEFAULT("cb_command")); | 1222 StartTracing(TRACE_DISABLED_BY_DEFAULT("cb_command")); |
1359 | 1223 |
1360 TestYUVReadback(800, | 1224 TestYUVReadback(800, |
1361 400, | 1225 400, |
1362 800, | 1226 800, |
1363 400, | 1227 400, |
1364 0, | 1228 0, |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1540 #if defined(TOOLKIT_GTK) | 1404 #if defined(TOOLKIT_GTK) |
1541 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); | 1405 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); |
1542 #endif | 1406 #endif |
1543 gfx::GLSurface::InitializeOneOff(); | 1407 gfx::GLSurface::InitializeOneOff(); |
1544 gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess()); | 1408 gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess()); |
1545 | 1409 |
1546 content::UnitTestTestSuite runner(suite); | 1410 content::UnitTestTestSuite runner(suite); |
1547 base::MessageLoop message_loop; | 1411 base::MessageLoop message_loop; |
1548 return runner.Run(); | 1412 return runner.Run(); |
1549 } | 1413 } |
OLD | NEW |