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

Commit d9af166a authored by Shan Huang's avatar Shan Huang Committed by Android (Google) Code Review
Browse files

Merge "Avoid reallocating FrameBuffer when bitmaps don't need updating." into main

parents 7c3c32d9 23a23265
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -68,8 +68,9 @@ interface WeatherEffect {
     * @param foreground A bitmap containing the foreground of the image, will be null when
     *   segmentation hasn't finished.
     * @param background A bitmap containing the background of the image
     * @return True if the bitmaps have been updated. False otherwise.
     */
    fun setBitmaps(foreground: Bitmap?, background: Bitmap)
    fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean

    /**
     * Apply matrix to transform coordinates in shaders. In Editor and preview, it's a center crop
+3 −2
Original line number Diff line number Diff line
@@ -93,9 +93,9 @@ abstract class WeatherEffectBase(
        colorGradingShader.setFloatUniform("intensity", colorGradingIntensity * intensity)
    }

    override fun setBitmaps(foreground: Bitmap?, background: Bitmap) {
    override fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean {
        if (this.foreground == foreground && this.background == background) {
            return
            return false
        }
        // Only when background changes, we can infer the bitmap set changes
        if (this.background != background) {
@@ -120,6 +120,7 @@ abstract class WeatherEffectBase(
            BitmapShader(this.foreground, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR),
        )
        adjustCropping(surfaceSize)
        return true
    }

    open fun updateTextureUniforms() {
+3 −1
Original line number Diff line number Diff line
@@ -59,13 +59,15 @@ class NoEffect(

    override fun setIntensity(intensity: Float) {}

    override fun setBitmaps(foreground: Bitmap?, background: Bitmap) {
    override fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean {
        // Only when background changes, we can infer the bitmap set changes
        if (this.background != background) {
            this.background.recycle()
            this.foreground.recycle()
            return false
        }
        this.background = background
        this.foreground = foreground ?: background
        return true
    }
}
+6 −2
Original line number Diff line number Diff line
@@ -92,8 +92,11 @@ class RainEffect(
        createOutlineBuffer()
    }

    override fun setBitmaps(foreground: Bitmap?, background: Bitmap) {
        super.setBitmaps(foreground, background)
    override fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean {
        if (!super.setBitmaps(foreground, background)) {
            return false
        }
        outlineBuffer.close()
        outlineBuffer =
            FrameBuffer(background.width, background.height).apply {
                setRenderEffect(RenderEffect.createBlurEffect(2f, 2f, Shader.TileMode.CLAMP))
@@ -102,6 +105,7 @@ class RainEffect(

        // Need to recreate the outline buffer as the outlineBuffer has changed due to background
        createOutlineBuffer()
        return true
    }

    override val shader: RuntimeShader
+6 −2
Original line number Diff line number Diff line
@@ -97,9 +97,12 @@ class SnowEffect(
        generateAccumulatedSnow()
    }

    override fun setBitmaps(foreground: Bitmap?, background: Bitmap) {
        super.setBitmaps(foreground, background)
    override fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean {
        if (!super.setBitmaps(foreground, background)) {
            return false
        }
        scale = getScale(parallaxMatrix)
        frameBuffer.close()
        frameBuffer =
            FrameBuffer(background.width, background.height).apply {
                setRenderEffect(
@@ -109,6 +112,7 @@ class SnowEffect(
        // GenerateAccumulatedSnow needs foreground for accumulatedSnowShader, and needs frameBuffer
        // which is also changed with background
        generateAccumulatedSnow()
        return true
    }

    override val shader: RuntimeShader