Loading core/java/android/content/res/AssetManager.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -815,9 +815,9 @@ public final class AssetManager implements AutoCloseable { /*package*/ static final int STYLE_DENSITY = 5; /*package*/ static final int STYLE_DENSITY = 5; @FastNative @FastNative /*package*/ native static final boolean applyStyle(long theme, /*package*/ native static final void applyStyle(long theme, int defStyleAttr, int defStyleRes, long xmlParser, int defStyleAttr, int defStyleRes, long xmlParser, int[] inAttrs, int[] outValues, int[] outIndices); int[] inAttrs, int length, long outValuesAddress, long outIndicesAddress); @FastNative @FastNative /*package*/ native static final boolean resolveAttrs(long theme, /*package*/ native static final boolean resolveAttrs(long theme, int defStyleAttr, int defStyleRes, int[] inValues, int defStyleAttr, int defStyleRes, int[] inValues, Loading core/java/android/content/res/ResourcesImpl.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -1126,7 +1126,7 @@ public class ResourcesImpl { final XmlBlock.Parser parser = (XmlBlock.Parser) set; final XmlBlock.Parser parser = (XmlBlock.Parser) set; AssetManager.applyStyle(mTheme, defStyleAttr, defStyleRes, AssetManager.applyStyle(mTheme, defStyleAttr, defStyleRes, parser != null ? parser.mParseState : 0, parser != null ? parser.mParseState : 0, attrs, array.mData, array.mIndices); attrs, attrs.length, array.mDataAddress, array.mIndicesAddress); array.mTheme = wrapper; array.mTheme = wrapper; array.mXml = parser; array.mXml = parser; Loading core/java/android/content/res/TypedArray.java +28 −24 Original line number Original line Diff line number Diff line Loading @@ -30,6 +30,8 @@ import android.util.TypedValue; import com.android.internal.util.XmlUtils; import com.android.internal.util.XmlUtils; import dalvik.system.VMRuntime; import java.util.Arrays; import java.util.Arrays; /** /** Loading @@ -44,30 +46,19 @@ import java.util.Arrays; public class TypedArray { public class TypedArray { static TypedArray obtain(Resources res, int len) { static TypedArray obtain(Resources res, int len) { final TypedArray attrs = res.mTypedArrayPool.acquire(); TypedArray attrs = res.mTypedArrayPool.acquire(); if (attrs != null) { if (attrs == null) { attrs.mLength = len; attrs = new TypedArray(res); attrs.mRecycled = false; } attrs.mRecycled = false; // Reset the assets, which may have changed due to configuration changes // Reset the assets, which may have changed due to configuration changes // or further resource loading. // or further resource loading. attrs.mAssets = res.getAssets(); attrs.mAssets = res.getAssets(); attrs.resize(len); final int fullLen = len * AssetManager.STYLE_NUM_ENTRIES; if (attrs.mData.length >= fullLen) { return attrs; } attrs.mData = new int[fullLen]; attrs.mIndices = new int[1 + len]; return attrs; return attrs; } } return new TypedArray(res, new int[len*AssetManager.STYLE_NUM_ENTRIES], new int[1+len], len); } private final Resources mResources; private final Resources mResources; private final DisplayMetrics mMetrics; private final DisplayMetrics mMetrics; private AssetManager mAssets; private AssetManager mAssets; Loading @@ -77,10 +68,25 @@ public class TypedArray { /*package*/ XmlBlock.Parser mXml; /*package*/ XmlBlock.Parser mXml; /*package*/ Resources.Theme mTheme; /*package*/ Resources.Theme mTheme; /*package*/ int[] mData; /*package*/ int[] mData; /*package*/ long mDataAddress; /*package*/ int[] mIndices; /*package*/ int[] mIndices; /*package*/ long mIndicesAddress; /*package*/ int mLength; /*package*/ int mLength; /*package*/ TypedValue mValue = new TypedValue(); /*package*/ TypedValue mValue = new TypedValue(); private void resize(int len) { mLength = len; final int dataLen = len * AssetManager.STYLE_NUM_ENTRIES; final int indicesLen = len + 1; final VMRuntime runtime = VMRuntime.getRuntime(); if (mData == null || mData.length < dataLen) { mData = (int[]) runtime.newNonMovableArray(int.class, dataLen); mDataAddress = runtime.addressOf(mData); mIndices = (int[]) runtime.newNonMovableArray(int.class, indicesLen); mIndicesAddress = runtime.addressOf(mIndices); } } /** /** * Returns the number of values in this array. * Returns the number of values in this array. * * Loading Loading @@ -1217,13 +1223,11 @@ public class TypedArray { return mAssets.getPooledStringForCookie(cookie, data[index+AssetManager.STYLE_DATA]); return mAssets.getPooledStringForCookie(cookie, data[index+AssetManager.STYLE_DATA]); } } /*package*/ TypedArray(Resources resources, int[] data, int[] indices, int len) { /** @hide */ protected TypedArray(Resources resources) { mResources = resources; mResources = resources; mMetrics = mResources.getDisplayMetrics(); mMetrics = mResources.getDisplayMetrics(); mAssets = mResources.getAssets(); mAssets = mResources.getAssets(); mData = data; mIndices = indices; mLength = len; } } @Override @Override Loading core/jni/android_util_AssetManager.cpp +10 −60 Original line number Original line Diff line number Diff line Loading @@ -1179,67 +1179,17 @@ static jboolean android_content_AssetManager_resolveAttrs(JNIEnv* env, jobject c return result ? JNI_TRUE : JNI_FALSE; return result ? JNI_TRUE : JNI_FALSE; } } static jboolean android_content_AssetManager_applyStyle(JNIEnv* env, jobject clazz, static void android_content_AssetManager_applyStyle(JNIEnv* env, jobject, jlong themeToken, jlong themeToken, jint defStyleAttr, jint defStyleRes, jlong xmlParserToken, jintArray attrsObj, jint length, jint defStyleAttr, jlong outValuesAddress, jlong outIndicesAddress) { jint defStyleRes, jint* attrs = env->GetIntArrayElements(attrsObj, 0); jlong xmlParserToken, jintArray attrs, jintArray outValues, jintArray outIndices) { if (themeToken == 0) { jniThrowNullPointerException(env, "theme token"); return JNI_FALSE; } if (attrs == NULL) { jniThrowNullPointerException(env, "attrs"); return JNI_FALSE; } if (outValues == NULL) { jniThrowNullPointerException(env, "out values"); return JNI_FALSE; } const jsize NI = env->GetArrayLength(attrs); const jsize NV = env->GetArrayLength(outValues); if (NV < (NI*STYLE_NUM_ENTRIES)) { jniThrowException(env, "java/lang/IndexOutOfBoundsException", "out values too small"); return JNI_FALSE; } jint* src = (jint*)env->GetPrimitiveArrayCritical(attrs, 0); if (src == NULL) { return JNI_FALSE; } jint* baseDest = (jint*)env->GetPrimitiveArrayCritical(outValues, 0); if (baseDest == NULL) { env->ReleasePrimitiveArrayCritical(attrs, src, 0); return JNI_FALSE; } jint* indices = NULL; if (outIndices != NULL) { if (env->GetArrayLength(outIndices) > NI) { indices = (jint*)env->GetPrimitiveArrayCritical(outIndices, 0); } } ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeToken); ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeToken); ResXMLParser* xmlParser = reinterpret_cast<ResXMLParser*>(xmlParserToken); ResXMLParser* xmlParser = reinterpret_cast<ResXMLParser*>(xmlParserToken); bool result = ApplyStyle(theme, xmlParser, uint32_t* outValues = reinterpret_cast<uint32_t*>(static_cast<uintptr_t>(outValuesAddress)); defStyleAttr, defStyleRes, uint32_t* outIndices = reinterpret_cast<uint32_t*>(static_cast<uintptr_t>(outIndicesAddress)); (uint32_t*) src, NI, ApplyStyle(theme, xmlParser, defStyleAttr, defStyleRes, (uint32_t*) baseDest, reinterpret_cast<const uint32_t*>(attrs), length, outValues, outIndices); (uint32_t*) indices); env->ReleaseIntArrayElements(attrsObj, attrs, JNI_ABORT); if (indices != NULL) { env->ReleasePrimitiveArrayCritical(outIndices, indices, 0); } env->ReleasePrimitiveArrayCritical(outValues, baseDest, 0); env->ReleasePrimitiveArrayCritical(attrs, src, 0); return result ? JNI_TRUE : JNI_FALSE; } } static jboolean android_content_AssetManager_retrieveAttributes(JNIEnv* env, jobject clazz, static jboolean android_content_AssetManager_retrieveAttributes(JNIEnv* env, jobject clazz, Loading Loading @@ -1795,7 +1745,7 @@ static const JNINativeMethod gAssetManagerMethods[] = { { "dumpTheme", "(JILjava/lang/String;Ljava/lang/String;)V", { "dumpTheme", "(JILjava/lang/String;Ljava/lang/String;)V", (void*) android_content_AssetManager_dumpTheme }, (void*) android_content_AssetManager_dumpTheme }, // @FastNative // @FastNative { "applyStyle","(JIIJ[I[I[I)Z", { "applyStyle","(JIIJ[IIJJ)V", (void*) android_content_AssetManager_applyStyle }, (void*) android_content_AssetManager_applyStyle }, // @FastNative // @FastNative { "resolveAttrs","(JII[I[I[I[I)Z", { "resolveAttrs","(JII[I[I[I[I)Z", Loading libs/androidfw/AttributeResolution.cpp +5 −8 Original line number Original line Diff line number Diff line Loading @@ -193,9 +193,9 @@ bool ResolveAttrs(ResTable::Theme* theme, uint32_t def_style_attr, uint32_t def_ return true; return true; } } bool ApplyStyle(ResTable::Theme* theme, ResXMLParser* xml_parser, uint32_t def_style_attr, void ApplyStyle(ResTable::Theme* theme, ResXMLParser* xml_parser, uint32_t def_style_attr, uint32_t def_style_res, uint32_t* attrs, size_t attrs_length, uint32_t* out_values, uint32_t def_style_res, const uint32_t* attrs, size_t attrs_length, uint32_t* out_indices) { uint32_t* out_values, uint32_t* out_indices) { if (kDebugStyles) { if (kDebugStyles) { ALOGI("APPLY STYLE: theme=0x%p defStyleAttr=0x%x defStyleRes=0x%x xml=0x%p", theme, ALOGI("APPLY STYLE: theme=0x%p defStyleAttr=0x%x defStyleRes=0x%x xml=0x%p", theme, def_style_attr, def_style_res, xml_parser); def_style_attr, def_style_res, xml_parser); Loading Loading @@ -376,7 +376,7 @@ bool ApplyStyle(ResTable::Theme* theme, ResXMLParser* xml_parser, uint32_t def_s out_values[STYLE_CHANGING_CONFIGURATIONS] = type_set_flags; out_values[STYLE_CHANGING_CONFIGURATIONS] = type_set_flags; out_values[STYLE_DENSITY] = config.density; out_values[STYLE_DENSITY] = config.density; if (out_indices != NULL && value.dataType != Res_value::TYPE_NULL) { if (value.dataType != Res_value::TYPE_NULL) { indices_idx++; indices_idx++; out_indices[indices_idx] = ii; out_indices[indices_idx] = ii; } } Loading @@ -386,11 +386,8 @@ bool ApplyStyle(ResTable::Theme* theme, ResXMLParser* xml_parser, uint32_t def_s res.unlock(); res.unlock(); if (out_indices != NULL) { out_indices[0] = indices_idx; out_indices[0] = indices_idx; } } return true; } bool RetrieveAttributes(const ResTable* res, ResXMLParser* xml_parser, uint32_t* attrs, bool RetrieveAttributes(const ResTable* res, ResXMLParser* xml_parser, uint32_t* attrs, size_t attrs_length, uint32_t* out_values, uint32_t* out_indices) { size_t attrs_length, uint32_t* out_values, uint32_t* out_indices) { Loading Loading
core/java/android/content/res/AssetManager.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -815,9 +815,9 @@ public final class AssetManager implements AutoCloseable { /*package*/ static final int STYLE_DENSITY = 5; /*package*/ static final int STYLE_DENSITY = 5; @FastNative @FastNative /*package*/ native static final boolean applyStyle(long theme, /*package*/ native static final void applyStyle(long theme, int defStyleAttr, int defStyleRes, long xmlParser, int defStyleAttr, int defStyleRes, long xmlParser, int[] inAttrs, int[] outValues, int[] outIndices); int[] inAttrs, int length, long outValuesAddress, long outIndicesAddress); @FastNative @FastNative /*package*/ native static final boolean resolveAttrs(long theme, /*package*/ native static final boolean resolveAttrs(long theme, int defStyleAttr, int defStyleRes, int[] inValues, int defStyleAttr, int defStyleRes, int[] inValues, Loading
core/java/android/content/res/ResourcesImpl.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -1126,7 +1126,7 @@ public class ResourcesImpl { final XmlBlock.Parser parser = (XmlBlock.Parser) set; final XmlBlock.Parser parser = (XmlBlock.Parser) set; AssetManager.applyStyle(mTheme, defStyleAttr, defStyleRes, AssetManager.applyStyle(mTheme, defStyleAttr, defStyleRes, parser != null ? parser.mParseState : 0, parser != null ? parser.mParseState : 0, attrs, array.mData, array.mIndices); attrs, attrs.length, array.mDataAddress, array.mIndicesAddress); array.mTheme = wrapper; array.mTheme = wrapper; array.mXml = parser; array.mXml = parser; Loading
core/java/android/content/res/TypedArray.java +28 −24 Original line number Original line Diff line number Diff line Loading @@ -30,6 +30,8 @@ import android.util.TypedValue; import com.android.internal.util.XmlUtils; import com.android.internal.util.XmlUtils; import dalvik.system.VMRuntime; import java.util.Arrays; import java.util.Arrays; /** /** Loading @@ -44,30 +46,19 @@ import java.util.Arrays; public class TypedArray { public class TypedArray { static TypedArray obtain(Resources res, int len) { static TypedArray obtain(Resources res, int len) { final TypedArray attrs = res.mTypedArrayPool.acquire(); TypedArray attrs = res.mTypedArrayPool.acquire(); if (attrs != null) { if (attrs == null) { attrs.mLength = len; attrs = new TypedArray(res); attrs.mRecycled = false; } attrs.mRecycled = false; // Reset the assets, which may have changed due to configuration changes // Reset the assets, which may have changed due to configuration changes // or further resource loading. // or further resource loading. attrs.mAssets = res.getAssets(); attrs.mAssets = res.getAssets(); attrs.resize(len); final int fullLen = len * AssetManager.STYLE_NUM_ENTRIES; if (attrs.mData.length >= fullLen) { return attrs; } attrs.mData = new int[fullLen]; attrs.mIndices = new int[1 + len]; return attrs; return attrs; } } return new TypedArray(res, new int[len*AssetManager.STYLE_NUM_ENTRIES], new int[1+len], len); } private final Resources mResources; private final Resources mResources; private final DisplayMetrics mMetrics; private final DisplayMetrics mMetrics; private AssetManager mAssets; private AssetManager mAssets; Loading @@ -77,10 +68,25 @@ public class TypedArray { /*package*/ XmlBlock.Parser mXml; /*package*/ XmlBlock.Parser mXml; /*package*/ Resources.Theme mTheme; /*package*/ Resources.Theme mTheme; /*package*/ int[] mData; /*package*/ int[] mData; /*package*/ long mDataAddress; /*package*/ int[] mIndices; /*package*/ int[] mIndices; /*package*/ long mIndicesAddress; /*package*/ int mLength; /*package*/ int mLength; /*package*/ TypedValue mValue = new TypedValue(); /*package*/ TypedValue mValue = new TypedValue(); private void resize(int len) { mLength = len; final int dataLen = len * AssetManager.STYLE_NUM_ENTRIES; final int indicesLen = len + 1; final VMRuntime runtime = VMRuntime.getRuntime(); if (mData == null || mData.length < dataLen) { mData = (int[]) runtime.newNonMovableArray(int.class, dataLen); mDataAddress = runtime.addressOf(mData); mIndices = (int[]) runtime.newNonMovableArray(int.class, indicesLen); mIndicesAddress = runtime.addressOf(mIndices); } } /** /** * Returns the number of values in this array. * Returns the number of values in this array. * * Loading Loading @@ -1217,13 +1223,11 @@ public class TypedArray { return mAssets.getPooledStringForCookie(cookie, data[index+AssetManager.STYLE_DATA]); return mAssets.getPooledStringForCookie(cookie, data[index+AssetManager.STYLE_DATA]); } } /*package*/ TypedArray(Resources resources, int[] data, int[] indices, int len) { /** @hide */ protected TypedArray(Resources resources) { mResources = resources; mResources = resources; mMetrics = mResources.getDisplayMetrics(); mMetrics = mResources.getDisplayMetrics(); mAssets = mResources.getAssets(); mAssets = mResources.getAssets(); mData = data; mIndices = indices; mLength = len; } } @Override @Override Loading
core/jni/android_util_AssetManager.cpp +10 −60 Original line number Original line Diff line number Diff line Loading @@ -1179,67 +1179,17 @@ static jboolean android_content_AssetManager_resolveAttrs(JNIEnv* env, jobject c return result ? JNI_TRUE : JNI_FALSE; return result ? JNI_TRUE : JNI_FALSE; } } static jboolean android_content_AssetManager_applyStyle(JNIEnv* env, jobject clazz, static void android_content_AssetManager_applyStyle(JNIEnv* env, jobject, jlong themeToken, jlong themeToken, jint defStyleAttr, jint defStyleRes, jlong xmlParserToken, jintArray attrsObj, jint length, jint defStyleAttr, jlong outValuesAddress, jlong outIndicesAddress) { jint defStyleRes, jint* attrs = env->GetIntArrayElements(attrsObj, 0); jlong xmlParserToken, jintArray attrs, jintArray outValues, jintArray outIndices) { if (themeToken == 0) { jniThrowNullPointerException(env, "theme token"); return JNI_FALSE; } if (attrs == NULL) { jniThrowNullPointerException(env, "attrs"); return JNI_FALSE; } if (outValues == NULL) { jniThrowNullPointerException(env, "out values"); return JNI_FALSE; } const jsize NI = env->GetArrayLength(attrs); const jsize NV = env->GetArrayLength(outValues); if (NV < (NI*STYLE_NUM_ENTRIES)) { jniThrowException(env, "java/lang/IndexOutOfBoundsException", "out values too small"); return JNI_FALSE; } jint* src = (jint*)env->GetPrimitiveArrayCritical(attrs, 0); if (src == NULL) { return JNI_FALSE; } jint* baseDest = (jint*)env->GetPrimitiveArrayCritical(outValues, 0); if (baseDest == NULL) { env->ReleasePrimitiveArrayCritical(attrs, src, 0); return JNI_FALSE; } jint* indices = NULL; if (outIndices != NULL) { if (env->GetArrayLength(outIndices) > NI) { indices = (jint*)env->GetPrimitiveArrayCritical(outIndices, 0); } } ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeToken); ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeToken); ResXMLParser* xmlParser = reinterpret_cast<ResXMLParser*>(xmlParserToken); ResXMLParser* xmlParser = reinterpret_cast<ResXMLParser*>(xmlParserToken); bool result = ApplyStyle(theme, xmlParser, uint32_t* outValues = reinterpret_cast<uint32_t*>(static_cast<uintptr_t>(outValuesAddress)); defStyleAttr, defStyleRes, uint32_t* outIndices = reinterpret_cast<uint32_t*>(static_cast<uintptr_t>(outIndicesAddress)); (uint32_t*) src, NI, ApplyStyle(theme, xmlParser, defStyleAttr, defStyleRes, (uint32_t*) baseDest, reinterpret_cast<const uint32_t*>(attrs), length, outValues, outIndices); (uint32_t*) indices); env->ReleaseIntArrayElements(attrsObj, attrs, JNI_ABORT); if (indices != NULL) { env->ReleasePrimitiveArrayCritical(outIndices, indices, 0); } env->ReleasePrimitiveArrayCritical(outValues, baseDest, 0); env->ReleasePrimitiveArrayCritical(attrs, src, 0); return result ? JNI_TRUE : JNI_FALSE; } } static jboolean android_content_AssetManager_retrieveAttributes(JNIEnv* env, jobject clazz, static jboolean android_content_AssetManager_retrieveAttributes(JNIEnv* env, jobject clazz, Loading Loading @@ -1795,7 +1745,7 @@ static const JNINativeMethod gAssetManagerMethods[] = { { "dumpTheme", "(JILjava/lang/String;Ljava/lang/String;)V", { "dumpTheme", "(JILjava/lang/String;Ljava/lang/String;)V", (void*) android_content_AssetManager_dumpTheme }, (void*) android_content_AssetManager_dumpTheme }, // @FastNative // @FastNative { "applyStyle","(JIIJ[I[I[I)Z", { "applyStyle","(JIIJ[IIJJ)V", (void*) android_content_AssetManager_applyStyle }, (void*) android_content_AssetManager_applyStyle }, // @FastNative // @FastNative { "resolveAttrs","(JII[I[I[I[I)Z", { "resolveAttrs","(JII[I[I[I[I)Z", Loading
libs/androidfw/AttributeResolution.cpp +5 −8 Original line number Original line Diff line number Diff line Loading @@ -193,9 +193,9 @@ bool ResolveAttrs(ResTable::Theme* theme, uint32_t def_style_attr, uint32_t def_ return true; return true; } } bool ApplyStyle(ResTable::Theme* theme, ResXMLParser* xml_parser, uint32_t def_style_attr, void ApplyStyle(ResTable::Theme* theme, ResXMLParser* xml_parser, uint32_t def_style_attr, uint32_t def_style_res, uint32_t* attrs, size_t attrs_length, uint32_t* out_values, uint32_t def_style_res, const uint32_t* attrs, size_t attrs_length, uint32_t* out_indices) { uint32_t* out_values, uint32_t* out_indices) { if (kDebugStyles) { if (kDebugStyles) { ALOGI("APPLY STYLE: theme=0x%p defStyleAttr=0x%x defStyleRes=0x%x xml=0x%p", theme, ALOGI("APPLY STYLE: theme=0x%p defStyleAttr=0x%x defStyleRes=0x%x xml=0x%p", theme, def_style_attr, def_style_res, xml_parser); def_style_attr, def_style_res, xml_parser); Loading Loading @@ -376,7 +376,7 @@ bool ApplyStyle(ResTable::Theme* theme, ResXMLParser* xml_parser, uint32_t def_s out_values[STYLE_CHANGING_CONFIGURATIONS] = type_set_flags; out_values[STYLE_CHANGING_CONFIGURATIONS] = type_set_flags; out_values[STYLE_DENSITY] = config.density; out_values[STYLE_DENSITY] = config.density; if (out_indices != NULL && value.dataType != Res_value::TYPE_NULL) { if (value.dataType != Res_value::TYPE_NULL) { indices_idx++; indices_idx++; out_indices[indices_idx] = ii; out_indices[indices_idx] = ii; } } Loading @@ -386,11 +386,8 @@ bool ApplyStyle(ResTable::Theme* theme, ResXMLParser* xml_parser, uint32_t def_s res.unlock(); res.unlock(); if (out_indices != NULL) { out_indices[0] = indices_idx; out_indices[0] = indices_idx; } } return true; } bool RetrieveAttributes(const ResTable* res, ResXMLParser* xml_parser, uint32_t* attrs, bool RetrieveAttributes(const ResTable* res, ResXMLParser* xml_parser, uint32_t* attrs, size_t attrs_length, uint32_t* out_values, uint32_t* out_indices) { size_t attrs_length, uint32_t* out_values, uint32_t* out_indices) { Loading