Refactor thumbnail layer code

Removed a redundant variable in AppWindowAnimator and simplified the
function arguments in WindowSurfacePlacer.

Fixes: 62029108
Test: go/wm-smoke
Change-Id: I0c3cc95e112ee267b3a77e367e831c3e0c10b5b0
This commit is contained in:
Matthew Ng
2017-09-29 10:27:24 -07:00
parent f62d88c7bc
commit b7e8a13b5d
5 changed files with 32 additions and 48 deletions

View File

@@ -16,10 +16,10 @@
package com.android.server.wm;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
@@ -78,11 +78,8 @@ public class AppWindowAnimator {
// requires that the duration of the two animations are the same.
SurfaceControl thumbnail;
int thumbnailTransactionSeq;
// TODO(b/62029108): combine both members into a private one. Create a member function to set
// the thumbnail layer to +1 to the highest layer position and replace all setter instances
// with this function. Remove all unnecessary calls to both variables in other classes.
int thumbnailLayer;
int thumbnailForceAboveLayer;
private int mThumbnailLayer;
Animation thumbnailAnimation;
final Transformation thumbnailTransformation = new Transformation();
// This flag indicates that the destruction of the thumbnail surface is synchronized with
@@ -256,7 +253,7 @@ public class AppWindowAnimator {
private void updateLayers() {
mAppToken.getDisplayContent().assignWindowLayers(false /* relayoutNeeded */);
thumbnailLayer = mAppToken.getHighestAnimLayer();
updateThumbnailLayer();
}
private void stepThumbnailAnimation(long currentTime) {
@@ -280,25 +277,34 @@ public class AppWindowAnimator {
thumbnail.setPosition(tmpFloats[Matrix.MTRANS_X], tmpFloats[Matrix.MTRANS_Y]);
if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(thumbnail,
"thumbnail", "alpha=" + thumbnailTransformation.getAlpha()
+ " layer=" + thumbnailLayer
+ " layer=" + mThumbnailLayer
+ " matrix=[" + tmpFloats[Matrix.MSCALE_X]
+ "," + tmpFloats[Matrix.MSKEW_Y]
+ "][" + tmpFloats[Matrix.MSKEW_X]
+ "," + tmpFloats[Matrix.MSCALE_Y] + "]");
thumbnail.setAlpha(thumbnailTransformation.getAlpha());
if (thumbnailForceAboveLayer > 0) {
thumbnail.setLayer(thumbnailForceAboveLayer + 1);
} else {
// The thumbnail is layered below the window immediately above this
// token's anim layer.
thumbnail.setLayer(thumbnailLayer + WindowManagerService.WINDOW_LAYER_MULTIPLIER
- WindowManagerService.LAYER_OFFSET_THUMBNAIL);
}
updateThumbnailLayer();
thumbnail.setMatrix(tmpFloats[Matrix.MSCALE_X], tmpFloats[Matrix.MSKEW_Y],
tmpFloats[Matrix.MSKEW_X], tmpFloats[Matrix.MSCALE_Y]);
thumbnail.setWindowCrop(thumbnailTransformation.getClipRect());
}
/**
* Updates the thumbnail layer z order to just above the highest animation layer if changed
*/
void updateThumbnailLayer() {
if (thumbnail != null) {
final int layer = mAppToken.getHighestAnimLayer();
if (layer != mThumbnailLayer) {
if (DEBUG_LAYERS) Slog.v(TAG,
"Setting thumbnail layer " + mAppToken + ": layer=" + layer);
thumbnail.setLayer(layer + WindowManagerService.WINDOW_LAYER_MULTIPLIER
- WindowManagerService.LAYER_OFFSET_THUMBNAIL);
mThumbnailLayer = layer;
}
}
}
/**
* Sometimes we need to synchronize the first frame of animation with some external event, e.g.
* Recents hiding some of its content. To achieve this, we prolong the start of the animaiton
@@ -473,7 +479,7 @@ public class AppWindowAnimator {
}
if (thumbnail != null) {
pw.print(prefix); pw.print("thumbnail="); pw.print(thumbnail);
pw.print(" layer="); pw.println(thumbnailLayer);
pw.print(" layer="); pw.println(mThumbnailLayer);
pw.print(prefix); pw.print("thumbnailAnimation="); pw.println(thumbnailAnimation);
pw.print(prefix); pw.print("thumbnailTransformation=");
pw.println(thumbnailTransformation.toShortString());

View File

@@ -1170,7 +1170,6 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
wAppAnimator.thumbnail.destroy();
}
wAppAnimator.thumbnail = tAppAnimator.thumbnail;
wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
tAppAnimator.thumbnail = null;
}

View File

@@ -391,10 +391,6 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
!= mTmpWindowAnimator.mAnimTransactionSequence) {
appAnimator.thumbnailTransactionSeq =
mTmpWindowAnimator.mAnimTransactionSequence;
appAnimator.thumbnailLayer = 0;
}
if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) {
appAnimator.thumbnailLayer = winAnimator.mAnimLayer;
}
}
};

View File

@@ -266,20 +266,8 @@ class WindowLayersController {
w.mLayer = layer;
w.mWinAnimator.mAnimLayer = w.getAnimLayerAdjustment()
+ w.getSpecialWindowAnimLayerAdjustment();
if (w.mAppToken != null && w.mAppToken.mAppAnimator.thumbnailForceAboveLayer > 0) {
if (w.mWinAnimator.mAnimLayer > w.mAppToken.mAppAnimator.thumbnailForceAboveLayer) {
w.mAppToken.mAppAnimator.thumbnailForceAboveLayer = w.mWinAnimator.mAnimLayer;
}
// TODO(b/62029108): the entire contents of the if statement should call the refactored
// function to set the thumbnail layer for w.AppToken
int highestLayer = w.mAppToken.getHighestAnimLayer();
if (highestLayer > 0) {
if (w.mAppToken.mAppAnimator.thumbnail != null
&& w.mAppToken.mAppAnimator.thumbnailForceAboveLayer != highestLayer) {
w.mAppToken.mAppAnimator.thumbnailForceAboveLayer = highestLayer;
w.mAppToken.mAppAnimator.thumbnail.setLayer(highestLayer + 1);
}
}
if (w.mAppToken != null) {
w.mAppToken.mAppAnimator.updateThumbnailLayer();
}
}
}

View File

@@ -342,10 +342,7 @@ class WindowSurfacePlacer {
mTmpLayerAndToken.token = null;
handleClosingApps(transit, animLp, voiceInteraction, mTmpLayerAndToken);
final AppWindowToken topClosingApp = mTmpLayerAndToken.token;
final int topClosingLayer = mTmpLayerAndToken.layer;
final AppWindowToken topOpeningApp = handleOpeningApps(transit,
animLp, voiceInteraction, topClosingLayer);
final AppWindowToken topOpeningApp = handleOpeningApps(transit, animLp, voiceInteraction);
mService.mAppTransition.setLastAppTransition(transit, topOpeningApp, topClosingApp);
@@ -387,8 +384,9 @@ class WindowSurfacePlacer {
}
private AppWindowToken handleOpeningApps(int transit, LayoutParams animLp,
boolean voiceInteraction, int topClosingLayer) {
boolean voiceInteraction) {
AppWindowToken topOpeningApp = null;
int topOpeningLayer = Integer.MIN_VALUE;
final int appsCount = mService.mOpeningApps.size();
for (int i = 0; i < appsCount; i++) {
AppWindowToken wtoken = mService.mOpeningApps.valueAt(i);
@@ -422,7 +420,6 @@ class WindowSurfacePlacer {
}
mService.mAnimator.mAppWindowAnimating |= appAnimator.isAnimating();
int topOpeningLayer = 0;
if (animLp != null) {
final int layer = wtoken.getHighestAnimLayer();
if (topOpeningApp == null || layer > topOpeningLayer) {
@@ -431,7 +428,7 @@ class WindowSurfacePlacer {
}
}
if (mService.mAppTransition.isNextAppTransitionThumbnailUp()) {
createThumbnailAppAnimator(transit, wtoken, topOpeningLayer, topClosingLayer);
createThumbnailAppAnimator(transit, wtoken);
}
}
return topOpeningApp;
@@ -473,7 +470,7 @@ class WindowSurfacePlacer {
}
}
if (mService.mAppTransition.isNextAppTransitionThumbnailDown()) {
createThumbnailAppAnimator(transit, wtoken, 0, layerAndToken.layer);
createThumbnailAppAnimator(transit, wtoken);
}
}
}
@@ -666,8 +663,7 @@ class WindowSurfacePlacer {
}
}
private void createThumbnailAppAnimator(int transit, AppWindowToken appToken,
int openingLayer, int closingLayer) {
private void createThumbnailAppAnimator(int transit, AppWindowToken appToken) {
AppWindowAnimator openingAppAnimator = (appToken == null) ? null : appToken.mAppAnimator;
if (openingAppAnimator == null || openingAppAnimator.animation == null) {
return;
@@ -724,7 +720,6 @@ class WindowSurfacePlacer {
anim = mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(appRect,
insets, thumbnailHeader, taskId, displayConfig.uiMode,
displayConfig.orientation);
openingAppAnimator.thumbnailForceAboveLayer = Math.max(openingLayer, closingLayer);
openingAppAnimator.deferThumbnailDestruction =
!mService.mAppTransition.isNextThumbnailTransitionScaleUp();
} else {
@@ -734,8 +729,8 @@ class WindowSurfacePlacer {
anim.restrictDuration(MAX_ANIMATION_DURATION);
anim.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
openingAppAnimator.updateThumbnailLayer();
openingAppAnimator.thumbnail = surfaceControl;
openingAppAnimator.thumbnailLayer = openingLayer;
openingAppAnimator.thumbnailAnimation = anim;
mService.mAppTransition.getNextAppTransitionStartRect(taskId, mTmpStartRect);
} catch (Surface.OutOfResourcesException e) {