From ec999979a7456a5d698f9a71f21b448ce0d9a661 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 26 Feb 2021 14:47:26 +0800 Subject: [PATCH] Optimize the Parcel read/write of remote animation Eliminate the overhead of class name. A read/write pair of RemoteAnimationTarget can be reduced from 30us to 7us. Bug: 181025587 Test: CtsWindowManagerDeviceTestCases Change-Id: I58bd69012fcc3e6cb72c1fcfbb1db697e6c70e87 --- .../android/app/PictureInPictureParams.java | 4 +- .../view/AppTransitionAnimationSpec.java | 8 ++-- .../view/RemoteAnimationDefinition.java | 4 +- .../android/view/RemoteAnimationTarget.java | 44 +++++++++---------- core/java/android/window/TaskSnapshot.java | 15 +++---- 5 files changed, 37 insertions(+), 38 deletions(-) diff --git a/core/java/android/app/PictureInPictureParams.java b/core/java/android/app/PictureInPictureParams.java index ea7eab2a28777..358ce6a83a21b 100644 --- a/core/java/android/app/PictureInPictureParams.java +++ b/core/java/android/app/PictureInPictureParams.java @@ -202,7 +202,7 @@ public final class PictureInPictureParams implements Parcelable { } if (in.readInt() != 0) { mUserActions = new ArrayList<>(); - in.readParcelableList(mUserActions, RemoteAction.class.getClassLoader()); + in.readTypedList(mUserActions, RemoteAction.CREATOR); } if (in.readInt() != 0) { mSourceRectHint = Rect.CREATOR.createFromParcel(in); @@ -386,7 +386,7 @@ public final class PictureInPictureParams implements Parcelable { } if (mUserActions != null) { out.writeInt(1); - out.writeParcelableList(mUserActions, 0); + out.writeTypedList(mUserActions, 0); } else { out.writeInt(0); } diff --git a/core/java/android/view/AppTransitionAnimationSpec.java b/core/java/android/view/AppTransitionAnimationSpec.java index 877bb56849108..3215f2bc2a50d 100644 --- a/core/java/android/view/AppTransitionAnimationSpec.java +++ b/core/java/android/view/AppTransitionAnimationSpec.java @@ -28,8 +28,8 @@ public class AppTransitionAnimationSpec implements Parcelable { public AppTransitionAnimationSpec(Parcel in) { taskId = in.readInt(); - rect = in.readParcelable(null); - buffer = in.readParcelable(null); + rect = in.readTypedObject(Rect.CREATOR); + buffer = in.readTypedObject(HardwareBuffer.CREATOR); } @Override @@ -40,8 +40,8 @@ public class AppTransitionAnimationSpec implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(taskId); - dest.writeParcelable(rect, 0 /* flags */); - dest.writeParcelable(buffer, 0); + dest.writeTypedObject(rect, 0 /* flags */); + dest.writeTypedObject(buffer, 0 /* flags */); } public static final @android.annotation.NonNull Parcelable.Creator CREATOR diff --git a/core/java/android/view/RemoteAnimationDefinition.java b/core/java/android/view/RemoteAnimationDefinition.java index a5ff19ee33121..ea9799584e20d 100644 --- a/core/java/android/view/RemoteAnimationDefinition.java +++ b/core/java/android/view/RemoteAnimationDefinition.java @@ -184,13 +184,13 @@ public class RemoteAnimationDefinition implements Parcelable { } private RemoteAnimationAdapterEntry(Parcel in) { - adapter = in.readParcelable(RemoteAnimationAdapter.class.getClassLoader()); + adapter = in.readTypedObject(RemoteAnimationAdapter.CREATOR); activityTypeFilter = in.readInt(); } @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeParcelable(adapter, flags); + dest.writeTypedObject(adapter, flags); dest.writeInt(activityTypeFilter); } diff --git a/core/java/android/view/RemoteAnimationTarget.java b/core/java/android/view/RemoteAnimationTarget.java index 258a72cbcab44..b1b670f5e0c99 100644 --- a/core/java/android/view/RemoteAnimationTarget.java +++ b/core/java/android/view/RemoteAnimationTarget.java @@ -222,20 +222,20 @@ public class RemoteAnimationTarget implements Parcelable { public RemoteAnimationTarget(Parcel in) { taskId = in.readInt(); mode = in.readInt(); - leash = in.readParcelable(null); + leash = in.readTypedObject(SurfaceControl.CREATOR); isTranslucent = in.readBoolean(); - clipRect = in.readParcelable(null); - contentInsets = in.readParcelable(null); + clipRect = in.readTypedObject(Rect.CREATOR); + contentInsets = in.readTypedObject(Rect.CREATOR); prefixOrderIndex = in.readInt(); - position = in.readParcelable(null); - localBounds = in.readParcelable(null); - sourceContainerBounds = in.readParcelable(null); - screenSpaceBounds = in.readParcelable(null); - windowConfiguration = in.readParcelable(null); + position = in.readTypedObject(Point.CREATOR); + localBounds = in.readTypedObject(Rect.CREATOR); + sourceContainerBounds = in.readTypedObject(Rect.CREATOR); + screenSpaceBounds = in.readTypedObject(Rect.CREATOR); + windowConfiguration = in.readTypedObject(WindowConfiguration.CREATOR); isNotInRecents = in.readBoolean(); - startLeash = in.readParcelable(null); - startBounds = in.readParcelable(null); - pictureInPictureParams = in.readParcelable(null); + startLeash = in.readTypedObject(SurfaceControl.CREATOR); + startBounds = in.readTypedObject(Rect.CREATOR); + pictureInPictureParams = in.readTypedObject(PictureInPictureParams.CREATOR); } @Override @@ -247,20 +247,20 @@ public class RemoteAnimationTarget implements Parcelable { public void writeToParcel(Parcel dest, int flags) { dest.writeInt(taskId); dest.writeInt(mode); - dest.writeParcelable(leash, 0 /* flags */); + dest.writeTypedObject(leash, 0 /* flags */); dest.writeBoolean(isTranslucent); - dest.writeParcelable(clipRect, 0 /* flags */); - dest.writeParcelable(contentInsets, 0 /* flags */); + dest.writeTypedObject(clipRect, 0 /* flags */); + dest.writeTypedObject(contentInsets, 0 /* flags */); dest.writeInt(prefixOrderIndex); - dest.writeParcelable(position, 0 /* flags */); - dest.writeParcelable(localBounds, 0 /* flags */); - dest.writeParcelable(sourceContainerBounds, 0 /* flags */); - dest.writeParcelable(screenSpaceBounds, 0 /* flags */); - dest.writeParcelable(windowConfiguration, 0 /* flags */); + dest.writeTypedObject(position, 0 /* flags */); + dest.writeTypedObject(localBounds, 0 /* flags */); + dest.writeTypedObject(sourceContainerBounds, 0 /* flags */); + dest.writeTypedObject(screenSpaceBounds, 0 /* flags */); + dest.writeTypedObject(windowConfiguration, 0 /* flags */); dest.writeBoolean(isNotInRecents); - dest.writeParcelable(startLeash, 0 /* flags */); - dest.writeParcelable(startBounds, 0 /* flags */); - dest.writeParcelable(pictureInPictureParams, 0 /* flags */); + dest.writeTypedObject(startLeash, 0 /* flags */); + dest.writeTypedObject(startBounds, 0 /* flags */); + dest.writeTypedObject(pictureInPictureParams, 0 /* flags */); } public void dump(PrintWriter pw, String prefix) { diff --git a/core/java/android/window/TaskSnapshot.java b/core/java/android/window/TaskSnapshot.java index dc07e44d4d98e..f1e5fb95ea545 100644 --- a/core/java/android/window/TaskSnapshot.java +++ b/core/java/android/window/TaskSnapshot.java @@ -46,7 +46,7 @@ public class TaskSnapshot implements Parcelable { private final int mOrientation; /** See {@link android.view.Surface.Rotation} */ @Surface.Rotation - private int mRotation; + private final int mRotation; /** The size of the snapshot before scaling */ private final Point mTaskSize; private final Rect mContentInsets; @@ -90,15 +90,15 @@ public class TaskSnapshot implements Parcelable { private TaskSnapshot(Parcel source) { mId = source.readLong(); mTopActivityComponent = ComponentName.readFromParcel(source); - mSnapshot = source.readParcelable(null /* classLoader */); + mSnapshot = source.readTypedObject(HardwareBuffer.CREATOR); int colorSpaceId = source.readInt(); mColorSpace = colorSpaceId >= 0 && colorSpaceId < ColorSpace.Named.values().length ? ColorSpace.get(ColorSpace.Named.values()[colorSpaceId]) : ColorSpace.get(ColorSpace.Named.SRGB); mOrientation = source.readInt(); mRotation = source.readInt(); - mTaskSize = source.readParcelable(null /* classLoader */); - mContentInsets = source.readParcelable(null /* classLoader */); + mTaskSize = source.readTypedObject(Point.CREATOR); + mContentInsets = source.readTypedObject(Rect.CREATOR); mIsLowResolution = source.readBoolean(); mIsRealSnapshot = source.readBoolean(); mWindowingMode = source.readInt(); @@ -235,13 +235,12 @@ public class TaskSnapshot implements Parcelable { public void writeToParcel(Parcel dest, int flags) { dest.writeLong(mId); ComponentName.writeToParcel(mTopActivityComponent, dest); - dest.writeParcelable(mSnapshot != null && !mSnapshot.isClosed() ? mSnapshot : null, - 0); + dest.writeTypedObject(mSnapshot != null && !mSnapshot.isClosed() ? mSnapshot : null, 0); dest.writeInt(mColorSpace.getId()); dest.writeInt(mOrientation); dest.writeInt(mRotation); - dest.writeParcelable(mTaskSize, 0); - dest.writeParcelable(mContentInsets, 0); + dest.writeTypedObject(mTaskSize, 0); + dest.writeTypedObject(mContentInsets, 0); dest.writeBoolean(mIsLowResolution); dest.writeBoolean(mIsRealSnapshot); dest.writeInt(mWindowingMode);