summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornicolasroard <nicolasroard@google.com>2013-03-21 21:33:22 -0700
committernicolasroard <nicolasroard@google.com>2013-03-21 21:33:22 -0700
commitcbbaef3e674898c3045486ae4930966c3dff1147 (patch)
tree90d4188ded60d061bc6ae47dc7f99cb40a6bd4ee /src
parentdc19e2f107b02b62f887dc500e107ad8f4a9cb07 (diff)
downloadandroid_packages_apps_Snap-cbbaef3e674898c3045486ae4930966c3dff1147.tar.gz
android_packages_apps_Snap-cbbaef3e674898c3045486ae4930966c3dff1147.tar.bz2
android_packages_apps_Snap-cbbaef3e674898c3045486ae4930966c3dff1147.zip
Fix problem applying the Fx filter
Also adds some debug info bug:8442036 Change-Id: Ife7fd4be664ae011e41969e74c7745da0a7a52f5
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/filtershow/cache/CachingPipeline.java26
-rw-r--r--src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java4
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java9
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java7
-rw-r--r--src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java7
5 files changed, 43 insertions, 10 deletions
diff --git a/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java b/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java
index 8d7fcd5d5..1190ea4f8 100644
--- a/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java
+++ b/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java
@@ -46,9 +46,11 @@ public class CachingPipeline {
private volatile GeometryMetadata mPreviousGeometry = null;
private volatile float mPreviewScaleFactor = 1.0f;
+ private volatile String mName = "";
- public CachingPipeline(FiltersManager filtersManager) {
+ public CachingPipeline(FiltersManager filtersManager, String name) {
mFiltersManager = filtersManager;
+ mName = name;
}
public synchronized void reset() {
@@ -72,6 +74,9 @@ public class CachingPipeline {
}
private synchronized void destroyPixelAllocations() {
+ if (DEBUG) {
+ Log.v(LOGTAG, "destroyPixelAllocations in " + getName());
+ }
if (mInPixelsAllocation != null) {
mInPixelsAllocation.destroy();
mInPixelsAllocation = null;
@@ -215,6 +220,14 @@ public class CachingPipeline {
}
+ public synchronized Bitmap renderFinalImage(Bitmap bitmap, ImagePreset preset) {
+ setPresetParameters(preset);
+ mFiltersManager.freeFilterResources(preset);
+ bitmap = preset.applyGeometry(bitmap);
+ bitmap = preset.apply(bitmap);
+ return bitmap;
+ }
+
public synchronized void compute(TripleBufferBitmap buffer, ImagePreset preset, int type) {
if (DEBUG) {
Log.v(LOGTAG, "compute preset " + preset);
@@ -291,14 +304,21 @@ public class CachingPipeline {
mHeight = bitmap.getHeight();
needsUpdate = true;
}
+ if (DEBUG) {
+ Log.v(LOGTAG, "prepareRenderscriptAllocations: " + needsUpdate + " in " + getName());
+ }
return needsUpdate;
}
- public Allocation getInPixelsAllocation() {
+ public synchronized Allocation getInPixelsAllocation() {
return mInPixelsAllocation;
}
- public Allocation getOutPixelsAllocation() {
+ public synchronized Allocation getOutPixelsAllocation() {
return mOutPixelsAllocation;
}
+
+ public String getName() {
+ return mName;
+ }
}
diff --git a/src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java b/src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java
index 20af215e4..1ba6e959e 100644
--- a/src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java
+++ b/src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java
@@ -111,8 +111,8 @@ public class FilteringPipeline implements Handler.Callback {
Process.THREAD_PRIORITY_FOREGROUND);
mHandlerThread.start();
mProcessingHandler = new Handler(mHandlerThread.getLooper(), this);
- mAccessoryPipeline = new CachingPipeline(FiltersManager.getManager());
- mPreviewPipeline = new CachingPipeline(FiltersManager.getPreviewManager());
+ mAccessoryPipeline = new CachingPipeline(FiltersManager.getManager(), "Accessory");
+ mPreviewPipeline = new CachingPipeline(FiltersManager.getPreviewManager(), "Preview");
}
public synchronized static FilteringPipeline getPipeline() {
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java
index 904a601f4..68e8a7c9d 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java
@@ -57,10 +57,15 @@ public class ImageFilterFx extends ImageFilter {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
- if (mFxBitmap == null || mFxBitmapId != getParameters().getBitmapResource()) {
+ int bitmapResourceId = getParameters().getBitmapResource();
+ if (bitmapResourceId == 0) { // null filter fx
+ return bitmap;
+ }
+
+ if (mFxBitmap == null || mFxBitmapId != bitmapResourceId) {
BitmapFactory.Options o = new BitmapFactory.Options();
o.inScaled = false;
- mFxBitmapId = getParameters().getBitmapResource();
+ mFxBitmapId = bitmapResourceId;
if (mFxBitmapId != 0) {
mFxBitmap = BitmapFactory.decodeResource(mResources, mFxBitmapId, o);
} else {
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
index b91051dbb..56e848aa7 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
@@ -27,6 +27,7 @@ import com.android.gallery3d.filtershow.cache.CachingPipeline;
public abstract class ImageFilterRS extends ImageFilter {
private static final String LOGTAG = "ImageFilterRS";
+ private boolean DEBUG = false;
private static volatile RenderScript sRS = null;
private static volatile Resources sResources = null;
@@ -66,6 +67,9 @@ public abstract class ImageFilterRS extends ImageFilter {
return bitmap;
}
CachingPipeline pipeline = getEnvironment().getCachingPipeline();
+ if (DEBUG) {
+ Log.v(LOGTAG, "apply filter " + getName() + " in pipeline " + pipeline.getName());
+ }
boolean needsUpdate = pipeline.prepareRenderscriptAllocations(bitmap);
if (needsUpdate || !isResourcesLoaded()) {
// the allocations changed size
@@ -75,6 +79,9 @@ public abstract class ImageFilterRS extends ImageFilter {
}
runFilter();
update(bitmap);
+ if (DEBUG) {
+ Log.v(LOGTAG, "DONE apply filter " + getName() + " in pipeline " + pipeline.getName());
+ }
}
} catch (android.renderscript.RSIllegalArgumentException e) {
Log.e(LOGTAG, "Illegal argument? " + e);
diff --git a/src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java b/src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java
index aa7e70065..35c155318 100644
--- a/src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java
+++ b/src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java
@@ -31,7 +31,9 @@ import android.util.Log;
import com.android.gallery3d.common.Utils;
import com.android.gallery3d.exif.ExifInterface;
+import com.android.gallery3d.filtershow.cache.CachingPipeline;
import com.android.gallery3d.filtershow.cache.ImageLoader;
+import com.android.gallery3d.filtershow.filters.FiltersManager;
import com.android.gallery3d.filtershow.presets.ImagePreset;
import com.android.gallery3d.util.XmpUtilHelper;
@@ -182,9 +184,8 @@ public class SaveCopyTask extends AsyncTask<ImagePreset, Void, Uri> {
if (bitmap == null) {
return null;
}
- preset.setupEnvironment();
- bitmap = preset.applyGeometry(bitmap);
- bitmap = preset.apply(bitmap);
+ CachingPipeline pipeline = new CachingPipeline(FiltersManager.getManager(), "Saving");
+ bitmap = pipeline.renderFinalImage(bitmap, preset);
Object xmp = getPanoramaXMPData(sourceUri, preset);
ExifInterface exif = getExifData(sourceUri);