From bf6ef8d78fffbce6c1849a4a28fb3f4401ad039e Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Mon, 6 Dec 2010 15:59:59 -0800 Subject: API review cleanup. Change-Id: Ieae7d450308b5637ed4253fe9baed3634c6ed141 --- graphics/java/android/renderscript/Allocation.java | 60 ++++---- graphics/java/android/renderscript/BaseObj.java | 8 +- graphics/java/android/renderscript/Element.java | 15 +- graphics/java/android/renderscript/Mesh.java | 6 +- graphics/java/android/renderscript/Program.java | 2 +- .../java/android/renderscript/ProgramFragment.java | 4 +- .../java/android/renderscript/ProgramVertex.java | 6 +- .../java/android/renderscript/RSSurfaceView.java | 54 ++------ .../java/android/renderscript/RenderScript.java | 75 +++++----- .../java/android/renderscript/RenderScriptGL.java | 154 +++++++++++++++++---- graphics/java/android/renderscript/Sampler.java | 56 ++++++++ graphics/java/android/renderscript/Type.java | 132 ++++++++---------- 12 files changed, 358 insertions(+), 214 deletions(-) (limited to 'graphics/java') diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index bad1208..074e423 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -84,24 +84,38 @@ public class Allocation extends BaseObj { mRS.nAllocationUploadToBufferObject(getID()); } - public void data(int[] d) { + + public void copyFrom(BaseObj[] d) { + mRS.validate(); + if (d.length != mType.getCount()) { + throw new RSIllegalArgumentException("Array size mismatch, allocation sizeX = " + + mType.getCount() + ", array length = " + d.length); + } + int i[] = new int[d.length]; + for (int ct=0; ct < d.length; ct++) { + i[ct] = d[ct].getID(); + } + subData1D(0, mType.getCount(), i); + } + + public void copyFrom(int[] d) { mRS.validate(); - subData1D(0, mType.getElementCount(), d); + subData1D(0, mType.getCount(), d); } - public void data(short[] d) { + public void copyFrom(short[] d) { mRS.validate(); - subData1D(0, mType.getElementCount(), d); + subData1D(0, mType.getCount(), d); } - public void data(byte[] d) { + public void copyFrom(byte[] d) { mRS.validate(); - subData1D(0, mType.getElementCount(), d); + subData1D(0, mType.getCount(), d); } - public void data(float[] d) { + public void copyFrom(float[] d) { mRS.validate(); - subData1D(0, mType.getElementCount(), d); + subData1D(0, mType.getCount(), d); } - public void updateFromBitmap(Bitmap b) { + public void copyFrom(Bitmap b) { mRS.validate(); if(mType.getX() != b.getWidth() || @@ -153,8 +167,8 @@ public class Allocation extends BaseObj { if(count < 1) { throw new RSIllegalArgumentException("Count must be >= 1."); } - if((off + count) > mType.getElementCount()) { - throw new RSIllegalArgumentException("Overflow, Available count " + mType.getElementCount() + + if((off + count) > mType.getCount()) { + throw new RSIllegalArgumentException("Overflow, Available count " + mType.getCount() + ", got " + count + " at offset " + off + "."); } if((len) < dataSize) { @@ -205,7 +219,7 @@ public class Allocation extends BaseObj { } public synchronized void resize(int dimX) { - if ((mType.getY() > 0)|| (mType.getZ() > 0) || mType.getFaces() || mType.getLOD()) { + if ((mType.getY() > 0)|| (mType.getZ() > 0) || mType.hasFaces() || mType.hasMipmaps()) { throw new RSInvalidStateException("Resize only support for 1D allocations at this time."); } mRS.nAllocationResize1D(getID(), dimX); @@ -340,7 +354,7 @@ public class Allocation extends BaseObj { rs.validate(); Type.Builder b = new Type.Builder(rs, e); - b.add(Dimension.X, count); + b.setX(count); Type t = b.create(); int id = rs.nAllocationCreateTyped(t.getID()); @@ -370,11 +384,9 @@ public class Allocation extends BaseObj { static private Type typeFromBitmap(RenderScript rs, Bitmap b, boolean mip) { Element e = elementFromBitmap(rs, b); Type.Builder tb = new Type.Builder(rs, e); - tb.add(Dimension.X, b.getWidth()); - tb.add(Dimension.Y, b.getHeight()); - if (mip) { - tb.add(Dimension.LOD, 1); - } + tb.setX(b.getWidth()); + tb.setY(b.getHeight()); + tb.setMipmaps(mip); return tb.create(); } @@ -414,12 +426,10 @@ public class Allocation extends BaseObj { Element e = elementFromBitmap(rs, b); Type.Builder tb = new Type.Builder(rs, e); - tb.add(Dimension.X, width); - tb.add(Dimension.Y, width); - tb.add(Dimension.FACE, 1); - if (genMips) { - tb.add(Dimension.LOD, 1); - } + tb.setX(width); + tb.setY(width); + tb.setFaces(true); + tb.setMipmaps(genMips); Type t = tb.create(); int id = rs.nAllocationCubeCreateFromBitmap(dstFmt.getID(), genMips, b); @@ -477,7 +487,7 @@ public class Allocation extends BaseObj { try { allocArray = str.getBytes("UTF-8"); Allocation alloc = Allocation.createSized(rs, Element.U8(rs), allocArray.length); - alloc.data(allocArray); + alloc.copyFrom(allocArray); return alloc; } catch (Exception e) { diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java index 78b5617..c02435f 100644 --- a/graphics/java/android/renderscript/BaseObj.java +++ b/graphics/java/android/renderscript/BaseObj.java @@ -48,13 +48,19 @@ class BaseObj { * * @return int */ - public int getID() { + int getID() { if (mDestroyed) { throw new RSInvalidStateException("using a destroyed object."); } return mID; } + void checkValid() { + if (mID == 0) { + throw new RSIllegalArgumentException("Invalid object."); + } + } + private int mID; private boolean mDestroyed; private String mName; diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java index 4b007f2..7e89a56 100644 --- a/graphics/java/android/renderscript/Element.java +++ b/graphics/java/android/renderscript/Element.java @@ -477,10 +477,6 @@ public class Element extends BaseObj { } - public void destroy() { - super.destroy(); - } - /** * Create a custom Element of the specified DataType. The DataKind will be * set to USER and the vector size to 1 indicating non-vector. @@ -489,7 +485,7 @@ public class Element extends BaseObj { * @param dt The DataType for the new element. * @return Element */ - public static Element createUser(RenderScript rs, DataType dt) { + static Element createUser(RenderScript rs, DataType dt) { DataKind dk = DataKind.USER; boolean norm = false; int vecSize = 1; @@ -510,7 +506,7 @@ public class Element extends BaseObj { */ public static Element createVector(RenderScript rs, DataType dt, int size) { if (size < 2 || size > 4) { - throw new RSIllegalArgumentException("Vector size out of rance 2-4."); + throw new RSIllegalArgumentException("Vector size out of range 2-4."); } DataKind dk = DataKind.USER; boolean norm = false; @@ -603,7 +599,7 @@ public class Element extends BaseObj { * @param name * @param arraySize */ - public void add(Element element, String name, int arraySize) { + public Builder add(Element element, String name, int arraySize) { if (arraySize < 1) { throw new RSIllegalArgumentException("Array size cannot be less than 1."); } @@ -622,6 +618,7 @@ public class Element extends BaseObj { mElementNames[mCount] = name; mArraySizes[mCount] = arraySize; mCount++; + return this; } /** @@ -630,8 +627,8 @@ public class Element extends BaseObj { * @param element * @param name */ - public void add(Element element, String name) { - add(element, name, 1); + public Builder add(Element element, String name) { + return add(element, name, 1); } /** diff --git a/graphics/java/android/renderscript/Mesh.java b/graphics/java/android/renderscript/Mesh.java index 4187992..9176bc8 100644 --- a/graphics/java/android/renderscript/Mesh.java +++ b/graphics/java/android/renderscript/Mesh.java @@ -174,7 +174,7 @@ public class Mesh extends BaseObj { Type newType(Element e, int size) { Type.Builder tb = new Type.Builder(mRS, e); - tb.add(Dimension.X, size); + tb.setX(size); return tb.create(); } @@ -466,12 +466,12 @@ public class Mesh extends BaseObj { Mesh sm = smb.create(); - sm.getVertexAllocation(0).data(mVtxData); + sm.getVertexAllocation(0).copyFrom(mVtxData); if(uploadToBufferObject) { sm.getVertexAllocation(0).uploadToBufferObject(); } - sm.getIndexAllocation(0).data(mIndexData); + sm.getIndexAllocation(0).copyFrom(mIndexData); sm.getIndexAllocation(0).uploadToBufferObject(); return sm; diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java index 22f3fc5..c3536c3 100644 --- a/graphics/java/android/renderscript/Program.java +++ b/graphics/java/android/renderscript/Program.java @@ -87,7 +87,7 @@ public class Program extends BaseObj { if ((slot < 0) || (slot >= mTextureCount)) { throw new IllegalArgumentException("Slot ID out of range."); } - if (va != null && va.getType().getFaces() && + if (va != null && va.getType().hasFaces() && mTextures[slot] != TextureType.TEXTURE_CUBE) { throw new IllegalArgumentException("Cannot bind cubemap to 2d texture slot"); } diff --git a/graphics/java/android/renderscript/ProgramFragment.java b/graphics/java/android/renderscript/ProgramFragment.java index faaf980..074c393 100644 --- a/graphics/java/android/renderscript/ProgramFragment.java +++ b/graphics/java/android/renderscript/ProgramFragment.java @@ -208,7 +208,7 @@ public class ProgramFragment extends Program { Element.Builder b = new Element.Builder(mRS); b.add(Element.F32_4(mRS), "Color"); Type.Builder typeBuilder = new Type.Builder(mRS, b.create()); - typeBuilder.add(Dimension.X, 1); + typeBuilder.setX(1); constType = typeBuilder.create(); addConstant(constType); } @@ -220,7 +220,7 @@ public class ProgramFragment extends Program { Allocation constantData = Allocation.createTyped(mRS,constType); float[] data = new float[4]; data[0] = data[1] = data[2] = data[3] = 1.0f; - constantData.data(data); + constantData.copyFrom(data); pf.bindConstants(constantData, 0); } return pf; diff --git a/graphics/java/android/renderscript/ProgramVertex.java b/graphics/java/android/renderscript/ProgramVertex.java index 998e05e..5d41f63 100644 --- a/graphics/java/android/renderscript/ProgramVertex.java +++ b/graphics/java/android/renderscript/ProgramVertex.java @@ -95,7 +95,7 @@ public class ProgramVertex extends Program { b.add(Element.MATRIX4X4(rs), "MVP"); Type.Builder typeBuilder = new Type.Builder(rs, b.create()); - typeBuilder.add(Dimension.X, 1); + typeBuilder.setX(1); return typeBuilder.create(); } @@ -153,7 +153,7 @@ public class ProgramVertex extends Program { Type constInputType = ProgramVertex.Builder.getConstantInputType(rs); mAlloc = Allocation.createTyped(rs, constInputType); int bufferSize = constInputType.getElement().getSizeBytes()* - constInputType.getElementCount(); + constInputType.getCount(); mIOBuffer = new FieldPacker(bufferSize); loadModelview(new Matrix4f()); loadProjection(new Matrix4f()); @@ -170,7 +170,7 @@ public class ProgramVertex extends Program { for(int i = 0; i < 16; i ++) { mIOBuffer.addF32(m.mMat[i]); } - mAlloc.data(mIOBuffer.getData()); + mAlloc.copyFrom(mIOBuffer.getData()); } public void loadModelview(Matrix4f m) { diff --git a/graphics/java/android/renderscript/RSSurfaceView.java b/graphics/java/android/renderscript/RSSurfaceView.java index 2540d01..0211a4a 100644 --- a/graphics/java/android/renderscript/RSSurfaceView.java +++ b/graphics/java/android/renderscript/RSSurfaceView.java @@ -69,7 +69,6 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback * not normally called or subclassed by clients of RSSurfaceView. */ public void surfaceCreated(SurfaceHolder holder) { - Log.v(RenderScript.LOG_TAG, "surfaceCreated"); mSurfaceHolder = holder; } @@ -79,9 +78,8 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback */ public void surfaceDestroyed(SurfaceHolder holder) { // Surface will be destroyed when we return - Log.v(RenderScript.LOG_TAG, "surfaceDestroyed"); if (mRS != null) { - mRS.contextSetSurface(0, 0, null); + mRS.setSurface(null, 0, 0); } } @@ -90,23 +88,21 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback * not normally called or subclassed by clients of RSSurfaceView. */ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { - Log.v(RenderScript.LOG_TAG, "surfaceChanged"); if (mRS != null) { - mRS.contextSetSurface(w, h, holder.getSurface()); + mRS.setSurface(holder, w, h); } } - /** + /** * Inform the view that the activity is paused. The owner of this view must * call this method when the activity is paused. Calling this method will * pause the rendering thread. * Must not be called before a renderer has been set. */ - public void onPause() { + public void pause() { if(mRS != null) { mRS.pause(); } - //Log.v(RenderScript.LOG_TAG, "onPause"); } /** @@ -116,49 +112,29 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback * thread. * Must not be called before a renderer has been set. */ - public void onResume() { + public void resume() { if(mRS != null) { mRS.resume(); } - //Log.v(RenderScript.LOG_TAG, "onResume"); - } - - /** - * Queue a runnable to be run on the GL rendering thread. This can be used - * to communicate with the Renderer on the rendering thread. - * Must not be called before a renderer has been set. - * @param r the runnable to be run on the GL rendering thread. - */ - public void queueEvent(Runnable r) { - //Log.v(RenderScript.LOG_TAG, "queueEvent"); - } - - /** - * This method is used as part of the View class and is not normally - * called or subclassed by clients of RSSurfaceView. - * Must not be called before a renderer has been set. - */ - @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); } - // ---------------------------------------------------------------------- - - public RenderScriptGL createRenderScript(RenderScriptGL.SurfaceConfig sc) { - Log.v(RenderScript.LOG_TAG, "createRenderScript"); - mRS = new RenderScriptGL(sc); - return mRS; + public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) { + RenderScriptGL rs = new RenderScriptGL(sc); + setRenderScriptGL(rs); + return rs; } - public void destroyRenderScript() { - Log.v(RenderScript.LOG_TAG, "destroyRenderScript"); + public void destroyRenderScriptGL() { mRS.destroy(); mRS = null; } - public void createRenderScript(RenderScriptGL rs) { + public void setRenderScriptGL(RenderScriptGL rs) { mRS = rs; } + + public RenderScriptGL getRenderScriptGL() { + return mRS; + } } diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index f16e045..6ff894d 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -38,9 +38,9 @@ import android.view.Surface; **/ public class RenderScript { static final String LOG_TAG = "RenderScript_jni"; - protected static final boolean DEBUG = false; + static final boolean DEBUG = false; @SuppressWarnings({"UnusedDeclaration", "deprecation"}) - protected static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV; + static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV; @@ -49,8 +49,8 @@ public class RenderScript { * field offsets. */ @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) - protected static boolean sInitialized; - native protected static void _nInit(); + static boolean sInitialized; + native static void _nInit(); static { @@ -183,9 +183,9 @@ public class RenderScript { rsnElementGetSubElements(mContext, id, IDs, names); } - native int rsnTypeCreate(int con, int eid, int[] dims, int[] vals); - synchronized int nTypeCreate(int eid, int[] dims, int[] vals) { - return rsnTypeCreate(mContext, eid, dims, vals); + 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) { + return rsnTypeCreate(mContext, eid, x, y, z, mips, faces); } native void rsnTypeGetNativeData(int con, int id, int[] typeData); synchronized void nTypeGetNativeData(int id, int[] typeData) { @@ -525,10 +525,10 @@ public class RenderScript { } - protected int mDev; - protected int mContext; + int mDev; + int mContext; @SuppressWarnings({"FieldCanBeLocal"}) - protected MessageThread mMessageThread; + MessageThread mMessageThread; Element mElement_U8; Element mElement_I8; @@ -604,7 +604,7 @@ public class RenderScript { * in the script. * */ - public static class RSMessage implements Runnable { + public static class RSMessageHandler implements Runnable { protected int[] mData; protected int mID; protected int mLength; @@ -617,7 +617,14 @@ public class RenderScript { * sent from sendToClient by scripts from this context. * */ - public RSMessage mMessageCallback = null; + RSMessageHandler mMessageCallback = null; + + public void setMessageHandler(RSMessageHandler msg) { + mMessageCallback = msg; + } + public RSMessageHandler getMessageHandler() { + return mMessageCallback; + } /** * Runtime error base class. An application should derive from this class @@ -625,7 +632,7 @@ public class RenderScript { * the fields in this class will be filled and the run method called. * */ - public static class RSAsyncError implements Runnable { + public static class RSErrorHandler implements Runnable { protected String mErrorMessage; protected int mErrorNum; public void run() { @@ -639,7 +646,14 @@ public class RenderScript { * This will cause program termaination. * */ - public RSAsyncError mErrorCallback = null; + RSErrorHandler mErrorCallback = null; + + public void setErrorHandler(RSErrorHandler msg) { + mErrorCallback = msg; + } + public RSErrorHandler getErrorHandler() { + return mErrorCallback; + } /** * RenderScript worker threads priority enumeration. The default value is @@ -648,6 +662,7 @@ public class RenderScript { * processes. */ public enum Priority { + // Remap these numbers to opaque... LOW (5), //ANDROID_PRIORITY_BACKGROUND + 5 NORMAL (-4); //ANDROID_PRIORITY_DISPLAY @@ -669,23 +684,23 @@ public class RenderScript { * * @param p New priority to be set. */ - public void contextSetPriority(Priority p) { + public void setPriority(Priority p) { validate(); nContextSetPriority(p.mID); } - protected static class MessageThread extends Thread { + static class MessageThread extends Thread { RenderScript mRS; boolean mRun = true; - int[] auxData = new int[2]; + int[] mAuxData = new int[2]; - public static final int RS_MESSAGE_TO_CLIENT_NONE = 0; - public static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1; - public static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2; - public static final int RS_MESSAGE_TO_CLIENT_ERROR = 3; - public static final int RS_MESSAGE_TO_CLIENT_USER = 4; + static final int RS_MESSAGE_TO_CLIENT_NONE = 0; + static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1; + static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2; + static final int RS_MESSAGE_TO_CLIENT_ERROR = 3; + static final int RS_MESSAGE_TO_CLIENT_USER = 4; - public static final int RS_ERROR_FATAL_UNKNOWN = 0x1000; + static final int RS_ERROR_FATAL_UNKNOWN = 0x1000; MessageThread(RenderScript rs) { super("RSMessageThread"); @@ -700,9 +715,9 @@ public class RenderScript { mRS.nContextInitToClient(mRS.mContext); while(mRun) { rbuf[0] = 0; - int msg = mRS.nContextPeekMessage(mRS.mContext, auxData, true); - int size = auxData[1]; - int subID = auxData[0]; + int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData, true); + int size = mAuxData[1]; + int subID = mAuxData[0]; if (msg == RS_MESSAGE_TO_CLIENT_USER) { if ((size>>2) >= rbuf.length) { @@ -775,12 +790,10 @@ public class RenderScript { * Print the currently available debugging information about the state of * the RS context to the log. * - * - * @param bits Currently ignored. */ - public void contextDump(int bits) { + public void contextDump() { validate(); - nContextDump(bits); + nContextDump(0); } /** @@ -817,7 +830,7 @@ public class RenderScript { return mContext != 0; } - protected int safeID(BaseObj o) { + int safeID(BaseObj o) { if(o != null) { return o.getID(); } diff --git a/graphics/java/android/renderscript/RenderScriptGL.java b/graphics/java/android/renderscript/RenderScriptGL.java index 181d4bd..4a1c40a 100644 --- a/graphics/java/android/renderscript/RenderScriptGL.java +++ b/graphics/java/android/renderscript/RenderScriptGL.java @@ -45,6 +45,9 @@ public class RenderScriptGL extends RenderScript { * Class which is used to describe a pixel format for a graphical buffer. * This is used to describe the intended format of the display surface. * + * The configuration is described by pairs of minimum and preferred bit + * depths for each component within the config and additional structural + * information. */ public static class SurfaceConfig { int mDepthMin = 0; @@ -81,38 +84,75 @@ public class RenderScriptGL extends RenderScript { throw new RSIllegalArgumentException("Minimum value provided out of range."); } if (upref < umin) { - throw new RSIllegalArgumentException("Prefered must be >= Minimum."); + throw new RSIllegalArgumentException("preferred must be >= Minimum."); } } - public void setColor(int minimum, int prefered) { - validateRange(minimum, prefered, 5, 8); + /** + * Set the per-component bit depth for color (red, green, blue). This + * configures the surface for an unsigned integer buffer type. + * + * @param minimum + * @param preferred + */ + public void setColor(int minimum, int preferred) { + validateRange(minimum, preferred, 5, 8); mColorMin = minimum; - mColorPref = prefered; + mColorPref = preferred; } - public void setAlpha(int minimum, int prefered) { - validateRange(minimum, prefered, 0, 8); + + /** + * Set the bit depth for alpha. This configures the surface for + * an unsigned integer buffer type. + * + * @param minimum + * @param preferred + */ + public void setAlpha(int minimum, int preferred) { + validateRange(minimum, preferred, 0, 8); mAlphaMin = minimum; - mAlphaPref = prefered; + mAlphaPref = preferred; } - public void setDepth(int minimum, int prefered) { - validateRange(minimum, prefered, 0, 24); + + /** + * Set the bit depth for the depth buffer. This configures the + * surface for an unsigned integer buffer type. If a minimum of 0 + * is specified then its possible no depth buffer will be + * allocated. + * + * @param minimum + * @param preferred + */ + public void setDepth(int minimum, int preferred) { + validateRange(minimum, preferred, 0, 24); mDepthMin = minimum; - mDepthPref = prefered; + mDepthPref = preferred; } - public void setSamples(int minimum, int prefered, float Q) { - validateRange(minimum, prefered, 0, 24); + + /** + * Configure the multisample rendering. + * + * @param minimum The required number of samples, must be at least 1. + * @param preferred The targe number of samples, must be at least + * minimum + * @param Q The quality of samples, range 0-1. Used to decide between + * different formats which have the same number of samples but + * different rendering quality. + */ + public void setSamples(int minimum, int preferred, float Q) { + validateRange(minimum, preferred, 1, 32); if (Q < 0.0f || Q > 1.0f) { throw new RSIllegalArgumentException("Quality out of 0-1 range."); } mSamplesMin = minimum; - mSamplesPref = prefered; + mSamplesPref = preferred; mSamplesQ = Q; } }; SurfaceConfig mSurfaceConfig; - +/* + // Keep? public void configureSurface(SurfaceHolder sh) { if (mSurfaceConfig.mAlphaMin > 1) { sh.setFormat(PixelFormat.RGBA_8888); @@ -123,7 +163,14 @@ public class RenderScriptGL extends RenderScript { public void checkSurface(SurfaceHolder sh) { } +*/ + /** + * Construct a new RenderScriptGL context. + * + * + * @param sc The desired format of the primart rendering surface. + */ public RenderScriptGL(SurfaceConfig sc) { mSurfaceConfig = new SurfaceConfig(sc); @@ -146,54 +193,113 @@ public class RenderScriptGL extends RenderScript { Element.initPredefined(this); } - public void contextSetSurface(int w, int h, Surface sur) { - mSurface = sur; + /** + * Bind an os surface + * + * + * @param w + * @param h + * @param sur + */ + public void setSurface(SurfaceHolder sur, int w, int h) { + validate(); + if (sur != null) { + mSurface = sur.getSurface(); + } else { + mSurface = null; + } mWidth = w; mHeight = h; - validate(); nContextSetSurface(w, h, mSurface); } + /** + * return the height of the last set surface. + * + * @return int + */ public int getHeight() { return mHeight; } + /** + * return the width of the last set surface. + * + * @return int + */ public int getWidth() { return mWidth; } - void pause() { + /** + * Temporarly halt calls to the root rendering script. + * + */ + public void pause() { validate(); nContextPause(); } - void resume() { + /** + * Resume calls to the root rendering script. + * + */ + public void resume() { validate(); nContextResume(); } - public void contextBindRootScript(Script s) { + /** + * Set the script to handle calls to render the primary surface. + * + * @param s Graphics script to process rendering requests. + */ + public void bindRootScript(Script s) { validate(); nContextBindRootScript(safeID(s)); } - public void contextBindProgramStore(ProgramStore p) { + /** + * Set the default ProgramStore object seen as the parent state by the root + * rendering script. + * + * @param p + */ + public void bindProgramStore(ProgramStore p) { validate(); nContextBindProgramStore(safeID(p)); } - public void contextBindProgramFragment(ProgramFragment p) { + /** + * Set the default ProgramFragment object seen as the parent state by the + * root rendering script. + * + * @param p + */ + public void bindProgramFragment(ProgramFragment p) { validate(); nContextBindProgramFragment(safeID(p)); } - public void contextBindProgramRaster(ProgramRaster p) { + /** + * Set the default ProgramRaster object seen as the parent state by the + * root rendering script. + * + * @param p + */ + public void bindProgramRaster(ProgramRaster p) { validate(); nContextBindProgramRaster(safeID(p)); } - public void contextBindProgramVertex(ProgramVertex p) { + /** + * Set the default ProgramVertex object seen as the parent state by the + * root rendering script. + * + * @param p + */ + public void bindProgramVertex(ProgramVertex p) { validate(); nContextBindProgramVertex(safeID(p)); } diff --git a/graphics/java/android/renderscript/Sampler.java b/graphics/java/android/renderscript/Sampler.java index b627207..9fbc09a 100644 --- a/graphics/java/android/renderscript/Sampler.java +++ b/graphics/java/android/renderscript/Sampler.java @@ -31,6 +31,9 @@ import android.graphics.BitmapFactory; /** * @hide * + * Sampler object which defines how data is extracted from textures. Samplers + * are attached to Program objects (currently only fragment) when those objects + * need to access texture data. **/ public class Sampler extends BaseObj { public enum Value { @@ -50,6 +53,14 @@ public class Sampler extends BaseObj { super(id, rs); } + /** + * Retrieve a sampler with min and mag set to nearest and wrap modes set to + * clamp. + * + * @param rs + * + * @return Sampler + */ public static Sampler CLAMP_NEAREST(RenderScript rs) { if(rs.mSampler_CLAMP_NEAREST == null) { Builder b = new Builder(rs); @@ -62,6 +73,14 @@ public class Sampler extends BaseObj { return rs.mSampler_CLAMP_NEAREST; } + /** + * Retrieve a sampler with min and mag set to linear and wrap modes set to + * clamp. + * + * @param rs + * + * @return Sampler + */ public static Sampler CLAMP_LINEAR(RenderScript rs) { if(rs.mSampler_CLAMP_LINEAR == null) { Builder b = new Builder(rs); @@ -74,6 +93,14 @@ public class Sampler extends BaseObj { return rs.mSampler_CLAMP_LINEAR; } + /** + * Retrieve a sampler with ag set to linear, min linear mipmap linear, and + * to and wrap modes set to clamp. + * + * @param rs + * + * @return Sampler + */ public static Sampler CLAMP_LINEAR_MIP_LINEAR(RenderScript rs) { if(rs.mSampler_CLAMP_LINEAR_MIP_LINEAR == null) { Builder b = new Builder(rs); @@ -86,6 +113,14 @@ public class Sampler extends BaseObj { return rs.mSampler_CLAMP_LINEAR_MIP_LINEAR; } + /** + * Retrieve a sampler with min and mag set to nearest and wrap modes set to + * wrap. + * + * @param rs + * + * @return Sampler + */ public static Sampler WRAP_NEAREST(RenderScript rs) { if(rs.mSampler_WRAP_NEAREST == null) { Builder b = new Builder(rs); @@ -98,6 +133,14 @@ public class Sampler extends BaseObj { return rs.mSampler_WRAP_NEAREST; } + /** + * Retrieve a sampler with min and mag set to nearest and wrap modes set to + * wrap. + * + * @param rs + * + * @return Sampler + */ public static Sampler WRAP_LINEAR(RenderScript rs) { if(rs.mSampler_WRAP_LINEAR == null) { Builder b = new Builder(rs); @@ -110,6 +153,14 @@ public class Sampler extends BaseObj { return rs.mSampler_WRAP_LINEAR; } + /** + * Retrieve a sampler with ag set to linear, min linear mipmap linear, and + * to and wrap modes set to wrap. + * + * @param rs + * + * @return Sampler + */ public static Sampler WRAP_LINEAR_MIP_LINEAR(RenderScript rs) { if(rs.mSampler_WRAP_LINEAR_MIP_LINEAR == null) { Builder b = new Builder(rs); @@ -123,6 +174,11 @@ public class Sampler extends BaseObj { } + /** + * Builder for creating non-standard samplers. Usefull if mix and match of + * wrap modes is necesary or if anisotropic filtering is desired. + * + */ public static class Builder { RenderScript mRS; Value mMin; diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java index 44aee63..859369c 100644 --- a/graphics/java/android/renderscript/Type.java +++ b/graphics/java/android/renderscript/Type.java @@ -42,7 +42,7 @@ public class Type extends BaseObj { int mDimX; int mDimY; int mDimZ; - boolean mDimLOD; + boolean mDimMipmaps; boolean mDimFaces; int mElementCount; Element mElement; @@ -88,8 +88,8 @@ public class Type extends BaseObj { * * @return boolean */ - public boolean getLOD() { - return mDimLOD; + public boolean hasMipmaps() { + return mDimMipmaps; } /** @@ -97,7 +97,7 @@ public class Type extends BaseObj { * * @return boolean */ - public boolean getFaces() { + public boolean hasFaces() { return mDimFaces; } @@ -106,31 +106,31 @@ public class Type extends BaseObj { * * @return int */ - public int getElementCount() { + public int getCount() { return mElementCount; } void calcElementCount() { - boolean hasLod = getLOD(); + boolean hasLod = hasMipmaps(); int x = getX(); int y = getY(); int z = getZ(); int faces = 1; - if(getFaces()) { + if (hasFaces()) { faces = 6; } - if(x == 0) { + if (x == 0) { x = 1; } - if(y == 0) { + if (y == 0) { y = 1; } - if(z == 0) { + if (z == 0) { z = 1; } int count = x * y * z * faces; - if(hasLod && (x > 1) && (y > 1) && (z > 1)) { + if (hasLod && (x > 1) && (y > 1) && (z > 1)) { if(x > 1) { x >>= 1; } @@ -151,10 +151,6 @@ public class Type extends BaseObj { super(id, rs); } - protected void finalize() throws Throwable { - super.finalize(); - } - @Override void updateFromNative() { // We have 6 integer to obtain mDimX; mDimY; mDimZ; @@ -165,7 +161,7 @@ public class Type extends BaseObj { mDimX = dataBuffer[0]; mDimY = dataBuffer[1]; mDimZ = dataBuffer[2]; - mDimLOD = dataBuffer[3] == 1 ? true : false; + mDimMipmaps = dataBuffer[3] == 1 ? true : false; mDimFaces = dataBuffer[4] == 1 ? true : false; int elementID = dataBuffer[5]; @@ -182,15 +178,13 @@ public class Type extends BaseObj { */ public static class Builder { RenderScript mRS; - Dimension[] mDimensions; - int[] mDimensionValues; - int mEntryCount; - Element mElement; + int mDimX = 1; + int mDimY; + int mDimZ; + boolean mDimMipmaps; + boolean mDimFaces; - class Entry { - Dimension mDim; - int mValue; - } + Element mElement; /** * Create a new builder object. @@ -199,13 +193,8 @@ public class Type extends BaseObj { * @param e The element for the type to be created. */ public Builder(RenderScript rs, Element e) { - if(e.getID() == 0) { - throw new RSIllegalArgumentException("Invalid element."); - } - + e.checkValid(); mRS = rs; - mDimensions = new Dimension[4]; - mDimensionValues = new int[4]; mElement = e; } @@ -216,76 +205,67 @@ public class Type extends BaseObj { * @param d * @param value */ - public void add(Dimension d, int value) { + public Builder setX(int value) { if(value < 1) { - throw new RSIllegalArgumentException("Values of less than 1 for Dimensions are not valid."); + throw new RSIllegalArgumentException("Values of less than 1 for Dimension X are not valid."); } - if(mDimensions.length >= mEntryCount) { - Dimension[] dn = new Dimension[mEntryCount + 8]; - System.arraycopy(mDimensions, 0, dn, 0, mEntryCount); - mDimensions = dn; + mDimX = value; + return this; + } - int[] in = new int[mEntryCount + 8]; - System.arraycopy(mDimensionValues, 0, in, 0, mEntryCount); - mDimensionValues = in; + public Builder setY(int value) { + if(value < 1) { + throw new RSIllegalArgumentException("Values of less than 1 for Dimension Y are not valid."); } - mDimensions[mEntryCount] = d; - mDimensionValues[mEntryCount] = value; - mEntryCount++; + mDimY = value; + return this; + } + + public Builder setMipmaps(boolean value) { + mDimMipmaps = value; + return this; } + public Builder setFaces(boolean value) { + mDimFaces = value; + return this; + } + + /** * Validate structure and create a new type. * * @return Type */ public Type create() { - int dims[] = new int[mEntryCount]; - for (int ct=0; ct < mEntryCount; ct++) { - dims[ct] = mDimensions[ct].mID; - } - - int id = mRS.nTypeCreate(mElement.getID(), dims, mDimensionValues); - Type t = new Type(id, mRS); - t.mElement = mElement; - - for(int ct=0; ct < mEntryCount; ct++) { - if(mDimensions[ct] == Dimension.X) { - t.mDimX = mDimensionValues[ct]; - } - if(mDimensions[ct] == Dimension.Y) { - t.mDimY = mDimensionValues[ct]; - } - if(mDimensions[ct] == Dimension.Z) { - t.mDimZ = mDimensionValues[ct]; - } - if(mDimensions[ct] == Dimension.LOD) { - t.mDimLOD = mDimensionValues[ct] != 0; - } - if(mDimensions[ct] == Dimension.FACE) { - t.mDimFaces = mDimensionValues[ct] != 0; - } - } - - if (t.mDimZ > 0) { - if ((t.mDimX < 1) || (t.mDimY < 1)) { + if (mDimZ > 0) { + if ((mDimX < 1) || (mDimY < 1)) { throw new RSInvalidStateException("Both X and Y dimension required when Z is present."); } - if (t.mDimFaces) { + if (mDimFaces) { throw new RSInvalidStateException("Cube maps not supported with 3D types."); } } - if (t.mDimY > 0) { - if (t.mDimX < 1) { + if (mDimY > 0) { + if (mDimX < 1) { throw new RSInvalidStateException("X dimension required when Y is present."); } } - if (t.mDimFaces) { - if (t.mDimY < 1) { + if (mDimFaces) { + if (mDimY < 1) { throw new RSInvalidStateException("Cube maps require 2D Types."); } } + int id = mRS.nTypeCreate(mElement.getID(), mDimX, mDimY, mDimZ, mDimMipmaps, mDimFaces); + Type t = new Type(id, mRS); + t.mElement = mElement; + t.mDimX = mDimX; + t.mDimY = mDimY; + t.mDimZ = mDimZ; + t.mDimMipmaps = mDimMipmaps; + t.mDimFaces = mDimFaces; + t.calcElementCount(); return t; } -- cgit v1.1