Flutter Engine
The Flutter Engine
Functions
SkGifDecoder Namespace Reference

Functions

SK_API bool IsGif (const void *, size_t)
 
SK_API std::unique_ptr< SkCodecDecode (std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
 
SK_API std::unique_ptr< SkCodecDecode (sk_sp< SkData >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
 
constexpr SkCodecs::Decoder Decoder ()
 
std::unique_ptr< SkCodecMakeFromStream (std::unique_ptr< SkStream > stream, SkCodec::SelectionPolicy selectionPolicy, SkCodec::Result *result)
 

Function Documentation

◆ Decode() [1/2]

std::unique_ptr< SkCodec > SkGifDecoder::Decode ( sk_sp< SkData data,
SkCodec::Result outResult,
SkCodecs::DecodeContext  ctx = nullptr 
)

Definition at line 1096 of file SkWuffsCodec.cpp.

1098 {
1099 if (!data) {
1100 if (outResult) {
1101 *outResult = SkCodec::kInvalidInput;
1102 }
1103 return nullptr;
1104 }
1105 return Decode(SkMemoryStream::Make(std::move(data)), outResult, ctx);
1106}
@ kInvalidInput
Definition: SkCodec.h:109
static std::unique_ptr< SkMemoryStream > Make(sk_sp< SkData > data)
Definition: SkStream.cpp:314
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ Decode() [2/2]

std::unique_ptr< SkCodec > SkGifDecoder::Decode ( std::unique_ptr< SkStream stream,
SkCodec::Result outResult,
SkCodecs::DecodeContext  ctx = nullptr 
)

Attempts to decode the given bytes as a GIF.

If the bytes are not a GIF, returns nullptr.

DecodeContext is ignored

Definition at line 1082 of file SkWuffsCodec.cpp.

1084 {
1085 SkCodec::Result resultStorage;
1086 if (!outResult) {
1087 outResult = &resultStorage;
1088 }
1090 if (ctx) {
1091 policy = *static_cast<SkCodec::SelectionPolicy*>(ctx);
1092 }
1093 return MakeFromStream(std::move(stream), policy, outResult);
1094}
Result
Definition: SkCodec.h:76
SelectionPolicy
Definition: SkCodec.h:136
std::unique_ptr< SkCodec > MakeFromStream(std::unique_ptr< SkStream > stream, SkCodec::SelectionPolicy selectionPolicy, SkCodec::Result *result)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network policy
Definition: switches.h:248

◆ Decoder()

constexpr SkCodecs::Decoder SkGifDecoder::Decoder ( )
inlineconstexpr

Definition at line 38 of file SkGifDecoder.h.

38 {
39 return { "gif", IsGif, Decode };
40}
SK_API std::unique_ptr< SkCodec > Decode(sk_sp< SkData >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
SK_API bool IsGif(const void *, size_t)

◆ IsGif()

bool SkGifDecoder::IsGif ( const void *  buf,
size_t  bytesRead 
)

Returns true if this data claims to be a GIF image.

Definition at line 977 of file SkWuffsCodec.cpp.

977 {
978 constexpr const char* gif_ptr = "GIF8";
979 constexpr size_t gif_len = 4;
980 return (bytesRead >= gif_len) && (memcmp(buf, gif_ptr, gif_len) == 0);
981}

◆ MakeFromStream()

std::unique_ptr< SkCodec > SkGifDecoder::MakeFromStream ( std::unique_ptr< SkStream stream,
SkCodec::SelectionPolicy  selectionPolicy,
SkCodec::Result result 
)

Definition at line 983 of file SkWuffsCodec.cpp.

985 {
987 if (!stream) {
989 return nullptr;
990 }
991
992 bool canSeek = stream->hasPosition() && stream->hasLength();
993
994 if (selectionPolicy != SkCodec::SelectionPolicy::kPreferStillImage) {
995 // Some clients (e.g. Android) need to be able to seek the stream, but may
996 // not provide a seekable stream. Copy the stream to one that can seek.
997 if (!canSeek) {
998 auto data = SkCopyStreamToData(stream.get());
999 stream = std::make_unique<SkMemoryStream>(std::move(data));
1000 canSeek = true;
1001 }
1002 }
1003
1005 wuffs_base__io_buffer iobuf =
1006 wuffs_base__make_io_buffer(wuffs_base__make_slice_u8(buffer, SK_WUFFS_CODEC_BUFFER_SIZE),
1007 wuffs_base__empty_io_buffer_meta());
1008 wuffs_base__image_config imgcfg = wuffs_base__null_image_config();
1009
1010 // Wuffs is primarily a C library, not a C++ one. Furthermore, outside of
1011 // the wuffs_base__etc types, the sizeof a file format specific type like
1012 // GIF's wuffs_gif__decoder can vary between Wuffs versions. If p is of
1013 // type wuffs_gif__decoder*, then the supported API treats p as a pointer
1014 // to an opaque type: a private implementation detail. The API is always
1015 // "set_foo(p, etc)" and not "p->foo = etc".
1016 //
1017 // See https://en.wikipedia.org/wiki/Opaque_pointer#C
1018 //
1019 // Thus, we don't use C++'s new operator (which requires knowing the sizeof
1020 // the struct at compile time). Instead, we use sk_malloc_canfail, with
1021 // sizeof__wuffs_gif__decoder returning the appropriate value for the
1022 // (statically or dynamically) linked version of the Wuffs library.
1023 //
1024 // As a C (not C++) library, none of the Wuffs types have constructors or
1025 // destructors.
1026 //
1027 // In RAII style, we can still use std::unique_ptr with these pointers, but
1028 // we pair the pointer with sk_free instead of C++'s delete.
1029 void* decoder_raw = sk_malloc_canfail(sizeof__wuffs_gif__decoder());
1030 if (!decoder_raw) {
1032 return nullptr;
1033 }
1034 std::unique_ptr<wuffs_gif__decoder, decltype(&sk_free)> decoder(
1035 reinterpret_cast<wuffs_gif__decoder*>(decoder_raw), &sk_free);
1036
1037 SkCodec::Result reset_result =
1038 reset_and_decode_image_config(decoder.get(), &imgcfg, &iobuf, stream.get());
1039 if (reset_result != SkCodec::kSuccess) {
1040 *result = reset_result;
1041 return nullptr;
1042 }
1043
1044 uint32_t width = imgcfg.pixcfg.width();
1045 uint32_t height = imgcfg.pixcfg.height();
1046 if ((width == 0) || (width > INT_MAX) || (height == 0) || (height > INT_MAX)) {
1048 return nullptr;
1049 }
1050
1051 uint64_t workbuf_len = decoder->workbuf_len().max_incl;
1052 void* workbuf_ptr_raw = nullptr;
1053 if (workbuf_len) {
1054 workbuf_ptr_raw = workbuf_len <= SIZE_MAX ? sk_malloc_canfail(workbuf_len) : nullptr;
1055 if (!workbuf_ptr_raw) {
1057 return nullptr;
1058 }
1059 }
1060 std::unique_ptr<uint8_t, decltype(&sk_free)> workbuf_ptr(
1061 reinterpret_cast<uint8_t*>(workbuf_ptr_raw), &sk_free);
1062
1064 (imgcfg.pixcfg.pixel_format().repr == WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL)
1067
1068 // In Skia's API, the alpha we calculate here and return is only for the
1069 // first frame.
1070 SkEncodedInfo::Alpha alpha = imgcfg.first_frame_is_opaque() ? SkEncodedInfo::kOpaque_Alpha
1072
1073 SkEncodedInfo encodedInfo = SkEncodedInfo::Make(width, height, color, alpha, 8);
1074
1076 return std::unique_ptr<SkCodec>(new SkWuffsCodec(std::move(encodedInfo), std::move(stream),
1077 canSeek,
1078 std::move(decoder), std::move(workbuf_ptr),
1079 workbuf_len, imgcfg, iobuf));
1080}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SK_API void sk_free(void *)
static void * sk_malloc_canfail(size_t size)
Definition: SkMalloc.h:93
sk_sp< SkData > SkCopyStreamToData(SkStream *stream)
Definition: SkStream.cpp:937
static SkCodec::Result reset_and_decode_image_config(wuffs_gif__decoder *decoder, wuffs_base__image_config *imgcfg, wuffs_base__io_buffer *b, SkStream *s)
#define SK_WUFFS_CODEC_BUFFER_SIZE
@ kInternalError
Definition: SkCodec.h:118
@ kSuccess
Definition: SkCodec.h:80
DlColor color
GAsyncResult * result
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
int32_t height
int32_t width
static SkEncodedInfo Make(int width, int height, Color color, Alpha alpha, int bitsPerComponent)