5#include "flutter/lib/ui/painting/image_generator.h"
9#include "flutter/fml/logging.h"
24 FML_DLOG(
ERROR) <<
"Failed to allocate memory for bitmap of size "
25 <<
info.computeMinByteSize() <<
"B";
29 const auto& pixmap =
bitmap.pixmap();
30 if (!
GetPixels(pixmap.info(), pixmap.writable_addr(), pixmap.rowBytes())) {
41 std::unique_ptr<SkImageGenerator> generator)
42 : generator_(
std::move(generator)) {}
45 return generator_->getInfo();
57 unsigned int frame_index) {
64 return generator_->getInfo().dimensions();
71 unsigned int frame_index,
72 std::optional<unsigned int> prior_frame) {
73 return generator_->getPixels(
info, pixels, row_bytes);
77 std::unique_ptr<SkImageGenerator> generator) {
81 return std::make_unique<BuiltinSkiaImageGenerator>(std::move(generator));
99 std::unique_ptr<SkCodec> codec)
100 : codec_(
std::move(codec)) {
115 return codec_->getFrameCount();
119 auto repetition_count = codec_->getRepetitionCount();
124 unsigned int frame_index) {
126 codec_->getFrameInfo(frame_index, &
info);
130 : std::optional<unsigned int>(
info.fRequiredFrame),
131 .duration =
static_cast<unsigned int>(
info.fDuration),
132 .disposal_method =
info.fDisposalMethod};
136 float desired_scale) {
137 SkISize size = codec_->getScaledDimensions(desired_scale);
148 unsigned int frame_index,
149 std::optional<unsigned int> prior_frame) {
151 options.fFrameIndex = frame_index;
152 if (prior_frame.has_value()) {
153 options.fPriorFrame = prior_frame.value();
162 temp_pixmap = output_pixmap;
172 FML_DLOG(
ERROR) <<
"Failed to allocate memory for bitmap of size "
176 temp_pixmap = temp_bitmap.
pixmap();
181 FML_DLOG(WARNING) <<
"codec could not get pixels. "
197 return std::make_unique<BuiltinSkiaCodecImageGenerator>(std::move(codec));
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kTopLeft_SkEncodedOrigin
static bool SkEncodedOriginSwapsWidthHeight(SkEncodedOrigin origin)
void swap(sk_sp< T > &a, sk_sp< T > &b)
const SkPixmap & pixmap() const
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
static std::unique_ptr< SkCodec > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
static const char * ResultToString(Result)
SkEncodedOrigin getOrigin() const
static constexpr int kNoFrame
SkImageInfo getInfo() const
const SkImageInfo & info() const
unsigned int GetPlayCount() const override
The number of times an animated image should play through before playback stops.
unsigned int GetFrameCount() const override
Get the number of frames that the encoded image stores. This method is always expected to be called b...
bool GetPixels(const SkImageInfo &info, void *pixels, size_t row_bytes, unsigned int frame_index=0, std::optional< unsigned int > prior_frame=std::nullopt) override
Decode the image into a given buffer. This method is currently always used for sub-pixel image decodi...
const ImageGenerator::FrameInfo GetFrameInfo(unsigned int frame_index) override
Get information about a single frame in the context of a multi-frame image, useful for animation and ...
~BuiltinSkiaCodecImageGenerator()
BuiltinSkiaCodecImageGenerator(std::unique_ptr< SkCodec > codec)
const SkImageInfo & GetInfo() override
Returns basic information about the contents of the encoded image. This information can almost always...
static std::unique_ptr< ImageGenerator > MakeFromData(sk_sp< SkData > data)
SkISize GetScaledDimensions(float desired_scale) override
Given a scale value, find the closest image size that can be used for efficiently decoding the image....
SkISize GetScaledDimensions(float desired_scale) override
Given a scale value, find the closest image size that can be used for efficiently decoding the image....
unsigned int GetPlayCount() const override
The number of times an animated image should play through before playback stops.
const SkImageInfo & GetInfo() override
Returns basic information about the contents of the encoded image. This information can almost always...
const ImageGenerator::FrameInfo GetFrameInfo(unsigned int frame_index) override
Get information about a single frame in the context of a multi-frame image, useful for animation and ...
bool GetPixels(const SkImageInfo &info, void *pixels, size_t row_bytes, unsigned int frame_index=0, std::optional< unsigned int > prior_frame=std::nullopt) override
Decode the image into a given buffer. This method is currently always used for sub-pixel image decodi...
unsigned int GetFrameCount() const override
Get the number of frames that the encoded image stores. This method is always expected to be called b...
BuiltinSkiaImageGenerator(std::unique_ptr< SkImageGenerator > generator)
static std::unique_ptr< ImageGenerator > MakeFromGenerator(std::unique_ptr< SkImageGenerator > generator)
~BuiltinSkiaImageGenerator()
virtual ~ImageGenerator()
static const unsigned int kInfinitePlayCount
Frame count value to denote infinite looping.
sk_sp< SkImage > GetImage()
Creates an SkImage based on the current ImageInfo of this ImageGenerator.
virtual const SkImageInfo & GetInfo()=0
Returns basic information about the contents of the encoded image. This information can almost always...
virtual bool GetPixels(const SkImageInfo &info, void *pixels, size_t row_bytes, unsigned int frame_index=0, std::optional< unsigned int > prior_frame=std::nullopt)=0
Decode the image into a given buffer. This method is currently always used for sub-pixel image decodi...
#define FML_DLOG(severity)
SK_API sk_sp< SkImage > RasterFromBitmap(const SkBitmap &bitmap)
SK_API bool Orient(const SkPixmap &dst, const SkPixmap &src, SkEncodedOrigin origin)
SK_API SkImageInfo SwapWidthHeight(const SkImageInfo &info)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
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
static SkImageInfo getInfoIncludingExif(SkCodec *codec)
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 JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
size_t computeMinByteSize() const
Info about a single frame in the context of a multi-frame image, useful for animation and blending.
std::optional< unsigned int > required_frame