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