blob: bb25297857dd869eeac3a2b5478742e5bc8a1781 [file] [log] [blame]
Jorim Jaggi21c39a72017-10-20 15:47:51 +02001/*
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
17package com.android.server.wm;
18
19import android.graphics.Point;
20import android.view.SurfaceControl;
21import android.view.SurfaceControl.Transaction;
22import android.view.animation.Animation;
23import android.view.animation.Transformation;
24
25import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
26
27/**
28 * Animation spec for regular window animations.
29 */
30public class WindowAnimationSpec implements AnimationSpec {
31
32 private Animation mAnimation;
33 private final Point mPosition = new Point();
Jorim Jaggia5e10572017-11-15 14:36:26 +010034 private final ThreadLocal<TmpValues> mThreadLocalTmps = ThreadLocal.withInitial(TmpValues::new);
Jorim Jaggi21c39a72017-10-20 15:47:51 +020035
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 Jaggia5e10572017-11-15 14:36:26 +010058 final TmpValues tmp = mThreadLocalTmps.get();
Jorim Jaggi21c39a72017-10-20 15:47:51 +020059 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 Jaggia5e10572017-11-15 14:36:26 +010066 private static class TmpValues {
Jorim Jaggi21c39a72017-10-20 15:47:51 +020067 final Transformation transformation = new Transformation();
68 final float[] floats = new float[9];
69 }
70}