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 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 LOG(ERROR) << "Bitmap color comparision failure"; | 901 LOG(ERROR) << "Bitmap color comparision failure"; |
902 return false; | 902 return false; |
903 } | 903 } |
904 } | 904 } |
905 } | 905 } |
906 return true; | 906 return true; |
907 } | 907 } |
908 | 908 |
909 // Test basic format readback. | 909 // Test basic format readback. |
910 bool TestTextureFormatReadback(const gfx::Size& src_size, | 910 bool TestTextureFormatReadback(const gfx::Size& src_size, |
911 SkBitmap::Config bitmap_config) { | 911 SkBitmap::Config bitmap_config, |
| 912 bool readback_async) { |
912 DCHECK((bitmap_config == SkBitmap::kRGB_565_Config) || | 913 DCHECK((bitmap_config == SkBitmap::kRGB_565_Config) || |
913 (bitmap_config == SkBitmap::kARGB_8888_Config)); | 914 (bitmap_config == SkBitmap::kARGB_8888_Config)); |
914 bool rgb565_format = (bitmap_config == SkBitmap::kRGB_565_Config); | 915 bool rgb565_format = (bitmap_config == SkBitmap::kRGB_565_Config); |
915 if (rgb565_format && !helper_->CanUseRgb565Readback()) { | 916 if (rgb565_format && !helper_->CanUseRgb565Readback()) { |
916 LOG(INFO) << "RGB565 Format Not supported on this platform"; | 917 LOG(INFO) << "RGB565 Format Not supported on this platform"; |
917 LOG(INFO) << "Skipping RGB565ReadBackTest"; | 918 LOG(INFO) << "Skipping RGB565ReadBackTest"; |
918 return true; | 919 return true; |
919 } | 920 } |
920 WebGLId src_texture = context_->createTexture(); | 921 WebGLId src_texture = context_->createTexture(); |
921 SkBitmap input_pixels; | 922 SkBitmap input_pixels; |
(...skipping 19 matching lines...) Expand all Loading... |
941 input_pixels.getPixels()); | 942 input_pixels.getPixels()); |
942 SkBitmap output_pixels; | 943 SkBitmap output_pixels; |
943 output_pixels.setConfig(bitmap_config, src_size.width(), | 944 output_pixels.setConfig(bitmap_config, src_size.width(), |
944 src_size.height()); | 945 src_size.height()); |
945 output_pixels.allocPixels(); | 946 output_pixels.allocPixels(); |
946 SkAutoLockPixels lock2(output_pixels); | 947 SkAutoLockPixels lock2(output_pixels); |
947 // Initialize the output bitmap with Green color. | 948 // Initialize the output bitmap with Green color. |
948 // When the readback is over output bitmap should have the red color. | 949 // When the readback is over output bitmap should have the red color. |
949 output_pixels.eraseColor(SK_ColorGREEN); | 950 output_pixels.eraseColor(SK_ColorGREEN); |
950 uint8* pixels = static_cast<uint8*>(output_pixels.getPixels()); | 951 uint8* pixels = static_cast<uint8*>(output_pixels.getPixels()); |
951 helper_->ReadbackTextureSync(src_texture, | 952 if (readback_async) { |
952 gfx::Rect(src_size), | 953 base::RunLoop run_loop; |
953 pixels, | 954 helper_->ReadbackTextureAsync(src_texture, |
954 bitmap_config); | 955 src_size, |
| 956 pixels, |
| 957 bitmap_config, |
| 958 base::Bind(&callcallback, |
| 959 run_loop.QuitClosure())); |
| 960 run_loop.Run(); |
| 961 } else { |
| 962 helper_->ReadbackTextureSync(src_texture, |
| 963 gfx::Rect(src_size), |
| 964 pixels, |
| 965 bitmap_config); |
| 966 } |
955 bool result = IsEqual(input_pixels, output_pixels); | 967 bool result = IsEqual(input_pixels, output_pixels); |
956 if (!result) { | 968 if (!result) { |
957 LOG(ERROR) << "Bitmap comparision failure"; | 969 LOG(ERROR) << "Bitmap comparision failure"; |
958 return false; | 970 return false; |
959 } | 971 } |
960 context_->deleteTexture(src_texture); | 972 context_->deleteTexture(src_texture); |
961 if (HasFailure()) { | 973 if (HasFailure()) { |
962 return false; | 974 return false; |
963 } | 975 } |
964 return true; | 976 return true; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 "8x1 -> 1x1 bilinear4 X\n"); | 1344 "8x1 -> 1x1 bilinear4 X\n"); |
1333 } | 1345 } |
1334 | 1346 |
1335 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context_; | 1347 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context_; |
1336 gpu::ContextSupport* context_support_; | 1348 gpu::ContextSupport* context_support_; |
1337 scoped_ptr<content::GLHelper> helper_; | 1349 scoped_ptr<content::GLHelper> helper_; |
1338 scoped_ptr<content::GLHelperScaling> helper_scaling_; | 1350 scoped_ptr<content::GLHelperScaling> helper_scaling_; |
1339 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; | 1351 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; |
1340 }; | 1352 }; |
1341 | 1353 |
1342 TEST_F(GLHelperTest, RGBAReadBackTest) { | 1354 TEST_F(GLHelperTest, ARGBSyncReadbackTest) { |
1343 const int kTestSize = 64; | 1355 const int kTestSize = 64; |
1344 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | 1356 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), |
1345 SkBitmap::kARGB_8888_Config); | 1357 SkBitmap::kARGB_8888_Config, |
| 1358 false); |
1346 EXPECT_EQ(result, true); | 1359 EXPECT_EQ(result, true); |
1347 } | 1360 } |
1348 | 1361 |
1349 TEST_F(GLHelperTest, RGB565ReadBackTest) { | 1362 TEST_F(GLHelperTest, RGB565SyncReadbackTest) { |
1350 const int kTestSize = 64; | 1363 const int kTestSize = 64; |
1351 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | 1364 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), |
1352 SkBitmap::kRGB_565_Config); | 1365 SkBitmap::kRGB_565_Config, |
| 1366 false); |
1353 EXPECT_EQ(result, true); | 1367 EXPECT_EQ(result, true); |
1354 } | 1368 } |
1355 | 1369 |
| 1370 TEST_F(GLHelperTest, ARGBASyncReadbackTest) { |
| 1371 const int kTestSize = 64; |
| 1372 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), |
| 1373 SkBitmap::kARGB_8888_Config, |
| 1374 true); |
| 1375 EXPECT_EQ(result, true); |
| 1376 } |
| 1377 |
| 1378 TEST_F(GLHelperTest, RGB565ASyncReadbackTest) { |
| 1379 const int kTestSize = 64; |
| 1380 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), |
| 1381 SkBitmap::kRGB_565_Config, |
| 1382 true); |
| 1383 EXPECT_EQ(result, true); |
| 1384 } |
| 1385 |
1356 TEST_F(GLHelperTest, YUVReadbackOptTest) { | 1386 TEST_F(GLHelperTest, YUVReadbackOptTest) { |
1357 // This test uses the cb_command tracing events to detect how many | 1387 // This test uses the cb_command tracing events to detect how many |
1358 // scaling passes are actually performed by the YUV readback pipeline. | 1388 // scaling passes are actually performed by the YUV readback pipeline. |
1359 StartTracing(TRACE_DISABLED_BY_DEFAULT("cb_command")); | 1389 StartTracing(TRACE_DISABLED_BY_DEFAULT("cb_command")); |
1360 | 1390 |
1361 TestYUVReadback(800, | 1391 TestYUVReadback(800, |
1362 400, | 1392 400, |
1363 800, | 1393 800, |
1364 400, | 1394 400, |
1365 0, | 1395 0, |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 #if defined(TOOLKIT_GTK) | 1571 #if defined(TOOLKIT_GTK) |
1542 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); | 1572 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); |
1543 #endif | 1573 #endif |
1544 gfx::GLSurface::InitializeOneOff(); | 1574 gfx::GLSurface::InitializeOneOff(); |
1545 gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess()); | 1575 gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess()); |
1546 | 1576 |
1547 content::UnitTestTestSuite runner(suite); | 1577 content::UnitTestTestSuite runner(suite); |
1548 base::MessageLoop message_loop; | 1578 base::MessageLoop message_loop; |
1549 return runner.Run(); | 1579 return runner.Run(); |
1550 } | 1580 } |
OLD | NEW |