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
11#include "third_party/skia/include/android/SkAnimatedImage.h"
12#include "third_party/skia/include/codec/SkAndroidCodec.h"
13#include "third_party/skia/include/codec/SkCodec.h"
14#include "third_party/skia/include/codec/SkGifDecoder.h"
15#include "third_party/skia/include/codec/SkWebpDecoder.h"
16
17namespace {
18std::unique_ptr<SkCodec> getCodecForData(SkData* data) {
19 if (SkGifDecoder::IsGif(data->data(), data->size())) {
20 return SkGifDecoder::Decode(sk_ref_sp(data), nullptr);
21 }
22 if (SkWebpDecoder::IsWebp(data->data(), data->size())) {
23 return SkWebpDecoder::Decode(sk_ref_sp(data), nullptr);
24 }
25 return nullptr;
26}
27} // namespace
28
29SKWASM_EXPORT SkAnimatedImage* animatedImage_create(SkData* data,
30 int target_width,
31 int target_height) {
33 auto codec = getCodecForData(data);
34 if (!codec) {
35 printf("Failed to create codec for animated image.\n");
36 return nullptr;
37 }
38
39 auto android_codec = SkAndroidCodec::MakeFromCodec(std::move(codec));
40 if (android_codec == nullptr) {
41 printf("Failed to create codec for animated image.\n");
42 return nullptr;
43 }
44
45 if (target_width == 0 || target_height == 0) {
46 return SkAnimatedImage::Make(std::move(android_codec)).release();
47 }
48
49 return SkAnimatedImage::Make(
50 std::move(android_codec),
51 SkImageInfo::MakeUnknown(target_width, target_height),
52 SkIRect::MakeWH(target_width, target_height), nullptr)
53 .release();
54}
55
60
62 return image->getFrameCount();
63}
64
66 return image->getRepetitionCount();
67}
68
70 SkAnimatedImage* image) {
71 return image->currentFrameDuration();
72}
73
75 image->decodeNextFrame();
76}
77
79 SkAnimatedImage* image) {
81 return flutter::DlImage::Make(image->getCurrentFrame()).release();
82}
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:32
static sk_sp< DlImage > Make(const SkImage *image)
Definition dl_image.cc:11
FlutterVulkanImage * image
uint32_t live_animated_image_count
uint32_t live_image_count
#define SKWASM_EXPORT
Definition export.h:10
std::shared_ptr< const fml::Mapping > data