Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dotlottie/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dotlottieRust {
}

group = "com.github.LottieFiles"
version = "0.13.8"
version = "0.14.0"

android {
namespace = "com.lottiefiles.dotlottie.core"
Expand Down
420 changes: 171 additions & 249 deletions dotlottie/src/main/cpp/dotlottie_player.h

Large diffs are not rendered by default.

408 changes: 198 additions & 210 deletions dotlottie/src/main/cpp/jni_bridge.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dotlottie/src/main/cpp/version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dlplayer-version=0.1.56-cfddbc8
dlplayer-version=0.1.57-372c366
api-type=c-api
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,7 @@ class DotLottieController {
fun loadAnimation(
animationId: String,
) {
val result =
dlplayer?.loadAnimation(animationId, this._width.value, this._height.value) ?: false
val result = dlplayer?.loadAnimation(animationId) ?: false

if (result) {
_bufferNeedsUpdate.value = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ fun DotLottieAnimation(
) {
val context = LocalContext.current

remember(context) { DotLottieJNI.ensureAndroidInitialized(context); Unit }

val rController = remember { controller ?: DotLottieController() }

val dlConfig = remember {
Expand Down Expand Up @@ -117,9 +119,9 @@ fun DotLottieAnimation(
}

val ticked = if (rController.stateMachineIsActive) {
dlPlayer.stateMachineTick()
dlPlayer.stateMachineTick(frameTimeNanos)
} else {
dlPlayer.tick()
dlPlayer.tick(frameTimeNanos)
}

// Poll and dispatch events
Expand Down Expand Up @@ -190,11 +192,11 @@ fun DotLottieAnimation(

when (animationData) {
is DotLottieContent.Json -> {
dlPlayer.loadAnimationData(animationData.jsonString, width, height)
dlPlayer.loadAnimationData(animationData.jsonString)
}

is DotLottieContent.Binary -> {
dlPlayer.loadDotlottieData(animationData.data, width, height)
dlPlayer.loadDotlottieData(animationData.data)
}
}

Expand Down Expand Up @@ -297,7 +299,6 @@ fun DotLottieAnimation(
val newBitmap = createBitmap(_width.toInt(), _height.toInt())
val pixelPtr = DotLottieJNI.nativeLockBitmapPixels(newBitmap)
if (pixelPtr == 0L) return@withLock
dlPlayer.resize(_width, _height)
dlPlayer.setSwTarget(pixelPtr, _width, _height)
bitmap = newBitmap
drawVersion++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ internal fun DotLottieGLAnimationHardwareBuffer(
loopCount: UInt = 0u,
) {
val context = LocalContext.current
remember(context) {
com.lottiefiles.dotlottie.core.jni.DotLottiePlayer.ensureAndroidInitialized(context); Unit
}
val rController = remember { controller ?: DotLottieController() }
val initialStateMachineId = remember { stateMachineId }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ internal fun DotLottieGLSurfaceAnimation(
val lifecycleOwner = LocalLifecycleOwner.current

val rController = remember { controller ?: DotLottieController() }
val initialStateMachineId = remember { stateMachineId }

// Hold a reference to the widget so we can interact with it
val glWidgetRef = remember { arrayOfNulls<GLWidget>(1) }
Expand All @@ -61,6 +60,7 @@ internal fun DotLottieGLSurfaceAnimation(
.useFrameInterpolation(useFrameInterpolation)
.marker(marker ?: "")
.loopCount(loopCount)
.stateMachineId(stateMachineId ?: "")
.build()
}

Expand Down Expand Up @@ -119,11 +119,6 @@ internal fun DotLottieGLSurfaceAnimation(
widget.setOnPlayerCreated { player, config ->
rController.setPlayerInstance(player, config)
rController.init()

if (!initialStateMachineId.isNullOrEmpty()) {
rController.stateMachineLoad(initialStateMachineId)
rController.stateMachineStart()
}
}

// Load content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ class DotLottieDrawable(

// stateMachineTick() calls player tick() internally (player is borrowed by state machine)
val ticked = if (stateMachineIsActive) {
player.stateMachineTick()
player.stateMachineTick(frameTimeNanos)
} else {
player.tick()
player.tick(frameTimeNanos)
}

// Poll and dispatch events on main thread
Expand Down Expand Up @@ -289,15 +289,11 @@ class DotLottieDrawable(
// 2. Load animation
when (animationData) {
is DotLottieContent.Json -> {
player.loadAnimationData(
animationData.jsonString,
width.toUInt(),
height.toUInt()
)
player.loadAnimationData(animationData.jsonString)
}

is DotLottieContent.Binary -> {
player.loadDotlottieData(animationData.data, width.toUInt(), height.toUInt())
player.loadDotlottieData(animationData.data)
}
}

Expand Down Expand Up @@ -341,7 +337,6 @@ class DotLottieDrawable(
val pixelPtr = DotLottieJNI.nativeLockBitmapPixels(newBitmap)
if (pixelPtr == 0L) return@withLock
player.setSwTarget(pixelPtr, width.toUInt(), height.toUInt())
player.resize(width.toUInt(), height.toUInt())
bitmapBuffer = newBitmap

// Unlock and recycle old bitmap
Expand Down Expand Up @@ -405,7 +400,7 @@ class DotLottieDrawable(
fun loadAnimation(
animationId: String,
) {
val result = dlPlayer?.loadAnimation(animationId, width.toUInt(), height.toUInt())
val result = dlPlayer?.loadAnimation(animationId)
if (result == true) {
scheduleFrame(forceUpdate = true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,10 @@ internal class GlHardwareRenderer : SharedGlThread.RenderClient {

val loaded = when (content) {
is DotLottieContent.Json -> {
player.loadAnimationData(
content.jsonString,
bufferWidth.toUInt(),
bufferHeight.toUInt()
)
player.loadAnimationData(content.jsonString)
}
is DotLottieContent.Binary -> {
player.loadDotlottieData(
content.data,
bufferWidth.toUInt(),
bufferHeight.toUInt()
)
player.loadDotlottieData(content.data)
}
}
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0)
Expand Down Expand Up @@ -213,7 +205,6 @@ internal class GlHardwareRenderer : SharedGlThread.RenderClient {
createRenderFbo()

val player = dlPlayer ?: return@post
player.resize(width.toUInt(), height.toUInt())
if (buffersValid && renderFboId != 0) {
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, renderFboId)
GLES20.glViewport(0, 0, width, height)
Expand Down Expand Up @@ -341,7 +332,7 @@ internal class GlHardwareRenderer : SharedGlThread.RenderClient {
return player.isPlaying() || player.stateMachineIsActive || !player.isLoaded()
}

override fun onRenderFrame() {
override fun onRenderFrame(frameTimeNanos: Long) {
val player = dlPlayer ?: return
if (bufferWidth <= 0 || bufferHeight <= 0) return
if (!buffersValid) return
Expand Down Expand Up @@ -370,9 +361,9 @@ internal class GlHardwareRenderer : SharedGlThread.RenderClient {

// Tick the player — ThorVG renders into renderFbo
val ticked = if (player.stateMachineIsActive) {
player.stateMachineTick()
player.stateMachineTick(frameTimeNanos)
} else {
player.tick()
player.tick(frameTimeNanos)
}

// Poll and dispatch events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class SharedGlThread private constructor() {

interface RenderClient {
/** Called on the shared GL thread during each choreographer frame. */
fun onRenderFrame()
fun onRenderFrame(frameTimeNanos: Long)
/** Whether this client needs rendering. Checked each frame. */
fun shouldRender(): Boolean
}
Expand Down Expand Up @@ -115,7 +115,7 @@ internal class SharedGlThread private constructor() {
for (client in clients) {
if (client.shouldRender()) {
anyActive = true
client.onRenderFrame()
client.onRenderFrame(frameTimeNanos)
lastRenderedClient = client
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class DotLottieAnimation @JvmOverloads constructor(
private val defStyleRes: Int = 0
) : View(context, attrs, defStyleAttr, defStyleRes) {

init {
com.lottiefiles.dotlottie.core.jni.DotLottiePlayer.ensureAndroidInitialized(context)
}

private var width: Int = 0
private var height: Int = 0
private var mConfig: Config? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class DotLottieGLAnimation @JvmOverloads constructor(
attrs: AttributeSet? = null,
) : TextureView(context, attrs), TextureView.SurfaceTextureListener, SharedGlThread.RenderClient {

init {
com.lottiefiles.dotlottie.core.jni.DotLottiePlayer.ensureAndroidInitialized(context)
}

private val sharedGl = SharedGlThread.instance

private var dlPlayer: DotLottiePlayer? = null
Expand Down Expand Up @@ -296,7 +300,6 @@ class DotLottieGLAnimation @JvmOverloads constructor(
height.toUInt()
)
glTargetDirty = false
player.resize(width.toUInt(), height.toUInt())
dirtyFrame = true
sharedGl.requestRender()
}
Expand Down Expand Up @@ -329,7 +332,7 @@ class DotLottieGLAnimation @JvmOverloads constructor(
return player.isPlaying() || player.stateMachineIsActive
}

override fun onRenderFrame() {
override fun onRenderFrame(frameTimeNanos: Long) {
val player = dlPlayer ?: return
if (!surfaceReady) return
if (surfaceWidth <= 0 || surfaceHeight <= 0) return
Expand Down Expand Up @@ -358,9 +361,9 @@ class DotLottieGLAnimation @JvmOverloads constructor(
GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight)

if (player.stateMachineIsActive) {
player.stateMachineTick()
player.stateMachineTick(frameTimeNanos)
} else {
player.tick()
player.tick(frameTimeNanos)
}

// Blit from render FBO to the window surface's default framebuffer
Expand Down Expand Up @@ -483,18 +486,10 @@ class DotLottieGLAnimation @JvmOverloads constructor(

when (content) {
is DotLottieContent.Json -> {
player.loadAnimationData(
content.jsonString,
surfaceWidth.toUInt(),
surfaceHeight.toUInt()
)
player.loadAnimationData(content.jsonString)
}
is DotLottieContent.Binary -> {
player.loadDotlottieData(
content.data,
surfaceWidth.toUInt(),
surfaceHeight.toUInt()
)
player.loadDotlottieData(content.data)
}
}

Expand Down Expand Up @@ -730,7 +725,7 @@ class DotLottieGLAnimation @JvmOverloads constructor(
fun manifest(): Manifest? = dlPlayer?.manifest()

fun loadAnimation(animationId: String) {
sharedGl.handler.post { dlPlayer?.loadAnimation(animationId, surfaceWidth.toUInt(), surfaceHeight.toUInt()) }
sharedGl.handler.post { dlPlayer?.loadAnimation(animationId) }
}

fun freeze() {
Expand All @@ -751,7 +746,6 @@ class DotLottieGLAnimation @JvmOverloads constructor(
sharedGl.makeCurrent(eglSurface)
destroyRenderFbo()
createRenderFbo()
dlPlayer?.resize(width.toUInt(), height.toUInt())
dlPlayer?.let { player ->
if (renderFboId != 0) {
player.setGlTarget(
Expand Down
Binary file modified dotlottie/src/main/jniLibs/arm64-v8a/libdotlottie_player.so
Binary file not shown.
Binary file modified dotlottie/src/main/jniLibs/armeabi-v7a/libdotlottie_player.so
Binary file not shown.
Binary file modified dotlottie/src/main/jniLibs/x86/libdotlottie_player.so
Binary file not shown.
Binary file modified dotlottie/src/main/jniLibs/x86_64/libdotlottie_player.so
Binary file not shown.
Loading
Loading