Remove libutils.so dependency from libRSDriver, libRSCpuRef, and most
parts of libRS_internal.
NOTE: we're resolving dependencies to provide a model for vendors.
For us, all this code is above the HAL, thus the dependencies
are acceptable; whereas for vendors, their equivalent of this code is
below the HAL, and so the dependencies are not acceptable.
This CL resolves the libutils dependency by:
- Implement the timings functions in android::renderscript namespace
using NDK APIs, instead of using libutils counterparts.
- Replace android::Vector and android::String8 by std::vector and
std::string.
- PROPERTY_VALUE_MAX is replaced as PROP_VALUE_MAX.
This CL didn't resolve the libutils dependency of rsFont.cpp and
rsDebugger.cpp in libRS_internal:
The dependent functionality in rsDebugHelper.h is off by default, and
only intended for use during development; and rsFont.cpp is part of
graphics API which is not implemented below the HAL and is not used as
a model by vendors.
Additionally, this CL fixed the bug that mNodes was sorted in a
decreasing order. Nodes in ScriptGroup should be executed in
ascending order. The bad sort was only for support lib; so there was a
previously-unknown bug in support lib implementation of ScriptGroup.
Background:
libutils contains a collection of things like Vector, String8,
CallStack. It served the purpose similar to a STL library, when there
was no stable STL implementation available in Android. And most
importantly, it is not part of NDK.
Support lib used to use our own implementations of android::Vector and
android::String8, because it can only depend on NDK, similarly for the
timing related functions.
As part of the Treble requirements, native RS, including vendor version
libRS_internal, libRSDriver, libRSCpuRef could only depend on NDK
too. So we need to break the dependency on libutils. And since we now
have reasonable support of STLs, we should use that instead.
Bug: 34396220
Test: mm, and all CTS tests pass on Bullhead;
RsTest and RSTest_CompatLib (both native and compat path) also pass.
Change-Id: Ib9a37d16235c1dcd0f5bae3b95c374e394483c91
diff --git a/cpu_ref/Android.mk b/cpu_ref/Android.mk
index 5d1b223..d50a77e 100644
--- a/cpu_ref/Android.mk
+++ b/cpu_ref/Android.mk
@@ -83,7 +83,7 @@
rsCpuIntrinsics_x86.cpp
endif
-LOCAL_SHARED_LIBRARIES += libRS_internal libc++ liblog libutils libz
+LOCAL_SHARED_LIBRARIES += libRS_internal libc++ liblog libz
LOCAL_SHARED_LIBRARIES += libbcinfo libblas
LOCAL_STATIC_LIBRARIES := libbnnmlowp
diff --git a/cpu_ref/rsCpuCore.h b/cpu_ref/rsCpuCore.h
index 8c5653f..59e6c4b 100644
--- a/cpu_ref/rsCpuCore.h
+++ b/cpu_ref/rsCpuCore.h
@@ -25,6 +25,8 @@
#include "rsScriptC.h"
#include "rsCpuCoreRuntime.h"
+#include <string>
+
namespace android {
namespace renderscript {
@@ -188,10 +190,10 @@
}
virtual void setBccPluginName(const char *name) {
- mBccPluginName.setTo(name);
+ mBccPluginName.assign(name);
}
virtual const char *getBccPluginName() const {
- return mBccPluginName.string();
+ return mBccPluginName.c_str();
}
bool getInKernel() override { return mInKernel; }
@@ -243,7 +245,7 @@
ScriptTLSStruct mTlsStruct;
RSSelectRTCallback mSelectRTCallback;
- String8 mBccPluginName;
+ std::string mBccPluginName;
// Specifies whether we should embed global variable information in the
// code via special RS variables that can be examined later by the driver.
diff --git a/cpu_ref/rsCpuExecutable.cpp b/cpu_ref/rsCpuExecutable.cpp
index 426d89e..400a465 100644
--- a/cpu_ref/rsCpuExecutable.cpp
+++ b/cpu_ref/rsCpuExecutable.cpp
@@ -165,7 +165,7 @@
return loaded;
}
-String8 SharedLibraryUtils::getRandomString(size_t len) {
+std::string SharedLibraryUtils::getRandomString(size_t len) {
char buf[len + 1];
for (size_t i = 0; i < len; i++) {
uint32_t r = arc4random() & 0xffff;
@@ -182,7 +182,7 @@
}
}
buf[len] = '\0';
- return String8(buf);
+ return std::string(buf);
}
void* SharedLibraryUtils::loadSOHelper(const char *origName, const char *cacheDir,
@@ -237,7 +237,7 @@
newName.append("librs.");
newName.append(resName);
newName.append("#");
- newName.append(getRandomString(6).string()); // 62^6 potential filename variants.
+ newName.append(getRandomString(6).c_str()); // 62^6 potential filename variants.
newName.append(".so");
int r = copyFile(newName.c_str(), origName);
diff --git a/cpu_ref/rsCpuExecutable.h b/cpu_ref/rsCpuExecutable.h
index 90d3759..ee58e37 100644
--- a/cpu_ref/rsCpuExecutable.h
+++ b/cpu_ref/rsCpuExecutable.h
@@ -17,10 +17,12 @@
#ifndef ANDROID_RENDERSCRIPT_EXECUTABLE_H
#define ANDROID_RENDERSCRIPT_EXECUTABLE_H
-#include <stdlib.h>
#include "rsCpuScript.h"
+#include <stdlib.h>
+#include <string>
+
namespace android {
namespace renderscript {
@@ -47,7 +49,7 @@
bool *alreadyLoaded = nullptr);
// Create a len length string containing random characters from [A-Za-z0-9].
- static String8 getRandomString(size_t len);
+ static std::string getRandomString(size_t len);
private:
// Attempt to load the shared library from origName, but then fall back to
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp
index 5bd2424..545e92f 100644
--- a/cpu_ref/rsCpuScript.cpp
+++ b/cpu_ref/rsCpuScript.cpp
@@ -58,7 +58,7 @@
#ifndef RS_COMPATIBILITY_LIB
static bool is_force_recompile() {
- char buf[PROPERTY_VALUE_MAX];
+ char buf[PROP_VALUE_MAX];
// Re-compile if floating point precision has been overridden.
android::renderscript::property_get("debug.rs.precision", buf, "");
@@ -176,7 +176,7 @@
if ((::strcmp(SYSLIBPATH, cacheDir) == 0) ||
(::strcmp(SYSLIBPATH_VENDOR, cacheDir) == 0))
return false;
- char buf[PROPERTY_VALUE_MAX];
+ char buf[PROP_VALUE_MAX];
android::renderscript::property_get("ro.debuggable", buf, "");
return (buf[0] == '1');
}
@@ -422,7 +422,7 @@
}
}
- mBitcodeFilePath.setTo(bcFileName.c_str());
+ mBitcodeFilePath.assign(bcFileName.c_str());
#else // RS_COMPATIBILITY_LIB is defined
const char *nativeLibDir = mCtx->getContext()->getNativeLibDir();
diff --git a/cpu_ref/rsCpuScript.h b/cpu_ref/rsCpuScript.h
index c6f9624..1814d5f 100644
--- a/cpu_ref/rsCpuScript.h
+++ b/cpu_ref/rsCpuScript.h
@@ -26,6 +26,8 @@
#include "rsCpuCore.h"
+#include <string>
+
namespace bcinfo {
class MetadataExtractor;
} // namespace bcinfo
@@ -130,14 +132,14 @@
public:
static const char* BCC_EXE_PATH;
- const char* getBitcodeFilePath() const { return mBitcodeFilePath.string(); }
+ const char* getBitcodeFilePath() const { return mBitcodeFilePath.c_str(); }
private:
bool setUpMtlsDimensions(MTLaunchStructCommon *mtls,
const RsLaunchDimensions &baseDim,
const RsScriptCall *sc);
- String8 mBitcodeFilePath;
+ std::string mBitcodeFilePath;
uint32_t mBuildChecksum;
bool mChecksumNeeded;
};
diff --git a/cpu_ref/rsCpuScriptGroup.cpp b/cpu_ref/rsCpuScriptGroup.cpp
index f7a330a..cc2933c 100644
--- a/cpu_ref/rsCpuScriptGroup.cpp
+++ b/cpu_ref/rsCpuScriptGroup.cpp
@@ -19,6 +19,8 @@
#include "rsScriptGroup.h"
#include "rsCpuScriptGroup.h"
+#include <vector>
+
namespace android {
namespace renderscript {
@@ -124,11 +126,11 @@
void CpuScriptGroupImpl::execute() {
- Vector<Allocation *> ins;
- Vector<bool> inExts;
- Vector<Allocation *> outs;
- Vector<bool> outExts;
- Vector<const ScriptKernelID *> kernels;
+ std::vector<Allocation *> ins;
+ std::vector<uint8_t> inExts;
+ std::vector<Allocation *> outs;
+ std::vector<uint8_t> outExts;
+ std::vector<const ScriptKernelID *> kernels;
bool fieldDep = false;
for (size_t ct=0; ct < mSG->mNodes.size(); ct++) {
@@ -194,11 +196,11 @@
rsAssert((k->mHasKernelOutput == (aout != nullptr)) &&
(k->mHasKernelInput == (ain != nullptr)));
- ins.add(ain);
- inExts.add(inExt);
- outs.add(aout);
- outExts.add(outExt);
- kernels.add(k);
+ ins.push_back(ain);
+ inExts.push_back(inExt);
+ outs.push_back(aout);
+ outExts.push_back(outExt);
+ kernels.push_back(k);
}
}
@@ -237,9 +239,9 @@
}
} else {
ScriptList sl;
- sl.ins = ins.array();
- sl.outs = outs.array();
- sl.kernels = kernels.array();
+ sl.ins = ins.data();
+ sl.outs = outs.data();
+ sl.kernels = kernels.data();
sl.count = kernels.size();
uint32_t inLen;
@@ -254,25 +256,25 @@
ains = const_cast<const Allocation**>(&ins[0]);
}
- Vector<const void *> usrPtrs;
- Vector<const void *> fnPtrs;
- Vector<uint32_t> sigs;
+ std::vector<const void *> usrPtrs;
+ std::vector<const void *> fnPtrs;
+ std::vector<uint32_t> sigs;
for (size_t ct=0; ct < kernels.size(); ct++) {
Script *s = kernels[ct]->mScript;
RsdCpuScriptImpl *si = (RsdCpuScriptImpl *)mCtx->lookupScript(s);
si->forEachKernelSetup(kernels[ct]->mSlot, &mtls);
- fnPtrs.add((void *)mtls.kernel);
- usrPtrs.add(mtls.fep.usr);
- sigs.add(mtls.fep.usrLen);
+ fnPtrs.push_back((void *)mtls.kernel);
+ usrPtrs.push_back(mtls.fep.usr);
+ sigs.push_back(mtls.fep.usrLen);
si->preLaunch(kernels[ct]->mSlot, ains, inLen, outs[ct],
mtls.fep.usr, mtls.fep.usrLen, nullptr);
}
- sl.sigs = sigs.array();
- sl.usrPtrs = usrPtrs.array();
- sl.fnPtrs = fnPtrs.array();
- sl.inExts = inExts.array();
- sl.outExts = outExts.array();
+ sl.sigs = sigs.data();
+ sl.usrPtrs = usrPtrs.data();
+ sl.fnPtrs = fnPtrs.data();
+ sl.inExts = inExts.data();
+ sl.outExts = outExts.data();
Script *s = kernels[0]->mScript;
RsdCpuScriptImpl *si = (RsdCpuScriptImpl *)mCtx->lookupScript(s);
diff --git a/cpu_ref/rsCpuScriptGroup.h b/cpu_ref/rsCpuScriptGroup.h
index a749ea4..7e1386d 100644
--- a/cpu_ref/rsCpuScriptGroup.h
+++ b/cpu_ref/rsCpuScriptGroup.h
@@ -41,9 +41,9 @@
struct ScriptList {
size_t count;
Allocation *const* ins;
- bool const* inExts;
+ uint8_t const* inExts;
Allocation *const* outs;
- bool const* outExts;
+ uint8_t const* outExts;
const void *const* usrPtrs;
size_t const *usrSizes;
uint32_t const *sigs;
diff --git a/cpu_ref/rsCpuScriptGroup2.cpp b/cpu_ref/rsCpuScriptGroup2.cpp
index 9d9929a..a8b72c4 100644
--- a/cpu_ref/rsCpuScriptGroup2.cpp
+++ b/cpu_ref/rsCpuScriptGroup2.cpp
@@ -483,7 +483,7 @@
cloneName.append(resName);
cloneName.append("#");
- cloneName.append(SharedLibraryUtils::getRandomString(6).string());
+ cloneName.append(SharedLibraryUtils::getRandomString(6).c_str());
// The last element in arguments is the output filename.
arguments.pop_back();