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

#include <android_image_generator.h>

Inheritance diagram for flutter::AndroidImageGenerator:
flutter::ImageGenerator

Public Member Functions

 ~AndroidImageGenerator ()
 
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, std::optional< unsigned int > prior_frame) 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...
 
void DecodeImage ()
 
- 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 bool Register (JNIEnv *env)
 
static std::shared_ptr< ImageGeneratorMakeFromData (sk_sp< SkData > data, const fml::RefPtr< fml::TaskRunner > &task_runner)
 
static void NativeImageHeaderCallback (JNIEnv *env, jclass jcaller, jlong generator_pointer, int width, int height)
 

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 17 of file android_image_generator.h.

Constructor & Destructor Documentation

◆ ~AndroidImageGenerator()

flutter::AndroidImageGenerator::~AndroidImageGenerator ( )
default

Member Function Documentation

◆ DecodeImage()

void flutter::AndroidImageGenerator::DecodeImage ( )

Definition at line 87 of file android_image_generator.cc.

87 {
88 DoDecodeImage();
89
90 header_decoded_latch_.Signal();
91 fully_decoded_latch_.Signal();
92}

◆ GetFrameCount()

unsigned int flutter::AndroidImageGenerator::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 32 of file android_image_generator.cc.

32 {
33 return 1;
34}

◆ GetFrameInfo()

const ImageGenerator::FrameInfo flutter::AndroidImageGenerator::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 40 of file android_image_generator.cc.

41 {
42 return {.required_frame = std::nullopt,
43 .duration = 0,
45}

◆ GetInfo()

const SkImageInfo & flutter::AndroidImageGenerator::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 27 of file android_image_generator.cc.

27 {
28 header_decoded_latch_.Wait();
29 return image_info_;
30}

◆ GetPixels()

bool flutter::AndroidImageGenerator::GetPixels ( const SkImageInfo info,
void *  pixels,
size_t  row_bytes,
unsigned int  frame_index,
std::optional< unsigned int prior_frame 
)
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 51 of file android_image_generator.cc.

55 {
56 fully_decoded_latch_.Wait();
57
58 if (!software_decoded_data_) {
59 return false;
60 }
61
62 if (kRGBA_8888_SkColorType != info.colorType()) {
63 return false;
64 }
65
66 switch (info.alphaType()) {
68 if (kOpaque_SkAlphaType != GetInfo().alphaType()) {
69 return false;
70 }
71 break;
73 break;
74 default:
75 return false;
76 }
77
78 // TODO(bdero): Override `GetImage()` to use `SkImage::FromAHardwareBuffer` on
79 // API level 30+ once it's updated to do symbol lookups and not get
80 // preprocessed out in Skia. This will allow for avoiding this copy in
81 // cases where the result image doesn't need to be resized.
82 memcpy(pixels, software_decoded_data_->data(),
83 software_decoded_data_->size());
84 return true;
85}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
const void * data() const
Definition: SkData.h:37
size_t size() const
Definition: SkData.h:30
const SkImageInfo & GetInfo() override
Returns basic information about the contents of the encoded image. This information can almost always...

◆ GetPlayCount()

unsigned int flutter::AndroidImageGenerator::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 36 of file android_image_generator.cc.

36 {
37 return 1;
38}

◆ GetScaledDimensions()

SkISize flutter::AndroidImageGenerator::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 47 of file android_image_generator.cc.

47 {
48 return GetInfo().dimensions();
49}
SkISize dimensions() const
Definition: SkImageInfo.h:421

◆ MakeFromData()

std::shared_ptr< ImageGenerator > flutter::AndroidImageGenerator::MakeFromData ( sk_sp< SkData data,
const fml::RefPtr< fml::TaskRunner > &  task_runner 
)
static

Definition at line 175 of file android_image_generator.cc.

177 {
178 std::shared_ptr<AndroidImageGenerator> generator(
179 new AndroidImageGenerator(std::move(data)));
180
182 task_runner, [generator]() { generator->DecodeImage(); });
183
184 if (generator->IsValidImageData()) {
185 return generator;
186 }
187
188 return nullptr;
189}
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
Definition: task_runner.cc:55
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

◆ NativeImageHeaderCallback()

void flutter::AndroidImageGenerator::NativeImageHeaderCallback ( JNIEnv *  env,
jclass  jcaller,
jlong  generator_pointer,
int  width,
int  height 
)
static

Definition at line 191 of file android_image_generator.cc.

195 {
196 AndroidImageGenerator* generator =
197 reinterpret_cast<AndroidImageGenerator*>(generator_address);
198
199 generator->image_info_ = SkImageInfo::Make(
201 generator->header_decoded_latch_.Signal();
202}
int32_t height
int32_t width
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ Register()

bool flutter::AndroidImageGenerator::Register ( JNIEnv *  env)
static

Definition at line 149 of file android_image_generator.cc.

149 {
151 env, env->FindClass("io/flutter/embedding/engine/FlutterJNI"));
152 FML_DCHECK(!g_flutter_jni_class->is_null());
153
154 g_decode_image_method = env->GetStaticMethodID(
155 g_flutter_jni_class->obj(), "decodeImage",
156 "(Ljava/nio/ByteBuffer;J)Landroid/graphics/Bitmap;");
158
159 static const JNINativeMethod header_decoded_method = {
160 .name = "nativeImageHeaderCallback",
161 .signature = "(JII)V",
162 .fnPtr = reinterpret_cast<void*>(
164 };
165 if (env->RegisterNatives(g_flutter_jni_class->obj(), &header_decoded_method,
166 1) != 0) {
168 << "Failed to register FlutterJNI.nativeImageHeaderCallback method";
169 return false;
170 }
171
172 return true;
173}
static void NativeImageHeaderCallback(JNIEnv *env, jclass jcaller, jlong generator_pointer, int width, int height)
#define FML_LOG(severity)
Definition: logging.h:82
#define FML_DCHECK(condition)
Definition: logging.h:103
Definition: __init__.py:1
static jmethodID g_decode_image_method
static fml::jni::ScopedJavaGlobalRef< jclass > * g_flutter_jni_class
#define ERROR(message)
Definition: elf_loader.cc:260

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