diff options
author | Tim Murray <timmurray@google.com> | 2013-12-13 12:54:37 -0800 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2013-12-18 17:09:27 -0800 |
commit | caf4126512b2152ea5f6573ce5d9ca29767b9678 (patch) | |
tree | e9f7c3ec55a27b184a7611bc48ed46f4ee050d7e | |
parent | db5de3870e9818879f1836687a10ce1cf586b38c (diff) | |
download | rs-caf4126512b2152ea5f6573ce5d9ca29767b9678.tar.gz |
Add user-defined cache path.
Change-Id: I7374d8e84d8dc6e74a6faa526c6e68ae11da6500
-rw-r--r-- | cpp/RenderScript.cpp | 13 | ||||
-rw-r--r-- | cpp/ScriptC.cpp | 2 | ||||
-rw-r--r-- | cpp/rsCppStructs.h | 9 | ||||
-rw-r--r-- | java/tests/HelloComputeNDK/libhellocomputendk/helloComputeNDK.cpp | 5 | ||||
-rw-r--r-- | tests/cppallocation/compute.cpp | 2 | ||||
-rw-r--r-- | tests/cppbasic/compute.cpp | 151 | ||||
-rw-r--r-- | tests/cppstrided/compute.cpp | 2 | ||||
-rw-r--r-- | tests/latency/Android.mk | 3 | ||||
-rw-r--r-- | tests/latency/latency.cpp | 2 | ||||
-rw-r--r-- | tests/typecheck/typecheck.cpp | 2 |
10 files changed, 106 insertions, 85 deletions
diff --git a/cpp/RenderScript.cpp b/cpp/RenderScript.cpp index 1da31c75..3a75ffe0 100644 --- a/cpp/RenderScript.cpp +++ b/cpp/RenderScript.cpp @@ -66,8 +66,8 @@ RS::~RS() { } } -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 @@ bool RS::initDispatch(int targetApi) { 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 0d653bd6..69d3bd55 100644 --- a/cpp/ScriptC.cpp +++ b/cpp/ScriptC.cpp @@ -25,6 +25,6 @@ ScriptC::ScriptC(sp<RS> rs, 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 e45e2fb9..0df201b1 100644 --- a/cpp/rsCppStructs.h +++ b/cpp/rsCppStructs.h @@ -90,10 +90,12 @@ class Sampler; /** * 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 @@ class Sampler; 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 @@ class Sampler; MessageHandlerFunc_t mMessageFunc; bool mInit; + std::string mCacheDir; + struct { sp<const Element> U8; sp<const Element> U8_2; @@ -246,6 +250,7 @@ class Sampler; } 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 6ed55893..4985664d 100644 --- a/java/tests/HelloComputeNDK/libhellocomputendk/helloComputeNDK.cpp +++ b/java/tests/HelloComputeNDK/libhellocomputendk/helloComputeNDK.cpp @@ -19,6 +19,7 @@ using namespace android::RSC; 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 @@ Java_com_example_android_rs_hellocomputendk_HelloComputeNDK_nativeMono(JNIEnv * 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/tests/cppallocation/compute.cpp b/tests/cppallocation/compute.cpp index b1d3d386..d1769588 100644 --- a/tests/cppallocation/compute.cpp +++ b/tests/cppallocation/compute.cpp @@ -22,7 +22,7 @@ int main(int argc, char** argv) 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 96aa324a..d93b453c 100644 --- a/tests/cppbasic/compute.cpp +++ b/tests/cppbasic/compute.cpp @@ -8,91 +8,96 @@ using namespace RSC; 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); + { + sp<RS> rs = new RS(); + printf("New RS %p\n", rs.get()); - 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"); + // only legitimate because this is a standalone executable + bool r = rs->init("/system/bin"); + printf("Init returned %i\n", r); - sc->invoke_bar(47, -3, 'c', -7, 14, -8); + sp<const Element> e = Element::RGBA_8888(rs); + printf("Element %p\n", e.get()); - // 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); + tb.setX(128); + tb.setY(128); sp<const Type> t = tb.create(); - sp<Allocation> kern1_in = Allocation::createTyped(rs, t); - sp<Allocation> kern1_out = Allocation::createTyped(rs, t); + 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()); - int *buf = new int[t->getCount()]; + 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); - - rs->finish(); - failed_alloc->copy1DTo(&failed); + 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); + + 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 80e423a4..819bcdca 100644 --- a/tests/cppstrided/compute.cpp +++ b/tests/cppstrided/compute.cpp @@ -23,7 +23,7 @@ int main(int argc, char** argv) 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 83d5ad8b..632ae2f1 100644 --- a/tests/latency/Android.mk +++ b/tests/latency/Android.mk @@ -17,7 +17,8 @@ LOCAL_SHARED_LIBRARIES := \ libui \ libbcc \ libbcinfo \ - libgui + libgui \ + libstlport LOCAL_MODULE:= rstest-latency diff --git a/tests/latency/latency.cpp b/tests/latency/latency.cpp index bea9237e..05337be7 100644 --- a/tests/latency/latency.cpp +++ b/tests/latency/latency.cpp @@ -57,7 +57,7 @@ int main(int argc, char** argv) 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 d50cbf60..76ae16f3 100644 --- a/tests/typecheck/typecheck.cpp +++ b/tests/typecheck/typecheck.cpp @@ -33,7 +33,7 @@ sp<Allocation> createAlloc(sp<RS> rs, sp<const Element> e) { 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); \ |