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

Commit 90a38dd7 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Removed shade drawing optimization

Why?
- This optimization has caused many glitches, it easy to break and
  we've done so a few times (technical debt.)
- It's unclear if not calling glClear() is still an optimization.
  Most graphics cards actually expect a glClear and are optimized
  to discard old frame buffers when the method is invoked

Change-Id: If1bb9b8bf4c907ca907dc1205ad05dabfefeba1b
Fixes: 113286511
Test: manual
Test: shalac@ is keeping an eye on the performance dashboard
parent 322a8b21
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -79,13 +79,6 @@
    <!-- Show camera affordance on Keyguard -->
    <bool name="config_keyguardShowCameraAffordance">false</bool>

    <!-- Whether we should use SRC drawing mode when drawing the scrim behind. If this flag is set,
         we change the canvas opacity so libhwui doesn't call glClear on our surface, and then we
         draw the scrim with SRC to overwrite the whole buffer, which saves us a layer of overdraw.
         However, SRC performs poorly on some devices, where it is more efficient to
         glClear + SRC_OVER, in which case this flag should be disabled. -->
    <bool name="config_status_bar_scrim_behind_use_src">true</bool>

    <!-- The length of the vibration when the notification pops open. -->
    <integer name="one_finger_pop_duration_ms">10</integer>

+2 −79
Original line number Diff line number Diff line
@@ -53,11 +53,8 @@ public class ScrimView extends View implements ConfigurationController.Configura
    private static final String TAG = "ScrimView";
    private final ColorExtractor.GradientColors mColors;
    private int mDensity;
    private boolean mDrawAsSrc;
    private float mViewAlpha = 1.0f;
    private ValueAnimator mAlphaAnimator;
    private Rect mExcludedRect = new Rect();
    private boolean mHasExcludedArea;
    private Drawable mDrawable;
    private PorterDuffColorFilter mColorFilter;
    private int mTintColor;
@@ -137,59 +134,8 @@ public class ScrimView extends View implements ConfigurationController.Configura

    @Override
    protected void onDraw(Canvas canvas) {
        if (mDrawAsSrc || mDrawable.getAlpha() > 0) {
            if (!mHasExcludedArea) {
        if (mDrawable.getAlpha() > 0) {
            mDrawable.draw(canvas);
            } else {
                if (mExcludedRect.top > 0) {
                    canvas.save();
                    canvas.clipRect(0, 0, getWidth(), mExcludedRect.top);
                    mDrawable.draw(canvas);
                    canvas.restore();
                }
                if (mExcludedRect.left > 0) {
                    canvas.save();
                    canvas.clipRect(0, mExcludedRect.top, mExcludedRect.left,
                            mExcludedRect.bottom);
                    mDrawable.draw(canvas);
                    canvas.restore();
                }
                if (mExcludedRect.right < getWidth()) {
                    canvas.save();
                    canvas.clipRect(mExcludedRect.right, mExcludedRect.top, getWidth(),
                            mExcludedRect.bottom);
                    mDrawable.draw(canvas);
                    canvas.restore();
                }
                if (mExcludedRect.bottom < getHeight()) {
                    canvas.save();
                    canvas.clipRect(0, mExcludedRect.bottom, getWidth(), getHeight());
                    mDrawable.draw(canvas);
                    canvas.restore();
                }
                // We also need to draw the rounded corners of the background
                canvas.save();
                canvas.clipRect(mExcludedRect.left, mExcludedRect.top,
                        mExcludedRect.left + mCornerRadius, mExcludedRect.top + mCornerRadius);
                mDrawable.draw(canvas);
                canvas.restore();
                canvas.save();
                canvas.clipRect(mExcludedRect.right - mCornerRadius, mExcludedRect.top,
                        mExcludedRect.right, mExcludedRect.top + mCornerRadius);
                mDrawable.draw(canvas);
                canvas.restore();
                canvas.save();
                canvas.clipRect(mExcludedRect.left, mExcludedRect.bottom - mCornerRadius,
                        mExcludedRect.left + mCornerRadius, mExcludedRect.bottom);
                mDrawable.draw(canvas);
                canvas.restore();
                canvas.save();
                canvas.clipRect(mExcludedRect.right - mCornerRadius,
                        mExcludedRect.bottom - mCornerRadius,
                        mExcludedRect.right, mExcludedRect.bottom);
                mDrawable.draw(canvas);
                canvas.restore();
            }
        }
    }

@@ -198,7 +144,6 @@ public class ScrimView extends View implements ConfigurationController.Configura
        mDrawable.setCallback(this);
        mDrawable.setBounds(getLeft(), getTop(), getRight(), getBottom());
        mDrawable.setAlpha((int) (255 * mViewAlpha));
        setDrawAsSrc(mDrawAsSrc);
        updateScreenSize();
        invalidate();
    }
@@ -211,12 +156,6 @@ public class ScrimView extends View implements ConfigurationController.Configura
        }
    }

    public void setDrawAsSrc(boolean asSrc) {
        mDrawAsSrc = asSrc;
        PorterDuff.Mode mode = asSrc ? PorterDuff.Mode.SRC : PorterDuff.Mode.SRC_OVER;
        mDrawable.setXfermode(new PorterDuffXfermode(mode));
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
@@ -328,22 +267,6 @@ public class ScrimView extends View implements ConfigurationController.Configura
        return mViewAlpha;
    }

    public void setExcludedArea(Rect area) {
        if (area == null) {
            mHasExcludedArea = false;
            invalidate();
            return;
        }

        int left = Math.max(area.left, 0);
        int top = Math.max(area.top, 0);
        int right = Math.min(area.right, getWidth());
        int bottom = Math.min(area.bottom, getHeight());
        mExcludedRect.set(left, top, right, bottom);
        mHasExcludedArea = left < right && top < bottom;
        invalidate();
    }

    public void setChangeRunnable(Runnable changeRunnable) {
        mChangeRunnable = changeRunnable;
    }
+2 −65
Original line number Diff line number Diff line
@@ -394,9 +394,6 @@ public class NotificationStackScrollLayout extends ViewGroup
    };
    private PorterDuffXfermode mSrcMode = new PorterDuffXfermode(PorterDuff.Mode.SRC);
    private boolean mPulsing;
    private boolean mDrawBackgroundAsSrc;
    private boolean mFadingOut;
    private boolean mParentNotFullyVisible;
    private boolean mGroupExpandedForMeasure;
    private boolean mScrollable;
    private View mForcedScroll;
@@ -789,21 +786,6 @@ public class NotificationStackScrollLayout extends ViewGroup
                R.dimen.heads_up_status_bar_padding);
    }

    public void setDrawBackgroundAsSrc(boolean asSrc) {
        mDrawBackgroundAsSrc = asSrc;
        updateSrcDrawing();
    }

    private void updateSrcDrawing() {
        if (!mShouldDrawNotificationBackground) {
            return;
        }

        mBackgroundPaint.setXfermode(mDrawBackgroundAsSrc && !mFadingOut && !mParentNotFullyVisible
                ? mSrcMode : null);
        invalidate();
    }

    private void notifyHeightChangeListener(ExpandableView view) {
        notifyHeightChangeListener(view, false /* needsAnimation */);
    }
@@ -1128,7 +1110,6 @@ public class NotificationStackScrollLayout extends ViewGroup
                && !mHeadsUpAnimatingAway;
        if (mIsClipped != clipped) {
            mIsClipped = clipped;
            updateFadingState();
        }

        if (animatingClipping) {
@@ -2447,7 +2428,7 @@ public class NotificationStackScrollLayout extends ViewGroup
                startBackgroundAnimation();
            } else {
                mCurrentBounds.set(mBackgroundBounds);
                applyCurrentBackgroundBounds();
                invalidate();
            }
        } else {
            abortBackgroundAnimators();
@@ -2575,25 +2556,11 @@ public class NotificationStackScrollLayout extends ViewGroup

    private void setBackgroundTop(int top) {
        mCurrentBounds.top = top;
        applyCurrentBackgroundBounds();
        invalidate();
    }

    public void setBackgroundBottom(int bottom) {
        mCurrentBounds.bottom = bottom;
        applyCurrentBackgroundBounds();
    }

    private void applyCurrentBackgroundBounds() {
        // If the background of the notification is not being drawn, then there is no need to
        // exclude an area in the scrim. Rather, the scrim's color should serve as the background.
        if (!mShouldDrawNotificationBackground) {
            return;
        }

        final boolean awake = mInterpolatedDarkAmount != 0 || mAmbientState.isDark();
        mScrimController.setExcludedBackgroundArea(
                mFadingOut || mParentNotFullyVisible || awake || mIsClipped ? null
                        : mCurrentBounds);
        invalidate();
    }

@@ -4176,7 +4143,6 @@ public class NotificationStackScrollLayout extends ViewGroup
            updateBackground();
        }
        requestChildrenUpdate();
        applyCurrentBackgroundBounds();
        updateWillNotDraw();
        notifyHeightChangeListener(mShelf);
    }
@@ -4650,35 +4616,6 @@ public class NotificationStackScrollLayout extends ViewGroup
        }
    }

    public void setFadingOut(boolean fadingOut) {
        if (fadingOut != mFadingOut) {
            mFadingOut = fadingOut;
            updateFadingState();
        }
    }

    public void setParentNotFullyVisible(boolean parentNotFullyVisible) {
        if (mScrimController == null) {
            // we're not set up yet.
            return;
        }
        if (parentNotFullyVisible != mParentNotFullyVisible) {
            mParentNotFullyVisible = parentNotFullyVisible;
            updateFadingState();
        }
    }

    private void updateFadingState() {
        applyCurrentBackgroundBounds();
        updateSrcDrawing();
    }

    @Override
    public void setAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha) {
        super.setAlpha(alpha);
        setFadingOut(alpha != 1.0f);
    }

    public void setQsExpanded(boolean qsExpanded) {
        mQsExpanded = qsExpanded;
        updateAlgorithmLayoutMinHeight();
+0 −34
Original line number Diff line number Diff line
@@ -2668,32 +2668,6 @@ public class NotificationPanelView extends PanelView implements
        setLaunchingAffordance(false);
    }

    @Override
    public void setAlpha(float alpha) {
        super.setAlpha(alpha);
        updateFullyVisibleState(false /* forceNotFullyVisible */);
    }

    /**
     * Must be called before starting a ViewPropertyAnimator alpha animation because those
     * do NOT call setAlpha and therefore don't properly update the fullyVisibleState.
     */
    public void notifyStartFading() {
        updateFullyVisibleState(true /* forceNotFullyVisible */);
    }

    @Override
    public void setVisibility(int visibility) {
        super.setVisibility(visibility);
        updateFullyVisibleState(false /* forceNotFullyVisible */);
    }

    private void updateFullyVisibleState(boolean forceNotFullyVisible) {
        mNotificationStackScroller.setParentNotFullyVisible(forceNotFullyVisible
                || getAlpha() != 1.0f
                || getVisibility() != VISIBLE);
    }

    /**
     * Set whether we are currently launching an affordance. This is currently only set when
     * launched via a camera gesture.
@@ -2992,10 +2966,6 @@ public class NotificationPanelView extends PanelView implements
        mNotificationStackScroller.setActivatedChild(o);
    }

    public void setParentNotFullyVisible(boolean parent) {
        mNotificationStackScroller.setParentNotFullyVisible(parent);
    }

    public void runAfterAnimationFinished(Runnable r) {
        mNotificationStackScroller.runAfterAnimationFinished(r);
    }
@@ -3020,8 +2990,4 @@ public class NotificationPanelView extends PanelView implements
        mNotificationStackScroller.setScrimController(scrimController);
        updateShowEmptyShadeView();
    }

    public void setDrawBackgroundAsSrc(boolean asSrc) {
        mNotificationStackScroller.setDrawBackgroundAsSrc(asSrc);
    }
}
+0 −8
Original line number Diff line number Diff line
@@ -685,10 +685,6 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo
        return scrim.getTag(TAG_KEY_ANIM) != null;
    }

    public void setDrawBehindAsSrc(boolean asSrc) {
        mScrimBehind.setDrawAsSrc(asSrc);
    }

    @VisibleForTesting
    void setOnAnimationFinished(Runnable onAnimationFinished) {
        mOnAnimationFinished = onAnimationFinished;
@@ -800,10 +796,6 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo
        return Handler.getMain();
    }

    public void setExcludedBackgroundArea(Rect area) {
        mScrimBehind.setExcludedArea(area);
    }

    public int getBackgroundColor() {
        int color = mLockColors.getMainColor();
        return Color.argb((int) (mScrimBehind.getViewAlpha() * Color.alpha(color)),
Loading