Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Attributes | List of all members
flutter::ImageGenerator Class Referenceabstract

The minimal interface necessary for defining a decoder that can be used for both single and multi-frame image decoding. Image generators can also optionally support decoding into a subscaled buffer. Implementers of ImageGenerator regularly keep internal state which is not thread safe, and so aliasing and parallel access should never be done with ImageGenerators. More...

#include <image_generator.h>

Inheritance diagram for flutter::ImageGenerator:
flutter::APNGImageGenerator flutter::AndroidImageGenerator flutter::BuiltinSkiaCodecImageGenerator flutter::BuiltinSkiaImageGenerator flutter::testing::FakeImageGenerator flutter::testing::SinglePixelImageGenerator flutter::testing::UnknownImageGenerator

Classes

struct  FrameInfo
 Info about a single frame in the context of a multi-frame image, useful for animation and blending. More...
 

Public Member Functions

virtual ~ImageGenerator ()
 
virtual const SkImageInfoGetInfo ()=0
 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. More...
 
virtual unsigned int GetFrameCount () const =0
 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. More...
 
virtual unsigned int GetPlayCount () const =0
 The number of times an animated image should play through before playback stops. More...
 
virtual const FrameInfo GetFrameInfo (unsigned int frame_index)=0
 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. More...
 
virtual SkISize GetScaledDimensions (float scale)=0
 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. More...
 
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 decoding. For full-sized still images, GetImage is always attempted first. More...
 
sk_sp< SkImageGetImage ()
 Creates an SkImage based on the current ImageInfo of this ImageGenerator. More...
 

Static Public Attributes

static const unsigned int kInfinitePlayCount
 Frame count value to denote infinite looping. More...
 

Detailed Description

The minimal interface necessary for defining a decoder that can be used for both single and multi-frame image decoding. Image generators can also optionally support decoding into a subscaled buffer. Implementers of ImageGenerator regularly keep internal state which is not thread safe, and so aliasing and parallel access should never be done with ImageGenerators.

See also
ImageGenerator::GetScaledDimensions

Definition at line 27 of file image_generator.h.

Constructor & Destructor Documentation

◆ ~ImageGenerator()

flutter::ImageGenerator::~ImageGenerator ( )
virtualdefault

Member Function Documentation

◆ GetFrameCount()

virtual unsigned int flutter::ImageGenerator::GetFrameCount ( ) const
pure virtual

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.

Implemented in flutter::testing::UnknownImageGenerator, flutter::testing::FakeImageGenerator, flutter::testing::SinglePixelImageGenerator, flutter::BuiltinSkiaImageGenerator, flutter::BuiltinSkiaCodecImageGenerator, flutter::APNGImageGenerator, and flutter::AndroidImageGenerator.

◆ GetFrameInfo()

virtual const FrameInfo flutter::ImageGenerator::GetFrameInfo ( unsigned int  frame_index)
pure virtual

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

Implemented in flutter::testing::UnknownImageGenerator, flutter::testing::FakeImageGenerator, flutter::testing::SinglePixelImageGenerator, flutter::BuiltinSkiaImageGenerator, flutter::BuiltinSkiaCodecImageGenerator, flutter::APNGImageGenerator, and flutter::AndroidImageGenerator.

◆ GetImage()

sk_sp< SkImage > flutter::ImageGenerator::GetImage ( )

Creates an SkImage based on the current ImageInfo of this ImageGenerator.

Returns
A new SkImage containing the decoded image data.

Definition at line 19 of file image_generator.cc.

19 {
21
23 if (!bitmap.tryAllocPixels(info)) {
24 FML_DLOG(ERROR) << "Failed to allocate memory for bitmap of size "
25 << info.computeMinByteSize() << "B";
26 return nullptr;
27 }
28
29 const auto& pixmap = bitmap.pixmap();
30 if (!GetPixels(pixmap.info(), pixmap.writable_addr(), pixmap.rowBytes())) {
31 FML_DLOG(ERROR) << "Failed to get pixels for image.";
32 return nullptr;
33 }
34 bitmap.setImmutable();
36}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
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)
Definition: logging.h:102
SK_API sk_sp< SkImage > RasterFromBitmap(const SkBitmap &bitmap)
Definition: bitmap.py:1
#define ERROR(message)
Definition: elf_loader.cc:260

◆ GetInfo()

virtual const SkImageInfo & flutter::ImageGenerator::GetInfo ( )
pure virtual

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.

Implemented in flutter::testing::UnknownImageGenerator, flutter::testing::FakeImageGenerator, flutter::testing::SinglePixelImageGenerator, flutter::BuiltinSkiaImageGenerator, flutter::BuiltinSkiaCodecImageGenerator, flutter::APNGImageGenerator, and flutter::AndroidImageGenerator.

◆ GetPixels()

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

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

Implemented in flutter::testing::UnknownImageGenerator, flutter::testing::FakeImageGenerator, flutter::testing::SinglePixelImageGenerator, flutter::APNGImageGenerator, flutter::AndroidImageGenerator, flutter::BuiltinSkiaImageGenerator, and flutter::BuiltinSkiaCodecImageGenerator.

◆ GetPlayCount()

virtual unsigned int flutter::ImageGenerator::GetPlayCount ( ) const
pure virtual

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.

Implemented in flutter::testing::UnknownImageGenerator, flutter::testing::FakeImageGenerator, flutter::testing::SinglePixelImageGenerator, flutter::BuiltinSkiaImageGenerator, flutter::BuiltinSkiaCodecImageGenerator, flutter::APNGImageGenerator, and flutter::AndroidImageGenerator.

◆ GetScaledDimensions()

virtual SkISize flutter::ImageGenerator::GetScaledDimensions ( float  scale)
pure virtual

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

Implemented in flutter::BuiltinSkiaImageGenerator, flutter::BuiltinSkiaCodecImageGenerator, flutter::APNGImageGenerator, flutter::AndroidImageGenerator, flutter::testing::UnknownImageGenerator, flutter::testing::FakeImageGenerator, and flutter::testing::SinglePixelImageGenerator.

Member Data Documentation

◆ kInfinitePlayCount

const unsigned int flutter::ImageGenerator::kInfinitePlayCount
static
Initial value:
=
static float max(float r, float g, float b)
Definition: hsl.cpp:49

Frame count value to denote infinite looping.

Definition at line 30 of file image_generator.h.


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