Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
serialization_callbacks.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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.
7#include "third_party/skia/include/core/SkColorSpace.h"
8#include "third_party/skia/include/core/SkImage.h"
9#include "third_party/skia/include/core/SkImageInfo.h"
10#include "third_party/skia/include/core/SkStream.h"
11#include "third_party/skia/include/core/SkTypeface.h"
12
13namespace flutter {
14
15SkSerialReturnType SerializeTypefaceWithoutData(SkTypeface* typeface,
16 void* ctx) {
17 return SkData::MakeEmpty();
18}
19
20SkSerialReturnType SerializeTypefaceWithData(SkTypeface* typeface, void* ctx) {
21 return typeface->serialize(SkTypeface::SerializeBehavior::kDoIncludeData);
22}
23
24sk_sp<SkTypeface> DeserializeTypefaceWithoutData(const void* data,
25 size_t length,
26 void* ctx) {
27 return nullptr;
28}
29
31 int32_t width;
32 int32_t height;
33 uint32_t color_type;
34 uint32_t alpha_type;
36} __attribute__((packed));
37
38SkSerialReturnType SerializeImageWithoutData(SkImage* image, void* ctx) {
39 const auto& info = image->imageInfo();
40 SkDynamicMemoryWStream stream;
41
42 ImageMetaData metadata = {info.width(), info.height(),
43 static_cast<uint32_t>(info.colorType()),
44 static_cast<uint32_t>(info.alphaType()),
45 static_cast<bool>(info.colorSpace())};
46 stream.write(&metadata, sizeof(ImageMetaData));
47
48 if (info.colorSpace()) {
49 auto color_space_data = info.colorSpace()->serialize();
50 FML_CHECK(color_space_data);
51 SkMemoryStream color_space_stream(color_space_data);
52 stream.writeStream(&color_space_stream, color_space_data->size());
53 }
54
55 return stream.detachAsData();
56};
57
58sk_sp<SkImage> DeserializeImageWithoutData(const void* data,
59 size_t length,
60 void* ctx) {
61 FML_CHECK(length >= sizeof(ImageMetaData));
62 auto metadata = static_cast<const ImageMetaData*>(data);
63 sk_sp<SkColorSpace> color_space = nullptr;
64 if (metadata->has_color_space) {
65 color_space = SkColorSpace::Deserialize(
66 static_cast<const uint8_t*>(data) + sizeof(ImageMetaData),
67 length - sizeof(ImageMetaData));
68 }
69
70 auto image_size = SkISize::Make(metadata->width, metadata->height);
71 auto info = SkImageInfo::Make(
72 image_size, static_cast<SkColorType>(metadata->color_type),
73 static_cast<SkAlphaType>(metadata->alpha_type), color_space);
74 sk_sp<SkData> image_data =
75 SkData::MakeUninitialized(image_size.width() * image_size.height() * 4);
76 memset(image_data->writable_data(), 0x0f, image_data->size());
77 sk_sp<SkImage> image =
78 SkImages::RasterFromData(info, image_data, image_size.width() * 4);
79
80 return image;
81};
82
83} // namespace flutter
FlutterVulkanImage * image
#define FML_CHECK(condition)
Definition logging.h:104
size_t length
SkSerialReturnType SerializeTypefaceWithData(SkTypeface *typeface, void *ctx)
sk_sp< SkImage > DeserializeImageWithoutData(const void *data, size_t length, void *ctx)
SkSerialReturnType SerializeTypefaceWithoutData(SkTypeface *typeface, void *ctx)
sk_sp< SkTypeface > DeserializeTypefaceWithoutData(const void *data, size_t length, void *ctx)
struct flutter::ImageMetaData __attribute__((packed))
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switch_defs.h:36
SkSerialReturnType SerializeImageWithoutData(SkImage *image, void *ctx)