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