Merge "Release leashes of insets controls if they are not needed" into sc-dev
This commit is contained in:
@@ -48,6 +48,7 @@ public class InsetsSourceControl implements Parcelable {
|
|||||||
private Insets mInsetsHint;
|
private Insets mInsetsHint;
|
||||||
|
|
||||||
private boolean mSkipAnimationOnce;
|
private boolean mSkipAnimationOnce;
|
||||||
|
private int mParcelableFlags;
|
||||||
|
|
||||||
public InsetsSourceControl(@InternalInsetsType int type, @Nullable SurfaceControl leash,
|
public InsetsSourceControl(@InternalInsetsType int type, @Nullable SurfaceControl leash,
|
||||||
Point surfacePosition, Insets insetsHint) {
|
Point surfacePosition, Insets insetsHint) {
|
||||||
@@ -132,6 +133,10 @@ public class InsetsSourceControl implements Parcelable {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setParcelableFlags(int parcelableFlags) {
|
||||||
|
mParcelableFlags = parcelableFlags;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -140,9 +145,9 @@ public class InsetsSourceControl implements Parcelable {
|
|||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
dest.writeInt(mType);
|
dest.writeInt(mType);
|
||||||
dest.writeTypedObject(mLeash, 0 /* parcelableFlags */);
|
dest.writeTypedObject(mLeash, mParcelableFlags);
|
||||||
dest.writeTypedObject(mSurfacePosition, 0 /* parcelableFlags */);
|
dest.writeTypedObject(mSurfacePosition, mParcelableFlags);
|
||||||
dest.writeTypedObject(mInsetsHint, 0 /* parcelableFlags */);
|
dest.writeTypedObject(mInsetsHint, mParcelableFlags);
|
||||||
dest.writeBoolean(mSkipAnimationOnce);
|
dest.writeBoolean(mSkipAnimationOnce);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5290,7 +5290,16 @@ public final class ViewRootImpl implements ViewParent,
|
|||||||
// b) When loosing control, controller can restore server state by taking last
|
// b) When loosing control, controller can restore server state by taking last
|
||||||
// dispatched state as truth.
|
// dispatched state as truth.
|
||||||
mInsetsController.onStateChanged((InsetsState) args.arg1);
|
mInsetsController.onStateChanged((InsetsState) args.arg1);
|
||||||
mInsetsController.onControlsChanged((InsetsSourceControl[]) args.arg2);
|
InsetsSourceControl[] controls = (InsetsSourceControl[]) args.arg2;
|
||||||
|
if (mAdded) {
|
||||||
|
mInsetsController.onControlsChanged(controls);
|
||||||
|
} else if (controls != null) {
|
||||||
|
for (InsetsSourceControl control : controls) {
|
||||||
|
if (control != null) {
|
||||||
|
control.release(SurfaceControl::release);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
args.recycle();
|
args.recycle();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -8136,6 +8145,10 @@ public final class ViewRootImpl implements ViewParent,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If our window is removed, we might not get notified about losing control.
|
||||||
|
// Invoking this can release the leashes as soon as possible instead of relying on GC.
|
||||||
|
mInsetsController.onControlsChanged(null);
|
||||||
|
|
||||||
mAdded = false;
|
mAdded = false;
|
||||||
}
|
}
|
||||||
WindowManagerGlobal.getInstance().doRemoveView(this);
|
WindowManagerGlobal.getInstance().doRemoveView(this);
|
||||||
|
|||||||
@@ -249,6 +249,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
|
|||||||
!activeControl.getSurfacePosition().equals(lastSurfacePosition);
|
!activeControl.getSurfacePosition().equals(lastSurfacePosition);
|
||||||
final boolean leashChanged =
|
final boolean leashChanged =
|
||||||
!haveSameLeash(mImeSourceControl, activeControl);
|
!haveSameLeash(mImeSourceControl, activeControl);
|
||||||
|
final InsetsSourceControl lastImeControl = mImeSourceControl;
|
||||||
mImeSourceControl = activeControl;
|
mImeSourceControl = activeControl;
|
||||||
if (mAnimation != null) {
|
if (mAnimation != null) {
|
||||||
if (positionChanged) {
|
if (positionChanged) {
|
||||||
@@ -262,6 +263,9 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
|
|||||||
removeImeSurface();
|
removeImeSurface();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (lastImeControl != null) {
|
||||||
|
lastImeControl.release(SurfaceControl::release);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import static android.content.pm.PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEME
|
|||||||
import static android.content.pm.PackageManager.FEATURE_PC;
|
import static android.content.pm.PackageManager.FEATURE_PC;
|
||||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||||
import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
|
import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
|
||||||
|
import static android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE;
|
||||||
import static android.os.Process.SYSTEM_UID;
|
import static android.os.Process.SYSTEM_UID;
|
||||||
import static android.os.Process.myPid;
|
import static android.os.Process.myPid;
|
||||||
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
|
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
|
||||||
@@ -2545,12 +2546,13 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
// We will leave the critical section before returning the leash to the client,
|
// 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
|
// so we need to copy the leash to prevent others release the one that we are
|
||||||
// about to return.
|
// about to return.
|
||||||
// TODO: We will have an extra copy if the client is not local.
|
if (controls[i] != null) {
|
||||||
// For now, we rely on GC to release it.
|
// This source control is an extra copy if the client is not local. By setting
|
||||||
// Maybe we can modify InsetsSourceControl.writeToParcel so it can release
|
// PARCELABLE_WRITE_RETURN_VALUE, the leash will be released at the end of
|
||||||
// the extra leash as soon as possible.
|
// SurfaceControl.writeToParcel.
|
||||||
outControls[i] = controls[i] != null
|
outControls[i] = new InsetsSourceControl(controls[i]);
|
||||||
? new InsetsSourceControl(controls[i]) : null;
|
outControls[i].setParcelableFlags(PARCELABLE_WRITE_RETURN_VALUE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user