Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhirkevich Alexander Y authored and Zhirkevich Alexander Y committed Jan 21, 2025
1 parent 36a2a42 commit 50a4063
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.github.alexzhirkevich.compottie

import kotlinx.atomicfu.locks.reentrantLock
import kotlinx.atomicfu.locks.withLock
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock

Expand All @@ -13,7 +11,7 @@ private class RefCountMutex(
@InternalCompottieApi
public class MultiOwnerMutex {

private val lock = reentrantLock()
private val lock = Mutex()
private val mutex = mutableMapOf<Any, RefCountMutex>()

public suspend fun <T> withLock(key: Any, action: suspend () -> T): T {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,25 @@ internal fun DynamicDrawProvider?.applyToPaint(
size: () -> Rect,
gradientCache: GradientCache
) {
this?.color?.let {
paint.color = it.derive(paint.color, state)
}
this?.gradient?.let {
val g = this?.gradient

if (g != null) {
paint.shader = GradientShader(
gradient = it.invoke(state, size()),
gradient = g.invoke(state, size()),
matrix = parentMatrix,
cache = gradientCache
)
} else {
paint.color = this?.color.derive(paint.color, state)
}

var alpha = 1f
paint.alpha = parentAlpha

opacity?.interpolatedNorm(state)?.let {
alpha = (alpha * it).coerceIn(0f,1f)
}

this?.opacity?.let {
alpha = it.derive(alpha, state).coerceIn(0f,1f)
paint.alpha = (paint.alpha * it).coerceIn(0f,1f)
}

paint.alpha = (alpha * parentAlpha).coerceIn(0f,1f)
paint.alpha = this?.opacity.derive(paint.alpha, state).coerceIn(0f,1f)
paint.colorFilter = this?.colorFilter.derive(paint.colorFilter, state)
paint.blendMode = this?.blendMode.derive(paint.blendMode, state)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,30 @@ internal value class LottieBlendMode(val type : Byte){
val Saturation = LottieBlendMode(13)
val Color = LottieBlendMode(14)
val Luminosity = LottieBlendMode(15)

val Add = LottieBlendMode(16)
val Mix = LottieBlendMode(17)
}
}

internal fun LottieBlendMode.asComposeBlendMode() : BlendMode {
return BlendModeMapping[this] ?: BlendMode.SrcOver
return when (this) {
LottieBlendMode.Normal -> BlendMode.SrcOver
LottieBlendMode.Multiply -> BlendMode.Multiply
LottieBlendMode.Screen -> BlendMode.Screen
LottieBlendMode.Overlay -> BlendMode.Overlay
LottieBlendMode.Darken -> BlendMode.Darken
LottieBlendMode.Lighten -> BlendMode.Lighten
LottieBlendMode.ColorDodge -> BlendMode.ColorDodge
LottieBlendMode.ColorBurn -> BlendMode.ColorBurn
LottieBlendMode.HardLight -> BlendMode.Hardlight
LottieBlendMode.SoftLight -> BlendMode.Softlight
LottieBlendMode.Difference -> BlendMode.Difference
LottieBlendMode.Exclusion -> BlendMode.Exclusion
LottieBlendMode.Hue -> BlendMode.Hue
LottieBlendMode.Saturation -> BlendMode.Saturation
LottieBlendMode.Color -> BlendMode.Color
LottieBlendMode.Luminosity -> BlendMode.Luminosity
else -> BlendMode.SrcOver
}
}

private val BlendModeMapping = mapOf(
LottieBlendMode.Normal to BlendMode.SrcOver,
LottieBlendMode.Multiply to BlendMode.Multiply,
LottieBlendMode.Screen to BlendMode.Screen,
LottieBlendMode.Overlay to BlendMode.Overlay,
LottieBlendMode.Darken to BlendMode.Darken,
LottieBlendMode.Lighten to BlendMode.Lighten,
LottieBlendMode.ColorDodge to BlendMode.ColorDodge,
LottieBlendMode.ColorBurn to BlendMode.ColorBurn,
LottieBlendMode.HardLight to BlendMode.Hardlight,
LottieBlendMode.SoftLight to BlendMode.Softlight,
LottieBlendMode.Difference to BlendMode.Difference,
LottieBlendMode.Exclusion to BlendMode.Exclusion,
LottieBlendMode.Hue to BlendMode.Hue,
LottieBlendMode.Saturation to BlendMode.Saturation,
LottieBlendMode.Color to BlendMode.Color,
LottieBlendMode.Luminosity to BlendMode.Luminosity
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.compose.ui.graphics.Matrix
import androidx.compose.ui.graphics.Paint
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.util.fastForEach
import io.github.alexzhirkevich.compottie.dynamic.DynamicFillProvider
import io.github.alexzhirkevich.compottie.dynamic.DynamicShapeLayerProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ internal class GradientFillShape(

roundShape?.applyTo(paint, state)

drawScope.drawIntoCanvas {
it.drawPath(path, paint)
}
drawScope.drawContext.canvas.drawPath(path, paint)
}

override fun getBounds(
Expand Down

0 comments on commit 50a4063

Please sign in to comment.