summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/Bitmap.java50
-rw-r--r--graphics/java/android/graphics/Canvas.java47
-rw-r--r--graphics/java/android/renderscript/Allocation.java41
-rw-r--r--graphics/java/android/renderscript/Element.java25
-rw-r--r--graphics/java/android/renderscript/Program.java43
-rw-r--r--graphics/java/android/renderscript/ProgramRaster.java4
-rw-r--r--graphics/java/android/renderscript/ProgramVertex.java10
-rw-r--r--graphics/java/android/renderscript/RenderScript.java26
-rw-r--r--graphics/java/android/renderscript/Type.java6
-rw-r--r--graphics/jni/Android.mk3
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp184
-rw-r--r--graphics/tests/graphicstests/src/android/graphics/BitmapFactoryTest.java47
12 files changed, 247 insertions, 239 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index d9ee3ec..9a19056 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -446,28 +446,30 @@ public final class Bitmap implements Parcelable {
Rect srcR = new Rect(x, y, x + width, y + height);
RectF dstR = new RectF(0, 0, width, height);
+ final Config newConfig = source.getConfig() == Config.ARGB_8888 ?
+ Config.ARGB_8888 : Config.RGB_565;
+
if (m == null || m.isIdentity()) {
- bitmap = createBitmap(neww, newh,
- source.hasAlpha() ? Config.ARGB_8888 : Config.RGB_565);
+ bitmap = createBitmap(neww, newh, newConfig, source.hasAlpha());
paint = null; // not needed
} else {
- /* the dst should have alpha if the src does, or if our matrix
- doesn't preserve rectness
- */
- boolean hasAlpha = source.hasAlpha() || !m.rectStaysRect();
+ final boolean transformed = !m.rectStaysRect();
+
RectF deviceR = new RectF();
m.mapRect(deviceR, dstR);
+
neww = Math.round(deviceR.width());
newh = Math.round(deviceR.height());
- bitmap = createBitmap(neww, newh, hasAlpha ? Config.ARGB_8888 : Config.RGB_565);
- if (hasAlpha) {
- bitmap.eraseColor(0);
- }
+
+ bitmap = createBitmap(neww, newh, transformed ? Config.ARGB_8888 : newConfig,
+ transformed || source.hasAlpha());
+
canvas.translate(-deviceR.left, -deviceR.top);
canvas.concat(m);
+
paint = new Paint();
paint.setFilterBitmap(filter);
- if (!m.rectStaysRect()) {
+ if (transformed) {
paint.setAntiAlias(true);
}
}
@@ -492,8 +494,30 @@ public final class Bitmap implements Parcelable {
* @throws IllegalArgumentException if the width or height are <= 0
*/
public static Bitmap createBitmap(int width, int height, Config config) {
+ return createBitmap(width, height, config, true);
+ }
+
+ /**
+ * Returns a mutable bitmap with the specified width and height. Its
+ * initial density is as per {@link #getDensity}.
+ *
+ * @param width The width of the bitmap
+ * @param height The height of the bitmap
+ * @param config The bitmap config to create.
+ * @param hasAlpha If the bitmap is ARGB_8888 this flag can be used to mark the
+ * bitmap as opaque. Doing so will clear the bitmap in black
+ * instead of transparent.
+ *
+ * @throws IllegalArgumentException if the width or height are <= 0
+ */
+ private static Bitmap createBitmap(int width, int height, Config config, boolean hasAlpha) {
Bitmap bm = nativeCreate(null, 0, width, width, height, config.nativeInt, true);
- bm.eraseColor(0); // start with black/transparent pixels
+ if (config == Config.ARGB_8888 && !hasAlpha) {
+ bm.eraseColor(0xff000000);
+ nativeSetHasAlpha(bm.mNativeBitmap, hasAlpha);
+ } else {
+ bm.eraseColor(0);
+ }
return bm;
}
@@ -1094,7 +1118,7 @@ public final class Bitmap implements Parcelable {
private static native void nativePrepareToDraw(int nativeBitmap);
private static native void nativeSetHasAlpha(int nBitmap, boolean hasAlpha);
private static native boolean nativeSameAs(int nb0, int nb1);
-
+
/* package */ final int ni() {
return mNativeBitmap;
}
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java
index 36a8e57..e75a19e 100644
--- a/graphics/java/android/graphics/Canvas.java
+++ b/graphics/java/android/graphics/Canvas.java
@@ -1551,7 +1551,52 @@ public class Canvas {
drawPicture(picture);
restore();
}
-
+
+ /**
+ * <p>Acquires the Canvas context. After invoking this method, the Canvas
+ * context can be modified by the caller. For instance, if you acquire
+ * the context of an OpenGL Canvas you can reset the GL viewport, scissor,
+ * etc.</p>
+ *
+ * <p>A call to {@link #acquireContext()} should aways be followed by
+ * a call to {@link #releaseContext()}, preferrably using a try block:</p>
+ *
+ * <pre>
+ * try {
+ * if (canvas.acquireContext()) {
+ * // Use the canvas and/or its context
+ * }
+ * } finally {
+ * canvas.releaseContext();
+ * }
+ * </pre>
+ *
+ * <p>Acquiring the context can be an expensive operation and should not
+ * be done unless absolutely necessary.</p>
+ *
+ * <p>Applications should never invoke this method directly.</p>
+ *
+ * @return True if the context could be acquired successfully, false
+ * otherwise (if the context is already acquired for instance.)
+ *
+ * @see #releaseContext()
+ *
+ * @hide
+ */
+ public boolean acquireContext() {
+ return false;
+ }
+
+ /**
+ * <p>Release the context acquired with {@link #acquireContext()}.</p>
+ *
+ * @see #acquireContext()
+ *
+ * @hide
+ */
+ public void releaseContext() {
+ }
+
@Override
protected void finalize() throws Throwable {
try {
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 6775c08..985d700 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -90,7 +90,7 @@ public class Allocation extends BaseObj {
subData1D(0, mType.getElementCount(), d);
}
- public void subData(int off, FieldPacker fp) {
+ public void subData(int xoff, FieldPacker fp) {
int eSize = mType.mElement.getSizeBytes();
final byte[] data = fp.getData();
@@ -99,8 +99,28 @@ public class Allocation extends BaseObj {
throw new IllegalArgumentException("Field packer length " + data.length +
" not divisible by element size " + eSize + ".");
}
- data1DChecks(off, count, data.length, data.length);
- mRS.nAllocationSubData1D(mID, off, count, data, data.length);
+ data1DChecks(xoff, count, data.length, data.length);
+ mRS.nAllocationSubData1D(mID, xoff, count, data, data.length);
+ }
+
+
+ public void subElementData(int xoff, int component_number, FieldPacker fp) {
+ if (component_number >= mType.mElement.mElements.length) {
+ throw new IllegalArgumentException("Component_number " + component_number + " out of range.");
+ }
+ if(xoff < 0) {
+ throw new IllegalArgumentException("Offset must be >= 0.");
+ }
+
+ final byte[] data = fp.getData();
+ int eSize = mType.mElement.mElements[component_number].getSizeBytes();
+
+ if (data.length != eSize) {
+ throw new IllegalArgumentException("Field packer sizelength " + data.length +
+ " does not match component size " + eSize + ".");
+ }
+
+ mRS.nAllocationSubElementData1D(mID, xoff, component_number, data, data.length);
}
private void data1DChecks(int off, int count, int len, int dataSize) {
@@ -142,7 +162,6 @@ public class Allocation extends BaseObj {
}
-
public void subData2D(int xoff, int yoff, int w, int h, int[] d) {
mRS.validate();
mRS.nAllocationSubData2D(mID, xoff, yoff, w, h, d, d.length * 4);
@@ -163,20 +182,6 @@ public class Allocation extends BaseObj {
mRS.nAllocationRead(mID, d);
}
- public void data(Object o) {
- mRS.validate();
- mRS.nAllocationSubDataFromObject(mID, mType, 0, o);
- }
-
- public void read(Object o) {
- mRS.validate();
- mRS.nAllocationSubReadFromObject(mID, mType, 0, o);
- }
-
- public void subData(int offset, Object o) {
- mRS.validate();
- mRS.nAllocationSubDataFromObject(mID, mType, offset, o);
- }
public class Adapter1D extends BaseObj {
Adapter1D(int id, RenderScript rs) {
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java
index ed09f89..05b2d60 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -27,6 +27,7 @@ public class Element extends BaseObj {
int mSize;
Element[] mElements;
String[] mElementNames;
+ int[] mArraySizes;
DataType mType;
DataKind mKind;
@@ -313,11 +314,12 @@ public class Element extends BaseObj {
return rs.mElement_MATRIX_2X2;
}
- Element(int id, RenderScript rs, Element[] e, String[] n) {
+ Element(int id, RenderScript rs, Element[] e, String[] n, int[] as) {
super(id, rs);
mSize = 0;
mElements = e;
mElementNames = n;
+ mArraySizes = as;
for (int ct = 0; ct < mElements.length; ct++ ) {
mSize += mElements[ct].mSize;
}
@@ -441,6 +443,7 @@ public class Element extends BaseObj {
RenderScript mRS;
Element[] mElements;
String[] mElementNames;
+ int[] mArraySizes;
int mCount;
public Builder(RenderScript rs) {
@@ -448,35 +451,49 @@ public class Element extends BaseObj {
mCount = 0;
mElements = new Element[8];
mElementNames = new String[8];
+ mArraySizes = new int[8];
}
- public void add(Element element, String name) {
+ public void add(Element element, String name, int arraySize) {
+ if (arraySize < 1) {
+ throw new IllegalArgumentException("Array size cannot be less than 1.");
+ }
if(mCount == mElements.length) {
Element[] e = new Element[mCount + 8];
String[] s = new String[mCount + 8];
+ int[] as = new int[mCount + 8];
System.arraycopy(mElements, 0, e, 0, mCount);
System.arraycopy(mElementNames, 0, s, 0, mCount);
+ System.arraycopy(mArraySizes, 0, as, 0, mCount);
mElements = e;
mElementNames = s;
+ mArraySizes = as;
}
mElements[mCount] = element;
mElementNames[mCount] = name;
+ mArraySizes[mCount] = arraySize;
mCount++;
}
+ public void add(Element element, String name) {
+ add(element, name, 1);
+ }
+
public Element create() {
mRS.validate();
Element[] ein = new Element[mCount];
String[] sin = new String[mCount];
+ int[] asin = new int[mCount];
java.lang.System.arraycopy(mElements, 0, ein, 0, mCount);
java.lang.System.arraycopy(mElementNames, 0, sin, 0, mCount);
+ java.lang.System.arraycopy(mArraySizes, 0, asin, 0, mCount);
int[] ids = new int[ein.length];
for (int ct = 0; ct < ein.length; ct++ ) {
ids[ct] = ein[ct].mID;
}
- int id = mRS.nElementCreate2(ids, sin);
- return new Element(id, mRS, ein, sin);
+ int id = mRS.nElementCreate2(ids, sin, asin);
+ return new Element(id, mRS, ein, sin, asin);
}
}
diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java
index 1628a97..c6ed72a 100644
--- a/graphics/java/android/renderscript/Program.java
+++ b/graphics/java/android/renderscript/Program.java
@@ -17,6 +17,11 @@
package android.renderscript;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import android.content.res.Resources;
import android.util.Config;
import android.util.Log;
@@ -95,6 +100,44 @@ public class Program extends BaseObj {
return this;
}
+ public BaseProgramBuilder setShader(Resources resources, int resourceID) {
+ byte[] str;
+ int strLength;
+ InputStream is = resources.openRawResource(resourceID);
+ try {
+ try {
+ str = new byte[1024];
+ strLength = 0;
+ while(true) {
+ int bytesLeft = str.length - strLength;
+ if (bytesLeft == 0) {
+ byte[] buf2 = new byte[str.length * 2];
+ System.arraycopy(str, 0, buf2, 0, str.length);
+ str = buf2;
+ bytesLeft = str.length - strLength;
+ }
+ int bytesRead = is.read(str, strLength, bytesLeft);
+ if (bytesRead <= 0) {
+ break;
+ }
+ strLength += bytesRead;
+ }
+ } finally {
+ is.close();
+ }
+ } catch(IOException e) {
+ throw new Resources.NotFoundException();
+ }
+
+ try {
+ mShader = new String(str, 0, strLength, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ Log.e("Renderscript shader creation", "Could not decode shader string");
+ }
+
+ return this;
+ }
+
public void addInput(Element e) throws IllegalStateException {
// Should check for consistant and non-conflicting names...
if(mInputCount >= MAX_INPUT) {
diff --git a/graphics/java/android/renderscript/ProgramRaster.java b/graphics/java/android/renderscript/ProgramRaster.java
index fd89b6e..791dac8 100644
--- a/graphics/java/android/renderscript/ProgramRaster.java
+++ b/graphics/java/android/renderscript/ProgramRaster.java
@@ -55,13 +55,13 @@ public class ProgramRaster extends BaseObj {
mCullMode = CullMode.BACK;
}
- public void setLineWidth(float w) {
+ void setLineWidth(float w) {
mRS.validate();
mLineWidth = w;
mRS.nProgramRasterSetLineWidth(mID, w);
}
- public void setCullMode(CullMode m) {
+ void setCullMode(CullMode m) {
mRS.validate();
mCullMode = m;
mRS.nProgramRasterSetCullMode(mID, m.mID);
diff --git a/graphics/java/android/renderscript/ProgramVertex.java b/graphics/java/android/renderscript/ProgramVertex.java
index c99efd6..b072433 100644
--- a/graphics/java/android/renderscript/ProgramVertex.java
+++ b/graphics/java/android/renderscript/ProgramVertex.java
@@ -107,14 +107,10 @@ public class ProgramVertex extends Program {
public Allocation mAlloc;
public MatrixAllocation(RenderScript rs) {
- mModel = new Matrix4f();
- mProjection = new Matrix4f();
- mTexture = new Matrix4f();
-
mAlloc = Allocation.createSized(rs, Element.createUser(rs, Element.DataType.FLOAT_32), 48);
- mAlloc.subData1D(MODELVIEW_OFFSET, 16, mModel.mMat);
- mAlloc.subData1D(PROJECTION_OFFSET, 16, mProjection.mMat);
- mAlloc.subData1D(TEXTURE_OFFSET, 16, mTexture.mMat);
+ loadModelview(new Matrix4f());
+ loadProjection(new Matrix4f());
+ loadTexture(new Matrix4f());
}
public void destroy() {
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 08ba7e2..1f3e159 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -152,9 +152,9 @@ public class RenderScript {
synchronized int nElementCreate(int type, int kind, boolean norm, int vecSize) {
return rsnElementCreate(mContext, type, kind, norm, vecSize);
}
- native int rsnElementCreate2(int con, int[] elements, String[] names);
- synchronized int nElementCreate2(int[] elements, String[] names) {
- return rsnElementCreate2(mContext, elements, names);
+ native int rsnElementCreate2(int con, int[] elements, String[] names, int[] arraySizes);
+ synchronized int nElementCreate2(int[] elements, String[] names, int[] arraySizes) {
+ return rsnElementCreate2(mContext, elements, names, arraySizes);
}
native void rsnElementGetNativeData(int con, int id, int[] elementData);
synchronized void nElementGetNativeData(int id, int[] elementData) {
@@ -177,14 +177,6 @@ public class RenderScript {
synchronized int nTypeCreate() {
return rsnTypeCreate(mContext);
}
- native void rsnTypeFinalDestroy(int con, Type t);
- synchronized void nTypeFinalDestroy(Type t) {
- rsnTypeFinalDestroy(mContext, t);
- }
- native void rsnTypeSetupFields(int con, Type t, int[] types, int[] bits, Field[] IDs);
- synchronized void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs) {
- rsnTypeSetupFields(mContext, t, types, bits, IDs);
- }
native void rsnTypeGetNativeData(int con, int id, int[] typeData);
synchronized void nTypeGetNativeData(int id, int[] typeData) {
rsnTypeGetNativeData(mContext, id, typeData);
@@ -232,6 +224,10 @@ public class RenderScript {
synchronized void nAllocationSubData1D(int id, int off, int count, byte[] d, int sizeBytes) {
rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes);
}
+ native void rsnAllocationSubElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
+ synchronized void nAllocationSubElementData1D(int id, int xoff, int compIdx, byte[] d, int sizeBytes) {
+ rsnAllocationSubElementData1D(mContext, id, xoff, compIdx, d, sizeBytes);
+ }
native void rsnAllocationSubData1D(int con, int id, int off, int count, float[] d, int sizeBytes);
synchronized void nAllocationSubData1D(int id, int off, int count, float[] d, int sizeBytes) {
rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes);
@@ -253,14 +249,6 @@ public class RenderScript {
synchronized void nAllocationRead(int id, float[] d) {
rsnAllocationRead(mContext, id, d);
}
- native void rsnAllocationSubDataFromObject(int con, int id, Type t, int offset, Object o);
- synchronized void nAllocationSubDataFromObject(int id, Type t, int offset, Object o) {
- rsnAllocationSubDataFromObject(mContext, id, t, offset, o);
- }
- native void rsnAllocationSubReadFromObject(int con, int id, Type t, int offset, Object o);
- synchronized void nAllocationSubReadFromObject(int id, Type t, int offset, Object o) {
- rsnAllocationSubReadFromObject(mContext, id, t, offset, o);
- }
native int rsnAllocationGetType(int con, int id);
synchronized int nAllocationGetType(int id) {
return rsnAllocationGetType(mContext, id);
diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java
index 21053c9..0b3db69 100644
--- a/graphics/java/android/renderscript/Type.java
+++ b/graphics/java/android/renderscript/Type.java
@@ -33,7 +33,6 @@ public class Type extends BaseObj {
int mElementCount;
Element mElement;
- private int mNativeCache;
Class mJavaClass;
public Element getElement() {
@@ -98,14 +97,9 @@ public class Type extends BaseObj {
Type(int id, RenderScript rs) {
super(id, rs);
- mNativeCache = 0;
}
protected void finalize() throws Throwable {
- if(mNativeCache != 0) {
- mRS.nTypeFinalDestroy(this);
- mNativeCache = 0;
- }
super.finalize();
}
diff --git a/graphics/jni/Android.mk b/graphics/jni/Android.mk
index 8476be1..4c4a128 100644
--- a/graphics/jni/Android.mk
+++ b/graphics/jni/Android.mk
@@ -13,14 +13,13 @@ LOCAL_SRC_FILES:= \
LOCAL_SHARED_LIBRARIES := \
libandroid_runtime \
- libacc \
libnativehelper \
libRS \
libcutils \
libskia \
libutils \
libui \
- libsurfaceflinger_client
+ libsurfaceflinger_client
LOCAL_STATIC_LIBRARIES :=
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 81f08e9..f07dbfd 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -70,9 +70,6 @@ static void _nInit(JNIEnv *_env, jclass _this)
jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
-
- jclass typeClass = _env->FindClass("android/renderscript/Type");
- gTypeNativeCache = _env->GetFieldID(typeClass, "mNativeCache", "I");
}
static void nInitElements(JNIEnv *_env, jobject _this, jint a8, jint rgba4444, jint rgba8888, jint rgb565)
@@ -256,12 +253,13 @@ nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind,
}
static jint
-nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, jintArray _ids, jobjectArray _names)
+nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, jintArray _ids, jobjectArray _names, jintArray _arraySizes)
{
int fieldCount = _env->GetArrayLength(_ids);
LOG_API("nElementCreate2, con(%p)", con);
jint *ids = _env->GetIntArrayElements(_ids, NULL);
+ jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
const char ** nameArray = (const char **)calloc(fieldCount, sizeof(char *));
size_t* sizeArray = (size_t*)calloc(fieldCount, sizeof(size_t));
@@ -270,12 +268,13 @@ nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, jintArray _ids, jobj
nameArray[ct] = _env->GetStringUTFChars(s, NULL);
sizeArray[ct] = _env->GetStringUTFLength(s);
}
- jint id = (jint)rsElementCreate2(con, fieldCount, (RsElement *)ids, nameArray, sizeArray);
+ jint id = (jint)rsElementCreate2(con, fieldCount, (RsElement *)ids, nameArray, sizeArray, (const uint32_t *)arraySizes);
for (int ct=0; ct < fieldCount; ct++) {
jstring s = (jstring)_env->GetObjectArrayElement(_names, ct);
_env->ReleaseStringUTFChars(s, nameArray[ct]);
}
_env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
+ _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
free(nameArray);
free(sizeArray);
return (jint)id;
@@ -360,124 +359,6 @@ nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArra
}
}
-static void * SF_LoadInt(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
-{
- ((int32_t *)buffer)[0] = _env->GetIntField(_obj, _field);
- return ((uint8_t *)buffer) + 4;
-}
-
-static void * SF_LoadShort(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
-{
- ((int16_t *)buffer)[0] = _env->GetShortField(_obj, _field);
- return ((uint8_t *)buffer) + 2;
-}
-
-static void * SF_LoadByte(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
-{
- ((int8_t *)buffer)[0] = _env->GetByteField(_obj, _field);
- return ((uint8_t *)buffer) + 1;
-}
-
-static void * SF_LoadFloat(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
-{
- ((float *)buffer)[0] = _env->GetFloatField(_obj, _field);
- return ((uint8_t *)buffer) + 4;
-}
-
-static void * SF_SaveInt(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
-{
- _env->SetIntField(_obj, _field, ((int32_t *)buffer)[0]);
- return ((uint8_t *)buffer) + 4;
-}
-
-static void * SF_SaveShort(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
-{
- _env->SetShortField(_obj, _field, ((int16_t *)buffer)[0]);
- return ((uint8_t *)buffer) + 2;
-}
-
-static void * SF_SaveByte(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
-{
- _env->SetByteField(_obj, _field, ((int8_t *)buffer)[0]);
- return ((uint8_t *)buffer) + 1;
-}
-
-static void * SF_SaveFloat(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
-{
- _env->SetFloatField(_obj, _field, ((float *)buffer)[0]);
- return ((uint8_t *)buffer) + 4;
-}
-
-struct TypeFieldCache {
- jfieldID field;
- int bits;
- void * (*ptr)(JNIEnv *, jobject, jfieldID, void *buffer);
- void * (*readPtr)(JNIEnv *, jobject, jfieldID, void *buffer);
-};
-
-struct TypeCache {
- int fieldCount;
- int size;
- TypeFieldCache fields[1];
-};
-
-//{"nTypeFinalDestroy", "(Landroid/renderscript/Type;)V", (void*)nTypeFinalDestroy },
-static void
-nTypeFinalDestroy(JNIEnv *_env, jobject _this, RsContext con, jobject _type)
-{
- TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache);
- free(tc);
-}
-
-// native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs);
-static void
-nTypeSetupFields(JNIEnv *_env, jobject _this, RsContext con, jobject _type, jintArray _types, jintArray _bits, jobjectArray _IDs)
-{
- int fieldCount = _env->GetArrayLength(_types);
- size_t structSize = sizeof(TypeCache) + (sizeof(TypeFieldCache) * (fieldCount-1));
- TypeCache *tc = (TypeCache *)malloc(structSize);
- memset(tc, 0, structSize);
-
- TypeFieldCache *tfc = &tc->fields[0];
- tc->fieldCount = fieldCount;
- _env->SetIntField(_type, gTypeNativeCache, (jint)tc);
-
- jint *fType = _env->GetIntArrayElements(_types, NULL);
- jint *fBits = _env->GetIntArrayElements(_bits, NULL);
- for (int ct=0; ct < fieldCount; ct++) {
- jobject field = _env->GetObjectArrayElement(_IDs, ct);
- tfc[ct].field = _env->FromReflectedField(field);
- tfc[ct].bits = fBits[ct];
-
- switch(fType[ct]) {
- case RS_TYPE_FLOAT_32:
- tfc[ct].ptr = SF_LoadFloat;
- tfc[ct].readPtr = SF_SaveFloat;
- break;
- case RS_TYPE_UNSIGNED_32:
- case RS_TYPE_SIGNED_32:
- tfc[ct].ptr = SF_LoadInt;
- tfc[ct].readPtr = SF_SaveInt;
- break;
- case RS_TYPE_UNSIGNED_16:
- case RS_TYPE_SIGNED_16:
- tfc[ct].ptr = SF_LoadShort;
- tfc[ct].readPtr = SF_SaveShort;
- break;
- case RS_TYPE_UNSIGNED_8:
- case RS_TYPE_SIGNED_8:
- tfc[ct].ptr = SF_LoadByte;
- tfc[ct].readPtr = SF_SaveByte;
- break;
- }
- tc->size += 4;
- }
-
- _env->ReleaseIntArrayElements(_types, fType, JNI_ABORT);
- _env->ReleaseIntArrayElements(_bits, fBits, JNI_ABORT);
-}
-
-
// -----------------------------------
static jint
@@ -649,6 +530,17 @@ nAllocationSubData1D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, j
}
static void
+// native void rsnAllocationSubElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
+nAllocationSubElementData1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint compIdx, jbyteArray data, int sizeBytes)
+{
+ jint len = _env->GetArrayLength(data);
+ LOG_API("nAllocationSubElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes);
+ jbyte *ptr = _env->GetByteArrayElements(data, NULL);
+ rsAllocation1DSubElementData(con, (RsAllocation)alloc, offset, ptr, compIdx, sizeBytes);
+ _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
+}
+
+static void
nAllocationSubData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint w, jint h, jintArray data, int sizeBytes)
{
jint len = _env->GetArrayLength(data);
@@ -688,45 +580,6 @@ nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloat
_env->ReleaseFloatArrayElements(data, ptr, 0);
}
-
-//{"nAllocationDataFromObject", "(ILandroid/renderscript/Type;Ljava/lang/Object;)V", (void*)nAllocationDataFromObject },
-static void
-nAllocationSubDataFromObject(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject _type, jint offset, jobject _o)
-{
- LOG_API("nAllocationDataFromObject con(%p), alloc(%p)", con, (RsAllocation)alloc);
-
- const TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache);
-
- void * bufAlloc = malloc(tc->size);
- void * buf = bufAlloc;
- for (int ct=0; ct < tc->fieldCount; ct++) {
- const TypeFieldCache *tfc = &tc->fields[ct];
- buf = tfc->ptr(_env, _o, tfc->field, buf);
- }
- rsAllocation1DSubData(con, (RsAllocation)alloc, offset, 1, bufAlloc, tc->size);
- free(bufAlloc);
-}
-
-static void
-nAllocationSubReadFromObject(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject _type, jint offset, jobject _o)
-{
- LOG_API("nAllocationReadFromObject con(%p), alloc(%p)", con, (RsAllocation)alloc);
-
- assert(offset == 0);
-
- const TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache);
-
- void * bufAlloc = malloc(tc->size);
- void * buf = bufAlloc;
- rsAllocationRead(con, (RsAllocation)alloc, bufAlloc);
-
- for (int ct=0; ct < tc->fieldCount; ct++) {
- const TypeFieldCache *tfc = &tc->fields[ct];
- buf = tfc->readPtr(_env, _o, tfc->field, buf);
- }
- free(bufAlloc);
-}
-
static jint
nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
{
@@ -1379,15 +1232,13 @@ static JNINativeMethod methods[] = {
{"rsnFontCreateFromFile", "(ILjava/lang/String;II)I", (void*)nFontCreateFromFile },
{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
-{"rsnElementCreate2", "(I[I[Ljava/lang/String;)I", (void*)nElementCreate2 },
+{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;)V", (void*)nElementGetSubElements },
{"rsnTypeBegin", "(II)V", (void*)nTypeBegin },
{"rsnTypeAdd", "(III)V", (void*)nTypeAdd },
{"rsnTypeCreate", "(I)I", (void*)nTypeCreate },
-{"rsnTypeFinalDestroy", "(ILandroid/renderscript/Type;)V", (void*)nTypeFinalDestroy },
-{"rsnTypeSetupFields", "(ILandroid/renderscript/Type;[I[I[Ljava/lang/reflect/Field;)V", (void*)nTypeSetupFields },
{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
{"rsnAllocationCreateTyped", "(II)I", (void*)nAllocationCreateTyped },
@@ -1401,12 +1252,11 @@ static JNINativeMethod methods[] = {
{"rsnAllocationSubData1D", "(IIII[SI)V", (void*)nAllocationSubData1D_s },
{"rsnAllocationSubData1D", "(IIII[BI)V", (void*)nAllocationSubData1D_b },
{"rsnAllocationSubData1D", "(IIII[FI)V", (void*)nAllocationSubData1D_f },
+{"rsnAllocationSubElementData1D", "(IIII[BI)V", (void*)nAllocationSubElementData1D },
{"rsnAllocationSubData2D", "(IIIIII[II)V", (void*)nAllocationSubData2D_i },
{"rsnAllocationSubData2D", "(IIIIII[FI)V", (void*)nAllocationSubData2D_f },
{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i },
{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f },
-{"rsnAllocationSubDataFromObject", "(IILandroid/renderscript/Type;ILjava/lang/Object;)V", (void*)nAllocationSubDataFromObject },
-{"rsnAllocationSubReadFromObject", "(IILandroid/renderscript/Type;ILjava/lang/Object;)V", (void*)nAllocationSubReadFromObject },
{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType},
{"rsnAdapter1DBindAllocation", "(III)V", (void*)nAdapter1DBindAllocation },
diff --git a/graphics/tests/graphicstests/src/android/graphics/BitmapFactoryTest.java b/graphics/tests/graphicstests/src/android/graphics/BitmapFactoryTest.java
new file mode 100644
index 0000000..09820ef
--- /dev/null
+++ b/graphics/tests/graphicstests/src/android/graphics/BitmapFactoryTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2010 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.graphics;
+
+import android.os.ParcelFileDescriptor;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FileDescriptor;
+
+import junit.framework.TestCase;
+
+
+public class BitmapFactoryTest extends TestCase {
+
+ // tests that we can decode bitmaps from MemoryFiles
+ @SmallTest
+ public void testBitmapParcelFileDescriptor() throws Exception {
+ Bitmap bitmap1 = Bitmap.createBitmap(
+ new int[] { Color.BLUE }, 1, 1, Bitmap.Config.RGB_565);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ bitmap1.compress(Bitmap.CompressFormat.PNG, 100, out);
+ ParcelFileDescriptor pfd = ParcelFileDescriptor.fromData(out.toByteArray(), null);
+ FileDescriptor fd = pfd.getFileDescriptor();
+ assertNotNull("Got null FileDescriptor", fd);
+ assertTrue("Got invalid FileDescriptor", fd.valid());
+ Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fd);
+ assertNotNull("BitmapFactory returned null", bitmap);
+ assertEquals("Bitmap width", 1, bitmap.getWidth());
+ assertEquals("Bitmap height", 1, bitmap.getHeight());
+ }
+
+}