Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
flutter::BuiltinSkiaImageGenerator Class Reference

#include <image_generator.h>

Inheritance diagram for flutter::BuiltinSkiaImageGenerator:
flutter::ImageGenerator

Public Member Functions

 ~BuiltinSkiaImageGenerator ()
 
 BuiltinSkiaImageGenerator (std::unique_ptr< SkImageGenerator > generator)
 
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. More...
 
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. More...
 
unsigned int GetPlayCount () const override
 The number of times an animated image should play through before playback stops. More...
 
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. More...
 
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. More...
 
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. More...
 
- Public Member Functions inherited from flutter::ImageGenerator
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 Member Functions

static std::unique_ptr< ImageGeneratorMakeFromGenerator (std::unique_ptr< SkImageGenerator > generator)
 

Additional Inherited Members

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

Detailed Description

Definition at line 144 of file image_generator.h.

Constructor & Destructor Documentation

◆ ~BuiltinSkiaImageGenerator()

flutter::BuiltinSkiaImageGenerator::~BuiltinSkiaImageGenerator ( )
default

◆ BuiltinSkiaImageGenerator()

flutter::BuiltinSkiaImageGenerator::BuiltinSkiaImageGenerator ( std::unique_ptr< SkImageGenerator generator)
explicit

Definition at line 40 of file image_generator.cc.

42 : generator_(std::move(generator)) {}

Member Function Documentation

◆ GetFrameCount()

unsigned int flutter::BuiltinSkiaImageGenerator::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 48 of file image_generator.cc.

48 {
49 return 1;
50}

◆ GetFrameInfo()

const ImageGenerator::FrameInfo flutter::BuiltinSkiaImageGenerator::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 56 of file image_generator.cc.

57 {
58 return {.required_frame = std::nullopt,
59 .duration = 0,
61}

◆ GetInfo()

const SkImageInfo & flutter::BuiltinSkiaImageGenerator::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 44 of file image_generator.cc.

44 {
45 return generator_->getInfo();
46}

◆ GetPixels()

bool flutter::BuiltinSkiaImageGenerator::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 67 of file image_generator.cc.

72 {
73 return generator_->getPixels(info, pixels, row_bytes);
74}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213

◆ GetPlayCount()

unsigned int flutter::BuiltinSkiaImageGenerator::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 52 of file image_generator.cc.

52 {
53 return 1;
54}

◆ GetScaledDimensions()

SkISize flutter::BuiltinSkiaImageGenerator::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 63 of file image_generator.cc.

63 {
64 return generator_->getInfo().dimensions();
65}

◆ MakeFromGenerator()

std::unique_ptr< ImageGenerator > flutter::BuiltinSkiaImageGenerator::MakeFromGenerator ( std::unique_ptr< SkImageGenerator generator)
static

Definition at line 76 of file image_generator.cc.

77 {
78 if (!generator) {
79 return nullptr;
80 }
81 return std::make_unique<BuiltinSkiaImageGenerator>(std::move(generator));
82}

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