Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
skottie::Animation Class Reference

#include <Skottie.h>

Inheritance diagram for skottie::Animation:
SkNVRefCnt< Animation >

Classes

class  Builder
 

Public Types

enum  RenderFlag : uint32_t { kSkipTopLevelIsolation = 0x01 , kDisableTopLevelClipping = 0x02 }
 
using RenderFlags = uint32_t
 

Public Member Functions

 ~Animation ()
 
void render (SkCanvas *canvas, const SkRect *dst=nullptr) const
 
void render (SkCanvas *canvas, const SkRect *dst, RenderFlags) const
 
void seek (SkScalar t, sksg::InvalidationController *ic=nullptr)
 
void seekFrame (double t, sksg::InvalidationController *ic=nullptr)
 
void seekFrameTime (double t, sksg::InvalidationController *=nullptr)
 
double duration () const
 
double fps () const
 
double inPoint () const
 
double outPoint () const
 
const SkStringversion () const
 
const SkSizesize () const
 
- Public Member Functions inherited from SkNVRefCnt< Animation >
 SkNVRefCnt ()
 
 ~SkNVRefCnt ()
 
bool unique () const
 
void ref () const
 
void unref () const
 
void deref () const
 
bool refCntGreaterThan (int32_t threadIsolatedTestCnt) const
 

Static Public Member Functions

static sk_sp< AnimationMake (const char *data, size_t length)
 
static sk_sp< AnimationMake (SkStream *)
 
static sk_sp< AnimationMakeFromFile (const char path[])
 

Detailed Description

Definition at line 93 of file Skottie.h.

Member Typedef Documentation

◆ RenderFlags

Definition at line 220 of file Skottie.h.

Member Enumeration Documentation

◆ RenderFlag

Enumerator
kSkipTopLevelIsolation 
kDisableTopLevelClipping 

Definition at line 210 of file Skottie.h.

210 : uint32_t {
211 // When rendering into a known transparent buffer, clients can pass
212 // this flag to avoid some unnecessary compositing overhead for
213 // animations using layer blend modes.
215 // By default, content is clipped to the intrinsic animation
216 // bounds (as determined by its size). If this flag is set,
217 // then the animation can draw outside of the bounds.
219 };

Constructor & Destructor Documentation

◆ ~Animation()

skottie::Animation::~Animation ( )
default

Member Function Documentation

◆ duration()

double skottie::Animation::duration ( ) const
inline

Returns the animation duration in seconds.

Definition at line 268 of file Skottie.h.

268{ return fDuration; }

◆ fps()

double skottie::Animation::fps ( ) const
inline

Returns the animation frame rate (frames / second).

Definition at line 273 of file Skottie.h.

273{ return fFPS; }

◆ inPoint()

double skottie::Animation::inPoint ( ) const
inline

Animation in point, in frame index units.

Definition at line 278 of file Skottie.h.

278{ return fInPoint; }

◆ Make() [1/2]

sk_sp< Animation > skottie::Animation::Make ( const char *  data,
size_t  length 
)
static

Animation factories.

Use the Builder helper above for more options/control.

Definition at line 534 of file Skottie.cpp.

534 {
535 return Builder().make(data, length);
536}
size_t length
DlVertices::Builder Builder

◆ Make() [2/2]

sk_sp< Animation > skottie::Animation::Make ( SkStream stream)
static

Definition at line 538 of file Skottie.cpp.

538 {
539 return Builder().make(stream);
540}

◆ MakeFromFile()

sk_sp< Animation > skottie::Animation::MakeFromFile ( const char  path[])
static

Definition at line 542 of file Skottie.cpp.

542 {
543 return Builder().makeFromFile(path);
544}

◆ outPoint()

double skottie::Animation::outPoint ( ) const
inline

Animation out point, in frame index units.

Definition at line 283 of file Skottie.h.

283{ return fOutPoint; }

◆ render() [1/2]

void skottie::Animation::render ( SkCanvas canvas,
const SkRect dst,
RenderFlags  renderFlags 
) const

Definition at line 486 of file Skottie.cpp.

486 {
487 TRACE_EVENT0("skottie", TRACE_FUNC);
488
489 if (!fSceneRoot)
490 return;
491
492 SkAutoCanvasRestore restore(canvas, true);
493
494 const SkRect srcR = SkRect::MakeSize(this->size());
495 if (dstR) {
497 }
498
499 if (!(renderFlags & RenderFlag::kDisableTopLevelClipping)) {
500 canvas->clipRect(srcR);
501 }
502
503 if ((fFlags & Flags::kRequiresTopLevelIsolation) &&
504 !(renderFlags & RenderFlag::kSkipTopLevelIsolation)) {
505 // The animation uses non-trivial blending, and needs
506 // to be rendered into a separate/transparent layer.
507 canvas->saveLayer(srcR, nullptr);
508 }
509
510 fSceneRoot->render(canvas);
511}
#define TRACE_FUNC
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition SkCanvas.cpp:500
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void concat(const SkMatrix &matrix)
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
Definition SkMatrix.h:157
@ kCenter_ScaleToFit
scales and aligns to center
Definition SkMatrix.h:139
const SkSize & size() const
Definition Skottie.h:286
void render(SkCanvas *, const RenderContext *=nullptr) const
static constexpr SkRect MakeSize(const SkSize &size)
Definition SkRect.h:633
#define TRACE_EVENT0(category_group, name)

◆ render() [2/2]

void skottie::Animation::render ( SkCanvas canvas,
const SkRect dst = nullptr 
) const

Draws the current animation frame.

It is undefined behavior to call render() on a newly created Animation before specifying an initial frame via one of the seek() variants.

Parameters
canvasdestination canvas
dstoptional destination rect
flagsoptional RenderFlags

Definition at line 482 of file Skottie.cpp.

482 {
483 this->render(canvas, dstR, 0);
484}
void render(SkCanvas *canvas, const SkRect *dst=nullptr) const
Definition Skottie.cpp:482

◆ seek()

void skottie::Animation::seek ( SkScalar  t,
sksg::InvalidationController ic = nullptr 
)
inline

[Deprecated: use one of the other versions.]

Updates the animation state for |t|.

Parameters
tnormalized [0..1] frame selector (0 -> first frame, 1 -> final frame)
icoptional invalidation controller (dirty region tracking)

Definition at line 244 of file Skottie.h.

244 {
245 this->seekFrameTime(t * this->duration(), ic);
246 }
void seekFrameTime(double t, sksg::InvalidationController *=nullptr)
Definition Skottie.cpp:530
double duration() const
Definition Skottie.h:268

◆ seekFrame()

void skottie::Animation::seekFrame ( double  t,
sksg::InvalidationController ic = nullptr 
)

Update the animation state to match |t|, specified as a frame index i.e. relative to duration() * fps().

Fractional values are allowed and meaningful - e.g.

0.0 -> first frame 1.0 -> second frame 0.5 -> halfway between first and second frame

Definition at line 513 of file Skottie.cpp.

513 {
514 TRACE_EVENT0("skottie", TRACE_FUNC);
515
516 if (!fSceneRoot)
517 return;
518
519 // Per AE/Lottie semantics out_point is exclusive.
520 const auto kLastValidFrame = std::nextafterf(fOutPoint, fInPoint),
521 comp_time = SkTPin<float>(fInPoint + t, fInPoint, kLastValidFrame);
522
523 for (const auto& anim : fAnimators) {
524 anim->seek(comp_time);
525 }
526
527 fSceneRoot->revalidate(ic, SkMatrix::I());
528}
static const SkMatrix & I()
const SkRect & revalidate(InvalidationController *, const SkMatrix &)
Definition SkSGNode.cpp:134

◆ seekFrameTime()

void skottie::Animation::seekFrameTime ( double  t,
sksg::InvalidationController ic = nullptr 
)

Update the animation state to match t, specifed in frame time i.e. relative to duration().

Definition at line 530 of file Skottie.cpp.

530 {
531 this->seekFrame(t * fFPS, ic);
532}
void seekFrame(double t, sksg::InvalidationController *ic=nullptr)
Definition Skottie.cpp:513

◆ size()

const SkSize & skottie::Animation::size ( ) const
inline

Definition at line 286 of file Skottie.h.

286{ return fSize; }

◆ version()

const SkString & skottie::Animation::version ( ) const
inline

Definition at line 285 of file Skottie.h.

285{ return fVersion; }

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