• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.google.android.wallpaper.weathereffects.graphics.none
18 
19 import android.graphics.Bitmap
20 import android.graphics.Canvas
21 import android.util.SizeF
22 import com.google.android.wallpaper.weathereffects.graphics.WeatherEffect
23 import com.google.android.wallpaper.weathereffects.graphics.utils.MatrixUtils
24 
25 /** Simply draws foreground and background images with no weather effect. */
26 class NoEffect(
27     private var foreground: Bitmap,
28     private var background: Bitmap,
29     private var surfaceSize: SizeF,
30 ) : WeatherEffect {
resizenull31     override fun resize(newSurfaceSize: SizeF) {
32         surfaceSize = newSurfaceSize
33     }
34 
updatenull35     override fun update(deltaMillis: Long, frameTimeNanos: Long) {}
36 
drawnull37     override fun draw(canvas: Canvas) {
38         canvas.drawBitmap(
39             background,
40             MatrixUtils.centerCropMatrix(
41                 surfaceSize,
42                 SizeF(background.width.toFloat(), background.height.toFloat()),
43             ),
44             null,
45         )
46         canvas.drawBitmap(
47             foreground,
48             MatrixUtils.centerCropMatrix(
49                 surfaceSize,
50                 SizeF(foreground.width.toFloat(), foreground.height.toFloat()),
51             ),
52             null,
53         )
54     }
55 
resetnull56     override fun reset() {}
57 
releasenull58     override fun release() {}
59 
setIntensitynull60     override fun setIntensity(intensity: Float) {}
61 
setBitmapsnull62     override fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean {
63         // Only when background changes, we can infer the bitmap set changes
64         if (this.background != background) {
65             this.background.recycle()
66             this.foreground.recycle()
67             return false
68         }
69         this.background = background
70         this.foreground = foreground ?: background
71         return true
72     }
73 }
74