1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.systemui.surfaceeffects.turbulencenoise
17 
18 import android.graphics.BlendMode
19 import android.graphics.Color
20 
21 /** Turbulence noise animation configuration. */
22 data class TurbulenceNoiseAnimationConfig(
23     /** The number of grids that is used to generate noise. */
24     val gridCount: Float = DEFAULT_NOISE_GRID_COUNT,
25 
26     /** Multiplier for the noise luma matte. Increase this for brighter effects. */
27     val luminosityMultiplier: Float = DEFAULT_LUMINOSITY_MULTIPLIER,
28 
29     /**
30      * Noise move speed variables.
31      *
32      * Its sign determines the direction; magnitude determines the speed. <ul>
33      *
34      * ```
35      *     <li> [noiseMoveSpeedX] positive: right to left; negative: left to right.
36      *     <li> [noiseMoveSpeedY] positive: bottom to top; negative: top to bottom.
37      *     <li> [noiseMoveSpeedZ] its sign doesn't matter much, as it moves in Z direction. Use it
38      *     to add turbulence in place.
39      * ```
40      *
41      * </ul>
42      */
43     val noiseMoveSpeedX: Float = 0f,
44     val noiseMoveSpeedY: Float = 0f,
45     val noiseMoveSpeedZ: Float = DEFAULT_NOISE_SPEED_Z,
46 
47     /** Color of the effect. */
48     var color: Int = DEFAULT_COLOR,
49     /** Background color of the effect. */
50     val backgroundColor: Int = DEFAULT_BACKGROUND_COLOR,
51     val opacity: Int = DEFAULT_OPACITY,
52     val width: Float = 0f,
53     val height: Float = 0f,
54     val maxDuration: Float = DEFAULT_MAX_DURATION_IN_MILLIS,
55     val easeInDuration: Float = DEFAULT_EASING_DURATION_IN_MILLIS,
56     val easeOutDuration: Float = DEFAULT_EASING_DURATION_IN_MILLIS,
57     val pixelDensity: Float = 1f,
58     val blendMode: BlendMode = DEFAULT_BLEND_MODE,
59     val onAnimationEnd: Runnable? = null,
60     /**
61      * Variants in noise. Higher number means more contrast; lower number means less contrast but
62      * make the noise dimmed. You may want to increase the [lumaMatteBlendFactor] to compensate.
63      * Expected range [0, 1].
64      */
65     val lumaMatteBlendFactor: Float = DEFAULT_LUMA_MATTE_BLEND_FACTOR,
66     /**
67      * Offset for the overall brightness in noise. Higher number makes the noise brighter. You may
68      * want to use this if you have made the noise softer using [lumaMatteBlendFactor]. Expected
69      * range [0, 1].
70      */
71     val lumaMatteOverallBrightness: Float = DEFAULT_LUMA_MATTE_OVERALL_BRIGHTNESS
72 ) {
73     companion object {
74         const val DEFAULT_MAX_DURATION_IN_MILLIS = 30_000f // Max 30 sec
75         const val DEFAULT_EASING_DURATION_IN_MILLIS = 750f
76         const val DEFAULT_LUMINOSITY_MULTIPLIER = 1f
77         const val DEFAULT_NOISE_GRID_COUNT = 1.2f
78         const val DEFAULT_NOISE_SPEED_Z = 0.3f
79         const val DEFAULT_OPACITY = 150 // full opacity is 255.
80         const val DEFAULT_COLOR = Color.WHITE
81         const val DEFAULT_LUMA_MATTE_BLEND_FACTOR = 1f
82         const val DEFAULT_LUMA_MATTE_OVERALL_BRIGHTNESS = 0f
83         const val DEFAULT_BACKGROUND_COLOR = Color.BLACK
84         val DEFAULT_BLEND_MODE = BlendMode.SRC_OVER
85     }
86 }
87