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

Commit a9e7a05b authored by Jason Sams's avatar Jason Sams
Browse files

Improve renderscript context teardown. Track object in the system and then...

Improve renderscript context teardown.  Track object in the system and then force their cleanup by releasing all user references once destroy context is called.  Java layer will no longer send destroy notifications for objects garbage collected once a context is destroyed.
parent a0cad2f5
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -60,9 +60,10 @@ class BaseObj {
    protected void finalize() throws Throwable
    {
        if (!mDestroyed) {
            if(mID != 0) {
            if(mID != 0 && mRS.isAlive()) {
                mRS.nObjDestroyOOB(mID);
            }
            mRS = null;
            mID = 0;
            mDestroyed = true;
            Log.v(RenderScript.LOG_TAG,
+4 −0
Original line number Diff line number Diff line
@@ -219,6 +219,10 @@ public class RenderScript {
        mDev = 0;
    }

    boolean isAlive() {
        return mContext != 0;
    }

    void pause() {
        nContextPause();
    }
+7 −1
Original line number Diff line number Diff line
@@ -62,6 +62,8 @@ public class Fountain extends Activity {

    @Override
    protected void onResume() {
        Log.e("rs", "onResume");

        // Ideally a game should implement onResume() and onPause()
        // to take appropriate action when the activity looses focus
        super.onResume();
@@ -70,12 +72,16 @@ public class Fountain extends Activity {

    @Override
    protected void onPause() {
        Log.e("rs", "onPause");

        // Ideally a game should implement onResume() and onPause()
        // to take appropriate action when the activity looses focus
        super.onPause();
        mView.onPause();

        Runtime.getRuntime().exit(0);


        //Runtime.getRuntime().exit(0);
    }


+26 −0
Original line number Diff line number Diff line
@@ -49,14 +49,40 @@ public class FountainView extends RSSurfaceView {
    private RenderScript mRS;
    private FountainRS mRender;

    private void destroyRS() {
        if(mRS != null) {
            mRS = null;
            destroyRenderScript();
        }
        java.lang.System.gc();
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        super.surfaceChanged(holder, format, w, h);

        Log.e("rs", "surfaceChanged");
        destroyRS();


        mRS = createRenderScript(false, true);
        mRender = new FountainRS();
        mRender.init(mRS, getResources(), w, h);
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
        // Surface will be destroyed when we return
        Log.v("rs", "surfaceDestroyed");
        destroyRS();

        try {
            java.lang.Thread.sleep(5000);
        } catch(InterruptedException e) {

        }
        Runtime.getRuntime().exit(0);
    }



    @Override
    public boolean onTouchEvent(MotionEvent ev)
+6 −6
Original line number Diff line number Diff line
@@ -21,12 +21,12 @@ using namespace android;
using namespace android::renderscript;


Adapter1D::Adapter1D()
Adapter1D::Adapter1D(Context *rsc) : ObjectBase(rsc)
{
    reset();
}

Adapter1D::Adapter1D(Allocation *a)
Adapter1D::Adapter1D(Context *rsc, Allocation *a) : ObjectBase(rsc)
{
    reset();
    setAllocation(a);
@@ -71,7 +71,7 @@ namespace renderscript {

RsAdapter1D rsi_Adapter1DCreate(Context *rsc)
{
    Adapter1D *a = new Adapter1D();
    Adapter1D *a = new Adapter1D(rsc);
    a->incUserRef();
    return a;
}
@@ -125,12 +125,12 @@ void rsi_Adapter1DData(Context *rsc, RsAdapter1D va, const void *data)

//////////////////////////

Adapter2D::Adapter2D()
Adapter2D::Adapter2D(Context *rsc) : ObjectBase(rsc)
{
    reset();
}

Adapter2D::Adapter2D(Allocation *a)
Adapter2D::Adapter2D(Context *rsc, Allocation *a) : ObjectBase(rsc)
{
    reset();
    setAllocation(a);
@@ -184,7 +184,7 @@ namespace renderscript {

RsAdapter2D rsi_Adapter2DCreate(Context *rsc)
{
    Adapter2D *a = new Adapter2D();
    Adapter2D *a = new Adapter2D(rsc);
    a->incUserRef();
    return a;
}
Loading