Cloudy icon indicating copy to clipboard operation
Cloudy copied to clipboard

Cloudy causes lags during animations

Open frakc opened this issue 1 year ago • 1 comments

Please complete the following information:

  • Library Version [e.g. v0.2.3]
  • Affected Device(s) [e.g. Samsung Galaxy s10 with Android 9.0]

Cloudy redraw is triggered every time and layout change occurs. Eg on code below I anime box which has no relation to blured box. Hoever cloudy is redrawing multiple times per each animation. On pre android12 device it causes significant frame skipps

 Column {
            Box(Modifier.size(300.dp)) {
                val graphicsLayer = rememberGraphicsLayer()

                Box(
                    Modifier
                        .fillMaxSize()
                        .cloudy(
                            80,
                            graphicsLayer = graphicsLayer,
                            onStateChanged = { Timber.e("cloudy ${it.javaClass.simpleName}") })
                        .background(Color.Blue)
                )
            }
            Box(Modifier.size(300.dp)) {

                var satarget by remember { mutableStateOf(false) }
                val sa by animateFloatAsState(if (satarget) 1f else 0f)
                Box(
                    Modifier
                        .height(300.dp * sa)
                        .fillMaxWidth()
                        .background(Color.Red)
                )
                LaunchedEffect(Unit) {
                    while (true) {
                        delay(400)
                        satarget = !satarget
                    }
                }
            }
        }

frakc avatar Oct 01 '24 14:10 frakc

It's a CPU-based blur that's executed in a blocking manner. The blur recalculates whenever the layout updates. I'm not sure if it updates multiple times per frame, but even if it only updates once per frame, it's still a slow CPU-based blurring process. To make it work fast, it needs to be hardware accelerated.

desugar-64 avatar Oct 10 '24 08:10 desugar-64