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 | |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 19 | import android.os.SystemClock; |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 20 | import android.view.SurfaceControl; |
| 21 | import android.view.SurfaceControl.Transaction; |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 22 | |
| 23 | import 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 | */ |
| 29 | class LocalAnimationAdapter implements AnimationAdapter { |
| 30 | |
| 31 | private final AnimationSpec mSpec; |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 32 | |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 33 | 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 Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 67 | @Override |
| 68 | public long getStatusBarTransitionsStartTime() { |
| 69 | return mSpec.calculateStatusBarTransitionStartTime(); |
| 70 | } |
| 71 | |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 72 | /** |
| 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 Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 92 | * @see AnimationAdapter#getStatusBarTransitionsStartTime |
| 93 | */ |
| 94 | default long calculateStatusBarTransitionStartTime() { |
| 95 | return SystemClock.uptimeMillis(); |
| 96 | } |
| 97 | |
| 98 | /** |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 99 | * @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 Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 106 | * @param t The transaction to use to apply a transform. |
| 107 | * @param leash The leash to apply the state to. |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 108 | * @param currentPlayTime The current time of the animation. |
| 109 | */ |
| 110 | void apply(Transaction t, SurfaceControl leash, long currentPlayTime); |
Jorim Jaggi | 2e3c31d | 2017-11-20 19:49:00 +0100 | [diff] [blame] | 111 | |
| 112 | /** |
| 113 | * @see AppTransition#canSkipFirstFrame |
| 114 | */ |
| 115 | default boolean canSkipFirstFrame() { |
| 116 | return false; |
| 117 | } |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 118 | } |
| 119 | } |