diff options
author | Jason Sams <rjsams@android.com> | 2009-12-07 13:00:25 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2009-12-07 13:00:25 -0800 |
commit | ffacbc3419825ec1c786dd3c27f3e2a8cd071d8f (patch) | |
tree | 6958434b5abf33e568682de68baed38a8ad5367a /graphics | |
parent | 1b15acf705a6bcca333b1e8a6a48039242cc7d57 (diff) | |
parent | fd2f6358321e95d661f24ba4e08327268035aa59 (diff) | |
download | frameworks_base-ffacbc3419825ec1c786dd3c27f3e2a8cd071d8f.zip frameworks_base-ffacbc3419825ec1c786dd3c27f3e2a8cd071d8f.tar.gz frameworks_base-ffacbc3419825ec1c786dd3c27f3e2a8cd071d8f.tar.bz2 |
am fd2f6358: Merge change I771bebb9 into eclair
Merge commit 'fd2f6358321e95d661f24ba4e08327268035aa59' into eclair-mr2
* commit 'fd2f6358321e95d661f24ba4e08327268035aa59':
Add Java exceptions to catch RS calls with no context or no surface.
Diffstat (limited to 'graphics')
11 files changed, 71 insertions, 0 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index 957f2dd..b6ac14a 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -40,27 +40,36 @@ public class Allocation extends BaseObj { } public void uploadToTexture(int baseMipLevel) { + mRS.validate(); + mRS.validateSurface(); mRS.nAllocationUploadToTexture(mID, baseMipLevel); } public void uploadToBufferObject() { + mRS.validate(); + mRS.validateSurface(); mRS.nAllocationUploadToBufferObject(mID); } public void data(int[] d) { + mRS.validate(); subData1D(0, mType.getElementCount(), d); } public void data(short[] d) { + mRS.validate(); subData1D(0, mType.getElementCount(), d); } public void data(byte[] d) { + mRS.validate(); subData1D(0, mType.getElementCount(), d); } public void data(float[] d) { + mRS.validate(); subData1D(0, mType.getElementCount(), d); } private void data1DChecks(int off, int count, int len, int dataSize) { + mRS.validate(); if((off < 0) || (count < 1) || ((off + count) > mType.getElementCount())) { throw new IllegalArgumentException("Offset or Count out of bounds."); } @@ -93,30 +102,37 @@ public class Allocation extends BaseObj { public void subData2D(int xoff, int yoff, int w, int h, int[] d) { + mRS.validate(); mRS.nAllocationSubData2D(mID, xoff, yoff, w, h, d, d.length * 4); } public void subData2D(int xoff, int yoff, int w, int h, float[] d) { + mRS.validate(); mRS.nAllocationSubData2D(mID, xoff, yoff, w, h, d, d.length * 4); } public void readData(int[] d) { + mRS.validate(); mRS.nAllocationRead(mID, d); } public void readData(float[] d) { + mRS.validate(); mRS.nAllocationRead(mID, d); } public void data(Object o) { + mRS.validate(); mRS.nAllocationSubDataFromObject(mID, mType, 0, o); } public void read(Object o) { + mRS.validate(); mRS.nAllocationSubReadFromObject(mID, mType, 0, o); } public void subData(int offset, Object o) { + mRS.validate(); mRS.nAllocationSubDataFromObject(mID, mType, offset, o); } @@ -127,27 +143,33 @@ public class Allocation extends BaseObj { } public void setConstraint(Dimension dim, int value) { + mRS.validate(); mRS.nAdapter1DSetConstraint(mID, dim.mID, value); } public void data(int[] d) { + mRS.validate(); mRS.nAdapter1DData(mID, d); } public void data(float[] d) { + mRS.validate(); mRS.nAdapter1DData(mID, d); } public void subData(int off, int count, int[] d) { + mRS.validate(); mRS.nAdapter1DSubData(mID, off, count, d); } public void subData(int off, int count, float[] d) { + mRS.validate(); mRS.nAdapter1DSubData(mID, off, count, d); } } public Adapter1D createAdapter1D() { + mRS.validate(); int id = mRS.nAdapter1DCreate(); if (id != 0) { mRS.nAdapter1DBindAllocation(id, mID); @@ -163,27 +185,33 @@ public class Allocation extends BaseObj { } public void setConstraint(Dimension dim, int value) { + mRS.validate(); mRS.nAdapter2DSetConstraint(mID, dim.mID, value); } public void data(int[] d) { + mRS.validate(); mRS.nAdapter2DData(mID, d); } public void data(float[] d) { + mRS.validate(); mRS.nAdapter2DData(mID, d); } public void subData(int xoff, int yoff, int w, int h, int[] d) { + mRS.validate(); mRS.nAdapter2DSubData(mID, xoff, yoff, w, h, d); } public void subData(int xoff, int yoff, int w, int h, float[] d) { + mRS.validate(); mRS.nAdapter2DSubData(mID, xoff, yoff, w, h, d); } } public Adapter2D createAdapter2D() { + mRS.validate(); int id = mRS.nAdapter2DCreate(); if (id != 0) { mRS.nAdapter2DBindAllocation(id, mID); @@ -202,6 +230,7 @@ public class Allocation extends BaseObj { static public Allocation createTyped(RenderScript rs, Type type) throws IllegalArgumentException { + rs.validate(); if(type.mID == 0) { throw new IllegalStateException("Bad Type"); } @@ -212,6 +241,7 @@ public class Allocation extends BaseObj { static public Allocation createSized(RenderScript rs, Element e, int count) throws IllegalArgumentException { + rs.validate(); Type.Builder b = new Type.Builder(rs, e); b.add(Dimension.X, count); Type t = b.create(); @@ -226,6 +256,7 @@ public class Allocation extends BaseObj { static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) throws IllegalArgumentException { + rs.validate(); int id = rs.nAllocationCreateFromBitmap(dstFmt.mID, genMips, b); return new Allocation(id, rs, null); } @@ -233,6 +264,7 @@ public class Allocation extends BaseObj { static public Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) throws IllegalArgumentException { + rs.validate(); int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mID, genMips, b); return new Allocation(id, rs, null); } @@ -240,6 +272,7 @@ public class Allocation extends BaseObj { static public Allocation createFromBitmapResource(RenderScript rs, Resources res, int id, Element dstFmt, boolean genMips) throws IllegalArgumentException { + rs.validate(); InputStream is = null; try { final TypedValue value = new TypedValue(); diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java index 73d8266..ee9b098 100644 --- a/graphics/java/android/renderscript/Element.java +++ b/graphics/java/android/renderscript/Element.java @@ -284,6 +284,7 @@ public class Element extends BaseObj { } public static Element createFromClass(RenderScript rs, Class c) { + rs.validate(); Field[] fields = c.getFields(); Builder b = new Builder(rs); @@ -322,6 +323,7 @@ public class Element extends BaseObj { } void init() { + mRS.validate(); internalCreate(mRS, this); } @@ -483,6 +485,7 @@ public class Element extends BaseObj { } public Element create() { + mRS.validate(); Element e = new Element(mRS, mEntryCount); java.lang.System.arraycopy(mEntries, 0, e.mEntries, 0, mEntryCount); e.init(); diff --git a/graphics/java/android/renderscript/Light.java b/graphics/java/android/renderscript/Light.java index 115ae03..aab656f 100644 --- a/graphics/java/android/renderscript/Light.java +++ b/graphics/java/android/renderscript/Light.java @@ -30,10 +30,12 @@ public class Light extends BaseObj { } public void setColor(float r, float g, float b) { + mRS.validate(); mRS.nLightSetColor(mID, r, g, b); } public void setPosition(float x, float y, float z) { + mRS.validate(); mRS.nLightSetPosition(mID, x, y, z); } @@ -65,6 +67,7 @@ public class Light extends BaseObj { } public Light create() { + mRS.validate(); return internalCreate(mRS, this); } } diff --git a/graphics/java/android/renderscript/ProgramFragment.java b/graphics/java/android/renderscript/ProgramFragment.java index 392d93d..1a72578 100644 --- a/graphics/java/android/renderscript/ProgramFragment.java +++ b/graphics/java/android/renderscript/ProgramFragment.java @@ -47,6 +47,7 @@ public class ProgramFragment extends BaseObj { public void bindTexture(Allocation va, int slot) throws IllegalArgumentException { + mRS.validate(); if((slot < 0) || (slot >= MAX_SLOT)) { throw new IllegalArgumentException("Slot ID out of range."); } @@ -56,6 +57,7 @@ public class ProgramFragment extends BaseObj { public void bindSampler(Sampler vs, int slot) throws IllegalArgumentException { + mRS.validate(); if((slot < 0) || (slot >= MAX_SLOT)) { throw new IllegalArgumentException("Slot ID out of range."); } @@ -149,6 +151,7 @@ public class ProgramFragment extends BaseObj { } public ProgramFragment create() { + mRS.validate(); return internalCreate(mRS, this); } } diff --git a/graphics/java/android/renderscript/ProgramRaster.java b/graphics/java/android/renderscript/ProgramRaster.java index ab327f1..56f9bf4 100644 --- a/graphics/java/android/renderscript/ProgramRaster.java +++ b/graphics/java/android/renderscript/ProgramRaster.java @@ -46,11 +46,13 @@ public class ProgramRaster extends BaseObj { } public void setLineWidth(float w) { + mRS.validate(); mLineWidth = w; mRS.nProgramRasterSetLineWidth(mID, w); } public void setPointSize(float s) { + mRS.validate(); mPointSize = s; mRS.nProgramRasterSetPointSize(mID, s); } @@ -98,6 +100,7 @@ public class ProgramRaster extends BaseObj { } public ProgramRaster create() { + mRS.validate(); return internalCreate(mRS, this); } } diff --git a/graphics/java/android/renderscript/ProgramStore.java b/graphics/java/android/renderscript/ProgramStore.java index 5cbe1b2..69be245 100644 --- a/graphics/java/android/renderscript/ProgramStore.java +++ b/graphics/java/android/renderscript/ProgramStore.java @@ -162,6 +162,7 @@ public class ProgramStore extends BaseObj { } public ProgramStore create() { + mRS.validate(); return internalCreate(mRS, this); } } diff --git a/graphics/java/android/renderscript/ProgramVertex.java b/graphics/java/android/renderscript/ProgramVertex.java index ddb23ac..ba97d5b 100644 --- a/graphics/java/android/renderscript/ProgramVertex.java +++ b/graphics/java/android/renderscript/ProgramVertex.java @@ -34,6 +34,7 @@ public class ProgramVertex extends BaseObj { } public void bindAllocation(MatrixAllocation va) { + mRS.validate(); mRS.nProgramVertexBindAllocation(mID, va.mAlloc.mID); } @@ -88,6 +89,7 @@ public class ProgramVertex extends BaseObj { } public ProgramVertex create() { + mRS.validate(); return internalCreate(mRS, this); } } diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index c42f647..0d8b675 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -242,6 +242,18 @@ public class RenderScript { } } + void validate() { + if (mContext == 0) { + throw new IllegalStateException("Calling RS with no Context active."); + } + } + + void validateSurface() { + if (mSurface == null) { + throw new IllegalStateException("Uploading data to GL with no surface."); + } + } + public void contextSetPriority(Priority p) { nContextSetPriority(p.mID); } diff --git a/graphics/java/android/renderscript/Sampler.java b/graphics/java/android/renderscript/Sampler.java index 5e0b110..625a576 100644 --- a/graphics/java/android/renderscript/Sampler.java +++ b/graphics/java/android/renderscript/Sampler.java @@ -100,6 +100,7 @@ public class Sampler extends BaseObj { } public Sampler create() { + mRS.validate(); return internalCreate(mRS, this); } } diff --git a/graphics/java/android/renderscript/Script.java b/graphics/java/android/renderscript/Script.java index 35791a3..57ccfa3 100644 --- a/graphics/java/android/renderscript/Script.java +++ b/graphics/java/android/renderscript/Script.java @@ -48,22 +48,27 @@ public class Script extends BaseObj { } public void bindAllocation(Allocation va, int slot) { + mRS.validate(); mRS.nScriptBindAllocation(mID, va.mID, slot); } public void setClearColor(float r, float g, float b, float a) { + mRS.validate(); mRS.nScriptSetClearColor(mID, r, g, b, a); } public void setClearDepth(float d) { + mRS.validate(); mRS.nScriptSetClearDepth(mID, d); } public void setClearStencil(int stencil) { + mRS.validate(); mRS.nScriptSetClearStencil(mID, stencil); } public void setTimeZone(String timeZone) { + mRS.validate(); try { mRS.nScriptSetTimeZone(mID, timeZone.getBytes("UTF-8")); } catch (java.io.UnsupportedEncodingException e) { diff --git a/graphics/java/android/renderscript/SimpleMesh.java b/graphics/java/android/renderscript/SimpleMesh.java index 3d10e3b..f45074e 100644 --- a/graphics/java/android/renderscript/SimpleMesh.java +++ b/graphics/java/android/renderscript/SimpleMesh.java @@ -35,18 +35,22 @@ public class SimpleMesh extends BaseObj { } public void bindVertexAllocation(Allocation a, int slot) { + mRS.validate(); mRS.nSimpleMeshBindVertex(mID, a.mID, slot); } public void bindIndexAllocation(Allocation a) { + mRS.validate(); mRS.nSimpleMeshBindIndex(mID, a.mID); } public Allocation createVertexAllocation(int slot) { + mRS.validate(); return Allocation.createTyped(mRS, mVertexTypes[slot]); } public Allocation createIndexAllocation() { + mRS.validate(); return Allocation.createTyped(mRS, mIndexType); } @@ -162,6 +166,7 @@ public class SimpleMesh extends BaseObj { } public SimpleMesh create() { + mRS.validate(); SimpleMesh sm = internalCreate(mRS, this); sm.mVertexTypes = new Type[mVertexTypeCount]; for(int ct=0; ct < mVertexTypeCount; ct++) { |