summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/filters
diff options
context:
space:
mode:
authornicolasroard <nicolasroard@google.com>2013-02-08 14:06:33 -0800
committernicolasroard <nicolasroard@google.com>2013-02-08 14:52:05 -0800
commitdeeddb19c78a4299cc0e4075ed0265820eeb20f0 (patch)
treea0f103eeeb1434d6dcbe27bc12ccea0e190d5312 /src/com/android/gallery3d/filtershow/filters
parentb7e69915ebc7fa89398649ec03e9aa619e9d9991 (diff)
downloadandroid_packages_apps_Snap-deeddb19c78a4299cc0e4075ed0265820eeb20f0.tar.gz
android_packages_apps_Snap-deeddb19c78a4299cc0e4075ed0265820eeb20f0.tar.bz2
android_packages_apps_Snap-deeddb19c78a4299cc0e4075ed0265820eeb20f0.zip
Fix leaks / init
Change-Id: I5befdc24cc89cdcfb73ee4d13f076b1c4a585cf6
Diffstat (limited to 'src/com/android/gallery3d/filtershow/filters')
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterImageBorderRepresentation.java20
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java34
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java10
3 files changed, 44 insertions, 20 deletions
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterImageBorderRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterImageBorderRepresentation.java
index 467409fb8..2b40fccc0 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterImageBorderRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterImageBorderRepresentation.java
@@ -16,18 +16,18 @@
package com.android.gallery3d.filtershow.filters;
-import android.graphics.drawable.Drawable;
-
public class FilterImageBorderRepresentation extends FilterRepresentation {
- private Drawable mDrawable;
private int mDrawableResource = 0;
- public FilterImageBorderRepresentation(int drawableResource, Drawable drawable) {
+ public FilterImageBorderRepresentation(int drawableResource) {
super("ImageBorder");
mDrawableResource = drawableResource;
- mDrawable = drawable;
setFilterClass(ImageFilterBorder.class);
setPriority(ImageFilter.TYPE_BORDER);
+ // load the drawable at init as we are in a background thread
+ // (see FilterShowActivity's LoadBordersTask)
+ ImageFilterBorder filter = (ImageFilterBorder) FiltersManager.getManager().getFilter(getFilterClass());
+ filter.getDrawable(getDrawableResource());
}
public String toString() {
@@ -38,7 +38,6 @@ public class FilterImageBorderRepresentation extends FilterRepresentation {
public FilterRepresentation clone() throws CloneNotSupportedException {
FilterImageBorderRepresentation representation = (FilterImageBorderRepresentation) super.clone();
representation.setName(getName());
- representation.setDrawable(getDrawable());
representation.setDrawableResource(getDrawableResource());
return representation;
}
@@ -47,7 +46,6 @@ public class FilterImageBorderRepresentation extends FilterRepresentation {
if (a instanceof FilterImageBorderRepresentation) {
FilterImageBorderRepresentation representation = (FilterImageBorderRepresentation) a;
setName(representation.getName());
- setDrawable(representation.getDrawable());
setDrawableResource(representation.getDrawableResource());
}
}
@@ -70,14 +68,6 @@ public class FilterImageBorderRepresentation extends FilterRepresentation {
return true;
}
- public Drawable getDrawable() {
- return mDrawable;
- }
-
- public void setDrawable(Drawable drawable) {
- mDrawable = drawable;
- }
-
public int getDrawableResource() {
return mDrawableResource;
}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java
index 6362124b9..200bcf153 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java
@@ -16,17 +16,25 @@
package com.android.gallery3d.filtershow.filters;
+import android.content.res.Resources;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
+import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import com.android.gallery3d.R;
+import java.util.HashMap;
+
public class ImageFilterBorder extends ImageFilter {
private static final float NINEPATCH_ICON_SCALING = 10;
private static final float BITMAP_ICON_SCALING = 1 / 3.0f;
private FilterImageBorderRepresentation mParameters = null;
+ private Resources mResources = null;
+
+ private HashMap<Integer, Drawable> mDrawables = new HashMap<Integer, Drawable>();
public ImageFilterBorder() {
mName = "Border";
@@ -67,14 +75,15 @@ public class ImageFilterBorder extends ImageFilter {
Rect bounds = new Rect(0, 0, (int) (w * scale1), (int) (h * scale1));
Canvas canvas = new Canvas(bitmap);
canvas.scale(scale2, scale2);
- getParameters().getDrawable().setBounds(bounds);
- getParameters().getDrawable().draw(canvas);
+ Drawable drawable = getDrawable(getParameters().getDrawableResource());
+ drawable.setBounds(bounds);
+ drawable.draw(canvas);
return bitmap;
}
@Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
- if (getParameters() == null || getParameters().getDrawable() == null) {
+ if (getParameters() == null || getParameters().getDrawableResource() == 0) {
return bitmap;
}
float scale2 = scaleFactor * 2.0f;
@@ -84,11 +93,28 @@ public class ImageFilterBorder extends ImageFilter {
@Override
public Bitmap iconApply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
- if (getParameters() == null || getParameters().getDrawable() == null) {
+ if (getParameters() == null || getParameters().getDrawableResource() == 0) {
return bitmap;
}
float scale1 = NINEPATCH_ICON_SCALING;
float scale2 = BITMAP_ICON_SCALING;
return applyHelper(bitmap, scale1, scale2);
}
+
+ public void setResources(Resources resources) {
+ if (mResources != resources) {
+ mResources = resources;
+ mDrawables.clear();
+ }
+ }
+
+ public Drawable getDrawable(int rsc) {
+ Drawable drawable = mDrawables.get(rsc);
+ if (drawable == null && mResources != null) {
+ drawable = new BitmapDrawable(mResources, BitmapFactory.decodeResource(mResources, rsc));
+ mDrawables.put(rsc, drawable);
+ }
+ return drawable;
+ }
+
}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
index 368e29a78..4778d3c08 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
@@ -31,7 +31,6 @@ public class ImageFilterRS extends ImageFilter {
private static Bitmap sOldBitmap = null;
private Bitmap mOldBitmap = null;
- private static Bitmap mReturnBitmap = null;
private final Bitmap.Config mBitmapConfig = Bitmap.Config.ARGB_8888;
public void prepare(Bitmap bitmap, float scaleFactor, boolean highQuality) {
@@ -95,6 +94,15 @@ public class ImageFilterRS extends ImageFilter {
public static void setRenderScriptContext(Activity context) {
mRS = RenderScript.create(context);
mResources = context.getResources();
+ if (mInPixelsAllocation != null) {
+ mInPixelsAllocation.destroy();
+ mInPixelsAllocation = null;
+ }
+ if (mOutPixelsAllocation != null) {
+ mOutPixelsAllocation.destroy();
+ mOutPixelsAllocation = null;
+ }
+ sOldBitmap = null;
}
}