Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
animated_image.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <memory>
6
12#include "third_party/skia/include/android/SkAnimatedImage.h"
13#include "third_party/skia/include/codec/SkAndroidCodec.h"
14#include "third_party/skia/include/codec/SkCodec.h"
15#include "third_party/skia/include/codec/SkGifDecoder.h"
16#include "third_party/skia/include/codec/SkWebpDecoder.h"
17
18namespace {
19std::unique_ptr<SkCodec> getCodecForData(SkData* data) {
20 if (SkGifDecoder::IsGif(data->data(), data->size())) {
21 return SkGifDecoder::Decode(sk_ref_sp(data), nullptr);
22 }
23 if (SkWebpDecoder::IsWebp(data->data(), data->size())) {
24 return SkWebpDecoder::Decode(sk_ref_sp(data), nullptr);
25 }
26 return nullptr;
27}
28} // namespace
29
30SKWASM_EXPORT SkAnimatedImage* animatedImage_create(SkData* data,
31 int target_width,
32 int target_height) {
34 auto codec = getCodecForData(data);
35 if (!codec) {
36 printf("Failed to create codec for animated image.\n");
37 return nullptr;
38 }
39
40 auto android_codec = SkAndroidCodec::MakeFromCodec(std::move(codec));
41 if (android_codec == nullptr) {
42 printf("Failed to create codec for animated image.\n");
43 return nullptr;
44 }
45
46 if (target_width == 0 || target_height == 0) {
47 return SkAnimatedImage::Make(std::move(android_codec)).release();
48 }
49
50 return SkAnimatedImage::Make(
51 std::move(android_codec),
52 SkImageInfo::MakeUnknown(target_width, target_height),
53 SkIRect::MakeWH(target_width, target_height), nullptr)
54 .release();
55}
56
61
63 return image->getFrameCount();
64}
65
67 return image->getRepetitionCount();
68}
69
71 SkAnimatedImage* image) {
72 return image->currentFrameDuration();
73}
74
76 image->decodeNextFrame();
77}
78
80 SkAnimatedImage* image) {
82 return flutter::DlImageSkia::Make(image->getCurrentFrame()).release();
83}
SKWASM_EXPORT int animatedImage_getRepetitionCount(SkAnimatedImage *image)
SKWASM_EXPORT int animatedImage_getCurrentFrameDurationMilliseconds(SkAnimatedImage *image)
SKWASM_EXPORT void animatedImage_decodeNextFrame(SkAnimatedImage *image)
SKWASM_EXPORT SkAnimatedImage * animatedImage_create(SkData *data, int target_width, int target_height)
SKWASM_EXPORT int animatedImage_getFrameCount(SkAnimatedImage *image)
SKWASM_EXPORT void animatedImage_dispose(SkAnimatedImage *image)
SKWASM_EXPORT flutter::DlImage * animatedImage_getCurrentFrame(SkAnimatedImage *image)
Represents an image whose allocation is (usually) resident on device memory.
Definition dl_image.h:34
static sk_sp< DlImage > Make(const SkImage *image)
FlutterVulkanImage * image
uint32_t live_animated_image_count
uint32_t live_image_count
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 switch_defs.h:36
#define SKWASM_EXPORT
Definition export.h:10