flutter_flutter/shell/common/picture_serializer.cc
Chinmay Garde cd9caf6de6 Update Skia revision to pull in GL native interface construction fixes on iOS. (#3265)
* Update Skia revision to pull in GL native interface construction fixes on iOS.

Fixed in https://skia-review.googlesource.com/c/5212/

* Use the new image encoder API from Skia.
2016-11-23 13:36:14 -08:00

35 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 "flutter/shell/common/picture_serializer.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkImageEncoder.h"
#include "third_party/skia/include/core/SkPixelSerializer.h"
#include "third_party/skia/include/core/SkStream.h"
namespace shell {
bool PngPixelSerializer::onUseEncodedData(const void*, size_t) {
return true;
}
SkData* PngPixelSerializer::onEncode(const SkPixmap& pixmap) {
SkDynamicMemoryWStream stream;
bool encode_result = SkEncodeImage(
&stream, pixmap, SkEncodedImageFormat::kPNG, 80 /* quality */);
return encode_result ? stream.detachAsData().release() : nullptr;
}
void SerializePicture(const std::string& path, SkPicture* picture) {
SkFILEWStream stream(path.c_str());
PngPixelSerializer serializer;
picture->serialize(&stream, &serializer);
}
} // namespace shell