summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java')
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java49
1 files changed, 30 insertions, 19 deletions
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
index cfbb560c7..69d18f805 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
@@ -22,13 +22,14 @@ import android.support.v8.renderscript.*;
import android.util.Log;
import android.content.res.Resources;
import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.cache.CachingPipeline;
+import com.android.gallery3d.filtershow.presets.PipelineInterface;
public abstract class ImageFilterRS extends ImageFilter {
private static final String LOGTAG = "ImageFilterRS";
private boolean DEBUG = false;
private int mLastInputWidth = 0;
private int mLastInputHeight = 0;
+ private long mLastTimeCalled;
public static boolean PERF_LOGGING = false;
@@ -51,26 +52,36 @@ public abstract class ImageFilterRS extends ImageFilter {
}
protected RenderScript getRenderScriptContext() {
- return CachingPipeline.getRenderScriptContext();
+ PipelineInterface pipeline = getEnvironment().getPipeline();
+ return pipeline.getRSContext();
}
protected Allocation getInPixelsAllocation() {
- CachingPipeline pipeline = getEnvironment().getCachingPipeline();
+ PipelineInterface pipeline = getEnvironment().getPipeline();
return pipeline.getInPixelsAllocation();
}
protected Allocation getOutPixelsAllocation() {
- CachingPipeline pipeline = getEnvironment().getCachingPipeline();
+ PipelineInterface pipeline = getEnvironment().getPipeline();
return pipeline.getOutPixelsAllocation();
}
@Override
public void apply(Allocation in, Allocation out) {
long startOverAll = System.nanoTime();
+ if (PERF_LOGGING) {
+ long delay = (startOverAll - mLastTimeCalled) / 1000;
+ String msg = String.format("%s; image size %dx%d; ", getName(),
+ in.getType().getX(), in.getType().getY());
+ msg += String.format("called after %.2f ms (%.2f FPS); ",
+ delay / 1000.f, 1000000.f / delay);
+ Log.i(LOGTAG, msg);
+ }
+ mLastTimeCalled = startOverAll;
long startFilter = 0;
long endFilter = 0;
if (!mResourcesLoaded) {
- CachingPipeline pipeline = getEnvironment().getCachingPipeline();
+ PipelineInterface pipeline = getEnvironment().getPipeline();
createFilter(pipeline.getResources(), getEnvironment().getScaleFactor(),
getEnvironment().getQuality(), in);
mResourcesLoaded = true;
@@ -102,7 +113,7 @@ public abstract class ImageFilterRS extends ImageFilter {
return bitmap;
}
try {
- CachingPipeline pipeline = getEnvironment().getCachingPipeline();
+ PipelineInterface pipeline = getEnvironment().getPipeline();
if (DEBUG) {
Log.v(LOGTAG, "apply filter " + getName() + " in pipeline " + pipeline.getName());
}
@@ -137,18 +148,16 @@ public abstract class ImageFilterRS extends ImageFilter {
displayLowMemoryToast();
Log.e(LOGTAG, "not enough memory for filter " + getName(), e);
}
-
return bitmap;
}
- protected static Allocation convertBitmap(Bitmap bitmap) {
- return Allocation.createFromBitmap(CachingPipeline.getRenderScriptContext(), bitmap,
+ protected static Allocation convertBitmap(RenderScript RS, Bitmap bitmap) {
+ return Allocation.createFromBitmap(RS, bitmap,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT | Allocation.USAGE_GRAPHICS_TEXTURE);
}
- private static Allocation convertRGBAtoA(Bitmap bitmap) {
- RenderScript RS = CachingPipeline.getRenderScriptContext();
+ private static Allocation convertRGBAtoA(RenderScript RS, Bitmap bitmap) {
if (RS != mRScache || mGreyConvert == null) {
mGreyConvert = new ScriptC_grey(RS, RS.getApplicationContext().getResources(),
R.raw.grey);
@@ -157,7 +166,7 @@ public abstract class ImageFilterRS extends ImageFilter {
Type.Builder tb_a8 = new Type.Builder(RS, Element.A_8(RS));
- Allocation bitmapTemp = convertBitmap(bitmap);
+ Allocation bitmapTemp = convertBitmap(RS, bitmap);
if (bitmapTemp.getType().getElement().isCompatible(Element.A_8(RS))) {
return bitmapTemp;
}
@@ -173,20 +182,20 @@ public abstract class ImageFilterRS extends ImageFilter {
}
public Allocation loadScaledResourceAlpha(int resource, int inSampleSize) {
- Resources res = CachingPipeline.getResources();
+ Resources res = getEnvironment().getPipeline().getResources();
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ALPHA_8;
options.inSampleSize = inSampleSize;
Bitmap bitmap = BitmapFactory.decodeResource(
res,
resource, options);
- Allocation ret = convertRGBAtoA(bitmap);
+ Allocation ret = convertRGBAtoA(getRenderScriptContext(), bitmap);
bitmap.recycle();
return ret;
}
public Allocation loadScaledResourceAlpha(int resource, int w, int h, int inSampleSize) {
- Resources res = CachingPipeline.getResources();
+ Resources res = getEnvironment().getPipeline().getResources();
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ALPHA_8;
options.inSampleSize = inSampleSize;
@@ -194,7 +203,7 @@ public abstract class ImageFilterRS extends ImageFilter {
res,
resource, options);
Bitmap resizeBitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
- Allocation ret = convertRGBAtoA(resizeBitmap);
+ Allocation ret = convertRGBAtoA(getRenderScriptContext(), resizeBitmap);
resizeBitmap.recycle();
bitmap.recycle();
return ret;
@@ -205,13 +214,13 @@ public abstract class ImageFilterRS extends ImageFilter {
}
public Allocation loadResource(int resource) {
- Resources res = CachingPipeline.getResources();
+ Resources res = getEnvironment().getPipeline().getResources();
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeResource(
res,
resource, options);
- Allocation ret = convertBitmap(bitmap);
+ Allocation ret = convertBitmap(getRenderScriptContext(), bitmap);
bitmap.recycle();
return ret;
}
@@ -232,7 +241,7 @@ public abstract class ImageFilterRS extends ImageFilter {
/**
* RS Script objects (and all other RS objects) should be cleared here
*/
- abstract protected void resetScripts();
+ public abstract void resetScripts();
/**
* Scripts values should be bound here
@@ -244,6 +253,8 @@ public abstract class ImageFilterRS extends ImageFilter {
return;
}
resetAllocations();
+ mLastInputWidth = 0;
+ mLastInputHeight = 0;
setResourcesLoaded(false);
}
}