1 /* 2 * Copyright (C) 2023 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.wallpaper.picker.customization.animation.shader 17 18 import android.graphics.RuntimeShader 19 import com.android.systemui.surfaceeffects.shaderutil.SdfShaderLibrary 20 21 /** 22 * Reveals whatever is behind the given image in a circular fashion. Imagine a hole in the given 23 * image that grows until it's invisible. 24 */ 25 // TODO (b/281878827): remove this and use loading animation in SystemUIShaderLib when available 26 class CircularRevealShader : RuntimeShader(REVEAL_SHADER) { 27 // language=AGSL 28 companion object { 29 30 private const val UNIFORMS = 31 """ 32 uniform shader in_src; 33 uniform half in_radius; 34 uniform vec2 in_maskCenter; 35 uniform half in_blur; 36 """ 37 38 private const val MAIN_SHADER = 39 """vec4 main(vec2 p) { 40 half4 src = in_src.eval(p); 41 half mask = soften(sdCircle(p - in_maskCenter, in_radius), in_blur); 42 43 return src * mask; 44 } 45 """ 46 47 private const val REVEAL_SHADER = 48 UNIFORMS + 49 SdfShaderLibrary.SHADER_SDF_OPERATION_LIB + 50 SdfShaderLibrary.CIRCLE_SDF + 51 MAIN_SHADER 52 } 53 setCenternull54 fun setCenter(x: Float, y: Float) { 55 setFloatUniform("in_maskCenter", x, y) 56 } 57 setRadiusnull58 fun setRadius(radius: Float) { 59 setFloatUniform("in_radius", radius) 60 } 61 setBlurnull62 fun setBlur(blur: Float) { 63 setFloatUniform("in_blur", blur) 64 } 65 } 66