Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
flutter::BuiltinSkiaCodecImageGenerator Class Reference

#include <image_generator.h>

Inheritance diagram for flutter::BuiltinSkiaCodecImageGenerator:
flutter::ImageGenerator

Public Member Functions

 ~BuiltinSkiaCodecImageGenerator ()
 
 BuiltinSkiaCodecImageGenerator (std::unique_ptr< SkCodec > codec)
 
 BuiltinSkiaCodecImageGenerator (sk_sp< SkData > buffer)
 
const SkImageInfoGetInfo () override
 Returns basic information about the contents of the encoded image. This information can almost always be collected by just interpreting the header of a decoded image.
 
unsigned int GetFrameCount () const override
 Get the number of frames that the encoded image stores. This method is always expected to be called before GetFrameInfo, as the underlying image decoder may interpret frame information that is then used when calling GetFrameInfo.
 
unsigned int GetPlayCount () const override
 The number of times an animated image should play through before playback stops.
 
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 frame blending. This method should only ever be called after GetFrameCount has been called. This information is nonsensical for single-frame images.
 
SkISize GetScaledDimensions (float desired_scale) override
 Given a scale value, find the closest image size that can be used for efficiently decoding the image. If subpixel image decoding is not supported by the decoder, this method should just return the original image size.
 
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 decoding. For full-sized still images, GetImage is always attempted first.
 
- Public Member Functions inherited from flutter::ImageGenerator
virtual ~ImageGenerator ()
 
sk_sp< SkImageGetImage ()
 Creates an SkImage based on the current ImageInfo of this ImageGenerator.
 

Static Public Member Functions

static std::unique_ptr< ImageGeneratorMakeFromData (sk_sp< SkData > data)
 

Additional Inherited Members

- Static Public Attributes inherited from flutter::ImageGenerator
static const unsigned int kInfinitePlayCount
 Frame count value to denote infinite looping.
 

Detailed Description

Definition at line 183 of file image_generator.h.

Constructor & Destructor Documentation

◆ ~BuiltinSkiaCodecImageGenerator()

flutter::BuiltinSkiaCodecImageGenerator::~BuiltinSkiaCodecImageGenerator ( )
default

◆ BuiltinSkiaCodecImageGenerator() [1/2]

flutter::BuiltinSkiaCodecImageGenerator::BuiltinSkiaCodecImageGenerator ( std::unique_ptr< SkCodec codec)
explicit

Definition at line 98 of file image_generator.cc.

100 : codec_(std::move(codec)) {
101 image_info_ = getInfoIncludingExif(codec_.get());
102}
static SkImageInfo getInfoIncludingExif(SkCodec *codec)

◆ BuiltinSkiaCodecImageGenerator() [2/2]

flutter::BuiltinSkiaCodecImageGenerator::BuiltinSkiaCodecImageGenerator ( sk_sp< SkData buffer)
explicit

Definition at line 104 of file image_generator.cc.

106 : codec_(SkCodec::MakeFromData(std::move(buffer)).release()) {
107 image_info_ = getInfoIncludingExif(codec_.get());
108}
static std::unique_ptr< SkCodec > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
Definition SkCodec.cpp:241
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

Member Function Documentation

◆ GetFrameCount()

unsigned int flutter::BuiltinSkiaCodecImageGenerator::GetFrameCount ( ) const
overridevirtual

Get the number of frames that the encoded image stores. This method is always expected to be called before GetFrameInfo, as the underlying image decoder may interpret frame information that is then used when calling GetFrameInfo.

Returns
The number of frames that the encoded image stores. This will always be 1 for single-frame images.

Implements flutter::ImageGenerator.

Definition at line 114 of file image_generator.cc.

114 {
115 return codec_->getFrameCount();
116}

◆ GetFrameInfo()

const ImageGenerator::FrameInfo flutter::BuiltinSkiaCodecImageGenerator::GetFrameInfo ( unsigned int  frame_index)
overridevirtual

Get information about a single frame in the context of a multi-frame image, useful for animation and frame blending. This method should only ever be called after GetFrameCount has been called. This information is nonsensical for single-frame images.

Parameters
[in]frame_indexThe index of the frame to get information about.
Returns
Information about the given frame. If the image is single-frame, a default result is returned.
See also
GetFrameCount

Implements flutter::ImageGenerator.

Definition at line 123 of file image_generator.cc.

124 {
126 codec_->getFrameInfo(frame_index, &info);
127 return {
128 .required_frame = info.fRequiredFrame == SkCodec::kNoFrame
129 ? std::nullopt
130 : std::optional<unsigned int>(info.fRequiredFrame),
131 .duration = static_cast<unsigned int>(info.fDuration),
132 .disposal_method = info.fDisposalMethod};
133}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static constexpr int kNoFrame
Definition SkCodec.h:650

◆ GetInfo()

const SkImageInfo & flutter::BuiltinSkiaCodecImageGenerator::GetInfo ( )
overridevirtual

Returns basic information about the contents of the encoded image. This information can almost always be collected by just interpreting the header of a decoded image.

Returns
Size and color information describing the image.
Note
This method is executed on the UI thread and used for layout purposes by the framework, and so this method should not perform long synchronous tasks.

Implements flutter::ImageGenerator.

Definition at line 110 of file image_generator.cc.

110 {
111 return image_info_;
112}

◆ GetPixels()

bool flutter::BuiltinSkiaCodecImageGenerator::GetPixels ( const SkImageInfo info,
void *  pixels,
size_t  row_bytes,
unsigned int  frame_index = 0,
std::optional< unsigned int prior_frame = std::nullopt 
)
overridevirtual

Decode the image into a given buffer. This method is currently always used for sub-pixel image decoding. For full-sized still images, GetImage is always attempted first.

Parameters
[in]infoThe desired size and color info of the decoded image to be returned. The implementation of GetScaledDimensions determines which sizes are supported by the image decoder.
[in]pixelsThe location where the raw decoded image data should be written.
[in]row_bytesThe total number of bytes that should make up a single row of decoded image data (i.e. width * bytes_per_pixel).
[in]frame_indexWhich frame to decode. This is only useful for multi-frame images.
[in]prior_frameOptional frame index parameter for multi-frame images which specifies the previous frame that should be use for blending. This hints to the decoder that it should use a previously cached frame instead of decoding dependency frame(s). If an empty value is supplied, the decoder should decode any necessary frames first.
Returns
True if the image was successfully decoded.
Note
This method performs potentially long synchronous work, and so it should never be executed on the UI thread. Image decoders do not require GPU acceleration, and so threads without a GPU context may also be used.
See also
GetScaledDimensions

Implements flutter::ImageGenerator.

Definition at line 144 of file image_generator.cc.

149 {
151 options.fFrameIndex = frame_index;
152 if (prior_frame.has_value()) {
153 options.fPriorFrame = prior_frame.value();
154 }
155 SkEncodedOrigin origin = codec_->getOrigin();
156
157 SkPixmap output_pixmap(info, pixels, row_bytes);
158 SkPixmap temp_pixmap;
159 SkBitmap temp_bitmap;
160 if (origin == kTopLeft_SkEncodedOrigin) {
161 // We can decode directly into the output buffer.
162 temp_pixmap = output_pixmap;
163 } else {
164 // We need to decode into a different buffer so we can re-orient
165 // the pixels later.
166 SkImageInfo temp_info = output_pixmap.info();
168 // We'll be decoding into a buffer that has height and width swapped.
169 temp_info = SkPixmapUtils::SwapWidthHeight(temp_info);
170 }
171 if (!temp_bitmap.tryAllocPixels(temp_info)) {
172 FML_DLOG(ERROR) << "Failed to allocate memory for bitmap of size "
173 << temp_info.computeMinByteSize() << "B";
174 return false;
175 }
176 temp_pixmap = temp_bitmap.pixmap();
177 }
178
179 SkCodec::Result result = codec_->getPixels(temp_pixmap, &options);
180 if (result != SkCodec::kSuccess) {
181 FML_DLOG(WARNING) << "codec could not get pixels. "
183 return false;
184 }
185 if (origin == kTopLeft_SkEncodedOrigin) {
186 return true;
187 }
188 return SkPixmapUtils::Orient(output_pixmap, temp_pixmap, origin);
189}
const char * options
SkEncodedOrigin
@ kTopLeft_SkEncodedOrigin
static bool SkEncodedOriginSwapsWidthHeight(SkEncodedOrigin origin)
const SkPixmap & pixmap() const
Definition SkBitmap.h:133
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:271
static const char * ResultToString(Result)
Definition SkCodec.cpp:880
@ kSuccess
Definition SkCodec.h:80
GAsyncResult * result
#define FML_DLOG(severity)
Definition logging.h:102
SK_API bool Orient(const SkPixmap &dst, const SkPixmap &src, SkEncodedOrigin origin)
SK_API SkImageInfo SwapWidthHeight(const SkImageInfo &info)
size_t computeMinByteSize() const
#define ERROR(message)

◆ GetPlayCount()

unsigned int flutter::BuiltinSkiaCodecImageGenerator::GetPlayCount ( ) const
overridevirtual

The number of times an animated image should play through before playback stops.

Returns
If this image is animated, the number of times the animation should play through is returned, otherwise it'll just return 1. If the animation should loop forever, kInfinitePlayCount is returned.

Implements flutter::ImageGenerator.

Definition at line 118 of file image_generator.cc.

118 {
119 auto repetition_count = codec_->getRepetitionCount();
120 return repetition_count < 0 ? kInfinitePlayCount : repetition_count + 1;
121}
static const unsigned int kInfinitePlayCount
Frame count value to denote infinite looping.

◆ GetScaledDimensions()

SkISize flutter::BuiltinSkiaCodecImageGenerator::GetScaledDimensions ( float  scale)
overridevirtual

Given a scale value, find the closest image size that can be used for efficiently decoding the image. If subpixel image decoding is not supported by the decoder, this method should just return the original image size.

Parameters
[in]scaleThe desired scale factor of the image for decoding.
Returns
The closest image size that can be used for efficiently decoding the image.
Note
This method is called prior to GetPixels in order to query for supported sizes.
See also
GetPixels

Implements flutter::ImageGenerator.

Definition at line 135 of file image_generator.cc.

136 {
137 SkISize size = codec_->getScaledDimensions(desired_scale);
138 if (SkEncodedOriginSwapsWidthHeight(codec_->getOrigin())) {
139 std::swap(size.fWidth, size.fHeight);
140 }
141 return size;
142}
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
Definition switches.h:259

◆ MakeFromData()

std::unique_ptr< ImageGenerator > flutter::BuiltinSkiaCodecImageGenerator::MakeFromData ( sk_sp< SkData data)
static

Definition at line 191 of file image_generator.cc.

192 {
193 auto codec = SkCodec::MakeFromData(std::move(data));
194 if (!codec) {
195 return nullptr;
196 }
197 return std::make_unique<BuiltinSkiaCodecImageGenerator>(std::move(codec));
198}
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

The documentation for this class was generated from the following files: