Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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, SkColor component2) { | |
| 846 int c1 = static_cast<int>(component1); | |
| 847 int c2 = static_cast<int>(component2); | |
| 848 return std::abs(c1 - c2) <= 40; | |
|
piman
2014/01/15 21:32:53
nit: 40 is arbitrary. It also seems high...
The ri
sivag
2014/01/16 11:50:59
Done.
| |
| 849 } | |
| 850 | |
| 851 bool ColorsClose(SkColor color1, SkColor color2, SkBitmap::Config config) { | |
| 852 bool red = ColorComponentsClose(SkColorGetR(color1), | |
| 853 SkColorGetR(color2)); | |
| 854 bool green = ColorComponentsClose(SkColorGetG(color1), | |
| 855 SkColorGetG(color2)); | |
| 856 bool blue = ColorComponentsClose(SkColorGetB(color1), | |
| 857 SkColorGetB(color2)); | |
| 858 bool alpha = ColorComponentsClose(SkColorGetB(color1), | |
| 859 SkColorGetB(color2)); | |
|
piman
2014/01/15 21:32:53
SkColorGetA ?
sivag
2014/01/16 11:50:59
Done.
| |
| 860 if (config == SkBitmap::kRGB_565_Config) { | |
| 861 return red && blue && green; | |
|
piman
2014/01/15 21:32:53
nit: You have 2 spaces before 'red'. Remove one.
sivag
2014/01/16 11:50:59
Done.
| |
| 862 } | |
| 863 return red && blue && green && alpha; | |
| 864 } | |
| 865 | |
| 866 bool IsEqual(const SkBitmap& bmp1, const SkBitmap& bmp2) { | |
| 867 if (bmp1.isNull() && bmp2.isNull()) | |
| 868 return true; | |
| 869 if (bmp1.width() != bmp2.width() || | |
| 870 bmp1.height() != bmp2.height()) { | |
| 871 LOG(ERROR) << "Bitmap geometry check failure"; | |
| 872 return false; | |
| 873 } | |
| 874 if (bmp1.getConfig() != bmp2.getConfig()) | |
| 875 return false; | |
| 876 | |
| 877 SkAutoLockPixels lock1(bmp1); | |
| 878 SkAutoLockPixels lock2(bmp2); | |
| 879 if (!bmp1.getPixels() || !bmp2.getPixels()) { | |
| 880 LOG(ERROR) << "Empty Bitmap!"; | |
| 881 return false; | |
| 882 } | |
| 883 for (int y = 0; y < bmp1.height(); ++y) { | |
| 884 for (int x = 0; x < bmp1.width(); ++x) { | |
| 885 if (!ColorsClose(bmp1.getColor(x,y), | |
| 886 bmp2.getColor(x,y), | |
| 887 bmp1.getConfig())) { | |
| 888 LOG(ERROR) << "Bitmap color comparision failure"; | |
| 889 return false; | |
| 890 } | |
| 891 } | |
| 892 } | |
| 893 return true; | |
| 894 } | |
| 895 | |
| 896 // Test basic format readback. | |
| 897 bool TestTextureFormatReadback(const gfx::Size& src_size, | |
| 898 SkBitmap::Config bitmap_config) { | |
| 899 DCHECK((bitmap_config == SkBitmap::kRGB_565_Config) || | |
| 900 (bitmap_config == SkBitmap::kARGB_8888_Config)); | |
| 901 bool rgb565_format = (bitmap_config == SkBitmap::kRGB_565_Config) ? | |
| 902 true : | |
|
piman
2014/01/15 21:32:53
nit: no need for ? true : false. (bitmap_config ==
sivag
2014/01/16 11:50:59
Done.
| |
| 903 false; | |
| 904 if (rgb565_format && !helper_->CanUseRgb565Readback()) { | |
| 905 LOG(ERROR) << "RGB565 Format Not supported on this platform"; | |
| 906 return false; | |
| 907 } | |
| 908 WebGLId src_texture = context_->createTexture(); | |
| 909 SkBitmap input_pixels; | |
| 910 input_pixels.setConfig(bitmap_config, src_size.width(), | |
| 911 src_size.height()); | |
| 912 input_pixels.allocPixels(); | |
| 913 SkAutoLockPixels lock1(input_pixels); | |
| 914 input_pixels.eraseARGB(0, 255, 0, 0); | |
| 915 context_->bindTexture(GL_TEXTURE_2D, src_texture); | |
| 916 GLenum format = (bitmap_config == SkBitmap::kRGB_565_Config) ? | |
| 917 GL_RGB : GL_RGBA; | |
| 918 GLenum type = (bitmap_config == SkBitmap::kRGB_565_Config) ? | |
| 919 GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE; | |
| 920 context_->texImage2D(GL_TEXTURE_2D, | |
| 921 0, | |
| 922 format, | |
| 923 src_size.width(), | |
| 924 src_size.height(), | |
| 925 0, | |
| 926 format, | |
| 927 type, | |
| 928 input_pixels.getPixels()); | |
| 929 SkBitmap output_pixels; | |
| 930 output_pixels.setConfig(bitmap_config, src_size.width(), | |
| 931 src_size.height()); | |
| 932 output_pixels.allocPixels(); | |
| 933 SkAutoLockPixels lock2(output_pixels); | |
| 934 output_pixels.eraseARGB(0, 0, 255, 0); | |
|
piman
2014/01/15 21:32:53
Can you add an explanation for why this doesn't ma
sivag
2014/01/16 11:50:59
Done.
| |
| 935 uint8* pixels = static_cast<uint8*>(output_pixels.getPixels()); | |
| 936 helper_->ReadbackTextureSync(src_texture, | |
| 937 gfx::Rect(src_size), | |
| 938 pixels, | |
| 939 bitmap_config); | |
| 940 bool result = IsEqual(input_pixels, output_pixels); | |
| 941 if (!result) { | |
| 942 LOG(ERROR) << "Bitmap comparision failure"; | |
| 943 return false; | |
| 944 } | |
| 945 context_->deleteTexture(src_texture); | |
| 946 if (HasFailure()) { | |
| 947 return false; | |
| 948 } | |
| 949 return true; | |
| 950 } | |
| 951 | |
| 844 // YUV readback test. Create a test pattern, convert to YUV | 952 // YUV readback test. Create a test pattern, convert to YUV |
| 845 // with reference implementation and compare to what gl_helper | 953 // with reference implementation and compare to what gl_helper |
| 846 // returns. | 954 // returns. |
| 847 void TestYUVReadback(int xsize, | 955 void TestYUVReadback(int xsize, |
| 848 int ysize, | 956 int ysize, |
| 849 int output_xsize, | 957 int output_xsize, |
| 850 int output_ysize, | 958 int output_ysize, |
| 851 int xmargin, | 959 int xmargin, |
| 852 int ymargin, | 960 int ymargin, |
| 853 int test_pattern, | 961 int test_pattern, |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1209 "8x1 -> 1x1 bilinear4 X\n"); | 1317 "8x1 -> 1x1 bilinear4 X\n"); |
| 1210 } | 1318 } |
| 1211 | 1319 |
| 1212 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context_; | 1320 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context_; |
| 1213 gpu::ContextSupport* context_support_; | 1321 gpu::ContextSupport* context_support_; |
| 1214 scoped_ptr<content::GLHelper> helper_; | 1322 scoped_ptr<content::GLHelper> helper_; |
| 1215 scoped_ptr<content::GLHelperScaling> helper_scaling_; | 1323 scoped_ptr<content::GLHelperScaling> helper_scaling_; |
| 1216 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; | 1324 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; |
| 1217 }; | 1325 }; |
| 1218 | 1326 |
| 1327 TEST_F(GLHelperTest, RGBAReadBackTest) { | |
| 1328 const int kTestSize = 64; | |
| 1329 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | |
| 1330 SkBitmap::kARGB_8888_Config); | |
| 1331 EXPECT_EQ(result, true); | |
| 1332 } | |
| 1333 | |
| 1334 TEST_F(GLHelperTest, RGB565ReadBackTest) { | |
| 1335 const int kTestSize = 64; | |
| 1336 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | |
| 1337 SkBitmap::kRGB_565_Config); | |
| 1338 EXPECT_EQ(result, true); | |
| 1339 } | |
| 1340 | |
| 1219 TEST_F(GLHelperTest, YUVReadbackOptTest) { | 1341 TEST_F(GLHelperTest, YUVReadbackOptTest) { |
| 1220 // This test uses the cb_command tracing events to detect how many | 1342 // This test uses the cb_command tracing events to detect how many |
| 1221 // scaling passes are actually performed by the YUV readback pipeline. | 1343 // scaling passes are actually performed by the YUV readback pipeline. |
| 1222 StartTracing(TRACE_DISABLED_BY_DEFAULT("cb_command")); | 1344 StartTracing(TRACE_DISABLED_BY_DEFAULT("cb_command")); |
| 1223 | 1345 |
| 1224 TestYUVReadback(800, | 1346 TestYUVReadback(800, |
| 1225 400, | 1347 400, |
| 1226 800, | 1348 800, |
| 1227 400, | 1349 400, |
| 1228 0, | 1350 0, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1404 #if defined(TOOLKIT_GTK) | 1526 #if defined(TOOLKIT_GTK) |
| 1405 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); | 1527 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); |
| 1406 #endif | 1528 #endif |
| 1407 gfx::GLSurface::InitializeOneOff(); | 1529 gfx::GLSurface::InitializeOneOff(); |
| 1408 gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess()); | 1530 gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess()); |
| 1409 | 1531 |
| 1410 content::UnitTestTestSuite runner(suite); | 1532 content::UnitTestTestSuite runner(suite); |
| 1411 base::MessageLoop message_loop; | 1533 base::MessageLoop message_loop; |
| 1412 return runner.Run(); | 1534 return runner.Run(); |
| 1413 } | 1535 } |
| OLD | NEW |