Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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.android.server.wm; |
| 18 | |
| 19 | import android.graphics.Point; |
| 20 | import android.view.SurfaceControl; |
| 21 | import android.view.SurfaceControl.Transaction; |
| 22 | import android.view.animation.Animation; |
| 23 | import android.view.animation.Transformation; |
| 24 | |
| 25 | import com.android.server.wm.LocalAnimationAdapter.AnimationSpec; |
| 26 | |
| 27 | /** |
| 28 | * Animation spec for regular window animations. |
| 29 | */ |
| 30 | public class WindowAnimationSpec implements AnimationSpec { |
| 31 | |
| 32 | private Animation mAnimation; |
| 33 | private final Point mPosition = new Point(); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame^] | 34 | private final ThreadLocal<TmpValues> mThreadLocalTmps = ThreadLocal.withInitial(TmpValues::new); |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 35 | |
| 36 | public WindowAnimationSpec(Animation animation, Point position) { |
| 37 | mAnimation = animation; |
| 38 | mPosition.set(position.x, position.y); |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public boolean getDetachWallpaper() { |
| 43 | return mAnimation.getDetachWallpaper(); |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public int getBackgroundColor() { |
| 48 | return mAnimation.getBackgroundColor(); |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public long getDuration() { |
| 53 | return mAnimation.computeDurationHint(); |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame^] | 58 | final TmpValues tmp = mThreadLocalTmps.get(); |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 59 | tmp.transformation.clear(); |
| 60 | mAnimation.getTransformation(currentPlayTime, tmp.transformation); |
| 61 | tmp.transformation.getMatrix().postTranslate(mPosition.x, mPosition.y); |
| 62 | t.setMatrix(leash, tmp.transformation.getMatrix(), tmp.floats); |
| 63 | t.setAlpha(leash, tmp.transformation.getAlpha()); |
| 64 | } |
| 65 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame^] | 66 | private static class TmpValues { |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 67 | final Transformation transformation = new Transformation(); |
| 68 | final float[] floats = new float[9]; |
| 69 | } |
| 70 | } |