Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SkAnimCodecPlayer Class Reference

#include <SkAnimCodecPlayer.h>

Public Member Functions

 SkAnimCodecPlayer (std::unique_ptr< SkCodec > codec)
 
 ~SkAnimCodecPlayer ()
 
sk_sp< SkImagegetFrame ()
 
SkISize dimensions () const
 
uint32_t duration () const
 
bool seek (uint32_t msec)
 

Detailed Description

Definition at line 22 of file SkAnimCodecPlayer.h.

Constructor & Destructor Documentation

◆ SkAnimCodecPlayer()

SkAnimCodecPlayer::SkAnimCodecPlayer ( std::unique_ptr< SkCodec codec)

Definition at line 32 of file SkAnimCodecPlayer.cpp.

32 : fCodec(std::move(codec)) {
33 fImageInfo = fCodec->getInfo();
34 fFrameInfos = fCodec->getFrameInfo();
35 fImages.resize(fFrameInfos.size());
36
37 // change the interpretation of fDuration to a end-time for that frame
38 size_t dur = 0;
39 for (auto& f : fFrameInfos) {
40 dur += f.fDuration;
41 f.fDuration = dur;
42 }
43 fTotalDuration = dur;
44
45 if (!fTotalDuration) {
46 // Static image -- may or may not have returned a single frame info.
47 fFrameInfos.clear();
48 fImages.clear();
49 fImages.push_back(SkImages::DeferredFromGenerator(
50 SkCodecImageGenerator::MakeFromCodec(std::move(fCodec))));
51 }
52}
static std::unique_ptr< SkImageGenerator > MakeFromCodec(std::unique_ptr< SkCodec >, std::optional< SkAlphaType >=std::nullopt)
SK_API sk_sp< SkImage > DeferredFromGenerator(std::unique_ptr< SkImageGenerator > imageGenerator)

◆ ~SkAnimCodecPlayer()

SkAnimCodecPlayer::~SkAnimCodecPlayer ( )

Definition at line 54 of file SkAnimCodecPlayer.cpp.

54{}

Member Function Documentation

◆ dimensions()

SkISize SkAnimCodecPlayer::dimensions ( ) const

Return the size of the image(s) that will be returned by getFrame().

Definition at line 56 of file SkAnimCodecPlayer.cpp.

56 {
57 if (!fCodec) {
58 auto image = fImages.front();
60 }
61 if (SkEncodedOriginSwapsWidthHeight(fCodec->getOrigin())) {
62 return { fImageInfo.height(), fImageInfo.width() };
63 }
64 return { fImageInfo.width(), fImageInfo.height() };
65}
static bool SkEncodedOriginSwapsWidthHeight(SkEncodedOrigin origin)
SkISize dimensions() const
Definition SkImage.h:297
sk_sp< SkImage > image
Definition examples.cpp:29
static constexpr SkISize MakeEmpty()
Definition SkSize.h:22
int width() const
int height() const

◆ duration()

uint32_t SkAnimCodecPlayer::duration ( ) const
inline

Returns the total duration of the animation in milliseconds. Returns 0 for a single-frame image.

Definition at line 43 of file SkAnimCodecPlayer.h.

43{ return fTotalDuration; }

◆ getFrame()

sk_sp< SkImage > SkAnimCodecPlayer::getFrame ( )

Returns the current frame of the animation. This defaults to the first frame for animated codecs (i.e. msec = 0). Calling this multiple times (without calling seek()) will always return the same image object (or null if there was an error).

Definition at line 131 of file SkAnimCodecPlayer.cpp.

131 {
132 SkASSERT(fTotalDuration > 0 || fImages.size() == 1);
133
134 return fTotalDuration > 0
135 ? this->getFrameAt(fCurrIndex)
136 : fImages.front();
137}
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ seek()

bool SkAnimCodecPlayer::seek ( uint32_t  msec)

Finds the closest frame associated with the time code (in milliseconds) and sets that to be the current frame (call getFrame() to retrieve that image). Returns true iff this call to seek() changed the "current frame" for the animation. Thus if seek() returns false, then getFrame() will return the same image as it did before this call to seek().

Definition at line 139 of file SkAnimCodecPlayer.cpp.

139 {
140 if (!fTotalDuration) {
141 return false;
142 }
143
144 msec %= fTotalDuration;
145
146 auto lower = std::lower_bound(fFrameInfos.begin(), fFrameInfos.end(), msec,
147 [](const SkCodec::FrameInfo& info, uint32_t msec) {
148 return (uint32_t)info.fDuration <= msec;
149 });
150 int prevIndex = fCurrIndex;
151 fCurrIndex = lower - fFrameInfos.begin();
152 return fCurrIndex != prevIndex;
153}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213

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