diff options
author | Xavier Ducrohet <xav@android.com> | 2010-11-18 18:24:51 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2010-11-18 18:26:55 -0800 |
commit | 5a09488a158b669577cd8eb557ce4feb62929e75 (patch) | |
tree | 3a689ddcd6c066318991273f98f61c1db674daaf /tools/layoutlib/bridge | |
parent | 3c68f2b386e5bab9b879e02ec7cdd8ff0c123235 (diff) | |
download | frameworks_base-5a09488a158b669577cd8eb557ce4feb62929e75.zip frameworks_base-5a09488a158b669577cd8eb557ce4feb62929e75.tar.gz frameworks_base-5a09488a158b669577cd8eb557ce4feb62929e75.tar.bz2 |
Layoutlib: Properly dispose of bitmap delegate.
This is done by initializing the android.util.Finalizers that's
reponsible for calling out to the native bitmap destructor.
Also implemented the native bitmap destructor
Also fix Bridge by removing obsolete API methods, and removing
some unneeded synchronized blocks now that the whole rendering
(and scene creation) is protected by a synchronized on the bridge
object anyway.
Change-Id: Ie1792da6db354836542dfc11f457fe4a6d78ddfb
Diffstat (limited to 'tools/layoutlib/bridge')
3 files changed, 16 insertions, 91 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java index 392462f..0920497 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java @@ -162,8 +162,7 @@ public class Bitmap_Delegate { } /*package*/ static void nativeDestructor(int nativeBitmap) { - // FIXME implement native delegate - throw new UnsupportedOperationException("Native delegate needed for Bitmap"); + sManager.removeDelegate(nativeBitmap); } /*package*/ static void nativeRecycle(int nativeBitmap) { diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java index 53da2ca..efa0f27 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java @@ -32,6 +32,7 @@ import com.android.tools.layoutlib.create.OverrideMethod; import android.graphics.Bitmap; import android.graphics.Typeface_Delegate; +import android.util.Finalizers; import java.lang.ref.SoftReference; import java.lang.reflect.Field; @@ -114,19 +115,12 @@ public final class Bridge extends LayoutBridge { */ @Override public boolean init(String fontOsLocation, Map<String, Map<String, Integer>> enumValueMap) { - BridgeAssetManager.initSystem(); + sEnumValueMap = enumValueMap; - return sinit(fontOsLocation, enumValueMap); - } + Finalizers.init(); - @Override - public boolean dispose() { - BridgeAssetManager.clearSystem(); - return true; - } + BridgeAssetManager.initSystem(); - private static synchronized boolean sinit(String fontOsLocation, - Map<String, Map<String, Integer>> enumValueMap) { // When DEBUG_LAYOUT is set and is not 0 or false, setup a default listener // on static (native) methods which prints the signature on the console and @@ -165,8 +159,6 @@ public final class Bridge extends LayoutBridge { return false; } - sEnumValueMap = enumValueMap; - // now parse com.android.internal.R (and only this one as android.R is a subset of // the internal version), and put the content in the maps. try { @@ -214,6 +206,12 @@ public final class Bridge extends LayoutBridge { return true; } + @Override + public boolean dispose() { + BridgeAssetManager.clearSystem(); + return true; + } + /** * Sets a 9 patch in a project cache or in the framework cache. * @param value the path of the 9 patch @@ -423,70 +421,4 @@ public final class Bridge extends LayoutBridge { return null; } - - - // ---------- OBSOLETE API METHODS ---------- - - /* - * For compatilibty purposes, we implement the old deprecated version of computeLayout. - * (non-Javadoc) - * @see com.android.layoutlib.api.ILayoutBridge#computeLayout(com.android.layoutlib.api.IXmlPullParser, java.lang.Object, int, int, java.lang.String, java.util.Map, java.util.Map, com.android.layoutlib.api.IProjectCallback, com.android.layoutlib.api.ILayoutLog) - */ - @Deprecated - public com.android.layoutlib.api.ILayoutResult computeLayout(IXmlPullParser layoutDescription, - Object projectKey, - int screenWidth, int screenHeight, String themeName, - Map<String, Map<String, IResourceValue>> projectResources, - Map<String, Map<String, IResourceValue>> frameworkResources, - IProjectCallback customViewLoader, ILayoutLog logger) { - throw new UnsupportedOperationException(); - } - - /* - * For compatilibty purposes, we implement the old deprecated version of computeLayout. - * (non-Javadoc) - * @see com.android.layoutlib.api.ILayoutBridge#computeLayout(com.android.layoutlib.api.IXmlPullParser, java.lang.Object, int, int, java.lang.String, boolean, java.util.Map, java.util.Map, com.android.layoutlib.api.IProjectCallback, com.android.layoutlib.api.ILayoutLog) - */ - @Deprecated - public com.android.layoutlib.api.ILayoutResult computeLayout(IXmlPullParser layoutDescription, - Object projectKey, - int screenWidth, int screenHeight, String themeName, boolean isProjectTheme, - Map<String, Map<String, IResourceValue>> projectResources, - Map<String, Map<String, IResourceValue>> frameworkResources, - IProjectCallback customViewLoader, ILayoutLog logger) { - throw new UnsupportedOperationException(); - } - - /* - * For compatilibty purposes, we implement the old deprecated version of computeLayout. - * (non-Javadoc) - * @see com.android.layoutlib.api.ILayoutBridge#computeLayout(com.android.layoutlib.api.IXmlPullParser, java.lang.Object, int, int, int, float, float, java.lang.String, boolean, java.util.Map, java.util.Map, com.android.layoutlib.api.IProjectCallback, com.android.layoutlib.api.ILayoutLog) - */ - @Deprecated - public com.android.layoutlib.api.ILayoutResult computeLayout(IXmlPullParser layoutDescription, - Object projectKey, - int screenWidth, int screenHeight, int density, float xdpi, float ydpi, - String themeName, boolean isProjectTheme, - Map<String, Map<String, IResourceValue>> projectResources, - Map<String, Map<String, IResourceValue>> frameworkResources, - IProjectCallback customViewLoader, ILayoutLog logger) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see com.android.layoutlib.api.ILayoutBridge#computeLayout(com.android.layoutlib.api.IXmlPullParser, java.lang.Object, int, int, boolean, int, float, float, java.lang.String, boolean, java.util.Map, java.util.Map, com.android.layoutlib.api.IProjectCallback, com.android.layoutlib.api.ILayoutLog) - */ - @Deprecated - public com.android.layoutlib.api.ILayoutResult computeLayout(IXmlPullParser layoutDescription, - Object projectKey, - int screenWidth, int screenHeight, boolean renderFullSize, - int density, float xdpi, float ydpi, - String themeName, boolean isProjectTheme, - Map<String, Map<String, IResourceValue>> projectResources, - Map<String, Map<String, IResourceValue>> frameworkResources, - IProjectCallback customViewLoader, ILayoutLog logger) { - throw new UnsupportedOperationException(); - } - } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java index 169d751..b272963 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java @@ -59,9 +59,7 @@ public final class DelegateManager<T> { * @return the delegate or null if not found. */ public T getDelegate(int native_object) { - synchronized (mDelegates) { - return mDelegates.get(native_object); - } + return mDelegates.get(native_object); } /** @@ -70,11 +68,9 @@ public final class DelegateManager<T> { * @return a unique native int to identify the delegate */ public int addDelegate(T newDelegate) { - synchronized (mDelegates) { - int native_object = ++mDelegateCounter; - mDelegates.put(native_object, newDelegate); - return native_object; - } + int native_object = ++mDelegateCounter; + mDelegates.put(native_object, newDelegate); + return native_object; } /** @@ -82,8 +78,6 @@ public final class DelegateManager<T> { * @param native_object the native int. */ public void removeDelegate(int native_object) { - synchronized (mDelegates) { - mDelegates.remove(native_object); - } + mDelegates.remove(native_object); } } |