Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c90af22 authored by nicolasroard's avatar nicolasroard
Browse files

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
parent 10bd1e0c
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -64,13 +64,16 @@ public abstract class ImageFilterRS extends ImageFilter {
            if (DEBUG) {
                Log.v(LOGTAG, "apply filter " + getName() + " in pipeline " + pipeline.getName());
            }
            pipeline.prepareRenderscriptAllocations(bitmap);
            Resources rsc = pipeline.getResources();
            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 @@ public abstract class ImageFilterRS extends ImageFilter {
     */
    abstract protected void resetScripts();

    /**
     * Scripts values should be bound here
     */
    abstract protected void bindScriptValues();

    public void freeResources() {
        if (!isResourcesLoaded()) {
            return;
+10 −8
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ public class ImageFilterSharpen extends ImageFilterRS {

    private static final String LOGTAG = "ImageFilterSharpen";
    private ScriptC_convolve3x3 mScript;
    float mScaleFactor;

    private FilterBasicRepresentation mParameters;

@@ -63,19 +62,14 @@ public class ImageFilterSharpen extends ImageFilterRS {
    @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;
@@ -91,6 +85,14 @@ public class ImageFilterSharpen extends ImageFilterRS {
        mScript.set_gCoeffs(f);
    }

    @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) {
+1 −0
Original line number Diff line number Diff line
@@ -77,4 +77,5 @@ public class FilterEnvironment {
    public void setCachingPipeline(CachingPipeline cachingPipeline) {
        mCachingPipeline = cachingPipeline;
    }

}