OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "sky/compositor/picture_serializer.h" |
| 6 |
| 7 #include "third_party/skia/include/core/SkData.h" |
| 8 #include "third_party/skia/include/core/SkPixelSerializer.h" |
| 9 #include "third_party/skia/include/core/SkStream.h" |
| 10 #include "ui/gfx/codec/png_codec.h" |
| 11 |
| 12 namespace sky { |
| 13 |
| 14 class PngPixelSerializer : public SkPixelSerializer { |
| 15 public: |
| 16 bool onUseEncodedData(const void*, size_t) override { return true; } |
| 17 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, |
| 18 size_t row_bytes) override { |
| 19 std::vector<unsigned char> data; |
| 20 |
| 21 SkBitmap bm; |
| 22 if (!bm.installPixels(info, const_cast<void*>(pixels), row_bytes)) |
| 23 return nullptr; |
| 24 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &data)) |
| 25 return nullptr; |
| 26 return SkData::NewWithCopy(&data.front(), data.size()); |
| 27 } |
| 28 }; |
| 29 |
| 30 void SerializePicture(const char* file_name, SkPicture* picture) { |
| 31 SkFILEWStream stream(file_name); |
| 32 PngPixelSerializer serializer; |
| 33 picture->serialize(&stream, &serializer); |
| 34 } |
| 35 |
| 36 } // namespace sky |
OLD | NEW |