Merge "Allow developers to specify a target RS API level for C++"
diff --git a/cpp/RenderScript.cpp b/cpp/RenderScript.cpp
index e0be0a6..5ee3060 100644
--- a/cpp/RenderScript.cpp
+++ b/cpp/RenderScript.cpp
@@ -75,10 +75,6 @@
}
}
-bool RS::init(const char * name, uint32_t flags) {
- return RS::init(name, RS_VERSION, flags);
-}
-
// This will only open API 19+ libRS, because that's when
// we changed libRS to extern "C" entry points.
static bool loadSO(const char* filename, int targetApi) {
@@ -139,10 +135,15 @@
return false;
}
-bool RS::init(const char * name, int targetApi, uint32_t flags) {
+bool RS::init(const char * name, uint32_t flags, int targetApi) {
if (mInit) {
return true;
}
+ // When using default value 0, set targetApi to RS_VERSION,
+ // to preserve the behavior of existing apps.
+ if (targetApi == 0) {
+ targetApi = RS_VERSION;
+ }
if (initDispatch(targetApi) == false) {
ALOGE("Couldn't initialize dispatch table");
diff --git a/cpp/rsCppStructs.h b/cpp/rsCppStructs.h
index 3f83ba1..5978226 100644
--- a/cpp/rsCppStructs.h
+++ b/cpp/rsCppStructs.h
@@ -371,9 +371,10 @@
* @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.
+ * @param[in] targetApi Optional target RS API level. (Default 0: Using the latest SDK/Platform API).
* @return true on success
*/
- bool init(const char * name, uint32_t flags = 0);
+ bool init(const char * name, uint32_t flags = 0, int targetApi = 0);
/**
* Sets the error handler function for this context. This error handler is
@@ -427,7 +428,6 @@
static bool usingNative;
static bool initDispatch(int targetApi);
- bool init(const char * name, int targetApi, uint32_t flags);
static void * threadProc(void *);
static bool gInitialized;