Loading weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/WeatherEffect.kt +2 −1 Original line number Diff line number Diff line Loading @@ -68,8 +68,9 @@ interface WeatherEffect { * @param foreground A bitmap containing the foreground of the image, will be null when * segmentation hasn't finished. * @param background A bitmap containing the background of the image * @return True if the bitmaps have been updated. False otherwise. */ fun setBitmaps(foreground: Bitmap?, background: Bitmap) fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean /** * Apply matrix to transform coordinates in shaders. In Editor and preview, it's a center crop Loading weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/WeatherEffectBase.kt +3 −2 Original line number Diff line number Diff line Loading @@ -93,9 +93,9 @@ abstract class WeatherEffectBase( colorGradingShader.setFloatUniform("intensity", colorGradingIntensity * intensity) } override fun setBitmaps(foreground: Bitmap?, background: Bitmap) { override fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean { if (this.foreground == foreground && this.background == background) { return return false } // Only when background changes, we can infer the bitmap set changes if (this.background != background) { Loading @@ -120,6 +120,7 @@ abstract class WeatherEffectBase( BitmapShader(this.foreground, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR), ) adjustCropping(surfaceSize) return true } open fun updateTextureUniforms() { Loading weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/none/NoEffect.kt +3 −1 Original line number Diff line number Diff line Loading @@ -59,13 +59,15 @@ class NoEffect( override fun setIntensity(intensity: Float) {} override fun setBitmaps(foreground: Bitmap?, background: Bitmap) { override fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean { // Only when background changes, we can infer the bitmap set changes if (this.background != background) { this.background.recycle() this.foreground.recycle() return false } this.background = background this.foreground = foreground ?: background return true } } weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/rain/RainEffect.kt +6 −2 Original line number Diff line number Diff line Loading @@ -92,8 +92,11 @@ class RainEffect( createOutlineBuffer() } override fun setBitmaps(foreground: Bitmap?, background: Bitmap) { super.setBitmaps(foreground, background) override fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean { if (!super.setBitmaps(foreground, background)) { return false } outlineBuffer.close() outlineBuffer = FrameBuffer(background.width, background.height).apply { setRenderEffect(RenderEffect.createBlurEffect(2f, 2f, Shader.TileMode.CLAMP)) Loading @@ -102,6 +105,7 @@ class RainEffect( // Need to recreate the outline buffer as the outlineBuffer has changed due to background createOutlineBuffer() return true } override val shader: RuntimeShader Loading weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/snow/SnowEffect.kt +6 −2 Original line number Diff line number Diff line Loading @@ -97,9 +97,12 @@ class SnowEffect( generateAccumulatedSnow() } override fun setBitmaps(foreground: Bitmap?, background: Bitmap) { super.setBitmaps(foreground, background) override fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean { if (!super.setBitmaps(foreground, background)) { return false } scale = getScale(parallaxMatrix) frameBuffer.close() frameBuffer = FrameBuffer(background.width, background.height).apply { setRenderEffect( Loading @@ -109,6 +112,7 @@ class SnowEffect( // GenerateAccumulatedSnow needs foreground for accumulatedSnowShader, and needs frameBuffer // which is also changed with background generateAccumulatedSnow() return true } override val shader: RuntimeShader Loading Loading
weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/WeatherEffect.kt +2 −1 Original line number Diff line number Diff line Loading @@ -68,8 +68,9 @@ interface WeatherEffect { * @param foreground A bitmap containing the foreground of the image, will be null when * segmentation hasn't finished. * @param background A bitmap containing the background of the image * @return True if the bitmaps have been updated. False otherwise. */ fun setBitmaps(foreground: Bitmap?, background: Bitmap) fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean /** * Apply matrix to transform coordinates in shaders. In Editor and preview, it's a center crop Loading
weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/WeatherEffectBase.kt +3 −2 Original line number Diff line number Diff line Loading @@ -93,9 +93,9 @@ abstract class WeatherEffectBase( colorGradingShader.setFloatUniform("intensity", colorGradingIntensity * intensity) } override fun setBitmaps(foreground: Bitmap?, background: Bitmap) { override fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean { if (this.foreground == foreground && this.background == background) { return return false } // Only when background changes, we can infer the bitmap set changes if (this.background != background) { Loading @@ -120,6 +120,7 @@ abstract class WeatherEffectBase( BitmapShader(this.foreground, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR), ) adjustCropping(surfaceSize) return true } open fun updateTextureUniforms() { Loading
weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/none/NoEffect.kt +3 −1 Original line number Diff line number Diff line Loading @@ -59,13 +59,15 @@ class NoEffect( override fun setIntensity(intensity: Float) {} override fun setBitmaps(foreground: Bitmap?, background: Bitmap) { override fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean { // Only when background changes, we can infer the bitmap set changes if (this.background != background) { this.background.recycle() this.foreground.recycle() return false } this.background = background this.foreground = foreground ?: background return true } }
weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/rain/RainEffect.kt +6 −2 Original line number Diff line number Diff line Loading @@ -92,8 +92,11 @@ class RainEffect( createOutlineBuffer() } override fun setBitmaps(foreground: Bitmap?, background: Bitmap) { super.setBitmaps(foreground, background) override fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean { if (!super.setBitmaps(foreground, background)) { return false } outlineBuffer.close() outlineBuffer = FrameBuffer(background.width, background.height).apply { setRenderEffect(RenderEffect.createBlurEffect(2f, 2f, Shader.TileMode.CLAMP)) Loading @@ -102,6 +105,7 @@ class RainEffect( // Need to recreate the outline buffer as the outlineBuffer has changed due to background createOutlineBuffer() return true } override val shader: RuntimeShader Loading
weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/snow/SnowEffect.kt +6 −2 Original line number Diff line number Diff line Loading @@ -97,9 +97,12 @@ class SnowEffect( generateAccumulatedSnow() } override fun setBitmaps(foreground: Bitmap?, background: Bitmap) { super.setBitmaps(foreground, background) override fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean { if (!super.setBitmaps(foreground, background)) { return false } scale = getScale(parallaxMatrix) frameBuffer.close() frameBuffer = FrameBuffer(background.width, background.height).apply { setRenderEffect( Loading @@ -109,6 +112,7 @@ class SnowEffect( // GenerateAccumulatedSnow needs foreground for accumulatedSnowShader, and needs frameBuffer // which is also changed with background generateAccumulatedSnow() return true } override val shader: RuntimeShader Loading