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

Commit f7f052e5 authored by Yein Jo's avatar Yein Jo
Browse files

Separate out ShaderLib from AnimationLib.

Bug: 258689851
Test: m, gradle build
Change-Id: I784637fbe09d82215cc99420d5a472ad06b5326a
parent b89917c0
Loading
Loading
Loading
Loading
+26 −0
Original line number Original line Diff line number Diff line
@@ -29,6 +29,10 @@ android_library {
        "src/**/*.java",
        "src/**/*.java",
        "src/**/*.kt",
        "src/**/*.kt",
    ],
    ],
    exclude_srcs: [
        "src/com/android/systemui/surfaceeffects/**/*.java",
        "src/com/android/systemui/surfaceeffects/**/*.kt",
    ],


    resource_dirs: [
    resource_dirs: [
        "res",
        "res",
@@ -38,8 +42,30 @@ android_library {
        "androidx.core_core-animation-nodeps",
        "androidx.core_core-animation-nodeps",
        "androidx.core_core-ktx",
        "androidx.core_core-ktx",
        "androidx.annotation_annotation",
        "androidx.annotation_annotation",
        "SystemUIShaderLib",
    ],
    ],


    manifest: "AndroidManifest.xml",
    manifest: "AndroidManifest.xml",
    kotlincflags: ["-Xjvm-default=all"],
    kotlincflags: ["-Xjvm-default=all"],
}
}

android_library {
    name: "SystemUIShaderLib",

    srcs: [
        "src/com/android/systemui/surfaceeffects/**/*.java",
        "src/com/android/systemui/surfaceeffects/**/*.kt",
    ],

    static_libs: [
        "androidx.core_core-animation-nodeps",
        "androidx.core_core-ktx",
        "androidx.annotation_annotation",
    ],

    manifest: "AndroidManifest.xml",
    kotlincflags: ["-Xjvm-default=all"],

    // sdk_version must be specified, otherwise it compiles against private APIs.
    sdk_version: "current",
}
+4 −14
Original line number Original line Diff line number Diff line
@@ -20,7 +20,6 @@ import android.content.Context
import android.graphics.Canvas
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Paint
import android.util.AttributeSet
import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.view.View
import androidx.annotation.VisibleForTesting
import androidx.annotation.VisibleForTesting


@@ -34,24 +33,15 @@ class MultiRippleView(context: Context?, attrs: AttributeSet?) : View(context, a
    @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
    @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
    val ripples = ArrayList<RippleAnimation>()
    val ripples = ArrayList<RippleAnimation>()
    private val ripplePaint = Paint()
    private val ripplePaint = Paint()
    private var isWarningLogged = false


    companion object {
    companion object {
        private const val TAG = "MultiRippleView"
        private const val TAG = "MultiRippleView"
    }
    }


    override fun onDraw(canvas: Canvas?) {
    override fun onDraw(canvas: Canvas) {
        if (canvas == null || !canvas.isHardwareAccelerated) {
        if (!canvas.isHardwareAccelerated) {
            // Drawing with the ripple shader requires hardware acceleration, so skip
            // Drawing with the ripple shader requires hardware acceleration, so skip if it's
            // if it's unsupported.
            // unsupported.
            if (!isWarningLogged) {
                // Only log once to not spam.
                Log.w(
                    TAG,
                    "Can't draw ripple shader. $canvas does not support hardware acceleration."
                )
                isWarningLogged = true
            }
            return
            return
        }
        }


+1 −1
Original line number Original line Diff line number Diff line
@@ -54,7 +54,7 @@ class RippleAnimation(private val config: RippleAnimationConfig) {
        }
        }
        animator.addListener(
        animator.addListener(
            object : AnimatorListenerAdapter() {
            object : AnimatorListenerAdapter() {
                override fun onAnimationEnd(animation: Animator?) {
                override fun onAnimationEnd(animation: Animator) {
                    onAnimationEnd?.run()
                    onAnimationEnd?.run()
                }
                }
            }
            }
+11 −5
Original line number Original line Diff line number Diff line
@@ -17,9 +17,9 @@ package com.android.systemui.surfaceeffects.ripple


import android.graphics.RuntimeShader
import android.graphics.RuntimeShader
import android.util.Log
import android.util.Log
import android.util.MathUtils
import android.view.animation.Interpolator
import android.view.animation.PathInterpolator
import androidx.annotation.VisibleForTesting
import androidx.annotation.VisibleForTesting
import com.android.systemui.animation.Interpolators
import com.android.systemui.surfaceeffects.shaderutil.SdfShaderLibrary
import com.android.systemui.surfaceeffects.shaderutil.SdfShaderLibrary
import com.android.systemui.surfaceeffects.shaderutil.ShaderUtilLibrary
import com.android.systemui.surfaceeffects.shaderutil.ShaderUtilLibrary


@@ -180,6 +180,13 @@ class RippleShader(rippleShape: RippleShape = RippleShape.CIRCLE) :


            return Math.min(fadeIn, fadeOut)
            return Math.min(fadeIn, fadeOut)
        }
        }

        private fun lerp(start: Float, stop: Float, amount: Float): Float {
            return start + (stop - start) * amount
        }

        // Copied from [Interpolators#STANDARD]. This is to remove dependency on AnimationLib.
        private val STANDARD: Interpolator = PathInterpolator(0.2f, 0f, 0f, 1f)
    }
    }


    /** Sets the center position of the ripple. */
    /** Sets the center position of the ripple. */
@@ -207,7 +214,7 @@ class RippleShader(rippleShape: RippleShape = RippleShape.CIRCLE) :
    var rawProgress: Float = 0.0f
    var rawProgress: Float = 0.0f
        set(value) {
        set(value) {
            field = value
            field = value
            progress = Interpolators.STANDARD.getInterpolation(value)
            progress = STANDARD.getInterpolation(value)


            setFloatUniform("in_fadeSparkle", getFade(sparkleRingFadeParams, value))
            setFloatUniform("in_fadeSparkle", getFade(sparkleRingFadeParams, value))
            setFloatUniform("in_fadeRing", getFade(baseRingFadeParams, value))
            setFloatUniform("in_fadeRing", getFade(baseRingFadeParams, value))
@@ -228,8 +235,7 @@ class RippleShader(rippleShape: RippleShape = RippleShape.CIRCLE) :
                "in_cornerRadius",
                "in_cornerRadius",
                Math.min(rippleSize.currentWidth, rippleSize.currentHeight)
                Math.min(rippleSize.currentWidth, rippleSize.currentHeight)
            )
            )

            setFloatUniform("in_blur", lerp(1.25f, 0.5f, value))
            setFloatUniform("in_blur", MathUtils.lerp(blurStart, blurEnd, value))
        }
        }


    /** Play time since the start of the effect. */
    /** Play time since the start of the effect. */
+5 −5
Original line number Original line Diff line number Diff line
@@ -196,7 +196,7 @@ open class RippleView(context: Context?, attrs: AttributeSet?) : View(context, a
        }
        }
        animator.addListener(
        animator.addListener(
            object : AnimatorListenerAdapter() {
            object : AnimatorListenerAdapter() {
                override fun onAnimationEnd(animation: Animator?) {
                override fun onAnimationEnd(animation: Animator) {
                    onAnimationEnd?.run()
                    onAnimationEnd?.run()
                }
                }
            }
            }
@@ -221,10 +221,10 @@ open class RippleView(context: Context?, attrs: AttributeSet?) : View(context, a
    /** Indicates whether the ripple animation is playing. */
    /** Indicates whether the ripple animation is playing. */
    fun rippleInProgress(): Boolean = animator.isRunning
    fun rippleInProgress(): Boolean = animator.isRunning


    override fun onDraw(canvas: Canvas?) {
    override fun onDraw(canvas: Canvas) {
        if (canvas == null || !canvas.isHardwareAccelerated) {
        if (!canvas.isHardwareAccelerated) {
            // Drawing with the ripple shader requires hardware acceleration, so skip
            // Drawing with the ripple shader requires hardware acceleration, so skip if it's
            // if it's unsupported.
            // unsupported.
            return
            return
        }
        }
        // To reduce overdraw, we mask the effect to a circle or a rectangle that's bigger than the
        // To reduce overdraw, we mask the effect to a circle or a rectangle that's bigger than the
Loading