Internal updates

This commit is contained in:
Kyant0 committed 2025-10-22 21:05:09 +08:00
1 parent 58871de4aa
commit 229d29b3f7
5 files changed
+17 -15

No files matched your search

@@ -342,7 +342,7 @@ private class DrawBackdropNode(
layoutCoordinates = null
}
}
exportedBackdrop?.currentCoordinates = coordinates
exportedBackdrop?.layerCoordinates = coordinates
}
}
@@ -382,6 +382,6 @@ private class DrawBackdropNode(
effectScope.reset()
layoutCoordinates = null
exportedBackdrop?.currentCoordinates = null
exportedBackdrop?.layerCoordinates = null
}
}
@@ -3,11 +3,15 @@ package com.kyant.backdrop
import android.graphics.RuntimeShader
import android.os.Build
import androidx.annotation.RequiresApi
import org.intellij.lang.annotations.Language
sealed interface RuntimeShaderCache {
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
fun obtainRuntimeShader(key: String, string: String): RuntimeShader
fun obtainRuntimeShader(
key: String,
@Language("AGSL") string: String
): RuntimeShader
}
internal class RuntimeShaderCacheImpl : RuntimeShaderCache {
@@ -84,15 +84,16 @@ private class CombinedBackdrops(
vararg val backdrops: Backdrop
) : Backdrop {
override val isCoordinatesDependent: Boolean = backdrops.any { it.isCoordinatesDependent }
override val isCoordinatesDependent: Boolean =
backdrops.any { it.isCoordinatesDependent }
override fun DrawScope.drawBackdrop(
density: Density,
coordinates: LayoutCoordinates?,
layerBlock: (GraphicsLayerScope.() -> Unit)?
) {
backdrops.forEach {
with(it) { drawBackdrop(density, coordinates, layerBlock) }
backdrops.forEach { backdrop ->
with(backdrop) { drawBackdrop(density, coordinates, layerBlock) }
}
}
}
@@ -39,7 +39,7 @@ class LayerBackdrop internal constructor(
override val isCoordinatesDependent: Boolean = true
internal var currentCoordinates: LayoutCoordinates? by mutableStateOf(null)
internal var layerCoordinates: LayoutCoordinates? by mutableStateOf(null)
private var inverseLayerScope: InverseLayerScope? = null
@@ -49,12 +49,12 @@ class LayerBackdrop internal constructor(
layerBlock: (GraphicsLayerScope.() -> Unit)?
) {
val coordinates = coordinates ?: return
val currentCoordinates = currentCoordinates ?: return
val layerCoordinates = layerCoordinates ?: return
withTransform({
if (layerBlock != null) {
with(obtainInverseLayerScope()) { inverseTransform(density, layerBlock) }
}
val offset = coordinates.positionInWindow() - currentCoordinates.positionInWindow()
val offset = coordinates.positionInWindow() - layerCoordinates.positionInWindow()
translate(-offset.x, -offset.y)
}) {
drawLayer(graphicsLayer)
@@ -2,7 +2,6 @@ package com.kyant.backdrop.backdrops
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.drawscope.ContentDrawScope
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.layout.LayoutCoordinates
import androidx.compose.ui.node.DrawModifierNode
import androidx.compose.ui.node.GlobalPositionAwareModifierNode
@@ -52,20 +51,18 @@ private class LayerBackdropNode(
override val shouldAutoInvalidate: Boolean = false
private val recordBlock: DrawScope.() -> Unit = { backdrop.onDraw(this as ContentDrawScope) }
override fun ContentDrawScope.draw() {
drawContent()
recordLayer(backdrop.graphicsLayer, block = recordBlock)
recordLayer(backdrop.graphicsLayer) { backdrop.onDraw(this@draw) }
}
override fun onGloballyPositioned(coordinates: LayoutCoordinates) {
if (coordinates.isAttached) {
backdrop.currentCoordinates = coordinates
backdrop.layerCoordinates = coordinates
}
}
override fun onDetach() {
backdrop.currentCoordinates = null
backdrop.layerCoordinates = null
}
}