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

Commit 1373a8eb authored by Christopher Tate's avatar Christopher Tate
Browse files

Localized optimizations in views and bitmaps

* Don't call context.getResources() redundantly when unnecessary;
  similarly for Resources.getCompatibilityInfo()

* During bitmap creation, don't bother clearing to 0: it's unnecessary
  because now that the raw bits are stored in a VM-side byte array, it
  was cleared at initialization time.  Also, don't use the sanity-
  checking public entry point to erase to a color, because we know
  that we're by definition in a "legal" path to erase to the initial
  contents and don't need to incur the overhead of the (inappropriate)
  sanity checking.

Change-Id: Idaca4d64fdecefd5d51337646ead32e1db510e02
parent a3cc20ff
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -129,7 +129,7 @@ public class EdgeEffect {
        mEdge = res.getDrawable(R.drawable.overscroll_edge);
        mEdge = res.getDrawable(R.drawable.overscroll_edge);
        mGlow = res.getDrawable(R.drawable.overscroll_glow);
        mGlow = res.getDrawable(R.drawable.overscroll_glow);


        mMinWidth = (int) (context.getResources().getDisplayMetrics().density * MIN_WIDTH + 0.5f);
        mMinWidth = (int) (res.getDisplayMetrics().density * MIN_WIDTH + 0.5f);
        mInterpolator = new DecelerateInterpolator();
        mInterpolator = new DecelerateInterpolator();
    }
    }


+7 −5
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.content.res.ColorStateList;
import android.content.res.CompatibilityInfo;
import android.content.res.Resources;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.content.res.XmlResourceParser;
@@ -449,18 +450,19 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        super(context, attrs, defStyle);
        super(context, attrs, defStyle);
        mText = "";
        mText = "";


        final Resources res = getResources();
        final CompatibilityInfo compat = res.getCompatibilityInfo();

        mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        mTextPaint.density = getResources().getDisplayMetrics().density;
        mTextPaint.density = res.getDisplayMetrics().density;
        mTextPaint.setCompatibilityScaling(
        mTextPaint.setCompatibilityScaling(compat.applicationScale);
                getResources().getCompatibilityInfo().applicationScale);


        // If we get the paint from the skin, we should set it to left, since
        // If we get the paint from the skin, we should set it to left, since
        // the layout always wants it to be left.
        // the layout always wants it to be left.
        // mTextPaint.setTextAlign(Paint.Align.LEFT);
        // mTextPaint.setTextAlign(Paint.Align.LEFT);


        mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mHighlightPaint.setCompatibilityScaling(
        mHighlightPaint.setCompatibilityScaling(compat.applicationScale);
                getResources().getCompatibilityInfo().applicationScale);


        mMovement = getDefaultMovementMethod();
        mMovement = getDefaultMovementMethod();
        mTransformation = null;
        mTransformation = null;
+5 −2
Original line number Original line Diff line number Diff line
@@ -604,10 +604,13 @@ public final class Bitmap implements Parcelable {
        }
        }
        Bitmap bm = nativeCreate(null, 0, width, width, height, config.nativeInt, true);
        Bitmap bm = nativeCreate(null, 0, width, width, height, config.nativeInt, true);
        if (config == Config.ARGB_8888 && !hasAlpha) {
        if (config == Config.ARGB_8888 && !hasAlpha) {
            bm.eraseColor(0xff000000);
            nativeErase(bm.mNativeBitmap, 0xff000000);
            nativeSetHasAlpha(bm.mNativeBitmap, hasAlpha);
            nativeSetHasAlpha(bm.mNativeBitmap, hasAlpha);
        } else {
        } else {
            bm.eraseColor(0);
            // No need to initialize it to zeroes; it is backed by a VM byte array
            // which is by definition preinitialized to all zeroes.
            //
            //nativeErase(bm.mNativeBitmap, 0);
        }
        }
        return bm;
        return bm;
    }
    }