Merge change I771bebb9 into eclair

* changes:
  Add Java exceptions to catch RS calls with no context or no surface.
This commit is contained in:
Android (Google) Code Review
2009-12-07 12:55:38 -08:00
11 changed files with 71 additions and 0 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -162,6 +162,7 @@ public class ProgramStore extends BaseObj {
}
public ProgramStore create() {
mRS.validate();
return internalCreate(mRS, this);
}
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -100,6 +100,7 @@ public class Sampler extends BaseObj {
}
public Sampler create() {
mRS.validate();
return internalCreate(mRS, this);
}
}

View File

@ -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) {

View File

@ -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++) {