diff options
author | Jason Sams <rjsams@android.com> | 2010-11-04 18:21:45 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-11-04 18:21:45 -0700 |
commit | afb9965fe883f86374c89baeea5ba7d6dcf2184c (patch) | |
tree | 171057f48f83dddd1384c5855e1d08b83200bf47 /graphics | |
parent | 2614c6c1f9fb19af21b901c16c443335bbc9d50b (diff) | |
parent | c1d6210fb5cc558ccea95a59a2b33bb9015fc7de (diff) | |
download | frameworks_base-afb9965fe883f86374c89baeea5ba7d6dcf2184c.zip frameworks_base-afb9965fe883f86374c89baeea5ba7d6dcf2184c.tar.gz frameworks_base-afb9965fe883f86374c89baeea5ba7d6dcf2184c.tar.bz2 |
Merge "More RS exceptions cleanup. Remove some dead code."
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/renderscript/BaseObj.java | 14 | ||||
-rw-r--r-- | graphics/java/android/renderscript/Element.java | 28 | ||||
-rw-r--r-- | graphics/java/android/renderscript/Program.java | 22 | ||||
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 6 | ||||
-rw-r--r-- | graphics/java/android/renderscript/RenderScriptGL.java | 33 | ||||
-rw-r--r-- | graphics/java/android/renderscript/Type.java | 4 | ||||
-rw-r--r-- | graphics/jni/android_renderscript_RenderScript.cpp | 13 |
7 files changed, 51 insertions, 69 deletions
diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java index 715e3fb..69907d9 100644 --- a/graphics/java/android/renderscript/BaseObj.java +++ b/graphics/java/android/renderscript/BaseObj.java @@ -33,7 +33,7 @@ class BaseObj { public int getID() { if (mDestroyed) { - throw new IllegalStateException("using a destroyed object."); + throw new RSInvalidStateException("using a destroyed object."); } return mID; } @@ -43,13 +43,12 @@ class BaseObj { String mName; RenderScript mRS; - public void setName(String s) throws IllegalStateException, IllegalArgumentException - { + public void setName(String s) { if(s.length() < 1) { - throw new IllegalArgumentException("setName does not accept a zero length string."); + throw new RSIllegalArgumentException("setName does not accept a zero length string."); } if(mName != null) { - throw new IllegalArgumentException("setName object already has a name."); + throw new RSIllegalArgumentException("setName object already has a name."); } try { @@ -61,8 +60,7 @@ class BaseObj { } } - protected void finalize() throws Throwable - { + protected void finalize() throws Throwable { if (!mDestroyed) { if(mID != 0 && mRS.isAlive()) { mRS.nObjDestroy(mID); @@ -78,7 +76,7 @@ class BaseObj { public void destroy() { if(mDestroyed) { - throw new IllegalStateException("Object already destroyed."); + throw new RSInvalidStateException("Object already destroyed."); } mDestroyed = true; mRS.nObjDestroy(mID); diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java index d013886..f844b7e 100644 --- a/graphics/java/android/renderscript/Element.java +++ b/graphics/java/android/renderscript/Element.java @@ -93,6 +93,18 @@ public class Element extends BaseObj { } } + public boolean isComplex() { + if (mElements == null) { + return false; + } + for (int ct=0; ct < mElements.length; ct++) { + if (mElements[ct].mElements != null) { + return true; + } + } + return false; + } + public static Element BOOLEAN(RenderScript rs) { if(rs.mElement_BOOLEAN == null) { rs.mElement_BOOLEAN = createUser(rs, DataType.BOOLEAN); @@ -397,7 +409,7 @@ public class Element extends BaseObj { } - public void destroy() throws IllegalStateException { + public void destroy() { super.destroy(); } @@ -412,7 +424,7 @@ public class Element extends BaseObj { public static Element createVector(RenderScript rs, DataType dt, int size) { if (size < 2 || size > 4) { - throw new IllegalArgumentException("Bad size"); + throw new RSIllegalArgumentException("Vector size out of rance 2-4."); } DataKind dk = DataKind.USER; boolean norm = false; @@ -426,22 +438,22 @@ public class Element extends BaseObj { dk == DataKind.PIXEL_LA || dk == DataKind.PIXEL_RGB || dk == DataKind.PIXEL_RGBA)) { - throw new IllegalArgumentException("Unsupported DataKind"); + throw new RSIllegalArgumentException("Unsupported DataKind"); } if (!(dt == DataType.UNSIGNED_8 || dt == DataType.UNSIGNED_5_6_5 || dt == DataType.UNSIGNED_4_4_4_4 || dt == DataType.UNSIGNED_5_5_5_1)) { - throw new IllegalArgumentException("Unsupported DataType"); + throw new RSIllegalArgumentException("Unsupported DataType"); } if (dt == DataType.UNSIGNED_5_6_5 && dk != DataKind.PIXEL_RGB) { - throw new IllegalArgumentException("Bad kind and type combo"); + throw new RSIllegalArgumentException("Bad kind and type combo"); } if (dt == DataType.UNSIGNED_5_5_5_1 && dk != DataKind.PIXEL_RGBA) { - throw new IllegalArgumentException("Bad kind and type combo"); + throw new RSIllegalArgumentException("Bad kind and type combo"); } if (dt == DataType.UNSIGNED_4_4_4_4 && dk != DataKind.PIXEL_RGBA) { - throw new IllegalArgumentException("Bad kind and type combo"); + throw new RSIllegalArgumentException("Bad kind and type combo"); } int size = 1; @@ -477,7 +489,7 @@ public class Element extends BaseObj { public void add(Element element, String name, int arraySize) { if (arraySize < 1) { - throw new IllegalArgumentException("Array size cannot be less than 1."); + throw new RSIllegalArgumentException("Array size cannot be less than 1."); } if(mCount == mElements.length) { Element[] e = new Element[mCount + 8]; diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java index ffcdbbc..35236ca 100644 --- a/graphics/java/android/renderscript/Program.java +++ b/graphics/java/android/renderscript/Program.java @@ -47,6 +47,13 @@ public class Program extends BaseObj { } public void bindConstants(Allocation a, int slot) { + if (slot < 0 || slot >= mConstants.length) { + throw new IllegalArgumentException("Slot ID out of range."); + } + if (a != null && + a.getType().getID() != mConstants[slot].getID()) { + throw new IllegalArgumentException("Allocation type does not match slot type."); + } mRS.nProgramBindConstants(mID, slot, a.mID); } @@ -141,7 +148,10 @@ public class Program extends BaseObj { public void addInput(Element e) throws IllegalStateException { // Should check for consistant and non-conflicting names... if(mInputCount >= MAX_INPUT) { - throw new IllegalArgumentException("Max input count exceeded."); + throw new RSIllegalArgumentException("Max input count exceeded."); + } + if (e.isComplex()) { + throw new RSIllegalArgumentException("Complex elements not allowed."); } mInputs[mInputCount++] = e; } @@ -149,7 +159,10 @@ public class Program extends BaseObj { public void addOutput(Element e) throws IllegalStateException { // Should check for consistant and non-conflicting names... if(mOutputCount >= MAX_OUTPUT) { - throw new IllegalArgumentException("Max output count exceeded."); + throw new RSIllegalArgumentException("Max output count exceeded."); + } + if (e.isComplex()) { + throw new RSIllegalArgumentException("Complex elements not allowed."); } mOutputs[mOutputCount++] = e; } @@ -164,7 +177,10 @@ public class Program extends BaseObj { public int addConstant(Type t) throws IllegalStateException { // Should check for consistant and non-conflicting names... if(mConstantCount >= MAX_CONSTANT) { - throw new IllegalArgumentException("Max input count exceeded."); + throw new RSIllegalArgumentException("Max input count exceeded."); + } + if (t.getElement().isComplex()) { + throw new RSIllegalArgumentException("Complex elements not allowed."); } mConstants[mConstantCount] = t; return mConstantCount++; diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 8f1f273..21efa39 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -156,10 +156,6 @@ public class RenderScript { synchronized void nObjDestroy(int id) { rsnObjDestroy(mContext, id); } - native int rsnFileOpen(int con, byte[] name); - synchronized int nFileOpen(byte[] name) { - return rsnFileOpen(mContext, name); - } native int rsnElementCreate(int con, int type, int kind, boolean norm, int vecSize); synchronized int nElementCreate(int type, int kind, boolean norm, int vecSize) { @@ -599,7 +595,7 @@ public class RenderScript { void validate() { if (mContext == 0) { - throw new IllegalStateException("Calling RS with no Context active."); + throw new RSInvalidStateException("Calling RS with no Context active."); } } diff --git a/graphics/java/android/renderscript/RenderScriptGL.java b/graphics/java/android/renderscript/RenderScriptGL.java index 21cbb9a..cace063 100644 --- a/graphics/java/android/renderscript/RenderScriptGL.java +++ b/graphics/java/android/renderscript/RenderScriptGL.java @@ -68,10 +68,10 @@ public class RenderScriptGL extends RenderScript { private void validateRange(int umin, int upref, int rmin, int rmax) { if (umin < rmin || umin > rmax) { - throw new IllegalArgumentException("Minimum value provided out of range."); + throw new RSIllegalArgumentException("Minimum value provided out of range."); } if (upref < umin) { - throw new IllegalArgumentException("Prefered must be >= Minimum."); + throw new RSIllegalArgumentException("Prefered must be >= Minimum."); } } @@ -93,7 +93,7 @@ public class RenderScriptGL extends RenderScript { public void setSamples(int minimum, int prefered, float Q) { validateRange(minimum, prefered, 0, 24); if (Q < 0.0f || Q > 1.0f) { - throw new IllegalArgumentException("Quality out of 0-1 range."); + throw new RSIllegalArgumentException("Quality out of 0-1 range."); } mSamplesMin = minimum; mSamplesPref = prefered; @@ -188,33 +188,6 @@ public class RenderScriptGL extends RenderScript { nContextBindProgramVertex(safeID(p)); } - - - - ////////////////////////////////////////////////////////////////////////////////// - // File - - public class File extends BaseObj { - File(int id) { - super(id, RenderScriptGL.this); - } - } - - public File fileOpen(String s) throws IllegalStateException, IllegalArgumentException - { - if(s.length() < 1) { - throw new IllegalArgumentException("fileOpen does not accept a zero length string."); - } - - try { - byte[] bytes = s.getBytes("UTF-8"); - int id = nFileOpen(bytes); - return new File(id); - } catch (java.io.UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } - } diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java index 9a40d1f..0d65737 100644 --- a/graphics/java/android/renderscript/Type.java +++ b/graphics/java/android/renderscript/Type.java @@ -136,7 +136,7 @@ public class Type extends BaseObj { public Builder(RenderScript rs, Element e) { if(e.mID == 0) { - throw new IllegalArgumentException("Invalid element."); + throw new RSIllegalArgumentException("Invalid element."); } mRS = rs; @@ -147,7 +147,7 @@ public class Type extends BaseObj { public void add(Dimension d, int value) { if(value < 1) { - throw new IllegalArgumentException("Values of less than 1 for Dimensions are not valid."); + throw new RSIllegalArgumentException("Values of less than 1 for Dimensions are not valid."); } if(mDimensions.length >= mEntryCount) { Dimension[] dn = new Dimension[mEntryCount + 8]; diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index b0faacc..1cc6dc1 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -118,18 +118,6 @@ nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj) rsObjDestroy(con, (void *)obj); } - -static jint -nFileOpen(JNIEnv *_env, jobject _this, RsContext con, jbyteArray str) -{ - LOG_API("nFileOpen, con(%p)", con); - jint len = _env->GetArrayLength(str); - jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); - jint ret = (jint)rsFileOpen(con, (const char *)cptr, len); - _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); - return ret; -} - // --------------------------------------------------------------------------- static jint @@ -1247,7 +1235,6 @@ static JNINativeMethod methods[] = { {"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName }, {"rsnObjDestroy", "(II)V", (void*)nObjDestroy }, -{"rsnFileOpen", "(I[B)I", (void*)nFileOpen }, {"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream }, {"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries }, {"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries }, |