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(SkStream&, void* ctx) {
25 return nullptr;
26}
27
29 int32_t width;
30 int32_t height;
31 uint32_t color_type;
32 uint32_t alpha_type;
34} __attribute__((packed));
35
36SkSerialReturnType SerializeImageWithoutData(SkImage* image, void* ctx) {
37 const auto& info = image->imageInfo();
38 SkDynamicMemoryWStream stream;
39
40 ImageMetaData metadata = {info.width(), info.height(),
41 static_cast<uint32_t>(info.colorType()),
42 static_cast<uint32_t>(info.alphaType()),
43 static_cast<bool>(info.colorSpace())};
44 stream.write(&metadata, sizeof(ImageMetaData));
45
46 if (info.colorSpace()) {
47 auto color_space_data = info.colorSpace()->serialize();
48 FML_CHECK(color_space_data);
49 SkMemoryStream color_space_stream(color_space_data);
50 stream.writeStream(&color_space_stream, color_space_data->size());
51 }
52
53 return stream.detachAsData();
54};
55
56// This must match the declaration of SkDeserialImageFromDataProc.
57// NOLINTNEXTLINE(performance-unnecessary-value-param)
58sk_sp<SkImage> DeserializeImageWithoutData(sk_sp<SkData> data,
59 std::optional<SkAlphaType>,
60 void*) {
61 FML_CHECK(data->size() >= sizeof(ImageMetaData));
62 auto metadata = static_cast<const ImageMetaData*>(data->data());
63 sk_sp<SkColorSpace> color_space = nullptr;
64 if (metadata->has_color_space) {
65 color_space =
66 SkColorSpace::Deserialize(data->bytes() + sizeof(ImageMetaData),
67 data->size() - 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
SkSerialReturnType SerializeTypefaceWithData(SkTypeface *typeface, void *ctx)
sk_sp< SkTypeface > DeserializeTypefaceWithoutData(SkStream &, void *ctx)
sk_sp< SkImage > DeserializeImageWithoutData(sk_sp< SkData > data, std::optional< SkAlphaType >, void *)
SkSerialReturnType SerializeTypefaceWithoutData(SkTypeface *typeface, 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)