Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Protected Member Functions | Package Functions | List of all members
org.skia.skottie.SkottieAnimation Class Reference
Inheritance diagram for org.skia.skottie.SkottieAnimation:

Classes

class  Config
 

Public Member Functions

void updateSurface (int width, int height)
 
void start ()
 
void end ()
 
void pause ()
 
void resume ()
 
long getStartDelay ()
 
void setStartDelay (long startDelay)
 
Animator setDuration (long duration)
 
boolean isRunning ()
 
long getDuration ()
 
long getTotalDuration ()
 
void setInterpolator (TimeInterpolator value)
 
void setProgress (float progress)
 
float getProgress ()
 
void doFrame (long frameTimeNanos)
 
void onSurfaceTextureAvailable (SurfaceTexture surface, int width, int height)
 
void onSurfaceTextureSizeChanged (SurfaceTexture surface, int width, int height)
 
boolean onSurfaceTextureDestroyed (SurfaceTexture surface)
 
void onSurfaceTextureUpdated (SurfaceTexture surfaceTexture)
 
void surfaceCreated (SurfaceHolder holder)
 
void surfaceChanged (SurfaceHolder holder, int format, int width, int height)
 
void surfaceDestroyed (SurfaceHolder holder)
 

Protected Member Functions

void finalize () throws Throwable
 

Package Functions

 SkottieAnimation (SurfaceTexture surfaceTexture, InputStream is)
 
 SkottieAnimation (TextureView view, InputStream is, int backgroundColor, int repeatCount)
 
 SkottieAnimation (SurfaceView view, InputStream is, int backgroundColor, int repeatCount)
 
void setSurfaceTexture (SurfaceTexture s)
 
Config getBackingViewConfig ()
 
void setBackingViewConfig (Config config)
 

Detailed Description

Definition at line 25 of file SkottieAnimation.java.

Constructor & Destructor Documentation

◆ SkottieAnimation() [1/3]

org.skia.skottie.SkottieAnimation.SkottieAnimation ( SurfaceTexture  surfaceTexture,
InputStream  is 
)
inlinepackage

Definition at line 50 of file SkottieAnimation.java.

50 {
51 if (init(is)) {
52 mSurfaceTexture = surfaceTexture;
53 }
54 }

◆ SkottieAnimation() [2/3]

org.skia.skottie.SkottieAnimation.SkottieAnimation ( TextureView  view,
InputStream  is,
int  backgroundColor,
int  repeatCount 
)
inlinepackage

Definition at line 55 of file SkottieAnimation.java.

55 {
56 if (init(is)) {
57 mSurfaceTexture = view.getSurfaceTexture();
58 }
59 view.setSurfaceTextureListener(this);
60 mBackgroundColor = backgroundColor;
61 mRepeatCount = repeatCount;
62 mRepeatCounter = mRepeatCount;
63 }

◆ SkottieAnimation() [3/3]

org.skia.skottie.SkottieAnimation.SkottieAnimation ( SurfaceView  view,
InputStream  is,
int  backgroundColor,
int  repeatCount 
)
inlinepackage

Definition at line 65 of file SkottieAnimation.java.

65 {
66 if (init(is)) {
67 mSurfaceHolder = view.getHolder();
68 }
69 mSurfaceHolder.addCallback(this);
70 mBackgroundColor = backgroundColor;
71 mRepeatCount = repeatCount;
72 mRepeatCounter = mRepeatCount;
73 }

Member Function Documentation

◆ doFrame()

void org.skia.skottie.SkottieAnimation.doFrame ( long  frameTimeNanos)
inline

Definition at line 378 of file SkottieAnimation.java.

378 {
379 if (mIsRunning) {
380 // Schedule next frame.
381 Choreographer.getInstance().postFrameCallback(this);
382
383 // Advance animation.
384 long durationNS = mDuration * 1000000;
385 long timeSinceAnimationStartNS = frameTimeNanos - mAnimationStartTime;
386 long animationProgressNS = timeSinceAnimationStartNS % durationNS;
387 mProgress = animationProgressNS / (float)durationNS;
388 if (timeSinceAnimationStartNS > durationNS) {
389 mAnimationStartTime += durationNS; // prevents overflow
390 }
391 if (timeSinceAnimationStartNS > durationNS) {
392 if (mRepeatCounter > 0) {
393 mRepeatCounter--;
394 } else if (mRepeatCounter == 0) {
395 mIsRunning = false;
396 mProgress = 1;
397 notifyAnimationEnd();
398 }
399 }
400 }
401 if (config.mValidSurface) {
402 drawFrame();
403 }
404 }

◆ end()

void org.skia.skottie.SkottieAnimation.end ( )
inline

Definition at line 176 of file SkottieAnimation.java.

176 {
177 try {
178 mRunner.runOnGLThread(() -> {
179 mIsRunning = false;
180 if (mEglSurface != null) {
181 // Ensure we always have a valid surface & context.
182 mRunner.mEgl.eglMakeCurrent(mRunner.mEglDisplay, mRunner.mPBufferSurface,
183 mRunner.mPBufferSurface, mRunner.mEglContext);
184 mRunner.mEgl.eglDestroySurface(mRunner.mEglDisplay, mEglSurface);
185 mEglSurface = null;
186 }
187 });
188 }
189 catch (Throwable t) {
190 Log.e(LOG_TAG, "stop failed", t);
191 throw new RuntimeException(t);
192 }
193 notifyAnimationEnd();
194 }
void Log(const char *format,...) SK_PRINTF_LIKE(1
Definition: TestRunner.cpp:137

◆ finalize()

void org.skia.skottie.SkottieAnimation.finalize ( ) throws Throwable
inlineprotected

Definition at line 132 of file SkottieAnimation.java.

132 {
133 try {
134 end();
135 nDeleteProxy(mNativeProxy);
136 mNativeProxy = 0;
137 } finally {
138 super.finalize();
139 }
140 }

◆ getBackingViewConfig()

Config org.skia.skottie.SkottieAnimation.getBackingViewConfig ( )
inlinepackage

Definition at line 467 of file SkottieAnimation.java.

467 {
468 return config;
469 }

◆ getDuration()

long org.skia.skottie.SkottieAnimation.getDuration ( )
inline

Definition at line 251 of file SkottieAnimation.java.

251 {
252 return mDuration;
253 }

◆ getProgress()

float org.skia.skottie.SkottieAnimation.getProgress ( )
inline

Definition at line 287 of file SkottieAnimation.java.

287 {
288 return mProgress;
289 }

◆ getStartDelay()

long org.skia.skottie.SkottieAnimation.getStartDelay ( )
inline

Definition at line 230 of file SkottieAnimation.java.

230 {
231 return 0;
232 }

◆ getTotalDuration()

long org.skia.skottie.SkottieAnimation.getTotalDuration ( )
inline

Definition at line 256 of file SkottieAnimation.java.

256 {
257 if (mRepeatCount == -1) {
258 return DURATION_INFINITE;
259 }
260 // TODO: add start delay when implemented
261 return mDuration * (1 + mRepeatCount);
262 }

◆ isRunning()

boolean org.skia.skottie.SkottieAnimation.isRunning ( )
inline

Definition at line 246 of file SkottieAnimation.java.

246 {
247 return mIsRunning;
248 }

◆ onSurfaceTextureAvailable()

void org.skia.skottie.SkottieAnimation.onSurfaceTextureAvailable ( SurfaceTexture  surface,
int  width,
int  height 
)
inline

Definition at line 407 of file SkottieAnimation.java.

407 {
408 // will be called on UI thread
409 try {
410 mRunner.runOnGLThread(() -> {
411 mSurfaceTexture = surface;
413 config.mValidSurface = true;
414 });
415 }
416 catch (Throwable t) {
417 Log.e(LOG_TAG, "updateSurface failed", t);
418 throw new RuntimeException(t);
419 }
420 }
void updateSurface(int width, int height)
VkSurfaceKHR surface
Definition: main.cc:49
int32_t height
int32_t width

◆ onSurfaceTextureDestroyed()

boolean org.skia.skottie.SkottieAnimation.onSurfaceTextureDestroyed ( SurfaceTexture  surface)
inline

Definition at line 429 of file SkottieAnimation.java.

429 {
430 // will be called on UI thread
431 onSurfaceTextureAvailable(null, 0, 0);
432 config.mValidSurface = false;
433 return true;
434 }
void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)

◆ onSurfaceTextureSizeChanged()

void org.skia.skottie.SkottieAnimation.onSurfaceTextureSizeChanged ( SurfaceTexture  surface,
int  width,
int  height 
)
inline

Definition at line 423 of file SkottieAnimation.java.

423 {
424 // will be called on UI thread
426 }

◆ onSurfaceTextureUpdated()

void org.skia.skottie.SkottieAnimation.onSurfaceTextureUpdated ( SurfaceTexture  surfaceTexture)
inline

Definition at line 437 of file SkottieAnimation.java.

437 {
438
439 }

◆ pause()

void org.skia.skottie.SkottieAnimation.pause ( )
inline

Definition at line 197 of file SkottieAnimation.java.

197 {
198 try {
199 mRunner.runOnGLThread(() -> {
200 mIsRunning = false;
201 });
202 }
203 catch (Throwable t) {
204 Log.e(LOG_TAG, "pause failed", t);
205 throw new RuntimeException(t);
206 }
207 }

◆ resume()

void org.skia.skottie.SkottieAnimation.resume ( )
inline

Definition at line 210 of file SkottieAnimation.java.

210 {
211 try {
212 mRunner.runOnGLThread(() -> {
213 if (!mIsRunning) {
214 long currentTime = System.nanoTime();
215 mAnimationStartTime = currentTime - (long)(1000000 * mDuration * mProgress);
216 mIsRunning = true;
217 mNewSurface = true;
218 doFrame(currentTime);
219 }
220 });
221 }
222 catch (Throwable t) {
223 Log.e(LOG_TAG, "resume failed", t);
224 throw new RuntimeException(t);
225 }
226 }
void doFrame(long frameTimeNanos)

◆ setBackingViewConfig()

void org.skia.skottie.SkottieAnimation.setBackingViewConfig ( Config  config)
inlinepackage

Definition at line 471 of file SkottieAnimation.java.

471 {
472 this.config.mSurfaceHeight = config.mSurfaceHeight;
473 this.config.mSurfaceWidth = config.mSurfaceWidth;
474 this.config.mValidSurface = config.mValidSurface;
475 }

◆ setDuration()

Animator org.skia.skottie.SkottieAnimation.setDuration ( long  duration)
inline

Definition at line 241 of file SkottieAnimation.java.

241 {
242 return null;
243 }

◆ setInterpolator()

void org.skia.skottie.SkottieAnimation.setInterpolator ( TimeInterpolator  value)
inline

Definition at line 266 of file SkottieAnimation.java.

266 {
267
268 }

◆ setProgress()

void org.skia.skottie.SkottieAnimation.setProgress ( float  progress)
inline

Definition at line 270 of file SkottieAnimation.java.

270 {
271 try {
272 mRunner.runOnGLThread(() -> {
273 mProgress = progress;
274 if (mIsRunning) {
275 mAnimationStartTime = System.nanoTime()
276 - (long)(1000000 * mDuration * mProgress);
277 }
278 drawFrame();
279 });
280 }
281 catch (Throwable t) {
282 Log.e(LOG_TAG, "setProgress failed", t);
283 throw new RuntimeException(t);
284 }
285 }

◆ setStartDelay()

void org.skia.skottie.SkottieAnimation.setStartDelay ( long  startDelay)
inline

Definition at line 236 of file SkottieAnimation.java.

236 {
237
238 }

◆ setSurfaceTexture()

void org.skia.skottie.SkottieAnimation.setSurfaceTexture ( SurfaceTexture  s)
inlinepackage

Definition at line 75 of file SkottieAnimation.java.

75 {
76 mSurfaceTexture = s;
77 }
struct MyStruct s

◆ start()

void org.skia.skottie.SkottieAnimation.start ( )
inline

Definition at line 151 of file SkottieAnimation.java.

151 {
152 try {
153 mRunner.runOnGLThread(() -> {
154 if (!mIsRunning) {
155 long currentTime = System.nanoTime();
156 mAnimationStartTime = currentTime - (long)(1000000 * mDuration * mProgress);
157 mIsRunning = true;
158 mNewSurface = true;
159 mRepeatCounter = mRepeatCount;
160 doFrame(currentTime);
161 }
162 });
163 }
164 catch (Throwable t) {
165 Log.e(LOG_TAG, "start failed", t);
166 throw new RuntimeException(t);
167 }
168 if (this.getListeners() != null) {
169 for (AnimatorListener l : this.getListeners()) {
170 l.onAnimationStart(this);
171 }
172 }
173 }

◆ surfaceChanged()

void org.skia.skottie.SkottieAnimation.surfaceChanged ( SurfaceHolder  holder,
int  format,
int  width,
int  height 
)
inline

Definition at line 447 of file SkottieAnimation.java.

447 {
448 try {
449 mRunner.runOnGLThread(() -> {
450 mSurfaceHolder = holder;
452 config.mValidSurface = true;
453 });
454 }
455 catch (Throwable t) {
456 Log.e(LOG_TAG, "updateSurface failed", t);
457 throw new RuntimeException(t);
458 }
459 }

◆ surfaceCreated()

void org.skia.skottie.SkottieAnimation.surfaceCreated ( SurfaceHolder  holder)
inline

Definition at line 443 of file SkottieAnimation.java.

443 {
444 }

◆ surfaceDestroyed()

void org.skia.skottie.SkottieAnimation.surfaceDestroyed ( SurfaceHolder  holder)
inline

Definition at line 462 of file SkottieAnimation.java.

462 {
463 config.mValidSurface = false;
464 surfaceChanged(null, 0, 0, 0);
465 }
void surfaceChanged(SurfaceHolder holder, int format, int width, int height)

◆ updateSurface()

void org.skia.skottie.SkottieAnimation.updateSurface ( int  width,
int  height 
)
inline

Definition at line 143 of file SkottieAnimation.java.

143 {
144 config.mSurfaceWidth = width;
145 config.mSurfaceHeight = height;
146 mNewSurface = true;
147 drawFrame();
148 }

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