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