Skip to content

Commit 1505ce2

Browse files
Craig MautnerAndroid (Google) Code Review
authored andcommitted
Merge "Move Surface operations out of WindowState."
2 parents d05b326 + c2f9be0 commit 1505ce2

File tree

6 files changed

+1052
-1023
lines changed

6 files changed

+1052
-1023
lines changed

services/java/com/android/server/wm/AppWindowToken.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,14 @@ void updateLayers() {
184184
final int adj = animLayerAdjustment;
185185
thumbnailLayer = -1;
186186
for (int i=0; i<N; i++) {
187-
WindowState w = allAppWindows.get(i);
188-
w.mAnimLayer = w.mLayer + adj;
189-
if (w.mAnimLayer > thumbnailLayer) {
190-
thumbnailLayer = w.mAnimLayer;
187+
final WindowState w = allAppWindows.get(i);
188+
final WindowStateAnimator winAnimator = w.mWinAnimator;
189+
winAnimator.mAnimLayer = w.mLayer + adj;
190+
if (winAnimator.mAnimLayer > thumbnailLayer) {
191+
thumbnailLayer = winAnimator.mAnimLayer;
191192
}
192193
if (WindowManagerService.DEBUG_LAYERS) Slog.v(WindowManagerService.TAG, "Updating layer " + w + ": "
193-
+ w.mAnimLayer);
194+
+ winAnimator.mAnimLayer);
194195
if (w == service.mInputMethodTarget && !service.mInputMethodTargetWaitingAnim) {
195196
service.setInputMethodAnimLayerAdjustment(adj);
196197
}
@@ -221,11 +222,11 @@ boolean showAllWindowsLocked() {
221222
boolean isAnimating = false;
222223
final int NW = allAppWindows.size();
223224
for (int i=0; i<NW; i++) {
224-
WindowState w = allAppWindows.get(i);
225+
WindowStateAnimator winAnimator = allAppWindows.get(i).mWinAnimator;
225226
if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
226-
"performing show on: " + w);
227-
w.performShowLocked();
228-
isAnimating |= w.mWinAnimator.isAnimating();
227+
"performing show on: " + winAnimator);
228+
winAnimator.performShowLocked();
229+
isAnimating |= winAnimator.isAnimating();
229230
}
230231
return isAnimating;
231232
}
@@ -390,7 +391,7 @@ void updateReportedVisibilityLocked() {
390391
+ win.isDrawnLw()
391392
+ ", isAnimating=" + win.mWinAnimator.isAnimating());
392393
if (!win.isDrawnLw()) {
393-
Slog.v(WindowManagerService.TAG, "Not displayed: s=" + win.mSurface
394+
Slog.v(WindowManagerService.TAG, "Not displayed: s=" + win.mWinAnimator.mSurface
394395
+ " pv=" + win.mPolicyVisibility
395396
+ " dp=" + win.mDrawPending
396397
+ " cdp=" + win.mCommitDrawPending

services/java/com/android/server/wm/DimAnimator.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,18 @@ void show(int dw, int dh) {
8585
* {@link #updateSurface} after all windows are examined.
8686
*/
8787
void updateParameters(Resources res, WindowState w, long currentTime) {
88-
mDimSurface.setLayer(w.mAnimLayer - WindowManagerService.LAYER_OFFSET_DIM);
88+
final WindowStateAnimator winAnimator = w.mWinAnimator;
89+
mDimSurface.setLayer(winAnimator.mAnimLayer - WindowManagerService.LAYER_OFFSET_DIM);
8990

9091
final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
91-
if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, " DIM " + mDimSurface
92-
+ ": layer=" + (w.mAnimLayer-1) + " target=" + target);
92+
if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, " DIM "
93+
+ mDimSurface + ": layer=" + (winAnimator.mAnimLayer-1) + " target=" + target);
9394
if (mDimTargetAlpha != target) {
9495
// If the desired dim level has changed, then
9596
// start an animation to it.
9697
mLastDimAnimTime = currentTime;
97-
long duration = (w.mWinAnimator.mAnimating && w.mWinAnimator.mAnimation != null)
98-
? w.mWinAnimator.mAnimation.computeDurationHint()
98+
long duration = (winAnimator.mAnimating && winAnimator.mAnimation != null)
99+
? winAnimator.mAnimation.computeDurationHint()
99100
: WindowManagerService.DEFAULT_DIM_DURATION;
100101
if (target > mDimTargetAlpha) {
101102
TypedValue tv = new TypedValue();

services/java/com/android/server/wm/WindowAnimator.java

Lines changed: 17 additions & 202 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import android.util.Slog;
1111
import android.view.Surface;
1212
import android.view.WindowManager;
13-
import android.view.WindowManager.LayoutParams;
1413
import android.view.WindowManagerPolicy;
1514
import android.view.animation.Animation;
1615

@@ -103,7 +102,7 @@ private void testWallpaperAndBackgroundLocked() {
103102
final int dw = mDw;
104103
final int dh = mDh;
105104
mWindowAnimationBackgroundSurface.show(dw, dh,
106-
target.mAnimLayer - WindowManagerService.LAYER_OFFSET_DIM,
105+
target.mWinAnimator.mAnimLayer - WindowManagerService.LAYER_OFFSET_DIM,
107106
mWindowAnimationBackgroundColor);
108107
} else if (mWindowAnimationBackgroundSurface != null) {
109108
mWindowAnimationBackgroundSurface.hide();
@@ -164,10 +163,9 @@ private void updateWindowsAndWallpaperLocked() {
164163
for (int i = mService.mWindows.size() - 1; i >= 0; i--) {
165164
WindowState w = mService.mWindows.get(i);
166165
WindowStateAnimator winAnimator = w.mWinAnimator;
167-
168166
final WindowManager.LayoutParams attrs = w.mAttrs;
169167

170-
if (w.mSurface != null) {
168+
if (winAnimator.mSurface != null) {
171169
final boolean wasAnimating = winAnimator.mWasAnimating;
172170
final boolean nowAnimating = winAnimator.stepAnimationLocked(mCurrentTime);
173171

@@ -181,13 +179,14 @@ private void updateWindowsAndWallpaperLocked() {
181179
// a detached wallpaper animation.
182180
if (nowAnimating) {
183181
if (winAnimator.mAnimation != null) {
184-
if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0
182+
if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0
185183
&& winAnimator.mAnimation.getDetachWallpaper()) {
186-
mService.mInnerFields.mDetachedWallpaper = w;
184+
mDetachedWallpaper = w;
187185
}
188186
if (winAnimator.mAnimation.getBackgroundColor() != 0) {
189187
if (mWindowAnimationBackground == null
190-
|| (w.mAnimLayer < mWindowAnimationBackground.mAnimLayer)) {
188+
|| (winAnimator.mAnimLayer <
189+
mWindowAnimationBackground.mWinAnimator.mAnimLayer)) {
191190
mWindowAnimationBackground = w;
192191
mWindowAnimationBackgroundColor =
193192
winAnimator.mAnimation.getBackgroundColor();
@@ -202,14 +201,14 @@ private void updateWindowsAndWallpaperLocked() {
202201
// displayed behind it.
203202
if (w.mAppToken != null && w.mAppToken.animation != null
204203
&& w.mAppToken.animating) {
205-
if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0
204+
if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0
206205
&& w.mAppToken.animation.getDetachWallpaper()) {
207-
mService.mInnerFields.mDetachedWallpaper = w;
206+
mDetachedWallpaper = w;
208207
}
209208
if (w.mAppToken.animation.getBackgroundColor() != 0) {
210209
if (mWindowAnimationBackground == null
211-
|| (w.mAnimLayer <
212-
mWindowAnimationBackground.mAnimLayer)) {
210+
|| (winAnimator.mAnimLayer <
211+
mWindowAnimationBackground.mWinAnimator.mAnimLayer)) {
213212
mWindowAnimationBackground = w;
214213
mWindowAnimationBackgroundColor =
215214
w.mAppToken.animation.getBackgroundColor();
@@ -296,7 +295,7 @@ private void updateWindowsAndWallpaperLocked() {
296295
+ w.isDrawnLw()
297296
+ ", isAnimating=" + winAnimator.isAnimating());
298297
if (!w.isDrawnLw()) {
299-
Slog.v(TAG, "Not displayed: s=" + w.mSurface
298+
Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurface
300299
+ " pv=" + w.mPolicyVisibility
301300
+ " dp=" + w.mDrawPending
302301
+ " cdp=" + w.mCommitDrawPending
@@ -323,7 +322,7 @@ private void updateWindowsAndWallpaperLocked() {
323322
}
324323
}
325324
} else if (w.mReadyToShow) {
326-
if (w.performShowLocked()) {
325+
if (winAnimator.performShowLocked()) {
327326
mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
328327
if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
329328
mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 5");
@@ -335,8 +334,8 @@ private void updateWindowsAndWallpaperLocked() {
335334
atoken.thumbnailTransactionSeq = mTransactionSequence;
336335
atoken.thumbnailLayer = 0;
337336
}
338-
if (atoken.thumbnailLayer < w.mAnimLayer) {
339-
atoken.thumbnailLayer = w.mAnimLayer;
337+
if (atoken.thumbnailLayer < winAnimator.mAnimLayer) {
338+
atoken.thumbnailLayer = winAnimator.mAnimLayer;
340339
}
341340
}
342341
} // end forall windows
@@ -386,14 +385,10 @@ private void testTokenMayBeDrawnLocked() {
386385
}
387386

388387
private void performAnimationsLocked() {
389-
if (WindowManagerService.DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
390-
+ mTransactionSequence + " mAnimating="
391-
+ mAnimating);
392-
393388
mTokenMayBeDrawn = false;
394389
mService.mInnerFields.mWallpaperMayChange = false;
395390
mForceHiding = false;
396-
mService.mInnerFields.mDetachedWallpaper = null;
391+
mDetachedWallpaper = null;
397392
mWindowAnimationBackground = null;
398393
mWindowAnimationBackgroundColor = 0;
399394

@@ -402,188 +397,8 @@ private void performAnimationsLocked() {
402397
if (mTokenMayBeDrawn) {
403398
testTokenMayBeDrawnLocked();
404399
}
405-
406-
if (WindowManagerService.DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
407-
+ Integer.toHexString(mPendingLayoutChanges));
408400
}
409401

410-
public void prepareSurfaceLocked(final WindowState w, final boolean recoveringMemory) {
411-
if (w.mSurface == null) {
412-
if (w.mOrientationChanging) {
413-
if (WindowManagerService.DEBUG_ORIENTATION) {
414-
Slog.v(TAG, "Orientation change skips hidden " + w);
415-
}
416-
w.mOrientationChanging = false;
417-
}
418-
return;
419-
}
420-
421-
boolean displayed = false;
422-
423-
w.computeShownFrameLocked();
424-
425-
int width, height;
426-
if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
427-
// for a scaled surface, we just want to use
428-
// the requested size.
429-
width = w.mRequestedWidth;
430-
height = w.mRequestedHeight;
431-
} else {
432-
width = w.mCompatFrame.width();
433-
height = w.mCompatFrame.height();
434-
}
435-
436-
if (width < 1) {
437-
width = 1;
438-
}
439-
if (height < 1) {
440-
height = 1;
441-
}
442-
final boolean surfaceResized = w.mSurfaceW != width || w.mSurfaceH != height;
443-
if (surfaceResized) {
444-
w.mSurfaceW = width;
445-
w.mSurfaceH = height;
446-
}
447-
448-
if (w.mSurfaceX != w.mShownFrame.left
449-
|| w.mSurfaceY != w.mShownFrame.top) {
450-
try {
451-
if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
452-
"POS " + w.mShownFrame.left
453-
+ ", " + w.mShownFrame.top, null);
454-
w.mSurfaceX = w.mShownFrame.left;
455-
w.mSurfaceY = w.mShownFrame.top;
456-
w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
457-
} catch (RuntimeException e) {
458-
Slog.w(TAG, "Error positioning surface of " + w
459-
+ " pos=(" + w.mShownFrame.left
460-
+ "," + w.mShownFrame.top + ")", e);
461-
if (!recoveringMemory) {
462-
mService.reclaimSomeSurfaceMemoryLocked(w, "position", true);
463-
}
464-
}
465-
}
466-
467-
if (surfaceResized) {
468-
try {
469-
if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
470-
"SIZE " + width + "x" + height, null);
471-
w.mSurfaceResized = true;
472-
w.mSurface.setSize(width, height);
473-
} catch (RuntimeException e) {
474-
// If something goes wrong with the surface (such
475-
// as running out of memory), don't take down the
476-
// entire system.
477-
Slog.e(TAG, "Error resizing surface of " + w
478-
+ " size=(" + width + "x" + height + ")", e);
479-
if (!recoveringMemory) {
480-
mService.reclaimSomeSurfaceMemoryLocked(w, "size", true);
481-
}
482-
}
483-
}
484-
485-
if (w.mAttachedHidden || !w.isReadyForDisplay()) {
486-
if (!w.mLastHidden) {
487-
//dump();
488-
w.mLastHidden = true;
489-
if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
490-
"HIDE (performLayout)", null);
491-
if (w.mSurface != null) {
492-
w.mSurfaceShown = false;
493-
try {
494-
w.mSurface.hide();
495-
} catch (RuntimeException e) {
496-
Slog.w(TAG, "Exception hiding surface in " + w);
497-
}
498-
}
499-
}
500-
// If we are waiting for this window to handle an
501-
// orientation change, well, it is hidden, so
502-
// doesn't really matter. Note that this does
503-
// introduce a potential glitch if the window
504-
// becomes unhidden before it has drawn for the
505-
// new orientation.
506-
if (w.mOrientationChanging) {
507-
w.mOrientationChanging = false;
508-
if (WindowManagerService.DEBUG_ORIENTATION) Slog.v(TAG,
509-
"Orientation change skips hidden " + w);
510-
}
511-
} else if (w.mLastLayer != w.mAnimLayer
512-
|| w.mLastAlpha != w.mShownAlpha
513-
|| w.mLastDsDx != w.mDsDx
514-
|| w.mLastDtDx != w.mDtDx
515-
|| w.mLastDsDy != w.mDsDy
516-
|| w.mLastDtDy != w.mDtDy
517-
|| w.mLastHScale != w.mHScale
518-
|| w.mLastVScale != w.mVScale
519-
|| w.mLastHidden) {
520-
displayed = true;
521-
w.mLastAlpha = w.mShownAlpha;
522-
w.mLastLayer = w.mAnimLayer;
523-
w.mLastDsDx = w.mDsDx;
524-
w.mLastDtDx = w.mDtDx;
525-
w.mLastDsDy = w.mDsDy;
526-
w.mLastDtDy = w.mDtDy;
527-
w.mLastHScale = w.mHScale;
528-
w.mLastVScale = w.mVScale;
529-
if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
530-
"alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
531-
+ " matrix=[" + (w.mDsDx*w.mHScale)
532-
+ "," + (w.mDtDx*w.mVScale)
533-
+ "][" + (w.mDsDy*w.mHScale)
534-
+ "," + (w.mDtDy*w.mVScale) + "]", null);
535-
if (w.mSurface != null) {
536-
try {
537-
w.mSurfaceAlpha = w.mShownAlpha;
538-
w.mSurface.setAlpha(w.mShownAlpha);
539-
w.mSurfaceLayer = w.mAnimLayer;
540-
w.mSurface.setLayer(w.mAnimLayer);
541-
w.mSurface.setMatrix(
542-
w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
543-
w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
544-
} catch (RuntimeException e) {
545-
Slog.w(TAG, "Error updating surface in " + w, e);
546-
if (!recoveringMemory) {
547-
mService.reclaimSomeSurfaceMemoryLocked(w, "update", true);
548-
}
549-
}
550-
}
551-
552-
if (w.mLastHidden && w.isDrawnLw()
553-
&& !w.mReadyToShow) {
554-
if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
555-
"SHOW (performLayout)", null);
556-
if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
557-
+ " during relayout");
558-
if (mService.showSurfaceRobustlyLocked(w)) {
559-
w.mHasDrawn = true;
560-
w.mLastHidden = false;
561-
} else {
562-
w.mOrientationChanging = false;
563-
}
564-
}
565-
if (w.mSurface != null) {
566-
w.mToken.hasVisible = true;
567-
}
568-
} else {
569-
displayed = true;
570-
}
571-
572-
if (displayed) {
573-
if (w.mOrientationChanging) {
574-
if (!w.isDrawnLw()) {
575-
mService.mInnerFields.mOrientationChangeComplete = false;
576-
if (WindowManagerService.DEBUG_ORIENTATION) Slog.v(TAG,
577-
"Orientation continue waiting for draw in " + w);
578-
} else {
579-
w.mOrientationChanging = false;
580-
if (WindowManagerService.DEBUG_ORIENTATION) Slog.v(TAG,
581-
"Orientation change complete in " + w);
582-
}
583-
}
584-
w.mToken.hasVisible = true;
585-
}
586-
}
587402

588403
void animate() {
589404
mPendingLayoutChanges = 0;
@@ -608,7 +423,7 @@ void animate() {
608423
final int N = mService.mWindows.size();
609424
for (int i=N-1; i>=0; i--) {
610425
WindowState w = mService.mWindows.get(i);
611-
prepareSurfaceLocked(w, true);
426+
w.mWinAnimator.prepareSurfaceLocked(true);
612427
}
613428

614429
if (mService.mDimAnimator != null && mService.mDimAnimator.mDimShown) {
@@ -629,7 +444,7 @@ void animate() {
629444
} finally {
630445
Surface.closeTransaction();
631446
}
632-
447+
633448
if (mWallpaperMayChange) {
634449
mService.notifyWallpaperMayChange();
635450
}

0 commit comments

Comments
 (0)