blob: 56175c7d0538bb377723fbb777b57006c83ff440 [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();
34 private final ThreadLocal<Tmp> mThreadLocalTmps = ThreadLocal.withInitial(Tmp::new);
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) {
58 final Tmp tmp = mThreadLocalTmps.get();
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
66 private static class Tmp {
67 final Transformation transformation = new Transformation();
68 final float[] floats = new float[9];
69 }
70}