| 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
|
|
|