summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2010-11-18 15:22:43 -0800
committerAlex Sakhartchouk <alexst@google.com>2010-11-18 15:27:28 -0800
commit67f2e442a31b8395e3c1951f8e91139ec7f2be99 (patch)
tree9e3001eb5181faec98ac13fa85c7915fb8c96c1a /graphics
parent3d019afcdb167a04d9c879285b448f9be1de3c67 (diff)
downloadframeworks_base-67f2e442a31b8395e3c1951f8e91139ec7f2be99.zip
frameworks_base-67f2e442a31b8395e3c1951f8e91139ec7f2be99.tar.gz
frameworks_base-67f2e442a31b8395e3c1951f8e91139ec7f2be99.tar.bz2
Support for cubemaps.
Change-Id: Iaf6087f614451a8e233b3e5bc49c834ab0ad08ee
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/renderscript/Allocation.java68
-rw-r--r--graphics/java/android/renderscript/Program.java55
-rw-r--r--graphics/java/android/renderscript/ProgramFragment.java14
-rw-r--r--graphics/java/android/renderscript/ProgramVertex.java14
-rw-r--r--graphics/java/android/renderscript/RenderScript.java4
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp22
6 files changed, 154 insertions, 23 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 0de53f2..bad1208 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -34,6 +34,18 @@ public class Allocation extends BaseObj {
Type mType;
Bitmap mBitmap;
+ public enum CubemapLayout {
+ VERTICAL_FACE_LIST (0),
+ HORIZONTAL_FACE_LIST (1),
+ VERTICAL_CROSS (2),
+ HORIZONTAL_CROSS (3);
+
+ int mID;
+ CubemapLayout(int id) {
+ mID = id;
+ }
+ }
+
Allocation(int id, RenderScript rs, Type t) {
super(id, rs);
mType = t;
@@ -355,18 +367,21 @@ public class Allocation extends BaseObj {
throw new RSInvalidStateException("Bad bitmap type: " + bc);
}
- static private Type typeFromBitmap(RenderScript rs, Bitmap b) {
+ static private Type typeFromBitmap(RenderScript rs, Bitmap b, boolean mip) {
Element e = elementFromBitmap(rs, b);
Type.Builder tb = new Type.Builder(rs, e);
tb.add(Dimension.X, b.getWidth());
tb.add(Dimension.Y, b.getHeight());
+ if (mip) {
+ tb.add(Dimension.LOD, 1);
+ }
return tb.create();
}
- static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) {
-
+ static public Allocation createFromBitmap(RenderScript rs, Bitmap b,
+ Element dstFmt, boolean genMips) {
rs.validate();
- Type t = typeFromBitmap(rs, b);
+ Type t = typeFromBitmap(rs, b, genMips);
int id = rs.nAllocationCreateFromBitmap(dstFmt.getID(), genMips, b);
if(id == 0) {
@@ -375,10 +390,49 @@ public class Allocation extends BaseObj {
return new Allocation(id, rs, t);
}
+ static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b,
+ Element dstFmt,
+ boolean genMips,
+ CubemapLayout layout) {
+ rs.validate();
+ int height = b.getHeight();
+ int width = b.getWidth();
+
+ if (layout != CubemapLayout.VERTICAL_FACE_LIST) {
+ throw new RSIllegalArgumentException("Only vertical face list supported");
+ }
+ if (height % 6 != 0) {
+ throw new RSIllegalArgumentException("Cubemap height must be multiple of 6");
+ }
+ if (height / 6 != width) {
+ throw new RSIllegalArgumentException("Only square cobe map faces supported");
+ }
+ boolean isPow2 = (width & (width - 1)) == 0;
+ if (!isPow2) {
+ throw new RSIllegalArgumentException("Only power of 2 cube faces supported");
+ }
+
+ Element e = elementFromBitmap(rs, b);
+ Type.Builder tb = new Type.Builder(rs, e);
+ tb.add(Dimension.X, width);
+ tb.add(Dimension.Y, width);
+ tb.add(Dimension.FACE, 1);
+ if (genMips) {
+ tb.add(Dimension.LOD, 1);
+ }
+ Type t = tb.create();
+
+ int id = rs.nAllocationCubeCreateFromBitmap(dstFmt.getID(), genMips, b);
+ if(id == 0) {
+ throw new RSRuntimeException("Load failed for bitmap " + b + " element " + e);
+ }
+ return new Allocation(id, rs, t);
+ }
+
static public Allocation createBitmapRef(RenderScript rs, Bitmap b) {
rs.validate();
- Type t = typeFromBitmap(rs, b);
+ Type t = typeFromBitmap(rs, b, false);
int id = rs.nAllocationCreateBitmapRef(t.getID(), b);
if(id == 0) {
@@ -404,7 +458,9 @@ public class Allocation extends BaseObj {
if (aId == 0) {
throw new RSRuntimeException("Load failed.");
}
- return new Allocation(aId, rs, null);
+ Allocation alloc = new Allocation(aId, rs, null);
+ alloc.updateFromNative();
+ return alloc;
} finally {
if (is != null) {
try {
diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java
index 83c3601..22f3fc5 100644
--- a/graphics/java/android/renderscript/Program.java
+++ b/graphics/java/android/renderscript/Program.java
@@ -36,9 +36,32 @@ public class Program extends BaseObj {
public static final int MAX_CONSTANT = 8;
public static final int MAX_TEXTURE = 8;
+ public enum TextureType {
+ TEXTURE_2D (0),
+ TEXTURE_CUBE (1);
+
+ int mID;
+ TextureType(int id) {
+ mID = id;
+ }
+ }
+
+ enum ProgramParam {
+ INPUT (0),
+ OUTPUT (1),
+ CONSTANT (2),
+ TEXTURE_TYPE (3);
+
+ int mID;
+ ProgramParam(int id) {
+ mID = id;
+ }
+ };
+
Element mInputs[];
Element mOutputs[];
Type mConstants[];
+ TextureType mTextures[];
int mTextureCount;
String mShader;
@@ -54,27 +77,34 @@ public class Program extends BaseObj {
a.getType().getID() != mConstants[slot].getID()) {
throw new IllegalArgumentException("Allocation type does not match slot type.");
}
- mRS.nProgramBindConstants(getID(), slot, a.getID());
+ int id = a != null ? a.getID() : 0;
+ mRS.nProgramBindConstants(getID(), slot, id);
}
public void bindTexture(Allocation va, int slot)
throws IllegalArgumentException {
mRS.validate();
- if((slot < 0) || (slot >= mTextureCount)) {
+ if ((slot < 0) || (slot >= mTextureCount)) {
throw new IllegalArgumentException("Slot ID out of range.");
}
+ if (va != null && va.getType().getFaces() &&
+ mTextures[slot] != TextureType.TEXTURE_CUBE) {
+ throw new IllegalArgumentException("Cannot bind cubemap to 2d texture slot");
+ }
- mRS.nProgramBindTexture(getID(), slot, va.getID());
+ int id = va != null ? va.getID() : 0;
+ mRS.nProgramBindTexture(getID(), slot, id);
}
public void bindSampler(Sampler vs, int slot)
throws IllegalArgumentException {
mRS.validate();
- if((slot < 0) || (slot >= mTextureCount)) {
+ if ((slot < 0) || (slot >= mTextureCount)) {
throw new IllegalArgumentException("Slot ID out of range.");
}
- mRS.nProgramBindSampler(getID(), slot, vs.getID());
+ int id = vs != null ? vs.getID() : 0;
+ mRS.nProgramBindSampler(getID(), slot, id);
}
@@ -84,6 +114,7 @@ public class Program extends BaseObj {
Element mOutputs[];
Type mConstants[];
Type mTextures[];
+ TextureType mTextureTypes[];
int mInputCount;
int mOutputCount;
int mConstantCount;
@@ -100,6 +131,7 @@ public class Program extends BaseObj {
mOutputCount = 0;
mConstantCount = 0;
mTextureCount = 0;
+ mTextureTypes = new TextureType[MAX_TEXTURE];
}
public BaseProgramBuilder setShader(String s) {
@@ -192,6 +224,17 @@ public class Program extends BaseObj {
throw new IllegalArgumentException("Max texture count exceeded.");
}
mTextureCount = count;
+ for (int i = 0; i < mTextureCount; i ++) {
+ mTextureTypes[i] = TextureType.TEXTURE_2D;
+ }
+ return this;
+ }
+
+ public BaseProgramBuilder addTexture(TextureType texType) throws IllegalArgumentException {
+ if(mTextureCount >= MAX_TEXTURE) {
+ throw new IllegalArgumentException("Max texture count exceeded.");
+ }
+ mTextureTypes[mTextureCount ++] = texType;
return this;
}
@@ -203,6 +246,8 @@ public class Program extends BaseObj {
p.mConstants = new Type[mConstantCount];
System.arraycopy(mConstants, 0, p.mConstants, 0, mConstantCount);
p.mTextureCount = mTextureCount;
+ p.mTextures = new TextureType[mTextureCount];
+ System.arraycopy(mTextureTypes, 0, p.mTextures, 0, mTextureCount);
}
}
diff --git a/graphics/java/android/renderscript/ProgramFragment.java b/graphics/java/android/renderscript/ProgramFragment.java
index d30e483..faaf980 100644
--- a/graphics/java/android/renderscript/ProgramFragment.java
+++ b/graphics/java/android/renderscript/ProgramFragment.java
@@ -37,23 +37,25 @@ public class ProgramFragment extends Program {
public ProgramFragment create() {
mRS.validate();
- int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + 1) * 2];
+ int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2];
int idx = 0;
for (int i=0; i < mInputCount; i++) {
- tmp[idx++] = 0;
+ tmp[idx++] = ProgramParam.INPUT.mID;
tmp[idx++] = mInputs[i].getID();
}
for (int i=0; i < mOutputCount; i++) {
- tmp[idx++] = 1;
+ tmp[idx++] = ProgramParam.OUTPUT.mID;
tmp[idx++] = mOutputs[i].getID();
}
for (int i=0; i < mConstantCount; i++) {
- tmp[idx++] = 2;
+ tmp[idx++] = ProgramParam.CONSTANT.mID;
tmp[idx++] = mConstants[i].getID();
}
- tmp[idx++] = 3;
- tmp[idx++] = mTextureCount;
+ for (int i=0; i < mTextureCount; i++) {
+ tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID;
+ tmp[idx++] = mTextureTypes[i].mID;
+ }
int id = mRS.nProgramFragmentCreate(mShader, tmp);
ProgramFragment pf = new ProgramFragment(id, mRS);
diff --git a/graphics/java/android/renderscript/ProgramVertex.java b/graphics/java/android/renderscript/ProgramVertex.java
index 13f017a..998e05e 100644
--- a/graphics/java/android/renderscript/ProgramVertex.java
+++ b/graphics/java/android/renderscript/ProgramVertex.java
@@ -46,23 +46,25 @@ public class ProgramVertex extends Program {
public ProgramVertex create() {
mRS.validate();
- int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount +1) * 2];
+ int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2];
int idx = 0;
for (int i=0; i < mInputCount; i++) {
- tmp[idx++] = 0;
+ tmp[idx++] = ProgramParam.INPUT.mID;
tmp[idx++] = mInputs[i].getID();
}
for (int i=0; i < mOutputCount; i++) {
- tmp[idx++] = 1;
+ tmp[idx++] = ProgramParam.OUTPUT.mID;
tmp[idx++] = mOutputs[i].getID();
}
for (int i=0; i < mConstantCount; i++) {
- tmp[idx++] = 2;
+ tmp[idx++] = ProgramParam.CONSTANT.mID;
tmp[idx++] = mConstants[i].getID();
}
- tmp[idx++] = 3;
- tmp[idx++] = mTextureCount;
+ for (int i=0; i < mTextureCount; i++) {
+ tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID;
+ tmp[idx++] = mTextureTypes[i].mID;
+ }
int id = mRS.nProgramVertexCreate(mShader, tmp);
ProgramVertex pv = new ProgramVertex(id, mRS);
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index dcf86e3..0660441 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -204,6 +204,10 @@ public class RenderScript {
synchronized int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp) {
return rsnAllocationCreateFromBitmap(mContext, dstFmt, genMips, bmp);
}
+ native int rsnAllocationCubeCreateFromBitmap(int con, int dstFmt, boolean genMips, Bitmap bmp);
+ synchronized int nAllocationCubeCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp) {
+ return rsnAllocationCubeCreateFromBitmap(mContext, dstFmt, genMips, bmp);
+ }
native int rsnAllocationCreateBitmapRef(int con, int type, Bitmap bmp);
synchronized int nAllocationCreateBitmapRef(int type, Bitmap bmp) {
return rsnAllocationCreateBitmapRef(mContext, type, bmp);
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 1cc4386..6a1a319 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -455,6 +455,27 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint dst
return 0;
}
+static int
+nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint dstFmt, jboolean genMips, jobject jbitmap)
+{
+ SkBitmap const * nativeBitmap =
+ (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
+ const SkBitmap& bitmap(*nativeBitmap);
+ SkBitmap::Config config = bitmap.getConfig();
+
+ RsElement e = SkBitmapToPredefined(config);
+ if (e) {
+ bitmap.lockPixels();
+ const int w = bitmap.width();
+ const int h = bitmap.height();
+ const void* ptr = bitmap.getPixels();
+ jint id = (jint)rsaAllocationCubeCreateFromBitmap(con, w, h, (RsElement)dstFmt, e, genMips, ptr);
+ bitmap.unlockPixels();
+ return id;
+ }
+ return 0;
+}
+
static void
nAllocationUpdateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
{
@@ -1301,6 +1322,7 @@ static JNINativeMethod methods[] = {
{"rsnAllocationCreateTyped", "(II)I", (void*)nAllocationCreateTyped },
{"rsnAllocationUpdateFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationUpdateFromBitmap },
{"rsnAllocationCreateFromBitmap", "(IIZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap },
+{"rsnAllocationCubeCreateFromBitmap","(IIZLandroid/graphics/Bitmap;)I", (void*)nAllocationCubeCreateFromBitmap },
{"rsnAllocationCreateBitmapRef", "(IILandroid/graphics/Bitmap;)I", (void*)nAllocationCreateBitmapRef },
{"rsnAllocationCreateFromAssetStream","(IIZI)I", (void*)nAllocationCreateFromAssetStream },
{"rsnAllocationUploadToTexture", "(IIZI)V", (void*)nAllocationUploadToTexture },