Re-enable caching step in RS filters
Bug: 8478659
Bug: 8459181
Bug: 8450339
Bug: 8457323
With the compatibility library, different Scripts instances
actually points to the same thing. We thus need to explicitely
rebind all the variables to the correct script instance before
running RS filters...
Change-Id: Id6cd4e44b5a67a3d2588e158c616b2b44e214a5b
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
index c76f7dd..2aeaed8 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
@@ -64,13 +64,16 @@
if (DEBUG) {
Log.v(LOGTAG, "apply filter " + getName() + " in pipeline " + pipeline.getName());
}
- pipeline.prepareRenderscriptAllocations(bitmap);
Resources rsc = pipeline.getResources();
- createFilter(rsc, scaleFactor, quality);
- setResourcesLoaded(true);
+ if (pipeline.prepareRenderscriptAllocations(bitmap)
+ || !isResourcesLoaded()) {
+ freeResources();
+ createFilter(rsc, scaleFactor, quality);
+ setResourcesLoaded(true);
+ }
+ bindScriptValues();
runFilter();
update(bitmap);
- freeResources();
if (DEBUG) {
Log.v(LOGTAG, "DONE apply filter " + getName() + " in pipeline " + pipeline.getName());
}
@@ -158,6 +161,11 @@
*/
abstract protected void resetScripts();
+ /**
+ * Scripts values should be bound here
+ */
+ abstract protected void bindScriptValues();
+
public void freeResources() {
if (!isResourcesLoaded()) {
return;
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java
index f545cd9..76ae475 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java
@@ -22,7 +22,6 @@
private static final String LOGTAG = "ImageFilterSharpen";
private ScriptC_convolve3x3 mScript;
- float mScaleFactor;
private FilterBasicRepresentation mParameters;
@@ -63,19 +62,14 @@
@Override
protected void createFilter(android.content.res.Resources res, float scaleFactor,
int quality) {
- int w = getInPixelsAllocation().getType().getX();
- int h = getInPixelsAllocation().getType().getY();
- mScaleFactor = scaleFactor;
-
if (mScript == null) {
mScript = new ScriptC_convolve3x3(getRenderScriptContext(), res, R.raw.convolve3x3);
}
- mScript.set_gWidth(w);
- mScript.set_gHeight(h);
}
private void computeKernel() {
- float p1 = mParameters.getValue() * mScaleFactor;
+ float scaleFactor = getEnvironment().getScaleFactor();
+ float p1 = mParameters.getValue() * scaleFactor;
float value = p1 / 100.0f;
float f[] = new float[9];
float p = value;
@@ -92,6 +86,14 @@
}
@Override
+ protected void bindScriptValues() {
+ int w = getInPixelsAllocation().getType().getX();
+ int h = getInPixelsAllocation().getType().getY();
+ mScript.set_gWidth(w);
+ mScript.set_gHeight(h);
+ }
+
+ @Override
protected void runFilter() {
if (mParameters == null) {
return;
diff --git a/src/com/android/gallery3d/filtershow/presets/FilterEnvironment.java b/src/com/android/gallery3d/filtershow/presets/FilterEnvironment.java
index c450360..b474b84 100644
--- a/src/com/android/gallery3d/filtershow/presets/FilterEnvironment.java
+++ b/src/com/android/gallery3d/filtershow/presets/FilterEnvironment.java
@@ -77,4 +77,5 @@
public void setCachingPipeline(CachingPipeline cachingPipeline) {
mCachingPipeline = cachingPipeline;
}
+
}