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

Commit c4d8eb6f authored by Romain Guy's avatar Romain Guy
Browse files

Speedup TextView fades (no more layers required.)

Also fixes a crash in the drop shadows cache and improves
drop shadows caching.

Change-Id: I9c0208a49467f9201d786ae0c129194b8d423923
parent 1b196022
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1729,7 +1729,7 @@ public abstract class Layout {
    private Alignment mAlignment = Alignment.ALIGN_NORMAL;
    private float mSpacingMult;
    private float mSpacingAdd;
    private static Rect sTempRect = new Rect();
    private static final Rect sTempRect = new Rect();
    private boolean mSpannedText;

    public static final int DIR_LEFT_TO_RIGHT = 1;
+18 −0
Original line number Diff line number Diff line
@@ -197,6 +197,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    
    private static final int PRIORITY = 100;

    private int mCurrentAlpha = 255;    
    private ColorStateList mTextColor;
    private int mCurTextColor;
    private ColorStateList mHintTextColor;
@@ -3856,6 +3857,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }
    }

    @Override
    protected boolean onSetAlpha(int alpha) {
        if (mMovement == null && getBackground() == null) {
            mCurrentAlpha = alpha;
            final Drawables dr = mDrawables;
            if (dr != null) {
                if (dr.mDrawableLeft != null) dr.mDrawableLeft.setAlpha(alpha);
                if (dr.mDrawableTop != null) dr.mDrawableTop.setAlpha(alpha);
                if (dr.mDrawableRight != null) dr.mDrawableRight.setAlpha(alpha);
                if (dr.mDrawableBottom != null) dr.mDrawableBottom.setAlpha(alpha);
            }
            return true;
        }
        return false;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        restartMarqueeIfNeeded();
@@ -3953,6 +3970,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }

        mTextPaint.setColor(color);
        mTextPaint.setAlpha(mCurrentAlpha);
        mTextPaint.drawableState = getDrawableState();

        canvas.save();
+19 −9
Original line number Diff line number Diff line
@@ -29,13 +29,18 @@ namespace android {
namespace uirenderer {

struct ShadowText {
    ShadowText() { }
    ShadowText() {
        text = NULL;
    }

    ShadowText(SkPaint* paint, uint32_t radius, uint32_t len, const char* srcText):
            paint(paint), radius(radius), len(len) {
            radius(radius), len(len) {
        text = new char[len];
        memcpy(text, srcText, len);

        textSize = paint->getTextSize();
        typeface = paint->getTypeface();

        hash = 0;
        uint32_t multiplier = 1;
        for (uint32_t i = 0; i < len; i++) {
@@ -46,7 +51,8 @@ struct ShadowText {
    }

    ShadowText(const ShadowText& shadow):
            paint(shadow.paint), radius(shadow.radius), len(shadow.len), hash(shadow.hash) {
            radius(shadow.radius), len(shadow.len), hash(shadow.hash),
            textSize(shadow.textSize), typeface(shadow.typeface) {
        text = new char[shadow.len];
        memcpy(text, shadow.text, shadow.len);
    }
@@ -55,10 +61,11 @@ struct ShadowText {
        delete[] text;
    }

    SkPaint* paint;
    uint32_t radius;
    uint32_t len;
    uint32_t hash;
    float textSize;
    SkTypeface* typeface;
    char *text;

    bool operator<(const ShadowText& rhs) const {
@@ -66,8 +73,10 @@ struct ShadowText {
        else if (len == rhs.len) {
            if (radius < rhs.radius) return true;
            else if (radius == rhs.radius) {
                if (paint < rhs.paint) return true;
                else if (paint == rhs.paint) {
                if (textSize < rhs.textSize) return true;
                else if (textSize == rhs.textSize) {
                    if (typeface < rhs.typeface) return true;
                    else if (typeface == rhs.typeface) {
                        if (hash < rhs.hash) return true;
                        if (hash == rhs.hash) {
                            return strncmp(text, rhs.text, len) < 0;
@@ -75,6 +84,7 @@ struct ShadowText {
                    }
                }
            }
        }
        return false;
    }
}; // struct ShadowText