5#include "flutter/shell/platform/android/android_image_generator.h"
10#include <android/bitmap.h>
13#include "flutter/fml/platform/android/jni_util.h"
28 header_decoded_latch_.Wait();
32unsigned int AndroidImageGenerator::GetFrameCount()
const {
36unsigned int AndroidImageGenerator::GetPlayCount()
const {
41 unsigned int frame_index) {
47SkISize AndroidImageGenerator::GetScaledDimensions(
float desired_scale) {
48 return GetInfo().dimensions();
54 unsigned int frame_index,
55 std::optional<unsigned int> prior_frame) {
56 fully_decoded_latch_.Wait();
58 if (!software_decoded_data_) {
66 switch (
info.alphaType()) {
82 memcpy(pixels, software_decoded_data_->data(),
83 software_decoded_data_->size());
87void AndroidImageGenerator::DecodeImage() {
90 header_decoded_latch_.Signal();
91 fully_decoded_latch_.Signal();
94void AndroidImageGenerator::DoDecodeImage() {
106 jobject direct_buffer =
107 env->NewDirectByteBuffer(
const_cast<void*
>(data_->data()), data_->size());
109 auto bitmap = std::make_unique<fml::jni::ScopedJavaGlobalRef<jobject>>(
112 reinterpret_cast<jlong
>(
this)));
119 AndroidBitmapInfo
info;
120 [[maybe_unused]]
int status;
121 if ((status = AndroidBitmap_getInfo(
env,
bitmap->obj(), &
info)) < 0) {
122 FML_DLOG(
ERROR) <<
"Failed to get bitmap info, status=" << status;
130 if ((status = AndroidBitmap_lockPixels(
env,
bitmap->obj(), &pixel_lock)) <
132 FML_DLOG(
ERROR) <<
"Failed to lock pixels, error=" << status;
140 AndroidBitmap_unlockPixels(
env,
bitmap->obj());
145 pixel_lock,
info.width *
info.height *
sizeof(uint32_t), on_release,
151 env,
env->FindClass(
"io/flutter/embedding/engine/FlutterJNI"));
156 "(Ljava/nio/ByteBuffer;J)Landroid/graphics/Bitmap;");
159 static const JNINativeMethod header_decoded_method = {
160 .name =
"nativeImageHeaderCallback",
161 .signature =
"(JII)V",
162 .fnPtr =
reinterpret_cast<void*
>(
163 &AndroidImageGenerator::NativeImageHeaderCallback),
168 <<
"Failed to register FlutterJNI.nativeImageHeaderCallback method";
175std::shared_ptr<ImageGenerator> AndroidImageGenerator::MakeFromData(
178 std::shared_ptr<AndroidImageGenerator> generator(
182 task_runner, [generator]() { generator->DecodeImage(); });
184 if (generator->IsValidImageData()) {
191void AndroidImageGenerator::NativeImageHeaderCallback(JNIEnv*
env,
193 jlong generator_address,
201 generator->header_decoded_latch_.
Signal();
204bool AndroidImageGenerator::IsValidImageData() {
210 return GetInfo().height() != -1;
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kOpaque_SkAlphaType
pixel is opaque
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
void(* ReleaseProc)(const void *ptr, void *context)
static sk_sp< SkData > MakeWithProc(const void *ptr, size_t length, ReleaseProc proc, void *ctx)
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
#define FML_DLOG(severity)
#define FML_LOG(severity)
#define FML_CHECK(condition)
#define FML_DCHECK(condition)
static jmethodID g_decode_image_method
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
static fml::jni::ScopedJavaGlobalRef< jclass > * g_flutter_jni_class
JNIEnv * AttachCurrentThread()
bool CheckException(JNIEnv *env)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
Info about a single frame in the context of a multi-frame image, useful for animation and blending.
std::optional< unsigned int > required_frame
std::shared_ptr< const fml::Mapping > data