API review cleanup.

Change-Id: Ieae7d450308b5637ed4253fe9baed3634c6ed141
This commit is contained in:
Jason Sams
2010-12-06 15:59:59 -08:00
parent 11a8af5ea1
commit bf6ef8d78f
44 changed files with 437 additions and 332 deletions

View File

@@ -84,24 +84,38 @@ public class Allocation extends BaseObj {
mRS.nAllocationUploadToBufferObject(getID());
}
public void data(int[] d) {
public void copyFrom(BaseObj[] 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);
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 updateFromBitmap(Bitmap b) {
public void copyFrom(int[] d) {
mRS.validate();
subData1D(0, mType.getCount(), d);
}
public void copyFrom(short[] d) {
mRS.validate();
subData1D(0, mType.getCount(), d);
}
public void copyFrom(byte[] d) {
mRS.validate();
subData1D(0, mType.getCount(), d);
}
public void copyFrom(float[] d) {
mRS.validate();
subData1D(0, mType.getCount(), d);
}
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) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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");
public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
RenderScriptGL rs = new RenderScriptGL(sc);
setRenderScriptGL(rs);
return rs;
}
/**
* 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 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;
}
}

View File

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

View File

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

View File

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

View File

@@ -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;
int[] in = new int[mEntryCount + 8];
System.arraycopy(mDimensionValues, 0, in, 0, mEntryCount);
mDimensionValues = in;
}
mDimensions[mEntryCount] = d;
mDimensionValues[mEntryCount] = value;
mEntryCount++;
mDimX = value;
return this;
}
public Builder setY(int value) {
if(value < 1) {
throw new RSIllegalArgumentException("Values of less than 1 for Dimension Y are not valid.");
}
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;
}

View File

@@ -357,19 +357,13 @@ nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id, jint
// -----------------------------------
static int
nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid, jintArray _dims, jintArray _dimValues)
nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces)
{
int count = _env->GetArrayLength(_dims);
LOG_API("nTypeCreate, con(%p)", con);
LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)",
con, eid, dimx, dimy, dimz, mips, faces);
jint *dimPtr = _env->GetIntArrayElements(_dims, NULL);
jint *dimValPtr = _env->GetIntArrayElements(_dimValues, NULL);
jint id = (jint)rsaTypeCreate(con, (RsElement)eid, count,
(RsDimension *)dimPtr, (uint32_t *)dimValPtr);
_env->ReleaseIntArrayElements(_dims, dimPtr, JNI_ABORT);
_env->ReleaseIntArrayElements(_dimValues, dimValPtr, JNI_ABORT);
jint id = (jint)rsaTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces);
return (jint)id;
}
@@ -1316,7 +1310,7 @@ static JNINativeMethod methods[] = {
{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;)V", (void*)nElementGetSubElements },
{"rsnTypeCreate", "(II[I[I)I", (void*)nTypeCreate },
{"rsnTypeCreate", "(IIIIIZZ)I", (void*)nTypeCreate },
{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
{"rsnAllocationCreateTyped", "(II)I", (void*)nAllocationCreateTyped },

View File

@@ -328,8 +328,7 @@ void rsaElementGetNativeData(RsContext, RsElement, uint32_t *elemData, uint32_t
void rsaElementGetSubElements(RsContext, RsElement, uint32_t *ids, const char **names, uint32_t dataSize);
// Async commands for returning new IDS
RsType rsaTypeCreate(RsContext, RsElement, uint32_t dimCount,
const RsDimension *dims, const uint32_t *vals);
RsType rsaTypeCreate(RsContext, RsElement, uint32_t dimX, uint32_t dimY, uint32_t dimZ, bool mips, bool faces);
RsAllocation rsaAllocationCreateTyped(RsContext rsc, RsType vtype);
RsAllocation rsaAllocationCreateFromBitmap(RsContext con, uint32_t w, uint32_t h, RsElement _dst, RsElement _src, bool genMips, const void *data);
RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, uint32_t w, uint32_t h, RsElement _dst, RsElement _src, bool genMips, const void *data);

View File

@@ -94,21 +94,14 @@ public class Balls extends Activity implements SensorEventListener {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onResume();
mView.onResume();
mView.resume();
}
@Override
protected void onPause() {
Log.e("rs", "onPause");
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onPause();
mView.onPause();
//Runtime.getRuntime().exit(0);
mView.pause();
Runtime.getRuntime().exit(0);
}
@Override

View File

@@ -63,7 +63,7 @@ public class BallsRS {
sb.addInput(mPoints.getElement());
ProgramVertex pvs = sb.create();
pvs.bindConstants(mVpConsts.getAllocation(), 0);
mRS.contextBindProgramVertex(pvs);
mRS.bindProgramVertex(pvs);
}
private Allocation loadTexture(int id) {
@@ -118,14 +118,14 @@ public class BallsRS {
mScript.set_gPFPoints(mPFPoints);
createProgramVertex();
mRS.contextBindProgramStore(ProgramStore.BLEND_ADD_DEPTH_NO_DEPTH(mRS));
mRS.bindProgramStore(ProgramStore.BLEND_ADD_DEPTH_NO_DEPTH(mRS));
mPhysicsScript.set_gMinPos(new Float2(5, 5));
mPhysicsScript.set_gMaxPos(new Float2(width - 5, height - 5));
mScript.invoke_initParts(width, height);
mRS.contextBindRootScript(mScript);
mRS.bindRootScript(mScript);
}
public void newTouchPosition(float x, float y, float pressure, int id) {

View File

@@ -53,8 +53,8 @@ public class BallsView extends RSSurfaceView {
super.surfaceChanged(holder, format, w, h);
if (mRS == null) {
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
mRS = createRenderScript(sc);
mRS.contextSetSurface(w, h, holder.getSurface());
mRS = createRenderScriptGL(sc);
mRS.setSurface(holder, w, h);
mRender = new BallsRS();
mRender.init(mRS, getResources(), w, h);
}
@@ -65,7 +65,7 @@ public class BallsView extends RSSurfaceView {
protected void onDetachedFromWindow() {
if(mRS != null) {
mRS = null;
destroyRenderScript();
destroyRenderScriptGL();
}
}

View File

@@ -67,7 +67,7 @@ public class Fountain extends Activity {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onResume();
mView.onResume();
mView.resume();
}
@Override
@@ -77,7 +77,7 @@ public class Fountain extends Activity {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onPause();
mView.onPause();
mView.pause();

View File

@@ -36,7 +36,7 @@ public class FountainRS {
ProgramFragment.Builder pfb = new ProgramFragment.Builder(rs);
pfb.setVaryingColor(true);
rs.contextBindProgramFragment(pfb.create());
rs.bindProgramFragment(pfb.create());
ScriptField_Point points = new ScriptField_Point(mRS, PART_COUNT);
@@ -48,7 +48,7 @@ public class FountainRS {
mScript = new ScriptC_fountain(mRS, mRes, R.raw.fountain);
mScript.set_partMesh(sm);
mScript.bind_point(points);
mRS.contextBindRootScript(mScript);
mRS.bindRootScript(mScript);
}
boolean holdingColor[] = new boolean[10];

View File

@@ -53,8 +53,8 @@ public class FountainView extends RSSurfaceView {
super.surfaceChanged(holder, format, w, h);
if (mRS == null) {
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
mRS = createRenderScript(sc);
mRS.contextSetSurface(w, h, holder.getSurface());
mRS = createRenderScriptGL(sc);
mRS.setSurface(holder, w, h);
mRender = new FountainRS();
mRender.init(mRS, getResources(), w, h);
}
@@ -64,7 +64,7 @@ public class FountainView extends RSSurfaceView {
protected void onDetachedFromWindow() {
if (mRS != null) {
mRS = null;
destroyRenderScript();
destroyRenderScriptGL();
}
}

View File

@@ -78,7 +78,7 @@ public class ImageProcessingActivity extends Activity
private SurfaceView mSurfaceView;
private ImageView mDisplayView;
class FilterCallback extends RenderScript.RSMessage {
class FilterCallback extends RenderScript.RSMessageHandler {
private Runnable mAction = new Runnable() {
public void run() {
mDisplayView.invalidate();
@@ -363,14 +363,14 @@ public class ImageProcessingActivity extends Activity
private void createScript() {
mRS = RenderScript.create();
mRS.mMessageCallback = new FilterCallback();
mRS.setMessageHandler(new FilterCallback());
mInPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapIn);
mOutPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapOut);
Type.Builder tb = new Type.Builder(mRS, Element.F32_4(mRS));
tb.add(android.renderscript.Dimension.X, mBitmapIn.getWidth());
tb.add(android.renderscript.Dimension.Y, mBitmapIn.getHeight());
tb.setX(mBitmapIn.getWidth());
tb.setY(mBitmapIn.getHeight());
mScratchPixelsAllocation1 = Allocation.createTyped(mRS, tb.create());
mScratchPixelsAllocation2 = Allocation.createTyped(mRS, tb.create());

View File

@@ -56,7 +56,7 @@ public class SceneGraph extends Activity {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onResume();
mView.onResume();
mView.resume();
}
@Override
@@ -64,7 +64,7 @@ public class SceneGraph extends Activity {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onPause();
mView.onPause();
mView.pause();
}
}

View File

@@ -210,7 +210,7 @@ public class SceneGraphRS {
mScript.bind_gRobot2(mRobot2.mParent.mChildField);
mScript.set_gRobot2Index(mRobot2.mIndexInParentGroup);
mRS.contextBindRootScript(mScript);
mRS.bindRootScript(mScript);
}
}

View File

@@ -55,8 +55,8 @@ public class SceneGraphView extends RSSurfaceView {
if (mRS == null) {
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
sc.setDepth(16, 24);
mRS = createRenderScript(sc);
mRS.contextSetSurface(w, h, holder.getSurface());
mRS = createRenderScriptGL(sc);
mRS.setSurface(holder, w, h);
mRender = new SceneGraphRS();
mRender.init(mRS, getResources(), w, h);
}
@@ -66,7 +66,7 @@ public class SceneGraphView extends RSSurfaceView {
protected void onDetachedFromWindow() {
if (mRS != null) {
mRS = null;
destroyRenderScript();
destroyRenderScriptGL();
}
}

View File

@@ -56,7 +56,7 @@ public class SimpleModel extends Activity {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onResume();
mView.onResume();
mView.resume();
}
@Override
@@ -64,7 +64,7 @@ public class SimpleModel extends Activity {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onPause();
mView.onPause();
mView.pause();
}
}

View File

@@ -160,7 +160,7 @@ public class SimpleModelRS {
initTextAllocation();
mRS.contextBindRootScript(mScript);
mRS.bindRootScript(mScript);
}
}

View File

@@ -55,8 +55,8 @@ public class SimpleModelView extends RSSurfaceView {
if (mRS == null) {
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
sc.setDepth(16, 24);
mRS = createRenderScript(sc);
mRS.contextSetSurface(w, h, holder.getSurface());
mRS = createRenderScriptGL(sc);
mRS.setSurface(holder, w, h);
mRender = new SimpleModelRS();
mRender.init(mRS, getResources(), w, h);
}
@@ -66,7 +66,7 @@ public class SimpleModelView extends RSSurfaceView {
protected void onDetachedFromWindow() {
if (mRS != null) {
mRS = null;
destroyRenderScript();
destroyRenderScriptGL();
}
}

View File

@@ -56,7 +56,7 @@ public class RsList extends Activity {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity loses focus
super.onResume();
mView.onResume();
mView.resume();
}
@Override
@@ -64,7 +64,7 @@ public class RsList extends Activity {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity loses focus
super.onPause();
mView.onPause();
mView.pause();
}
}

View File

@@ -137,7 +137,7 @@ public class RsListRS {
mItalic = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8);
mScript.set_gItalic(mItalic);
mRS.contextBindRootScript(mScript);
mRS.bindRootScript(mScript);
}
}

View File

@@ -55,8 +55,8 @@ public class RsListView extends RSSurfaceView {
if (mRS == null) {
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
sc.setDepth(16, 24);
mRS = createRenderScript(sc);
mRS.contextSetSurface(w, h, holder.getSurface());
mRS = createRenderScriptGL(sc);
mRS.setSurface(holder, w, h);
mRender = new RsListRS();
mRender.init(mRS, getResources(), w, h);
}
@@ -66,7 +66,7 @@ public class RsListView extends RSSurfaceView {
protected void onDetachedFromWindow() {
if (mRS != null) {
mRS = null;
destroyRenderScript();
destroyRenderScriptGL();
}
}

View File

@@ -56,7 +56,7 @@ public class RsRenderStates extends Activity {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onResume();
mView.onResume();
mView.resume();
}
@Override
@@ -64,7 +64,7 @@ public class RsRenderStates extends Activity {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onPause();
mView.onPause();
mView.pause();
}
}

View File

@@ -396,7 +396,7 @@ public class RsRenderStatesRS {
initProgramRaster();
initCustomShaders();
mRS.contextBindRootScript(mScript);
mRS.bindRootScript(mScript);
}
}

View File

@@ -55,8 +55,8 @@ public class RsRenderStatesView extends RSSurfaceView {
if (mRS == null) {
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
sc.setDepth(16, 24);
mRS = createRenderScript(sc);
mRS.contextSetSurface(w, h, holder.getSurface());
mRS = createRenderScriptGL(sc);
mRS.setSurface(holder, w, h);
mRender = new RsRenderStatesRS();
mRender.init(mRS, getResources(), w, h);
}
@@ -66,7 +66,7 @@ public class RsRenderStatesView extends RSSurfaceView {
protected void onDetachedFromWindow() {
if (mRS != null) {
mRS = null;
destroyRenderScript();
destroyRenderScriptGL();
}
}

View File

@@ -63,7 +63,7 @@ public class RSTest extends Activity {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity loses focus
super.onResume();
mView.onResume();
mView.resume();
}
@Override
@@ -71,7 +71,7 @@ public class RSTest extends Activity {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity loses focus
super.onPause();
mView.onPause();
mView.pause();
}
static void log(String message) {

View File

@@ -95,7 +95,7 @@ public class RSTestCore {
mFont = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD, 8);
mScript.set_gFont(mFont);
mRS.contextBindRootScript(mScript);
mRS.bindRootScript(mScript);
test_iter = unitTests.listIterator();
refreshTestResults(); /* Kick off the first test */
@@ -148,7 +148,7 @@ public class RSTestCore {
mListAllocs.copyAll();
mScript.bind_gList(mListAllocs);
mRS.contextBindRootScript(mScript);
mRS.bindRootScript(mScript);
}
}

View File

@@ -53,8 +53,8 @@ public class RSTestView extends RSSurfaceView {
super.surfaceChanged(holder, format, w, h);
if (mRS == null) {
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
mRS = createRenderScript(sc);
mRS.contextSetSurface(w, h, holder.getSurface());
mRS = createRenderScriptGL(sc);
mRS.setSurface(holder, w, h);
mRender = new RSTestCore();
mRender.init(mRS, getResources(), w, h);
}
@@ -65,7 +65,7 @@ public class RSTestView extends RSSurfaceView {
if(mRS != null) {
mRender.cleanup();
mRS = null;
destroyRenderScript();
destroyRenderScriptGL();
}
}

View File

@@ -30,7 +30,7 @@ public class UT_fp_mad extends UnitTest {
public void run() {
RenderScript pRS = RenderScript.create();
ScriptC_fp_mad s = new ScriptC_fp_mad(pRS, mRes, R.raw.fp_mad);
pRS.mMessageCallback = mRsMessage;
pRS.setMessageHandler(mRsMessage);
s.invoke_fp_mad_test(0, 0);
pRS.finish();
waitForMessage();

View File

@@ -89,7 +89,7 @@ public class UT_primitives extends UnitTest {
public void run() {
RenderScript pRS = RenderScript.create();
ScriptC_primitives s = new ScriptC_primitives(pRS, mRes, R.raw.primitives);
pRS.mMessageCallback = mRsMessage;
pRS.setMessageHandler(mRsMessage);
if (!initializeGlobals(s)) {
// initializeGlobals failed
result = -1;

View File

@@ -30,7 +30,7 @@ public class UT_rsdebug extends UnitTest {
public void run() {
RenderScript pRS = RenderScript.create();
ScriptC_rsdebug s = new ScriptC_rsdebug(pRS, mRes, R.raw.rsdebug);
pRS.mMessageCallback = mRsMessage;
pRS.setMessageHandler(mRsMessage);
s.invoke_test_rsdebug(0, 0);
pRS.finish();
waitForMessage();

View File

@@ -29,8 +29,8 @@ public class UT_rstypes extends UnitTest {
public void run() {
RenderScript pRS = RenderScript.create();
ScriptC_rstypes s = new ScriptC_rstypes(pRS, mRes, R.raw.rstypes, true);
pRS.mMessageCallback = mRsMessage;
ScriptC_rstypes s = new ScriptC_rstypes(pRS, mRes, R.raw.rstypes);
pRS.setMessageHandler(mRsMessage);
s.invoke_test_rstypes(0, 0);
pRS.finish();
waitForMessage();

View File

@@ -30,7 +30,7 @@ public class UT_vector_array extends UnitTest {
public void run() {
RenderScript pRS = RenderScript.create();
ScriptC_vector_array s = new ScriptC_vector_array(pRS, mRes, R.raw.vector_array);
pRS.mMessageCallback = mRsMessage;
pRS.setMessageHandler(mRsMessage);
s.invoke_vector_array_test();
pRS.finish();
waitForMessage();

View File

@@ -15,7 +15,7 @@
*/
package com.android.rs.test;
import android.renderscript.RenderScript.RSMessage;
import android.renderscript.RenderScript.RSMessageHandler;
import android.util.Log;
public class UnitTest extends Thread {
@@ -53,7 +53,7 @@ public class UnitTest extends Thread {
this (null);
}
protected RSMessage mRsMessage = new RSMessage() {
protected RSMessageHandler mRsMessage = new RSMessageHandler() {
public void run() {
if (result == 0) {
switch (mID) {

View File

@@ -848,9 +848,7 @@ RsAllocation rsaAllocationCreateFromBitmap(RsContext con, uint32_t w, uint32_t h
const Element *dst = static_cast<const Element *>(_dst);
//LOGE("%p rsi_AllocationCreateFromBitmap %i %i %i", rsc, w, h, genMips);
RsDimension dims[] = {RS_DIMENSION_X, RS_DIMENSION_Y, RS_DIMENSION_LOD};
uint32_t dimValues[] = {w, h, genMips};
RsType type = rsaTypeCreate(rsc, _dst, 3, dims, dimValues);
RsType type = rsaTypeCreate(rsc, _dst, w, h, 0, genMips, false);
RsAllocation vTexAlloc = rsaAllocationCreateTyped(rsc, type);
Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
@@ -888,9 +886,7 @@ RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, uint32_t w, uint32
// Cubemap allocation's faces should be Width by Width each.
// Source data should have 6 * Width by Width pixels
// Error checking is done in the java layer
RsDimension dims[] = {RS_DIMENSION_X, RS_DIMENSION_Y, RS_DIMENSION_LOD, RS_DIMENSION_FACE};
uint32_t dimValues[] = {w, w, genMips, true};
RsType type = rsaTypeCreate(rsc, _dst, 4, dims, dimValues);
RsType type = rsaTypeCreate(rsc, _dst, w, h, 0, genMips, true);
RsAllocation vTexAlloc = rsaAllocationCreateTyped(rsc, type);
Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);

View File

@@ -272,33 +272,12 @@ namespace renderscript {
}
}
RsType rsaTypeCreate(RsContext con, RsElement _e, uint32_t dimCount,
const RsDimension *dims, const uint32_t *vals) {
RsType rsaTypeCreate(RsContext con, RsElement _e, uint32_t dimX,
uint32_t dimY, uint32_t dimZ, bool mips, bool faces) {
Context *rsc = static_cast<Context *>(con);
Element *e = static_cast<Element *>(_e);
TypeState * stc = &rsc->mStateType;
uint32_t dimX = 0;
uint32_t dimY = 0;
uint32_t dimZ = 0;
uint32_t dimLOD = 0;
uint32_t dimFaces = 0;
for (uint32_t ct=0; ct < dimCount; ct++) {
switch (dims[ct]) {
case RS_DIMENSION_X: dimX = vals[ct]; break;
case RS_DIMENSION_Y: dimY = vals[ct]; break;
case RS_DIMENSION_Z: dimZ = vals[ct]; break;
case RS_DIMENSION_LOD: dimLOD = vals[ct]; break;
case RS_DIMENSION_FACE: dimFaces = vals[ct]; break;
default:
LOGE("rsaTypeCreate: Bad dimension");
rsAssert(0);
}
}
return Type::getType(rsc, e, dimX, dimY, dimZ, dimLOD, dimFaces);
return Type::getType(rsc, e, dimX, dimY, dimZ, mips, faces);
}
void rsaTypeGetNativeData(RsContext con, RsType type, uint32_t *typeData, uint32_t typeDataSize) {