diff options
author | Stephen Hines <srhines@google.com> | 2012-09-12 20:44:32 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2012-09-12 20:44:32 -0700 |
commit | d2936939ec10879e25746322db60071f79f28c1b (patch) | |
tree | 30a2677e9954d4a72c86a1b71a9b645175d4046e | |
parent | 529e07e9dece7df93e06932630b483c184933eb8 (diff) | |
download | android_frameworks_compile_slang-d2936939ec10879e25746322db60071f79f28c1b.tar.gz android_frameworks_compile_slang-d2936939ec10879e25746322db60071f79f28c1b.tar.bz2 android_frameworks_compile_slang-d2936939ec10879e25746322db60071f79f28c1b.zip |
Simpler ScriptC constructors
This change replaces the old 3-argument version of reflected ScriptC
constructors with a new single argument (just the RenderScript object).
We can do this safely because there are lookup functions for Resources
and resource IDs directly in the Android API (and accessible via the
RenderScript object). For now, we are still reflecting the legacy version
of the constructor as well, since all existing app source code would be
using it.
Change-Id: I362d6e2bea0f580630b5da9049df029b0f8d7620
-rw-r--r-- | slang_rs_reflection.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/slang_rs_reflection.cpp b/slang_rs_reflection.cpp index f69070c..c781241 100644 --- a/slang_rs_reflection.cpp +++ b/slang_rs_reflection.cpp @@ -61,6 +61,8 @@ #define RS_FP_PREFIX "__rs_fp_" +#define RS_RESOURCE_NAME "__rs_resource_name" + #define RS_EXPORT_FUNC_INDEX_PREFIX "mExportFuncIdx_" #define RS_EXPORT_FOREACH_INDEX_PREFIX "mExportForEachIdx_" @@ -304,11 +306,36 @@ bool RSReflection::genScriptClass(Context &C, } void RSReflection::genScriptClassConstructor(Context &C) { + // Provide a simple way to reference this object. + C.indent() << "private static final String " RS_RESOURCE_NAME " = \"" + << C.getResourceId() + << "\";" << std::endl; + + // Generate a simple constructor with only a single parameter (the rest + // can be inferred from information we already have). C.indent() << "// Constructor" << std::endl; C.startFunction(Context::AM_Public, false, NULL, C.getClassName(), + 1, + "RenderScript", "rs"); + // Call alternate constructor with required parameters. + // Look up the proper raw bitcode resource id via the context. + C.indent() << "this(rs," << std::endl; + C.indent() << " rs.getApplicationContext().getResources()," << std::endl; + C.indent() << " rs.getApplicationContext().getResources()." + "getIdentifier(" << std::endl; + C.indent() << " " RS_RESOURCE_NAME ", \"raw\"," << std::endl; + C.indent() << " rs.getApplicationContext().getPackageName()));" + << std::endl; + C.endFunction(); + + // Alternate constructor (legacy) with 3 original parameters. + C.startFunction(Context::AM_Public, + false, + NULL, + C.getClassName(), 3, "RenderScript", "rs", "Resources", "resources", |