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

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

Issue 88033002: Add RGB565 Texture readback support in gl_helper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes done as per review comments (WIP: gl_helper_unittests) Created 6 years, 11 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
OLDNEW
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 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 PrintChannel(source, 1); 834 PrintChannel(source, 1);
835 LOG(ERROR) << "-------before yuv conversion: blue-------"; 835 LOG(ERROR) << "-------before yuv conversion: blue-------";
836 PrintChannel(source, 2); 836 PrintChannel(source, 2);
837 } 837 }
838 return; 838 return;
839 } 839 }
840 } 840 }
841 } 841 }
842 } 842 }
843 843
844 bool ColorComponentsClose(SkColor component1, SkColor component2) {
845 int c1 = static_cast<int>(component1);
846 int c2 = static_cast<int>(component2);
847 return std::abs(c1 - c2) <= 40;
848 }
849
850 bool ColorsClose(SkColor color1, SkColor color2) {
851 // Be tolerant of floating point rounding and lossy color space conversions.
852 return ColorComponentsClose(SkColorGetR(color1), SkColorGetR(color2)) &&
853 ColorComponentsClose(SkColorGetG(color1), SkColorGetG(color2)) &&
854 ColorComponentsClose(SkColorGetB(color1), SkColorGetB(color2)) &&
855 ColorComponentsClose(SkColorGetA(color1), SkColorGetA(color2));
856 }
857
858 bool IsEqual(const SkBitmap& bmp1, const SkBitmap& bmp2) {
859 if (bmp1.isNull() && bmp2.isNull())
860 return true;
861 if (bmp1.width() != bmp2.width() ||
862 bmp1.height() != bmp2.height() ||
863 bmp1.config() != SkBitmap::kARGB_8888_Config ||
864 bmp2.config() != SkBitmap::kARGB_8888_Config) {
865 LOG(ERROR) << "Bitmap geometry check failure";
866 return false;
867 }
868 SkAutoLockPixels lock1(bmp1);
869 SkAutoLockPixels lock2(bmp2);
870 if (!bmp1.getPixels() || !bmp2.getPixels()){
871 LOG(ERROR) << "Bitmap is not having pixels";
872 return false;
873 }
874 for (int y = 0; y < bmp1.height(); ++y) {
875 for (int x = 0; x < bmp1.width(); ++x) {
876 if (!ColorsClose(bmp1.getColor(x,y), bmp2.getColor(x,y)))
877 LOG(ERROR) << "Bitmaps color comparision failure";
878 return false;
879 }
880 }
881 return true;
882 }
883
884 //Async readback test. Create a test pattern, create texture
885 //with test pattern , bind it to fbo and async read the fbo.
886 //compare inital input with async read output.
887 void TestAsyncReadback(const gfx::Size& src_size,
888 const gfx::Rect& src_subrect,
889 const gfx::Size& dst_size,
890 SkBitmap::Config bitmap_config) {
891 DCHECK((bitmap_config == SkBitmap::kRGB_565_Config)||
piman 2014/01/10 22:38:33 nit: space before ||
sivag 2014/01/15 15:24:13 Done.
892 (bitmap_config == SkBitmap::kARGB_8888_Config));
piman 2014/01/10 22:38:33 nit: indent (1 more space)
sivag 2014/01/15 15:24:13 Done.
893 bool rgb565_format = (bitmap_config == SkBitmap::kRGB_565_Config) ?
894 true :
895 false;
896 if(rgb565_format && !helper_->CanUseRgb565Readback())
piman 2014/01/10 22:38:33 nit: space between if and (
sivag 2014/01/15 15:24:13 Done.
897 {
piman 2014/01/10 22:38:33 nit: on previous line
sivag 2014/01/15 15:24:13 Done.
898 LOG(ERROR) << "RGB565 Format Not supported on this platform";
899 return;
900 }
901 WebGLId src_texture = context_->createTexture();
902 SkBitmap input_pixels;
903 input_pixels.setConfig(bitmap_config, src_size.width() ,
904 src_size.height());
905 input_pixels.allocPixels();
906 SkAutoLockPixels lock1(input_pixels);
907 // Clear with Red Color
908 input_pixels.eraseColor(SK_ColorRED);
909 context_->bindTexture(GL_TEXTURE_2D, src_texture);
910
911 GLenum format = (bitmap_config == SkBitmap::kRGB_565_Config) ?
912 GL_RGB : GL_RGBA;
913 GLenum type = (bitmap_config == SkBitmap::kRGB_565_Config) ?
914 GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE;
915
916 context_->texImage2D(GL_TEXTURE_2D,
917 0,
918 format,
919 src_size.width(),
920 src_size.height(),
921 0,
922 format,
923 type,
924 input_pixels.getPixels());
925
926 scoped_ptr<SkBitmap> bitmap(new SkBitmap);
927 bitmap->setConfig(bitmap_config,
928 dst_size.width(),
929 dst_size.height(),
930 0, kOpaque_SkAlphaType);
931 if (!bitmap->allocPixels())
932 return;
933 // Clear with White Color
934 input_pixels.eraseColor(SK_ColorWHITE);
935 SkAutoLockPixels lock2(*bitmap);
936 uint8* pixels = static_cast<uint8*>(bitmap->getPixels());
937
938 /*base::RunLoop run_loop;
939 WebGLId framebuffer = context_->createFramebuffer();
940 context_->bindFramebuffer(GL_FRAMEBUFFER, framebuffer);
941 context_->bindTexture(GL_TEXTURE_2D, src_texture);
942 context_->framebufferTexture2D(GL_FRAMEBUFFER,
943 GL_COLOR_ATTACHMENT0,
944 GL_TEXTURE_2D,
945 src_texture,
946 0);*/
947 // Sync read back doesnt have 565 support.
948 helper_->ReadbackTextureSync(src_texture, gfx::Rect(src_size), pixels);
949 // Need to Implement Async Read here?
950 //run_loop.Run();
951 // Both the bitmaps should be same.
952 bool result = IsEqual(input_pixels, *bitmap);
953 if(!result){
954 LOG(ERROR) << "Bitmap comparision failure";
955 }
956 context_->deleteTexture(src_texture);
957 }
958
844 // YUV readback test. Create a test pattern, convert to YUV 959 // YUV readback test. Create a test pattern, convert to YUV
845 // with reference implementation and compare to what gl_helper 960 // with reference implementation and compare to what gl_helper
846 // returns. 961 // returns.
847 void TestYUVReadback(int xsize, 962 void TestYUVReadback(int xsize,
848 int ysize, 963 int ysize,
849 int output_xsize, 964 int output_xsize,
850 int output_ysize, 965 int output_ysize,
851 int xmargin, 966 int xmargin,
852 int ymargin, 967 int ymargin,
853 int test_pattern, 968 int test_pattern,
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 } 1499 }
1385 } 1500 }
1386 } 1501 }
1387 } 1502 }
1388 1503
1389 TEST_F(GLHelperTest, CheckOptimizations) { 1504 TEST_F(GLHelperTest, CheckOptimizations) {
1390 // Test in baseclass since it is friends with GLHelperScaling 1505 // Test in baseclass since it is friends with GLHelperScaling
1391 CheckOptimizationsTest(); 1506 CheckOptimizationsTest();
1392 } 1507 }
1393 1508
1509 TEST_F(GLHelperTest, AsyncReadBackTest) {
1510
1511 TestAsyncReadback(gfx::Size(100,100),
1512 gfx::Rect(100,100),
1513 gfx::Size(100,100),
1514 SkBitmap::kARGB_8888_Config);
1515 // Async readback 565?
1516 if (HasFailure()) {
1517 return;
1518 }
1519 }
1520
1394 } // namespace 1521 } // namespace
1395 1522
1396 // These tests needs to run against a proper GL environment, so we 1523 // These tests needs to run against a proper GL environment, so we
1397 // need to set it up before we can run the tests. 1524 // need to set it up before we can run the tests.
1398 int main(int argc, char** argv) { 1525 int main(int argc, char** argv) {
1399 CommandLine::Init(argc, argv); 1526 CommandLine::Init(argc, argv);
1400 base::TestSuite* suite = new content::ContentTestSuite(argc, argv); 1527 base::TestSuite* suite = new content::ContentTestSuite(argc, argv);
1401 #if defined(OS_MACOSX) 1528 #if defined(OS_MACOSX)
1402 base::mac::ScopedNSAutoreleasePool pool; 1529 base::mac::ScopedNSAutoreleasePool pool;
1403 #endif 1530 #endif
1404 #if defined(TOOLKIT_GTK) 1531 #if defined(TOOLKIT_GTK)
1405 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); 1532 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess());
1406 #endif 1533 #endif
1407 gfx::GLSurface::InitializeOneOff(); 1534 gfx::GLSurface::InitializeOneOff();
1408 gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess()); 1535 gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess());
1409 1536
1410 content::UnitTestTestSuite runner(suite); 1537 content::UnitTestTestSuite runner(suite);
1411 base::MessageLoop message_loop; 1538 base::MessageLoop message_loop;
1412 return runner.Run(); 1539 return runner.Run();
1413 } 1540 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698