From b109cc78616abee7291eb42094cd156b5db3355d Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Mon, 7 Jan 2013 18:20:12 -0800 Subject: [PATCH] Add YUV allocation creation. Change-Id: I0d1ff72f60481eb9c28cf058eab72e689494d14b --- .../android/renderscript/RenderScript.java | 6 ++-- graphics/java/android/renderscript/Type.java | 31 ++++++++++++++++++- .../jni/android_renderscript_RenderScript.cpp | 10 +++--- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 900720a6ec00d..fa115ffc93b24 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -240,10 +240,10 @@ public class RenderScript { 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 93d8b4b0ad9c9..cb12594db430f 100644 --- a/graphics/java/android/renderscript/Type.java +++ b/graphics/java/android/renderscript/Type.java @@ -18,6 +18,8 @@ package android.renderscript; import java.lang.reflect.Field; + +import android.graphics.ImageFormat; import android.util.Log; /** @@ -208,6 +210,7 @@ public class Type extends BaseObj { int mDimZ; boolean mDimMipmaps; boolean mDimFaces; + int mYuv; Element mElement; @@ -263,6 +266,25 @@ public class Type extends BaseObj { 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 @@ public class Type extends BaseObj { } } + 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 @@ public class Type extends BaseObj { 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 75c7903f39147..54413b46092e4 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -427,12 +427,12 @@ nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id, 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 @@ static JNINativeMethod methods[] = { {"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 },