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

Unified Diff: sky/compositor/picture_serializer.cc

Issue 853863003: Serialize SkPictures to the file system (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « sky/compositor/picture_serializer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/compositor/picture_serializer.cc
diff --git a/sky/compositor/picture_serializer.cc b/sky/compositor/picture_serializer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..47117e718af96d6eaf141668cec7e0954ad405d6
--- /dev/null
+++ b/sky/compositor/picture_serializer.cc
@@ -0,0 +1,36 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sky/compositor/picture_serializer.h"
+
+#include "third_party/skia/include/core/SkData.h"
+#include "third_party/skia/include/core/SkPixelSerializer.h"
+#include "third_party/skia/include/core/SkStream.h"
+#include "ui/gfx/codec/png_codec.h"
+
+namespace sky {
+
+class PngPixelSerializer : public SkPixelSerializer {
+ public:
+ bool onUseEncodedData(const void*, size_t) override { return true; }
+ SkData* onEncodePixels(const SkImageInfo& info, const void* pixels,
+ size_t row_bytes) override {
+ std::vector<unsigned char> data;
+
+ SkBitmap bm;
+ if (!bm.installPixels(info, const_cast<void*>(pixels), row_bytes))
+ return nullptr;
+ if (!gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &data))
+ return nullptr;
+ return SkData::NewWithCopy(&data.front(), data.size());
+ }
+};
+
+void SerializePicture(const char* file_name, SkPicture* picture) {
+ SkFILEWStream stream(file_name);
+ PngPixelSerializer serializer;
+ picture->serialize(&stream, &serializer);
+}
+
+} // namespace sky
« no previous file with comments | « sky/compositor/picture_serializer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698