Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1 | // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | package com.android.server.wm; |
| 4 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 5 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 6 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
| 7 | |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 8 | import static com.android.server.wm.WindowManagerService.LayoutFields.CLEAR_ORIENTATION_CHANGE_COMPLETE; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9 | import static com.android.server.wm.WindowManagerService.LayoutFields.SET_TURN_ON_SCREEN; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 10 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 11 | import android.content.Context; |
| 12 | import android.graphics.Matrix; |
| 13 | import android.graphics.PixelFormat; |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 14 | import android.graphics.Point; |
| 15 | import android.graphics.PointF; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 16 | import android.graphics.Rect; |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 17 | import android.graphics.Region; |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 18 | import android.os.Debug; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 19 | import android.os.RemoteException; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 20 | import android.util.Slog; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 21 | import android.view.Surface; |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 22 | import android.view.SurfaceSession; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 23 | import android.view.WindowManager; |
| 24 | import android.view.WindowManagerPolicy; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 25 | import android.view.WindowManager.LayoutParams; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 26 | import android.view.animation.Animation; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 27 | import android.view.animation.AnimationUtils; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 28 | import android.view.animation.Transformation; |
| 29 | |
| 30 | import com.android.server.wm.WindowManagerService.H; |
| 31 | |
| 32 | import java.io.PrintWriter; |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 33 | import java.util.ArrayList; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 36 | * Keep track of animations and surface operations for a single WindowState. |
| 37 | **/ |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 38 | class WindowStateAnimator { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 39 | static final boolean DEBUG_VISIBILITY = WindowManagerService.DEBUG_VISIBILITY; |
| 40 | static final boolean DEBUG_ANIM = WindowManagerService.DEBUG_ANIM; |
| 41 | static final boolean DEBUG_LAYERS = WindowManagerService.DEBUG_LAYERS; |
| 42 | static final boolean DEBUG_STARTING_WINDOW = WindowManagerService.DEBUG_STARTING_WINDOW; |
| 43 | static final boolean SHOW_TRANSACTIONS = WindowManagerService.SHOW_TRANSACTIONS; |
| 44 | static final boolean SHOW_LIGHT_TRANSACTIONS = WindowManagerService.SHOW_LIGHT_TRANSACTIONS; |
| 45 | static final boolean SHOW_SURFACE_ALLOC = WindowManagerService.SHOW_SURFACE_ALLOC; |
| 46 | static final boolean localLOGV = WindowManagerService.localLOGV; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 47 | static final boolean DEBUG_ORIENTATION = WindowManagerService.DEBUG_ORIENTATION; |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 48 | static final boolean DEBUG_SURFACE_TRACE = WindowManagerService.DEBUG_SURFACE_TRACE; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 49 | |
| 50 | static final String TAG = "WindowStateAnimator"; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 51 | |
| 52 | final WindowManagerService mService; |
| 53 | final WindowState mWin; |
| 54 | final WindowState mAttachedWindow; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 55 | final WindowAnimator mAnimator; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 56 | final Session mSession; |
| 57 | final WindowManagerPolicy mPolicy; |
| 58 | final Context mContext; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 59 | |
| 60 | // Currently running animation. |
| 61 | boolean mAnimating; |
| 62 | boolean mLocalAnimating; |
| 63 | Animation mAnimation; |
| 64 | boolean mAnimationIsEntrance; |
| 65 | boolean mHasTransformation; |
| 66 | boolean mHasLocalTransformation; |
| 67 | final Transformation mTransformation = new Transformation(); |
| 68 | boolean mWasAnimating; // Were we animating going into the most recent animation step? |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 69 | int mAnimLayer; |
| 70 | int mLastLayer; |
| 71 | |
| 72 | Surface mSurface; |
| 73 | Surface mPendingDestroySurface; |
| 74 | boolean mReportDestroySurface; |
| 75 | boolean mSurfacePendingDestroy; |
| 76 | |
| 77 | /** |
| 78 | * Set when we have changed the size of the surface, to know that |
| 79 | * we must tell them application to resize (and thus redraw itself). |
| 80 | */ |
| 81 | boolean mSurfaceResized; |
| 82 | |
| 83 | /** |
| 84 | * Set if the client has asked that the destroy of its surface be delayed |
| 85 | * until it explicitly says it is okay. |
| 86 | */ |
| 87 | boolean mSurfaceDestroyDeferred; |
| 88 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 89 | float mShownAlpha = 0; |
| 90 | float mAlpha = 0; |
| 91 | float mLastAlpha = 0; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 92 | |
| 93 | // Used to save animation distances between the time they are calculated and when they are |
| 94 | // used. |
| 95 | int mAnimDw; |
| 96 | int mAnimDh; |
| 97 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 98 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 99 | |
| 100 | boolean mHaveMatrix; |
| 101 | |
| 102 | // For debugging, this is the last information given to the surface flinger. |
| 103 | boolean mSurfaceShown; |
| 104 | float mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 105 | int mSurfaceLayer; |
| 106 | float mSurfaceAlpha; |
| 107 | |
| 108 | // Set to true if, when the window gets displayed, it should perform |
| 109 | // an enter animation. |
| 110 | boolean mEnterAnimationPending; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 111 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 112 | /** This is set when there is no Surface */ |
| 113 | static final int NO_SURFACE = 0; |
| 114 | /** This is set after the Surface has been created but before the window has been drawn. During |
| 115 | * this time the surface is hidden. */ |
| 116 | static final int DRAW_PENDING = 1; |
| 117 | /** This is set after the window has finished drawing for the first time but before its surface |
| 118 | * is shown. The surface will be displayed when the next layout is run. */ |
| 119 | static final int COMMIT_DRAW_PENDING = 2; |
| 120 | /** This is set during the time after the window's drawing has been committed, and before its |
| 121 | * surface is actually shown. It is used to delay showing the surface until all windows in a |
| 122 | * token are ready to be shown. */ |
| 123 | static final int READY_TO_SHOW = 3; |
| 124 | /** Set when the window has been shown in the screen the first time. */ |
| 125 | static final int HAS_DRAWN = 4; |
| 126 | int mDrawState; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 127 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 128 | /** Was this window last hidden? */ |
| 129 | boolean mLastHidden; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 130 | |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 131 | int mAttrFlags; |
| 132 | int mAttrType; |
| 133 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 134 | public WindowStateAnimator(final WindowManagerService service, final WindowState win, |
| 135 | final WindowState attachedWindow) { |
| 136 | mService = service; |
| 137 | mWin = win; |
| 138 | mAttachedWindow = attachedWindow; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 139 | mAnimator = mService.mAnimator; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 140 | mSession = win.mSession; |
| 141 | mPolicy = mService.mPolicy; |
| 142 | mContext = mService.mContext; |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 143 | mAttrFlags = win.mAttrs.flags; |
| 144 | mAttrType = win.mAttrs.type; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | public void setAnimation(Animation anim) { |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 148 | if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 149 | mAnimating = false; |
| 150 | mLocalAnimating = false; |
| 151 | mAnimation = anim; |
| 152 | mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION); |
| 153 | mAnimation.scaleCurrentDuration(mService.mWindowAnimationScale); |
| 154 | // Start out animation gone if window is gone, or visible if window is visible. |
| 155 | mTransformation.clear(); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 156 | mTransformation.setAlpha(mLastHidden ? 0 : 1); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 157 | mHasLocalTransformation = true; |
| 158 | } |
| 159 | |
| 160 | public void clearAnimation() { |
| 161 | if (mAnimation != null) { |
| 162 | mAnimating = true; |
| 163 | mLocalAnimating = false; |
| 164 | mAnimation.cancel(); |
| 165 | mAnimation = null; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /** Is the window or its container currently animating? */ |
| 170 | boolean isAnimating() { |
| 171 | final WindowState attached = mAttachedWindow; |
| 172 | final AppWindowToken atoken = mWin.mAppToken; |
| 173 | return mAnimation != null |
| 174 | || (attached != null && attached.mWinAnimator.mAnimation != null) |
| 175 | || (atoken != null && |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 176 | (atoken.mAppAnimator.animation != null |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 177 | || atoken.inPendingTransaction)); |
| 178 | } |
| 179 | |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame^] | 180 | /** Is the window animating the DummyAnimation? */ |
| 181 | boolean isDummyAnimation() { |
| 182 | final AppWindowToken atoken = mWin.mAppToken; |
| 183 | return atoken != null |
| 184 | && atoken.mAppAnimator.animation == AppWindowAnimator.sDummyAnimation; |
| 185 | } |
| 186 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 187 | /** Is this window currently animating? */ |
| 188 | boolean isWindowAnimating() { |
| 189 | return mAnimation != null; |
| 190 | } |
| 191 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 192 | void cancelExitAnimationForNextAnimationLocked() { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 193 | if (mAnimation != null) { |
| 194 | mAnimation.cancel(); |
| 195 | mAnimation = null; |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 196 | mLocalAnimating = false; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 197 | destroySurfaceLocked(); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 198 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | private boolean stepAnimation(long currentTime) { |
| 202 | if ((mAnimation == null) || !mLocalAnimating) { |
| 203 | return false; |
| 204 | } |
| 205 | mTransformation.clear(); |
| 206 | final boolean more = mAnimation.getTransformation(currentTime, mTransformation); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 207 | if (DEBUG_ANIM) Slog.v( |
| 208 | TAG, "Stepped animation in " + this + |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 209 | ": more=" + more + ", xform=" + mTransformation); |
| 210 | return more; |
| 211 | } |
| 212 | |
| 213 | // This must be called while inside a transaction. Returns true if |
| 214 | // there is more animation to run. |
| 215 | boolean stepAnimationLocked(long currentTime) { |
| 216 | // Save the animation state as it was before this step so WindowManagerService can tell if |
| 217 | // we just started or just stopped animating by comparing mWasAnimating with isAnimating(). |
| 218 | mWasAnimating = mAnimating; |
| 219 | if (mService.okToDisplay()) { |
| 220 | // We will run animations as long as the display isn't frozen. |
| 221 | |
| 222 | if (mWin.isDrawnLw() && mAnimation != null) { |
| 223 | mHasTransformation = true; |
| 224 | mHasLocalTransformation = true; |
| 225 | if (!mLocalAnimating) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 226 | if (DEBUG_ANIM) Slog.v( |
| 227 | TAG, "Starting animation in " + this + |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 228 | " @ " + currentTime + ": ww=" + mWin.mFrame.width() + |
| 229 | " wh=" + mWin.mFrame.height() + |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 230 | " dw=" + mAnimDw + " dh=" + mAnimDh + |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 231 | " scale=" + mService.mWindowAnimationScale); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 232 | mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(), |
| 233 | mAnimDw, mAnimDh); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 234 | mAnimation.setStartTime(currentTime); |
| 235 | mLocalAnimating = true; |
| 236 | mAnimating = true; |
| 237 | } |
| 238 | if ((mAnimation != null) && mLocalAnimating) { |
| 239 | if (stepAnimation(currentTime)) { |
| 240 | return true; |
| 241 | } |
| 242 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 243 | if (DEBUG_ANIM) Slog.v( |
| 244 | TAG, "Finished animation in " + this + |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 245 | " @ " + currentTime); |
| 246 | //WindowManagerService.this.dump(); |
| 247 | } |
| 248 | mHasLocalTransformation = false; |
| 249 | if ((!mLocalAnimating || mAnimationIsEntrance) && mWin.mAppToken != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 250 | && mWin.mAppToken.mAppAnimator.animation != null) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 251 | // When our app token is animating, we kind-of pretend like |
| 252 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 253 | // part of this check means that we will only do this if |
| 254 | // our window is not currently exiting, or it is not |
| 255 | // locally animating itself. The idea being that one that |
| 256 | // is exiting and doing a local animation should be removed |
| 257 | // once that animation is done. |
| 258 | mAnimating = true; |
| 259 | mHasTransformation = true; |
| 260 | mTransformation.clear(); |
| 261 | return false; |
| 262 | } else if (mHasTransformation) { |
| 263 | // Little trick to get through the path below to act like |
| 264 | // we have finished an animation. |
| 265 | mAnimating = true; |
| 266 | } else if (isAnimating()) { |
| 267 | mAnimating = true; |
| 268 | } |
| 269 | } else if (mAnimation != null) { |
| 270 | // If the display is frozen, and there is a pending animation, |
| 271 | // clear it and make sure we run the cleanup code. |
| 272 | mAnimating = true; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | if (!mAnimating && !mLocalAnimating) { |
| 276 | return false; |
| 277 | } |
| 278 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 279 | // Done animating, clean up. |
| 280 | if (DEBUG_ANIM) Slog.v( |
| 281 | TAG, "Animation done in " + this + ": exiting=" + mWin.mExiting |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 282 | + ", reportedVisible=" |
| 283 | + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false)); |
| 284 | |
| 285 | mAnimating = false; |
| 286 | mLocalAnimating = false; |
| 287 | if (mAnimation != null) { |
| 288 | mAnimation.cancel(); |
| 289 | mAnimation = null; |
| 290 | } |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 291 | if (mAnimator.mWindowDetachedWallpaper == mWin) { |
| 292 | mAnimator.mWindowDetachedWallpaper = null; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 293 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 294 | mAnimLayer = mWin.mLayer; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 295 | if (mWin.mIsImWindow) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 296 | mAnimLayer += mService.mInputMethodAnimLayerAdjustment; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 297 | } else if (mWin.mIsWallpaper) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 298 | mAnimLayer += mService.mWallpaperAnimLayerAdjustment; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 299 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 300 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
| 301 | + " anim layer: " + mAnimLayer); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 302 | mHasTransformation = false; |
| 303 | mHasLocalTransformation = false; |
| 304 | if (mWin.mPolicyVisibility != mWin.mPolicyVisibilityAfterAnim) { |
| 305 | if (WindowState.DEBUG_VISIBILITY) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 306 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 307 | + mWin.mPolicyVisibilityAfterAnim); |
| 308 | } |
| 309 | mWin.mPolicyVisibility = mWin.mPolicyVisibilityAfterAnim; |
| 310 | mService.mLayoutNeeded = true; |
| 311 | if (!mWin.mPolicyVisibility) { |
| 312 | if (mService.mCurrentFocus == mWin) { |
| 313 | mService.mFocusMayChange = true; |
| 314 | } |
| 315 | // Window is no longer visible -- make sure if we were waiting |
| 316 | // for it to be displayed before enabling the display, that |
| 317 | // we allow the display to be enabled now. |
| 318 | mService.enableScreenIfNeededLocked(); |
| 319 | } |
| 320 | } |
| 321 | mTransformation.clear(); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 322 | if (mDrawState == HAS_DRAWN |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 323 | && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 324 | && mWin.mAppToken != null |
| 325 | && mWin.mAppToken.firstWindowDrawn |
| 326 | && mWin.mAppToken.startingData != null) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 327 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 328 | + mWin.mToken + ": first real window done animating"); |
| 329 | mService.mFinishedStarting.add(mWin.mAppToken); |
| 330 | mService.mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 331 | } |
| 332 | |
| 333 | finishExit(); |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 334 | mAnimator.mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
| 335 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) mService.debugLayoutRepeats( |
| 336 | "WindowStateAnimator", mAnimator.mPendingLayoutChanges); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 337 | |
| 338 | if (mWin.mAppToken != null) { |
| 339 | mWin.mAppToken.updateReportedVisibilityLocked(); |
| 340 | } |
| 341 | |
| 342 | return false; |
| 343 | } |
| 344 | |
| 345 | void finishExit() { |
| 346 | if (WindowManagerService.DEBUG_ANIM) Slog.v( |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 347 | TAG, "finishExit in " + this |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 348 | + ": exiting=" + mWin.mExiting |
| 349 | + " remove=" + mWin.mRemoveOnExit |
| 350 | + " windowAnimating=" + isWindowAnimating()); |
| 351 | |
| 352 | final int N = mWin.mChildWindows.size(); |
| 353 | for (int i=0; i<N; i++) { |
| 354 | mWin.mChildWindows.get(i).mWinAnimator.finishExit(); |
| 355 | } |
| 356 | |
| 357 | if (!mWin.mExiting) { |
| 358 | return; |
| 359 | } |
| 360 | |
| 361 | if (isWindowAnimating()) { |
| 362 | return; |
| 363 | } |
| 364 | |
| 365 | if (WindowManagerService.localLOGV) Slog.v( |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 366 | TAG, "Exit animation finished in " + this |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 367 | + ": remove=" + mWin.mRemoveOnExit); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 368 | if (mSurface != null) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 369 | mService.mDestroySurface.add(mWin); |
| 370 | mWin.mDestroying = true; |
| 371 | if (WindowState.SHOW_TRANSACTIONS) WindowManagerService.logSurface( |
| 372 | mWin, "HIDE (finishExit)", null); |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame^] | 373 | hide(); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 374 | } |
| 375 | mWin.mExiting = false; |
| 376 | if (mWin.mRemoveOnExit) { |
| 377 | mService.mPendingRemove.add(mWin); |
| 378 | mWin.mRemoveOnExit = false; |
| 379 | } |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame^] | 380 | if (mService.mWallpaperTarget == mWin) { |
| 381 | mAnimator.hideWallpapersLocked(); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | void hide() { |
| 386 | if (!mLastHidden) { |
| 387 | //dump(); |
| 388 | mLastHidden = true; |
| 389 | if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, |
| 390 | "HIDE (performLayout)", null); |
| 391 | if (mSurface != null) { |
| 392 | mSurfaceShown = false; |
| 393 | try { |
| 394 | mSurface.hide(); |
| 395 | } catch (RuntimeException e) { |
| 396 | Slog.w(TAG, "Exception hiding surface in " + mWin); |
| 397 | } |
| 398 | } |
| 399 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 402 | boolean finishDrawingLocked() { |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 403 | if (mDrawState == DRAW_PENDING) { |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 404 | if (DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
| 405 | TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + this + " in " |
| 406 | + mSurface); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 407 | mDrawState = COMMIT_DRAW_PENDING; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 408 | return true; |
| 409 | } |
| 410 | return false; |
| 411 | } |
| 412 | |
| 413 | // This must be called while inside a transaction. |
| 414 | boolean commitFinishDrawingLocked(long currentTime) { |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 415 | if (mDrawState != COMMIT_DRAW_PENDING) { |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 416 | return false; |
| 417 | } |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 418 | if (DEBUG_ANIM) |
| 419 | Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurface); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 420 | mDrawState = READY_TO_SHOW; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 421 | final boolean starting = mWin.mAttrs.type == TYPE_APPLICATION_STARTING; |
| 422 | final AppWindowToken atoken = mWin.mAppToken; |
| 423 | if (atoken == null || atoken.allDrawn || starting) { |
| 424 | performShowLocked(); |
| 425 | } |
| 426 | return true; |
| 427 | } |
| 428 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 429 | static class SurfaceTrace extends Surface { |
| 430 | private final static String SURFACE_TAG = "SurfaceTrace"; |
| 431 | final static ArrayList<SurfaceTrace> sSurfaces = new ArrayList<SurfaceTrace>(); |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 432 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 433 | private float mSurfaceTraceAlpha = 0; |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 434 | private int mLayer; |
| 435 | private PointF mPosition = new PointF(); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 436 | private Point mSize; |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 437 | private boolean mShown = false; |
| 438 | private String mName = "Not named"; |
| 439 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 440 | public SurfaceTrace(SurfaceSession s, |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 441 | int pid, int display, int w, int h, int format, int flags) throws |
| 442 | OutOfResourcesException { |
| 443 | super(s, pid, display, w, h, format, flags); |
| 444 | mSize = new Point(w, h); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 445 | Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by " |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 446 | + Debug.getCallers(3)); |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 449 | public SurfaceTrace(SurfaceSession s, |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 450 | int pid, String name, int display, int w, int h, int format, int flags) |
| 451 | throws OutOfResourcesException { |
| 452 | super(s, pid, name, display, w, h, format, flags); |
| 453 | mName = name; |
| 454 | mSize = new Point(w, h); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 455 | Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by " |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 456 | + Debug.getCallers(3)); |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | @Override |
| 460 | public void setAlpha(float alpha) { |
| 461 | super.setAlpha(alpha); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 462 | mSurfaceTraceAlpha = alpha; |
| 463 | Slog.v(SURFACE_TAG, "setAlpha: " + this + ". Called by " |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 464 | + Debug.getCallers(3)); |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | @Override |
| 468 | public void setLayer(int zorder) { |
| 469 | super.setLayer(zorder); |
| 470 | mLayer = zorder; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 471 | Slog.v(SURFACE_TAG, "setLayer: " + this + ". Called by " |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 472 | + Debug.getCallers(3)); |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 473 | |
| 474 | sSurfaces.remove(this); |
| 475 | int i; |
| 476 | for (i = sSurfaces.size() - 1; i >= 0; i--) { |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 477 | SurfaceTrace s = sSurfaces.get(i); |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 478 | if (s.mLayer < zorder) { |
| 479 | break; |
| 480 | } |
| 481 | } |
| 482 | sSurfaces.add(i + 1, this); |
| 483 | } |
| 484 | |
| 485 | @Override |
| 486 | public void setPosition(float x, float y) { |
| 487 | super.setPosition(x, y); |
| 488 | mPosition = new PointF(x, y); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 489 | Slog.v(SURFACE_TAG, "setPosition: " + this + ". Called by " |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 490 | + Debug.getCallers(3)); |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | @Override |
| 494 | public void setSize(int w, int h) { |
| 495 | super.setSize(w, h); |
| 496 | mSize = new Point(w, h); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 497 | Slog.v(SURFACE_TAG, "setSize: " + this + ". Called by " |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 498 | + Debug.getCallers(3)); |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | @Override |
| 502 | public void hide() { |
| 503 | super.hide(); |
| 504 | mShown = false; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 505 | Slog.v(SURFACE_TAG, "hide: " + this + ". Called by " |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 506 | + Debug.getCallers(3)); |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 507 | } |
| 508 | @Override |
| 509 | public void show() { |
| 510 | super.show(); |
| 511 | mShown = true; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 512 | Slog.v(SURFACE_TAG, "show: " + this + ". Called by " |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 513 | + Debug.getCallers(3)); |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | @Override |
| 517 | public void destroy() { |
| 518 | super.destroy(); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 519 | Slog.v(SURFACE_TAG, "destroy: " + this + ". Called by " |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 520 | + Debug.getCallers(3)); |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 521 | sSurfaces.remove(this); |
| 522 | } |
| 523 | |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 524 | @Override |
| 525 | public void release() { |
| 526 | super.release(); |
| 527 | Slog.v(SURFACE_TAG, "release: " + this + ". Called by " |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 528 | + Debug.getCallers(3)); |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 529 | sSurfaces.remove(this); |
| 530 | } |
| 531 | |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 532 | static void dumpAllSurfaces() { |
| 533 | final int N = sSurfaces.size(); |
| 534 | for (int i = 0; i < N; i++) { |
| 535 | Slog.i(TAG, "SurfaceDump: " + sSurfaces.get(i)); |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | @Override |
| 540 | public String toString() { |
Craig Mautner | fbf378c | 2012-04-23 17:24:21 -0700 | [diff] [blame] | 541 | return "Surface " + Integer.toHexString(System.identityHashCode(this)) + " " |
| 542 | + mName + ": shown=" + mShown + " layer=" + mLayer |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 543 | + " alpha=" + mSurfaceTraceAlpha + " " + mPosition.x + "," + mPosition.y |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 544 | + " " + mSize.x + "x" + mSize.y; |
| 545 | } |
| 546 | } |
| 547 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 548 | Surface createSurfaceLocked() { |
| 549 | if (mSurface == null) { |
| 550 | mReportDestroySurface = false; |
| 551 | mSurfacePendingDestroy = false; |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 552 | if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG, |
| 553 | "createSurface " + this + ": mDrawState=DRAW_PENDING"); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 554 | mDrawState = DRAW_PENDING; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 555 | if (mWin.mAppToken != null) { |
| 556 | mWin.mAppToken.allDrawn = false; |
| 557 | } |
| 558 | |
| 559 | mService.makeWindowFreezingScreenIfNeededLocked(mWin); |
| 560 | |
| 561 | int flags = 0; |
| 562 | final WindowManager.LayoutParams attrs = mWin.mAttrs; |
| 563 | |
| 564 | if ((attrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 565 | flags |= Surface.SECURE; |
| 566 | } |
| 567 | if (WindowState.DEBUG_VISIBILITY) Slog.v( |
| 568 | TAG, "Creating surface in session " |
| 569 | + mSession.mSurfaceSession + " window " + this |
| 570 | + " w=" + mWin.mCompatFrame.width() |
| 571 | + " h=" + mWin.mCompatFrame.height() + " format=" |
| 572 | + attrs.format + " flags=" + flags); |
| 573 | |
| 574 | int w = mWin.mCompatFrame.width(); |
| 575 | int h = mWin.mCompatFrame.height(); |
| 576 | if ((attrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 577 | // for a scaled surface, we always want the requested |
| 578 | // size. |
| 579 | w = mWin.mRequestedWidth; |
| 580 | h = mWin.mRequestedHeight; |
| 581 | } |
| 582 | |
| 583 | // Something is wrong and SurfaceFlinger will not like this, |
| 584 | // try to revert to sane values |
| 585 | if (w <= 0) w = 1; |
| 586 | if (h <= 0) h = 1; |
| 587 | |
| 588 | mSurfaceShown = false; |
| 589 | mSurfaceLayer = 0; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 590 | mSurfaceAlpha = 0; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 591 | mSurfaceX = 0; |
| 592 | mSurfaceY = 0; |
| 593 | mSurfaceW = w; |
| 594 | mSurfaceH = h; |
| 595 | try { |
| 596 | final boolean isHwAccelerated = (attrs.flags & |
| 597 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 598 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format; |
| 599 | if (!PixelFormat.formatHasAlpha(attrs.format)) { |
| 600 | flags |= Surface.OPAQUE; |
| 601 | } |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 602 | if (DEBUG_SURFACE_TRACE) { |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 603 | mSurface = new SurfaceTrace( |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 604 | mSession.mSurfaceSession, mSession.mPid, |
| 605 | attrs.getTitle().toString(), |
| 606 | 0, w, h, format, flags); |
| 607 | } else { |
| 608 | mSurface = new Surface( |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 609 | mSession.mSurfaceSession, mSession.mPid, |
| 610 | attrs.getTitle().toString(), |
| 611 | 0, w, h, format, flags); |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 612 | } |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 613 | mWin.mHasSurface = true; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 614 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG, |
| 615 | " CREATE SURFACE " |
| 616 | + mSurface + " IN SESSION " |
| 617 | + mSession.mSurfaceSession |
| 618 | + ": pid=" + mSession.mPid + " format=" |
| 619 | + attrs.format + " flags=0x" |
| 620 | + Integer.toHexString(flags) |
| 621 | + " / " + this); |
| 622 | } catch (Surface.OutOfResourcesException e) { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 623 | mWin.mHasSurface = false; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 624 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
| 625 | mService.reclaimSomeSurfaceMemoryLocked(this, "create", true); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 626 | mDrawState = NO_SURFACE; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 627 | return null; |
| 628 | } catch (Exception e) { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 629 | mWin.mHasSurface = false; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 630 | Slog.e(TAG, "Exception creating surface", e); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 631 | mDrawState = NO_SURFACE; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 632 | return null; |
| 633 | } |
| 634 | |
| 635 | if (WindowManagerService.localLOGV) Slog.v( |
| 636 | TAG, "Got surface: " + mSurface |
| 637 | + ", set left=" + mWin.mFrame.left + " top=" + mWin.mFrame.top |
| 638 | + ", animLayer=" + mAnimLayer); |
| 639 | if (SHOW_LIGHT_TRANSACTIONS) { |
| 640 | Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked"); |
| 641 | WindowManagerService.logSurface(mWin, "CREATE pos=(" |
| 642 | + mWin.mFrame.left + "," + mWin.mFrame.top + ") (" |
| 643 | + mWin.mCompatFrame.width() + "x" + mWin.mCompatFrame.height() |
| 644 | + "), layer=" + mAnimLayer + " HIDE", null); |
| 645 | } |
| 646 | Surface.openTransaction(); |
| 647 | try { |
| 648 | try { |
| 649 | mSurfaceX = mWin.mFrame.left + mWin.mXOffset; |
| 650 | mSurfaceY = mWin.mFrame.top + mWin.mYOffset; |
| 651 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 652 | mSurfaceLayer = mAnimLayer; |
| 653 | mSurface.setLayer(mAnimLayer); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 654 | mSurface.setAlpha(0); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 655 | mSurfaceShown = false; |
| 656 | mSurface.hide(); |
| 657 | if ((mWin.mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| 658 | if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "DITHER", null); |
| 659 | mSurface.setFlags(Surface.SURFACE_DITHER, Surface.SURFACE_DITHER); |
| 660 | } |
| 661 | } catch (RuntimeException e) { |
| 662 | Slog.w(TAG, "Error creating surface in " + w, e); |
| 663 | mService.reclaimSomeSurfaceMemoryLocked(this, "create-init", true); |
| 664 | } |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 665 | mLastHidden = true; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 666 | } finally { |
| 667 | Surface.closeTransaction(); |
| 668 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 669 | "<<< CLOSE TRANSACTION createSurfaceLocked"); |
| 670 | } |
| 671 | if (WindowManagerService.localLOGV) Slog.v( |
| 672 | TAG, "Created surface " + this); |
| 673 | } |
| 674 | return mSurface; |
| 675 | } |
| 676 | |
| 677 | void destroySurfaceLocked() { |
| 678 | if (mWin.mAppToken != null && mWin == mWin.mAppToken.startingWindow) { |
| 679 | mWin.mAppToken.startingDisplayed = false; |
| 680 | } |
| 681 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 682 | mDrawState = NO_SURFACE; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 683 | if (mSurface != null) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 684 | |
| 685 | int i = mWin.mChildWindows.size(); |
| 686 | while (i > 0) { |
| 687 | i--; |
| 688 | WindowState c = mWin.mChildWindows.get(i); |
| 689 | c.mAttachedHidden = true; |
| 690 | } |
| 691 | |
| 692 | if (mReportDestroySurface) { |
| 693 | mReportDestroySurface = false; |
| 694 | mSurfacePendingDestroy = true; |
| 695 | try { |
| 696 | mWin.mClient.dispatchGetNewSurface(); |
| 697 | // We'll really destroy on the next time around. |
| 698 | return; |
| 699 | } catch (RemoteException e) { |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | try { |
| 704 | if (DEBUG_VISIBILITY) { |
| 705 | RuntimeException e = null; |
| 706 | if (!WindowManagerService.HIDE_STACK_CRAWLS) { |
| 707 | e = new RuntimeException(); |
| 708 | e.fillInStackTrace(); |
| 709 | } |
| 710 | Slog.w(TAG, "Window " + this + " destroying surface " |
| 711 | + mSurface + ", session " + mSession, e); |
| 712 | } |
| 713 | if (mSurfaceDestroyDeferred) { |
| 714 | if (mSurface != null && mPendingDestroySurface != mSurface) { |
| 715 | if (mPendingDestroySurface != null) { |
| 716 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { |
| 717 | RuntimeException e = null; |
| 718 | if (!WindowManagerService.HIDE_STACK_CRAWLS) { |
| 719 | e = new RuntimeException(); |
| 720 | e.fillInStackTrace(); |
| 721 | } |
| 722 | WindowManagerService.logSurface(mWin, "DESTROY PENDING", e); |
| 723 | } |
| 724 | mPendingDestroySurface.destroy(); |
| 725 | } |
| 726 | mPendingDestroySurface = mSurface; |
| 727 | } |
| 728 | } else { |
| 729 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { |
| 730 | RuntimeException e = null; |
| 731 | if (!WindowManagerService.HIDE_STACK_CRAWLS) { |
| 732 | e = new RuntimeException(); |
| 733 | e.fillInStackTrace(); |
| 734 | } |
| 735 | WindowManagerService.logSurface(mWin, "DESTROY", e); |
| 736 | } |
| 737 | mSurface.destroy(); |
| 738 | } |
| 739 | } catch (RuntimeException e) { |
| 740 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| 741 | + " surface " + mSurface + " session " + mSession |
| 742 | + ": " + e.toString()); |
| 743 | } |
| 744 | |
| 745 | mSurfaceShown = false; |
| 746 | mSurface = null; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 747 | mWin.mHasSurface =false; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 748 | } |
| 749 | } |
| 750 | |
| 751 | void destroyDeferredSurfaceLocked() { |
| 752 | try { |
| 753 | if (mPendingDestroySurface != null) { |
| 754 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { |
| 755 | RuntimeException e = null; |
| 756 | if (!WindowManagerService.HIDE_STACK_CRAWLS) { |
| 757 | e = new RuntimeException(); |
| 758 | e.fillInStackTrace(); |
| 759 | } |
| 760 | WindowManagerService.logSurface(mWin, "DESTROY PENDING", e); |
| 761 | } |
| 762 | mPendingDestroySurface.destroy(); |
| 763 | } |
| 764 | } catch (RuntimeException e) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 765 | Slog.w(TAG, "Exception thrown when destroying Window " |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 766 | + this + " surface " + mPendingDestroySurface |
| 767 | + " session " + mSession + ": " + e.toString()); |
| 768 | } |
| 769 | mSurfaceDestroyDeferred = false; |
| 770 | mPendingDestroySurface = null; |
| 771 | } |
| 772 | |
| 773 | void computeShownFrameLocked() { |
| 774 | final boolean selfTransformation = mHasLocalTransformation; |
| 775 | Transformation attachedTransformation = |
| 776 | (mAttachedWindow != null && mAttachedWindow.mWinAnimator.mHasLocalTransformation) |
| 777 | ? mAttachedWindow.mWinAnimator.mTransformation : null; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 778 | final AppWindowAnimator appAnimator = |
| 779 | mWin.mAppToken == null ? null : mWin.mAppToken.mAppAnimator; |
| 780 | Transformation appTransformation = (appAnimator != null && appAnimator.hasTransformation) |
| 781 | ? appAnimator.transformation : null; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 782 | |
| 783 | // Wallpapers are animated based on the "real" window they |
| 784 | // are currently targeting. |
| 785 | if (mWin.mAttrs.type == TYPE_WALLPAPER && mService.mLowerWallpaperTarget == null |
| 786 | && mService.mWallpaperTarget != null) { |
| 787 | if (mService.mWallpaperTarget.mWinAnimator.mHasLocalTransformation && |
| 788 | mService.mWallpaperTarget.mWinAnimator.mAnimation != null && |
| 789 | !mService.mWallpaperTarget.mWinAnimator.mAnimation.getDetachWallpaper()) { |
| 790 | attachedTransformation = mService.mWallpaperTarget.mWinAnimator.mTransformation; |
| 791 | if (WindowManagerService.DEBUG_WALLPAPER && attachedTransformation != null) { |
| 792 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
| 793 | } |
| 794 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 795 | final AppWindowAnimator wpAppAnimator = mService.mWallpaperTarget.mAppToken == null |
| 796 | ? null : mService.mWallpaperTarget.mAppToken.mAppAnimator; |
| 797 | if (wpAppAnimator != null && |
| 798 | wpAppAnimator.hasTransformation && |
| 799 | wpAppAnimator.animation != null && |
| 800 | !wpAppAnimator.animation.getDetachWallpaper()) { |
| 801 | appTransformation = wpAppAnimator.transformation; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 802 | if (WindowManagerService.DEBUG_WALLPAPER && appTransformation != null) { |
| 803 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | final boolean screenAnimation = mService.mAnimator.mScreenRotationAnimation != null |
| 809 | && mService.mAnimator.mScreenRotationAnimation.isAnimating(); |
| 810 | if (selfTransformation || attachedTransformation != null |
| 811 | || appTransformation != null || screenAnimation) { |
| 812 | // cache often used attributes locally |
| 813 | final Rect frame = mWin.mFrame; |
| 814 | final float tmpFloats[] = mService.mTmpFloats; |
| 815 | final Matrix tmpMatrix = mWin.mTmpMatrix; |
| 816 | |
| 817 | // Compute the desired transformation. |
| 818 | if (screenAnimation) { |
| 819 | // If we are doing a screen animation, the global rotation |
| 820 | // applied to windows can result in windows that are carefully |
| 821 | // aligned with each other to slightly separate, allowing you |
| 822 | // to see what is behind them. An unsightly mess. This... |
| 823 | // thing... magically makes it call good: scale each window |
| 824 | // slightly (two pixels larger in each dimension, from the |
| 825 | // window's center). |
| 826 | final float w = frame.width(); |
| 827 | final float h = frame.height(); |
| 828 | if (w>=1 && h>=1) { |
| 829 | tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2); |
| 830 | } else { |
| 831 | tmpMatrix.reset(); |
| 832 | } |
| 833 | } else { |
| 834 | tmpMatrix.reset(); |
| 835 | } |
| 836 | tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale); |
| 837 | if (selfTransformation) { |
| 838 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| 839 | } |
| 840 | tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset); |
| 841 | if (attachedTransformation != null) { |
| 842 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| 843 | } |
| 844 | if (appTransformation != null) { |
| 845 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| 846 | } |
| 847 | if (screenAnimation) { |
| 848 | tmpMatrix.postConcat( |
| 849 | mService.mAnimator.mScreenRotationAnimation.getEnterTransformation().getMatrix()); |
| 850 | } |
| 851 | |
| 852 | // "convert" it into SurfaceFlinger's format |
| 853 | // (a 2x2 matrix + an offset) |
| 854 | // Here we must not transform the position of the surface |
| 855 | // since it is already included in the transformation. |
| 856 | //Slog.i(TAG, "Transform: " + matrix); |
| 857 | |
| 858 | mHaveMatrix = true; |
| 859 | tmpMatrix.getValues(tmpFloats); |
| 860 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 861 | mDtDx = tmpFloats[Matrix.MSKEW_Y]; |
| 862 | mDsDy = tmpFloats[Matrix.MSKEW_X]; |
| 863 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| 864 | float x = tmpFloats[Matrix.MTRANS_X]; |
| 865 | float y = tmpFloats[Matrix.MTRANS_Y]; |
| 866 | int w = frame.width(); |
| 867 | int h = frame.height(); |
| 868 | mWin.mShownFrame.set(x, y, x+w, y+h); |
| 869 | |
| 870 | // Now set the alpha... but because our current hardware |
| 871 | // can't do alpha transformation on a non-opaque surface, |
| 872 | // turn it off if we are running an animation that is also |
| 873 | // transforming since it is more important to have that |
| 874 | // animation be smooth. |
| 875 | mShownAlpha = mAlpha; |
| 876 | if (!mService.mLimitedAlphaCompositing |
| 877 | || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format) |
| 878 | || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 879 | && x == frame.left && y == frame.top))) { |
| 880 | //Slog.i(TAG, "Applying alpha transform"); |
| 881 | if (selfTransformation) { |
| 882 | mShownAlpha *= mTransformation.getAlpha(); |
| 883 | } |
| 884 | if (attachedTransformation != null) { |
| 885 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 886 | } |
| 887 | if (appTransformation != null) { |
| 888 | mShownAlpha *= appTransformation.getAlpha(); |
| 889 | } |
| 890 | if (screenAnimation) { |
| 891 | mShownAlpha *= |
| 892 | mService.mAnimator.mScreenRotationAnimation.getEnterTransformation().getAlpha(); |
| 893 | } |
| 894 | } else { |
| 895 | //Slog.i(TAG, "Not applying alpha transform"); |
| 896 | } |
| 897 | |
| 898 | if (WindowManagerService.localLOGV) Slog.v( |
| 899 | TAG, "computeShownFrameLocked: Animating " + this + |
| 900 | ": " + mWin.mShownFrame + |
| 901 | ", alpha=" + mTransformation.getAlpha() + ", mShownAlpha=" + mShownAlpha); |
| 902 | return; |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 903 | } else if (mWin.mIsWallpaper && |
| 904 | (mAnimator.mPendingActions & WindowAnimator.WALLPAPER_ACTION_PENDING) != 0) { |
| 905 | return; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | if (WindowManagerService.localLOGV) Slog.v( |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 909 | TAG, "computeShownFrameLocked: " + this + |
| 910 | " not attached, mAlpha=" + mAlpha); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 911 | mWin.mShownFrame.set(mWin.mFrame); |
| 912 | if (mWin.mXOffset != 0 || mWin.mYOffset != 0) { |
| 913 | mWin.mShownFrame.offset(mWin.mXOffset, mWin.mYOffset); |
| 914 | } |
| 915 | mShownAlpha = mAlpha; |
| 916 | mHaveMatrix = false; |
| 917 | mDsDx = mWin.mGlobalScale; |
| 918 | mDtDx = 0; |
| 919 | mDsDy = 0; |
| 920 | mDtDy = mWin.mGlobalScale; |
| 921 | } |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 922 | |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 923 | void setSurfaceBoundaries(final boolean recoveringMemory) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 924 | final WindowState w = mWin; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 925 | int width, height; |
| 926 | if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 927 | // for a scaled surface, we just want to use |
| 928 | // the requested size. |
| 929 | width = w.mRequestedWidth; |
| 930 | height = w.mRequestedHeight; |
| 931 | } else { |
| 932 | width = w.mCompatFrame.width(); |
| 933 | height = w.mCompatFrame.height(); |
| 934 | } |
| 935 | |
| 936 | if (width < 1) { |
| 937 | width = 1; |
| 938 | } |
| 939 | if (height < 1) { |
| 940 | height = 1; |
| 941 | } |
| 942 | final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height; |
| 943 | if (surfaceResized) { |
| 944 | mSurfaceW = width; |
| 945 | mSurfaceH = height; |
| 946 | } |
| 947 | |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 948 | final float left = w.mShownFrame.left; |
| 949 | final float top = w.mShownFrame.top; |
| 950 | if (mSurfaceX != left || mSurfaceY != top) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 951 | try { |
| 952 | if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 953 | "POS " + left + ", " + top, null); |
| 954 | mSurfaceX = left; |
| 955 | mSurfaceY = top; |
| 956 | mSurface.setPosition(left, top); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 957 | } catch (RuntimeException e) { |
| 958 | Slog.w(TAG, "Error positioning surface of " + w |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 959 | + " pos=(" + left |
| 960 | + "," + top + ")", e); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 961 | if (!recoveringMemory) { |
| 962 | mService.reclaimSomeSurfaceMemoryLocked(this, "position", true); |
| 963 | } |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | if (surfaceResized) { |
| 968 | try { |
| 969 | if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, |
| 970 | "SIZE " + width + "x" + height, null); |
| 971 | mSurfaceResized = true; |
| 972 | mSurface.setSize(width, height); |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 973 | mAnimator.mPendingLayoutChanges |= |
| 974 | WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 975 | } catch (RuntimeException e) { |
| 976 | // If something goes wrong with the surface (such |
| 977 | // as running out of memory), don't take down the |
| 978 | // entire system. |
| 979 | Slog.e(TAG, "Error resizing surface of " + w |
| 980 | + " size=(" + width + "x" + height + ")", e); |
| 981 | if (!recoveringMemory) { |
| 982 | mService.reclaimSomeSurfaceMemoryLocked(this, "size", true); |
| 983 | } |
| 984 | } |
| 985 | } |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | public void prepareSurfaceLocked(final boolean recoveringMemory) { |
| 989 | final WindowState w = mWin; |
| 990 | if (mSurface == null) { |
| 991 | if (w.mOrientationChanging) { |
| 992 | if (DEBUG_ORIENTATION) { |
| 993 | Slog.v(TAG, "Orientation change skips hidden " + w); |
| 994 | } |
| 995 | w.mOrientationChanging = false; |
| 996 | } |
| 997 | return; |
| 998 | } |
| 999 | |
| 1000 | boolean displayed = false; |
| 1001 | |
| 1002 | computeShownFrameLocked(); |
| 1003 | |
| 1004 | setSurfaceBoundaries(recoveringMemory); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1005 | |
Craig Mautner | de6198e | 2012-04-19 09:59:31 -0700 | [diff] [blame] | 1006 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame^] | 1007 | hide(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1008 | // If we are waiting for this window to handle an |
| 1009 | // orientation change, well, it is hidden, so |
| 1010 | // doesn't really matter. Note that this does |
| 1011 | // introduce a potential glitch if the window |
| 1012 | // becomes unhidden before it has drawn for the |
| 1013 | // new orientation. |
| 1014 | if (w.mOrientationChanging) { |
| 1015 | w.mOrientationChanging = false; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1016 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1017 | "Orientation change skips hidden " + w); |
| 1018 | } |
| 1019 | } else if (mLastLayer != mAnimLayer |
| 1020 | || mLastAlpha != mShownAlpha |
| 1021 | || mLastDsDx != mDsDx |
| 1022 | || mLastDtDx != mDtDx |
| 1023 | || mLastDsDy != mDsDy |
| 1024 | || mLastDtDy != mDtDy |
| 1025 | || w.mLastHScale != w.mHScale |
| 1026 | || w.mLastVScale != w.mVScale |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1027 | || mLastHidden) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1028 | displayed = true; |
| 1029 | mLastAlpha = mShownAlpha; |
| 1030 | mLastLayer = mAnimLayer; |
| 1031 | mLastDsDx = mDsDx; |
| 1032 | mLastDtDx = mDtDx; |
| 1033 | mLastDsDy = mDsDy; |
| 1034 | mLastDtDy = mDtDy; |
| 1035 | w.mLastHScale = w.mHScale; |
| 1036 | w.mLastVScale = w.mVScale; |
| 1037 | if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, |
| 1038 | "alpha=" + mShownAlpha + " layer=" + mAnimLayer |
| 1039 | + " matrix=[" + (mDsDx*w.mHScale) |
| 1040 | + "," + (mDtDx*w.mVScale) |
| 1041 | + "][" + (mDsDy*w.mHScale) |
| 1042 | + "," + (mDtDy*w.mVScale) + "]", null); |
| 1043 | if (mSurface != null) { |
| 1044 | try { |
| 1045 | mSurfaceAlpha = mShownAlpha; |
| 1046 | mSurface.setAlpha(mShownAlpha); |
| 1047 | mSurfaceLayer = w.mWinAnimator.mAnimLayer; |
| 1048 | mSurface.setLayer(w.mWinAnimator.mAnimLayer); |
| 1049 | mSurface.setMatrix( |
| 1050 | mDsDx*w.mHScale, mDtDx*w.mVScale, |
| 1051 | mDsDy*w.mHScale, mDtDy*w.mVScale); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1052 | |
| 1053 | if (mLastHidden && mDrawState == HAS_DRAWN) { |
| 1054 | if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, |
| 1055 | "SHOW (performLayout)", null); |
| 1056 | if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
| 1057 | + " during relayout"); |
| 1058 | if (showSurfaceRobustlyLocked()) { |
| 1059 | mLastHidden = false; |
| 1060 | } else { |
| 1061 | w.mOrientationChanging = false; |
| 1062 | } |
| 1063 | } |
| 1064 | if (mSurface != null) { |
| 1065 | w.mToken.hasVisible = true; |
| 1066 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1067 | } catch (RuntimeException e) { |
| 1068 | Slog.w(TAG, "Error updating surface in " + w, e); |
| 1069 | if (!recoveringMemory) { |
| 1070 | mService.reclaimSomeSurfaceMemoryLocked(this, "update", true); |
| 1071 | } |
| 1072 | } |
| 1073 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1074 | } else { |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 1075 | if (DEBUG_ANIM) { |
| 1076 | Slog.v(TAG, "prepareSurface: No changes in animation for " + mWin); |
| 1077 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1078 | displayed = true; |
| 1079 | } |
| 1080 | |
| 1081 | if (displayed) { |
| 1082 | if (w.mOrientationChanging) { |
| 1083 | if (!w.isDrawnLw()) { |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 1084 | mAnimator.mBulkUpdateParams |= CLEAR_ORIENTATION_CHANGE_COMPLETE; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1085 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1086 | "Orientation continue waiting for draw in " + w); |
| 1087 | } else { |
| 1088 | w.mOrientationChanging = false; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1089 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1090 | } |
| 1091 | } |
| 1092 | w.mToken.hasVisible = true; |
| 1093 | } |
| 1094 | } |
| 1095 | |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 1096 | void setTransparentRegionHint(final Region region) { |
Craig Mautner | 1f4e0cc | 2012-04-10 14:24:38 -0700 | [diff] [blame] | 1097 | if (mSurface == null) { |
| 1098 | Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true"); |
| 1099 | return; |
| 1100 | } |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 1101 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 1102 | ">>> OPEN TRANSACTION setTransparentRegion"); |
| 1103 | Surface.openTransaction(); |
| 1104 | try { |
| 1105 | if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, |
| 1106 | "transparentRegionHint=" + region, null); |
| 1107 | mSurface.setTransparentRegionHint(region); |
| 1108 | } finally { |
| 1109 | Surface.closeTransaction(); |
| 1110 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 1111 | "<<< CLOSE TRANSACTION setTransparentRegion"); |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | void setWallpaperOffset(int left, int top) { |
| 1116 | Surface.openTransaction(); |
| 1117 | try { |
| 1118 | mSurfaceX = left; |
| 1119 | mSurfaceY = top; |
| 1120 | mSurface.setPosition(left, top); |
| 1121 | } catch (RuntimeException e) { |
| 1122 | Slog.w(TAG, "Error positioning surface of " + mWin |
| 1123 | + " pos=(" + left + "," + top + ")", e); |
| 1124 | } |
| 1125 | Surface.closeTransaction(); |
| 1126 | } |
| 1127 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1128 | // This must be called while inside a transaction. |
| 1129 | boolean performShowLocked() { |
| 1130 | if (DEBUG_VISIBILITY) { |
| 1131 | RuntimeException e = null; |
| 1132 | if (!WindowManagerService.HIDE_STACK_CRAWLS) { |
| 1133 | e = new RuntimeException(); |
| 1134 | e.fillInStackTrace(); |
| 1135 | } |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 1136 | Slog.v(TAG, "performShow on " + this |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1137 | + ": mDrawState=" + mDrawState + " readyForDisplay=" |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1138 | + mWin.isReadyForDisplay() |
| 1139 | + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 1140 | } |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1141 | if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplay()) { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1142 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1143 | WindowManagerService.logSurface(mWin, "SHOW (performShowLocked)", null); |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 1144 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1145 | + " during animation: policyVis=" + mWin.mPolicyVisibility |
| 1146 | + " attHidden=" + mWin.mAttachedHidden |
| 1147 | + " tok.hiddenRequested=" |
| 1148 | + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false) |
| 1149 | + " tok.hidden=" |
| 1150 | + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false) |
| 1151 | + " animating=" + mAnimating |
| 1152 | + " tok animating=" |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1153 | + (mWin.mAppToken != null ? mWin.mAppToken.mAppAnimator.animating : false)); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1154 | |
| 1155 | mService.enableScreenIfNeededLocked(); |
| 1156 | |
| 1157 | applyEnterAnimationLocked(); |
| 1158 | |
Craig Mautner | de6198e | 2012-04-19 09:59:31 -0700 | [diff] [blame] | 1159 | // Force the show in the next prepareSurfaceLocked() call. |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1160 | mLastAlpha = -1; |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 1161 | if (DEBUG_ANIM) Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN"); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1162 | mDrawState = HAS_DRAWN; |
Craig Mautner | de6198e | 2012-04-19 09:59:31 -0700 | [diff] [blame] | 1163 | mService.scheduleAnimationLocked(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1164 | |
| 1165 | int i = mWin.mChildWindows.size(); |
| 1166 | while (i > 0) { |
| 1167 | i--; |
| 1168 | WindowState c = mWin.mChildWindows.get(i); |
| 1169 | if (c.mAttachedHidden) { |
| 1170 | c.mAttachedHidden = false; |
| 1171 | if (c.mWinAnimator.mSurface != null) { |
| 1172 | c.mWinAnimator.performShowLocked(); |
| 1173 | // It hadn't been shown, which means layout not |
| 1174 | // performed on it, so now we want to make sure to |
| 1175 | // do a layout. If called from within the transaction |
| 1176 | // loop, this will cause it to restart with a new |
| 1177 | // layout. |
| 1178 | mService.mLayoutNeeded = true; |
| 1179 | } |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING |
| 1184 | && mWin.mAppToken != null) { |
| 1185 | mWin.mAppToken.firstWindowDrawn = true; |
| 1186 | |
| 1187 | if (mWin.mAppToken.startingData != null) { |
| 1188 | if (WindowManagerService.DEBUG_STARTING_WINDOW || |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 1189 | WindowManagerService.DEBUG_ANIM) Slog.v(TAG, |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1190 | "Finish starting " + mWin.mToken |
| 1191 | + ": first real window is shown, no animation"); |
| 1192 | // If this initial window is animating, stop it -- we |
| 1193 | // will do an animation to reveal it from behind the |
| 1194 | // starting window, so there is no need for it to also |
| 1195 | // be doing its own stuff. |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 1196 | clearAnimation(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1197 | mService.mFinishedStarting.add(mWin.mAppToken); |
| 1198 | mService.mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 1199 | } |
| 1200 | mWin.mAppToken.updateReportedVisibilityLocked(); |
| 1201 | } |
| 1202 | |
| 1203 | return true; |
| 1204 | } |
| 1205 | |
| 1206 | return false; |
| 1207 | } |
| 1208 | |
| 1209 | /** |
| 1210 | * Have the surface flinger show a surface, robustly dealing with |
| 1211 | * error conditions. In particular, if there is not enough memory |
| 1212 | * to show the surface, then we will try to get rid of other surfaces |
| 1213 | * in order to succeed. |
| 1214 | * |
| 1215 | * @return Returns true if the surface was successfully shown. |
| 1216 | */ |
| 1217 | boolean showSurfaceRobustlyLocked() { |
| 1218 | try { |
| 1219 | if (mSurface != null) { |
| 1220 | mSurfaceShown = true; |
| 1221 | mSurface.show(); |
| 1222 | if (mWin.mTurnOnScreen) { |
| 1223 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 1224 | "Show surface turning screen on: " + mWin); |
| 1225 | mWin.mTurnOnScreen = false; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 1226 | mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | return true; |
| 1230 | } catch (RuntimeException e) { |
| 1231 | Slog.w(TAG, "Failure showing surface " + mSurface + " in " + mWin, e); |
| 1232 | } |
| 1233 | |
| 1234 | mService.reclaimSomeSurfaceMemoryLocked(this, "show", true); |
| 1235 | |
| 1236 | return false; |
| 1237 | } |
| 1238 | |
| 1239 | void applyEnterAnimationLocked() { |
| 1240 | final int transit; |
| 1241 | if (mEnterAnimationPending) { |
| 1242 | mEnterAnimationPending = false; |
| 1243 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 1244 | } else { |
| 1245 | transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 1246 | } |
| 1247 | |
| 1248 | applyAnimationLocked(transit, true); |
| 1249 | } |
| 1250 | |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 1251 | // TODO(cmautner): Move back to WindowState? |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1252 | /** |
| 1253 | * Choose the correct animation and set it to the passed WindowState. |
| 1254 | * @param transit If WindowManagerPolicy.TRANSIT_PREVIEW_DONE and the app window has been drawn |
| 1255 | * then the animation will be app_starting_exit. Any other value loads the animation from |
| 1256 | * the switch statement below. |
| 1257 | * @param isEntrance The animation type the last time this was called. Used to keep from |
| 1258 | * loading the same animation twice. |
| 1259 | * @return true if an animation has been loaded. |
| 1260 | */ |
| 1261 | boolean applyAnimationLocked(int transit, boolean isEntrance) { |
| 1262 | if (mLocalAnimating && mAnimationIsEntrance == isEntrance) { |
| 1263 | // If we are trying to apply an animation, but already running |
| 1264 | // an animation of the same type, then just leave that one alone. |
| 1265 | return true; |
| 1266 | } |
| 1267 | |
| 1268 | // Only apply an animation if the display isn't frozen. If it is |
| 1269 | // frozen, there is no reason to animate and it can cause strange |
| 1270 | // artifacts when we unfreeze the display if some different animation |
| 1271 | // is running. |
| 1272 | if (mService.okToDisplay()) { |
| 1273 | int anim = mPolicy.selectAnimationLw(mWin, transit); |
| 1274 | int attr = -1; |
| 1275 | Animation a = null; |
| 1276 | if (anim != 0) { |
| 1277 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 1278 | } else { |
| 1279 | switch (transit) { |
| 1280 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 1281 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 1282 | break; |
| 1283 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 1284 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 1285 | break; |
| 1286 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 1287 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 1288 | break; |
| 1289 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 1290 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 1291 | break; |
| 1292 | } |
| 1293 | if (attr >= 0) { |
| 1294 | a = mService.loadAnimation(mWin.mAttrs, attr); |
| 1295 | } |
| 1296 | } |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 1297 | if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG, |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1298 | "applyAnimation: win=" + this |
| 1299 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 1300 | + " a=" + a |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1301 | + " mAnimation=" + mAnimation |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 1302 | + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3)); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1303 | if (a != null) { |
| 1304 | if (WindowManagerService.DEBUG_ANIM) { |
| 1305 | RuntimeException e = null; |
| 1306 | if (!WindowManagerService.HIDE_STACK_CRAWLS) { |
| 1307 | e = new RuntimeException(); |
| 1308 | e.fillInStackTrace(); |
| 1309 | } |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 1310 | Slog.v(TAG, "Loaded animation " + a + " for " + this, e); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1311 | } |
| 1312 | setAnimation(a); |
| 1313 | mAnimationIsEntrance = isEntrance; |
| 1314 | } |
| 1315 | } else { |
| 1316 | clearAnimation(); |
| 1317 | } |
| 1318 | |
| 1319 | return mAnimation != null; |
| 1320 | } |
| 1321 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1322 | public void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
| 1323 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 1324 | || mAnimation != null) { |
| 1325 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 1326 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 1327 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 1328 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 1329 | } |
| 1330 | if (mHasTransformation || mHasLocalTransformation) { |
| 1331 | pw.print(prefix); pw.print("XForm: has="); |
| 1332 | pw.print(mHasTransformation); |
| 1333 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 1334 | pw.print(" "); mTransformation.printShortString(pw); |
| 1335 | pw.println(); |
| 1336 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1337 | if (mSurface != null) { |
| 1338 | if (dumpAll) { |
| 1339 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1340 | pw.print(prefix); pw.print("mDrawState="); pw.print(mDrawState); |
| 1341 | pw.print(" mLastHidden="); pw.println(mLastHidden); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1342 | } |
| 1343 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 1344 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 1345 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 1346 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 1347 | pw.print(","); pw.print(mSurfaceY); |
| 1348 | pw.print(") "); pw.print(mSurfaceW); |
| 1349 | pw.print(" x "); pw.println(mSurfaceH); |
| 1350 | } |
| 1351 | if (mPendingDestroySurface != null) { |
| 1352 | pw.print(prefix); pw.print("mPendingDestroySurface="); |
| 1353 | pw.println(mPendingDestroySurface); |
| 1354 | } |
| 1355 | if (mSurfaceResized || mSurfaceDestroyDeferred) { |
| 1356 | pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized); |
| 1357 | pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred); |
| 1358 | } |
| 1359 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 1360 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 1361 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 1362 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 1363 | } |
| 1364 | if (mHaveMatrix || mWin.mGlobalScale != 1) { |
| 1365 | pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale); |
| 1366 | pw.print(" mDsDx="); pw.print(mDsDx); |
| 1367 | pw.print(" mDtDx="); pw.print(mDtDx); |
| 1368 | pw.print(" mDsDy="); pw.print(mDsDy); |
| 1369 | pw.print(" mDtDy="); pw.println(mDtDy); |
| 1370 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1373 | @Override |
| 1374 | public String toString() { |
| 1375 | StringBuffer sb = new StringBuffer("WindowStateAnimator ("); |
| 1376 | sb.append(mWin.mLastTitle + "): "); |
| 1377 | sb.append("mSurface " + mSurface); |
| 1378 | sb.append(", mAnimation " + mAnimation); |
| 1379 | return sb.toString(); |
| 1380 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1381 | } |