Merge "Remove preserve surfaces" into sc-dev

This commit is contained in:
Chavi Weingarten
2021-02-05 22:37:01 +00:00
committed by Android (Google) Code Review
11 changed files with 13 additions and 237 deletions

View File

@@ -188,8 +188,6 @@ public final class SurfaceControl implements Parcelable {
IBinder displayToken, int mode);
private static native void nativeDeferTransactionUntil(long transactionObj, long nativeObject,
long barrierObject, long frame);
private static native void nativeReparentChildren(long transactionObj, long nativeObject,
long newParentObject);
private static native void nativeReparent(long transactionObj, long nativeObject,
long newParentNativeObject);
@@ -2969,15 +2967,6 @@ public final class SurfaceControl implements Parcelable {
return this;
}
/**
* @hide
*/
public Transaction reparentChildren(SurfaceControl sc, SurfaceControl newParent) {
checkPreconditions(sc);
nativeReparentChildren(mNativeObject, sc.mNativeObject, newParent.mNativeObject);
return this;
}
/**
* Re-parents a given layer to a new parent. Children inherit transform (position, scaling)
* crop, visibility, and Z-ordering from their parents, as if the children were pixels within the

View File

@@ -116,14 +116,6 @@ public final class WindowManagerGlobal {
*/
public static final int RELAYOUT_INSETS_PENDING = 0x1;
/**
* Flag for relayout: the client may be currently using the current surface,
* so if it is to be destroyed as a part of the relayout the destroy must
* be deferred until later. The client will call performDeferredDestroy()
* when it is okay.
*/
public static final int RELAYOUT_DEFER_SURFACE_DESTROY = 0x2;
public static final int ADD_FLAG_IN_TOUCH_MODE = 0x1;
public static final int ADD_FLAG_APP_VISIBLE = 0x2;
public static final int ADD_FLAG_USE_TRIPLE_BUFFERING = 0x4;

View File

@@ -1409,16 +1409,6 @@ static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transac
transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
}
static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
jlong nativeObject,
jlong newParentObject) {
auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
transaction->reparentChildren(ctrl, newParent);
}
static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
jlong nativeObject,
jlong newParentObject) {
@@ -1838,8 +1828,6 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
(void*)nativeGetProtectedContentSupport },
{"nativeDeferTransactionUntil", "(JJJJ)V",
(void*)nativeDeferTransactionUntil },
{"nativeReparentChildren", "(JJJ)V",
(void*)nativeReparentChildren } ,
{"nativeReparent", "(JJJ)V",
(void*)nativeReparent },
{"nativeCaptureDisplay",

View File

@@ -1362,7 +1362,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
return;
}
final boolean surfaceReady = w.isDrawn() // Regular case
|| w.mWinAnimator.mSurfaceDestroyDeferred // The preserved surface is still ready.
|| w.isDragResizeChanged(); // Waiting for relayoutWindow to call preserveSurface.
final boolean needsLetterbox = surfaceReady && isLetterboxed(w);
updateRoundedCorners(w);

View File

@@ -933,7 +933,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
}
win.destroySurfaceUnchecked();
win.mWinAnimator.destroyPreservedSurfaceLocked(win.getSyncTransaction());
} while (i > 0);
mWmService.mDestroySurface.clear();
}

View File

@@ -220,8 +220,6 @@ public class WindowAnimator {
mRemoveReplacedWindows = false;
}
mService.destroyPreservedSurfaceLocked();
mService.mAtmService.mTaskOrganizerController.dispatchPendingEvents();
executeAfterPrepareSurfacesRunnables();

View File

@@ -83,7 +83,6 @@ import static android.view.WindowManager.TRANSIT_NONE;
import static android.view.WindowManager.TRANSIT_RELAUNCH;
import static android.view.WindowManagerGlobal.ADD_OKAY;
import static android.view.WindowManagerGlobal.ADD_TOO_MANY_TOKENS;
import static android.view.WindowManagerGlobal.RELAYOUT_DEFER_SURFACE_DESTROY;
import static android.view.WindowManagerGlobal.RELAYOUT_RES_BLAST_SYNC;
import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_INVALID;
@@ -639,13 +638,6 @@ public class WindowManagerService extends IWindowManager.Stub
*/
final ArrayList<WindowState> mDestroySurface = new ArrayList<>();
/**
* Windows with a preserved surface waiting to be destroyed. These windows
* are going through a surface change. We keep the old surface around until
* the first frame on the new surface finishes drawing.
*/
final ArrayList<WindowState> mDestroyPreservedSurface = new ArrayList<>();
/**
* This is set when we have run out of memory, and will either be an empty
* list or contain windows that need to be force removed.
@@ -2343,7 +2335,6 @@ public class WindowManagerService extends IWindowManager.Stub
if (DEBUG_LAYOUT) Slog.v(TAG_WM, "Relayout " + win + ": viewVisibility=" + viewVisibility
+ " req=" + requestedWidth + "x" + requestedHeight + " " + win.mAttrs);
winAnimator.mSurfaceDestroyDeferred = (flags & RELAYOUT_DEFER_SURFACE_DESTROY) != 0;
if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
winAnimator.mAlpha = attrs.alpha;
}
@@ -5518,14 +5509,6 @@ public class WindowManagerService extends IWindowManager.Stub
}
}
void destroyPreservedSurfaceLocked() {
for (int i = mDestroyPreservedSurface.size() - 1; i >= 0 ; i--) {
final WindowState w = mDestroyPreservedSurface.get(i);
w.mWinAnimator.destroyPreservedSurfaceLocked(w.getSyncTransaction());
}
mDestroyPreservedSurface.clear();
}
// -------------------------------------------------------------
// IWindowManager API
// -------------------------------------------------------------

View File

@@ -104,7 +104,6 @@ import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED;
import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM;
import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ADD_REMOVE;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS;
@@ -2243,7 +2242,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
disposeInputChannel();
mWinAnimator.destroyDeferredSurfaceLocked(mTmpTransaction);
mWinAnimator.destroySurfaceLocked(mTmpTransaction);
mTmpTransaction.apply();
mSession.windowRemovedLocked();
@@ -3309,11 +3307,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
return destroyedSomething;
}
if (appStopped || mWindowRemovalAllowed) {
mWinAnimator.destroyPreservedSurfaceLocked(mTmpTransaction);
mTmpTransaction.apply();
}
if (mDestroying) {
ProtoLog.e(WM_DEBUG_ADD_REMOVE, "win=%s"
+ " destroySurfaces: appStopped=%b"
@@ -5001,23 +4994,8 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
}
// When we change the Surface size, in scenarios which may require changing
// the surface position in sync with the resize, we use a preserved surface
// so we can freeze it while waiting for the client to report draw on the newly
// sized surface. At the moment this logic is only in place for switching
// in and out of the big surface for split screen resize.
if (isDragResizeChanged()) {
setDragResizing();
// We can only change top level windows to the full-screen surface when
// resizing (as we only have one full-screen surface). So there is no need
// to preserve and destroy windows which are attached to another, they
// will keep their surface and its size may change over time.
if (mHasSurface && !isChildWindow()) {
mWinAnimator.preserveSurfaceLocked(getSyncTransaction());
result |= RELAYOUT_RES_SURFACE_CHANGED |
RELAYOUT_RES_FIRST_TIME;
scheduleAnimation();
}
}
final boolean freeformResizing = isDragResizing()
&& getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;

View File

@@ -116,15 +116,7 @@ class WindowStateAnimator {
boolean mAnimationIsEntrance;
WindowSurfaceController mSurfaceController;
private WindowSurfaceController mPendingDestroySurface;
/**
* Set if the client has asked that the destroy of its surface be delayed
* until it explicitly says it is okay.
*/
boolean mSurfaceDestroyDeferred;
private boolean mDestroyPreservedSurfaceUponRedraw;
float mShownAlpha = 0;
float mAlpha = 0;
float mLastAlpha = 0;
@@ -257,11 +249,6 @@ class WindowStateAnimator {
//dump();
mLastHidden = true;
// We may have a preserved surface which we no longer need. If there was a quick
// VISIBLE, GONE, VISIBLE, GONE sequence, the surface may never draw, so we don't mark
// it to be destroyed in prepareSurfaceLocked.
markPreservedSurfaceForDestroy();
if (mSurfaceController != null) {
mSurfaceController.hide(transaction, reason);
}
@@ -323,70 +310,6 @@ class WindowStateAnimator {
return result;
}
void preserveSurfaceLocked(SurfaceControl.Transaction t) {
if (mDestroyPreservedSurfaceUponRedraw) {
// This could happen when switching the surface mode very fast. For example,
// we preserved a surface when dragResizing changed to true. Then before the
// preserved surface is removed, dragResizing changed to false again.
// In this case, we need to leave the preserved surface alone, and destroy
// the actual surface, so that the createSurface call could create a surface
// of the proper size. The preserved surface will still be removed when client
// finishes drawing to the new surface.
mSurfaceDestroyDeferred = false;
// Make sure to reparent any children of the new surface back to the preserved
// surface before destroying it.
if (mSurfaceController != null && mPendingDestroySurface != null) {
mPostDrawTransaction.reparentChildren(
mSurfaceController.mSurfaceControl,
mPendingDestroySurface.mSurfaceControl).apply();
}
destroySurfaceLocked(t);
mSurfaceDestroyDeferred = true;
return;
}
ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE SET FREEZE LAYER: %s", mWin);
if (mSurfaceController != null) {
// Our SurfaceControl is always at layer 0 within the parent Surface managed by
// window-state. We want this old Surface to stay on top of the new one
// until we do the swap, so we place it at a positive layer.
t.setLayer(mSurfaceController.mSurfaceControl, PRESERVED_SURFACE_LAYER);
}
mDestroyPreservedSurfaceUponRedraw = true;
mSurfaceDestroyDeferred = true;
destroySurfaceLocked(t);
}
void destroyPreservedSurfaceLocked(SurfaceControl.Transaction t) {
if (!mDestroyPreservedSurfaceUponRedraw) {
return;
}
// If we are preserving a surface but we aren't relaunching that means
// we are just doing an in-place switch. In that case any SurfaceFlinger side
// child layers need to be reparented to the new surface to make this
// transparent to the app.
// If the children are detached, we don't want to reparent them to the new surface.
// Instead let the children get removed when the old surface is deleted.
if (mSurfaceController != null && mPendingDestroySurface != null
&& !mPendingDestroySurface.mChildrenDetached
&& (mWin.mActivityRecord == null || !mWin.mActivityRecord.isRelaunching())) {
mPostDrawTransaction.reparentChildren(
mPendingDestroySurface.mSurfaceControl,
mSurfaceController.mSurfaceControl).apply();
}
destroyDeferredSurfaceLocked(t);
mDestroyPreservedSurfaceUponRedraw = false;
}
private void markPreservedSurfaceForDestroy() {
if (mDestroyPreservedSurfaceUponRedraw
&& !mService.mDestroyPreservedSurface.contains(mWin)) {
mService.mDestroyPreservedSurface.add(mWin);
}
}
void resetDrawState() {
mDrawState = DRAW_PENDING;
@@ -508,39 +431,23 @@ class WindowStateAnimator {
return;
}
// When destroying a surface we want to make sure child windows are hidden. If we are
// preserving the surface until redraw though we intend to swap it out with another surface
// for resizing. In this case the window always remains visible to the user and the child
// windows should likewise remain visible.
if (!mDestroyPreservedSurfaceUponRedraw) {
mWin.mHidden = true;
}
mWin.mHidden = true;
try {
if (DEBUG_VISIBILITY) logWithStack(TAG, "Window " + this + " destroying surface "
+ mSurfaceController + ", session " + mSession);
if (mSurfaceDestroyDeferred) {
if (mSurfaceController != null && mPendingDestroySurface != mSurfaceController) {
if (mPendingDestroySurface != null) {
ProtoLog.i(WM_SHOW_SURFACE_ALLOC, "SURFACE DESTROY PENDING: %s. %s",
mWin, new RuntimeException().fillInStackTrace());
mPendingDestroySurface.destroy(t);
}
mPendingDestroySurface = mSurfaceController;
}
} else {
ProtoLog.i(WM_SHOW_SURFACE_ALLOC, "SURFACE DESTROY: %s. %s",
mWin, new RuntimeException().fillInStackTrace());
destroySurface(t);
if (DEBUG_VISIBILITY) {
logWithStack(TAG, "Window " + this + " destroying surface "
+ mSurfaceController + ", session " + mSession);
}
ProtoLog.i(WM_SHOW_SURFACE_ALLOC, "SURFACE DESTROY: %s. %s",
mWin, new RuntimeException().fillInStackTrace());
destroySurface(t);
// Don't hide wallpaper if we're deferring the surface destroy
// because of a surface change.
if (!mDestroyPreservedSurfaceUponRedraw) {
mWallpaperControllerLocked.hideWallpapers(mWin);
}
mWallpaperControllerLocked.hideWallpapers(mWin);
} catch (RuntimeException e) {
Slog.w(TAG, "Exception thrown when destroying Window " + this
+ " surface " + mSurfaceController + " session " + mSession + ": " + e.toString());
+ " surface " + mSurfaceController + " session " + mSession + ": "
+ e.toString());
}
// Whether the surface was preserved (and copied to mPendingDestroySurface) or not, it
@@ -554,27 +461,6 @@ class WindowStateAnimator {
mDrawState = NO_SURFACE;
}
void destroyDeferredSurfaceLocked(SurfaceControl.Transaction t) {
try {
if (mPendingDestroySurface != null) {
ProtoLog.i(WM_SHOW_SURFACE_ALLOC, "SURFACE DESTROY PENDING: %s. %s",
mWin, new RuntimeException().fillInStackTrace());
mPendingDestroySurface.destroy(t);
// Don't hide wallpaper if we're destroying a deferred surface
// after a surface mode change.
if (!mDestroyPreservedSurfaceUponRedraw) {
mWallpaperControllerLocked.hideWallpapers(mWin);
}
}
} catch (RuntimeException e) {
Slog.w(TAG, "Exception thrown when destroying Window "
+ this + " surface " + mPendingDestroySurface
+ " session " + mSession + ": " + e.toString());
}
mSurfaceDestroyDeferred = false;
mPendingDestroySurface = null;
}
void computeShownFrameLocked() {
if (mIsWallpaper && mService.mRoot.mWallpaperActionPending) {
return;
@@ -744,7 +630,6 @@ class WindowStateAnimator {
if (prepared && mDrawState == HAS_DRAWN) {
if (mLastHidden) {
if (showSurfaceRobustlyLocked(t)) {
markPreservedSurfaceForDestroy();
mAnimator.requestRemovalOfReplacedWindows(w);
mLastHidden = false;
if (mIsWallpaper) {
@@ -905,20 +790,6 @@ class WindowStateAnimator {
if (!shown)
return false;
// If we had a preserved surface it's no longer needed, and it may be harmful
// if we are transparent.
if (mPendingDestroySurface != null && mDestroyPreservedSurfaceUponRedraw) {
final SurfaceControl pendingSurfaceControl = mPendingDestroySurface.mSurfaceControl;
mPostDrawTransaction.reparent(pendingSurfaceControl, null);
// If the children are detached, we don't want to reparent them to the new surface.
// Instead let the children get removed when the old surface is deleted.
if (!mPendingDestroySurface.mChildrenDetached) {
mPostDrawTransaction.reparentChildren(
mPendingDestroySurface.mSurfaceControl,
mSurfaceController.mSurfaceControl);
}
}
t.merge(mPostDrawTransaction);
return true;
}
@@ -1058,13 +929,6 @@ class WindowStateAnimator {
pw.println();
}
if (mPendingDestroySurface != null) {
pw.print(prefix); pw.print("mPendingDestroySurface=");
pw.println(mPendingDestroySurface);
}
if (mSurfaceDestroyDeferred) {
pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
}
if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
pw.print(" mAlpha="); pw.print(mAlpha);

View File

@@ -55,8 +55,6 @@ class WindowSurfaceController {
private boolean mSurfaceShown = false;
private float mSurfaceX = 0;
private float mSurfaceY = 0;
private int mSurfaceW = 0;
private int mSurfaceH = 0;
// Initialize to the identity matrix.
private float mLastDsdx = 1;
@@ -82,9 +80,6 @@ class WindowSurfaceController {
int flags, WindowStateAnimator animator, int windowType) {
mAnimator = animator;
mSurfaceW = w;
mSurfaceH = h;
title = name;
mService = animator.mService;
@@ -104,8 +99,8 @@ class WindowSurfaceController {
.setMetadata(METADATA_OWNER_PID, mWindowSession.mPid)
.setCallsite("WindowSurfaceController");
final boolean useBLAST = mService.mUseBLAST && ((win.getAttrs().privateFlags &
WindowManager.LayoutParams.PRIVATE_FLAG_USE_BLAST) != 0);
final boolean useBLAST = mService.mUseBLAST && ((win.getAttrs().privateFlags
& WindowManager.LayoutParams.PRIVATE_FLAG_USE_BLAST) != 0);
if (useBLAST) {
b.setBLASTLayer();
@@ -119,7 +114,6 @@ class WindowSurfaceController {
void hide(SurfaceControl.Transaction transaction, String reason) {
ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE HIDE ( %s ): %s", reason, title);
mAnimator.destroyPreservedSurfaceLocked(transaction);
if (mSurfaceShown) {
hideSurface(transaction);
}
@@ -335,9 +329,7 @@ class WindowSurfaceController {
pw.print(" layer="); pw.print(mSurfaceLayer);
pw.print(" alpha="); pw.print(mSurfaceAlpha);
pw.print(" rect=("); pw.print(mSurfaceX);
pw.print(","); pw.print(mSurfaceY);
pw.print(") "); pw.print(mSurfaceW);
pw.print(" x "); pw.print(mSurfaceH);
pw.print(","); pw.print(mSurfaceY); pw.print(") ");
pw.print(" transform=("); pw.print(mLastDsdx); pw.print(", ");
pw.print(mLastDtdx); pw.print(", "); pw.print(mLastDsdy);
pw.print(", "); pw.print(mLastDtdy); pw.println(")");

View File

@@ -151,12 +151,6 @@ public class StubTransaction extends SurfaceControl.Transaction {
return this;
}
@Override
public SurfaceControl.Transaction reparentChildren(SurfaceControl sc,
SurfaceControl newParent) {
return this;
}
@Override
public SurfaceControl.Transaction reparent(SurfaceControl sc, SurfaceControl newParent) {
return this;