Merge "Add YUV allocation creation."
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 900720a..fa115ff 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -240,10 +240,10 @@
rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
}
- native int rsnTypeCreate(int con, int eid, int x, int y, int z, boolean mips, boolean faces);
- synchronized int nTypeCreate(int eid, int x, int y, int z, boolean mips, boolean faces) {
+ native int rsnTypeCreate(int con, int eid, int x, int y, int z, boolean mips, boolean faces, int yuv);
+ synchronized int nTypeCreate(int eid, int x, int y, int z, boolean mips, boolean faces, int yuv) {
validate();
- return rsnTypeCreate(mContext, eid, x, y, z, mips, faces);
+ return rsnTypeCreate(mContext, eid, x, y, z, mips, faces, yuv);
}
native void rsnTypeGetNativeData(int con, int id, int[] typeData);
synchronized void nTypeGetNativeData(int id, int[] typeData) {
diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java
index 93d8b4b..cb12594 100644
--- a/graphics/java/android/renderscript/Type.java
+++ b/graphics/java/android/renderscript/Type.java
@@ -18,6 +18,8 @@
import java.lang.reflect.Field;
+
+import android.graphics.ImageFormat;
import android.util.Log;
/**
@@ -208,6 +210,7 @@
int mDimZ;
boolean mDimMipmaps;
boolean mDimFaces;
+ int mYuv;
Element mElement;
@@ -263,6 +266,25 @@
return this;
}
+ /**
+ * @hide
+ *
+ * only NV21, YV12. Enums from ImageFormat
+ */
+ public Builder setYuvFormat(int yuvFormat) {
+ switch (yuvFormat) {
+ case android.graphics.ImageFormat.NV21:
+ case android.graphics.ImageFormat.YV12:
+ break;
+
+ default:
+ throw new RSIllegalArgumentException("Only NV21 and YV12 are supported..");
+ }
+
+ mYuv = yuvFormat;
+ return this;
+ }
+
/**
* Validate structure and create a new type.
@@ -289,8 +311,14 @@
}
}
+ if (mYuv != 0) {
+ if ((mDimZ != 0) || mDimFaces || mDimMipmaps) {
+ throw new RSInvalidStateException("YUV only supports basic 2D.");
+ }
+ }
+
int id = mRS.nTypeCreate(mElement.getID(mRS),
- mDimX, mDimY, mDimZ, mDimMipmaps, mDimFaces);
+ mDimX, mDimY, mDimZ, mDimMipmaps, mDimFaces, mYuv);
Type t = new Type(id, mRS);
t.mElement = mElement;
t.mDimX = mDimX;
@@ -298,6 +326,7 @@
t.mDimZ = mDimZ;
t.mDimMipmaps = mDimMipmaps;
t.mDimFaces = mDimFaces;
+ t.mDimYuv = mYuv;
t.calcElementCount();
return t;
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 75c7903..54413b4 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -427,12 +427,12 @@
static int
nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
- jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces)
+ jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
{
- LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)",
- con, eid, dimx, dimy, dimz, mips, faces);
+ LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)",
+ con, eid, dimx, dimy, dimz, mips, faces, yuv);
- jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces);
+ jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces, yuv);
return (jint)id;
}
@@ -1454,7 +1454,7 @@
{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
-{"rsnTypeCreate", "(IIIIIZZ)I", (void*)nTypeCreate },
+{"rsnTypeCreate", "(IIIIIZZI)I", (void*)nTypeCreate },
{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
{"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped },