Flutter Engine
The Flutter Engine
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.
5#include "flutter/fml/logging.h"
11
12namespace flutter {
13
15 return SkData::MakeEmpty();
16}
17
20}
21
23 size_t length,
24 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
37 const auto& info = image->imageInfo();
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
57 size_t length,
58 void* ctx) {
59 FML_CHECK(length >= sizeof(ImageMetaData));
60 auto metadata = static_cast<const ImageMetaData*>(data);
61 sk_sp<SkColorSpace> color_space = nullptr;
62 if (metadata->has_color_space) {
63 color_space = SkColorSpace::Deserialize(
64 static_cast<const uint8_t*>(data) + sizeof(ImageMetaData),
65 length - sizeof(ImageMetaData));
66 }
67
68 auto image_size = SkISize::Make(metadata->width, metadata->height);
70 image_size, static_cast<SkColorType>(metadata->color_type),
71 static_cast<SkAlphaType>(metadata->alpha_type), color_space);
72 sk_sp<SkData> image_data =
73 SkData::MakeUninitialized(image_size.width() * image_size.height() * 4);
74 memset(image_data->writable_data(), 0x0f, image_data->size());
76 SkImages::RasterFromData(info, image_data, image_size.width() * 4);
77
78 return image;
79};
80
81} // namespace flutter
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SkAlphaType
Definition: SkAlphaType.h:26
SkColorType
Definition: SkColorType.h:19
static sk_sp< SkColorSpace > Deserialize(const void *data, size_t length)
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116
void * writable_data()
Definition: SkData.h:52
static sk_sp< SkData > MakeEmpty()
Definition: SkData.cpp:94
size_t size() const
Definition: SkData.h:30
const SkImageInfo & imageInfo() const
Definition: SkImage.h:279
void serialize(SkWStream *, SerializeBehavior=SerializeBehavior::kIncludeDataIfLocal) const
Definition: SkTypeface.cpp:202
#define FML_CHECK(condition)
Definition: logging.h:85
size_t length
SK_API sk_sp< SkImage > RasterFromData(const SkImageInfo &info, sk_sp< SkData > pixels, size_t rowBytes)
sk_sp< const SkImage > image
Definition: SkRecords.h:269
sk_sp< SkData > SerializeTypefaceWithData(SkTypeface *typeface, void *ctx)
sk_sp< SkImage > DeserializeImageWithoutData(const void *data, size_t length, void *ctx)
sk_sp< SkTypeface > DeserializeTypefaceWithoutData(const void *data, size_t length, void *ctx)
sk_sp< SkData > 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: switches.h:41
sk_sp< SkData > SerializeImageWithoutData(SkImage *image, void *ctx)
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)