am b9c4cccf: Merge "Reduce the amount of allocations on Paint_Delegate" into mnc-ub-dev

* commit 'b9c4cccf672d725e75d393c492c917ba726c365c':
  Reduce the amount of allocations on Paint_Delegate
This commit is contained in:
Diego Perez
2015-09-30 09:34:45 +00:00
committed by Android Git Automerger
2 changed files with 61 additions and 19 deletions

View File

@@ -178,7 +178,9 @@ public class FontFamily_Delegate {
desiredStyle.mIsItalic = isItalic;
FontInfo bestFont = null;
int bestMatch = Integer.MAX_VALUE;
for (FontInfo font : mFonts) {
//noinspection ForLoopReplaceableByForEach (avoid iterator instantiation)
for (int i = 0, n = mFonts.size(); i < n; i++) {
FontInfo font = mFonts.get(i);
int match = computeMatch(font, desiredStyle);
if (match < bestMatch) {
bestMatch = match;
@@ -415,7 +417,9 @@ public class FontFamily_Delegate {
boolean isItalic = fontInfo.mIsItalic;
// The list is usually just two fonts big. So iterating over all isn't as bad as it looks.
// It's biggest for roboto where the size is 12.
for (FontInfo font : mFonts) {
//noinspection ForLoopReplaceableByForEach (avoid iterator instantiation)
for (int i = 0, n = mFonts.size(); i < n; i++) {
FontInfo font = mFonts.get(i);
if (font.mWeight == weight && font.mIsItalic == isItalic) {
return false;
}

View File

@@ -480,8 +480,10 @@ public class Paint_Delegate {
return;
}
delegate.mTextSize = textSize;
delegate.updateFontObject();
if (delegate.mTextSize != textSize) {
delegate.mTextSize = textSize;
delegate.updateFontObject();
}
}
@LayoutlibDelegate
@@ -503,8 +505,10 @@ public class Paint_Delegate {
return;
}
delegate.mTextScaleX = scaleX;
delegate.updateFontObject();
if (delegate.mTextScaleX != scaleX) {
delegate.mTextScaleX = scaleX;
delegate.updateFontObject();
}
}
@LayoutlibDelegate
@@ -526,8 +530,10 @@ public class Paint_Delegate {
return;
}
delegate.mTextSkewX = skewX;
delegate.updateFontObject();
if (delegate.mTextSkewX != skewX) {
delegate.mTextSkewX = skewX;
delegate.updateFontObject();
}
}
@LayoutlibDelegate
@@ -897,9 +903,12 @@ public class Paint_Delegate {
return 0;
}
delegate.mTypeface = Typeface_Delegate.getDelegate(typeface);
delegate.mNativeTypeface = typeface;
delegate.updateFontObject();
Typeface_Delegate typefaceDelegate = Typeface_Delegate.getDelegate(typeface);
if (delegate.mTypeface != typefaceDelegate || delegate.mNativeTypeface != typeface) {
delegate.mTypeface = Typeface_Delegate.getDelegate(typeface);
delegate.mNativeTypeface = typeface;
delegate.updateFontObject();
}
return typeface;
}
@@ -1214,13 +1223,31 @@ public class Paint_Delegate {
mCap = paint.mCap;
mJoin = paint.mJoin;
mTextAlign = paint.mTextAlign;
mTypeface = paint.mTypeface;
mNativeTypeface = paint.mNativeTypeface;
boolean needsFontUpdate = false;
if (mTypeface != paint.mTypeface || mNativeTypeface != paint.mNativeTypeface) {
mTypeface = paint.mTypeface;
mNativeTypeface = paint.mNativeTypeface;
needsFontUpdate = true;
}
if (mTextSize != paint.mTextSize) {
mTextSize = paint.mTextSize;
needsFontUpdate = true;
}
if (mTextScaleX != paint.mTextScaleX) {
mTextScaleX = paint.mTextScaleX;
needsFontUpdate = true;
}
if (mTextSkewX != paint.mTextSkewX) {
mTextSkewX = paint.mTextSkewX;
needsFontUpdate = true;
}
mStrokeWidth = paint.mStrokeWidth;
mStrokeMiter = paint.mStrokeMiter;
mTextSize = paint.mTextSize;
mTextScaleX = paint.mTextScaleX;
mTextSkewX = paint.mTextSkewX;
mXfermode = paint.mXfermode;
mColorFilter = paint.mColorFilter;
mShader = paint.mShader;
@@ -1228,7 +1255,10 @@ public class Paint_Delegate {
mMaskFilter = paint.mMaskFilter;
mRasterizer = paint.mRasterizer;
mHintingMode = paint.mHintingMode;
updateFontObject();
if (needsFontUpdate) {
updateFontObject();
}
}
private void reset() {
@@ -1264,10 +1294,18 @@ public class Paint_Delegate {
// Get the fonts from the TypeFace object.
List<Font> fonts = mTypeface.getFonts(mFontVariant);
if (fonts.isEmpty()) {
mFonts = Collections.emptyList();
return;
}
// create new font objects as well as FontMetrics, based on the current text size
// and skew info.
ArrayList<FontInfo> infoList = new ArrayList<FontInfo>(fonts.size());
for (Font font : fonts) {
int nFonts = fonts.size();
ArrayList<FontInfo> infoList = new ArrayList<FontInfo>(nFonts);
//noinspection ForLoopReplaceableByForEach (avoid iterator instantiation)
for (int i = 0; i < nFonts; i++) {
Font font = fonts.get(i);
if (font == null) {
// If the font is null, add null to infoList. When rendering the text, if this
// null is reached, a warning will be logged.