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

Unified Diff: ui/gfx/compositor/layer_unittest.cc

Issue 8463024: Implement CompositorCC::ReadPixels (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compositor::ReadPixels now returns bool Created 9 years, 1 month 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: ui/gfx/compositor/layer_unittest.cc
diff --git a/ui/gfx/compositor/layer_unittest.cc b/ui/gfx/compositor/layer_unittest.cc
index 7445256c199f3696227ee0e16b7e31ed0e055ada..3e07179599db0c904b9c4524ac6a6f7f4566665b 100644
--- a/ui/gfx/compositor/layer_unittest.cc
+++ b/ui/gfx/compositor/layer_unittest.cc
@@ -4,9 +4,14 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/path_service.h"
+#include "base/string_util.h"
#include "base/memory/scoped_ptr.h"
jonathan.backer 2011/11/14 14:06:58 nit: alphabetize
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/canvas_skia.h"
+#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/compositor/compositor_observer.h"
#include "ui/gfx/compositor/layer.h"
#include "ui/gfx/compositor/layer_animation_sequence.h"
@@ -173,6 +178,20 @@ class NullLayerDelegate : public LayerDelegate {
DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate);
};
+// Encodes a bitmap into a PNG and write to disk. Returns true on success. The
+// parent directory does not have to exist.
jonathan.backer 2011/11/14 14:06:58 This is great. Just don't see where it's called. (
+bool WritePNGFile(const SkBitmap& bitmap, const FilePath& file_path) {
+ std::vector<unsigned char> png_data;
+ if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &png_data) &&
+ file_util::CreateDirectory(file_path.DirName())) {
+ int bytes_written = file_util::WriteFile(
+ file_path, reinterpret_cast<char*>(&png_data[0]), png_data.size());
+ if (bytes_written == static_cast<int>(png_data.size()))
+ return true;
+ }
+ return false;
+}
+
}
#if defined(OS_WIN)
@@ -792,7 +811,7 @@ TEST_F(LayerWithRealCompositorTest, MAYBE_DrawPixels) {
DrawTree(layer.get());
SkBitmap bitmap;
- GetCompositor()->ReadPixels(&bitmap);
+ ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap));
ASSERT_FALSE(bitmap.empty());
SkAutoLockPixels lock(bitmap);

Powered by Google App Engine
This is Rietveld 408576698