Skip to content

Commit 5d724f5

Browse files
Craig MautnerAndroid (Google) Code Review
authored andcommitted
Merge "Further isolate the Surface from WindowState."
2 parents 0cf7507 + c8bc97e commit 5d724f5

File tree

4 files changed

+59
-48
lines changed

4 files changed

+59
-48
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ void updateReportedVisibilityLocked() {
376376
int numDrawn = 0;
377377
boolean nowGone = true;
378378

379-
if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "Update reported visibility: " + this);
379+
if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
380+
"Update reported visibility: " + this);
380381
final int N = allAppWindows.size();
381382
for (int i=0; i<N; i++) {
382383
WindowState win = allAppWindows.get(i);

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

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,7 +2314,7 @@ public void removeWindowLocked(Session session, WindowState win) {
23142314
// to hold off on removing the window until the animation is done.
23152315
// If the display is frozen, just remove immediately, since the
23162316
// animation wouldn't be seen.
2317-
if (win.mWinAnimator.mSurface != null && okToDisplay()) {
2317+
if (win.mHasSurface && okToDisplay()) {
23182318
// If we are not currently running the exit animation, we
23192319
// need to see about starting one.
23202320
wasVisible = win.isWinVisibleLw();
@@ -2458,8 +2458,7 @@ private void removeWindowInnerLocked(Session session, WindowState win) {
24582458
}
24592459

24602460
static void logSurface(WindowState w, String msg, RuntimeException where) {
2461-
String str = " SURFACE " + Integer.toHexString(w.hashCode())
2462-
+ ": " + msg + " / " + w.mAttrs.getTitle();
2461+
String str = " SURFACE " + msg + ": " + w;
24632462
if (where != null) {
24642463
Slog.i(TAG, str, where);
24652464
} else {
@@ -2481,15 +2480,14 @@ void setTransparentRegionWindow(Session session, IWindow client, Region region)
24812480
try {
24822481
synchronized (mWindowMap) {
24832482
WindowState w = windowForClientLocked(session, client, false);
2484-
WindowStateAnimator winAnimator = w.mWinAnimator;
2485-
if ((w != null) && (winAnimator.mSurface != null)) {
2483+
if ((w != null) && w.mHasSurface) {
24862484
if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
24872485
">>> OPEN TRANSACTION setTransparentRegion");
24882486
Surface.openTransaction();
24892487
try {
24902488
if (SHOW_TRANSACTIONS) logSurface(w,
24912489
"transparentRegionHint=" + region, null);
2492-
winAnimator.mSurface.setTransparentRegionHint(region);
2490+
w.mWinAnimator.mSurface.setTransparentRegionHint(region);
24932491
} finally {
24942492
Surface.closeTransaction();
24952493
if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
@@ -2618,10 +2616,10 @@ public int relayoutWindow(Session session, IWindow client, int seq,
26182616

26192617
synchronized(mWindowMap) {
26202618
WindowState win = windowForClientLocked(session, client, false);
2621-
WindowStateAnimator winAnimator = win.mWinAnimator;
26222619
if (win == null) {
26232620
return 0;
26242621
}
2622+
WindowStateAnimator winAnimator = win.mWinAnimator;
26252623
if (win.mRequestedWidth != requestedWidth
26262624
|| win.mRequestedHeight != requestedHeight) {
26272625
win.mLayoutNeeded = true;
@@ -2702,6 +2700,7 @@ public int relayoutWindow(Session session, IWindow client, int seq,
27022700
displayed = !win.isVisibleLw();
27032701
if (win.mExiting) {
27042702
winAnimator.cancelExitAnimationForNextAnimationLocked();
2703+
win.mExiting = false;
27052704
}
27062705
if (win.mDestroying) {
27072706
win.mDestroying = false;
@@ -2740,7 +2739,7 @@ public int relayoutWindow(Session session, IWindow client, int seq,
27402739
surfaceChanged = true;
27412740
}
27422741
try {
2743-
if (winAnimator.mSurface == null) {
2742+
if (!win.mHasSurface) {
27442743
surfaceChanged = true;
27452744
}
27462745
Surface surface = winAnimator.createSurfaceLocked();
@@ -3416,15 +3415,13 @@ public int getOrientationFromWindowsLocked() {
34163415
}
34173416

34183417
public int getOrientationFromAppTokensLocked() {
3419-
int pos = mAppTokens.size() - 1;
34203418
int curGroup = 0;
34213419
int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
34223420
boolean findingBehind = false;
34233421
boolean haveGroup = false;
34243422
boolean lastFullscreen = false;
3425-
while (pos >= 0) {
3423+
for (int pos = mAppTokens.size() - 1; pos >= 0; pos--) {
34263424
AppWindowToken wtoken = mAppTokens.get(pos);
3427-
pos--;
34283425

34293426
if (DEBUG_APP_ORIENTATION) Slog.v(TAG, "Checking app orientation: " + wtoken);
34303427

@@ -4138,7 +4135,7 @@ void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
41384135
WindowState w = wtoken.allAppWindows.get(i);
41394136
if (w.mAppFreezing) {
41404137
w.mAppFreezing = false;
4141-
if (w.mWinAnimator.mSurface != null && !w.mOrientationChanging) {
4138+
if (w.mHasSurface && !w.mOrientationChanging) {
41424139
if (DEBUG_ORIENTATION) Slog.v(TAG, "set mOrientationChanging of " + w);
41434140
w.mOrientationChanging = true;
41444141
}
@@ -4726,7 +4723,7 @@ public void closeSystemDialogs(String reason) {
47264723
synchronized(mWindowMap) {
47274724
for (int i=mWindows.size()-1; i>=0; i--) {
47284725
WindowState w = mWindows.get(i);
4729-
if (w.mWinAnimator.mSurface != null) {
4726+
if (w.mHasSurface) {
47304727
try {
47314728
w.mClient.closeSystemDialogs(reason);
47324729
} catch (RemoteException e) {
@@ -5198,7 +5195,7 @@ public Bitmap screenshotApplications(IBinder appToken, int width, int height) {
51985195
boolean including = false;
51995196
for (int i=mWindows.size()-1; i>=0; i--) {
52005197
WindowState ws = mWindows.get(i);
5201-
if (ws.mWinAnimator.mSurface == null) {
5198+
if (!ws.mHasSurface) {
52025199
continue;
52035200
}
52045201
if (ws.mLayer >= aboveAppLayer) {
@@ -5512,7 +5509,7 @@ public boolean updateRotationUncheckedLocked(boolean inTransaction) {
55125509

55135510
for (int i=mWindows.size()-1; i>=0; i--) {
55145511
WindowState w = mWindows.get(i);
5515-
if (w.mWinAnimator.mSurface != null) {
5512+
if (w.mHasSurface) {
55165513
if (DEBUG_ORIENTATION) Slog.v(TAG, "Set mOrientationChanging of " + w);
55175514
w.mOrientationChanging = true;
55185515
}
@@ -8027,7 +8024,7 @@ private int animateAwayWallpaperLocked() {
80278024
mAnimator.mForceHiding = false;
80288025
for (int i=mWindows.size()-1; i>=0; i--) {
80298026
WindowState w = mWindows.get(i);
8030-
if (w.mWinAnimator.mSurface != null) {
8027+
if (w.mHasSurface) {
80318028
final WindowManager.LayoutParams attrs = w.mAttrs;
80328029
if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
80338030
if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
@@ -8127,7 +8124,7 @@ private void handleNotObscuredLocked(final WindowState w, final long currentTime
81278124
final int attrFlags = attrs.flags;
81288125
final boolean canBeSeen = w.isDisplayedLw();
81298126

8130-
if (w.mWinAnimator.mSurface != null) {
8127+
if (w.mHasSurface) {
81318128
if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
81328129
mInnerFields.mHoldScreen = w.mSession;
81338130
}
@@ -8279,7 +8276,7 @@ private final void performLayoutAndPlaceSurfacesLockedInner(
82798276
mPolicy.beginAnimationLw(dw, dh);
82808277
for (i = mWindows.size() - 1; i >= 0; i--) {
82818278
WindowState w = mWindows.get(i);
8282-
if (w.mWinAnimator.mSurface != null) {
8279+
if (w.mHasSurface) {
82838280
mPolicy.animatingWindowLw(w, w.mAttrs);
82848281
}
82858282
}
@@ -8397,7 +8394,7 @@ private final void performLayoutAndPlaceSurfacesLockedInner(
83978394
updateResizingWindows(w);
83988395

83998396
// Moved from updateWindowsAndWallpaperLocked().
8400-
if (winAnimator.mSurface != null) {
8397+
if (w.mHasSurface) {
84018398
// Take care of the window being ready to display.
84028399
if (winAnimator.commitFinishDrawingLocked(currentTime)) {
84038400
if ((w.mAttrs.flags
@@ -8456,10 +8453,8 @@ private final void performLayoutAndPlaceSurfacesLockedInner(
84568453
stopFreezingDisplayLocked();
84578454
}
84588455

8459-
i = mResizingWindows.size();
8460-
if (i > 0) {
8461-
do {
8462-
i--;
8456+
if (!mResizingWindows.isEmpty()) {
8457+
for (i = mResizingWindows.size() - 1; i >= 0; i--) {
84638458
WindowState win = mResizingWindows.get(i);
84648459
final WindowStateAnimator winAnimator = win.mWinAnimator;
84658460
try {
@@ -8490,7 +8485,7 @@ private final void performLayoutAndPlaceSurfacesLockedInner(
84908485
} catch (RemoteException e) {
84918486
win.mOrientationChanging = false;
84928487
}
8493-
} while (i > 0);
8488+
}
84948489
mResizingWindows.clear();
84958490
}
84968491

@@ -8725,6 +8720,7 @@ boolean reclaimSomeSurfaceMemoryLocked(WindowStateAnimator winAnimator, String o
87258720
wsa.mSurface.destroy();
87268721
wsa.mSurfaceShown = false;
87278722
wsa.mSurface = null;
8723+
ws.mHasSurface = false;
87288724
mForceRemoves.add(ws);
87298725
i--;
87308726
N--;
@@ -8737,6 +8733,7 @@ boolean reclaimSomeSurfaceMemoryLocked(WindowStateAnimator winAnimator, String o
87378733
wsa.mSurface.destroy();
87388734
wsa.mSurfaceShown = false;
87398735
wsa.mSurface = null;
8736+
ws.mHasSurface = false;
87408737
leakedSurface = true;
87418738
}
87428739
}
@@ -8775,6 +8772,7 @@ boolean reclaimSomeSurfaceMemoryLocked(WindowStateAnimator winAnimator, String o
87758772
surface.destroy();
87768773
winAnimator.mSurfaceShown = false;
87778774
winAnimator.mSurface = null;
8775+
winAnimator.mWin.mHasSurface = false;
87788776
}
87798777

87808778
try {

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ final class WindowState implements WindowManagerPolicy.WindowState {
246246

247247
final WindowStateAnimator mWinAnimator;
248248

249+
boolean mHasSurface = false;
250+
249251
WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
250252
WindowState attachedWindow, int seq, WindowManager.LayoutParams a,
251253
int viewVisibility) {
@@ -609,7 +611,7 @@ void prelayout() {
609611
*/
610612
public boolean isVisibleLw() {
611613
final AppWindowToken atoken = mAppToken;
612-
return mWinAnimator.mSurface != null && mPolicyVisibility && !mAttachedHidden
614+
return mHasSurface && mPolicyVisibility && !mAttachedHidden
613615
&& (atoken == null || !atoken.hiddenRequested)
614616
&& !mExiting && !mDestroying;
615617
}
@@ -630,7 +632,7 @@ public boolean isVisibleOrBehindKeyguardLw() {
630632
final AppWindowToken atoken = mAppToken;
631633
final boolean animating = atoken != null
632634
? (atoken.animation != null) : false;
633-
return mWinAnimator.mSurface != null && !mDestroying && !mExiting
635+
return mHasSurface && !mDestroying && !mExiting
634636
&& (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
635637
&& ((!mAttachedHidden && mViewVisibility == View.VISIBLE
636638
&& !mRootToken.hidden)
@@ -644,7 +646,7 @@ public boolean isVisibleOrBehindKeyguardLw() {
644646
*/
645647
public boolean isWinVisibleLw() {
646648
final AppWindowToken atoken = mAppToken;
647-
return mWinAnimator.mSurface != null && mPolicyVisibility && !mAttachedHidden
649+
return mHasSurface && mPolicyVisibility && !mAttachedHidden
648650
&& (atoken == null || !atoken.hiddenRequested || atoken.animating)
649651
&& !mExiting && !mDestroying;
650652
}
@@ -654,7 +656,7 @@ public boolean isWinVisibleLw() {
654656
* the associated app token, not the pending requested hidden state.
655657
*/
656658
boolean isVisibleNow() {
657-
return mWinAnimator.mSurface != null && mPolicyVisibility && !mAttachedHidden
659+
return mHasSurface && mPolicyVisibility && !mAttachedHidden
658660
&& !mRootToken.hidden && !mExiting && !mDestroying;
659661
}
660662

@@ -674,7 +676,7 @@ boolean isPotentialDragTarget() {
674676
*/
675677
boolean isVisibleOrAdding() {
676678
final AppWindowToken atoken = mAppToken;
677-
return ((mWinAnimator.mSurface != null && !mWinAnimator.mReportDestroySurface)
679+
return ((mHasSurface && !mWinAnimator.mReportDestroySurface)
678680
|| (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
679681
&& mPolicyVisibility && !mAttachedHidden
680682
&& (atoken == null || !atoken.hiddenRequested)
@@ -687,15 +689,15 @@ boolean isVisibleOrAdding() {
687689
* being visible.
688690
*/
689691
boolean isOnScreen() {
692+
if (!mHasSurface || !mPolicyVisibility || mDestroying) {
693+
return false;
694+
}
690695
final AppWindowToken atoken = mAppToken;
691696
if (atoken != null) {
692-
return mWinAnimator.mSurface != null && mPolicyVisibility && !mDestroying
693-
&& ((!mAttachedHidden && !atoken.hiddenRequested)
697+
return ((!mAttachedHidden && !atoken.hiddenRequested)
694698
|| mWinAnimator.mAnimation != null || atoken.animation != null);
695-
} else {
696-
return mWinAnimator.mSurface != null && mPolicyVisibility && !mDestroying
697-
&& (!mAttachedHidden || mWinAnimator.mAnimation != null);
698699
}
700+
return !mAttachedHidden || mWinAnimator.mAnimation != null;
699701
}
700702

701703
/**
@@ -707,7 +709,7 @@ boolean isReadyForDisplay() {
707709
mService.mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
708710
return false;
709711
}
710-
return mWinAnimator.mSurface != null && mPolicyVisibility && !mDestroying
712+
return mHasSurface && mPolicyVisibility && !mDestroying
711713
&& ((!mAttachedHidden && mViewVisibility == View.VISIBLE
712714
&& !mRootToken.hidden)
713715
|| mWinAnimator.mAnimation != null
@@ -741,8 +743,8 @@ public boolean isGoneForLayoutLw() {
741743
* complete UI in to.
742744
*/
743745
public boolean isDrawnLw() {
744-
return mWinAnimator.mSurface != null && !mDestroying
745-
&& !mWinAnimator.mDrawPending && !mWinAnimator.mCommitDrawPending;
746+
return mHasSurface && !mDestroying &&
747+
!mWinAnimator.mDrawPending && !mWinAnimator.mCommitDrawPending;
746748
}
747749

748750
/**
@@ -1017,8 +1019,8 @@ void dump(PrintWriter pw, String prefix, boolean dumpAll) {
10171019
}
10181020
pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
10191021
}
1020-
pw.print(prefix); pw.print("mShownFrame=");
1021-
mShownFrame.printShortString(pw); pw.println();
1022+
pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
1023+
pw.print(" mShownFrame="); mShownFrame.printShortString(pw); pw.println();
10221024
if (dumpAll) {
10231025
pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
10241026
pw.print(" last="); mLastFrame.printShortString(pw);

0 commit comments

Comments
 (0)