Jorim Jaggi | 988f668 | 2017-11-17 17:46:43 +0100 | [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 static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
| 20 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 21 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 22 | import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION; |
| 23 | |
| 24 | import android.graphics.GraphicBuffer; |
| 25 | import android.graphics.PixelFormat; |
| 26 | import android.graphics.Point; |
| 27 | import android.os.Binder; |
| 28 | import android.util.Slog; |
| 29 | import android.view.Surface; |
| 30 | import android.view.SurfaceControl; |
| 31 | import android.view.SurfaceControl.Builder; |
| 32 | import android.view.SurfaceControl.Transaction; |
| 33 | import android.view.animation.Animation; |
| 34 | |
| 35 | import com.android.server.wm.SurfaceAnimator.Animatable; |
| 36 | |
| 37 | /** |
| 38 | * Represents a surface that is displayed over an {@link AppWindowToken} |
| 39 | */ |
| 40 | class AppWindowThumbnail implements Animatable { |
| 41 | |
| 42 | private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowThumbnail" : TAG_WM; |
| 43 | |
| 44 | private final AppWindowToken mAppToken; |
| 45 | private final SurfaceControl mSurfaceControl; |
| 46 | private final SurfaceAnimator mSurfaceAnimator; |
| 47 | private final int mWidth; |
| 48 | private final int mHeight; |
| 49 | |
| 50 | AppWindowThumbnail(Transaction t, AppWindowToken appToken, GraphicBuffer thumbnailHeader) { |
| 51 | mAppToken = appToken; |
Jorim Jaggi | 4130a68 | 2018-01-09 14:28:44 +0100 | [diff] [blame] | 52 | mSurfaceAnimator = new SurfaceAnimator(this, this::onAnimationFinished, |
| 53 | appToken.mService.mAnimator::addAfterPrepareSurfacesRunnable, appToken.mService); |
Jorim Jaggi | 988f668 | 2017-11-17 17:46:43 +0100 | [diff] [blame] | 54 | mWidth = thumbnailHeader.getWidth(); |
| 55 | mHeight = thumbnailHeader.getHeight(); |
| 56 | |
| 57 | // Create a new surface for the thumbnail |
| 58 | WindowState window = appToken.findMainWindow(); |
| 59 | |
| 60 | // TODO: This should be attached as a child to the app token, once the thumbnail animations |
| 61 | // use relative coordinates. Once we start animating task we can also consider attaching |
| 62 | // this to the task. |
| 63 | mSurfaceControl = appToken.makeSurface() |
| 64 | .setName("thumbnail anim: " + appToken.toString()) |
| 65 | .setSize(mWidth, mHeight) |
| 66 | .setFormat(PixelFormat.TRANSLUCENT) |
| 67 | .setMetadata(appToken.windowType, |
| 68 | window != null ? window.mOwnerUid : Binder.getCallingUid()) |
| 69 | .build(); |
| 70 | |
| 71 | if (SHOW_TRANSACTIONS) { |
| 72 | Slog.i(TAG, " THUMBNAIL " + mSurfaceControl + ": CREATE"); |
| 73 | } |
| 74 | |
| 75 | // Transfer the thumbnail to the surface |
| 76 | Surface drawSurface = new Surface(); |
| 77 | drawSurface.copyFrom(mSurfaceControl); |
| 78 | drawSurface.attachAndQueueBuffer(thumbnailHeader); |
| 79 | drawSurface.release(); |
| 80 | t.show(mSurfaceControl); |
| 81 | |
| 82 | // We parent the thumbnail to the task, and just place it on top of anything else in the |
| 83 | // task. |
| 84 | t.setLayer(mSurfaceControl, Integer.MAX_VALUE); |
| 85 | } |
| 86 | |
| 87 | void startAnimation(Transaction t, Animation anim) { |
Tony Mak | 64b8d56 | 2017-12-28 17:44:02 +0000 | [diff] [blame] | 88 | startAnimation(t, anim, null /* position */); |
| 89 | } |
| 90 | |
| 91 | void startAnimation(Transaction t, Animation anim, Point position) { |
Jorim Jaggi | 988f668 | 2017-11-17 17:46:43 +0100 | [diff] [blame] | 92 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 93 | anim.scaleCurrentDuration(mAppToken.mService.getTransitionAnimationScaleLocked()); |
chaviw | 2301211 | 2017-12-20 15:29:04 -0800 | [diff] [blame] | 94 | mSurfaceAnimator.startAnimation(t, new LocalAnimationAdapter( |
Tony Mak | 64b8d56 | 2017-12-28 17:44:02 +0000 | [diff] [blame] | 95 | new WindowAnimationSpec(anim, position, |
chaviw | 2301211 | 2017-12-20 15:29:04 -0800 | [diff] [blame] | 96 | mAppToken.mService.mAppTransition.canSkipFirstFrame()), |
| 97 | mAppToken.mService.mSurfaceAnimationRunner), false /* hidden */); |
Jorim Jaggi | 988f668 | 2017-11-17 17:46:43 +0100 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | private void onAnimationFinished() { |
| 101 | } |
| 102 | |
| 103 | void setShowing(Transaction pendingTransaction, boolean show) { |
Jorim Jaggi | 2e3c31d | 2017-11-20 19:49:00 +0100 | [diff] [blame] | 104 | // TODO: Not needed anymore once thumbnail is attached to the app. |
Jorim Jaggi | 988f668 | 2017-11-17 17:46:43 +0100 | [diff] [blame] | 105 | if (show) { |
| 106 | pendingTransaction.show(mSurfaceControl); |
| 107 | } else { |
| 108 | pendingTransaction.hide(mSurfaceControl); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | void destroy() { |
| 113 | mSurfaceAnimator.cancelAnimation(); |
| 114 | mSurfaceControl.destroy(); |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public Transaction getPendingTransaction() { |
| 119 | return mAppToken.getPendingTransaction(); |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public void commitPendingTransaction() { |
| 124 | mAppToken.commitPendingTransaction(); |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public void destroyAfterPendingTransaction(SurfaceControl surface) { |
| 129 | mAppToken.destroyAfterPendingTransaction(surface); |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) { |
| 134 | t.setLayer(leash, Integer.MAX_VALUE); |
| 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public void onAnimationLeashDestroyed(Transaction t) { |
Jorim Jaggi | 2e3c31d | 2017-11-20 19:49:00 +0100 | [diff] [blame] | 139 | |
| 140 | // TODO: Once attached to app token, we don't need to hide it immediately if thumbnail |
| 141 | // became visible. |
Jorim Jaggi | 988f668 | 2017-11-17 17:46:43 +0100 | [diff] [blame] | 142 | t.hide(mSurfaceControl); |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public Builder makeAnimationLeash() { |
Jorim Jaggi | 596a199 | 2017-12-29 14:48:02 +0100 | [diff] [blame] | 147 | return mAppToken.makeSurface(); |
Jorim Jaggi | 988f668 | 2017-11-17 17:46:43 +0100 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public SurfaceControl getSurfaceControl() { |
| 152 | return mSurfaceControl; |
| 153 | } |
| 154 | |
| 155 | @Override |
Jorim Jaggi | 596a199 | 2017-12-29 14:48:02 +0100 | [diff] [blame] | 156 | public SurfaceControl getAnimationLeashParent() { |
| 157 | return mAppToken.getAppAnimationLayer(); |
| 158 | } |
| 159 | |
| 160 | @Override |
Jorim Jaggi | 988f668 | 2017-11-17 17:46:43 +0100 | [diff] [blame] | 161 | public SurfaceControl getParentSurfaceControl() { |
| 162 | return mAppToken.getParentSurfaceControl(); |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public int getSurfaceWidth() { |
| 167 | return mWidth; |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public int getSurfaceHeight() { |
| 172 | return mHeight; |
| 173 | } |
| 174 | } |