Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4ef7ca5a authored by shawnlin's avatar shawnlin
Browse files

Fixed regression on jank test of changeBrightness

Replace using hardware layer for alpha animation with drawing
transparent color with MULTIPLY mode.

Test: atest google/perf/jank/SystemUI/UbSystemUIJankTests-Trace:android.platform.systemui.tests.jank.SystemUiJankTests#testChangeBrightness
Change-Id: I9615af89c4418dd90ccc86e9e7c71d88e7121826
Fixes: 79266233
parent c443a7cb
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -56,8 +56,6 @@
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <include layout="@layout/brightness_mirror" />

    <ViewStub android:id="@+id/fullscreen_user_switcher_stub"
              android:layout="@layout/car_fullscreen_user_switcher"
              android:layout_width="match_parent"
@@ -68,6 +66,8 @@
        android:layout_height="match_parent"
        android:visibility="invisible" />

    <include layout="@layout/brightness_mirror" />

    <com.android.systemui.statusbar.ScrimView
        android:id="@+id/scrim_in_front"
        android:layout_width="match_parent"
+3 −0
Original line number Diff line number Diff line
@@ -67,6 +67,9 @@
    <item type="id" name="transformation_start_scale_x_tag"/>
    <item type="id" name="transformation_start_scale_y_tag"/>
    <item type="id" name="continuous_clipping_tag"/>
    <item type="id" name="panel_alpha_animator_tag"/>
    <item type="id" name="panel_alpha_animator_start_tag"/>
    <item type="id" name="panel_alpha_animator_end_tag"/>

    <!-- Whether the icon is from a notification for which targetSdk < L -->
    <item type="id" name="icon_is_pre_L"/>
+63 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.os.PowerManager;
import android.util.AttributeSet;
@@ -250,6 +252,33 @@ public class NotificationPanelView extends PanelView implements
    private ArrayList<Runnable> mVerticalTranslationListener = new ArrayList<>();
    private HeadsUpAppearanceController mHeadsUpAppearanceController;

    private int mPanelAlpha;
    private int mCurrentPanelAlpha;
    private final Paint mAlphaPaint = new Paint();
    private Runnable mPanelAlphaEndAction;
    private AnimatorListenerAdapter mAnimatorListenerAdapter = new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (mPanelAlphaEndAction != null) {
                mPanelAlphaEndAction.run();
            }
        }
    };
    private final AnimatableProperty PANEL_ALPHA = AnimatableProperty.from(
            "panelAlpha",
            NotificationPanelView::setPanelAlphaInternal,
            NotificationPanelView::getCurrentPanelAlpha,
            R.id.panel_alpha_animator_tag,
            R.id.panel_alpha_animator_start_tag,
            R.id.panel_alpha_animator_end_tag);
    private final AnimationProperties PANEL_ALPHA_OUT_PROPERTIES = new AnimationProperties()
            .setDuration(150)
            .setCustomInterpolator(PANEL_ALPHA.getProperty(), Interpolators.ALPHA_OUT);
    private final AnimationProperties PANEL_ALPHA_IN_PROPERTIES = new AnimationProperties()
            .setDuration(200)
            .setAnimationFinishListener(mAnimatorListenerAdapter)
            .setCustomInterpolator(PANEL_ALPHA.getProperty(), Interpolators.ALPHA_IN);

    public NotificationPanelView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setWillNotDraw(!DEBUG);
@@ -257,6 +286,8 @@ public class NotificationPanelView extends PanelView implements
        mPowerManager = context.getSystemService(PowerManager.class);
        mAccessibilityManager = context.getSystemService(AccessibilityManager.class);
        setAccessibilityPaneTitle(determineAccessibilityPaneTitle());
        mAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));
        setPanelAlpha(255, false /* animate */);
    }

    public void setStatusBar(StatusBar bar) {
@@ -2302,6 +2333,38 @@ public class NotificationPanelView extends PanelView implements
        }
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
        if (mCurrentPanelAlpha != 255) {
            canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mAlphaPaint);
        }
    }

    public float getCurrentPanelAlpha() {
        return mCurrentPanelAlpha;
    }

    public boolean setPanelAlpha(int alpha, boolean animate) {
        if (mPanelAlpha != alpha) {
            mPanelAlpha = alpha;
            PropertyAnimator.setProperty(this, PANEL_ALPHA, alpha,
                    alpha == 255 ? PANEL_ALPHA_IN_PROPERTIES : PANEL_ALPHA_OUT_PROPERTIES, animate);
            return true;
        }
        return false;
    }

    public void setPanelAlphaInternal(float alpha) {
        mCurrentPanelAlpha = (int) alpha;
        mAlphaPaint.setARGB(mCurrentPanelAlpha, 255, 255, 255);
        invalidate();
    }

    public void setPanelAlphaEndAction(Runnable r) {
        mPanelAlphaEndAction = r;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
+7 −30
Original line number Diff line number Diff line
@@ -22,14 +22,12 @@ import android.util.ArraySet;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.widget.FrameLayout;

import com.android.internal.util.Preconditions;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.statusbar.phone.NotificationPanelView;
import com.android.systemui.statusbar.phone.StatusBarWindowView;
import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;

import java.util.function.Consumer;

@@ -39,13 +37,9 @@ import java.util.function.Consumer;
public class BrightnessMirrorController
        implements CallbackController<BrightnessMirrorController.BrightnessMirrorListener> {

    private final static long TRANSITION_DURATION_OUT = 150;
    private final static long TRANSITION_DURATION_IN = 200;

    private final StatusBarWindowView mStatusBarWindow;
    private final NotificationStackScrollLayout mStackScroller;
    private final Consumer<Boolean> mVisibilityCallback;
    private final View mNotificationPanel;
    private final NotificationPanelView mNotificationPanel;
    private final ArraySet<BrightnessMirrorListener> mBrightnessMirrorListeners = new ArraySet<>();
    private final int[] mInt2Cache = new int[2];
    private View mBrightnessMirror;
@@ -55,38 +49,21 @@ public class BrightnessMirrorController
        mStatusBarWindow = statusBarWindow;
        mBrightnessMirror = statusBarWindow.findViewById(R.id.brightness_mirror);
        mNotificationPanel = statusBarWindow.findViewById(R.id.notification_panel);
        mStackScroller = statusBarWindow.findViewById(R.id.notification_stack_scroller);
        mNotificationPanel.setPanelAlphaEndAction(() -> {
            mBrightnessMirror.setVisibility(View.INVISIBLE);
        });
        mVisibilityCallback = visibilityCallback;
    }

    public void showMirror() {
        mBrightnessMirror.setVisibility(View.VISIBLE);
        mStackScroller.setFadingOut(true);
        mVisibilityCallback.accept(true);
        outAnimation(mNotificationPanel.animate())
                .withLayer();
        mNotificationPanel.setPanelAlpha(0, true /* animate */);
    }

    public void hideMirror() {
        mVisibilityCallback.accept(false);
        inAnimation(mNotificationPanel.animate())
                .withLayer()
                .withEndAction(() -> {
                    mBrightnessMirror.setVisibility(View.INVISIBLE);
                    mStackScroller.setFadingOut(false);
                });
    }

    private ViewPropertyAnimator outAnimation(ViewPropertyAnimator a) {
        return a.alpha(0.0f)
                .setDuration(TRANSITION_DURATION_OUT)
                .setInterpolator(Interpolators.ALPHA_OUT)
                .withEndAction(null);
    }
    private ViewPropertyAnimator inAnimation(ViewPropertyAnimator a) {
        return a.alpha(1.0f)
                .setDuration(TRANSITION_DURATION_IN)
                .setInterpolator(Interpolators.ALPHA_IN);
        mNotificationPanel.setPanelAlpha(255, true /* animate */);
    }

    public void setLocation(View original) {
+7 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ public class AnimationProperties {
    public long duration;
    public long delay;
    private ArrayMap<Property, Interpolator> mInterpolatorMap;
    private AnimatorListenerAdapter mAnimatorListenerAdapter;

    /**
     * @return an animation filter for this animation.
@@ -48,7 +49,12 @@ public class AnimationProperties {
     * @return a listener that should be run whenever any property finished its animation
     */
    public AnimatorListenerAdapter getAnimationFinishListener() {
        return null;
        return mAnimatorListenerAdapter;
    }

    public AnimationProperties setAnimationFinishListener(AnimatorListenerAdapter listener) {
        mAnimatorListenerAdapter = listener;
        return this;
    }

    public boolean wasAdded(View view) {