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

Commit 2ff24ae2 authored by Yein Jo's avatar Yein Jo
Browse files

Update weather configs' constructors.

Replace the create function with the constructor, as we don't want to
expose color grading param to be set by the client.

Bug: 325090421
Test: m, gradle
Flag: NA
Change-Id: I7ca165e89cb6fe6593b1e0cd9a3057688191cedd
parent 4e374ba3
Loading
Loading
Loading
Loading
+34 −30
Original line number Diff line number Diff line
@@ -37,38 +37,42 @@ data class FogEffectConfig(
    /** Pixel density of the display. Used for dithering. */
    val pixelDensity: Float,
    /** The amount of the fog. This contributes to the color grading as well. */
    @FloatRange(from = 0.0, to = 1.0) val intensity: Float = 1f,
    @FloatRange(from = 0.0, to = 1.0) val intensity: Float,
    /** The intensity of the color grading. 0: no color grading, 1: color grading in full effect. */
    @FloatRange(from = 0.0, to = 1.0) val colorGradingIntensity: Float = 0.7f,
    @FloatRange(from = 0.0, to = 1.0) val colorGradingIntensity: Float,
) {

    companion object {

    /**
         * A convenient way for creating a [FogEffectConfig]. If the client does not want to use
         * this constructor, a [FogEffectConfig] object can still be created a directly.
     * Constructor for [FogEffectConfig].
     *
     * @param assets the application [AssetManager].
     * @param foreground a bitmap containing the foreground of the image.
     * @param background a bitmap containing the background of the image.
     * @param pixelDensity pixel density of the display.
         * @return the [FogEffectConfig] object.
     * @param intensity initial intensity that affects the amount of fog and color grading. Expected
     *   range is [0, 1]. You can always change the intensity dynamically. Defaults to 1.
     */
        fun create(
    constructor(
        assets: AssetManager,
        foreground: Bitmap,
        background: Bitmap,
        pixelDensity: Float,
        ): FogEffectConfig {
            return FogEffectConfig(
                shader = GraphicsUtils.loadShader(assets, "shaders/fog_effect.agsl"),
                colorGradingShader =
                    GraphicsUtils.loadShader(assets, "shaders/color_grading_lut.agsl"),
                lut = GraphicsUtils.loadTexture(assets, "textures/lut_rain_and_fog.png"),
        intensity: Float = DEFAULT_INTENSITY,
    ) : this(
        shader = GraphicsUtils.loadShader(assets, SHADER_PATH),
        colorGradingShader = GraphicsUtils.loadShader(assets, COLOR_GRADING_SHADER_PATH),
        lut = GraphicsUtils.loadTexture(assets, LOOKUP_TABLE_TEXTURE_PATH),
        foreground,
        background,
                pixelDensity
        pixelDensity,
        intensity,
        COLOR_GRADING_INTENSITY
    )
        }

    private companion object {
        private const val SHADER_PATH = "shaders/fog_effect.agsl"
        private const val COLOR_GRADING_SHADER_PATH = "shaders/color_grading_lut.agsl"
        private const val LOOKUP_TABLE_TEXTURE_PATH = "textures/lut_rain_and_fog.png"
        private const val DEFAULT_INTENSITY = 1f
        private const val COLOR_GRADING_INTENSITY = 0.7f
    }
}
+33 −24
Original line number Diff line number Diff line
@@ -37,32 +37,41 @@ data class RainEffectConfig(
    /** A bitmap containing the blurred background. */
    val blurredBackground: Bitmap,
    /** The amount of the rain. This contributes to the color grading as well. */
    @FloatRange(from = 0.0, to = 1.0) val intensity: Float = 1f,
    @FloatRange(from = 0.0, to = 1.0) val intensity: Float,
    /** The intensity of the color grading. 0: no color grading, 1: color grading in full effect. */
    @FloatRange(from = 0.0, to = 1.0) val colorGradingIntensity: Float = 0.7f,
    @FloatRange(from = 0.0, to = 1.0) val colorGradingIntensity: Float,
) {

    companion object {

    /**
         * A convenient way for creating a [RainEffectConfig]. If the client does not want to use
         * this constructor, a [RainEffectConfig] object can still be created a directly.
     * Constructor for [RainEffectConfig].
     *
     * @param context the application context.
     * @param foreground a bitmap containing the foreground of the image.
     * @param background a bitmap containing the background of the image.
         * @return the [RainEffectConfig] object.
     * @param intensity initial intensity that affects the amount of rain and color grading.
     *   Expected range is [0, 1]. You can always change the intensity dynamically. Defaults to 1.
     */
        fun create(context: Context, foreground: Bitmap, background: Bitmap): RainEffectConfig {
            return RainEffectConfig(
                shader = GraphicsUtils.loadShader(context.assets, "shaders/rain_effect.agsl"),
                colorGradingShader =
                    GraphicsUtils.loadShader(context.assets, "shaders/color_grading_lut.agsl"),
                lut = GraphicsUtils.loadTexture(context.assets, "textures/lut_rain_and_fog.png"),
    constructor(
        context: Context,
        foreground: Bitmap,
        background: Bitmap,
        intensity: Float = DEFAULT_INTENSITY,
    ) : this(
        shader = GraphicsUtils.loadShader(context.assets, SHADER_PATH),
        colorGradingShader = GraphicsUtils.loadShader(context.assets, COLOR_GRADING_SHADER_PATH),
        lut = GraphicsUtils.loadTexture(context.assets, LOOKUP_TABLE_TEXTURE_PATH),
        foreground,
        background,
                GraphicsUtils.blurImage(context, background, 10f)
        blurredBackground = GraphicsUtils.blurImage(context, background, BLUR_RADIUS),
        intensity,
        COLOR_GRADING_INTENSITY
    )
        }

    private companion object {
        private const val SHADER_PATH = "shaders/rain_effect.agsl"
        private const val COLOR_GRADING_SHADER_PATH = "shaders/color_grading_lut.agsl"
        private const val LOOKUP_TABLE_TEXTURE_PATH = "textures/lut_rain_and_fog.png"
        private const val BLUR_RADIUS = 10f
        private const val DEFAULT_INTENSITY = 1f
        private const val COLOR_GRADING_INTENSITY = 0.7f
    }
}
+36 −26
Original line number Diff line number Diff line
@@ -39,34 +39,44 @@ data class SnowEffectConfig(
    /** A bitmap containing the blurred background. */
    val blurredBackground: Bitmap,
    /** The amount of the snow flakes. This contributes to the color grading as well. */
    @FloatRange(from = 0.0, to = 1.0) val intensity: Float = 1f,
    @FloatRange(from = 0.0, to = 1.0) val intensity: Float,
    /** The intensity of the color grading. 0: no color grading, 1: color grading in full effect. */
    @FloatRange(from = 0.0, to = 1.0) val colorGradingIntensity: Float = 0.7f,
    @FloatRange(from = 0.0, to = 1.0) val colorGradingIntensity: Float,
) {

    companion object {

    /**
         * A convenient way for creating a [SnowEffectConfig]. If the client does not want to use
         * this constructor, a [SnowEffectConfig] object can still be created a directly.
     * Constructor for [SnowEffectConfig].
     *
     * @param context the application context.
     * @param foreground a bitmap containing the foreground of the image.
     * @param background a bitmap containing the background of the image.
         * @return the [SnowEffectConfig] object.
     * @param intensity initial intensity that affects the amount of snow flakes and color grading.
     *   Expected range is [0, 1]. You can always change the intensity dynamically. Defaults to 1.
     */
        fun create(context: Context, foreground: Bitmap, background: Bitmap): SnowEffectConfig {
            return SnowEffectConfig(
                shader = GraphicsUtils.loadShader(context.assets, "shaders/snow_effect.agsl"),
    constructor(
        context: Context,
        foreground: Bitmap,
        background: Bitmap,
        intensity: Float = DEFAULT_INTENSITY,
    ) : this(
        shader = GraphicsUtils.loadShader(context.assets, SHADER_PATH),
        accumulatedSnowShader =
                    GraphicsUtils.loadShader(context.assets, "shaders/snow_accumulation.agsl"),
                colorGradingShader =
                    GraphicsUtils.loadShader(context.assets, "shaders/color_grading_lut.agsl"),
                lut = GraphicsUtils.loadTexture(context.assets, "textures/lut_rain_and_fog.png"),
            GraphicsUtils.loadShader(context.assets, ACCUMULATED_SNOW_SHADER_PATH),
        colorGradingShader = GraphicsUtils.loadShader(context.assets, COLOR_GRADING_SHADER_PATH),
        lut = GraphicsUtils.loadTexture(context.assets, LOOKUP_TABLE_TEXTURE_PATH),
        foreground,
        background,
                GraphicsUtils.blurImage(context, background, 20f)
        blurredBackground = GraphicsUtils.blurImage(context, background, BLUR_RADIUS),
        intensity,
        COLOR_GRADING_INTENSITY
    )
        }

    private companion object {
        private const val SHADER_PATH = "shaders/snow_effect.agsl"
        private const val ACCUMULATED_SNOW_SHADER_PATH = "shaders/snow_accumulation.agsl"
        private const val COLOR_GRADING_SHADER_PATH = "shaders/color_grading_lut.agsl"
        private const val LOOKUP_TABLE_TEXTURE_PATH = "textures/lut_rain_and_fog.png"
        private const val BLUR_RADIUS = 20f
        private const val DEFAULT_INTENSITY = 1f
        private const val COLOR_GRADING_INTENSITY = 0.7f
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -126,19 +126,19 @@ class WeatherEngine(

        when (weatherEffect) {
            WallpaperInfoContract.WeatherEffect.RAIN -> {
                val rainConfig = RainEffectConfig.create(context, foreground, background)
                val rainConfig = RainEffectConfig(context, foreground, background)
                activeEffect = RainEffect(rainConfig, screenSize.toSizeF())
            }

            WallpaperInfoContract.WeatherEffect.FOG -> {
                val fogConfig = FogEffectConfig.create(
                val fogConfig = FogEffectConfig(
                    context.assets, foreground, background, context.resources.displayMetrics.density
                )
                activeEffect = FogEffect(fogConfig, screenSize.toSizeF())
            }

            WallpaperInfoContract.WeatherEffect.SNOW -> {
                val snowConfig = SnowEffectConfig.create(context, foreground, background)
                val snowConfig = SnowEffectConfig(context, foreground, background)
                activeEffect = SnowEffect(snowConfig, screenSize.toSizeF(), context.mainExecutor)
            }