Load icon of splash screen only once
It is unnecessary to load icon without scale and load again with scale. Just load the scaled one directly. The construction time of SplashScreenView: Dialer : 36ms -> 24ms Messages: 21ms -> 13ms Contacts: 27ms -> 16ms Bug: 187104264 Test: OpenAppMicrobenchmark Change-Id: I0b71d3038f85a0839af862e5822e10fccbe1395d
This commit is contained in:
@@ -250,7 +250,7 @@ public class SplashscreenContentDrawer {
|
||||
private SplashScreenView mCachedResult;
|
||||
private int mThemeColor;
|
||||
private Drawable mFinalIconDrawable;
|
||||
private float mScale = 1f;
|
||||
private int mFinalIconSize = mIconSize;
|
||||
|
||||
StartingWindowViewBuilder setWindowBGColor(@ColorInt int background) {
|
||||
mThemeColor = background;
|
||||
@@ -287,48 +287,46 @@ public class SplashscreenContentDrawer {
|
||||
|
||||
Drawable iconDrawable;
|
||||
final int animationDuration;
|
||||
final int iconSize;
|
||||
if (mEmptyView) {
|
||||
// empty splash screen case
|
||||
animationDuration = 0;
|
||||
iconSize = 0;
|
||||
mFinalIconSize = 0;
|
||||
} else if (mTmpAttrs.mReplaceIcon != null) {
|
||||
// replaced icon, don't process
|
||||
iconDrawable = mTmpAttrs.mReplaceIcon;
|
||||
animationDuration = mTmpAttrs.mAnimationDuration;
|
||||
createIconDrawable(iconDrawable, mIconSize);
|
||||
iconSize = mIconSize;
|
||||
createIconDrawable(iconDrawable);
|
||||
} else {
|
||||
final float iconScale = (float) mIconSize / (float) mDefaultIconSize;
|
||||
iconDrawable = mIconProvider.getIcon(mActivityInfo);
|
||||
final float iconScale = (float) mIconSize / (float) mDefaultIconSize;
|
||||
final int densityDpi = mContext.getResources().getDisplayMetrics().densityDpi;
|
||||
final int scaledIconDpi = (int) (0.5f + iconScale * densityDpi);
|
||||
iconDrawable = mIconProvider.getIcon(mActivityInfo, scaledIconDpi);
|
||||
if (iconDrawable == null) {
|
||||
iconDrawable = mContext.getPackageManager().getDefaultActivityIcon();
|
||||
}
|
||||
if (!processAdaptiveIcon(iconDrawable, iconScale)) {
|
||||
if (!processAdaptiveIcon(iconDrawable)) {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "The icon is not an AdaptiveIconDrawable");
|
||||
}
|
||||
// TODO process legacy icon(bitmap)
|
||||
final Drawable tempIcon = loadIconByDensity(iconDrawable, iconScale);
|
||||
createIconDrawable(tempIcon, mIconSize);
|
||||
createIconDrawable(iconDrawable);
|
||||
}
|
||||
animationDuration = 0;
|
||||
iconSize = (int) (0.5 + mIconSize * mScale);
|
||||
}
|
||||
|
||||
mCachedResult = fillViewWithIcon(iconSize, mFinalIconDrawable, animationDuration);
|
||||
mCachedResult = fillViewWithIcon(mFinalIconSize, mFinalIconDrawable, animationDuration);
|
||||
mBuildComplete = true;
|
||||
return mCachedResult;
|
||||
}
|
||||
|
||||
private void createIconDrawable(Drawable iconDrawable, int iconSize) {
|
||||
private void createIconDrawable(Drawable iconDrawable) {
|
||||
mFinalIconDrawable = SplashscreenIconDrawableFactory.makeIconDrawable(
|
||||
mTmpAttrs.mIconBgColor != Color.TRANSPARENT
|
||||
? mTmpAttrs.mIconBgColor : mThemeColor,
|
||||
iconDrawable, iconSize, mSplashscreenWorkerHandler);
|
||||
iconDrawable, mFinalIconSize, mSplashscreenWorkerHandler);
|
||||
}
|
||||
|
||||
private boolean processAdaptiveIcon(Drawable iconDrawable, float iconScale) {
|
||||
private boolean processAdaptiveIcon(Drawable iconDrawable) {
|
||||
if (!(iconDrawable instanceof AdaptiveIconDrawable)) {
|
||||
return false;
|
||||
}
|
||||
@@ -339,7 +337,7 @@ public class SplashscreenContentDrawer {
|
||||
final DrawableColorTester backIconTester =
|
||||
new DrawableColorTester(adaptiveIconDrawable.getBackground());
|
||||
|
||||
Drawable iconForeground = adaptiveIconDrawable.getForeground();
|
||||
final Drawable iconForeground = adaptiveIconDrawable.getForeground();
|
||||
final DrawableColorTester foreIconTester =
|
||||
new DrawableColorTester(iconForeground, true /* filterTransparent */);
|
||||
|
||||
@@ -378,35 +376,20 @@ public class SplashscreenContentDrawer {
|
||||
final float noBgScale =
|
||||
foreIconTester.nonTransparentRatio() < ENLARGE_FOREGROUND_ICON_THRESHOLD
|
||||
? NO_BACKGROUND_SCALE : 1f;
|
||||
final Drawable tempIcon = loadIconByDensity(iconDrawable, iconScale * noBgScale);
|
||||
if (tempIcon instanceof AdaptiveIconDrawable) {
|
||||
mScale = noBgScale;
|
||||
iconForeground = ((AdaptiveIconDrawable) tempIcon).getForeground();
|
||||
}
|
||||
// Using AdaptiveIconDrawable here can help keep the shape consistent with the
|
||||
// current settings.
|
||||
final int iconSize = (int) (0.5f + mIconSize * mScale);
|
||||
createIconDrawable(iconForeground, iconSize);
|
||||
mFinalIconSize = (int) (0.5f + mIconSize * noBgScale);
|
||||
createIconDrawable(iconForeground);
|
||||
} else {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "makeSplashScreenContentView: draw whole icon");
|
||||
}
|
||||
final Drawable tempIcon = loadIconByDensity(iconDrawable, iconScale);
|
||||
createIconDrawable(tempIcon, mIconSize);
|
||||
createIconDrawable(iconDrawable);
|
||||
}
|
||||
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
|
||||
return true;
|
||||
}
|
||||
|
||||
private Drawable loadIconByDensity(Drawable baseDrawable, float scale) {
|
||||
if (scale == 1 && baseDrawable != null) {
|
||||
return baseDrawable;
|
||||
}
|
||||
final int densityDpi = mContext.getResources().getDisplayMetrics().densityDpi;
|
||||
final int updateDpi = (int) (0.5f + scale * densityDpi);
|
||||
return mIconProvider.getIcon(mActivityInfo, updateDpi);
|
||||
}
|
||||
|
||||
private SplashScreenView fillViewWithIcon(int iconSize, Drawable iconDrawable,
|
||||
int animationDuration) {
|
||||
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "fillViewWithIcon");
|
||||
|
||||
Reference in New Issue
Block a user