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

Commit 01f0ad7c authored by Stephen Hines's avatar Stephen Hines
Browse files

Fix clear() operation for rsScriptC.

- This removes a memory leak where some elements were not getting tracked
  properly (and then triggering an assert when a context is destroyed).
- Convert ScriptCState to use a tracked object reference for mScript.
- Add a missing clear to FontState.
- Clean up synchronization in RSTest so that our graphics context outlives
  any subtest context.

Change-Id: I0d5768c4d2f8810dd1ae2f68b1edd7e150f382fd
parent 3ebb1ba5
Loading
Loading
Loading
Loading
+48 −3
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.renderscript.*;
import android.util.Log;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.Timer;
import java.util.TimerTask;


public class RSTestCore {
@@ -42,12 +44,18 @@ public class RSTestCore {
    private ArrayList<UnitTest> unitTests;
    private ListIterator<UnitTest> test_iter;
    private UnitTest activeTest;
    private boolean stopTesting;

    /* Periodic timer for ensuring future tests get scheduled */
    private Timer mTimer;
    public static final int RS_TIMER_PERIOD = 100;

    public void init(RenderScriptGL rs, Resources res, int width, int height) {
        mRS = rs;
        mRes = res;
        mWidth = width;
        mHeight = height;
        stopTesting = false;

        mScript = new ScriptC_rslist(mRS, mRes, R.raw.rslist, true);

@@ -88,9 +96,17 @@ public class RSTestCore {

        test_iter = unitTests.listIterator();
        refreshTestResults(); /* Kick off the first test */

        TimerTask pTask = new TimerTask() {
            public void run() {
                refreshTestResults();
            }
        };

        mTimer = new Timer();
        mTimer.schedule(pTask, RS_TIMER_PERIOD, RS_TIMER_PERIOD);
    }

    static int count = 0;
    public void checkAndRunNextTest() {
        if (activeTest != null) {
            if (!activeTest.isAlive()) {
@@ -104,7 +120,7 @@ public class RSTestCore {
            }
        }

        if (activeTest == null) {
        if (!stopTesting && activeTest == null) {
            if (test_iter.hasNext()) {
                activeTest = test_iter.next();
                activeTest.start();
@@ -112,8 +128,14 @@ public class RSTestCore {
                 * should start running. The message handler in UnitTest.java
                 * ensures this. */
            }
            else {
                if (mTimer != null) {
                    mTimer.cancel();
                    mTimer.purge();
                    mTimer = null;
                }
            }
        }
        count++;
    }

    public void refreshTestResults() {
@@ -127,6 +149,29 @@ public class RSTestCore {
        }
    }

    public void cleanup() {
        stopTesting = true;
        UnitTest t = activeTest;

        /* Stop periodic refresh of testing */
        if (mTimer != null) {
            mTimer.cancel();
            mTimer.purge();
            mTimer = null;
        }

        /* Wait to exit until we finish the current test */
        if (t != null) {
            try {
                t.join();
            }
            catch (InterruptedException e) {
            }
            t = null;
        }

    }

    public void newTouchPosition(float x, float y, float pressure, int id) {
    }

+1 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ public class RSTestView extends RSSurfaceView {
    @Override
    protected void onDetachedFromWindow() {
        if(mRS != null) {
            mRender.cleanup();
            mRS = null;
            destroyRenderScript();
        }
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ public class UT_fp_mad extends UnitTest {
        pRS.mMessageCallback = mRsMessage;
        s.invoke_fp_mad_test(0, 0);
        pRS.finish();
        waitForMessage();
        pRS.destroy();
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ public class UT_primitives extends UnitTest {
        pRS.mMessageCallback = mRsMessage;
        s.invoke_primitives_test(0, 0);
        pRS.finish();
        waitForMessage();
        pRS.destroy();
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ public class UnitTest extends Thread {
    public int result;
    private ScriptField_ListAllocs_s.Item mItem;
    private RSTestCore mRSTC;
    private boolean msgHandled;

    /* These constants must match those in shared.rsh */
    public static final int RS_MSG_TEST_PASSED = 100;
@@ -35,6 +36,7 @@ public class UnitTest extends Thread {
        super();
        mRSTC = rstc;
        name = n;
        msgHandled = false;
        result = initResult;
        testID = numTests++;
    }
@@ -67,6 +69,7 @@ public class UnitTest extends Thread {

            if (mItem != null) {
                mItem.result = result;
                msgHandled = true;
                try {
                    mRSTC.refreshTestResults();
                }
@@ -79,6 +82,12 @@ public class UnitTest extends Thread {
        }
    };

    public void waitForMessage() {
        while (!msgHandled) {
            yield();
        }
    }

    public void setItem(ScriptField_ListAllocs_s.Item item) {
        mItem = item;
    }
Loading