Merge "Add arrays to elements."
This commit is contained in:
committed by
Android (Google) Code Review
commit
65cb3bae15
@@ -27,6 +27,7 @@ public class Element extends BaseObj {
|
||||
int mSize;
|
||||
Element[] mElements;
|
||||
String[] mElementNames;
|
||||
int[] mArraySizes;
|
||||
|
||||
DataType mType;
|
||||
DataKind mKind;
|
||||
@@ -313,11 +314,12 @@ public class Element extends BaseObj {
|
||||
return rs.mElement_MATRIX_2X2;
|
||||
}
|
||||
|
||||
Element(int id, RenderScript rs, Element[] e, String[] n) {
|
||||
Element(int id, RenderScript rs, Element[] e, String[] n, int[] as) {
|
||||
super(id, rs);
|
||||
mSize = 0;
|
||||
mElements = e;
|
||||
mElementNames = n;
|
||||
mArraySizes = as;
|
||||
for (int ct = 0; ct < mElements.length; ct++ ) {
|
||||
mSize += mElements[ct].mSize;
|
||||
}
|
||||
@@ -441,6 +443,7 @@ public class Element extends BaseObj {
|
||||
RenderScript mRS;
|
||||
Element[] mElements;
|
||||
String[] mElementNames;
|
||||
int[] mArraySizes;
|
||||
int mCount;
|
||||
|
||||
public Builder(RenderScript rs) {
|
||||
@@ -448,35 +451,49 @@ public class Element extends BaseObj {
|
||||
mCount = 0;
|
||||
mElements = new Element[8];
|
||||
mElementNames = new String[8];
|
||||
mArraySizes = new int[8];
|
||||
}
|
||||
|
||||
public void add(Element element, String name) {
|
||||
public void add(Element element, String name, int arraySize) {
|
||||
if (arraySize < 1) {
|
||||
throw new IllegalArgumentException("Array size cannot be less than 1.");
|
||||
}
|
||||
if(mCount == mElements.length) {
|
||||
Element[] e = new Element[mCount + 8];
|
||||
String[] s = new String[mCount + 8];
|
||||
int[] as = new int[mCount + 8];
|
||||
System.arraycopy(mElements, 0, e, 0, mCount);
|
||||
System.arraycopy(mElementNames, 0, s, 0, mCount);
|
||||
System.arraycopy(mArraySizes, 0, as, 0, mCount);
|
||||
mElements = e;
|
||||
mElementNames = s;
|
||||
mArraySizes = as;
|
||||
}
|
||||
mElements[mCount] = element;
|
||||
mElementNames[mCount] = name;
|
||||
mArraySizes[mCount] = arraySize;
|
||||
mCount++;
|
||||
}
|
||||
|
||||
public void add(Element element, String name) {
|
||||
add(element, name, 1);
|
||||
}
|
||||
|
||||
public Element create() {
|
||||
mRS.validate();
|
||||
Element[] ein = new Element[mCount];
|
||||
String[] sin = new String[mCount];
|
||||
int[] asin = new int[mCount];
|
||||
java.lang.System.arraycopy(mElements, 0, ein, 0, mCount);
|
||||
java.lang.System.arraycopy(mElementNames, 0, sin, 0, mCount);
|
||||
java.lang.System.arraycopy(mArraySizes, 0, asin, 0, mCount);
|
||||
|
||||
int[] ids = new int[ein.length];
|
||||
for (int ct = 0; ct < ein.length; ct++ ) {
|
||||
ids[ct] = ein[ct].mID;
|
||||
}
|
||||
int id = mRS.nElementCreate2(ids, sin);
|
||||
return new Element(id, mRS, ein, sin);
|
||||
int id = mRS.nElementCreate2(ids, sin, asin);
|
||||
return new Element(id, mRS, ein, sin, asin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -152,9 +152,9 @@ public class RenderScript {
|
||||
synchronized int nElementCreate(int type, int kind, boolean norm, int vecSize) {
|
||||
return rsnElementCreate(mContext, type, kind, norm, vecSize);
|
||||
}
|
||||
native int rsnElementCreate2(int con, int[] elements, String[] names);
|
||||
synchronized int nElementCreate2(int[] elements, String[] names) {
|
||||
return rsnElementCreate2(mContext, elements, names);
|
||||
native int rsnElementCreate2(int con, int[] elements, String[] names, int[] arraySizes);
|
||||
synchronized int nElementCreate2(int[] elements, String[] names, int[] arraySizes) {
|
||||
return rsnElementCreate2(mContext, elements, names, arraySizes);
|
||||
}
|
||||
native void rsnElementGetNativeData(int con, int id, int[] elementData);
|
||||
synchronized void nElementGetNativeData(int id, int[] elementData) {
|
||||
|
||||
@@ -253,12 +253,13 @@ nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind,
|
||||
}
|
||||
|
||||
static jint
|
||||
nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, jintArray _ids, jobjectArray _names)
|
||||
nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, jintArray _ids, jobjectArray _names, jintArray _arraySizes)
|
||||
{
|
||||
int fieldCount = _env->GetArrayLength(_ids);
|
||||
LOG_API("nElementCreate2, con(%p)", con);
|
||||
|
||||
jint *ids = _env->GetIntArrayElements(_ids, NULL);
|
||||
jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
|
||||
const char ** nameArray = (const char **)calloc(fieldCount, sizeof(char *));
|
||||
size_t* sizeArray = (size_t*)calloc(fieldCount, sizeof(size_t));
|
||||
|
||||
@@ -267,12 +268,13 @@ nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, jintArray _ids, jobj
|
||||
nameArray[ct] = _env->GetStringUTFChars(s, NULL);
|
||||
sizeArray[ct] = _env->GetStringUTFLength(s);
|
||||
}
|
||||
jint id = (jint)rsElementCreate2(con, fieldCount, (RsElement *)ids, nameArray, sizeArray);
|
||||
jint id = (jint)rsElementCreate2(con, fieldCount, (RsElement *)ids, nameArray, sizeArray, (const uint32_t *)arraySizes);
|
||||
for (int ct=0; ct < fieldCount; ct++) {
|
||||
jstring s = (jstring)_env->GetObjectArrayElement(_names, ct);
|
||||
_env->ReleaseStringUTFChars(s, nameArray[ct]);
|
||||
}
|
||||
_env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
|
||||
_env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
|
||||
free(nameArray);
|
||||
free(sizeArray);
|
||||
return (jint)id;
|
||||
@@ -1230,7 +1232,7 @@ static JNINativeMethod methods[] = {
|
||||
{"rsnFontCreateFromFile", "(ILjava/lang/String;II)I", (void*)nFontCreateFromFile },
|
||||
|
||||
{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
|
||||
{"rsnElementCreate2", "(I[I[Ljava/lang/String;)I", (void*)nElementCreate2 },
|
||||
{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
|
||||
{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
|
||||
{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;)V", (void*)nElementGetSubElements },
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@ ElementCreate2 {
|
||||
param const RsElement * elements
|
||||
param const char ** names
|
||||
param const size_t * nameLengths
|
||||
param const uint32_t * arraySize
|
||||
ret RsElement
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ size_t Element::getSizeBits() const
|
||||
|
||||
size_t total = 0;
|
||||
for (size_t ct=0; ct < mFieldCount; ct++) {
|
||||
total += mFields[ct].e->mBits;
|
||||
total += mFields[ct].e->mBits * mFields[ct].arraySize;;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
@@ -95,6 +95,7 @@ void Element::serialize(OStream *stream) const
|
||||
stream->addU32(mFieldCount);
|
||||
for(uint32_t ct = 0; ct < mFieldCount; ct++) {
|
||||
stream->addString(&mFields[ct].name);
|
||||
stream->addU32(mFields[ct].arraySize);
|
||||
mFields[ct].e->serialize(stream);
|
||||
}
|
||||
}
|
||||
@@ -122,6 +123,7 @@ Element *Element::createFromStream(Context *rsc, IStream *stream)
|
||||
elem->mFields = new ElementField_t [elem->mFieldCount];
|
||||
for(uint32_t ct = 0; ct < elem->mFieldCount; ct ++) {
|
||||
stream->loadString(&elem->mFields[ct].name);
|
||||
elem->mFields[ct].arraySize = stream->loadU32();
|
||||
Element *fieldElem = Element::createFromStream(rsc, stream);
|
||||
elem->mFields[ct].e.set(fieldElem);
|
||||
elem->mFields[ct].offsetBits = offset;
|
||||
@@ -155,7 +157,8 @@ Element *Element::createFromStream(Context *rsc, IStream *stream)
|
||||
for (uint32_t i=0; i < elem->mFieldCount; i++) {
|
||||
if ((ee->mFields[i].e.get() != elem->mFields[i].e.get()) ||
|
||||
(ee->mFields[i].name.length() != elem->mFields[i].name.length()) ||
|
||||
(ee->mFields[i].name != elem->mFields[i].name)) {
|
||||
(ee->mFields[i].name != elem->mFields[i].name) ||
|
||||
(ee->mFields[i].arraySize != elem->mFields[i].arraySize)) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
@@ -200,7 +203,7 @@ const Element * Element::create(Context *rsc, RsDataType dt, RsDataKind dk,
|
||||
}
|
||||
|
||||
const Element * Element::create(Context *rsc, size_t count, const Element **ein,
|
||||
const char **nin, const size_t * lengths)
|
||||
const char **nin, const size_t * lengths, const uint32_t *asin)
|
||||
{
|
||||
// Look for an existing match.
|
||||
for (uint32_t ct=0; ct < rsc->mStateElement.mElements.size(); ct++) {
|
||||
@@ -210,7 +213,8 @@ const Element * Element::create(Context *rsc, size_t count, const Element **ein,
|
||||
for (uint32_t i=0; i < count; i++) {
|
||||
if ((ee->mFields[i].e.get() != ein[i]) ||
|
||||
(ee->mFields[i].name.length() != lengths[i]) ||
|
||||
(ee->mFields[i].name != nin[i])) {
|
||||
(ee->mFields[i].name != nin[i]) ||
|
||||
(ee->mFields[i].arraySize != asin[i])) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
@@ -230,6 +234,7 @@ const Element * Element::create(Context *rsc, size_t count, const Element **ein,
|
||||
e->mFields[ct].e.set(ein[ct]);
|
||||
e->mFields[ct].name.setTo(nin[ct], lengths[ct]);
|
||||
e->mFields[ct].offsetBits = bits;
|
||||
e->mFields[ct].arraySize = asin[ct];
|
||||
bits += ein[ct]->getSizeBits();
|
||||
|
||||
if (ein[ct]->mHasReference) {
|
||||
@@ -274,7 +279,11 @@ void Element::incRefs(const void *ptr) const
|
||||
const uint8_t *p = static_cast<const uint8_t *>(ptr);
|
||||
for (uint32_t i=0; i < mFieldCount; i++) {
|
||||
if (mFields[i].e->mHasReference) {
|
||||
mFields[i].e->incRefs(&p[mFields[i].offsetBits >> 3]);
|
||||
p = &p[mFields[i].offsetBits >> 3];
|
||||
for (uint32_t ct=0; ct < mFields[i].arraySize; ct++) {
|
||||
mFields[i].e->incRefs(p);
|
||||
p += mFields[i].e->getSizeBytes();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -293,7 +302,11 @@ void Element::decRefs(const void *ptr) const
|
||||
const uint8_t *p = static_cast<const uint8_t *>(ptr);
|
||||
for (uint32_t i=0; i < mFieldCount; i++) {
|
||||
if (mFields[i].e->mHasReference) {
|
||||
mFields[i].e->decRefs(&p[mFields[i].offsetBits >> 3]);
|
||||
p = &p[mFields[i].offsetBits >> 3];
|
||||
for (uint32_t ct=0; ct < mFields[i].arraySize; ct++) {
|
||||
mFields[i].e->decRefs(p);
|
||||
p += mFields[i].e->getSizeBytes();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -331,10 +344,11 @@ RsElement rsi_ElementCreate2(Context *rsc,
|
||||
size_t count,
|
||||
const RsElement * ein,
|
||||
const char ** names,
|
||||
const size_t * nameLengths)
|
||||
const size_t * nameLengths,
|
||||
const uint32_t * arraySizes)
|
||||
{
|
||||
//LOGE("rsi_ElementCreate2 %i", count);
|
||||
const Element *e = Element::create(rsc, count, (const Element **)ein, names, nameLengths);
|
||||
const Element *e = Element::create(rsc, count, (const Element **)ein, names, nameLengths, arraySizes);
|
||||
e->incUserRef();
|
||||
return (RsElement)e;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
static const Element * create(Context *rsc, RsDataType dt, RsDataKind dk,
|
||||
bool isNorm, uint32_t vecSize);
|
||||
static const Element * create(Context *rsc, size_t count, const Element **,
|
||||
const char **, const size_t * lengths);
|
||||
const char **, const size_t * lengths, const uint32_t *asin);
|
||||
|
||||
void incRefs(const void *) const;
|
||||
void decRefs(const void *) const;
|
||||
@@ -80,6 +80,7 @@ protected:
|
||||
String8 name;
|
||||
ObjectBaseRef<const Element> e;
|
||||
uint32_t offsetBits;
|
||||
uint32_t arraySize;
|
||||
} ElementField_t;
|
||||
ElementField_t *mFields;
|
||||
size_t mFieldCount;
|
||||
|
||||
@@ -488,8 +488,9 @@ void FontState::initVertexArrayBuffers()
|
||||
size_t lengths[2];
|
||||
lengths[0] = posName.size();
|
||||
lengths[1] = texName.size();
|
||||
uint32_t arraySizes[2] = {1, 1};
|
||||
|
||||
const Element *vertexDataElem = Element::create(mRSC, 2, elemArray, nameArray, lengths);
|
||||
const Element *vertexDataElem = Element::create(mRSC, 2, elemArray, nameArray, lengths, arraySizes);
|
||||
|
||||
Type *vertexDataType = new Type(mRSC);
|
||||
vertexDataType->setDimX(mMaxNumberOfQuads * 4);
|
||||
|
||||
Reference in New Issue
Block a user