diff options
author | Jason Sams <rjsams@android.com> | 2009-07-31 16:26:13 -0700 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2009-07-31 16:26:13 -0700 |
commit | 36e612a488511940b61f09803b270aa1c61b68e0 (patch) | |
tree | d127d889ee21474d6fb845a190c87fb12eab2eca /graphics/java | |
parent | b5a57ad94388ebcd3717a6970a12449055eadabe (diff) | |
download | frameworks_base-36e612a488511940b61f09803b270aa1c61b68e0.zip frameworks_base-36e612a488511940b61f09803b270aa1c61b68e0.tar.gz frameworks_base-36e612a488511940b61f09803b270aa1c61b68e0.tar.bz2 |
Begin splitting up RenderScript.java into seperate classes. First piece split off Element.
Diffstat (limited to 'graphics/java')
-rw-r--r-- | graphics/java/android/renderscript/BaseObj.java | 67 | ||||
-rw-r--r-- | graphics/java/android/renderscript/Element.java | 205 | ||||
-rw-r--r-- | graphics/java/android/renderscript/ProgramVertexAlloc.java | 5 | ||||
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 453 |
4 files changed, 441 insertions, 289 deletions
diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java new file mode 100644 index 0000000..f70aee5 --- /dev/null +++ b/graphics/java/android/renderscript/BaseObj.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.renderscript; + +import android.util.Log; + +/** + * @hide + * + **/ +class BaseObj { + + BaseObj(RenderScript rs) { + mRS = rs; + mID = 0; + } + + public int getID() { + return mID; + } + + int mID; + String mName; + RenderScript mRS; + + public void setName(String s) throws IllegalStateException, IllegalArgumentException + { + if(s.length() < 1) { + throw new IllegalArgumentException("setName does not accept a zero length string."); + } + if(mName != null) { + throw new IllegalArgumentException("setName object already has a name."); + } + + try { + byte[] bytes = s.getBytes("UTF-8"); + mRS.nAssignName(mID, bytes); + mName = s; + } catch (java.io.UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + + protected void finalize() throws Throwable + { + if (mID != 0) { + Log.v(RenderScript.LOG_TAG, + "Element finalized without having released the RS reference."); + } + super.finalize(); + } +} + diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java new file mode 100644 index 0000000..8e0a7a1 --- /dev/null +++ b/graphics/java/android/renderscript/Element.java @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.renderscript; + + +/** + * @hide + * + **/ +public class Element extends BaseObj { + final int mPredefinedID; + final boolean mIsPredefined; + + public static final Element USER_U8 = new Element(0); + public static final Element USER_I8 = new Element(1); + public static final Element USER_U16 = new Element(2); + public static final Element USER_I16 = new Element(3); + public static final Element USER_U32 = new Element(4); + public static final Element USER_I32 = new Element(5); + public static final Element USER_FLOAT = new Element(6); + + public static final Element A_8 = new Element(7); + public static final Element RGB_565 = new Element(8); + public static final Element RGB_888 = new Element(11); + public static final Element RGBA_5551 = new Element(9); + public static final Element RGBA_4444 = new Element(10); + public static final Element RGBA_8888 = new Element(12); + + public static final Element INDEX_16 = new Element(13); + public static final Element INDEX_32 = new Element(14); + public static final Element XY_F32 = new Element(15); + public static final Element XYZ_F32 = new Element(16); + public static final Element ST_XY_F32 = new Element(17); + public static final Element ST_XYZ_F32 = new Element(18); + public static final Element NORM_XYZ_F32 = new Element(19); + public static final Element NORM_ST_XYZ_F32 = new Element(20); + + void initPredef(RenderScript rs) { + mID = rs.nElementGetPredefined(mPredefinedID); + } + + static void init(RenderScript rs) { + USER_U8.initPredef(rs); + USER_I8.initPredef(rs); + USER_U16.initPredef(rs); + USER_I16.initPredef(rs); + USER_U32.initPredef(rs); + USER_I32.initPredef(rs); + USER_FLOAT.initPredef(rs); + + A_8.initPredef(rs); + RGB_565.initPredef(rs); + RGB_888.initPredef(rs); + RGBA_5551.initPredef(rs); + RGBA_4444.initPredef(rs); + RGBA_8888.initPredef(rs); + + INDEX_16.initPredef(rs); + INDEX_32.initPredef(rs); + XY_F32.initPredef(rs); + XYZ_F32.initPredef(rs); + ST_XY_F32.initPredef(rs); + ST_XYZ_F32.initPredef(rs); + NORM_XYZ_F32.initPredef(rs); + NORM_ST_XYZ_F32.initPredef(rs); + } + + + public enum DataType { + FLOAT (0), + UNSIGNED (1), + SIGNED (2); + + int mID; + DataType(int id) { + mID = id; + } + } + + public enum DataKind { + USER (0), + RED (1), + GREEN (2), + BLUE (3), + ALPHA (4), + LUMINANCE (5), + INTENSITY (6), + X (7), + Y (8), + Z (9), + W (10), + S (11), + T (12), + Q (13), + R (14), + NX (15), + NY (16), + NZ (17), + INDEX (18); + + int mID; + DataKind(int id) { + mID = id; + } + } + + + Element(int predef) { + super(null); + mID = 0; + mPredefinedID = predef; + mIsPredefined = true; + } + + Element(int id, RenderScript rs) { + super(rs); + mID = id; + mPredefinedID = 0; + mIsPredefined = false; + } + + public void destroy() throws IllegalStateException { + if(mIsPredefined) { + throw new IllegalStateException("Attempting to destroy a predefined Element."); + } + mRS.nElementDestroy(mID); + mID = 0; + } + + + + + public static class Builder { + RenderScript mRS; + boolean mActive = true; + + Builder(RenderScript rs) { + mRS = rs; + } + + void begin() throws IllegalStateException { + if (mActive) { + throw new IllegalStateException("Element builder already active."); + } + mRS.nElementBegin(); + mActive = true; + } + + public Builder add(Element e) throws IllegalArgumentException, IllegalStateException { + if(!mActive) { + throw new IllegalStateException("Element builder not active."); + } + if(!e.mIsPredefined) { + throw new IllegalArgumentException("add requires a predefined Element."); + } + mRS.nElementAddPredefined(e.mID); + return this; + } + + public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits) + throws IllegalStateException { + if(!mActive) { + throw new IllegalStateException("Element builder not active."); + } + int norm = 0; + if (isNormalized) { + norm = 1; + } + mRS.nElementAdd(dt.mID, dk.mID, norm, bits); + return this; + } + + public void abort() throws IllegalStateException { + if(!mActive) { + throw new IllegalStateException("Element builder not active."); + } + mActive = false; + } + + public Element create() throws IllegalStateException { + if(!mActive) { + throw new IllegalStateException("Element builder not active."); + } + int id = mRS.nElementCreate(); + mActive = false; + return new Element(id, mRS); + } + } + +} + diff --git a/graphics/java/android/renderscript/ProgramVertexAlloc.java b/graphics/java/android/renderscript/ProgramVertexAlloc.java index 82bcc30..424e0ad 100644 --- a/graphics/java/android/renderscript/ProgramVertexAlloc.java +++ b/graphics/java/android/renderscript/ProgramVertexAlloc.java @@ -40,10 +40,7 @@ public class ProgramVertexAlloc { mProjection = new Matrix(); mTexture = new Matrix(); - mAlloc = rs.allocationCreatePredefSized( - RenderScript.ElementPredefined.USER_FLOAT, - 48); - + mAlloc = rs.allocationCreateSized(Element.USER_FLOAT, 48); mAlloc.subData1D(MODELVIEW_OFFSET, 16, mModel.mMat); mAlloc.subData1D(PROJECTION_OFFSET, 16, mProjection.mMat); mAlloc.subData1D(TEXTURE_OFFSET, 16, mTexture.mMat); diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 904361f..3d4f333 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -14,30 +14,21 @@ * limitations under the License. */ -/** - * @hide - * - **/ package android.renderscript; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; + +import android.content.res.Resources; +import android.os.Bundle; +import android.util.Config; +import android.util.Log; +import android.view.Surface; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; import android.graphics.Color; -import android.os.Bundle; -import android.content.res.Resources; -import android.util.Log; -import android.util.Config; -import android.view.Menu; -import android.view.MenuItem; -import android.view.Window; -import android.view.View; -import android.view.Surface; /** * @hide @@ -71,125 +62,125 @@ public class RenderScript { mBitmapOptions.inScaled = false; } - native private int nDeviceCreate(); - native private void nDeviceDestroy(int dev); - native private int nContextCreate(int dev, Surface sur, int ver); - native private void nContextDestroy(int con); + native int nDeviceCreate(); + native void nDeviceDestroy(int dev); + native int nContextCreate(int dev, Surface sur, int ver); + native void nContextDestroy(int con); //void rsContextBindSampler (uint32_t slot, RsSampler sampler); //void rsContextBindRootScript (RsScript sampler); - native private void nContextBindRootScript(int script); - native private void nContextBindSampler(int sampler, int slot); - native private void nContextBindProgramFragmentStore(int pfs); - native private void nContextBindProgramFragment(int pf); - native private void nContextBindProgramVertex(int pf); - - native private void nAssignName(int obj, byte[] name); - native private int nFileOpen(byte[] name); - - native private void nElementBegin(); - native private void nElementAddPredefined(int predef); - native private void nElementAdd(int kind, int type, int norm, int bits); - native private int nElementCreate(); - native private int nElementGetPredefined(int predef); - native private void nElementDestroy(int obj); - - native private void nTypeBegin(int elementID); - native private void nTypeAdd(int dim, int val); - native private int nTypeCreate(); - native private void nTypeDestroy(int id); - - native private int nAllocationCreateTyped(int type); - native private int nAllocationCreatePredefSized(int predef, int count); - native private int nAllocationCreateSized(int elem, int count); - native private int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp); - native private int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp); - - native private void nAllocationUploadToTexture(int alloc, int baseMioLevel); - native private void nAllocationDestroy(int alloc); - native private void nAllocationData(int id, int[] d); - native private void nAllocationData(int id, float[] d); - native private void nAllocationSubData1D(int id, int off, int count, int[] d); - native private void nAllocationSubData1D(int id, int off, int count, float[] d); - native private void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, int[] d); - native private void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d); - - native private void nTriangleMeshDestroy(int id); - native private void nTriangleMeshBegin(int vertex, int index); - native private void nTriangleMeshAddVertex_XY (float x, float y); - native private void nTriangleMeshAddVertex_XYZ (float x, float y, float z); - native private void nTriangleMeshAddVertex_XY_ST (float x, float y, float s, float t); - native private void nTriangleMeshAddVertex_XYZ_ST (float x, float y, float z, float s, float t); - native private void nTriangleMeshAddVertex_XYZ_ST_NORM (float x, float y, float z, float s, float t, float nx, float ny, float nz); - native private void nTriangleMeshAddTriangle(int i1, int i2, int i3); - native private int nTriangleMeshCreate(); - - native private void nAdapter1DDestroy(int id); - native private void nAdapter1DBindAllocation(int ad, int alloc); - native private void nAdapter1DSetConstraint(int ad, int dim, int value); - native private void nAdapter1DData(int ad, int[] d); - native private void nAdapter1DSubData(int ad, int off, int count, int[] d); - native private void nAdapter1DData(int ad, float[] d); - native private void nAdapter1DSubData(int ad, int off, int count, float[] d); - native private int nAdapter1DCreate(); - - native private void nScriptDestroy(int script); - native private void nScriptBindAllocation(int vtm, int alloc, int slot); - native private void nScriptCBegin(); - native private void nScriptCSetClearColor(float r, float g, float b, float a); - native private void nScriptCSetClearDepth(float depth); - native private void nScriptCSetClearStencil(int stencil); - native private void nScriptCSetTimeZone(byte[] timeZone); - native private void nScriptCAddType(int type); - native private void nScriptCSetRoot(boolean isRoot); - native private void nScriptCSetScript(byte[] script, int offset, int length); - native private int nScriptCCreate(); - - native private void nSamplerDestroy(int sampler); - native private void nSamplerBegin(); - native private void nSamplerSet(int param, int value); - native private int nSamplerCreate(); - - native private void nProgramFragmentStoreBegin(int in, int out); - native private void nProgramFragmentStoreDepthFunc(int func); - native private void nProgramFragmentStoreDepthMask(boolean enable); - native private void nProgramFragmentStoreColorMask(boolean r, boolean g, boolean b, boolean a); - native private void nProgramFragmentStoreBlendFunc(int src, int dst); - native private void nProgramFragmentStoreDither(boolean enable); - native private int nProgramFragmentStoreCreate(); - native private void nProgramFragmentStoreDestroy(int pgm); - - native private void nProgramFragmentBegin(int in, int out); - native private void nProgramFragmentBindTexture(int vpf, int slot, int a); - native private void nProgramFragmentBindSampler(int vpf, int slot, int s); - native private void nProgramFragmentSetType(int slot, int vt); - native private void nProgramFragmentSetEnvMode(int slot, int env); - native private void nProgramFragmentSetTexEnable(int slot, boolean enable); - native private int nProgramFragmentCreate(); - native private void nProgramFragmentDestroy(int pgm); - - native private void nProgramVertexDestroy(int pv); - native private void nProgramVertexBindAllocation(int pv, int slot, int mID); - native private void nProgramVertexBegin(int inID, int outID); - native private void nProgramVertexSetType(int slot, int mID); - native private void nProgramVertexSetTextureMatrixEnable(boolean enable); - native private void nProgramVertexAddLight(int id); - native private int nProgramVertexCreate(); - - native private void nLightBegin(); - native private void nLightSetIsMono(boolean isMono); - native private void nLightSetIsLocal(boolean isLocal); - native private int nLightCreate(); - native private void nLightDestroy(int l); - native private void nLightSetColor(int l, float r, float g, float b); - native private void nLightSetPosition(int l, float x, float y, float z); + native void nContextBindRootScript(int script); + native void nContextBindSampler(int sampler, int slot); + native void nContextBindProgramFragmentStore(int pfs); + native void nContextBindProgramFragment(int pf); + native void nContextBindProgramVertex(int pf); + + native void nAssignName(int obj, byte[] name); + native int nFileOpen(byte[] name); + + native void nElementBegin(); + native void nElementAddPredefined(int predef); + native void nElementAdd(int kind, int type, int norm, int bits); + native int nElementCreate(); + native int nElementGetPredefined(int predef); + native void nElementDestroy(int obj); + + native void nTypeBegin(int elementID); + native void nTypeAdd(int dim, int val); + native int nTypeCreate(); + native void nTypeDestroy(int id); + + native int nAllocationCreateTyped(int type); + native int nAllocationCreatePredefSized(int predef, int count); + native int nAllocationCreateSized(int elem, int count); + native int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp); + native int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp); + + native void nAllocationUploadToTexture(int alloc, int baseMioLevel); + native void nAllocationDestroy(int alloc); + native void nAllocationData(int id, int[] d); + native void nAllocationData(int id, float[] d); + native void nAllocationSubData1D(int id, int off, int count, int[] d); + native void nAllocationSubData1D(int id, int off, int count, float[] d); + native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, int[] d); + native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d); + + native void nTriangleMeshDestroy(int id); + native void nTriangleMeshBegin(int vertex, int index); + native void nTriangleMeshAddVertex_XY (float x, float y); + native void nTriangleMeshAddVertex_XYZ (float x, float y, float z); + native void nTriangleMeshAddVertex_XY_ST (float x, float y, float s, float t); + native void nTriangleMeshAddVertex_XYZ_ST (float x, float y, float z, float s, float t); + native void nTriangleMeshAddVertex_XYZ_ST_NORM (float x, float y, float z, float s, float t, float nx, float ny, float nz); + native void nTriangleMeshAddTriangle(int i1, int i2, int i3); + native int nTriangleMeshCreate(); + + native void nAdapter1DDestroy(int id); + native void nAdapter1DBindAllocation(int ad, int alloc); + native void nAdapter1DSetConstraint(int ad, int dim, int value); + native void nAdapter1DData(int ad, int[] d); + native void nAdapter1DSubData(int ad, int off, int count, int[] d); + native void nAdapter1DData(int ad, float[] d); + native void nAdapter1DSubData(int ad, int off, int count, float[] d); + native int nAdapter1DCreate(); + + native void nScriptDestroy(int script); + native void nScriptBindAllocation(int vtm, int alloc, int slot); + native void nScriptCBegin(); + native void nScriptCSetClearColor(float r, float g, float b, float a); + native void nScriptCSetClearDepth(float depth); + native void nScriptCSetClearStencil(int stencil); + native void nScriptCSetTimeZone(byte[] timeZone); + native void nScriptCAddType(int type); + native void nScriptCSetRoot(boolean isRoot); + native void nScriptCSetScript(byte[] script, int offset, int length); + native int nScriptCCreate(); + + native void nSamplerDestroy(int sampler); + native void nSamplerBegin(); + native void nSamplerSet(int param, int value); + native int nSamplerCreate(); + + native void nProgramFragmentStoreBegin(int in, int out); + native void nProgramFragmentStoreDepthFunc(int func); + native void nProgramFragmentStoreDepthMask(boolean enable); + native void nProgramFragmentStoreColorMask(boolean r, boolean g, boolean b, boolean a); + native void nProgramFragmentStoreBlendFunc(int src, int dst); + native void nProgramFragmentStoreDither(boolean enable); + native int nProgramFragmentStoreCreate(); + native void nProgramFragmentStoreDestroy(int pgm); + + native void nProgramFragmentBegin(int in, int out); + native void nProgramFragmentBindTexture(int vpf, int slot, int a); + native void nProgramFragmentBindSampler(int vpf, int slot, int s); + native void nProgramFragmentSetType(int slot, int vt); + native void nProgramFragmentSetEnvMode(int slot, int env); + native void nProgramFragmentSetTexEnable(int slot, boolean enable); + native int nProgramFragmentCreate(); + native void nProgramFragmentDestroy(int pgm); + + native void nProgramVertexDestroy(int pv); + native void nProgramVertexBindAllocation(int pv, int slot, int mID); + native void nProgramVertexBegin(int inID, int outID); + native void nProgramVertexSetType(int slot, int mID); + native void nProgramVertexSetTextureMatrixEnable(boolean enable); + native void nProgramVertexAddLight(int id); + native int nProgramVertexCreate(); + + native void nLightBegin(); + native void nLightSetIsMono(boolean isMono); + native void nLightSetIsLocal(boolean isLocal); + native int nLightCreate(); + native void nLightDestroy(int l); + native void nLightSetColor(int l, float r, float g, float b); + native void nLightSetPosition(int l, float x, float y, float z); private int mDev; private int mContext; private Surface mSurface; - + private static boolean mElementsInitialized = false; /////////////////////////////////////////////////////////////////////////////////// // @@ -198,120 +189,25 @@ public class RenderScript { mSurface = sur; mDev = nDeviceCreate(); mContext = nContextCreate(mDev, mSurface, 0); - } - private class BaseObj { - BaseObj() { - mID = 0; - } - - public int getID() { - return mID; - } - - int mID; - String mName; - - public void setName(String s) throws IllegalStateException, IllegalArgumentException - { - if(s.length() < 1) { - throw new IllegalArgumentException("setName does not accept a zero length string."); - } - if(mName != null) { - throw new IllegalArgumentException("setName object already has a name."); - } - - try { - byte[] bytes = s.getBytes("UTF-8"); - nAssignName(mID, bytes); - mName = s; - } catch (java.io.UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } - - protected void finalize() throws Throwable - { - if (mID != 0) { - Log.v(LOG_TAG, - "Element finalized without having released the RS reference."); - } - super.finalize(); + // TODO: This should be protected by a lock + if(!mElementsInitialized) { + Element.init(this); + mElementsInitialized = true; } } - ////////////////////////////////////////////////////////////////////////////////// // Element - public enum ElementPredefined { - USER_U8 (0), - USER_I8 (1), - USER_U16 (2), - USER_I16 (3), - USER_U32 (4), - USER_I32 (5), - USER_FLOAT (6), - - A_8 (7), - RGB_565 (8), - RGB_888 (11), - RGBA_5551 (9), - RGBA_4444 (10), - RGBA_8888 (12), - - INDEX_16 (13), - INDEX_32 (14), - XY_F32 (15), - XYZ_F32 (16), - ST_XY_F32 (17), - ST_XYZ_F32 (18), - NORM_XYZ_F32 (19), - NORM_ST_XYZ_F32 (20); - - int mID; - ElementPredefined(int id) { - mID = id; - } + Element.Builder mElementBuilder = new Element.Builder(this); + public Element.Builder elementBuilderCreate() throws IllegalStateException { + mElementBuilder.begin(); + return mElementBuilder; } - public enum DataType { - FLOAT (0), - UNSIGNED (1), - SIGNED (2); - int mID; - DataType(int id) { - mID = id; - } - } - - public enum DataKind { - USER (0), - RED (1), - GREEN (2), - BLUE (3), - ALPHA (4), - LUMINANCE (5), - INTENSITY (6), - X (7), - Y (8), - Z (9), - W (10), - S (11), - T (12), - Q (13), - R (14), - NX (15), - NY (16), - NZ (17), - INDEX (18); - int mID; - DataKind(int id) { - mID = id; - } - } public enum DepthFunc { ALWAYS (0), @@ -398,46 +294,6 @@ public class RenderScript { } } - - - public class Element extends BaseObj { - Element(int id) { - mID = id; - } - - public void estroy() { - nElementDestroy(mID); - mID = 0; - } - } - - public void elementBegin() { - nElementBegin(); - } - - public void elementAddPredefined(ElementPredefined e) { - nElementAddPredefined(e.mID); - } - - public void elementAdd(DataType dt, DataKind dk, boolean isNormalized, int bits) { - int norm = 0; - if (isNormalized) { - norm = 1; - } - nElementAdd(dt.mID, dk.mID, norm, bits); - } - - public Element elementCreate() { - int id = nElementCreate(); - return new Element(id); - } - - public Element elementGetPredefined(ElementPredefined predef) { - int id = nElementGetPredefined(predef.mID); - return new Element(id); - } - - ////////////////////////////////////////////////////////////////////////////////// // Type @@ -457,6 +313,7 @@ public class RenderScript { public class Type extends BaseObj { Type(int id) { + super(RenderScript.this); mID = id; } @@ -485,6 +342,7 @@ public class RenderScript { public class Allocation extends BaseObj { Allocation(int id) { + super(RenderScript.this); mID = id; } @@ -527,34 +385,48 @@ public class RenderScript { return new Allocation(id); } - public Allocation allocationCreatePredefSized(ElementPredefined e, int count) { - int id = nAllocationCreatePredefSized(e.mID, count); - return new Allocation(id); - } - public Allocation allocationCreateSized(Element e, int count) { - int id = nAllocationCreateSized(e.mID, count); + int id; + if(e.mIsPredefined) { + id = nAllocationCreatePredefSized(e.mPredefinedID, count); + } else { + id = nAllocationCreateSized(e.mID, count); + } return new Allocation(id); } - public Allocation allocationCreateFromBitmap(Bitmap b, ElementPredefined dstFmt, boolean genMips) { - int id = nAllocationCreateFromBitmap(dstFmt.mID, genMips, b); + public Allocation allocationCreateFromBitmap(Bitmap b, Element dstFmt, boolean genMips) + throws IllegalArgumentException { + if(!dstFmt.mIsPredefined) { + throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element."); + } + + int id = nAllocationCreateFromBitmap(dstFmt.mPredefinedID, genMips, b); return new Allocation(id); } - public Allocation allocationCreateFromBitmapBoxed(Bitmap b, ElementPredefined dstFmt, boolean genMips) { - int id = nAllocationCreateFromBitmapBoxed(dstFmt.mID, genMips, b); + public Allocation allocationCreateFromBitmapBoxed(Bitmap b, Element dstFmt, boolean genMips) + throws IllegalArgumentException { + if(!dstFmt.mIsPredefined) { + throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element."); + } + + int id = nAllocationCreateFromBitmapBoxed(dstFmt.mPredefinedID, genMips, b); return new Allocation(id); } - public Allocation allocationCreateFromBitmapResource(Resources res, int id, ElementPredefined internalElement, boolean genMips) { + public Allocation allocationCreateFromBitmapResource(Resources res, int id, Element dstFmt, boolean genMips) + throws IllegalArgumentException { + Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions); - return allocationCreateFromBitmap(b, internalElement, genMips); + return allocationCreateFromBitmap(b, dstFmt, genMips); } - public Allocation allocationCreateFromBitmapResourceBoxed(Resources res, int id, ElementPredefined internalElement, boolean genMips) { + public Allocation allocationCreateFromBitmapResourceBoxed(Resources res, int id, Element dstFmt, boolean genMips) + throws IllegalArgumentException { + Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions); - return allocationCreateFromBitmapBoxed(b, internalElement, genMips); + return allocationCreateFromBitmapBoxed(b, dstFmt, genMips); } @@ -563,6 +435,7 @@ public class RenderScript { public class Adapter1D extends BaseObj { Adapter1D(int id) { + super(RenderScript.this); mID = id; } @@ -607,6 +480,7 @@ public class RenderScript { public class TriangleMesh extends BaseObj { TriangleMesh(int id) { + super(RenderScript.this); mID = id; } @@ -617,6 +491,7 @@ public class RenderScript { } public void triangleMeshBegin(Element vertex, Element index) { + Log.e("rs", "vtx " + vertex.toString() + " " + vertex.mID + " " + vertex.mPredefinedID); nTriangleMeshBegin(vertex.mID, index.mID); } @@ -654,6 +529,7 @@ public class RenderScript { public class Script extends BaseObj { Script(int id) { + super(RenderScript.this); mID = id; } @@ -674,12 +550,12 @@ public class RenderScript { public void scriptCSetTimeZone(String timeZone) { try { byte[] bytes = timeZone.getBytes("UTF-8"); - nScriptCSetTimeZone(bytes); + nScriptCSetTimeZone(bytes); } catch (java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } } - + public void scriptCSetClearColor(float r, float g, float b, float a) { nScriptCSetClearColor(r, g, b, a); } @@ -752,6 +628,7 @@ public class RenderScript { public class ProgramVertex extends BaseObj { ProgramVertex(int id) { + super(RenderScript.this); mID = id; } @@ -800,6 +677,7 @@ public class RenderScript { public class ProgramFragmentStore extends BaseObj { ProgramFragmentStore(int id) { + super(RenderScript.this); mID = id; } @@ -851,6 +729,7 @@ public class RenderScript { public class ProgramFragment extends BaseObj { ProgramFragment(int id) { + super(RenderScript.this); mID = id; } @@ -906,6 +785,7 @@ public class RenderScript { public class Sampler extends BaseObj { Sampler(int id) { + super(RenderScript.this); mID = id; } @@ -933,6 +813,7 @@ public class RenderScript { public class Light extends BaseObj { Light(int id) { + super(RenderScript.this); mID = id; } @@ -972,6 +853,7 @@ public class RenderScript { public class File extends BaseObj { File(int id) { + super(RenderScript.this); mID = id; } @@ -1035,3 +917,4 @@ public class RenderScript { } + |