am 3f980f09: Merge changes I7374d8e8,Ie344b3db

* commit '3f980f092a533a6d2d396b9edead15acee24c4c3':
  Add user-defined cache path.
  Fix HelloComputeNDK for RS NDK API update.
diff --git a/cpp/RenderScript.cpp b/cpp/RenderScript.cpp
index 1da31c7..3a75ffe 100644
--- a/cpp/RenderScript.cpp
+++ b/cpp/RenderScript.cpp
@@ -66,8 +66,8 @@
     }
 }
 
-bool RS::init(uint32_t flags) {
-    return RS::init(RS_VERSION, flags);
+bool RS::init(std::string name, uint32_t flags) {
+    return RS::init(name, RS_VERSION, flags);
 }
 
 static bool loadSymbols(void* handle) {
@@ -462,12 +462,19 @@
     return false;
 }
 
-bool RS::init(int targetApi, uint32_t flags) {
+bool RS::init(std::string &name, int targetApi, uint32_t flags) {
+    if (mInit) {
+        return true;
+    }
+
     if (initDispatch(targetApi) == false) {
         ALOGE("Couldn't initialize dispatch table");
         return false;
     }
 
+    mCacheDir = name;
+    mCacheDir += "/com.android.renderscript.cache/";
+
     mDev = RS::dispatch->DeviceCreate();
     if (mDev == 0) {
         ALOGE("Device creation failed");
diff --git a/cpp/ScriptC.cpp b/cpp/ScriptC.cpp
index 0d653bd..69d3bd5 100644
--- a/cpp/ScriptC.cpp
+++ b/cpp/ScriptC.cpp
@@ -25,6 +25,6 @@
                  const char *cacheDir, size_t cacheDirLength)
 : Script(NULL, rs) {
     mID = RS::dispatch->ScriptCCreate(rs->getContext(), cachedName, cachedNameLength,
-                                      cacheDir, cacheDirLength, (const char *)codeTxt, codeLength);
+                                      rs->mCacheDir.c_str(), rs->mCacheDir.length(), (const char *)codeTxt, codeLength);
 }
 
diff --git a/cpp/rsCppStructs.h b/cpp/rsCppStructs.h
index e45e2fb..0df201b 100644
--- a/cpp/rsCppStructs.h
+++ b/cpp/rsCppStructs.h
@@ -90,10 +90,12 @@
 
     /**
      * Initializes a RenderScript context. A context must be initialized before it can be used.
+     * @param[in] name Directory name to be used by this context. This should be equivalent to
+     * Context.getCacheDir().
      * @param[in] flags Optional flags for this context.
      * @return true on success
      */
-    bool init(uint32_t flags = 0);
+    bool init(std::string name, uint32_t flags = 0);
 
     /**
      * Sets the error handler function for this context. This error handler is
@@ -147,7 +149,7 @@
     static bool usingNative;
     static bool initDispatch(int targetApi);
 
-    bool init(int targetApi, uint32_t flags);
+    bool init(std::string &name, int targetApi, uint32_t flags);
     static void * threadProc(void *);
 
     static bool gInitialized;
@@ -165,6 +167,8 @@
     MessageHandlerFunc_t mMessageFunc;
     bool mInit;
 
+    std::string mCacheDir;
+
     struct {
         sp<const Element> U8;
         sp<const Element> U8_2;
@@ -246,6 +250,7 @@
     } mSamplers;
     friend class Sampler;
     friend class Element;
+    friend class ScriptC;
 };
 
  /**
diff --git a/java/tests/HelloComputeNDK/libhellocomputendk/helloComputeNDK.cpp b/java/tests/HelloComputeNDK/libhellocomputendk/helloComputeNDK.cpp
index 6ed5589..4985664 100644
--- a/java/tests/HelloComputeNDK/libhellocomputendk/helloComputeNDK.cpp
+++ b/java/tests/HelloComputeNDK/libhellocomputendk/helloComputeNDK.cpp
@@ -19,6 +19,7 @@
 extern "C" JNIEXPORT void JNICALL
 Java_com_example_android_rs_hellocomputendk_HelloComputeNDK_nativeMono(JNIEnv * env,
                                                                        jclass,
+                                                                       jstring pathObj,
                                                                        jint X,
                                                                        jint Y,
                                                                        jobject jbitmapIn,
@@ -32,8 +33,10 @@
     AndroidBitmap_lockPixels(env, jbitmapIn, &inputPtr);
     AndroidBitmap_lockPixels(env, jbitmapOut, &outputPtr);
 
+    const char * path = env->GetStringUTFChars(pathObj, NULL);
     sp<RS> rs = new RS();
-    rs->init();
+    rs->init(path);
+    env->ReleaseStringUTFChars(pathObj, path);
 
     sp<const Element> e = Element::RGBA_8888(rs);
 
diff --git a/java/tests/HelloComputeNDK/src/com/example/android/rs/hellocomputendk/HelloComputeNDK.java b/java/tests/HelloComputeNDK/src/com/example/android/rs/hellocomputendk/HelloComputeNDK.java
index aec6497..87ef646 100644
--- a/java/tests/HelloComputeNDK/src/com/example/android/rs/hellocomputendk/HelloComputeNDK.java
+++ b/java/tests/HelloComputeNDK/src/com/example/android/rs/hellocomputendk/HelloComputeNDK.java
@@ -30,7 +30,7 @@
         System.loadLibrary("hellocomputendk");
     }
 
-    native void nativeMono(int X, int Y, Bitmap in, Bitmap out);
+    native void nativeMono(String cacheDir, int X, int Y, Bitmap in, Bitmap out);
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -47,7 +47,9 @@
         ImageView out = (ImageView) findViewById(R.id.displayout);
         out.setImageBitmap(mBitmapOut);
 
-        nativeMono(mBitmapIn.getWidth(), mBitmapIn.getHeight(), mBitmapIn, mBitmapOut);
+        nativeMono(this.getCacheDir().toString(),
+                   mBitmapIn.getWidth(), mBitmapIn.getHeight(),
+                   mBitmapIn, mBitmapOut);
 
     }
 
diff --git a/tests/cppallocation/compute.cpp b/tests/cppallocation/compute.cpp
index b1d3d38..d176958 100644
--- a/tests/cppallocation/compute.cpp
+++ b/tests/cppallocation/compute.cpp
@@ -22,7 +22,7 @@
 
     sp<RS> rs = new RS();
 
-    bool r = rs->init();
+    bool r = rs->init("/system/bin");
 
     sp<const Element> e = Element::U32(rs);
 
diff --git a/tests/cppbasic/compute.cpp b/tests/cppbasic/compute.cpp
index 96aa324..d93b453 100644
--- a/tests/cppbasic/compute.cpp
+++ b/tests/cppbasic/compute.cpp
@@ -8,91 +8,96 @@
 
 int test_compute()
 {
-    sp<RS> rs = new RS();
-    printf("New RS %p\n", rs.get());
-
-    bool r = rs->init();
-    printf("Init returned %i\n", r);
-
-    sp<const Element> e = Element::RGBA_8888(rs);
-    printf("Element %p\n", e.get());
-
-    Type::Builder tb(rs, e);
-    tb.setX(128);
-    tb.setY(128);
-    sp<const Type> t = tb.create();
-    printf("Type %p\n", t.get());
-
-
-    sp<Allocation> a1 = Allocation::createSized(rs, e, 1000);
-    printf("Allocation %p\n", a1.get());
-
-    sp<Allocation> ain = Allocation::createTyped(rs, t);
-    sp<Allocation> aout = Allocation::createTyped(rs, t);
-    printf("Allocation %p %p\n", ain.get(), aout.get());
-
-    sp<ScriptC_mono> sc = new ScriptC_mono(rs);
-    printf("new script\n");
-
-    sc->set_alloc(a1);
-    sc->set_elem(e);
-    sc->set_type(t);
-    sc->set_script(sc);
-    sc->set_script(NULL);
-    sp<const Sampler> samp = Sampler::CLAMP_NEAREST(rs);
-    sc->set_sampler(samp);
-
-    // We read back the status from the script-side via a "failed" allocation.
-    sp<const Element> failed_e = Element::BOOLEAN(rs);
-    Type::Builder failed_tb(rs, failed_e);
-    failed_tb.setX(1);
-    sp<const Type> failed_t = failed_tb.create();
-    sp<Allocation> failed_alloc = Allocation::createTyped(rs, failed_t);
     bool failed = false;
-    failed_alloc->copy1DRangeFrom(0, failed_t->getCount(), &failed);
-    sc->bind_failed(failed_alloc);
 
-    uint32_t *buf = new uint32_t[t->getCount()];
-    for (uint32_t ct=0; ct < t->getCount(); ct++) {
-        buf[ct] = ct | (ct << 16);
-    }
-    ain->copy1DRangeFrom(0, t->getCount(), buf);
-    delete [] buf;
-
-    sc->forEach_root(ain, aout);
-
-    sc->invoke_foo(99, 3.1f);
-    sc->set_g_f(39.9f);
-    sc->set_g_i(-14);
-    sc->invoke_foo(99, 3.1f);
-    printf("for each done\n");
-
-    sc->invoke_bar(47, -3, 'c', -7, 14, -8);
-
-    // Verify a simple kernel.
     {
-        static const uint32_t xDim = 7;
-        static const uint32_t yDim = 7;
-        sp<const Element> e = Element::I32(rs);
-        Type::Builder tb(rs, e);
-        tb.setX(xDim);
-        tb.setY(yDim);
-        sp<const Type> t = tb.create();
-        sp<Allocation> kern1_in = Allocation::createTyped(rs, t);
-        sp<Allocation> kern1_out = Allocation::createTyped(rs, t);
+        sp<RS> rs = new RS();
+        printf("New RS %p\n", rs.get());
 
-        int *buf = new int[t->getCount()];
+        // only legitimate because this is a standalone executable
+        bool r = rs->init("/system/bin");
+        printf("Init returned %i\n", r);
+
+        sp<const Element> e = Element::RGBA_8888(rs);
+        printf("Element %p\n", e.get());
+
+        Type::Builder tb(rs, e);
+        tb.setX(128);
+        tb.setY(128);
+        sp<const Type> t = tb.create();
+        printf("Type %p\n", t.get());
+
+
+        sp<Allocation> a1 = Allocation::createSized(rs, e, 1000);
+        printf("Allocation %p\n", a1.get());
+
+        sp<Allocation> ain = Allocation::createTyped(rs, t);
+        sp<Allocation> aout = Allocation::createTyped(rs, t);
+        printf("Allocation %p %p\n", ain.get(), aout.get());
+
+        sp<ScriptC_mono> sc = new ScriptC_mono(rs);
+        printf("new script\n");
+
+        sc->set_alloc(a1);
+        sc->set_elem(e);
+        sc->set_type(t);
+        sc->set_script(sc);
+        sc->set_script(NULL);
+        sp<const Sampler> samp = Sampler::CLAMP_NEAREST(rs);
+        sc->set_sampler(samp);
+
+        // We read back the status from the script-side via a "failed" allocation.
+        sp<const Element> failed_e = Element::BOOLEAN(rs);
+        Type::Builder failed_tb(rs, failed_e);
+        failed_tb.setX(1);
+        sp<const Type> failed_t = failed_tb.create();
+        sp<Allocation> failed_alloc = Allocation::createTyped(rs, failed_t);
+
+        failed_alloc->copy1DRangeFrom(0, failed_t->getCount(), &failed);
+        sc->bind_failed(failed_alloc);
+
+        uint32_t *buf = new uint32_t[t->getCount()];
         for (uint32_t ct=0; ct < t->getCount(); ct++) {
-            buf[ct] = 5;
+            buf[ct] = ct | (ct << 16);
         }
-        kern1_in->copy2DRangeFrom(0, 0, xDim, yDim, buf);
+        ain->copy1DRangeFrom(0, t->getCount(), buf);
         delete [] buf;
 
-        sc->forEach_kern1(kern1_in, kern1_out);
-        sc->forEach_verify_kern1(kern1_out);
+        sc->forEach_root(ain, aout);
 
-        rs->finish();
-        failed_alloc->copy1DTo(&failed);
+        sc->invoke_foo(99, 3.1f);
+        sc->set_g_f(39.9f);
+        sc->set_g_i(-14);
+        sc->invoke_foo(99, 3.1f);
+        printf("for each done\n");
+
+        sc->invoke_bar(47, -3, 'c', -7, 14, -8);
+
+        // Verify a simple kernel.
+        {
+            static const uint32_t xDim = 7;
+            static const uint32_t yDim = 7;
+            sp<const Element> e = Element::I32(rs);
+            Type::Builder tb(rs, e);
+            tb.setX(xDim);
+            tb.setY(yDim);
+            sp<const Type> t = tb.create();
+            sp<Allocation> kern1_in = Allocation::createTyped(rs, t);
+            sp<Allocation> kern1_out = Allocation::createTyped(rs, t);
+
+            int *buf = new int[t->getCount()];
+            for (uint32_t ct=0; ct < t->getCount(); ct++) {
+                buf[ct] = 5;
+            }
+            kern1_in->copy2DRangeFrom(0, 0, xDim, yDim, buf);
+            delete [] buf;
+
+            sc->forEach_kern1(kern1_in, kern1_out);
+            sc->forEach_verify_kern1(kern1_out);
+
+            rs->finish();
+            failed_alloc->copy1DTo(&failed);
+        }
     }
 
     return failed;
diff --git a/tests/cppstrided/compute.cpp b/tests/cppstrided/compute.cpp
index 80e423a..819bcdc 100644
--- a/tests/cppstrided/compute.cpp
+++ b/tests/cppstrided/compute.cpp
@@ -23,7 +23,7 @@
 
     sp<RS> rs = new RS();
 
-    bool r = rs->init();
+    bool r = rs->init("/system/bin");
 
     sp<const Element> e = Element::U32(rs);
 
diff --git a/tests/latency/Android.mk b/tests/latency/Android.mk
index 83d5ad8..632ae2f 100644
--- a/tests/latency/Android.mk
+++ b/tests/latency/Android.mk
@@ -17,7 +17,8 @@
 	libui \
 	libbcc \
 	libbcinfo \
-	libgui
+	libgui \
+	libstlport
 
 LOCAL_MODULE:= rstest-latency
 
diff --git a/tests/latency/latency.cpp b/tests/latency/latency.cpp
index bea9237..05337be 100644
--- a/tests/latency/latency.cpp
+++ b/tests/latency/latency.cpp
@@ -57,7 +57,7 @@
     if (forceCpu) flags |= RS_INIT_LOW_LATENCY;
     if (synchronous) flags |= RS_INIT_SYNCHRONOUS;
 
-    bool r = rs->init(flags);
+    bool r = rs->init("/system/bin", flags);
 
     sp<const Element> e = Element::U32(rs);
 
diff --git a/tests/typecheck/typecheck.cpp b/tests/typecheck/typecheck.cpp
index d50cbf6..76ae16f 100644
--- a/tests/typecheck/typecheck.cpp
+++ b/tests/typecheck/typecheck.cpp
@@ -33,7 +33,7 @@
 bool test_elem_##KERNELNAME##_##ENAME() { \
     printf("Verifying forEach_test_" #KERNELNAME "() with " #ENAME "\n"); \
     sp<RS> rs = new RS(); \
-    bool r = rs->init(); \
+    bool r = rs->init("/system/bin"); \
     sp<Allocation> a = createAlloc(rs, Element::ENAME(rs)); \
     ScriptC_kernels sc(rs); \
     sc.forEach_test_##KERNELNAME(a); \