summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Tate <ctate@google.com>2011-11-10 19:59:13 -0800
committerChristopher Tate <ctate@google.com>2011-11-11 12:46:48 -0800
commit1373a8eb581fe3c8e9a036e69042015f98a7e346 (patch)
tree0f71cda77b7f24614a90b6ed428788f2cf8a85a0
parenta3cc20fff073bd3ca588f1e61f0f7034aecf3ebb (diff)
downloadframeworks_base-1373a8eb581fe3c8e9a036e69042015f98a7e346.zip
frameworks_base-1373a8eb581fe3c8e9a036e69042015f98a7e346.tar.gz
frameworks_base-1373a8eb581fe3c8e9a036e69042015f98a7e346.tar.bz2
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
-rw-r--r--core/java/android/widget/EdgeEffect.java2
-rw-r--r--core/java/android/widget/TextView.java12
-rw-r--r--graphics/java/android/graphics/Bitmap.java7
3 files changed, 13 insertions, 8 deletions
diff --git a/core/java/android/widget/EdgeEffect.java b/core/java/android/widget/EdgeEffect.java
index fd2abc2..326587e 100644
--- a/core/java/android/widget/EdgeEffect.java
+++ b/core/java/android/widget/EdgeEffect.java
@@ -129,7 +129,7 @@ public class EdgeEffect {
mEdge = res.getDrawable(R.drawable.overscroll_edge);
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();
}
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index bc8721a..b106cc5 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -24,6 +24,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
+import android.content.res.CompatibilityInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
@@ -449,18 +450,19 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
super(context, attrs, defStyle);
mText = "";
+ final Resources res = getResources();
+ final CompatibilityInfo compat = res.getCompatibilityInfo();
+
mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
- mTextPaint.density = getResources().getDisplayMetrics().density;
- mTextPaint.setCompatibilityScaling(
- getResources().getCompatibilityInfo().applicationScale);
+ mTextPaint.density = res.getDisplayMetrics().density;
+ mTextPaint.setCompatibilityScaling(compat.applicationScale);
// If we get the paint from the skin, we should set it to left, since
// the layout always wants it to be left.
// mTextPaint.setTextAlign(Paint.Align.LEFT);
mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
- mHighlightPaint.setCompatibilityScaling(
- getResources().getCompatibilityInfo().applicationScale);
+ mHighlightPaint.setCompatibilityScaling(compat.applicationScale);
mMovement = getDefaultMovementMethod();
mTransformation = null;
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index 79acd55..380b3d8 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -604,10 +604,13 @@ public final class Bitmap implements Parcelable {
}
Bitmap bm = nativeCreate(null, 0, width, width, height, config.nativeInt, true);
if (config == Config.ARGB_8888 && !hasAlpha) {
- bm.eraseColor(0xff000000);
+ nativeErase(bm.mNativeBitmap, 0xff000000);
nativeSetHasAlpha(bm.mNativeBitmap, hasAlpha);
} 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;
}