Skip to content

Commit 48ba1e7

Browse files
author
Craig Mautner
committed
Defer a couple of Surface actions for WSAnimator.
Perform the set-transparent-region-hint operation outside of the WindowManagerService loop. This is to isolate the Surface operation from the WindowManagerService inner loop. Similarly, defer the setWallpaperOffset call so it's animation is not coupled to the WindowManagerService inner loop. Note that both operations are still being done on the WindowManagerService thread. Change-Id: I97f030b2a9b7cffe91c77342a299bfac6e59e9f8
1 parent c8bc97e commit 48ba1e7

File tree

2 files changed

+74
-19
lines changed

2 files changed

+74
-19
lines changed

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

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,6 +1972,11 @@ void wallpaperOffsetsComplete(IBinder window) {
19721972
}
19731973
}
19741974

1975+
// TODO(cmautner): Move to WindowAnimator.
1976+
void setWallpaperOffset(final WindowStateAnimator winAnimator, final int left, final int top) {
1977+
mH.sendMessage(mH.obtainMessage(H.SET_WALLPAPER_OFFSET, left, top, winAnimator));
1978+
}
1979+
19751980
void updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
19761981
final int dw = mAppDisplayWidth;
19771982
final int dh = mAppDisplayHeight;
@@ -2010,10 +2015,8 @@ void updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
20102015
if (SHOW_TRANSACTIONS) logSurface(wallpaper,
20112016
"POS " + wallpaper.mShownFrame.left
20122017
+ ", " + wallpaper.mShownFrame.top, null);
2013-
winAnimator.mSurfaceX = wallpaper.mShownFrame.left;
2014-
winAnimator.mSurfaceY = wallpaper.mShownFrame.top;
2015-
winAnimator.mSurface.setPosition(wallpaper.mShownFrame.left,
2016-
wallpaper.mShownFrame.top);
2018+
setWallpaperOffset(winAnimator, (int) wallpaper.mShownFrame.left,
2019+
(int) wallpaper.mShownFrame.top);
20172020
} catch (RuntimeException e) {
20182021
Slog.w(TAG, "Error positioning surface of " + wallpaper
20192022
+ " pos=(" + wallpaper.mShownFrame.left
@@ -2474,25 +2477,20 @@ static void logSurface(Surface s, String title, String msg, RuntimeException whe
24742477
Slog.i(TAG, str);
24752478
}
24762479
}
2477-
2480+
2481+
// TODO(cmautner): Move to WindowStateAnimator.
2482+
void setTransparentRegionHint(final WindowStateAnimator winAnimator, final Region region) {
2483+
mH.sendMessage(mH.obtainMessage(H.SET_TRANSPARENT_REGION,
2484+
new Pair<WindowStateAnimator, Region>(winAnimator, region)));
2485+
}
2486+
24782487
void setTransparentRegionWindow(Session session, IWindow client, Region region) {
24792488
long origId = Binder.clearCallingIdentity();
24802489
try {
24812490
synchronized (mWindowMap) {
24822491
WindowState w = windowForClientLocked(session, client, false);
24832492
if ((w != null) && w.mHasSurface) {
2484-
if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
2485-
">>> OPEN TRANSACTION setTransparentRegion");
2486-
Surface.openTransaction();
2487-
try {
2488-
if (SHOW_TRANSACTIONS) logSurface(w,
2489-
"transparentRegionHint=" + region, null);
2490-
w.mWinAnimator.mSurface.setTransparentRegionHint(region);
2491-
} finally {
2492-
Surface.closeTransaction();
2493-
if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
2494-
"<<< CLOSE TRANSACTION setTransparentRegion");
2495-
}
2493+
setTransparentRegionHint(w.mWinAnimator, region);
24962494
}
24972495
}
24982496
} finally {
@@ -2615,6 +2613,7 @@ public int relayoutWindow(Session session, IWindow client, int seq,
26152613
long origId = Binder.clearCallingIdentity();
26162614

26172615
synchronized(mWindowMap) {
2616+
// TODO(cmautner): synchronize on mAnimator or win.mWinAnimator.
26182617
WindowState win = windowForClientLocked(session, client, false);
26192618
if (win == null) {
26202619
return 0;
@@ -6656,6 +6655,10 @@ final class H extends Handler {
66566655
public static final int WAITING_FOR_DRAWN_TIMEOUT = 24;
66576656
public static final int BULK_UPDATE_PARAMETERS = 25;
66586657

6658+
public static final int ANIMATOR_WHAT_OFFSET = 100000;
6659+
public static final int SET_TRANSPARENT_REGION = ANIMATOR_WHAT_OFFSET + 1;
6660+
public static final int SET_WALLPAPER_OFFSET = ANIMATOR_WHAT_OFFSET + 2;
6661+
66596662
private Session mLastReportedHold;
66606663

66616664
public H() {
@@ -7079,6 +7082,28 @@ public void handleMessage(Message msg) {
70797082

70807083
requestTraversalLocked();
70817084
}
7085+
break;
7086+
}
7087+
7088+
// Animation messages. Move to Window{State}Animator
7089+
case SET_TRANSPARENT_REGION: {
7090+
// TODO(cmautner): Remove sync.
7091+
synchronized (mWindowMap) {
7092+
Pair<WindowStateAnimator, Region> pair =
7093+
(Pair<WindowStateAnimator, Region>) msg.obj;
7094+
final WindowStateAnimator winAnimator = pair.first;
7095+
winAnimator.setTransparentRegionHint(pair.second);
7096+
}
7097+
break;
7098+
}
7099+
7100+
case SET_WALLPAPER_OFFSET: {
7101+
// TODO(cmautner): Remove sync.
7102+
synchronized (mWindowMap) {
7103+
final WindowStateAnimator winAnimator = (WindowStateAnimator) msg.obj;
7104+
winAnimator.setWallpaperOffset(msg.arg1, msg.arg2);
7105+
}
7106+
break;
70827107
}
70837108
}
70847109
}

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.graphics.Matrix;
1010
import android.graphics.PixelFormat;
1111
import android.graphics.Rect;
12+
import android.graphics.Region;
1213
import android.os.RemoteException;
1314
import android.util.Slog;
1415
import android.view.Surface;
@@ -357,7 +358,7 @@ void finishExit() {
357358

358359
boolean finishDrawingLocked() {
359360
if (mDrawPending) {
360-
if (SHOW_TRANSACTIONS || WindowManagerService.DEBUG_ORIENTATION) Slog.v(
361+
if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
361362
TAG, "finishDrawingLocked: " + this + " in " + mSurface);
362363
mCommitDrawPending = true;
363364
mDrawPending = false;
@@ -386,7 +387,7 @@ Surface createSurfaceLocked() {
386387
if (mSurface == null) {
387388
mReportDestroySurface = false;
388389
mSurfacePendingDestroy = false;
389-
if (WindowManagerService.DEBUG_ORIENTATION) Slog.i(TAG,
390+
if (DEBUG_ORIENTATION) Slog.i(TAG,
390391
"createSurface " + this + ": DRAW NOW PENDING");
391392
mDrawPending = true;
392393
mCommitDrawPending = false;
@@ -923,6 +924,34 @@ public void prepareSurfaceLocked(final boolean recoveringMemory) {
923924
}
924925
}
925926

927+
void setTransparentRegionHint(final Region region) {
928+
if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
929+
">>> OPEN TRANSACTION setTransparentRegion");
930+
Surface.openTransaction();
931+
try {
932+
if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
933+
"transparentRegionHint=" + region, null);
934+
mSurface.setTransparentRegionHint(region);
935+
} finally {
936+
Surface.closeTransaction();
937+
if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
938+
"<<< CLOSE TRANSACTION setTransparentRegion");
939+
}
940+
}
941+
942+
void setWallpaperOffset(int left, int top) {
943+
Surface.openTransaction();
944+
try {
945+
mSurfaceX = left;
946+
mSurfaceY = top;
947+
mSurface.setPosition(left, top);
948+
} catch (RuntimeException e) {
949+
Slog.w(TAG, "Error positioning surface of " + mWin
950+
+ " pos=(" + left + "," + top + ")", e);
951+
}
952+
Surface.closeTransaction();
953+
}
954+
926955
// This must be called while inside a transaction.
927956
boolean performShowLocked() {
928957
if (DEBUG_VISIBILITY) {
@@ -1053,6 +1082,7 @@ void applyEnterAnimationLocked() {
10531082
applyAnimationLocked(transit, true);
10541083
}
10551084

1085+
// TODO(cmautner): Move back to WindowState?
10561086
/**
10571087
* Choose the correct animation and set it to the passed WindowState.
10581088
* @param transit If WindowManagerPolicy.TRANSIT_PREVIEW_DONE and the app window has been drawn

0 commit comments

Comments
 (0)