flutter_flutter/sky/shell/gpu/picture_serializer.cc
Adam Barth 6d1af600b1 Trim unneeded depedendencies from sky/compositor
Now we just depend on Skia and Base, which makes the compositor easier
to understand.

Also, update our skia/ext/refptr.h to match the current version of the
code in Chromium. This version adds support for several useful C++11
patterns.
2016-01-12 22:02:08 -08:00

38 lines
1.1 KiB
C++

// 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/shell/gpu/picture_serializer.h"
#include <vector>
#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* onEncode(const SkPixmap& pixmap) override {
std::vector<unsigned char> data;
SkBitmap bm;
if (!bm.installPixels(pixmap))
return nullptr;
if (!gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &data))
return nullptr;
return SkData::NewWithCopy(&data.front(), data.size());
}
};
void SerializePicture(const base::FilePath& file_name, SkPicture* picture) {
SkFILEWStream stream(file_name.AsUTF8Unsafe().c_str());
PngPixelSerializer serializer;
picture->serialize(&stream, &serializer);
}
} // namespace sky