Merge "Clean unnecessary lock of WindowAnimator#animate" into rvc-dev am: 15b6d1e648 am: 485f5b266a

Change-Id: I6f37620d9e5fea565261390e4777ffef7a14e3b1
This commit is contained in:
Automerger Merge Worker
2020-03-16 04:20:58 +00:00
2 changed files with 75 additions and 95 deletions

View File

@@ -96,8 +96,8 @@ public class WindowAnimator {
mAnimationFrameCallback = frameTimeNs -> { mAnimationFrameCallback = frameTimeNs -> {
synchronized (mService.mGlobalLock) { synchronized (mService.mGlobalLock) {
mAnimationFrameCallbackScheduled = false; mAnimationFrameCallbackScheduled = false;
animate(frameTimeNs);
} }
animate(frameTimeNs);
}; };
} }
@@ -115,110 +115,94 @@ public class WindowAnimator {
mInitialized = true; mInitialized = true;
} }
/**
* DO NOT HOLD THE WINDOW MANAGER LOCK WHILE CALLING THIS METHOD. Reason: the method closes
* an animation transaction, that might be blocking until the next sf-vsync, so we want to make
* sure other threads can make progress if this happens.
*/
private void animate(long frameTimeNs) { private void animate(long frameTimeNs) {
if (!mInitialized) {
synchronized (mService.mGlobalLock) { return;
if (!mInitialized) {
return;
}
// Schedule next frame already such that back-pressure happens continuously
scheduleAnimation();
} }
synchronized (mService.mGlobalLock) { // Schedule next frame already such that back-pressure happens continuously.
mCurrentTime = frameTimeNs / TimeUtils.NANOS_PER_MS; scheduleAnimation();
mBulkUpdateParams = SET_ORIENTATION_CHANGE_COMPLETE;
if (DEBUG_WINDOW_TRACE) { mCurrentTime = frameTimeNs / TimeUtils.NANOS_PER_MS;
Slog.i(TAG, "!!! animate: entry time=" + mCurrentTime); mBulkUpdateParams = SET_ORIENTATION_CHANGE_COMPLETE;
if (DEBUG_WINDOW_TRACE) {
Slog.i(TAG, "!!! animate: entry time=" + mCurrentTime);
}
ProtoLog.i(WM_SHOW_TRANSACTIONS, ">>> OPEN TRANSACTION animate");
mService.openSurfaceTransaction();
try {
final AccessibilityController accessibilityController =
mService.mAccessibilityController;
final int numDisplays = mDisplayContentsAnimators.size();
for (int i = 0; i < numDisplays; i++) {
final int displayId = mDisplayContentsAnimators.keyAt(i);
final DisplayContent dc = mService.mRoot.getDisplayContent(displayId);
// Update animations of all applications, including those associated with
// exiting/removed apps.
dc.updateWindowsForAnimator();
dc.prepareSurfaces();
} }
ProtoLog.i(WM_SHOW_TRANSACTIONS, ">>> OPEN TRANSACTION animate"); for (int i = 0; i < numDisplays; i++) {
mService.openSurfaceTransaction(); final int displayId = mDisplayContentsAnimators.keyAt(i);
try { final DisplayContent dc = mService.mRoot.getDisplayContent(displayId);
final AccessibilityController accessibilityController =
mService.mAccessibilityController; dc.checkAppWindowsReadyToShow();
final int numDisplays = mDisplayContentsAnimators.size(); if (accessibilityController != null) {
for (int i = 0; i < numDisplays; i++) { accessibilityController.drawMagnifiedRegionBorderIfNeededLocked(displayId,
final int displayId = mDisplayContentsAnimators.keyAt(i); mTransaction);
final DisplayContent dc = mService.mRoot.getDisplayContent(displayId);
// Update animations of all applications, including those
// associated with exiting/removed apps
dc.updateWindowsForAnimator();
dc.prepareSurfaces();
} }
for (int i = 0; i < numDisplays; i++) {
final int displayId = mDisplayContentsAnimators.keyAt(i);
final DisplayContent dc = mService.mRoot.getDisplayContent(displayId);
dc.checkAppWindowsReadyToShow();
if (accessibilityController != null) {
accessibilityController.drawMagnifiedRegionBorderIfNeededLocked(displayId,
mTransaction);
}
}
cancelAnimation();
if (mService.mWatermark != null) {
mService.mWatermark.drawIfNeeded();
}
SurfaceControl.mergeToGlobalTransaction(mTransaction);
} catch (RuntimeException e) {
Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
} finally {
mService.closeSurfaceTransaction("WindowAnimator");
ProtoLog.i(WM_SHOW_TRANSACTIONS, "<<< CLOSE TRANSACTION animate");
} }
boolean hasPendingLayoutChanges = mService.mRoot.hasPendingLayoutChanges(this); cancelAnimation();
boolean doRequest = false;
if (mBulkUpdateParams != 0) { if (mService.mWatermark != null) {
doRequest = mService.mRoot.copyAnimToLayoutParams(); mService.mWatermark.drawIfNeeded();
} }
if (hasPendingLayoutChanges || doRequest) { SurfaceControl.mergeToGlobalTransaction(mTransaction);
mService.mWindowPlacerLocked.requestTraversal(); } catch (RuntimeException e) {
} Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
} finally {
mService.closeSurfaceTransaction("WindowAnimator");
ProtoLog.i(WM_SHOW_TRANSACTIONS, "<<< CLOSE TRANSACTION animate");
}
final boolean rootAnimating = mService.mRoot.isAnimating(TRANSITION | CHILDREN); final boolean hasPendingLayoutChanges = mService.mRoot.hasPendingLayoutChanges(this);
if (rootAnimating && !mLastRootAnimating) { final boolean doRequest = mBulkUpdateParams != 0 && mService.mRoot.copyAnimToLayoutParams();
if (hasPendingLayoutChanges || doRequest) {
mService.mWindowPlacerLocked.requestTraversal();
}
// Usually app transitions but quite a load onto the system already (with all the final boolean rootAnimating = mService.mRoot.isAnimating(TRANSITION | CHILDREN);
// things happening in app), so pause task snapshot persisting to not increase the if (rootAnimating && !mLastRootAnimating) {
// load. // Usually app transitions but quite a load onto the system already (with all the things
mService.mTaskSnapshotController.setPersisterPaused(true); // happening in app), so pause task snapshot persisting to not increase the load.
Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "animating", 0); mService.mTaskSnapshotController.setPersisterPaused(true);
} Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "animating", 0);
if (!rootAnimating && mLastRootAnimating) { }
mService.mWindowPlacerLocked.requestTraversal(); if (!rootAnimating && mLastRootAnimating) {
mService.mTaskSnapshotController.setPersisterPaused(false); mService.mWindowPlacerLocked.requestTraversal();
Trace.asyncTraceEnd(Trace.TRACE_TAG_WINDOW_MANAGER, "animating", 0); mService.mTaskSnapshotController.setPersisterPaused(false);
} Trace.asyncTraceEnd(Trace.TRACE_TAG_WINDOW_MANAGER, "animating", 0);
}
mLastRootAnimating = rootAnimating; mLastRootAnimating = rootAnimating;
if (mRemoveReplacedWindows) { if (mRemoveReplacedWindows) {
mService.mRoot.removeReplacedWindows(); mService.mRoot.removeReplacedWindows();
mRemoveReplacedWindows = false; mRemoveReplacedWindows = false;
} }
mService.destroyPreservedSurfaceLocked(); mService.destroyPreservedSurfaceLocked();
executeAfterPrepareSurfacesRunnables(); executeAfterPrepareSurfacesRunnables();
if (DEBUG_WINDOW_TRACE) { if (DEBUG_WINDOW_TRACE) {
Slog.i(TAG, "!!! animate: exit" Slog.i(TAG, "!!! animate: exit"
+ " mBulkUpdateParams=" + Integer.toHexString(mBulkUpdateParams) + " mBulkUpdateParams=" + Integer.toHexString(mBulkUpdateParams)
+ " hasPendingLayoutChanges=" + hasPendingLayoutChanges); + " hasPendingLayoutChanges=" + hasPendingLayoutChanges);
}
} }
} }

View File

@@ -1007,9 +1007,7 @@ public class WindowManagerService extends IWindowManager.Stub
void openSurfaceTransaction() { void openSurfaceTransaction() {
try { try {
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "openSurfaceTransaction"); Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "openSurfaceTransaction");
synchronized (mGlobalLock) { SurfaceControl.openTransaction();
SurfaceControl.openTransaction();
}
} finally { } finally {
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
} }
@@ -1022,10 +1020,8 @@ public class WindowManagerService extends IWindowManager.Stub
void closeSurfaceTransaction(String where) { void closeSurfaceTransaction(String where) {
try { try {
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "closeSurfaceTransaction"); Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "closeSurfaceTransaction");
synchronized (mGlobalLock) { SurfaceControl.closeTransaction();
SurfaceControl.closeTransaction(); mWindowTracing.logState(where);
mWindowTracing.logState(where);
}
} finally { } finally {
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
} }