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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/client/gl_helper_unittests.cc
diff --git a/content/common/gpu/client/gl_helper_unittests.cc b/content/common/gpu/client/gl_helper_unittests.cc
index 5abeabd260096ffc88cf4bdd0bf1b1ce1ec672d1..9ea54441d3d6f95237d9141af518a4f8631cd1c1 100644
--- a/content/common/gpu/client/gl_helper_unittests.cc
+++ b/content/common/gpu/client/gl_helper_unittests.cc
@@ -841,6 +841,121 @@ class GLHelperTest : public testing::Test {
}
}
+ bool ColorComponentsClose(SkColor component1, SkColor component2) {
+ int c1 = static_cast<int>(component1);
+ int c2 = static_cast<int>(component2);
+ return std::abs(c1 - c2) <= 40;
+ }
+
+ bool ColorsClose(SkColor color1, SkColor color2) {
+ // Be tolerant of floating point rounding and lossy color space conversions.
+ return ColorComponentsClose(SkColorGetR(color1), SkColorGetR(color2)) &&
+ ColorComponentsClose(SkColorGetG(color1), SkColorGetG(color2)) &&
+ ColorComponentsClose(SkColorGetB(color1), SkColorGetB(color2)) &&
+ ColorComponentsClose(SkColorGetA(color1), SkColorGetA(color2));
+ }
+
+ bool IsEqual(const SkBitmap& bmp1, const SkBitmap& bmp2) {
+ if (bmp1.isNull() && bmp2.isNull())
+ return true;
+ if (bmp1.width() != bmp2.width() ||
+ bmp1.height() != bmp2.height() ||
+ bmp1.config() != SkBitmap::kARGB_8888_Config ||
+ bmp2.config() != SkBitmap::kARGB_8888_Config) {
+ LOG(ERROR) << "Bitmap geometry check failure";
+ return false;
+ }
+ SkAutoLockPixels lock1(bmp1);
+ SkAutoLockPixels lock2(bmp2);
+ if (!bmp1.getPixels() || !bmp2.getPixels()){
+ LOG(ERROR) << "Bitmap is not having pixels";
+ return false;
+ }
+ for (int y = 0; y < bmp1.height(); ++y) {
+ for (int x = 0; x < bmp1.width(); ++x) {
+ if (!ColorsClose(bmp1.getColor(x,y), bmp2.getColor(x,y)))
+ LOG(ERROR) << "Bitmaps color comparision failure";
+ return false;
+ }
+ }
+ return true;
+ }
+
+ //Async readback test. Create a test pattern, create texture
+ //with test pattern , bind it to fbo and async read the fbo.
+ //compare inital input with async read output.
+ void TestAsyncReadback(const gfx::Size& src_size,
+ const gfx::Rect& src_subrect,
+ const gfx::Size& dst_size,
+ SkBitmap::Config bitmap_config) {
+ 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.
+ (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.
+ bool rgb565_format = (bitmap_config == SkBitmap::kRGB_565_Config) ?
+ true :
+ false;
+ 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.
+ {
piman 2014/01/10 22:38:33 nit: on previous line
sivag 2014/01/15 15:24:13 Done.
+ LOG(ERROR) << "RGB565 Format Not supported on this platform";
+ return;
+ }
+ WebGLId src_texture = context_->createTexture();
+ SkBitmap input_pixels;
+ input_pixels.setConfig(bitmap_config, src_size.width() ,
+ src_size.height());
+ input_pixels.allocPixels();
+ SkAutoLockPixels lock1(input_pixels);
+ // Clear with Red Color
+ input_pixels.eraseColor(SK_ColorRED);
+ context_->bindTexture(GL_TEXTURE_2D, src_texture);
+
+ GLenum format = (bitmap_config == SkBitmap::kRGB_565_Config) ?
+ GL_RGB : GL_RGBA;
+ GLenum type = (bitmap_config == SkBitmap::kRGB_565_Config) ?
+ GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE;
+
+ context_->texImage2D(GL_TEXTURE_2D,
+ 0,
+ format,
+ src_size.width(),
+ src_size.height(),
+ 0,
+ format,
+ type,
+ input_pixels.getPixels());
+
+ scoped_ptr<SkBitmap> bitmap(new SkBitmap);
+ bitmap->setConfig(bitmap_config,
+ dst_size.width(),
+ dst_size.height(),
+ 0, kOpaque_SkAlphaType);
+ if (!bitmap->allocPixels())
+ return;
+ // Clear with White Color
+ input_pixels.eraseColor(SK_ColorWHITE);
+ SkAutoLockPixels lock2(*bitmap);
+ uint8* pixels = static_cast<uint8*>(bitmap->getPixels());
+
+ /*base::RunLoop run_loop;
+ WebGLId framebuffer = context_->createFramebuffer();
+ context_->bindFramebuffer(GL_FRAMEBUFFER, framebuffer);
+ context_->bindTexture(GL_TEXTURE_2D, src_texture);
+ context_->framebufferTexture2D(GL_FRAMEBUFFER,
+ GL_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D,
+ src_texture,
+ 0);*/
+ // Sync read back doesnt have 565 support.
+ helper_->ReadbackTextureSync(src_texture, gfx::Rect(src_size), pixels);
+ // Need to Implement Async Read here?
+ //run_loop.Run();
+ // Both the bitmaps should be same.
+ bool result = IsEqual(input_pixels, *bitmap);
+ if(!result){
+ LOG(ERROR) << "Bitmap comparision failure";
+ }
+ context_->deleteTexture(src_texture);
+ }
+
// YUV readback test. Create a test pattern, convert to YUV
// with reference implementation and compare to what gl_helper
// returns.
@@ -1391,6 +1506,18 @@ TEST_F(GLHelperTest, CheckOptimizations) {
CheckOptimizationsTest();
}
+TEST_F(GLHelperTest, AsyncReadBackTest) {
+
+ TestAsyncReadback(gfx::Size(100,100),
+ gfx::Rect(100,100),
+ gfx::Size(100,100),
+ SkBitmap::kARGB_8888_Config);
+ // Async readback 565?
+ if (HasFailure()) {
+ return;
+ }
+}
+
} // namespace
// These tests needs to run against a proper GL environment, so we

Powered by Google App Engine
This is Rietveld 408576698