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

Commit dea98122 authored by Alec Mouri's avatar Alec Mouri
Browse files

Add workload that draws a blur region over an animating background

Also add plumbing for specifying a blur region

Bug: 405591499
Flag: EXEMPT test only
Test: run apk
Change-Id: Id56307db2eaaecf368b3ea9fb17121c84651a171
parent 60bdbc69
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
        </activity>

        <activity android:name=".activities.BlurOnOffActivity" />
        <activity android:name=".activities.BlurRegionActivity" />
        <activity android:name=".activities.TrivialActivity" />

    </application>
+3 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.widget.ExpandableListView
import android.widget.TextView
import androidx.activity.ComponentActivity
import com.android.test.transactionflinger.activities.BlurOnOffActivity
import com.android.test.transactionflinger.activities.BlurRegionActivity
import com.android.test.transactionflinger.activities.TrivialActivity
import kotlin.reflect.KClass

@@ -42,7 +43,8 @@ private val AllDemos = listOf(
    DemoGroup(
        "Workloads", listOf(
            Demo("TrivialActivity", TrivialActivity::class),
            Demo("BlurOnOffActivity", BlurOnOffActivity::class)
            Demo("BlurOnOffActivity", BlurOnOffActivity::class),
            Demo("BlurRegionActivity", BlurRegionActivity::class)
        )
    )
)
+29 −0
Original line number Diff line number Diff line
@@ -38,6 +38,9 @@ class Scene {
    /** Radius of a blur applied to content behind this scene */
    var backgroundBlurRadius = 0

    /** Region behind which to blur */
    var blurRegion = BlurRegion(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

    /** Location of the top-left position in the x-direction of this scene, on a range of [0, 1] */
    var x = 0.0

@@ -49,6 +52,7 @@ class Scene {

    /** Height of the scene normalized on [0, 1] */
    var height = 1.0

    var startTime = 0L
        private set

@@ -84,6 +88,21 @@ class Scene {
        }
    }

    private fun getBlurRegion(width: Int, height: Int): FloatArray {
        return floatArrayOf(
            blurRegion.blurRadius.toFloat(),
            blurRegion.alpha.toFloat(),
            (blurRegion.left * width).toFloat(),
            (blurRegion.top * height).toFloat(),
            (blurRegion.right * width).toFloat(),
            (blurRegion.bottom * height).toFloat(),
            blurRegion.cornerRadiusTL.toFloat(),
            blurRegion.cornerRadiusTR.toFloat(),
            blurRegion.cornerRadiusBL.toFloat(),
            blurRegion.cornerRadiusBR.toFloat()
        )
    }


    private fun onDraw(
        data: Choreographer.FrameData,
@@ -109,6 +128,10 @@ class Scene {
            it.invoke(this@Scene, data)
            synchronized(transaction) {
                transaction.setBackgroundBlurRadius(surfaceControl, backgroundBlurRadius)
                transaction.setBlurRegions(
                    surfaceControl,
                    arrayOf(getBlurRegion(parentWidth, parentHeight))
                )
            }
        }

@@ -163,6 +186,12 @@ class Scene {
        renderNode.endRecording()
        return renderNode
    }

    data class BlurRegion(
        val blurRadius: Double, val alpha: Double, val left: Double,
        val top: Double, val right: Double, val bottom: Double, val cornerRadiusTL: Double,
        val cornerRadiusTR: Double, val cornerRadiusBL: Double, val cornerRadiusBR: Double
    )
}

/**
+0 −1
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ class BlurOnOffActivity : SceneActivity() {
                width = 0.5
                height = 0.5
            }

            scene {
                content { data, width, height ->
                    // SurfaceControl blurs don't work unless we draw a transparent buffer.
+97 −0
Original line number Diff line number Diff line
/*
 * Copyright 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.test.transactionflinger.activities

import android.graphics.Color
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.RenderNode
import com.android.test.transactionflinger.Scene
import com.android.test.transactionflinger.scene
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.nanoseconds

/**
 * A scene that draws half the screen black and the other half white, alternating at 60fps.
 * The middle region of the screen is blurred.
 */
class BlurRegionActivity : SceneActivity() {
    override fun obtainScene(): Scene {
        return scene {
            scene {
                content { data, width, height ->
                    val animationTime =
                        ((data.preferredFrameTimeline.deadlineNanos - startTime) % 33.milliseconds.inWholeNanoseconds).nanoseconds

                    val channel = if (animationTime < 16.milliseconds) {
                        0
                    } else {
                        255
                    }
                    val renderNode = RenderNode("cogsapp")
                    renderNode.setPosition(Rect(0, 0, width, height))
                    val paint = Paint()
                    paint.color = Color.argb(255, channel, channel, channel)
                    renderNode.beginRecording(width, height).drawPaint(paint)
                    renderNode.endRecording()
                    renderNode
                }
                x = 0.0
                y = 0.0
                width = 1.0
                height = 0.5
            }
            scene {
                content { data, width, height ->
                    val animationTime =
                        ((data.preferredFrameTimeline.deadlineNanos - startTime) % 33.milliseconds.inWholeNanoseconds).nanoseconds

                    val channel = if (animationTime < 16.milliseconds) {
                        255
                    } else {
                        0
                    }
                    val renderNode = RenderNode("cogsapp")
                    renderNode.setPosition(Rect(0, 0, width, height))
                    val paint = Paint()
                    paint.color = Color.argb(255, channel, channel, channel)
                    renderNode.beginRecording(width, height).drawPaint(paint)
                    renderNode.endRecording()
                    renderNode
                }
                x = 0.0
                y = 0.5
                width = 1.0
                height = 0.5
            }
            scene {
                content { data, width, height ->
                    // SurfaceControl blurs don't work unless we draw a transparent buffer.
                    // https://www.youtube.com/watch?v=76p_ncbffCE
                    drawColor(Color.TRANSPARENT, data, width, height)
                }
                properties { data ->
                    blurRegion = Scene.BlurRegion(
                        10.0, 1.0,
                        0.25, 0.25, 0.75, 0.75, 0.0,
                        0.0, 0.0, 0.0
                    )
                }
            }
        }
    }
}
 No newline at end of file