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

Commit 0b658664 authored by Michael Jurka's avatar Michael Jurka
Browse files

Speeding up System UI pressed anim

No longer saving a layer in KeyButtonView.onDraw,
which prevents a framebuffer readback on some
drivers and cuts ~3ms from render time per frame
(on some frames, up to ~10ms)

Change-Id: I5df56c20098f35c8ae6c25e76c67d81e9b72d1f7
parent 81754949
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ public class KeyButtonView extends ImageView {

        mGlowBG = a.getDrawable(R.styleable.KeyButtonView_glowBackground);
        if (mGlowBG != null) {
            mDrawingAlpha = BUTTON_QUIESCENT_ALPHA;
            setDrawingAlpha(BUTTON_QUIESCENT_ALPHA);
        }
        
        a.recycle();
@@ -107,17 +107,13 @@ public class KeyButtonView extends ImageView {
            final int h = getHeight();
            canvas.scale(mGlowScale, mGlowScale, w*0.5f, h*0.5f);
            mGlowBG.setBounds(0, 0, w, h);
            mGlowBG.setAlpha((int)(mGlowAlpha * 255));
            mGlowBG.setAlpha((int)(mDrawingAlpha * mGlowAlpha * 255));
            mGlowBG.draw(canvas);
            canvas.restore();
            mRect.right = w;
            mRect.bottom = h;
            canvas.saveLayerAlpha(mRect, (int)(mDrawingAlpha * 255), Canvas.ALL_SAVE_FLAG);
        }
        super.onDraw(canvas);
        if (mGlowBG != null) {
            canvas.restore();
        }
    }

    public float getDrawingAlpha() {
@@ -127,8 +123,11 @@ public class KeyButtonView extends ImageView {

    public void setDrawingAlpha(float x) {
        if (mGlowBG == null) return;
        // Calling setAlpha(int), which is an ImageView-specific
        // method that's different from setAlpha(float). This sets
        // the alpha on this ImageView's drawable directly
        setAlpha((int) (x * 255));
        mDrawingAlpha = x;
        invalidate();
    }

    public float getGlowAlpha() {