Merge "Stop allocating memory for non-existing controls"

This commit is contained in:
TreeHugger Robot
2023-01-05 15:01:09 +00:00
committed by Android (Google) Code Review
12 changed files with 78 additions and 28 deletions

View File

@@ -127,7 +127,7 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase
final ClientWindowFrames mOutFrames = new ClientWindowFrames();
final MergedConfiguration mOutMergedConfiguration = new MergedConfiguration();
final InsetsState mOutInsetsState = new InsetsState();
final InsetsSourceControl[] mOutControls = new InsetsSourceControl[0];
final InsetsSourceControl.Array mOutControls = new InsetsSourceControl.Array();
final IWindow mWindow;
final View mView;
final WindowManager.LayoutParams mParams;

View File

@@ -86,7 +86,7 @@ public class WindowAddRemovePerfTest extends WindowManagerPerfTestBase
final WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams();
final int mRequestedVisibleTypes = WindowInsets.Type.defaultVisible();
final InsetsState mOutInsetsState = new InsetsState();
final InsetsSourceControl[] mOutControls = new InsetsSourceControl[0];
final InsetsSourceControl.Array mOutControls = new InsetsSourceControl.Array();
final Rect mOutAttachedFrame = new Rect();
final float[] mOutSizeCompatScale = { 1f };

View File

@@ -252,7 +252,7 @@ public abstract class WallpaperService extends Service {
final Rect mDispatchedStableInsets = new Rect();
DisplayCutout mDispatchedDisplayCutout = DisplayCutout.NO_CUTOUT;
final InsetsState mInsetsState = new InsetsState();
final InsetsSourceControl[] mTempControls = new InsetsSourceControl[0];
final InsetsSourceControl.Array mTempControls = new InsetsSourceControl.Array();
final MergedConfiguration mMergedConfiguration = new MergedConfiguration();
final Bundle mSyncSeqIdBundle = new Bundle();
private final Point mSurfaceSize = new Point();

View File

@@ -49,12 +49,12 @@ interface IWindowSession {
int addToDisplay(IWindow window, in WindowManager.LayoutParams attrs,
in int viewVisibility, in int layerStackId, int requestedVisibleTypes,
out InputChannel outInputChannel, out InsetsState insetsState,
out InsetsSourceControl[] activeControls, out Rect attachedFrame,
out InsetsSourceControl.Array activeControls, out Rect attachedFrame,
out float[] sizeCompatScale);
int addToDisplayAsUser(IWindow window, in WindowManager.LayoutParams attrs,
in int viewVisibility, in int layerStackId, in int userId, int requestedVisibleTypes,
out InputChannel outInputChannel, out InsetsState insetsState,
out InsetsSourceControl[] activeControls, out Rect attachedFrame,
out InsetsSourceControl.Array activeControls, out Rect attachedFrame,
out float[] sizeCompatScale);
int addToDisplayWithoutInputChannel(IWindow window, in WindowManager.LayoutParams attrs,
in int viewVisibility, in int layerStackId, out InsetsState insetsState,
@@ -91,7 +91,7 @@ interface IWindowSession {
int requestedWidth, int requestedHeight, int viewVisibility,
int flags, int seq, int lastSyncSeqId, out ClientWindowFrames outFrames,
out MergedConfiguration outMergedConfiguration, out SurfaceControl outSurfaceControl,
out InsetsState insetsState, out InsetsSourceControl[] activeControls,
out InsetsState insetsState, out InsetsSourceControl.Array activeControls,
out Bundle bundle);
/**

View File

@@ -17,3 +17,4 @@
package android.view;
parcelable InsetsSourceControl;
parcelable InsetsSourceControl.Array;

View File

@@ -257,4 +257,52 @@ public class InsetsSourceControl implements Parcelable {
}
proto.end(token);
}
/**
* Used to obtain the array from the argument of a binder call. In this way, the length of the
* array can be dynamic.
*/
public static class Array implements Parcelable {
private @Nullable InsetsSourceControl[] mControls;
public Array() {
}
public Array(Parcel in) {
readFromParcel(in);
}
public void set(@Nullable InsetsSourceControl[] controls) {
mControls = controls;
}
public @Nullable InsetsSourceControl[] get() {
return mControls;
}
@Override
public int describeContents() {
return 0;
}
public void readFromParcel(Parcel in) {
mControls = in.createTypedArray(InsetsSourceControl.CREATOR);
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeTypedArray(mControls, flags);
}
public static final @NonNull Creator<Array> CREATOR = new Creator<>() {
public Array createFromParcel(Parcel in) {
return new Array(in);
}
public Array[] newArray(int size) {
return new Array[size];
}
};
}
}

View File

@@ -23,7 +23,6 @@ import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.InputDevice.SOURCE_CLASS_NONE;
import static android.view.InsetsState.ITYPE_IME;
import static android.view.InsetsState.SIZE;
import static android.view.View.PFLAG_DRAW_ANIMATION;
import static android.view.View.SYSTEM_UI_FLAG_FULLSCREEN;
import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
@@ -705,7 +704,7 @@ public final class ViewRootImpl implements ViewParent,
private int mRelayoutSeq;
private final Rect mWinFrameInScreen = new Rect();
private final InsetsState mTempInsets = new InsetsState();
private final InsetsSourceControl[] mTempControls = new InsetsSourceControl[SIZE];
private final InsetsSourceControl.Array mTempControls = new InsetsSourceControl.Array();
private final WindowConfiguration mTempWinConfig = new WindowConfiguration();
private float mInvCompatScale = 1f;
final ViewTreeObserver.InternalInsetsInfo mLastGivenInsets
@@ -1264,7 +1263,7 @@ public final class ViewRootImpl implements ViewParent,
}
if (mTranslator != null) {
mTranslator.translateInsetsStateInScreenToAppWindow(mTempInsets);
mTranslator.translateSourceControlsInScreenToAppWindow(mTempControls);
mTranslator.translateSourceControlsInScreenToAppWindow(mTempControls.get());
mTranslator.translateRectInScreenToAppWindow(attachedFrame);
}
mTmpFrames.attachedFrame = attachedFrame;
@@ -1288,7 +1287,7 @@ public final class ViewRootImpl implements ViewParent,
(res & WindowManagerGlobal.ADD_FLAG_ALWAYS_CONSUME_SYSTEM_BARS) != 0;
mPendingAlwaysConsumeSystemBars = mAttachInfo.mAlwaysConsumeSystemBars;
mInsetsController.onStateChanged(mTempInsets);
mInsetsController.onControlsChanged(mTempControls);
mInsetsController.onControlsChanged(mTempControls.get());
final InsetsState state = mInsetsController.getState();
final Rect displayCutoutSafe = mTempRect;
state.getDisplayCutoutSafe(displayCutoutSafe);
@@ -8334,12 +8333,12 @@ public final class ViewRootImpl implements ViewParent,
mTranslator.translateRectInScreenToAppWindow(mTmpFrames.displayFrame);
mTranslator.translateRectInScreenToAppWindow(mTmpFrames.attachedFrame);
mTranslator.translateInsetsStateInScreenToAppWindow(mTempInsets);
mTranslator.translateSourceControlsInScreenToAppWindow(mTempControls);
mTranslator.translateSourceControlsInScreenToAppWindow(mTempControls.get());
}
mInvCompatScale = 1f / mTmpFrames.compatScale;
CompatibilityInfo.applyOverrideScaleIfNeeded(mPendingMergedConfiguration);
mInsetsController.onStateChanged(mTempInsets);
mInsetsController.onControlsChanged(mTempControls);
mInsetsController.onControlsChanged(mTempControls.get());
mPendingAlwaysConsumeSystemBars =
(relayoutResult & RELAYOUT_RES_CONSUME_ALWAYS_SYSTEM_BARS) != 0;

View File

@@ -148,7 +148,7 @@ public class WindowlessWindowManager implements IWindowSession {
public int addToDisplay(IWindow window, WindowManager.LayoutParams attrs,
int viewVisibility, int displayId, @InsetsType int requestedVisibleTypes,
InputChannel outInputChannel, InsetsState outInsetsState,
InsetsSourceControl[] outActiveControls, Rect outAttachedFrame,
InsetsSourceControl.Array outActiveControls, Rect outAttachedFrame,
float[] outSizeCompatScale) {
final SurfaceControl.Builder b = new SurfaceControl.Builder(mSurfaceSession)
.setFormat(attrs.format)
@@ -200,7 +200,7 @@ public class WindowlessWindowManager implements IWindowSession {
public int addToDisplayAsUser(IWindow window, WindowManager.LayoutParams attrs,
int viewVisibility, int displayId, int userId, @InsetsType int requestedVisibleTypes,
InputChannel outInputChannel, InsetsState outInsetsState,
InsetsSourceControl[] outActiveControls, Rect outAttachedFrame,
InsetsSourceControl.Array outActiveControls, Rect outAttachedFrame,
float[] outSizeCompatScale) {
return addToDisplay(window, attrs, viewVisibility, displayId, requestedVisibleTypes,
outInputChannel, outInsetsState, outActiveControls, outAttachedFrame,
@@ -290,7 +290,7 @@ public class WindowlessWindowManager implements IWindowSession {
int requestedWidth, int requestedHeight, int viewFlags, int flags, int seq,
int lastSyncSeqId, ClientWindowFrames outFrames,
MergedConfiguration outMergedConfiguration, SurfaceControl outSurfaceControl,
InsetsState outInsetsState, InsetsSourceControl[] outActiveControls,
InsetsState outInsetsState, InsetsSourceControl.Array outActiveControls,
Bundle outSyncSeqIdBundle) {
final State state;
synchronized (this) {

View File

@@ -111,7 +111,7 @@ public class TaskSnapshotWindow {
final SurfaceControl surfaceControl = new SurfaceControl();
final ClientWindowFrames tmpFrames = new ClientWindowFrames();
final InsetsSourceControl[] tmpControls = new InsetsSourceControl[0];
final InsetsSourceControl.Array tmpControls = new InsetsSourceControl.Array();
final MergedConfiguration tmpMergedConfiguration = new MergedConfiguration();
final TaskDescription taskDescription;

View File

@@ -118,7 +118,7 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
private float mLastReportedAnimatorScale;
private String mPackageName;
private String mRelayoutTag;
private final InsetsSourceControl[] mDummyControls = new InsetsSourceControl[0];
private final InsetsSourceControl.Array mDummyControls = new InsetsSourceControl.Array();
final boolean mSetsUnrestrictedKeepClearAreas;
public Session(WindowManagerService service, IWindowSessionCallback callback) {
@@ -198,7 +198,7 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
public int addToDisplay(IWindow window, WindowManager.LayoutParams attrs,
int viewVisibility, int displayId, @InsetsType int requestedVisibleTypes,
InputChannel outInputChannel, InsetsState outInsetsState,
InsetsSourceControl[] outActiveControls, Rect outAttachedFrame,
InsetsSourceControl.Array outActiveControls, Rect outAttachedFrame,
float[] outSizeCompatScale) {
return mService.addWindow(this, window, attrs, viewVisibility, displayId,
UserHandle.getUserId(mUid), requestedVisibleTypes, outInputChannel, outInsetsState,
@@ -209,7 +209,7 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
public int addToDisplayAsUser(IWindow window, WindowManager.LayoutParams attrs,
int viewVisibility, int displayId, int userId, @InsetsType int requestedVisibleTypes,
InputChannel outInputChannel, InsetsState outInsetsState,
InsetsSourceControl[] outActiveControls, Rect outAttachedFrame,
InsetsSourceControl.Array outActiveControls, Rect outAttachedFrame,
float[] outSizeCompatScale) {
return mService.addWindow(this, window, attrs, viewVisibility, displayId, userId,
requestedVisibleTypes, outInputChannel, outInsetsState, outActiveControls,
@@ -246,7 +246,7 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
int requestedWidth, int requestedHeight, int viewFlags, int flags, int seq,
int lastSyncSeqId, ClientWindowFrames outFrames,
MergedConfiguration mergedConfiguration, SurfaceControl outSurfaceControl,
InsetsState outInsetsState, InsetsSourceControl[] outActiveControls,
InsetsState outInsetsState, InsetsSourceControl.Array outActiveControls,
Bundle outSyncSeqIdBundle) {
if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
+ Binder.getCallingPid());

View File

@@ -1423,9 +1423,9 @@ public class WindowManagerService extends IWindowManager.Stub
public int addWindow(Session session, IWindow client, LayoutParams attrs, int viewVisibility,
int displayId, int requestUserId, @InsetsType int requestedVisibleTypes,
InputChannel outInputChannel, InsetsState outInsetsState,
InsetsSourceControl[] outActiveControls, Rect outAttachedFrame,
InsetsSourceControl.Array outActiveControls, Rect outAttachedFrame,
float[] outSizeCompatScale) {
Arrays.fill(outActiveControls, null);
outActiveControls.set(null);
int[] appOp = new int[1];
final boolean isRoundedCornerOverlay = (attrs.privateFlags
& PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY) != 0;
@@ -2215,10 +2215,10 @@ public class WindowManagerService extends IWindowManager.Stub
int requestedWidth, int requestedHeight, int viewVisibility, int flags, int seq,
int lastSyncSeqId, ClientWindowFrames outFrames,
MergedConfiguration outMergedConfiguration, SurfaceControl outSurfaceControl,
InsetsState outInsetsState, InsetsSourceControl[] outActiveControls,
InsetsState outInsetsState, InsetsSourceControl.Array outActiveControls,
Bundle outSyncIdBundle) {
if (outActiveControls != null) {
Arrays.fill(outActiveControls, null);
outActiveControls.set(null);
}
int result = 0;
boolean configChanged = false;
@@ -2590,11 +2590,12 @@ public class WindowManagerService extends IWindowManager.Stub
return result;
}
private void getInsetsSourceControls(WindowState win, InsetsSourceControl[] outControls) {
private void getInsetsSourceControls(WindowState win, InsetsSourceControl.Array outArray) {
final InsetsSourceControl[] controls =
win.getDisplayContent().getInsetsStateController().getControlsForDispatch(win);
if (controls != null) {
final int length = Math.min(controls.length, outControls.length);
final int length = controls.length;
final InsetsSourceControl[] outControls = new InsetsSourceControl[length];
for (int i = 0; i < length; i++) {
// We will leave the critical section before returning the leash to the client,
// so we need to copy the leash to prevent others release the one that we are
@@ -2607,6 +2608,7 @@ public class WindowManagerService extends IWindowManager.Stub
outControls[i].setParcelableFlags(PARCELABLE_WRITE_RETURN_VALUE);
}
}
outArray.set(outControls);
}
}

View File

@@ -214,7 +214,7 @@ public class WindowManagerServiceTests extends WindowTestsBase {
final MergedConfiguration outConfig = new MergedConfiguration();
final SurfaceControl outSurfaceControl = new SurfaceControl();
final InsetsState outInsetsState = new InsetsState();
final InsetsSourceControl[] outControls = new InsetsSourceControl[0];
final InsetsSourceControl.Array outControls = new InsetsSourceControl.Array();
final Bundle outBundle = new Bundle();
mWm.relayoutWindow(win.mSession, win.mClient, win.mAttrs, w, h, View.GONE, 0, 0, 0,
outFrames, outConfig, outSurfaceControl, outInsetsState, outControls, outBundle);
@@ -351,7 +351,7 @@ public class WindowManagerServiceTests extends WindowTestsBase {
mWm.addWindow(session, new TestIWindow(), params, View.VISIBLE, DEFAULT_DISPLAY,
UserHandle.USER_SYSTEM, WindowInsets.Type.defaultVisible(), null, new InsetsState(),
new InsetsSourceControl[0], new Rect(), new float[1]);
new InsetsSourceControl.Array(), new Rect(), new float[1]);
verify(mWm.mWindowContextListenerController, never()).registerWindowContainerListener(any(),
any(), anyInt(), anyInt(), any());