Merge "WM: Replace eEarlyWakeup flags with explicit eEarlyWakeup start and end flags" into rvc-dev am: 278f00319f am: 66bab75ea1 am: e212052243

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11852824

Change-Id: Ib9c33e702bac83eb46620074cd28a9f1129fb3e3
This commit is contained in:
Ady Abraham
2020-06-18 05:23:14 +00:00
committed by Automerger Merge Worker
10 changed files with 79 additions and 30 deletions

View File

@@ -102,6 +102,8 @@ public final class SurfaceControl implements Parcelable {
long otherTransactionObj); long otherTransactionObj);
private static native void nativeSetAnimationTransaction(long transactionObj); private static native void nativeSetAnimationTransaction(long transactionObj);
private static native void nativeSetEarlyWakeup(long transactionObj); private static native void nativeSetEarlyWakeup(long transactionObj);
private static native void nativeSetEarlyWakeupStart(long transactionObj);
private static native void nativeSetEarlyWakeupEnd(long transactionObj);
private static native void nativeSetLayer(long transactionObj, long nativeObject, int zorder); private static native void nativeSetLayer(long transactionObj, long nativeObject, int zorder);
private static native void nativeSetRelativeLayer(long transactionObj, long nativeObject, private static native void nativeSetRelativeLayer(long transactionObj, long nativeObject,
@@ -2775,6 +2777,8 @@ public final class SurfaceControl implements Parcelable {
} }
/** /**
* @deprecated use {@link Transaction#setEarlyWakeupStart()}
*
* Indicate that SurfaceFlinger should wake up earlier than usual as a result of this * Indicate that SurfaceFlinger should wake up earlier than usual as a result of this
* transaction. This should be used when the caller thinks that the scene is complex enough * transaction. This should be used when the caller thinks that the scene is complex enough
* that it's likely to hit GL composition, and thus, SurfaceFlinger needs to more time in * that it's likely to hit GL composition, and thus, SurfaceFlinger needs to more time in
@@ -2783,11 +2787,35 @@ public final class SurfaceControl implements Parcelable {
* Corresponds to setting ISurfaceComposer::eEarlyWakeup * Corresponds to setting ISurfaceComposer::eEarlyWakeup
* @hide * @hide
*/ */
@Deprecated
public Transaction setEarlyWakeup() { public Transaction setEarlyWakeup() {
nativeSetEarlyWakeup(mNativeObject); nativeSetEarlyWakeup(mNativeObject);
return this; return this;
} }
/**
* Provides a hint to SurfaceFlinger to change its offset so that SurfaceFlinger wakes up
* earlier to compose surfaces. The caller should use this as a hint to SurfaceFlinger
* when the scene is complex enough to use GPU composition. The hint will remain active
* until until the client calls {@link Transaction#setEarlyWakeupEnd}.
*
* @hide
*/
public Transaction setEarlyWakeupStart() {
nativeSetEarlyWakeupStart(mNativeObject);
return this;
}
/**
* Removes the early wake up hint set by {@link Transaction#setEarlyWakeupStart}.
*
* @hide
*/
public Transaction setEarlyWakeupEnd() {
nativeSetEarlyWakeupEnd(mNativeObject);
return this;
}
/** /**
* Sets an arbitrary piece of metadata on the surface. This is a helper for int data. * Sets an arbitrary piece of metadata on the surface. This is a helper for int data.
* @hide * @hide

View File

@@ -640,7 +640,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
mTmpRect.set(0, 0, mSurfaceWidth, mSurfaceHeight); mTmpRect.set(0, 0, mSurfaceWidth, mSurfaceHeight);
} }
SyncRtSurfaceTransactionApplier applier = new SyncRtSurfaceTransactionApplier(this); SyncRtSurfaceTransactionApplier applier = new SyncRtSurfaceTransactionApplier(this);
applier.scheduleApply(false /* earlyWakeup */, applier.scheduleApply(
new SyncRtSurfaceTransactionApplier.SurfaceParams.Builder(mSurfaceControl) new SyncRtSurfaceTransactionApplier.SurfaceParams.Builder(mSurfaceControl)
.withWindowCrop(mTmpRect) .withWindowCrop(mTmpRect)
.build()); .build());

View File

@@ -53,11 +53,10 @@ public class SyncRtSurfaceTransactionApplier {
/** /**
* Schedules applying surface parameters on the next frame. * Schedules applying surface parameters on the next frame.
* *
* @param earlyWakeup Whether to set {@link Transaction#setEarlyWakeup()} on transaction.
* @param params The surface parameters to apply. DO NOT MODIFY the list after passing into * @param params The surface parameters to apply. DO NOT MODIFY the list after passing into
* this method to avoid synchronization issues. * this method to avoid synchronization issues.
*/ */
public void scheduleApply(boolean earlyWakeup, final SurfaceParams... params) { public void scheduleApply(final SurfaceParams... params) {
if (mTargetViewRootImpl == null) { if (mTargetViewRootImpl == null) {
return; return;
} }
@@ -67,7 +66,7 @@ public class SyncRtSurfaceTransactionApplier {
return; return;
} }
Transaction t = new Transaction(); Transaction t = new Transaction();
applyParams(t, frame, earlyWakeup, params); applyParams(t, frame, params);
}); });
// Make sure a frame gets scheduled. // Make sure a frame gets scheduled.
@@ -78,12 +77,10 @@ public class SyncRtSurfaceTransactionApplier {
* Applies surface parameters on the next frame. * Applies surface parameters on the next frame.
* @param t transaction to apply all parameters in. * @param t transaction to apply all parameters in.
* @param frame frame to synchronize to. Set -1 when sync is not required. * @param frame frame to synchronize to. Set -1 when sync is not required.
* @param earlyWakeup Whether to set {@link Transaction#setEarlyWakeup()} on transaction.
* @param params The surface parameters to apply. DO NOT MODIFY the list after passing into * @param params The surface parameters to apply. DO NOT MODIFY the list after passing into
* this method to avoid synchronization issues. * this method to avoid synchronization issues.
*/ */
void applyParams(Transaction t, long frame, boolean earlyWakeup, void applyParams(Transaction t, long frame, final SurfaceParams... params) {
final SurfaceParams... params) {
for (int i = params.length - 1; i >= 0; i--) { for (int i = params.length - 1; i >= 0; i--) {
SurfaceParams surfaceParams = params[i]; SurfaceParams surfaceParams = params[i];
SurfaceControl surface = surfaceParams.surface; SurfaceControl surface = surfaceParams.surface;
@@ -92,9 +89,6 @@ public class SyncRtSurfaceTransactionApplier {
} }
applyParams(t, surfaceParams, mTmpFloat9); applyParams(t, surfaceParams, mTmpFloat9);
} }
if (earlyWakeup) {
t.setEarlyWakeup();
}
t.apply(); t.apply();
} }

View File

@@ -120,13 +120,12 @@ public class ViewRootInsetsControllerHost implements InsetsController.Host {
mApplier = new SyncRtSurfaceTransactionApplier(mViewRoot.mView); mApplier = new SyncRtSurfaceTransactionApplier(mViewRoot.mView);
} }
if (mViewRoot.mView.isHardwareAccelerated()) { if (mViewRoot.mView.isHardwareAccelerated()) {
mApplier.scheduleApply(false /* earlyWakeup */, params); mApplier.scheduleApply(params);
} else { } else {
// Window doesn't support hardware acceleration, no synchronization for now. // Window doesn't support hardware acceleration, no synchronization for now.
// TODO(b/149342281): use mViewRoot.mSurface.getNextFrameNumber() to sync on every // TODO(b/149342281): use mViewRoot.mSurface.getNextFrameNumber() to sync on every
// frame instead. // frame instead.
mApplier.applyParams(new SurfaceControl.Transaction(), -1 /* frame */, mApplier.applyParams(new SurfaceControl.Transaction(), -1 /* frame */, params);
false /* earlyWakeup */, params);
} }
} }

View File

@@ -395,6 +395,16 @@ static void nativeSetEarlyWakeup(JNIEnv* env, jclass clazz, jlong transactionObj
transaction->setEarlyWakeup(); transaction->setEarlyWakeup();
} }
static void nativeSetEarlyWakeupStart(JNIEnv* env, jclass clazz, jlong transactionObj) {
auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
transaction->setExplicitEarlyWakeupStart();
}
static void nativeSetEarlyWakeupEnd(JNIEnv* env, jclass clazz, jlong transactionObj) {
auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
transaction->setExplicitEarlyWakeupEnd();
}
static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj, static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
jlong nativeObject, jint zorder) { jlong nativeObject, jint zorder) {
auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
@@ -1501,6 +1511,10 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
(void*)nativeSetAnimationTransaction }, (void*)nativeSetAnimationTransaction },
{"nativeSetEarlyWakeup", "(J)V", {"nativeSetEarlyWakeup", "(J)V",
(void*)nativeSetEarlyWakeup }, (void*)nativeSetEarlyWakeup },
{"nativeSetEarlyWakeupStart", "(J)V",
(void*)nativeSetEarlyWakeupStart },
{"nativeSetEarlyWakeupEnd", "(J)V",
(void*)nativeSetEarlyWakeupEnd },
{"nativeSetLayer", "(JJI)V", {"nativeSetLayer", "(JJI)V",
(void*)nativeSetLayer }, (void*)nativeSetLayer },
{"nativeSetRelativeLayer", "(JJJI)V", {"nativeSetRelativeLayer", "(JJJI)V",

View File

@@ -115,7 +115,6 @@ public class SyncRtSurfaceTransactionApplierCompat {
t.deferTransactionUntil(surfaceParams.surface, mBarrierSurfaceControl, frame); t.deferTransactionUntil(surfaceParams.surface, mBarrierSurfaceControl, frame);
surfaceParams.applyTo(t); surfaceParams.applyTo(t);
} }
t.setEarlyWakeup();
t.apply(); t.apply();
Trace.traceEnd(Trace.TRACE_TAG_VIEW); Trace.traceEnd(Trace.TRACE_TAG_VIEW);
Message.obtain(mApplyHandler, MSG_UPDATE_SEQUENCE_NUMBER, toApplySeqNo, 0) Message.obtain(mApplyHandler, MSG_UPDATE_SEQUENCE_NUMBER, toApplySeqNo, 0)

View File

@@ -99,8 +99,8 @@ public class TransactionCompat {
return this; return this;
} }
@Deprecated
public TransactionCompat setEarlyWakeup() { public TransactionCompat setEarlyWakeup() {
mTransaction.setEarlyWakeup();
return this; return this;
} }
@@ -114,7 +114,7 @@ public class TransactionCompat {
t.deferTransactionUntil(surfaceControl, barrier, frameNumber); t.deferTransactionUntil(surfaceControl, barrier, frameNumber);
} }
@Deprecated
public static void setEarlyWakeup(Transaction t) { public static void setEarlyWakeup(Transaction t) {
t.setEarlyWakeup();
} }
} }

View File

@@ -293,7 +293,7 @@ public class ActivityLaunchAnimator {
.withCornerRadius(mCornerRadius) .withCornerRadius(mCornerRadius)
.withVisibility(true) .withVisibility(true)
.build(); .build();
mSyncRtTransactionApplier.scheduleApply(true /* earlyWakeup */, params); mSyncRtTransactionApplier.scheduleApply(params);
} }
@Override @Override

View File

@@ -239,9 +239,6 @@ class SurfaceAnimationRunner {
} }
private void applyTransformation(RunningAnimation a, Transaction t, long currentPlayTime) { private void applyTransformation(RunningAnimation a, Transaction t, long currentPlayTime) {
if (a.mAnimSpec.needsEarlyWakeup()) {
t.setEarlyWakeup();
}
a.mAnimSpec.apply(t, a.mLeash, currentPlayTime); a.mAnimSpec.apply(t, a.mLeash, currentPlayTime);
} }

View File

@@ -17,6 +17,10 @@
package com.android.server.wm; package com.android.server.wm;
import static com.android.server.wm.ProtoLogGroup.WM_SHOW_TRANSACTIONS; import static com.android.server.wm.ProtoLogGroup.WM_SHOW_TRANSACTIONS;
import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_ALL;
import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION;
import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_RECENTS;
import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_SCREEN_ROTATION;
import static com.android.server.wm.WindowContainer.AnimationFlags.CHILDREN; import static com.android.server.wm.WindowContainer.AnimationFlags.CHILDREN;
import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE; import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
@@ -52,6 +56,9 @@ public class WindowAnimator {
/** Is any window animating? */ /** Is any window animating? */
private boolean mLastRootAnimating; private boolean mLastRootAnimating;
/** True if we are running any animations that require expensive composition. */
private boolean mRunningExpensiveAnimations;
final Choreographer.FrameCallback mAnimationFrameCallback; final Choreographer.FrameCallback mAnimationFrameCallback;
/** Time of current animation step. Reset on each iteration */ /** Time of current animation step. Reset on each iteration */
@@ -165,12 +172,8 @@ public class WindowAnimator {
mService.mWatermark.drawIfNeeded(); mService.mWatermark.drawIfNeeded();
} }
SurfaceControl.mergeToGlobalTransaction(mTransaction);
} catch (RuntimeException e) { } catch (RuntimeException e) {
Slog.wtf(TAG, "Unhandled exception in Window Manager", e); Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
} finally {
mService.closeSurfaceTransaction("WindowAnimator");
ProtoLog.i(WM_SHOW_TRANSACTIONS, "<<< CLOSE TRANSACTION animate");
} }
final boolean hasPendingLayoutChanges = mService.mRoot.hasPendingLayoutChanges(this); final boolean hasPendingLayoutChanges = mService.mRoot.hasPendingLayoutChanges(this);
@@ -179,21 +182,36 @@ public class WindowAnimator {
mService.mWindowPlacerLocked.requestTraversal(); mService.mWindowPlacerLocked.requestTraversal();
} }
final boolean rootAnimating = mService.mRoot.isAnimating(TRANSITION | CHILDREN); final boolean rootAnimating = mService.mRoot.isAnimating(TRANSITION | CHILDREN /* flags */,
ANIMATION_TYPE_ALL /* typesToCheck */);
if (rootAnimating && !mLastRootAnimating) { if (rootAnimating && !mLastRootAnimating) {
// Usually app transitions but quite a load onto the system already (with all the things
// happening in app), so pause task snapshot persisting to not increase the load.
mService.mTaskSnapshotController.setPersisterPaused(true);
Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "animating", 0); Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "animating", 0);
} }
if (!rootAnimating && mLastRootAnimating) { if (!rootAnimating && mLastRootAnimating) {
mService.mWindowPlacerLocked.requestTraversal(); mService.mWindowPlacerLocked.requestTraversal();
mService.mTaskSnapshotController.setPersisterPaused(false);
Trace.asyncTraceEnd(Trace.TRACE_TAG_WINDOW_MANAGER, "animating", 0); Trace.asyncTraceEnd(Trace.TRACE_TAG_WINDOW_MANAGER, "animating", 0);
} }
mLastRootAnimating = rootAnimating; mLastRootAnimating = rootAnimating;
final boolean runningExpensiveAnimations =
mService.mRoot.isAnimating(TRANSITION | CHILDREN /* flags */,
ANIMATION_TYPE_APP_TRANSITION | ANIMATION_TYPE_SCREEN_ROTATION
| ANIMATION_TYPE_RECENTS /* typesToCheck */);
if (runningExpensiveAnimations && !mRunningExpensiveAnimations) {
// Usually app transitions put quite a load onto the system already (with all the things
// happening in app), so pause task snapshot persisting to not increase the load.
mService.mTaskSnapshotController.setPersisterPaused(true);
mTransaction.setEarlyWakeupStart();
} else if (!runningExpensiveAnimations && mRunningExpensiveAnimations) {
mService.mTaskSnapshotController.setPersisterPaused(false);
mTransaction.setEarlyWakeupEnd();
}
mRunningExpensiveAnimations = runningExpensiveAnimations;
SurfaceControl.mergeToGlobalTransaction(mTransaction);
mService.closeSurfaceTransaction("WindowAnimator");
ProtoLog.i(WM_SHOW_TRANSACTIONS, "<<< CLOSE TRANSACTION animate");
if (mRemoveReplacedWindows) { if (mRemoveReplacedWindows) {
mService.mRoot.removeReplacedWindows(); mService.mRoot.removeReplacedWindows();
mRemoveReplacedWindows = false; mRemoveReplacedWindows = false;