Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f0956b91 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix generate frame buffer being called unnecessarily when matrix...

Merge "Fix generate frame buffer being called unnecessarily when matrix changes due to the precision of bitmapScale" into main
parents aedb3b8c fb888de8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -122,7 +122,7 @@ vec4 main(float2 fragCoord) {
    // 1.4. Blend with the foreground. Any effect from here will be in front of the subject.
    color.rgb = normalBlend(color.rgb, colorForeground.rgb, colorForeground.a);

    // (1.5. Draw splashes)
    // 1.5. Draw splashes
    color.rgb = drawSplashes(uv, fragCoord, color.rgb);

    // 1.6. Generate a layer of rain in front of the subject (bigger and faster).
+7 −0
Original line number Diff line number Diff line
@@ -138,4 +138,11 @@ abstract class WeatherEffectBase(
            BitmapShader(background, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR),
        )
    }

    companion object {
        // When extracting the scale from the parallax matrix, there will be a very small difference
        // due to floating-point precision.
        // We use FLOAT_TOLERANCE to avoid triggering actions on these insignificant scale changes.
        const val FLOAT_TOLERANCE = 0.0001F
    }
}
+23 −3
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.google.android.wallpaper.weathereffects.graphics.FrameBuffer
import com.google.android.wallpaper.weathereffects.graphics.WeatherEffect.Companion.DEFAULT_INTENSITY
import com.google.android.wallpaper.weathereffects.graphics.WeatherEffectBase
import com.google.android.wallpaper.weathereffects.graphics.utils.GraphicsUtils
import com.google.android.wallpaper.weathereffects.graphics.utils.MatrixUtils.getScale
import com.google.android.wallpaper.weathereffects.graphics.utils.TimeUtils
import java.util.concurrent.Executor

@@ -50,8 +51,8 @@ class RainEffect(
        FrameBuffer(background.width, background.height).apply {
            setRenderEffect(
                RenderEffect.createBlurEffect(
                    2f / bitmapScale,
                    2f / bitmapScale,
                    BLUR_RADIUS / bitmapScale,
                    BLUR_RADIUS / bitmapScale,
                    Shader.TileMode.CLAMP,
                )
            )
@@ -77,13 +78,30 @@ class RainEffect(
        canvas.drawPaint(rainPaint)
    }

    override fun release() {
        super.release()
        outlineBuffer.close()
    }

    override fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean {
        if (!super.setBitmaps(foreground, background)) {
            return false
        }
        outlineBuffer.close()
        outlineBuffer = FrameBuffer(background.width, background.height)

        bitmapScale = getScale(parallaxMatrix)
        // Different from snow effects, we only need to change blur radius when bitmaps change
        // it only gives the range of rain splashes and doesn't influence the visual effects
        outlineBuffer.setRenderEffect(
            RenderEffect.createBlurEffect(
                BLUR_RADIUS / bitmapScale,
                BLUR_RADIUS / bitmapScale,
                Shader.TileMode.CLAMP,
            )
        )

        updateTextureUniforms()
        createOutlineBuffer()
        return true
    }

@@ -109,6 +127,7 @@ class RainEffect(
            "background",
            BitmapShader(super.background, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR),
        )
        createOutlineBuffer()
    }

    /**
@@ -154,5 +173,6 @@ class RainEffect(

    companion object {
        const val MAX_RAIN_OUTLINE_THICKNESS = 11f
        const val BLUR_RADIUS = 2f
    }
}
+10 −10
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.google.android.wallpaper.weathereffects.graphics.utils.MathUtils
import com.google.android.wallpaper.weathereffects.graphics.utils.MatrixUtils.getScale
import com.google.android.wallpaper.weathereffects.graphics.utils.TimeUtils
import java.util.concurrent.Executor
import kotlin.math.abs

/** Defines and generates the rain weather effect animation. */
class SnowEffect(
@@ -107,7 +108,6 @@ class SnowEffect(
        frameBuffer.close()
        frameBuffer = FrameBuffer(background.width, background.height)
        val newScale = getScale(parallaxMatrix)
        if (bitmapScale != newScale) {
        bitmapScale = newScale
        frameBuffer.setRenderEffect(
            RenderEffect.createBlurEffect(
@@ -116,7 +116,6 @@ class SnowEffect(
                Shader.TileMode.CLAMP,
            )
        )
        }
        // GenerateAccumulatedSnow needs foreground for accumulatedSnowShader, and needs frameBuffer
        // which is also changed with background
        generateAccumulatedSnow()
@@ -138,7 +137,8 @@ class SnowEffect(
    override fun setMatrix(matrix: Matrix) {
        val oldScale = bitmapScale
        super.setMatrix(matrix)
        if (bitmapScale != oldScale) {
        // Blur radius should change with scale because it decides the fluffiness of snow
        if (abs(bitmapScale - oldScale) > FLOAT_TOLERANCE) {
            frameBuffer.setRenderEffect(
                RenderEffect.createBlurEffect(
                    BLUR_RADIUS / bitmapScale,