Merge "Optimize the Parcel read/write of common window data" into sc-dev
This commit is contained in:
@@ -57,7 +57,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
|
||||
* TODO: Investigate combining with {@link #mAppBounds}. Can the latter be a product of the
|
||||
* former?
|
||||
*/
|
||||
private Rect mBounds = new Rect();
|
||||
private final Rect mBounds = new Rect();
|
||||
|
||||
/**
|
||||
* {@link android.graphics.Rect} defining app bounds. The dimensions override usages of
|
||||
@@ -71,7 +71,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
|
||||
* The maximum {@link Rect} bounds that an app can expect. It is used to report value of
|
||||
* {@link WindowManager#getMaximumWindowMetrics()}.
|
||||
*/
|
||||
private Rect mMaxBounds = new Rect();
|
||||
private final Rect mMaxBounds = new Rect();
|
||||
|
||||
/**
|
||||
* The current rotation of this window container relative to the default
|
||||
@@ -240,9 +240,9 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeParcelable(mBounds, flags);
|
||||
dest.writeParcelable(mAppBounds, flags);
|
||||
dest.writeParcelable(mMaxBounds, flags);
|
||||
mBounds.writeToParcel(dest, flags);
|
||||
dest.writeTypedObject(mAppBounds, flags);
|
||||
mMaxBounds.writeToParcel(dest, flags);
|
||||
dest.writeInt(mWindowingMode);
|
||||
dest.writeInt(mActivityType);
|
||||
dest.writeInt(mAlwaysOnTop);
|
||||
@@ -250,10 +250,11 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
|
||||
dest.writeInt(mDisplayWindowingMode);
|
||||
}
|
||||
|
||||
private void readFromParcel(Parcel source) {
|
||||
mBounds = source.readParcelable(Rect.class.getClassLoader());
|
||||
mAppBounds = source.readParcelable(Rect.class.getClassLoader());
|
||||
mMaxBounds = source.readParcelable(Rect.class.getClassLoader());
|
||||
/** @hide */
|
||||
public void readFromParcel(@NonNull Parcel source) {
|
||||
mBounds.readFromParcel(source);
|
||||
mAppBounds = source.readTypedObject(Rect.CREATOR);
|
||||
mMaxBounds.readFromParcel(source);
|
||||
mWindowingMode = source.readInt();
|
||||
mActivityType = source.readInt();
|
||||
mAlwaysOnTop = source.readInt();
|
||||
@@ -693,9 +694,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
|
||||
}
|
||||
protoOutputStream.write(WINDOWING_MODE, mWindowingMode);
|
||||
protoOutputStream.write(ACTIVITY_TYPE, mActivityType);
|
||||
if (mBounds != null) {
|
||||
mBounds.dumpDebug(protoOutputStream, BOUNDS);
|
||||
}
|
||||
mBounds.dumpDebug(protoOutputStream, BOUNDS);
|
||||
mMaxBounds.dumpDebug(protoOutputStream, MAX_BOUNDS);
|
||||
protoOutputStream.end(token);
|
||||
}
|
||||
@@ -719,11 +718,9 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
|
||||
mAppBounds.readFromProto(proto, APP_BOUNDS);
|
||||
break;
|
||||
case (int) BOUNDS:
|
||||
mBounds = new Rect();
|
||||
mBounds.readFromProto(proto, BOUNDS);
|
||||
break;
|
||||
case (int) MAX_BOUNDS:
|
||||
mMaxBounds = new Rect();
|
||||
mMaxBounds.readFromProto(proto, MAX_BOUNDS);
|
||||
break;
|
||||
case (int) WINDOWING_MODE:
|
||||
|
||||
@@ -1956,7 +1956,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
|
||||
dest.writeInt(mnc);
|
||||
|
||||
fixUpLocaleList();
|
||||
dest.writeParcelable(mLocaleList, flags);
|
||||
dest.writeTypedObject(mLocaleList, flags);
|
||||
|
||||
if(userSetLocale) {
|
||||
dest.writeInt(1);
|
||||
@@ -1980,7 +1980,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
|
||||
dest.writeInt(compatScreenWidthDp);
|
||||
dest.writeInt(compatScreenHeightDp);
|
||||
dest.writeInt(compatSmallestScreenWidthDp);
|
||||
dest.writeValue(windowConfiguration);
|
||||
windowConfiguration.writeToParcel(dest, flags);
|
||||
dest.writeInt(assetsSeq);
|
||||
dest.writeInt(seq);
|
||||
dest.writeInt(fontWeightAdjustment);
|
||||
@@ -1991,7 +1991,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
|
||||
mcc = source.readInt();
|
||||
mnc = source.readInt();
|
||||
|
||||
mLocaleList = source.readParcelable(LocaleList.class.getClassLoader());
|
||||
mLocaleList = source.readTypedObject(LocaleList.CREATOR);
|
||||
locale = mLocaleList.get(0);
|
||||
|
||||
userSetLocale = (source.readInt()==1);
|
||||
@@ -2012,7 +2012,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
|
||||
compatScreenWidthDp = source.readInt();
|
||||
compatScreenHeightDp = source.readInt();
|
||||
compatSmallestScreenWidthDp = source.readInt();
|
||||
windowConfiguration.setTo((WindowConfiguration) source.readValue(null));
|
||||
windowConfiguration.readFromParcel(source);
|
||||
assetsSeq = source.readInt();
|
||||
seq = source.readInt();
|
||||
fontWeightAdjustment = source.readInt();
|
||||
|
||||
@@ -33,9 +33,9 @@ import java.io.PrintWriter;
|
||||
*/
|
||||
public class MergedConfiguration implements Parcelable {
|
||||
|
||||
private Configuration mGlobalConfig = new Configuration();
|
||||
private Configuration mOverrideConfig = new Configuration();
|
||||
private Configuration mMergedConfig = new Configuration();
|
||||
private final Configuration mGlobalConfig = new Configuration();
|
||||
private final Configuration mOverrideConfig = new Configuration();
|
||||
private final Configuration mMergedConfig = new Configuration();
|
||||
|
||||
public MergedConfiguration() {
|
||||
}
|
||||
@@ -59,15 +59,15 @@ public class MergedConfiguration implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeParcelable(mGlobalConfig, flags);
|
||||
dest.writeParcelable(mOverrideConfig, flags);
|
||||
dest.writeParcelable(mMergedConfig, flags);
|
||||
mGlobalConfig.writeToParcel(dest, flags);
|
||||
mOverrideConfig.writeToParcel(dest, flags);
|
||||
mMergedConfig.writeToParcel(dest, flags);
|
||||
}
|
||||
|
||||
public void readFromParcel(Parcel source) {
|
||||
mGlobalConfig = source.readParcelable(Configuration.class.getClassLoader());
|
||||
mOverrideConfig = source.readParcelable(Configuration.class.getClassLoader());
|
||||
mMergedConfig = source.readParcelable(Configuration.class.getClassLoader());
|
||||
mGlobalConfig.readFromParcel(source);
|
||||
mOverrideConfig.readFromParcel(source);
|
||||
mMergedConfig.readFromParcel(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -261,11 +261,7 @@ public class InsetsSource implements Parcelable {
|
||||
|
||||
public InsetsSource(Parcel in) {
|
||||
mType = in.readInt();
|
||||
if (in.readInt() != 0) {
|
||||
mFrame = Rect.CREATOR.createFromParcel(in);
|
||||
} else {
|
||||
mFrame = null;
|
||||
}
|
||||
mFrame = Rect.CREATOR.createFromParcel(in);
|
||||
if (in.readInt() != 0) {
|
||||
mVisibleFrame = Rect.CREATOR.createFromParcel(in);
|
||||
} else {
|
||||
@@ -282,12 +278,7 @@ public class InsetsSource implements Parcelable {
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(mType);
|
||||
if (mFrame != null) {
|
||||
dest.writeInt(1);
|
||||
mFrame.writeToParcel(dest, 0);
|
||||
} else {
|
||||
dest.writeInt(0);
|
||||
}
|
||||
mFrame.writeToParcel(dest, 0);
|
||||
if (mVisibleFrame != null) {
|
||||
dest.writeInt(1);
|
||||
mVisibleFrame.writeToParcel(dest, 0);
|
||||
|
||||
@@ -77,8 +77,8 @@ public class InsetsSourceControl implements Parcelable {
|
||||
|
||||
public InsetsSourceControl(Parcel in) {
|
||||
mType = in.readInt();
|
||||
mLeash = in.readParcelable(null /* loader */);
|
||||
mSurfacePosition = in.readParcelable(null /* loader */);
|
||||
mLeash = in.readTypedObject(SurfaceControl.CREATOR);
|
||||
mSurfacePosition = in.readTypedObject(Point.CREATOR);
|
||||
mSkipAnimationOnce = in.readBoolean();
|
||||
}
|
||||
|
||||
@@ -119,8 +119,8 @@ public class InsetsSourceControl implements Parcelable {
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(mType);
|
||||
dest.writeParcelable(mLeash, 0 /* flags*/);
|
||||
dest.writeParcelable(mSurfacePosition, 0 /* flags*/);
|
||||
dest.writeTypedObject(mLeash, 0 /* parcelableFlags */);
|
||||
dest.writeTypedObject(mSurfacePosition, 0 /* parcelableFlags */);
|
||||
dest.writeBoolean(mSkipAnimationOnce);
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ public class InsetsState implements Parcelable {
|
||||
static final int ISIDE_FLOATING = 4;
|
||||
static final int ISIDE_UNKNOWN = 5;
|
||||
|
||||
private InsetsSource[] mSources = new InsetsSource[SIZE];
|
||||
private final InsetsSource[] mSources = new InsetsSource[SIZE];
|
||||
|
||||
/**
|
||||
* The frame of the display these sources are relative to.
|
||||
@@ -804,7 +804,7 @@ public class InsetsState implements Parcelable {
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
mDisplayFrame.writeToParcel(dest, flags);
|
||||
mDisplayCutout.writeToParcel(dest, flags);
|
||||
dest.writeParcelableArray(mSources, 0);
|
||||
dest.writeTypedArray(mSources, 0 /* parcelableFlags */);
|
||||
dest.writeTypedObject(mRoundedCorners, flags);
|
||||
}
|
||||
|
||||
@@ -820,9 +820,9 @@ public class InsetsState implements Parcelable {
|
||||
};
|
||||
|
||||
public void readFromParcel(Parcel in) {
|
||||
mDisplayFrame.set(Rect.CREATOR.createFromParcel(in));
|
||||
mDisplayCutout.set(DisplayCutout.ParcelableWrapper.CREATOR.createFromParcel(in));
|
||||
mSources = in.readParcelableArray(null, InsetsSource.class);
|
||||
mDisplayFrame.readFromParcel(in);
|
||||
mDisplayCutout.readFromParcel(in);
|
||||
in.readTypedArray(mSources, InsetsSource.CREATOR);
|
||||
mRoundedCorners = in.readTypedObject(RoundedCorners.CREATOR);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,9 +58,9 @@ public class ClientWindowFrames implements Parcelable {
|
||||
|
||||
/** Needed for AIDL out parameters. */
|
||||
public void readFromParcel(Parcel in) {
|
||||
frame.set(Rect.CREATOR.createFromParcel(in));
|
||||
displayFrame.set(Rect.CREATOR.createFromParcel(in));
|
||||
backdropFrame.set(Rect.CREATOR.createFromParcel(in));
|
||||
frame.readFromParcel(in);
|
||||
displayFrame.readFromParcel(in);
|
||||
backdropFrame.readFromParcel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
133
core/tests/benchmarks/src/android/os/ParcelableBenchmark.java
Normal file
133
core/tests/benchmarks/src/android/os/ParcelableBenchmark.java
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.os;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.util.MergedConfiguration;
|
||||
import android.view.InsetsSource;
|
||||
import android.view.InsetsState;
|
||||
|
||||
import com.google.caliper.AfterExperiment;
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
|
||||
/**
|
||||
* Benchmark of read/write large Parcelable class. This also shows the performance of different
|
||||
* implementations for nested Parcelable class:
|
||||
* <ul>
|
||||
* <li>Well-written read/writeFromParcel (direct access)</li>
|
||||
* <li>read/writeTypedObject (object creation + addition int to indicate nullity)</li>
|
||||
* <li>read/writeParcelable (object creation + addition type String)</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class ParcelableBenchmark {
|
||||
private Parcel mParcel;
|
||||
|
||||
@BeforeExperiment
|
||||
protected void setUp() {
|
||||
mParcel = Parcel.obtain();
|
||||
}
|
||||
|
||||
@AfterExperiment
|
||||
protected void tearDown() {
|
||||
mParcel.recycle();
|
||||
mParcel = null;
|
||||
}
|
||||
|
||||
public void timeReadWriteMergedConfiguration(int reps) {
|
||||
final MergedConfiguration mergedConfiguration = new MergedConfiguration();
|
||||
for (int i = 0; i < reps; i++) {
|
||||
mergedConfiguration.writeToParcel(mParcel, 0);
|
||||
mParcel.setDataPosition(0);
|
||||
mergedConfiguration.readFromParcel(mParcel);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeReadWriteInsetsState(int reps) {
|
||||
final InsetsState insetsState = new InsetsState();
|
||||
for (int i = 0; i < InsetsState.SIZE; i++) {
|
||||
insetsState.addSource(new InsetsSource(i));
|
||||
}
|
||||
for (int i = 0; i < reps; i++) {
|
||||
insetsState.writeToParcel(mParcel, 0);
|
||||
mParcel.setDataPosition(0);
|
||||
insetsState.readFromParcel(mParcel);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeReadWritePointArray(int reps) {
|
||||
final PointArray pointArray = new PointArray();
|
||||
for (int i = 0; i < reps; i++) {
|
||||
pointArray.writeToParcel(mParcel, 0);
|
||||
mParcel.setDataPosition(0);
|
||||
pointArray.readFromParcel(mParcel);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeReadWritePointArrayFast(int reps) {
|
||||
final PointArrayFast pointArray = new PointArrayFast();
|
||||
for (int i = 0; i < reps; i++) {
|
||||
pointArray.writeToParcel(mParcel, 0);
|
||||
mParcel.setDataPosition(0);
|
||||
pointArray.readFromParcel(mParcel);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ParcelCreator")
|
||||
private static class PointArray implements Parcelable {
|
||||
Rect mBounds = new Rect();
|
||||
Point[] mPoints = new Point[10];
|
||||
{
|
||||
for (int i = 0; i < mPoints.length; i++) {
|
||||
mPoints[i] = new Point();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeParcelable(mBounds, flags);
|
||||
dest.writeParcelableArray(mPoints, flags);
|
||||
}
|
||||
|
||||
void readFromParcel(Parcel in) {
|
||||
mBounds = in.readParcelable(Rect.class.getClassLoader());
|
||||
mPoints = in.readParcelableArray(Point.class.getClassLoader(), Point.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ParcelCreator")
|
||||
private static class PointArrayFast extends PointArray {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
mBounds.writeToParcel(dest, flags);
|
||||
dest.writeTypedArray(mPoints, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
void readFromParcel(Parcel in) {
|
||||
mBounds.readFromParcel(in);
|
||||
in.readTypedArray(mPoints, Point.CREATOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user