Flutter Engine
The Flutter Engine
Classes | Typedefs | Functions
SkCodecs Namespace Reference

Classes

struct  Decoder
 

Typedefs

using DecodeContext = void *
 
using IsFormatCallback = bool(*)(const void *data, size_t len)
 
using MakeFromStreamCallback = std::unique_ptr< SkCodec >(*)(std::unique_ptr< SkStream >, SkCodec::Result *, DecodeContext)
 

Functions

void SK_API Register (Decoder d)
 
SK_API sk_sp< SkImageDeferredImage (std::unique_ptr< SkCodec > codec, std::optional< SkAlphaType > alphaType=std::nullopt)
 
static std::vector< Decoder > * get_decoders_for_editing ()
 
const std::vector< Decoder > & get_decoders ()
 
bool HasDecoder (std::string_view id)
 

Typedef Documentation

◆ DecodeContext

using SkCodecs::DecodeContext = typedef void*

Definition at line 1047 of file SkCodec.h.

◆ IsFormatCallback

using SkCodecs::IsFormatCallback = typedef bool (*)(const void* data, size_t len)

Definition at line 1048 of file SkCodec.h.

◆ MakeFromStreamCallback

using SkCodecs::MakeFromStreamCallback = typedef std::unique_ptr<SkCodec> (*)(std::unique_ptr<SkStream>, SkCodec::Result*, DecodeContext)

Definition at line 1049 of file SkCodec.h.

Function Documentation

◆ DeferredImage()

sk_sp< SkImage > SkCodecs::DeferredImage ( std::unique_ptr< SkCodec codec,
std::optional< SkAlphaType alphaType = std::nullopt 
)

Return a SkImage produced by the codec, but attempts to defer image allocation until the image is actually used/drawn. This deferral allows the system to cache the result, either on the CPU or on the GPU, depending on where the image is drawn. If memory is low, the cache may be purged, causing the next draw of the image to have to re-decode.

If alphaType is nullopt, the image's alpha type will be chosen automatically based on the image format. Transparent images will default to kPremul_SkAlphaType. If alphaType contains kPremul_SkAlphaType or kUnpremul_SkAlphaType, that alpha type will be used. Forcing opaque (passing kOpaque_SkAlphaType) is not allowed, and will return nullptr.

Parameters
codecA non-null codec (e.g. from SkPngDecoder::Decode)
Returns
created SkImage, or nullptr

Definition at line 64 of file SkImageGenerator_FromEncoded.cpp.

64 {
66 SkCodecImageGenerator::MakeFromCodec(std::move(codec), alphaType));
67}
static std::unique_ptr< SkImageGenerator > MakeFromCodec(std::unique_ptr< SkCodec >, std::optional< SkAlphaType >=std::nullopt)
SK_API sk_sp< SkImage > DeferredFromGenerator(std::unique_ptr< SkImageGenerator > imageGenerator)

◆ get_decoders()

const std::vector< Decoder > & SkCodecs::get_decoders ( )

Definition at line 130 of file SkCodec.cpp.

130 {
131 auto decoders = get_decoders_for_editing();
132 return *decoders;
133}
static std::vector< Decoder > * get_decoders_for_editing()
Definition: SkCodec.cpp:85

◆ get_decoders_for_editing()

static std::vector< Decoder > * SkCodecs::get_decoders_for_editing ( )
static

Definition at line 85 of file SkCodec.cpp.

85 {
87#if !defined(SK_DISABLE_LEGACY_INIT_DECODERS)
88 static SkOnce once;
89 once([] {
90 if (decoders->empty()) {
91#if defined(SK_CODEC_DECODES_PNG)
92 decoders->push_back(SkPngDecoder::Decoder());
93#endif
94#if defined(SK_CODEC_DECODES_JPEG)
95 decoders->push_back(SkJpegDecoder::Decoder());
96#endif
97#if defined(SK_CODEC_DECODES_WEBP)
98 decoders->push_back(SkWebpDecoder::Decoder());
99#endif
100#if defined(SK_CODEC_DECODES_GIF) || defined(SK_HAS_WUFFS_LIBRARY)
101 decoders->push_back(SkGifDecoder::Decoder());
102#endif
103#if defined(SK_CODEC_DECODES_ICO)
104 decoders->push_back(SkIcoDecoder::Decoder());
105#endif
106#if defined(SK_CODEC_DECODES_BMP)
107 decoders->push_back(SkBmpDecoder::Decoder());
108#endif
109#if defined(SK_CODEC_DECODES_WBMP)
110 decoders->push_back(SkWbmpDecoder::Decoder());
111#endif
112#if defined(SK_CODEC_DECODES_AVIF)
113 decoders->push_back(SkAvifDecoder::Decoder());
114#endif
115#if defined(SK_CODEC_DECODES_JPEGXL)
116 decoders->push_back(SkJpegxlDecoder::Decoder());
117#endif
118#if defined(SK_HAS_HEIF_LIBRARY)
119 decoders->push_back(SkHeifDecoder::Decoder());
120#endif
121#if defined(SK_CODEC_DECODES_RAW)
122 decoders->push_back(SkRawDecoder::Decoder());
123#endif
124 }
125 });
126#endif // !defined(SK_DISABLE_LEGACY_INIT_DECODERS)
127 return decoders.get();
128}
const T * get() const
Definition: SkOnce.h:22

◆ HasDecoder()

bool SkCodecs::HasDecoder ( std::string_view  id)

Definition at line 146 of file SkCodec.cpp.

146 {
147 for (const SkCodecs::Decoder& decoder : get_decoders()) {
148 if (decoder.id == id) {
149 return true;
150 }
151 }
152 return false;
153}
const std::vector< Decoder > & get_decoders()
Definition: SkCodec.cpp:130

◆ Register()

void SkCodecs::Register ( Decoder  d)

Definition at line 135 of file SkCodec.cpp.

135 {
136 auto decoders = get_decoders_for_editing();
137 for (size_t i = 0; i < decoders->size(); i++) {
138 if ((*decoders)[i].id == d.id) {
139 (*decoders)[i] = d;
140 return;
141 }
142 }
143 decoders->push_back(d);
144}
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19