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

Commit ec6947bb authored by Shih-wei Liao's avatar Shih-wei Liao Committed by Android (Google) Code Review
Browse files

Merge "1. Add Context to a RenderScript or RenderScriptGL instance. This is...

Merge "1. Add Context to a RenderScript or RenderScriptGL instance.    This is to allow RenderScript to better interact with the Android environment.    E.g., per-app cache. 2. Plumbing, testing. 3. Added getApplicationContext in RenderScript.java."
parents 00db2213 6b32fab1
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback
    }

    public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
        RenderScriptGL rs = new RenderScriptGL(sc);
      RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
        setRenderScriptGL(rs);
        return rs;
    }
@@ -137,4 +137,3 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback
        return mRS;
    }
}
+20 −9
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.renderscript;

import java.lang.reflect.Field;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Config;
@@ -42,7 +43,7 @@ public class RenderScript {
    @SuppressWarnings({"UnusedDeclaration", "deprecation"})
    static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;


    private Context mApplicationContext;

    /*
     * We use a class initializer to allow the native code to cache some
@@ -416,9 +417,9 @@ public class RenderScript {
    synchronized void nScriptCSetScript(byte[] script, int offset, int length) {
        rsnScriptCSetScript(mContext, script, offset, length);
    }
    native int  rsnScriptCCreate(int con, String val);
    synchronized int nScriptCCreate(String val) {
        return rsnScriptCCreate(mContext, val);
    native int  rsnScriptCCreate(int con, String val, String cacheDir);
    synchronized int nScriptCCreate(String resName, String cacheDir) {
      return rsnScriptCCreate(mContext, resName, cacheDir);
    }

    native void rsnSamplerBegin(int con);
@@ -776,17 +777,27 @@ public class RenderScript {
        }
    }

    RenderScript() {
    RenderScript(Context ctx) {
        mApplicationContext = ctx.getApplicationContext();
    }

    /**
     * Create a basic RenderScript context.
     * Gets the application context associated with the RenderScript context.
     *
     * @return The application context.
     */
    public final Context getApplicationContext() {
        return mApplicationContext;
    }

    /**
     * Create a basic RenderScript context.
     *
     * @param ctx The context.
     * @return RenderScript
     */
    public static RenderScript create() {
        RenderScript rs = new RenderScript();
    public static RenderScript create(Context ctx) {
        RenderScript rs = new RenderScript(ctx);

        rs.mDev = rs.nDeviceCreate();
        rs.mContext = rs.nContextCreate(rs.mDev, 0);
+4 −4
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.renderscript;

import java.lang.reflect.Field;

import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -168,10 +169,11 @@ public class RenderScriptGL extends RenderScript {
    /**
     * Construct a new RenderScriptGL context.
     *
     *
     * @param ctx The context.
     * @param sc The desired format of the primart rendering surface.
     */
    public RenderScriptGL(SurfaceConfig sc) {
    public RenderScriptGL(Context ctx, SurfaceConfig sc) {
        super(ctx);
        mSurfaceConfig = new SurfaceConfig(sc);

        mSurface = null;
@@ -304,5 +306,3 @@ public class RenderScriptGL extends RenderScript {
    }

}

+4 −1
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@

package android.renderscript;

import android.content.Context;
import android.content.res.Resources;
import android.util.Log;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map.Entry;
@@ -76,6 +78,7 @@ public class ScriptC extends Script {
        rs.nScriptCBegin();
        rs.nScriptCSetScript(pgm, 0, pgmLength);
        Log.v(TAG, "Create script for resource = " + resources.getResourceName(resourceID));
        return rs.nScriptCCreate(resources.getResourceName(resourceID));
        String cacheDir = rs.getApplicationContext().getCacheDir().toString();
        return rs.nScriptCCreate(resources.getResourceName(resourceID), cacheDir);
    }
}
+7 −4
Original line number Diff line number Diff line
@@ -902,11 +902,15 @@ exit:
}

static jint
nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con, jstring resName)
nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con, jstring resName, jstring cacheDir)
{
    LOG_API("nScriptCCreate, con(%p)", con);
    const char* resNameUTF = _env->GetStringUTFChars(resName, NULL);
    return (jint)rsScriptCCreate(con, resNameUTF);
    const char* cacheDirUTF = _env->GetStringUTFChars(cacheDir, NULL);
    jint i = (jint)rsScriptCCreate(con, resNameUTF, cacheDirUTF);
    _env->ReleaseStringUTFChars(resName, resNameUTF);
    _env->ReleaseStringUTFChars(cacheDir, cacheDirUTF);
    return i;
}

// ---------------------------------------------------------------------------
@@ -1297,7 +1301,7 @@ static JNINativeMethod methods[] = {

{"rsnScriptCBegin",                  "(I)V",                                  (void*)nScriptCBegin },
{"rsnScriptCSetScript",              "(I[BII)V",                              (void*)nScriptCSetScript },
{"rsnScriptCCreate",                 "(ILjava/lang/String;)I",                (void*)nScriptCCreate },
{"rsnScriptCCreate",                 "(ILjava/lang/String;Ljava/lang/String;)I",  (void*)nScriptCCreate },

{"rsnProgramStoreBegin",             "(III)V",                                (void*)nProgramStoreBegin },
{"rsnProgramStoreDepthFunc",         "(II)V",                                 (void*)nProgramStoreDepthFunc },
@@ -1372,4 +1376,3 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
bail:
    return result;
}
Loading