Removed last bits of predefined element types from native code. Predefined types are now constructed at the java layer from standard building blocks.
diff --git a/RenderScript.h b/RenderScript.h
index fe68511..87a2f4a 100644
--- a/RenderScript.h
+++ b/RenderScript.h
@@ -90,32 +90,6 @@
RS_KIND_POINT_SIZE
};
-enum RsElementPredefined {
- RS_ELEMENT_USER_U8,
- RS_ELEMENT_USER_I8,
- RS_ELEMENT_USER_U16,
- RS_ELEMENT_USER_I16,
- RS_ELEMENT_USER_U32,
- RS_ELEMENT_USER_I32,
- RS_ELEMENT_USER_FLOAT,
-
- RS_ELEMENT_A_8, // 7
- RS_ELEMENT_RGB_565, // 8
- RS_ELEMENT_RGBA_5551, // 9
- RS_ELEMENT_RGBA_4444, // 10
- RS_ELEMENT_RGB_888, // 11
- RS_ELEMENT_RGBA_8888, // 12
-
- RS_ELEMENT_INDEX_16, //13
- RS_ELEMENT_INDEX_32,
- RS_ELEMENT_XY_F32,
- RS_ELEMENT_XYZ_F32,
- RS_ELEMENT_ST_XY_F32,
- RS_ELEMENT_ST_XYZ_F32,
- RS_ELEMENT_NORM_XYZ_F32,
- RS_ELEMENT_NORM_ST_XYZ_F32,
-};
-
enum RsSamplerParam {
RS_SAMPLER_MIN_FILTER,
RS_SAMPLER_MAG_FILTER,
diff --git a/rs.spec b/rs.spec
index a6eb467..8cdf2b7 100644
--- a/rs.spec
+++ b/rs.spec
@@ -55,11 +55,6 @@
ret RsElement
}
-ElementGetPredefined {
- param RsElementPredefined predef
- ret RsElement
- }
-
TypeBegin {
param RsElement type
}
@@ -78,24 +73,12 @@
ret RsAllocation
}
-AllocationCreatePredefSized {
- param RsElementPredefined predef
- param size_t count
- ret RsAllocation
- }
-
AllocationCreateSized {
param RsElement e
param size_t count
ret RsAllocation
}
-AllocationCreateFromFile {
- param const char *file
- param bool genMips
- ret RsAllocation
- }
-
AllocationCreateFromBitmap {
param uint32_t width
param uint32_t height
diff --git a/rsAllocation.cpp b/rsAllocation.cpp
index c267e16..cb82624 100644
--- a/rsAllocation.cpp
+++ b/rsAllocation.cpp
@@ -191,12 +191,6 @@
return alloc;
}
-RsAllocation rsi_AllocationCreatePredefSized(Context *rsc, RsElementPredefined t, size_t count)
-{
- RsElement e = rsi_ElementGetPredefined(rsc, t);
- return rsi_AllocationCreateSized(rsc, e, count);
-}
-
RsAllocation rsi_AllocationCreateSized(Context *rsc, RsElement e, size_t count)
{
Type * type = new Type();
@@ -421,116 +415,6 @@
}
-
-RsAllocation rsi_AllocationCreateFromFile(Context *rsc, const char *file, bool genMips)
-{
- bool use32bpp = false;
-
- typedef struct _Win3xBitmapHeader
- {
- uint16_t type;
- uint32_t totalSize;
- uint32_t reserved;
- uint32_t offset;
- int32_t hdrSize; /* Size of this header in bytes */
- int32_t width; /* Image width in pixels */
- int32_t height; /* Image height in pixels */
- int16_t planes; /* Number of color planes */
- int16_t bpp; /* Number of bits per pixel */
- /* Fields added for Windows 3.x follow this line */
- int32_t compression; /* Compression methods used */
- int32_t sizeOfBitmap; /* Size of bitmap in bytes */
- int32_t horzResolution; /* Horizontal resolution in pixels per meter */
- int32_t vertResolution; /* Vertical resolution in pixels per meter */
- int32_t colorsUsed; /* Number of colors in the image */
- int32_t colorsImportant; /* Minimum number of important colors */
- } __attribute__((__packed__)) WIN3XBITMAPHEADER;
-
- _Win3xBitmapHeader hdr;
-
- FILE *f = fopen(file, "rb");
- if (f == NULL) {
- LOGE("rsAllocationCreateFromBitmap failed to open file %s", file);
- return NULL;
- }
- memset(&hdr, 0, sizeof(hdr));
- fread(&hdr, sizeof(hdr), 1, f);
-
- if (hdr.bpp != 24) {
- LOGE("Unsuported BMP type");
- fclose(f);
- return NULL;
- }
-
- int32_t texWidth = rsHigherPow2(hdr.width);
- int32_t texHeight = rsHigherPow2(hdr.height);
-
- if (use32bpp) {
- rsi_TypeBegin(rsc, rsi_ElementGetPredefined(rsc, RS_ELEMENT_RGBA_8888));
- } else {
- rsi_TypeBegin(rsc, rsi_ElementGetPredefined(rsc, RS_ELEMENT_RGB_565));
- }
- rsi_TypeAdd(rsc, RS_DIMENSION_X, texWidth);
- rsi_TypeAdd(rsc, RS_DIMENSION_Y, texHeight);
- if (genMips) {
- rsi_TypeAdd(rsc, RS_DIMENSION_LOD, 1);
- }
- RsType type = rsi_TypeCreate(rsc);
-
- RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, type);
- Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
- texAlloc->incUserRef();
- if (texAlloc == NULL) {
- LOGE("Memory allocation failure");
- fclose(f);
- return NULL;
- }
-
- // offset to letterbox if height is not pow2
- Adapter2D adapt(texAlloc);
- uint8_t * fileInBuf = new uint8_t[texWidth * 3];
- uint32_t yOffset = (hdr.width - hdr.height) / 2;
-
- if (use32bpp) {
- uint8_t *tmp = static_cast<uint8_t *>(adapt.getElement(0, yOffset));
- for (int y=0; y < hdr.height; y++) {
- fseek(f, hdr.offset + (y*hdr.width*3), SEEK_SET);
- fread(fileInBuf, 1, hdr.width * 3, f);
- for(int x=0; x < hdr.width; x++) {
- tmp[0] = fileInBuf[x*3 + 2];
- tmp[1] = fileInBuf[x*3 + 1];
- tmp[2] = fileInBuf[x*3];
- tmp[3] = 0xff;
- tmp += 4;
- }
- }
- } else {
- uint16_t *tmp = static_cast<uint16_t *>(adapt.getElement(0, yOffset));
- for (int y=0; y < hdr.height; y++) {
- fseek(f, hdr.offset + (y*hdr.width*3), SEEK_SET);
- fread(fileInBuf, 1, hdr.width * 3, f);
- for(int x=0; x < hdr.width; x++) {
- *tmp = rs888to565(fileInBuf[x*3 + 2], fileInBuf[x*3 + 1], fileInBuf[x*3]);
- tmp++;
- }
- }
- }
-
- fclose(f);
- delete [] fileInBuf;
-
- if (genMips) {
- Adapter2D adapt2(texAlloc);
- for(uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) {
- adapt.setLOD(lod);
- adapt2.setLOD(lod + 1);
- mip(adapt2, adapt);
- }
- }
-
- return texAlloc;
-}
-
void rsi_AllocationData(Context *rsc, RsAllocation va, const void *data, uint32_t sizeBytes)
{
Allocation *a = static_cast<Allocation *>(va);
diff --git a/rsElement.cpp b/rsElement.cpp
index 6794522..b5267b3 100644
--- a/rsElement.cpp
+++ b/rsElement.cpp
@@ -21,170 +21,6 @@
using namespace android;
using namespace android::renderscript;
-void ElementState::initPredefined()
-{
- Component * u_8 = new Component(Component::USER, Component::UNSIGNED, true, 8, 0);
- Component * i_8 = new Component(Component::USER, Component::SIGNED, true, 8, 0);
- Component * u_16 = new Component(Component::USER, Component::UNSIGNED, true, 16, 0);
- Component * i_16 = new Component(Component::USER, Component::SIGNED, true, 16, 0);
- Component * u_32 = new Component(Component::USER, Component::UNSIGNED, true, 32, 0);
- Component * i_32 = new Component(Component::USER, Component::SIGNED, true, 32, 0);
- Component * f_32 = new Component(Component::USER, Component::FLOAT, true, 32, 0);
-
-
- Component * r_4 = new Component(Component::RED, Component::UNSIGNED, true, 4, 0);
- Component * r_5 = new Component(Component::RED, Component::UNSIGNED, true, 5, 0);
- Component * r_8 = new Component(Component::RED, Component::UNSIGNED, true, 8, 0);
-
- Component * g_4 = new Component(Component::GREEN, Component::UNSIGNED, true, 4, 0);
- Component * g_5 = new Component(Component::GREEN, Component::UNSIGNED, true, 5, 0);
- Component * g_6 = new Component(Component::GREEN, Component::UNSIGNED, true, 6, 0);
- Component * g_8 = new Component(Component::GREEN, Component::UNSIGNED, true, 8, 0);
-
- Component * b_4 = new Component(Component::BLUE, Component::UNSIGNED, true, 4, 0);
- Component * b_5 = new Component(Component::BLUE, Component::UNSIGNED, true, 5, 0);
- Component * b_8 = new Component(Component::BLUE, Component::UNSIGNED, true, 8, 0);
-
- Component * a_1 = new Component(Component::ALPHA, Component::UNSIGNED, true, 1, 0);
- Component * a_4 = new Component(Component::ALPHA, Component::UNSIGNED, true, 4, 0);
- Component * a_8 = new Component(Component::ALPHA, Component::UNSIGNED, true, 8, 0);
-
- Component * idx_16 = new Component(Component::INDEX, Component::UNSIGNED, false, 16, 0);
- Component * idx_32 = new Component(Component::INDEX, Component::UNSIGNED, false, 32, 0);
-
- Component * x = new Component(Component::X, Component::FLOAT, false, 32, 0);
- Component * y = new Component(Component::Y, Component::FLOAT, false, 32, 0);
- Component * z = new Component(Component::Z, Component::FLOAT, false, 32, 0);
-
- Component * nx = new Component(Component::NX, Component::FLOAT, false, 32, 0);
- Component * ny = new Component(Component::NY, Component::FLOAT, false, 32, 0);
- Component * nz = new Component(Component::NZ, Component::FLOAT, false, 32, 0);
-
- Component * s = new Component(Component::S, Component::FLOAT, false, 32, 0);
- Component * t = new Component(Component::T, Component::FLOAT, false, 32, 0);
-
- Element * e;
-
- e = new Element(1);
- e->setComponent(0, u_8);
- mPredefinedList.add(Predefined(RS_ELEMENT_USER_U8, e));
-
- e = new Element(1);
- e->setComponent(0, i_8);
- mPredefinedList.add(Predefined(RS_ELEMENT_USER_I8, e));
-
- e = new Element(1);
- e->setComponent(0, u_16);
- mPredefinedList.add(Predefined(RS_ELEMENT_USER_U16, e));
-
- e = new Element(1);
- e->setComponent(0, i_16);
- mPredefinedList.add(Predefined(RS_ELEMENT_USER_I16, e));
-
- e = new Element(1);
- e->setComponent(0, u_32);
- mPredefinedList.add(Predefined(RS_ELEMENT_USER_U32, e));
-
- e = new Element(1);
- e->setComponent(0, i_32);
- mPredefinedList.add(Predefined(RS_ELEMENT_USER_I32, e));
-
- e = new Element(1);
- e->setComponent(0, f_32);
- mPredefinedList.add(Predefined(RS_ELEMENT_USER_FLOAT, e));
-
- e = new Element(1);
- e->setComponent(0, a_8);
- mPredefinedList.add(Predefined(RS_ELEMENT_A_8, e));
-
- e = new Element(3);
- e->setComponent(0, r_5);
- e->setComponent(1, g_6);
- e->setComponent(2, b_5);
- mPredefinedList.add(Predefined(RS_ELEMENT_RGB_565, e));
-
- e = new Element(4);
- e->setComponent(0, r_5);
- e->setComponent(1, g_5);
- e->setComponent(2, b_5);
- e->setComponent(3, a_1);
- mPredefinedList.add(Predefined(RS_ELEMENT_RGBA_5551, e));
-
- e = new Element(4);
- e->setComponent(0, r_4);
- e->setComponent(1, g_4);
- e->setComponent(2, b_4);
- e->setComponent(3, a_4);
- mPredefinedList.add(Predefined(RS_ELEMENT_RGBA_4444, e));
-
- e = new Element(3);
- e->setComponent(0, r_8);
- e->setComponent(1, g_8);
- e->setComponent(2, b_8);
- mPredefinedList.add(Predefined(RS_ELEMENT_RGB_888, e));
-
- e = new Element(4);
- e->setComponent(0, r_8);
- e->setComponent(1, g_8);
- e->setComponent(2, b_8);
- e->setComponent(3, a_8);
- mPredefinedList.add(Predefined(RS_ELEMENT_RGBA_8888, e));
-
- e = new Element(1);
- e->setComponent(0, idx_16);
- mPredefinedList.add(Predefined(RS_ELEMENT_INDEX_16, e));
-
- e = new Element(1);
- e->setComponent(0, idx_32);
- mPredefinedList.add(Predefined(RS_ELEMENT_INDEX_32, e));
-
- e = new Element(2);
- e->setComponent(0, x);
- e->setComponent(1, y);
- mPredefinedList.add(Predefined(RS_ELEMENT_XY_F32, e));
-
- e = new Element(3);
- e->setComponent(0, x);
- e->setComponent(1, y);
- e->setComponent(2, z);
- mPredefinedList.add(Predefined(RS_ELEMENT_XYZ_F32, e));
-
- e = new Element(4);
- e->setComponent(0, s);
- e->setComponent(1, t);
- e->setComponent(2, x);
- e->setComponent(3, y);
- mPredefinedList.add(Predefined(RS_ELEMENT_ST_XY_F32, e));
-
- e = new Element(5);
- e->setComponent(0, s);
- e->setComponent(1, t);
- e->setComponent(2, x);
- e->setComponent(3, y);
- e->setComponent(4, z);
- mPredefinedList.add(Predefined(RS_ELEMENT_ST_XYZ_F32, e));
-
- e = new Element(6);
- e->setComponent(0, nx);
- e->setComponent(1, ny);
- e->setComponent(2, nz);
- e->setComponent(3, x);
- e->setComponent(4, y);
- e->setComponent(5, z);
- mPredefinedList.add(Predefined(RS_ELEMENT_NORM_XYZ_F32, e));
-
- e = new Element(8);
- e->setComponent(0, nx);
- e->setComponent(1, ny);
- e->setComponent(2, nz);
- e->setComponent(3, s);
- e->setComponent(4, t);
- e->setComponent(5, x);
- e->setComponent(6, y);
- e->setComponent(7, z);
- mPredefinedList.add(Predefined(RS_ELEMENT_NORM_ST_XYZ_F32, e));
-}
-
Element::Element()
{
@@ -358,39 +194,6 @@
rsc->mStateElement.mComponentBuildList.clear();
}
-void rsi_ElementAddPredefined(Context *rsc, RsElementPredefined predef)
-{
- ElementState * sec = &rsc->mStateElement;
-
- RsElement ve = rsi_ElementGetPredefined(rsc, predef);
- const Element *e = static_cast<const Element *>(ve);
-
- for(size_t ct = 0; ct < sec->mPredefinedList[predef].mElement->getComponentCount(); ct++) {
- sec->mComponentBuildList.add(sec->mPredefinedList[predef].mElement->getComponent(ct));
- }
-}
-
-RsElement rsi_ElementGetPredefined(Context *rsc, RsElementPredefined predef)
-{
- ElementState * sec = &rsc->mStateElement;
-
- if (!sec->mPredefinedList.size()) {
- sec->initPredefined();
- }
-
- if ((predef < 0) ||
- (static_cast<uint32_t>(predef) >= sec->mPredefinedList.size())) {
- LOGE("rsElementGetPredefined: Request for bad predefined type");
- // error
- return NULL;
- }
-
- rsAssert(sec->mPredefinedList[predef].mEnum == predef);
- Element * e = sec->mPredefinedList[predef].mElement;
- e->incUserRef();
- return e;
-}
-
void rsi_ElementAdd(Context *rsc, RsDataKind dk, RsDataType dt, bool isNormalized, size_t bits, const char *name)
{
ElementState * sec = &rsc->mStateElement;
diff --git a/rsElement.h b/rsElement.h
index 0918522..7b5a83d 100644
--- a/rsElement.h
+++ b/rsElement.h
@@ -69,24 +69,6 @@
~ElementState();
Vector<Component *> mComponentBuildList;
-
-
-
- struct Predefined {
- Predefined() {
- mElement = NULL;
- }
- Predefined(RsElementPredefined en, Element *e) {
- mEnum = en;
- mElement = e;
- }
- RsElementPredefined mEnum;
- Element * mElement;
- };
- Vector<Predefined> mPredefinedList;
-
- void initPredefined();
-
};
diff --git a/rsProgramVertex.cpp b/rsProgramVertex.cpp
index a07e166..dda56d7 100644
--- a/rsProgramVertex.cpp
+++ b/rsProgramVertex.cpp
@@ -133,9 +133,16 @@
void ProgramVertexState::init(Context *rsc, int32_t w, int32_t h)
{
+ rsi_ElementBegin(rsc);
+ rsi_ElementAdd(rsc, RS_KIND_USER, RS_TYPE_FLOAT, false, 32, NULL);
+ RsElement e = rsi_ElementCreate(rsc);
+
+ rsi_TypeBegin(rsc, e);
+ rsi_TypeAdd(rsc, RS_DIMENSION_X, 48);
+ mAllocType = rsi_TypeCreate(rsc);
+
ProgramVertex *pv = new ProgramVertex(NULL, NULL);
- Allocation *alloc = (Allocation *)
- rsi_AllocationCreatePredefSized(rsc, RS_ELEMENT_USER_FLOAT, 48);
+ Allocation *alloc = (Allocation *)rsi_AllocationCreateTyped(rsc, mAllocType);
mDefaultAlloc.set(alloc);
mDefault.set(pv);
diff --git a/rsProgramVertex.h b/rsProgramVertex.h
index 523c3ed..32d147c 100644
--- a/rsProgramVertex.h
+++ b/rsProgramVertex.h
@@ -64,7 +64,7 @@
ObjectBaseRef<ProgramVertex> mLast;
ObjectBaseRef<Allocation> mDefaultAlloc;
-
+ RsType mAllocType;
ProgramVertex *mPV;