blob: 2173fa3a283d1741b0c139e6ad44652273790ebf [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
Jorim Jaggif5f9e122017-10-24 18:21:09 +020019import android.os.SystemClock;
Jorim Jaggi21c39a72017-10-20 15:47:51 +020020import android.view.SurfaceControl;
21import android.view.SurfaceControl.Transaction;
Jorim Jaggi21c39a72017-10-20 15:47:51 +020022
23import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback;
24
25/**
26 * Animation that can be executed without holding the window manager lock. See
27 * {@link SurfaceAnimationRunner}.
28 */
29class LocalAnimationAdapter implements AnimationAdapter {
30
31 private final AnimationSpec mSpec;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020032
Jorim Jaggi21c39a72017-10-20 15:47:51 +020033 private final SurfaceAnimationRunner mAnimator;
34
35 LocalAnimationAdapter(AnimationSpec spec, SurfaceAnimationRunner animator) {
36 mSpec = spec;
37 mAnimator = animator;
38 }
39
40 @Override
41 public boolean getDetachWallpaper() {
42 return mSpec.getDetachWallpaper();
43 }
44
45 @Override
46 public int getBackgroundColor() {
47 return mSpec.getBackgroundColor();
48 }
49
50 @Override
51 public void startAnimation(SurfaceControl animationLeash, Transaction t,
52 OnAnimationFinishedCallback finishCallback) {
53 mAnimator.startAnimation(mSpec, animationLeash, t,
54 () -> finishCallback.onAnimationFinished(this));
55 }
56
57 @Override
58 public void onAnimationCancelled(SurfaceControl animationLeash) {
59 mAnimator.onAnimationCancelled(animationLeash);
60 }
61
62 @Override
63 public long getDurationHint() {
64 return mSpec.getDuration();
65 }
66
Jorim Jaggif5f9e122017-10-24 18:21:09 +020067 @Override
68 public long getStatusBarTransitionsStartTime() {
69 return mSpec.calculateStatusBarTransitionStartTime();
70 }
71
Jorim Jaggi21c39a72017-10-20 15:47:51 +020072 /**
73 * Describes how to apply an animation.
74 */
75 interface AnimationSpec {
76
77 /**
78 * @see AnimationAdapter#getDetachWallpaper
79 */
80 default boolean getDetachWallpaper() {
81 return false;
82 }
83
84 /**
85 * @see AnimationAdapter#getBackgroundColor
86 */
87 default int getBackgroundColor() {
88 return 0;
89 }
90
91 /**
Jorim Jaggif5f9e122017-10-24 18:21:09 +020092 * @see AnimationAdapter#getStatusBarTransitionsStartTime
93 */
94 default long calculateStatusBarTransitionStartTime() {
95 return SystemClock.uptimeMillis();
96 }
97
98 /**
Jorim Jaggi21c39a72017-10-20 15:47:51 +020099 * @return The duration of the animation.
100 */
101 long getDuration();
102
103 /**
104 * Called when the spec needs to apply the current animation state to the leash.
105 *
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200106 * @param t The transaction to use to apply a transform.
107 * @param leash The leash to apply the state to.
Jorim Jaggi21c39a72017-10-20 15:47:51 +0200108 * @param currentPlayTime The current time of the animation.
109 */
110 void apply(Transaction t, SurfaceControl leash, long currentPlayTime);
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +0100111
112 /**
113 * @see AppTransition#canSkipFirstFrame
114 */
115 default boolean canSkipFirstFrame() {
116 return false;
117 }
Jorim Jaggi21c39a72017-10-20 15:47:51 +0200118 }
119}