forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
picture_serializer.cc
34 lines (25 loc) · 1.06 KB
/
picture_serializer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// 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